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