Mercurial > hg > aboriginal
comparison 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 |
comparison
equal
deleted
inserted
replaced
1659:56b1418d6fc7 | 1660:c1addb6ebb84 |
---|---|
158 int main(int argc, char *argv[]) | 158 int main(int argc, char *argv[]) |
159 { | 159 { |
160 char *topdir, *ccprefix, *dynlink, *cc, *temp, **keepv, **hdr, **outv; | 160 char *topdir, *ccprefix, *dynlink, *cc, *temp, **keepv, **hdr, **outv; |
161 int i, keepc, srcfiles, flags, outc; | 161 int i, keepc, srcfiles, flags, outc; |
162 struct dlist *libs = 0; | 162 struct dlist *libs = 0; |
163 | |
164 argc--; | |
165 argv++; | |
166 | 163 |
167 keepv = xmalloc(argc*sizeof(char *)); | 164 keepv = xmalloc(argc*sizeof(char *)); |
168 flags = MASK_BIT(Clink)|MASK_BIT(Cstart)|MASK_BIT(Cstdinc)|MASK_BIT(Cstdlib) | 165 flags = MASK_BIT(Clink)|MASK_BIT(Cstart)|MASK_BIT(Cstdinc)|MASK_BIT(Cstdlib) |
169 |MASK_BIT(CPctordtor); | 166 |MASK_BIT(CPctordtor); |
170 keepc = srcfiles = 0; | 167 keepc = srcfiles = 0; |
218 if (i<2) { | 215 if (i<2) { |
219 fprintf(stderr, "Bad name '%s'\n", ccprefix); | 216 fprintf(stderr, "Bad name '%s'\n", ccprefix); |
220 exit(1); | 217 exit(1); |
221 } | 218 } |
222 if (!strcmp("++", ccprefix+i-2)) { | 219 if (!strcmp("++", ccprefix+i-2)) { |
223 cc = xmprintf("%s++", cc); | 220 cc = "raw++"; |
224 SET_FLAG(CP); | 221 SET_FLAG(CP); |
225 SET_FLAG(CPstdinc); | 222 SET_FLAG(CPstdinc); |
226 } | 223 if (i<3) exit(1); |
227 if (!strcmp("gcc", ccprefix+i-3)) i -= 3; // TODO: yank | 224 i -= 3; |
225 } else if (!strcmp("gcc", ccprefix+i-3)) i -= 3; // TODO: yank | |
228 else if (!strcmp("cc", ccprefix+i-2)) i-=2; | 226 else if (!strcmp("cc", ccprefix+i-2)) i-=2; |
229 else if (!strcmp("cpp", ccprefix+i-3)) { | 227 else if (!strcmp("cpp", ccprefix+i-3)) { |
230 i -= 3; | 228 i -= 3; |
231 CLEAR_FLAG(Clink); | 229 CLEAR_FLAG(Clink); |
232 } else return 1; // TODO: wrap ld | 230 } else return 1; // TODO: wrap ld |
306 struct dlist *dl; | 304 struct dlist *dl; |
307 int show = 0; | 305 int show = 0; |
308 | 306 |
309 // Just add prefix to prog-name | 307 // Just add prefix to prog-name |
310 if (!strncmp(c += 6, "prog-name=", 10)) { | 308 if (!strncmp(c += 6, "prog-name=", 10)) { |
311 printf("%s%s", ccprefix, c+10); | 309 printf("%s%s\n", ccprefix, c+10); |
312 exit(0); | 310 exit(0); |
313 } | 311 } |
314 | 312 |
315 if (!strncmp(c, "file-name=", 10)) c += 10; | 313 if (!strncmp(c, "file-name=", 10)) { |
316 else if (!strcmp(c, "search-dirs")) { | 314 c += 10; |
315 if (!strcmp(c, "include")) { | |
316 printf("%s/cc/include\n", topdir); | |
317 exit(0); | |
318 } | |
319 } else if (!strcmp(c, "search-dirs")) { | |
317 c = ""; | 320 c = ""; |
318 show = 1; | 321 show = 1; |
319 printf("install: %s/\nprograms: %s\nlibraries:", | 322 printf("install: %s/\nprograms: %s\nlibraries:", |
320 topdir, getenv("PATH")); | 323 topdir, getenv("PATH")); |
321 } else if (!strcmp(c, "libgcc-file-name")) c = "libgcc.a"; | 324 } else if (!strcmp(c, "libgcc-file-name")) { |
325 printf("%s/cc/lib/libgcc.a\n", topdir); | |
326 exit(0); | |
327 } | |
322 else break; | 328 else break; |
323 | 329 |
324 // Adjust dlist before traversing (move fallback to end, break circle) | 330 // Adjust dlist before traversing (move fallback to end, break circle) |
325 libs = libs->next->next; | 331 libs = libs->next->next; |
326 libs->prev->next = 0; | 332 libs->prev->next = 0; |
346 } else if (!strcmp(c, "shared-libgcc")) SET_FLAG(Clibccso); | 352 } else if (!strcmp(c, "shared-libgcc")) SET_FLAG(Clibccso); |
347 else if (!strcmp(c, "static-libgcc")) CLEAR_FLAG(Clibccso); | 353 else if (!strcmp(c, "static-libgcc")) CLEAR_FLAG(Clibccso); |
348 else keepc++; | 354 else keepc++; |
349 } else if (*c == 'v' && !c[1]) { | 355 } else if (*c == 'v' && !c[1]) { |
350 SET_FLAG(Cverbose); | 356 SET_FLAG(Cverbose); |
351 printf("%s: %s\n", argv[0], topdir); | 357 printf("ccwrap: %s\n", topdir); |
352 } else if (!strncmp(c, "Wl,", 3)) { | 358 } else if (!strncmp(c, "Wl,", 3)) { |
353 temp = strstr(c, ",-static"); | 359 temp = strstr(c, ",-static"); |
354 if (temp && (!temp[8] || temp[8]==',')) { | 360 if (temp && (!temp[8] || temp[8]==',')) { |
355 SET_FLAG(Cstatic); | 361 SET_FLAG(Cstatic); |
356 CLEAR_FLAG(Clibccso); | 362 CLEAR_FLAG(Clibccso); |
362 | 368 |
363 // Initialize argument list for exec call | 369 // Initialize argument list for exec call |
364 | 370 |
365 // what's a good outc size? | 371 // what's a good outc size? |
366 | 372 |
367 outc = (argc+keepc+32)*sizeof(char *); | 373 outc = (argc+keepc+64)*sizeof(char *); |
368 memset(outv = xmalloc(outc), 0, outc); | 374 memset(outv = xmalloc(outc), 0, outc); |
369 outc = 0; | 375 outc = 0; |
370 outv[outc++] = cc; | 376 outv[outc++] = cc; |
371 | 377 |
372 // Are we linking? | 378 // Are we linking? |
387 } | 393 } |
388 if (GET_FLAG(Clink)) { | 394 if (GET_FLAG(Clink)) { |
389 // Zab defaults, add dynamic linker | 395 // Zab defaults, add dynamic linker |
390 outv[outc++] = "-nostdlib"; | 396 outv[outc++] = "-nostdlib"; |
391 outv[outc++] = GET_FLAG(Cstatic) ? "-static" : dynlink; | 397 outv[outc++] = GET_FLAG(Cstatic) ? "-static" : dynlink; |
398 if (GET_FLAG(Cshared)) outv[outc++] = "-shared"; | |
392 | 399 |
393 // Copy libraries to output (first move fallback to end, break circle) | 400 // Copy libraries to output (first move fallback to end, break circle) |
394 libs = libs->next->next; | 401 libs = libs->next->next; |
395 libs->prev->next = 0; | 402 libs->prev->next = 0; |
396 for (; libs; libs = libs->next) | 403 for (; libs; libs = libs->next) |
436 outv[outc++] = xmprintf("%s/lib/crtn.o", topdir); | 443 outv[outc++] = xmprintf("%s/lib/crtn.o", topdir); |
437 } | 444 } |
438 } | 445 } |
439 outv[outc] = 0; | 446 outv[outc] = 0; |
440 | 447 |
441 for(i=0; i<outc; i++) printf("\"%s\" ", outv[i]); | 448 if (getenv("CCWRAP_DEBUG")) { |
442 printf("\n"); | 449 fprintf(stderr, "outgoing:"); |
450 for(i=0; i<outc; i++) printf(stderr, " \"%s\"", outv[i]); | |
451 fprintf(stderr, "\n"); | |
452 } | |
453 | |
454 execvp(*outv, outv); | |
455 fprintf(stderr, "%s: %s\n", *outv, strerror(errno)); | |
456 exit(1); | |
443 | 457 |
444 return 0; | 458 return 0; |
445 } | 459 } |