From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 2/9] arch: add an option to specify the OS: --os=$OS
Date: Thu, 9 Jul 2020 01:41:44 +0200 [thread overview]
Message-ID: <20200708234151.57845-3-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20200708234151.57845-1-luc.vanoostenryck@gmail.com>
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 --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);
--
2.27.0
next prev parent reply other threads:[~2020-07-08 23:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-08 23:41 [PATCH 0/9] OS-specific small fixes & cleanup Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 1/9] x86: reorg the target file Luc Van Oostenryck
2020-07-08 23:41 ` Luc Van Oostenryck [this message]
2020-07-08 23:41 ` [PATCH 3/9] predefine: add __linux__ & __linux Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 4/9] predefine: no __unix__ for Darwin Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 5/9] x86: fixes types for NetBSD & OpenBSD Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 6/9] sparc: char are unsigned on Solaris Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 7/9] arch: add predefines for OS identification Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 8/9] cygwin: add the predefines '__cdecl', Luc Van Oostenryck
2020-07-08 23:41 ` [PATCH 9/9] cgcc: remove now unneeded options & defines Luc Van Oostenryck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200708234151.57845-3-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).