commit 8273c5fa450aabafdfac1f775561620459232459
parent 1b2acd131d2a7fb8eff689946d9c0dbc6b201f58
Author: xplshn <anto@xplshn.com.ar>
Date: Tue, 24 Nov 2026 14:33:37 -0300
cpp: system macros from ospredef files
Diffstat:
8 files changed, 60 insertions(+), 18 deletions(-)
diff --git a/cmd/dev/cc/cc.h b/cmd/dev/cc/cc.h
@@ -396,6 +396,9 @@ extern const struct target *targ;
void targinit(const char *);
+/* the macros that name the system, from the ospredef file tagged for it */
+extern const char ospredef[];
+
/* attr */
enum attrkind {
diff --git a/cmd/dev/cc/cpp.c b/cmd/dev/cc/cpp.c
@@ -65,24 +65,7 @@ main(int argc, char *argv[])
p += sprintf(p, "#define __riscv 1\n");
#endif
-#if defined(__linux__)
- p += sprintf(p, "#define __linux__ 1\n");
- p += sprintf(p, "#define __unix__ 1\n");
-#elif defined(__FreeBSD__)
- p += sprintf(p, "#define __FreeBSD__ 1\n");
- p += sprintf(p, "#define __unix__ 1\n");
-#elif defined(__NetBSD__)
- p += sprintf(p, "#define __NetBSD__ 1\n");
- p += sprintf(p, "#define __unix__ 1\n");
-#elif defined(__OpenBSD__)
- p += sprintf(p, "#define __OpenBSD__ 1\n");
- p += sprintf(p, "#define __unix__ 1\n");
-#elif defined(__APPLE__)
- p += sprintf(p, "#define __APPLE__ 1\n");
- p += sprintf(p, "#define __unix__ 1\n");
-#elif defined(__unix__)
- p += sprintf(p, "#define __unix__ 1\n");
-#endif
+ p += sprintf(p, "%s", ospredef);
predefs_len = p - predefs;
cmdline_cap = predefs_len + 2048;
diff --git a/cmd/dev/cc/ospredef_darwin.c b/cmd/dev/cc/ospredef_darwin.c
@@ -0,0 +1,9 @@
+/* see license file for copyright and license details */
+#include <stdbool.h>
+#include "util.h"
+#include "cc.h"
+
+#if defined(__APPLE__) && !defined(ARUU_FORCE_OTHER)
+const char ospredef[] = "#define __APPLE__ 1\n"
+ "#define __unix__ 1\n";
+#endif
diff --git a/cmd/dev/cc/ospredef_freebsd.c b/cmd/dev/cc/ospredef_freebsd.c
@@ -0,0 +1,9 @@
+/* see license file for copyright and license details */
+#include <stdbool.h>
+#include "util.h"
+#include "cc.h"
+
+#if defined(__FreeBSD__) && !defined(ARUU_FORCE_OTHER)
+const char ospredef[] = "#define __FreeBSD__ 1\n"
+ "#define __unix__ 1\n";
+#endif
diff --git a/cmd/dev/cc/ospredef_linux.c b/cmd/dev/cc/ospredef_linux.c
@@ -0,0 +1,9 @@
+/* see license file for copyright and license details */
+#include <stdbool.h>
+#include "util.h"
+#include "cc.h"
+
+#if defined(__linux__) && !defined(ARUU_FORCE_OTHER)
+const char ospredef[] = "#define __linux__ 1\n"
+ "#define __unix__ 1\n";
+#endif
diff --git a/cmd/dev/cc/ospredef_netbsd.c b/cmd/dev/cc/ospredef_netbsd.c
@@ -0,0 +1,9 @@
+/* see license file for copyright and license details */
+#include <stdbool.h>
+#include "util.h"
+#include "cc.h"
+
+#if defined(__NetBSD__) && !defined(ARUU_FORCE_OTHER)
+const char ospredef[] = "#define __NetBSD__ 1\n"
+ "#define __unix__ 1\n";
+#endif
diff --git a/cmd/dev/cc/ospredef_openbsd.c b/cmd/dev/cc/ospredef_openbsd.c
@@ -0,0 +1,9 @@
+/* see license file for copyright and license details */
+#include <stdbool.h>
+#include "util.h"
+#include "cc.h"
+
+#if defined(__OpenBSD__) && !defined(ARUU_FORCE_OTHER)
+const char ospredef[] = "#define __OpenBSD__ 1\n"
+ "#define __unix__ 1\n";
+#endif
diff --git a/cmd/dev/cc/ospredef_other.c b/cmd/dev/cc/ospredef_other.c
@@ -0,0 +1,11 @@
+/* see license file for copyright and license details */
+#include <stdbool.h>
+#include "util.h"
+#include "cc.h"
+
+/* a system with no file of its own is taken for some unix */
+#if !(defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \
+ || defined(__APPLE__)) \
+ || defined(ARUU_FORCE_OTHER)
+const char ospredef[] = "#define __unix__ 1\n";
+#endif