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