From a187dfef40e6fb18d04dfd140396787cc0711feb Mon Sep 17 00:00:00 2001 From: Geert Custers Date: Tue, 20 Jul 2021 10:47:04 +0000 Subject: [PATCH] meta: add mlibc-config.h and replace bit/features.h --- abis/linux/x86_64/signal.h | 1 - abis/mlibc/signal.h | 2 -- internal-config.h.in | 1 + meson.build | 15 ++++++++++++++- mlibc-config.h.in | 10 ++++++++++ options/ansi/generic/environment.cpp | 2 +- options/ansi/generic/locale-stubs.cpp | 1 - options/ansi/generic/stdlib-stubs.cpp | 4 ++-- options/ansi/include/ctype.h | 4 ++-- options/ansi/include/errno.h | 1 - options/ansi/include/locale.h | 4 ++-- options/ansi/include/setjmp.h | 4 ++-- options/ansi/include/signal.h | 4 ++-- options/ansi/include/stdio.h | 4 ++-- options/ansi/include/stdlib.h | 4 ++-- options/ansi/include/string.h | 4 ++-- options/ansi/include/time.h | 4 ++-- options/ansi/include/wctype.h | 4 ++-- options/glibc/include/sys/ioctl.h | 7 ++++--- options/internal/include/bits/feature.h | 10 ---------- options/internal/include/mlibc/all-sysdeps.hpp | 8 ++++---- options/posix/generic/sys-select-stubs.cpp | 3 +-- options/posix/include/unistd.h | 4 ++-- sysdeps/linux/generic/cxx-syscall.hpp | 4 ++-- sysdeps/linux/generic/sysdeps.cpp | 4 ++-- 25 files changed, 61 insertions(+), 52 deletions(-) create mode 100644 mlibc-config.h.in delete mode 100644 options/internal/include/bits/feature.h diff --git a/abis/linux/x86_64/signal.h b/abis/linux/x86_64/signal.h index 56c591fb..141001ab 100644 --- a/abis/linux/x86_64/signal.h +++ b/abis/linux/x86_64/signal.h @@ -3,7 +3,6 @@ #include #include -#include #include #include diff --git a/abis/mlibc/signal.h b/abis/mlibc/signal.h index e1afc76b..663bdfc1 100644 --- a/abis/mlibc/signal.h +++ b/abis/mlibc/signal.h @@ -1,8 +1,6 @@ #ifndef _ABIBITS_SIGNAL_H #define _ABIBITS_SIGNAL_H -#include - #include #include diff --git a/internal-config.h.in b/internal-config.h.in index bb3779b2..5e34be50 100644 --- a/internal-config.h.in +++ b/internal-config.h.in @@ -1,3 +1,4 @@ +#pragma once #mesondefine MLIBC_SYSTEM_NAME #mesondefine MLIBC_MAP_DSO_SEGMENTS diff --git a/meson.build b/meson.build index edcd2302..c683687b 100644 --- a/meson.build +++ b/meson.build @@ -31,6 +31,7 @@ disable_linux_option = get_option('disable_linux_option') disable_iconv_option = get_option('disable_iconv_option') disable_intl_option = get_option('disable_intl_option') internal_conf = configuration_data() +mlibc_conf = configuration_data() if not headers_only cxxshim_dep = subproject('cxxshim').get_variable('cxxshim_dep') @@ -127,6 +128,12 @@ endif # Configuration based on enabled options. #---------------------------------------------------------------------------------------- +mlibc_conf.set('__MLIBC_ANSI_OPTION', not disable_ansi_option) +mlibc_conf.set('__MLIBC_POSIX_OPTION', not disable_posix_option) +mlibc_conf.set('__MLIBC_LINUX_OPTION', not disable_linux_option) +mlibc_conf.set('__MLIBC_INTL_OPTION', not disable_intl_option) +mlibc_conf.set('__MLIBC_ICONV_OPTION', not disable_iconv_option) + if not disable_ansi_option rtdl_include_dirs += include_directories('options/ansi/include') libc_include_dirs += include_directories('options/ansi/include') @@ -150,6 +157,7 @@ rtdl_include_dirs += include_directories('options/elf/include') rtdl_include_dirs += include_directories('options/linux/include') libc_include_dirs += include_directories('options/elf/include') libc_include_dirs += include_directories('options/linux/include') +libc_include_dirs += include_directories('.') #---------------------------------------------------------------------------------------- @@ -157,6 +165,12 @@ configure_file(input: 'internal-config.h.in', output: 'internal-config.h', configuration: internal_conf) +configure_file(input: 'mlibc-config.h.in', + output: 'mlibc-config.h', + configuration: mlibc_conf, + install: true, + install_dir: get_option('includedir')) + internal_sources = [ 'options/internal/generic/allocator.cpp', 'options/internal/generic/charcode.cpp', @@ -188,7 +202,6 @@ if not no_headers install_headers( 'options/internal/include/bits/wchar_t.h', 'options/internal/include/bits/wint_t.h', - 'options/internal/include/bits/feature.h', 'options/internal/include/bits/size_t.h', 'options/internal/include/bits/types.h', 'options/internal/include/bits/ensure.h', diff --git a/mlibc-config.h.in b/mlibc-config.h.in new file mode 100644 index 00000000..ad6e6e89 --- /dev/null +++ b/mlibc-config.h.in @@ -0,0 +1,10 @@ +#ifndef _MLIBC_CONFIG_H +#define _MLIBC_CONFIG_H + +#mesondefine __MLIBC_ANSI_OPTION +#mesondefine __MLIBC_POSIX_OPTION +#mesondefine __MLIBC_LINUX_OPTION +#mesondefine __MLIBC_INTL_OPTION +#mesondefine __MLIBC_ICONV_OPTION + +#endif // _MLIBC_CONFIG_H diff --git a/options/ansi/generic/environment.cpp b/options/ansi/generic/environment.cpp index 0871c012..d20ec84b 100644 --- a/options/ansi/generic/environment.cpp +++ b/options/ansi/generic/environment.cpp @@ -121,7 +121,7 @@ int putenv(char *string) { } // namespace mlibc -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION int putenv(char *string) { return mlibc::putenv(string); diff --git a/options/ansi/generic/locale-stubs.cpp b/options/ansi/generic/locale-stubs.cpp index 0d5648db..fb8ca118 100644 --- a/options/ansi/generic/locale-stubs.cpp +++ b/options/ansi/generic/locale-stubs.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include diff --git a/options/ansi/generic/stdlib-stubs.cpp b/options/ansi/generic/stdlib-stubs.cpp index d4d0aa67..072c863a 100644 --- a/options/ansi/generic/stdlib-stubs.cpp +++ b/options/ansi/generic/stdlib-stubs.cpp @@ -20,7 +20,7 @@ #include #include -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION #include #endif // __MLIBC_POSIX_OPTION @@ -274,7 +274,7 @@ int system(const char *command) { return -1; } -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION pthread_testcancel(); #endif // __MLIBC_POSIX_OPTION diff --git a/options/ansi/include/ctype.h b/options/ansi/include/ctype.h index 046ee0b9..5d8e12cc 100644 --- a/options/ansi/include/ctype.h +++ b/options/ansi/include/ctype.h @@ -1,7 +1,7 @@ #ifndef _CTYPE_H #define _CTYPE_H -#include +#include #ifdef __cplusplus extern "C" { @@ -35,7 +35,7 @@ int toupper(int c); } #endif -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION # include #endif diff --git a/options/ansi/include/errno.h b/options/ansi/include/errno.h index b52bc1c8..475bbc5a 100644 --- a/options/ansi/include/errno.h +++ b/options/ansi/include/errno.h @@ -1,7 +1,6 @@ #ifndef _ERRNO_H #define _ERRNO_H -#include #include // Some programs define their own errno as an "extern int" if it is not a macro. diff --git a/options/ansi/include/locale.h b/options/ansi/include/locale.h index 99035df1..21c2401a 100644 --- a/options/ansi/include/locale.h +++ b/options/ansi/include/locale.h @@ -2,7 +2,7 @@ #ifndef _LOCALE_H #define _LOCALE_H -#include +#include #include @@ -65,7 +65,7 @@ struct lconv *localeconv(void); // posix extension -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION # include #endif // __MLIBC_POSIX_OPTION diff --git a/options/ansi/include/setjmp.h b/options/ansi/include/setjmp.h index 1ea973cd..aa3c8f49 100644 --- a/options/ansi/include/setjmp.h +++ b/options/ansi/include/setjmp.h @@ -2,7 +2,7 @@ #ifndef _SETJMP_H #define _SETJMP_H -#include +#include #include #include @@ -27,7 +27,7 @@ typedef struct { sigset_t sigset; } sigjmp_buf[1]; -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION __attribute__ (( returns_twice )) int sigsetjmp(sigjmp_buf buffer, int savesigs); __attribute__ (( noreturn )) void siglongjmp(sigjmp_buf buffer, int value); #endif // __MLIBC_POSIX_OPTION diff --git a/options/ansi/include/signal.h b/options/ansi/include/signal.h index f1b11631..dce82523 100644 --- a/options/ansi/include/signal.h +++ b/options/ansi/include/signal.h @@ -2,7 +2,7 @@ #define _SIGNAL_H #include -#include +#include #ifdef __cplusplus extern "C" { @@ -34,7 +34,7 @@ int raise(int sig); } #endif -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION # include #endif diff --git a/options/ansi/include/stdio.h b/options/ansi/include/stdio.h index 4eb59e5e..ce5f5f21 100644 --- a/options/ansi/include/stdio.h +++ b/options/ansi/include/stdio.h @@ -3,9 +3,9 @@ #define _STDIO_H #include -#include #include #include +#include // Glibc extensions require ssize_t. #include @@ -186,7 +186,7 @@ int fputs_unlocked(const char *, FILE *); } #endif -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION # include #endif diff --git a/options/ansi/include/stdlib.h b/options/ansi/include/stdlib.h index 153fae74..65ac34f7 100644 --- a/options/ansi/include/stdlib.h +++ b/options/ansi/include/stdlib.h @@ -2,7 +2,7 @@ #define _STDLIB_H #include -#include +#include #include #include #include @@ -109,7 +109,7 @@ size_t wcstombs(char *mb_string, const wchar_t *__restrict wc_string, size_t max } #endif -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION # include #endif diff --git a/options/ansi/include/string.h b/options/ansi/include/string.h index d8bce017..befb8d8c 100644 --- a/options/ansi/include/string.h +++ b/options/ansi/include/string.h @@ -1,7 +1,7 @@ #ifndef _STRING_H #define _STRING_H -#include +#include #include #include @@ -62,7 +62,7 @@ int strverscmp(const char *l0, const char *r0); } #endif -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION # include #endif diff --git a/options/ansi/include/time.h b/options/ansi/include/time.h index 167706f2..9fbbceed 100644 --- a/options/ansi/include/time.h +++ b/options/ansi/include/time.h @@ -1,11 +1,11 @@ #ifndef _TIME_H #define _TIME_H -#include #include #include #include #include +#include // [7.27.1] Components of time @@ -72,7 +72,7 @@ void tzset(void); // POSIX extensions. -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION # include #endif // __MLIBC_POSIX_OPTION diff --git a/options/ansi/include/wctype.h b/options/ansi/include/wctype.h index 3c2a3f49..d7a139c1 100644 --- a/options/ansi/include/wctype.h +++ b/options/ansi/include/wctype.h @@ -1,7 +1,7 @@ #ifndef _WCTYPE_H #define _WCTYPE_H -#include +#include #include #ifdef __cplusplus @@ -41,7 +41,7 @@ wint_t towctrans(wint_t, wctrans_t); } #endif -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION # include #endif diff --git a/options/glibc/include/sys/ioctl.h b/options/glibc/include/sys/ioctl.h index 12e193ec..913aaa84 100644 --- a/options/glibc/include/sys/ioctl.h +++ b/options/glibc/include/sys/ioctl.h @@ -1,12 +1,13 @@ #ifndef _SYS_IOCTL_H #define _SYS_IOCTL_H -#include +#include // On Linux, sys/ioctl.h includes the termios ioctls. -#if __MLIBC_LINUX_OPTION +// TODO(geert): fix this!! +// #ifdef __MLIBC_LINUX_OPTION # include -#endif +// #endif #ifdef __cplusplus extern "C" { diff --git a/options/internal/include/bits/feature.h b/options/internal/include/bits/feature.h deleted file mode 100644 index 5784c4d0..00000000 --- a/options/internal/include/bits/feature.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _BITS_FEATURE_H -#define _BITS_FEATURE_H - -// TODO: The files for this macro are chosen somewhat arbitrarily. -// TODO: Choose canonical files (like a bits/posix/alltypes.h) -#define __MLIBC_ANSI_OPTION __has_include() -#define __MLIBC_POSIX_OPTION __has_include() -#define __MLIBC_LINUX_OPTION __has_include() - -#endif // _BITS_FEATURE_H diff --git a/options/internal/include/mlibc/all-sysdeps.hpp b/options/internal/include/mlibc/all-sysdeps.hpp index 02f11cf9..72f713df 100644 --- a/options/internal/include/mlibc/all-sysdeps.hpp +++ b/options/internal/include/mlibc/all-sysdeps.hpp @@ -1,18 +1,18 @@ #ifndef MLIBC_ALL_SYSDEPS #define MLIBC_ALL_SYSDEPS -#include +#include #include -#if __MLIBC_ANSI_OPTION +#ifdef __MLIBC_ANSI_OPTION # include #endif // __MLIBC_ANSI_OPTION -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION # include #endif // __MLIBC_POSIX_OPTION -#if __MLIBC_LINUX_OPTION +#ifdef __MLIBC_LINUX_OPTION # include #endif // __MLIBC_LINUX_OPTION diff --git a/options/posix/generic/sys-select-stubs.cpp b/options/posix/generic/sys-select-stubs.cpp index 29ba28c1..f2df249b 100644 --- a/options/posix/generic/sys-select-stubs.cpp +++ b/options/posix/generic/sys-select-stubs.cpp @@ -5,9 +5,8 @@ #include #include -#include #include -#include +#include #include diff --git a/options/posix/include/unistd.h b/options/posix/include/unistd.h index fbca634d..f010ca92 100644 --- a/options/posix/include/unistd.h +++ b/options/posix/include/unistd.h @@ -2,7 +2,7 @@ #ifndef _UNISTD_H #define _UNISTD_H -#include +#include #include #include #include @@ -234,7 +234,7 @@ int pipe2(int *pipefd, int flags); } #endif -#if __MLIBC_LINUX_OPTION +#ifdef __MLIBC_LINUX_OPTION # include #endif diff --git a/sysdeps/linux/generic/cxx-syscall.hpp b/sysdeps/linux/generic/cxx-syscall.hpp index bfc80f0c..4eb9cb04 100644 --- a/sysdeps/linux/generic/cxx-syscall.hpp +++ b/sysdeps/linux/generic/cxx-syscall.hpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include // GCC allows register + asm placement in extern "C" mode, but not in C++ mode. @@ -159,7 +159,7 @@ namespace mlibc { template sc_result_t do_cp_syscall(int sc, T... args) { -#if __MLIBC_POSIX_OPTION && !defined(MLIBC_BUILDING_RTDL) +#if defined(__MLIBC_POSIX_OPTION) && !defined(MLIBC_BUILDING_RTDL) auto result = static_cast(do_nargs_cp_syscall(sc, sc_cast(args)...)); if (int e = sc_error(result); e) { auto tcb = reinterpret_cast(get_current_tcb()); diff --git a/sysdeps/linux/generic/sysdeps.cpp b/sysdeps/linux/generic/sysdeps.cpp index e7241b9f..018e0d05 100644 --- a/sysdeps/linux/generic/sysdeps.cpp +++ b/sysdeps/linux/generic/sysdeps.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include #include #include @@ -251,7 +251,7 @@ int sys_sleep(time_t *secs, long *nanos) { return 0; } -#if __MLIBC_POSIX_OPTION +#ifdef __MLIBC_POSIX_OPTION #include #include