xref: /illumos-gate/usr/src/tools/cw/cw.c (revision 54836668)
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
228*54836668Spetede  * -xmodel=kernel		-ffreestanding -mcmodel=kernel -mno-red-zone
229d430274bSsherrym  * -Wu,-save_args		-msave-args
2307c478bd9Sstevel@tonic-gate  * -w				pass-thru
2317c478bd9Sstevel@tonic-gate  * -Xa				-std=iso9899:199409 or -ansi
2327c478bd9Sstevel@tonic-gate  * -Xc				-ansi -pedantic
2337c478bd9Sstevel@tonic-gate  * -Xt				error
2347c478bd9Sstevel@tonic-gate  * -Xs				-traditional -std=c89
2357c478bd9Sstevel@tonic-gate  * -x386			-march=i386 (x86 only)
2367c478bd9Sstevel@tonic-gate  * -x486			-march=i486 (x86 only)
2377c478bd9Sstevel@tonic-gate  * -xarch=<a>			table
23802e56f3fSwesolows  * -xbuiltin[=<b>]		-fbuiltin (-fno-builtin otherwise)
2397c478bd9Sstevel@tonic-gate  * -xCC				ignore
2407c478bd9Sstevel@tonic-gate  * -xchar_byte_order=<o>	error
2417c478bd9Sstevel@tonic-gate  * -xchip=<c>			table
2427c478bd9Sstevel@tonic-gate  * -xcode=<c>			table
2438c1a3716Ssherrym  * -xdebugformat=<format>	ignore (always use dwarf-2 for gcc)
244159cf8a6Swesolows  * -xcrossfile[=<n>]		ignore
2457c478bd9Sstevel@tonic-gate  * -xe				error
2467c478bd9Sstevel@tonic-gate  * -xF				error
2477c478bd9Sstevel@tonic-gate  * -xhelp=<f>			error
2487c478bd9Sstevel@tonic-gate  * -xildoff			ignore
2497c478bd9Sstevel@tonic-gate  * -xildon			ignore
2507c478bd9Sstevel@tonic-gate  * -xinline			ignore
2517c478bd9Sstevel@tonic-gate  * -xlibmieee			error
2527c478bd9Sstevel@tonic-gate  * -xlibmil			error
2537c478bd9Sstevel@tonic-gate  * -xlic_lib=sunperf		error
2547c478bd9Sstevel@tonic-gate  * -xM				-M
2557c478bd9Sstevel@tonic-gate  * -xM1				-MM
2567c478bd9Sstevel@tonic-gate  * -xmaxopt=[...]		error
2577c478bd9Sstevel@tonic-gate  * -xnolib			-nodefaultlibs
2587c478bd9Sstevel@tonic-gate  * -xnolibmil			error
2597c478bd9Sstevel@tonic-gate  * -xO<n>			-O<n>
2607c478bd9Sstevel@tonic-gate  * -xP				error
2617c478bd9Sstevel@tonic-gate  * -xpentium			-march=pentium (x86 only)
2627c478bd9Sstevel@tonic-gate  * -xpg				error
2637c478bd9Sstevel@tonic-gate  * -xprofile=<p>		error
2647c478bd9Sstevel@tonic-gate  * -xregs=<r>			table
2657c478bd9Sstevel@tonic-gate  * -xs				error
2667c478bd9Sstevel@tonic-gate  * -xsb				error
2677c478bd9Sstevel@tonic-gate  * -xsbfast			error
2687c478bd9Sstevel@tonic-gate  * -xsfpconst			error
2697c478bd9Sstevel@tonic-gate  * -xspace			ignore (-not -Os)
2707c478bd9Sstevel@tonic-gate  * -xstrconst			ignore
2717c478bd9Sstevel@tonic-gate  * -xtarget=<t>			table
2727c478bd9Sstevel@tonic-gate  * -xtemp=<dir>			error
2737c478bd9Sstevel@tonic-gate  * -xtime			error
2747c478bd9Sstevel@tonic-gate  * -xtransition			-Wtransition
2757c478bd9Sstevel@tonic-gate  * -xtrigraphs=<yes|no>		-trigraphs -notrigraphs
2767c478bd9Sstevel@tonic-gate  * -xunroll=n			error
2778c1a3716Ssherrym  * -W0,-xdbggen=no%usedonly	-fno-eliminate-unused-debug-symbols
2788c1a3716Ssherrym  *				-fno-eliminate-unused-debug-types
2797c478bd9Sstevel@tonic-gate  * -Y<c>,<dir>			error
2807c478bd9Sstevel@tonic-gate  * -YA,<dir>			error
2817c478bd9Sstevel@tonic-gate  * -YI,<dir>			-nostdinc -I<dir>
2827c478bd9Sstevel@tonic-gate  * -YP,<dir>			error
2837c478bd9Sstevel@tonic-gate  * -YS,<dir>			error
2847c478bd9Sstevel@tonic-gate  */
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate #include <stdio.h>
2877c478bd9Sstevel@tonic-gate #include <sys/types.h>
2887c478bd9Sstevel@tonic-gate #include <unistd.h>
2897c478bd9Sstevel@tonic-gate #include <string.h>
2907c478bd9Sstevel@tonic-gate #include <stdlib.h>
2917c478bd9Sstevel@tonic-gate #include <ctype.h>
29280ab886dSwesolows #include <fcntl.h>
29380ab886dSwesolows #include <errno.h>
29480ab886dSwesolows #include <stdarg.h>
2957c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
2967c478bd9Sstevel@tonic-gate #include <sys/param.h>
2977c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
29880ab886dSwesolows #include <sys/wait.h>
29980ab886dSwesolows #include <sys/stat.h>
30080ab886dSwesolows 
30180ab886dSwesolows #define	CW_F_CXX	0x01
30280ab886dSwesolows #define	CW_F_SHADOW	0x02
30380ab886dSwesolows #define	CW_F_EXEC	0x04
30480ab886dSwesolows #define	CW_F_ECHO	0x08
30580ab886dSwesolows #define	CW_F_XLATE	0x10
3061912d2c4Swesolows #define	CW_F_PROG	0x20
30780ab886dSwesolows 
30880ab886dSwesolows typedef enum cw_compiler {
30980ab886dSwesolows 	CW_C_CC = 0,
31080ab886dSwesolows 	CW_C_GCC
31180ab886dSwesolows } cw_compiler_t;
31280ab886dSwesolows 
31380ab886dSwesolows static const char *cmds[] = {
31480ab886dSwesolows 	"cc", "CC",
31580ab886dSwesolows 	"gcc", "g++"
31680ab886dSwesolows };
3177c478bd9Sstevel@tonic-gate 
31880ab886dSwesolows static const char *dirs[] = {
31980ab886dSwesolows 	DEFAULT_CC_DIR, DEFAULT_CPLUSPLUS_DIR,
32080ab886dSwesolows 	DEFAULT_GCC_DIR, DEFAULT_GPLUSPLUS_DIR
32180ab886dSwesolows };
3227c478bd9Sstevel@tonic-gate 
32380ab886dSwesolows #define	CC(ctx) \
32480ab886dSwesolows 	(((ctx)->i_flags & CW_F_SHADOW) ? \
32580ab886dSwesolows 	    ((ctx)->i_compiler == CW_C_CC ? CW_C_GCC : CW_C_CC) : \
32680ab886dSwesolows 	    (ctx)->i_compiler)
3277c478bd9Sstevel@tonic-gate 
32880ab886dSwesolows #define	CIDX(compiler, flags)	\
32980ab886dSwesolows 	((int)(compiler) << 1) + ((flags) & CW_F_CXX ? 1 : 0)
33080ab886dSwesolows 
33180ab886dSwesolows typedef enum cw_op {
33280ab886dSwesolows 	CW_O_NONE = 0,
33380ab886dSwesolows 	CW_O_PREPROCESS,
33480ab886dSwesolows 	CW_O_COMPILE,
33580ab886dSwesolows 	CW_O_LINK
33680ab886dSwesolows } cw_op_t;
33780ab886dSwesolows 
33880ab886dSwesolows struct aelist {
33980ab886dSwesolows 	struct ae {
34080ab886dSwesolows 		struct ae *ae_next;
34180ab886dSwesolows 		char *ae_arg;
34280ab886dSwesolows 	} *ael_head, *ael_tail;
34380ab886dSwesolows 	int ael_argc;
34480ab886dSwesolows };
34580ab886dSwesolows 
34680ab886dSwesolows typedef struct cw_ictx {
34780ab886dSwesolows 	cw_compiler_t	i_compiler;
34880ab886dSwesolows 	struct aelist	*i_ae;
34980ab886dSwesolows 	uint32_t	i_flags;
35080ab886dSwesolows 	int		i_oldargc;
35180ab886dSwesolows 	char		**i_oldargv;
35280ab886dSwesolows 	pid_t		i_pid;
35380ab886dSwesolows 	char		i_discard[MAXPATHLEN];
3541912d2c4Swesolows 	char		*i_stderr;
35580ab886dSwesolows } cw_ictx_t;
35680ab886dSwesolows 
35780ab886dSwesolows static const char *progname;
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate static const char *xarch_tbl[] = {
3607c478bd9Sstevel@tonic-gate #if defined(__x86)
3617c478bd9Sstevel@tonic-gate 	"generic",	NULL,
3627c478bd9Sstevel@tonic-gate 	"generic64",	"-m64", "-mtune=opteron", NULL,
3637c478bd9Sstevel@tonic-gate 	"amd64",	"-m64", "-mtune=opteron", NULL,
3647c478bd9Sstevel@tonic-gate 	"386",		"-march=i386", NULL,
3657c478bd9Sstevel@tonic-gate 	"pentium_pro",	"-march=pentiumpro", NULL,
3667c478bd9Sstevel@tonic-gate #elif defined(__sparc)
3677c478bd9Sstevel@tonic-gate 	"generic",	"-m32", "-mcpu=v8", NULL,
3687c478bd9Sstevel@tonic-gate 	"generic64",	"-m64", "-mcpu=v9", NULL,
3697c478bd9Sstevel@tonic-gate 	"v8",		"-m32", "-mcpu=v8", "-mno-v8plus", NULL,
3707c478bd9Sstevel@tonic-gate 	"v8plus",	"-m32", "-mcpu=v9", "-mv8plus", NULL,
3717c478bd9Sstevel@tonic-gate 	"v8plusa",	"-m32", "-mcpu=ultrasparc", "-mv8plus", "-mvis", NULL,
3727c478bd9Sstevel@tonic-gate 	"v8plusb",	"-m32", "-mcpu=ultrasparc3", "-mv8plus", "-mvis", NULL,
3737c478bd9Sstevel@tonic-gate 	"v9",		"-m64", "-mcpu=v9", NULL,
3747c478bd9Sstevel@tonic-gate 	"v9a",		"-m64", "-mcpu=ultrasparc", "-mvis", NULL,
3757c478bd9Sstevel@tonic-gate 	"v9b",		"-m64", "-mcpu=ultrasparc3", "-mvis", NULL,
3767c478bd9Sstevel@tonic-gate #endif
3777c478bd9Sstevel@tonic-gate 	NULL,		NULL
3787c478bd9Sstevel@tonic-gate };
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate static const char *xchip_tbl[] = {
3817c478bd9Sstevel@tonic-gate #if defined(__x86)
3827c478bd9Sstevel@tonic-gate 	"386",		"-mtune=i386", NULL,
3837c478bd9Sstevel@tonic-gate 	"486",		"-mtune=i486", NULL,
3847c478bd9Sstevel@tonic-gate 	"pentium",	"-mtune=pentium", NULL,
3857c478bd9Sstevel@tonic-gate 	"pentium_pro",  "-mtune=pentiumpro", NULL,
3867c478bd9Sstevel@tonic-gate #elif defined(__sparc)
3877c478bd9Sstevel@tonic-gate 	"super",	"-mtune=supersparc", NULL,
3887c478bd9Sstevel@tonic-gate 	"ultra",	"-mtune=ultrasparc", NULL,
3897c478bd9Sstevel@tonic-gate 	"ultra3",	"-mtune=ultrasparc3", NULL,
3907c478bd9Sstevel@tonic-gate #endif
3917c478bd9Sstevel@tonic-gate 	NULL,		NULL
3927c478bd9Sstevel@tonic-gate };
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate static const char *xcode_tbl[] = {
3957c478bd9Sstevel@tonic-gate #if defined(__sparc)
3967c478bd9Sstevel@tonic-gate 	"abs32",	"-fno-pic", "-mcmodel=medlow", NULL,
3977c478bd9Sstevel@tonic-gate 	"abs44",	"-fno-pic", "-mcmodel=medmid", NULL,
3987c478bd9Sstevel@tonic-gate 	"abs64",	"-fno-pic", "-mcmodel=medany", NULL,
3997c478bd9Sstevel@tonic-gate 	"pic13",	"-fpic", NULL,
4007c478bd9Sstevel@tonic-gate 	"pic32",	"-fPIC", NULL,
4017c478bd9Sstevel@tonic-gate #endif
4027c478bd9Sstevel@tonic-gate 	NULL,		NULL
4037c478bd9Sstevel@tonic-gate };
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate static const char *xtarget_tbl[] = {
4067c478bd9Sstevel@tonic-gate #if defined(__x86)
4077c478bd9Sstevel@tonic-gate 	"pentium_pro",	"-march=pentiumpro", NULL,
4087c478bd9Sstevel@tonic-gate #endif	/* __x86 */
4097c478bd9Sstevel@tonic-gate 	NULL,		NULL
4107c478bd9Sstevel@tonic-gate };
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate static const char *xregs_tbl[] = {
4137c478bd9Sstevel@tonic-gate #if defined(__sparc)
4147c478bd9Sstevel@tonic-gate 	"appl",		"-mapp-regs", NULL,
4157c478bd9Sstevel@tonic-gate 	"no%appl",	"-mno-app-regs", NULL,
4167c478bd9Sstevel@tonic-gate 	"float",	"-mfpu", NULL,
4177c478bd9Sstevel@tonic-gate 	"no%float",	"-mno-fpu", NULL,
4187c478bd9Sstevel@tonic-gate #endif	/* __sparc */
4197c478bd9Sstevel@tonic-gate 	NULL,		NULL
4207c478bd9Sstevel@tonic-gate };
4217c478bd9Sstevel@tonic-gate 
42280ab886dSwesolows static void
42380ab886dSwesolows nomem(void)
42480ab886dSwesolows {
42580ab886dSwesolows 	(void) fprintf(stderr, "%s: error: out of memory\n", progname);
42680ab886dSwesolows 	exit(1);
42780ab886dSwesolows }
4287c478bd9Sstevel@tonic-gate 
42980ab886dSwesolows static void
43080ab886dSwesolows cw_perror(const char *fmt, ...)
4317c478bd9Sstevel@tonic-gate {
43280ab886dSwesolows 	va_list ap;
43380ab886dSwesolows 	int saved_errno = errno;
43480ab886dSwesolows 
43580ab886dSwesolows 	(void) fprintf(stderr, "%s: error: ", progname);
43680ab886dSwesolows 
43780ab886dSwesolows 	va_start(ap, fmt);
43880ab886dSwesolows 	(void) vfprintf(stderr, fmt, ap);
43980ab886dSwesolows 	va_end(ap);
44080ab886dSwesolows 
44180ab886dSwesolows 	(void) fprintf(stderr, " (%s)\n", strerror(saved_errno));
4427c478bd9Sstevel@tonic-gate }
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate static void
4457c478bd9Sstevel@tonic-gate newae(struct aelist *ael, const char *arg)
4467c478bd9Sstevel@tonic-gate {
4477c478bd9Sstevel@tonic-gate 	struct ae *ae;
4487c478bd9Sstevel@tonic-gate 
44980ab886dSwesolows 	if ((ae = calloc(sizeof (*ae), 1)) == NULL)
45080ab886dSwesolows 		nomem();
4517c478bd9Sstevel@tonic-gate 	ae->ae_arg = strdup(arg);
4527c478bd9Sstevel@tonic-gate 	if (ael->ael_tail == NULL)
4537c478bd9Sstevel@tonic-gate 		ael->ael_head = ae;
4547c478bd9Sstevel@tonic-gate 	else
4557c478bd9Sstevel@tonic-gate 		ael->ael_tail->ae_next = ae;
4567c478bd9Sstevel@tonic-gate 	ael->ael_tail = ae;
45780ab886dSwesolows 	ael->ael_argc++;
45880ab886dSwesolows }
45980ab886dSwesolows 
46080ab886dSwesolows static cw_ictx_t *
46180ab886dSwesolows newictx(void)
46280ab886dSwesolows {
46380ab886dSwesolows 	cw_ictx_t *ctx = calloc(sizeof (cw_ictx_t), 1);
46480ab886dSwesolows 	if (ctx)
46580ab886dSwesolows 		if ((ctx->i_ae = calloc(sizeof (struct aelist), 1)) == NULL) {
46680ab886dSwesolows 			free(ctx);
46780ab886dSwesolows 			return (NULL);
46880ab886dSwesolows 		}
46980ab886dSwesolows 
47080ab886dSwesolows 	return (ctx);
4717c478bd9Sstevel@tonic-gate }
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate static void
4747c478bd9Sstevel@tonic-gate error(const char *arg)
4757c478bd9Sstevel@tonic-gate {
4767c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
47780ab886dSwesolows 	    "%s: error: mapping failed at or near arg '%s'\n", progname, arg);
4787c478bd9Sstevel@tonic-gate 	exit(2);
4797c478bd9Sstevel@tonic-gate }
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate /*
4827c478bd9Sstevel@tonic-gate  * Add the current favourite set of warnings to the gcc invocation.
4837c478bd9Sstevel@tonic-gate  */
4847c478bd9Sstevel@tonic-gate static void
4857c478bd9Sstevel@tonic-gate warnings(struct aelist *h)
4867c478bd9Sstevel@tonic-gate {
4877c478bd9Sstevel@tonic-gate 	static int warningsonce;
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 	if (warningsonce++)
4907c478bd9Sstevel@tonic-gate 		return;
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate 	newae(h, "-Wall");
4937c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-unknown-pragmas");
4947c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-missing-braces");
4957c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-sign-compare");
4967c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-parentheses");
4977c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-uninitialized");
4987c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-implicit-function-declaration");
4997c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-unused");
5007c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-trigraphs");
5017c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-char-subscripts");
5027c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-switch");
5037c478bd9Sstevel@tonic-gate }
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate static void
5067c478bd9Sstevel@tonic-gate optim_disable(struct aelist *h, int level)
5077c478bd9Sstevel@tonic-gate {
5087c478bd9Sstevel@tonic-gate 	if (level >= 2) {
5097c478bd9Sstevel@tonic-gate 		newae(h, "-fno-strict-aliasing");
5107c478bd9Sstevel@tonic-gate 		newae(h, "-fno-unit-at-a-time");
5117c478bd9Sstevel@tonic-gate 		newae(h, "-fno-optimize-sibling-calls");
5127c478bd9Sstevel@tonic-gate 	}
5137c478bd9Sstevel@tonic-gate }
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate /* ARGSUSED */
5167c478bd9Sstevel@tonic-gate static void
5177c478bd9Sstevel@tonic-gate Xamode(struct aelist *h)
5187c478bd9Sstevel@tonic-gate {
5197c478bd9Sstevel@tonic-gate }
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate static void
5227c478bd9Sstevel@tonic-gate Xcmode(struct aelist *h)
5237c478bd9Sstevel@tonic-gate {
5247c478bd9Sstevel@tonic-gate 	static int xconce;
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	if (xconce++)
5277c478bd9Sstevel@tonic-gate 		return;
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 	newae(h, "-ansi");
5307c478bd9Sstevel@tonic-gate 	newae(h, "-pedantic-errors");
5317c478bd9Sstevel@tonic-gate }
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate static void
5347c478bd9Sstevel@tonic-gate Xsmode(struct aelist *h)
5357c478bd9Sstevel@tonic-gate {
5367c478bd9Sstevel@tonic-gate 	static int xsonce;
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate 	if (xsonce++)
5397c478bd9Sstevel@tonic-gate 		return;
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate 	newae(h, "-traditional");
5427c478bd9Sstevel@tonic-gate 	newae(h, "-traditional-cpp");
5437c478bd9Sstevel@tonic-gate }
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate static void
5467c478bd9Sstevel@tonic-gate usage()
5477c478bd9Sstevel@tonic-gate {
5487c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
5497c478bd9Sstevel@tonic-gate 	    "usage: %s { -_cc | -_gcc | -_CC | -_g++ } [ -_compiler | ... ]\n",
5507c478bd9Sstevel@tonic-gate 	    progname);
5517c478bd9Sstevel@tonic-gate 	exit(2);
5527c478bd9Sstevel@tonic-gate }
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate static void
5557c478bd9Sstevel@tonic-gate xlate(struct aelist *h, const char *xarg, const char **table)
5567c478bd9Sstevel@tonic-gate {
5577c478bd9Sstevel@tonic-gate 	while (*table != NULL && strcmp(xarg, *table) != 0) {
5587c478bd9Sstevel@tonic-gate 		while (*table != NULL)
5597c478bd9Sstevel@tonic-gate 			table++;
5607c478bd9Sstevel@tonic-gate 		table++;
5617c478bd9Sstevel@tonic-gate 	}
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate 	if (*table == NULL)
5647c478bd9Sstevel@tonic-gate 		error(xarg);
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate 	table++;
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 	while (*table != NULL) {
5697c478bd9Sstevel@tonic-gate 		newae(h, *table);
5707c478bd9Sstevel@tonic-gate 		table++;
5717c478bd9Sstevel@tonic-gate 	}
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate static void
57580ab886dSwesolows do_gcc(cw_ictx_t *ctx)
5767c478bd9Sstevel@tonic-gate {
5777c478bd9Sstevel@tonic-gate 	int c;
57880ab886dSwesolows 	int pic = 0, nolibc = 0;
57980ab886dSwesolows 	int in_output = 0, seen_o = 0, c_files = 0;
58080ab886dSwesolows 	cw_op_t op = CW_O_LINK;
5817c478bd9Sstevel@tonic-gate 	char *model = NULL;
5827c478bd9Sstevel@tonic-gate 
5831912d2c4Swesolows 	if (ctx->i_flags & CW_F_PROG) {
5841912d2c4Swesolows 		newae(ctx->i_ae, "--version");
5851912d2c4Swesolows 		return;
5861912d2c4Swesolows 	}
5871912d2c4Swesolows 
58880ab886dSwesolows 	newae(ctx->i_ae, "-fident");
58980ab886dSwesolows 	newae(ctx->i_ae, "-finline");
59080ab886dSwesolows 	newae(ctx->i_ae, "-fno-inline-functions");
59180ab886dSwesolows 	newae(ctx->i_ae, "-fno-builtin");
59280ab886dSwesolows 	newae(ctx->i_ae, "-fno-asm");
59380ab886dSwesolows 	newae(ctx->i_ae, "-nodefaultlibs");
5947c478bd9Sstevel@tonic-gate 
59502e56f3fSwesolows #if defined(__sparc)
59602e56f3fSwesolows 	/*
59702e56f3fSwesolows 	 * The SPARC ldd and std instructions require 8-byte alignment of
59802e56f3fSwesolows 	 * their address operand.  gcc correctly uses them only when the
59902e56f3fSwesolows 	 * ABI requires 8-byte alignment; unfortunately we have a number of
60002e56f3fSwesolows 	 * pieces of buggy code that doesn't conform to the ABI.  This
60102e56f3fSwesolows 	 * flag makes gcc work more like Studio with -xmemalign=4.
60202e56f3fSwesolows 	 */
60380ab886dSwesolows 	newae(ctx->i_ae, "-mno-integer-ldd-std");
60402e56f3fSwesolows #endif
60502e56f3fSwesolows 
6067c478bd9Sstevel@tonic-gate 	/*
6077c478bd9Sstevel@tonic-gate 	 * This is needed because 'u' is defined
6087c478bd9Sstevel@tonic-gate 	 * under a conditional on 'sun'.  Should
6097c478bd9Sstevel@tonic-gate 	 * probably just remove the conditional,
6107c478bd9Sstevel@tonic-gate 	 * or make it be dependent on '__sun'.
6117c478bd9Sstevel@tonic-gate 	 *
6127c478bd9Sstevel@tonic-gate 	 * -Dunix is also missing in enhanced ANSI mode
6137c478bd9Sstevel@tonic-gate 	 */
61480ab886dSwesolows 	newae(ctx->i_ae, "-D__sun");
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate 	/*
6177c478bd9Sstevel@tonic-gate 	 * Walk the argument list, translating as we go ..
6187c478bd9Sstevel@tonic-gate 	 */
6197c478bd9Sstevel@tonic-gate 
62080ab886dSwesolows 	while (--ctx->i_oldargc > 0) {
62180ab886dSwesolows 		char *arg = *++ctx->i_oldargv;
6227c478bd9Sstevel@tonic-gate 		size_t arglen = strlen(arg);
6237c478bd9Sstevel@tonic-gate 
62480ab886dSwesolows 		if (*arg == '-') {
6257c478bd9Sstevel@tonic-gate 			arglen--;
62680ab886dSwesolows 		} else {
6277c478bd9Sstevel@tonic-gate 			/*
6287c478bd9Sstevel@tonic-gate 			 * Discard inline files that gcc doesn't grok
6297c478bd9Sstevel@tonic-gate 			 */
63080ab886dSwesolows 			if (!in_output && arglen > 3 &&
6317c478bd9Sstevel@tonic-gate 			    strcmp(arg + arglen - 3, ".il") == 0)
6327c478bd9Sstevel@tonic-gate 				continue;
6337c478bd9Sstevel@tonic-gate 
63480ab886dSwesolows 			if (!in_output && arglen > 2 &&
63580ab886dSwesolows 			    arg[arglen - 2] == '.' &&
63680ab886dSwesolows 			    (arg[arglen - 1] == 'S' || arg[arglen - 1] == 's' ||
63780ab886dSwesolows 			    arg[arglen - 1] == 'c' || arg[arglen - 1] == 'i'))
63880ab886dSwesolows 				c_files++;
63980ab886dSwesolows 
6407c478bd9Sstevel@tonic-gate 			/*
64180ab886dSwesolows 			 * Otherwise, filenames and partial arguments
64280ab886dSwesolows 			 * are passed through for gcc to chew on.  However,
64380ab886dSwesolows 			 * output is always discarded for the secondary
64480ab886dSwesolows 			 * compiler.
6457c478bd9Sstevel@tonic-gate 			 */
64680ab886dSwesolows 			if ((ctx->i_flags & CW_F_SHADOW) && in_output)
64780ab886dSwesolows 				newae(ctx->i_ae, ctx->i_discard);
64880ab886dSwesolows 			else
64980ab886dSwesolows 				newae(ctx->i_ae, arg);
65080ab886dSwesolows 			in_output = 0;
6517c478bd9Sstevel@tonic-gate 			continue;
6527c478bd9Sstevel@tonic-gate 		}
6537c478bd9Sstevel@tonic-gate 
65480ab886dSwesolows 		if (ctx->i_flags & CW_F_CXX) {
6557c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-compat=", 8) == 0) {
6567c478bd9Sstevel@tonic-gate 				/* discard -compat=4 and -compat=5 */
6577c478bd9Sstevel@tonic-gate 				continue;
6587c478bd9Sstevel@tonic-gate 			}
6597c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Qoption") == 0) {
6607c478bd9Sstevel@tonic-gate 				/* discard -Qoption and its two arguments */
66180ab886dSwesolows 				if (ctx->i_oldargc < 3)
6627c478bd9Sstevel@tonic-gate 					error(arg);
66380ab886dSwesolows 				ctx->i_oldargc -= 2;
66480ab886dSwesolows 				ctx->i_oldargv += 2;
6657c478bd9Sstevel@tonic-gate 				continue;
6667c478bd9Sstevel@tonic-gate 			}
6677c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-xwe") == 0) {
6687c478bd9Sstevel@tonic-gate 				/* turn warnings into errors */
66980ab886dSwesolows 				newae(ctx->i_ae, "-Werror");
6707c478bd9Sstevel@tonic-gate 				continue;
6717c478bd9Sstevel@tonic-gate 			}
6727c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-noex") == 0) {
6737c478bd9Sstevel@tonic-gate 				/* no exceptions */
67480ab886dSwesolows 				newae(ctx->i_ae, "-fno-exceptions");
6757c478bd9Sstevel@tonic-gate 				/* no run time type descriptor information */
67680ab886dSwesolows 				newae(ctx->i_ae, "-fno-rtti");
6777c478bd9Sstevel@tonic-gate 				continue;
6787c478bd9Sstevel@tonic-gate 			}
6797c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-pic") == 0) {
68080ab886dSwesolows 				newae(ctx->i_ae, "-fpic");
6817c478bd9Sstevel@tonic-gate 				pic = 1;
6827c478bd9Sstevel@tonic-gate 				continue;
6837c478bd9Sstevel@tonic-gate 			}
6847c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-PIC") == 0) {
68580ab886dSwesolows 				newae(ctx->i_ae, "-fPIC");
6867c478bd9Sstevel@tonic-gate 				pic = 1;
6877c478bd9Sstevel@tonic-gate 				continue;
6887c478bd9Sstevel@tonic-gate 			}
6897c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-norunpath") == 0) {
6907c478bd9Sstevel@tonic-gate 				/* gcc has no corresponding option */
6917c478bd9Sstevel@tonic-gate 				continue;
6927c478bd9Sstevel@tonic-gate 			}
6937c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-nolib") == 0) {
6947c478bd9Sstevel@tonic-gate 				/* -nodefaultlibs is on by default */
6957c478bd9Sstevel@tonic-gate 				nolibc = 1;
6967c478bd9Sstevel@tonic-gate 				continue;
6977c478bd9Sstevel@tonic-gate 			}
6987c478bd9Sstevel@tonic-gate #if defined(__sparc)
6997c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-cg92") == 0) {
70080ab886dSwesolows 				xlate(ctx->i_ae, "v8", xarch_tbl);
70180ab886dSwesolows 				xlate(ctx->i_ae, "super", xchip_tbl);
7027c478bd9Sstevel@tonic-gate 				continue;
7037c478bd9Sstevel@tonic-gate 			}
7047c478bd9Sstevel@tonic-gate #endif	/* __sparc */
7057c478bd9Sstevel@tonic-gate 		}
7067c478bd9Sstevel@tonic-gate 
7077c478bd9Sstevel@tonic-gate 		switch ((c = arg[1])) {
7087c478bd9Sstevel@tonic-gate 		case '_':
7097c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-_noecho") == 0)
71080ab886dSwesolows 				ctx->i_flags &= ~CW_F_ECHO;
7117c478bd9Sstevel@tonic-gate 			else if (strncmp(arg, "-_cc=", 5) == 0 ||
7127c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-_CC=", 5) == 0)
7137c478bd9Sstevel@tonic-gate 				/* EMPTY */;
7147c478bd9Sstevel@tonic-gate 			else if (strncmp(arg, "-_gcc=", 6) == 0 ||
7157c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-_g++=", 6) == 0)
71680ab886dSwesolows 				newae(ctx->i_ae, arg + 6);
71780ab886dSwesolows 			else
7187c478bd9Sstevel@tonic-gate 				error(arg);
7197c478bd9Sstevel@tonic-gate 			break;
7207c478bd9Sstevel@tonic-gate 		case '#':
7217c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
72280ab886dSwesolows 				newae(ctx->i_ae, "-v");
7237c478bd9Sstevel@tonic-gate 				break;
7247c478bd9Sstevel@tonic-gate 			}
7257c478bd9Sstevel@tonic-gate 			error(arg);
7267c478bd9Sstevel@tonic-gate 			break;
7277c478bd9Sstevel@tonic-gate 		case 'g':
72880ab886dSwesolows 			newae(ctx->i_ae, "-gdwarf-2");
7297c478bd9Sstevel@tonic-gate 			break;
7307c478bd9Sstevel@tonic-gate 		case 'E':
7317c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
73280ab886dSwesolows 				newae(ctx->i_ae, "-xc");
73380ab886dSwesolows 				newae(ctx->i_ae, arg);
73480ab886dSwesolows 				op = CW_O_PREPROCESS;
7357c478bd9Sstevel@tonic-gate 				nolibc = 1;
7367c478bd9Sstevel@tonic-gate 				break;
7377c478bd9Sstevel@tonic-gate 			}
7387c478bd9Sstevel@tonic-gate 			error(arg);
7397c478bd9Sstevel@tonic-gate 			break;
7407c478bd9Sstevel@tonic-gate 		case 'c':
7417c478bd9Sstevel@tonic-gate 		case 'S':
74280ab886dSwesolows 			if (arglen == 1) {
74380ab886dSwesolows 				op = CW_O_COMPILE;
7447c478bd9Sstevel@tonic-gate 				nolibc = 1;
74580ab886dSwesolows 			}
7467c478bd9Sstevel@tonic-gate 			/* FALLTHROUGH */
7477c478bd9Sstevel@tonic-gate 		case 'C':
7487c478bd9Sstevel@tonic-gate 		case 'H':
7497c478bd9Sstevel@tonic-gate 		case 'p':
7507c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
75180ab886dSwesolows 				newae(ctx->i_ae, arg);
7527c478bd9Sstevel@tonic-gate 				break;
7537c478bd9Sstevel@tonic-gate 			}
7547c478bd9Sstevel@tonic-gate 			error(arg);
7557c478bd9Sstevel@tonic-gate 			break;
7567c478bd9Sstevel@tonic-gate 		case 'A':
7577c478bd9Sstevel@tonic-gate 		case 'h':
7587c478bd9Sstevel@tonic-gate 		case 'I':
7597c478bd9Sstevel@tonic-gate 		case 'i':
7607c478bd9Sstevel@tonic-gate 		case 'L':
7617c478bd9Sstevel@tonic-gate 		case 'l':
7627c478bd9Sstevel@tonic-gate 		case 'R':
7637c478bd9Sstevel@tonic-gate 		case 'U':
7647c478bd9Sstevel@tonic-gate 		case 'u':
7657c478bd9Sstevel@tonic-gate 		case 'w':
76680ab886dSwesolows 			newae(ctx->i_ae, arg);
76780ab886dSwesolows 			break;
76880ab886dSwesolows 		case 'o':
76980ab886dSwesolows 			seen_o = 1;
77080ab886dSwesolows 			if (arglen == 1) {
77180ab886dSwesolows 				in_output = 1;
77280ab886dSwesolows 				newae(ctx->i_ae, arg);
77380ab886dSwesolows 			} else if (ctx->i_flags & CW_F_SHADOW) {
77480ab886dSwesolows 				newae(ctx->i_ae, "-o");
77580ab886dSwesolows 				newae(ctx->i_ae, ctx->i_discard);
77680ab886dSwesolows 			} else {
77780ab886dSwesolows 				newae(ctx->i_ae, arg);
77880ab886dSwesolows 			}
7797c478bd9Sstevel@tonic-gate 			break;
7807c478bd9Sstevel@tonic-gate 		case 'D':
78180ab886dSwesolows 			newae(ctx->i_ae, arg);
7827c478bd9Sstevel@tonic-gate 			/*
7837c478bd9Sstevel@tonic-gate 			 * XXX	Clearly a hack ... do we need _KADB too?
7847c478bd9Sstevel@tonic-gate 			 */
7857c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-D_KERNEL") == 0 ||
7867c478bd9Sstevel@tonic-gate 			    strcmp(arg, "-D_BOOT") == 0)
78780ab886dSwesolows 				newae(ctx->i_ae, "-ffreestanding");
7887c478bd9Sstevel@tonic-gate 			break;
7897c478bd9Sstevel@tonic-gate 		case 'd':
7907c478bd9Sstevel@tonic-gate 			if (arglen == 2) {
7917c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-dy") == 0) {
79280ab886dSwesolows 					newae(ctx->i_ae, "-Wl,-dy");
7937c478bd9Sstevel@tonic-gate 					break;
7947c478bd9Sstevel@tonic-gate 				}
7957c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-dn") == 0) {
79680ab886dSwesolows 					newae(ctx->i_ae, "-Wl,-dn");
7977c478bd9Sstevel@tonic-gate 					break;
7987c478bd9Sstevel@tonic-gate 				}
7997c478bd9Sstevel@tonic-gate 			}
8007c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-dalign") == 0) {
8017c478bd9Sstevel@tonic-gate 				/*
8027c478bd9Sstevel@tonic-gate 				 * -dalign forces alignment in some cases;
8037c478bd9Sstevel@tonic-gate 				 * gcc does not need any flag to do this.
8047c478bd9Sstevel@tonic-gate 				 */
8057c478bd9Sstevel@tonic-gate 				break;
8067c478bd9Sstevel@tonic-gate 			}
8077c478bd9Sstevel@tonic-gate 			error(arg);
8087c478bd9Sstevel@tonic-gate 			break;
8097c478bd9Sstevel@tonic-gate 		case 'e':
8107c478bd9Sstevel@tonic-gate 			if (strcmp(arg,
8117c478bd9Sstevel@tonic-gate 			    "-erroff=E_EMPTY_TRANSLATION_UNIT") == 0) {
8127c478bd9Sstevel@tonic-gate 				/*
8137c478bd9Sstevel@tonic-gate 				 * Accept but ignore this -- gcc doesn't
8147c478bd9Sstevel@tonic-gate 				 * seem to complain about empty translation
8157c478bd9Sstevel@tonic-gate 				 * units
8167c478bd9Sstevel@tonic-gate 				 */
8177c478bd9Sstevel@tonic-gate 				break;
8187c478bd9Sstevel@tonic-gate 			}
8197c478bd9Sstevel@tonic-gate 			/* XX64 -- ignore all -erroff= options, for now */
8207c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-erroff=", 8) == 0)
8217c478bd9Sstevel@tonic-gate 				break;
8227c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-errtags=yes") == 0) {
82380ab886dSwesolows 				warnings(ctx->i_ae);
8247c478bd9Sstevel@tonic-gate 				break;
8257c478bd9Sstevel@tonic-gate 			}
8267c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-errwarn=%all") == 0) {
82780ab886dSwesolows 				newae(ctx->i_ae, "-Werror");
8287c478bd9Sstevel@tonic-gate 				break;
8297c478bd9Sstevel@tonic-gate 			}
8307c478bd9Sstevel@tonic-gate 			error(arg);
8317c478bd9Sstevel@tonic-gate 			break;
8327c478bd9Sstevel@tonic-gate 		case 'f':
8337c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-flags") == 0) {
83480ab886dSwesolows 				newae(ctx->i_ae, "--help");
8357c478bd9Sstevel@tonic-gate 				break;
8367c478bd9Sstevel@tonic-gate 			}
8377c478bd9Sstevel@tonic-gate 			error(arg);
8387c478bd9Sstevel@tonic-gate 			break;
8397c478bd9Sstevel@tonic-gate 		case 'G':
84080ab886dSwesolows 			newae(ctx->i_ae, "-shared");
8417c478bd9Sstevel@tonic-gate 			nolibc = 1;
8427c478bd9Sstevel@tonic-gate 			break;
8437c478bd9Sstevel@tonic-gate 		case 'k':
8447c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-keeptmp") == 0) {
84580ab886dSwesolows 				newae(ctx->i_ae, "-save-temps");
8467c478bd9Sstevel@tonic-gate 				break;
8477c478bd9Sstevel@tonic-gate 			}
8487c478bd9Sstevel@tonic-gate 			error(arg);
8497c478bd9Sstevel@tonic-gate 			break;
8507c478bd9Sstevel@tonic-gate 		case 'K':
8517c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
85280ab886dSwesolows 				if ((arg = *++ctx->i_oldargv) == NULL ||
85380ab886dSwesolows 				    *arg == '\0')
8547c478bd9Sstevel@tonic-gate 					error("-K");
85580ab886dSwesolows 				ctx->i_oldargc--;
8567c478bd9Sstevel@tonic-gate 			} else {
8577c478bd9Sstevel@tonic-gate 				arg += 2;
8587c478bd9Sstevel@tonic-gate 			}
8597c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "pic") == 0) {
86080ab886dSwesolows 				newae(ctx->i_ae, "-fpic");
8617c478bd9Sstevel@tonic-gate 				pic = 1;
8627c478bd9Sstevel@tonic-gate 				break;
8637c478bd9Sstevel@tonic-gate 			}
8647c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "PIC") == 0) {
86580ab886dSwesolows 				newae(ctx->i_ae, "-fPIC");
8667c478bd9Sstevel@tonic-gate 				pic = 1;
8677c478bd9Sstevel@tonic-gate 				break;
8687c478bd9Sstevel@tonic-gate 			}
8697c478bd9Sstevel@tonic-gate 			error("-K");
8707c478bd9Sstevel@tonic-gate 			break;
8717c478bd9Sstevel@tonic-gate 		case 'm':
8727c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-mt") == 0) {
87380ab886dSwesolows 				newae(ctx->i_ae, "-D_REENTRANT");
8747c478bd9Sstevel@tonic-gate 				break;
8757c478bd9Sstevel@tonic-gate 			}
8767c478bd9Sstevel@tonic-gate 			error(arg);
8777c478bd9Sstevel@tonic-gate 			break;
8787c478bd9Sstevel@tonic-gate 		case 'B':	/* linker options */
8797c478bd9Sstevel@tonic-gate 		case 'M':
8807c478bd9Sstevel@tonic-gate 		case 'z':
8817c478bd9Sstevel@tonic-gate 			{
8827c478bd9Sstevel@tonic-gate 				char *opt;
8837c478bd9Sstevel@tonic-gate 				size_t len;
8847c478bd9Sstevel@tonic-gate 				char *s;
8857c478bd9Sstevel@tonic-gate 
8867c478bd9Sstevel@tonic-gate 				if (arglen == 1) {
88780ab886dSwesolows 					opt = *++ctx->i_oldargv;
8887c478bd9Sstevel@tonic-gate 					if (opt == NULL || *opt == '\0')
8897c478bd9Sstevel@tonic-gate 						error(arg);
89080ab886dSwesolows 					ctx->i_oldargc--;
8917c478bd9Sstevel@tonic-gate 				} else {
8927c478bd9Sstevel@tonic-gate 					opt = arg + 2;
8937c478bd9Sstevel@tonic-gate 				}
8947c478bd9Sstevel@tonic-gate 				len = strlen(opt) + 7;
89580ab886dSwesolows 				if ((s = malloc(len)) == NULL)
89680ab886dSwesolows 					nomem();
8977c478bd9Sstevel@tonic-gate 				(void) snprintf(s, len, "-Wl,-%c%s", c, opt);
89880ab886dSwesolows 				newae(ctx->i_ae, s);
8997c478bd9Sstevel@tonic-gate 				free(s);
9007c478bd9Sstevel@tonic-gate 			}
9017c478bd9Sstevel@tonic-gate 			break;
9027c478bd9Sstevel@tonic-gate 		case 'n':
9037c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-noqueue") == 0) {
9047c478bd9Sstevel@tonic-gate 				/*
9057c478bd9Sstevel@tonic-gate 				 * Horrid license server stuff - n/a
9067c478bd9Sstevel@tonic-gate 				 */
9077c478bd9Sstevel@tonic-gate 				break;
9087c478bd9Sstevel@tonic-gate 			}
9097c478bd9Sstevel@tonic-gate 			error(arg);
9107c478bd9Sstevel@tonic-gate 			break;
9117c478bd9Sstevel@tonic-gate 		case 'O':
9127c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
91380ab886dSwesolows 				newae(ctx->i_ae, "-O");
9147c478bd9Sstevel@tonic-gate 				break;
9157c478bd9Sstevel@tonic-gate 			}
9167c478bd9Sstevel@tonic-gate 			error(arg);
9177c478bd9Sstevel@tonic-gate 			break;
9187c478bd9Sstevel@tonic-gate 		case 'P':
9197c478bd9Sstevel@tonic-gate 			/*
9207c478bd9Sstevel@tonic-gate 			 * We could do '-E -o filename.i', but that's hard,
9217c478bd9Sstevel@tonic-gate 			 * and we don't need it for the case that's triggering
9227c478bd9Sstevel@tonic-gate 			 * this addition.  We'll require the user to specify
9237c478bd9Sstevel@tonic-gate 			 * -o in the Makefile.  If they don't they'll find out
9247c478bd9Sstevel@tonic-gate 			 * in a hurry.
9257c478bd9Sstevel@tonic-gate 			 */
92680ab886dSwesolows 			newae(ctx->i_ae, "-E");
92780ab886dSwesolows 			op = CW_O_PREPROCESS;
9287c478bd9Sstevel@tonic-gate 			nolibc = 1;
9297c478bd9Sstevel@tonic-gate 			break;
9307c478bd9Sstevel@tonic-gate 		case 'q':
9317c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-qp") == 0) {
93280ab886dSwesolows 				newae(ctx->i_ae, "-p");
9337c478bd9Sstevel@tonic-gate 				break;
9347c478bd9Sstevel@tonic-gate 			}
9357c478bd9Sstevel@tonic-gate 			error(arg);
9367c478bd9Sstevel@tonic-gate 			break;
9377c478bd9Sstevel@tonic-gate 		case 's':
9387c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
93980ab886dSwesolows 				newae(ctx->i_ae, "-Wl,-s");
9407c478bd9Sstevel@tonic-gate 				break;
9417c478bd9Sstevel@tonic-gate 			}
9427c478bd9Sstevel@tonic-gate 			error(arg);
9437c478bd9Sstevel@tonic-gate 			break;
944159cf8a6Swesolows 		case 't':
945159cf8a6Swesolows 			if (arglen == 1) {
94680ab886dSwesolows 				newae(ctx->i_ae, "-Wl,-t");
947159cf8a6Swesolows 				break;
948159cf8a6Swesolows 			}
949159cf8a6Swesolows 			error(arg);
950159cf8a6Swesolows 			break;
9517c478bd9Sstevel@tonic-gate 		case 'V':
9527c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
95380ab886dSwesolows 				ctx->i_flags &= ~CW_F_ECHO;
95480ab886dSwesolows 				newae(ctx->i_ae, "--version");
9557c478bd9Sstevel@tonic-gate 				break;
9567c478bd9Sstevel@tonic-gate 			}
9577c478bd9Sstevel@tonic-gate 			error(arg);
9587c478bd9Sstevel@tonic-gate 			break;
9597c478bd9Sstevel@tonic-gate 		case 'v':
9607c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
96180ab886dSwesolows 				warnings(ctx->i_ae);
9627c478bd9Sstevel@tonic-gate 				break;
9637c478bd9Sstevel@tonic-gate 			}
9647c478bd9Sstevel@tonic-gate 			error(arg);
9657c478bd9Sstevel@tonic-gate 			break;
9667c478bd9Sstevel@tonic-gate 		case 'W':
9677c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wp,-xc99", 9) == 0) {
9687c478bd9Sstevel@tonic-gate 				/*
9697c478bd9Sstevel@tonic-gate 				 * gcc's preprocessor will accept c99
9707c478bd9Sstevel@tonic-gate 				 * regardless, so accept and ignore.
9717c478bd9Sstevel@tonic-gate 				 */
9727c478bd9Sstevel@tonic-gate 				break;
9737c478bd9Sstevel@tonic-gate 			}
9747c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wa,", 4) == 0 ||
9757c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-Wp,", 4) == 0 ||
9767c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-Wl,", 4) == 0) {
97780ab886dSwesolows 				newae(ctx->i_ae, arg);
9787c478bd9Sstevel@tonic-gate 				break;
9797c478bd9Sstevel@tonic-gate 			}
9807c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-xc99=pragma") == 0) {
9817c478bd9Sstevel@tonic-gate 				/* (undocumented) enables _Pragma */
9827c478bd9Sstevel@tonic-gate 				break;
9837c478bd9Sstevel@tonic-gate 			}
9847c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-xc99=%none") == 0) {
9857c478bd9Sstevel@tonic-gate 				/*
9867c478bd9Sstevel@tonic-gate 				 * This is a polite way of saying
9877c478bd9Sstevel@tonic-gate 				 * "no c99 constructs allowed!"
9887c478bd9Sstevel@tonic-gate 				 * For now, just accept and ignore this.
9897c478bd9Sstevel@tonic-gate 				 */
9907c478bd9Sstevel@tonic-gate 				break;
9917c478bd9Sstevel@tonic-gate 			}
9924afe1ab8Sesaxe 			if (strcmp(arg, "-W0,-noglobal") == 0 ||
9934afe1ab8Sesaxe 			    strcmp(arg, "-W0,-xglobalstatic") == 0) {
9947c478bd9Sstevel@tonic-gate 				/*
9957c478bd9Sstevel@tonic-gate 				 * gcc doesn't prefix local symbols
9967c478bd9Sstevel@tonic-gate 				 * in debug mode, so this is not needed.
9977c478bd9Sstevel@tonic-gate 				 */
9987c478bd9Sstevel@tonic-gate 				break;
9997c478bd9Sstevel@tonic-gate 			}
10007c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-Lt") == 0) {
10017c478bd9Sstevel@tonic-gate 				/*
10027c478bd9Sstevel@tonic-gate 				 * Generate tests at the top of loops.
10037c478bd9Sstevel@tonic-gate 				 * There is no direct gcc equivalent, ignore.
10047c478bd9Sstevel@tonic-gate 				 */
10057c478bd9Sstevel@tonic-gate 				break;
10067c478bd9Sstevel@tonic-gate 			}
10078c1a3716Ssherrym 			if (strcmp(arg, "-W0,-xdbggen=no%usedonly") == 0) {
100880ab886dSwesolows 				newae(ctx->i_ae,
100980ab886dSwesolows 				    "-fno-eliminate-unused-debug-symbols");
101080ab886dSwesolows 				newae(ctx->i_ae,
101180ab886dSwesolows 				    "-fno-eliminate-unused-debug-types");
10128c1a3716Ssherrym 				break;
10138c1a3716Ssherrym 			}
10149dd82889Spetede 			if (strcmp(arg, "-W2,-xwrap_int") == 0) {
10159dd82889Spetede 				/*
10169dd82889Spetede 				 * Use the legacy behaviour (pre-SS11)
10179dd82889Spetede 				 * for integer wrapping.
10189dd82889Spetede 				 * gcc does not need this.
10199dd82889Spetede 				 */
10209dd82889Spetede 				break;
10219dd82889Spetede 			}
10227c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W2,-Rcond_elim") == 0) {
10237c478bd9Sstevel@tonic-gate 				/*
10247c478bd9Sstevel@tonic-gate 				 * Elimination and expansion of conditionals;
10257c478bd9Sstevel@tonic-gate 				 * gcc has no direct equivalent.
10267c478bd9Sstevel@tonic-gate 				 */
10277c478bd9Sstevel@tonic-gate 				break;
10287c478bd9Sstevel@tonic-gate 			}
10297c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Wd,-xsafe=unboundsym") == 0) {
10307c478bd9Sstevel@tonic-gate 				/*
10317c478bd9Sstevel@tonic-gate 				 * Prevents optimizing away checks for
10327c478bd9Sstevel@tonic-gate 				 * unbound weak symbol addresses.  gcc does
10337c478bd9Sstevel@tonic-gate 				 * not do this, so it's not needed.
10347c478bd9Sstevel@tonic-gate 				 */
10357c478bd9Sstevel@tonic-gate 				break;
10367c478bd9Sstevel@tonic-gate 			}
10377c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wc,-xcode=", 11) == 0) {
103880ab886dSwesolows 				xlate(ctx->i_ae, arg + 11, xcode_tbl);
10397c478bd9Sstevel@tonic-gate 				if (strncmp(arg + 11, "pic", 3) == 0)
10407c478bd9Sstevel@tonic-gate 					pic = 1;
10417c478bd9Sstevel@tonic-gate 				break;
10427c478bd9Sstevel@tonic-gate 			}
10437c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wc,-Qiselect", 13) == 0) {
10447c478bd9Sstevel@tonic-gate 				/*
10457c478bd9Sstevel@tonic-gate 				 * Prevents insertion of register symbols.
10467c478bd9Sstevel@tonic-gate 				 * gcc doesn't do this, so ignore it.
10477c478bd9Sstevel@tonic-gate 				 */
10487c478bd9Sstevel@tonic-gate 				break;
10497c478bd9Sstevel@tonic-gate 			}
10509dd82889Spetede 			if (strcmp(arg, "-Wc,-Qassembler-ounrefsym=0") == 0) {
10519dd82889Spetede 				/*
10529dd82889Spetede 				 * Prevents optimizing away of static variables.
10539dd82889Spetede 				 * gcc does not do this, so it's not needed.
10549dd82889Spetede 				 */
10559dd82889Spetede 				break;
10569dd82889Spetede 			}
10577c478bd9Sstevel@tonic-gate #if defined(__x86)
10587c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Wu,-no_got_reloc") == 0) {
105980ab886dSwesolows 				newae(ctx->i_ae, "-fno-jump-tables");
106080ab886dSwesolows 				newae(ctx->i_ae, "-fno-constant-pools");
10617c478bd9Sstevel@tonic-gate 				break;
10627c478bd9Sstevel@tonic-gate 			}
10637c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Wu,-xmodel=kernel") == 0) {
106480ab886dSwesolows 				newae(ctx->i_ae, "-ffreestanding");
106580ab886dSwesolows 				newae(ctx->i_ae, "-mno-red-zone");
10667c478bd9Sstevel@tonic-gate 				model = "-mcmodel=kernel";
10677c478bd9Sstevel@tonic-gate 				nolibc = 1;
10687c478bd9Sstevel@tonic-gate 				break;
10697c478bd9Sstevel@tonic-gate 			}
1070d430274bSsherrym 			if (strcmp(arg, "-Wu,-save_args") == 0) {
107180ab886dSwesolows 				newae(ctx->i_ae, "-msave-args");
1072d430274bSsherrym 				break;
1073d430274bSsherrym 			}
10747c478bd9Sstevel@tonic-gate #endif	/* __x86 */
10757c478bd9Sstevel@tonic-gate 			error(arg);
10767c478bd9Sstevel@tonic-gate 			break;
10777c478bd9Sstevel@tonic-gate 		case 'X':
10787c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Xa") == 0 ||
10797c478bd9Sstevel@tonic-gate 			    strcmp(arg, "-Xt") == 0) {
108080ab886dSwesolows 				Xamode(ctx->i_ae);
10817c478bd9Sstevel@tonic-gate 				break;
10827c478bd9Sstevel@tonic-gate 			}
10837c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Xc") == 0) {
108480ab886dSwesolows 				Xcmode(ctx->i_ae);
10857c478bd9Sstevel@tonic-gate 				break;
10867c478bd9Sstevel@tonic-gate 			}
10877c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Xs") == 0) {
108880ab886dSwesolows 				Xsmode(ctx->i_ae);
10897c478bd9Sstevel@tonic-gate 				break;
10907c478bd9Sstevel@tonic-gate 			}
10917c478bd9Sstevel@tonic-gate 			error(arg);
10927c478bd9Sstevel@tonic-gate 			break;
10937c478bd9Sstevel@tonic-gate 		case 'x':
10947c478bd9Sstevel@tonic-gate 			if (arglen == 1)
10957c478bd9Sstevel@tonic-gate 				error(arg);
10967c478bd9Sstevel@tonic-gate 			switch (arg[2]) {
10977c478bd9Sstevel@tonic-gate #if defined(__x86)
10987c478bd9Sstevel@tonic-gate 			case '3':
10997c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-x386") == 0) {
110080ab886dSwesolows 					newae(ctx->i_ae, "-march=i386");
11017c478bd9Sstevel@tonic-gate 					break;
11027c478bd9Sstevel@tonic-gate 				}
11037c478bd9Sstevel@tonic-gate 				error(arg);
11047c478bd9Sstevel@tonic-gate 				break;
11057c478bd9Sstevel@tonic-gate 			case '4':
11067c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-x486") == 0) {
110780ab886dSwesolows 					newae(ctx->i_ae, "-march=i486");
11087c478bd9Sstevel@tonic-gate 					break;
11097c478bd9Sstevel@tonic-gate 				}
11107c478bd9Sstevel@tonic-gate 				error(arg);
11117c478bd9Sstevel@tonic-gate 				break;
11127c478bd9Sstevel@tonic-gate #endif	/* __x86 */
11137c478bd9Sstevel@tonic-gate 			case 'a':
11147c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xarch=", 7) == 0) {
111580ab886dSwesolows 					xlate(ctx->i_ae, arg + 7, xarch_tbl);
11167c478bd9Sstevel@tonic-gate 					break;
11177c478bd9Sstevel@tonic-gate 				}
11187c478bd9Sstevel@tonic-gate 				error(arg);
11197c478bd9Sstevel@tonic-gate 				break;
112002e56f3fSwesolows 			case 'b':
112102e56f3fSwesolows 				if (strncmp(arg, "-xbuiltin=", 10) == 0) {
112202e56f3fSwesolows 					if (strcmp(arg + 10, "%all"))
112380ab886dSwesolows 						newae(ctx->i_ae, "-fbuiltin");
112402e56f3fSwesolows 					break;
112502e56f3fSwesolows 				}
112602e56f3fSwesolows 				error(arg);
112702e56f3fSwesolows 				break;
11287c478bd9Sstevel@tonic-gate 			case 'C':
11297c478bd9Sstevel@tonic-gate 				/* Accept C++ style comments -- ignore */
11307c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xCC") == 0)
11317c478bd9Sstevel@tonic-gate 					break;
11327c478bd9Sstevel@tonic-gate 				error(arg);
11337c478bd9Sstevel@tonic-gate 				break;
11347c478bd9Sstevel@tonic-gate 			case 'c':
11357c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xc99=%all", 10) == 0) {
113680ab886dSwesolows 					newae(ctx->i_ae, "-std=gnu99");
11377c478bd9Sstevel@tonic-gate 					break;
11387c478bd9Sstevel@tonic-gate 				}
11397c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xc99=%none", 11) == 0) {
114080ab886dSwesolows 					newae(ctx->i_ae, "-std=gnu89");
11417c478bd9Sstevel@tonic-gate 					break;
11427c478bd9Sstevel@tonic-gate 				}
11437c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xchip=", 7) == 0) {
114480ab886dSwesolows 					xlate(ctx->i_ae, arg + 7, xchip_tbl);
11457c478bd9Sstevel@tonic-gate 					break;
11467c478bd9Sstevel@tonic-gate 				}
11477c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xcode=", 7) == 0) {
114880ab886dSwesolows 					xlate(ctx->i_ae, arg + 7, xcode_tbl);
11497c478bd9Sstevel@tonic-gate 					if (strncmp(arg + 7, "pic", 3) == 0)
11507c478bd9Sstevel@tonic-gate 						pic = 1;
11517c478bd9Sstevel@tonic-gate 					break;
11527c478bd9Sstevel@tonic-gate 				}
11537c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xcache=", 8) == 0)
11547c478bd9Sstevel@tonic-gate 					break;
1155159cf8a6Swesolows 				if (strncmp(arg, "-xcrossfile", 11) == 0)
1156159cf8a6Swesolows 					break;
11577c478bd9Sstevel@tonic-gate 				error(arg);
11587c478bd9Sstevel@tonic-gate 				break;
11597c478bd9Sstevel@tonic-gate 			case 'd':
11607c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xdepend") == 0)
11617c478bd9Sstevel@tonic-gate 					break;
11628c1a3716Ssherrym 				if (strncmp(arg, "-xdebugformat=", 14) == 0)
11638c1a3716Ssherrym 					break;
11647c478bd9Sstevel@tonic-gate 				error(arg);
11657c478bd9Sstevel@tonic-gate 				break;
11667c478bd9Sstevel@tonic-gate 			case 'F':
11677c478bd9Sstevel@tonic-gate 				/* compile for mapfile reordering -- ignore */
11687c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xF") == 0)
11697c478bd9Sstevel@tonic-gate 					break;
11707c478bd9Sstevel@tonic-gate 				error(arg);
11717c478bd9Sstevel@tonic-gate 				break;
11727c478bd9Sstevel@tonic-gate 			case 'i':
11737c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xinline", 8) == 0)
11747c478bd9Sstevel@tonic-gate 					/* No inlining; ignore */
11757c478bd9Sstevel@tonic-gate 					break;
11767c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xildon") == 0 ||
11777c478bd9Sstevel@tonic-gate 				    strcmp(arg, "-xildoff") == 0)
11787c478bd9Sstevel@tonic-gate 					/* No incremental linking; ignore */
11797c478bd9Sstevel@tonic-gate 					break;
11807c478bd9Sstevel@tonic-gate 				error(arg);
11817c478bd9Sstevel@tonic-gate 				break;
1182*54836668Spetede #if defined(__x86)
1183*54836668Spetede 			case 'm':
1184*54836668Spetede 				if (strcmp(arg, "-xmodel=kernel") == 0) {
1185*54836668Spetede 					newae(ctx->i_ae, "-ffreestanding");
1186*54836668Spetede 					newae(ctx->i_ae, "-mno-red-zone");
1187*54836668Spetede 					model = "-mcmodel=kernel";
1188*54836668Spetede 					nolibc = 1;
1189*54836668Spetede 					break;
1190*54836668Spetede 				}
1191*54836668Spetede 				error(arg);
1192*54836668Spetede 				break;
1193*54836668Spetede #endif	/* __x86 */
11947c478bd9Sstevel@tonic-gate 			case 'M':
11957c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xM") == 0) {
119680ab886dSwesolows 					newae(ctx->i_ae, "-M");
11977c478bd9Sstevel@tonic-gate 					break;
11987c478bd9Sstevel@tonic-gate 				}
11997c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xM1") == 0) {
120080ab886dSwesolows 					newae(ctx->i_ae, "-MM");
12017c478bd9Sstevel@tonic-gate 					break;
12027c478bd9Sstevel@tonic-gate 				}
12037c478bd9Sstevel@tonic-gate 				error(arg);
12047c478bd9Sstevel@tonic-gate 				break;
12057c478bd9Sstevel@tonic-gate 			case 'n':
12067c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xnolib") == 0) {
12077c478bd9Sstevel@tonic-gate 					nolibc = 1;
12087c478bd9Sstevel@tonic-gate 					break;
12097c478bd9Sstevel@tonic-gate 				}
12107c478bd9Sstevel@tonic-gate 				error(arg);
12117c478bd9Sstevel@tonic-gate 				break;
12127c478bd9Sstevel@tonic-gate 			case 'O':
12137c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xO", 3) == 0) {
12147c478bd9Sstevel@tonic-gate 					size_t len = strlen(arg);
121580ab886dSwesolows 					char *s;
12167c478bd9Sstevel@tonic-gate 					int c = *(arg + 3);
12177c478bd9Sstevel@tonic-gate 					int level;
12187c478bd9Sstevel@tonic-gate 
12197c478bd9Sstevel@tonic-gate 					if (len != 4 || !isdigit(c))
12207c478bd9Sstevel@tonic-gate 						error(arg);
12217c478bd9Sstevel@tonic-gate 
122280ab886dSwesolows 					if ((s = malloc(len)) == NULL)
122380ab886dSwesolows 						nomem();
122480ab886dSwesolows 
12257c478bd9Sstevel@tonic-gate 					level = atoi(arg + 3);
12267c478bd9Sstevel@tonic-gate 					if (level > 5)
12277c478bd9Sstevel@tonic-gate 						error(arg);
12287c478bd9Sstevel@tonic-gate 					if (level >= 2) {
12297c478bd9Sstevel@tonic-gate 						/*
12307c478bd9Sstevel@tonic-gate 						 * For gcc-3.4.x at -O2 we
12317c478bd9Sstevel@tonic-gate 						 * need to disable optimizations
12327c478bd9Sstevel@tonic-gate 						 * that break ON.
12337c478bd9Sstevel@tonic-gate 						 */
123480ab886dSwesolows 						optim_disable(ctx->i_ae, level);
12357c478bd9Sstevel@tonic-gate 						/*
12367c478bd9Sstevel@tonic-gate 						 * limit -xO3 to -O2 as well.
12377c478bd9Sstevel@tonic-gate 						 */
12387c478bd9Sstevel@tonic-gate 						level = 2;
12397c478bd9Sstevel@tonic-gate 					}
12407c478bd9Sstevel@tonic-gate 					(void) snprintf(s, len, "-O%d", level);
124180ab886dSwesolows 					newae(ctx->i_ae, s);
12427c478bd9Sstevel@tonic-gate 					free(s);
12437c478bd9Sstevel@tonic-gate 					break;
12447c478bd9Sstevel@tonic-gate 				}
12457c478bd9Sstevel@tonic-gate 				error(arg);
12467c478bd9Sstevel@tonic-gate 				break;
12477c478bd9Sstevel@tonic-gate 			case 'p':
12487c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xpentium") == 0) {
124980ab886dSwesolows 					newae(ctx->i_ae, "-march=pentium");
12507c478bd9Sstevel@tonic-gate 					break;
12517c478bd9Sstevel@tonic-gate 				}
12527c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xpg") == 0) {
125380ab886dSwesolows 					newae(ctx->i_ae, "-pg");
12547c478bd9Sstevel@tonic-gate 					break;
12557c478bd9Sstevel@tonic-gate 				}
12567c478bd9Sstevel@tonic-gate 				error(arg);
12577c478bd9Sstevel@tonic-gate 				break;
12587c478bd9Sstevel@tonic-gate 			case 'r':
12597c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xregs=", 7) == 0) {
126080ab886dSwesolows 					xlate(ctx->i_ae, arg + 7, xregs_tbl);
12617c478bd9Sstevel@tonic-gate 					break;
12627c478bd9Sstevel@tonic-gate 				}
12637c478bd9Sstevel@tonic-gate 				error(arg);
12647c478bd9Sstevel@tonic-gate 				break;
12657c478bd9Sstevel@tonic-gate 			case 's':
12667c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xs") == 0 ||
12677c478bd9Sstevel@tonic-gate 				    strcmp(arg, "-xspace") == 0 ||
12687c478bd9Sstevel@tonic-gate 				    strcmp(arg, "-xstrconst") == 0)
12697c478bd9Sstevel@tonic-gate 					break;
12707c478bd9Sstevel@tonic-gate 				error(arg);
12717c478bd9Sstevel@tonic-gate 				break;
12727c478bd9Sstevel@tonic-gate 			case 't':
12737c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xtransition") == 0) {
127480ab886dSwesolows 					newae(ctx->i_ae, "-Wtransition");
12757c478bd9Sstevel@tonic-gate 					break;
12767c478bd9Sstevel@tonic-gate 				}
12777c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xtrigraphs=yes") == 0) {
127880ab886dSwesolows 					newae(ctx->i_ae, "-trigraphs");
12797c478bd9Sstevel@tonic-gate 					break;
12807c478bd9Sstevel@tonic-gate 				}
12817c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xtrigraphs=no") == 0) {
128280ab886dSwesolows 					newae(ctx->i_ae, "-notrigraphs");
12837c478bd9Sstevel@tonic-gate 					break;
12847c478bd9Sstevel@tonic-gate 				}
12857c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xtarget=", 9) == 0) {
128680ab886dSwesolows 					xlate(ctx->i_ae, arg + 9, xtarget_tbl);
12877c478bd9Sstevel@tonic-gate 					break;
12887c478bd9Sstevel@tonic-gate 				}
12897c478bd9Sstevel@tonic-gate 				error(arg);
12907c478bd9Sstevel@tonic-gate 				break;
12917c478bd9Sstevel@tonic-gate 			case 'e':
12927c478bd9Sstevel@tonic-gate 			case 'h':
12937c478bd9Sstevel@tonic-gate 			case 'l':
12947c478bd9Sstevel@tonic-gate 			default:
12957c478bd9Sstevel@tonic-gate 				error(arg);
12967c478bd9Sstevel@tonic-gate 				break;
12977c478bd9Sstevel@tonic-gate 			}
12987c478bd9Sstevel@tonic-gate 			break;
12997c478bd9Sstevel@tonic-gate 		case 'Y':
13007c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
130180ab886dSwesolows 				if ((arg = *++ctx->i_oldargv) == NULL ||
130280ab886dSwesolows 				    *arg == '\0')
13037c478bd9Sstevel@tonic-gate 					error("-Y");
130480ab886dSwesolows 				ctx->i_oldargc--;
13057c478bd9Sstevel@tonic-gate 				arglen = strlen(arg + 1);
13067c478bd9Sstevel@tonic-gate 			} else {
13077c478bd9Sstevel@tonic-gate 				arg += 2;
13087c478bd9Sstevel@tonic-gate 			}
13097c478bd9Sstevel@tonic-gate 			/* Just ignore -YS,... for now */
13107c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "S,", 2) == 0)
13117c478bd9Sstevel@tonic-gate 				break;
13127c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "l,", 2) == 0) {
13137c478bd9Sstevel@tonic-gate 				char *s = strdup(arg);
13147c478bd9Sstevel@tonic-gate 				s[0] = '-';
13157c478bd9Sstevel@tonic-gate 				s[1] = 'B';
131680ab886dSwesolows 				newae(ctx->i_ae, s);
13177c478bd9Sstevel@tonic-gate 				free(s);
13187c478bd9Sstevel@tonic-gate 				break;
13197c478bd9Sstevel@tonic-gate 			}
13207c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "I,", 2) == 0) {
13217c478bd9Sstevel@tonic-gate 				char *s = strdup(arg);
13227c478bd9Sstevel@tonic-gate 				s[0] = '-';
13237c478bd9Sstevel@tonic-gate 				s[1] = 'I';
132480ab886dSwesolows 				newae(ctx->i_ae, "-nostdinc");
132580ab886dSwesolows 				newae(ctx->i_ae, s);
13267c478bd9Sstevel@tonic-gate 				free(s);
13277c478bd9Sstevel@tonic-gate 				break;
13287c478bd9Sstevel@tonic-gate 			}
13297c478bd9Sstevel@tonic-gate 			error(arg);
13307c478bd9Sstevel@tonic-gate 			break;
13317c478bd9Sstevel@tonic-gate 		case 'Q':
13327c478bd9Sstevel@tonic-gate 			/*
13337c478bd9Sstevel@tonic-gate 			 * We could map -Qy into -Wl,-Qy etc.
13347c478bd9Sstevel@tonic-gate 			 */
13357c478bd9Sstevel@tonic-gate 		default:
13367c478bd9Sstevel@tonic-gate 			error(arg);
13377c478bd9Sstevel@tonic-gate 			break;
13387c478bd9Sstevel@tonic-gate 		}
13397c478bd9Sstevel@tonic-gate 	}
13407c478bd9Sstevel@tonic-gate 
134180ab886dSwesolows 	if (c_files > 1 && (ctx->i_flags & CW_F_SHADOW) &&
134280ab886dSwesolows 	    op != CW_O_PREPROCESS) {
134380ab886dSwesolows 		(void) fprintf(stderr, "%s: error: multiple source files are "
134480ab886dSwesolows 		    "allowed only with -E or -P\n", progname);
134580ab886dSwesolows 		exit(2);
134680ab886dSwesolows 	}
134780ab886dSwesolows 	if (op == CW_O_LINK && (ctx->i_flags & CW_F_SHADOW))
134880ab886dSwesolows 		exit(0);
134980ab886dSwesolows 
13507c478bd9Sstevel@tonic-gate 	if (model && !pic)
135180ab886dSwesolows 		newae(ctx->i_ae, model);
13527c478bd9Sstevel@tonic-gate 	if (!nolibc)
135380ab886dSwesolows 		newae(ctx->i_ae, "-lc");
135480ab886dSwesolows 	if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) {
135580ab886dSwesolows 		newae(ctx->i_ae, "-o");
135680ab886dSwesolows 		newae(ctx->i_ae, ctx->i_discard);
135780ab886dSwesolows 	}
135880ab886dSwesolows }
135980ab886dSwesolows 
136080ab886dSwesolows static void
136180ab886dSwesolows do_cc(cw_ictx_t *ctx)
136280ab886dSwesolows {
136380ab886dSwesolows 	int in_output = 0, seen_o = 0;
136480ab886dSwesolows 	cw_op_t op = CW_O_LINK;
136580ab886dSwesolows 
13661912d2c4Swesolows 	if (ctx->i_flags & CW_F_PROG) {
13671912d2c4Swesolows 		newae(ctx->i_ae, "-V");
13681912d2c4Swesolows 		return;
13691912d2c4Swesolows 	}
13701912d2c4Swesolows 
137180ab886dSwesolows 	while (--ctx->i_oldargc > 0) {
137280ab886dSwesolows 		char *arg = *++ctx->i_oldargv;
137380ab886dSwesolows 
137480ab886dSwesolows 		if (*arg != '-') {
137580ab886dSwesolows 			if (in_output == 0 || !(ctx->i_flags & CW_F_SHADOW)) {
137680ab886dSwesolows 				newae(ctx->i_ae, arg);
137780ab886dSwesolows 			} else {
137880ab886dSwesolows 				in_output = 0;
137980ab886dSwesolows 				newae(ctx->i_ae, ctx->i_discard);
138080ab886dSwesolows 			}
138180ab886dSwesolows 			continue;
138280ab886dSwesolows 		}
138380ab886dSwesolows 		switch (*(arg + 1)) {
138480ab886dSwesolows 		case '_':
138580ab886dSwesolows 			if (strcmp(arg, "-_noecho") == 0) {
138680ab886dSwesolows 				ctx->i_flags &= ~CW_F_ECHO;
138780ab886dSwesolows 			} else if (strncmp(arg, "-_cc=", 5) == 0 ||
138880ab886dSwesolows 			    strncmp(arg, "-_CC=", 5) == 0) {
138980ab886dSwesolows 				newae(ctx->i_ae, arg + 5);
139080ab886dSwesolows 			} else if (strncmp(arg, "-_gcc=", 6) != 0 &&
139180ab886dSwesolows 			    strncmp(arg, "-_g++=", 6) != 0) {
139280ab886dSwesolows 				(void) fprintf(stderr,
139380ab886dSwesolows 				    "%s: invalid argument '%s'\n", progname,
139480ab886dSwesolows 				    arg);
139580ab886dSwesolows 				exit(2);
139680ab886dSwesolows 			}
139780ab886dSwesolows 			break;
139880ab886dSwesolows 		case 'V':
139980ab886dSwesolows 			ctx->i_flags &= ~CW_F_ECHO;
140080ab886dSwesolows 			newae(ctx->i_ae, arg);
140180ab886dSwesolows 			break;
140280ab886dSwesolows 		case 'o':
140380ab886dSwesolows 			seen_o = 1;
140480ab886dSwesolows 			if (strlen(arg) == 2) {
140580ab886dSwesolows 				in_output = 1;
140680ab886dSwesolows 				newae(ctx->i_ae, arg);
140780ab886dSwesolows 			} else if (ctx->i_flags & CW_F_SHADOW) {
140880ab886dSwesolows 				newae(ctx->i_ae, "-o");
140980ab886dSwesolows 				newae(ctx->i_ae, ctx->i_discard);
141080ab886dSwesolows 			} else {
141180ab886dSwesolows 				newae(ctx->i_ae, arg);
141280ab886dSwesolows 			}
141380ab886dSwesolows 			break;
141480ab886dSwesolows 		case 'c':
141580ab886dSwesolows 		case 'S':
141680ab886dSwesolows 			op = CW_O_COMPILE;
141780ab886dSwesolows 			newae(ctx->i_ae, arg);
141880ab886dSwesolows 			break;
141980ab886dSwesolows 		case 'E':
142080ab886dSwesolows 		case 'P':
142180ab886dSwesolows 			op = CW_O_PREPROCESS;
142280ab886dSwesolows 		/*FALLTHROUGH*/
142380ab886dSwesolows 		default:
142480ab886dSwesolows 			newae(ctx->i_ae, arg);
142580ab886dSwesolows 		}
142680ab886dSwesolows 	}
142780ab886dSwesolows 
142880ab886dSwesolows 	if ((op == CW_O_LINK || op == CW_O_PREPROCESS) &&
142980ab886dSwesolows 	    (ctx->i_flags & CW_F_SHADOW))
143080ab886dSwesolows 		exit(0);
143180ab886dSwesolows 
143280ab886dSwesolows 	if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) {
143380ab886dSwesolows 		newae(ctx->i_ae, "-o");
143480ab886dSwesolows 		newae(ctx->i_ae, ctx->i_discard);
143580ab886dSwesolows 	}
14367c478bd9Sstevel@tonic-gate }
14377c478bd9Sstevel@tonic-gate 
14387c478bd9Sstevel@tonic-gate static void
143980ab886dSwesolows prepctx(cw_ictx_t *ctx)
14407c478bd9Sstevel@tonic-gate {
144180ab886dSwesolows 	const char *dir, *cmd;
14427c478bd9Sstevel@tonic-gate 	char *program;
144380ab886dSwesolows 	size_t len;
14447c478bd9Sstevel@tonic-gate 
144580ab886dSwesolows 	dir = dirs[CIDX(CC(ctx), ctx->i_flags)];
144680ab886dSwesolows 	cmd = cmds[CIDX(CC(ctx), ctx->i_flags)];
144780ab886dSwesolows 	len = strlen(dir) + strlen(cmd) + 2;
144880ab886dSwesolows 	if ((program = malloc(len)) == NULL)
144980ab886dSwesolows 		nomem();
14507c478bd9Sstevel@tonic-gate 	(void) snprintf(program, len, "%s/%s", dir, cmd);
14517c478bd9Sstevel@tonic-gate 
145280ab886dSwesolows 	newae(ctx->i_ae, program);
145380ab886dSwesolows 
14541912d2c4Swesolows 	if (ctx->i_flags & CW_F_PROG) {
14551912d2c4Swesolows 		(void) printf("%s: %s\n", (ctx->i_flags & CW_F_SHADOW) ?
14561912d2c4Swesolows 		    "shadow" : "primary", program);
14571912d2c4Swesolows 		(void) fflush(stdout);
14581912d2c4Swesolows 	}
14591912d2c4Swesolows 
146080ab886dSwesolows 	if (!(ctx->i_flags & CW_F_XLATE))
146180ab886dSwesolows 		return;
146280ab886dSwesolows 
146380ab886dSwesolows 	switch (CC(ctx)) {
146480ab886dSwesolows 	case CW_C_CC:
146580ab886dSwesolows 		do_cc(ctx);
146680ab886dSwesolows 		break;
146780ab886dSwesolows 	case CW_C_GCC:
146880ab886dSwesolows 		do_gcc(ctx);
146980ab886dSwesolows 		break;
147080ab886dSwesolows 	}
147180ab886dSwesolows }
147280ab886dSwesolows 
147380ab886dSwesolows static int
147480ab886dSwesolows invoke(cw_ictx_t *ctx)
147580ab886dSwesolows {
147680ab886dSwesolows 	char **newargv;
147780ab886dSwesolows 	int ac;
147880ab886dSwesolows 	struct ae *a;
147980ab886dSwesolows 
148080ab886dSwesolows 	if ((newargv = calloc(sizeof (*newargv), ctx->i_ae->ael_argc + 1)) ==
148180ab886dSwesolows 	    NULL)
148280ab886dSwesolows 		nomem();
148380ab886dSwesolows 
148480ab886dSwesolows 	if (ctx->i_flags & CW_F_ECHO)
148580ab886dSwesolows 		(void) fprintf(stderr, "+ ");
148680ab886dSwesolows 
148780ab886dSwesolows 	for (ac = 0, a = ctx->i_ae->ael_head; a; a = a->ae_next, ac++) {
148880ab886dSwesolows 		newargv[ac] = a->ae_arg;
148980ab886dSwesolows 		if (ctx->i_flags & CW_F_ECHO)
149080ab886dSwesolows 			(void) fprintf(stderr, "%s ", a->ae_arg);
149180ab886dSwesolows 		if (a == ctx->i_ae->ael_tail)
149280ab886dSwesolows 			break;
149380ab886dSwesolows 	}
149480ab886dSwesolows 
149580ab886dSwesolows 	if (ctx->i_flags & CW_F_ECHO) {
149680ab886dSwesolows 		(void) fprintf(stderr, "\n");
149780ab886dSwesolows 		(void) fflush(stderr);
149880ab886dSwesolows 	}
149980ab886dSwesolows 
150080ab886dSwesolows 	if (!(ctx->i_flags & CW_F_EXEC))
150180ab886dSwesolows 		return (0);
150280ab886dSwesolows 
15037c478bd9Sstevel@tonic-gate 	/*
150480ab886dSwesolows 	 * We must fix up the environment here so that the
150580ab886dSwesolows 	 * dependency files are not trampled by the shadow compiler.
15067c478bd9Sstevel@tonic-gate 	 */
150780ab886dSwesolows 	if ((ctx->i_flags & CW_F_SHADOW) &&
150880ab886dSwesolows 	    (unsetenv("SUNPRO_DEPENDENCIES") != 0 ||
150980ab886dSwesolows 	    unsetenv("DEPENDENCIES_OUTPUT") != 0)) {
151080ab886dSwesolows 		(void) fprintf(stderr, "error: environment setup failed: %s\n",
151180ab886dSwesolows 		    strerror(errno));
151280ab886dSwesolows 		return (-1);
151380ab886dSwesolows 	}
15147c478bd9Sstevel@tonic-gate 
151580ab886dSwesolows 	(void) execv(newargv[0], newargv);
151680ab886dSwesolows 	cw_perror("couldn't run %s", newargv[0]);
15177c478bd9Sstevel@tonic-gate 
151880ab886dSwesolows 	return (-1);
151980ab886dSwesolows }
152080ab886dSwesolows 
152180ab886dSwesolows static int
152280ab886dSwesolows reap(cw_ictx_t *ctx)
152380ab886dSwesolows {
15241912d2c4Swesolows 	int status, ret = 0;
152580ab886dSwesolows 	char buf[1024];
152680ab886dSwesolows 	struct stat s;
152780ab886dSwesolows 
152880ab886dSwesolows 	do {
15291912d2c4Swesolows 		(void) waitpid(ctx->i_pid, &status, 0);
15301912d2c4Swesolows 		if (status != 0) {
15311912d2c4Swesolows 			if (WIFSIGNALED(status)) {
15321912d2c4Swesolows 				ret = -WTERMSIG(status);
153380ab886dSwesolows 				break;
15341912d2c4Swesolows 			} else if (WIFEXITED(status)) {
15351912d2c4Swesolows 				ret = WEXITSTATUS(status);
153680ab886dSwesolows 				break;
153780ab886dSwesolows 			}
15387c478bd9Sstevel@tonic-gate 		}
15391912d2c4Swesolows 	} while (!WIFEXITED(status) && !WIFSIGNALED(status));
154080ab886dSwesolows 
154180ab886dSwesolows 	(void) unlink(ctx->i_discard);
154280ab886dSwesolows 
15431912d2c4Swesolows 	if (stat(ctx->i_stderr, &s) < 0) {
154480ab886dSwesolows 		cw_perror("stat failed on child cleanup");
154580ab886dSwesolows 		return (-1);
15467c478bd9Sstevel@tonic-gate 	}
154780ab886dSwesolows 	if (s.st_size != 0) {
15481912d2c4Swesolows 		FILE *f;
154980ab886dSwesolows 
15501912d2c4Swesolows 		if ((f = fopen(ctx->i_stderr, "r")) != NULL) {
15511912d2c4Swesolows 			while (fgets(buf, sizeof (buf), f))
15521912d2c4Swesolows 				(void) fprintf(stderr, "%s", buf);
15531912d2c4Swesolows 			(void) fflush(stderr);
15541912d2c4Swesolows 			(void) fclose(f);
15551912d2c4Swesolows 		}
155680ab886dSwesolows 	}
15571912d2c4Swesolows 	(void) unlink(ctx->i_stderr);
15581912d2c4Swesolows 	free(ctx->i_stderr);
15591912d2c4Swesolows 
15601912d2c4Swesolows 	/*
15611912d2c4Swesolows 	 * cc returns an error code when given -V; we want that to succeed.
15621912d2c4Swesolows 	 */
15631912d2c4Swesolows 	if (ctx->i_flags & CW_F_PROG)
15641912d2c4Swesolows 		return (0);
156580ab886dSwesolows 
156680ab886dSwesolows 	return (ret);
156780ab886dSwesolows }
156880ab886dSwesolows 
156980ab886dSwesolows static int
157080ab886dSwesolows exec_ctx(cw_ictx_t *ctx, int block)
157180ab886dSwesolows {
157280ab886dSwesolows 	char *file;
157380ab886dSwesolows 
157480ab886dSwesolows 	/*
157580ab886dSwesolows 	 * To avoid offending cc's sensibilities, the name of its output
157680ab886dSwesolows 	 * file must end in '.o'.
157780ab886dSwesolows 	 */
157880ab886dSwesolows 	if ((file = tempnam(NULL, ".cw")) == NULL) {
157980ab886dSwesolows 		nomem();
158080ab886dSwesolows 		return (-1);
158180ab886dSwesolows 	}
158280ab886dSwesolows 	(void) strlcpy(ctx->i_discard, file, MAXPATHLEN);
158380ab886dSwesolows 	(void) strlcat(ctx->i_discard, ".o", MAXPATHLEN);
158480ab886dSwesolows 	free(file);
158580ab886dSwesolows 
15861912d2c4Swesolows 	if ((ctx->i_stderr = tempnam(NULL, ".cw")) == NULL) {
15871912d2c4Swesolows 		nomem();
158880ab886dSwesolows 		return (-1);
158980ab886dSwesolows 	}
159080ab886dSwesolows 
159180ab886dSwesolows 	if ((ctx->i_pid = fork()) == 0) {
15921912d2c4Swesolows 		int fd;
15931912d2c4Swesolows 
159480ab886dSwesolows 		(void) fclose(stderr);
15951912d2c4Swesolows 		if ((fd = open(ctx->i_stderr, O_WRONLY | O_CREAT | O_EXCL,
15961912d2c4Swesolows 		    0666)) < 0) {
15971912d2c4Swesolows 			cw_perror("open failed for standard error");
15981912d2c4Swesolows 			exit(1);
15991912d2c4Swesolows 		}
16001912d2c4Swesolows 		if (dup2(fd, 2) < 0) {
160180ab886dSwesolows 			cw_perror("dup2 failed for standard error");
160280ab886dSwesolows 			exit(1);
160380ab886dSwesolows 		}
16041912d2c4Swesolows 		if (fd != 2)
16051912d2c4Swesolows 			(void) close(fd);
160680ab886dSwesolows 		if (freopen("/dev/fd/2", "w", stderr) == NULL) {
160780ab886dSwesolows 			cw_perror("freopen failed for /dev/fd/2");
160880ab886dSwesolows 			exit(1);
160980ab886dSwesolows 		}
161080ab886dSwesolows 		prepctx(ctx);
161180ab886dSwesolows 		exit(invoke(ctx));
161280ab886dSwesolows 	}
161380ab886dSwesolows 
161480ab886dSwesolows 	if (ctx->i_pid < 0) {
161580ab886dSwesolows 		cw_perror("fork failed");
161680ab886dSwesolows 		return (1);
161780ab886dSwesolows 	}
161880ab886dSwesolows 
161980ab886dSwesolows 	if (block)
162080ab886dSwesolows 		return (reap(ctx));
162180ab886dSwesolows 
162280ab886dSwesolows 	return (0);
16237c478bd9Sstevel@tonic-gate }
16247c478bd9Sstevel@tonic-gate 
16257c478bd9Sstevel@tonic-gate int
16267c478bd9Sstevel@tonic-gate main(int argc, char **argv)
16277c478bd9Sstevel@tonic-gate {
162880ab886dSwesolows 	cw_ictx_t *ctx = newictx();
162980ab886dSwesolows 	cw_ictx_t *ctx_shadow = newictx();
16307c478bd9Sstevel@tonic-gate 	const char *dir;
16317c478bd9Sstevel@tonic-gate 	char cc_buf[MAXPATHLEN], gcc_buf[MAXPATHLEN];
163280ab886dSwesolows 	int do_serial, do_shadow;
163380ab886dSwesolows 	int ret = 0;
16347c478bd9Sstevel@tonic-gate 
16357c478bd9Sstevel@tonic-gate 	if ((progname = strrchr(argv[0], '/')) == NULL)
16367c478bd9Sstevel@tonic-gate 		progname = argv[0];
16377c478bd9Sstevel@tonic-gate 	else
16387c478bd9Sstevel@tonic-gate 		progname++;
16397c478bd9Sstevel@tonic-gate 
164080ab886dSwesolows 	if (ctx == NULL || ctx_shadow == NULL)
164180ab886dSwesolows 		nomem();
164280ab886dSwesolows 
164380ab886dSwesolows 	ctx->i_flags = CW_F_ECHO|CW_F_XLATE;
16447c478bd9Sstevel@tonic-gate 
16457c478bd9Sstevel@tonic-gate 	/*
16467c478bd9Sstevel@tonic-gate 	 * Figure out where to get our tools from.  This depends on
16477c478bd9Sstevel@tonic-gate 	 * the environment variables set at run time.
16487c478bd9Sstevel@tonic-gate 	 */
16497c478bd9Sstevel@tonic-gate 	if ((dir = getenv("SPRO_VROOT")) != NULL) {
16507c478bd9Sstevel@tonic-gate 		(void) snprintf(cc_buf, MAXPATHLEN, "%s/bin", dir);
16517c478bd9Sstevel@tonic-gate 	} else if ((dir = getenv("SPRO_ROOT")) != NULL) {
1652ac204d0dSpetede 		(void) snprintf(cc_buf, MAXPATHLEN, "%s/SS11/bin", dir);
16537c478bd9Sstevel@tonic-gate 	} else if ((dir = getenv("BUILD_TOOLS")) != NULL) {
16547c478bd9Sstevel@tonic-gate 		(void) snprintf(cc_buf, MAXPATHLEN,
1655ac204d0dSpetede 		    "%s/SUNWspro/SS11/bin", dir);
16567c478bd9Sstevel@tonic-gate 	}
165780ab886dSwesolows 	if (dir != NULL) {
165880ab886dSwesolows 		dirs[CIDX(CW_C_CC, 0)] = (const char *)cc_buf;
165980ab886dSwesolows 		dirs[CIDX(CW_C_CC, CW_F_CXX)] = (const char *)cc_buf;
166080ab886dSwesolows 	}
16617c478bd9Sstevel@tonic-gate 
16627c478bd9Sstevel@tonic-gate 	if ((dir = getenv("GNU_ROOT")) != NULL) {
16637c478bd9Sstevel@tonic-gate 		(void) snprintf(gcc_buf, MAXPATHLEN, "%s/bin", dir);
166480ab886dSwesolows 		dirs[CIDX(CW_C_GCC, 0)] = (const char *)gcc_buf;
166580ab886dSwesolows 		dirs[CIDX(CW_C_GCC, CW_F_CXX)] = (const char *)gcc_buf;
16667c478bd9Sstevel@tonic-gate 	}
16677c478bd9Sstevel@tonic-gate 
166880ab886dSwesolows 	if ((dir = getenv("CW_CC_DIR")) != NULL)
166980ab886dSwesolows 		dirs[CIDX(CW_C_CC, 0)] = dir;
167080ab886dSwesolows 	if ((dir = getenv("CW_CPLUSPLUS_DIR")) != NULL)
167180ab886dSwesolows 		dirs[CIDX(CW_C_CC, CW_F_CXX)] = dir;
167280ab886dSwesolows 	if ((dir = getenv("CW_GCC_DIR")) != NULL)
167380ab886dSwesolows 		dirs[CIDX(CW_C_GCC, 0)] = dir;
167480ab886dSwesolows 	if ((dir = getenv("CW_GPLUSPLUS_DIR")) != NULL)
167580ab886dSwesolows 		dirs[CIDX(CW_C_GCC, CW_F_CXX)] = dir;
167680ab886dSwesolows 
167780ab886dSwesolows 	do_shadow = (getenv("CW_NO_SHADOW") ? 0 : 1);
167880ab886dSwesolows 	do_serial = (getenv("CW_SHADOW_SERIAL") ? 1 : 0);
167980ab886dSwesolows 
168080ab886dSwesolows 	if (getenv("CW_NO_EXEC") == NULL)
168180ab886dSwesolows 		ctx->i_flags |= CW_F_EXEC;
16827c478bd9Sstevel@tonic-gate 
16837c478bd9Sstevel@tonic-gate 	/*
16847c478bd9Sstevel@tonic-gate 	 * The first argument must be one of "-_cc", "-_gcc", "-_CC", or "-_g++"
16857c478bd9Sstevel@tonic-gate 	 */
16867c478bd9Sstevel@tonic-gate 	if (argc == 1)
16877c478bd9Sstevel@tonic-gate 		usage();
16887c478bd9Sstevel@tonic-gate 	argc--;
16897c478bd9Sstevel@tonic-gate 	argv++;
16907c478bd9Sstevel@tonic-gate 	if (strcmp(argv[0], "-_cc") == 0) {
169180ab886dSwesolows 		ctx->i_compiler = CW_C_CC;
16927c478bd9Sstevel@tonic-gate 	} else if (strcmp(argv[0], "-_gcc") == 0) {
169380ab886dSwesolows 		ctx->i_compiler = CW_C_GCC;
16947c478bd9Sstevel@tonic-gate 	} else if (strcmp(argv[0], "-_CC") == 0) {
169580ab886dSwesolows 		ctx->i_compiler = CW_C_CC;
169680ab886dSwesolows 		ctx->i_flags |= CW_F_CXX;
16977c478bd9Sstevel@tonic-gate 	} else if (strcmp(argv[0], "-_g++") == 0) {
169880ab886dSwesolows 		ctx->i_compiler = CW_C_GCC;
169980ab886dSwesolows 		ctx->i_flags |= CW_F_CXX;
17007c478bd9Sstevel@tonic-gate 	} else {
17017c478bd9Sstevel@tonic-gate 		/* assume "-_gcc" by default */
17027c478bd9Sstevel@tonic-gate 		argc++;
17037c478bd9Sstevel@tonic-gate 		argv--;
170480ab886dSwesolows 		ctx->i_compiler = CW_C_GCC;
17057c478bd9Sstevel@tonic-gate 	}
17067c478bd9Sstevel@tonic-gate 
17071912d2c4Swesolows 	/*
17081912d2c4Swesolows 	 * -_compiler - tell us the path to the primary compiler only
17091912d2c4Swesolows 	 */
171080ab886dSwesolows 	if (argc > 1 && strcmp(argv[1], "-_compiler") == 0) {
171180ab886dSwesolows 		ctx->i_flags &= ~CW_F_XLATE;
171280ab886dSwesolows 		prepctx(ctx);
171380ab886dSwesolows 		(void) printf("%s\n", ctx->i_ae->ael_head->ae_arg);
171480ab886dSwesolows 		return (0);
17157c478bd9Sstevel@tonic-gate 	}
17167c478bd9Sstevel@tonic-gate 
17171912d2c4Swesolows 	/*
17181912d2c4Swesolows 	 * -_versions - tell us the cw version, paths to all compilers, and
17191912d2c4Swesolows 	 *		ask each for its version if we know how.
17201912d2c4Swesolows 	 */
17211912d2c4Swesolows 	if (argc > 1 && strcmp(argv[1], "-_versions") == 0) {
17221912d2c4Swesolows 		(void) printf("%s", "cw version %I%");
17231912d2c4Swesolows 		if (!do_shadow)
17241912d2c4Swesolows 			(void) printf(" (SHADOW MODE DISABLED)");
17251912d2c4Swesolows 		(void) printf("\n");
17261912d2c4Swesolows 		(void) fflush(stdout);
17271912d2c4Swesolows 		ctx->i_flags &= ~CW_F_ECHO;
17281912d2c4Swesolows 		ctx->i_flags |= CW_F_PROG|CW_F_EXEC;
17291912d2c4Swesolows 		argc--;
17301912d2c4Swesolows 		argv++;
17311912d2c4Swesolows 		do_serial = 1;
17321912d2c4Swesolows 	}
17331912d2c4Swesolows 
17341912d2c4Swesolows 	ctx->i_oldargc = argc;
17351912d2c4Swesolows 	ctx->i_oldargv = argv;
17361912d2c4Swesolows 
173780ab886dSwesolows 	ret |= exec_ctx(ctx, do_serial);
173880ab886dSwesolows 
173980ab886dSwesolows 	if (do_shadow) {
174080ab886dSwesolows 		(void) memcpy(ctx_shadow, ctx, sizeof (cw_ictx_t));
174180ab886dSwesolows 		ctx_shadow->i_flags |= CW_F_SHADOW;
174280ab886dSwesolows 		ret |= exec_ctx(ctx_shadow, 1);
17437c478bd9Sstevel@tonic-gate 	}
17447c478bd9Sstevel@tonic-gate 
174580ab886dSwesolows 	if (!do_serial)
174680ab886dSwesolows 		ret |= reap(ctx);
17477c478bd9Sstevel@tonic-gate 
174880ab886dSwesolows 	return (ret);
17497c478bd9Sstevel@tonic-gate }
1750