xref: /illumos-gate/usr/src/tools/cw/cw.c (revision 1912d2c4)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
502e56f3fSwesolows  * Common Development and Distribution License (the "License").
602e56f3fSwesolows  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2102e56f3fSwesolows 
227c478bd9Sstevel@tonic-gate /*
2380ab886dSwesolows  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Wrapper for the GNU C compiler to make it accept the Sun C compiler
317c478bd9Sstevel@tonic-gate  * arguments where possible.
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  * Since the translation is inexact, this is something of a work-in-progress.
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * -#		Verbose mode
387c478bd9Sstevel@tonic-gate  * -###		Show compiler commands built by driver, no compilation
397c478bd9Sstevel@tonic-gate  * -A<name[(tokens)]>	Preprocessor predicate assertion
407c478bd9Sstevel@tonic-gate  * -B<[static|dynamic]>	Specify dynamic or static binding
417c478bd9Sstevel@tonic-gate  * -C		Prevent preprocessor from removing comments
427c478bd9Sstevel@tonic-gate  * -c		Compile only - produce .o files, suppress linking
437c478bd9Sstevel@tonic-gate  * -cg92	Alias for -xtarget=ss1000
447c478bd9Sstevel@tonic-gate  * -D<name[=token]>	Associate name with token as if by #define
457c478bd9Sstevel@tonic-gate  * -d[y|n]	dynamic [-dy] or static [-dn] option to linker
467c478bd9Sstevel@tonic-gate  * -E		Compile source through preprocessor only, output to stdout
477c478bd9Sstevel@tonic-gate  * -erroff=<t>	Suppress warnings specified by tags t(%none, %all, <tag list>)
487c478bd9Sstevel@tonic-gate  * -errtags=<a>	Display messages with tags a(no, yes)
497c478bd9Sstevel@tonic-gate  * -errwarn=<t>	Treats warnings specified by tags t(%none, %all, <tag list>)
507c478bd9Sstevel@tonic-gate  *		as errors
517c478bd9Sstevel@tonic-gate  * -fast	Optimize using a selection of options
527c478bd9Sstevel@tonic-gate  * -fd		Report old-style function definitions and declarations
537c478bd9Sstevel@tonic-gate  * -flags	Show this summary of compiler options
547c478bd9Sstevel@tonic-gate  * -fnonstd	Initialize floating-point hardware to non-standard preferences
557c478bd9Sstevel@tonic-gate  * -fns[=<yes|no>] Select non-standard floating point mode
567c478bd9Sstevel@tonic-gate  * -fprecision=<p> Set FP rounding precision mode p(single, double, extended)
577c478bd9Sstevel@tonic-gate  * -fround=<r>	Select the IEEE rounding mode in effect at startup
587c478bd9Sstevel@tonic-gate  * -fsimple[=<n>] Select floating-point optimization preferences <n>
597c478bd9Sstevel@tonic-gate  * -fsingle	Use single-precision arithmetic (-Xt and -Xs modes only)
607c478bd9Sstevel@tonic-gate  * -ftrap=<t>	Select floating-point trapping mode in effect at startup
617c478bd9Sstevel@tonic-gate  * -fstore	force floating pt. values to target precision on assignment
627c478bd9Sstevel@tonic-gate  * -G		Build a dynamic shared library
637c478bd9Sstevel@tonic-gate  * -g		Compile for debugging
647c478bd9Sstevel@tonic-gate  * -H		Print path name of each file included during compilation
657c478bd9Sstevel@tonic-gate  * -h <name>	Assign <name> to generated dynamic shared library
667c478bd9Sstevel@tonic-gate  * -I<dir>	Add <dir> to preprocessor #include file search path
677c478bd9Sstevel@tonic-gate  * -i		Passed to linker to ignore any LD_LIBRARY_PATH setting
687c478bd9Sstevel@tonic-gate  * -keeptmp	Keep temporary files created during compilation
697c478bd9Sstevel@tonic-gate  * -KPIC	Compile position independent code with 32-bit addresses
707c478bd9Sstevel@tonic-gate  * -Kpic	Compile position independent code
717c478bd9Sstevel@tonic-gate  * -L<dir>	Pass to linker to add <dir> to the library search path
727c478bd9Sstevel@tonic-gate  * -l<name>	Link with library lib<name>.a or lib<name>.so
737c478bd9Sstevel@tonic-gate  * -mc		Remove duplicate strings from .comment section of output files
747c478bd9Sstevel@tonic-gate  * -mr		Remove all strings from .comment section of output files
757c478bd9Sstevel@tonic-gate  * -mr,"string"	Remove all strings and append "string" to .comment section
767c478bd9Sstevel@tonic-gate  * -mt		Specify options needed when compiling multi-threaded code
777c478bd9Sstevel@tonic-gate  * -native	Find available processor, generate code accordingly
787c478bd9Sstevel@tonic-gate  * -nofstore	Do not force floating pt. values to target precision
797c478bd9Sstevel@tonic-gate  *		on assignment
807c478bd9Sstevel@tonic-gate  * -nolib	Same as -xnolib
817c478bd9Sstevel@tonic-gate  * -noqueue	Disable queuing of compiler license requests
827c478bd9Sstevel@tonic-gate  * -norunpath	Do not build in a runtime path for shared libraries
83662492f5Ssherrym  * -O		Use default optimization level (-xO2 or -xO3. Check man page.)
847c478bd9Sstevel@tonic-gate  * -o <outputfile> Set name of output file to <outputfile>
857c478bd9Sstevel@tonic-gate  * -P		Compile source through preprocessor only, output to .i  file
867c478bd9Sstevel@tonic-gate  * -PIC		Alias for -KPIC or -xcode=pic32
877c478bd9Sstevel@tonic-gate  * -p		Compile for profiling with prof
887c478bd9Sstevel@tonic-gate  * -pic		Alias for -Kpic or -xcode=pic13
897c478bd9Sstevel@tonic-gate  * -Q[y|n]	Emit/don't emit identification info to output file
907c478bd9Sstevel@tonic-gate  * -qp		Compile for profiling with prof
917c478bd9Sstevel@tonic-gate  * -R<dir[:dir]> Build runtime search path list into executable
927c478bd9Sstevel@tonic-gate  * -S		Compile and only generate assembly code (.s)
937c478bd9Sstevel@tonic-gate  * -s		Strip symbol table from the executable file
94159cf8a6Swesolows  * -t		Turn off duplicate symbol warnings when linking
957c478bd9Sstevel@tonic-gate  * -U<name>	Delete initial definition of preprocessor symbol <name>
967c478bd9Sstevel@tonic-gate  * -V		Report version number of each compilation phase
977c478bd9Sstevel@tonic-gate  * -v		Do stricter semantic checking
987c478bd9Sstevel@tonic-gate  * -W<c>,<arg>	Pass <arg> to specified component <c> (a,l,m,p,0,2,h,i,u)
997c478bd9Sstevel@tonic-gate  * -w		Suppress compiler warning messages
1007c478bd9Sstevel@tonic-gate  * -Xa		Compile assuming ANSI C conformance, allow K & R extensions
1017c478bd9Sstevel@tonic-gate  *		(default mode)
1027c478bd9Sstevel@tonic-gate  * -Xc		Compile assuming strict ANSI C conformance
1037c478bd9Sstevel@tonic-gate  * -Xs		Compile assuming (pre-ANSI) K & R C style code
1047c478bd9Sstevel@tonic-gate  * -Xt		Compile assuming K & R conformance, allow ANSI C
1057c478bd9Sstevel@tonic-gate  * -x386	Generate code for the 80386 processor
1067c478bd9Sstevel@tonic-gate  * -x486	Generate code for the 80486 processor
1077c478bd9Sstevel@tonic-gate  * -xarch=<a>	Specify target architecture instruction set
1087c478bd9Sstevel@tonic-gate  * -xbuiltin[=<b>] When profitable inline, or substitute intrinisic functions
1097c478bd9Sstevel@tonic-gate  *		for system functions, b={%all,%none}
1107c478bd9Sstevel@tonic-gate  * -xCC		Accept C++ style comments
1117c478bd9Sstevel@tonic-gate  * -xchar_byte_order=<o> Specify multi-char byte order <o> (default, high, low)
1127c478bd9Sstevel@tonic-gate  * -xchip=<c>	Specify the target processor for use by the optimizer
1137c478bd9Sstevel@tonic-gate  * -xcode=<c>	Generate different code for forming addresses
1147c478bd9Sstevel@tonic-gate  * -xcrossfile[=<n>] Enable optimization and inlining across source files,
1157c478bd9Sstevel@tonic-gate  *		n={0|1}
1167c478bd9Sstevel@tonic-gate  * -xe		Perform only syntax/semantic checking, no code generation
1177c478bd9Sstevel@tonic-gate  * -xF		Compile for later mapfile reordering
1187c478bd9Sstevel@tonic-gate  * -xhelp=<f>	Display on-line help information f(flags, readme, errors)
1197c478bd9Sstevel@tonic-gate  * -xildoff	Cancel -xildon
1207c478bd9Sstevel@tonic-gate  * -xildon	Enable use of the incremental linker, ild
1217c478bd9Sstevel@tonic-gate  * -xinline=[<a>,...,<a>]  Attempt inlining of specified user routines,
1227c478bd9Sstevel@tonic-gate  *		<a>={%auto,func,no%func}
1237c478bd9Sstevel@tonic-gate  * -xlibmieee	Force IEEE 754 return values for math routines in
1247c478bd9Sstevel@tonic-gate  *		exceptional cases
1257c478bd9Sstevel@tonic-gate  * -xlibmil	Inline selected libm math routines for optimization
1267c478bd9Sstevel@tonic-gate  * -xlic_lib=sunperf	Link in the Sun supplied performance libraries
1277c478bd9Sstevel@tonic-gate  * -xlicinfo	Show license server information
1287c478bd9Sstevel@tonic-gate  * -xM		Generate makefile dependencies
1297c478bd9Sstevel@tonic-gate  * -xM1		Generate makefile dependencies, but exclude /usr/include
1307c478bd9Sstevel@tonic-gate  * -xmaxopt=[off,1,2,3,4,5] maximum optimization level allowed on #pragma opt
1317c478bd9Sstevel@tonic-gate  * -xnolib	Do not link with default system libraries
1327c478bd9Sstevel@tonic-gate  * -xnolibmil	Cancel -xlibmil on command line
1337c478bd9Sstevel@tonic-gate  * -xO<n>	Generate optimized code (n={1|2|3|4|5})
1347c478bd9Sstevel@tonic-gate  * -xP		Print prototypes for function definitions
1357c478bd9Sstevel@tonic-gate  * -xpentium	Generate code for the pentium processor
1367c478bd9Sstevel@tonic-gate  * -xpg		Compile for profiling with gprof
1377c478bd9Sstevel@tonic-gate  * -xprofile=<p> Collect data for a profile or use a profile to optimize
1387c478bd9Sstevel@tonic-gate  *		<p>={{collect,use}[:<path>],tcov}
1397c478bd9Sstevel@tonic-gate  * -xregs=<r>	Control register allocation
1407c478bd9Sstevel@tonic-gate  * -xs		Allow debugging without object (.o) files
1417c478bd9Sstevel@tonic-gate  * -xsb		Compile for use with the WorkShop source browser
1427c478bd9Sstevel@tonic-gate  * -xsbfast	Generate only WorkShop source browser info, no compilation
1437c478bd9Sstevel@tonic-gate  * -xsfpconst	Represent unsuffixed floating point constants as single
1447c478bd9Sstevel@tonic-gate  *		precision
1457c478bd9Sstevel@tonic-gate  * -xspace	Do not do optimizations that increase code size
1467c478bd9Sstevel@tonic-gate  * -xstrconst	Place string literals into read-only data segment
1477c478bd9Sstevel@tonic-gate  * -xtarget=<t>	Specify target system for optimization
1487c478bd9Sstevel@tonic-gate  * -xtemp=<dir>	Set directory for temporary files to <dir>
1497c478bd9Sstevel@tonic-gate  * -xtime	Report the execution time for each compilation phase
1507c478bd9Sstevel@tonic-gate  * -xtransition	Emit warnings for differences between K&R C and ANSI C
1517c478bd9Sstevel@tonic-gate  * -xtrigraphs[=<yes|no>] Enable|disable trigraph translation
1527c478bd9Sstevel@tonic-gate  * -xunroll=n	Enable unrolling loops n times where possible
1537c478bd9Sstevel@tonic-gate  * -Y<c>,<dir>	Specify <dir> for location of component <c> (a,l,m,p,0,h,i,u)
1547c478bd9Sstevel@tonic-gate  * -YA,<dir>	Change default directory searched for components
1557c478bd9Sstevel@tonic-gate  * -YI,<dir>	Change default directory searched for include files
1567c478bd9Sstevel@tonic-gate  * -YP,<dir>	Change default directory for finding libraries files
1577c478bd9Sstevel@tonic-gate  * -YS,<dir>	Change default directory for startup object files
1587c478bd9Sstevel@tonic-gate  */
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate /*
1617c478bd9Sstevel@tonic-gate  * Translation table:
1627c478bd9Sstevel@tonic-gate  */
1637c478bd9Sstevel@tonic-gate /*
1647c478bd9Sstevel@tonic-gate  * -#				-v
1657c478bd9Sstevel@tonic-gate  * -###				error
1667c478bd9Sstevel@tonic-gate  * -A<name[(tokens)]>		pass-thru
1677c478bd9Sstevel@tonic-gate  * -B<[static|dynamic]>		pass-thru (syntax error for anything else)
1687c478bd9Sstevel@tonic-gate  * -C				pass-thru
1697c478bd9Sstevel@tonic-gate  * -c				pass-thru
1707c478bd9Sstevel@tonic-gate  * -cg92			-m32 -mcpu=v8 -mtune=supersparc (SPARC only)
1717c478bd9Sstevel@tonic-gate  * -D<name[=token]>		pass-thru
1727c478bd9Sstevel@tonic-gate  * -dy or -dn			-Wl,-dy or -Wl,-dn
1737c478bd9Sstevel@tonic-gate  * -E				pass-thru
1747c478bd9Sstevel@tonic-gate  * -erroff=E_EMPTY_TRANSLATION_UNIT ignore
1757c478bd9Sstevel@tonic-gate  * -errtags=%all		-Wall
1767c478bd9Sstevel@tonic-gate  * -errwarn=%all		-Werror else -Wno-error
1777c478bd9Sstevel@tonic-gate  * -fast			error
1787c478bd9Sstevel@tonic-gate  * -fd				error
1797c478bd9Sstevel@tonic-gate  * -flags			--help
1807c478bd9Sstevel@tonic-gate  * -fnonstd			error
1817c478bd9Sstevel@tonic-gate  * -fns[=<yes|no>]		error
1827c478bd9Sstevel@tonic-gate  * -fprecision=<p>		error
1837c478bd9Sstevel@tonic-gate  * -fround=<r>			error
1847c478bd9Sstevel@tonic-gate  * -fsimple[=<n>]		error
1857c478bd9Sstevel@tonic-gate  * -fsingle[=<n>]		error
1867c478bd9Sstevel@tonic-gate  * -ftrap=<t>			error
1877c478bd9Sstevel@tonic-gate  * -fstore			error
1887c478bd9Sstevel@tonic-gate  * -G				pass-thru
1897c478bd9Sstevel@tonic-gate  * -g				pass-thru
1907c478bd9Sstevel@tonic-gate  * -H				pass-thru
1917c478bd9Sstevel@tonic-gate  * -h <name>			pass-thru
1927c478bd9Sstevel@tonic-gate  * -I<dir>			pass-thru
1937c478bd9Sstevel@tonic-gate  * -i				pass-thru
1947c478bd9Sstevel@tonic-gate  * -keeptmp			-save-temps
1957c478bd9Sstevel@tonic-gate  * -KPIC			-fPIC
1967c478bd9Sstevel@tonic-gate  * -Kpic			-fpic
1977c478bd9Sstevel@tonic-gate  * -L<dir>			pass-thru
1987c478bd9Sstevel@tonic-gate  * -l<name>			pass-thru
1997c478bd9Sstevel@tonic-gate  * -mc				error
2007c478bd9Sstevel@tonic-gate  * -mr				error
2017c478bd9Sstevel@tonic-gate  * -mr,"string"			error
2027c478bd9Sstevel@tonic-gate  * -mt				-D_REENTRANT
2037c478bd9Sstevel@tonic-gate  * -native			error
2047c478bd9Sstevel@tonic-gate  * -nofstore			error
2057c478bd9Sstevel@tonic-gate  * -nolib			-nodefaultlibs
2067c478bd9Sstevel@tonic-gate  * -noqueue			ignore
2077c478bd9Sstevel@tonic-gate  * -norunpath			ignore
208662492f5Ssherrym  * -O				-O1 (Check the man page to be certain)
2097c478bd9Sstevel@tonic-gate  * -o <outputfile>		pass-thru
2107c478bd9Sstevel@tonic-gate  * -P				-E -o filename.i (or error)
2117c478bd9Sstevel@tonic-gate  * -PIC				-fPIC (C++ only)
2127c478bd9Sstevel@tonic-gate  * -p				pass-thru
2137c478bd9Sstevel@tonic-gate  * -pic				-fpic (C++ only)
2147c478bd9Sstevel@tonic-gate  * -Q[y|n]			error
2157c478bd9Sstevel@tonic-gate  * -qp				-p
2167c478bd9Sstevel@tonic-gate  * -R<dir[:dir]>		pass-thru
2177c478bd9Sstevel@tonic-gate  * -S				pass-thru
2187c478bd9Sstevel@tonic-gate  * -s				-Wl,-s
219159cf8a6Swesolows  * -t				-Wl,-t
2207c478bd9Sstevel@tonic-gate  * -U<name>			pass-thru
2217c478bd9Sstevel@tonic-gate  * -V				--version
2227c478bd9Sstevel@tonic-gate  * -v				-Wall
2237c478bd9Sstevel@tonic-gate  * -Wa,<arg>			pass-thru
2247c478bd9Sstevel@tonic-gate  * -Wp,<arg>			pass-thru except -xc99=<a>
2257c478bd9Sstevel@tonic-gate  * -Wl,<arg>			pass-thru
2267c478bd9Sstevel@tonic-gate  * -W{m,0,2,h,i,u>		error/ignore
2277c478bd9Sstevel@tonic-gate  * -Wu,-xmodel=kernel		-ffreestanding -mcmodel=kernel -mno-red-zone
228d430274bSsherrym  * -Wu,-save_args		-msave-args
2297c478bd9Sstevel@tonic-gate  * -w				pass-thru
2307c478bd9Sstevel@tonic-gate  * -Xa				-std=iso9899:199409 or -ansi
2317c478bd9Sstevel@tonic-gate  * -Xc				-ansi -pedantic
2327c478bd9Sstevel@tonic-gate  * -Xt				error
2337c478bd9Sstevel@tonic-gate  * -Xs				-traditional -std=c89
2347c478bd9Sstevel@tonic-gate  * -x386			-march=i386 (x86 only)
2357c478bd9Sstevel@tonic-gate  * -x486			-march=i486 (x86 only)
2367c478bd9Sstevel@tonic-gate  * -xarch=<a>			table
23702e56f3fSwesolows  * -xbuiltin[=<b>]		-fbuiltin (-fno-builtin otherwise)
2387c478bd9Sstevel@tonic-gate  * -xCC				ignore
2397c478bd9Sstevel@tonic-gate  * -xchar_byte_order=<o>	error
2407c478bd9Sstevel@tonic-gate  * -xchip=<c>			table
2417c478bd9Sstevel@tonic-gate  * -xcode=<c>			table
2428c1a3716Ssherrym  * -xdebugformat=<format>	ignore (always use dwarf-2 for gcc)
243159cf8a6Swesolows  * -xcrossfile[=<n>]		ignore
2447c478bd9Sstevel@tonic-gate  * -xe				error
2457c478bd9Sstevel@tonic-gate  * -xF				error
2467c478bd9Sstevel@tonic-gate  * -xhelp=<f>			error
2477c478bd9Sstevel@tonic-gate  * -xildoff			ignore
2487c478bd9Sstevel@tonic-gate  * -xildon			ignore
2497c478bd9Sstevel@tonic-gate  * -xinline			ignore
2507c478bd9Sstevel@tonic-gate  * -xlibmieee			error
2517c478bd9Sstevel@tonic-gate  * -xlibmil			error
2527c478bd9Sstevel@tonic-gate  * -xlic_lib=sunperf		error
2537c478bd9Sstevel@tonic-gate  * -xM				-M
2547c478bd9Sstevel@tonic-gate  * -xM1				-MM
2557c478bd9Sstevel@tonic-gate  * -xmaxopt=[...]		error
2567c478bd9Sstevel@tonic-gate  * -xnolib			-nodefaultlibs
2577c478bd9Sstevel@tonic-gate  * -xnolibmil			error
2587c478bd9Sstevel@tonic-gate  * -xO<n>			-O<n>
2597c478bd9Sstevel@tonic-gate  * -xP				error
2607c478bd9Sstevel@tonic-gate  * -xpentium			-march=pentium (x86 only)
2617c478bd9Sstevel@tonic-gate  * -xpg				error
2627c478bd9Sstevel@tonic-gate  * -xprofile=<p>		error
2637c478bd9Sstevel@tonic-gate  * -xregs=<r>			table
2647c478bd9Sstevel@tonic-gate  * -xs				error
2657c478bd9Sstevel@tonic-gate  * -xsb				error
2667c478bd9Sstevel@tonic-gate  * -xsbfast			error
2677c478bd9Sstevel@tonic-gate  * -xsfpconst			error
2687c478bd9Sstevel@tonic-gate  * -xspace			ignore (-not -Os)
2697c478bd9Sstevel@tonic-gate  * -xstrconst			ignore
2707c478bd9Sstevel@tonic-gate  * -xtarget=<t>			table
2717c478bd9Sstevel@tonic-gate  * -xtemp=<dir>			error
2727c478bd9Sstevel@tonic-gate  * -xtime			error
2737c478bd9Sstevel@tonic-gate  * -xtransition			-Wtransition
2747c478bd9Sstevel@tonic-gate  * -xtrigraphs=<yes|no>		-trigraphs -notrigraphs
2757c478bd9Sstevel@tonic-gate  * -xunroll=n			error
2768c1a3716Ssherrym  * -W0,-xdbggen=no%usedonly	-fno-eliminate-unused-debug-symbols
2778c1a3716Ssherrym  *				-fno-eliminate-unused-debug-types
2787c478bd9Sstevel@tonic-gate  * -Y<c>,<dir>			error
2797c478bd9Sstevel@tonic-gate  * -YA,<dir>			error
2807c478bd9Sstevel@tonic-gate  * -YI,<dir>			-nostdinc -I<dir>
2817c478bd9Sstevel@tonic-gate  * -YP,<dir>			error
2827c478bd9Sstevel@tonic-gate  * -YS,<dir>			error
2837c478bd9Sstevel@tonic-gate  */
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate #include <stdio.h>
2867c478bd9Sstevel@tonic-gate #include <sys/types.h>
2877c478bd9Sstevel@tonic-gate #include <unistd.h>
2887c478bd9Sstevel@tonic-gate #include <string.h>
2897c478bd9Sstevel@tonic-gate #include <stdlib.h>
2907c478bd9Sstevel@tonic-gate #include <ctype.h>
29180ab886dSwesolows #include <fcntl.h>
29280ab886dSwesolows #include <errno.h>
29380ab886dSwesolows #include <stdarg.h>
2947c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
2957c478bd9Sstevel@tonic-gate #include <sys/param.h>
2967c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
29780ab886dSwesolows #include <sys/wait.h>
29880ab886dSwesolows #include <sys/stat.h>
29980ab886dSwesolows 
30080ab886dSwesolows #define	CW_F_CXX	0x01
30180ab886dSwesolows #define	CW_F_SHADOW	0x02
30280ab886dSwesolows #define	CW_F_EXEC	0x04
30380ab886dSwesolows #define	CW_F_ECHO	0x08
30480ab886dSwesolows #define	CW_F_XLATE	0x10
305*1912d2c4Swesolows #define	CW_F_PROG	0x20
30680ab886dSwesolows 
30780ab886dSwesolows typedef enum cw_compiler {
30880ab886dSwesolows 	CW_C_CC = 0,
30980ab886dSwesolows 	CW_C_GCC
31080ab886dSwesolows } cw_compiler_t;
31180ab886dSwesolows 
31280ab886dSwesolows static const char *cmds[] = {
31380ab886dSwesolows 	"cc", "CC",
31480ab886dSwesolows 	"gcc", "g++"
31580ab886dSwesolows };
3167c478bd9Sstevel@tonic-gate 
31780ab886dSwesolows static const char *dirs[] = {
31880ab886dSwesolows 	DEFAULT_CC_DIR, DEFAULT_CPLUSPLUS_DIR,
31980ab886dSwesolows 	DEFAULT_GCC_DIR, DEFAULT_GPLUSPLUS_DIR
32080ab886dSwesolows };
3217c478bd9Sstevel@tonic-gate 
32280ab886dSwesolows #define	CC(ctx) \
32380ab886dSwesolows 	(((ctx)->i_flags & CW_F_SHADOW) ? \
32480ab886dSwesolows 	    ((ctx)->i_compiler == CW_C_CC ? CW_C_GCC : CW_C_CC) : \
32580ab886dSwesolows 	    (ctx)->i_compiler)
3267c478bd9Sstevel@tonic-gate 
32780ab886dSwesolows #define	CIDX(compiler, flags)	\
32880ab886dSwesolows 	((int)(compiler) << 1) + ((flags) & CW_F_CXX ? 1 : 0)
32980ab886dSwesolows 
33080ab886dSwesolows typedef enum cw_op {
33180ab886dSwesolows 	CW_O_NONE = 0,
33280ab886dSwesolows 	CW_O_PREPROCESS,
33380ab886dSwesolows 	CW_O_COMPILE,
33480ab886dSwesolows 	CW_O_LINK
33580ab886dSwesolows } cw_op_t;
33680ab886dSwesolows 
33780ab886dSwesolows struct aelist {
33880ab886dSwesolows 	struct ae {
33980ab886dSwesolows 		struct ae *ae_next;
34080ab886dSwesolows 		char *ae_arg;
34180ab886dSwesolows 	} *ael_head, *ael_tail;
34280ab886dSwesolows 	int ael_argc;
34380ab886dSwesolows };
34480ab886dSwesolows 
34580ab886dSwesolows typedef struct cw_ictx {
34680ab886dSwesolows 	cw_compiler_t	i_compiler;
34780ab886dSwesolows 	struct aelist	*i_ae;
34880ab886dSwesolows 	uint32_t	i_flags;
34980ab886dSwesolows 	int		i_oldargc;
35080ab886dSwesolows 	char		**i_oldargv;
35180ab886dSwesolows 	pid_t		i_pid;
35280ab886dSwesolows 	char		i_discard[MAXPATHLEN];
353*1912d2c4Swesolows 	char		*i_stderr;
35480ab886dSwesolows } cw_ictx_t;
35580ab886dSwesolows 
35680ab886dSwesolows static const char *progname;
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate static const char *xarch_tbl[] = {
3597c478bd9Sstevel@tonic-gate #if defined(__x86)
3607c478bd9Sstevel@tonic-gate 	"generic",	NULL,
3617c478bd9Sstevel@tonic-gate 	"generic64",	"-m64", "-mtune=opteron", NULL,
3627c478bd9Sstevel@tonic-gate 	"amd64",	"-m64", "-mtune=opteron", NULL,
3637c478bd9Sstevel@tonic-gate 	"386",		"-march=i386", NULL,
3647c478bd9Sstevel@tonic-gate 	"pentium_pro",	"-march=pentiumpro", NULL,
3657c478bd9Sstevel@tonic-gate #elif defined(__sparc)
3667c478bd9Sstevel@tonic-gate 	"generic",	"-m32", "-mcpu=v8", NULL,
3677c478bd9Sstevel@tonic-gate 	"generic64",	"-m64", "-mcpu=v9", NULL,
3687c478bd9Sstevel@tonic-gate 	"v8",		"-m32", "-mcpu=v8", "-mno-v8plus", NULL,
3697c478bd9Sstevel@tonic-gate 	"v8plus",	"-m32", "-mcpu=v9", "-mv8plus", NULL,
3707c478bd9Sstevel@tonic-gate 	"v8plusa",	"-m32", "-mcpu=ultrasparc", "-mv8plus", "-mvis", NULL,
3717c478bd9Sstevel@tonic-gate 	"v8plusb",	"-m32", "-mcpu=ultrasparc3", "-mv8plus", "-mvis", NULL,
3727c478bd9Sstevel@tonic-gate 	"v9",		"-m64", "-mcpu=v9", NULL,
3737c478bd9Sstevel@tonic-gate 	"v9a",		"-m64", "-mcpu=ultrasparc", "-mvis", NULL,
3747c478bd9Sstevel@tonic-gate 	"v9b",		"-m64", "-mcpu=ultrasparc3", "-mvis", NULL,
3757c478bd9Sstevel@tonic-gate #endif
3767c478bd9Sstevel@tonic-gate 	NULL,		NULL
3777c478bd9Sstevel@tonic-gate };
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate static const char *xchip_tbl[] = {
3807c478bd9Sstevel@tonic-gate #if defined(__x86)
3817c478bd9Sstevel@tonic-gate 	"386",		"-mtune=i386", NULL,
3827c478bd9Sstevel@tonic-gate 	"486",		"-mtune=i486", NULL,
3837c478bd9Sstevel@tonic-gate 	"pentium",	"-mtune=pentium", NULL,
3847c478bd9Sstevel@tonic-gate 	"pentium_pro",  "-mtune=pentiumpro", NULL,
3857c478bd9Sstevel@tonic-gate #elif defined(__sparc)
3867c478bd9Sstevel@tonic-gate 	"super",	"-mtune=supersparc", NULL,
3877c478bd9Sstevel@tonic-gate 	"ultra",	"-mtune=ultrasparc", NULL,
3887c478bd9Sstevel@tonic-gate 	"ultra3",	"-mtune=ultrasparc3", NULL,
3897c478bd9Sstevel@tonic-gate #endif
3907c478bd9Sstevel@tonic-gate 	NULL,		NULL
3917c478bd9Sstevel@tonic-gate };
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate static const char *xcode_tbl[] = {
3947c478bd9Sstevel@tonic-gate #if defined(__sparc)
3957c478bd9Sstevel@tonic-gate 	"abs32",	"-fno-pic", "-mcmodel=medlow", NULL,
3967c478bd9Sstevel@tonic-gate 	"abs44",	"-fno-pic", "-mcmodel=medmid", NULL,
3977c478bd9Sstevel@tonic-gate 	"abs64",	"-fno-pic", "-mcmodel=medany", NULL,
3987c478bd9Sstevel@tonic-gate 	"pic13",	"-fpic", NULL,
3997c478bd9Sstevel@tonic-gate 	"pic32",	"-fPIC", NULL,
4007c478bd9Sstevel@tonic-gate #endif
4017c478bd9Sstevel@tonic-gate 	NULL,		NULL
4027c478bd9Sstevel@tonic-gate };
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate static const char *xtarget_tbl[] = {
4057c478bd9Sstevel@tonic-gate #if defined(__x86)
4067c478bd9Sstevel@tonic-gate 	"pentium_pro",	"-march=pentiumpro", NULL,
4077c478bd9Sstevel@tonic-gate #endif	/* __x86 */
4087c478bd9Sstevel@tonic-gate 	NULL,		NULL
4097c478bd9Sstevel@tonic-gate };
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate static const char *xregs_tbl[] = {
4127c478bd9Sstevel@tonic-gate #if defined(__sparc)
4137c478bd9Sstevel@tonic-gate 	"appl",		"-mapp-regs", NULL,
4147c478bd9Sstevel@tonic-gate 	"no%appl",	"-mno-app-regs", NULL,
4157c478bd9Sstevel@tonic-gate 	"float",	"-mfpu", NULL,
4167c478bd9Sstevel@tonic-gate 	"no%float",	"-mno-fpu", NULL,
4177c478bd9Sstevel@tonic-gate #endif	/* __sparc */
4187c478bd9Sstevel@tonic-gate 	NULL,		NULL
4197c478bd9Sstevel@tonic-gate };
4207c478bd9Sstevel@tonic-gate 
42180ab886dSwesolows static void
42280ab886dSwesolows nomem(void)
42380ab886dSwesolows {
42480ab886dSwesolows 	(void) fprintf(stderr, "%s: error: out of memory\n", progname);
42580ab886dSwesolows 	exit(1);
42680ab886dSwesolows }
4277c478bd9Sstevel@tonic-gate 
42880ab886dSwesolows static void
42980ab886dSwesolows cw_perror(const char *fmt, ...)
4307c478bd9Sstevel@tonic-gate {
43180ab886dSwesolows 	va_list ap;
43280ab886dSwesolows 	int saved_errno = errno;
43380ab886dSwesolows 
43480ab886dSwesolows 	(void) fprintf(stderr, "%s: error: ", progname);
43580ab886dSwesolows 
43680ab886dSwesolows 	va_start(ap, fmt);
43780ab886dSwesolows 	(void) vfprintf(stderr, fmt, ap);
43880ab886dSwesolows 	va_end(ap);
43980ab886dSwesolows 
44080ab886dSwesolows 	(void) fprintf(stderr, " (%s)\n", strerror(saved_errno));
4417c478bd9Sstevel@tonic-gate }
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate static void
4447c478bd9Sstevel@tonic-gate newae(struct aelist *ael, const char *arg)
4457c478bd9Sstevel@tonic-gate {
4467c478bd9Sstevel@tonic-gate 	struct ae *ae;
4477c478bd9Sstevel@tonic-gate 
44880ab886dSwesolows 	if ((ae = calloc(sizeof (*ae), 1)) == NULL)
44980ab886dSwesolows 		nomem();
4507c478bd9Sstevel@tonic-gate 	ae->ae_arg = strdup(arg);
4517c478bd9Sstevel@tonic-gate 	if (ael->ael_tail == NULL)
4527c478bd9Sstevel@tonic-gate 		ael->ael_head = ae;
4537c478bd9Sstevel@tonic-gate 	else
4547c478bd9Sstevel@tonic-gate 		ael->ael_tail->ae_next = ae;
4557c478bd9Sstevel@tonic-gate 	ael->ael_tail = ae;
45680ab886dSwesolows 	ael->ael_argc++;
45780ab886dSwesolows }
45880ab886dSwesolows 
45980ab886dSwesolows static cw_ictx_t *
46080ab886dSwesolows newictx(void)
46180ab886dSwesolows {
46280ab886dSwesolows 	cw_ictx_t *ctx = calloc(sizeof (cw_ictx_t), 1);
46380ab886dSwesolows 	if (ctx)
46480ab886dSwesolows 		if ((ctx->i_ae = calloc(sizeof (struct aelist), 1)) == NULL) {
46580ab886dSwesolows 			free(ctx);
46680ab886dSwesolows 			return (NULL);
46780ab886dSwesolows 		}
46880ab886dSwesolows 
46980ab886dSwesolows 	return (ctx);
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate static void
4737c478bd9Sstevel@tonic-gate error(const char *arg)
4747c478bd9Sstevel@tonic-gate {
4757c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
47680ab886dSwesolows 	    "%s: error: mapping failed at or near arg '%s'\n", progname, arg);
4777c478bd9Sstevel@tonic-gate 	exit(2);
4787c478bd9Sstevel@tonic-gate }
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate /*
4817c478bd9Sstevel@tonic-gate  * Add the current favourite set of warnings to the gcc invocation.
4827c478bd9Sstevel@tonic-gate  */
4837c478bd9Sstevel@tonic-gate static void
4847c478bd9Sstevel@tonic-gate warnings(struct aelist *h)
4857c478bd9Sstevel@tonic-gate {
4867c478bd9Sstevel@tonic-gate 	static int warningsonce;
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 	if (warningsonce++)
4897c478bd9Sstevel@tonic-gate 		return;
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 	newae(h, "-Wall");
4927c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-unknown-pragmas");
4937c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-missing-braces");
4947c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-sign-compare");
4957c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-parentheses");
4967c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-uninitialized");
4977c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-implicit-function-declaration");
4987c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-unused");
4997c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-trigraphs");
5007c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-char-subscripts");
5017c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-switch");
5027c478bd9Sstevel@tonic-gate }
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate static void
5057c478bd9Sstevel@tonic-gate optim_disable(struct aelist *h, int level)
5067c478bd9Sstevel@tonic-gate {
5077c478bd9Sstevel@tonic-gate 	if (level >= 2) {
5087c478bd9Sstevel@tonic-gate 		newae(h, "-fno-strict-aliasing");
5097c478bd9Sstevel@tonic-gate 		newae(h, "-fno-unit-at-a-time");
5107c478bd9Sstevel@tonic-gate 		newae(h, "-fno-optimize-sibling-calls");
5117c478bd9Sstevel@tonic-gate 	}
5127c478bd9Sstevel@tonic-gate }
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate /* ARGSUSED */
5157c478bd9Sstevel@tonic-gate static void
5167c478bd9Sstevel@tonic-gate Xamode(struct aelist *h)
5177c478bd9Sstevel@tonic-gate {
5187c478bd9Sstevel@tonic-gate }
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate static void
5217c478bd9Sstevel@tonic-gate Xcmode(struct aelist *h)
5227c478bd9Sstevel@tonic-gate {
5237c478bd9Sstevel@tonic-gate 	static int xconce;
5247c478bd9Sstevel@tonic-gate 
5257c478bd9Sstevel@tonic-gate 	if (xconce++)
5267c478bd9Sstevel@tonic-gate 		return;
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate 	newae(h, "-ansi");
5297c478bd9Sstevel@tonic-gate 	newae(h, "-pedantic-errors");
5307c478bd9Sstevel@tonic-gate }
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate static void
5337c478bd9Sstevel@tonic-gate Xsmode(struct aelist *h)
5347c478bd9Sstevel@tonic-gate {
5357c478bd9Sstevel@tonic-gate 	static int xsonce;
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 	if (xsonce++)
5387c478bd9Sstevel@tonic-gate 		return;
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 	newae(h, "-traditional");
5417c478bd9Sstevel@tonic-gate 	newae(h, "-traditional-cpp");
5427c478bd9Sstevel@tonic-gate }
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate static void
5457c478bd9Sstevel@tonic-gate usage()
5467c478bd9Sstevel@tonic-gate {
5477c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
5487c478bd9Sstevel@tonic-gate 	    "usage: %s { -_cc | -_gcc | -_CC | -_g++ } [ -_compiler | ... ]\n",
5497c478bd9Sstevel@tonic-gate 	    progname);
5507c478bd9Sstevel@tonic-gate 	exit(2);
5517c478bd9Sstevel@tonic-gate }
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate static void
5547c478bd9Sstevel@tonic-gate xlate(struct aelist *h, const char *xarg, const char **table)
5557c478bd9Sstevel@tonic-gate {
5567c478bd9Sstevel@tonic-gate 	while (*table != NULL && strcmp(xarg, *table) != 0) {
5577c478bd9Sstevel@tonic-gate 		while (*table != NULL)
5587c478bd9Sstevel@tonic-gate 			table++;
5597c478bd9Sstevel@tonic-gate 		table++;
5607c478bd9Sstevel@tonic-gate 	}
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 	if (*table == NULL)
5637c478bd9Sstevel@tonic-gate 		error(xarg);
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 	table++;
5667c478bd9Sstevel@tonic-gate 
5677c478bd9Sstevel@tonic-gate 	while (*table != NULL) {
5687c478bd9Sstevel@tonic-gate 		newae(h, *table);
5697c478bd9Sstevel@tonic-gate 		table++;
5707c478bd9Sstevel@tonic-gate 	}
5717c478bd9Sstevel@tonic-gate }
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate static void
57480ab886dSwesolows do_gcc(cw_ictx_t *ctx)
5757c478bd9Sstevel@tonic-gate {
5767c478bd9Sstevel@tonic-gate 	int c;
57780ab886dSwesolows 	int pic = 0, nolibc = 0;
57880ab886dSwesolows 	int in_output = 0, seen_o = 0, c_files = 0;
57980ab886dSwesolows 	cw_op_t op = CW_O_LINK;
5807c478bd9Sstevel@tonic-gate 	char *model = NULL;
5817c478bd9Sstevel@tonic-gate 
582*1912d2c4Swesolows 	if (ctx->i_flags & CW_F_PROG) {
583*1912d2c4Swesolows 		newae(ctx->i_ae, "--version");
584*1912d2c4Swesolows 		return;
585*1912d2c4Swesolows 	}
586*1912d2c4Swesolows 
58780ab886dSwesolows 	newae(ctx->i_ae, "-fident");
58880ab886dSwesolows 	newae(ctx->i_ae, "-finline");
58980ab886dSwesolows 	newae(ctx->i_ae, "-fno-inline-functions");
59080ab886dSwesolows 	newae(ctx->i_ae, "-fno-builtin");
59180ab886dSwesolows 	newae(ctx->i_ae, "-fno-asm");
59280ab886dSwesolows 	newae(ctx->i_ae, "-nodefaultlibs");
5937c478bd9Sstevel@tonic-gate 
59402e56f3fSwesolows #if defined(__sparc)
59502e56f3fSwesolows 	/*
59602e56f3fSwesolows 	 * The SPARC ldd and std instructions require 8-byte alignment of
59702e56f3fSwesolows 	 * their address operand.  gcc correctly uses them only when the
59802e56f3fSwesolows 	 * ABI requires 8-byte alignment; unfortunately we have a number of
59902e56f3fSwesolows 	 * pieces of buggy code that doesn't conform to the ABI.  This
60002e56f3fSwesolows 	 * flag makes gcc work more like Studio with -xmemalign=4.
60102e56f3fSwesolows 	 */
60280ab886dSwesolows 	newae(ctx->i_ae, "-mno-integer-ldd-std");
60302e56f3fSwesolows #endif
60402e56f3fSwesolows 
6057c478bd9Sstevel@tonic-gate 	/*
6067c478bd9Sstevel@tonic-gate 	 * This is needed because 'u' is defined
6077c478bd9Sstevel@tonic-gate 	 * under a conditional on 'sun'.  Should
6087c478bd9Sstevel@tonic-gate 	 * probably just remove the conditional,
6097c478bd9Sstevel@tonic-gate 	 * or make it be dependent on '__sun'.
6107c478bd9Sstevel@tonic-gate 	 *
6117c478bd9Sstevel@tonic-gate 	 * -Dunix is also missing in enhanced ANSI mode
6127c478bd9Sstevel@tonic-gate 	 */
61380ab886dSwesolows 	newae(ctx->i_ae, "-D__sun");
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate 	/*
6167c478bd9Sstevel@tonic-gate 	 * Walk the argument list, translating as we go ..
6177c478bd9Sstevel@tonic-gate 	 */
6187c478bd9Sstevel@tonic-gate 
61980ab886dSwesolows 	while (--ctx->i_oldargc > 0) {
62080ab886dSwesolows 		char *arg = *++ctx->i_oldargv;
6217c478bd9Sstevel@tonic-gate 		size_t arglen = strlen(arg);
6227c478bd9Sstevel@tonic-gate 
62380ab886dSwesolows 		if (*arg == '-') {
6247c478bd9Sstevel@tonic-gate 			arglen--;
62580ab886dSwesolows 		} else {
6267c478bd9Sstevel@tonic-gate 			/*
6277c478bd9Sstevel@tonic-gate 			 * Discard inline files that gcc doesn't grok
6287c478bd9Sstevel@tonic-gate 			 */
62980ab886dSwesolows 			if (!in_output && arglen > 3 &&
6307c478bd9Sstevel@tonic-gate 			    strcmp(arg + arglen - 3, ".il") == 0)
6317c478bd9Sstevel@tonic-gate 				continue;
6327c478bd9Sstevel@tonic-gate 
63380ab886dSwesolows 			if (!in_output && arglen > 2 &&
63480ab886dSwesolows 			    arg[arglen - 2] == '.' &&
63580ab886dSwesolows 			    (arg[arglen - 1] == 'S' || arg[arglen - 1] == 's' ||
63680ab886dSwesolows 			    arg[arglen - 1] == 'c' || arg[arglen - 1] == 'i'))
63780ab886dSwesolows 				c_files++;
63880ab886dSwesolows 
6397c478bd9Sstevel@tonic-gate 			/*
64080ab886dSwesolows 			 * Otherwise, filenames and partial arguments
64180ab886dSwesolows 			 * are passed through for gcc to chew on.  However,
64280ab886dSwesolows 			 * output is always discarded for the secondary
64380ab886dSwesolows 			 * compiler.
6447c478bd9Sstevel@tonic-gate 			 */
64580ab886dSwesolows 			if ((ctx->i_flags & CW_F_SHADOW) && in_output)
64680ab886dSwesolows 				newae(ctx->i_ae, ctx->i_discard);
64780ab886dSwesolows 			else
64880ab886dSwesolows 				newae(ctx->i_ae, arg);
64980ab886dSwesolows 			in_output = 0;
6507c478bd9Sstevel@tonic-gate 			continue;
6517c478bd9Sstevel@tonic-gate 		}
6527c478bd9Sstevel@tonic-gate 
65380ab886dSwesolows 		if (ctx->i_flags & CW_F_CXX) {
6547c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-compat=", 8) == 0) {
6557c478bd9Sstevel@tonic-gate 				/* discard -compat=4 and -compat=5 */
6567c478bd9Sstevel@tonic-gate 				continue;
6577c478bd9Sstevel@tonic-gate 			}
6587c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Qoption") == 0) {
6597c478bd9Sstevel@tonic-gate 				/* discard -Qoption and its two arguments */
66080ab886dSwesolows 				if (ctx->i_oldargc < 3)
6617c478bd9Sstevel@tonic-gate 					error(arg);
66280ab886dSwesolows 				ctx->i_oldargc -= 2;
66380ab886dSwesolows 				ctx->i_oldargv += 2;
6647c478bd9Sstevel@tonic-gate 				continue;
6657c478bd9Sstevel@tonic-gate 			}
6667c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-xwe") == 0) {
6677c478bd9Sstevel@tonic-gate 				/* turn warnings into errors */
66880ab886dSwesolows 				newae(ctx->i_ae, "-Werror");
6697c478bd9Sstevel@tonic-gate 				continue;
6707c478bd9Sstevel@tonic-gate 			}
6717c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-noex") == 0) {
6727c478bd9Sstevel@tonic-gate 				/* no exceptions */
67380ab886dSwesolows 				newae(ctx->i_ae, "-fno-exceptions");
6747c478bd9Sstevel@tonic-gate 				/* no run time type descriptor information */
67580ab886dSwesolows 				newae(ctx->i_ae, "-fno-rtti");
6767c478bd9Sstevel@tonic-gate 				continue;
6777c478bd9Sstevel@tonic-gate 			}
6787c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-pic") == 0) {
67980ab886dSwesolows 				newae(ctx->i_ae, "-fpic");
6807c478bd9Sstevel@tonic-gate 				pic = 1;
6817c478bd9Sstevel@tonic-gate 				continue;
6827c478bd9Sstevel@tonic-gate 			}
6837c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-PIC") == 0) {
68480ab886dSwesolows 				newae(ctx->i_ae, "-fPIC");
6857c478bd9Sstevel@tonic-gate 				pic = 1;
6867c478bd9Sstevel@tonic-gate 				continue;
6877c478bd9Sstevel@tonic-gate 			}
6887c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-norunpath") == 0) {
6897c478bd9Sstevel@tonic-gate 				/* gcc has no corresponding option */
6907c478bd9Sstevel@tonic-gate 				continue;
6917c478bd9Sstevel@tonic-gate 			}
6927c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-nolib") == 0) {
6937c478bd9Sstevel@tonic-gate 				/* -nodefaultlibs is on by default */
6947c478bd9Sstevel@tonic-gate 				nolibc = 1;
6957c478bd9Sstevel@tonic-gate 				continue;
6967c478bd9Sstevel@tonic-gate 			}
6977c478bd9Sstevel@tonic-gate #if defined(__sparc)
6987c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-cg92") == 0) {
69980ab886dSwesolows 				xlate(ctx->i_ae, "v8", xarch_tbl);
70080ab886dSwesolows 				xlate(ctx->i_ae, "super", xchip_tbl);
7017c478bd9Sstevel@tonic-gate 				continue;
7027c478bd9Sstevel@tonic-gate 			}
7037c478bd9Sstevel@tonic-gate #endif	/* __sparc */
7047c478bd9Sstevel@tonic-gate 		}
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate 		switch ((c = arg[1])) {
7077c478bd9Sstevel@tonic-gate 		case '_':
7087c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-_noecho") == 0)
70980ab886dSwesolows 				ctx->i_flags &= ~CW_F_ECHO;
7107c478bd9Sstevel@tonic-gate 			else if (strncmp(arg, "-_cc=", 5) == 0 ||
7117c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-_CC=", 5) == 0)
7127c478bd9Sstevel@tonic-gate 				/* EMPTY */;
7137c478bd9Sstevel@tonic-gate 			else if (strncmp(arg, "-_gcc=", 6) == 0 ||
7147c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-_g++=", 6) == 0)
71580ab886dSwesolows 				newae(ctx->i_ae, arg + 6);
71680ab886dSwesolows 			else
7177c478bd9Sstevel@tonic-gate 				error(arg);
7187c478bd9Sstevel@tonic-gate 			break;
7197c478bd9Sstevel@tonic-gate 		case '#':
7207c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
72180ab886dSwesolows 				newae(ctx->i_ae, "-v");
7227c478bd9Sstevel@tonic-gate 				break;
7237c478bd9Sstevel@tonic-gate 			}
7247c478bd9Sstevel@tonic-gate 			error(arg);
7257c478bd9Sstevel@tonic-gate 			break;
7267c478bd9Sstevel@tonic-gate 		case 'g':
72780ab886dSwesolows 			newae(ctx->i_ae, "-gdwarf-2");
7287c478bd9Sstevel@tonic-gate 			break;
7297c478bd9Sstevel@tonic-gate 		case 'E':
7307c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
73180ab886dSwesolows 				newae(ctx->i_ae, "-xc");
73280ab886dSwesolows 				newae(ctx->i_ae, arg);
73380ab886dSwesolows 				op = CW_O_PREPROCESS;
7347c478bd9Sstevel@tonic-gate 				nolibc = 1;
7357c478bd9Sstevel@tonic-gate 				break;
7367c478bd9Sstevel@tonic-gate 			}
7377c478bd9Sstevel@tonic-gate 			error(arg);
7387c478bd9Sstevel@tonic-gate 			break;
7397c478bd9Sstevel@tonic-gate 		case 'c':
7407c478bd9Sstevel@tonic-gate 		case 'S':
74180ab886dSwesolows 			if (arglen == 1) {
74280ab886dSwesolows 				op = CW_O_COMPILE;
7437c478bd9Sstevel@tonic-gate 				nolibc = 1;
74480ab886dSwesolows 			}
7457c478bd9Sstevel@tonic-gate 			/* FALLTHROUGH */
7467c478bd9Sstevel@tonic-gate 		case 'C':
7477c478bd9Sstevel@tonic-gate 		case 'H':
7487c478bd9Sstevel@tonic-gate 		case 'p':
7497c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
75080ab886dSwesolows 				newae(ctx->i_ae, arg);
7517c478bd9Sstevel@tonic-gate 				break;
7527c478bd9Sstevel@tonic-gate 			}
7537c478bd9Sstevel@tonic-gate 			error(arg);
7547c478bd9Sstevel@tonic-gate 			break;
7557c478bd9Sstevel@tonic-gate 		case 'A':
7567c478bd9Sstevel@tonic-gate 		case 'h':
7577c478bd9Sstevel@tonic-gate 		case 'I':
7587c478bd9Sstevel@tonic-gate 		case 'i':
7597c478bd9Sstevel@tonic-gate 		case 'L':
7607c478bd9Sstevel@tonic-gate 		case 'l':
7617c478bd9Sstevel@tonic-gate 		case 'R':
7627c478bd9Sstevel@tonic-gate 		case 'U':
7637c478bd9Sstevel@tonic-gate 		case 'u':
7647c478bd9Sstevel@tonic-gate 		case 'w':
76580ab886dSwesolows 			newae(ctx->i_ae, arg);
76680ab886dSwesolows 			break;
76780ab886dSwesolows 		case 'o':
76880ab886dSwesolows 			seen_o = 1;
76980ab886dSwesolows 			if (arglen == 1) {
77080ab886dSwesolows 				in_output = 1;
77180ab886dSwesolows 				newae(ctx->i_ae, arg);
77280ab886dSwesolows 			} else if (ctx->i_flags & CW_F_SHADOW) {
77380ab886dSwesolows 				newae(ctx->i_ae, "-o");
77480ab886dSwesolows 				newae(ctx->i_ae, ctx->i_discard);
77580ab886dSwesolows 			} else {
77680ab886dSwesolows 				newae(ctx->i_ae, arg);
77780ab886dSwesolows 			}
7787c478bd9Sstevel@tonic-gate 			break;
7797c478bd9Sstevel@tonic-gate 		case 'D':
78080ab886dSwesolows 			newae(ctx->i_ae, arg);
7817c478bd9Sstevel@tonic-gate 			/*
7827c478bd9Sstevel@tonic-gate 			 * XXX	Clearly a hack ... do we need _KADB too?
7837c478bd9Sstevel@tonic-gate 			 */
7847c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-D_KERNEL") == 0 ||
7857c478bd9Sstevel@tonic-gate 			    strcmp(arg, "-D_BOOT") == 0)
78680ab886dSwesolows 				newae(ctx->i_ae, "-ffreestanding");
7877c478bd9Sstevel@tonic-gate 			break;
7887c478bd9Sstevel@tonic-gate 		case 'd':
7897c478bd9Sstevel@tonic-gate 			if (arglen == 2) {
7907c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-dy") == 0) {
79180ab886dSwesolows 					newae(ctx->i_ae, "-Wl,-dy");
7927c478bd9Sstevel@tonic-gate 					break;
7937c478bd9Sstevel@tonic-gate 				}
7947c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-dn") == 0) {
79580ab886dSwesolows 					newae(ctx->i_ae, "-Wl,-dn");
7967c478bd9Sstevel@tonic-gate 					break;
7977c478bd9Sstevel@tonic-gate 				}
7987c478bd9Sstevel@tonic-gate 			}
7997c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-dalign") == 0) {
8007c478bd9Sstevel@tonic-gate 				/*
8017c478bd9Sstevel@tonic-gate 				 * -dalign forces alignment in some cases;
8027c478bd9Sstevel@tonic-gate 				 * gcc does not need any flag to do this.
8037c478bd9Sstevel@tonic-gate 				 */
8047c478bd9Sstevel@tonic-gate 				break;
8057c478bd9Sstevel@tonic-gate 			}
8067c478bd9Sstevel@tonic-gate 			error(arg);
8077c478bd9Sstevel@tonic-gate 			break;
8087c478bd9Sstevel@tonic-gate 		case 'e':
8097c478bd9Sstevel@tonic-gate 			if (strcmp(arg,
8107c478bd9Sstevel@tonic-gate 			    "-erroff=E_EMPTY_TRANSLATION_UNIT") == 0) {
8117c478bd9Sstevel@tonic-gate 				/*
8127c478bd9Sstevel@tonic-gate 				 * Accept but ignore this -- gcc doesn't
8137c478bd9Sstevel@tonic-gate 				 * seem to complain about empty translation
8147c478bd9Sstevel@tonic-gate 				 * units
8157c478bd9Sstevel@tonic-gate 				 */
8167c478bd9Sstevel@tonic-gate 				break;
8177c478bd9Sstevel@tonic-gate 			}
8187c478bd9Sstevel@tonic-gate 			/* XX64 -- ignore all -erroff= options, for now */
8197c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-erroff=", 8) == 0)
8207c478bd9Sstevel@tonic-gate 				break;
8217c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-errtags=yes") == 0) {
82280ab886dSwesolows 				warnings(ctx->i_ae);
8237c478bd9Sstevel@tonic-gate 				break;
8247c478bd9Sstevel@tonic-gate 			}
8257c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-errwarn=%all") == 0) {
82680ab886dSwesolows 				newae(ctx->i_ae, "-Werror");
8277c478bd9Sstevel@tonic-gate 				break;
8287c478bd9Sstevel@tonic-gate 			}
8297c478bd9Sstevel@tonic-gate 			error(arg);
8307c478bd9Sstevel@tonic-gate 			break;
8317c478bd9Sstevel@tonic-gate 		case 'f':
8327c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-flags") == 0) {
83380ab886dSwesolows 				newae(ctx->i_ae, "--help");
8347c478bd9Sstevel@tonic-gate 				break;
8357c478bd9Sstevel@tonic-gate 			}
8367c478bd9Sstevel@tonic-gate 			error(arg);
8377c478bd9Sstevel@tonic-gate 			break;
8387c478bd9Sstevel@tonic-gate 		case 'G':
83980ab886dSwesolows 			newae(ctx->i_ae, "-shared");
8407c478bd9Sstevel@tonic-gate 			nolibc = 1;
8417c478bd9Sstevel@tonic-gate 			break;
8427c478bd9Sstevel@tonic-gate 		case 'k':
8437c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-keeptmp") == 0) {
84480ab886dSwesolows 				newae(ctx->i_ae, "-save-temps");
8457c478bd9Sstevel@tonic-gate 				break;
8467c478bd9Sstevel@tonic-gate 			}
8477c478bd9Sstevel@tonic-gate 			error(arg);
8487c478bd9Sstevel@tonic-gate 			break;
8497c478bd9Sstevel@tonic-gate 		case 'K':
8507c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
85180ab886dSwesolows 				if ((arg = *++ctx->i_oldargv) == NULL ||
85280ab886dSwesolows 				    *arg == '\0')
8537c478bd9Sstevel@tonic-gate 					error("-K");
85480ab886dSwesolows 				ctx->i_oldargc--;
8557c478bd9Sstevel@tonic-gate 			} else {
8567c478bd9Sstevel@tonic-gate 				arg += 2;
8577c478bd9Sstevel@tonic-gate 			}
8587c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "pic") == 0) {
85980ab886dSwesolows 				newae(ctx->i_ae, "-fpic");
8607c478bd9Sstevel@tonic-gate 				pic = 1;
8617c478bd9Sstevel@tonic-gate 				break;
8627c478bd9Sstevel@tonic-gate 			}
8637c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "PIC") == 0) {
86480ab886dSwesolows 				newae(ctx->i_ae, "-fPIC");
8657c478bd9Sstevel@tonic-gate 				pic = 1;
8667c478bd9Sstevel@tonic-gate 				break;
8677c478bd9Sstevel@tonic-gate 			}
8687c478bd9Sstevel@tonic-gate 			error("-K");
8697c478bd9Sstevel@tonic-gate 			break;
8707c478bd9Sstevel@tonic-gate 		case 'm':
8717c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-mt") == 0) {
87280ab886dSwesolows 				newae(ctx->i_ae, "-D_REENTRANT");
8737c478bd9Sstevel@tonic-gate 				break;
8747c478bd9Sstevel@tonic-gate 			}
8757c478bd9Sstevel@tonic-gate 			error(arg);
8767c478bd9Sstevel@tonic-gate 			break;
8777c478bd9Sstevel@tonic-gate 		case 'B':	/* linker options */
8787c478bd9Sstevel@tonic-gate 		case 'M':
8797c478bd9Sstevel@tonic-gate 		case 'z':
8807c478bd9Sstevel@tonic-gate 			{
8817c478bd9Sstevel@tonic-gate 				char *opt;
8827c478bd9Sstevel@tonic-gate 				size_t len;
8837c478bd9Sstevel@tonic-gate 				char *s;
8847c478bd9Sstevel@tonic-gate 
8857c478bd9Sstevel@tonic-gate 				if (arglen == 1) {
88680ab886dSwesolows 					opt = *++ctx->i_oldargv;
8877c478bd9Sstevel@tonic-gate 					if (opt == NULL || *opt == '\0')
8887c478bd9Sstevel@tonic-gate 						error(arg);
88980ab886dSwesolows 					ctx->i_oldargc--;
8907c478bd9Sstevel@tonic-gate 				} else {
8917c478bd9Sstevel@tonic-gate 					opt = arg + 2;
8927c478bd9Sstevel@tonic-gate 				}
8937c478bd9Sstevel@tonic-gate 				len = strlen(opt) + 7;
89480ab886dSwesolows 				if ((s = malloc(len)) == NULL)
89580ab886dSwesolows 					nomem();
8967c478bd9Sstevel@tonic-gate 				(void) snprintf(s, len, "-Wl,-%c%s", c, opt);
89780ab886dSwesolows 				newae(ctx->i_ae, s);
8987c478bd9Sstevel@tonic-gate 				free(s);
8997c478bd9Sstevel@tonic-gate 			}
9007c478bd9Sstevel@tonic-gate 			break;
9017c478bd9Sstevel@tonic-gate 		case 'n':
9027c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-noqueue") == 0) {
9037c478bd9Sstevel@tonic-gate 				/*
9047c478bd9Sstevel@tonic-gate 				 * Horrid license server stuff - n/a
9057c478bd9Sstevel@tonic-gate 				 */
9067c478bd9Sstevel@tonic-gate 				break;
9077c478bd9Sstevel@tonic-gate 			}
9087c478bd9Sstevel@tonic-gate 			error(arg);
9097c478bd9Sstevel@tonic-gate 			break;
9107c478bd9Sstevel@tonic-gate 		case 'O':
9117c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
91280ab886dSwesolows 				newae(ctx->i_ae, "-O");
9137c478bd9Sstevel@tonic-gate 				break;
9147c478bd9Sstevel@tonic-gate 			}
9157c478bd9Sstevel@tonic-gate 			error(arg);
9167c478bd9Sstevel@tonic-gate 			break;
9177c478bd9Sstevel@tonic-gate 		case 'P':
9187c478bd9Sstevel@tonic-gate 			/*
9197c478bd9Sstevel@tonic-gate 			 * We could do '-E -o filename.i', but that's hard,
9207c478bd9Sstevel@tonic-gate 			 * and we don't need it for the case that's triggering
9217c478bd9Sstevel@tonic-gate 			 * this addition.  We'll require the user to specify
9227c478bd9Sstevel@tonic-gate 			 * -o in the Makefile.  If they don't they'll find out
9237c478bd9Sstevel@tonic-gate 			 * in a hurry.
9247c478bd9Sstevel@tonic-gate 			 */
92580ab886dSwesolows 			newae(ctx->i_ae, "-E");
92680ab886dSwesolows 			op = CW_O_PREPROCESS;
9277c478bd9Sstevel@tonic-gate 			nolibc = 1;
9287c478bd9Sstevel@tonic-gate 			break;
9297c478bd9Sstevel@tonic-gate 		case 'q':
9307c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-qp") == 0) {
93180ab886dSwesolows 				newae(ctx->i_ae, "-p");
9327c478bd9Sstevel@tonic-gate 				break;
9337c478bd9Sstevel@tonic-gate 			}
9347c478bd9Sstevel@tonic-gate 			error(arg);
9357c478bd9Sstevel@tonic-gate 			break;
9367c478bd9Sstevel@tonic-gate 		case 's':
9377c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
93880ab886dSwesolows 				newae(ctx->i_ae, "-Wl,-s");
9397c478bd9Sstevel@tonic-gate 				break;
9407c478bd9Sstevel@tonic-gate 			}
9417c478bd9Sstevel@tonic-gate 			error(arg);
9427c478bd9Sstevel@tonic-gate 			break;
943159cf8a6Swesolows 		case 't':
944159cf8a6Swesolows 			if (arglen == 1) {
94580ab886dSwesolows 				newae(ctx->i_ae, "-Wl,-t");
946159cf8a6Swesolows 				break;
947159cf8a6Swesolows 			}
948159cf8a6Swesolows 			error(arg);
949159cf8a6Swesolows 			break;
9507c478bd9Sstevel@tonic-gate 		case 'V':
9517c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
95280ab886dSwesolows 				ctx->i_flags &= ~CW_F_ECHO;
95380ab886dSwesolows 				newae(ctx->i_ae, "--version");
9547c478bd9Sstevel@tonic-gate 				break;
9557c478bd9Sstevel@tonic-gate 			}
9567c478bd9Sstevel@tonic-gate 			error(arg);
9577c478bd9Sstevel@tonic-gate 			break;
9587c478bd9Sstevel@tonic-gate 		case 'v':
9597c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
96080ab886dSwesolows 				warnings(ctx->i_ae);
9617c478bd9Sstevel@tonic-gate 				break;
9627c478bd9Sstevel@tonic-gate 			}
9637c478bd9Sstevel@tonic-gate 			error(arg);
9647c478bd9Sstevel@tonic-gate 			break;
9657c478bd9Sstevel@tonic-gate 		case 'W':
9667c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wp,-xc99", 9) == 0) {
9677c478bd9Sstevel@tonic-gate 				/*
9687c478bd9Sstevel@tonic-gate 				 * gcc's preprocessor will accept c99
9697c478bd9Sstevel@tonic-gate 				 * regardless, so accept and ignore.
9707c478bd9Sstevel@tonic-gate 				 */
9717c478bd9Sstevel@tonic-gate 				break;
9727c478bd9Sstevel@tonic-gate 			}
9737c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wa,", 4) == 0 ||
9747c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-Wp,", 4) == 0 ||
9757c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-Wl,", 4) == 0) {
97680ab886dSwesolows 				newae(ctx->i_ae, arg);
9777c478bd9Sstevel@tonic-gate 				break;
9787c478bd9Sstevel@tonic-gate 			}
9797c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-xc99=pragma") == 0) {
9807c478bd9Sstevel@tonic-gate 				/* (undocumented) enables _Pragma */
9817c478bd9Sstevel@tonic-gate 				break;
9827c478bd9Sstevel@tonic-gate 			}
9837c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-xc99=%none") == 0) {
9847c478bd9Sstevel@tonic-gate 				/*
9857c478bd9Sstevel@tonic-gate 				 * This is a polite way of saying
9867c478bd9Sstevel@tonic-gate 				 * "no c99 constructs allowed!"
9877c478bd9Sstevel@tonic-gate 				 * For now, just accept and ignore this.
9887c478bd9Sstevel@tonic-gate 				 */
9897c478bd9Sstevel@tonic-gate 				break;
9907c478bd9Sstevel@tonic-gate 			}
9917c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-noglobal") == 0) {
9927c478bd9Sstevel@tonic-gate 				/*
9937c478bd9Sstevel@tonic-gate 				 * gcc doesn't prefix local symbols
9947c478bd9Sstevel@tonic-gate 				 * in debug mode, so this is not needed.
9957c478bd9Sstevel@tonic-gate 				 */
9967c478bd9Sstevel@tonic-gate 				break;
9977c478bd9Sstevel@tonic-gate 			}
9987c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-Lt") == 0) {
9997c478bd9Sstevel@tonic-gate 				/*
10007c478bd9Sstevel@tonic-gate 				 * Generate tests at the top of loops.
10017c478bd9Sstevel@tonic-gate 				 * There is no direct gcc equivalent, ignore.
10027c478bd9Sstevel@tonic-gate 				 */
10037c478bd9Sstevel@tonic-gate 				break;
10047c478bd9Sstevel@tonic-gate 			}
10058c1a3716Ssherrym 			if (strcmp(arg, "-W0,-xdbggen=no%usedonly") == 0) {
100680ab886dSwesolows 				newae(ctx->i_ae,
100780ab886dSwesolows 				    "-fno-eliminate-unused-debug-symbols");
100880ab886dSwesolows 				newae(ctx->i_ae,
100980ab886dSwesolows 				    "-fno-eliminate-unused-debug-types");
10108c1a3716Ssherrym 				break;
10118c1a3716Ssherrym 			}
10127c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W2,-Rcond_elim") == 0) {
10137c478bd9Sstevel@tonic-gate 				/*
10147c478bd9Sstevel@tonic-gate 				 * Elimination and expansion of conditionals;
10157c478bd9Sstevel@tonic-gate 				 * gcc has no direct equivalent.
10167c478bd9Sstevel@tonic-gate 				 */
10177c478bd9Sstevel@tonic-gate 				break;
10187c478bd9Sstevel@tonic-gate 			}
10197c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Wd,-xsafe=unboundsym") == 0) {
10207c478bd9Sstevel@tonic-gate 				/*
10217c478bd9Sstevel@tonic-gate 				 * Prevents optimizing away checks for
10227c478bd9Sstevel@tonic-gate 				 * unbound weak symbol addresses.  gcc does
10237c478bd9Sstevel@tonic-gate 				 * not do this, so it's not needed.
10247c478bd9Sstevel@tonic-gate 				 */
10257c478bd9Sstevel@tonic-gate 				break;
10267c478bd9Sstevel@tonic-gate 			}
10277c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wc,-xcode=", 11) == 0) {
102880ab886dSwesolows 				xlate(ctx->i_ae, arg + 11, xcode_tbl);
10297c478bd9Sstevel@tonic-gate 				if (strncmp(arg + 11, "pic", 3) == 0)
10307c478bd9Sstevel@tonic-gate 					pic = 1;
10317c478bd9Sstevel@tonic-gate 				break;
10327c478bd9Sstevel@tonic-gate 			}
10337c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wc,-Qiselect", 13) == 0) {
10347c478bd9Sstevel@tonic-gate 				/*
10357c478bd9Sstevel@tonic-gate 				 * Prevents insertion of register symbols.
10367c478bd9Sstevel@tonic-gate 				 * gcc doesn't do this, so ignore it.
10377c478bd9Sstevel@tonic-gate 				 */
10387c478bd9Sstevel@tonic-gate 				break;
10397c478bd9Sstevel@tonic-gate 			}
10407c478bd9Sstevel@tonic-gate #if defined(__x86)
10417c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Wu,-no_got_reloc") == 0) {
104280ab886dSwesolows 				newae(ctx->i_ae, "-fno-jump-tables");
104380ab886dSwesolows 				newae(ctx->i_ae, "-fno-constant-pools");
10447c478bd9Sstevel@tonic-gate 				break;
10457c478bd9Sstevel@tonic-gate 			}
10467c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Wu,-xmodel=kernel") == 0) {
104780ab886dSwesolows 				newae(ctx->i_ae, "-ffreestanding");
104880ab886dSwesolows 				newae(ctx->i_ae, "-mno-red-zone");
10497c478bd9Sstevel@tonic-gate 				model = "-mcmodel=kernel";
10507c478bd9Sstevel@tonic-gate 				nolibc = 1;
10517c478bd9Sstevel@tonic-gate 				break;
10527c478bd9Sstevel@tonic-gate 			}
1053d430274bSsherrym 			if (strcmp(arg, "-Wu,-save_args") == 0) {
105480ab886dSwesolows 				newae(ctx->i_ae, "-msave-args");
1055d430274bSsherrym 				break;
1056d430274bSsherrym 			}
10577c478bd9Sstevel@tonic-gate #endif	/* __x86 */
10587c478bd9Sstevel@tonic-gate 			error(arg);
10597c478bd9Sstevel@tonic-gate 			break;
10607c478bd9Sstevel@tonic-gate 		case 'X':
10617c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Xa") == 0 ||
10627c478bd9Sstevel@tonic-gate 			    strcmp(arg, "-Xt") == 0) {
106380ab886dSwesolows 				Xamode(ctx->i_ae);
10647c478bd9Sstevel@tonic-gate 				break;
10657c478bd9Sstevel@tonic-gate 			}
10667c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Xc") == 0) {
106780ab886dSwesolows 				Xcmode(ctx->i_ae);
10687c478bd9Sstevel@tonic-gate 				break;
10697c478bd9Sstevel@tonic-gate 			}
10707c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Xs") == 0) {
107180ab886dSwesolows 				Xsmode(ctx->i_ae);
10727c478bd9Sstevel@tonic-gate 				break;
10737c478bd9Sstevel@tonic-gate 			}
10747c478bd9Sstevel@tonic-gate 			error(arg);
10757c478bd9Sstevel@tonic-gate 			break;
10767c478bd9Sstevel@tonic-gate 		case 'x':
10777c478bd9Sstevel@tonic-gate 			if (arglen == 1)
10787c478bd9Sstevel@tonic-gate 				error(arg);
10797c478bd9Sstevel@tonic-gate 			switch (arg[2]) {
10807c478bd9Sstevel@tonic-gate #if defined(__x86)
10817c478bd9Sstevel@tonic-gate 			case '3':
10827c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-x386") == 0) {
108380ab886dSwesolows 					newae(ctx->i_ae, "-march=i386");
10847c478bd9Sstevel@tonic-gate 					break;
10857c478bd9Sstevel@tonic-gate 				}
10867c478bd9Sstevel@tonic-gate 				error(arg);
10877c478bd9Sstevel@tonic-gate 				break;
10887c478bd9Sstevel@tonic-gate 			case '4':
10897c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-x486") == 0) {
109080ab886dSwesolows 					newae(ctx->i_ae, "-march=i486");
10917c478bd9Sstevel@tonic-gate 					break;
10927c478bd9Sstevel@tonic-gate 				}
10937c478bd9Sstevel@tonic-gate 				error(arg);
10947c478bd9Sstevel@tonic-gate 				break;
10957c478bd9Sstevel@tonic-gate #endif	/* __x86 */
10967c478bd9Sstevel@tonic-gate 			case 'a':
10977c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xarch=", 7) == 0) {
109880ab886dSwesolows 					xlate(ctx->i_ae, arg + 7, xarch_tbl);
10997c478bd9Sstevel@tonic-gate 					break;
11007c478bd9Sstevel@tonic-gate 				}
11017c478bd9Sstevel@tonic-gate 				error(arg);
11027c478bd9Sstevel@tonic-gate 				break;
110302e56f3fSwesolows 			case 'b':
110402e56f3fSwesolows 				if (strncmp(arg, "-xbuiltin=", 10) == 0) {
110502e56f3fSwesolows 					if (strcmp(arg + 10, "%all"))
110680ab886dSwesolows 						newae(ctx->i_ae, "-fbuiltin");
110702e56f3fSwesolows 					break;
110802e56f3fSwesolows 				}
110902e56f3fSwesolows 				error(arg);
111002e56f3fSwesolows 				break;
11117c478bd9Sstevel@tonic-gate 			case 'C':
11127c478bd9Sstevel@tonic-gate 				/* Accept C++ style comments -- ignore */
11137c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xCC") == 0)
11147c478bd9Sstevel@tonic-gate 					break;
11157c478bd9Sstevel@tonic-gate 				error(arg);
11167c478bd9Sstevel@tonic-gate 				break;
11177c478bd9Sstevel@tonic-gate 			case 'c':
11187c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xc99=%all", 10) == 0) {
111980ab886dSwesolows 					newae(ctx->i_ae, "-std=gnu99");
11207c478bd9Sstevel@tonic-gate 					break;
11217c478bd9Sstevel@tonic-gate 				}
11227c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xc99=%none", 11) == 0) {
112380ab886dSwesolows 					newae(ctx->i_ae, "-std=gnu89");
11247c478bd9Sstevel@tonic-gate 					break;
11257c478bd9Sstevel@tonic-gate 				}
11267c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xchip=", 7) == 0) {
112780ab886dSwesolows 					xlate(ctx->i_ae, arg + 7, xchip_tbl);
11287c478bd9Sstevel@tonic-gate 					break;
11297c478bd9Sstevel@tonic-gate 				}
11307c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xcode=", 7) == 0) {
113180ab886dSwesolows 					xlate(ctx->i_ae, arg + 7, xcode_tbl);
11327c478bd9Sstevel@tonic-gate 					if (strncmp(arg + 7, "pic", 3) == 0)
11337c478bd9Sstevel@tonic-gate 						pic = 1;
11347c478bd9Sstevel@tonic-gate 					break;
11357c478bd9Sstevel@tonic-gate 				}
11367c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xcache=", 8) == 0)
11377c478bd9Sstevel@tonic-gate 					break;
1138159cf8a6Swesolows 				if (strncmp(arg, "-xcrossfile", 11) == 0)
1139159cf8a6Swesolows 					break;
11407c478bd9Sstevel@tonic-gate 				error(arg);
11417c478bd9Sstevel@tonic-gate 				break;
11427c478bd9Sstevel@tonic-gate 			case 'd':
11437c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xdepend") == 0)
11447c478bd9Sstevel@tonic-gate 					break;
11458c1a3716Ssherrym 				if (strncmp(arg, "-xdebugformat=", 14) == 0)
11468c1a3716Ssherrym 					break;
11477c478bd9Sstevel@tonic-gate 				error(arg);
11487c478bd9Sstevel@tonic-gate 				break;
11497c478bd9Sstevel@tonic-gate 			case 'F':
11507c478bd9Sstevel@tonic-gate 				/* compile for mapfile reordering -- ignore */
11517c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xF") == 0)
11527c478bd9Sstevel@tonic-gate 					break;
11537c478bd9Sstevel@tonic-gate 				error(arg);
11547c478bd9Sstevel@tonic-gate 				break;
11557c478bd9Sstevel@tonic-gate 			case 'i':
11567c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xinline", 8) == 0)
11577c478bd9Sstevel@tonic-gate 					/* No inlining; ignore */
11587c478bd9Sstevel@tonic-gate 					break;
11597c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xildon") == 0 ||
11607c478bd9Sstevel@tonic-gate 				    strcmp(arg, "-xildoff") == 0)
11617c478bd9Sstevel@tonic-gate 					/* No incremental linking; ignore */
11627c478bd9Sstevel@tonic-gate 					break;
11637c478bd9Sstevel@tonic-gate 				error(arg);
11647c478bd9Sstevel@tonic-gate 				break;
11657c478bd9Sstevel@tonic-gate 			case 'M':
11667c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xM") == 0) {
116780ab886dSwesolows 					newae(ctx->i_ae, "-M");
11687c478bd9Sstevel@tonic-gate 					break;
11697c478bd9Sstevel@tonic-gate 				}
11707c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xM1") == 0) {
117180ab886dSwesolows 					newae(ctx->i_ae, "-MM");
11727c478bd9Sstevel@tonic-gate 					break;
11737c478bd9Sstevel@tonic-gate 				}
11747c478bd9Sstevel@tonic-gate 				error(arg);
11757c478bd9Sstevel@tonic-gate 				break;
11767c478bd9Sstevel@tonic-gate 			case 'n':
11777c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xnolib") == 0) {
11787c478bd9Sstevel@tonic-gate 					nolibc = 1;
11797c478bd9Sstevel@tonic-gate 					break;
11807c478bd9Sstevel@tonic-gate 				}
11817c478bd9Sstevel@tonic-gate 				error(arg);
11827c478bd9Sstevel@tonic-gate 				break;
11837c478bd9Sstevel@tonic-gate 			case 'O':
11847c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xO", 3) == 0) {
11857c478bd9Sstevel@tonic-gate 					size_t len = strlen(arg);
118680ab886dSwesolows 					char *s;
11877c478bd9Sstevel@tonic-gate 					int c = *(arg + 3);
11887c478bd9Sstevel@tonic-gate 					int level;
11897c478bd9Sstevel@tonic-gate 
11907c478bd9Sstevel@tonic-gate 					if (len != 4 || !isdigit(c))
11917c478bd9Sstevel@tonic-gate 						error(arg);
11927c478bd9Sstevel@tonic-gate 
119380ab886dSwesolows 					if ((s = malloc(len)) == NULL)
119480ab886dSwesolows 						nomem();
119580ab886dSwesolows 
11967c478bd9Sstevel@tonic-gate 					level = atoi(arg + 3);
11977c478bd9Sstevel@tonic-gate 					if (level > 5)
11987c478bd9Sstevel@tonic-gate 						error(arg);
11997c478bd9Sstevel@tonic-gate 					if (level >= 2) {
12007c478bd9Sstevel@tonic-gate 						/*
12017c478bd9Sstevel@tonic-gate 						 * For gcc-3.4.x at -O2 we
12027c478bd9Sstevel@tonic-gate 						 * need to disable optimizations
12037c478bd9Sstevel@tonic-gate 						 * that break ON.
12047c478bd9Sstevel@tonic-gate 						 */
120580ab886dSwesolows 						optim_disable(ctx->i_ae, level);
12067c478bd9Sstevel@tonic-gate 						/*
12077c478bd9Sstevel@tonic-gate 						 * limit -xO3 to -O2 as well.
12087c478bd9Sstevel@tonic-gate 						 */
12097c478bd9Sstevel@tonic-gate 						level = 2;
12107c478bd9Sstevel@tonic-gate 					}
12117c478bd9Sstevel@tonic-gate 					(void) snprintf(s, len, "-O%d", level);
121280ab886dSwesolows 					newae(ctx->i_ae, s);
12137c478bd9Sstevel@tonic-gate 					free(s);
12147c478bd9Sstevel@tonic-gate 					break;
12157c478bd9Sstevel@tonic-gate 				}
12167c478bd9Sstevel@tonic-gate 				error(arg);
12177c478bd9Sstevel@tonic-gate 				break;
12187c478bd9Sstevel@tonic-gate 			case 'p':
12197c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xpentium") == 0) {
122080ab886dSwesolows 					newae(ctx->i_ae, "-march=pentium");
12217c478bd9Sstevel@tonic-gate 					break;
12227c478bd9Sstevel@tonic-gate 				}
12237c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xpg") == 0) {
122480ab886dSwesolows 					newae(ctx->i_ae, "-pg");
12257c478bd9Sstevel@tonic-gate 					break;
12267c478bd9Sstevel@tonic-gate 				}
12277c478bd9Sstevel@tonic-gate 				error(arg);
12287c478bd9Sstevel@tonic-gate 				break;
12297c478bd9Sstevel@tonic-gate 			case 'r':
12307c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xregs=", 7) == 0) {
123180ab886dSwesolows 					xlate(ctx->i_ae, arg + 7, xregs_tbl);
12327c478bd9Sstevel@tonic-gate 					break;
12337c478bd9Sstevel@tonic-gate 				}
12347c478bd9Sstevel@tonic-gate 				error(arg);
12357c478bd9Sstevel@tonic-gate 				break;
12367c478bd9Sstevel@tonic-gate 			case 's':
12377c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xs") == 0 ||
12387c478bd9Sstevel@tonic-gate 				    strcmp(arg, "-xspace") == 0 ||
12397c478bd9Sstevel@tonic-gate 				    strcmp(arg, "-xstrconst") == 0)
12407c478bd9Sstevel@tonic-gate 					break;
12417c478bd9Sstevel@tonic-gate 				error(arg);
12427c478bd9Sstevel@tonic-gate 				break;
12437c478bd9Sstevel@tonic-gate 			case 't':
12447c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xtransition") == 0) {
124580ab886dSwesolows 					newae(ctx->i_ae, "-Wtransition");
12467c478bd9Sstevel@tonic-gate 					break;
12477c478bd9Sstevel@tonic-gate 				}
12487c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xtrigraphs=yes") == 0) {
124980ab886dSwesolows 					newae(ctx->i_ae, "-trigraphs");
12507c478bd9Sstevel@tonic-gate 					break;
12517c478bd9Sstevel@tonic-gate 				}
12527c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xtrigraphs=no") == 0) {
125380ab886dSwesolows 					newae(ctx->i_ae, "-notrigraphs");
12547c478bd9Sstevel@tonic-gate 					break;
12557c478bd9Sstevel@tonic-gate 				}
12567c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xtarget=", 9) == 0) {
125780ab886dSwesolows 					xlate(ctx->i_ae, arg + 9, xtarget_tbl);
12587c478bd9Sstevel@tonic-gate 					break;
12597c478bd9Sstevel@tonic-gate 				}
12607c478bd9Sstevel@tonic-gate 				error(arg);
12617c478bd9Sstevel@tonic-gate 				break;
12627c478bd9Sstevel@tonic-gate 			case 'e':
12637c478bd9Sstevel@tonic-gate 			case 'h':
12647c478bd9Sstevel@tonic-gate 			case 'l':
12657c478bd9Sstevel@tonic-gate 			default:
12667c478bd9Sstevel@tonic-gate 				error(arg);
12677c478bd9Sstevel@tonic-gate 				break;
12687c478bd9Sstevel@tonic-gate 			}
12697c478bd9Sstevel@tonic-gate 			break;
12707c478bd9Sstevel@tonic-gate 		case 'Y':
12717c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
127280ab886dSwesolows 				if ((arg = *++ctx->i_oldargv) == NULL ||
127380ab886dSwesolows 				    *arg == '\0')
12747c478bd9Sstevel@tonic-gate 					error("-Y");
127580ab886dSwesolows 				ctx->i_oldargc--;
12767c478bd9Sstevel@tonic-gate 				arglen = strlen(arg + 1);
12777c478bd9Sstevel@tonic-gate 			} else {
12787c478bd9Sstevel@tonic-gate 				arg += 2;
12797c478bd9Sstevel@tonic-gate 			}
12807c478bd9Sstevel@tonic-gate 			/* Just ignore -YS,... for now */
12817c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "S,", 2) == 0)
12827c478bd9Sstevel@tonic-gate 				break;
12837c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "l,", 2) == 0) {
12847c478bd9Sstevel@tonic-gate 				char *s = strdup(arg);
12857c478bd9Sstevel@tonic-gate 				s[0] = '-';
12867c478bd9Sstevel@tonic-gate 				s[1] = 'B';
128780ab886dSwesolows 				newae(ctx->i_ae, s);
12887c478bd9Sstevel@tonic-gate 				free(s);
12897c478bd9Sstevel@tonic-gate 				break;
12907c478bd9Sstevel@tonic-gate 			}
12917c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "I,", 2) == 0) {
12927c478bd9Sstevel@tonic-gate 				char *s = strdup(arg);
12937c478bd9Sstevel@tonic-gate 				s[0] = '-';
12947c478bd9Sstevel@tonic-gate 				s[1] = 'I';
129580ab886dSwesolows 				newae(ctx->i_ae, "-nostdinc");
129680ab886dSwesolows 				newae(ctx->i_ae, s);
12977c478bd9Sstevel@tonic-gate 				free(s);
12987c478bd9Sstevel@tonic-gate 				break;
12997c478bd9Sstevel@tonic-gate 			}
13007c478bd9Sstevel@tonic-gate 			error(arg);
13017c478bd9Sstevel@tonic-gate 			break;
13027c478bd9Sstevel@tonic-gate 		case 'Q':
13037c478bd9Sstevel@tonic-gate 			/*
13047c478bd9Sstevel@tonic-gate 			 * We could map -Qy into -Wl,-Qy etc.
13057c478bd9Sstevel@tonic-gate 			 */
13067c478bd9Sstevel@tonic-gate 		default:
13077c478bd9Sstevel@tonic-gate 			error(arg);
13087c478bd9Sstevel@tonic-gate 			break;
13097c478bd9Sstevel@tonic-gate 		}
13107c478bd9Sstevel@tonic-gate 	}
13117c478bd9Sstevel@tonic-gate 
131280ab886dSwesolows 	if (c_files > 1 && (ctx->i_flags & CW_F_SHADOW) &&
131380ab886dSwesolows 	    op != CW_O_PREPROCESS) {
131480ab886dSwesolows 		(void) fprintf(stderr, "%s: error: multiple source files are "
131580ab886dSwesolows 		    "allowed only with -E or -P\n", progname);
131680ab886dSwesolows 		exit(2);
131780ab886dSwesolows 	}
131880ab886dSwesolows 	if (op == CW_O_LINK && (ctx->i_flags & CW_F_SHADOW))
131980ab886dSwesolows 		exit(0);
132080ab886dSwesolows 
13217c478bd9Sstevel@tonic-gate 	if (model && !pic)
132280ab886dSwesolows 		newae(ctx->i_ae, model);
13237c478bd9Sstevel@tonic-gate 	if (!nolibc)
132480ab886dSwesolows 		newae(ctx->i_ae, "-lc");
132580ab886dSwesolows 	if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) {
132680ab886dSwesolows 		newae(ctx->i_ae, "-o");
132780ab886dSwesolows 		newae(ctx->i_ae, ctx->i_discard);
132880ab886dSwesolows 	}
132980ab886dSwesolows }
133080ab886dSwesolows 
133180ab886dSwesolows static void
133280ab886dSwesolows do_cc(cw_ictx_t *ctx)
133380ab886dSwesolows {
133480ab886dSwesolows 	int in_output = 0, seen_o = 0;
133580ab886dSwesolows 	cw_op_t op = CW_O_LINK;
133680ab886dSwesolows 
1337*1912d2c4Swesolows 	if (ctx->i_flags & CW_F_PROG) {
1338*1912d2c4Swesolows 		newae(ctx->i_ae, "-V");
1339*1912d2c4Swesolows 		return;
1340*1912d2c4Swesolows 	}
1341*1912d2c4Swesolows 
134280ab886dSwesolows 	while (--ctx->i_oldargc > 0) {
134380ab886dSwesolows 		char *arg = *++ctx->i_oldargv;
134480ab886dSwesolows 
134580ab886dSwesolows 		if (*arg != '-') {
134680ab886dSwesolows 			if (in_output == 0 || !(ctx->i_flags & CW_F_SHADOW)) {
134780ab886dSwesolows 				newae(ctx->i_ae, arg);
134880ab886dSwesolows 			} else {
134980ab886dSwesolows 				in_output = 0;
135080ab886dSwesolows 				newae(ctx->i_ae, ctx->i_discard);
135180ab886dSwesolows 			}
135280ab886dSwesolows 			continue;
135380ab886dSwesolows 		}
135480ab886dSwesolows 		switch (*(arg + 1)) {
135580ab886dSwesolows 		case '_':
135680ab886dSwesolows 			if (strcmp(arg, "-_noecho") == 0) {
135780ab886dSwesolows 				ctx->i_flags &= ~CW_F_ECHO;
135880ab886dSwesolows 			} else if (strncmp(arg, "-_cc=", 5) == 0 ||
135980ab886dSwesolows 			    strncmp(arg, "-_CC=", 5) == 0) {
136080ab886dSwesolows 				newae(ctx->i_ae, arg + 5);
136180ab886dSwesolows 			} else if (strncmp(arg, "-_gcc=", 6) != 0 &&
136280ab886dSwesolows 			    strncmp(arg, "-_g++=", 6) != 0) {
136380ab886dSwesolows 				(void) fprintf(stderr,
136480ab886dSwesolows 				    "%s: invalid argument '%s'\n", progname,
136580ab886dSwesolows 				    arg);
136680ab886dSwesolows 				exit(2);
136780ab886dSwesolows 			}
136880ab886dSwesolows 			break;
136980ab886dSwesolows 		case 'V':
137080ab886dSwesolows 			ctx->i_flags &= ~CW_F_ECHO;
137180ab886dSwesolows 			newae(ctx->i_ae, arg);
137280ab886dSwesolows 			break;
137380ab886dSwesolows 		case 'o':
137480ab886dSwesolows 			seen_o = 1;
137580ab886dSwesolows 			if (strlen(arg) == 2) {
137680ab886dSwesolows 				in_output = 1;
137780ab886dSwesolows 				newae(ctx->i_ae, arg);
137880ab886dSwesolows 			} else if (ctx->i_flags & CW_F_SHADOW) {
137980ab886dSwesolows 				newae(ctx->i_ae, "-o");
138080ab886dSwesolows 				newae(ctx->i_ae, ctx->i_discard);
138180ab886dSwesolows 			} else {
138280ab886dSwesolows 				newae(ctx->i_ae, arg);
138380ab886dSwesolows 			}
138480ab886dSwesolows 			break;
138580ab886dSwesolows 		case 'c':
138680ab886dSwesolows 		case 'S':
138780ab886dSwesolows 			op = CW_O_COMPILE;
138880ab886dSwesolows 			newae(ctx->i_ae, arg);
138980ab886dSwesolows 			break;
139080ab886dSwesolows 		case 'E':
139180ab886dSwesolows 		case 'P':
139280ab886dSwesolows 			op = CW_O_PREPROCESS;
139380ab886dSwesolows 		/*FALLTHROUGH*/
139480ab886dSwesolows 		default:
139580ab886dSwesolows 			newae(ctx->i_ae, arg);
139680ab886dSwesolows 		}
139780ab886dSwesolows 	}
139880ab886dSwesolows 
139980ab886dSwesolows 	if ((op == CW_O_LINK || op == CW_O_PREPROCESS) &&
140080ab886dSwesolows 	    (ctx->i_flags & CW_F_SHADOW))
140180ab886dSwesolows 		exit(0);
140280ab886dSwesolows 
140380ab886dSwesolows 	if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) {
140480ab886dSwesolows 		newae(ctx->i_ae, "-o");
140580ab886dSwesolows 		newae(ctx->i_ae, ctx->i_discard);
140680ab886dSwesolows 	}
14077c478bd9Sstevel@tonic-gate }
14087c478bd9Sstevel@tonic-gate 
14097c478bd9Sstevel@tonic-gate static void
141080ab886dSwesolows prepctx(cw_ictx_t *ctx)
14117c478bd9Sstevel@tonic-gate {
141280ab886dSwesolows 	const char *dir, *cmd;
14137c478bd9Sstevel@tonic-gate 	char *program;
141480ab886dSwesolows 	size_t len;
14157c478bd9Sstevel@tonic-gate 
141680ab886dSwesolows 	dir = dirs[CIDX(CC(ctx), ctx->i_flags)];
141780ab886dSwesolows 	cmd = cmds[CIDX(CC(ctx), ctx->i_flags)];
141880ab886dSwesolows 	len = strlen(dir) + strlen(cmd) + 2;
141980ab886dSwesolows 	if ((program = malloc(len)) == NULL)
142080ab886dSwesolows 		nomem();
14217c478bd9Sstevel@tonic-gate 	(void) snprintf(program, len, "%s/%s", dir, cmd);
14227c478bd9Sstevel@tonic-gate 
142380ab886dSwesolows 	newae(ctx->i_ae, program);
142480ab886dSwesolows 
1425*1912d2c4Swesolows 	if (ctx->i_flags & CW_F_PROG) {
1426*1912d2c4Swesolows 		(void) printf("%s: %s\n", (ctx->i_flags & CW_F_SHADOW) ?
1427*1912d2c4Swesolows 		    "shadow" : "primary", program);
1428*1912d2c4Swesolows 		(void) fflush(stdout);
1429*1912d2c4Swesolows 	}
1430*1912d2c4Swesolows 
143180ab886dSwesolows 	if (!(ctx->i_flags & CW_F_XLATE))
143280ab886dSwesolows 		return;
143380ab886dSwesolows 
143480ab886dSwesolows 	switch (CC(ctx)) {
143580ab886dSwesolows 	case CW_C_CC:
143680ab886dSwesolows 		do_cc(ctx);
143780ab886dSwesolows 		break;
143880ab886dSwesolows 	case CW_C_GCC:
143980ab886dSwesolows 		do_gcc(ctx);
144080ab886dSwesolows 		break;
144180ab886dSwesolows 	}
144280ab886dSwesolows }
144380ab886dSwesolows 
144480ab886dSwesolows static int
144580ab886dSwesolows invoke(cw_ictx_t *ctx)
144680ab886dSwesolows {
144780ab886dSwesolows 	char **newargv;
144880ab886dSwesolows 	int ac;
144980ab886dSwesolows 	struct ae *a;
145080ab886dSwesolows 
145180ab886dSwesolows 	if ((newargv = calloc(sizeof (*newargv), ctx->i_ae->ael_argc + 1)) ==
145280ab886dSwesolows 	    NULL)
145380ab886dSwesolows 		nomem();
145480ab886dSwesolows 
145580ab886dSwesolows 	if (ctx->i_flags & CW_F_ECHO)
145680ab886dSwesolows 		(void) fprintf(stderr, "+ ");
145780ab886dSwesolows 
145880ab886dSwesolows 	for (ac = 0, a = ctx->i_ae->ael_head; a; a = a->ae_next, ac++) {
145980ab886dSwesolows 		newargv[ac] = a->ae_arg;
146080ab886dSwesolows 		if (ctx->i_flags & CW_F_ECHO)
146180ab886dSwesolows 			(void) fprintf(stderr, "%s ", a->ae_arg);
146280ab886dSwesolows 		if (a == ctx->i_ae->ael_tail)
146380ab886dSwesolows 			break;
146480ab886dSwesolows 	}
146580ab886dSwesolows 
146680ab886dSwesolows 	if (ctx->i_flags & CW_F_ECHO) {
146780ab886dSwesolows 		(void) fprintf(stderr, "\n");
146880ab886dSwesolows 		(void) fflush(stderr);
146980ab886dSwesolows 	}
147080ab886dSwesolows 
147180ab886dSwesolows 	if (!(ctx->i_flags & CW_F_EXEC))
147280ab886dSwesolows 		return (0);
147380ab886dSwesolows 
14747c478bd9Sstevel@tonic-gate 	/*
147580ab886dSwesolows 	 * We must fix up the environment here so that the
147680ab886dSwesolows 	 * dependency files are not trampled by the shadow compiler.
14777c478bd9Sstevel@tonic-gate 	 */
147880ab886dSwesolows 	if ((ctx->i_flags & CW_F_SHADOW) &&
147980ab886dSwesolows 	    (unsetenv("SUNPRO_DEPENDENCIES") != 0 ||
148080ab886dSwesolows 	    unsetenv("DEPENDENCIES_OUTPUT") != 0)) {
148180ab886dSwesolows 		(void) fprintf(stderr, "error: environment setup failed: %s\n",
148280ab886dSwesolows 		    strerror(errno));
148380ab886dSwesolows 		return (-1);
148480ab886dSwesolows 	}
14857c478bd9Sstevel@tonic-gate 
148680ab886dSwesolows 	(void) execv(newargv[0], newargv);
148780ab886dSwesolows 	cw_perror("couldn't run %s", newargv[0]);
14887c478bd9Sstevel@tonic-gate 
148980ab886dSwesolows 	return (-1);
149080ab886dSwesolows }
149180ab886dSwesolows 
149280ab886dSwesolows static int
149380ab886dSwesolows reap(cw_ictx_t *ctx)
149480ab886dSwesolows {
1495*1912d2c4Swesolows 	int status, ret = 0;
149680ab886dSwesolows 	char buf[1024];
149780ab886dSwesolows 	struct stat s;
149880ab886dSwesolows 
149980ab886dSwesolows 	do {
1500*1912d2c4Swesolows 		(void) waitpid(ctx->i_pid, &status, 0);
1501*1912d2c4Swesolows 		if (status != 0) {
1502*1912d2c4Swesolows 			if (WIFSIGNALED(status)) {
1503*1912d2c4Swesolows 				ret = -WTERMSIG(status);
150480ab886dSwesolows 				break;
1505*1912d2c4Swesolows 			} else if (WIFEXITED(status)) {
1506*1912d2c4Swesolows 				ret = WEXITSTATUS(status);
150780ab886dSwesolows 				break;
150880ab886dSwesolows 			}
15097c478bd9Sstevel@tonic-gate 		}
1510*1912d2c4Swesolows 	} while (!WIFEXITED(status) && !WIFSIGNALED(status));
151180ab886dSwesolows 
151280ab886dSwesolows 	(void) unlink(ctx->i_discard);
151380ab886dSwesolows 
1514*1912d2c4Swesolows 	if (stat(ctx->i_stderr, &s) < 0) {
151580ab886dSwesolows 		cw_perror("stat failed on child cleanup");
151680ab886dSwesolows 		return (-1);
15177c478bd9Sstevel@tonic-gate 	}
151880ab886dSwesolows 	if (s.st_size != 0) {
1519*1912d2c4Swesolows 		FILE *f;
152080ab886dSwesolows 
1521*1912d2c4Swesolows 		if ((f = fopen(ctx->i_stderr, "r")) != NULL) {
1522*1912d2c4Swesolows 			while (fgets(buf, sizeof (buf), f))
1523*1912d2c4Swesolows 				(void) fprintf(stderr, "%s", buf);
1524*1912d2c4Swesolows 			(void) fflush(stderr);
1525*1912d2c4Swesolows 			(void) fclose(f);
1526*1912d2c4Swesolows 		}
152780ab886dSwesolows 	}
1528*1912d2c4Swesolows 	(void) unlink(ctx->i_stderr);
1529*1912d2c4Swesolows 	free(ctx->i_stderr);
1530*1912d2c4Swesolows 
1531*1912d2c4Swesolows 	/*
1532*1912d2c4Swesolows 	 * cc returns an error code when given -V; we want that to succeed.
1533*1912d2c4Swesolows 	 */
1534*1912d2c4Swesolows 	if (ctx->i_flags & CW_F_PROG)
1535*1912d2c4Swesolows 		return (0);
153680ab886dSwesolows 
153780ab886dSwesolows 	return (ret);
153880ab886dSwesolows }
153980ab886dSwesolows 
154080ab886dSwesolows static int
154180ab886dSwesolows exec_ctx(cw_ictx_t *ctx, int block)
154280ab886dSwesolows {
154380ab886dSwesolows 	char *file;
154480ab886dSwesolows 
154580ab886dSwesolows 	/*
154680ab886dSwesolows 	 * To avoid offending cc's sensibilities, the name of its output
154780ab886dSwesolows 	 * file must end in '.o'.
154880ab886dSwesolows 	 */
154980ab886dSwesolows 	if ((file = tempnam(NULL, ".cw")) == NULL) {
155080ab886dSwesolows 		nomem();
155180ab886dSwesolows 		return (-1);
155280ab886dSwesolows 	}
155380ab886dSwesolows 	(void) strlcpy(ctx->i_discard, file, MAXPATHLEN);
155480ab886dSwesolows 	(void) strlcat(ctx->i_discard, ".o", MAXPATHLEN);
155580ab886dSwesolows 	free(file);
155680ab886dSwesolows 
1557*1912d2c4Swesolows 	if ((ctx->i_stderr = tempnam(NULL, ".cw")) == NULL) {
1558*1912d2c4Swesolows 		nomem();
155980ab886dSwesolows 		return (-1);
156080ab886dSwesolows 	}
156180ab886dSwesolows 
156280ab886dSwesolows 	if ((ctx->i_pid = fork()) == 0) {
1563*1912d2c4Swesolows 		int fd;
1564*1912d2c4Swesolows 
156580ab886dSwesolows 		(void) fclose(stderr);
1566*1912d2c4Swesolows 		if ((fd = open(ctx->i_stderr, O_WRONLY | O_CREAT | O_EXCL,
1567*1912d2c4Swesolows 		    0666)) < 0) {
1568*1912d2c4Swesolows 			cw_perror("open failed for standard error");
1569*1912d2c4Swesolows 			exit(1);
1570*1912d2c4Swesolows 		}
1571*1912d2c4Swesolows 		if (dup2(fd, 2) < 0) {
157280ab886dSwesolows 			cw_perror("dup2 failed for standard error");
157380ab886dSwesolows 			exit(1);
157480ab886dSwesolows 		}
1575*1912d2c4Swesolows 		if (fd != 2)
1576*1912d2c4Swesolows 			(void) close(fd);
157780ab886dSwesolows 		if (freopen("/dev/fd/2", "w", stderr) == NULL) {
157880ab886dSwesolows 			cw_perror("freopen failed for /dev/fd/2");
157980ab886dSwesolows 			exit(1);
158080ab886dSwesolows 		}
158180ab886dSwesolows 		prepctx(ctx);
158280ab886dSwesolows 		exit(invoke(ctx));
158380ab886dSwesolows 	}
158480ab886dSwesolows 
158580ab886dSwesolows 	if (ctx->i_pid < 0) {
158680ab886dSwesolows 		cw_perror("fork failed");
158780ab886dSwesolows 		return (1);
158880ab886dSwesolows 	}
158980ab886dSwesolows 
159080ab886dSwesolows 	if (block)
159180ab886dSwesolows 		return (reap(ctx));
159280ab886dSwesolows 
159380ab886dSwesolows 	return (0);
15947c478bd9Sstevel@tonic-gate }
15957c478bd9Sstevel@tonic-gate 
15967c478bd9Sstevel@tonic-gate int
15977c478bd9Sstevel@tonic-gate main(int argc, char **argv)
15987c478bd9Sstevel@tonic-gate {
159980ab886dSwesolows 	cw_ictx_t *ctx = newictx();
160080ab886dSwesolows 	cw_ictx_t *ctx_shadow = newictx();
16017c478bd9Sstevel@tonic-gate 	const char *dir;
16027c478bd9Sstevel@tonic-gate 	char cc_buf[MAXPATHLEN], gcc_buf[MAXPATHLEN];
160380ab886dSwesolows 	int do_serial, do_shadow;
160480ab886dSwesolows 	int ret = 0;
16057c478bd9Sstevel@tonic-gate 
16067c478bd9Sstevel@tonic-gate 	if ((progname = strrchr(argv[0], '/')) == NULL)
16077c478bd9Sstevel@tonic-gate 		progname = argv[0];
16087c478bd9Sstevel@tonic-gate 	else
16097c478bd9Sstevel@tonic-gate 		progname++;
16107c478bd9Sstevel@tonic-gate 
161180ab886dSwesolows 	if (ctx == NULL || ctx_shadow == NULL)
161280ab886dSwesolows 		nomem();
161380ab886dSwesolows 
161480ab886dSwesolows 	ctx->i_flags = CW_F_ECHO|CW_F_XLATE;
16157c478bd9Sstevel@tonic-gate 
16167c478bd9Sstevel@tonic-gate 	/*
16177c478bd9Sstevel@tonic-gate 	 * Figure out where to get our tools from.  This depends on
16187c478bd9Sstevel@tonic-gate 	 * the environment variables set at run time.
16197c478bd9Sstevel@tonic-gate 	 */
16207c478bd9Sstevel@tonic-gate 	if ((dir = getenv("SPRO_VROOT")) != NULL) {
16217c478bd9Sstevel@tonic-gate 		(void) snprintf(cc_buf, MAXPATHLEN, "%s/bin", dir);
16227c478bd9Sstevel@tonic-gate 	} else if ((dir = getenv("SPRO_ROOT")) != NULL) {
162335a86aa1Spetede 		(void) snprintf(cc_buf, MAXPATHLEN, "%s/SOS10/bin", dir);
16247c478bd9Sstevel@tonic-gate 	} else if ((dir = getenv("BUILD_TOOLS")) != NULL) {
16257c478bd9Sstevel@tonic-gate 		(void) snprintf(cc_buf, MAXPATHLEN,
162635a86aa1Spetede 		    "%s/SUNWspro/SOS10/bin", dir);
16277c478bd9Sstevel@tonic-gate 	}
162880ab886dSwesolows 	if (dir != NULL) {
162980ab886dSwesolows 		dirs[CIDX(CW_C_CC, 0)] = (const char *)cc_buf;
163080ab886dSwesolows 		dirs[CIDX(CW_C_CC, CW_F_CXX)] = (const char *)cc_buf;
163180ab886dSwesolows 	}
16327c478bd9Sstevel@tonic-gate 
16337c478bd9Sstevel@tonic-gate 	if ((dir = getenv("GNU_ROOT")) != NULL) {
16347c478bd9Sstevel@tonic-gate 		(void) snprintf(gcc_buf, MAXPATHLEN, "%s/bin", dir);
163580ab886dSwesolows 		dirs[CIDX(CW_C_GCC, 0)] = (const char *)gcc_buf;
163680ab886dSwesolows 		dirs[CIDX(CW_C_GCC, CW_F_CXX)] = (const char *)gcc_buf;
16377c478bd9Sstevel@tonic-gate 	}
16387c478bd9Sstevel@tonic-gate 
163980ab886dSwesolows 	if ((dir = getenv("CW_CC_DIR")) != NULL)
164080ab886dSwesolows 		dirs[CIDX(CW_C_CC, 0)] = dir;
164180ab886dSwesolows 	if ((dir = getenv("CW_CPLUSPLUS_DIR")) != NULL)
164280ab886dSwesolows 		dirs[CIDX(CW_C_CC, CW_F_CXX)] = dir;
164380ab886dSwesolows 	if ((dir = getenv("CW_GCC_DIR")) != NULL)
164480ab886dSwesolows 		dirs[CIDX(CW_C_GCC, 0)] = dir;
164580ab886dSwesolows 	if ((dir = getenv("CW_GPLUSPLUS_DIR")) != NULL)
164680ab886dSwesolows 		dirs[CIDX(CW_C_GCC, CW_F_CXX)] = dir;
164780ab886dSwesolows 
164880ab886dSwesolows 	do_shadow = (getenv("CW_NO_SHADOW") ? 0 : 1);
164980ab886dSwesolows 	do_serial = (getenv("CW_SHADOW_SERIAL") ? 1 : 0);
165080ab886dSwesolows 
165180ab886dSwesolows 	if (getenv("CW_NO_EXEC") == NULL)
165280ab886dSwesolows 		ctx->i_flags |= CW_F_EXEC;
16537c478bd9Sstevel@tonic-gate 
16547c478bd9Sstevel@tonic-gate 	/*
16557c478bd9Sstevel@tonic-gate 	 * The first argument must be one of "-_cc", "-_gcc", "-_CC", or "-_g++"
16567c478bd9Sstevel@tonic-gate 	 */
16577c478bd9Sstevel@tonic-gate 	if (argc == 1)
16587c478bd9Sstevel@tonic-gate 		usage();
16597c478bd9Sstevel@tonic-gate 	argc--;
16607c478bd9Sstevel@tonic-gate 	argv++;
16617c478bd9Sstevel@tonic-gate 	if (strcmp(argv[0], "-_cc") == 0) {
166280ab886dSwesolows 		ctx->i_compiler = CW_C_CC;
16637c478bd9Sstevel@tonic-gate 	} else if (strcmp(argv[0], "-_gcc") == 0) {
166480ab886dSwesolows 		ctx->i_compiler = CW_C_GCC;
16657c478bd9Sstevel@tonic-gate 	} else if (strcmp(argv[0], "-_CC") == 0) {
166680ab886dSwesolows 		ctx->i_compiler = CW_C_CC;
166780ab886dSwesolows 		ctx->i_flags |= CW_F_CXX;
16687c478bd9Sstevel@tonic-gate 	} else if (strcmp(argv[0], "-_g++") == 0) {
166980ab886dSwesolows 		ctx->i_compiler = CW_C_GCC;
167080ab886dSwesolows 		ctx->i_flags |= CW_F_CXX;
16717c478bd9Sstevel@tonic-gate 	} else {
16727c478bd9Sstevel@tonic-gate 		/* assume "-_gcc" by default */
16737c478bd9Sstevel@tonic-gate 		argc++;
16747c478bd9Sstevel@tonic-gate 		argv--;
167580ab886dSwesolows 		ctx->i_compiler = CW_C_GCC;
16767c478bd9Sstevel@tonic-gate 	}
16777c478bd9Sstevel@tonic-gate 
1678*1912d2c4Swesolows 	/*
1679*1912d2c4Swesolows 	 * -_compiler - tell us the path to the primary compiler only
1680*1912d2c4Swesolows 	 */
168180ab886dSwesolows 	if (argc > 1 && strcmp(argv[1], "-_compiler") == 0) {
168280ab886dSwesolows 		ctx->i_flags &= ~CW_F_XLATE;
168380ab886dSwesolows 		prepctx(ctx);
168480ab886dSwesolows 		(void) printf("%s\n", ctx->i_ae->ael_head->ae_arg);
168580ab886dSwesolows 		return (0);
16867c478bd9Sstevel@tonic-gate 	}
16877c478bd9Sstevel@tonic-gate 
1688*1912d2c4Swesolows 	/*
1689*1912d2c4Swesolows 	 * -_versions - tell us the cw version, paths to all compilers, and
1690*1912d2c4Swesolows 	 *		ask each for its version if we know how.
1691*1912d2c4Swesolows 	 */
1692*1912d2c4Swesolows 	if (argc > 1 && strcmp(argv[1], "-_versions") == 0) {
1693*1912d2c4Swesolows 		(void) printf("%s", "cw version %I%");
1694*1912d2c4Swesolows 		if (!do_shadow)
1695*1912d2c4Swesolows 			(void) printf(" (SHADOW MODE DISABLED)");
1696*1912d2c4Swesolows 		(void) printf("\n");
1697*1912d2c4Swesolows 		(void) fflush(stdout);
1698*1912d2c4Swesolows 		ctx->i_flags &= ~CW_F_ECHO;
1699*1912d2c4Swesolows 		ctx->i_flags |= CW_F_PROG|CW_F_EXEC;
1700*1912d2c4Swesolows 		argc--;
1701*1912d2c4Swesolows 		argv++;
1702*1912d2c4Swesolows 		do_serial = 1;
1703*1912d2c4Swesolows 	}
1704*1912d2c4Swesolows 
1705*1912d2c4Swesolows 	ctx->i_oldargc = argc;
1706*1912d2c4Swesolows 	ctx->i_oldargv = argv;
1707*1912d2c4Swesolows 
170880ab886dSwesolows 	ret |= exec_ctx(ctx, do_serial);
170980ab886dSwesolows 
171080ab886dSwesolows 	if (do_shadow) {
171180ab886dSwesolows 		(void) memcpy(ctx_shadow, ctx, sizeof (cw_ictx_t));
171280ab886dSwesolows 		ctx_shadow->i_flags |= CW_F_SHADOW;
171380ab886dSwesolows 		ret |= exec_ctx(ctx_shadow, 1);
17147c478bd9Sstevel@tonic-gate 	}
17157c478bd9Sstevel@tonic-gate 
171680ab886dSwesolows 	if (!do_serial)
171780ab886dSwesolows 		ret |= reap(ctx);
17187c478bd9Sstevel@tonic-gate 
171980ab886dSwesolows 	return (ret);
17207c478bd9Sstevel@tonic-gate }
1721