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