blob: cc404f3e947796cd06b711c626387aa640721a22 [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 */
43};
44
45static 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
58int main(int argc, char **argv)
59{
Daniel Nyströme8c46b12011-06-21 21:54:27 +020060 char **args, **cur;
Peter Korsgaard85dc57f2011-04-29 13:09:26 +020061
Daniel Nyströme8c46b12011-06-21 21:54:27 +020062 cur = args = malloc(sizeof(predef_args) + (sizeof(char *) * argc));
63 if (args == NULL) {
64 perror(__FILE__ ": malloc");
65 return 2;
Peter Korsgaard85dc57f2011-04-29 13:09:26 +020066 }
67
Daniel Nyströme8c46b12011-06-21 21:54:27 +020068 /* 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 Korsgaard85dc57f2011-04-29 13:09:26 +020078
79 strcat(path, get_basename(argv[0]));
80
81 if (execv(path, args))
82 perror(path);
83
Daniel Nyströme8c46b12011-06-21 21:54:27 +020084 free(args);
85
Peter Korsgaard85dc57f2011-04-29 13:09:26 +020086 return 2;
87}