annotate sources/toys/ccwrap.c @ 863:4bfe2b34dd9f

Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
author Rob Landley <rob@landley.net>
date Mon, 26 Oct 2009 06:09:29 -0500
parents 1067e99efbdc
children 626288dd5cf3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set ts=4 :*/
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
2 /*
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * Copyright (C) 2000 Manuel Novoa III
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
4 * Copyright (C) 2002-2003 Erik Andersen
800
d20b91530061 Be a little more consistent about space vs tab indentation.
Rob Landley <rob@landley.net>
parents: 748
diff changeset
5 * Copyright (C) 2006-2009 Rob Landley <rob@landley.net>
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
6 *
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
7 * Wrapper to use uClibc with gcc, and make gcc relocatable.
812
4e1e6aa7f445 Convince gcc to build/install libgcc_eh.a even for --disable-shared compilers, and tell the wrapper to expect it.
Rob Landley <rob@landley.net>
parents: 807
diff changeset
8 *
4e1e6aa7f445 Convince gcc to build/install libgcc_eh.a even for --disable-shared compilers, and tell the wrapper to expect it.
Rob Landley <rob@landley.net>
parents: 807
diff changeset
9 * Licensed under GPLv2.
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
10 */
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
11
16
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
12 #define _GNU_SOURCE
433
c7a1631711f4 Smallish wrapper cleanups, more to come.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
13 #include <alloca.h>
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
14 #include <stdio.h>
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
15 #include <stdlib.h>
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
16 #include <stdarg.h>
76
5703436a408e Update the uClibc snapshot and make config changes it needs.
Rob Landley <rob@landley.net>
parents: 65
diff changeset
17 #include <string.h>
57
f393a630a5b3 Weird ordering dependency. I think it's a uClibc bug?
Rob Landley <rob@landley.net>
parents: 56
diff changeset
18 #include <strings.h>
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
19 #include <unistd.h>
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
20 #include <errno.h>
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
21 #include <sys/stat.h>
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
22 #include <sys/wait.h>
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
23
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
24 static char *topdir;
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
25 static char nostdinc[] = "-nostdinc";
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
26 static char nostartfiles[] = "-nostartfiles";
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
27 static char nodefaultlibs[] = "-nodefaultlibs";
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
28 static char nostdlib[] = "-nostdlib";
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
29
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
30 // For C++
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
31 static char nostdinc_plus[] = "-nostdinc++";
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
32
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
33 // gcc 4.3 generates tons of spurious warnings which you can't shut off.
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
34
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
35 #define xasprintf(...) do {int ignore=asprintf(__VA_ARGS__);} while(0)
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
36
438
e9f3011ec40d Teach wrapper about libgcc_eh.a for static linking.
Rob Landley <rob@landley.net>
parents: 435
diff changeset
37 // #define GIMME_AN_S for wrapper to support --enable-shared toolchain.
e9f3011ec40d Teach wrapper about libgcc_eh.a for static linking.
Rob Landley <rob@landley.net>
parents: 435
diff changeset
38
390
a9a9eee9e620 Teach the wrapper script to do the libgcc_s --as-needed stuff when
Rob Landley <rob@landley.net>
parents: 257
diff changeset
39 #ifdef GIMME_AN_S
438
e9f3011ec40d Teach wrapper about libgcc_eh.a for static linking.
Rob Landley <rob@landley.net>
parents: 435
diff changeset
40 #define ADD_GCC_S() \
e9f3011ec40d Teach wrapper about libgcc_eh.a for static linking.
Rob Landley <rob@landley.net>
parents: 435
diff changeset
41 do { \
e9f3011ec40d Teach wrapper about libgcc_eh.a for static linking.
Rob Landley <rob@landley.net>
parents: 435
diff changeset
42 if (!use_static_linking) \
e9f3011ec40d Teach wrapper about libgcc_eh.a for static linking.
Rob Landley <rob@landley.net>
parents: 435
diff changeset
43 gcc_argv[argcnt++] = "-Wl,--as-needed,-lgcc_s,--no-as-needed"; \
e9f3011ec40d Teach wrapper about libgcc_eh.a for static linking.
Rob Landley <rob@landley.net>
parents: 435
diff changeset
44 else gcc_argv[argcnt++] = "-lgcc_eh"; \
e9f3011ec40d Teach wrapper about libgcc_eh.a for static linking.
Rob Landley <rob@landley.net>
parents: 435
diff changeset
45 } while (0);
390
a9a9eee9e620 Teach the wrapper script to do the libgcc_s --as-needed stuff when
Rob Landley <rob@landley.net>
parents: 257
diff changeset
46 #else
812
4e1e6aa7f445 Convince gcc to build/install libgcc_eh.a even for --disable-shared compilers, and tell the wrapper to expect it.
Rob Landley <rob@landley.net>
parents: 807
diff changeset
47 #define ADD_GCC_S() gcc_argv[argcnt++] = "-lgcc_eh"
390
a9a9eee9e620 Teach the wrapper script to do the libgcc_s --as-needed stuff when
Rob Landley <rob@landley.net>
parents: 257
diff changeset
48 #endif
a9a9eee9e620 Teach the wrapper script to do the libgcc_s --as-needed stuff when
Rob Landley <rob@landley.net>
parents: 257
diff changeset
49
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
50 // Confirm that a regular file exists, and (optionally) has the executable bit.
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
51 int is_file(char *filename, int has_exe)
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
52 {
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
53 // Confirm it has the executable bit set, if necessary.
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
54 if (!has_exe || !access(filename, X_OK)) {
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
55 struct stat st;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
56
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
57 // Confirm it exists and is not a directory.
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
58 if (!stat(filename, &st) && S_ISREG(st.st_mode)) return 1;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
59 }
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
60 return 0;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
61 }
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
62
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
63 // Find an executable in a colon-separated path
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
64
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
65 char *find_in_path(char *path, char *filename, int has_exe)
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
66 {
839
1067e99efbdc ccwrap shouldn't segfault if PATH isn't exported. (Thanks to Wangji Hoan for spotting this bug.)
Rob Landley <rob@landley.net>
parents: 812
diff changeset
67 // Don't segfault if $PATH wasn't exported
1067e99efbdc ccwrap shouldn't segfault if PATH isn't exported. (Thanks to Wangji Hoan for spotting this bug.)
Rob Landley <rob@landley.net>
parents: 812
diff changeset
68 if (!path) return 0;
1067e99efbdc ccwrap shouldn't segfault if PATH isn't exported. (Thanks to Wangji Hoan for spotting this bug.)
Rob Landley <rob@landley.net>
parents: 812
diff changeset
69
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
70 char *cwd = getcwd(NULL, 0);
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
71
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
72 if (index(filename, '/') && is_file(filename, has_exe))
863
4bfe2b34dd9f Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents: 839
diff changeset
73 return realpath(filename, NULL);
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
74
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
75 for (;;) {
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
76 char *str, *next = path ? index(path, ':') : NULL;
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
77 int len = next ? next-path : strlen(path);
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
78
64
51b8220c37e7 Make wrapper script work when /bin is a symlink to /usr/bin and the wrapper
Rob Landley <rob@landley.net>
parents: 63
diff changeset
79 // The +3 is a corner case: if strlen(filename) is 1, make sure we
51b8220c37e7 Make wrapper script work when /bin is a symlink to /usr/bin and the wrapper
Rob Landley <rob@landley.net>
parents: 63
diff changeset
80 // have enough space to append ".." to make topdir.
51b8220c37e7 Make wrapper script work when /bin is a symlink to /usr/bin and the wrapper
Rob Landley <rob@landley.net>
parents: 63
diff changeset
81 str = malloc(strlen(filename) + (len ? len : strlen(cwd)) + 3);
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
82 if (!len) sprintf(str, "%s/%s", cwd, filename);
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
83 else {
16
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
84 char *str2 = str;
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
85
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
86 strncpy(str, path, len);
16
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
87 str2 = str+len;
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
88 *(str2++) = '/';
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
89 strcpy(str2, filename);
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
90 }
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
91
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
92 // If it's not a directory, return it.
863
4bfe2b34dd9f Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents: 839
diff changeset
93 if (is_file(str, has_exe)) {
4bfe2b34dd9f Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents: 839
diff changeset
94 char *s = realpath(str, NULL);
4bfe2b34dd9f Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents: 839
diff changeset
95 free(str);
4bfe2b34dd9f Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents: 839
diff changeset
96 return s;
4bfe2b34dd9f Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents: 839
diff changeset
97 } else free(str);
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
98
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
99 if (!next) break;
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
100 path += len;
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
101 path++;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
102 }
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
103 free(cwd);
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
104
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
105 return NULL;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
106 }
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
107
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
108 int main(int argc, char **argv)
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
109 {
435
d8e531563e35 Clean out some of the old uClibc build dir stuff nothing uses anymore.
Rob Landley <rob@landley.net>
parents: 434
diff changeset
110 int linking = 1, use_static_linking = 0;
549
2edf40b17ee2 Select crtbegin.o and crtend.o variants more accurately for -static and -shared.
Rob Landley <rob@landley.net>
parents: 548
diff changeset
111 int use_stdinc = 1, use_start = 1, use_stdlib = 1, use_shared = 0;
435
d8e531563e35 Clean out some of the old uClibc build dir stuff nothing uses anymore.
Rob Landley <rob@landley.net>
parents: 434
diff changeset
112 int source_count = 0, verbose = 0;
528
71f438cde285 Make compiler wrapper parse -M options correctly, so uClibc make utils works.
Rob Landley <rob@landley.net>
parents: 447
diff changeset
113 int i, argcnt, liblen, lplen;
16
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
114 char **gcc_argv, **libraries, **libpath;
435
d8e531563e35 Clean out some of the old uClibc build dir stuff nothing uses anymore.
Rob Landley <rob@landley.net>
parents: 434
diff changeset
115 char *dlstr, *incstr, *devprefix, *libstr;
748
897fb219ead7 Teach ccwrap to handle --print-prog-name=ld and such.
Rob Landley <rob@landley.net>
parents: 684
diff changeset
116 char *cc, *toolprefix;
439
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
117 char *debug_wrapper=getenv("WRAPPER_DEBUG");
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
118
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
119 // For C++
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
120
547
65b71915c836 Clean up ccwrap some more.
Rob Landley <rob@landley.net>
parents: 546
diff changeset
121 char *cpp = NULL;
748
897fb219ead7 Teach ccwrap to handle --print-prog-name=ld and such.
Rob Landley <rob@landley.net>
parents: 684
diff changeset
122 int prefixlen, ctor_dtor = 1, use_nostdinc_plus = 0;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
123
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
124 // For profiling
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
125 int profile = 0;
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
126
42
7b0f34fbc35a Fix inappropriate activation of profiling support, and add environment variable
Rob Landley <rob@landley.net>
parents: 30
diff changeset
127 if(debug_wrapper) {
217
01fd30185476 Use fprintf(stderr,...) instead of dprintf(2,...) to be more portable.
Rob Landley <rob@landley.net>
parents: 76
diff changeset
128 fprintf(stderr,"incoming: ");
433
c7a1631711f4 Smallish wrapper cleanups, more to come.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
129 for(gcc_argv=argv;*gcc_argv;gcc_argv++)
c7a1631711f4 Smallish wrapper cleanups, more to come.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
130 fprintf(stderr,"%s ",*gcc_argv);
217
01fd30185476 Use fprintf(stderr,...) instead of dprintf(2,...) to be more portable.
Rob Landley <rob@landley.net>
parents: 76
diff changeset
131 fprintf(stderr,"\n\n");
42
7b0f34fbc35a Fix inappropriate activation of profiling support, and add environment variable
Rob Landley <rob@landley.net>
parents: 30
diff changeset
132 }
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
133
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
134 // Allocate space for new command line
433
c7a1631711f4 Smallish wrapper cleanups, more to come.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
135 gcc_argv = alloca(sizeof(char*) * (argc + 128));
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
136
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
137 // What directory is the wrapper script in?
16
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
138 if(!(topdir = find_in_path(getenv("PATH"), argv[0], 1))) {
839
1067e99efbdc ccwrap shouldn't segfault if PATH isn't exported. (Thanks to Wangji Hoan for spotting this bug.)
Rob Landley <rob@landley.net>
parents: 812
diff changeset
139 fprintf(stderr, "can't find %s in $PATH (did you export it?)\n", argv[0]);
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
140 exit(1);
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
141 } else {
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
142 char *path = getenv("PATH"), *temp;
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
143
64
51b8220c37e7 Make wrapper script work when /bin is a symlink to /usr/bin and the wrapper
Rob Landley <rob@landley.net>
parents: 63
diff changeset
144 // Add that directory to the start of $PATH. (Better safe than sorry.)
16
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
145 *rindex(topdir,'/') = 0;
257
d37e39370d39 Fix cross compiler toolchain to be properly relocatable on x86-64 host.
Rob Landley <rob@landley.net>
parents: 217
diff changeset
146 temp = malloc(5+strlen(topdir)+1+strlen(topdir)+14+strlen(path)+1);
d37e39370d39 Fix cross compiler toolchain to be properly relocatable on x86-64 host.
Rob Landley <rob@landley.net>
parents: 217
diff changeset
147 sprintf(temp,"PATH=%s:%s/../tools/bin:%s",topdir,topdir,path);
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
148 putenv(temp);
16
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
149
64
51b8220c37e7 Make wrapper script work when /bin is a symlink to /usr/bin and the wrapper
Rob Landley <rob@landley.net>
parents: 63
diff changeset
150 // The directory above the wrapper script should have include, gcc,
65
79295919b775 Ok, when appending .. instead of truncating at /, remember the "stop truncating"
Rob Landley <rob@landley.net>
parents: 64
diff changeset
151 // and lib directories. However, the script could have a symlink
79295919b775 Ok, when appending .. instead of truncating at /, remember the "stop truncating"
Rob Landley <rob@landley.net>
parents: 64
diff changeset
152 // pointing to its directory (ala /bin -> /usr/bin), so append ".."
79295919b775 Ok, when appending .. instead of truncating at /, remember the "stop truncating"
Rob Landley <rob@landley.net>
parents: 64
diff changeset
153 // instead of trucating the path.
79295919b775 Ok, when appending .. instead of truncating at /, remember the "stop truncating"
Rob Landley <rob@landley.net>
parents: 64
diff changeset
154 strcat(topdir,"/..");
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
155 }
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
156
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
157 // What's the name of the C compiler we're wrapping? (It may have a
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
158 // cross-prefix.)
439
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
159 cc = getenv("WRAPPER_CC");
390
a9a9eee9e620 Teach the wrapper script to do the libgcc_s --as-needed stuff when
Rob Landley <rob@landley.net>
parents: 257
diff changeset
160 if (!cc) cc = GCC_UNWRAPPED_NAME;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
161
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
162 // Check end of name, since there could be a cross-prefix on the thing
748
897fb219ead7 Teach ccwrap to handle --print-prog-name=ld and such.
Rob Landley <rob@landley.net>
parents: 684
diff changeset
163 toolprefix = strrchr(argv[0], '/');
897fb219ead7 Teach ccwrap to handle --print-prog-name=ld and such.
Rob Landley <rob@landley.net>
parents: 684
diff changeset
164 if (!toolprefix) toolprefix = argv[0];
800
d20b91530061 Be a little more consistent about space vs tab indentation.
Rob Landley <rob@landley.net>
parents: 748
diff changeset
165 else toolprefix++;
748
897fb219ead7 Teach ccwrap to handle --print-prog-name=ld and such.
Rob Landley <rob@landley.net>
parents: 684
diff changeset
166
897fb219ead7 Teach ccwrap to handle --print-prog-name=ld and such.
Rob Landley <rob@landley.net>
parents: 684
diff changeset
167 prefixlen = strlen(toolprefix);
807
d0b74a631587 Teach ccwrap.c to use arch-specific WRAPPER_TOPDIR values, to avoid interfering with canadian cross.
Rob Landley <rob@landley.net>
parents: 800
diff changeset
168 if (prefixlen>=3 && !strcmp(toolprefix+prefixlen-3, "gcc")) prefixlen -= 3;
800
d20b91530061 Be a little more consistent about space vs tab indentation.
Rob Landley <rob@landley.net>
parents: 748
diff changeset
169 else if (!strcmp(toolprefix+prefixlen-2, "cc")) prefixlen -= 2;
748
897fb219ead7 Teach ccwrap to handle --print-prog-name=ld and such.
Rob Landley <rob@landley.net>
parents: 684
diff changeset
170 else if (!strcmp(toolprefix+prefixlen-2, "ld")) {
800
d20b91530061 Be a little more consistent about space vs tab indentation.
Rob Landley <rob@landley.net>
parents: 748
diff changeset
171 prefixlen -= 2;
433
c7a1631711f4 Smallish wrapper cleanups, more to come.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
172
c7a1631711f4 Smallish wrapper cleanups, more to come.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
173 // TODO: put support for wrapping the linker here.
c7a1631711f4 Smallish wrapper cleanups, more to come.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
174
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
175 // Wrapping the c++ compiler?
748
897fb219ead7 Teach ccwrap to handle --print-prog-name=ld and such.
Rob Landley <rob@landley.net>
parents: 684
diff changeset
176 } else if (!strcmp(toolprefix+prefixlen-2, "++")) {
897fb219ead7 Teach ccwrap to handle --print-prog-name=ld and such.
Rob Landley <rob@landley.net>
parents: 684
diff changeset
177 int len = strlen(cc);
433
c7a1631711f4 Smallish wrapper cleanups, more to come.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
178 cpp = alloca(len+1);
c7a1631711f4 Smallish wrapper cleanups, more to come.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
179 strcpy(cpp, cc);
c7a1631711f4 Smallish wrapper cleanups, more to come.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
180 cpp[len-1]='+';
c7a1631711f4 Smallish wrapper cleanups, more to come.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
181 cpp[len-2]='+';
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
182 use_nostdinc_plus = 1;
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
183 }
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
184
439
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
185 devprefix = getenv("WRAPPER_TOPDIR");
807
d0b74a631587 Teach ccwrap.c to use arch-specific WRAPPER_TOPDIR values, to avoid interfering with canadian cross.
Rob Landley <rob@landley.net>
parents: 800
diff changeset
186 if (!devprefix) {
d0b74a631587 Teach ccwrap.c to use arch-specific WRAPPER_TOPDIR values, to avoid interfering with canadian cross.
Rob Landley <rob@landley.net>
parents: 800
diff changeset
187 char *temp, *temp2;
d0b74a631587 Teach ccwrap.c to use arch-specific WRAPPER_TOPDIR values, to avoid interfering with canadian cross.
Rob Landley <rob@landley.net>
parents: 800
diff changeset
188 xasprintf(&temp, "%.*sWRAPPER_TOPDIR", prefixlen, toolprefix);
d0b74a631587 Teach ccwrap.c to use arch-specific WRAPPER_TOPDIR values, to avoid interfering with canadian cross.
Rob Landley <rob@landley.net>
parents: 800
diff changeset
189 temp2 = temp;
d0b74a631587 Teach ccwrap.c to use arch-specific WRAPPER_TOPDIR values, to avoid interfering with canadian cross.
Rob Landley <rob@landley.net>
parents: 800
diff changeset
190 while (*temp2) {
d0b74a631587 Teach ccwrap.c to use arch-specific WRAPPER_TOPDIR values, to avoid interfering with canadian cross.
Rob Landley <rob@landley.net>
parents: 800
diff changeset
191 if (*temp2 == '-') *temp2='_';
d0b74a631587 Teach ccwrap.c to use arch-specific WRAPPER_TOPDIR values, to avoid interfering with canadian cross.
Rob Landley <rob@landley.net>
parents: 800
diff changeset
192 temp2++;
d0b74a631587 Teach ccwrap.c to use arch-specific WRAPPER_TOPDIR values, to avoid interfering with canadian cross.
Rob Landley <rob@landley.net>
parents: 800
diff changeset
193 }
d0b74a631587 Teach ccwrap.c to use arch-specific WRAPPER_TOPDIR values, to avoid interfering with canadian cross.
Rob Landley <rob@landley.net>
parents: 800
diff changeset
194 devprefix = getenv(temp);
d0b74a631587 Teach ccwrap.c to use arch-specific WRAPPER_TOPDIR values, to avoid interfering with canadian cross.
Rob Landley <rob@landley.net>
parents: 800
diff changeset
195 }
547
65b71915c836 Clean up ccwrap some more.
Rob Landley <rob@landley.net>
parents: 546
diff changeset
196 if (!devprefix) devprefix = topdir;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
197
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
198 incstr = getenv("UCLIBC_GCC_INC");
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
199 libstr = getenv("UCLIBC_GCC_LIB");
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
200
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
201 // Figure out where the dynamic linker is.
63
89cf9497824e Teach the native build about ld-uClibc.so.0 can living in /tools.
Rob Landley <rob@landley.net>
parents: 57
diff changeset
202 dlstr = getenv("UCLIBC_DYNAMIC_LINKER");
89cf9497824e Teach the native build about ld-uClibc.so.0 can living in /tools.
Rob Landley <rob@landley.net>
parents: 57
diff changeset
203 if (!dlstr) dlstr = "/lib/ld-uClibc.so.0";
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
204 xasprintf(&dlstr, "-Wl,--dynamic-linker,%s", dlstr);
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
205
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
206 liblen = 0;
433
c7a1631711f4 Smallish wrapper cleanups, more to come.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
207 libraries = alloca(sizeof(char*) * (argc));
439
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
208 libraries[liblen] = 0;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
209
434
116c10067f4a Replace variable "n" with something greppable.
Rob Landley <rob@landley.net>
parents: 433
diff changeset
210 lplen = 0;
433
c7a1631711f4 Smallish wrapper cleanups, more to come.
Rob Landley <rob@landley.net>
parents: 403
diff changeset
211 libpath = alloca(sizeof(char*) * (argc));
439
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
212 libpath[lplen] = 0;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
213
18
eaf7a8d5e697 Managed to get a working toolchain, with wrapper script, to build a hello
Rob Landley <rob@landley.net>
parents: 16
diff changeset
214 // Parse the incoming gcc arguments.
eaf7a8d5e697 Managed to get a working toolchain, with wrapper script, to build a hello
Rob Landley <rob@landley.net>
parents: 16
diff changeset
215
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
216 for (i=1; i<argc; i++) {
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
217 if (argv[i][0] == '-' && argv[i][1]) { /* option */
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
218 switch (argv[i][1]) {
528
71f438cde285 Make compiler wrapper parse -M options correctly, so uClibc make utils works.
Rob Landley <rob@landley.net>
parents: 447
diff changeset
219 case 'M': /* generate dependencies */
71f438cde285 Make compiler wrapper parse -M options correctly, so uClibc make utils works.
Rob Landley <rob@landley.net>
parents: 447
diff changeset
220 {
71f438cde285 Make compiler wrapper parse -M options correctly, so uClibc make utils works.
Rob Landley <rob@landley.net>
parents: 447
diff changeset
221 char *p = argv[i];
71f438cde285 Make compiler wrapper parse -M options correctly, so uClibc make utils works.
Rob Landley <rob@landley.net>
parents: 447
diff changeset
222
71f438cde285 Make compiler wrapper parse -M options correctly, so uClibc make utils works.
Rob Landley <rob@landley.net>
parents: 447
diff changeset
223 // -M and -MM imply -E and thus no linking
71f438cde285 Make compiler wrapper parse -M options correctly, so uClibc make utils works.
Rob Landley <rob@landley.net>
parents: 447
diff changeset
224 // Other -MX options _don't_, including -MMD.
71f438cde285 Make compiler wrapper parse -M options correctly, so uClibc make utils works.
Rob Landley <rob@landley.net>
parents: 447
diff changeset
225 if (p[2] && (p[2]!='M' || p[3])) break;
71f438cde285 Make compiler wrapper parse -M options correctly, so uClibc make utils works.
Rob Landley <rob@landley.net>
parents: 447
diff changeset
226 }
71f438cde285 Make compiler wrapper parse -M options correctly, so uClibc make utils works.
Rob Landley <rob@landley.net>
parents: 447
diff changeset
227 // fall through
71f438cde285 Make compiler wrapper parse -M options correctly, so uClibc make utils works.
Rob Landley <rob@landley.net>
parents: 447
diff changeset
228
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
229 case 'c': /* compile or assemble */
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
230 case 'S': /* generate assembler code */
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
231 case 'E': /* preprocess only */
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
232 linking = 0;
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
233 break;
18
eaf7a8d5e697 Managed to get a working toolchain, with wrapper script, to build a hello
Rob Landley <rob@landley.net>
parents: 16
diff changeset
234
eaf7a8d5e697 Managed to get a working toolchain, with wrapper script, to build a hello
Rob Landley <rob@landley.net>
parents: 16
diff changeset
235 case 'L': /* library path */
434
116c10067f4a Replace variable "n" with something greppable.
Rob Landley <rob@landley.net>
parents: 433
diff changeset
236 libpath[lplen++] = argv[i];
439
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
237 libpath[lplen] = 0;
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
238 if (!argv[i][2]) {
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
239 argv[i] = 0;
434
116c10067f4a Replace variable "n" with something greppable.
Rob Landley <rob@landley.net>
parents: 433
diff changeset
240 libpath[lplen++] = argv[++i];
439
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
241 libpath[lplen] = 0;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
242 }
439
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
243 argv[i] = 0;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
244 break;
18
eaf7a8d5e697 Managed to get a working toolchain, with wrapper script, to build a hello
Rob Landley <rob@landley.net>
parents: 16
diff changeset
245
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
246 case 'l': /* library */
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
247 libraries[liblen++] = argv[i];
439
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
248 libraries[liblen] = 0;
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
249 argv[i] = 0;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
250 break;
18
eaf7a8d5e697 Managed to get a working toolchain, with wrapper script, to build a hello
Rob Landley <rob@landley.net>
parents: 16
diff changeset
251
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
252 case 'v': /* verbose */
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
253 if (argv[i][2] == 0) verbose = 1;
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
254 printf("Invoked as %s\n", argv[0]);
16
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
255 printf("Reference path: %s\n", topdir);
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
256 break;
18
eaf7a8d5e697 Managed to get a working toolchain, with wrapper script, to build a hello
Rob Landley <rob@landley.net>
parents: 16
diff changeset
257
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
258 case 'n':
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
259 if (!strcmp(nostdinc,argv[i])) use_stdinc = 0;
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
260 else if (!strcmp(nostartfiles,argv[i])) {
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
261 ctor_dtor = 0;
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
262 use_start = 0;
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
263 } else if (!strcmp(nodefaultlibs,argv[i])) {
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
264 use_stdlib = 0;
439
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
265 argv[i] = 0;
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
266 } else if (!strcmp(nostdlib,argv[i])) {
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
267 ctor_dtor = 0;
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
268 use_start = 0;
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
269 use_stdlib = 0;
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
270 } else if (!strcmp(nostdinc_plus,argv[i]))
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
271 use_nostdinc_plus = 0;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
272 break;
18
eaf7a8d5e697 Managed to get a working toolchain, with wrapper script, to build a hello
Rob Landley <rob@landley.net>
parents: 16
diff changeset
273
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
274 case 's':
684
222886c9b3f5 Fix wrapper so it doesn't misinterpret -static-libgcc as -static.
Rob Landley <rob@landley.net>
parents: 550
diff changeset
275 if (!strcmp(argv[i],"-static")) use_static_linking = 1;
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
276 if (!strcmp("-shared",argv[i])) {
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
277 use_start = 0;
549
2edf40b17ee2 Select crtbegin.o and crtend.o variants more accurately for -static and -shared.
Rob Landley <rob@landley.net>
parents: 548
diff changeset
278 use_shared = 1;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
279 }
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
280 break;
18
eaf7a8d5e697 Managed to get a working toolchain, with wrapper script, to build a hello
Rob Landley <rob@landley.net>
parents: 16
diff changeset
281
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
282 case 'W': /* -static could be passed directly to ld */
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
283 if (!strncmp("-Wl,",argv[i],4)) {
684
222886c9b3f5 Fix wrapper so it doesn't misinterpret -static-libgcc as -static.
Rob Landley <rob@landley.net>
parents: 550
diff changeset
284 char *temp = strstr(argv[i], ",-static");
222886c9b3f5 Fix wrapper so it doesn't misinterpret -static-libgcc as -static.
Rob Landley <rob@landley.net>
parents: 550
diff changeset
285 if (temp && (!temp[7] || temp[7]==','))
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
286 use_static_linking = 1;
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
287 if (strstr(argv[i],"--dynamic-linker")) dlstr = 0;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
288 }
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
289 break;
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
290
20
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
291 case 'p':
29
db08bdb5e9de The poor design of the gcc command line never ceases to amaze. Notice how
Rob Landley <rob@landley.net>
parents: 28
diff changeset
292 wow_this_sucks:
20
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
293 if (!strncmp("-print-",argv[i],7)) {
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
294 char *temp, *temp2;
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
295 int itemp, showall = 0;
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
296
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
297 temp = argv[i]+7;
748
897fb219ead7 Teach ccwrap to handle --print-prog-name=ld and such.
Rob Landley <rob@landley.net>
parents: 684
diff changeset
298 if (!strncmp(temp, "prog-name=", 10)) {
897fb219ead7 Teach ccwrap to handle --print-prog-name=ld and such.
Rob Landley <rob@landley.net>
parents: 684
diff changeset
299 printf("%.*s%s\n", prefixlen, toolprefix, temp+10);
897fb219ead7 Teach ccwrap to handle --print-prog-name=ld and such.
Rob Landley <rob@landley.net>
parents: 684
diff changeset
300 exit(0);
897fb219ead7 Teach ccwrap to handle --print-prog-name=ld and such.
Rob Landley <rob@landley.net>
parents: 684
diff changeset
301 } else if (!strcmp(temp, "search-dirs")) {
20
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
302 printf("install: %s/\n",devprefix);
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
303 printf("programs: %s\n",getenv("PATH"));
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
304 printf("libraries: ");
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
305 temp2 = "";
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
306 showall = 1;
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
307 } else if (!strncmp(temp, "file-name=", 10))
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
308 temp2 = temp+10;
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
309 else if (!strcmp(temp, "libgcc-file-name"))
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
310 temp2="libgcc.a";
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
311 else break;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
312
20
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
313 // Find this entry in the library path.
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
314 for(itemp=0;;itemp++) {
441
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
315 if (itemp == lplen)
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
316 xasprintf(&temp, "%s/gcc/lib/%s", devprefix,
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
317 temp2);
441
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
318 else if (itemp == lplen+1)
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
319 xasprintf(&temp, "%s/lib/%s", devprefix, temp2);
441
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
320
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
321 // This is so "include" finds the gcc internal
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
322 // include dir. The uClibc build needs this.
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
323 else if (itemp == lplen+2)
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
324 xasprintf(&temp, "%s/gcc/%s", devprefix, temp2);
441
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
325 else if (itemp == lplen+3) {
20
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
326 temp = temp2;
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
327 break;
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
328 } else xasprintf(&temp, "%s/%s", libpath[itemp],
20
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
329 temp2);
441
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
330
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
331 if (debug_wrapper)
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
332 fprintf(stderr, "try=%s\n", temp);
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
333
20
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
334 if (showall) printf(":%s"+(itemp?0:1), temp);
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
335 else if (!access(temp, F_OK)) break;
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
336 }
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
337
441
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
338
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
339
20
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
340 printf("%s\n"+(showall ? 2 : 0), temp);
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
341 exit(0);
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
342
44067ab61cd2 Switch linking back on as the default, add support for -print-search-dirs,
Rob Landley <rob@landley.net>
parents: 19
diff changeset
343 // Profiling.
42
7b0f34fbc35a Fix inappropriate activation of profiling support, and add environment variable
Rob Landley <rob@landley.net>
parents: 30
diff changeset
344 } else if (!strcmp("-pg",argv[i])) profile = 1;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
345 break;
18
eaf7a8d5e697 Managed to get a working toolchain, with wrapper script, to build a hello
Rob Landley <rob@landley.net>
parents: 16
diff changeset
346
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
347 case 'f':
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
348 // profiling
549
2edf40b17ee2 Select crtbegin.o and crtend.o variants more accurately for -static and -shared.
Rob Landley <rob@landley.net>
parents: 548
diff changeset
349 if (strcmp("-fprofile-arcs",argv[i]) == 0) profile = 1;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
350 break;
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
351
19
b5ffd82d9ae5 Two problems: 1) Needed to parse -print-file-name= to make the uClibc build
Rob Landley <rob@landley.net>
parents: 18
diff changeset
352 // --longopts
b5ffd82d9ae5 Two problems: 1) Needed to parse -print-file-name= to make the uClibc build
Rob Landley <rob@landley.net>
parents: 18
diff changeset
353
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
354 case '-':
29
db08bdb5e9de The poor design of the gcc command line never ceases to amaze. Notice how
Rob Landley <rob@landley.net>
parents: 28
diff changeset
355 if (!strncmp(argv[i],"--print-",8)) {
db08bdb5e9de The poor design of the gcc command line never ceases to amaze. Notice how
Rob Landley <rob@landley.net>
parents: 28
diff changeset
356 argv[i]++;
db08bdb5e9de The poor design of the gcc command line never ceases to amaze. Notice how
Rob Landley <rob@landley.net>
parents: 28
diff changeset
357 goto wow_this_sucks;
684
222886c9b3f5 Fix wrapper so it doesn't misinterpret -static-libgcc as -static.
Rob Landley <rob@landley.net>
parents: 550
diff changeset
358 } else if (!strcmp(argv[i], "--static")) {
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
359 use_static_linking = 1;
439
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
360 argv[i] = 0;
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
361 } else if (!strcmp("--version", argv[i])) {
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
362 printf("uClibc ");
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
363 fflush(stdout);
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
364 break;
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
365 } else if (!strcmp("--uclibc-cc", argv[i]) && argv[i+1]) {
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
366 cc = argv[i + 1];
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
367 argv[i] = 0;
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
368 argv[i + 1] = 0;
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
369 } else if (!strncmp ("--uclibc-cc=", argv[i], 12)) {
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
370 cc = argv[i] + 12;
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
371 argv[i] = 0;
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
372 } else if (!strcmp("--uclibc-no-ctors", argv[i])) {
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
373 ctor_dtor = 0;
439
f257bd255545 Next round of wrapper cleanups: give C++ includes a sane path, prefix environment variables with WRAPPER_, don't set pointers to a char '\0' value.
Rob Landley <rob@landley.net>
parents: 438
diff changeset
374 argv[i] = 0;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
375 }
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
376 break;
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
377 }
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
378 // assume it is an existing source file
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
379 } else ++source_count;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
380 }
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
381
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
382 argcnt = 0;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
383
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
384 gcc_argv[argcnt++] = cpp ? cpp : cc;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
385
447
4ed02d53fc92 Add C++ support to native compiler, based on uClibc++.
Rob Landley <rob@landley.net>
parents: 441
diff changeset
386 if (cpp) gcc_argv[argcnt++] = "-fno-use-cxa-atexit";
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
387
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
388 if (linking && source_count) {
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
389 //#if defined HAS_ELF && ! defined HAS_MMU
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
390 // gcc_argv[argcnt++] = "-Wl,-elf2flt";
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
391 //#endif
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
392 gcc_argv[argcnt++] = nostdlib;
684
222886c9b3f5 Fix wrapper so it doesn't misinterpret -static-libgcc as -static.
Rob Landley <rob@landley.net>
parents: 550
diff changeset
393 if (use_static_linking) gcc_argv[argcnt++] = "-static";
547
65b71915c836 Clean up ccwrap some more.
Rob Landley <rob@landley.net>
parents: 546
diff changeset
394 else if (dlstr) gcc_argv[argcnt++] = dlstr;
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
395 for (i=0; i<lplen; i++)
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
396 if (libpath[i]) gcc_argv[argcnt++] = libpath[i];
547
65b71915c836 Clean up ccwrap some more.
Rob Landley <rob@landley.net>
parents: 546
diff changeset
397
65b71915c836 Clean up ccwrap some more.
Rob Landley <rob@landley.net>
parents: 546
diff changeset
398 // just to be safe:
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
399 xasprintf(gcc_argv+(argcnt++), "-Wl,-rpath-link,%s/lib", devprefix);
547
65b71915c836 Clean up ccwrap some more.
Rob Landley <rob@landley.net>
parents: 546
diff changeset
400
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
401 if (libstr) gcc_argv[argcnt++] = libstr;
441
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
402
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
403 xasprintf(gcc_argv+(argcnt++), "-L%s/lib", devprefix);
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
404 xasprintf(gcc_argv+(argcnt++), "-L%s/gcc/lib", devprefix);
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
405 }
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
406 if (use_stdinc && source_count) {
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
407 gcc_argv[argcnt++] = nostdinc;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
408
447
4ed02d53fc92 Add C++ support to native compiler, based on uClibc++.
Rob Landley <rob@landley.net>
parents: 441
diff changeset
409 if (cpp) {
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
410 if (use_nostdinc_plus) gcc_argv[argcnt++] = nostdinc_plus;
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
411 gcc_argv[argcnt++] = "-isystem";
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
412 xasprintf(gcc_argv+(argcnt++), "%s/c++/include", devprefix);
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
413 }
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
414
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
415 gcc_argv[argcnt++] = "-isystem";
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
416 xasprintf(gcc_argv+(argcnt++), "%s/include", devprefix);
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
417 gcc_argv[argcnt++] = "-isystem";
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
418 xasprintf(gcc_argv+(argcnt++), "%s/gcc/include", devprefix);
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
419 if (incstr) gcc_argv[argcnt++] = incstr;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
420 }
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
421
800
d20b91530061 Be a little more consistent about space vs tab indentation.
Rob Landley <rob@landley.net>
parents: 748
diff changeset
422 gcc_argv[argcnt++] = "-U__nptl__";
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
423
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
424 if (linking && source_count) {
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
425
547
65b71915c836 Clean up ccwrap some more.
Rob Landley <rob@landley.net>
parents: 546
diff changeset
426 if (profile)
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
427 xasprintf(gcc_argv+(argcnt++), "%s/lib/gcrt1.o", devprefix);
547
65b71915c836 Clean up ccwrap some more.
Rob Landley <rob@landley.net>
parents: 546
diff changeset
428
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
429 if (ctor_dtor) {
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
430 xasprintf(gcc_argv+(argcnt++), "%s/lib/crti.o", devprefix);
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
431 xasprintf(gcc_argv+(argcnt++), "%s/gcc/lib/crtbegin%s", devprefix,
549
2edf40b17ee2 Select crtbegin.o and crtend.o variants more accurately for -static and -shared.
Rob Landley <rob@landley.net>
parents: 548
diff changeset
432 use_shared ? "S.o" : use_static_linking ? "T.o" : ".o");
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
433 }
441
8d14303eeca8 Upgrade --print-file-name to search $WRAPPER_DIR/lib, to print the directories it's trying when WRAPPER_DEBUG=1, and a few in-passing cleanups.
Rob Landley <rob@landley.net>
parents: 439
diff changeset
434 if (use_start && !profile)
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
435 xasprintf(gcc_argv+(argcnt++), "%s/lib/crt1.o", devprefix);
16
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
436
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
437 // Add remaining unclaimed arguments.
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
438
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
439 for (i=1; i<argc; i++) if (argv[i]) gcc_argv[argcnt++] = argv[i];
16
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
440
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
441 if (use_stdlib) {
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
442 //gcc_argv[argcnt++] = "-Wl,--start-group";
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
443 gcc_argv[argcnt++] = "-lgcc";
438
e9f3011ec40d Teach wrapper about libgcc_eh.a for static linking.
Rob Landley <rob@landley.net>
parents: 435
diff changeset
444 ADD_GCC_S();
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
445 }
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
446 for (i = 0 ; i < liblen ; i++)
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
447 if (libraries[i]) gcc_argv[argcnt++] = libraries[i];
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
448 if (use_stdlib) {
447
4ed02d53fc92 Add C++ support to native compiler, based on uClibc++.
Rob Landley <rob@landley.net>
parents: 441
diff changeset
449 if (cpp) {
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
450 gcc_argv[argcnt++] = "-lstdc++";
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
451 gcc_argv[argcnt++] = "-lm";
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
452 }
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
453 gcc_argv[argcnt++] = "-lc";
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
454 gcc_argv[argcnt++] = "-lgcc";
438
e9f3011ec40d Teach wrapper about libgcc_eh.a for static linking.
Rob Landley <rob@landley.net>
parents: 435
diff changeset
455 ADD_GCC_S();
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
456 //gcc_argv[argcnt++] = "-Wl,--end-group";
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
457 }
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
458 if (ctor_dtor) {
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
459 xasprintf(gcc_argv+(argcnt++), "%s/gcc/lib/crtend%s", devprefix,
549
2edf40b17ee2 Select crtbegin.o and crtend.o variants more accurately for -static and -shared.
Rob Landley <rob@landley.net>
parents: 548
diff changeset
460 use_shared ? "S.o" : ".o");
550
64779e0f6c28 Make spurious gcc 4.3 warnings shut up. (What a horrible compiler.)
Rob Landley <rob@landley.net>
parents: 549
diff changeset
461 xasprintf(gcc_argv+(argcnt++), "%s/lib/crtn.o", devprefix);
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
462 }
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
463 } else for (i=1; i<argc; i++) if (argv[i]) gcc_argv[argcnt++] = argv[i];
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
464
28
a6a06bf0c541 Replace single character variable names with ones that are easier to grep for.
Rob Landley <rob@landley.net>
parents: 22
diff changeset
465 gcc_argv[argcnt++] = NULL;
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
466
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
467 if (verbose) {
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
468 for (i=0; gcc_argv[i]; i++) printf("arg[%2i] = %s\n", i, gcc_argv[i]);
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
469 fflush(stdout);
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
470 }
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
471
42
7b0f34fbc35a Fix inappropriate activation of profiling support, and add environment variable
Rob Landley <rob@landley.net>
parents: 30
diff changeset
472 if (debug_wrapper) {
217
01fd30185476 Use fprintf(stderr,...) instead of dprintf(2,...) to be more portable.
Rob Landley <rob@landley.net>
parents: 76
diff changeset
473 fprintf(stderr, "outgoing: ");
548
b826a6168464 Coding style and whitespace cleanups, and remove one unnecessary if(cpp).
Rob Landley <rob@landley.net>
parents: 547
diff changeset
474 for (i=0; gcc_argv[i]; i++) fprintf(stderr, "%s ",gcc_argv[i]);
217
01fd30185476 Use fprintf(stderr,...) instead of dprintf(2,...) to be more portable.
Rob Landley <rob@landley.net>
parents: 76
diff changeset
475 fprintf(stderr, "\n\n");
42
7b0f34fbc35a Fix inappropriate activation of profiling support, and add environment variable
Rob Landley <rob@landley.net>
parents: 30
diff changeset
476 }
7b0f34fbc35a Fix inappropriate activation of profiling support, and add environment variable
Rob Landley <rob@landley.net>
parents: 30
diff changeset
477
16
7946bc54424b Some more work on the wrapper. Still doesn't work yet.
Rob Landley <rob@landley.net>
parents: 14
diff changeset
478 execvp(gcc_argv[0], gcc_argv);
14
8b4600334a3d Replace the path finding logic with the stuff from toybox.
Rob Landley <rob@landley.net>
parents: 13
diff changeset
479 fprintf(stderr, "%s: %s\n", cpp ? cpp : cc, strerror(errno));
13
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
480 exit(EXIT_FAILURE);
d34028ce8602 A version of the old uClibc wrapper script, which Chris Faylor maintained for
Rob Landley <rob@landley.net>
parents:
diff changeset
481 }