diff options
| author | 2026-03-25 20:28:42 +0100 | |
|---|---|---|
| committer | 2026-03-25 20:28:42 +0100 | |
| commit | 9caddc7b3a2286cb45128c0b7374c92d482df1fa (patch) | |
| tree | d3d7f0ff332d344b886242d6fef3d486dfd5bf05 /src | |
| parent | a0ee3d43a4bd009893b38df7721b1d2692b3c736 (diff) | |
driver: try to autodetect crosscc includs
Diffstat (limited to 'src')
| -rw-r--r-- | src/a_main.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/a_main.c b/src/a_main.c index 62eff8c..1cf9e37 100644 --- a/src/a_main.c +++ b/src/a_main.c @@ -5,6 +5,7 @@ #include <errno.h> #include <stdlib.h> #include <sys/types.h> +#include <sys/stat.h> #include <sys/wait.h> #include <signal.h> #include <unistd.h> @@ -13,6 +14,7 @@ CCOption ccopt; CInclPath *cinclpaths[5]; static CInclPath **cinclpath_tails[5]; +static int nsysinclpaths; static void addinclpath(int ord, const char *path) @@ -27,6 +29,8 @@ addinclpath(int ord, const char *path) cinclpaths[ord] = p; } cinclpath_tails[ord] = &p->next; + if (*path == '/') + ++nsysinclpaths; } /* parse an argument of the form 'opt=abcd' @@ -771,12 +775,29 @@ main(int argc, char **argv) prihelp(); return 1; } + int nincl0 = nsysinclpaths; optparse(argv); /* global init */ if (!targ_init(task.targ, &host_targ) || !target.arch) { fatal(NULL, "unsupported target: %s", task.targ ? task.targ : HOST_TRIPLE); } + if (iscrosscc() && nsysinclpaths == nincl0) { + /* try '/usr/<target>/include' */ + struct stat st; + char path[4096]; + int n = bfmt(&(WriteBuf)MEMBUF(path,sizeof path), "/usr/%s/include/%c", task.targ, 0); + if (n < sizeof path + && stat(path, &st) == 0) { + path[n-2] = '\0'; + addinclpath(CINCL_isystem, alloccopy(&globarena, path, n, 1)); + note(0, NULL, "found cross compiler include path %'s", path); + } else { + warn(NULL, + "defaulting to host include paths while cross compiling for %s might not work", + task.targ); + } + } for (const char *const *p = host_predefs; *p; ++p) predef(0, *p); |