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