Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 1 | /** |
Arnout Vandecappelle | f6ae243 | 2015-10-04 13:28:41 +0100 | [diff] [blame] | 2 | * Buildroot wrapper for toolchains. This simply executes the real toolchain |
| 3 | * with a number of arguments (sysroot/arch/..) hardcoded, to ensure the |
| 4 | * toolchain uses the correct configuration. |
Arnout Vandecappelle | befb9a3 | 2012-07-15 01:12:05 +0000 | [diff] [blame] | 5 | * The hardcoded path arguments are defined relative to the actual location |
| 6 | * of the binary. |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 7 | * |
| 8 | * (C) 2011 Peter Korsgaard <jacmet@sunsite.dk> |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 9 | * (C) 2011 Daniel Nyström <daniel.nystrom@timeterminal.se> |
Arnout Vandecappelle | befb9a3 | 2012-07-15 01:12:05 +0000 | [diff] [blame] | 10 | * (C) 2012 Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be> |
Spenser Gilliland | aa86b52 | 2013-07-19 18:31:58 -0500 | [diff] [blame] | 11 | * (C) 2013 Spenser Gilliland <spenser@gillilanding.com> |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 12 | * |
| 13 | * This file is licensed under the terms of the GNU General Public License |
| 14 | * version 2. This program is licensed "as is" without any warranty of any |
| 15 | * kind, whether express or implied. |
| 16 | */ |
| 17 | |
Thomas Petazzoni | 5aa205e | 2014-12-10 23:53:46 +0100 | [diff] [blame] | 18 | #define _GNU_SOURCE |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <string.h> |
| 21 | #include <limits.h> |
| 22 | #include <unistd.h> |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 23 | #include <stdlib.h> |
Thomas Petazzoni | 5aa205e | 2014-12-10 23:53:46 +0100 | [diff] [blame] | 24 | #include <errno.h> |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 25 | |
Arnout Vandecappelle | d82f69c | 2015-10-04 16:23:56 +0100 | [diff] [blame] | 26 | #ifdef BR_CCACHE |
| 27 | static char ccache_path[PATH_MAX]; |
| 28 | #endif |
Arnout Vandecappelle | befb9a3 | 2012-07-15 01:12:05 +0000 | [diff] [blame] | 29 | static char path[PATH_MAX]; |
| 30 | static char sysroot[PATH_MAX]; |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 31 | |
Spenser Gilliland | aa86b52 | 2013-07-19 18:31:58 -0500 | [diff] [blame] | 32 | /** |
| 33 | * GCC errors out with certain combinations of arguments (examples are |
Baruch Siach | 5c76842 | 2014-04-10 08:46:25 +0300 | [diff] [blame] | 34 | * -mfloat-abi={hard|soft} and -m{little|big}-endian), so we have to ensure |
Spenser Gilliland | aa86b52 | 2013-07-19 18:31:58 -0500 | [diff] [blame] | 35 | * that we only pass the predefined one to the real compiler if the inverse |
| 36 | * option isn't in the argument list. |
| 37 | * This specifies the worst case number of extra arguments we might pass |
Yann E. MORIN | 2c1dc32 | 2014-01-07 23:46:05 +0100 | [diff] [blame] | 38 | * Currently, we have: |
| 39 | * -mfloat-abi= |
| 40 | * -march= |
Yann E. MORIN | 2c1dc32 | 2014-01-07 23:46:05 +0100 | [diff] [blame] | 41 | * -mcpu= |
Spenser Gilliland | aa86b52 | 2013-07-19 18:31:58 -0500 | [diff] [blame] | 42 | */ |
Yann E. MORIN | 1c8c0d9 | 2017-02-20 18:16:31 +0100 | [diff] [blame^] | 43 | #define EXCLUSIVE_ARGS 3 |
Spenser Gilliland | aa86b52 | 2013-07-19 18:31:58 -0500 | [diff] [blame] | 44 | |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 45 | static char *predef_args[] = { |
Arnout Vandecappelle | d82f69c | 2015-10-04 16:23:56 +0100 | [diff] [blame] | 46 | #ifdef BR_CCACHE |
| 47 | ccache_path, |
| 48 | #endif |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 49 | path, |
Arnout Vandecappelle | befb9a3 | 2012-07-15 01:12:05 +0000 | [diff] [blame] | 50 | "--sysroot", sysroot, |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 51 | #ifdef BR_ABI |
| 52 | "-mabi=" BR_ABI, |
| 53 | #endif |
Spenser Gilliland | 27c9370 | 2013-07-19 18:31:57 -0500 | [diff] [blame] | 54 | #ifdef BR_FPU |
Thomas Petazzoni | d774551 | 2013-07-16 10:03:12 +0200 | [diff] [blame] | 55 | "-mfpu=" BR_FPU, |
| 56 | #endif |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 57 | #ifdef BR_SOFTFLOAT |
| 58 | "-msoft-float", |
| 59 | #endif /* BR_SOFTFLOAT */ |
Thomas Petazzoni | 85d0769 | 2013-07-16 10:03:22 +0200 | [diff] [blame] | 60 | #ifdef BR_MODE |
| 61 | "-m" BR_MODE, |
| 62 | #endif |
Arnout Vandecappelle (Essensium/Mind) | a22dc0f | 2012-03-13 23:30:00 +0100 | [diff] [blame] | 63 | #ifdef BR_64 |
| 64 | "-m64", |
| 65 | #endif |
Ray Kinsella | 968f5d5 | 2015-10-19 11:02:52 +0000 | [diff] [blame] | 66 | #ifdef BR_OMIT_LOCK_PREFIX |
| 67 | "-Wa,-momit-lock-prefix=yes", |
| 68 | #endif |
Vicente Olivert Riera | 240564a | 2016-11-09 16:16:57 +0000 | [diff] [blame] | 69 | #ifdef BR_NO_FUSED_MADD |
| 70 | "-mno-fused-madd", |
| 71 | #endif |
Sonic Zhang | 5713382 | 2013-05-03 00:39:34 +0000 | [diff] [blame] | 72 | #ifdef BR_BINFMT_FLAT |
| 73 | "-Wl,-elf2flt", |
| 74 | #endif |
Markos Chandras | f3a2b80 | 2013-10-14 10:52:25 +0100 | [diff] [blame] | 75 | #ifdef BR_MIPS_TARGET_LITTLE_ENDIAN |
| 76 | "-EL", |
| 77 | #endif |
Alexey Brodkin | 2b93fe5 | 2015-03-10 14:50:24 +0300 | [diff] [blame] | 78 | #if defined(BR_MIPS_TARGET_BIG_ENDIAN) || defined(BR_ARC_TARGET_BIG_ENDIAN) |
Markos Chandras | f3a2b80 | 2013-10-14 10:52:25 +0100 | [diff] [blame] | 79 | "-EB", |
| 80 | #endif |
Thomas Petazzoni | b95e436 | 2011-12-31 12:09:33 +0100 | [diff] [blame] | 81 | #ifdef BR_ADDITIONAL_CFLAGS |
| 82 | BR_ADDITIONAL_CFLAGS |
| 83 | #endif |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 84 | }; |
| 85 | |
Yann E. MORIN | 31c093e | 2016-12-04 10:21:55 +0100 | [diff] [blame] | 86 | /* A {string,length} tuple, to avoid computing strlen() on constants. |
| 87 | * - str must be a \0-terminated string |
| 88 | * - len does not account for the terminating '\0' |
| 89 | */ |
| 90 | struct str_len_s { |
| 91 | const char *str; |
Yann E. MORIN | 61cb120 | 2016-08-29 17:53:59 +0200 | [diff] [blame] | 92 | size_t len; |
| 93 | }; |
| 94 | |
Yann E. MORIN | 31c093e | 2016-12-04 10:21:55 +0100 | [diff] [blame] | 95 | /* Define a {string,length} tuple. Takes an unquoted constant string as |
| 96 | * parameter. sizeof() on a string literal includes the terminating \0, |
| 97 | * but we don't want to count it. |
| 98 | */ |
| 99 | #define STR_LEN(s) { #s, sizeof(#s)-1 } |
| 100 | |
Yann E. MORIN | 3eccf76 | 2016-12-04 10:21:56 +0100 | [diff] [blame] | 101 | /* List of paths considered unsafe for cross-compilation. |
| 102 | * |
| 103 | * An unsafe path is one that points to a directory with libraries or |
| 104 | * headers for the build machine, which are not suitable for the target. |
| 105 | */ |
| 106 | static const struct str_len_s unsafe_paths[] = { |
| 107 | STR_LEN(/lib), |
| 108 | STR_LEN(/usr/include), |
| 109 | STR_LEN(/usr/lib), |
| 110 | STR_LEN(/usr/local/include), |
| 111 | STR_LEN(/usr/local/lib), |
| 112 | { NULL, 0 }, |
| 113 | }; |
| 114 | |
Yann E. MORIN | 61cb120 | 2016-08-29 17:53:59 +0200 | [diff] [blame] | 115 | /* Unsafe options are options that specify a potentialy unsafe path, |
| 116 | * that will be checked by check_unsafe_path(), below. |
Yann E. MORIN | 61cb120 | 2016-08-29 17:53:59 +0200 | [diff] [blame] | 117 | */ |
Yann E. MORIN | 31c093e | 2016-12-04 10:21:55 +0100 | [diff] [blame] | 118 | static const struct str_len_s unsafe_opts[] = { |
| 119 | STR_LEN(-I), |
| 120 | STR_LEN(-idirafter), |
| 121 | STR_LEN(-iquote), |
| 122 | STR_LEN(-isystem), |
| 123 | STR_LEN(-L), |
Yann E. MORIN | 61cb120 | 2016-08-29 17:53:59 +0200 | [diff] [blame] | 124 | { NULL, 0 }, |
| 125 | }; |
| 126 | |
Yann E. MORIN | 105a8c1 | 2016-08-29 17:53:58 +0200 | [diff] [blame] | 127 | /* Check if path is unsafe for cross-compilation. Unsafe paths are those |
| 128 | * pointing to the standard native include or library paths. |
| 129 | * |
| 130 | * We print the arguments leading to the failure. For some options, gcc |
| 131 | * accepts the path to be concatenated to the argument (e.g. -I/foo/bar) |
| 132 | * or separated (e.g. -I /foo/bar). In the first case, we need only print |
| 133 | * the argument as it already contains the path (arg_has_path), while in |
| 134 | * the second case we need to print both (!arg_has_path). |
| 135 | * |
| 136 | * If paranoid, exit in error instead of just printing a warning. |
| 137 | */ |
| 138 | static void check_unsafe_path(const char *arg, |
| 139 | const char *path, |
| 140 | int paranoid, |
| 141 | int arg_has_path) |
Thomas Petazzoni | 5aa205e | 2014-12-10 23:53:46 +0100 | [diff] [blame] | 142 | { |
Yann E. MORIN | 3eccf76 | 2016-12-04 10:21:56 +0100 | [diff] [blame] | 143 | const struct str_len_s *p; |
Thomas Petazzoni | 5aa205e | 2014-12-10 23:53:46 +0100 | [diff] [blame] | 144 | |
Yann E. MORIN | 3eccf76 | 2016-12-04 10:21:56 +0100 | [diff] [blame] | 145 | for (p=unsafe_paths; p->str; p++) { |
| 146 | if (strncmp(path, p->str, p->len)) |
Thomas Petazzoni | 5aa205e | 2014-12-10 23:53:46 +0100 | [diff] [blame] | 147 | continue; |
Yann E. MORIN | 105a8c1 | 2016-08-29 17:53:58 +0200 | [diff] [blame] | 148 | fprintf(stderr, |
| 149 | "%s: %s: unsafe header/library path used in cross-compilation: '%s%s%s'\n", |
| 150 | program_invocation_short_name, |
| 151 | paranoid ? "ERROR" : "WARNING", |
| 152 | arg, |
| 153 | arg_has_path ? "" : "' '", /* close single-quote, space, open single-quote */ |
| 154 | arg_has_path ? "" : path); /* so that arg and path are properly quoted. */ |
| 155 | if (paranoid) |
| 156 | exit(1); |
Thomas Petazzoni | 5aa205e | 2014-12-10 23:53:46 +0100 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 160 | int main(int argc, char **argv) |
| 161 | { |
Arnout Vandecappelle | 792f127 | 2015-10-04 13:28:56 +0100 | [diff] [blame] | 162 | char **args, **cur, **exec_args; |
Arnout Vandecappelle | befb9a3 | 2012-07-15 01:12:05 +0000 | [diff] [blame] | 163 | char *relbasedir, *absbasedir; |
| 164 | char *progpath = argv[0]; |
| 165 | char *basename; |
Yann E. MORIN | 60cb290 | 2013-09-21 00:00:30 +0200 | [diff] [blame] | 166 | char *env_debug; |
Thomas Petazzoni | 5aa205e | 2014-12-10 23:53:46 +0100 | [diff] [blame] | 167 | char *paranoid_wrapper; |
| 168 | int paranoid; |
Yann E. MORIN | 60cb290 | 2013-09-21 00:00:30 +0200 | [diff] [blame] | 169 | int ret, i, count = 0, debug; |
Arnout Vandecappelle | befb9a3 | 2012-07-15 01:12:05 +0000 | [diff] [blame] | 170 | |
| 171 | /* Calculate the relative paths */ |
| 172 | basename = strrchr(progpath, '/'); |
| 173 | if (basename) { |
| 174 | *basename = '\0'; |
| 175 | basename++; |
| 176 | relbasedir = malloc(strlen(progpath) + 7); |
| 177 | if (relbasedir == NULL) { |
| 178 | perror(__FILE__ ": malloc"); |
| 179 | return 2; |
| 180 | } |
| 181 | sprintf(relbasedir, "%s/../..", argv[0]); |
| 182 | absbasedir = realpath(relbasedir, NULL); |
| 183 | } else { |
| 184 | basename = progpath; |
Patrick Ziegler | 74ae7af | 2013-05-28 23:41:19 +0000 | [diff] [blame] | 185 | absbasedir = malloc(PATH_MAX + 1); |
| 186 | ret = readlink("/proc/self/exe", absbasedir, PATH_MAX); |
| 187 | if (ret < 0) { |
| 188 | perror(__FILE__ ": readlink"); |
| 189 | return 2; |
| 190 | } |
| 191 | absbasedir[ret] = '\0'; |
| 192 | for (i = ret; i > 0; i--) { |
| 193 | if (absbasedir[i] == '/') { |
| 194 | absbasedir[i] = '\0'; |
| 195 | if (++count == 3) |
| 196 | break; |
| 197 | } |
| 198 | } |
Arnout Vandecappelle | befb9a3 | 2012-07-15 01:12:05 +0000 | [diff] [blame] | 199 | } |
| 200 | if (absbasedir == NULL) { |
| 201 | perror(__FILE__ ": realpath"); |
| 202 | return 2; |
| 203 | } |
| 204 | |
| 205 | /* Fill in the relative paths */ |
| 206 | #ifdef BR_CROSS_PATH_REL |
Arnout Vandecappelle | 5ce73dc | 2015-10-14 23:05:55 +0200 | [diff] [blame] | 207 | ret = snprintf(path, sizeof(path), "%s/" BR_CROSS_PATH_REL "/%s" BR_CROSS_PATH_SUFFIX, absbasedir, basename); |
Peter Korsgaard | ccdb179 | 2015-10-05 08:25:17 +0200 | [diff] [blame] | 208 | #elif defined(BR_CROSS_PATH_ABS) |
Arnout Vandecappelle | 5ce73dc | 2015-10-14 23:05:55 +0200 | [diff] [blame] | 209 | ret = snprintf(path, sizeof(path), BR_CROSS_PATH_ABS "/%s" BR_CROSS_PATH_SUFFIX, basename); |
| 210 | #else |
Arnout Vandecappelle | 919c06c | 2015-10-04 13:28:42 +0100 | [diff] [blame] | 211 | ret = snprintf(path, sizeof(path), "%s/usr/bin/%s" BR_CROSS_PATH_SUFFIX, absbasedir, basename); |
Arnout Vandecappelle | befb9a3 | 2012-07-15 01:12:05 +0000 | [diff] [blame] | 212 | #endif |
| 213 | if (ret >= sizeof(path)) { |
| 214 | perror(__FILE__ ": overflow"); |
| 215 | return 3; |
| 216 | } |
Arnout Vandecappelle | d82f69c | 2015-10-04 16:23:56 +0100 | [diff] [blame] | 217 | #ifdef BR_CCACHE |
| 218 | ret = snprintf(ccache_path, sizeof(ccache_path), "%s/usr/bin/ccache", absbasedir); |
| 219 | if (ret >= sizeof(ccache_path)) { |
| 220 | perror(__FILE__ ": overflow"); |
| 221 | return 3; |
| 222 | } |
| 223 | #endif |
Arnout Vandecappelle | befb9a3 | 2012-07-15 01:12:05 +0000 | [diff] [blame] | 224 | ret = snprintf(sysroot, sizeof(sysroot), "%s/" BR_SYSROOT, absbasedir); |
| 225 | if (ret >= sizeof(sysroot)) { |
| 226 | perror(__FILE__ ": overflow"); |
| 227 | return 3; |
| 228 | } |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 229 | |
Spenser Gilliland | aa86b52 | 2013-07-19 18:31:58 -0500 | [diff] [blame] | 230 | cur = args = malloc(sizeof(predef_args) + |
| 231 | (sizeof(char *) * (argc + EXCLUSIVE_ARGS))); |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 232 | if (args == NULL) { |
| 233 | perror(__FILE__ ": malloc"); |
| 234 | return 2; |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 235 | } |
| 236 | |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 237 | /* start with predefined args */ |
| 238 | memcpy(cur, predef_args, sizeof(predef_args)); |
| 239 | cur += sizeof(predef_args) / sizeof(predef_args[0]); |
| 240 | |
Spenser Gilliland | aa86b52 | 2013-07-19 18:31:58 -0500 | [diff] [blame] | 241 | #ifdef BR_FLOAT_ABI |
| 242 | /* add float abi if not overridden in args */ |
| 243 | for (i = 1; i < argc; i++) { |
| 244 | if (!strncmp(argv[i], "-mfloat-abi=", strlen("-mfloat-abi=")) || |
| 245 | !strcmp(argv[i], "-msoft-float") || |
| 246 | !strcmp(argv[i], "-mhard-float")) |
| 247 | break; |
| 248 | } |
| 249 | |
| 250 | if (i == argc) |
| 251 | *cur++ = "-mfloat-abi=" BR_FLOAT_ABI; |
| 252 | #endif |
| 253 | |
Yann E. MORIN | 2c1dc32 | 2014-01-07 23:46:05 +0100 | [diff] [blame] | 254 | #if defined(BR_ARCH) || \ |
Yann E. MORIN | 2c1dc32 | 2014-01-07 23:46:05 +0100 | [diff] [blame] | 255 | defined(BR_CPU) |
Thomas De Schampheleire | b62cb78 | 2015-07-26 12:53:07 +0200 | [diff] [blame] | 256 | /* Add our -march/cpu flags, but only if none of |
| 257 | * -march/mtune/mcpu are already specified on the commandline |
Yann E. MORIN | 2c1dc32 | 2014-01-07 23:46:05 +0100 | [diff] [blame] | 258 | */ |
| 259 | for (i = 1; i < argc; i++) { |
| 260 | if (!strncmp(argv[i], "-march=", strlen("-march=")) || |
Thomas De Schampheleire | b62cb78 | 2015-07-26 12:53:07 +0200 | [diff] [blame] | 261 | !strncmp(argv[i], "-mtune=", strlen("-mtune=")) || |
Yann E. MORIN | 2c1dc32 | 2014-01-07 23:46:05 +0100 | [diff] [blame] | 262 | !strncmp(argv[i], "-mcpu=", strlen("-mcpu=" ))) |
| 263 | break; |
| 264 | } |
| 265 | if (i == argc) { |
| 266 | #ifdef BR_ARCH |
| 267 | *cur++ = "-march=" BR_ARCH; |
| 268 | #endif |
Yann E. MORIN | 2c1dc32 | 2014-01-07 23:46:05 +0100 | [diff] [blame] | 269 | #ifdef BR_CPU |
| 270 | *cur++ = "-mcpu=" BR_CPU; |
| 271 | #endif |
| 272 | } |
Thomas Petazzoni | 5715d2d | 2014-10-21 22:27:16 +0200 | [diff] [blame] | 273 | #endif /* ARCH || CPU */ |
Yann E. MORIN | 2c1dc32 | 2014-01-07 23:46:05 +0100 | [diff] [blame] | 274 | |
Thomas Petazzoni | 5aa205e | 2014-12-10 23:53:46 +0100 | [diff] [blame] | 275 | paranoid_wrapper = getenv("BR_COMPILER_PARANOID_UNSAFE_PATH"); |
| 276 | if (paranoid_wrapper && strlen(paranoid_wrapper) > 0) |
| 277 | paranoid = 1; |
| 278 | else |
| 279 | paranoid = 0; |
| 280 | |
| 281 | /* Check for unsafe library and header paths */ |
| 282 | for (i = 1; i < argc; i++) { |
Yann E. MORIN | 31c093e | 2016-12-04 10:21:55 +0100 | [diff] [blame] | 283 | const struct str_len_s *opt; |
| 284 | for (opt=unsafe_opts; opt->str; opt++ ) { |
Yann E. MORIN | 61cb120 | 2016-08-29 17:53:59 +0200 | [diff] [blame] | 285 | /* Skip any non-unsafe option. */ |
Yann E. MORIN | 31c093e | 2016-12-04 10:21:55 +0100 | [diff] [blame] | 286 | if (strncmp(argv[i], opt->str, opt->len)) |
Thomas Petazzoni | 5aa205e | 2014-12-10 23:53:46 +0100 | [diff] [blame] | 287 | continue; |
Yann E. MORIN | 61cb120 | 2016-08-29 17:53:59 +0200 | [diff] [blame] | 288 | |
| 289 | /* Handle both cases: |
| 290 | * - path is a separate argument, |
| 291 | * - path is concatenated with option. |
| 292 | */ |
| 293 | if (argv[i][opt->len] == '\0') { |
| 294 | i++; |
| 295 | if (i == argc) |
| 296 | break; |
| 297 | check_unsafe_path(argv[i-1], argv[i], paranoid, 0); |
| 298 | } else |
| 299 | check_unsafe_path(argv[i], argv[i] + opt->len, paranoid, 1); |
Thomas Petazzoni | 5aa205e | 2014-12-10 23:53:46 +0100 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 303 | /* append forward args */ |
| 304 | memcpy(cur, &argv[1], sizeof(char *) * (argc - 1)); |
| 305 | cur += argc - 1; |
| 306 | |
| 307 | /* finish with NULL termination */ |
| 308 | *cur = NULL; |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 309 | |
Arnout Vandecappelle | 792f127 | 2015-10-04 13:28:56 +0100 | [diff] [blame] | 310 | exec_args = args; |
| 311 | #ifdef BR_CCACHE |
| 312 | if (getenv("BR_NO_CCACHE")) |
| 313 | /* Skip the ccache call */ |
| 314 | exec_args++; |
| 315 | #endif |
| 316 | |
Yann E. MORIN | 60cb290 | 2013-09-21 00:00:30 +0200 | [diff] [blame] | 317 | /* Debug the wrapper to see actual arguments passed to |
| 318 | * the compiler: |
| 319 | * unset, empty, or 0: do not trace |
| 320 | * set to 1 : trace all arguments on a single line |
| 321 | * set to 2 : trace one argument per line |
| 322 | */ |
Yann E. MORIN | 35c666e | 2014-03-03 23:55:05 +0100 | [diff] [blame] | 323 | if ((env_debug = getenv("BR2_DEBUG_WRAPPER"))) { |
Yann E. MORIN | 60cb290 | 2013-09-21 00:00:30 +0200 | [diff] [blame] | 324 | debug = atoi(env_debug); |
| 325 | if (debug > 0) { |
| 326 | fprintf(stderr, "Toolchain wrapper executing:"); |
Arnout Vandecappelle | f4682cf | 2015-10-04 16:25:00 +0100 | [diff] [blame] | 327 | #ifdef BR_CCACHE_HASH |
| 328 | fprintf(stderr, "%sCCACHE_COMPILERCHECK='string:" BR_CCACHE_HASH "'", |
| 329 | (debug == 2) ? "\n " : " "); |
| 330 | #endif |
Arnout Vandecappelle | 1e97b27 | 2015-10-04 16:25:32 +0100 | [diff] [blame] | 331 | #ifdef BR_CCACHE_BASEDIR |
| 332 | fprintf(stderr, "%sCCACHE_BASEDIR='" BR_CCACHE_BASEDIR "'", |
| 333 | (debug == 2) ? "\n " : " "); |
| 334 | #endif |
Arnout Vandecappelle | 792f127 | 2015-10-04 13:28:56 +0100 | [diff] [blame] | 335 | for (i = 0; exec_args[i]; i++) |
Yann E. MORIN | 60cb290 | 2013-09-21 00:00:30 +0200 | [diff] [blame] | 336 | fprintf(stderr, "%s'%s'", |
Arnout Vandecappelle | 792f127 | 2015-10-04 13:28:56 +0100 | [diff] [blame] | 337 | (debug == 2) ? "\n " : " ", exec_args[i]); |
Yann E. MORIN | 60cb290 | 2013-09-21 00:00:30 +0200 | [diff] [blame] | 338 | fprintf(stderr, "\n"); |
| 339 | } |
Yann E. MORIN | aaa06aa | 2013-07-18 23:54:50 +0200 | [diff] [blame] | 340 | } |
| 341 | |
Arnout Vandecappelle | f4682cf | 2015-10-04 16:25:00 +0100 | [diff] [blame] | 342 | #ifdef BR_CCACHE_HASH |
| 343 | /* Allow compilercheck to be overridden through the environment */ |
| 344 | if (setenv("CCACHE_COMPILERCHECK", "string:" BR_CCACHE_HASH, 0)) { |
| 345 | perror(__FILE__ ": Failed to set CCACHE_COMPILERCHECK"); |
| 346 | return 3; |
| 347 | } |
| 348 | #endif |
Arnout Vandecappelle | 1e97b27 | 2015-10-04 16:25:32 +0100 | [diff] [blame] | 349 | #ifdef BR_CCACHE_BASEDIR |
| 350 | /* Allow compilercheck to be overridden through the environment */ |
| 351 | if (setenv("CCACHE_BASEDIR", BR_CCACHE_BASEDIR, 0)) { |
| 352 | perror(__FILE__ ": Failed to set CCACHE_BASEDIR"); |
| 353 | return 3; |
| 354 | } |
| 355 | #endif |
Arnout Vandecappelle | f4682cf | 2015-10-04 16:25:00 +0100 | [diff] [blame] | 356 | |
Arnout Vandecappelle | 792f127 | 2015-10-04 13:28:56 +0100 | [diff] [blame] | 357 | if (execv(exec_args[0], exec_args)) |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 358 | perror(path); |
| 359 | |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 360 | free(args); |
| 361 | |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 362 | return 2; |
| 363 | } |