diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-06-28 16:52:18 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-07-03 16:31:28 +0200 |
commit | 606a0cce749504d6044ed19da76c5f87258f58be (patch) | |
tree | 3ae9f603b490349d2f309db4307965dd259fd1a4 /etc/patches | |
parent | ef234ac53362d848e96e656926ea3d48f06830c7 (diff) | |
download | bootstrappable-toolchain-606a0cce749504d6044ed19da76c5f87258f58be.tar.gz |
stage-0/gcc wrapper: point to a parallel directory
... so that we can install-with-deps the wrapper, in case the bootstrap
compiler has dependencies not present on the host machine.
Diffstat (limited to 'etc/patches')
-rw-r--r-- | etc/patches/wrapper.c | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/etc/patches/wrapper.c b/etc/patches/wrapper.c index ca4f4b1..727bd0c 100644 --- a/etc/patches/wrapper.c +++ b/etc/patches/wrapper.c @@ -6,25 +6,45 @@ int main(int argc, char** argv) { #include "toolname.h" #include "link_args.h" - char *s, *path, *newpath, *prgdir, *cwd, **newargv, *tool; - size_t size, s_s, s_cwd, s_prgdir, s_path, s_toolname; + char *s, *path, *newpath, *prgdir, *cwd, **newargv, *tool, *tmp; + size_t size, s_s, s_cwd, s_prgdir, s_path, s_toolname, s_tmp; int i; for (link_args_c =0; link_args[link_args_c] != NULL; link_args_c++) {} - if ((prgdir=strdup(argv[0])) == NULL) { + if ((tmp=strdup(argv[0])) == NULL) { return 66; } - s = strrchr(prgdir, '/'); + s = strrchr(tmp, '/'); if (s == NULL) { - prgdir = getenv("CC_REAL_DIRECTORY"); - if (prgdir == NULL) { - prgdir = "."; + s = getenv("CC_DIR"); + if (s == NULL) { + s = getenv("CC"); } - } else { + if (s == NULL) { + s = getenv("CXX"); + } + if (s != NULL) { + if ((tmp=strdup(s)) == NULL) { + return 66; + } + s = strrchr(tmp, '/'); + } + } + if (s != NULL) { *s = '\0'; + s_tmp = strlen(tmp); + if ((prgdir=(char*)malloc(s_tmp + 1 + strlen(dir_offset) + 1)) == NULL) { + return 66; + } + strcpy(prgdir, tmp); + strcpy(&prgdir[s_tmp], "/"); + strcpy(&prgdir[s_tmp+1], dir_offset); + } else { + prgdir = dir_offset; /* last resort */ } + cwd = "."; if (*prgdir != '/') { /* called by non-absolute path, need to prefix with cwd */ for (size = 1024;; size *= 2) { @@ -50,7 +70,7 @@ int main(int argc, char** argv) { strcpy(&prgdir[s_cwd+1], s); } - /* prgdir is now our best guess for the directory argv[0] is located in */ + /* prgdir is now our best guess for the directory the real program is located in */ path = getenv("PATH"); if (path == NULL) { path = prgdir; @@ -70,14 +90,6 @@ int main(int argc, char** argv) { if ((newargv=(char**)malloc((argc + link_args_c + 1)*sizeof(char*)))==NULL) { return 66; } - for (i=0; i<argc; i++) { - newargv[i] = argv[i]; - } - for (i=0; i < link_args_c; i++) { - newargv[argc+i] = link_args[i]; - } - newargv[argc+link_args_c] = NULL; - s_prgdir = strlen(prgdir); s_toolname = strlen(toolname); if ((tool=(char*)malloc(s_prgdir+1+s_toolname+1))==NULL) { @@ -87,6 +99,15 @@ int main(int argc, char** argv) { strcpy(&tool[s_prgdir], "/"); strcpy(&tool[s_prgdir+1], toolname); + newargv[0] = tool; + for (i=1; i<argc; i++) { + newargv[i] = argv[i]; + } + for (i=0; i < link_args_c; i++) { + newargv[argc+i] = link_args[i]; + } + newargv[argc+link_args_c] = NULL; + execv(tool, newargv); return 65; /* exec failed */ |