ext-toolchain-wrapper.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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>
  7. * (C) 2011 Daniel Nyström <daniel.nystrom@timeterminal.se>
  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. #include <stdio.h>
  14. #include <string.h>
  15. #include <limits.h>
  16. #include <unistd.h>
  17. #include <stdlib.h>
  18. static char path[PATH_MAX] = BR_CROSS_PATH;
  19. static char *predef_args[] = {
  20. path,
  21. "--sysroot", BR_SYSROOT,
  22. #ifdef BR_ARCH
  23. "-march=" BR_ARCH,
  24. #endif /* BR_ARCH */
  25. #ifdef BR_TUNE
  26. "-mtune=" BR_TUNE,
  27. #endif /* BR_TUNE */
  28. #ifdef BR_CPU
  29. "-mcpu=" BR_CPU,
  30. #endif
  31. #ifdef BR_ABI
  32. "-mabi=" BR_ABI,
  33. #endif
  34. #ifdef BR_SOFTFLOAT
  35. "-msoft-float",
  36. #endif /* BR_SOFTFLOAT */
  37. #ifdef BR_VFPFLOAT
  38. "-mfpu=vfp",
  39. #endif /* BR_VFPFLOAT */
  40. #ifdef BR_64
  41. "-m64",
  42. #endif
  43. #ifdef BR_ADDITIONAL_CFLAGS
  44. BR_ADDITIONAL_CFLAGS
  45. #endif
  46. };
  47. static const char *get_basename(const char *name)
  48. {
  49. const char *base;
  50. base = strrchr(name, '/');
  51. if (base)
  52. base++;
  53. else
  54. base = name;
  55. return base;
  56. }
  57. int main(int argc, char **argv)
  58. {
  59. char **args, **cur;
  60. cur = args = malloc(sizeof(predef_args) + (sizeof(char *) * argc));
  61. if (args == NULL) {
  62. perror(__FILE__ ": malloc");
  63. return 2;
  64. }
  65. /* start with predefined args */
  66. memcpy(cur, predef_args, sizeof(predef_args));
  67. cur += sizeof(predef_args) / sizeof(predef_args[0]);
  68. /* append forward args */
  69. memcpy(cur, &argv[1], sizeof(char *) * (argc - 1));
  70. cur += argc - 1;
  71. /* finish with NULL termination */
  72. *cur = NULL;
  73. strcat(path, get_basename(argv[0]));
  74. if (execv(path, args))
  75. perror(path);
  76. free(args);
  77. return 2;
  78. }