From 93194ef8447718ae78b345ce0a920bb5e6fdc090 Mon Sep 17 00:00:00 2001 From: lemon Date: Thu, 1 Jan 2026 12:00:33 +0100 Subject: Use a configure script, query system toolchain for default include paths --- main.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'main.c') 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 #include @@ -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(); } -- cgit v1.2.3