xref: /illumos-gate/usr/src/tools/cw/cw.c (revision 662492f5)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 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
83*662492f5Ssherrym  * -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
947c478bd9Sstevel@tonic-gate  * -U<name>	Delete initial definition of preprocessor symbol <name>
957c478bd9Sstevel@tonic-gate  * -V		Report version number of each compilation phase
967c478bd9Sstevel@tonic-gate  * -v		Do stricter semantic checking
977c478bd9Sstevel@tonic-gate  * -W<c>,<arg>	Pass <arg> to specified component <c> (a,l,m,p,0,2,h,i,u)
987c478bd9Sstevel@tonic-gate  * -w		Suppress compiler warning messages
997c478bd9Sstevel@tonic-gate  * -Xa		Compile assuming ANSI C conformance, allow K & R extensions
1007c478bd9Sstevel@tonic-gate  *		(default mode)
1017c478bd9Sstevel@tonic-gate  * -Xc		Compile assuming strict ANSI C conformance
1027c478bd9Sstevel@tonic-gate  * -Xs		Compile assuming (pre-ANSI) K & R C style code
1037c478bd9Sstevel@tonic-gate  * -Xt		Compile assuming K & R conformance, allow ANSI C
1047c478bd9Sstevel@tonic-gate  * -x386	Generate code for the 80386 processor
1057c478bd9Sstevel@tonic-gate  * -x486	Generate code for the 80486 processor
1067c478bd9Sstevel@tonic-gate  * -xarch=<a>	Specify target architecture instruction set
1077c478bd9Sstevel@tonic-gate  * -xbuiltin[=<b>] When profitable inline, or substitute intrinisic functions
1087c478bd9Sstevel@tonic-gate  *		for system functions, b={%all,%none}
1097c478bd9Sstevel@tonic-gate  * -xCC		Accept C++ style comments
1107c478bd9Sstevel@tonic-gate  * -xchar_byte_order=<o> Specify multi-char byte order <o> (default, high, low)
1117c478bd9Sstevel@tonic-gate  * -xchip=<c>	Specify the target processor for use by the optimizer
1127c478bd9Sstevel@tonic-gate  * -xcode=<c>	Generate different code for forming addresses
1137c478bd9Sstevel@tonic-gate  * -xcrossfile[=<n>] Enable optimization and inlining across source files,
1147c478bd9Sstevel@tonic-gate  *		n={0|1}
1157c478bd9Sstevel@tonic-gate  * -xe		Perform only syntax/semantic checking, no code generation
1167c478bd9Sstevel@tonic-gate  * -xF		Compile for later mapfile reordering
1177c478bd9Sstevel@tonic-gate  * -xhelp=<f>	Display on-line help information f(flags, readme, errors)
1187c478bd9Sstevel@tonic-gate  * -xildoff	Cancel -xildon
1197c478bd9Sstevel@tonic-gate  * -xildon	Enable use of the incremental linker, ild
1207c478bd9Sstevel@tonic-gate  * -xinline=[<a>,...,<a>]  Attempt inlining of specified user routines,
1217c478bd9Sstevel@tonic-gate  *		<a>={%auto,func,no%func}
1227c478bd9Sstevel@tonic-gate  * -xlibmieee	Force IEEE 754 return values for math routines in
1237c478bd9Sstevel@tonic-gate  *		exceptional cases
1247c478bd9Sstevel@tonic-gate  * -xlibmil	Inline selected libm math routines for optimization
1257c478bd9Sstevel@tonic-gate  * -xlic_lib=sunperf	Link in the Sun supplied performance libraries
1267c478bd9Sstevel@tonic-gate  * -xlicinfo	Show license server information
1277c478bd9Sstevel@tonic-gate  * -xM		Generate makefile dependencies
1287c478bd9Sstevel@tonic-gate  * -xM1		Generate makefile dependencies, but exclude /usr/include
1297c478bd9Sstevel@tonic-gate  * -xmaxopt=[off,1,2,3,4,5] maximum optimization level allowed on #pragma opt
1307c478bd9Sstevel@tonic-gate  * -xnolib	Do not link with default system libraries
1317c478bd9Sstevel@tonic-gate  * -xnolibmil	Cancel -xlibmil on command line
1327c478bd9Sstevel@tonic-gate  * -xO<n>	Generate optimized code (n={1|2|3|4|5})
1337c478bd9Sstevel@tonic-gate  * -xP		Print prototypes for function definitions
1347c478bd9Sstevel@tonic-gate  * -xpentium	Generate code for the pentium processor
1357c478bd9Sstevel@tonic-gate  * -xpg		Compile for profiling with gprof
1367c478bd9Sstevel@tonic-gate  * -xprofile=<p> Collect data for a profile or use a profile to optimize
1377c478bd9Sstevel@tonic-gate  *		<p>={{collect,use}[:<path>],tcov}
1387c478bd9Sstevel@tonic-gate  * -xregs=<r>	Control register allocation
1397c478bd9Sstevel@tonic-gate  * -xs		Allow debugging without object (.o) files
1407c478bd9Sstevel@tonic-gate  * -xsb		Compile for use with the WorkShop source browser
1417c478bd9Sstevel@tonic-gate  * -xsbfast	Generate only WorkShop source browser info, no compilation
1427c478bd9Sstevel@tonic-gate  * -xsfpconst	Represent unsuffixed floating point constants as single
1437c478bd9Sstevel@tonic-gate  *		precision
1447c478bd9Sstevel@tonic-gate  * -xspace	Do not do optimizations that increase code size
1457c478bd9Sstevel@tonic-gate  * -xstrconst	Place string literals into read-only data segment
1467c478bd9Sstevel@tonic-gate  * -xtarget=<t>	Specify target system for optimization
1477c478bd9Sstevel@tonic-gate  * -xtemp=<dir>	Set directory for temporary files to <dir>
1487c478bd9Sstevel@tonic-gate  * -xtime	Report the execution time for each compilation phase
1497c478bd9Sstevel@tonic-gate  * -xtransition	Emit warnings for differences between K&R C and ANSI C
1507c478bd9Sstevel@tonic-gate  * -xtrigraphs[=<yes|no>] Enable|disable trigraph translation
1517c478bd9Sstevel@tonic-gate  * -xunroll=n	Enable unrolling loops n times where possible
1527c478bd9Sstevel@tonic-gate  * -Y<c>,<dir>	Specify <dir> for location of component <c> (a,l,m,p,0,h,i,u)
1537c478bd9Sstevel@tonic-gate  * -YA,<dir>	Change default directory searched for components
1547c478bd9Sstevel@tonic-gate  * -YI,<dir>	Change default directory searched for include files
1557c478bd9Sstevel@tonic-gate  * -YP,<dir>	Change default directory for finding libraries files
1567c478bd9Sstevel@tonic-gate  * -YS,<dir>	Change default directory for startup object files
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate /*
1607c478bd9Sstevel@tonic-gate  * Translation table:
1617c478bd9Sstevel@tonic-gate  */
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate  * -#				-v
1647c478bd9Sstevel@tonic-gate  * -###				error
1657c478bd9Sstevel@tonic-gate  * -A<name[(tokens)]>		pass-thru
1667c478bd9Sstevel@tonic-gate  * -B<[static|dynamic]>		pass-thru (syntax error for anything else)
1677c478bd9Sstevel@tonic-gate  * -C				pass-thru
1687c478bd9Sstevel@tonic-gate  * -c				pass-thru
1697c478bd9Sstevel@tonic-gate  * -cg92			-m32 -mcpu=v8 -mtune=supersparc (SPARC only)
1707c478bd9Sstevel@tonic-gate  * -D<name[=token]>		pass-thru
1717c478bd9Sstevel@tonic-gate  * -dy or -dn			-Wl,-dy or -Wl,-dn
1727c478bd9Sstevel@tonic-gate  * -E				pass-thru
1737c478bd9Sstevel@tonic-gate  * -erroff=E_EMPTY_TRANSLATION_UNIT ignore
1747c478bd9Sstevel@tonic-gate  * -errtags=%all		-Wall
1757c478bd9Sstevel@tonic-gate  * -errwarn=%all		-Werror else -Wno-error
1767c478bd9Sstevel@tonic-gate  * -fast			error
1777c478bd9Sstevel@tonic-gate  * -fd				error
1787c478bd9Sstevel@tonic-gate  * -flags			--help
1797c478bd9Sstevel@tonic-gate  * -fnonstd			error
1807c478bd9Sstevel@tonic-gate  * -fns[=<yes|no>]		error
1817c478bd9Sstevel@tonic-gate  * -fprecision=<p>		error
1827c478bd9Sstevel@tonic-gate  * -fround=<r>			error
1837c478bd9Sstevel@tonic-gate  * -fsimple[=<n>]		error
1847c478bd9Sstevel@tonic-gate  * -fsingle[=<n>]		error
1857c478bd9Sstevel@tonic-gate  * -ftrap=<t>			error
1867c478bd9Sstevel@tonic-gate  * -fstore			error
1877c478bd9Sstevel@tonic-gate  * -G				pass-thru
1887c478bd9Sstevel@tonic-gate  * -g				pass-thru
1897c478bd9Sstevel@tonic-gate  * -H				pass-thru
1907c478bd9Sstevel@tonic-gate  * -h <name>			pass-thru
1917c478bd9Sstevel@tonic-gate  * -I<dir>			pass-thru
1927c478bd9Sstevel@tonic-gate  * -i				pass-thru
1937c478bd9Sstevel@tonic-gate  * -keeptmp			-save-temps
1947c478bd9Sstevel@tonic-gate  * -KPIC			-fPIC
1957c478bd9Sstevel@tonic-gate  * -Kpic			-fpic
1967c478bd9Sstevel@tonic-gate  * -L<dir>			pass-thru
1977c478bd9Sstevel@tonic-gate  * -l<name>			pass-thru
1987c478bd9Sstevel@tonic-gate  * -mc				error
1997c478bd9Sstevel@tonic-gate  * -mr				error
2007c478bd9Sstevel@tonic-gate  * -mr,"string"			error
2017c478bd9Sstevel@tonic-gate  * -mt				-D_REENTRANT
2027c478bd9Sstevel@tonic-gate  * -native			error
2037c478bd9Sstevel@tonic-gate  * -nofstore			error
2047c478bd9Sstevel@tonic-gate  * -nolib			-nodefaultlibs
2057c478bd9Sstevel@tonic-gate  * -noqueue			ignore
2067c478bd9Sstevel@tonic-gate  * -norunpath			ignore
207*662492f5Ssherrym  * -O				-O1 (Check the man page to be certain)
2087c478bd9Sstevel@tonic-gate  * -o <outputfile>		pass-thru
2097c478bd9Sstevel@tonic-gate  * -P				-E -o filename.i (or error)
2107c478bd9Sstevel@tonic-gate  * -PIC				-fPIC (C++ only)
2117c478bd9Sstevel@tonic-gate  * -p				pass-thru
2127c478bd9Sstevel@tonic-gate  * -pic				-fpic (C++ only)
2137c478bd9Sstevel@tonic-gate  * -Q[y|n]			error
2147c478bd9Sstevel@tonic-gate  * -qp				-p
2157c478bd9Sstevel@tonic-gate  * -R<dir[:dir]>		pass-thru
2167c478bd9Sstevel@tonic-gate  * -S				pass-thru
2177c478bd9Sstevel@tonic-gate  * -s				-Wl,-s
2187c478bd9Sstevel@tonic-gate  * -U<name>			pass-thru
2197c478bd9Sstevel@tonic-gate  * -V				--version
2207c478bd9Sstevel@tonic-gate  * -v				-Wall
2217c478bd9Sstevel@tonic-gate  * -Wa,<arg>			pass-thru
2227c478bd9Sstevel@tonic-gate  * -Wp,<arg>			pass-thru except -xc99=<a>
2237c478bd9Sstevel@tonic-gate  * -Wl,<arg>			pass-thru
2247c478bd9Sstevel@tonic-gate  * -W{m,0,2,h,i,u>		error/ignore
2257c478bd9Sstevel@tonic-gate  * -Wu,-xmodel=kernel		-ffreestanding -mcmodel=kernel -mno-red-zone
2267c478bd9Sstevel@tonic-gate  * -w				pass-thru
2277c478bd9Sstevel@tonic-gate  * -Xa				-std=iso9899:199409 or -ansi
2287c478bd9Sstevel@tonic-gate  * -Xc				-ansi -pedantic
2297c478bd9Sstevel@tonic-gate  * -Xt				error
2307c478bd9Sstevel@tonic-gate  * -Xs				-traditional -std=c89
2317c478bd9Sstevel@tonic-gate  * -x386			-march=i386 (x86 only)
2327c478bd9Sstevel@tonic-gate  * -x486			-march=i486 (x86 only)
2337c478bd9Sstevel@tonic-gate  * -xarch=<a>			table
2347c478bd9Sstevel@tonic-gate  * -xbuiltin[=<b>]		error
2357c478bd9Sstevel@tonic-gate  * -xCC				ignore
2367c478bd9Sstevel@tonic-gate  * -xchar_byte_order=<o>	error
2377c478bd9Sstevel@tonic-gate  * -xchip=<c>			table
2387c478bd9Sstevel@tonic-gate  * -xcode=<c>			table
2397c478bd9Sstevel@tonic-gate  * -xcrossfile[=<n>]		error
2407c478bd9Sstevel@tonic-gate  * -xe				error
2417c478bd9Sstevel@tonic-gate  * -xF				error
2427c478bd9Sstevel@tonic-gate  * -xhelp=<f>			error
2437c478bd9Sstevel@tonic-gate  * -xildoff			ignore
2447c478bd9Sstevel@tonic-gate  * -xildon			ignore
2457c478bd9Sstevel@tonic-gate  * -xinline			ignore
2467c478bd9Sstevel@tonic-gate  * -xlibmieee			error
2477c478bd9Sstevel@tonic-gate  * -xlibmil			error
2487c478bd9Sstevel@tonic-gate  * -xlic_lib=sunperf		error
2497c478bd9Sstevel@tonic-gate  * -xM				-M
2507c478bd9Sstevel@tonic-gate  * -xM1				-MM
2517c478bd9Sstevel@tonic-gate  * -xmaxopt=[...]		error
2527c478bd9Sstevel@tonic-gate  * -xnolib			-nodefaultlibs
2537c478bd9Sstevel@tonic-gate  * -xnolibmil			error
2547c478bd9Sstevel@tonic-gate  * -xO<n>			-O<n>
2557c478bd9Sstevel@tonic-gate  * -xP				error
2567c478bd9Sstevel@tonic-gate  * -xpentium			-march=pentium (x86 only)
2577c478bd9Sstevel@tonic-gate  * -xpg				error
2587c478bd9Sstevel@tonic-gate  * -xprofile=<p>		error
2597c478bd9Sstevel@tonic-gate  * -xregs=<r>			table
2607c478bd9Sstevel@tonic-gate  * -xs				error
2617c478bd9Sstevel@tonic-gate  * -xsb				error
2627c478bd9Sstevel@tonic-gate  * -xsbfast			error
2637c478bd9Sstevel@tonic-gate  * -xsfpconst			error
2647c478bd9Sstevel@tonic-gate  * -xspace			ignore (-not -Os)
2657c478bd9Sstevel@tonic-gate  * -xstrconst			ignore
2667c478bd9Sstevel@tonic-gate  * -xtarget=<t>			table
2677c478bd9Sstevel@tonic-gate  * -xtemp=<dir>			error
2687c478bd9Sstevel@tonic-gate  * -xtime			error
2697c478bd9Sstevel@tonic-gate  * -xtransition			-Wtransition
2707c478bd9Sstevel@tonic-gate  * -xtrigraphs=<yes|no>		-trigraphs -notrigraphs
2717c478bd9Sstevel@tonic-gate  * -xunroll=n			error
2727c478bd9Sstevel@tonic-gate  * -Y<c>,<dir>			error
2737c478bd9Sstevel@tonic-gate  * -YA,<dir>			error
2747c478bd9Sstevel@tonic-gate  * -YI,<dir>			-nostdinc -I<dir>
2757c478bd9Sstevel@tonic-gate  * -YP,<dir>			error
2767c478bd9Sstevel@tonic-gate  * -YS,<dir>			error
2777c478bd9Sstevel@tonic-gate  */
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate #include <stdio.h>
2807c478bd9Sstevel@tonic-gate #include <sys/types.h>
2817c478bd9Sstevel@tonic-gate #include <unistd.h>
2827c478bd9Sstevel@tonic-gate #include <string.h>
2837c478bd9Sstevel@tonic-gate #include <stdlib.h>
2847c478bd9Sstevel@tonic-gate #include <ctype.h>
2857c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
2867c478bd9Sstevel@tonic-gate #include <sys/param.h>
2877c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate static int echo = 1;
2907c478bd9Sstevel@tonic-gate static int newargc;
2917c478bd9Sstevel@tonic-gate static const char *progname;
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate static char *default_cc_dir;
2947c478bd9Sstevel@tonic-gate static char *default_gcc_dir;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate static char *default_cplusplus_dir;
2977c478bd9Sstevel@tonic-gate static char *default_gplusplus_dir;
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate static const char *xarch_tbl[] = {
3007c478bd9Sstevel@tonic-gate #if defined(__x86)
3017c478bd9Sstevel@tonic-gate 	"generic",	NULL,
3027c478bd9Sstevel@tonic-gate 	"generic64",	"-m64", "-mtune=opteron", NULL,
3037c478bd9Sstevel@tonic-gate 	"amd64",	"-m64", "-mtune=opteron", NULL,
3047c478bd9Sstevel@tonic-gate 	"386",		"-march=i386", NULL,
3057c478bd9Sstevel@tonic-gate 	"pentium_pro",	"-march=pentiumpro", NULL,
3067c478bd9Sstevel@tonic-gate #elif defined(__sparc)
3077c478bd9Sstevel@tonic-gate 	"generic",	"-m32", "-mcpu=v8", NULL,
3087c478bd9Sstevel@tonic-gate 	"generic64",	"-m64", "-mcpu=v9", NULL,
3097c478bd9Sstevel@tonic-gate 	"v8",		"-m32", "-mcpu=v8", "-mno-v8plus", NULL,
3107c478bd9Sstevel@tonic-gate 	"v8plus",	"-m32", "-mcpu=v9", "-mv8plus", NULL,
3117c478bd9Sstevel@tonic-gate 	"v8plusa",	"-m32", "-mcpu=ultrasparc", "-mv8plus", "-mvis", NULL,
3127c478bd9Sstevel@tonic-gate 	"v8plusb",	"-m32", "-mcpu=ultrasparc3", "-mv8plus", "-mvis", NULL,
3137c478bd9Sstevel@tonic-gate 	"v9",		"-m64", "-mcpu=v9", NULL,
3147c478bd9Sstevel@tonic-gate 	"v9a",		"-m64", "-mcpu=ultrasparc", "-mvis", NULL,
3157c478bd9Sstevel@tonic-gate 	"v9b",		"-m64", "-mcpu=ultrasparc3", "-mvis", NULL,
3167c478bd9Sstevel@tonic-gate #endif
3177c478bd9Sstevel@tonic-gate 	NULL,		NULL
3187c478bd9Sstevel@tonic-gate };
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate static const char *xchip_tbl[] = {
3217c478bd9Sstevel@tonic-gate #if defined(__x86)
3227c478bd9Sstevel@tonic-gate 	"386",		"-mtune=i386", NULL,
3237c478bd9Sstevel@tonic-gate 	"486",		"-mtune=i486", NULL,
3247c478bd9Sstevel@tonic-gate 	"pentium",	"-mtune=pentium", NULL,
3257c478bd9Sstevel@tonic-gate 	"pentium_pro",  "-mtune=pentiumpro", NULL,
3267c478bd9Sstevel@tonic-gate #elif defined(__sparc)
3277c478bd9Sstevel@tonic-gate 	"super",	"-mtune=supersparc", NULL,
3287c478bd9Sstevel@tonic-gate 	"ultra",	"-mtune=ultrasparc", NULL,
3297c478bd9Sstevel@tonic-gate 	"ultra3",	"-mtune=ultrasparc3", NULL,
3307c478bd9Sstevel@tonic-gate #endif
3317c478bd9Sstevel@tonic-gate 	NULL,		NULL
3327c478bd9Sstevel@tonic-gate };
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate static const char *xcode_tbl[] = {
3357c478bd9Sstevel@tonic-gate #if defined(__sparc)
3367c478bd9Sstevel@tonic-gate 	"abs32",	"-fno-pic", "-mcmodel=medlow", NULL,
3377c478bd9Sstevel@tonic-gate 	"abs44",	"-fno-pic", "-mcmodel=medmid", NULL,
3387c478bd9Sstevel@tonic-gate 	"abs64",	"-fno-pic", "-mcmodel=medany", NULL,
3397c478bd9Sstevel@tonic-gate 	"pic13",	"-fpic", NULL,
3407c478bd9Sstevel@tonic-gate 	"pic32",	"-fPIC", NULL,
3417c478bd9Sstevel@tonic-gate #endif
3427c478bd9Sstevel@tonic-gate 	NULL,		NULL
3437c478bd9Sstevel@tonic-gate };
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate static const char *xtarget_tbl[] = {
3467c478bd9Sstevel@tonic-gate #if defined(__x86)
3477c478bd9Sstevel@tonic-gate 	"pentium_pro",	"-march=pentiumpro", NULL,
3487c478bd9Sstevel@tonic-gate #endif	/* __x86 */
3497c478bd9Sstevel@tonic-gate 	NULL,		NULL
3507c478bd9Sstevel@tonic-gate };
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate static const char *xregs_tbl[] = {
3537c478bd9Sstevel@tonic-gate #if defined(__sparc)
3547c478bd9Sstevel@tonic-gate 	"appl",		"-mapp-regs", NULL,
3557c478bd9Sstevel@tonic-gate 	"no%appl",	"-mno-app-regs", NULL,
3567c478bd9Sstevel@tonic-gate 	"float",	"-mfpu", NULL,
3577c478bd9Sstevel@tonic-gate 	"no%float",	"-mno-fpu", NULL,
3587c478bd9Sstevel@tonic-gate #endif	/* __sparc */
3597c478bd9Sstevel@tonic-gate 	NULL,		NULL
3607c478bd9Sstevel@tonic-gate };
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate struct aelist {
3637c478bd9Sstevel@tonic-gate 	struct ae {
3647c478bd9Sstevel@tonic-gate 		struct ae *ae_next;
3657c478bd9Sstevel@tonic-gate 		char *ae_arg;
3667c478bd9Sstevel@tonic-gate 	} *ael_head, *ael_tail;
3677c478bd9Sstevel@tonic-gate };
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate static struct aelist *
3707c478bd9Sstevel@tonic-gate newael(void)
3717c478bd9Sstevel@tonic-gate {
3727c478bd9Sstevel@tonic-gate 	return (calloc(sizeof (struct aelist), 1));
3737c478bd9Sstevel@tonic-gate }
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate static void
3767c478bd9Sstevel@tonic-gate newae(struct aelist *ael, const char *arg)
3777c478bd9Sstevel@tonic-gate {
3787c478bd9Sstevel@tonic-gate 	struct ae *ae;
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 	ae = calloc(sizeof (*ae), 1);
3817c478bd9Sstevel@tonic-gate 	ae->ae_arg = strdup(arg);
3827c478bd9Sstevel@tonic-gate 	if (ael->ael_tail == NULL)
3837c478bd9Sstevel@tonic-gate 		ael->ael_head = ae;
3847c478bd9Sstevel@tonic-gate 	else
3857c478bd9Sstevel@tonic-gate 		ael->ael_tail->ae_next = ae;
3867c478bd9Sstevel@tonic-gate 	ael->ael_tail = ae;
3877c478bd9Sstevel@tonic-gate 	newargc++;
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate static void
3917c478bd9Sstevel@tonic-gate error(const char *arg)
3927c478bd9Sstevel@tonic-gate {
3937c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
3947c478bd9Sstevel@tonic-gate 	    "%s: mapping failed at or near arg '%s'\n", progname, arg);
3957c478bd9Sstevel@tonic-gate 	exit(2);
3967c478bd9Sstevel@tonic-gate }
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate /*
3997c478bd9Sstevel@tonic-gate  * Add the current favourite set of warnings to the gcc invocation.
4007c478bd9Sstevel@tonic-gate  */
4017c478bd9Sstevel@tonic-gate static void
4027c478bd9Sstevel@tonic-gate warnings(struct aelist *h)
4037c478bd9Sstevel@tonic-gate {
4047c478bd9Sstevel@tonic-gate 	static int warningsonce;
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 	if (warningsonce++)
4077c478bd9Sstevel@tonic-gate 		return;
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 	newae(h, "-Wall");
4107c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-unknown-pragmas");
4117c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-missing-braces");
4127c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-sign-compare");
4137c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-parentheses");
4147c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-uninitialized");
4157c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-implicit-function-declaration");
4167c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-unused");
4177c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-trigraphs");
4187c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-char-subscripts");
4197c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-switch");
4207c478bd9Sstevel@tonic-gate }
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate static void
4237c478bd9Sstevel@tonic-gate optim_disable(struct aelist *h, int level)
4247c478bd9Sstevel@tonic-gate {
4257c478bd9Sstevel@tonic-gate 	if (level >= 2) {
4267c478bd9Sstevel@tonic-gate 		newae(h, "-fno-strict-aliasing");
4277c478bd9Sstevel@tonic-gate 		newae(h, "-fno-unit-at-a-time");
4287c478bd9Sstevel@tonic-gate 		newae(h, "-fno-optimize-sibling-calls");
4297c478bd9Sstevel@tonic-gate 	}
4307c478bd9Sstevel@tonic-gate }
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate /* ARGSUSED */
4337c478bd9Sstevel@tonic-gate static void
4347c478bd9Sstevel@tonic-gate Xamode(struct aelist *h)
4357c478bd9Sstevel@tonic-gate {
4367c478bd9Sstevel@tonic-gate }
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate static void
4397c478bd9Sstevel@tonic-gate Xcmode(struct aelist *h)
4407c478bd9Sstevel@tonic-gate {
4417c478bd9Sstevel@tonic-gate 	static int xconce;
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 	if (xconce++)
4447c478bd9Sstevel@tonic-gate 		return;
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate 	newae(h, "-ansi");
4477c478bd9Sstevel@tonic-gate 	newae(h, "-pedantic-errors");
4487c478bd9Sstevel@tonic-gate }
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate static void
4517c478bd9Sstevel@tonic-gate Xsmode(struct aelist *h)
4527c478bd9Sstevel@tonic-gate {
4537c478bd9Sstevel@tonic-gate 	static int xsonce;
4547c478bd9Sstevel@tonic-gate 
4557c478bd9Sstevel@tonic-gate 	if (xsonce++)
4567c478bd9Sstevel@tonic-gate 		return;
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	newae(h, "-traditional");
4597c478bd9Sstevel@tonic-gate 	newae(h, "-traditional-cpp");
4607c478bd9Sstevel@tonic-gate }
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate static void
4637c478bd9Sstevel@tonic-gate usage()
4647c478bd9Sstevel@tonic-gate {
4657c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
4667c478bd9Sstevel@tonic-gate 	    "usage: %s { -_cc | -_gcc | -_CC | -_g++ } [ -_compiler | ... ]\n",
4677c478bd9Sstevel@tonic-gate 	    progname);
4687c478bd9Sstevel@tonic-gate 	exit(2);
4697c478bd9Sstevel@tonic-gate }
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate static void
4727c478bd9Sstevel@tonic-gate xlate(struct aelist *h, const char *xarg, const char **table)
4737c478bd9Sstevel@tonic-gate {
4747c478bd9Sstevel@tonic-gate 	while (*table != NULL && strcmp(xarg, *table) != 0) {
4757c478bd9Sstevel@tonic-gate 		while (*table != NULL)
4767c478bd9Sstevel@tonic-gate 			table++;
4777c478bd9Sstevel@tonic-gate 		table++;
4787c478bd9Sstevel@tonic-gate 	}
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate 	if (*table == NULL)
4817c478bd9Sstevel@tonic-gate 		error(xarg);
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate 	table++;
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 	while (*table != NULL) {
4867c478bd9Sstevel@tonic-gate 		newae(h, *table);
4877c478bd9Sstevel@tonic-gate 		table++;
4887c478bd9Sstevel@tonic-gate 	}
4897c478bd9Sstevel@tonic-gate }
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate static void
4927c478bd9Sstevel@tonic-gate do_gcc(const char *dir, const char *cmd, int argc, char **argv,
4937c478bd9Sstevel@tonic-gate     struct aelist *h, int cplusplus)
4947c478bd9Sstevel@tonic-gate {
4957c478bd9Sstevel@tonic-gate 	int c;
4967c478bd9Sstevel@tonic-gate 	int pic = 0;
4977c478bd9Sstevel@tonic-gate 	int nolibc = 0;
4987c478bd9Sstevel@tonic-gate 	char *model = NULL;
4997c478bd9Sstevel@tonic-gate 	char *program;
5007c478bd9Sstevel@tonic-gate 	size_t len = strlen(dir) + strlen(cmd) + 2;
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 	program = malloc(len);
5037c478bd9Sstevel@tonic-gate 	(void) snprintf(program, len, "%s/%s", dir, cmd);
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 	/*
5067c478bd9Sstevel@tonic-gate 	 * Basic defaults for ON compilation
5077c478bd9Sstevel@tonic-gate 	 */
5087c478bd9Sstevel@tonic-gate 	newae(h, program);
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate 	newae(h, "-fident");
5117c478bd9Sstevel@tonic-gate 	newae(h, "-finline");
5127c478bd9Sstevel@tonic-gate 	newae(h, "-fno-inline-functions");
5137c478bd9Sstevel@tonic-gate 	newae(h, "-fno-builtin");
5147c478bd9Sstevel@tonic-gate 	newae(h, "-fno-asm");
5157c478bd9Sstevel@tonic-gate 	newae(h, "-nodefaultlibs");
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate 	/*
5187c478bd9Sstevel@tonic-gate 	 * This is needed because 'u' is defined
5197c478bd9Sstevel@tonic-gate 	 * under a conditional on 'sun'.  Should
5207c478bd9Sstevel@tonic-gate 	 * probably just remove the conditional,
5217c478bd9Sstevel@tonic-gate 	 * or make it be dependent on '__sun'.
5227c478bd9Sstevel@tonic-gate 	 *
5237c478bd9Sstevel@tonic-gate 	 * -Dunix is also missing in enhanced ANSI mode
5247c478bd9Sstevel@tonic-gate 	 */
5257c478bd9Sstevel@tonic-gate 	newae(h, "-D__sun");
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate 	/*
5287c478bd9Sstevel@tonic-gate 	 * Walk the argument list, translating as we go ..
5297c478bd9Sstevel@tonic-gate 	 */
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 	while (--argc > 0) {
5327c478bd9Sstevel@tonic-gate 		char *arg = *++argv;
5337c478bd9Sstevel@tonic-gate 		size_t arglen = strlen(arg);
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 		if (*arg == '-')
5367c478bd9Sstevel@tonic-gate 			arglen--;
5377c478bd9Sstevel@tonic-gate 		else {
5387c478bd9Sstevel@tonic-gate 			/*
5397c478bd9Sstevel@tonic-gate 			 * Discard inline files that gcc doesn't grok
5407c478bd9Sstevel@tonic-gate 			 */
5417c478bd9Sstevel@tonic-gate 			if (arglen > 3 &&
5427c478bd9Sstevel@tonic-gate 			    strcmp(arg + arglen - 3, ".il") == 0)
5437c478bd9Sstevel@tonic-gate 				continue;
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 			/*
5467c478bd9Sstevel@tonic-gate 			 * Otherwise, filenames, and partial arguments
5477c478bd9Sstevel@tonic-gate 			 * are simply passed through for gcc to chew on.
5487c478bd9Sstevel@tonic-gate 			 */
5497c478bd9Sstevel@tonic-gate 			newae(h, arg);
5507c478bd9Sstevel@tonic-gate 			continue;
5517c478bd9Sstevel@tonic-gate 		}
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate 		if (cplusplus) {
5547c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-compat=", 8) == 0) {
5557c478bd9Sstevel@tonic-gate 				/* discard -compat=4 and -compat=5 */
5567c478bd9Sstevel@tonic-gate 				continue;
5577c478bd9Sstevel@tonic-gate 			}
5587c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Qoption") == 0) {
5597c478bd9Sstevel@tonic-gate 				/* discard -Qoption and its two arguments */
5607c478bd9Sstevel@tonic-gate 				if (argc < 3)
5617c478bd9Sstevel@tonic-gate 					error(arg);
5627c478bd9Sstevel@tonic-gate 				argc -= 2;
5637c478bd9Sstevel@tonic-gate 				argv += 2;
5647c478bd9Sstevel@tonic-gate 				continue;
5657c478bd9Sstevel@tonic-gate 			}
5667c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-xwe") == 0) {
5677c478bd9Sstevel@tonic-gate 				/* turn warnings into errors */
5687c478bd9Sstevel@tonic-gate 				/* newae(h, "-Werror"); */
5697c478bd9Sstevel@tonic-gate 				continue;
5707c478bd9Sstevel@tonic-gate 			}
5717c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-noex") == 0) {
5727c478bd9Sstevel@tonic-gate 				/* no exceptions */
5737c478bd9Sstevel@tonic-gate 				newae(h, "-fno-exceptions");
5747c478bd9Sstevel@tonic-gate 				/* no run time type descriptor information */
5757c478bd9Sstevel@tonic-gate 				newae(h, "-fno-rtti");
5767c478bd9Sstevel@tonic-gate 				continue;
5777c478bd9Sstevel@tonic-gate 			}
5787c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-pic") == 0) {
5797c478bd9Sstevel@tonic-gate 				newae(h, "-fpic");
5807c478bd9Sstevel@tonic-gate 				pic = 1;
5817c478bd9Sstevel@tonic-gate 				continue;
5827c478bd9Sstevel@tonic-gate 			}
5837c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-PIC") == 0) {
5847c478bd9Sstevel@tonic-gate 				newae(h, "-fPIC");
5857c478bd9Sstevel@tonic-gate 				pic = 1;
5867c478bd9Sstevel@tonic-gate 				continue;
5877c478bd9Sstevel@tonic-gate 			}
5887c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-norunpath") == 0) {
5897c478bd9Sstevel@tonic-gate 				/* gcc has no corresponding option */
5907c478bd9Sstevel@tonic-gate 				continue;
5917c478bd9Sstevel@tonic-gate 			}
5927c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-nolib") == 0) {
5937c478bd9Sstevel@tonic-gate 				/* -nodefaultlibs is on by default */
5947c478bd9Sstevel@tonic-gate 				nolibc = 1;
5957c478bd9Sstevel@tonic-gate 				continue;
5967c478bd9Sstevel@tonic-gate 			}
5977c478bd9Sstevel@tonic-gate #if defined(__sparc)
5987c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-cg92") == 0) {
5997c478bd9Sstevel@tonic-gate 				xlate(h, "v8", xarch_tbl);
6007c478bd9Sstevel@tonic-gate 				xlate(h, "super", xchip_tbl);
6017c478bd9Sstevel@tonic-gate 				continue;
6027c478bd9Sstevel@tonic-gate 			}
6037c478bd9Sstevel@tonic-gate #endif	/* __sparc */
6047c478bd9Sstevel@tonic-gate 		}
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate 		switch ((c = arg[1])) {
6077c478bd9Sstevel@tonic-gate 		case '_':
6087c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-_noecho") == 0)
6097c478bd9Sstevel@tonic-gate 				echo = 0;
6107c478bd9Sstevel@tonic-gate 			else if (strncmp(arg, "-_cc=", 5) == 0 ||
6117c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-_CC=", 5) == 0)
6127c478bd9Sstevel@tonic-gate 				/* EMPTY */;
6137c478bd9Sstevel@tonic-gate 			else if (strncmp(arg, "-_gcc=", 6) == 0 ||
6147c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-_g++=", 6) == 0)
6157c478bd9Sstevel@tonic-gate 				newae(h, arg + 6);
6167c478bd9Sstevel@tonic-gate 			else if (strcmp(arg, "-_compiler") == 0) {
6177c478bd9Sstevel@tonic-gate 				(void) printf("%s\n", program);
6187c478bd9Sstevel@tonic-gate 				exit(0);
6197c478bd9Sstevel@tonic-gate 			} else
6207c478bd9Sstevel@tonic-gate 				error(arg);
6217c478bd9Sstevel@tonic-gate 			break;
6227c478bd9Sstevel@tonic-gate 		case '#':
6237c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
6247c478bd9Sstevel@tonic-gate 				newae(h, "-v");
6257c478bd9Sstevel@tonic-gate 				break;
6267c478bd9Sstevel@tonic-gate 			}
6277c478bd9Sstevel@tonic-gate 			error(arg);
6287c478bd9Sstevel@tonic-gate 			break;
6297c478bd9Sstevel@tonic-gate 		case 'g':
6307c478bd9Sstevel@tonic-gate 			newae(h, "-gdwarf-2");
6317c478bd9Sstevel@tonic-gate 			break;
6327c478bd9Sstevel@tonic-gate 		case 'E':
6337c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
6347c478bd9Sstevel@tonic-gate 				newae(h, "-xc");
6357c478bd9Sstevel@tonic-gate 				newae(h, arg);
6367c478bd9Sstevel@tonic-gate 				nolibc = 1;
6377c478bd9Sstevel@tonic-gate 				break;
6387c478bd9Sstevel@tonic-gate 			}
6397c478bd9Sstevel@tonic-gate 			error(arg);
6407c478bd9Sstevel@tonic-gate 			break;
6417c478bd9Sstevel@tonic-gate 		case 'c':
6427c478bd9Sstevel@tonic-gate 		case 'S':
6437c478bd9Sstevel@tonic-gate 			if (arglen == 1)
6447c478bd9Sstevel@tonic-gate 				nolibc = 1;
6457c478bd9Sstevel@tonic-gate 			/* FALLTHROUGH */
6467c478bd9Sstevel@tonic-gate 		case 'C':
6477c478bd9Sstevel@tonic-gate 		case 'H':
6487c478bd9Sstevel@tonic-gate 		case 'p':
6497c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
6507c478bd9Sstevel@tonic-gate 				newae(h, arg);
6517c478bd9Sstevel@tonic-gate 				break;
6527c478bd9Sstevel@tonic-gate 			}
6537c478bd9Sstevel@tonic-gate 			error(arg);
6547c478bd9Sstevel@tonic-gate 			break;
6557c478bd9Sstevel@tonic-gate 		case 'A':
6567c478bd9Sstevel@tonic-gate 		case 'h':
6577c478bd9Sstevel@tonic-gate 		case 'I':
6587c478bd9Sstevel@tonic-gate 		case 'i':
6597c478bd9Sstevel@tonic-gate 		case 'L':
6607c478bd9Sstevel@tonic-gate 		case 'l':
6617c478bd9Sstevel@tonic-gate 		case 'o':
6627c478bd9Sstevel@tonic-gate 		case 'R':
6637c478bd9Sstevel@tonic-gate 		case 'U':
6647c478bd9Sstevel@tonic-gate 		case 'u':
6657c478bd9Sstevel@tonic-gate 		case 'w':
6667c478bd9Sstevel@tonic-gate 			newae(h, arg);
6677c478bd9Sstevel@tonic-gate 			break;
6687c478bd9Sstevel@tonic-gate 		case 'D':
6697c478bd9Sstevel@tonic-gate 			newae(h, arg);
6707c478bd9Sstevel@tonic-gate 			/*
6717c478bd9Sstevel@tonic-gate 			 * XXX	Clearly a hack ... do we need _KADB too?
6727c478bd9Sstevel@tonic-gate 			 */
6737c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-D_KERNEL") == 0 ||
6747c478bd9Sstevel@tonic-gate 			    strcmp(arg, "-D_BOOT") == 0)
6757c478bd9Sstevel@tonic-gate 				newae(h, "-ffreestanding");
6767c478bd9Sstevel@tonic-gate 			break;
6777c478bd9Sstevel@tonic-gate 		case 'd':
6787c478bd9Sstevel@tonic-gate 			if (arglen == 2) {
6797c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-dy") == 0) {
6807c478bd9Sstevel@tonic-gate 					newae(h, "-Wl,-dy");
6817c478bd9Sstevel@tonic-gate 					break;
6827c478bd9Sstevel@tonic-gate 				}
6837c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-dn") == 0) {
6847c478bd9Sstevel@tonic-gate 					newae(h, "-Wl,-dn");
6857c478bd9Sstevel@tonic-gate 					break;
6867c478bd9Sstevel@tonic-gate 				}
6877c478bd9Sstevel@tonic-gate 			}
6887c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-dalign") == 0) {
6897c478bd9Sstevel@tonic-gate 				/*
6907c478bd9Sstevel@tonic-gate 				 * -dalign forces alignment in some cases;
6917c478bd9Sstevel@tonic-gate 				 * gcc does not need any flag to do this.
6927c478bd9Sstevel@tonic-gate 				 */
6937c478bd9Sstevel@tonic-gate 				break;
6947c478bd9Sstevel@tonic-gate 			}
6957c478bd9Sstevel@tonic-gate 			error(arg);
6967c478bd9Sstevel@tonic-gate 			break;
6977c478bd9Sstevel@tonic-gate 		case 'e':
6987c478bd9Sstevel@tonic-gate 			if (strcmp(arg,
6997c478bd9Sstevel@tonic-gate 			    "-erroff=E_EMPTY_TRANSLATION_UNIT") == 0) {
7007c478bd9Sstevel@tonic-gate 				/*
7017c478bd9Sstevel@tonic-gate 				 * Accept but ignore this -- gcc doesn't
7027c478bd9Sstevel@tonic-gate 				 * seem to complain about empty translation
7037c478bd9Sstevel@tonic-gate 				 * units
7047c478bd9Sstevel@tonic-gate 				 */
7057c478bd9Sstevel@tonic-gate 				break;
7067c478bd9Sstevel@tonic-gate 			}
7077c478bd9Sstevel@tonic-gate 			/* XX64 -- ignore all -erroff= options, for now */
7087c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-erroff=", 8) == 0)
7097c478bd9Sstevel@tonic-gate 				break;
7107c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-errtags=yes") == 0) {
7117c478bd9Sstevel@tonic-gate 				warnings(h);
7127c478bd9Sstevel@tonic-gate 				break;
7137c478bd9Sstevel@tonic-gate 			}
7147c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-errwarn=%all") == 0) {
7157c478bd9Sstevel@tonic-gate 				newae(h, "-Werror");
7167c478bd9Sstevel@tonic-gate 				break;
7177c478bd9Sstevel@tonic-gate 			}
7187c478bd9Sstevel@tonic-gate 			error(arg);
7197c478bd9Sstevel@tonic-gate 			break;
7207c478bd9Sstevel@tonic-gate 		case 'f':
7217c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-flags") == 0) {
7227c478bd9Sstevel@tonic-gate 				newae(h, "--help");
7237c478bd9Sstevel@tonic-gate 				break;
7247c478bd9Sstevel@tonic-gate 			}
7257c478bd9Sstevel@tonic-gate 			error(arg);
7267c478bd9Sstevel@tonic-gate 			break;
7277c478bd9Sstevel@tonic-gate 		case 'G':
7287c478bd9Sstevel@tonic-gate 			newae(h, "-shared");
7297c478bd9Sstevel@tonic-gate 			nolibc = 1;
7307c478bd9Sstevel@tonic-gate 			break;
7317c478bd9Sstevel@tonic-gate 		case 'k':
7327c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-keeptmp") == 0) {
7337c478bd9Sstevel@tonic-gate 				newae(h, "-save-temps");
7347c478bd9Sstevel@tonic-gate 				break;
7357c478bd9Sstevel@tonic-gate 			}
7367c478bd9Sstevel@tonic-gate 			error(arg);
7377c478bd9Sstevel@tonic-gate 			break;
7387c478bd9Sstevel@tonic-gate 		case 'K':
7397c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
7407c478bd9Sstevel@tonic-gate 				if ((arg = *++argv) == NULL || *arg == '\0')
7417c478bd9Sstevel@tonic-gate 					error("-K");
7427c478bd9Sstevel@tonic-gate 				argc--;
7437c478bd9Sstevel@tonic-gate 			} else {
7447c478bd9Sstevel@tonic-gate 				arg += 2;
7457c478bd9Sstevel@tonic-gate 			}
7467c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "pic") == 0) {
7477c478bd9Sstevel@tonic-gate 				newae(h, "-fpic");
7487c478bd9Sstevel@tonic-gate 				pic = 1;
7497c478bd9Sstevel@tonic-gate 				break;
7507c478bd9Sstevel@tonic-gate 			}
7517c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "PIC") == 0) {
7527c478bd9Sstevel@tonic-gate 				newae(h, "-fPIC");
7537c478bd9Sstevel@tonic-gate 				pic = 1;
7547c478bd9Sstevel@tonic-gate 				break;
7557c478bd9Sstevel@tonic-gate 			}
7567c478bd9Sstevel@tonic-gate 			error("-K");
7577c478bd9Sstevel@tonic-gate 			break;
7587c478bd9Sstevel@tonic-gate 		case 'm':
7597c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-mt") == 0) {
7607c478bd9Sstevel@tonic-gate 				newae(h, "-D_REENTRANT");
7617c478bd9Sstevel@tonic-gate 				break;
7627c478bd9Sstevel@tonic-gate 			}
7637c478bd9Sstevel@tonic-gate 			error(arg);
7647c478bd9Sstevel@tonic-gate 			break;
7657c478bd9Sstevel@tonic-gate 		case 'B':	/* linker options */
7667c478bd9Sstevel@tonic-gate 		case 'M':
7677c478bd9Sstevel@tonic-gate 		case 'z':
7687c478bd9Sstevel@tonic-gate 			{
7697c478bd9Sstevel@tonic-gate 				char *opt;
7707c478bd9Sstevel@tonic-gate 				size_t len;
7717c478bd9Sstevel@tonic-gate 				char *s;
7727c478bd9Sstevel@tonic-gate 
7737c478bd9Sstevel@tonic-gate 				if (arglen == 1) {
7747c478bd9Sstevel@tonic-gate 					opt = *++argv;
7757c478bd9Sstevel@tonic-gate 					if (opt == NULL || *opt == '\0')
7767c478bd9Sstevel@tonic-gate 						error(arg);
7777c478bd9Sstevel@tonic-gate 					argc--;
7787c478bd9Sstevel@tonic-gate 				} else {
7797c478bd9Sstevel@tonic-gate 					opt = arg + 2;
7807c478bd9Sstevel@tonic-gate 				}
7817c478bd9Sstevel@tonic-gate 				len = strlen(opt) + 7;
7827c478bd9Sstevel@tonic-gate 				s = malloc(len);
7837c478bd9Sstevel@tonic-gate 				(void) snprintf(s, len, "-Wl,-%c%s", c, opt);
7847c478bd9Sstevel@tonic-gate 				newae(h, s);
7857c478bd9Sstevel@tonic-gate 				free(s);
7867c478bd9Sstevel@tonic-gate 			}
7877c478bd9Sstevel@tonic-gate 			break;
7887c478bd9Sstevel@tonic-gate 		case 'n':
7897c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-noqueue") == 0) {
7907c478bd9Sstevel@tonic-gate 				/*
7917c478bd9Sstevel@tonic-gate 				 * Horrid license server stuff - n/a
7927c478bd9Sstevel@tonic-gate 				 */
7937c478bd9Sstevel@tonic-gate 				break;
7947c478bd9Sstevel@tonic-gate 			}
7957c478bd9Sstevel@tonic-gate 			error(arg);
7967c478bd9Sstevel@tonic-gate 			break;
7977c478bd9Sstevel@tonic-gate 		case 'O':
7987c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
7997c478bd9Sstevel@tonic-gate 				newae(h, "-O");
8007c478bd9Sstevel@tonic-gate 				break;
8017c478bd9Sstevel@tonic-gate 			}
8027c478bd9Sstevel@tonic-gate 			error(arg);
8037c478bd9Sstevel@tonic-gate 			break;
8047c478bd9Sstevel@tonic-gate 		case 'P':
8057c478bd9Sstevel@tonic-gate 			/*
8067c478bd9Sstevel@tonic-gate 			 * We could do '-E -o filename.i', but that's hard,
8077c478bd9Sstevel@tonic-gate 			 * and we don't need it for the case that's triggering
8087c478bd9Sstevel@tonic-gate 			 * this addition.  We'll require the user to specify
8097c478bd9Sstevel@tonic-gate 			 * -o in the Makefile.  If they don't they'll find out
8107c478bd9Sstevel@tonic-gate 			 * in a hurry.
8117c478bd9Sstevel@tonic-gate 			 */
8127c478bd9Sstevel@tonic-gate 			newae(h, "-E");
8137c478bd9Sstevel@tonic-gate 			nolibc = 1;
8147c478bd9Sstevel@tonic-gate 			break;
8157c478bd9Sstevel@tonic-gate 		case 'q':
8167c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-qp") == 0) {
8177c478bd9Sstevel@tonic-gate 				newae(h, "-p");
8187c478bd9Sstevel@tonic-gate 				break;
8197c478bd9Sstevel@tonic-gate 			}
8207c478bd9Sstevel@tonic-gate 			error(arg);
8217c478bd9Sstevel@tonic-gate 			break;
8227c478bd9Sstevel@tonic-gate 		case 's':
8237c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
8247c478bd9Sstevel@tonic-gate 				newae(h, "-Wl,-s");
8257c478bd9Sstevel@tonic-gate 				break;
8267c478bd9Sstevel@tonic-gate 			}
8277c478bd9Sstevel@tonic-gate 			error(arg);
8287c478bd9Sstevel@tonic-gate 			break;
8297c478bd9Sstevel@tonic-gate 		case 'V':
8307c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
8317c478bd9Sstevel@tonic-gate 				echo = 0;
8327c478bd9Sstevel@tonic-gate 				newae(h, "--version");
8337c478bd9Sstevel@tonic-gate 				break;
8347c478bd9Sstevel@tonic-gate 			}
8357c478bd9Sstevel@tonic-gate 			error(arg);
8367c478bd9Sstevel@tonic-gate 			break;
8377c478bd9Sstevel@tonic-gate 		case 'v':
8387c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
8397c478bd9Sstevel@tonic-gate 				warnings(h);
8407c478bd9Sstevel@tonic-gate 				break;
8417c478bd9Sstevel@tonic-gate 			}
8427c478bd9Sstevel@tonic-gate 			error(arg);
8437c478bd9Sstevel@tonic-gate 			break;
8447c478bd9Sstevel@tonic-gate 		case 'W':
8457c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wp,-xc99", 9) == 0) {
8467c478bd9Sstevel@tonic-gate 				/*
8477c478bd9Sstevel@tonic-gate 				 * gcc's preprocessor will accept c99
8487c478bd9Sstevel@tonic-gate 				 * regardless, so accept and ignore.
8497c478bd9Sstevel@tonic-gate 				 */
8507c478bd9Sstevel@tonic-gate 				break;
8517c478bd9Sstevel@tonic-gate 			}
8527c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wa,", 4) == 0 ||
8537c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-Wp,", 4) == 0 ||
8547c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-Wl,", 4) == 0) {
8557c478bd9Sstevel@tonic-gate 				newae(h, arg);
8567c478bd9Sstevel@tonic-gate 				break;
8577c478bd9Sstevel@tonic-gate 			}
8587c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-xc99=pragma") == 0) {
8597c478bd9Sstevel@tonic-gate 				/* (undocumented) enables _Pragma */
8607c478bd9Sstevel@tonic-gate 				break;
8617c478bd9Sstevel@tonic-gate 			}
8627c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-xc99=%none") == 0) {
8637c478bd9Sstevel@tonic-gate 				/*
8647c478bd9Sstevel@tonic-gate 				 * This is a polite way of saying
8657c478bd9Sstevel@tonic-gate 				 * "no c99 constructs allowed!"
8667c478bd9Sstevel@tonic-gate 				 * For now, just accept and ignore this.
8677c478bd9Sstevel@tonic-gate 				 */
8687c478bd9Sstevel@tonic-gate 				break;
8697c478bd9Sstevel@tonic-gate 			}
8707c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-noglobal") == 0) {
8717c478bd9Sstevel@tonic-gate 				/*
8727c478bd9Sstevel@tonic-gate 				 * gcc doesn't prefix local symbols
8737c478bd9Sstevel@tonic-gate 				 * in debug mode, so this is not needed.
8747c478bd9Sstevel@tonic-gate 				 */
8757c478bd9Sstevel@tonic-gate 				break;
8767c478bd9Sstevel@tonic-gate 			}
8777c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-Lt") == 0) {
8787c478bd9Sstevel@tonic-gate 				/*
8797c478bd9Sstevel@tonic-gate 				 * Generate tests at the top of loops.
8807c478bd9Sstevel@tonic-gate 				 * There is no direct gcc equivalent, ignore.
8817c478bd9Sstevel@tonic-gate 				 */
8827c478bd9Sstevel@tonic-gate 				break;
8837c478bd9Sstevel@tonic-gate 			}
8847c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W2,-Rcond_elim") == 0) {
8857c478bd9Sstevel@tonic-gate 				/*
8867c478bd9Sstevel@tonic-gate 				 * Elimination and expansion of conditionals;
8877c478bd9Sstevel@tonic-gate 				 * gcc has no direct equivalent.
8887c478bd9Sstevel@tonic-gate 				 */
8897c478bd9Sstevel@tonic-gate 				break;
8907c478bd9Sstevel@tonic-gate 			}
8917c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Wd,-xsafe=unboundsym") == 0) {
8927c478bd9Sstevel@tonic-gate 				/*
8937c478bd9Sstevel@tonic-gate 				 * Prevents optimizing away checks for
8947c478bd9Sstevel@tonic-gate 				 * unbound weak symbol addresses.  gcc does
8957c478bd9Sstevel@tonic-gate 				 * not do this, so it's not needed.
8967c478bd9Sstevel@tonic-gate 				 */
8977c478bd9Sstevel@tonic-gate 				break;
8987c478bd9Sstevel@tonic-gate 			}
8997c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wc,-xcode=", 11) == 0) {
9007c478bd9Sstevel@tonic-gate 				xlate(h, arg + 11, xcode_tbl);
9017c478bd9Sstevel@tonic-gate 				if (strncmp(arg + 11, "pic", 3) == 0)
9027c478bd9Sstevel@tonic-gate 					pic = 1;
9037c478bd9Sstevel@tonic-gate 				break;
9047c478bd9Sstevel@tonic-gate 			}
9057c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wc,-Qiselect", 13) == 0) {
9067c478bd9Sstevel@tonic-gate 				/*
9077c478bd9Sstevel@tonic-gate 				 * Prevents insertion of register symbols.
9087c478bd9Sstevel@tonic-gate 				 * gcc doesn't do this, so ignore it.
9097c478bd9Sstevel@tonic-gate 				 */
9107c478bd9Sstevel@tonic-gate 				break;
9117c478bd9Sstevel@tonic-gate 			}
9127c478bd9Sstevel@tonic-gate #if defined(__x86)
9137c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Wu,-no_got_reloc") == 0) {
9147c478bd9Sstevel@tonic-gate 				/*
9157c478bd9Sstevel@tonic-gate 				 * Don't create any GOT relocations?
9167c478bd9Sstevel@tonic-gate 				 * Well, gcc doesn't have this degree
9177c478bd9Sstevel@tonic-gate 				 * of control over its pic code ...
9187c478bd9Sstevel@tonic-gate 				 */
9197c478bd9Sstevel@tonic-gate 				break;
9207c478bd9Sstevel@tonic-gate 			}
9217c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Wu,-xmodel=kernel") == 0) {
9227c478bd9Sstevel@tonic-gate 				newae(h, "-ffreestanding");
9237c478bd9Sstevel@tonic-gate 				newae(h, "-mno-red-zone");
9247c478bd9Sstevel@tonic-gate 				model = "-mcmodel=kernel";
9257c478bd9Sstevel@tonic-gate 				nolibc = 1;
9267c478bd9Sstevel@tonic-gate 				break;
9277c478bd9Sstevel@tonic-gate 			}
9287c478bd9Sstevel@tonic-gate #endif	/* __x86 */
9297c478bd9Sstevel@tonic-gate 			error(arg);
9307c478bd9Sstevel@tonic-gate 			break;
9317c478bd9Sstevel@tonic-gate 		case 'X':
9327c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Xa") == 0 ||
9337c478bd9Sstevel@tonic-gate 			    strcmp(arg, "-Xt") == 0) {
9347c478bd9Sstevel@tonic-gate 				Xamode(h);
9357c478bd9Sstevel@tonic-gate 				break;
9367c478bd9Sstevel@tonic-gate 			}
9377c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Xc") == 0) {
9387c478bd9Sstevel@tonic-gate 				Xcmode(h);
9397c478bd9Sstevel@tonic-gate 				break;
9407c478bd9Sstevel@tonic-gate 			}
9417c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Xs") == 0) {
9427c478bd9Sstevel@tonic-gate 				Xsmode(h);
9437c478bd9Sstevel@tonic-gate 				break;
9447c478bd9Sstevel@tonic-gate 			}
9457c478bd9Sstevel@tonic-gate 			error(arg);
9467c478bd9Sstevel@tonic-gate 			break;
9477c478bd9Sstevel@tonic-gate 		case 'x':
9487c478bd9Sstevel@tonic-gate 			if (arglen == 1)
9497c478bd9Sstevel@tonic-gate 				error(arg);
9507c478bd9Sstevel@tonic-gate 			switch (arg[2]) {
9517c478bd9Sstevel@tonic-gate #if defined(__x86)
9527c478bd9Sstevel@tonic-gate 			case '3':
9537c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-x386") == 0) {
9547c478bd9Sstevel@tonic-gate 					newae(h, "-march=i386");
9557c478bd9Sstevel@tonic-gate 					break;
9567c478bd9Sstevel@tonic-gate 				}
9577c478bd9Sstevel@tonic-gate 				error(arg);
9587c478bd9Sstevel@tonic-gate 				break;
9597c478bd9Sstevel@tonic-gate 			case '4':
9607c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-x486") == 0) {
9617c478bd9Sstevel@tonic-gate 					newae(h, "-march=i486");
9627c478bd9Sstevel@tonic-gate 					break;
9637c478bd9Sstevel@tonic-gate 				}
9647c478bd9Sstevel@tonic-gate 				error(arg);
9657c478bd9Sstevel@tonic-gate 				break;
9667c478bd9Sstevel@tonic-gate #endif	/* __x86 */
9677c478bd9Sstevel@tonic-gate 			case 'a':
9687c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xarch=", 7) == 0) {
9697c478bd9Sstevel@tonic-gate 					xlate(h, arg + 7, xarch_tbl);
9707c478bd9Sstevel@tonic-gate 					break;
9717c478bd9Sstevel@tonic-gate 				}
9727c478bd9Sstevel@tonic-gate 				error(arg);
9737c478bd9Sstevel@tonic-gate 				break;
9747c478bd9Sstevel@tonic-gate 			case 'C':
9757c478bd9Sstevel@tonic-gate 				/* Accept C++ style comments -- ignore */
9767c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xCC") == 0)
9777c478bd9Sstevel@tonic-gate 					break;
9787c478bd9Sstevel@tonic-gate 				error(arg);
9797c478bd9Sstevel@tonic-gate 				break;
9807c478bd9Sstevel@tonic-gate 			case 'c':
9817c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xc99=%all", 10) == 0) {
9827c478bd9Sstevel@tonic-gate 					newae(h, "-std=gnu99");
9837c478bd9Sstevel@tonic-gate 					break;
9847c478bd9Sstevel@tonic-gate 				}
9857c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xc99=%none", 11) == 0) {
9867c478bd9Sstevel@tonic-gate 					newae(h, "-std=gnu89");
9877c478bd9Sstevel@tonic-gate 					break;
9887c478bd9Sstevel@tonic-gate 				}
9897c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xchip=", 7) == 0) {
9907c478bd9Sstevel@tonic-gate 					xlate(h, arg + 7, xchip_tbl);
9917c478bd9Sstevel@tonic-gate 					break;
9927c478bd9Sstevel@tonic-gate 				}
9937c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xcode=", 7) == 0) {
9947c478bd9Sstevel@tonic-gate 					xlate(h, arg + 7, xcode_tbl);
9957c478bd9Sstevel@tonic-gate 					if (strncmp(arg + 7, "pic", 3) == 0)
9967c478bd9Sstevel@tonic-gate 						pic = 1;
9977c478bd9Sstevel@tonic-gate 					break;
9987c478bd9Sstevel@tonic-gate 				}
9997c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xcache=", 8) == 0)
10007c478bd9Sstevel@tonic-gate 					break;
10017c478bd9Sstevel@tonic-gate 				error(arg);
10027c478bd9Sstevel@tonic-gate 				break;
10037c478bd9Sstevel@tonic-gate 			case 'd':
10047c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xdepend") == 0)
10057c478bd9Sstevel@tonic-gate 					break;
10067c478bd9Sstevel@tonic-gate 				error(arg);
10077c478bd9Sstevel@tonic-gate 				break;
10087c478bd9Sstevel@tonic-gate 			case 'F':
10097c478bd9Sstevel@tonic-gate 				/* compile for mapfile reordering -- ignore */
10107c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xF") == 0)
10117c478bd9Sstevel@tonic-gate 					break;
10127c478bd9Sstevel@tonic-gate 				error(arg);
10137c478bd9Sstevel@tonic-gate 				break;
10147c478bd9Sstevel@tonic-gate 			case 'i':
10157c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xinline", 8) == 0)
10167c478bd9Sstevel@tonic-gate 					/* No inlining; ignore */
10177c478bd9Sstevel@tonic-gate 					break;
10187c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xildon") == 0 ||
10197c478bd9Sstevel@tonic-gate 				    strcmp(arg, "-xildoff") == 0)
10207c478bd9Sstevel@tonic-gate 					/* No incremental linking; ignore */
10217c478bd9Sstevel@tonic-gate 					break;
10227c478bd9Sstevel@tonic-gate 				error(arg);
10237c478bd9Sstevel@tonic-gate 				break;
10247c478bd9Sstevel@tonic-gate 			case 'M':
10257c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xM") == 0) {
10267c478bd9Sstevel@tonic-gate 					newae(h, "-M");
10277c478bd9Sstevel@tonic-gate 					break;
10287c478bd9Sstevel@tonic-gate 				}
10297c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xM1") == 0) {
10307c478bd9Sstevel@tonic-gate 					newae(h, "-MM");
10317c478bd9Sstevel@tonic-gate 					break;
10327c478bd9Sstevel@tonic-gate 				}
10337c478bd9Sstevel@tonic-gate 				error(arg);
10347c478bd9Sstevel@tonic-gate 				break;
10357c478bd9Sstevel@tonic-gate 			case 'n':
10367c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xnolib") == 0) {
10377c478bd9Sstevel@tonic-gate 					nolibc = 1;
10387c478bd9Sstevel@tonic-gate 					break;
10397c478bd9Sstevel@tonic-gate 				}
10407c478bd9Sstevel@tonic-gate 				error(arg);
10417c478bd9Sstevel@tonic-gate 				break;
10427c478bd9Sstevel@tonic-gate 			case 'O':
10437c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xO", 3) == 0) {
10447c478bd9Sstevel@tonic-gate 					size_t len = strlen(arg);
10457c478bd9Sstevel@tonic-gate 					char *s = malloc(len);
10467c478bd9Sstevel@tonic-gate 					int c = *(arg + 3);
10477c478bd9Sstevel@tonic-gate 					int level;
10487c478bd9Sstevel@tonic-gate 
10497c478bd9Sstevel@tonic-gate 					if (len != 4 || !isdigit(c))
10507c478bd9Sstevel@tonic-gate 						error(arg);
10517c478bd9Sstevel@tonic-gate 
10527c478bd9Sstevel@tonic-gate 					level = atoi(arg + 3);
10537c478bd9Sstevel@tonic-gate 					if (level > 5)
10547c478bd9Sstevel@tonic-gate 						error(arg);
10557c478bd9Sstevel@tonic-gate 					if (level >= 2) {
10567c478bd9Sstevel@tonic-gate 						/*
10577c478bd9Sstevel@tonic-gate 						 * For gcc-3.4.x at -O2 we
10587c478bd9Sstevel@tonic-gate 						 * need to disable optimizations
10597c478bd9Sstevel@tonic-gate 						 * that break ON.
10607c478bd9Sstevel@tonic-gate 						 */
10617c478bd9Sstevel@tonic-gate 						optim_disable(h, level);
10627c478bd9Sstevel@tonic-gate 						/*
10637c478bd9Sstevel@tonic-gate 						 * limit -xO3 to -O2 as well.
10647c478bd9Sstevel@tonic-gate 						 */
10657c478bd9Sstevel@tonic-gate 						level = 2;
10667c478bd9Sstevel@tonic-gate 					}
10677c478bd9Sstevel@tonic-gate 					(void) snprintf(s, len, "-O%d", level);
10687c478bd9Sstevel@tonic-gate 					newae(h, s);
10697c478bd9Sstevel@tonic-gate 					free(s);
10707c478bd9Sstevel@tonic-gate 					break;
10717c478bd9Sstevel@tonic-gate 				}
10727c478bd9Sstevel@tonic-gate 				error(arg);
10737c478bd9Sstevel@tonic-gate 				break;
10747c478bd9Sstevel@tonic-gate 			case 'p':
10757c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xpentium") == 0) {
10767c478bd9Sstevel@tonic-gate 					newae(h, "-march=pentium");
10777c478bd9Sstevel@tonic-gate 					break;
10787c478bd9Sstevel@tonic-gate 				}
10797c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xpg") == 0) {
10807c478bd9Sstevel@tonic-gate 					newae(h, "-pg");
10817c478bd9Sstevel@tonic-gate 					break;
10827c478bd9Sstevel@tonic-gate 				}
10837c478bd9Sstevel@tonic-gate 				error(arg);
10847c478bd9Sstevel@tonic-gate 				break;
10857c478bd9Sstevel@tonic-gate 			case 'r':
10867c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xregs=", 7) == 0) {
10877c478bd9Sstevel@tonic-gate 					xlate(h, arg + 7, xregs_tbl);
10887c478bd9Sstevel@tonic-gate 					break;
10897c478bd9Sstevel@tonic-gate 				}
10907c478bd9Sstevel@tonic-gate 				error(arg);
10917c478bd9Sstevel@tonic-gate 				break;
10927c478bd9Sstevel@tonic-gate 			case 's':
10937c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xs") == 0 ||
10947c478bd9Sstevel@tonic-gate 				    strcmp(arg, "-xspace") == 0 ||
10957c478bd9Sstevel@tonic-gate 				    strcmp(arg, "-xstrconst") == 0)
10967c478bd9Sstevel@tonic-gate 					break;
10977c478bd9Sstevel@tonic-gate 				error(arg);
10987c478bd9Sstevel@tonic-gate 				break;
10997c478bd9Sstevel@tonic-gate 			case 't':
11007c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xtransition") == 0) {
11017c478bd9Sstevel@tonic-gate 					newae(h, "-Wtransition");
11027c478bd9Sstevel@tonic-gate 					break;
11037c478bd9Sstevel@tonic-gate 				}
11047c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xtrigraphs=yes") == 0) {
11057c478bd9Sstevel@tonic-gate 					newae(h, "-trigraphs");
11067c478bd9Sstevel@tonic-gate 					break;
11077c478bd9Sstevel@tonic-gate 				}
11087c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xtrigraphs=no") == 0) {
11097c478bd9Sstevel@tonic-gate 					newae(h, "-notrigraphs");
11107c478bd9Sstevel@tonic-gate 					break;
11117c478bd9Sstevel@tonic-gate 				}
11127c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xtarget=", 9) == 0) {
11137c478bd9Sstevel@tonic-gate 					xlate(h, arg + 9, xtarget_tbl);
11147c478bd9Sstevel@tonic-gate 					break;
11157c478bd9Sstevel@tonic-gate 				}
11167c478bd9Sstevel@tonic-gate 				error(arg);
11177c478bd9Sstevel@tonic-gate 				break;
11187c478bd9Sstevel@tonic-gate 			case 'b':
11197c478bd9Sstevel@tonic-gate 			case 'e':
11207c478bd9Sstevel@tonic-gate 			case 'h':
11217c478bd9Sstevel@tonic-gate 			case 'l':
11227c478bd9Sstevel@tonic-gate 			default:
11237c478bd9Sstevel@tonic-gate 				error(arg);
11247c478bd9Sstevel@tonic-gate 				break;
11257c478bd9Sstevel@tonic-gate 			}
11267c478bd9Sstevel@tonic-gate 			break;
11277c478bd9Sstevel@tonic-gate 		case 'Y':
11287c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
11297c478bd9Sstevel@tonic-gate 				if ((arg = *++argv) == NULL || *arg == '\0')
11307c478bd9Sstevel@tonic-gate 					error("-Y");
11317c478bd9Sstevel@tonic-gate 				argc--;
11327c478bd9Sstevel@tonic-gate 				arglen = strlen(arg + 1);
11337c478bd9Sstevel@tonic-gate 			} else {
11347c478bd9Sstevel@tonic-gate 				arg += 2;
11357c478bd9Sstevel@tonic-gate 			}
11367c478bd9Sstevel@tonic-gate 			/* Just ignore -YS,... for now */
11377c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "S,", 2) == 0)
11387c478bd9Sstevel@tonic-gate 				break;
11397c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "l,", 2) == 0) {
11407c478bd9Sstevel@tonic-gate 				char *s = strdup(arg);
11417c478bd9Sstevel@tonic-gate 				s[0] = '-';
11427c478bd9Sstevel@tonic-gate 				s[1] = 'B';
11437c478bd9Sstevel@tonic-gate 				newae(h, s);
11447c478bd9Sstevel@tonic-gate 				free(s);
11457c478bd9Sstevel@tonic-gate 				break;
11467c478bd9Sstevel@tonic-gate 			}
11477c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "I,", 2) == 0) {
11487c478bd9Sstevel@tonic-gate 				char *s = strdup(arg);
11497c478bd9Sstevel@tonic-gate 				s[0] = '-';
11507c478bd9Sstevel@tonic-gate 				s[1] = 'I';
11517c478bd9Sstevel@tonic-gate 				newae(h, "-nostdinc");
11527c478bd9Sstevel@tonic-gate 				newae(h, s);
11537c478bd9Sstevel@tonic-gate 				free(s);
11547c478bd9Sstevel@tonic-gate 				break;
11557c478bd9Sstevel@tonic-gate 			}
11567c478bd9Sstevel@tonic-gate 			error(arg);
11577c478bd9Sstevel@tonic-gate 			break;
11587c478bd9Sstevel@tonic-gate 		case 'Q':
11597c478bd9Sstevel@tonic-gate 			/*
11607c478bd9Sstevel@tonic-gate 			 * We could map -Qy into -Wl,-Qy etc.
11617c478bd9Sstevel@tonic-gate 			 */
11627c478bd9Sstevel@tonic-gate 		default:
11637c478bd9Sstevel@tonic-gate 			error(arg);
11647c478bd9Sstevel@tonic-gate 			break;
11657c478bd9Sstevel@tonic-gate 		}
11667c478bd9Sstevel@tonic-gate 	}
11677c478bd9Sstevel@tonic-gate 
11687c478bd9Sstevel@tonic-gate 	if (model && !pic)
11697c478bd9Sstevel@tonic-gate 		newae(h, model);
11707c478bd9Sstevel@tonic-gate 	if (!nolibc)
11717c478bd9Sstevel@tonic-gate 		newae(h, "-lc");
11727c478bd9Sstevel@tonic-gate }
11737c478bd9Sstevel@tonic-gate 
11747c478bd9Sstevel@tonic-gate /* ARGSUSED4 */
11757c478bd9Sstevel@tonic-gate static void
11767c478bd9Sstevel@tonic-gate do_cc(const char *dir, const char *cmd, int argc, char **argv,
11777c478bd9Sstevel@tonic-gate     struct aelist *h, int cplusplus)
11787c478bd9Sstevel@tonic-gate {
11797c478bd9Sstevel@tonic-gate 	char *program;
11807c478bd9Sstevel@tonic-gate 	size_t len = strlen(dir) + strlen(cmd) + 2;
11817c478bd9Sstevel@tonic-gate 
11827c478bd9Sstevel@tonic-gate 	program = malloc(len);
11837c478bd9Sstevel@tonic-gate 	(void) snprintf(program, len, "%s/%s", dir, cmd);
11847c478bd9Sstevel@tonic-gate 
11857c478bd9Sstevel@tonic-gate 	/*
11867c478bd9Sstevel@tonic-gate 	 * This is pretty simple.
11877c478bd9Sstevel@tonic-gate 	 * We just have to recognize -V, -_noecho, -_compiler, -_cc= and -_gcc=
11887c478bd9Sstevel@tonic-gate 	 */
11897c478bd9Sstevel@tonic-gate 	newae(h, program);
11907c478bd9Sstevel@tonic-gate 
11917c478bd9Sstevel@tonic-gate 	while (--argc > 0) {
11927c478bd9Sstevel@tonic-gate 		char *arg = *++argv;
11937c478bd9Sstevel@tonic-gate 
11947c478bd9Sstevel@tonic-gate 		if (*arg != '-') {
11957c478bd9Sstevel@tonic-gate 			newae(h, arg);
11967c478bd9Sstevel@tonic-gate 		} else if (*(arg + 1) != '_') {
11977c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-V") == 0)
11987c478bd9Sstevel@tonic-gate 				echo = 0;
11997c478bd9Sstevel@tonic-gate 			newae(h, arg);
12007c478bd9Sstevel@tonic-gate 		} else if (strcmp(arg, "-_noecho") == 0) {
12017c478bd9Sstevel@tonic-gate 			echo = 0;
12027c478bd9Sstevel@tonic-gate 		} else if (strcmp(arg, "-_compiler") == 0) {
12037c478bd9Sstevel@tonic-gate 			(void) printf("%s\n", program);
12047c478bd9Sstevel@tonic-gate 			exit(0);
12057c478bd9Sstevel@tonic-gate 		} else if (strncmp(arg, "-_cc=", 5) == 0 ||
12067c478bd9Sstevel@tonic-gate 		    strncmp(arg, "-_CC=", 5) == 0) {
12077c478bd9Sstevel@tonic-gate 			newae(h, arg + 5);
12087c478bd9Sstevel@tonic-gate 		} else if (strncmp(arg, "-_gcc=", 6) != 0 &&
12097c478bd9Sstevel@tonic-gate 		    strncmp(arg, "-_g++=", 6) != 0) {
12107c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
12117c478bd9Sstevel@tonic-gate 			    "%s: invalid argument '%s'\n", progname, arg);
12127c478bd9Sstevel@tonic-gate 			exit(2);
12137c478bd9Sstevel@tonic-gate 		}
12147c478bd9Sstevel@tonic-gate 	}
12157c478bd9Sstevel@tonic-gate }
12167c478bd9Sstevel@tonic-gate 
12177c478bd9Sstevel@tonic-gate int
12187c478bd9Sstevel@tonic-gate main(int argc, char **argv)
12197c478bd9Sstevel@tonic-gate {
12207c478bd9Sstevel@tonic-gate 	struct aelist *h = newael();
12217c478bd9Sstevel@tonic-gate 	const char *dir;
12227c478bd9Sstevel@tonic-gate 	int ac;
12237c478bd9Sstevel@tonic-gate 	char **newargv;
12247c478bd9Sstevel@tonic-gate 	struct ae *a;
12257c478bd9Sstevel@tonic-gate 	char cc_buf[MAXPATHLEN], gcc_buf[MAXPATHLEN];
12267c478bd9Sstevel@tonic-gate 
12277c478bd9Sstevel@tonic-gate 	if ((progname = strrchr(argv[0], '/')) == NULL)
12287c478bd9Sstevel@tonic-gate 		progname = argv[0];
12297c478bd9Sstevel@tonic-gate 	else
12307c478bd9Sstevel@tonic-gate 		progname++;
12317c478bd9Sstevel@tonic-gate 
12327c478bd9Sstevel@tonic-gate 	default_cc_dir = DEFAULT_CC_DIR;
12337c478bd9Sstevel@tonic-gate 	default_gcc_dir = DEFAULT_GCC_DIR;
12347c478bd9Sstevel@tonic-gate 	default_cplusplus_dir = DEFAULT_CPLUSPLUS_DIR;
12357c478bd9Sstevel@tonic-gate 	default_gplusplus_dir = DEFAULT_GPLUSPLUS_DIR;
12367c478bd9Sstevel@tonic-gate 
12377c478bd9Sstevel@tonic-gate 	/*
12387c478bd9Sstevel@tonic-gate 	 * Figure out where to get our tools from.  This depends on
12397c478bd9Sstevel@tonic-gate 	 * the environment variables set at run time.
12407c478bd9Sstevel@tonic-gate 	 */
12417c478bd9Sstevel@tonic-gate 	if ((dir = getenv("SPRO_VROOT")) != NULL) {
12427c478bd9Sstevel@tonic-gate 		(void) snprintf(cc_buf, MAXPATHLEN, "%s/bin", dir);
12437c478bd9Sstevel@tonic-gate 	} else if ((dir = getenv("SPRO_ROOT")) != NULL) {
12447c478bd9Sstevel@tonic-gate 		(void) snprintf(cc_buf, MAXPATHLEN, "%s/SOS8/bin", dir);
12457c478bd9Sstevel@tonic-gate 	} else if ((dir = getenv("BUILD_TOOLS")) != NULL) {
12467c478bd9Sstevel@tonic-gate 		(void) snprintf(cc_buf, MAXPATHLEN,
12477c478bd9Sstevel@tonic-gate 		    "%s/SUNWspro/SOS8/bin", dir);
12487c478bd9Sstevel@tonic-gate 	}
12497c478bd9Sstevel@tonic-gate 	if (dir != NULL)
12507c478bd9Sstevel@tonic-gate 		default_cc_dir = (char *)cc_buf;
12517c478bd9Sstevel@tonic-gate 
12527c478bd9Sstevel@tonic-gate 	if ((dir = getenv("GNU_ROOT")) != NULL) {
12537c478bd9Sstevel@tonic-gate 		(void) snprintf(gcc_buf, MAXPATHLEN, "%s/bin", dir);
12547c478bd9Sstevel@tonic-gate 		default_gcc_dir = (char *)gcc_buf;
12557c478bd9Sstevel@tonic-gate 	}
12567c478bd9Sstevel@tonic-gate 
12577c478bd9Sstevel@tonic-gate 	default_cplusplus_dir = default_cc_dir;
12587c478bd9Sstevel@tonic-gate 	default_gplusplus_dir = default_gcc_dir;
12597c478bd9Sstevel@tonic-gate 
12607c478bd9Sstevel@tonic-gate 	/*
12617c478bd9Sstevel@tonic-gate 	 * The first argument must be one of "-_cc", "-_gcc", "-_CC", or "-_g++"
12627c478bd9Sstevel@tonic-gate 	 */
12637c478bd9Sstevel@tonic-gate 	if (argc == 1)
12647c478bd9Sstevel@tonic-gate 		usage();
12657c478bd9Sstevel@tonic-gate 	argc--;
12667c478bd9Sstevel@tonic-gate 	argv++;
12677c478bd9Sstevel@tonic-gate 	if (strcmp(argv[0], "-_cc") == 0) {
12687c478bd9Sstevel@tonic-gate 		if ((dir = getenv("CW_CC_DIR")) == NULL)
12697c478bd9Sstevel@tonic-gate 			dir = default_cc_dir;
12707c478bd9Sstevel@tonic-gate 		do_cc(dir, "cc", argc, argv, h, 0);
12717c478bd9Sstevel@tonic-gate 	} else if (strcmp(argv[0], "-_gcc") == 0) {
12727c478bd9Sstevel@tonic-gate 		if ((dir = getenv("CW_GCC_DIR")) == NULL)
12737c478bd9Sstevel@tonic-gate 			dir = default_gcc_dir;
12747c478bd9Sstevel@tonic-gate 		do_gcc(dir, "gcc", argc, argv, h, 0);
12757c478bd9Sstevel@tonic-gate 	} else if (strcmp(argv[0], "-_CC") == 0) {
12767c478bd9Sstevel@tonic-gate 		if ((dir = getenv("CW_CPLUSPLUS_DIR")) == NULL)
12777c478bd9Sstevel@tonic-gate 			dir = default_cplusplus_dir;
12787c478bd9Sstevel@tonic-gate 		do_cc(dir, "CC", argc, argv, h, 1);
12797c478bd9Sstevel@tonic-gate 	} else if (strcmp(argv[0], "-_g++") == 0) {
12807c478bd9Sstevel@tonic-gate 		if ((dir = getenv("CW_GPLUSPLUS_DIR")) == NULL)
12817c478bd9Sstevel@tonic-gate 			dir = default_gplusplus_dir;
12827c478bd9Sstevel@tonic-gate 		do_gcc(dir, "g++", argc, argv, h, 1);
12837c478bd9Sstevel@tonic-gate 	} else {
12847c478bd9Sstevel@tonic-gate 		/* assume "-_gcc" by default */
12857c478bd9Sstevel@tonic-gate 		argc++;
12867c478bd9Sstevel@tonic-gate 		argv--;
12877c478bd9Sstevel@tonic-gate 		if ((dir = getenv("CW_GCC_DIR")) == NULL)
12887c478bd9Sstevel@tonic-gate 			dir = default_gcc_dir;
12897c478bd9Sstevel@tonic-gate 		do_gcc(dir, "gcc", argc, argv, h, 0);
12907c478bd9Sstevel@tonic-gate 	}
12917c478bd9Sstevel@tonic-gate 
12927c478bd9Sstevel@tonic-gate 	newargv = calloc(sizeof (*newargv), newargc + 1);
12937c478bd9Sstevel@tonic-gate 
12947c478bd9Sstevel@tonic-gate 	if (echo)
12957c478bd9Sstevel@tonic-gate 		(void) printf("+ ");
12967c478bd9Sstevel@tonic-gate 
12977c478bd9Sstevel@tonic-gate 	for (ac = 0, a = h->ael_head; a; a = a->ae_next, ac++) {
12987c478bd9Sstevel@tonic-gate 		newargv[ac] = a->ae_arg;
12997c478bd9Sstevel@tonic-gate 		if (echo)
13007c478bd9Sstevel@tonic-gate 			(void) printf("%s ", a->ae_arg);
13017c478bd9Sstevel@tonic-gate 		if (a == h->ael_tail)
13027c478bd9Sstevel@tonic-gate 			break;
13037c478bd9Sstevel@tonic-gate 	}
13047c478bd9Sstevel@tonic-gate 
13057c478bd9Sstevel@tonic-gate 	if (echo) {
13067c478bd9Sstevel@tonic-gate 		(void) printf("\n");
13077c478bd9Sstevel@tonic-gate 		(void) fflush(stdout);
13087c478bd9Sstevel@tonic-gate 	}
13097c478bd9Sstevel@tonic-gate 
13107c478bd9Sstevel@tonic-gate 	/*
13117c478bd9Sstevel@tonic-gate 	 * Here goes ..
13127c478bd9Sstevel@tonic-gate 	 */
13137c478bd9Sstevel@tonic-gate 	(void) execvp(newargv[0], newargv);
13147c478bd9Sstevel@tonic-gate 
13157c478bd9Sstevel@tonic-gate 	/*
13167c478bd9Sstevel@tonic-gate 	 * execvp() returns only on error.
13177c478bd9Sstevel@tonic-gate 	 */
13187c478bd9Sstevel@tonic-gate 	perror("execvp");
13197c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "%s: couldn't run %s\n",
13207c478bd9Sstevel@tonic-gate 	    progname, newargv[0]);
13217c478bd9Sstevel@tonic-gate 	return (4);
13227c478bd9Sstevel@tonic-gate }
1323