blob: 82595eaa727e1213e0cd567232ad1c02122e4a88 [file] [log] [blame]
Peter Korsgaard85dc57f2011-04-29 13:09:26 +02001/**
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öme8c46b12011-06-21 21:54:27 +02007 * (C) 2011 Daniel Nyström <daniel.nystrom@timeterminal.se>
Peter Korsgaard85dc57f2011-04-29 13:09:26 +02008 *
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öme8c46b12011-06-21 21:54:27 +020018#include <stdlib.h>
Peter Korsgaard85dc57f2011-04-29 13:09:26 +020019
20static char path[PATH_MAX] = BR_CROSS_PATH;
21
Daniel Nyströme8c46b12011-06-21 21:54:27 +020022static char *predef_args[] = {
Peter Korsgaard85dc57f2011-04-29 13:09:26 +020023 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 MARCEL3fb60102011-11-01 13:19:16 +010031#ifdef BR_CPU
32 "-mcpu=" BR_CPU,
33#endif
Peter Korsgaard85dc57f2011-04-29 13:09:26 +020034#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)a22dc0f2012-03-13 23:30:00 +010043#ifdef BR_64
44 "-m64",
45#endif
Thomas Petazzonib95e4362011-12-31 12:09:33 +010046#ifdef BR_ADDITIONAL_CFLAGS
47 BR_ADDITIONAL_CFLAGS
48#endif
Peter Korsgaard85dc57f2011-04-29 13:09:26 +020049};
50
51static 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
64int main(int argc, char **argv)
65{
Daniel Nyströme8c46b12011-06-21 21:54:27 +020066 char **args, **cur;
Peter Korsgaard85dc57f2011-04-29 13:09:26 +020067
Daniel Nyströme8c46b12011-06-21 21:54:27 +020068 cur = args = malloc(sizeof(predef_args) + (sizeof(char *) * argc));
69 if (args == NULL) {
70 perror(__FILE__ ": malloc");
71 return 2;
Peter Korsgaard85dc57f2011-04-29 13:09:26 +020072 }
73
Daniel Nyströme8c46b12011-06-21 21:54:27 +020074 /* 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 Korsgaard85dc57f2011-04-29 13:09:26 +020084
85 strcat(path, get_basename(argv[0]));
86
87 if (execv(path, args))
88 perror(path);
89
Daniel Nyströme8c46b12011-06-21 21:54:27 +020090 free(args);
91
Peter Korsgaard85dc57f2011-04-29 13:09:26 +020092 return 2;
93}