289 char *ae_arg;
290 } *ael_head, *ael_tail;
291 int ael_argc;
292 };
293
294 typedef enum {
295 GNU,
296 SUN,
297 SMATCH
298 } compiler_style_t;
299
300 typedef struct {
301 char *c_name;
302 char *c_path;
303 compiler_style_t c_style;
304 } cw_compiler_t;
305
306 typedef struct cw_ictx {
307 struct cw_ictx *i_next;
308 cw_compiler_t *i_compiler;
309 struct aelist *i_ae;
310 uint32_t i_flags;
311 int i_oldargc;
312 char **i_oldargv;
313 pid_t i_pid;
314 char *i_tmpdir;
315 char *i_stderr;
316 } cw_ictx_t;
317
318 /*
319 * Status values to indicate which Studio compiler and associated
320 * flags are being used.
321 */
322 #define M32 0x01 /* -m32 - only on Studio 12 */
323 #define M64 0x02 /* -m64 - only on Studio 12 */
324 #define SS11 0x100 /* Studio 11 */
325 #define SS12 0x200 /* Studio 12 */
326
327 #define TRANS_ENTRY 5
328 /*
1192 case 'h':
1193 case 'l':
1194 default:
1195 error(arg);
1196 break;
1197 }
1198 break;
1199 case 'Y':
1200 if (arglen == 1) {
1201 if ((arg = *++ctx->i_oldargv) == NULL ||
1202 *arg == '\0')
1203 error("-Y");
1204 ctx->i_oldargc--;
1205 arglen = strlen(arg + 1);
1206 } else {
1207 arg += 2;
1208 }
1209 /* Just ignore -YS,... for now */
1210 if (strncmp(arg, "S,", 2) == 0)
1211 break;
1212 if (strncmp(arg, "l,", 2) == 0) {
1213 char *s = strdup(arg);
1214 s[0] = '-';
1215 s[1] = 'B';
1216 newae(ctx->i_ae, s);
1217 free(s);
1218 break;
1219 }
1220 if (strncmp(arg, "I,", 2) == 0) {
1221 char *s = strdup(arg);
1222 s[0] = '-';
1223 s[1] = 'I';
1224 newae(ctx->i_ae, "-nostdinc");
1225 newae(ctx->i_ae, s);
1226 free(s);
1227 break;
1228 }
1229 error(arg);
1230 break;
1231 case 'Q':
1232 /*
1233 * We could map -Qy into -Wl,-Qy etc.
1234 */
1235 default:
1236 error(arg);
1237 break;
1238 }
1239 }
1451 exit(0);
1452 }
1453
1454 if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) {
1455 newae(ctx->i_ae, "-o");
1456 newae(ctx->i_ae, discard_file_name(ctx, NULL));
1457 }
1458 }
1459
1460 static void
1461 prepctx(cw_ictx_t *ctx)
1462 {
1463 newae(ctx->i_ae, ctx->i_compiler->c_path);
1464
1465 if (ctx->i_flags & CW_F_PROG) {
1466 (void) printf("%s: %s\n", (ctx->i_flags & CW_F_SHADOW) ?
1467 "shadow" : "primary", ctx->i_compiler->c_path);
1468 (void) fflush(stdout);
1469 }
1470
1471 if (!(ctx->i_flags & CW_F_XLATE))
1472 return;
1473
1474 switch (ctx->i_compiler->c_style) {
1475 case SUN:
1476 do_cc(ctx);
1477 break;
1478 case GNU:
1479 do_gcc(ctx);
1480 break;
1481 case SMATCH:
1482 do_smatch(ctx);
1483 break;
1484 }
1485 }
1486
1487 static int
1488 invoke(cw_ictx_t *ctx)
1489 {
1490 char **newargv;
1710 int
1711 main(int argc, char **argv)
1712 {
1713 int ch;
1714 cw_compiler_t primary = { NULL, NULL, 0 };
1715 cw_compiler_t shadows[10];
1716 int nshadows = 0;
1717 int ret = 0;
1718 boolean_t do_serial = B_FALSE;
1719 boolean_t do_exec = B_FALSE;
1720 boolean_t vflg = B_FALSE;
1721 boolean_t Cflg = B_FALSE;
1722 boolean_t cflg = B_FALSE;
1723 boolean_t nflg = B_FALSE;
1724 char *tmpdir;
1725
1726 cw_ictx_t *main_ctx;
1727
1728 static struct option longopts[] = {
1729 { "compiler", no_argument, NULL, 'c' },
1730 { "noecho", no_argument, NULL, 'n' },
1731 { "primary", required_argument, NULL, 'p' },
1732 { "shadow", required_argument, NULL, 's' },
1733 { "versions", no_argument, NULL, 'v' },
1734 { NULL, 0, NULL, 0 },
1735 };
1736
1737
1738 if ((main_ctx = newictx()) == NULL)
1739 nomem();
1740
1741 while ((ch = getopt_long(argc, argv, "C", longopts, NULL)) != -1) {
1742 switch (ch) {
1743 case 'c':
1744 cflg = B_TRUE;
1745 break;
1746 case 'C':
1747 Cflg = B_TRUE;
1748 break;
1749 case 'n':
1750 nflg = B_TRUE;
1751 break;
1752 case 'p':
1753 if (primary.c_path != NULL) {
1754 warnx("Only one primary compiler may "
1755 "be specified");
1756 usage();
1757 }
1758
1759 parse_compiler(optarg, &primary);
1760 break;
1761 case 's':
1762 if (nshadows >= 10)
1763 errx(1, "May only use 10 shadows at "
1764 "the moment");
1765 parse_compiler(optarg, &shadows[nshadows]);
1766 nshadows++;
1767 break;
|
289 char *ae_arg;
290 } *ael_head, *ael_tail;
291 int ael_argc;
292 };
293
294 typedef enum {
295 GNU,
296 SUN,
297 SMATCH
298 } compiler_style_t;
299
300 typedef struct {
301 char *c_name;
302 char *c_path;
303 compiler_style_t c_style;
304 } cw_compiler_t;
305
306 typedef struct cw_ictx {
307 struct cw_ictx *i_next;
308 cw_compiler_t *i_compiler;
309 char *i_linker;
310 struct aelist *i_ae;
311 uint32_t i_flags;
312 int i_oldargc;
313 char **i_oldargv;
314 pid_t i_pid;
315 char *i_tmpdir;
316 char *i_stderr;
317 } cw_ictx_t;
318
319 /*
320 * Status values to indicate which Studio compiler and associated
321 * flags are being used.
322 */
323 #define M32 0x01 /* -m32 - only on Studio 12 */
324 #define M64 0x02 /* -m64 - only on Studio 12 */
325 #define SS11 0x100 /* Studio 11 */
326 #define SS12 0x200 /* Studio 12 */
327
328 #define TRANS_ENTRY 5
329 /*
1193 case 'h':
1194 case 'l':
1195 default:
1196 error(arg);
1197 break;
1198 }
1199 break;
1200 case 'Y':
1201 if (arglen == 1) {
1202 if ((arg = *++ctx->i_oldargv) == NULL ||
1203 *arg == '\0')
1204 error("-Y");
1205 ctx->i_oldargc--;
1206 arglen = strlen(arg + 1);
1207 } else {
1208 arg += 2;
1209 }
1210 /* Just ignore -YS,... for now */
1211 if (strncmp(arg, "S,", 2) == 0)
1212 break;
1213 if (strncmp(arg, "I,", 2) == 0) {
1214 char *s = strdup(arg);
1215 s[0] = '-';
1216 s[1] = 'I';
1217 newae(ctx->i_ae, "-nostdinc");
1218 newae(ctx->i_ae, s);
1219 free(s);
1220 break;
1221 }
1222 error(arg);
1223 break;
1224 case 'Q':
1225 /*
1226 * We could map -Qy into -Wl,-Qy etc.
1227 */
1228 default:
1229 error(arg);
1230 break;
1231 }
1232 }
1444 exit(0);
1445 }
1446
1447 if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) {
1448 newae(ctx->i_ae, "-o");
1449 newae(ctx->i_ae, discard_file_name(ctx, NULL));
1450 }
1451 }
1452
1453 static void
1454 prepctx(cw_ictx_t *ctx)
1455 {
1456 newae(ctx->i_ae, ctx->i_compiler->c_path);
1457
1458 if (ctx->i_flags & CW_F_PROG) {
1459 (void) printf("%s: %s\n", (ctx->i_flags & CW_F_SHADOW) ?
1460 "shadow" : "primary", ctx->i_compiler->c_path);
1461 (void) fflush(stdout);
1462 }
1463
1464 if (ctx->i_linker != NULL)
1465 setenv("LD_ALTEXEC", ctx->i_linker, 1);
1466
1467 if (!(ctx->i_flags & CW_F_XLATE))
1468 return;
1469
1470 switch (ctx->i_compiler->c_style) {
1471 case SUN:
1472 do_cc(ctx);
1473 break;
1474 case GNU:
1475 do_gcc(ctx);
1476 break;
1477 case SMATCH:
1478 do_smatch(ctx);
1479 break;
1480 }
1481 }
1482
1483 static int
1484 invoke(cw_ictx_t *ctx)
1485 {
1486 char **newargv;
1706 int
1707 main(int argc, char **argv)
1708 {
1709 int ch;
1710 cw_compiler_t primary = { NULL, NULL, 0 };
1711 cw_compiler_t shadows[10];
1712 int nshadows = 0;
1713 int ret = 0;
1714 boolean_t do_serial = B_FALSE;
1715 boolean_t do_exec = B_FALSE;
1716 boolean_t vflg = B_FALSE;
1717 boolean_t Cflg = B_FALSE;
1718 boolean_t cflg = B_FALSE;
1719 boolean_t nflg = B_FALSE;
1720 char *tmpdir;
1721
1722 cw_ictx_t *main_ctx;
1723
1724 static struct option longopts[] = {
1725 { "compiler", no_argument, NULL, 'c' },
1726 { "linker", required_argument, NULL, 'l' },
1727 { "noecho", no_argument, NULL, 'n' },
1728 { "primary", required_argument, NULL, 'p' },
1729 { "shadow", required_argument, NULL, 's' },
1730 { "versions", no_argument, NULL, 'v' },
1731 { NULL, 0, NULL, 0 },
1732 };
1733
1734
1735 if ((main_ctx = newictx()) == NULL)
1736 nomem();
1737
1738 while ((ch = getopt_long(argc, argv, "C", longopts, NULL)) != -1) {
1739 switch (ch) {
1740 case 'c':
1741 cflg = B_TRUE;
1742 break;
1743 case 'C':
1744 Cflg = B_TRUE;
1745 break;
1746 case 'l':
1747 if ((main_ctx->i_linker = strdup(optarg)) == NULL)
1748 nomem();
1749 break;
1750 case 'n':
1751 nflg = B_TRUE;
1752 break;
1753 case 'p':
1754 if (primary.c_path != NULL) {
1755 warnx("Only one primary compiler may "
1756 "be specified");
1757 usage();
1758 }
1759
1760 parse_compiler(optarg, &primary);
1761 break;
1762 case 's':
1763 if (nshadows >= 10)
1764 errx(1, "May only use 10 shadows at "
1765 "the moment");
1766 parse_compiler(optarg, &shadows[nshadows]);
1767 nshadows++;
1768 break;
|