34988f driver, compile & link mode: support arbitrary & known compiler wrappers.

Authored and Committed by midipix 5 years ago
    driver, compile & link mode: support arbitrary & known compiler wrappers.
    
        
file modified
+1 -0
include/slibtool/slibtool.h CHANGED
@@ -244,6 +244,7 @@ struct slbt_common_ctx {
244
244
char ** cargv;
245
245
char ** targv;
246
246
char * libname;
247
+ const char * ccwrap;
247
248
const char * target;
248
249
const char * output;
249
250
const char * shrext;
file modified
+33 -6
src/driver/slbt_driver_ctx.c CHANGED
@@ -263,12 +263,14 @@ static int slbt_split_argv(
263
263
bool flast;
264
264
bool fcopy;
265
265
size_t size;
266
+ const char * base;
266
267
struct argv_meta * meta;
267
268
struct argv_entry * entry;
268
269
struct argv_entry * mode;
269
270
struct argv_entry * config;
270
271
struct argv_entry * finish;
271
272
struct argv_entry * features;
273
+ struct argv_entry * ccwrap;
272
274
const struct argv_option ** popt;
273
275
const struct argv_option ** optout;
274
276
const struct argv_option * optv[SLBT_OPTV_ELEMENTS];
@@ -311,7 +313,7 @@ static int slbt_split_argv(
311
313
}
312
314
313
315
/* missing all of --mode, --config, --features, and --finish? */
314
- mode = config = finish = features = 0;
316
+ mode = config = finish = features = ccwrap = 0;
315
317
316
318
for (entry=meta->entries; entry->fopt; entry++)
317
319
if (entry->tag == TAG_MODE)
@@ -322,6 +324,8 @@ static int slbt_split_argv(
322
324
finish = entry;
323
325
else if (entry->tag == TAG_FEATURES)
324
326
features = entry;
327
+ else if (entry->tag == TAG_CCWRAP)
328
+ ccwrap = entry;
325
329
326
330
argv_free(meta);
327
331
@@ -422,8 +426,8 @@ static int slbt_split_argv(
422
426
argv = sargv->dargv;
423
427
424
428
/* allocate split vectors */
425
- if ((sargv->targv = calloc(2*(argc+1),sizeof(char *))))
426
- sargv->cargv = sargv->targv + argc + 1;
429
+ if ((sargv->targv = calloc(2*(argc+2),sizeof(char *))))
430
+ sargv->cargv = sargv->targv + argc + 2;
427
431
else
428
432
return -1;
429
433
@@ -441,13 +445,32 @@ static int slbt_split_argv(
441
445
for (i=0; i<ctx.unitidx; i++)
442
446
sargv->targv[i] = argv[i];
443
447
448
+ /* split vector marks */
449
+ targv = sargv->targv + i;
450
+ cargv = sargv->cargv;
451
+
452
+ /* known wrappers */
453
+ if (ctx.unitidx && !ccwrap) {
454
+ if ((base = strrchr(argv[i],'/')))
455
+ base++;
456
+ else if ((base = strrchr(argv[i],'\\')))
457
+ base++;
458
+ else
459
+ base = argv[i];
460
+
461
+ if (!strcmp(base,"ccache")
462
+ || !strcmp(base,"distcc")
463
+ || !strcmp(base,"compiler")
464
+ || !strcmp(base,"purify")) {
465
+ *targv++ = "--ccwrap";
466
+ *targv++ = argv[i++];
467
+ }
468
+ }
469
+
444
470
/* split vectors: legacy mixture */
445
471
for (optout=optv; optout[0]->tag != TAG_OUTPUT; optout++)
446
472
(void)0;
447
473
448
- targv = sargv->targv + i;
449
- cargv = sargv->cargv;
450
-
451
474
for (; i<argc; i++) {
452
475
if (argv[i][0] != '-') {
453
476
if (argv[i+1] && (argv[i+1][0] == '+')
@@ -1332,6 +1355,10 @@ int slbt_get_driver_ctx(
1332
1355
1333
1356
break;
1334
1357
1358
+ case TAG_CCWRAP:
1359
+ cctx.ccwrap = entry->arg;
1360
+ break;
1361
+
1335
1362
case TAG_IMPLIB:
1336
1363
if (!strcmp("idata",entry->arg)) {
1337
1364
cctx.drvflags |= SLBT_DRIVER_IMPLIB_IDATA;
src/internal/slibtool_driver_impl.h CHANGED
@@ -35,6 +35,7 @@ enum app_tags {
35
35
TAG_DEPS,
36
36
TAG_SILENT,
37
37
TAG_TAG,
38
+ TAG_CCWRAP,
38
39
TAG_VERBOSE,
39
40
TAG_TARGET,
40
41
TAG_HOST,
file modified
+11 -3
src/logic/slbt_exec_compile.c CHANGED
@@ -43,6 +43,7 @@ static int slbt_exec_compile_finalize_argument_vector(
43
43
char ** cap;
44
44
char ** src;
45
45
char ** dst;
46
+ char * ccwrap;
46
47
47
48
/* vector size */
48
49
base = ectx->argv;
@@ -89,12 +90,17 @@ static int slbt_exec_compile_finalize_argument_vector(
89
90
}
90
91
}
91
92
92
- /* (program name) */
93
- dst = &base[1];
93
+ /* program name, ccwrap */
94
+ if ((ccwrap = (char *)dctx->cctx->ccwrap)) {
95
+ base[1] = base[0];
96
+ base[0] = ccwrap;
97
+ base++;
98
+ }
94
99
95
100
/* join all other args */
96
101
src = aargv;
97
102
cap = aarg;
103
+ dst = &base[1];
98
104
99
105
for (; src<cap; )
100
106
*dst++ = *src++;
@@ -126,6 +132,7 @@ int slbt_exec_compile(
126
132
{
127
133
int ret;
128
134
char * fpic;
135
+ char * ccwrap;
129
136
struct slbt_exec_ctx * actx = 0;
130
137
const struct slbt_common_ctx * cctx = dctx->cctx;
131
138
@@ -153,7 +160,8 @@ int slbt_exec_compile(
153
160
}
154
161
155
162
/* compile mode */
156
- ectx->program = ectx->compiler;
163
+ ccwrap = (char *)cctx->ccwrap;
164
+ ectx->program = ccwrap ? ccwrap : ectx->compiler;
157
165
ectx->argv = ectx->cargv;
158
166
159
167
/* -fpic */
file modified
+14 -4
src/logic/slbt_exec_link.c CHANGED
@@ -588,6 +588,7 @@ static int slbt_exec_link_finalize_argument_vector(
588
588
char ** dst;
589
589
char * arg;
590
590
char * dot;
591
+ char * ccwrap;
591
592
const char * arsuffix;
592
593
593
594
/* vector size */
@@ -717,12 +718,17 @@ static int slbt_exec_link_finalize_argument_vector(
717
718
}
718
719
}
719
720
720
- /* (program name) */
721
- dst = &base[1];
721
+ /* program name, ccwrap */
722
+ if ((ccwrap = (char *)dctx->cctx->ccwrap)) {
723
+ base[1] = base[0];
724
+ base[0] = ccwrap;
725
+ base++;
726
+ }
722
727
723
728
/* join object args */
724
729
src = oargv;
725
730
cap = oarg;
731
+ dst = &base[1];
726
732
727
733
for (; src<cap; )
728
734
*dst++ = *src++;
@@ -1254,6 +1260,7 @@ static int slbt_exec_link_create_library(
1254
1260
int fdcwd;
1255
1261
char ** parg;
1256
1262
char ** xarg;
1263
+ char * ccwrap;
1257
1264
char cwd [PATH_MAX];
1258
1265
char output [PATH_MAX];
1259
1266
char soname [PATH_MAX];
@@ -1399,8 +1406,9 @@ static int slbt_exec_link_create_library(
1399
1406
return SLBT_NESTED_ERROR(dctx);
1400
1407
1401
1408
/* using alternate argument vector */
1409
+ ccwrap = (char *)dctx->cctx->ccwrap;
1402
1410
ectx->argv = depsmeta.altv;
1403
- ectx->program = depsmeta.altv[0];
1411
+ ectx->program = ccwrap ? ccwrap : depsmeta.altv[0];
1404
1412
1405
1413
/* sigh */
1406
1414
if (slbt_exec_link_finalize_argument_vector(dctx,ectx))
@@ -1432,6 +1440,7 @@ static int slbt_exec_link_create_executable(
1432
1440
char ** parg;
1433
1441
char ** xarg;
1434
1442
char * base;
1443
+ char * ccwrap;
1435
1444
char cwd [PATH_MAX];
1436
1445
char output [PATH_MAX];
1437
1446
char wrapper[PATH_MAX];
@@ -1531,8 +1540,9 @@ static int slbt_exec_link_create_executable(
1531
1540
return SLBT_NESTED_ERROR(dctx);
1532
1541
1533
1542
/* using alternate argument vector */
1543
+ ccwrap = (char *)dctx->cctx->ccwrap;
1534
1544
ectx->argv = depsmeta.altv;
1535
- ectx->program = depsmeta.altv[0];
1545
+ ectx->program = ccwrap ? ccwrap : depsmeta.altv[0];
1536
1546
1537
1547
/* executable wrapper symlink */
1538
1548
if ((size_t)snprintf(wraplnk,sizeof(wraplnk),"%s.exe.wrapper",
file modified
+9 -0
src/skin/slbt_skin_default.c CHANGED
@@ -56,6 +56,15 @@ const struct argv_option slbt_default_options[] = {
56
56
"and/or static archive. option syntax is "
57
57
"--legabits[=%s]"},
58
58
59
+ {"ccwrap", 0,TAG_CCWRAP,ARGV_OPTARG_REQUIRED,0,0,
60
+ "<program>",
61
+ "use %s as a compiler driver wrapper; "
62
+ "for the purpose of compatibility, "
63
+ "this switch may be omitted for known "
64
+ "wrappers (ccache, compiler, distcc, "
65
+ "and purify) when immediately followed "
66
+ "by the compiler argument."},
67
+
59
68
{"no-warnings", 0,TAG_WARNINGS,ARGV_OPTARG_NONE,0,0,0,""},
60
69
61
70
{"preserve-dup-deps", 0,TAG_DEPS,ARGV_OPTARG_NONE,0,0,0,