meta: add mlibc-config.h and replace bit/features.h

This commit is contained in:
Geert Custers 2021-07-20 10:47:04 +00:00
parent a80b6af80a
commit a187dfef40
25 changed files with 61 additions and 52 deletions

View file

@ -3,7 +3,6 @@
#include <stdint.h>
#include <time.h>
#include <bits/feature.h>
#include <abi-bits/pid_t.h>
#include <abi-bits/uid_t.h>

View file

@ -1,8 +1,6 @@
#ifndef _ABIBITS_SIGNAL_H
#define _ABIBITS_SIGNAL_H
#include <bits/feature.h>
#include <abi-bits/pid_t.h>
#include <abi-bits/uid_t.h>

View file

@ -1,3 +1,4 @@
#pragma once
#mesondefine MLIBC_SYSTEM_NAME
#mesondefine MLIBC_MAP_DSO_SEGMENTS

View file

@ -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',

10
mlibc-config.h.in Normal file
View file

@ -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

View file

@ -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);

View file

@ -4,7 +4,6 @@
#include <string.h>
#include <bits/ensure.h>
#include <bits/feature.h>
#include <mlibc/debug.hpp>
#include <frg/optional.hpp>

View file

@ -20,7 +20,7 @@
#include <mlibc/ansi-sysdeps.hpp>
#include <mlibc/strtofp.hpp>
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
#include <pthread.h>
#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

View file

@ -1,7 +1,7 @@
#ifndef _CTYPE_H
#define _CTYPE_H
#include <bits/feature.h>
#include <mlibc-config.h>
#ifdef __cplusplus
extern "C" {
@ -35,7 +35,7 @@ int toupper(int c);
}
#endif
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_ctype.h>
#endif

View file

@ -1,7 +1,6 @@
#ifndef _ERRNO_H
#define _ERRNO_H
#include <bits/feature.h>
#include <abi-bits/errno.h>
// Some programs define their own errno as an "extern int" if it is not a macro.

View file

@ -2,7 +2,7 @@
#ifndef _LOCALE_H
#define _LOCALE_H
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/null.h>
@ -65,7 +65,7 @@ struct lconv *localeconv(void);
// posix extension
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_locale.h>
#endif // __MLIBC_POSIX_OPTION

View file

@ -2,7 +2,7 @@
#ifndef _SETJMP_H
#define _SETJMP_H
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/machine.h>
#include <abi-bits/signal.h>
@ -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

View file

@ -2,7 +2,7 @@
#define _SIGNAL_H
#include <abi-bits/signal.h>
#include <bits/feature.h>
#include <mlibc-config.h>
#ifdef __cplusplus
extern "C" {
@ -34,7 +34,7 @@ int raise(int sig);
}
#endif
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_signal.h>
#endif

View file

@ -3,9 +3,9 @@
#define _STDIO_H
#include <abi-bits/seek-whence.h>
#include <bits/feature.h>
#include <bits/null.h>
#include <bits/size_t.h>
#include <mlibc-config.h>
// Glibc extensions require ssize_t.
#include <bits/ssize_t.h>
@ -186,7 +186,7 @@ int fputs_unlocked(const char *, FILE *);
}
#endif
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_stdio.h>
#endif

View file

@ -2,7 +2,7 @@
#define _STDLIB_H
#include <alloca.h>
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/null.h>
#include <bits/size_t.h>
#include <bits/wchar_t.h>
@ -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 <bits/posix/posix_stdlib.h>
#endif

View file

@ -1,7 +1,7 @@
#ifndef _STRING_H
#define _STRING_H
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/null.h>
#include <bits/size_t.h>
@ -62,7 +62,7 @@ int strverscmp(const char *l0, const char *r0);
}
#endif
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_string.h>
#endif

View file

@ -1,11 +1,11 @@
#ifndef _TIME_H
#define _TIME_H
#include <bits/feature.h>
#include <bits/null.h>
#include <bits/size_t.h>
#include <bits/ansi/time_t.h>
#include <bits/ansi/timespec.h>
#include <mlibc-config.h>
// [7.27.1] Components of time
@ -72,7 +72,7 @@ void tzset(void);
// POSIX extensions.
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_time.h>
#endif // __MLIBC_POSIX_OPTION

View file

@ -1,7 +1,7 @@
#ifndef _WCTYPE_H
#define _WCTYPE_H
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/wint_t.h>
#ifdef __cplusplus
@ -41,7 +41,7 @@ wint_t towctrans(wint_t, wctrans_t);
}
#endif
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <bits/posix/posix_wctype.h>
#endif

View file

@ -1,12 +1,13 @@
#ifndef _SYS_IOCTL_H
#define _SYS_IOCTL_H
#include <bits/feature.h>
#include <mlibc-config.h>
// On Linux, sys/ioctl.h includes the termios ioctls.
#if __MLIBC_LINUX_OPTION
// TODO(geert): fix this!!
// #ifdef __MLIBC_LINUX_OPTION
# include <asm/ioctls.h>
#endif
// #endif
#ifdef __cplusplus
extern "C" {

View file

@ -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(<stdlib.h>)
#define __MLIBC_POSIX_OPTION __has_include(<unistd.h>)
#define __MLIBC_LINUX_OPTION __has_include(<linux/types.h>)
#endif // _BITS_FEATURE_H

View file

@ -1,18 +1,18 @@
#ifndef MLIBC_ALL_SYSDEPS
#define MLIBC_ALL_SYSDEPS
#include <bits/feature.h>
#include <mlibc-config.h>
#include <internal-config.h>
#if __MLIBC_ANSI_OPTION
#ifdef __MLIBC_ANSI_OPTION
# include <mlibc/ansi-sysdeps.hpp>
#endif // __MLIBC_ANSI_OPTION
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
# include <mlibc/posix-sysdeps.hpp>
#endif // __MLIBC_POSIX_OPTION
#if __MLIBC_LINUX_OPTION
#ifdef __MLIBC_LINUX_OPTION
# include <mlibc/linux-sysdeps.hpp>
#endif // __MLIBC_LINUX_OPTION

View file

@ -5,9 +5,8 @@
#include <unistd.h>
#include <errno.h>
#include <mlibc/debug.hpp>
#include <bits/ensure.h>
#include <bits/feature.h>
#include <mlibc-config.h>
#include <mlibc/posix-sysdeps.hpp>

View file

@ -2,7 +2,7 @@
#ifndef _UNISTD_H
#define _UNISTD_H
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/types.h>
#include <bits/size_t.h>
#include <bits/ssize_t.h>
@ -234,7 +234,7 @@ int pipe2(int *pipefd, int flags);
}
#endif
#if __MLIBC_LINUX_OPTION
#ifdef __MLIBC_LINUX_OPTION
# include <bits/linux/linux_unistd.h>
#endif

View file

@ -1,7 +1,7 @@
#include <errno.h>
#include <mlibc/tcb.hpp>
#include <mlibc/thread.hpp>
#include <bits/feature.h>
#include <mlibc-config.h>
#include <utility>
// GCC allows register + asm placement in extern "C" mode, but not in C++ mode.
@ -159,7 +159,7 @@ namespace mlibc {
template<typename... T>
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<sc_result_t>(do_nargs_cp_syscall(sc, sc_cast(args)...));
if (int e = sc_error(result); e) {
auto tcb = reinterpret_cast<Tcb*>(get_current_tcb());

View file

@ -1,7 +1,7 @@
#include <errno.h>
#include <type_traits>
#include <bits/feature.h>
#include <mlibc-config.h>
#include <bits/ensure.h>
#include <mlibc/debug.hpp>
#include <mlibc/all-sysdeps.hpp>
@ -251,7 +251,7 @@ int sys_sleep(time_t *secs, long *nanos) {
return 0;
}
#if __MLIBC_POSIX_OPTION
#ifdef __MLIBC_POSIX_OPTION
#include <sys/ioctl.h>
#include <sched.h>