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