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