From 606a0cce749504d6044ed19da76c5f87258f58be Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Fri, 28 Jun 2024 16:52:18 +0200 Subject: 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. --- etc/patches/wrapper.c | 55 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'etc/patches') 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