Mercurial > hg > aboriginal
annotate sources/toys/ccwrap2.c @ 1660:c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 23 Jun 2014 06:01:02 -0500 |
parents | 38b18a4707dd |
children |
rev | line source |
---|---|
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 /* Copyright 2013 Rob Landley <rob@landley.net> |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 * |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 * C compiler wrapper. Parses command line, supplies path information for |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 * headers and libraries. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 */ |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 #undef _FORTIFY_SOURCE |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 #include <libgen.h> |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 #include <stdarg.h> |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 #include <stdio.h> |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 #include <stdlib.h> |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 #include <string.h> |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 #include <sys/stat.h> |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 #include <sys/types.h> |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 #include <unistd.h> |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 // Default to musl |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 #ifndef DYNAMIC_LINKER |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 #define DYNAMIC_LINKER "/lib/libc.so" |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 #endif |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 // Some plumbing from toybox |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 void *xmalloc(long len) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 void *ret = malloc(len); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 if (!ret) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 fprintf(stderr, "bad malloc\n"); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 exit(1); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 // Die unless we can allocate enough space to sprintf() into. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 char *xmprintf(char *format, ...) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 va_list va, va2; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 int len; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 char *ret; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
42 va_start(va, format); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
43 va_copy(va2, va); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
44 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
45 // How long is it? |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
46 len = vsnprintf(0, 0, format, va); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
47 len++; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
48 va_end(va); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
49 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
50 // Allocate and do the sprintf() |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 ret = xmalloc(len); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
52 vsnprintf(ret, len, format, va2); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 va_end(va2); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
54 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
55 return ret; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
56 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
58 // Confirm that a regular file exists, and (optionally) has the executable bit. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
59 int is_file(char *filename, int has_exe) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
60 { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
61 // Confirm it has the executable bit set, if necessary. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
62 if (!has_exe || !access(filename, X_OK)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
63 struct stat st; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
64 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
65 // Confirm it exists and is not a directory. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
66 if (!stat(filename, &st) && S_ISREG(st.st_mode)) return 1; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
67 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
68 return 0; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
69 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
70 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
71 // Find a file in a colon-separated path |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
72 char *find_in_path(char *path, char *filename, int has_exe) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
73 { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
74 char *cwd = getcwd(0, 0); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
75 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
76 if (index(filename, '/') && is_file(filename, has_exe)) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
77 return realpath(filename, 0); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
78 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
79 while (path) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
80 char *str, *next = path ? index(path, ':') : 0; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
81 int len = next ? next-path : strlen(path); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
82 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
83 if (!len) str = xmprintf("%s/%s", cwd, filename); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
84 else str = xmprintf("%*s/%s", len, path, filename); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
85 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
86 // If it's not a directory, return it. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
87 if (is_file(str, has_exe)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
88 char *s = realpath(str, 0); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
89 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
90 free(str); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
91 free(cwd); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
92 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
93 return s; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
94 } else free(str); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
95 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
96 if (next) next++; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
97 path = next; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
98 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
99 free(cwd); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
100 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
101 return NULL; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
102 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
103 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
104 struct dlist { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
105 struct dlist *next, *prev; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
106 char *str; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
107 }; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
108 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
109 // Append to end of doubly linked list (in-order insertion) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
110 void dlist_add(struct dlist **list, char *str) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
111 { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
112 struct dlist *new = xmalloc(sizeof(struct dlist)); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
113 |
1657
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
114 new->str = str; |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
115 if (*list) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
116 new->next = *list; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
117 new->prev = (*list)->prev; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
118 (*list)->prev->next = new; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
119 (*list)->prev = new; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
120 } else *list = new->next = new->prev = new; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
121 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
122 *list = new; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
123 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
124 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
125 // Some compiler versions don't provide separate T and S versions of begin/end, |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
126 // so fall back to the base version if they're not there. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
127 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
128 char *find_TSpath(char *base, char *top, int use_shared, int use_static_linking) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
129 { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
130 int i; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
131 char *temp; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
132 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
133 temp = xmprintf(base, top, |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
134 use_shared ? "S.o" : use_static_linking ? "T.o" : ".o"); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
135 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
136 if (!is_file(temp, 0)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
137 free(temp); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
138 temp = xmprintf(base, top, ".o"); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
139 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
140 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
141 return temp; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
142 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
143 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
144 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
145 enum { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
146 Clibccso, Clink, Cprofile, Cshared, Cstart, Cstatic, Cstdinc, Cstdlib, |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
147 Cverbose, Cx, Cdashdash, |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
148 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
149 CPctordtor, CP, CPstdinc |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
150 }; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
151 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
152 #define MASK_BIT(X) (1<<X) |
1657
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
153 #define SET_FLAG(X) (flags |= MASK_BIT(X)) |
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
154 #define CLEAR_FLAG(X) (flags &= ~MASK_BIT(X)) |
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
155 #define GET_FLAG(X) (flags & MASK_BIT(X)) |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
156 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
157 // Read the command line arguments and work out status |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
158 int main(int argc, char *argv[]) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
159 { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
160 char *topdir, *ccprefix, *dynlink, *cc, *temp, **keepv, **hdr, **outv; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
161 int i, keepc, srcfiles, flags, outc; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
162 struct dlist *libs = 0; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
163 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
164 keepv = xmalloc(argc*sizeof(char *)); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
165 flags = MASK_BIT(Clink)|MASK_BIT(Cstart)|MASK_BIT(Cstdinc)|MASK_BIT(Cstdlib) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
166 |MASK_BIT(CPctordtor); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
167 keepc = srcfiles = 0; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
168 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
169 if (getenv("CCWRAP_DEBUG")) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
170 SET_FLAG(Cverbose); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
171 fprintf(stderr, "incoming: "); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
172 for (i=0; i<argc; i++) fprintf(stderr, "%s ", argv[i]); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
173 fprintf(stderr, "\n\n"); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
174 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
175 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
176 // Find the cannonical path to the directory containing our executable |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
177 topdir = find_in_path(getenv("PATH"), *argv, 1); |
1657
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
178 if (!topdir || !(temp = rindex(topdir, '/')) || strlen(*argv)<2) { |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
179 fprintf(stderr, "Can't find %s in $PATH (did you export it?)\n", *argv); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
180 exit(1); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
181 } |
1657
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
182 // We want to strip off the bin/ but the path we followed can end with |
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
183 // a symlink, so append .. instead. |
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
184 strcpy(++temp, ".."); |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
185 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
186 // Add our binary's directory and the tools directory to $PATH so gcc's |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
187 // convulsive flailing probably blunders through here first. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
188 // Note: do this before reading topdir from environment variable, because |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
189 // toolchain binaries go with wrapper even if headers/libraries don't. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
190 temp = getenv("PATH"); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
191 if (!temp) temp = ""; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
192 temp = xmprintf("PATH=%s/bin:%s/tools/bin:%s", topdir, topdir, temp); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
193 putenv(temp); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
194 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
195 // Override header/library search path with environment variable? |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
196 temp = getenv("CCWRAP_TOPDIR"); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
197 if (!temp) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
198 cc = xmprintf("%sCCWRAP_TOPDIR", ccprefix); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
199 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
200 for (i=0; cc[i]; i++) if (cc[i] == '-') cc[i]='_'; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
201 temp = getenv(cc); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
202 free(cc); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
203 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
204 if (temp) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
205 free(topdir); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
206 topdir = temp; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
207 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
208 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
209 // Name of the C compiler we're wrapping. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
210 cc = getenv("CCWRAP_CC"); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
211 if (!cc) cc = "rawcc"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
212 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
213 // figure out cross compiler prefix |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
214 i = strlen(ccprefix = basename(*argv)); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
215 if (i<2) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
216 fprintf(stderr, "Bad name '%s'\n", ccprefix); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
217 exit(1); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
218 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
219 if (!strcmp("++", ccprefix+i-2)) { |
1660
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
220 cc = "raw++"; |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
221 SET_FLAG(CP); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
222 SET_FLAG(CPstdinc); |
1660
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
223 if (i<3) exit(1); |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
224 i -= 3; |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
225 } else if (!strcmp("gcc", ccprefix+i-3)) i -= 3; // TODO: yank |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
226 else if (!strcmp("cc", ccprefix+i-2)) i-=2; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
227 else if (!strcmp("cpp", ccprefix+i-3)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
228 i -= 3; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
229 CLEAR_FLAG(Clink); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
230 } else return 1; // TODO: wrap ld |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
231 if (!(ccprefix = strndup(ccprefix, i))) exit(1); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
232 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
233 // Does toolchain have a shared libcc? |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
234 temp = xmprintf("%s/lib/libgcc_s.so", topdir); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
235 if (is_file(temp, 0)) SET_FLAG(Clibccso); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
236 free(temp); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
237 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
238 // Where's the dynamic linker? |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
239 temp = getenv("CCWRAP_DYNAMIC_LINKER"); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
240 if (!temp) temp = DYNAMIC_LINKER; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
241 dynlink = xmprintf("-Wl,--dynamic-linker,%s", temp); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
242 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
243 // Fallback library search path, these will wind up at the end |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
244 dlist_add(&libs, xmprintf("%s/lib", topdir)); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
245 dlist_add(&libs, xmprintf("%s/cc/lib", topdir)); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
246 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
247 // Parse command line arguments |
1657
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
248 for (i=1; i<argc; i++) { |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
249 char *c = keepv[keepc++] = argv[i]; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
250 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
251 if (!strcmp(c, "--")) SET_FLAG(Cdashdash); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
252 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
253 // is this an option? |
1658
38b18a4707dd
More ccwrap debugging. "-" is an argument, not an option. Actually fall through to process --doubledash version of -singledash options. The -rpath-link line has the same visiblity as -L since it's link time path modification.
Rob Landley <rob@landley.net>
parents:
1657
diff
changeset
|
254 if (*c == '-' && c[1] && !GET_FLAG(Cdashdash)) c++; |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
255 else { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
256 srcfiles++; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
257 continue; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
258 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
259 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
260 // Second dash? |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
261 if (*c == '-') { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
262 // Passthrough double dash versions of single-dash options. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
263 if (!strncmp(c, "-print-", 7) || !strncmp(c, "-static", 7) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
264 || !strncmp(c, "-shared", 7)) c++; |
1658
38b18a4707dd
More ccwrap debugging. "-" is an argument, not an option. Actually fall through to process --doubledash version of -singledash options. The -rpath-link line has the same visiblity as -L since it's link time path modification.
Rob Landley <rob@landley.net>
parents:
1657
diff
changeset
|
265 else { |
38b18a4707dd
More ccwrap debugging. "-" is an argument, not an option. Actually fall through to process --doubledash version of -singledash options. The -rpath-link line has the same visiblity as -L since it's link time path modification.
Rob Landley <rob@landley.net>
parents:
1657
diff
changeset
|
266 if (!strcmp(c, "-no-ctors")) { |
38b18a4707dd
More ccwrap debugging. "-" is an argument, not an option. Actually fall through to process --doubledash version of -singledash options. The -rpath-link line has the same visiblity as -L since it's link time path modification.
Rob Landley <rob@landley.net>
parents:
1657
diff
changeset
|
267 CLEAR_FLAG(CPctordtor); |
38b18a4707dd
More ccwrap debugging. "-" is an argument, not an option. Actually fall through to process --doubledash version of -singledash options. The -rpath-link line has the same visiblity as -L since it's link time path modification.
Rob Landley <rob@landley.net>
parents:
1657
diff
changeset
|
268 keepc--; |
38b18a4707dd
More ccwrap debugging. "-" is an argument, not an option. Actually fall through to process --doubledash version of -singledash options. The -rpath-link line has the same visiblity as -L since it's link time path modification.
Rob Landley <rob@landley.net>
parents:
1657
diff
changeset
|
269 } |
38b18a4707dd
More ccwrap debugging. "-" is an argument, not an option. Actually fall through to process --doubledash version of -singledash options. The -rpath-link line has the same visiblity as -L since it's link time path modification.
Rob Landley <rob@landley.net>
parents:
1657
diff
changeset
|
270 continue; |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
271 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
272 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
273 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
274 // -M and -MM imply -E and thus no linking. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
275 // Other -M? options don't, including -MMD |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
276 if (*c == 'M' && c[1] && (c[1] != 'M' || c[2])) continue; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
277 |
1657
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
278 // compile, preprocess, assemble... options that suppress linking. |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
279 if (strchr("cEMS", *c)) CLEAR_FLAG(Clink); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
280 else if (*c == 'L') { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
281 if (c[1]) dlist_add(&libs, c+1); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
282 else if (!argv[++i]) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
283 fprintf(stderr, "-L at end of args\n"); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
284 exit(1); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
285 } else dlist_add(&libs, argv[i]); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
286 keepc--; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
287 } else if (*c == 'f') { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
288 if (!strcmp(c, "fprofile-arcs")) SET_FLAG(Cprofile); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
289 } else if (*c == 'n') { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
290 keepc--; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
291 if (!strcmp(c, "nodefaultlibs")) CLEAR_FLAG(Cstdlib); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
292 else if (!strcmp(c, "nostartfiles")) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
293 CLEAR_FLAG(CPctordtor); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
294 CLEAR_FLAG(Cstart); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
295 } else if (!strcmp(c, "nostdinc")) CLEAR_FLAG(Cstdinc); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
296 else if (!strcmp(c, "nostdinc++")) CLEAR_FLAG(CPstdinc); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
297 else if (!strcmp(c, "nostdlib")) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
298 CLEAR_FLAG(Cstdlib); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
299 CLEAR_FLAG(Cstart); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
300 CLEAR_FLAG(CPctordtor); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
301 } else keepc++; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
302 } else if (*c == 'p') { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
303 if (!strncmp(c, "print-", 6)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
304 struct dlist *dl; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
305 int show = 0; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
306 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
307 // Just add prefix to prog-name |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
308 if (!strncmp(c += 6, "prog-name=", 10)) { |
1660
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
309 printf("%s%s\n", ccprefix, c+10); |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
310 exit(0); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
311 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
312 |
1660
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
313 if (!strncmp(c, "file-name=", 10)) { |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
314 c += 10; |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
315 if (!strcmp(c, "include")) { |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
316 printf("%s/cc/include\n", topdir); |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
317 exit(0); |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
318 } |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
319 } else if (!strcmp(c, "search-dirs")) { |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
320 c = ""; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
321 show = 1; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
322 printf("install: %s/\nprograms: %s\nlibraries:", |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
323 topdir, getenv("PATH")); |
1660
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
324 } else if (!strcmp(c, "libgcc-file-name")) { |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
325 printf("%s/cc/lib/libgcc.a\n", topdir); |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
326 exit(0); |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
327 } |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
328 else break; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
329 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
330 // Adjust dlist before traversing (move fallback to end, break circle) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
331 libs = libs->next->next; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
332 libs->prev->next = 0; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
333 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
334 // Either display the list, or find first hit. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
335 for (dl = libs; dl; dl = dl->next) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
336 if (show) printf(":%s" + (dl==libs), dl->str); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
337 else if (!access(dl->str, F_OK)) break; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
338 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
339 if (dl) printf("%s", dl->str); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
340 printf("\n"); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
341 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
342 return 0; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
343 } else if (!strcmp(c, "pg")) SET_FLAG(Cprofile); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
344 } else if (*c == 's') { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
345 keepc--; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
346 if (!strcmp(c, "shared")) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
347 CLEAR_FLAG(Cstart); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
348 SET_FLAG(Cshared); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
349 } else if (!strcmp(c, "static")) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
350 SET_FLAG(Cstatic); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
351 CLEAR_FLAG(Clibccso); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
352 } else if (!strcmp(c, "shared-libgcc")) SET_FLAG(Clibccso); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
353 else if (!strcmp(c, "static-libgcc")) CLEAR_FLAG(Clibccso); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
354 else keepc++; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
355 } else if (*c == 'v' && !c[1]) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
356 SET_FLAG(Cverbose); |
1660
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
357 printf("ccwrap: %s\n", topdir); |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
358 } else if (!strncmp(c, "Wl,", 3)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
359 temp = strstr(c, ",-static"); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
360 if (temp && (!temp[8] || temp[8]==',')) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
361 SET_FLAG(Cstatic); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
362 CLEAR_FLAG(Clibccso); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
363 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
364 // This argument specifies dynamic linker, so we shouldn't. |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
365 if (strstr(c, "--dynamic-linker")) dynlink = 0; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
366 } else if (*c == 'x') SET_FLAG(Cx); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
367 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
368 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
369 // Initialize argument list for exec call |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
370 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
371 // what's a good outc size? |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
372 |
1660
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
373 outc = (argc+keepc+64)*sizeof(char *); |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
374 memset(outv = xmalloc(outc), 0, outc); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
375 outc = 0; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
376 outv[outc++] = cc; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
377 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
378 // Are we linking? |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
379 if (srcfiles) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
380 outv[outc++] = "-nostdinc"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
381 if (GET_FLAG(CP)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
382 outv[outc++] = "-nostdinc++"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
383 if (GET_FLAG(CPstdinc)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
384 outv[outc++] = "-isystem"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
385 outv[outc++] = xmprintf("%s/c++/include", topdir); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
386 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
387 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
388 if (GET_FLAG(Cstdinc)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
389 outv[outc++] = "-isystem"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
390 outv[outc++] = xmprintf("%s/include", topdir); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
391 outv[outc++] = "-isystem"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
392 outv[outc++] = xmprintf("%s/cc/include", topdir); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
393 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
394 if (GET_FLAG(Clink)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
395 // Zab defaults, add dynamic linker |
1657
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
396 outv[outc++] = "-nostdlib"; |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
397 outv[outc++] = GET_FLAG(Cstatic) ? "-static" : dynlink; |
1660
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
398 if (GET_FLAG(Cshared)) outv[outc++] = "-shared"; |
1658
38b18a4707dd
More ccwrap debugging. "-" is an argument, not an option. Actually fall through to process --doubledash version of -singledash options. The -rpath-link line has the same visiblity as -L since it's link time path modification.
Rob Landley <rob@landley.net>
parents:
1657
diff
changeset
|
399 |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
400 // Copy libraries to output (first move fallback to end, break circle) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
401 libs = libs->next->next; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
402 libs->prev->next = 0; |
1657
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
403 for (; libs; libs = libs->next) |
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
404 outv[outc++] = xmprintf("-L%s", libs->str); |
1658
38b18a4707dd
More ccwrap debugging. "-" is an argument, not an option. Actually fall through to process --doubledash version of -singledash options. The -rpath-link line has the same visiblity as -L since it's link time path modification.
Rob Landley <rob@landley.net>
parents:
1657
diff
changeset
|
405 outv[outc++] = xmprintf("-Wl,-rpath-link,%s/lib", topdir); // TODO: in? |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
406 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
407 // TODO: -fprofile-arcs |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
408 if (GET_FLAG(Cprofile)) xmprintf("%s/lib/gcrt1.o", topdir); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
409 if (GET_FLAG(CPctordtor)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
410 outv[outc++] = xmprintf("%s/lib/crti.o", topdir); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
411 outv[outc++] = find_TSpath("%s/cc/lib/crtbegin%s", topdir, |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
412 GET_FLAG(Cshared), GET_FLAG(Cstatic)); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
413 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
414 if (!GET_FLAG(Cprofile) && GET_FLAG(Cstart)) |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
415 outv[outc++] = xmprintf("%s/lib/%scrt1.o", topdir, |
1657
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
416 GET_FLAG(Cshared) ? "S" : ""); |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
417 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
418 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
419 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
420 // Copy unclaimed arguments |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
421 memcpy(outv+outc, keepv, keepc*sizeof(char *)); |
1657
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
422 outc += keepc; |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
423 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
424 if (srcfiles && GET_FLAG(Clink)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
425 if (GET_FLAG(Cx)) outv[outc++] = "-xnone"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
426 if (GET_FLAG(Cstdlib)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
427 if (GET_FLAG(CP)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
428 outv[outc++] = "-lstdc++"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
429 //outv[outc++] = "-lm"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
430 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
431 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
432 // libgcc can call libc which can call libgcc |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
433 outv[outc++] = "-Wl,--start-group,--as-needed"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
434 outv[outc++] = "-lgcc"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
435 if (GET_FLAG(Clibccso)) outv[outc++] = "-lgcc_s"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
436 else outv[outc++] = "-lgcc_eh"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
437 outv[outc++] = "-lc"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
438 outv[outc++] = "-Wl,--no-as-needed,--end-group"; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
439 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
440 if (GET_FLAG(CPctordtor)) { |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
441 outv[outc++] = find_TSpath("%s/cc/lib/crtend%s", topdir, |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
442 GET_FLAG(Cshared), GET_FLAG(Cstatic)); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
443 outv[outc++] = xmprintf("%s/lib/crtn.o", topdir); |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
444 } |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
445 } |
1657
84e47eac0f28
First round of bug fixes for new ccwrap.
Rob Landley <rob@landley.net>
parents:
1656
diff
changeset
|
446 outv[outc] = 0; |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
447 |
1660
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
448 if (getenv("CCWRAP_DEBUG")) { |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
449 fprintf(stderr, "outgoing:"); |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
450 for(i=0; i<outc; i++) printf(stderr, " \"%s\"", outv[i]); |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
451 fprintf(stderr, "\n"); |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
452 } |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
453 |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
454 execvp(*outv, outv); |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
455 fprintf(stderr, "%s: %s\n", *outv, strerror(errno)); |
c1addb6ebb84
More fixes from testing. Swap testing code for exec code.
Rob Landley <rob@landley.net>
parents:
1658
diff
changeset
|
456 exit(1); |
1656
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
457 |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
458 return 0; |
00928b6d7895
First pass at ccwrap rewrite for (among other things) musl support.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
459 } |