summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-11-24 16:49:14 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-11-28 00:52:07 +0100
commit6bca188679d235ddbad2e97aa3e4186a4730686e (patch)
treec65def4c0940b6c4d1bd2afe0c611fe3b2c02cee
parent61b8e17e1456b272dbc9c14e599fb6a20984aaf6 (diff)
downloadsparse-6bca188679d235ddbad2e97aa3e4186a4730686e.tar.gz
arch: use a variable for the OS
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@gmail.com>
-rw-r--r--lib.c1
-rw-r--r--lib.h1
-rw-r--r--machine.h26
-rw-r--r--target.c24
4 files changed, 41 insertions, 11 deletions
diff --git a/lib.c b/lib.c
index 602960a0..8bfe4e1c 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 00c60812..24febfbf 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 22b05d91..e98a6446 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,
+};
+
+#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 d03b179b..c89bb07d 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
}