aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-06-28 14:27:45 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-07-13 17:49:51 +0200
commit7fffea101f878d7040fec4347d52544f6994b042 (patch)
treec247f970ddb27e39d595461cba3ff68a1c807fac
parenta52ccc23e3c97e752cfabe7edebe05331b0d94e4 (diff)
downloadsparse-7fffea101f878d7040fec4347d52544f6994b042.tar.gz
arch: add an option to specify the OS: --os=$OS
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>
-rw-r--r--machine.h1
-rw-r--r--options.c11
-rw-r--r--sparse.110
-rw-r--r--target.c29
-rw-r--r--target.h1
5 files changed, 52 insertions, 0 deletions
diff --git a/machine.h b/machine.h
index 7407e716..cc02818c 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 9f05bdf9..530d15ad 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 d916ad9e..19c8c4e3 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, otherwise some generic settings are used.
+.
.SH DEBUG OPTIONS
.TP
.B \-fmem-report
diff --git a/target.c b/target.c
index 6776c3a1..8de1b1f3 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 8f79426c..0a8e2deb 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);