diff mbox series

[2/9] arch: add an option to specify the OS: --os=$OS

Message ID 20200708234151.57845-3-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series OS-specific small fixes & cleanup | expand

Commit Message

Luc Van Oostenryck July 8, 2020, 11:41 p.m. UTC
This is not needed when doing native 'compilation' but is
quite handy when testing the predefined types & macros.
The supported OSes are: 'linux', 'freebsd', 'openbsd', 'netbsd'
'darwin', 'sunos', 'cygwin' and a generic 'unix'.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 machine.h |  1 +
 options.c | 11 +++++++++++
 sparse.1  | 10 ++++++++++
 target.c  | 29 +++++++++++++++++++++++++++++
 target.h  |  1 +
 5 files changed, 52 insertions(+)
diff mbox series

Patch

diff --git a/machine.h b/machine.h
index 7407e71627e1..cc02818c81bf 100644
--- a/machine.h
+++ b/machine.h
@@ -94,6 +94,7 @@  enum fp_abi {
 
 enum {
 	OS_UNKNOWN,
+	OS_NONE,
 	OS_UNIX,
 	OS_CYGWIN,
 	OS_DARWIN,
diff --git a/options.c b/options.c
index 9f05bdf9cf4f..530d15adeffd 100644
--- a/options.c
+++ b/options.c
@@ -925,6 +925,16 @@  static char **handle_param(char *arg, char **next)
 	return next;
 }
 
+static char **handle_os(char *arg, char **next)
+{
+	if (*arg++ != '=')
+		die("missing argument for --os option");
+
+	target_os(arg);
+
+	return next;
+}
+
 static char **handle_version(char *arg, char **next)
 {
 	printf("%s\n", SPARSE_VERSION);
@@ -941,6 +951,7 @@  static char **handle_long_options(char *arg, char **next)
 {
 	static struct switches cmd[] = {
 		{ "arch", handle_arch, 1 },
+		{ "os",   handle_os, 1 },
 		{ "param", handle_param, 1 },
 		{ "version", handle_version },
 		{ NULL, NULL }
diff --git a/sparse.1 b/sparse.1
index d916ad9ee54e..82467b23330b 100644
--- a/sparse.1
+++ b/sparse.1
@@ -464,6 +464,16 @@  Look for system headers in the multiarch subdirectory \fIdir\fR.
 The \fIdir\fR name would normally take the form of the target's
 normalized GNU triplet. (e.g. i386-linux-gnu).
 .
+.TP
+.B \-\-os=\fIOS\fR
+Specify the target Operating System.
+This only makes a few differences with the predefined types.
+The accepted values are: linux, unix, freebsd, netbsd, opensd, sunos, darwin
+and cygwin.
+
+The default OS is the one of the machine used to build Sparse if it can be
+detected, oherwise some generic settings are used.
+.
 .SH DEBUG OPTIONS
 .TP
 .B \-fmem-report
diff --git a/target.c b/target.c
index 6776c3a1cbb0..8de1b1f3d9d2 100644
--- a/target.c
+++ b/target.c
@@ -136,6 +136,35 @@  enum machine target_parse(const char *name)
 	return MACH_UNKNOWN;
 }
 
+void target_os(const char *name)
+{
+	static const struct os {
+		const char *name;
+		int os;
+	} oses[] = {
+		{ "cygwin",	OS_CYGWIN },
+		{ "darwin",	OS_DARWIN },
+		{ "freebsd",	OS_FREEBSD },
+		{ "linux",	OS_LINUX },
+		{ "native",	OS_NATIVE, },
+		{ "netbsd",	OS_NETBSD },
+		{ "none",	OS_NONE },
+		{ "openbsd",	OS_OPENBSD },
+		{ "sunos",	OS_SUNOS },
+		{ "unix",	OS_UNIX },
+		{ NULL },
+	}, *p;
+
+	for (p = &oses[0]; p->name; p++) {
+		if (!strcmp(p->name, name)) {
+			arch_os = p->os;
+			return;
+		}
+	}
+
+	die("invalid os: %s", name);
+}
+
 
 void target_config(enum machine mach)
 {
diff --git a/target.h b/target.h
index 8f79426c096a..0a8e2deba306 100644
--- a/target.h
+++ b/target.h
@@ -105,6 +105,7 @@  extern const struct target target_x86_64;
 extern const struct target *arch_target;
 
 enum machine target_parse(const char *name);
+void target_os(const char *name);
 void target_config(enum machine mach);
 void target_init(void);