gcc-uClibc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (C) 2000 Manuel Novoa III
  3. *
  4. * This is a crude wrapper to use uClibc with gcc.
  5. * It was originally written to work around ./configure for ext2fs-utils.
  6. * It certainly can be improved, but it works for me in the normal cases.
  7. *
  8. * TODO:
  9. * Check/modify gcc-specific environment variables?
  10. */
  11. #ifdef DEBUG
  12. #include <stdio.h>
  13. #endif
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <unistd.h>
  17. #include "gcc-uClibc.h"
  18. #define UCLIBC_START UCLIBC_DIR"sysdeps/linux/"TARGET_ARCH"/_start.o"
  19. #define UCLIBC_START_G UCLIBC_START
  20. #define UCLIBC_LIB UCLIBC_DIR"libc.a"
  21. #if 1
  22. #define UCLIBC_LIB_G UCLIBC_LIB
  23. #else
  24. #define UCLIBC_LIB_G UCLIBC_DIR"libc.a-debug"
  25. #endif
  26. #define UCLIBC_INC "-I"UCLIBC_DIR"include/"
  27. static char nostdinc[] = "-nostdinc";
  28. static char nostartfiles[] = "-nostartfiles";
  29. static char nodefaultlibs[] = "-nodefaultlibs";
  30. static char nostdlib[] = "-nostdlib";
  31. int main(int argc, char **argv)
  32. {
  33. int debugging = 0, linking = 1;
  34. int use_stdinc = 1, use_start = 1, use_stdlib = 1;
  35. int i, j;
  36. int source_count;
  37. char ** gcc_argv;
  38. source_count = 0;
  39. for ( i = 1 ; i < argc ; i++ ) {
  40. if (argv[i][0] == '-') { /* option */
  41. switch (argv[i][1]) {
  42. case 'c':
  43. case 'S':
  44. case 'E':
  45. case 'r':
  46. if (argv[i][2] == 0) linking = 0;
  47. break;
  48. case 'g':
  49. if (argv[i][2] == 0) debugging = 1;
  50. break;
  51. case 'n':
  52. if (strcmp(nostdinc,argv[i]) == 0) {
  53. use_stdinc = 0;
  54. } else if (strcmp(nostartfiles,argv[i]) == 0) {
  55. use_start = 0;
  56. } else if (strcmp(nodefaultlibs,argv[i]) == 0) {
  57. use_stdlib = 0;
  58. } else if (strcmp(nostdlib,argv[i]) == 0) {
  59. use_start = 0;
  60. use_stdlib = 0;
  61. }
  62. }
  63. } else { /* assume it is an existing source file */
  64. ++source_count;
  65. }
  66. }
  67. #if 1
  68. gcc_argv = __builtin_alloca(sizeof(char*) * (argc + 20));
  69. #else
  70. if (!(gcc_argv = malloc(sizeof(char) * (argc + 20)))) {
  71. return EXIT_FAILURE;
  72. }
  73. #endif
  74. i = 0;
  75. gcc_argv[i++] = GCC_BIN;
  76. for ( j = 1 ; j < argc ; j++ ) {
  77. gcc_argv[i++] = argv[j];
  78. }
  79. if (use_stdinc) {
  80. gcc_argv[i++] = nostdinc;
  81. gcc_argv[i++] = UCLIBC_INC;
  82. gcc_argv[i++] = GCC_INCDIR;
  83. }
  84. if (linking && source_count) {
  85. gcc_argv[i++] = "-static";
  86. if (use_start) {
  87. if (debugging) {
  88. gcc_argv[i++] = UCLIBC_START_G;
  89. } else {
  90. gcc_argv[i++] = UCLIBC_START;
  91. }
  92. }
  93. if (use_stdlib) {
  94. gcc_argv[i++] = "-nostdlib";
  95. if (debugging) {
  96. gcc_argv[i++] = UCLIBC_LIB_G;
  97. } else {
  98. gcc_argv[i++] = UCLIBC_LIB;
  99. }
  100. gcc_argv[i++] = GCC_LIB;
  101. }
  102. }
  103. gcc_argv[i++] = NULL;
  104. #ifdef DEBUG
  105. for ( j = 0 ; gcc_argv[j] ; j++ ) {
  106. printf("arg[%2i] = %s\n", j, gcc_argv[j]);
  107. }
  108. return EXIT_SUCCESS;
  109. #else
  110. return execvp(GCC_BIN, gcc_argv);
  111. #endif
  112. }