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 */ |
Arnout Vandecappelle (Essensium/Mind) | a22dc0f | 2012-03-13 23:30:00 +0100 | [diff] [blame^] | 43 | #ifdef BR_64 |
| 44 | "-m64", |
| 45 | #endif |
Thomas Petazzoni | b95e436 | 2011-12-31 12:09:33 +0100 | [diff] [blame] | 46 | #ifdef BR_ADDITIONAL_CFLAGS |
| 47 | BR_ADDITIONAL_CFLAGS |
| 48 | #endif |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | static const char *get_basename(const char *name) |
| 52 | { |
| 53 | const char *base; |
| 54 | |
| 55 | base = strrchr(name, '/'); |
| 56 | if (base) |
| 57 | base++; |
| 58 | else |
| 59 | base = name; |
| 60 | |
| 61 | return base; |
| 62 | } |
| 63 | |
| 64 | int main(int argc, char **argv) |
| 65 | { |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 66 | char **args, **cur; |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 67 | |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 68 | cur = args = malloc(sizeof(predef_args) + (sizeof(char *) * argc)); |
| 69 | if (args == NULL) { |
| 70 | perror(__FILE__ ": malloc"); |
| 71 | return 2; |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 72 | } |
| 73 | |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 74 | /* start with predefined args */ |
| 75 | memcpy(cur, predef_args, sizeof(predef_args)); |
| 76 | cur += sizeof(predef_args) / sizeof(predef_args[0]); |
| 77 | |
| 78 | /* append forward args */ |
| 79 | memcpy(cur, &argv[1], sizeof(char *) * (argc - 1)); |
| 80 | cur += argc - 1; |
| 81 | |
| 82 | /* finish with NULL termination */ |
| 83 | *cur = NULL; |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 84 | |
| 85 | strcat(path, get_basename(argv[0])); |
| 86 | |
| 87 | if (execv(path, args)) |
| 88 | perror(path); |
| 89 | |
Daniel Nyström | e8c46b1 | 2011-06-21 21:54:27 +0200 | [diff] [blame] | 90 | free(args); |
| 91 | |
Peter Korsgaard | 85dc57f | 2011-04-29 13:09:26 +0200 | [diff] [blame] | 92 | return 2; |
| 93 | } |