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