aboutsummaryrefslogtreecommitdiffhomepage
path: root/main.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2026-01-01 12:00:33 +0100
committerlemon <lsof@mailbox.org>2026-01-01 12:01:45 +0100
commit93194ef8447718ae78b345ce0a920bb5e6fdc090 (patch)
tree34551543dffff4b53e66ffb94839cddc70810568 /main.c
parentd7203ea5f46fef1b41ba3b32c0b9313df3b3740c (diff)
Use a configure script, query system toolchain for default include paths
Diffstat (limited to 'main.c')
-rw-r--r--main.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/main.c b/main.c
index eacef15..a821baa 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,5 @@
#include "common.h"
-#include "hostconfig.h"
+#include "hostconfig.h" /* run ./configure */
#include "obj/obj.h"
#include <errno.h>
#include <stdlib.h>
@@ -128,6 +128,9 @@ optparse(char **args)
if (!strcmp(arg, "help") || !strcmp(arg, "h") || !strcmp(arg, "-help")) {
prihelp();
exit(0);
+ } else if (!strcmp(arg, "dumpmachine")) {
+ pfmt("%s\n", HOST_TRIPLE);
+ exit(0);
} else if ((x = optval(arg, "std"))) {
if (!strcmp(x, "c89") || !strcmp(x, "c90")) ccopt.cstd = STDC89;
else if (!strcmp(x, "c99")) ccopt.cstd = STDC99;
@@ -367,12 +370,19 @@ hasprog(const char *prog)
return WEXITSTATUS(wstat) < 125;
}
+static bool
+iscrosscc(void)
+{
+ return target.os != HOST_OS || target.arch != HOST_ARCH || target.abi != HOST_ABI;
+}
+
struct cmdargs { vec_of(const char *); };
static void
findlinkcmd(struct cmdargs *cmd)
{
- if (task.targ && (target.os != HOST_OS || target.arch != HOST_ARCH || target.abi != HOST_ABI)) {
+ if (task.targ && iscrosscc()) {
+ /* try to find a cross compiling toolchain, e.g. aarch64-linux-gnu-gcc */
static const char *ccs[] = {"cc", "gcc", "clang"};
char cross[1024];
for (int i = 0; i < countof(ccs); ++i) {
@@ -385,6 +395,7 @@ findlinkcmd(struct cmdargs *cmd)
return;
}
}
+ /* zig cc fallback, which works great as cross compiler toolchain */
if (hasprog("zig")) {
vpush(cmd, "zig");
vpush(cmd, "cc");
@@ -394,7 +405,7 @@ findlinkcmd(struct cmdargs *cmd)
fatal(NULL, "cannot link to cross-compilation target: no appropiate toolchain installed");
}
} else {
- vpush(cmd, "cc");
+ vpush(cmd, HOST_CC);
}
}
@@ -489,7 +500,7 @@ driver(void)
{
void cpp(struct wbuf *, const char *);
if (task.verbose)
- efmt("# Target: %s\n", task.targ ? task.targ : "(host)");
+ efmt("# Target: %s\n", task.targ ? task.targ : HOST_TRIPLE);
if (task.syntaxonly)
task.out = "/dev/null"; // HACK
if (task.outft == OFTobj) {
@@ -627,7 +638,7 @@ main(int argc, char **argv)
/* global init */
targ_init(task.targ);
if (!target.arch)
- fatal(NULL, "unsupported target: %s", task.targ ? task.targ : "(host)");
+ fatal(NULL, "unsupported target: %s", task.targ ? task.targ : HOST_TRIPLE);
return driver();
}