Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Buildroot wrapper for external toolchains. This simply executes the real |
| 3 | * toolchain with a number of arguments (sysroot/arch/..) hardcoded, |
| 4 | * to ensure the external toolchain uses the correct configuration. |
| 5 | * |
| 6 | * (C) 2011 Peter Korsgaard <jacmet@sunsite.dk> |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 7 | * (C) 2011 Daniel Nyström <daniel.nystrom@timeterminal.se> |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 8 | * |
| 9 | * This file is licensed under the terms of the GNU General Public License |
| 10 | * version 2. This program is licensed "as is" without any warranty of any |
| 11 | * kind, whether express or implied. |
| 12 | */ |
| 13 | |
| 14 | #include <stdio.h> |
| 15 | #include <string.h> |
| 16 | #include <limits.h> |
| 17 | #include <unistd.h> |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 18 | #include <stdlib.h> |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 19 | |
| 20 | static char path[PATH_MAX] = BR_CROSS_PATH; |
| 21 | |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 22 | static char *predef_args[] = { |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 23 | path, |
| 24 | "--sysroot", BR_SYSROOT, |
| 25 | #ifdef BR_ARCH |
| 26 | "-march=" BR_ARCH, |
| 27 | #endif /* BR_ARCH */ |
| 28 | #ifdef BR_TUNE |
| 29 | "-mtune=" BR_TUNE, |
| 30 | #endif /* BR_TUNE */ |
Stany MARCEL | 3fb6010 | 2011-11-01 13:19:16 +0100 | [diff] [blame^] | 31 | #ifdef BR_CPU |
| 32 | "-mcpu=" BR_CPU, |
| 33 | #endif |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 34 | #ifdef BR_ABI |
| 35 | "-mabi=" BR_ABI, |
| 36 | #endif |
| 37 | #ifdef BR_SOFTFLOAT |
| 38 | "-msoft-float", |
| 39 | #endif /* BR_SOFTFLOAT */ |
| 40 | #ifdef BR_VFPFLOAT |
| 41 | "-mfpu=vfp", |
| 42 | #endif /* BR_VFPFLOAT */ |
| 43 | }; |
| 44 | |
| 45 | static const char *get_basename(const char *name) |
| 46 | { |
| 47 | const char *base; |
| 48 | |
| 49 | base = strrchr(name, '/'); |
| 50 | if (base) |
| 51 | base++; |
| 52 | else |
| 53 | base = name; |
| 54 | |
| 55 | return base; |
| 56 | } |
| 57 | |
| 58 | int main(int argc, char **argv) |
| 59 | { |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 60 | char **args, **cur; |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 61 | |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 62 | cur = args = malloc(sizeof(predef_args) + (sizeof(char *) * argc)); |
| 63 | if (args == NULL) { |
| 64 | perror(__FILE__ ": malloc"); |
| 65 | return 2; |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 66 | } |
| 67 | |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 68 | /* start with predefined args */ |
| 69 | memcpy(cur, predef_args, sizeof(predef_args)); |
| 70 | cur += sizeof(predef_args) / sizeof(predef_args[0]); |
| 71 | |
| 72 | /* append forward args */ |
| 73 | memcpy(cur, &argv[1], sizeof(char *) * (argc - 1)); |
| 74 | cur += argc - 1; |
| 75 | |
| 76 | /* finish with NULL termination */ |
| 77 | *cur = NULL; |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 78 | |
| 79 | strcat(path, get_basename(argv[0])); |
| 80 | |
| 81 | if (execv(path, args)) |
| 82 | perror(path); |
| 83 | |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 84 | free(args); |
| 85 | |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 86 | return 2; |
| 87 | } |