On 27/11/2019 02:06, Luc Van Oostenryck wrote: > There are a few OS-specific settings and handling them > with #ifdef is 1) ugly, 2) can only work with when specifically > built for this OS (either a native or cross-build). > > So, use a variable to hold the OS and initialize it to the one > used to compile sparse. This avoid the ugly #ifdef and allow > simpler transition if if the future sparse would take the OS > in parameter (maybe as triple). > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> > --- > lib.c | 1 + > lib.h | 1 + > machine.h | 26 ++++++++++++++++++++++++++ > target.c | 24 +++++++++++++----------- > 4 files changed, 41 insertions(+), 11 deletions(-) > > diff --git a/lib.c b/lib.c > index 602960a08..8bfe4e1c9 100644 > --- a/lib.c > +++ b/lib.c > @@ -329,6 +329,7 @@ static int arch_msize_long = 0; > int arch_m64 = ARCH_M64_DEFAULT; > int arch_big_endian = ARCH_BIG_ENDIAN; > int arch_mach = MACH_NATIVE; > +int arch_os = OS_NATIVE; > int arch_cmodel = CMODEL_UNKNOWN; > > > diff --git a/lib.h b/lib.h > index 00c608125..24febfbfa 100644 > --- a/lib.h > +++ b/lib.h > @@ -207,6 +207,7 @@ extern int funsigned_char; > extern int arch_m64; > extern int arch_big_endian; > extern int arch_mach; > +extern int arch_os; > > enum { > CMODEL_UNKNOWN, > diff --git a/machine.h b/machine.h > index 22b05d91a..e98a64462 100644 > --- a/machine.h > +++ b/machine.h > @@ -70,4 +70,30 @@ enum machine { > #define MACH_NATIVE MACH_UNKNOWN > #endif > > + > +enum { > + OS_CYGWIN, > + OS_DARWIN, > + OS_FREEBSD, > + OS_LINUX, > + OS_NETBSD, > + OS_OPENBSD, > + OS_SUNOS, > + OS_UNKNOWN, > +}; cgcc also supports: gnu (== Hurd kernel, Linux userspace ?) gnu/kfreebsd (== Hurd kernel, FreeBSD userspace ?) Yes, I am just guessing at the above definitions! ;-) [I think Debian have these builds, right?] ATB, Ramsay Jones > + > +#if defined(__linux__) || defined(__linux) > +#define OS_NATIVE OS_LINUX > +#elif defined(__FreeBSD__) > +#define OS_NATIVE OS_FREEBSD > +#elif defined(__APPLE__) > +#define OS_NATIVE OS_DARWIN > +#elif defined(__CYGWIN__) > +#define OS_NATIVE OS_CYGWIN > +#elif defined(__sun__) && defined(__sun) > +#define OS_NATIVE OS_SUNOS > +#else > +#define OS_NATIVE OS_UNKNOWN > +#endif > + > #endif > diff --git a/target.c b/target.c > index d03b179be..c89bb07d2 100644 > --- a/target.c > +++ b/target.c > @@ -83,13 +83,19 @@ void init_target(void) > wchar_ctype = &long_ctype; > /* fall through */ > case MACH_X86_64: > -#if defined(__APPLE__) > - int64_ctype = &llong_ctype; > - uint64_ctype = &ullong_ctype; > -#endif > -#if defined(__FreeBSD__) || defined(__APPLE__) > - wint_ctype = &int_ctype; > -#endif > + switch (arch_os) { > + case OS_CYGWIN: > + wchar_ctype = &ushort_ctype; > + break; > + case OS_DARWIN: > + int64_ctype = &llong_ctype; > + uint64_ctype = &ullong_ctype; > + wint_ctype = &int_ctype; > + break; > + case OS_FREEBSD: > + wint_ctype = &int_ctype; > + break; > + } > break; > case MACH_M68K: > case MACH_SPARC32: > @@ -178,8 +184,4 @@ void init_target(void) > pointer_alignment = 8; > break; > } > - > -#if defined(__CYGWIN__) > - wchar_ctype = &ushort_ctype; > -#endif > } >