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