ext-toolchain-wrapper.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. *
  8. * This file is licensed under the terms of the GNU General Public License
  9. * version 2. This program is licensed "as is" without any warranty of any
  10. * kind, whether express or implied.
  11. */
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <limits.h>
  15. #include <unistd.h>
  16. #define MAXARGS 1000
  17. static char path[PATH_MAX] = BR_CROSS_PATH;
  18. static char *args[MAXARGS] = {
  19. path,
  20. "--sysroot", BR_SYSROOT,
  21. #ifdef BR_ARCH
  22. "-march=" BR_ARCH,
  23. #endif /* BR_ARCH */
  24. #ifdef BR_TUNE
  25. "-mtune=" BR_TUNE,
  26. #endif /* BR_TUNE */
  27. #ifdef BR_ABI
  28. "-mabi=" BR_ABI,
  29. #endif
  30. #ifdef BR_SOFTFLOAT
  31. "-msoft-float",
  32. #endif /* BR_SOFTFLOAT */
  33. #ifdef BR_VFPFLOAT
  34. "-mfpu=vfp",
  35. #endif /* BR_VFPFLOAT */
  36. };
  37. static const char *get_basename(const char *name)
  38. {
  39. const char *base;
  40. base = strrchr(name, '/');
  41. if (base)
  42. base++;
  43. else
  44. base = name;
  45. return base;
  46. }
  47. int main(int argc, char **argv)
  48. {
  49. int i;
  50. for (i=0; args[i]; i++);
  51. if ((argc+i) >= MAXARGS) {
  52. fputs("Too many arguments\n", stderr);
  53. return 1;
  54. }
  55. /* forward args */
  56. memcpy(&args[i], &argv[1], sizeof(argv[0]) * (argc - 1));
  57. strcat(path, get_basename(argv[0]));
  58. if (execv(path, args))
  59. perror(path);
  60. return 2;
  61. }