Print this page
5196 The cw wrapper restricts gcc to -O2
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/cw/cw.c
+++ new/usr/src/tools/cw/cw.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 + * Copyright 2014 Gary Mills
24 + *
23 25 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 26 * Use is subject to license terms.
25 27 */
26 28
27 29 /*
28 30 * Wrapper for the GNU C compiler to make it accept the Sun C compiler
29 31 * arguments where possible.
30 32 *
31 33 * Since the translation is inexact, this is something of a work-in-progress.
32 34 *
33 35 */
34 36
35 37 /* If you modify this file, you must increment CW_VERSION */
36 -#define CW_VERSION "1.29"
38 +#define CW_VERSION "1.30"
37 39
38 40 /*
39 41 * -# Verbose mode
40 42 * -### Show compiler commands built by driver, no compilation
41 43 * -A<name[(tokens)]> Preprocessor predicate assertion
42 44 * -B<[static|dynamic]> Specify dynamic or static binding
43 45 * -C Prevent preprocessor from removing comments
44 46 * -c Compile only - produce .o files, suppress linking
45 47 * -cg92 Alias for -xtarget=ss1000
46 48 * -D<name[=token]> Associate name with token as if by #define
47 49 * -d[y|n] dynamic [-dy] or static [-dn] option to linker
48 50 * -E Compile source through preprocessor only, output to stdout
49 51 * -erroff=<t> Suppress warnings specified by tags t(%none, %all, <tag list>)
50 52 * -errtags=<a> Display messages with tags a(no, yes)
51 53 * -errwarn=<t> Treats warnings specified by tags t(%none, %all, <tag list>)
52 54 * as errors
53 55 * -fast Optimize using a selection of options
54 56 * -fd Report old-style function definitions and declarations
55 57 * -features=zla Allow zero-length arrays
56 58 * -flags Show this summary of compiler options
57 59 * -fnonstd Initialize floating-point hardware to non-standard preferences
58 60 * -fns[=<yes|no>] Select non-standard floating point mode
59 61 * -fprecision=<p> Set FP rounding precision mode p(single, double, extended)
60 62 * -fround=<r> Select the IEEE rounding mode in effect at startup
61 63 * -fsimple[=<n>] Select floating-point optimization preferences <n>
62 64 * -fsingle Use single-precision arithmetic (-Xt and -Xs modes only)
63 65 * -ftrap=<t> Select floating-point trapping mode in effect at startup
64 66 * -fstore force floating pt. values to target precision on assignment
65 67 * -G Build a dynamic shared library
66 68 * -g Compile for debugging
67 69 * -H Print path name of each file included during compilation
68 70 * -h <name> Assign <name> to generated dynamic shared library
69 71 * -I<dir> Add <dir> to preprocessor #include file search path
70 72 * -i Passed to linker to ignore any LD_LIBRARY_PATH setting
71 73 * -keeptmp Keep temporary files created during compilation
72 74 * -KPIC Compile position independent code with 32-bit addresses
73 75 * -Kpic Compile position independent code
74 76 * -L<dir> Pass to linker to add <dir> to the library search path
75 77 * -l<name> Link with library lib<name>.a or lib<name>.so
76 78 * -mc Remove duplicate strings from .comment section of output files
77 79 * -mr Remove all strings from .comment section of output files
78 80 * -mr,"string" Remove all strings and append "string" to .comment section
79 81 * -mt Specify options needed when compiling multi-threaded code
80 82 * -native Find available processor, generate code accordingly
81 83 * -nofstore Do not force floating pt. values to target precision
82 84 * on assignment
83 85 * -nolib Same as -xnolib
84 86 * -noqueue Disable queuing of compiler license requests
85 87 * -norunpath Do not build in a runtime path for shared libraries
86 88 * -O Use default optimization level (-xO2 or -xO3. Check man page.)
87 89 * -o <outputfile> Set name of output file to <outputfile>
88 90 * -P Compile source through preprocessor only, output to .i file
89 91 * -PIC Alias for -KPIC or -xcode=pic32
90 92 * -p Compile for profiling with prof
91 93 * -pic Alias for -Kpic or -xcode=pic13
92 94 * -Q[y|n] Emit/don't emit identification info to output file
93 95 * -qp Compile for profiling with prof
94 96 * -R<dir[:dir]> Build runtime search path list into executable
95 97 * -S Compile and only generate assembly code (.s)
96 98 * -s Strip symbol table from the executable file
97 99 * -t Turn off duplicate symbol warnings when linking
98 100 * -U<name> Delete initial definition of preprocessor symbol <name>
99 101 * -V Report version number of each compilation phase
100 102 * -v Do stricter semantic checking
101 103 * -W<c>,<arg> Pass <arg> to specified component <c> (a,l,m,p,0,2,h,i,u)
102 104 * -w Suppress compiler warning messages
103 105 * -Xa Compile assuming ANSI C conformance, allow K & R extensions
104 106 * (default mode)
105 107 * -Xc Compile assuming strict ANSI C conformance
106 108 * -Xs Compile assuming (pre-ANSI) K & R C style code
107 109 * -Xt Compile assuming K & R conformance, allow ANSI C
108 110 * -x386 Generate code for the 80386 processor
109 111 * -x486 Generate code for the 80486 processor
110 112 * -xarch=<a> Specify target architecture instruction set
111 113 * -xbuiltin[=<b>] When profitable inline, or substitute intrinisic functions
112 114 * for system functions, b={%all,%none}
113 115 * -xCC Accept C++ style comments
114 116 * -xchar_byte_order=<o> Specify multi-char byte order <o> (default, high, low)
115 117 * -xchip=<c> Specify the target processor for use by the optimizer
116 118 * -xcode=<c> Generate different code for forming addresses
117 119 * -xcrossfile[=<n>] Enable optimization and inlining across source files,
118 120 * n={0|1}
119 121 * -xe Perform only syntax/semantic checking, no code generation
120 122 * -xF Compile for later mapfile reordering or unused section
121 123 * elimination
122 124 * -xhelp=<f> Display on-line help information f(flags, readme, errors)
123 125 * -xildoff Cancel -xildon
124 126 * -xildon Enable use of the incremental linker, ild
125 127 * -xinline=[<a>,...,<a>] Attempt inlining of specified user routines,
126 128 * <a>={%auto,func,no%func}
127 129 * -xlibmieee Force IEEE 754 return values for math routines in
128 130 * exceptional cases
129 131 * -xlibmil Inline selected libm math routines for optimization
130 132 * -xlic_lib=sunperf Link in the Sun supplied performance libraries
131 133 * -xlicinfo Show license server information
132 134 * -xM Generate makefile dependencies
133 135 * -xM1 Generate makefile dependencies, but exclude /usr/include
134 136 * -xmaxopt=[off,1,2,3,4,5] maximum optimization level allowed on #pragma opt
135 137 * -xnolib Do not link with default system libraries
136 138 * -xnolibmil Cancel -xlibmil on command line
137 139 * -xO<n> Generate optimized code (n={1|2|3|4|5})
138 140 * -xP Print prototypes for function definitions
139 141 * -xpentium Generate code for the pentium processor
140 142 * -xpg Compile for profiling with gprof
141 143 * -xprofile=<p> Collect data for a profile or use a profile to optimize
142 144 * <p>={{collect,use}[:<path>],tcov}
143 145 * -xregs=<r> Control register allocation
144 146 * -xs Allow debugging without object (.o) files
145 147 * -xsb Compile for use with the WorkShop source browser
146 148 * -xsbfast Generate only WorkShop source browser info, no compilation
147 149 * -xsfpconst Represent unsuffixed floating point constants as single
148 150 * precision
149 151 * -xspace Do not do optimizations that increase code size
150 152 * -xstrconst Place string literals into read-only data segment
151 153 * -xtarget=<t> Specify target system for optimization
152 154 * -xtemp=<dir> Set directory for temporary files to <dir>
153 155 * -xtime Report the execution time for each compilation phase
154 156 * -xtransition Emit warnings for differences between K&R C and ANSI C
155 157 * -xtrigraphs[=<yes|no>] Enable|disable trigraph translation
156 158 * -xunroll=n Enable unrolling loops n times where possible
157 159 * -Y<c>,<dir> Specify <dir> for location of component <c> (a,l,m,p,0,h,i,u)
158 160 * -YA,<dir> Change default directory searched for components
159 161 * -YI,<dir> Change default directory searched for include files
160 162 * -YP,<dir> Change default directory for finding libraries files
161 163 * -YS,<dir> Change default directory for startup object files
162 164 */
163 165
164 166 /*
165 167 * Translation table:
166 168 */
167 169 /*
168 170 * -# -v
169 171 * -### error
170 172 * -A<name[(tokens)]> pass-thru
171 173 * -B<[static|dynamic]> pass-thru (syntax error for anything else)
172 174 * -C pass-thru
173 175 * -c pass-thru
174 176 * -cg92 -m32 -mcpu=v8 -mtune=supersparc (SPARC only)
175 177 * -D<name[=token]> pass-thru
176 178 * -dy or -dn -Wl,-dy or -Wl,-dn
177 179 * -E pass-thru
178 180 * -erroff=E_EMPTY_TRANSLATION_UNIT ignore
179 181 * -errtags=%all -Wall
180 182 * -errwarn=%all -Werror else -Wno-error
181 183 * -fast error
182 184 * -fd error
183 185 * -features=zla ignore
184 186 * -flags --help
185 187 * -fnonstd error
186 188 * -fns[=<yes|no>] error
187 189 * -fprecision=<p> error
188 190 * -fround=<r> error
189 191 * -fsimple[=<n>] error
190 192 * -fsingle[=<n>] error
191 193 * -ftrap=<t> error
192 194 * -fstore error
193 195 * -G pass-thru
194 196 * -g pass-thru
195 197 * -H pass-thru
196 198 * -h <name> pass-thru
197 199 * -I<dir> pass-thru
198 200 * -i pass-thru
199 201 * -keeptmp -save-temps
200 202 * -KPIC -fPIC
201 203 * -Kpic -fpic
202 204 * -L<dir> pass-thru
203 205 * -l<name> pass-thru
204 206 * -mc error
205 207 * -mr error
206 208 * -mr,"string" error
207 209 * -mt -D_REENTRANT
208 210 * -native error
209 211 * -nofstore error
210 212 * -nolib -nodefaultlibs
211 213 * -noqueue ignore
212 214 * -norunpath ignore
213 215 * -O -O1 (Check the man page to be certain)
214 216 * -o <outputfile> pass-thru
215 217 * -P -E -o filename.i (or error)
216 218 * -PIC -fPIC (C++ only)
217 219 * -p pass-thru
218 220 * -pic -fpic (C++ only)
219 221 * -Q[y|n] error
220 222 * -qp -p
221 223 * -R<dir[:dir]> pass-thru
222 224 * -S pass-thru
223 225 * -s -Wl,-s
224 226 * -t -Wl,-t
225 227 * -U<name> pass-thru
226 228 * -V --version
227 229 * -v -Wall
228 230 * -Wa,<arg> pass-thru
229 231 * -Wp,<arg> pass-thru except -xc99=<a>
230 232 * -Wl,<arg> pass-thru
231 233 * -W{m,0,2,h,i,u> error/ignore
232 234 * -Wu,-xmodel=kernel -ffreestanding -mcmodel=kernel -mno-red-zone
233 235 * -xmodel=kernel -ffreestanding -mcmodel=kernel -mno-red-zone
234 236 * -Wu,-save_args -msave-args
235 237 * -w pass-thru
236 238 * -Xa -std=iso9899:199409 or -ansi
237 239 * -Xc -ansi -pedantic
238 240 * -Xt error
239 241 * -Xs -traditional -std=c89
240 242 * -x386 -march=i386 (x86 only)
241 243 * -x486 -march=i486 (x86 only)
242 244 * -xarch=<a> table
243 245 * -xbuiltin[=<b>] -fbuiltin (-fno-builtin otherwise)
244 246 * -xCC ignore
245 247 * -xchar_byte_order=<o> error
246 248 * -xchip=<c> table
247 249 * -xcode=<c> table
248 250 * -xdebugformat=<format> ignore (always use dwarf-2 for gcc)
249 251 * -xcrossfile[=<n>] ignore
250 252 * -xe error
251 253 * -xF error
252 254 * -xhelp=<f> error
253 255 * -xildoff ignore
254 256 * -xildon ignore
255 257 * -xinline ignore
256 258 * -xlibmieee error
257 259 * -xlibmil error
258 260 * -xlic_lib=sunperf error
259 261 * -xM -M
260 262 * -xM1 -MM
261 263 * -xmaxopt=[...] error
262 264 * -xnolib -nodefaultlibs
263 265 * -xnolibmil error
264 266 * -xO<n> -O<n>
265 267 * -xP error
266 268 * -xpentium -march=pentium (x86 only)
267 269 * -xpg error
268 270 * -xprofile=<p> error
269 271 * -xregs=<r> table
270 272 * -xs error
271 273 * -xsb error
272 274 * -xsbfast error
273 275 * -xsfpconst error
274 276 * -xspace ignore (-not -Os)
275 277 * -xstrconst ignore
276 278 * -xtarget=<t> table
277 279 * -xtemp=<dir> error
278 280 * -xtime error
279 281 * -xtransition -Wtransition
280 282 * -xtrigraphs=<yes|no> -trigraphs -notrigraphs
281 283 * -xunroll=n error
282 284 * -W0,-xdbggen=no%usedonly -fno-eliminate-unused-debug-symbols
283 285 * -fno-eliminate-unused-debug-types
284 286 * -Y<c>,<dir> error
285 287 * -YA,<dir> error
286 288 * -YI,<dir> -nostdinc -I<dir>
287 289 * -YP,<dir> error
288 290 * -YS,<dir> error
289 291 */
290 292
291 293 #include <stdio.h>
292 294 #include <sys/types.h>
293 295 #include <unistd.h>
294 296 #include <string.h>
295 297 #include <stdlib.h>
296 298 #include <ctype.h>
297 299 #include <fcntl.h>
298 300 #include <errno.h>
299 301 #include <stdarg.h>
300 302 #include <sys/utsname.h>
301 303 #include <sys/param.h>
302 304 #include <sys/isa_defs.h>
303 305 #include <sys/wait.h>
304 306 #include <sys/stat.h>
305 307
306 308 #define CW_F_CXX 0x01
307 309 #define CW_F_SHADOW 0x02
308 310 #define CW_F_EXEC 0x04
309 311 #define CW_F_ECHO 0x08
310 312 #define CW_F_XLATE 0x10
311 313 #define CW_F_PROG 0x20
312 314
313 315 typedef enum cw_compiler {
314 316 CW_C_CC = 0,
315 317 CW_C_GCC
316 318 } cw_compiler_t;
317 319
318 320 static const char *cmds[] = {
319 321 "cc", "CC",
320 322 "gcc", "g++"
321 323 };
322 324
323 325 static char default_dir[2][MAXPATHLEN] = {
324 326 DEFAULT_CC_DIR,
325 327 DEFAULT_GCC_DIR,
326 328 };
327 329
328 330 #define CC(ctx) \
329 331 (((ctx)->i_flags & CW_F_SHADOW) ? \
330 332 ((ctx)->i_compiler == CW_C_CC ? CW_C_GCC : CW_C_CC) : \
331 333 (ctx)->i_compiler)
332 334
333 335 #define CIDX(compiler, flags) \
334 336 ((int)(compiler) << 1) + ((flags) & CW_F_CXX ? 1 : 0)
335 337
336 338 typedef enum cw_op {
337 339 CW_O_NONE = 0,
338 340 CW_O_PREPROCESS,
339 341 CW_O_COMPILE,
340 342 CW_O_LINK
341 343 } cw_op_t;
342 344
343 345 struct aelist {
344 346 struct ae {
345 347 struct ae *ae_next;
346 348 char *ae_arg;
347 349 } *ael_head, *ael_tail;
348 350 int ael_argc;
349 351 };
350 352
351 353 typedef struct cw_ictx {
352 354 cw_compiler_t i_compiler;
353 355 struct aelist *i_ae;
354 356 uint32_t i_flags;
355 357 int i_oldargc;
356 358 char **i_oldargv;
357 359 pid_t i_pid;
358 360 char i_discard[MAXPATHLEN];
359 361 char *i_stderr;
360 362 } cw_ictx_t;
361 363
362 364 /*
363 365 * Status values to indicate which Studio compiler and associated
364 366 * flags are being used.
365 367 */
366 368 #define M32 0x01 /* -m32 - only on Studio 12 */
367 369 #define M64 0x02 /* -m64 - only on Studio 12 */
368 370 #define SS11 0x100 /* Studio 11 */
369 371 #define SS12 0x200 /* Studio 12 */
370 372
371 373 #define TRANS_ENTRY 5
372 374 /*
373 375 * Translation table definition for the -xarch= flag. The "x_arg"
374 376 * value is translated into the appropriate gcc flags according
375 377 * to the values in x_trans[n]. The x_flags indicates what compiler
376 378 * is being used and what flags have been set via the use of
377 379 * "x_arg".
378 380 */
379 381 typedef struct xarch_table {
380 382 char *x_arg;
381 383 int x_flags;
382 384 char *x_trans[TRANS_ENTRY];
383 385 } xarch_table_t;
384 386
385 387 /*
386 388 * The translation table for the -xarch= flag used in the Studio compilers.
387 389 */
388 390 static const xarch_table_t xtbl[] = {
389 391 #if defined(__x86)
390 392 { "generic", SS11 },
391 393 { "generic64", (SS11|M64), { "-m64", "-mtune=opteron" } },
392 394 { "amd64", (SS11|M64), { "-m64", "-mtune=opteron" } },
393 395 { "386", SS11, { "-march=i386" } },
394 396 { "pentium_pro", SS11, { "-march=pentiumpro" } },
395 397 #elif defined(__sparc)
396 398 { "generic", (SS11|M32), { "-m32", "-mcpu=v8" } },
397 399 { "generic64", (SS11|M64), { "-m64", "-mcpu=v9" } },
398 400 { "v8", (SS11|M32), { "-m32", "-mcpu=v8", "-mno-v8plus" } },
399 401 { "v8plus", (SS11|M32), { "-m32", "-mcpu=v9", "-mv8plus" } },
400 402 { "v8plusa", (SS11|M32), { "-m32", "-mcpu=ultrasparc", "-mv8plus",
401 403 "-mvis" } },
402 404 { "v8plusb", (SS11|M32), { "-m32", "-mcpu=ultrasparc3", "-mv8plus",
403 405 "-mvis" } },
404 406 { "v9", (SS11|M64), { "-m64", "-mcpu=v9" } },
405 407 { "v9a", (SS11|M64), { "-m64", "-mcpu=ultrasparc", "-mvis" } },
406 408 { "v9b", (SS11|M64), { "-m64", "-mcpu=ultrasparc3", "-mvis" } },
407 409 { "sparc", SS12, { "-mcpu=v9", "-mv8plus" } },
408 410 { "sparcvis", SS12, { "-mcpu=ultrasparc", "-mvis" } },
409 411 { "sparcvis2", SS12, { "-mcpu=ultrasparc3", "-mvis" } }
410 412 #endif
411 413 };
412 414
413 415 static int xtbl_size = sizeof (xtbl) / sizeof (xarch_table_t);
414 416
415 417 static const char *progname;
416 418
417 419 static const char *xchip_tbl[] = {
418 420 #if defined(__x86)
419 421 "386", "-mtune=i386", NULL,
420 422 "486", "-mtune=i486", NULL,
421 423 "pentium", "-mtune=pentium", NULL,
422 424 "pentium_pro", "-mtune=pentiumpro", NULL,
423 425 #elif defined(__sparc)
424 426 "super", "-mtune=supersparc", NULL,
425 427 "ultra", "-mtune=ultrasparc", NULL,
426 428 "ultra3", "-mtune=ultrasparc3", NULL,
427 429 #endif
428 430 NULL, NULL
429 431 };
430 432
431 433 static const char *xcode_tbl[] = {
432 434 #if defined(__sparc)
433 435 "abs32", "-fno-pic", "-mcmodel=medlow", NULL,
434 436 "abs44", "-fno-pic", "-mcmodel=medmid", NULL,
435 437 "abs64", "-fno-pic", "-mcmodel=medany", NULL,
436 438 "pic13", "-fpic", NULL,
437 439 "pic32", "-fPIC", NULL,
438 440 #endif
439 441 NULL, NULL
440 442 };
441 443
442 444 static const char *xtarget_tbl[] = {
443 445 #if defined(__x86)
444 446 "pentium_pro", "-march=pentiumpro", NULL,
445 447 #endif /* __x86 */
446 448 NULL, NULL
447 449 };
448 450
449 451 static const char *xregs_tbl[] = {
450 452 #if defined(__sparc)
451 453 "appl", "-mapp-regs", NULL,
452 454 "no%appl", "-mno-app-regs", NULL,
453 455 "float", "-mfpu", NULL,
454 456 "no%float", "-mno-fpu", NULL,
455 457 #endif /* __sparc */
456 458 NULL, NULL
457 459 };
458 460
459 461 static void
460 462 nomem(void)
461 463 {
462 464 (void) fprintf(stderr, "%s: error: out of memory\n", progname);
463 465 exit(1);
464 466 }
465 467
466 468 static void
467 469 cw_perror(const char *fmt, ...)
468 470 {
469 471 va_list ap;
470 472 int saved_errno = errno;
471 473
472 474 (void) fprintf(stderr, "%s: error: ", progname);
473 475
474 476 va_start(ap, fmt);
475 477 (void) vfprintf(stderr, fmt, ap);
476 478 va_end(ap);
477 479
478 480 (void) fprintf(stderr, " (%s)\n", strerror(saved_errno));
479 481 }
480 482
481 483 static void
482 484 newae(struct aelist *ael, const char *arg)
483 485 {
484 486 struct ae *ae;
485 487
486 488 if ((ae = calloc(sizeof (*ae), 1)) == NULL)
487 489 nomem();
488 490 ae->ae_arg = strdup(arg);
489 491 if (ael->ael_tail == NULL)
490 492 ael->ael_head = ae;
491 493 else
492 494 ael->ael_tail->ae_next = ae;
493 495 ael->ael_tail = ae;
494 496 ael->ael_argc++;
495 497 }
496 498
497 499 static cw_ictx_t *
498 500 newictx(void)
499 501 {
500 502 cw_ictx_t *ctx = calloc(sizeof (cw_ictx_t), 1);
501 503 if (ctx)
502 504 if ((ctx->i_ae = calloc(sizeof (struct aelist), 1)) == NULL) {
503 505 free(ctx);
504 506 return (NULL);
505 507 }
506 508
507 509 return (ctx);
508 510 }
509 511
510 512 static void
511 513 error(const char *arg)
512 514 {
513 515 (void) fprintf(stderr,
514 516 "%s: error: mapping failed at or near arg '%s'\n", progname, arg);
515 517 exit(2);
516 518 }
517 519
518 520 /*
519 521 * Add the current favourite set of warnings to the gcc invocation.
520 522 */
521 523 static void
522 524 warnings(struct aelist *h)
523 525 {
524 526 static int warningsonce;
525 527
526 528 if (warningsonce++)
↓ open down ↓ |
480 lines elided |
↑ open up ↑ |
527 529 return;
528 530
529 531 /*
530 532 * Enable as many warnings as exist, then disable those that we never
531 533 * ever want.
532 534 */
533 535 newae(h, "-Wall");
534 536 newae(h, "-Wextra");
535 537 }
536 538
537 -static void
538 -optim_disable(struct aelist *h, int level)
539 -{
540 - if (level >= 2) {
541 - newae(h, "-fno-strict-aliasing");
542 - newae(h, "-fno-unit-at-a-time");
543 - newae(h, "-fno-optimize-sibling-calls");
544 - }
545 -}
546 -
547 539 /* ARGSUSED */
548 540 static void
549 541 Xamode(struct aelist *h)
550 542 {
551 543 }
552 544
553 545 static void
554 546 Xcmode(struct aelist *h)
555 547 {
556 548 static int xconce;
557 549
558 550 if (xconce++)
559 551 return;
560 552
561 553 newae(h, "-ansi");
562 554 newae(h, "-pedantic-errors");
563 555 }
564 556
565 557 static void
566 558 Xsmode(struct aelist *h)
567 559 {
568 560 static int xsonce;
569 561
570 562 if (xsonce++)
571 563 return;
572 564
573 565 newae(h, "-traditional");
574 566 newae(h, "-traditional-cpp");
575 567 }
576 568
577 569 static void
578 570 usage()
579 571 {
580 572 (void) fprintf(stderr,
581 573 "usage: %s { -_cc | -_gcc | -_CC | -_g++ } [ -_compiler | ... ]\n",
582 574 progname);
583 575 exit(2);
584 576 }
585 577
586 578 static int
587 579 xlate_xtb(struct aelist *h, const char *xarg)
588 580 {
589 581 int i, j;
590 582
591 583 for (i = 0; i < xtbl_size; i++) {
592 584 if (strcmp(xtbl[i].x_arg, xarg) == 0)
593 585 break;
594 586 }
595 587
596 588 /*
597 589 * At the end of the table and so no matching "arg" entry
598 590 * found and so this must be a bad -xarch= flag.
599 591 */
600 592 if (i == xtbl_size)
601 593 error(xarg);
602 594
603 595 for (j = 0; j < TRANS_ENTRY; j++) {
604 596 if (xtbl[i].x_trans[j] != NULL)
605 597 newae(h, xtbl[i].x_trans[j]);
606 598 else
607 599 break;
608 600 }
609 601 return (xtbl[i].x_flags);
610 602
611 603 }
612 604
613 605 static void
614 606 xlate(struct aelist *h, const char *xarg, const char **table)
615 607 {
616 608 while (*table != NULL && strcmp(xarg, *table) != 0) {
617 609 while (*table != NULL)
618 610 table++;
619 611 table++;
620 612 }
621 613
622 614 if (*table == NULL)
623 615 error(xarg);
624 616
625 617 table++;
626 618
627 619 while (*table != NULL) {
628 620 newae(h, *table);
629 621 table++;
630 622 }
631 623 }
632 624
633 625 static void
634 626 do_gcc(cw_ictx_t *ctx)
635 627 {
636 628 int c;
637 629 int pic = 0, nolibc = 0;
638 630 int in_output = 0, seen_o = 0, c_files = 0;
639 631 cw_op_t op = CW_O_LINK;
640 632 char *model = NULL;
641 633 int mflag = 0;
642 634
643 635 if (ctx->i_flags & CW_F_PROG) {
644 636 newae(ctx->i_ae, "--version");
645 637 return;
646 638 }
647 639
648 640 newae(ctx->i_ae, "-fident");
649 641 newae(ctx->i_ae, "-finline");
650 642 newae(ctx->i_ae, "-fno-inline-functions");
651 643 newae(ctx->i_ae, "-fno-builtin");
652 644 newae(ctx->i_ae, "-fno-asm");
653 645 newae(ctx->i_ae, "-fdiagnostics-show-option");
654 646 newae(ctx->i_ae, "-nodefaultlibs");
655 647
656 648 #if defined(__sparc)
657 649 /*
658 650 * The SPARC ldd and std instructions require 8-byte alignment of
659 651 * their address operand. gcc correctly uses them only when the
660 652 * ABI requires 8-byte alignment; unfortunately we have a number of
661 653 * pieces of buggy code that doesn't conform to the ABI. This
662 654 * flag makes gcc work more like Studio with -xmemalign=4.
663 655 */
664 656 newae(ctx->i_ae, "-mno-integer-ldd-std");
665 657 #endif
666 658
667 659 /*
668 660 * This is needed because 'u' is defined
669 661 * under a conditional on 'sun'. Should
670 662 * probably just remove the conditional,
671 663 * or make it be dependent on '__sun'.
672 664 *
673 665 * -Dunix is also missing in enhanced ANSI mode
674 666 */
675 667 newae(ctx->i_ae, "-D__sun");
676 668
677 669 /*
678 670 * Walk the argument list, translating as we go ..
679 671 */
680 672
681 673 while (--ctx->i_oldargc > 0) {
682 674 char *arg = *++ctx->i_oldargv;
683 675 size_t arglen = strlen(arg);
684 676
685 677 if (*arg == '-') {
686 678 arglen--;
687 679 } else {
688 680 /*
689 681 * Discard inline files that gcc doesn't grok
690 682 */
691 683 if (!in_output && arglen > 3 &&
692 684 strcmp(arg + arglen - 3, ".il") == 0)
693 685 continue;
694 686
695 687 if (!in_output && arglen > 2 &&
696 688 arg[arglen - 2] == '.' &&
697 689 (arg[arglen - 1] == 'S' || arg[arglen - 1] == 's' ||
698 690 arg[arglen - 1] == 'c' || arg[arglen - 1] == 'i'))
699 691 c_files++;
700 692
701 693 /*
702 694 * Otherwise, filenames and partial arguments
703 695 * are passed through for gcc to chew on. However,
704 696 * output is always discarded for the secondary
705 697 * compiler.
706 698 */
707 699 if ((ctx->i_flags & CW_F_SHADOW) && in_output)
708 700 newae(ctx->i_ae, ctx->i_discard);
709 701 else
710 702 newae(ctx->i_ae, arg);
711 703 in_output = 0;
712 704 continue;
713 705 }
714 706
715 707 if (ctx->i_flags & CW_F_CXX) {
716 708 if (strncmp(arg, "-compat=", 8) == 0) {
717 709 /* discard -compat=4 and -compat=5 */
718 710 continue;
719 711 }
720 712 if (strcmp(arg, "-Qoption") == 0) {
721 713 /* discard -Qoption and its two arguments */
722 714 if (ctx->i_oldargc < 3)
723 715 error(arg);
724 716 ctx->i_oldargc -= 2;
725 717 ctx->i_oldargv += 2;
726 718 continue;
727 719 }
728 720 if (strcmp(arg, "-xwe") == 0) {
729 721 /* turn warnings into errors */
730 722 newae(ctx->i_ae, "-Werror");
731 723 continue;
732 724 }
733 725 if (strcmp(arg, "-noex") == 0) {
734 726 /* no exceptions */
735 727 newae(ctx->i_ae, "-fno-exceptions");
736 728 /* no run time type descriptor information */
737 729 newae(ctx->i_ae, "-fno-rtti");
738 730 continue;
739 731 }
740 732 if (strcmp(arg, "-pic") == 0) {
741 733 newae(ctx->i_ae, "-fpic");
742 734 pic = 1;
743 735 continue;
744 736 }
745 737 if (strcmp(arg, "-PIC") == 0) {
746 738 newae(ctx->i_ae, "-fPIC");
747 739 pic = 1;
748 740 continue;
749 741 }
750 742 if (strcmp(arg, "-norunpath") == 0) {
751 743 /* gcc has no corresponding option */
752 744 continue;
753 745 }
754 746 if (strcmp(arg, "-nolib") == 0) {
755 747 /* -nodefaultlibs is on by default */
756 748 nolibc = 1;
757 749 continue;
758 750 }
759 751 #if defined(__sparc)
760 752 if (strcmp(arg, "-cg92") == 0) {
761 753 mflag |= xlate_xtb(ctx->i_ae, "v8");
762 754 xlate(ctx->i_ae, "super", xchip_tbl);
763 755 continue;
764 756 }
765 757 #endif /* __sparc */
766 758 }
767 759
768 760 switch ((c = arg[1])) {
769 761 case '_':
770 762 if (strcmp(arg, "-_noecho") == 0)
771 763 ctx->i_flags &= ~CW_F_ECHO;
772 764 else if (strncmp(arg, "-_cc=", 5) == 0 ||
773 765 strncmp(arg, "-_CC=", 5) == 0)
774 766 /* EMPTY */;
775 767 else if (strncmp(arg, "-_gcc=", 6) == 0 ||
776 768 strncmp(arg, "-_g++=", 6) == 0)
777 769 newae(ctx->i_ae, arg + 6);
778 770 else
779 771 error(arg);
780 772 break;
781 773 case '#':
782 774 if (arglen == 1) {
783 775 newae(ctx->i_ae, "-v");
784 776 break;
785 777 }
786 778 error(arg);
787 779 break;
788 780 case 'g':
789 781 newae(ctx->i_ae, "-gdwarf-2");
790 782 break;
791 783 case 'E':
792 784 if (arglen == 1) {
793 785 newae(ctx->i_ae, "-xc");
794 786 newae(ctx->i_ae, arg);
795 787 op = CW_O_PREPROCESS;
796 788 nolibc = 1;
797 789 break;
798 790 }
799 791 error(arg);
800 792 break;
801 793 case 'c':
802 794 case 'S':
803 795 if (arglen == 1) {
804 796 op = CW_O_COMPILE;
805 797 nolibc = 1;
806 798 }
807 799 /* FALLTHROUGH */
808 800 case 'C':
809 801 case 'H':
810 802 case 'p':
811 803 if (arglen == 1) {
812 804 newae(ctx->i_ae, arg);
813 805 break;
814 806 }
815 807 error(arg);
816 808 break;
817 809 case 'A':
818 810 case 'h':
819 811 case 'I':
820 812 case 'i':
821 813 case 'L':
822 814 case 'l':
823 815 case 'R':
824 816 case 'U':
825 817 case 'u':
826 818 case 'w':
827 819 newae(ctx->i_ae, arg);
828 820 break;
829 821 case 'o':
830 822 seen_o = 1;
831 823 if (arglen == 1) {
832 824 in_output = 1;
833 825 newae(ctx->i_ae, arg);
834 826 } else if (ctx->i_flags & CW_F_SHADOW) {
835 827 newae(ctx->i_ae, "-o");
836 828 newae(ctx->i_ae, ctx->i_discard);
837 829 } else {
838 830 newae(ctx->i_ae, arg);
839 831 }
840 832 break;
841 833 case 'D':
842 834 newae(ctx->i_ae, arg);
843 835 /*
844 836 * XXX Clearly a hack ... do we need _KADB too?
845 837 */
846 838 if (strcmp(arg, "-D_KERNEL") == 0 ||
847 839 strcmp(arg, "-D_BOOT") == 0)
848 840 newae(ctx->i_ae, "-ffreestanding");
849 841 break;
850 842 case 'd':
851 843 if (arglen == 2) {
852 844 if (strcmp(arg, "-dy") == 0) {
853 845 newae(ctx->i_ae, "-Wl,-dy");
854 846 break;
855 847 }
856 848 if (strcmp(arg, "-dn") == 0) {
857 849 newae(ctx->i_ae, "-Wl,-dn");
858 850 break;
859 851 }
860 852 }
861 853 if (strcmp(arg, "-dalign") == 0) {
862 854 /*
863 855 * -dalign forces alignment in some cases;
864 856 * gcc does not need any flag to do this.
865 857 */
866 858 break;
867 859 }
868 860 error(arg);
869 861 break;
870 862 case 'e':
871 863 if (strcmp(arg,
872 864 "-erroff=E_EMPTY_TRANSLATION_UNIT") == 0) {
873 865 /*
874 866 * Accept but ignore this -- gcc doesn't
875 867 * seem to complain about empty translation
876 868 * units
877 869 */
878 870 break;
879 871 }
880 872 /* XX64 -- ignore all -erroff= options, for now */
881 873 if (strncmp(arg, "-erroff=", 8) == 0)
882 874 break;
883 875 if (strcmp(arg, "-errtags=yes") == 0) {
884 876 warnings(ctx->i_ae);
885 877 break;
886 878 }
887 879 if (strcmp(arg, "-errwarn=%all") == 0) {
888 880 newae(ctx->i_ae, "-Werror");
889 881 break;
890 882 }
891 883 error(arg);
892 884 break;
893 885 case 'f':
894 886 if (strcmp(arg, "-flags") == 0) {
895 887 newae(ctx->i_ae, "--help");
896 888 break;
897 889 }
898 890 if (strncmp(arg, "-features=zla", 13) == 0) {
899 891 /*
900 892 * Accept but ignore this -- gcc allows
901 893 * zero length arrays.
902 894 */
903 895 break;
904 896 }
905 897 error(arg);
906 898 break;
907 899 case 'G':
908 900 newae(ctx->i_ae, "-shared");
909 901 nolibc = 1;
910 902 break;
911 903 case 'k':
912 904 if (strcmp(arg, "-keeptmp") == 0) {
913 905 newae(ctx->i_ae, "-save-temps");
914 906 break;
915 907 }
916 908 error(arg);
917 909 break;
918 910 case 'K':
919 911 if (arglen == 1) {
920 912 if ((arg = *++ctx->i_oldargv) == NULL ||
921 913 *arg == '\0')
922 914 error("-K");
923 915 ctx->i_oldargc--;
924 916 } else {
925 917 arg += 2;
926 918 }
927 919 if (strcmp(arg, "pic") == 0) {
928 920 newae(ctx->i_ae, "-fpic");
929 921 pic = 1;
930 922 break;
931 923 }
932 924 if (strcmp(arg, "PIC") == 0) {
933 925 newae(ctx->i_ae, "-fPIC");
934 926 pic = 1;
935 927 break;
936 928 }
937 929 error("-K");
938 930 break;
939 931 case 'm':
940 932 if (strcmp(arg, "-mt") == 0) {
941 933 newae(ctx->i_ae, "-D_REENTRANT");
942 934 break;
943 935 }
944 936 if (strcmp(arg, "-m64") == 0) {
945 937 newae(ctx->i_ae, "-m64");
946 938 #if defined(__x86)
947 939 newae(ctx->i_ae, "-mtune=opteron");
948 940 #endif
949 941 mflag |= M64;
950 942 break;
951 943 }
952 944 if (strcmp(arg, "-m32") == 0) {
953 945 newae(ctx->i_ae, "-m32");
954 946 mflag |= M32;
955 947 break;
956 948 }
957 949 error(arg);
958 950 break;
959 951 case 'B': /* linker options */
960 952 case 'M':
961 953 case 'z':
962 954 {
963 955 char *opt;
964 956 size_t len;
965 957 char *s;
966 958
967 959 if (arglen == 1) {
968 960 opt = *++ctx->i_oldargv;
969 961 if (opt == NULL || *opt == '\0')
970 962 error(arg);
971 963 ctx->i_oldargc--;
972 964 } else {
973 965 opt = arg + 2;
974 966 }
975 967 len = strlen(opt) + 7;
976 968 if ((s = malloc(len)) == NULL)
977 969 nomem();
978 970 (void) snprintf(s, len, "-Wl,-%c%s", c, opt);
979 971 newae(ctx->i_ae, s);
980 972 free(s);
981 973 }
982 974 break;
983 975 case 'n':
984 976 if (strcmp(arg, "-noqueue") == 0) {
985 977 /*
986 978 * Horrid license server stuff - n/a
987 979 */
988 980 break;
989 981 }
990 982 error(arg);
991 983 break;
992 984 case 'O':
993 985 if (arglen == 1) {
994 986 newae(ctx->i_ae, "-O");
995 987 break;
996 988 }
997 989 error(arg);
998 990 break;
999 991 case 'P':
1000 992 /*
1001 993 * We could do '-E -o filename.i', but that's hard,
1002 994 * and we don't need it for the case that's triggering
1003 995 * this addition. We'll require the user to specify
1004 996 * -o in the Makefile. If they don't they'll find out
1005 997 * in a hurry.
1006 998 */
1007 999 newae(ctx->i_ae, "-E");
1008 1000 op = CW_O_PREPROCESS;
1009 1001 nolibc = 1;
1010 1002 break;
1011 1003 case 'q':
1012 1004 if (strcmp(arg, "-qp") == 0) {
1013 1005 newae(ctx->i_ae, "-p");
1014 1006 break;
1015 1007 }
1016 1008 error(arg);
1017 1009 break;
1018 1010 case 's':
1019 1011 if (arglen == 1) {
1020 1012 newae(ctx->i_ae, "-Wl,-s");
1021 1013 break;
1022 1014 }
1023 1015 error(arg);
1024 1016 break;
1025 1017 case 't':
1026 1018 if (arglen == 1) {
1027 1019 newae(ctx->i_ae, "-Wl,-t");
1028 1020 break;
1029 1021 }
1030 1022 error(arg);
1031 1023 break;
1032 1024 case 'V':
1033 1025 if (arglen == 1) {
1034 1026 ctx->i_flags &= ~CW_F_ECHO;
1035 1027 newae(ctx->i_ae, "--version");
1036 1028 break;
1037 1029 }
1038 1030 error(arg);
1039 1031 break;
1040 1032 case 'v':
1041 1033 if (arglen == 1) {
1042 1034 warnings(ctx->i_ae);
1043 1035 break;
1044 1036 }
1045 1037 error(arg);
1046 1038 break;
1047 1039 case 'W':
1048 1040 if (strncmp(arg, "-Wp,-xc99", 9) == 0) {
1049 1041 /*
1050 1042 * gcc's preprocessor will accept c99
1051 1043 * regardless, so accept and ignore.
1052 1044 */
1053 1045 break;
1054 1046 }
1055 1047 if (strncmp(arg, "-Wa,", 4) == 0 ||
1056 1048 strncmp(arg, "-Wp,", 4) == 0 ||
1057 1049 strncmp(arg, "-Wl,", 4) == 0) {
1058 1050 newae(ctx->i_ae, arg);
1059 1051 break;
1060 1052 }
1061 1053 if (strcmp(arg, "-W0,-xc99=pragma") == 0) {
1062 1054 /* (undocumented) enables _Pragma */
1063 1055 break;
1064 1056 }
1065 1057 if (strcmp(arg, "-W0,-xc99=%none") == 0) {
1066 1058 /*
1067 1059 * This is a polite way of saying
1068 1060 * "no c99 constructs allowed!"
1069 1061 * For now, just accept and ignore this.
1070 1062 */
1071 1063 break;
1072 1064 }
1073 1065 if (strcmp(arg, "-W0,-noglobal") == 0 ||
1074 1066 strcmp(arg, "-W0,-xglobalstatic") == 0) {
1075 1067 /*
1076 1068 * gcc doesn't prefix local symbols
1077 1069 * in debug mode, so this is not needed.
1078 1070 */
1079 1071 break;
1080 1072 }
1081 1073 if (strcmp(arg, "-W0,-Lt") == 0) {
1082 1074 /*
1083 1075 * Generate tests at the top of loops.
1084 1076 * There is no direct gcc equivalent, ignore.
1085 1077 */
1086 1078 break;
1087 1079 }
1088 1080 if (strcmp(arg, "-W0,-xdbggen=no%usedonly") == 0) {
1089 1081 newae(ctx->i_ae,
1090 1082 "-fno-eliminate-unused-debug-symbols");
1091 1083 newae(ctx->i_ae,
1092 1084 "-fno-eliminate-unused-debug-types");
1093 1085 break;
1094 1086 }
1095 1087 if (strcmp(arg, "-W2,-xwrap_int") == 0) {
1096 1088 /*
1097 1089 * Use the legacy behaviour (pre-SS11)
1098 1090 * for integer wrapping.
1099 1091 * gcc does not need this.
1100 1092 */
1101 1093 break;
1102 1094 }
1103 1095 if (strcmp(arg, "-W2,-Rcond_elim") == 0) {
1104 1096 /*
1105 1097 * Elimination and expansion of conditionals;
1106 1098 * gcc has no direct equivalent.
1107 1099 */
1108 1100 break;
1109 1101 }
1110 1102 if (strcmp(arg, "-Wd,-xsafe=unboundsym") == 0) {
1111 1103 /*
1112 1104 * Prevents optimizing away checks for
1113 1105 * unbound weak symbol addresses. gcc does
1114 1106 * not do this, so it's not needed.
1115 1107 */
1116 1108 break;
1117 1109 }
1118 1110 if (strncmp(arg, "-Wc,-xcode=", 11) == 0) {
1119 1111 xlate(ctx->i_ae, arg + 11, xcode_tbl);
1120 1112 if (strncmp(arg + 11, "pic", 3) == 0)
1121 1113 pic = 1;
1122 1114 break;
1123 1115 }
1124 1116 if (strncmp(arg, "-Wc,-Qiselect", 13) == 0) {
1125 1117 /*
1126 1118 * Prevents insertion of register symbols.
1127 1119 * gcc doesn't do this, so ignore it.
1128 1120 */
1129 1121 break;
1130 1122 }
1131 1123 if (strcmp(arg, "-Wc,-Qassembler-ounrefsym=0") == 0) {
1132 1124 /*
1133 1125 * Prevents optimizing away of static variables.
1134 1126 * gcc does not do this, so it's not needed.
1135 1127 */
1136 1128 break;
1137 1129 }
1138 1130 #if defined(__x86)
1139 1131 if (strcmp(arg, "-Wu,-xmodel=kernel") == 0) {
1140 1132 newae(ctx->i_ae, "-ffreestanding");
1141 1133 newae(ctx->i_ae, "-mno-red-zone");
1142 1134 model = "-mcmodel=kernel";
1143 1135 nolibc = 1;
1144 1136 break;
1145 1137 }
1146 1138 if (strcmp(arg, "-Wu,-save_args") == 0) {
1147 1139 newae(ctx->i_ae, "-msave-args");
1148 1140 break;
1149 1141 }
1150 1142 #endif /* __x86 */
1151 1143 error(arg);
1152 1144 break;
1153 1145 case 'X':
1154 1146 if (strcmp(arg, "-Xa") == 0 ||
1155 1147 strcmp(arg, "-Xt") == 0) {
1156 1148 Xamode(ctx->i_ae);
1157 1149 break;
1158 1150 }
1159 1151 if (strcmp(arg, "-Xc") == 0) {
1160 1152 Xcmode(ctx->i_ae);
1161 1153 break;
1162 1154 }
1163 1155 if (strcmp(arg, "-Xs") == 0) {
1164 1156 Xsmode(ctx->i_ae);
1165 1157 break;
1166 1158 }
1167 1159 error(arg);
1168 1160 break;
1169 1161 case 'x':
1170 1162 if (arglen == 1)
1171 1163 error(arg);
1172 1164 switch (arg[2]) {
1173 1165 #if defined(__x86)
1174 1166 case '3':
1175 1167 if (strcmp(arg, "-x386") == 0) {
1176 1168 newae(ctx->i_ae, "-march=i386");
1177 1169 break;
1178 1170 }
1179 1171 error(arg);
1180 1172 break;
1181 1173 case '4':
1182 1174 if (strcmp(arg, "-x486") == 0) {
1183 1175 newae(ctx->i_ae, "-march=i486");
1184 1176 break;
1185 1177 }
1186 1178 error(arg);
1187 1179 break;
1188 1180 #endif /* __x86 */
1189 1181 case 'a':
1190 1182 if (strncmp(arg, "-xarch=", 7) == 0) {
1191 1183 mflag |= xlate_xtb(ctx->i_ae, arg + 7);
1192 1184 break;
1193 1185 }
1194 1186 error(arg);
1195 1187 break;
1196 1188 case 'b':
1197 1189 if (strncmp(arg, "-xbuiltin=", 10) == 0) {
1198 1190 if (strcmp(arg + 10, "%all"))
1199 1191 newae(ctx->i_ae, "-fbuiltin");
1200 1192 break;
1201 1193 }
1202 1194 error(arg);
1203 1195 break;
1204 1196 case 'C':
1205 1197 /* Accept C++ style comments -- ignore */
1206 1198 if (strcmp(arg, "-xCC") == 0)
1207 1199 break;
1208 1200 error(arg);
1209 1201 break;
1210 1202 case 'c':
1211 1203 if (strncmp(arg, "-xc99=%all", 10) == 0) {
1212 1204 newae(ctx->i_ae, "-std=gnu99");
1213 1205 break;
1214 1206 }
1215 1207 if (strncmp(arg, "-xc99=%none", 11) == 0) {
1216 1208 newae(ctx->i_ae, "-std=gnu89");
1217 1209 break;
1218 1210 }
1219 1211 if (strncmp(arg, "-xchip=", 7) == 0) {
1220 1212 xlate(ctx->i_ae, arg + 7, xchip_tbl);
1221 1213 break;
1222 1214 }
1223 1215 if (strncmp(arg, "-xcode=", 7) == 0) {
1224 1216 xlate(ctx->i_ae, arg + 7, xcode_tbl);
1225 1217 if (strncmp(arg + 7, "pic", 3) == 0)
1226 1218 pic = 1;
1227 1219 break;
1228 1220 }
1229 1221 if (strncmp(arg, "-xcache=", 8) == 0)
1230 1222 break;
1231 1223 if (strncmp(arg, "-xcrossfile", 11) == 0)
1232 1224 break;
1233 1225 error(arg);
1234 1226 break;
1235 1227 case 'd':
1236 1228 if (strcmp(arg, "-xdepend") == 0)
1237 1229 break;
1238 1230 if (strncmp(arg, "-xdebugformat=", 14) == 0)
1239 1231 break;
1240 1232 error(arg);
1241 1233 break;
1242 1234 case 'F':
1243 1235 /*
1244 1236 * Compile for mapfile reordering, or unused
1245 1237 * section elimination, syntax can be -xF or
1246 1238 * more complex, like -xF=%all -- ignore.
1247 1239 */
1248 1240 if (strncmp(arg, "-xF", 3) == 0)
1249 1241 break;
1250 1242 error(arg);
1251 1243 break;
1252 1244 case 'i':
1253 1245 if (strncmp(arg, "-xinline", 8) == 0)
1254 1246 /* No inlining; ignore */
1255 1247 break;
1256 1248 if (strcmp(arg, "-xildon") == 0 ||
1257 1249 strcmp(arg, "-xildoff") == 0)
1258 1250 /* No incremental linking; ignore */
1259 1251 break;
1260 1252 error(arg);
1261 1253 break;
1262 1254 #if defined(__x86)
1263 1255 case 'm':
1264 1256 if (strcmp(arg, "-xmodel=kernel") == 0) {
1265 1257 newae(ctx->i_ae, "-ffreestanding");
1266 1258 newae(ctx->i_ae, "-mno-red-zone");
1267 1259 model = "-mcmodel=kernel";
1268 1260 nolibc = 1;
1269 1261 break;
1270 1262 }
1271 1263 error(arg);
1272 1264 break;
1273 1265 #endif /* __x86 */
1274 1266 case 'M':
1275 1267 if (strcmp(arg, "-xM") == 0) {
1276 1268 newae(ctx->i_ae, "-M");
1277 1269 break;
1278 1270 }
1279 1271 if (strcmp(arg, "-xM1") == 0) {
1280 1272 newae(ctx->i_ae, "-MM");
1281 1273 break;
1282 1274 }
1283 1275 error(arg);
1284 1276 break;
1285 1277 case 'n':
1286 1278 if (strcmp(arg, "-xnolib") == 0) {
1287 1279 nolibc = 1;
1288 1280 break;
1289 1281 }
1290 1282 error(arg);
1291 1283 break;
1292 1284 case 'O':
1293 1285 if (strncmp(arg, "-xO", 3) == 0) {
1294 1286 size_t len = strlen(arg);
1295 1287 char *s;
1296 1288 int c = *(arg + 3);
1297 1289 int level;
↓ open down ↓ |
741 lines elided |
↑ open up ↑ |
1298 1290
1299 1291 if (len != 4 || !isdigit(c))
1300 1292 error(arg);
1301 1293
1302 1294 if ((s = malloc(len)) == NULL)
1303 1295 nomem();
1304 1296
1305 1297 level = atoi(arg + 3);
1306 1298 if (level > 5)
1307 1299 error(arg);
1308 - if (level >= 2) {
1309 - /*
1310 - * For gcc-3.4.x at -O2 we
1311 - * need to disable optimizations
1312 - * that break ON.
1313 - */
1314 - optim_disable(ctx->i_ae, level);
1315 - /*
1316 - * limit -xO3 to -O2 as well.
1317 - */
1318 - level = 2;
1319 - }
1320 1300 (void) snprintf(s, len, "-O%d", level);
1321 1301 newae(ctx->i_ae, s);
1322 1302 free(s);
1323 1303 break;
1324 1304 }
1325 1305 error(arg);
1326 1306 break;
1327 1307 case 'p':
1328 1308 if (strcmp(arg, "-xpentium") == 0) {
1329 1309 newae(ctx->i_ae, "-march=pentium");
1330 1310 break;
1331 1311 }
1332 1312 if (strcmp(arg, "-xpg") == 0) {
1333 1313 newae(ctx->i_ae, "-pg");
1334 1314 break;
1335 1315 }
1336 1316 error(arg);
1337 1317 break;
1338 1318 case 'r':
1339 1319 if (strncmp(arg, "-xregs=", 7) == 0) {
1340 1320 xlate(ctx->i_ae, arg + 7, xregs_tbl);
1341 1321 break;
1342 1322 }
1343 1323 error(arg);
1344 1324 break;
1345 1325 case 's':
1346 1326 if (strcmp(arg, "-xs") == 0 ||
1347 1327 strcmp(arg, "-xspace") == 0 ||
1348 1328 strcmp(arg, "-xstrconst") == 0)
1349 1329 break;
1350 1330 error(arg);
1351 1331 break;
1352 1332 case 't':
1353 1333 if (strcmp(arg, "-xtransition") == 0) {
1354 1334 newae(ctx->i_ae, "-Wtransition");
1355 1335 break;
1356 1336 }
1357 1337 if (strcmp(arg, "-xtrigraphs=yes") == 0) {
1358 1338 newae(ctx->i_ae, "-trigraphs");
1359 1339 break;
1360 1340 }
1361 1341 if (strcmp(arg, "-xtrigraphs=no") == 0) {
1362 1342 newae(ctx->i_ae, "-notrigraphs");
1363 1343 break;
1364 1344 }
1365 1345 if (strncmp(arg, "-xtarget=", 9) == 0) {
1366 1346 xlate(ctx->i_ae, arg + 9, xtarget_tbl);
1367 1347 break;
1368 1348 }
1369 1349 error(arg);
1370 1350 break;
1371 1351 case 'e':
1372 1352 case 'h':
1373 1353 case 'l':
1374 1354 default:
1375 1355 error(arg);
1376 1356 break;
1377 1357 }
1378 1358 break;
1379 1359 case 'Y':
1380 1360 if (arglen == 1) {
1381 1361 if ((arg = *++ctx->i_oldargv) == NULL ||
1382 1362 *arg == '\0')
1383 1363 error("-Y");
1384 1364 ctx->i_oldargc--;
1385 1365 arglen = strlen(arg + 1);
1386 1366 } else {
1387 1367 arg += 2;
1388 1368 }
1389 1369 /* Just ignore -YS,... for now */
1390 1370 if (strncmp(arg, "S,", 2) == 0)
1391 1371 break;
1392 1372 if (strncmp(arg, "l,", 2) == 0) {
1393 1373 char *s = strdup(arg);
1394 1374 s[0] = '-';
1395 1375 s[1] = 'B';
1396 1376 newae(ctx->i_ae, s);
1397 1377 free(s);
1398 1378 break;
1399 1379 }
1400 1380 if (strncmp(arg, "I,", 2) == 0) {
1401 1381 char *s = strdup(arg);
1402 1382 s[0] = '-';
1403 1383 s[1] = 'I';
1404 1384 newae(ctx->i_ae, "-nostdinc");
1405 1385 newae(ctx->i_ae, s);
1406 1386 free(s);
1407 1387 break;
1408 1388 }
1409 1389 error(arg);
1410 1390 break;
1411 1391 case 'Q':
1412 1392 /*
1413 1393 * We could map -Qy into -Wl,-Qy etc.
1414 1394 */
1415 1395 default:
1416 1396 error(arg);
1417 1397 break;
1418 1398 }
1419 1399 }
1420 1400
1421 1401 if (c_files > 1 && (ctx->i_flags & CW_F_SHADOW) &&
1422 1402 op != CW_O_PREPROCESS) {
1423 1403 (void) fprintf(stderr, "%s: error: multiple source files are "
1424 1404 "allowed only with -E or -P\n", progname);
1425 1405 exit(2);
1426 1406 }
1427 1407
1428 1408 /*
1429 1409 * Make sure that we do not have any unintended interactions between
1430 1410 * the xarch options passed in and the version of the Studio compiler
1431 1411 * used.
1432 1412 */
1433 1413 if ((mflag & (SS11|SS12)) == (SS11|SS12)) {
1434 1414 (void) fprintf(stderr,
1435 1415 "Conflicting \"-xarch=\" flags (both Studio 11 and 12)\n");
1436 1416 exit(2);
1437 1417 }
1438 1418
1439 1419 switch (mflag) {
1440 1420 case 0:
1441 1421 /* FALLTHROUGH */
1442 1422 case M32:
1443 1423 #if defined(__sparc)
1444 1424 /*
1445 1425 * Only -m32 is defined and so put in the missing xarch
1446 1426 * translation.
1447 1427 */
1448 1428 newae(ctx->i_ae, "-mcpu=v8");
1449 1429 newae(ctx->i_ae, "-mno-v8plus");
1450 1430 #endif
1451 1431 break;
1452 1432 case M64:
1453 1433 #if defined(__sparc)
1454 1434 /*
1455 1435 * Only -m64 is defined and so put in the missing xarch
1456 1436 * translation.
1457 1437 */
1458 1438 newae(ctx->i_ae, "-mcpu=v9");
1459 1439 #endif
1460 1440 break;
1461 1441 case SS12:
1462 1442 #if defined(__sparc)
1463 1443 /* no -m32/-m64 flag used - this is an error for sparc builds */
1464 1444 (void) fprintf(stderr, "No -m32/-m64 flag defined\n");
1465 1445 exit(2);
1466 1446 #endif
1467 1447 break;
1468 1448 case SS11:
1469 1449 /* FALLTHROUGH */
1470 1450 case (SS11|M32):
1471 1451 case (SS11|M64):
1472 1452 break;
1473 1453 case (SS12|M32):
1474 1454 #if defined(__sparc)
1475 1455 /*
1476 1456 * Need to add in further 32 bit options because with SS12
1477 1457 * the xarch=sparcvis option can be applied to 32 or 64
1478 1458 * bit, and so the translatation table (xtbl) cannot handle
1479 1459 * that.
1480 1460 */
1481 1461 newae(ctx->i_ae, "-mv8plus");
1482 1462 #endif
1483 1463 break;
1484 1464 case (SS12|M64):
1485 1465 break;
1486 1466 default:
1487 1467 (void) fprintf(stderr,
1488 1468 "Incompatible -xarch= and/or -m32/-m64 options used.\n");
1489 1469 exit(2);
1490 1470 }
1491 1471 if (op == CW_O_LINK && (ctx->i_flags & CW_F_SHADOW))
1492 1472 exit(0);
1493 1473
1494 1474 if (model && !pic)
1495 1475 newae(ctx->i_ae, model);
1496 1476 if (!nolibc)
1497 1477 newae(ctx->i_ae, "-lc");
1498 1478 if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) {
1499 1479 newae(ctx->i_ae, "-o");
1500 1480 newae(ctx->i_ae, ctx->i_discard);
1501 1481 }
1502 1482 }
1503 1483
1504 1484 static void
1505 1485 do_cc(cw_ictx_t *ctx)
1506 1486 {
1507 1487 int in_output = 0, seen_o = 0;
1508 1488 cw_op_t op = CW_O_LINK;
1509 1489
1510 1490 if (ctx->i_flags & CW_F_PROG) {
1511 1491 newae(ctx->i_ae, "-V");
1512 1492 return;
1513 1493 }
1514 1494
1515 1495 while (--ctx->i_oldargc > 0) {
1516 1496 char *arg = *++ctx->i_oldargv;
1517 1497
1518 1498 if (*arg != '-') {
1519 1499 if (in_output == 0 || !(ctx->i_flags & CW_F_SHADOW)) {
1520 1500 newae(ctx->i_ae, arg);
1521 1501 } else {
1522 1502 in_output = 0;
1523 1503 newae(ctx->i_ae, ctx->i_discard);
1524 1504 }
1525 1505 continue;
1526 1506 }
1527 1507 switch (*(arg + 1)) {
1528 1508 case '_':
1529 1509 if (strcmp(arg, "-_noecho") == 0) {
1530 1510 ctx->i_flags &= ~CW_F_ECHO;
1531 1511 } else if (strncmp(arg, "-_cc=", 5) == 0 ||
1532 1512 strncmp(arg, "-_CC=", 5) == 0) {
1533 1513 newae(ctx->i_ae, arg + 5);
1534 1514 } else if (strncmp(arg, "-_gcc=", 6) != 0 &&
1535 1515 strncmp(arg, "-_g++=", 6) != 0) {
1536 1516 (void) fprintf(stderr,
1537 1517 "%s: invalid argument '%s'\n", progname,
1538 1518 arg);
1539 1519 exit(2);
1540 1520 }
1541 1521 break;
1542 1522 case 'V':
1543 1523 ctx->i_flags &= ~CW_F_ECHO;
1544 1524 newae(ctx->i_ae, arg);
1545 1525 break;
1546 1526 case 'o':
1547 1527 seen_o = 1;
1548 1528 if (strlen(arg) == 2) {
1549 1529 in_output = 1;
1550 1530 newae(ctx->i_ae, arg);
1551 1531 } else if (ctx->i_flags & CW_F_SHADOW) {
1552 1532 newae(ctx->i_ae, "-o");
1553 1533 newae(ctx->i_ae, ctx->i_discard);
1554 1534 } else {
1555 1535 newae(ctx->i_ae, arg);
1556 1536 }
1557 1537 break;
1558 1538 case 'c':
1559 1539 case 'S':
1560 1540 if (strlen(arg) == 2)
1561 1541 op = CW_O_COMPILE;
1562 1542 newae(ctx->i_ae, arg);
1563 1543 break;
1564 1544 case 'E':
1565 1545 case 'P':
1566 1546 if (strlen(arg) == 2)
1567 1547 op = CW_O_PREPROCESS;
1568 1548 /*FALLTHROUGH*/
1569 1549 default:
1570 1550 newae(ctx->i_ae, arg);
1571 1551 }
1572 1552 }
1573 1553
1574 1554 if ((op == CW_O_LINK || op == CW_O_PREPROCESS) &&
1575 1555 (ctx->i_flags & CW_F_SHADOW))
1576 1556 exit(0);
1577 1557
1578 1558 if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) {
1579 1559 newae(ctx->i_ae, "-o");
1580 1560 newae(ctx->i_ae, ctx->i_discard);
1581 1561 }
1582 1562 }
1583 1563
1584 1564 static void
1585 1565 prepctx(cw_ictx_t *ctx)
1586 1566 {
1587 1567 const char *dir = NULL, *cmd;
1588 1568 char *program = NULL;
1589 1569 size_t len;
1590 1570
1591 1571 switch (CIDX(CC(ctx), ctx->i_flags)) {
1592 1572 case CIDX(CW_C_CC, 0):
1593 1573 program = getenv("CW_CC");
1594 1574 dir = getenv("CW_CC_DIR");
1595 1575 break;
1596 1576 case CIDX(CW_C_CC, CW_F_CXX):
1597 1577 program = getenv("CW_CPLUSPLUS");
1598 1578 dir = getenv("CW_CPLUSPLUS_DIR");
1599 1579 break;
1600 1580 case CIDX(CW_C_GCC, 0):
1601 1581 program = getenv("CW_GCC");
1602 1582 dir = getenv("CW_GCC_DIR");
1603 1583 break;
1604 1584 case CIDX(CW_C_GCC, CW_F_CXX):
1605 1585 program = getenv("CW_GPLUSPLUS");
1606 1586 dir = getenv("CW_GPLUSPLUS_DIR");
1607 1587 break;
1608 1588 }
1609 1589
1610 1590 if (program == NULL) {
1611 1591 if (dir == NULL)
1612 1592 dir = default_dir[CC(ctx)];
1613 1593 cmd = cmds[CIDX(CC(ctx), ctx->i_flags)];
1614 1594 len = strlen(dir) + strlen(cmd) + 2;
1615 1595 if ((program = malloc(len)) == NULL)
1616 1596 nomem();
1617 1597 (void) snprintf(program, len, "%s/%s", dir, cmd);
1618 1598 }
1619 1599
1620 1600 newae(ctx->i_ae, program);
1621 1601
1622 1602 if (ctx->i_flags & CW_F_PROG) {
1623 1603 (void) printf("%s: %s\n", (ctx->i_flags & CW_F_SHADOW) ?
1624 1604 "shadow" : "primary", program);
1625 1605 (void) fflush(stdout);
1626 1606 }
1627 1607
1628 1608 if (!(ctx->i_flags & CW_F_XLATE))
1629 1609 return;
1630 1610
1631 1611 switch (CC(ctx)) {
1632 1612 case CW_C_CC:
1633 1613 do_cc(ctx);
1634 1614 break;
1635 1615 case CW_C_GCC:
1636 1616 do_gcc(ctx);
1637 1617 break;
1638 1618 }
1639 1619 }
1640 1620
1641 1621 static int
1642 1622 invoke(cw_ictx_t *ctx)
1643 1623 {
1644 1624 char **newargv;
1645 1625 int ac;
1646 1626 struct ae *a;
1647 1627
1648 1628 if ((newargv = calloc(sizeof (*newargv), ctx->i_ae->ael_argc + 1)) ==
1649 1629 NULL)
1650 1630 nomem();
1651 1631
1652 1632 if (ctx->i_flags & CW_F_ECHO)
1653 1633 (void) fprintf(stderr, "+ ");
1654 1634
1655 1635 for (ac = 0, a = ctx->i_ae->ael_head; a; a = a->ae_next, ac++) {
1656 1636 newargv[ac] = a->ae_arg;
1657 1637 if (ctx->i_flags & CW_F_ECHO)
1658 1638 (void) fprintf(stderr, "%s ", a->ae_arg);
1659 1639 if (a == ctx->i_ae->ael_tail)
1660 1640 break;
1661 1641 }
1662 1642
1663 1643 if (ctx->i_flags & CW_F_ECHO) {
1664 1644 (void) fprintf(stderr, "\n");
1665 1645 (void) fflush(stderr);
1666 1646 }
1667 1647
1668 1648 if (!(ctx->i_flags & CW_F_EXEC))
1669 1649 return (0);
1670 1650
1671 1651 /*
1672 1652 * We must fix up the environment here so that the
1673 1653 * dependency files are not trampled by the shadow compiler.
1674 1654 */
1675 1655 if ((ctx->i_flags & CW_F_SHADOW) &&
1676 1656 (unsetenv("SUNPRO_DEPENDENCIES") != 0 ||
1677 1657 unsetenv("DEPENDENCIES_OUTPUT") != 0)) {
1678 1658 (void) fprintf(stderr, "error: environment setup failed: %s\n",
1679 1659 strerror(errno));
1680 1660 return (-1);
1681 1661 }
1682 1662
1683 1663 (void) execv(newargv[0], newargv);
1684 1664 cw_perror("couldn't run %s", newargv[0]);
1685 1665
1686 1666 return (-1);
1687 1667 }
1688 1668
1689 1669 static int
1690 1670 reap(cw_ictx_t *ctx)
1691 1671 {
1692 1672 int status, ret = 0;
1693 1673 char buf[1024];
1694 1674 struct stat s;
1695 1675
1696 1676 /*
1697 1677 * Only wait for one specific child.
1698 1678 */
1699 1679 if (ctx->i_pid <= 0)
1700 1680 return (-1);
1701 1681
1702 1682 do {
1703 1683 if (waitpid(ctx->i_pid, &status, 0) < 0) {
1704 1684 cw_perror("cannot reap child");
1705 1685 return (-1);
1706 1686 }
1707 1687 if (status != 0) {
1708 1688 if (WIFSIGNALED(status)) {
1709 1689 ret = -WTERMSIG(status);
1710 1690 break;
1711 1691 } else if (WIFEXITED(status)) {
1712 1692 ret = WEXITSTATUS(status);
1713 1693 break;
1714 1694 }
1715 1695 }
1716 1696 } while (!WIFEXITED(status) && !WIFSIGNALED(status));
1717 1697
1718 1698 (void) unlink(ctx->i_discard);
1719 1699
1720 1700 if (stat(ctx->i_stderr, &s) < 0) {
1721 1701 cw_perror("stat failed on child cleanup");
1722 1702 return (-1);
1723 1703 }
1724 1704 if (s.st_size != 0) {
1725 1705 FILE *f;
1726 1706
1727 1707 if ((f = fopen(ctx->i_stderr, "r")) != NULL) {
1728 1708 while (fgets(buf, sizeof (buf), f))
1729 1709 (void) fprintf(stderr, "%s", buf);
1730 1710 (void) fflush(stderr);
1731 1711 (void) fclose(f);
1732 1712 }
1733 1713 }
1734 1714 (void) unlink(ctx->i_stderr);
1735 1715 free(ctx->i_stderr);
1736 1716
1737 1717 /*
1738 1718 * cc returns an error code when given -V; we want that to succeed.
1739 1719 */
1740 1720 if (ctx->i_flags & CW_F_PROG)
1741 1721 return (0);
1742 1722
1743 1723 return (ret);
1744 1724 }
1745 1725
1746 1726 static int
1747 1727 exec_ctx(cw_ictx_t *ctx, int block)
1748 1728 {
1749 1729 char *file;
1750 1730
1751 1731 /*
1752 1732 * To avoid offending cc's sensibilities, the name of its output
1753 1733 * file must end in '.o'.
1754 1734 */
1755 1735 if ((file = tempnam(NULL, ".cw")) == NULL) {
1756 1736 nomem();
1757 1737 return (-1);
1758 1738 }
1759 1739 (void) strlcpy(ctx->i_discard, file, MAXPATHLEN);
1760 1740 (void) strlcat(ctx->i_discard, ".o", MAXPATHLEN);
1761 1741 free(file);
1762 1742
1763 1743 if ((ctx->i_stderr = tempnam(NULL, ".cw")) == NULL) {
1764 1744 nomem();
1765 1745 return (-1);
1766 1746 }
1767 1747
1768 1748 if ((ctx->i_pid = fork()) == 0) {
1769 1749 int fd;
1770 1750
1771 1751 (void) fclose(stderr);
1772 1752 if ((fd = open(ctx->i_stderr, O_WRONLY | O_CREAT | O_EXCL,
1773 1753 0666)) < 0) {
1774 1754 cw_perror("open failed for standard error");
1775 1755 exit(1);
1776 1756 }
1777 1757 if (dup2(fd, 2) < 0) {
1778 1758 cw_perror("dup2 failed for standard error");
1779 1759 exit(1);
1780 1760 }
1781 1761 if (fd != 2)
1782 1762 (void) close(fd);
1783 1763 if (freopen("/dev/fd/2", "w", stderr) == NULL) {
1784 1764 cw_perror("freopen failed for /dev/fd/2");
1785 1765 exit(1);
1786 1766 }
1787 1767 prepctx(ctx);
1788 1768 exit(invoke(ctx));
1789 1769 }
1790 1770
1791 1771 if (ctx->i_pid < 0) {
1792 1772 cw_perror("fork failed");
1793 1773 return (1);
1794 1774 }
1795 1775
1796 1776 if (block)
1797 1777 return (reap(ctx));
1798 1778
1799 1779 return (0);
1800 1780 }
1801 1781
1802 1782 int
1803 1783 main(int argc, char **argv)
1804 1784 {
1805 1785 cw_ictx_t *ctx = newictx();
1806 1786 cw_ictx_t *ctx_shadow = newictx();
1807 1787 const char *dir;
1808 1788 int do_serial, do_shadow;
1809 1789 int ret = 0;
1810 1790
1811 1791 if ((progname = strrchr(argv[0], '/')) == NULL)
1812 1792 progname = argv[0];
1813 1793 else
1814 1794 progname++;
1815 1795
1816 1796 if (ctx == NULL || ctx_shadow == NULL)
1817 1797 nomem();
1818 1798
1819 1799 ctx->i_flags = CW_F_ECHO|CW_F_XLATE;
1820 1800
1821 1801 /*
1822 1802 * Figure out where to get our tools from. This depends on
1823 1803 * the environment variables set at run time.
1824 1804 */
1825 1805 if ((dir = getenv("SPRO_VROOT")) != NULL) {
1826 1806 (void) snprintf(default_dir[CW_C_CC], MAXPATHLEN,
1827 1807 "%s/bin", dir);
1828 1808 } else if ((dir = getenv("SPRO_ROOT")) != NULL) {
1829 1809 (void) snprintf(default_dir[CW_C_CC], MAXPATHLEN,
1830 1810 "%s/SS12/bin", dir);
1831 1811 } else if ((dir = getenv("BUILD_TOOLS")) != NULL) {
1832 1812 (void) snprintf(default_dir[CW_C_CC], MAXPATHLEN,
1833 1813 "%s/SUNWspro/SS12/bin", dir);
1834 1814 }
1835 1815
1836 1816 if ((dir = getenv("GCC_ROOT")) != NULL) {
1837 1817 (void) snprintf(default_dir[CW_C_GCC], MAXPATHLEN,
1838 1818 "%s/bin", dir);
1839 1819 }
1840 1820
1841 1821 do_shadow = (getenv("CW_NO_SHADOW") ? 0 : 1);
1842 1822 do_serial = (getenv("CW_SHADOW_SERIAL") ? 1 : 0);
1843 1823
1844 1824 if (getenv("CW_NO_EXEC") == NULL)
1845 1825 ctx->i_flags |= CW_F_EXEC;
1846 1826
1847 1827 /*
1848 1828 * The first argument must be one of "-_cc", "-_gcc", "-_CC", or "-_g++"
1849 1829 */
1850 1830 if (argc == 1)
1851 1831 usage();
1852 1832 argc--;
1853 1833 argv++;
1854 1834 if (strcmp(argv[0], "-_cc") == 0) {
1855 1835 ctx->i_compiler = CW_C_CC;
1856 1836 } else if (strcmp(argv[0], "-_gcc") == 0) {
1857 1837 ctx->i_compiler = CW_C_GCC;
1858 1838 } else if (strcmp(argv[0], "-_CC") == 0) {
1859 1839 ctx->i_compiler = CW_C_CC;
1860 1840 ctx->i_flags |= CW_F_CXX;
1861 1841 } else if (strcmp(argv[0], "-_g++") == 0) {
1862 1842 ctx->i_compiler = CW_C_GCC;
1863 1843 ctx->i_flags |= CW_F_CXX;
1864 1844 } else {
1865 1845 /* assume "-_gcc" by default */
1866 1846 argc++;
1867 1847 argv--;
1868 1848 ctx->i_compiler = CW_C_GCC;
1869 1849 }
1870 1850
1871 1851 /*
1872 1852 * -_compiler - tell us the path to the primary compiler only
1873 1853 */
1874 1854 if (argc > 1 && strcmp(argv[1], "-_compiler") == 0) {
1875 1855 ctx->i_flags &= ~CW_F_XLATE;
1876 1856 prepctx(ctx);
1877 1857 (void) printf("%s\n", ctx->i_ae->ael_head->ae_arg);
1878 1858 return (0);
1879 1859 }
1880 1860
1881 1861 /*
1882 1862 * -_versions - tell us the cw version, paths to all compilers, and
1883 1863 * ask each for its version if we know how.
1884 1864 */
1885 1865 if (argc > 1 && strcmp(argv[1], "-_versions") == 0) {
1886 1866 (void) printf("cw version %s", CW_VERSION);
1887 1867 if (!do_shadow)
1888 1868 (void) printf(" (SHADOW MODE DISABLED)");
1889 1869 (void) printf("\n");
1890 1870 (void) fflush(stdout);
1891 1871 ctx->i_flags &= ~CW_F_ECHO;
1892 1872 ctx->i_flags |= CW_F_PROG|CW_F_EXEC;
1893 1873 argc--;
1894 1874 argv++;
1895 1875 do_serial = 1;
1896 1876 }
1897 1877
1898 1878 ctx->i_oldargc = argc;
1899 1879 ctx->i_oldargv = argv;
1900 1880
1901 1881 ret |= exec_ctx(ctx, do_serial);
1902 1882
1903 1883 if (do_shadow) {
1904 1884 (void) memcpy(ctx_shadow, ctx, sizeof (cw_ictx_t));
1905 1885 ctx_shadow->i_flags |= CW_F_SHADOW;
1906 1886 ret |= exec_ctx(ctx_shadow, 1);
1907 1887 }
1908 1888
1909 1889 if (!do_serial)
1910 1890 ret |= reap(ctx);
1911 1891
1912 1892 return (ret);
1913 1893 }
↓ open down ↓ |
584 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX