xref: /illumos-gate/usr/src/tools/cw/cw.c (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * Wrapper for the GNU C compiler to make it accept the Sun C compiler
31*7c478bd9Sstevel@tonic-gate  * arguments where possible.
32*7c478bd9Sstevel@tonic-gate  *
33*7c478bd9Sstevel@tonic-gate  * Since the translation is inexact, this is something of a work-in-progress.
34*7c478bd9Sstevel@tonic-gate  */
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate /*
37*7c478bd9Sstevel@tonic-gate  * -#		Verbose mode
38*7c478bd9Sstevel@tonic-gate  * -###		Show compiler commands built by driver, no compilation
39*7c478bd9Sstevel@tonic-gate  * -A<name[(tokens)]>	Preprocessor predicate assertion
40*7c478bd9Sstevel@tonic-gate  * -B<[static|dynamic]>	Specify dynamic or static binding
41*7c478bd9Sstevel@tonic-gate  * -C		Prevent preprocessor from removing comments
42*7c478bd9Sstevel@tonic-gate  * -c		Compile only - produce .o files, suppress linking
43*7c478bd9Sstevel@tonic-gate  * -cg92	Alias for -xtarget=ss1000
44*7c478bd9Sstevel@tonic-gate  * -D<name[=token]>	Associate name with token as if by #define
45*7c478bd9Sstevel@tonic-gate  * -d[y|n]	dynamic [-dy] or static [-dn] option to linker
46*7c478bd9Sstevel@tonic-gate  * -E		Compile source through preprocessor only, output to stdout
47*7c478bd9Sstevel@tonic-gate  * -erroff=<t>	Suppress warnings specified by tags t(%none, %all, <tag list>)
48*7c478bd9Sstevel@tonic-gate  * -errtags=<a>	Display messages with tags a(no, yes)
49*7c478bd9Sstevel@tonic-gate  * -errwarn=<t>	Treats warnings specified by tags t(%none, %all, <tag list>)
50*7c478bd9Sstevel@tonic-gate  *		as errors
51*7c478bd9Sstevel@tonic-gate  * -fast	Optimize using a selection of options
52*7c478bd9Sstevel@tonic-gate  * -fd		Report old-style function definitions and declarations
53*7c478bd9Sstevel@tonic-gate  * -flags	Show this summary of compiler options
54*7c478bd9Sstevel@tonic-gate  * -fnonstd	Initialize floating-point hardware to non-standard preferences
55*7c478bd9Sstevel@tonic-gate  * -fns[=<yes|no>] Select non-standard floating point mode
56*7c478bd9Sstevel@tonic-gate  * -fprecision=<p> Set FP rounding precision mode p(single, double, extended)
57*7c478bd9Sstevel@tonic-gate  * -fround=<r>	Select the IEEE rounding mode in effect at startup
58*7c478bd9Sstevel@tonic-gate  * -fsimple[=<n>] Select floating-point optimization preferences <n>
59*7c478bd9Sstevel@tonic-gate  * -fsingle	Use single-precision arithmetic (-Xt and -Xs modes only)
60*7c478bd9Sstevel@tonic-gate  * -ftrap=<t>	Select floating-point trapping mode in effect at startup
61*7c478bd9Sstevel@tonic-gate  * -fstore	force floating pt. values to target precision on assignment
62*7c478bd9Sstevel@tonic-gate  * -G		Build a dynamic shared library
63*7c478bd9Sstevel@tonic-gate  * -g		Compile for debugging
64*7c478bd9Sstevel@tonic-gate  * -H		Print path name of each file included during compilation
65*7c478bd9Sstevel@tonic-gate  * -h <name>	Assign <name> to generated dynamic shared library
66*7c478bd9Sstevel@tonic-gate  * -I<dir>	Add <dir> to preprocessor #include file search path
67*7c478bd9Sstevel@tonic-gate  * -i		Passed to linker to ignore any LD_LIBRARY_PATH setting
68*7c478bd9Sstevel@tonic-gate  * -keeptmp	Keep temporary files created during compilation
69*7c478bd9Sstevel@tonic-gate  * -KPIC	Compile position independent code with 32-bit addresses
70*7c478bd9Sstevel@tonic-gate  * -Kpic	Compile position independent code
71*7c478bd9Sstevel@tonic-gate  * -L<dir>	Pass to linker to add <dir> to the library search path
72*7c478bd9Sstevel@tonic-gate  * -l<name>	Link with library lib<name>.a or lib<name>.so
73*7c478bd9Sstevel@tonic-gate  * -mc		Remove duplicate strings from .comment section of output files
74*7c478bd9Sstevel@tonic-gate  * -mr		Remove all strings from .comment section of output files
75*7c478bd9Sstevel@tonic-gate  * -mr,"string"	Remove all strings and append "string" to .comment section
76*7c478bd9Sstevel@tonic-gate  * -mt		Specify options needed when compiling multi-threaded code
77*7c478bd9Sstevel@tonic-gate  * -native	Find available processor, generate code accordingly
78*7c478bd9Sstevel@tonic-gate  * -nofstore	Do not force floating pt. values to target precision
79*7c478bd9Sstevel@tonic-gate  *		on assignment
80*7c478bd9Sstevel@tonic-gate  * -nolib	Same as -xnolib
81*7c478bd9Sstevel@tonic-gate  * -noqueue	Disable queuing of compiler license requests
82*7c478bd9Sstevel@tonic-gate  * -norunpath	Do not build in a runtime path for shared libraries
83*7c478bd9Sstevel@tonic-gate  * -O		Use default optimization level (-xO2)
84*7c478bd9Sstevel@tonic-gate  * -o <outputfile> Set name of output file to <outputfile>
85*7c478bd9Sstevel@tonic-gate  * -P		Compile source through preprocessor only, output to .i  file
86*7c478bd9Sstevel@tonic-gate  * -PIC		Alias for -KPIC or -xcode=pic32
87*7c478bd9Sstevel@tonic-gate  * -p		Compile for profiling with prof
88*7c478bd9Sstevel@tonic-gate  * -pic		Alias for -Kpic or -xcode=pic13
89*7c478bd9Sstevel@tonic-gate  * -Q[y|n]	Emit/don't emit identification info to output file
90*7c478bd9Sstevel@tonic-gate  * -qp		Compile for profiling with prof
91*7c478bd9Sstevel@tonic-gate  * -R<dir[:dir]> Build runtime search path list into executable
92*7c478bd9Sstevel@tonic-gate  * -S		Compile and only generate assembly code (.s)
93*7c478bd9Sstevel@tonic-gate  * -s		Strip symbol table from the executable file
94*7c478bd9Sstevel@tonic-gate  * -U<name>	Delete initial definition of preprocessor symbol <name>
95*7c478bd9Sstevel@tonic-gate  * -V		Report version number of each compilation phase
96*7c478bd9Sstevel@tonic-gate  * -v		Do stricter semantic checking
97*7c478bd9Sstevel@tonic-gate  * -W<c>,<arg>	Pass <arg> to specified component <c> (a,l,m,p,0,2,h,i,u)
98*7c478bd9Sstevel@tonic-gate  * -w		Suppress compiler warning messages
99*7c478bd9Sstevel@tonic-gate  * -Xa		Compile assuming ANSI C conformance, allow K & R extensions
100*7c478bd9Sstevel@tonic-gate  *		(default mode)
101*7c478bd9Sstevel@tonic-gate  * -Xc		Compile assuming strict ANSI C conformance
102*7c478bd9Sstevel@tonic-gate  * -Xs		Compile assuming (pre-ANSI) K & R C style code
103*7c478bd9Sstevel@tonic-gate  * -Xt		Compile assuming K & R conformance, allow ANSI C
104*7c478bd9Sstevel@tonic-gate  * -x386	Generate code for the 80386 processor
105*7c478bd9Sstevel@tonic-gate  * -x486	Generate code for the 80486 processor
106*7c478bd9Sstevel@tonic-gate  * -xarch=<a>	Specify target architecture instruction set
107*7c478bd9Sstevel@tonic-gate  * -xbuiltin[=<b>] When profitable inline, or substitute intrinisic functions
108*7c478bd9Sstevel@tonic-gate  *		for system functions, b={%all,%none}
109*7c478bd9Sstevel@tonic-gate  * -xCC		Accept C++ style comments
110*7c478bd9Sstevel@tonic-gate  * -xchar_byte_order=<o> Specify multi-char byte order <o> (default, high, low)
111*7c478bd9Sstevel@tonic-gate  * -xchip=<c>	Specify the target processor for use by the optimizer
112*7c478bd9Sstevel@tonic-gate  * -xcode=<c>	Generate different code for forming addresses
113*7c478bd9Sstevel@tonic-gate  * -xcrossfile[=<n>] Enable optimization and inlining across source files,
114*7c478bd9Sstevel@tonic-gate  *		n={0|1}
115*7c478bd9Sstevel@tonic-gate  * -xe		Perform only syntax/semantic checking, no code generation
116*7c478bd9Sstevel@tonic-gate  * -xF		Compile for later mapfile reordering
117*7c478bd9Sstevel@tonic-gate  * -xhelp=<f>	Display on-line help information f(flags, readme, errors)
118*7c478bd9Sstevel@tonic-gate  * -xildoff	Cancel -xildon
119*7c478bd9Sstevel@tonic-gate  * -xildon	Enable use of the incremental linker, ild
120*7c478bd9Sstevel@tonic-gate  * -xinline=[<a>,...,<a>]  Attempt inlining of specified user routines,
121*7c478bd9Sstevel@tonic-gate  *		<a>={%auto,func,no%func}
122*7c478bd9Sstevel@tonic-gate  * -xlibmieee	Force IEEE 754 return values for math routines in
123*7c478bd9Sstevel@tonic-gate  *		exceptional cases
124*7c478bd9Sstevel@tonic-gate  * -xlibmil	Inline selected libm math routines for optimization
125*7c478bd9Sstevel@tonic-gate  * -xlic_lib=sunperf	Link in the Sun supplied performance libraries
126*7c478bd9Sstevel@tonic-gate  * -xlicinfo	Show license server information
127*7c478bd9Sstevel@tonic-gate  * -xM		Generate makefile dependencies
128*7c478bd9Sstevel@tonic-gate  * -xM1		Generate makefile dependencies, but exclude /usr/include
129*7c478bd9Sstevel@tonic-gate  * -xmaxopt=[off,1,2,3,4,5] maximum optimization level allowed on #pragma opt
130*7c478bd9Sstevel@tonic-gate  * -xnolib	Do not link with default system libraries
131*7c478bd9Sstevel@tonic-gate  * -xnolibmil	Cancel -xlibmil on command line
132*7c478bd9Sstevel@tonic-gate  * -xO<n>	Generate optimized code (n={1|2|3|4|5})
133*7c478bd9Sstevel@tonic-gate  * -xP		Print prototypes for function definitions
134*7c478bd9Sstevel@tonic-gate  * -xpentium	Generate code for the pentium processor
135*7c478bd9Sstevel@tonic-gate  * -xpg		Compile for profiling with gprof
136*7c478bd9Sstevel@tonic-gate  * -xprofile=<p> Collect data for a profile or use a profile to optimize
137*7c478bd9Sstevel@tonic-gate  *		<p>={{collect,use}[:<path>],tcov}
138*7c478bd9Sstevel@tonic-gate  * -xregs=<r>	Control register allocation
139*7c478bd9Sstevel@tonic-gate  * -xs		Allow debugging without object (.o) files
140*7c478bd9Sstevel@tonic-gate  * -xsb		Compile for use with the WorkShop source browser
141*7c478bd9Sstevel@tonic-gate  * -xsbfast	Generate only WorkShop source browser info, no compilation
142*7c478bd9Sstevel@tonic-gate  * -xsfpconst	Represent unsuffixed floating point constants as single
143*7c478bd9Sstevel@tonic-gate  *		precision
144*7c478bd9Sstevel@tonic-gate  * -xspace	Do not do optimizations that increase code size
145*7c478bd9Sstevel@tonic-gate  * -xstrconst	Place string literals into read-only data segment
146*7c478bd9Sstevel@tonic-gate  * -xtarget=<t>	Specify target system for optimization
147*7c478bd9Sstevel@tonic-gate  * -xtemp=<dir>	Set directory for temporary files to <dir>
148*7c478bd9Sstevel@tonic-gate  * -xtime	Report the execution time for each compilation phase
149*7c478bd9Sstevel@tonic-gate  * -xtransition	Emit warnings for differences between K&R C and ANSI C
150*7c478bd9Sstevel@tonic-gate  * -xtrigraphs[=<yes|no>] Enable|disable trigraph translation
151*7c478bd9Sstevel@tonic-gate  * -xunroll=n	Enable unrolling loops n times where possible
152*7c478bd9Sstevel@tonic-gate  * -Y<c>,<dir>	Specify <dir> for location of component <c> (a,l,m,p,0,h,i,u)
153*7c478bd9Sstevel@tonic-gate  * -YA,<dir>	Change default directory searched for components
154*7c478bd9Sstevel@tonic-gate  * -YI,<dir>	Change default directory searched for include files
155*7c478bd9Sstevel@tonic-gate  * -YP,<dir>	Change default directory for finding libraries files
156*7c478bd9Sstevel@tonic-gate  * -YS,<dir>	Change default directory for startup object files
157*7c478bd9Sstevel@tonic-gate  */
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate /*
160*7c478bd9Sstevel@tonic-gate  * Translation table:
161*7c478bd9Sstevel@tonic-gate  */
162*7c478bd9Sstevel@tonic-gate /*
163*7c478bd9Sstevel@tonic-gate  * -#				-v
164*7c478bd9Sstevel@tonic-gate  * -###				error
165*7c478bd9Sstevel@tonic-gate  * -A<name[(tokens)]>		pass-thru
166*7c478bd9Sstevel@tonic-gate  * -B<[static|dynamic]>		pass-thru (syntax error for anything else)
167*7c478bd9Sstevel@tonic-gate  * -C				pass-thru
168*7c478bd9Sstevel@tonic-gate  * -c				pass-thru
169*7c478bd9Sstevel@tonic-gate  * -cg92			-m32 -mcpu=v8 -mtune=supersparc (SPARC only)
170*7c478bd9Sstevel@tonic-gate  * -D<name[=token]>		pass-thru
171*7c478bd9Sstevel@tonic-gate  * -dy or -dn			-Wl,-dy or -Wl,-dn
172*7c478bd9Sstevel@tonic-gate  * -E				pass-thru
173*7c478bd9Sstevel@tonic-gate  * -erroff=E_EMPTY_TRANSLATION_UNIT ignore
174*7c478bd9Sstevel@tonic-gate  * -errtags=%all		-Wall
175*7c478bd9Sstevel@tonic-gate  * -errwarn=%all		-Werror else -Wno-error
176*7c478bd9Sstevel@tonic-gate  * -fast			error
177*7c478bd9Sstevel@tonic-gate  * -fd				error
178*7c478bd9Sstevel@tonic-gate  * -flags			--help
179*7c478bd9Sstevel@tonic-gate  * -fnonstd			error
180*7c478bd9Sstevel@tonic-gate  * -fns[=<yes|no>]		error
181*7c478bd9Sstevel@tonic-gate  * -fprecision=<p>		error
182*7c478bd9Sstevel@tonic-gate  * -fround=<r>			error
183*7c478bd9Sstevel@tonic-gate  * -fsimple[=<n>]		error
184*7c478bd9Sstevel@tonic-gate  * -fsingle[=<n>]		error
185*7c478bd9Sstevel@tonic-gate  * -ftrap=<t>			error
186*7c478bd9Sstevel@tonic-gate  * -fstore			error
187*7c478bd9Sstevel@tonic-gate  * -G				pass-thru
188*7c478bd9Sstevel@tonic-gate  * -g				pass-thru
189*7c478bd9Sstevel@tonic-gate  * -H				pass-thru
190*7c478bd9Sstevel@tonic-gate  * -h <name>			pass-thru
191*7c478bd9Sstevel@tonic-gate  * -I<dir>			pass-thru
192*7c478bd9Sstevel@tonic-gate  * -i				pass-thru
193*7c478bd9Sstevel@tonic-gate  * -keeptmp			-save-temps
194*7c478bd9Sstevel@tonic-gate  * -KPIC			-fPIC
195*7c478bd9Sstevel@tonic-gate  * -Kpic			-fpic
196*7c478bd9Sstevel@tonic-gate  * -L<dir>			pass-thru
197*7c478bd9Sstevel@tonic-gate  * -l<name>			pass-thru
198*7c478bd9Sstevel@tonic-gate  * -mc				error
199*7c478bd9Sstevel@tonic-gate  * -mr				error
200*7c478bd9Sstevel@tonic-gate  * -mr,"string"			error
201*7c478bd9Sstevel@tonic-gate  * -mt				-D_REENTRANT
202*7c478bd9Sstevel@tonic-gate  * -native			error
203*7c478bd9Sstevel@tonic-gate  * -nofstore			error
204*7c478bd9Sstevel@tonic-gate  * -nolib			-nodefaultlibs
205*7c478bd9Sstevel@tonic-gate  * -noqueue			ignore
206*7c478bd9Sstevel@tonic-gate  * -norunpath			ignore
207*7c478bd9Sstevel@tonic-gate  * -O				-O2
208*7c478bd9Sstevel@tonic-gate  * -o <outputfile>		pass-thru
209*7c478bd9Sstevel@tonic-gate  * -P				-E -o filename.i (or error)
210*7c478bd9Sstevel@tonic-gate  * -PIC				-fPIC (C++ only)
211*7c478bd9Sstevel@tonic-gate  * -p				pass-thru
212*7c478bd9Sstevel@tonic-gate  * -pic				-fpic (C++ only)
213*7c478bd9Sstevel@tonic-gate  * -Q[y|n]			error
214*7c478bd9Sstevel@tonic-gate  * -qp				-p
215*7c478bd9Sstevel@tonic-gate  * -R<dir[:dir]>		pass-thru
216*7c478bd9Sstevel@tonic-gate  * -S				pass-thru
217*7c478bd9Sstevel@tonic-gate  * -s				-Wl,-s
218*7c478bd9Sstevel@tonic-gate  * -U<name>			pass-thru
219*7c478bd9Sstevel@tonic-gate  * -V				--version
220*7c478bd9Sstevel@tonic-gate  * -v				-Wall
221*7c478bd9Sstevel@tonic-gate  * -Wa,<arg>			pass-thru
222*7c478bd9Sstevel@tonic-gate  * -Wp,<arg>			pass-thru except -xc99=<a>
223*7c478bd9Sstevel@tonic-gate  * -Wl,<arg>			pass-thru
224*7c478bd9Sstevel@tonic-gate  * -W{m,0,2,h,i,u>		error/ignore
225*7c478bd9Sstevel@tonic-gate  * -Wu,-xmodel=kernel		-ffreestanding -mcmodel=kernel -mno-red-zone
226*7c478bd9Sstevel@tonic-gate  * -w				pass-thru
227*7c478bd9Sstevel@tonic-gate  * -Xa				-std=iso9899:199409 or -ansi
228*7c478bd9Sstevel@tonic-gate  * -Xc				-ansi -pedantic
229*7c478bd9Sstevel@tonic-gate  * -Xt				error
230*7c478bd9Sstevel@tonic-gate  * -Xs				-traditional -std=c89
231*7c478bd9Sstevel@tonic-gate  * -x386			-march=i386 (x86 only)
232*7c478bd9Sstevel@tonic-gate  * -x486			-march=i486 (x86 only)
233*7c478bd9Sstevel@tonic-gate  * -xarch=<a>			table
234*7c478bd9Sstevel@tonic-gate  * -xbuiltin[=<b>]		error
235*7c478bd9Sstevel@tonic-gate  * -xCC				ignore
236*7c478bd9Sstevel@tonic-gate  * -xchar_byte_order=<o>	error
237*7c478bd9Sstevel@tonic-gate  * -xchip=<c>			table
238*7c478bd9Sstevel@tonic-gate  * -xcode=<c>			table
239*7c478bd9Sstevel@tonic-gate  * -xcrossfile[=<n>]		error
240*7c478bd9Sstevel@tonic-gate  * -xe				error
241*7c478bd9Sstevel@tonic-gate  * -xF				error
242*7c478bd9Sstevel@tonic-gate  * -xhelp=<f>			error
243*7c478bd9Sstevel@tonic-gate  * -xildoff			ignore
244*7c478bd9Sstevel@tonic-gate  * -xildon			ignore
245*7c478bd9Sstevel@tonic-gate  * -xinline			ignore
246*7c478bd9Sstevel@tonic-gate  * -xlibmieee			error
247*7c478bd9Sstevel@tonic-gate  * -xlibmil			error
248*7c478bd9Sstevel@tonic-gate  * -xlic_lib=sunperf		error
249*7c478bd9Sstevel@tonic-gate  * -xM				-M
250*7c478bd9Sstevel@tonic-gate  * -xM1				-MM
251*7c478bd9Sstevel@tonic-gate  * -xmaxopt=[...]		error
252*7c478bd9Sstevel@tonic-gate  * -xnolib			-nodefaultlibs
253*7c478bd9Sstevel@tonic-gate  * -xnolibmil			error
254*7c478bd9Sstevel@tonic-gate  * -xO<n>			-O<n>
255*7c478bd9Sstevel@tonic-gate  * -xP				error
256*7c478bd9Sstevel@tonic-gate  * -xpentium			-march=pentium (x86 only)
257*7c478bd9Sstevel@tonic-gate  * -xpg				error
258*7c478bd9Sstevel@tonic-gate  * -xprofile=<p>		error
259*7c478bd9Sstevel@tonic-gate  * -xregs=<r>			table
260*7c478bd9Sstevel@tonic-gate  * -xs				error
261*7c478bd9Sstevel@tonic-gate  * -xsb				error
262*7c478bd9Sstevel@tonic-gate  * -xsbfast			error
263*7c478bd9Sstevel@tonic-gate  * -xsfpconst			error
264*7c478bd9Sstevel@tonic-gate  * -xspace			ignore (-not -Os)
265*7c478bd9Sstevel@tonic-gate  * -xstrconst			ignore
266*7c478bd9Sstevel@tonic-gate  * -xtarget=<t>			table
267*7c478bd9Sstevel@tonic-gate  * -xtemp=<dir>			error
268*7c478bd9Sstevel@tonic-gate  * -xtime			error
269*7c478bd9Sstevel@tonic-gate  * -xtransition			-Wtransition
270*7c478bd9Sstevel@tonic-gate  * -xtrigraphs=<yes|no>		-trigraphs -notrigraphs
271*7c478bd9Sstevel@tonic-gate  * -xunroll=n			error
272*7c478bd9Sstevel@tonic-gate  * -Y<c>,<dir>			error
273*7c478bd9Sstevel@tonic-gate  * -YA,<dir>			error
274*7c478bd9Sstevel@tonic-gate  * -YI,<dir>			-nostdinc -I<dir>
275*7c478bd9Sstevel@tonic-gate  * -YP,<dir>			error
276*7c478bd9Sstevel@tonic-gate  * -YS,<dir>			error
277*7c478bd9Sstevel@tonic-gate  */
278*7c478bd9Sstevel@tonic-gate 
279*7c478bd9Sstevel@tonic-gate #include <stdio.h>
280*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
281*7c478bd9Sstevel@tonic-gate #include <unistd.h>
282*7c478bd9Sstevel@tonic-gate #include <string.h>
283*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
284*7c478bd9Sstevel@tonic-gate #include <ctype.h>
285*7c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
286*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
287*7c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate static int echo = 1;
290*7c478bd9Sstevel@tonic-gate static int newargc;
291*7c478bd9Sstevel@tonic-gate static const char *progname;
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate static char *default_cc_dir;
294*7c478bd9Sstevel@tonic-gate static char *default_gcc_dir;
295*7c478bd9Sstevel@tonic-gate 
296*7c478bd9Sstevel@tonic-gate static char *default_cplusplus_dir;
297*7c478bd9Sstevel@tonic-gate static char *default_gplusplus_dir;
298*7c478bd9Sstevel@tonic-gate 
299*7c478bd9Sstevel@tonic-gate static const char *xarch_tbl[] = {
300*7c478bd9Sstevel@tonic-gate #if defined(__x86)
301*7c478bd9Sstevel@tonic-gate 	"generic",	NULL,
302*7c478bd9Sstevel@tonic-gate 	"generic64",	"-m64", "-mtune=opteron", NULL,
303*7c478bd9Sstevel@tonic-gate 	"amd64",	"-m64", "-mtune=opteron", NULL,
304*7c478bd9Sstevel@tonic-gate 	"386",		"-march=i386", NULL,
305*7c478bd9Sstevel@tonic-gate 	"pentium_pro",	"-march=pentiumpro", NULL,
306*7c478bd9Sstevel@tonic-gate #elif defined(__sparc)
307*7c478bd9Sstevel@tonic-gate 	"generic",	"-m32", "-mcpu=v8", NULL,
308*7c478bd9Sstevel@tonic-gate 	"generic64",	"-m64", "-mcpu=v9", NULL,
309*7c478bd9Sstevel@tonic-gate 	"v8",		"-m32", "-mcpu=v8", "-mno-v8plus", NULL,
310*7c478bd9Sstevel@tonic-gate 	"v8plus",	"-m32", "-mcpu=v9", "-mv8plus", NULL,
311*7c478bd9Sstevel@tonic-gate 	"v8plusa",	"-m32", "-mcpu=ultrasparc", "-mv8plus", "-mvis", NULL,
312*7c478bd9Sstevel@tonic-gate 	"v8plusb",	"-m32", "-mcpu=ultrasparc3", "-mv8plus", "-mvis", NULL,
313*7c478bd9Sstevel@tonic-gate 	"v9",		"-m64", "-mcpu=v9", NULL,
314*7c478bd9Sstevel@tonic-gate 	"v9a",		"-m64", "-mcpu=ultrasparc", "-mvis", NULL,
315*7c478bd9Sstevel@tonic-gate 	"v9b",		"-m64", "-mcpu=ultrasparc3", "-mvis", NULL,
316*7c478bd9Sstevel@tonic-gate #endif
317*7c478bd9Sstevel@tonic-gate 	NULL,		NULL
318*7c478bd9Sstevel@tonic-gate };
319*7c478bd9Sstevel@tonic-gate 
320*7c478bd9Sstevel@tonic-gate static const char *xchip_tbl[] = {
321*7c478bd9Sstevel@tonic-gate #if defined(__x86)
322*7c478bd9Sstevel@tonic-gate 	"386",		"-mtune=i386", NULL,
323*7c478bd9Sstevel@tonic-gate 	"486",		"-mtune=i486", NULL,
324*7c478bd9Sstevel@tonic-gate 	"pentium",	"-mtune=pentium", NULL,
325*7c478bd9Sstevel@tonic-gate 	"pentium_pro",  "-mtune=pentiumpro", NULL,
326*7c478bd9Sstevel@tonic-gate #elif defined(__sparc)
327*7c478bd9Sstevel@tonic-gate 	"super",	"-mtune=supersparc", NULL,
328*7c478bd9Sstevel@tonic-gate 	"ultra",	"-mtune=ultrasparc", NULL,
329*7c478bd9Sstevel@tonic-gate 	"ultra3",	"-mtune=ultrasparc3", NULL,
330*7c478bd9Sstevel@tonic-gate #endif
331*7c478bd9Sstevel@tonic-gate 	NULL,		NULL
332*7c478bd9Sstevel@tonic-gate };
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate static const char *xcode_tbl[] = {
335*7c478bd9Sstevel@tonic-gate #if defined(__sparc)
336*7c478bd9Sstevel@tonic-gate 	"abs32",	"-fno-pic", "-mcmodel=medlow", NULL,
337*7c478bd9Sstevel@tonic-gate 	"abs44",	"-fno-pic", "-mcmodel=medmid", NULL,
338*7c478bd9Sstevel@tonic-gate 	"abs64",	"-fno-pic", "-mcmodel=medany", NULL,
339*7c478bd9Sstevel@tonic-gate 	"pic13",	"-fpic", NULL,
340*7c478bd9Sstevel@tonic-gate 	"pic32",	"-fPIC", NULL,
341*7c478bd9Sstevel@tonic-gate #endif
342*7c478bd9Sstevel@tonic-gate 	NULL,		NULL
343*7c478bd9Sstevel@tonic-gate };
344*7c478bd9Sstevel@tonic-gate 
345*7c478bd9Sstevel@tonic-gate static const char *xtarget_tbl[] = {
346*7c478bd9Sstevel@tonic-gate #if defined(__x86)
347*7c478bd9Sstevel@tonic-gate 	"pentium_pro",	"-march=pentiumpro", NULL,
348*7c478bd9Sstevel@tonic-gate #endif	/* __x86 */
349*7c478bd9Sstevel@tonic-gate 	NULL,		NULL
350*7c478bd9Sstevel@tonic-gate };
351*7c478bd9Sstevel@tonic-gate 
352*7c478bd9Sstevel@tonic-gate static const char *xregs_tbl[] = {
353*7c478bd9Sstevel@tonic-gate #if defined(__sparc)
354*7c478bd9Sstevel@tonic-gate 	"appl",		"-mapp-regs", NULL,
355*7c478bd9Sstevel@tonic-gate 	"no%appl",	"-mno-app-regs", NULL,
356*7c478bd9Sstevel@tonic-gate 	"float",	"-mfpu", NULL,
357*7c478bd9Sstevel@tonic-gate 	"no%float",	"-mno-fpu", NULL,
358*7c478bd9Sstevel@tonic-gate #endif	/* __sparc */
359*7c478bd9Sstevel@tonic-gate 	NULL,		NULL
360*7c478bd9Sstevel@tonic-gate };
361*7c478bd9Sstevel@tonic-gate 
362*7c478bd9Sstevel@tonic-gate struct aelist {
363*7c478bd9Sstevel@tonic-gate 	struct ae {
364*7c478bd9Sstevel@tonic-gate 		struct ae *ae_next;
365*7c478bd9Sstevel@tonic-gate 		char *ae_arg;
366*7c478bd9Sstevel@tonic-gate 	} *ael_head, *ael_tail;
367*7c478bd9Sstevel@tonic-gate };
368*7c478bd9Sstevel@tonic-gate 
369*7c478bd9Sstevel@tonic-gate static struct aelist *
370*7c478bd9Sstevel@tonic-gate newael(void)
371*7c478bd9Sstevel@tonic-gate {
372*7c478bd9Sstevel@tonic-gate 	return (calloc(sizeof (struct aelist), 1));
373*7c478bd9Sstevel@tonic-gate }
374*7c478bd9Sstevel@tonic-gate 
375*7c478bd9Sstevel@tonic-gate static void
376*7c478bd9Sstevel@tonic-gate newae(struct aelist *ael, const char *arg)
377*7c478bd9Sstevel@tonic-gate {
378*7c478bd9Sstevel@tonic-gate 	struct ae *ae;
379*7c478bd9Sstevel@tonic-gate 
380*7c478bd9Sstevel@tonic-gate 	ae = calloc(sizeof (*ae), 1);
381*7c478bd9Sstevel@tonic-gate 	ae->ae_arg = strdup(arg);
382*7c478bd9Sstevel@tonic-gate 	if (ael->ael_tail == NULL)
383*7c478bd9Sstevel@tonic-gate 		ael->ael_head = ae;
384*7c478bd9Sstevel@tonic-gate 	else
385*7c478bd9Sstevel@tonic-gate 		ael->ael_tail->ae_next = ae;
386*7c478bd9Sstevel@tonic-gate 	ael->ael_tail = ae;
387*7c478bd9Sstevel@tonic-gate 	newargc++;
388*7c478bd9Sstevel@tonic-gate }
389*7c478bd9Sstevel@tonic-gate 
390*7c478bd9Sstevel@tonic-gate static void
391*7c478bd9Sstevel@tonic-gate error(const char *arg)
392*7c478bd9Sstevel@tonic-gate {
393*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
394*7c478bd9Sstevel@tonic-gate 	    "%s: mapping failed at or near arg '%s'\n", progname, arg);
395*7c478bd9Sstevel@tonic-gate 	exit(2);
396*7c478bd9Sstevel@tonic-gate }
397*7c478bd9Sstevel@tonic-gate 
398*7c478bd9Sstevel@tonic-gate /*
399*7c478bd9Sstevel@tonic-gate  * Add the current favourite set of warnings to the gcc invocation.
400*7c478bd9Sstevel@tonic-gate  */
401*7c478bd9Sstevel@tonic-gate static void
402*7c478bd9Sstevel@tonic-gate warnings(struct aelist *h)
403*7c478bd9Sstevel@tonic-gate {
404*7c478bd9Sstevel@tonic-gate 	static int warningsonce;
405*7c478bd9Sstevel@tonic-gate 
406*7c478bd9Sstevel@tonic-gate 	if (warningsonce++)
407*7c478bd9Sstevel@tonic-gate 		return;
408*7c478bd9Sstevel@tonic-gate 
409*7c478bd9Sstevel@tonic-gate 	newae(h, "-Wall");
410*7c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-unknown-pragmas");
411*7c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-missing-braces");
412*7c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-sign-compare");
413*7c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-parentheses");
414*7c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-uninitialized");
415*7c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-implicit-function-declaration");
416*7c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-unused");
417*7c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-trigraphs");
418*7c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-char-subscripts");
419*7c478bd9Sstevel@tonic-gate 	newae(h, "-Wno-switch");
420*7c478bd9Sstevel@tonic-gate }
421*7c478bd9Sstevel@tonic-gate 
422*7c478bd9Sstevel@tonic-gate static void
423*7c478bd9Sstevel@tonic-gate optim_disable(struct aelist *h, int level)
424*7c478bd9Sstevel@tonic-gate {
425*7c478bd9Sstevel@tonic-gate 	if (level >= 2) {
426*7c478bd9Sstevel@tonic-gate 		newae(h, "-fno-strict-aliasing");
427*7c478bd9Sstevel@tonic-gate 		newae(h, "-fno-unit-at-a-time");
428*7c478bd9Sstevel@tonic-gate 		newae(h, "-fno-optimize-sibling-calls");
429*7c478bd9Sstevel@tonic-gate 	}
430*7c478bd9Sstevel@tonic-gate }
431*7c478bd9Sstevel@tonic-gate 
432*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
433*7c478bd9Sstevel@tonic-gate static void
434*7c478bd9Sstevel@tonic-gate Xamode(struct aelist *h)
435*7c478bd9Sstevel@tonic-gate {
436*7c478bd9Sstevel@tonic-gate }
437*7c478bd9Sstevel@tonic-gate 
438*7c478bd9Sstevel@tonic-gate static void
439*7c478bd9Sstevel@tonic-gate Xcmode(struct aelist *h)
440*7c478bd9Sstevel@tonic-gate {
441*7c478bd9Sstevel@tonic-gate 	static int xconce;
442*7c478bd9Sstevel@tonic-gate 
443*7c478bd9Sstevel@tonic-gate 	if (xconce++)
444*7c478bd9Sstevel@tonic-gate 		return;
445*7c478bd9Sstevel@tonic-gate 
446*7c478bd9Sstevel@tonic-gate 	newae(h, "-ansi");
447*7c478bd9Sstevel@tonic-gate 	newae(h, "-pedantic-errors");
448*7c478bd9Sstevel@tonic-gate }
449*7c478bd9Sstevel@tonic-gate 
450*7c478bd9Sstevel@tonic-gate static void
451*7c478bd9Sstevel@tonic-gate Xsmode(struct aelist *h)
452*7c478bd9Sstevel@tonic-gate {
453*7c478bd9Sstevel@tonic-gate 	static int xsonce;
454*7c478bd9Sstevel@tonic-gate 
455*7c478bd9Sstevel@tonic-gate 	if (xsonce++)
456*7c478bd9Sstevel@tonic-gate 		return;
457*7c478bd9Sstevel@tonic-gate 
458*7c478bd9Sstevel@tonic-gate 	newae(h, "-traditional");
459*7c478bd9Sstevel@tonic-gate 	newae(h, "-traditional-cpp");
460*7c478bd9Sstevel@tonic-gate }
461*7c478bd9Sstevel@tonic-gate 
462*7c478bd9Sstevel@tonic-gate static void
463*7c478bd9Sstevel@tonic-gate usage()
464*7c478bd9Sstevel@tonic-gate {
465*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
466*7c478bd9Sstevel@tonic-gate 	    "usage: %s { -_cc | -_gcc | -_CC | -_g++ } [ -_compiler | ... ]\n",
467*7c478bd9Sstevel@tonic-gate 	    progname);
468*7c478bd9Sstevel@tonic-gate 	exit(2);
469*7c478bd9Sstevel@tonic-gate }
470*7c478bd9Sstevel@tonic-gate 
471*7c478bd9Sstevel@tonic-gate static void
472*7c478bd9Sstevel@tonic-gate xlate(struct aelist *h, const char *xarg, const char **table)
473*7c478bd9Sstevel@tonic-gate {
474*7c478bd9Sstevel@tonic-gate 	while (*table != NULL && strcmp(xarg, *table) != 0) {
475*7c478bd9Sstevel@tonic-gate 		while (*table != NULL)
476*7c478bd9Sstevel@tonic-gate 			table++;
477*7c478bd9Sstevel@tonic-gate 		table++;
478*7c478bd9Sstevel@tonic-gate 	}
479*7c478bd9Sstevel@tonic-gate 
480*7c478bd9Sstevel@tonic-gate 	if (*table == NULL)
481*7c478bd9Sstevel@tonic-gate 		error(xarg);
482*7c478bd9Sstevel@tonic-gate 
483*7c478bd9Sstevel@tonic-gate 	table++;
484*7c478bd9Sstevel@tonic-gate 
485*7c478bd9Sstevel@tonic-gate 	while (*table != NULL) {
486*7c478bd9Sstevel@tonic-gate 		newae(h, *table);
487*7c478bd9Sstevel@tonic-gate 		table++;
488*7c478bd9Sstevel@tonic-gate 	}
489*7c478bd9Sstevel@tonic-gate }
490*7c478bd9Sstevel@tonic-gate 
491*7c478bd9Sstevel@tonic-gate static void
492*7c478bd9Sstevel@tonic-gate do_gcc(const char *dir, const char *cmd, int argc, char **argv,
493*7c478bd9Sstevel@tonic-gate     struct aelist *h, int cplusplus)
494*7c478bd9Sstevel@tonic-gate {
495*7c478bd9Sstevel@tonic-gate 	int c;
496*7c478bd9Sstevel@tonic-gate 	int pic = 0;
497*7c478bd9Sstevel@tonic-gate 	int nolibc = 0;
498*7c478bd9Sstevel@tonic-gate 	char *model = NULL;
499*7c478bd9Sstevel@tonic-gate 	char *program;
500*7c478bd9Sstevel@tonic-gate 	size_t len = strlen(dir) + strlen(cmd) + 2;
501*7c478bd9Sstevel@tonic-gate 
502*7c478bd9Sstevel@tonic-gate 	program = malloc(len);
503*7c478bd9Sstevel@tonic-gate 	(void) snprintf(program, len, "%s/%s", dir, cmd);
504*7c478bd9Sstevel@tonic-gate 
505*7c478bd9Sstevel@tonic-gate 	/*
506*7c478bd9Sstevel@tonic-gate 	 * Basic defaults for ON compilation
507*7c478bd9Sstevel@tonic-gate 	 */
508*7c478bd9Sstevel@tonic-gate 	newae(h, program);
509*7c478bd9Sstevel@tonic-gate 
510*7c478bd9Sstevel@tonic-gate 	newae(h, "-fident");
511*7c478bd9Sstevel@tonic-gate 	newae(h, "-finline");
512*7c478bd9Sstevel@tonic-gate 	newae(h, "-fno-inline-functions");
513*7c478bd9Sstevel@tonic-gate 	newae(h, "-fno-builtin");
514*7c478bd9Sstevel@tonic-gate 	newae(h, "-fno-asm");
515*7c478bd9Sstevel@tonic-gate 	newae(h, "-nodefaultlibs");
516*7c478bd9Sstevel@tonic-gate 
517*7c478bd9Sstevel@tonic-gate 	/*
518*7c478bd9Sstevel@tonic-gate 	 * This is needed because 'u' is defined
519*7c478bd9Sstevel@tonic-gate 	 * under a conditional on 'sun'.  Should
520*7c478bd9Sstevel@tonic-gate 	 * probably just remove the conditional,
521*7c478bd9Sstevel@tonic-gate 	 * or make it be dependent on '__sun'.
522*7c478bd9Sstevel@tonic-gate 	 *
523*7c478bd9Sstevel@tonic-gate 	 * -Dunix is also missing in enhanced ANSI mode
524*7c478bd9Sstevel@tonic-gate 	 */
525*7c478bd9Sstevel@tonic-gate 	newae(h, "-D__sun");
526*7c478bd9Sstevel@tonic-gate 
527*7c478bd9Sstevel@tonic-gate 	/*
528*7c478bd9Sstevel@tonic-gate 	 * Walk the argument list, translating as we go ..
529*7c478bd9Sstevel@tonic-gate 	 */
530*7c478bd9Sstevel@tonic-gate 
531*7c478bd9Sstevel@tonic-gate 	while (--argc > 0) {
532*7c478bd9Sstevel@tonic-gate 		char *arg = *++argv;
533*7c478bd9Sstevel@tonic-gate 		size_t arglen = strlen(arg);
534*7c478bd9Sstevel@tonic-gate 
535*7c478bd9Sstevel@tonic-gate 		if (*arg == '-')
536*7c478bd9Sstevel@tonic-gate 			arglen--;
537*7c478bd9Sstevel@tonic-gate 		else {
538*7c478bd9Sstevel@tonic-gate 			/*
539*7c478bd9Sstevel@tonic-gate 			 * Discard inline files that gcc doesn't grok
540*7c478bd9Sstevel@tonic-gate 			 */
541*7c478bd9Sstevel@tonic-gate 			if (arglen > 3 &&
542*7c478bd9Sstevel@tonic-gate 			    strcmp(arg + arglen - 3, ".il") == 0)
543*7c478bd9Sstevel@tonic-gate 				continue;
544*7c478bd9Sstevel@tonic-gate 
545*7c478bd9Sstevel@tonic-gate 			/*
546*7c478bd9Sstevel@tonic-gate 			 * Otherwise, filenames, and partial arguments
547*7c478bd9Sstevel@tonic-gate 			 * are simply passed through for gcc to chew on.
548*7c478bd9Sstevel@tonic-gate 			 */
549*7c478bd9Sstevel@tonic-gate 			newae(h, arg);
550*7c478bd9Sstevel@tonic-gate 			continue;
551*7c478bd9Sstevel@tonic-gate 		}
552*7c478bd9Sstevel@tonic-gate 
553*7c478bd9Sstevel@tonic-gate 		if (cplusplus) {
554*7c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-compat=", 8) == 0) {
555*7c478bd9Sstevel@tonic-gate 				/* discard -compat=4 and -compat=5 */
556*7c478bd9Sstevel@tonic-gate 				continue;
557*7c478bd9Sstevel@tonic-gate 			}
558*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Qoption") == 0) {
559*7c478bd9Sstevel@tonic-gate 				/* discard -Qoption and its two arguments */
560*7c478bd9Sstevel@tonic-gate 				if (argc < 3)
561*7c478bd9Sstevel@tonic-gate 					error(arg);
562*7c478bd9Sstevel@tonic-gate 				argc -= 2;
563*7c478bd9Sstevel@tonic-gate 				argv += 2;
564*7c478bd9Sstevel@tonic-gate 				continue;
565*7c478bd9Sstevel@tonic-gate 			}
566*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-xwe") == 0) {
567*7c478bd9Sstevel@tonic-gate 				/* turn warnings into errors */
568*7c478bd9Sstevel@tonic-gate 				/* newae(h, "-Werror"); */
569*7c478bd9Sstevel@tonic-gate 				continue;
570*7c478bd9Sstevel@tonic-gate 			}
571*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-noex") == 0) {
572*7c478bd9Sstevel@tonic-gate 				/* no exceptions */
573*7c478bd9Sstevel@tonic-gate 				newae(h, "-fno-exceptions");
574*7c478bd9Sstevel@tonic-gate 				/* no run time type descriptor information */
575*7c478bd9Sstevel@tonic-gate 				newae(h, "-fno-rtti");
576*7c478bd9Sstevel@tonic-gate 				continue;
577*7c478bd9Sstevel@tonic-gate 			}
578*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-pic") == 0) {
579*7c478bd9Sstevel@tonic-gate 				newae(h, "-fpic");
580*7c478bd9Sstevel@tonic-gate 				pic = 1;
581*7c478bd9Sstevel@tonic-gate 				continue;
582*7c478bd9Sstevel@tonic-gate 			}
583*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-PIC") == 0) {
584*7c478bd9Sstevel@tonic-gate 				newae(h, "-fPIC");
585*7c478bd9Sstevel@tonic-gate 				pic = 1;
586*7c478bd9Sstevel@tonic-gate 				continue;
587*7c478bd9Sstevel@tonic-gate 			}
588*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-norunpath") == 0) {
589*7c478bd9Sstevel@tonic-gate 				/* gcc has no corresponding option */
590*7c478bd9Sstevel@tonic-gate 				continue;
591*7c478bd9Sstevel@tonic-gate 			}
592*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-nolib") == 0) {
593*7c478bd9Sstevel@tonic-gate 				/* -nodefaultlibs is on by default */
594*7c478bd9Sstevel@tonic-gate 				nolibc = 1;
595*7c478bd9Sstevel@tonic-gate 				continue;
596*7c478bd9Sstevel@tonic-gate 			}
597*7c478bd9Sstevel@tonic-gate #if defined(__sparc)
598*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-cg92") == 0) {
599*7c478bd9Sstevel@tonic-gate 				xlate(h, "v8", xarch_tbl);
600*7c478bd9Sstevel@tonic-gate 				xlate(h, "super", xchip_tbl);
601*7c478bd9Sstevel@tonic-gate 				continue;
602*7c478bd9Sstevel@tonic-gate 			}
603*7c478bd9Sstevel@tonic-gate #endif	/* __sparc */
604*7c478bd9Sstevel@tonic-gate 		}
605*7c478bd9Sstevel@tonic-gate 
606*7c478bd9Sstevel@tonic-gate 		switch ((c = arg[1])) {
607*7c478bd9Sstevel@tonic-gate 		case '_':
608*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-_noecho") == 0)
609*7c478bd9Sstevel@tonic-gate 				echo = 0;
610*7c478bd9Sstevel@tonic-gate 			else if (strncmp(arg, "-_cc=", 5) == 0 ||
611*7c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-_CC=", 5) == 0)
612*7c478bd9Sstevel@tonic-gate 				/* EMPTY */;
613*7c478bd9Sstevel@tonic-gate 			else if (strncmp(arg, "-_gcc=", 6) == 0 ||
614*7c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-_g++=", 6) == 0)
615*7c478bd9Sstevel@tonic-gate 				newae(h, arg + 6);
616*7c478bd9Sstevel@tonic-gate 			else if (strcmp(arg, "-_compiler") == 0) {
617*7c478bd9Sstevel@tonic-gate 				(void) printf("%s\n", program);
618*7c478bd9Sstevel@tonic-gate 				exit(0);
619*7c478bd9Sstevel@tonic-gate 			} else
620*7c478bd9Sstevel@tonic-gate 				error(arg);
621*7c478bd9Sstevel@tonic-gate 			break;
622*7c478bd9Sstevel@tonic-gate 		case '#':
623*7c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
624*7c478bd9Sstevel@tonic-gate 				newae(h, "-v");
625*7c478bd9Sstevel@tonic-gate 				break;
626*7c478bd9Sstevel@tonic-gate 			}
627*7c478bd9Sstevel@tonic-gate 			error(arg);
628*7c478bd9Sstevel@tonic-gate 			break;
629*7c478bd9Sstevel@tonic-gate 		case 'g':
630*7c478bd9Sstevel@tonic-gate 			newae(h, "-gdwarf-2");
631*7c478bd9Sstevel@tonic-gate 			break;
632*7c478bd9Sstevel@tonic-gate 		case 'E':
633*7c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
634*7c478bd9Sstevel@tonic-gate 				newae(h, "-xc");
635*7c478bd9Sstevel@tonic-gate 				newae(h, arg);
636*7c478bd9Sstevel@tonic-gate 				nolibc = 1;
637*7c478bd9Sstevel@tonic-gate 				break;
638*7c478bd9Sstevel@tonic-gate 			}
639*7c478bd9Sstevel@tonic-gate 			error(arg);
640*7c478bd9Sstevel@tonic-gate 			break;
641*7c478bd9Sstevel@tonic-gate 		case 'c':
642*7c478bd9Sstevel@tonic-gate 		case 'S':
643*7c478bd9Sstevel@tonic-gate 			if (arglen == 1)
644*7c478bd9Sstevel@tonic-gate 				nolibc = 1;
645*7c478bd9Sstevel@tonic-gate 			/* FALLTHROUGH */
646*7c478bd9Sstevel@tonic-gate 		case 'C':
647*7c478bd9Sstevel@tonic-gate 		case 'H':
648*7c478bd9Sstevel@tonic-gate 		case 'p':
649*7c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
650*7c478bd9Sstevel@tonic-gate 				newae(h, arg);
651*7c478bd9Sstevel@tonic-gate 				break;
652*7c478bd9Sstevel@tonic-gate 			}
653*7c478bd9Sstevel@tonic-gate 			error(arg);
654*7c478bd9Sstevel@tonic-gate 			break;
655*7c478bd9Sstevel@tonic-gate 		case 'A':
656*7c478bd9Sstevel@tonic-gate 		case 'h':
657*7c478bd9Sstevel@tonic-gate 		case 'I':
658*7c478bd9Sstevel@tonic-gate 		case 'i':
659*7c478bd9Sstevel@tonic-gate 		case 'L':
660*7c478bd9Sstevel@tonic-gate 		case 'l':
661*7c478bd9Sstevel@tonic-gate 		case 'o':
662*7c478bd9Sstevel@tonic-gate 		case 'R':
663*7c478bd9Sstevel@tonic-gate 		case 'U':
664*7c478bd9Sstevel@tonic-gate 		case 'u':
665*7c478bd9Sstevel@tonic-gate 		case 'w':
666*7c478bd9Sstevel@tonic-gate 			newae(h, arg);
667*7c478bd9Sstevel@tonic-gate 			break;
668*7c478bd9Sstevel@tonic-gate 		case 'D':
669*7c478bd9Sstevel@tonic-gate 			newae(h, arg);
670*7c478bd9Sstevel@tonic-gate 			/*
671*7c478bd9Sstevel@tonic-gate 			 * XXX	Clearly a hack ... do we need _KADB too?
672*7c478bd9Sstevel@tonic-gate 			 */
673*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-D_KERNEL") == 0 ||
674*7c478bd9Sstevel@tonic-gate 			    strcmp(arg, "-D_BOOT") == 0)
675*7c478bd9Sstevel@tonic-gate 				newae(h, "-ffreestanding");
676*7c478bd9Sstevel@tonic-gate 			break;
677*7c478bd9Sstevel@tonic-gate 		case 'd':
678*7c478bd9Sstevel@tonic-gate 			if (arglen == 2) {
679*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-dy") == 0) {
680*7c478bd9Sstevel@tonic-gate 					newae(h, "-Wl,-dy");
681*7c478bd9Sstevel@tonic-gate 					break;
682*7c478bd9Sstevel@tonic-gate 				}
683*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-dn") == 0) {
684*7c478bd9Sstevel@tonic-gate 					newae(h, "-Wl,-dn");
685*7c478bd9Sstevel@tonic-gate 					break;
686*7c478bd9Sstevel@tonic-gate 				}
687*7c478bd9Sstevel@tonic-gate 			}
688*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-dalign") == 0) {
689*7c478bd9Sstevel@tonic-gate 				/*
690*7c478bd9Sstevel@tonic-gate 				 * -dalign forces alignment in some cases;
691*7c478bd9Sstevel@tonic-gate 				 * gcc does not need any flag to do this.
692*7c478bd9Sstevel@tonic-gate 				 */
693*7c478bd9Sstevel@tonic-gate 				break;
694*7c478bd9Sstevel@tonic-gate 			}
695*7c478bd9Sstevel@tonic-gate 			error(arg);
696*7c478bd9Sstevel@tonic-gate 			break;
697*7c478bd9Sstevel@tonic-gate 		case 'e':
698*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg,
699*7c478bd9Sstevel@tonic-gate 			    "-erroff=E_EMPTY_TRANSLATION_UNIT") == 0) {
700*7c478bd9Sstevel@tonic-gate 				/*
701*7c478bd9Sstevel@tonic-gate 				 * Accept but ignore this -- gcc doesn't
702*7c478bd9Sstevel@tonic-gate 				 * seem to complain about empty translation
703*7c478bd9Sstevel@tonic-gate 				 * units
704*7c478bd9Sstevel@tonic-gate 				 */
705*7c478bd9Sstevel@tonic-gate 				break;
706*7c478bd9Sstevel@tonic-gate 			}
707*7c478bd9Sstevel@tonic-gate 			/* XX64 -- ignore all -erroff= options, for now */
708*7c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-erroff=", 8) == 0)
709*7c478bd9Sstevel@tonic-gate 				break;
710*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-errtags=yes") == 0) {
711*7c478bd9Sstevel@tonic-gate 				warnings(h);
712*7c478bd9Sstevel@tonic-gate 				break;
713*7c478bd9Sstevel@tonic-gate 			}
714*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-errwarn=%all") == 0) {
715*7c478bd9Sstevel@tonic-gate 				newae(h, "-Werror");
716*7c478bd9Sstevel@tonic-gate 				break;
717*7c478bd9Sstevel@tonic-gate 			}
718*7c478bd9Sstevel@tonic-gate 			error(arg);
719*7c478bd9Sstevel@tonic-gate 			break;
720*7c478bd9Sstevel@tonic-gate 		case 'f':
721*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-flags") == 0) {
722*7c478bd9Sstevel@tonic-gate 				newae(h, "--help");
723*7c478bd9Sstevel@tonic-gate 				break;
724*7c478bd9Sstevel@tonic-gate 			}
725*7c478bd9Sstevel@tonic-gate 			error(arg);
726*7c478bd9Sstevel@tonic-gate 			break;
727*7c478bd9Sstevel@tonic-gate 		case 'G':
728*7c478bd9Sstevel@tonic-gate 			newae(h, "-shared");
729*7c478bd9Sstevel@tonic-gate 			nolibc = 1;
730*7c478bd9Sstevel@tonic-gate 			break;
731*7c478bd9Sstevel@tonic-gate 		case 'k':
732*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-keeptmp") == 0) {
733*7c478bd9Sstevel@tonic-gate 				newae(h, "-save-temps");
734*7c478bd9Sstevel@tonic-gate 				break;
735*7c478bd9Sstevel@tonic-gate 			}
736*7c478bd9Sstevel@tonic-gate 			error(arg);
737*7c478bd9Sstevel@tonic-gate 			break;
738*7c478bd9Sstevel@tonic-gate 		case 'K':
739*7c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
740*7c478bd9Sstevel@tonic-gate 				if ((arg = *++argv) == NULL || *arg == '\0')
741*7c478bd9Sstevel@tonic-gate 					error("-K");
742*7c478bd9Sstevel@tonic-gate 				argc--;
743*7c478bd9Sstevel@tonic-gate 			} else {
744*7c478bd9Sstevel@tonic-gate 				arg += 2;
745*7c478bd9Sstevel@tonic-gate 			}
746*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "pic") == 0) {
747*7c478bd9Sstevel@tonic-gate 				newae(h, "-fpic");
748*7c478bd9Sstevel@tonic-gate 				pic = 1;
749*7c478bd9Sstevel@tonic-gate 				break;
750*7c478bd9Sstevel@tonic-gate 			}
751*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "PIC") == 0) {
752*7c478bd9Sstevel@tonic-gate 				newae(h, "-fPIC");
753*7c478bd9Sstevel@tonic-gate 				pic = 1;
754*7c478bd9Sstevel@tonic-gate 				break;
755*7c478bd9Sstevel@tonic-gate 			}
756*7c478bd9Sstevel@tonic-gate 			error("-K");
757*7c478bd9Sstevel@tonic-gate 			break;
758*7c478bd9Sstevel@tonic-gate 		case 'm':
759*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-mt") == 0) {
760*7c478bd9Sstevel@tonic-gate 				newae(h, "-D_REENTRANT");
761*7c478bd9Sstevel@tonic-gate 				break;
762*7c478bd9Sstevel@tonic-gate 			}
763*7c478bd9Sstevel@tonic-gate 			error(arg);
764*7c478bd9Sstevel@tonic-gate 			break;
765*7c478bd9Sstevel@tonic-gate 		case 'B':	/* linker options */
766*7c478bd9Sstevel@tonic-gate 		case 'M':
767*7c478bd9Sstevel@tonic-gate 		case 'z':
768*7c478bd9Sstevel@tonic-gate 			{
769*7c478bd9Sstevel@tonic-gate 				char *opt;
770*7c478bd9Sstevel@tonic-gate 				size_t len;
771*7c478bd9Sstevel@tonic-gate 				char *s;
772*7c478bd9Sstevel@tonic-gate 
773*7c478bd9Sstevel@tonic-gate 				if (arglen == 1) {
774*7c478bd9Sstevel@tonic-gate 					opt = *++argv;
775*7c478bd9Sstevel@tonic-gate 					if (opt == NULL || *opt == '\0')
776*7c478bd9Sstevel@tonic-gate 						error(arg);
777*7c478bd9Sstevel@tonic-gate 					argc--;
778*7c478bd9Sstevel@tonic-gate 				} else {
779*7c478bd9Sstevel@tonic-gate 					opt = arg + 2;
780*7c478bd9Sstevel@tonic-gate 				}
781*7c478bd9Sstevel@tonic-gate 				len = strlen(opt) + 7;
782*7c478bd9Sstevel@tonic-gate 				s = malloc(len);
783*7c478bd9Sstevel@tonic-gate 				(void) snprintf(s, len, "-Wl,-%c%s", c, opt);
784*7c478bd9Sstevel@tonic-gate 				newae(h, s);
785*7c478bd9Sstevel@tonic-gate 				free(s);
786*7c478bd9Sstevel@tonic-gate 			}
787*7c478bd9Sstevel@tonic-gate 			break;
788*7c478bd9Sstevel@tonic-gate 		case 'n':
789*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-noqueue") == 0) {
790*7c478bd9Sstevel@tonic-gate 				/*
791*7c478bd9Sstevel@tonic-gate 				 * Horrid license server stuff - n/a
792*7c478bd9Sstevel@tonic-gate 				 */
793*7c478bd9Sstevel@tonic-gate 				break;
794*7c478bd9Sstevel@tonic-gate 			}
795*7c478bd9Sstevel@tonic-gate 			error(arg);
796*7c478bd9Sstevel@tonic-gate 			break;
797*7c478bd9Sstevel@tonic-gate 		case 'O':
798*7c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
799*7c478bd9Sstevel@tonic-gate 				newae(h, "-O");
800*7c478bd9Sstevel@tonic-gate 				break;
801*7c478bd9Sstevel@tonic-gate 			}
802*7c478bd9Sstevel@tonic-gate 			error(arg);
803*7c478bd9Sstevel@tonic-gate 			break;
804*7c478bd9Sstevel@tonic-gate 		case 'P':
805*7c478bd9Sstevel@tonic-gate 			/*
806*7c478bd9Sstevel@tonic-gate 			 * We could do '-E -o filename.i', but that's hard,
807*7c478bd9Sstevel@tonic-gate 			 * and we don't need it for the case that's triggering
808*7c478bd9Sstevel@tonic-gate 			 * this addition.  We'll require the user to specify
809*7c478bd9Sstevel@tonic-gate 			 * -o in the Makefile.  If they don't they'll find out
810*7c478bd9Sstevel@tonic-gate 			 * in a hurry.
811*7c478bd9Sstevel@tonic-gate 			 */
812*7c478bd9Sstevel@tonic-gate 			newae(h, "-E");
813*7c478bd9Sstevel@tonic-gate 			nolibc = 1;
814*7c478bd9Sstevel@tonic-gate 			break;
815*7c478bd9Sstevel@tonic-gate 		case 'q':
816*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-qp") == 0) {
817*7c478bd9Sstevel@tonic-gate 				newae(h, "-p");
818*7c478bd9Sstevel@tonic-gate 				break;
819*7c478bd9Sstevel@tonic-gate 			}
820*7c478bd9Sstevel@tonic-gate 			error(arg);
821*7c478bd9Sstevel@tonic-gate 			break;
822*7c478bd9Sstevel@tonic-gate 		case 's':
823*7c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
824*7c478bd9Sstevel@tonic-gate 				newae(h, "-Wl,-s");
825*7c478bd9Sstevel@tonic-gate 				break;
826*7c478bd9Sstevel@tonic-gate 			}
827*7c478bd9Sstevel@tonic-gate 			error(arg);
828*7c478bd9Sstevel@tonic-gate 			break;
829*7c478bd9Sstevel@tonic-gate 		case 'V':
830*7c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
831*7c478bd9Sstevel@tonic-gate 				echo = 0;
832*7c478bd9Sstevel@tonic-gate 				newae(h, "--version");
833*7c478bd9Sstevel@tonic-gate 				break;
834*7c478bd9Sstevel@tonic-gate 			}
835*7c478bd9Sstevel@tonic-gate 			error(arg);
836*7c478bd9Sstevel@tonic-gate 			break;
837*7c478bd9Sstevel@tonic-gate 		case 'v':
838*7c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
839*7c478bd9Sstevel@tonic-gate 				warnings(h);
840*7c478bd9Sstevel@tonic-gate 				break;
841*7c478bd9Sstevel@tonic-gate 			}
842*7c478bd9Sstevel@tonic-gate 			error(arg);
843*7c478bd9Sstevel@tonic-gate 			break;
844*7c478bd9Sstevel@tonic-gate 		case 'W':
845*7c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wp,-xc99", 9) == 0) {
846*7c478bd9Sstevel@tonic-gate 				/*
847*7c478bd9Sstevel@tonic-gate 				 * gcc's preprocessor will accept c99
848*7c478bd9Sstevel@tonic-gate 				 * regardless, so accept and ignore.
849*7c478bd9Sstevel@tonic-gate 				 */
850*7c478bd9Sstevel@tonic-gate 				break;
851*7c478bd9Sstevel@tonic-gate 			}
852*7c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wa,", 4) == 0 ||
853*7c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-Wp,", 4) == 0 ||
854*7c478bd9Sstevel@tonic-gate 			    strncmp(arg, "-Wl,", 4) == 0) {
855*7c478bd9Sstevel@tonic-gate 				newae(h, arg);
856*7c478bd9Sstevel@tonic-gate 				break;
857*7c478bd9Sstevel@tonic-gate 			}
858*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-xc99=pragma") == 0) {
859*7c478bd9Sstevel@tonic-gate 				/* (undocumented) enables _Pragma */
860*7c478bd9Sstevel@tonic-gate 				break;
861*7c478bd9Sstevel@tonic-gate 			}
862*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-xc99=%none") == 0) {
863*7c478bd9Sstevel@tonic-gate 				/*
864*7c478bd9Sstevel@tonic-gate 				 * This is a polite way of saying
865*7c478bd9Sstevel@tonic-gate 				 * "no c99 constructs allowed!"
866*7c478bd9Sstevel@tonic-gate 				 * For now, just accept and ignore this.
867*7c478bd9Sstevel@tonic-gate 				 */
868*7c478bd9Sstevel@tonic-gate 				break;
869*7c478bd9Sstevel@tonic-gate 			}
870*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-noglobal") == 0) {
871*7c478bd9Sstevel@tonic-gate 				/*
872*7c478bd9Sstevel@tonic-gate 				 * gcc doesn't prefix local symbols
873*7c478bd9Sstevel@tonic-gate 				 * in debug mode, so this is not needed.
874*7c478bd9Sstevel@tonic-gate 				 */
875*7c478bd9Sstevel@tonic-gate 				break;
876*7c478bd9Sstevel@tonic-gate 			}
877*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W0,-Lt") == 0) {
878*7c478bd9Sstevel@tonic-gate 				/*
879*7c478bd9Sstevel@tonic-gate 				 * Generate tests at the top of loops.
880*7c478bd9Sstevel@tonic-gate 				 * There is no direct gcc equivalent, ignore.
881*7c478bd9Sstevel@tonic-gate 				 */
882*7c478bd9Sstevel@tonic-gate 				break;
883*7c478bd9Sstevel@tonic-gate 			}
884*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-W2,-Rcond_elim") == 0) {
885*7c478bd9Sstevel@tonic-gate 				/*
886*7c478bd9Sstevel@tonic-gate 				 * Elimination and expansion of conditionals;
887*7c478bd9Sstevel@tonic-gate 				 * gcc has no direct equivalent.
888*7c478bd9Sstevel@tonic-gate 				 */
889*7c478bd9Sstevel@tonic-gate 				break;
890*7c478bd9Sstevel@tonic-gate 			}
891*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Wd,-xsafe=unboundsym") == 0) {
892*7c478bd9Sstevel@tonic-gate 				/*
893*7c478bd9Sstevel@tonic-gate 				 * Prevents optimizing away checks for
894*7c478bd9Sstevel@tonic-gate 				 * unbound weak symbol addresses.  gcc does
895*7c478bd9Sstevel@tonic-gate 				 * not do this, so it's not needed.
896*7c478bd9Sstevel@tonic-gate 				 */
897*7c478bd9Sstevel@tonic-gate 				break;
898*7c478bd9Sstevel@tonic-gate 			}
899*7c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wc,-xcode=", 11) == 0) {
900*7c478bd9Sstevel@tonic-gate 				xlate(h, arg + 11, xcode_tbl);
901*7c478bd9Sstevel@tonic-gate 				if (strncmp(arg + 11, "pic", 3) == 0)
902*7c478bd9Sstevel@tonic-gate 					pic = 1;
903*7c478bd9Sstevel@tonic-gate 				break;
904*7c478bd9Sstevel@tonic-gate 			}
905*7c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "-Wc,-Qiselect", 13) == 0) {
906*7c478bd9Sstevel@tonic-gate 				/*
907*7c478bd9Sstevel@tonic-gate 				 * Prevents insertion of register symbols.
908*7c478bd9Sstevel@tonic-gate 				 * gcc doesn't do this, so ignore it.
909*7c478bd9Sstevel@tonic-gate 				 */
910*7c478bd9Sstevel@tonic-gate 				break;
911*7c478bd9Sstevel@tonic-gate 			}
912*7c478bd9Sstevel@tonic-gate #if defined(__x86)
913*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Wu,-no_got_reloc") == 0) {
914*7c478bd9Sstevel@tonic-gate 				/*
915*7c478bd9Sstevel@tonic-gate 				 * Don't create any GOT relocations?
916*7c478bd9Sstevel@tonic-gate 				 * Well, gcc doesn't have this degree
917*7c478bd9Sstevel@tonic-gate 				 * of control over its pic code ...
918*7c478bd9Sstevel@tonic-gate 				 */
919*7c478bd9Sstevel@tonic-gate 				break;
920*7c478bd9Sstevel@tonic-gate 			}
921*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Wu,-xmodel=kernel") == 0) {
922*7c478bd9Sstevel@tonic-gate 				newae(h, "-ffreestanding");
923*7c478bd9Sstevel@tonic-gate 				newae(h, "-mno-red-zone");
924*7c478bd9Sstevel@tonic-gate 				model = "-mcmodel=kernel";
925*7c478bd9Sstevel@tonic-gate 				nolibc = 1;
926*7c478bd9Sstevel@tonic-gate 				break;
927*7c478bd9Sstevel@tonic-gate 			}
928*7c478bd9Sstevel@tonic-gate #endif	/* __x86 */
929*7c478bd9Sstevel@tonic-gate 			error(arg);
930*7c478bd9Sstevel@tonic-gate 			break;
931*7c478bd9Sstevel@tonic-gate 		case 'X':
932*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Xa") == 0 ||
933*7c478bd9Sstevel@tonic-gate 			    strcmp(arg, "-Xt") == 0) {
934*7c478bd9Sstevel@tonic-gate 				Xamode(h);
935*7c478bd9Sstevel@tonic-gate 				break;
936*7c478bd9Sstevel@tonic-gate 			}
937*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Xc") == 0) {
938*7c478bd9Sstevel@tonic-gate 				Xcmode(h);
939*7c478bd9Sstevel@tonic-gate 				break;
940*7c478bd9Sstevel@tonic-gate 			}
941*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-Xs") == 0) {
942*7c478bd9Sstevel@tonic-gate 				Xsmode(h);
943*7c478bd9Sstevel@tonic-gate 				break;
944*7c478bd9Sstevel@tonic-gate 			}
945*7c478bd9Sstevel@tonic-gate 			error(arg);
946*7c478bd9Sstevel@tonic-gate 			break;
947*7c478bd9Sstevel@tonic-gate 		case 'x':
948*7c478bd9Sstevel@tonic-gate 			if (arglen == 1)
949*7c478bd9Sstevel@tonic-gate 				error(arg);
950*7c478bd9Sstevel@tonic-gate 			switch (arg[2]) {
951*7c478bd9Sstevel@tonic-gate #if defined(__x86)
952*7c478bd9Sstevel@tonic-gate 			case '3':
953*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-x386") == 0) {
954*7c478bd9Sstevel@tonic-gate 					newae(h, "-march=i386");
955*7c478bd9Sstevel@tonic-gate 					break;
956*7c478bd9Sstevel@tonic-gate 				}
957*7c478bd9Sstevel@tonic-gate 				error(arg);
958*7c478bd9Sstevel@tonic-gate 				break;
959*7c478bd9Sstevel@tonic-gate 			case '4':
960*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-x486") == 0) {
961*7c478bd9Sstevel@tonic-gate 					newae(h, "-march=i486");
962*7c478bd9Sstevel@tonic-gate 					break;
963*7c478bd9Sstevel@tonic-gate 				}
964*7c478bd9Sstevel@tonic-gate 				error(arg);
965*7c478bd9Sstevel@tonic-gate 				break;
966*7c478bd9Sstevel@tonic-gate #endif	/* __x86 */
967*7c478bd9Sstevel@tonic-gate 			case 'a':
968*7c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xarch=", 7) == 0) {
969*7c478bd9Sstevel@tonic-gate 					xlate(h, arg + 7, xarch_tbl);
970*7c478bd9Sstevel@tonic-gate 					break;
971*7c478bd9Sstevel@tonic-gate 				}
972*7c478bd9Sstevel@tonic-gate 				error(arg);
973*7c478bd9Sstevel@tonic-gate 				break;
974*7c478bd9Sstevel@tonic-gate 			case 'C':
975*7c478bd9Sstevel@tonic-gate 				/* Accept C++ style comments -- ignore */
976*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xCC") == 0)
977*7c478bd9Sstevel@tonic-gate 					break;
978*7c478bd9Sstevel@tonic-gate 				error(arg);
979*7c478bd9Sstevel@tonic-gate 				break;
980*7c478bd9Sstevel@tonic-gate 			case 'c':
981*7c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xc99=%all", 10) == 0) {
982*7c478bd9Sstevel@tonic-gate 					newae(h, "-std=gnu99");
983*7c478bd9Sstevel@tonic-gate 					break;
984*7c478bd9Sstevel@tonic-gate 				}
985*7c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xc99=%none", 11) == 0) {
986*7c478bd9Sstevel@tonic-gate 					newae(h, "-std=gnu89");
987*7c478bd9Sstevel@tonic-gate 					break;
988*7c478bd9Sstevel@tonic-gate 				}
989*7c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xchip=", 7) == 0) {
990*7c478bd9Sstevel@tonic-gate 					xlate(h, arg + 7, xchip_tbl);
991*7c478bd9Sstevel@tonic-gate 					break;
992*7c478bd9Sstevel@tonic-gate 				}
993*7c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xcode=", 7) == 0) {
994*7c478bd9Sstevel@tonic-gate 					xlate(h, arg + 7, xcode_tbl);
995*7c478bd9Sstevel@tonic-gate 					if (strncmp(arg + 7, "pic", 3) == 0)
996*7c478bd9Sstevel@tonic-gate 						pic = 1;
997*7c478bd9Sstevel@tonic-gate 					break;
998*7c478bd9Sstevel@tonic-gate 				}
999*7c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xcache=", 8) == 0)
1000*7c478bd9Sstevel@tonic-gate 					break;
1001*7c478bd9Sstevel@tonic-gate 				error(arg);
1002*7c478bd9Sstevel@tonic-gate 				break;
1003*7c478bd9Sstevel@tonic-gate 			case 'd':
1004*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xdepend") == 0)
1005*7c478bd9Sstevel@tonic-gate 					break;
1006*7c478bd9Sstevel@tonic-gate 				error(arg);
1007*7c478bd9Sstevel@tonic-gate 				break;
1008*7c478bd9Sstevel@tonic-gate 			case 'F':
1009*7c478bd9Sstevel@tonic-gate 				/* compile for mapfile reordering -- ignore */
1010*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xF") == 0)
1011*7c478bd9Sstevel@tonic-gate 					break;
1012*7c478bd9Sstevel@tonic-gate 				error(arg);
1013*7c478bd9Sstevel@tonic-gate 				break;
1014*7c478bd9Sstevel@tonic-gate 			case 'i':
1015*7c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xinline", 8) == 0)
1016*7c478bd9Sstevel@tonic-gate 					/* No inlining; ignore */
1017*7c478bd9Sstevel@tonic-gate 					break;
1018*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xildon") == 0 ||
1019*7c478bd9Sstevel@tonic-gate 				    strcmp(arg, "-xildoff") == 0)
1020*7c478bd9Sstevel@tonic-gate 					/* No incremental linking; ignore */
1021*7c478bd9Sstevel@tonic-gate 					break;
1022*7c478bd9Sstevel@tonic-gate 				error(arg);
1023*7c478bd9Sstevel@tonic-gate 				break;
1024*7c478bd9Sstevel@tonic-gate 			case 'M':
1025*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xM") == 0) {
1026*7c478bd9Sstevel@tonic-gate 					newae(h, "-M");
1027*7c478bd9Sstevel@tonic-gate 					break;
1028*7c478bd9Sstevel@tonic-gate 				}
1029*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xM1") == 0) {
1030*7c478bd9Sstevel@tonic-gate 					newae(h, "-MM");
1031*7c478bd9Sstevel@tonic-gate 					break;
1032*7c478bd9Sstevel@tonic-gate 				}
1033*7c478bd9Sstevel@tonic-gate 				error(arg);
1034*7c478bd9Sstevel@tonic-gate 				break;
1035*7c478bd9Sstevel@tonic-gate 			case 'n':
1036*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xnolib") == 0) {
1037*7c478bd9Sstevel@tonic-gate 					nolibc = 1;
1038*7c478bd9Sstevel@tonic-gate 					break;
1039*7c478bd9Sstevel@tonic-gate 				}
1040*7c478bd9Sstevel@tonic-gate 				error(arg);
1041*7c478bd9Sstevel@tonic-gate 				break;
1042*7c478bd9Sstevel@tonic-gate 			case 'O':
1043*7c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xO", 3) == 0) {
1044*7c478bd9Sstevel@tonic-gate 					size_t len = strlen(arg);
1045*7c478bd9Sstevel@tonic-gate 					char *s = malloc(len);
1046*7c478bd9Sstevel@tonic-gate 					int c = *(arg + 3);
1047*7c478bd9Sstevel@tonic-gate 					int level;
1048*7c478bd9Sstevel@tonic-gate 
1049*7c478bd9Sstevel@tonic-gate 					if (len != 4 || !isdigit(c))
1050*7c478bd9Sstevel@tonic-gate 						error(arg);
1051*7c478bd9Sstevel@tonic-gate 
1052*7c478bd9Sstevel@tonic-gate 					level = atoi(arg + 3);
1053*7c478bd9Sstevel@tonic-gate 					if (level > 5)
1054*7c478bd9Sstevel@tonic-gate 						error(arg);
1055*7c478bd9Sstevel@tonic-gate 					if (level >= 2) {
1056*7c478bd9Sstevel@tonic-gate 						/*
1057*7c478bd9Sstevel@tonic-gate 						 * For gcc-3.4.x at -O2 we
1058*7c478bd9Sstevel@tonic-gate 						 * need to disable optimizations
1059*7c478bd9Sstevel@tonic-gate 						 * that break ON.
1060*7c478bd9Sstevel@tonic-gate 						 */
1061*7c478bd9Sstevel@tonic-gate 						optim_disable(h, level);
1062*7c478bd9Sstevel@tonic-gate 						/*
1063*7c478bd9Sstevel@tonic-gate 						 * limit -xO3 to -O2 as well.
1064*7c478bd9Sstevel@tonic-gate 						 */
1065*7c478bd9Sstevel@tonic-gate 						level = 2;
1066*7c478bd9Sstevel@tonic-gate 					}
1067*7c478bd9Sstevel@tonic-gate 					(void) snprintf(s, len, "-O%d", level);
1068*7c478bd9Sstevel@tonic-gate 					newae(h, s);
1069*7c478bd9Sstevel@tonic-gate 					free(s);
1070*7c478bd9Sstevel@tonic-gate 					break;
1071*7c478bd9Sstevel@tonic-gate 				}
1072*7c478bd9Sstevel@tonic-gate 				error(arg);
1073*7c478bd9Sstevel@tonic-gate 				break;
1074*7c478bd9Sstevel@tonic-gate 			case 'p':
1075*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xpentium") == 0) {
1076*7c478bd9Sstevel@tonic-gate 					newae(h, "-march=pentium");
1077*7c478bd9Sstevel@tonic-gate 					break;
1078*7c478bd9Sstevel@tonic-gate 				}
1079*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xpg") == 0) {
1080*7c478bd9Sstevel@tonic-gate 					newae(h, "-pg");
1081*7c478bd9Sstevel@tonic-gate 					break;
1082*7c478bd9Sstevel@tonic-gate 				}
1083*7c478bd9Sstevel@tonic-gate 				error(arg);
1084*7c478bd9Sstevel@tonic-gate 				break;
1085*7c478bd9Sstevel@tonic-gate 			case 'r':
1086*7c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xregs=", 7) == 0) {
1087*7c478bd9Sstevel@tonic-gate 					xlate(h, arg + 7, xregs_tbl);
1088*7c478bd9Sstevel@tonic-gate 					break;
1089*7c478bd9Sstevel@tonic-gate 				}
1090*7c478bd9Sstevel@tonic-gate 				error(arg);
1091*7c478bd9Sstevel@tonic-gate 				break;
1092*7c478bd9Sstevel@tonic-gate 			case 's':
1093*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xs") == 0 ||
1094*7c478bd9Sstevel@tonic-gate 				    strcmp(arg, "-xspace") == 0 ||
1095*7c478bd9Sstevel@tonic-gate 				    strcmp(arg, "-xstrconst") == 0)
1096*7c478bd9Sstevel@tonic-gate 					break;
1097*7c478bd9Sstevel@tonic-gate 				error(arg);
1098*7c478bd9Sstevel@tonic-gate 				break;
1099*7c478bd9Sstevel@tonic-gate 			case 't':
1100*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xtransition") == 0) {
1101*7c478bd9Sstevel@tonic-gate 					newae(h, "-Wtransition");
1102*7c478bd9Sstevel@tonic-gate 					break;
1103*7c478bd9Sstevel@tonic-gate 				}
1104*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xtrigraphs=yes") == 0) {
1105*7c478bd9Sstevel@tonic-gate 					newae(h, "-trigraphs");
1106*7c478bd9Sstevel@tonic-gate 					break;
1107*7c478bd9Sstevel@tonic-gate 				}
1108*7c478bd9Sstevel@tonic-gate 				if (strcmp(arg, "-xtrigraphs=no") == 0) {
1109*7c478bd9Sstevel@tonic-gate 					newae(h, "-notrigraphs");
1110*7c478bd9Sstevel@tonic-gate 					break;
1111*7c478bd9Sstevel@tonic-gate 				}
1112*7c478bd9Sstevel@tonic-gate 				if (strncmp(arg, "-xtarget=", 9) == 0) {
1113*7c478bd9Sstevel@tonic-gate 					xlate(h, arg + 9, xtarget_tbl);
1114*7c478bd9Sstevel@tonic-gate 					break;
1115*7c478bd9Sstevel@tonic-gate 				}
1116*7c478bd9Sstevel@tonic-gate 				error(arg);
1117*7c478bd9Sstevel@tonic-gate 				break;
1118*7c478bd9Sstevel@tonic-gate 			case 'b':
1119*7c478bd9Sstevel@tonic-gate 			case 'e':
1120*7c478bd9Sstevel@tonic-gate 			case 'h':
1121*7c478bd9Sstevel@tonic-gate 			case 'l':
1122*7c478bd9Sstevel@tonic-gate 			default:
1123*7c478bd9Sstevel@tonic-gate 				error(arg);
1124*7c478bd9Sstevel@tonic-gate 				break;
1125*7c478bd9Sstevel@tonic-gate 			}
1126*7c478bd9Sstevel@tonic-gate 			break;
1127*7c478bd9Sstevel@tonic-gate 		case 'Y':
1128*7c478bd9Sstevel@tonic-gate 			if (arglen == 1) {
1129*7c478bd9Sstevel@tonic-gate 				if ((arg = *++argv) == NULL || *arg == '\0')
1130*7c478bd9Sstevel@tonic-gate 					error("-Y");
1131*7c478bd9Sstevel@tonic-gate 				argc--;
1132*7c478bd9Sstevel@tonic-gate 				arglen = strlen(arg + 1);
1133*7c478bd9Sstevel@tonic-gate 			} else {
1134*7c478bd9Sstevel@tonic-gate 				arg += 2;
1135*7c478bd9Sstevel@tonic-gate 			}
1136*7c478bd9Sstevel@tonic-gate 			/* Just ignore -YS,... for now */
1137*7c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "S,", 2) == 0)
1138*7c478bd9Sstevel@tonic-gate 				break;
1139*7c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "l,", 2) == 0) {
1140*7c478bd9Sstevel@tonic-gate 				char *s = strdup(arg);
1141*7c478bd9Sstevel@tonic-gate 				s[0] = '-';
1142*7c478bd9Sstevel@tonic-gate 				s[1] = 'B';
1143*7c478bd9Sstevel@tonic-gate 				newae(h, s);
1144*7c478bd9Sstevel@tonic-gate 				free(s);
1145*7c478bd9Sstevel@tonic-gate 				break;
1146*7c478bd9Sstevel@tonic-gate 			}
1147*7c478bd9Sstevel@tonic-gate 			if (strncmp(arg, "I,", 2) == 0) {
1148*7c478bd9Sstevel@tonic-gate 				char *s = strdup(arg);
1149*7c478bd9Sstevel@tonic-gate 				s[0] = '-';
1150*7c478bd9Sstevel@tonic-gate 				s[1] = 'I';
1151*7c478bd9Sstevel@tonic-gate 				newae(h, "-nostdinc");
1152*7c478bd9Sstevel@tonic-gate 				newae(h, s);
1153*7c478bd9Sstevel@tonic-gate 				free(s);
1154*7c478bd9Sstevel@tonic-gate 				break;
1155*7c478bd9Sstevel@tonic-gate 			}
1156*7c478bd9Sstevel@tonic-gate 			error(arg);
1157*7c478bd9Sstevel@tonic-gate 			break;
1158*7c478bd9Sstevel@tonic-gate 		case 'Q':
1159*7c478bd9Sstevel@tonic-gate 			/*
1160*7c478bd9Sstevel@tonic-gate 			 * We could map -Qy into -Wl,-Qy etc.
1161*7c478bd9Sstevel@tonic-gate 			 */
1162*7c478bd9Sstevel@tonic-gate 		default:
1163*7c478bd9Sstevel@tonic-gate 			error(arg);
1164*7c478bd9Sstevel@tonic-gate 			break;
1165*7c478bd9Sstevel@tonic-gate 		}
1166*7c478bd9Sstevel@tonic-gate 	}
1167*7c478bd9Sstevel@tonic-gate 
1168*7c478bd9Sstevel@tonic-gate 	if (model && !pic)
1169*7c478bd9Sstevel@tonic-gate 		newae(h, model);
1170*7c478bd9Sstevel@tonic-gate 	if (!nolibc)
1171*7c478bd9Sstevel@tonic-gate 		newae(h, "-lc");
1172*7c478bd9Sstevel@tonic-gate }
1173*7c478bd9Sstevel@tonic-gate 
1174*7c478bd9Sstevel@tonic-gate /* ARGSUSED4 */
1175*7c478bd9Sstevel@tonic-gate static void
1176*7c478bd9Sstevel@tonic-gate do_cc(const char *dir, const char *cmd, int argc, char **argv,
1177*7c478bd9Sstevel@tonic-gate     struct aelist *h, int cplusplus)
1178*7c478bd9Sstevel@tonic-gate {
1179*7c478bd9Sstevel@tonic-gate 	char *program;
1180*7c478bd9Sstevel@tonic-gate 	size_t len = strlen(dir) + strlen(cmd) + 2;
1181*7c478bd9Sstevel@tonic-gate 
1182*7c478bd9Sstevel@tonic-gate 	program = malloc(len);
1183*7c478bd9Sstevel@tonic-gate 	(void) snprintf(program, len, "%s/%s", dir, cmd);
1184*7c478bd9Sstevel@tonic-gate 
1185*7c478bd9Sstevel@tonic-gate 	/*
1186*7c478bd9Sstevel@tonic-gate 	 * This is pretty simple.
1187*7c478bd9Sstevel@tonic-gate 	 * We just have to recognize -V, -_noecho, -_compiler, -_cc= and -_gcc=
1188*7c478bd9Sstevel@tonic-gate 	 */
1189*7c478bd9Sstevel@tonic-gate 	newae(h, program);
1190*7c478bd9Sstevel@tonic-gate 
1191*7c478bd9Sstevel@tonic-gate 	while (--argc > 0) {
1192*7c478bd9Sstevel@tonic-gate 		char *arg = *++argv;
1193*7c478bd9Sstevel@tonic-gate 
1194*7c478bd9Sstevel@tonic-gate 		if (*arg != '-') {
1195*7c478bd9Sstevel@tonic-gate 			newae(h, arg);
1196*7c478bd9Sstevel@tonic-gate 		} else if (*(arg + 1) != '_') {
1197*7c478bd9Sstevel@tonic-gate 			if (strcmp(arg, "-V") == 0)
1198*7c478bd9Sstevel@tonic-gate 				echo = 0;
1199*7c478bd9Sstevel@tonic-gate 			newae(h, arg);
1200*7c478bd9Sstevel@tonic-gate 		} else if (strcmp(arg, "-_noecho") == 0) {
1201*7c478bd9Sstevel@tonic-gate 			echo = 0;
1202*7c478bd9Sstevel@tonic-gate 		} else if (strcmp(arg, "-_compiler") == 0) {
1203*7c478bd9Sstevel@tonic-gate 			(void) printf("%s\n", program);
1204*7c478bd9Sstevel@tonic-gate 			exit(0);
1205*7c478bd9Sstevel@tonic-gate 		} else if (strncmp(arg, "-_cc=", 5) == 0 ||
1206*7c478bd9Sstevel@tonic-gate 		    strncmp(arg, "-_CC=", 5) == 0) {
1207*7c478bd9Sstevel@tonic-gate 			newae(h, arg + 5);
1208*7c478bd9Sstevel@tonic-gate 		} else if (strncmp(arg, "-_gcc=", 6) != 0 &&
1209*7c478bd9Sstevel@tonic-gate 		    strncmp(arg, "-_g++=", 6) != 0) {
1210*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
1211*7c478bd9Sstevel@tonic-gate 			    "%s: invalid argument '%s'\n", progname, arg);
1212*7c478bd9Sstevel@tonic-gate 			exit(2);
1213*7c478bd9Sstevel@tonic-gate 		}
1214*7c478bd9Sstevel@tonic-gate 	}
1215*7c478bd9Sstevel@tonic-gate }
1216*7c478bd9Sstevel@tonic-gate 
1217*7c478bd9Sstevel@tonic-gate int
1218*7c478bd9Sstevel@tonic-gate main(int argc, char **argv)
1219*7c478bd9Sstevel@tonic-gate {
1220*7c478bd9Sstevel@tonic-gate 	struct aelist *h = newael();
1221*7c478bd9Sstevel@tonic-gate 	const char *dir;
1222*7c478bd9Sstevel@tonic-gate 	int ac;
1223*7c478bd9Sstevel@tonic-gate 	char **newargv;
1224*7c478bd9Sstevel@tonic-gate 	struct ae *a;
1225*7c478bd9Sstevel@tonic-gate 	char cc_buf[MAXPATHLEN], gcc_buf[MAXPATHLEN];
1226*7c478bd9Sstevel@tonic-gate 
1227*7c478bd9Sstevel@tonic-gate 	if ((progname = strrchr(argv[0], '/')) == NULL)
1228*7c478bd9Sstevel@tonic-gate 		progname = argv[0];
1229*7c478bd9Sstevel@tonic-gate 	else
1230*7c478bd9Sstevel@tonic-gate 		progname++;
1231*7c478bd9Sstevel@tonic-gate 
1232*7c478bd9Sstevel@tonic-gate 	default_cc_dir = DEFAULT_CC_DIR;
1233*7c478bd9Sstevel@tonic-gate 	default_gcc_dir = DEFAULT_GCC_DIR;
1234*7c478bd9Sstevel@tonic-gate 	default_cplusplus_dir = DEFAULT_CPLUSPLUS_DIR;
1235*7c478bd9Sstevel@tonic-gate 	default_gplusplus_dir = DEFAULT_GPLUSPLUS_DIR;
1236*7c478bd9Sstevel@tonic-gate 
1237*7c478bd9Sstevel@tonic-gate 	/*
1238*7c478bd9Sstevel@tonic-gate 	 * Figure out where to get our tools from.  This depends on
1239*7c478bd9Sstevel@tonic-gate 	 * the environment variables set at run time.
1240*7c478bd9Sstevel@tonic-gate 	 */
1241*7c478bd9Sstevel@tonic-gate 	if ((dir = getenv("SPRO_VROOT")) != NULL) {
1242*7c478bd9Sstevel@tonic-gate 		(void) snprintf(cc_buf, MAXPATHLEN, "%s/bin", dir);
1243*7c478bd9Sstevel@tonic-gate 	} else if ((dir = getenv("SPRO_ROOT")) != NULL) {
1244*7c478bd9Sstevel@tonic-gate 		(void) snprintf(cc_buf, MAXPATHLEN, "%s/SOS8/bin", dir);
1245*7c478bd9Sstevel@tonic-gate 	} else if ((dir = getenv("BUILD_TOOLS")) != NULL) {
1246*7c478bd9Sstevel@tonic-gate 		(void) snprintf(cc_buf, MAXPATHLEN,
1247*7c478bd9Sstevel@tonic-gate 		    "%s/SUNWspro/SOS8/bin", dir);
1248*7c478bd9Sstevel@tonic-gate 	}
1249*7c478bd9Sstevel@tonic-gate 	if (dir != NULL)
1250*7c478bd9Sstevel@tonic-gate 		default_cc_dir = (char *)cc_buf;
1251*7c478bd9Sstevel@tonic-gate 
1252*7c478bd9Sstevel@tonic-gate 	if ((dir = getenv("GNU_ROOT")) != NULL) {
1253*7c478bd9Sstevel@tonic-gate 		(void) snprintf(gcc_buf, MAXPATHLEN, "%s/bin", dir);
1254*7c478bd9Sstevel@tonic-gate 		default_gcc_dir = (char *)gcc_buf;
1255*7c478bd9Sstevel@tonic-gate 	}
1256*7c478bd9Sstevel@tonic-gate 
1257*7c478bd9Sstevel@tonic-gate 	default_cplusplus_dir = default_cc_dir;
1258*7c478bd9Sstevel@tonic-gate 	default_gplusplus_dir = default_gcc_dir;
1259*7c478bd9Sstevel@tonic-gate 
1260*7c478bd9Sstevel@tonic-gate 	/*
1261*7c478bd9Sstevel@tonic-gate 	 * The first argument must be one of "-_cc", "-_gcc", "-_CC", or "-_g++"
1262*7c478bd9Sstevel@tonic-gate 	 */
1263*7c478bd9Sstevel@tonic-gate 	if (argc == 1)
1264*7c478bd9Sstevel@tonic-gate 		usage();
1265*7c478bd9Sstevel@tonic-gate 	argc--;
1266*7c478bd9Sstevel@tonic-gate 	argv++;
1267*7c478bd9Sstevel@tonic-gate 	if (strcmp(argv[0], "-_cc") == 0) {
1268*7c478bd9Sstevel@tonic-gate 		if ((dir = getenv("CW_CC_DIR")) == NULL)
1269*7c478bd9Sstevel@tonic-gate 			dir = default_cc_dir;
1270*7c478bd9Sstevel@tonic-gate 		do_cc(dir, "cc", argc, argv, h, 0);
1271*7c478bd9Sstevel@tonic-gate 	} else if (strcmp(argv[0], "-_gcc") == 0) {
1272*7c478bd9Sstevel@tonic-gate 		if ((dir = getenv("CW_GCC_DIR")) == NULL)
1273*7c478bd9Sstevel@tonic-gate 			dir = default_gcc_dir;
1274*7c478bd9Sstevel@tonic-gate 		do_gcc(dir, "gcc", argc, argv, h, 0);
1275*7c478bd9Sstevel@tonic-gate 	} else if (strcmp(argv[0], "-_CC") == 0) {
1276*7c478bd9Sstevel@tonic-gate 		if ((dir = getenv("CW_CPLUSPLUS_DIR")) == NULL)
1277*7c478bd9Sstevel@tonic-gate 			dir = default_cplusplus_dir;
1278*7c478bd9Sstevel@tonic-gate 		do_cc(dir, "CC", argc, argv, h, 1);
1279*7c478bd9Sstevel@tonic-gate 	} else if (strcmp(argv[0], "-_g++") == 0) {
1280*7c478bd9Sstevel@tonic-gate 		if ((dir = getenv("CW_GPLUSPLUS_DIR")) == NULL)
1281*7c478bd9Sstevel@tonic-gate 			dir = default_gplusplus_dir;
1282*7c478bd9Sstevel@tonic-gate 		do_gcc(dir, "g++", argc, argv, h, 1);
1283*7c478bd9Sstevel@tonic-gate 	} else {
1284*7c478bd9Sstevel@tonic-gate 		/* assume "-_gcc" by default */
1285*7c478bd9Sstevel@tonic-gate 		argc++;
1286*7c478bd9Sstevel@tonic-gate 		argv--;
1287*7c478bd9Sstevel@tonic-gate 		if ((dir = getenv("CW_GCC_DIR")) == NULL)
1288*7c478bd9Sstevel@tonic-gate 			dir = default_gcc_dir;
1289*7c478bd9Sstevel@tonic-gate 		do_gcc(dir, "gcc", argc, argv, h, 0);
1290*7c478bd9Sstevel@tonic-gate 	}
1291*7c478bd9Sstevel@tonic-gate 
1292*7c478bd9Sstevel@tonic-gate 	newargv = calloc(sizeof (*newargv), newargc + 1);
1293*7c478bd9Sstevel@tonic-gate 
1294*7c478bd9Sstevel@tonic-gate 	if (echo)
1295*7c478bd9Sstevel@tonic-gate 		(void) printf("+ ");
1296*7c478bd9Sstevel@tonic-gate 
1297*7c478bd9Sstevel@tonic-gate 	for (ac = 0, a = h->ael_head; a; a = a->ae_next, ac++) {
1298*7c478bd9Sstevel@tonic-gate 		newargv[ac] = a->ae_arg;
1299*7c478bd9Sstevel@tonic-gate 		if (echo)
1300*7c478bd9Sstevel@tonic-gate 			(void) printf("%s ", a->ae_arg);
1301*7c478bd9Sstevel@tonic-gate 		if (a == h->ael_tail)
1302*7c478bd9Sstevel@tonic-gate 			break;
1303*7c478bd9Sstevel@tonic-gate 	}
1304*7c478bd9Sstevel@tonic-gate 
1305*7c478bd9Sstevel@tonic-gate 	if (echo) {
1306*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1307*7c478bd9Sstevel@tonic-gate 		(void) fflush(stdout);
1308*7c478bd9Sstevel@tonic-gate 	}
1309*7c478bd9Sstevel@tonic-gate 
1310*7c478bd9Sstevel@tonic-gate 	/*
1311*7c478bd9Sstevel@tonic-gate 	 * Here goes ..
1312*7c478bd9Sstevel@tonic-gate 	 */
1313*7c478bd9Sstevel@tonic-gate 	(void) execvp(newargv[0], newargv);
1314*7c478bd9Sstevel@tonic-gate 
1315*7c478bd9Sstevel@tonic-gate 	/*
1316*7c478bd9Sstevel@tonic-gate 	 * execvp() returns only on error.
1317*7c478bd9Sstevel@tonic-gate 	 */
1318*7c478bd9Sstevel@tonic-gate 	perror("execvp");
1319*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "%s: couldn't run %s\n",
1320*7c478bd9Sstevel@tonic-gate 	    progname, newargv[0]);
1321*7c478bd9Sstevel@tonic-gate 	return (4);
1322*7c478bd9Sstevel@tonic-gate }
1323