1*aa9ef484SJohn Levon 27c478bd9Sstevel@tonic-gate /* 37c478bd9Sstevel@tonic-gate * CDDL HEADER START 47c478bd9Sstevel@tonic-gate * 57c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 602e56f3fSwesolows * Common Development and Distribution License (the "License"). 702e56f3fSwesolows * You may not use this file except in compliance 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 */ 2202e56f3fSwesolows 2325c28e83SPiotr Jasiukajtis /* 24*aa9ef484SJohn Levon * Copyright 2018, Richard Lowe. 2525c28e83SPiotr Jasiukajtis */ 267c478bd9Sstevel@tonic-gate /* 277fbf8d03SScott Rotondo * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 287c478bd9Sstevel@tonic-gate * Use is subject to license terms. 297c478bd9Sstevel@tonic-gate */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate /* 327c478bd9Sstevel@tonic-gate * Wrapper for the GNU C compiler to make it accept the Sun C compiler 337c478bd9Sstevel@tonic-gate * arguments where possible. 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate * Since the translation is inexact, this is something of a work-in-progress. 369a70fc3bSMark J. Nelson * 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 399a70fc3bSMark J. Nelson /* If you modify this file, you must increment CW_VERSION */ 40*aa9ef484SJohn Levon #define CW_VERSION "2.0" 419a70fc3bSMark J. Nelson 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * -# Verbose mode 447c478bd9Sstevel@tonic-gate * -### Show compiler commands built by driver, no compilation 457c478bd9Sstevel@tonic-gate * -A<name[(tokens)]> Preprocessor predicate assertion 467c478bd9Sstevel@tonic-gate * -B<[static|dynamic]> Specify dynamic or static binding 477c478bd9Sstevel@tonic-gate * -C Prevent preprocessor from removing comments 487c478bd9Sstevel@tonic-gate * -c Compile only - produce .o files, suppress linking 497c478bd9Sstevel@tonic-gate * -cg92 Alias for -xtarget=ss1000 507c478bd9Sstevel@tonic-gate * -D<name[=token]> Associate name with token as if by #define 517c478bd9Sstevel@tonic-gate * -d[y|n] dynamic [-dy] or static [-dn] option to linker 527c478bd9Sstevel@tonic-gate * -E Compile source through preprocessor only, output to stdout 537c478bd9Sstevel@tonic-gate * -erroff=<t> Suppress warnings specified by tags t(%none, %all, <tag list>) 547c478bd9Sstevel@tonic-gate * -errtags=<a> Display messages with tags a(no, yes) 557c478bd9Sstevel@tonic-gate * -errwarn=<t> Treats warnings specified by tags t(%none, %all, <tag list>) 567c478bd9Sstevel@tonic-gate * as errors 577c478bd9Sstevel@tonic-gate * -fast Optimize using a selection of options 587c478bd9Sstevel@tonic-gate * -fd Report old-style function definitions and declarations 590e62f92eSMark Logan * -features=zla Allow zero-length arrays 607c478bd9Sstevel@tonic-gate * -flags Show this summary of compiler options 617c478bd9Sstevel@tonic-gate * -fnonstd Initialize floating-point hardware to non-standard preferences 627c478bd9Sstevel@tonic-gate * -fns[=<yes|no>] Select non-standard floating point mode 637c478bd9Sstevel@tonic-gate * -fprecision=<p> Set FP rounding precision mode p(single, double, extended) 647c478bd9Sstevel@tonic-gate * -fround=<r> Select the IEEE rounding mode in effect at startup 657c478bd9Sstevel@tonic-gate * -fsimple[=<n>] Select floating-point optimization preferences <n> 667c478bd9Sstevel@tonic-gate * -fsingle Use single-precision arithmetic (-Xt and -Xs modes only) 677c478bd9Sstevel@tonic-gate * -ftrap=<t> Select floating-point trapping mode in effect at startup 687c478bd9Sstevel@tonic-gate * -fstore force floating pt. values to target precision on assignment 697c478bd9Sstevel@tonic-gate * -G Build a dynamic shared library 707c478bd9Sstevel@tonic-gate * -g Compile for debugging 717c478bd9Sstevel@tonic-gate * -H Print path name of each file included during compilation 727c478bd9Sstevel@tonic-gate * -h <name> Assign <name> to generated dynamic shared library 737c478bd9Sstevel@tonic-gate * -I<dir> Add <dir> to preprocessor #include file search path 747c478bd9Sstevel@tonic-gate * -i Passed to linker to ignore any LD_LIBRARY_PATH setting 757c478bd9Sstevel@tonic-gate * -keeptmp Keep temporary files created during compilation 767c478bd9Sstevel@tonic-gate * -KPIC Compile position independent code with 32-bit addresses 777c478bd9Sstevel@tonic-gate * -Kpic Compile position independent code 787c478bd9Sstevel@tonic-gate * -L<dir> Pass to linker to add <dir> to the library search path 797c478bd9Sstevel@tonic-gate * -l<name> Link with library lib<name>.a or lib<name>.so 807c478bd9Sstevel@tonic-gate * -mc Remove duplicate strings from .comment section of output files 817c478bd9Sstevel@tonic-gate * -mr Remove all strings from .comment section of output files 827c478bd9Sstevel@tonic-gate * -mr,"string" Remove all strings and append "string" to .comment section 837c478bd9Sstevel@tonic-gate * -mt Specify options needed when compiling multi-threaded code 847c478bd9Sstevel@tonic-gate * -native Find available processor, generate code accordingly 857c478bd9Sstevel@tonic-gate * -nofstore Do not force floating pt. values to target precision 867c478bd9Sstevel@tonic-gate * on assignment 877c478bd9Sstevel@tonic-gate * -nolib Same as -xnolib 887c478bd9Sstevel@tonic-gate * -noqueue Disable queuing of compiler license requests 897c478bd9Sstevel@tonic-gate * -norunpath Do not build in a runtime path for shared libraries 90662492f5Ssherrym * -O Use default optimization level (-xO2 or -xO3. Check man page.) 917c478bd9Sstevel@tonic-gate * -o <outputfile> Set name of output file to <outputfile> 927c478bd9Sstevel@tonic-gate * -P Compile source through preprocessor only, output to .i file 937c478bd9Sstevel@tonic-gate * -PIC Alias for -KPIC or -xcode=pic32 947c478bd9Sstevel@tonic-gate * -p Compile for profiling with prof 957c478bd9Sstevel@tonic-gate * -pic Alias for -Kpic or -xcode=pic13 967c478bd9Sstevel@tonic-gate * -Q[y|n] Emit/don't emit identification info to output file 977c478bd9Sstevel@tonic-gate * -qp Compile for profiling with prof 987c478bd9Sstevel@tonic-gate * -R<dir[:dir]> Build runtime search path list into executable 997c478bd9Sstevel@tonic-gate * -S Compile and only generate assembly code (.s) 1007c478bd9Sstevel@tonic-gate * -s Strip symbol table from the executable file 101159cf8a6Swesolows * -t Turn off duplicate symbol warnings when linking 1027c478bd9Sstevel@tonic-gate * -U<name> Delete initial definition of preprocessor symbol <name> 1037c478bd9Sstevel@tonic-gate * -V Report version number of each compilation phase 1047c478bd9Sstevel@tonic-gate * -v Do stricter semantic checking 1057c478bd9Sstevel@tonic-gate * -W<c>,<arg> Pass <arg> to specified component <c> (a,l,m,p,0,2,h,i,u) 1067c478bd9Sstevel@tonic-gate * -w Suppress compiler warning messages 1077c478bd9Sstevel@tonic-gate * -Xa Compile assuming ANSI C conformance, allow K & R extensions 1087c478bd9Sstevel@tonic-gate * (default mode) 1097c478bd9Sstevel@tonic-gate * -Xc Compile assuming strict ANSI C conformance 1107c478bd9Sstevel@tonic-gate * -Xs Compile assuming (pre-ANSI) K & R C style code 1117c478bd9Sstevel@tonic-gate * -Xt Compile assuming K & R conformance, allow ANSI C 1127c478bd9Sstevel@tonic-gate * -x386 Generate code for the 80386 processor 1137c478bd9Sstevel@tonic-gate * -x486 Generate code for the 80486 processor 1147c478bd9Sstevel@tonic-gate * -xarch=<a> Specify target architecture instruction set 1157c478bd9Sstevel@tonic-gate * -xbuiltin[=<b>] When profitable inline, or substitute intrinisic functions 1167c478bd9Sstevel@tonic-gate * for system functions, b={%all,%none} 1177c478bd9Sstevel@tonic-gate * -xCC Accept C++ style comments 1187c478bd9Sstevel@tonic-gate * -xchar_byte_order=<o> Specify multi-char byte order <o> (default, high, low) 1197c478bd9Sstevel@tonic-gate * -xchip=<c> Specify the target processor for use by the optimizer 1207c478bd9Sstevel@tonic-gate * -xcode=<c> Generate different code for forming addresses 1217c478bd9Sstevel@tonic-gate * -xcrossfile[=<n>] Enable optimization and inlining across source files, 1227c478bd9Sstevel@tonic-gate * n={0|1} 1237c478bd9Sstevel@tonic-gate * -xe Perform only syntax/semantic checking, no code generation 124f795e658Srie * -xF Compile for later mapfile reordering or unused section 125f795e658Srie * elimination 1267c478bd9Sstevel@tonic-gate * -xhelp=<f> Display on-line help information f(flags, readme, errors) 1277c478bd9Sstevel@tonic-gate * -xildoff Cancel -xildon 1287c478bd9Sstevel@tonic-gate * -xildon Enable use of the incremental linker, ild 1297c478bd9Sstevel@tonic-gate * -xinline=[<a>,...,<a>] Attempt inlining of specified user routines, 1307c478bd9Sstevel@tonic-gate * <a>={%auto,func,no%func} 1317c478bd9Sstevel@tonic-gate * -xlibmieee Force IEEE 754 return values for math routines in 1327c478bd9Sstevel@tonic-gate * exceptional cases 1337c478bd9Sstevel@tonic-gate * -xlibmil Inline selected libm math routines for optimization 1347c478bd9Sstevel@tonic-gate * -xlic_lib=sunperf Link in the Sun supplied performance libraries 1357c478bd9Sstevel@tonic-gate * -xlicinfo Show license server information 1367c478bd9Sstevel@tonic-gate * -xM Generate makefile dependencies 1377c478bd9Sstevel@tonic-gate * -xM1 Generate makefile dependencies, but exclude /usr/include 1387c478bd9Sstevel@tonic-gate * -xmaxopt=[off,1,2,3,4,5] maximum optimization level allowed on #pragma opt 1397c478bd9Sstevel@tonic-gate * -xnolib Do not link with default system libraries 1407c478bd9Sstevel@tonic-gate * -xnolibmil Cancel -xlibmil on command line 1417c478bd9Sstevel@tonic-gate * -xO<n> Generate optimized code (n={1|2|3|4|5}) 1427c478bd9Sstevel@tonic-gate * -xP Print prototypes for function definitions 1437c478bd9Sstevel@tonic-gate * -xpentium Generate code for the pentium processor 1447c478bd9Sstevel@tonic-gate * -xpg Compile for profiling with gprof 1457c478bd9Sstevel@tonic-gate * -xprofile=<p> Collect data for a profile or use a profile to optimize 1467c478bd9Sstevel@tonic-gate * <p>={{collect,use}[:<path>],tcov} 1477c478bd9Sstevel@tonic-gate * -xregs=<r> Control register allocation 1487c478bd9Sstevel@tonic-gate * -xs Allow debugging without object (.o) files 1497c478bd9Sstevel@tonic-gate * -xsb Compile for use with the WorkShop source browser 1507c478bd9Sstevel@tonic-gate * -xsbfast Generate only WorkShop source browser info, no compilation 1517c478bd9Sstevel@tonic-gate * -xsfpconst Represent unsuffixed floating point constants as single 1527c478bd9Sstevel@tonic-gate * precision 1537c478bd9Sstevel@tonic-gate * -xspace Do not do optimizations that increase code size 1547c478bd9Sstevel@tonic-gate * -xstrconst Place string literals into read-only data segment 1557c478bd9Sstevel@tonic-gate * -xtarget=<t> Specify target system for optimization 1567c478bd9Sstevel@tonic-gate * -xtemp=<dir> Set directory for temporary files to <dir> 1577c478bd9Sstevel@tonic-gate * -xtime Report the execution time for each compilation phase 1587c478bd9Sstevel@tonic-gate * -xtransition Emit warnings for differences between K&R C and ANSI C 1597c478bd9Sstevel@tonic-gate * -xtrigraphs[=<yes|no>] Enable|disable trigraph translation 1607c478bd9Sstevel@tonic-gate * -xunroll=n Enable unrolling loops n times where possible 1617c478bd9Sstevel@tonic-gate * -Y<c>,<dir> Specify <dir> for location of component <c> (a,l,m,p,0,h,i,u) 1627c478bd9Sstevel@tonic-gate * -YA,<dir> Change default directory searched for components 1637c478bd9Sstevel@tonic-gate * -YI,<dir> Change default directory searched for include files 1647c478bd9Sstevel@tonic-gate * -YP,<dir> Change default directory for finding libraries files 1657c478bd9Sstevel@tonic-gate * -YS,<dir> Change default directory for startup object files 1667c478bd9Sstevel@tonic-gate */ 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate /* 1697c478bd9Sstevel@tonic-gate * Translation table: 1707c478bd9Sstevel@tonic-gate */ 1717c478bd9Sstevel@tonic-gate /* 1727c478bd9Sstevel@tonic-gate * -# -v 1737c478bd9Sstevel@tonic-gate * -### error 1747c478bd9Sstevel@tonic-gate * -A<name[(tokens)]> pass-thru 1757c478bd9Sstevel@tonic-gate * -B<[static|dynamic]> pass-thru (syntax error for anything else) 1767c478bd9Sstevel@tonic-gate * -C pass-thru 1777c478bd9Sstevel@tonic-gate * -c pass-thru 1787c478bd9Sstevel@tonic-gate * -cg92 -m32 -mcpu=v8 -mtune=supersparc (SPARC only) 1797c478bd9Sstevel@tonic-gate * -D<name[=token]> pass-thru 1807c478bd9Sstevel@tonic-gate * -dy or -dn -Wl,-dy or -Wl,-dn 1817c478bd9Sstevel@tonic-gate * -E pass-thru 1827c478bd9Sstevel@tonic-gate * -erroff=E_EMPTY_TRANSLATION_UNIT ignore 1837c478bd9Sstevel@tonic-gate * -errtags=%all -Wall 1847c478bd9Sstevel@tonic-gate * -errwarn=%all -Werror else -Wno-error 1857c478bd9Sstevel@tonic-gate * -fast error 1867c478bd9Sstevel@tonic-gate * -fd error 1870e62f92eSMark Logan * -features=zla ignore 1887c478bd9Sstevel@tonic-gate * -flags --help 1897c478bd9Sstevel@tonic-gate * -fnonstd error 1907c478bd9Sstevel@tonic-gate * -fns[=<yes|no>] error 1917c478bd9Sstevel@tonic-gate * -fprecision=<p> error 1927c478bd9Sstevel@tonic-gate * -fround=<r> error 1937c478bd9Sstevel@tonic-gate * -fsimple[=<n>] error 1947c478bd9Sstevel@tonic-gate * -fsingle[=<n>] error 1957c478bd9Sstevel@tonic-gate * -ftrap=<t> error 1967c478bd9Sstevel@tonic-gate * -fstore error 1977c478bd9Sstevel@tonic-gate * -G pass-thru 1987c478bd9Sstevel@tonic-gate * -g pass-thru 1997c478bd9Sstevel@tonic-gate * -H pass-thru 2007c478bd9Sstevel@tonic-gate * -h <name> pass-thru 2017c478bd9Sstevel@tonic-gate * -I<dir> pass-thru 2027c478bd9Sstevel@tonic-gate * -i pass-thru 2037c478bd9Sstevel@tonic-gate * -keeptmp -save-temps 2047c478bd9Sstevel@tonic-gate * -KPIC -fPIC 2057c478bd9Sstevel@tonic-gate * -Kpic -fpic 2067c478bd9Sstevel@tonic-gate * -L<dir> pass-thru 2077c478bd9Sstevel@tonic-gate * -l<name> pass-thru 2087c478bd9Sstevel@tonic-gate * -mc error 2097c478bd9Sstevel@tonic-gate * -mr error 2107c478bd9Sstevel@tonic-gate * -mr,"string" error 2117c478bd9Sstevel@tonic-gate * -mt -D_REENTRANT 2127c478bd9Sstevel@tonic-gate * -native error 2137c478bd9Sstevel@tonic-gate * -nofstore error 2147c478bd9Sstevel@tonic-gate * -nolib -nodefaultlibs 2157c478bd9Sstevel@tonic-gate * -noqueue ignore 2167c478bd9Sstevel@tonic-gate * -norunpath ignore 217662492f5Ssherrym * -O -O1 (Check the man page to be certain) 2187c478bd9Sstevel@tonic-gate * -o <outputfile> pass-thru 2197c478bd9Sstevel@tonic-gate * -P -E -o filename.i (or error) 2207c478bd9Sstevel@tonic-gate * -PIC -fPIC (C++ only) 2217c478bd9Sstevel@tonic-gate * -p pass-thru 2227c478bd9Sstevel@tonic-gate * -pic -fpic (C++ only) 2237c478bd9Sstevel@tonic-gate * -Q[y|n] error 2247c478bd9Sstevel@tonic-gate * -qp -p 2257c478bd9Sstevel@tonic-gate * -R<dir[:dir]> pass-thru 2267c478bd9Sstevel@tonic-gate * -S pass-thru 2277c478bd9Sstevel@tonic-gate * -s -Wl,-s 228159cf8a6Swesolows * -t -Wl,-t 2297c478bd9Sstevel@tonic-gate * -U<name> pass-thru 2307c478bd9Sstevel@tonic-gate * -V --version 2317c478bd9Sstevel@tonic-gate * -v -Wall 2327c478bd9Sstevel@tonic-gate * -Wa,<arg> pass-thru 2337c478bd9Sstevel@tonic-gate * -Wp,<arg> pass-thru except -xc99=<a> 2347c478bd9Sstevel@tonic-gate * -Wl,<arg> pass-thru 2357c478bd9Sstevel@tonic-gate * -W{m,0,2,h,i,u> error/ignore 2367c478bd9Sstevel@tonic-gate * -Wu,-xmodel=kernel -ffreestanding -mcmodel=kernel -mno-red-zone 23754836668Spetede * -xmodel=kernel -ffreestanding -mcmodel=kernel -mno-red-zone 238d430274bSsherrym * -Wu,-save_args -msave-args 2397c478bd9Sstevel@tonic-gate * -w pass-thru 2407c478bd9Sstevel@tonic-gate * -Xa -std=iso9899:199409 or -ansi 2417c478bd9Sstevel@tonic-gate * -Xc -ansi -pedantic 2427c478bd9Sstevel@tonic-gate * -Xt error 2437c478bd9Sstevel@tonic-gate * -Xs -traditional -std=c89 2447c478bd9Sstevel@tonic-gate * -x386 -march=i386 (x86 only) 2457c478bd9Sstevel@tonic-gate * -x486 -march=i486 (x86 only) 2467c478bd9Sstevel@tonic-gate * -xarch=<a> table 24702e56f3fSwesolows * -xbuiltin[=<b>] -fbuiltin (-fno-builtin otherwise) 2487c478bd9Sstevel@tonic-gate * -xCC ignore 2497c478bd9Sstevel@tonic-gate * -xchar_byte_order=<o> error 2507c478bd9Sstevel@tonic-gate * -xchip=<c> table 2517c478bd9Sstevel@tonic-gate * -xcode=<c> table 2528c1a3716Ssherrym * -xdebugformat=<format> ignore (always use dwarf-2 for gcc) 253159cf8a6Swesolows * -xcrossfile[=<n>] ignore 2547c478bd9Sstevel@tonic-gate * -xe error 2557c478bd9Sstevel@tonic-gate * -xF error 2567c478bd9Sstevel@tonic-gate * -xhelp=<f> error 2577c478bd9Sstevel@tonic-gate * -xildoff ignore 2587c478bd9Sstevel@tonic-gate * -xildon ignore 2597c478bd9Sstevel@tonic-gate * -xinline ignore 2607c478bd9Sstevel@tonic-gate * -xlibmieee error 2617c478bd9Sstevel@tonic-gate * -xlibmil error 2627c478bd9Sstevel@tonic-gate * -xlic_lib=sunperf error 2637c478bd9Sstevel@tonic-gate * -xM -M 2647c478bd9Sstevel@tonic-gate * -xM1 -MM 2657c478bd9Sstevel@tonic-gate * -xmaxopt=[...] error 2667c478bd9Sstevel@tonic-gate * -xnolib -nodefaultlibs 2677c478bd9Sstevel@tonic-gate * -xnolibmil error 2687c478bd9Sstevel@tonic-gate * -xO<n> -O<n> 2697c478bd9Sstevel@tonic-gate * -xP error 2707c478bd9Sstevel@tonic-gate * -xpentium -march=pentium (x86 only) 2717c478bd9Sstevel@tonic-gate * -xpg error 2727c478bd9Sstevel@tonic-gate * -xprofile=<p> error 2737c478bd9Sstevel@tonic-gate * -xregs=<r> table 2747c478bd9Sstevel@tonic-gate * -xs error 2757c478bd9Sstevel@tonic-gate * -xsb error 2767c478bd9Sstevel@tonic-gate * -xsbfast error 2777c478bd9Sstevel@tonic-gate * -xsfpconst error 2787c478bd9Sstevel@tonic-gate * -xspace ignore (-not -Os) 2797c478bd9Sstevel@tonic-gate * -xstrconst ignore 2807c478bd9Sstevel@tonic-gate * -xtarget=<t> table 2817c478bd9Sstevel@tonic-gate * -xtemp=<dir> error 2827c478bd9Sstevel@tonic-gate * -xtime error 2837c478bd9Sstevel@tonic-gate * -xtransition -Wtransition 2847c478bd9Sstevel@tonic-gate * -xtrigraphs=<yes|no> -trigraphs -notrigraphs 2857c478bd9Sstevel@tonic-gate * -xunroll=n error 2868c1a3716Ssherrym * -W0,-xdbggen=no%usedonly -fno-eliminate-unused-debug-symbols 2878c1a3716Ssherrym * -fno-eliminate-unused-debug-types 2887c478bd9Sstevel@tonic-gate * -Y<c>,<dir> error 2897c478bd9Sstevel@tonic-gate * -YA,<dir> error 2907c478bd9Sstevel@tonic-gate * -YI,<dir> -nostdinc -I<dir> 2917c478bd9Sstevel@tonic-gate * -YP,<dir> error 2927c478bd9Sstevel@tonic-gate * -YS,<dir> error 2937c478bd9Sstevel@tonic-gate */ 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate #include <ctype.h> 296*aa9ef484SJohn Levon #include <err.h> 29780ab886dSwesolows #include <errno.h> 298*aa9ef484SJohn Levon #include <fcntl.h> 299*aa9ef484SJohn Levon #include <getopt.h> 300*aa9ef484SJohn Levon #include <stdio.h> 301*aa9ef484SJohn Levon #include <stdlib.h> 302*aa9ef484SJohn Levon #include <string.h> 303*aa9ef484SJohn Levon #include <unistd.h> 304*aa9ef484SJohn Levon 3057c478bd9Sstevel@tonic-gate #include <sys/param.h> 30680ab886dSwesolows #include <sys/stat.h> 307*aa9ef484SJohn Levon #include <sys/types.h> 308*aa9ef484SJohn Levon #include <sys/utsname.h> 309*aa9ef484SJohn Levon #include <sys/wait.h> 31080ab886dSwesolows 31180ab886dSwesolows #define CW_F_CXX 0x01 31280ab886dSwesolows #define CW_F_SHADOW 0x02 31380ab886dSwesolows #define CW_F_EXEC 0x04 31480ab886dSwesolows #define CW_F_ECHO 0x08 31580ab886dSwesolows #define CW_F_XLATE 0x10 3161912d2c4Swesolows #define CW_F_PROG 0x20 31780ab886dSwesolows 31880ab886dSwesolows typedef enum cw_op { 31980ab886dSwesolows CW_O_NONE = 0, 32080ab886dSwesolows CW_O_PREPROCESS, 32180ab886dSwesolows CW_O_COMPILE, 32280ab886dSwesolows CW_O_LINK 32380ab886dSwesolows } cw_op_t; 32480ab886dSwesolows 32580ab886dSwesolows struct aelist { 32680ab886dSwesolows struct ae { 32780ab886dSwesolows struct ae *ae_next; 32880ab886dSwesolows char *ae_arg; 32980ab886dSwesolows } *ael_head, *ael_tail; 33080ab886dSwesolows int ael_argc; 33180ab886dSwesolows }; 33280ab886dSwesolows 333*aa9ef484SJohn Levon typedef enum { 334*aa9ef484SJohn Levon GNU, 335*aa9ef484SJohn Levon SUN 336*aa9ef484SJohn Levon } compiler_style_t; 337*aa9ef484SJohn Levon 338*aa9ef484SJohn Levon typedef struct { 339*aa9ef484SJohn Levon char *c_name; 340*aa9ef484SJohn Levon char *c_path; 341*aa9ef484SJohn Levon compiler_style_t c_style; 342*aa9ef484SJohn Levon } cw_compiler_t; 343*aa9ef484SJohn Levon 34480ab886dSwesolows typedef struct cw_ictx { 345*aa9ef484SJohn Levon struct cw_ictx *i_next; 346*aa9ef484SJohn Levon cw_compiler_t *i_compiler; 34780ab886dSwesolows struct aelist *i_ae; 34880ab886dSwesolows uint32_t i_flags; 34980ab886dSwesolows int i_oldargc; 35080ab886dSwesolows char **i_oldargv; 35180ab886dSwesolows pid_t i_pid; 35280ab886dSwesolows char i_discard[MAXPATHLEN]; 3531912d2c4Swesolows char *i_stderr; 35480ab886dSwesolows } cw_ictx_t; 35580ab886dSwesolows 356e521259dSpetede /* 357e521259dSpetede * Status values to indicate which Studio compiler and associated 358e521259dSpetede * flags are being used. 359e521259dSpetede */ 360e521259dSpetede #define M32 0x01 /* -m32 - only on Studio 12 */ 361e521259dSpetede #define M64 0x02 /* -m64 - only on Studio 12 */ 362e521259dSpetede #define SS11 0x100 /* Studio 11 */ 363e521259dSpetede #define SS12 0x200 /* Studio 12 */ 3647c478bd9Sstevel@tonic-gate 365e521259dSpetede #define TRANS_ENTRY 5 366e521259dSpetede /* 367e521259dSpetede * Translation table definition for the -xarch= flag. The "x_arg" 368e521259dSpetede * value is translated into the appropriate gcc flags according 369e521259dSpetede * to the values in x_trans[n]. The x_flags indicates what compiler 370e521259dSpetede * is being used and what flags have been set via the use of 371e521259dSpetede * "x_arg". 372e521259dSpetede */ 373e521259dSpetede typedef struct xarch_table { 374e521259dSpetede char *x_arg; 375e521259dSpetede int x_flags; 376e521259dSpetede char *x_trans[TRANS_ENTRY]; 377e521259dSpetede } xarch_table_t; 378e521259dSpetede 379e521259dSpetede /* 380e521259dSpetede * The translation table for the -xarch= flag used in the Studio compilers. 381e521259dSpetede */ 382e521259dSpetede static const xarch_table_t xtbl[] = { 3837c478bd9Sstevel@tonic-gate #if defined(__x86) 384*aa9ef484SJohn Levon { "generic", SS11, {NULL} }, 3857a6460b6Spetede { "generic64", (SS11|M64), { "-m64", "-mtune=opteron" } }, 3867a6460b6Spetede { "amd64", (SS11|M64), { "-m64", "-mtune=opteron" } }, 3877a6460b6Spetede { "386", SS11, { "-march=i386" } }, 3887a6460b6Spetede { "pentium_pro", SS11, { "-march=pentiumpro" } }, 38925c28e83SPiotr Jasiukajtis { "sse", SS11, { "-msse", "-mfpmath=sse" } }, 39025c28e83SPiotr Jasiukajtis { "sse2", SS11, { "-msse2", "-mfpmath=sse" } }, 3917c478bd9Sstevel@tonic-gate #elif defined(__sparc) 3927a6460b6Spetede { "generic", (SS11|M32), { "-m32", "-mcpu=v8" } }, 3937a6460b6Spetede { "generic64", (SS11|M64), { "-m64", "-mcpu=v9" } }, 3947a6460b6Spetede { "v8", (SS11|M32), { "-m32", "-mcpu=v8", "-mno-v8plus" } }, 3957a6460b6Spetede { "v8plus", (SS11|M32), { "-m32", "-mcpu=v9", "-mv8plus" } }, 3967a6460b6Spetede { "v8plusa", (SS11|M32), { "-m32", "-mcpu=ultrasparc", "-mv8plus", 3977a6460b6Spetede "-mvis" } }, 3987a6460b6Spetede { "v8plusb", (SS11|M32), { "-m32", "-mcpu=ultrasparc3", "-mv8plus", 3997a6460b6Spetede "-mvis" } }, 4007a6460b6Spetede { "v9", (SS11|M64), { "-m64", "-mcpu=v9" } }, 4017a6460b6Spetede { "v9a", (SS11|M64), { "-m64", "-mcpu=ultrasparc", "-mvis" } }, 4027a6460b6Spetede { "v9b", (SS11|M64), { "-m64", "-mcpu=ultrasparc3", "-mvis" } }, 4037a6460b6Spetede { "sparc", SS12, { "-mcpu=v9", "-mv8plus" } }, 4047a6460b6Spetede { "sparcvis", SS12, { "-mcpu=ultrasparc", "-mvis" } }, 4057a6460b6Spetede { "sparcvis2", SS12, { "-mcpu=ultrasparc3", "-mvis" } } 4067c478bd9Sstevel@tonic-gate #endif 4077c478bd9Sstevel@tonic-gate }; 4087c478bd9Sstevel@tonic-gate 409e521259dSpetede static int xtbl_size = sizeof (xtbl) / sizeof (xarch_table_t); 410e521259dSpetede 4117c478bd9Sstevel@tonic-gate static const char *xchip_tbl[] = { 4127c478bd9Sstevel@tonic-gate #if defined(__x86) 4137c478bd9Sstevel@tonic-gate "386", "-mtune=i386", NULL, 4147c478bd9Sstevel@tonic-gate "486", "-mtune=i486", NULL, 4157c478bd9Sstevel@tonic-gate "pentium", "-mtune=pentium", NULL, 4167c478bd9Sstevel@tonic-gate "pentium_pro", "-mtune=pentiumpro", NULL, 4177c478bd9Sstevel@tonic-gate #elif defined(__sparc) 4187c478bd9Sstevel@tonic-gate "super", "-mtune=supersparc", NULL, 4197c478bd9Sstevel@tonic-gate "ultra", "-mtune=ultrasparc", NULL, 4207c478bd9Sstevel@tonic-gate "ultra3", "-mtune=ultrasparc3", NULL, 4217c478bd9Sstevel@tonic-gate #endif 4227c478bd9Sstevel@tonic-gate NULL, NULL 4237c478bd9Sstevel@tonic-gate }; 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate static const char *xcode_tbl[] = { 4267c478bd9Sstevel@tonic-gate #if defined(__sparc) 4277c478bd9Sstevel@tonic-gate "abs32", "-fno-pic", "-mcmodel=medlow", NULL, 4287c478bd9Sstevel@tonic-gate "abs44", "-fno-pic", "-mcmodel=medmid", NULL, 4297c478bd9Sstevel@tonic-gate "abs64", "-fno-pic", "-mcmodel=medany", NULL, 4307c478bd9Sstevel@tonic-gate "pic13", "-fpic", NULL, 4317c478bd9Sstevel@tonic-gate "pic32", "-fPIC", NULL, 4327c478bd9Sstevel@tonic-gate #endif 4337c478bd9Sstevel@tonic-gate NULL, NULL 4347c478bd9Sstevel@tonic-gate }; 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate static const char *xtarget_tbl[] = { 4377c478bd9Sstevel@tonic-gate #if defined(__x86) 4387c478bd9Sstevel@tonic-gate "pentium_pro", "-march=pentiumpro", NULL, 4397c478bd9Sstevel@tonic-gate #endif /* __x86 */ 4407c478bd9Sstevel@tonic-gate NULL, NULL 4417c478bd9Sstevel@tonic-gate }; 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate static const char *xregs_tbl[] = { 4447c478bd9Sstevel@tonic-gate #if defined(__sparc) 4457c478bd9Sstevel@tonic-gate "appl", "-mapp-regs", NULL, 4467c478bd9Sstevel@tonic-gate "no%appl", "-mno-app-regs", NULL, 4477c478bd9Sstevel@tonic-gate "float", "-mfpu", NULL, 4487c478bd9Sstevel@tonic-gate "no%float", "-mno-fpu", NULL, 4497c478bd9Sstevel@tonic-gate #endif /* __sparc */ 4507c478bd9Sstevel@tonic-gate NULL, NULL 4517c478bd9Sstevel@tonic-gate }; 4527c478bd9Sstevel@tonic-gate 45380ab886dSwesolows static void 45480ab886dSwesolows nomem(void) 45580ab886dSwesolows { 456*aa9ef484SJohn Levon errx(1, "out of memory"); 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate static void 4607c478bd9Sstevel@tonic-gate newae(struct aelist *ael, const char *arg) 4617c478bd9Sstevel@tonic-gate { 4627c478bd9Sstevel@tonic-gate struct ae *ae; 4637c478bd9Sstevel@tonic-gate 46480ab886dSwesolows if ((ae = calloc(sizeof (*ae), 1)) == NULL) 46580ab886dSwesolows nomem(); 4667c478bd9Sstevel@tonic-gate ae->ae_arg = strdup(arg); 4677c478bd9Sstevel@tonic-gate if (ael->ael_tail == NULL) 4687c478bd9Sstevel@tonic-gate ael->ael_head = ae; 4697c478bd9Sstevel@tonic-gate else 4707c478bd9Sstevel@tonic-gate ael->ael_tail->ae_next = ae; 4717c478bd9Sstevel@tonic-gate ael->ael_tail = ae; 47280ab886dSwesolows ael->ael_argc++; 47380ab886dSwesolows } 47480ab886dSwesolows 47580ab886dSwesolows static cw_ictx_t * 47680ab886dSwesolows newictx(void) 47780ab886dSwesolows { 47880ab886dSwesolows cw_ictx_t *ctx = calloc(sizeof (cw_ictx_t), 1); 47980ab886dSwesolows if (ctx) 48080ab886dSwesolows if ((ctx->i_ae = calloc(sizeof (struct aelist), 1)) == NULL) { 48180ab886dSwesolows free(ctx); 48280ab886dSwesolows return (NULL); 48380ab886dSwesolows } 48480ab886dSwesolows 48580ab886dSwesolows return (ctx); 4867c478bd9Sstevel@tonic-gate } 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate static void 4897c478bd9Sstevel@tonic-gate error(const char *arg) 4907c478bd9Sstevel@tonic-gate { 491*aa9ef484SJohn Levon errx(2, "error: mapping failed at or near arg '%s'", arg); 4927c478bd9Sstevel@tonic-gate } 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate /* 4957c478bd9Sstevel@tonic-gate * Add the current favourite set of warnings to the gcc invocation. 4967c478bd9Sstevel@tonic-gate */ 4977c478bd9Sstevel@tonic-gate static void 4987c478bd9Sstevel@tonic-gate warnings(struct aelist *h) 4997c478bd9Sstevel@tonic-gate { 5007c478bd9Sstevel@tonic-gate static int warningsonce; 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate if (warningsonce++) 5037c478bd9Sstevel@tonic-gate return; 5047c478bd9Sstevel@tonic-gate 5057014882cSRichard Lowe /* 5067014882cSRichard Lowe * Enable as many warnings as exist, then disable those that we never 5077014882cSRichard Lowe * ever want. 5087014882cSRichard Lowe */ 5097c478bd9Sstevel@tonic-gate newae(h, "-Wall"); 5107014882cSRichard Lowe newae(h, "-Wextra"); 5117c478bd9Sstevel@tonic-gate } 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate static void 5147c478bd9Sstevel@tonic-gate optim_disable(struct aelist *h, int level) 5157c478bd9Sstevel@tonic-gate { 5167c478bd9Sstevel@tonic-gate if (level >= 2) { 5177c478bd9Sstevel@tonic-gate newae(h, "-fno-strict-aliasing"); 5187c478bd9Sstevel@tonic-gate newae(h, "-fno-unit-at-a-time"); 5197c478bd9Sstevel@tonic-gate newae(h, "-fno-optimize-sibling-calls"); 5207c478bd9Sstevel@tonic-gate } 5217c478bd9Sstevel@tonic-gate } 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate /* ARGSUSED */ 5247c478bd9Sstevel@tonic-gate static void 525*aa9ef484SJohn Levon Xamode(struct aelist __unused *h) 5267c478bd9Sstevel@tonic-gate { 5277c478bd9Sstevel@tonic-gate } 5287c478bd9Sstevel@tonic-gate 5297c478bd9Sstevel@tonic-gate static void 5307c478bd9Sstevel@tonic-gate Xcmode(struct aelist *h) 5317c478bd9Sstevel@tonic-gate { 5327c478bd9Sstevel@tonic-gate static int xconce; 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate if (xconce++) 5357c478bd9Sstevel@tonic-gate return; 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate newae(h, "-ansi"); 5387c478bd9Sstevel@tonic-gate newae(h, "-pedantic-errors"); 5397c478bd9Sstevel@tonic-gate } 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate static void 5427c478bd9Sstevel@tonic-gate Xsmode(struct aelist *h) 5437c478bd9Sstevel@tonic-gate { 5447c478bd9Sstevel@tonic-gate static int xsonce; 5457c478bd9Sstevel@tonic-gate 5467c478bd9Sstevel@tonic-gate if (xsonce++) 5477c478bd9Sstevel@tonic-gate return; 5487c478bd9Sstevel@tonic-gate 5497c478bd9Sstevel@tonic-gate newae(h, "-traditional"); 5507c478bd9Sstevel@tonic-gate newae(h, "-traditional-cpp"); 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate static void 5547c478bd9Sstevel@tonic-gate usage() 5557c478bd9Sstevel@tonic-gate { 556*aa9ef484SJohn Levon extern char *__progname; 5577c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 558*aa9ef484SJohn Levon "usage: %s [-C] [--versions] --primary <compiler> " 559*aa9ef484SJohn Levon "[--shadow <compiler>]... -- cflags...\n", 560*aa9ef484SJohn Levon __progname); 561*aa9ef484SJohn Levon (void) fprintf(stderr, "compilers take the form: name,path,style\n" 562*aa9ef484SJohn Levon " - name: a unique name usable in flag specifiers\n" 563*aa9ef484SJohn Levon " - path: path to the compiler binary\n" 564*aa9ef484SJohn Levon " - style: the style of flags expected: either sun or gnu\n"); 5657c478bd9Sstevel@tonic-gate exit(2); 5667c478bd9Sstevel@tonic-gate } 5677c478bd9Sstevel@tonic-gate 568e521259dSpetede static int 569e521259dSpetede xlate_xtb(struct aelist *h, const char *xarg) 570e521259dSpetede { 571e521259dSpetede int i, j; 572e521259dSpetede 573e521259dSpetede for (i = 0; i < xtbl_size; i++) { 574e521259dSpetede if (strcmp(xtbl[i].x_arg, xarg) == 0) 575e521259dSpetede break; 576e521259dSpetede } 577e521259dSpetede 578e521259dSpetede /* 579e521259dSpetede * At the end of the table and so no matching "arg" entry 580e521259dSpetede * found and so this must be a bad -xarch= flag. 581e521259dSpetede */ 582e521259dSpetede if (i == xtbl_size) 583e521259dSpetede error(xarg); 584e521259dSpetede 585e521259dSpetede for (j = 0; j < TRANS_ENTRY; j++) { 586e521259dSpetede if (xtbl[i].x_trans[j] != NULL) 587e521259dSpetede newae(h, xtbl[i].x_trans[j]); 588e521259dSpetede else 589e521259dSpetede break; 590e521259dSpetede } 591e521259dSpetede return (xtbl[i].x_flags); 592e521259dSpetede 593e521259dSpetede } 594e521259dSpetede 5957c478bd9Sstevel@tonic-gate static void 5967c478bd9Sstevel@tonic-gate xlate(struct aelist *h, const char *xarg, const char **table) 5977c478bd9Sstevel@tonic-gate { 5987c478bd9Sstevel@tonic-gate while (*table != NULL && strcmp(xarg, *table) != 0) { 5997c478bd9Sstevel@tonic-gate while (*table != NULL) 6007c478bd9Sstevel@tonic-gate table++; 6017c478bd9Sstevel@tonic-gate table++; 6027c478bd9Sstevel@tonic-gate } 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate if (*table == NULL) 6057c478bd9Sstevel@tonic-gate error(xarg); 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate table++; 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate while (*table != NULL) { 6107c478bd9Sstevel@tonic-gate newae(h, *table); 6117c478bd9Sstevel@tonic-gate table++; 6127c478bd9Sstevel@tonic-gate } 6137c478bd9Sstevel@tonic-gate } 6147c478bd9Sstevel@tonic-gate 6157c478bd9Sstevel@tonic-gate static void 61680ab886dSwesolows do_gcc(cw_ictx_t *ctx) 6177c478bd9Sstevel@tonic-gate { 6187c478bd9Sstevel@tonic-gate int c; 61980ab886dSwesolows int pic = 0, nolibc = 0; 62080ab886dSwesolows int in_output = 0, seen_o = 0, c_files = 0; 62180ab886dSwesolows cw_op_t op = CW_O_LINK; 6227c478bd9Sstevel@tonic-gate char *model = NULL; 623*aa9ef484SJohn Levon char *nameflag; 624e521259dSpetede int mflag = 0; 6257c478bd9Sstevel@tonic-gate 6261912d2c4Swesolows if (ctx->i_flags & CW_F_PROG) { 6271912d2c4Swesolows newae(ctx->i_ae, "--version"); 6281912d2c4Swesolows return; 6291912d2c4Swesolows } 6301912d2c4Swesolows 63180ab886dSwesolows newae(ctx->i_ae, "-fident"); 63280ab886dSwesolows newae(ctx->i_ae, "-finline"); 63380ab886dSwesolows newae(ctx->i_ae, "-fno-inline-functions"); 63480ab886dSwesolows newae(ctx->i_ae, "-fno-builtin"); 63580ab886dSwesolows newae(ctx->i_ae, "-fno-asm"); 6367014882cSRichard Lowe newae(ctx->i_ae, "-fdiagnostics-show-option"); 63780ab886dSwesolows newae(ctx->i_ae, "-nodefaultlibs"); 6387c478bd9Sstevel@tonic-gate 63902e56f3fSwesolows #if defined(__sparc) 64002e56f3fSwesolows /* 64102e56f3fSwesolows * The SPARC ldd and std instructions require 8-byte alignment of 64202e56f3fSwesolows * their address operand. gcc correctly uses them only when the 64302e56f3fSwesolows * ABI requires 8-byte alignment; unfortunately we have a number of 64402e56f3fSwesolows * pieces of buggy code that doesn't conform to the ABI. This 64502e56f3fSwesolows * flag makes gcc work more like Studio with -xmemalign=4. 64602e56f3fSwesolows */ 64780ab886dSwesolows newae(ctx->i_ae, "-mno-integer-ldd-std"); 64802e56f3fSwesolows #endif 64902e56f3fSwesolows 6507c478bd9Sstevel@tonic-gate /* 6517c478bd9Sstevel@tonic-gate * This is needed because 'u' is defined 6527c478bd9Sstevel@tonic-gate * under a conditional on 'sun'. Should 6537c478bd9Sstevel@tonic-gate * probably just remove the conditional, 6547c478bd9Sstevel@tonic-gate * or make it be dependent on '__sun'. 6557c478bd9Sstevel@tonic-gate * 6567c478bd9Sstevel@tonic-gate * -Dunix is also missing in enhanced ANSI mode 6577c478bd9Sstevel@tonic-gate */ 65880ab886dSwesolows newae(ctx->i_ae, "-D__sun"); 6597c478bd9Sstevel@tonic-gate 660*aa9ef484SJohn Levon if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->c_name) == -1) 661*aa9ef484SJohn Levon nomem(); 662*aa9ef484SJohn Levon 6637c478bd9Sstevel@tonic-gate /* 6647c478bd9Sstevel@tonic-gate * Walk the argument list, translating as we go .. 6657c478bd9Sstevel@tonic-gate */ 66680ab886dSwesolows while (--ctx->i_oldargc > 0) { 66780ab886dSwesolows char *arg = *++ctx->i_oldargv; 6687c478bd9Sstevel@tonic-gate size_t arglen = strlen(arg); 6697c478bd9Sstevel@tonic-gate 67080ab886dSwesolows if (*arg == '-') { 6717c478bd9Sstevel@tonic-gate arglen--; 67280ab886dSwesolows } else { 6737c478bd9Sstevel@tonic-gate /* 6747c478bd9Sstevel@tonic-gate * Discard inline files that gcc doesn't grok 6757c478bd9Sstevel@tonic-gate */ 67680ab886dSwesolows if (!in_output && arglen > 3 && 6777c478bd9Sstevel@tonic-gate strcmp(arg + arglen - 3, ".il") == 0) 6787c478bd9Sstevel@tonic-gate continue; 6797c478bd9Sstevel@tonic-gate 68080ab886dSwesolows if (!in_output && arglen > 2 && 68180ab886dSwesolows arg[arglen - 2] == '.' && 68280ab886dSwesolows (arg[arglen - 1] == 'S' || arg[arglen - 1] == 's' || 68380ab886dSwesolows arg[arglen - 1] == 'c' || arg[arglen - 1] == 'i')) 68480ab886dSwesolows c_files++; 68580ab886dSwesolows 6867c478bd9Sstevel@tonic-gate /* 68780ab886dSwesolows * Otherwise, filenames and partial arguments 68880ab886dSwesolows * are passed through for gcc to chew on. However, 68980ab886dSwesolows * output is always discarded for the secondary 69080ab886dSwesolows * compiler. 6917c478bd9Sstevel@tonic-gate */ 69280ab886dSwesolows if ((ctx->i_flags & CW_F_SHADOW) && in_output) 69380ab886dSwesolows newae(ctx->i_ae, ctx->i_discard); 69480ab886dSwesolows else 69580ab886dSwesolows newae(ctx->i_ae, arg); 69680ab886dSwesolows in_output = 0; 6977c478bd9Sstevel@tonic-gate continue; 6987c478bd9Sstevel@tonic-gate } 6997c478bd9Sstevel@tonic-gate 70080ab886dSwesolows if (ctx->i_flags & CW_F_CXX) { 701*aa9ef484SJohn Levon if (strncmp(arg, "-_g++=", 6) == 0) { 702*aa9ef484SJohn Levon newae(ctx->i_ae, strchr(arg, '=') + 1); 703*aa9ef484SJohn Levon continue; 704*aa9ef484SJohn Levon } 7057c478bd9Sstevel@tonic-gate if (strncmp(arg, "-compat=", 8) == 0) { 7067c478bd9Sstevel@tonic-gate /* discard -compat=4 and -compat=5 */ 7077c478bd9Sstevel@tonic-gate continue; 7087c478bd9Sstevel@tonic-gate } 7097c478bd9Sstevel@tonic-gate if (strcmp(arg, "-Qoption") == 0) { 7107c478bd9Sstevel@tonic-gate /* discard -Qoption and its two arguments */ 71180ab886dSwesolows if (ctx->i_oldargc < 3) 7127c478bd9Sstevel@tonic-gate error(arg); 71380ab886dSwesolows ctx->i_oldargc -= 2; 71480ab886dSwesolows ctx->i_oldargv += 2; 7157c478bd9Sstevel@tonic-gate continue; 7167c478bd9Sstevel@tonic-gate } 7177c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xwe") == 0) { 7187c478bd9Sstevel@tonic-gate /* turn warnings into errors */ 71980ab886dSwesolows newae(ctx->i_ae, "-Werror"); 7207c478bd9Sstevel@tonic-gate continue; 7217c478bd9Sstevel@tonic-gate } 7227c478bd9Sstevel@tonic-gate if (strcmp(arg, "-noex") == 0) { 7237c478bd9Sstevel@tonic-gate /* no exceptions */ 72480ab886dSwesolows newae(ctx->i_ae, "-fno-exceptions"); 7257c478bd9Sstevel@tonic-gate /* no run time type descriptor information */ 72680ab886dSwesolows newae(ctx->i_ae, "-fno-rtti"); 7277c478bd9Sstevel@tonic-gate continue; 7287c478bd9Sstevel@tonic-gate } 7297c478bd9Sstevel@tonic-gate if (strcmp(arg, "-pic") == 0) { 73080ab886dSwesolows newae(ctx->i_ae, "-fpic"); 7317c478bd9Sstevel@tonic-gate pic = 1; 7327c478bd9Sstevel@tonic-gate continue; 7337c478bd9Sstevel@tonic-gate } 7347c478bd9Sstevel@tonic-gate if (strcmp(arg, "-PIC") == 0) { 73580ab886dSwesolows newae(ctx->i_ae, "-fPIC"); 7367c478bd9Sstevel@tonic-gate pic = 1; 7377c478bd9Sstevel@tonic-gate continue; 7387c478bd9Sstevel@tonic-gate } 7397c478bd9Sstevel@tonic-gate if (strcmp(arg, "-norunpath") == 0) { 7407c478bd9Sstevel@tonic-gate /* gcc has no corresponding option */ 7417c478bd9Sstevel@tonic-gate continue; 7427c478bd9Sstevel@tonic-gate } 7437c478bd9Sstevel@tonic-gate if (strcmp(arg, "-nolib") == 0) { 7447c478bd9Sstevel@tonic-gate /* -nodefaultlibs is on by default */ 7457c478bd9Sstevel@tonic-gate nolibc = 1; 7467c478bd9Sstevel@tonic-gate continue; 7477c478bd9Sstevel@tonic-gate } 7487c478bd9Sstevel@tonic-gate #if defined(__sparc) 7497c478bd9Sstevel@tonic-gate if (strcmp(arg, "-cg92") == 0) { 750e521259dSpetede mflag |= xlate_xtb(ctx->i_ae, "v8"); 75180ab886dSwesolows xlate(ctx->i_ae, "super", xchip_tbl); 7527c478bd9Sstevel@tonic-gate continue; 7537c478bd9Sstevel@tonic-gate } 7547c478bd9Sstevel@tonic-gate #endif /* __sparc */ 7557c478bd9Sstevel@tonic-gate } 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate switch ((c = arg[1])) { 7587c478bd9Sstevel@tonic-gate case '_': 759*aa9ef484SJohn Levon if ((strncmp(arg, nameflag, strlen(nameflag)) == 0) || 760*aa9ef484SJohn Levon (strncmp(arg, "-_gcc=", 6) == 0) || 761*aa9ef484SJohn Levon (strncmp(arg, "-_gnu=", 6) == 0)) { 762*aa9ef484SJohn Levon newae(ctx->i_ae, strchr(arg, '=') + 1); 763*aa9ef484SJohn Levon } 7647c478bd9Sstevel@tonic-gate break; 7657c478bd9Sstevel@tonic-gate case '#': 7667c478bd9Sstevel@tonic-gate if (arglen == 1) { 76780ab886dSwesolows newae(ctx->i_ae, "-v"); 7687c478bd9Sstevel@tonic-gate break; 7697c478bd9Sstevel@tonic-gate } 7707c478bd9Sstevel@tonic-gate error(arg); 7717c478bd9Sstevel@tonic-gate break; 7727c478bd9Sstevel@tonic-gate case 'g': 77380ab886dSwesolows newae(ctx->i_ae, "-gdwarf-2"); 7747c478bd9Sstevel@tonic-gate break; 7757c478bd9Sstevel@tonic-gate case 'E': 7767c478bd9Sstevel@tonic-gate if (arglen == 1) { 77780ab886dSwesolows newae(ctx->i_ae, "-xc"); 77880ab886dSwesolows newae(ctx->i_ae, arg); 77980ab886dSwesolows op = CW_O_PREPROCESS; 7807c478bd9Sstevel@tonic-gate nolibc = 1; 7817c478bd9Sstevel@tonic-gate break; 7827c478bd9Sstevel@tonic-gate } 7837c478bd9Sstevel@tonic-gate error(arg); 7847c478bd9Sstevel@tonic-gate break; 7857c478bd9Sstevel@tonic-gate case 'c': 7867c478bd9Sstevel@tonic-gate case 'S': 78780ab886dSwesolows if (arglen == 1) { 78880ab886dSwesolows op = CW_O_COMPILE; 7897c478bd9Sstevel@tonic-gate nolibc = 1; 79080ab886dSwesolows } 7917c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 7927c478bd9Sstevel@tonic-gate case 'C': 7937c478bd9Sstevel@tonic-gate case 'H': 7947c478bd9Sstevel@tonic-gate case 'p': 7957c478bd9Sstevel@tonic-gate if (arglen == 1) { 79680ab886dSwesolows newae(ctx->i_ae, arg); 7977c478bd9Sstevel@tonic-gate break; 7987c478bd9Sstevel@tonic-gate } 7997c478bd9Sstevel@tonic-gate error(arg); 8007c478bd9Sstevel@tonic-gate break; 8017c478bd9Sstevel@tonic-gate case 'A': 8027c478bd9Sstevel@tonic-gate case 'h': 8037c478bd9Sstevel@tonic-gate case 'I': 8047c478bd9Sstevel@tonic-gate case 'i': 8057c478bd9Sstevel@tonic-gate case 'L': 8067c478bd9Sstevel@tonic-gate case 'l': 8077c478bd9Sstevel@tonic-gate case 'R': 8087c478bd9Sstevel@tonic-gate case 'U': 8097c478bd9Sstevel@tonic-gate case 'u': 8107c478bd9Sstevel@tonic-gate case 'w': 81180ab886dSwesolows newae(ctx->i_ae, arg); 81280ab886dSwesolows break; 81380ab886dSwesolows case 'o': 81480ab886dSwesolows seen_o = 1; 81580ab886dSwesolows if (arglen == 1) { 81680ab886dSwesolows in_output = 1; 81780ab886dSwesolows newae(ctx->i_ae, arg); 81880ab886dSwesolows } else if (ctx->i_flags & CW_F_SHADOW) { 81980ab886dSwesolows newae(ctx->i_ae, "-o"); 82080ab886dSwesolows newae(ctx->i_ae, ctx->i_discard); 82180ab886dSwesolows } else { 82280ab886dSwesolows newae(ctx->i_ae, arg); 82380ab886dSwesolows } 8247c478bd9Sstevel@tonic-gate break; 8257c478bd9Sstevel@tonic-gate case 'D': 82680ab886dSwesolows newae(ctx->i_ae, arg); 8277c478bd9Sstevel@tonic-gate /* 8287c478bd9Sstevel@tonic-gate * XXX Clearly a hack ... do we need _KADB too? 8297c478bd9Sstevel@tonic-gate */ 8307c478bd9Sstevel@tonic-gate if (strcmp(arg, "-D_KERNEL") == 0 || 8317c478bd9Sstevel@tonic-gate strcmp(arg, "-D_BOOT") == 0) 83280ab886dSwesolows newae(ctx->i_ae, "-ffreestanding"); 8337c478bd9Sstevel@tonic-gate break; 8347c478bd9Sstevel@tonic-gate case 'd': 8357c478bd9Sstevel@tonic-gate if (arglen == 2) { 8367c478bd9Sstevel@tonic-gate if (strcmp(arg, "-dy") == 0) { 83780ab886dSwesolows newae(ctx->i_ae, "-Wl,-dy"); 8387c478bd9Sstevel@tonic-gate break; 8397c478bd9Sstevel@tonic-gate } 8407c478bd9Sstevel@tonic-gate if (strcmp(arg, "-dn") == 0) { 84180ab886dSwesolows newae(ctx->i_ae, "-Wl,-dn"); 8427c478bd9Sstevel@tonic-gate break; 8437c478bd9Sstevel@tonic-gate } 8447c478bd9Sstevel@tonic-gate } 8457c478bd9Sstevel@tonic-gate if (strcmp(arg, "-dalign") == 0) { 8467c478bd9Sstevel@tonic-gate /* 8477c478bd9Sstevel@tonic-gate * -dalign forces alignment in some cases; 8487c478bd9Sstevel@tonic-gate * gcc does not need any flag to do this. 8497c478bd9Sstevel@tonic-gate */ 8507c478bd9Sstevel@tonic-gate break; 8517c478bd9Sstevel@tonic-gate } 8527c478bd9Sstevel@tonic-gate error(arg); 8537c478bd9Sstevel@tonic-gate break; 8547c478bd9Sstevel@tonic-gate case 'e': 8557c478bd9Sstevel@tonic-gate if (strcmp(arg, 8567c478bd9Sstevel@tonic-gate "-erroff=E_EMPTY_TRANSLATION_UNIT") == 0) { 8577c478bd9Sstevel@tonic-gate /* 8587c478bd9Sstevel@tonic-gate * Accept but ignore this -- gcc doesn't 8597c478bd9Sstevel@tonic-gate * seem to complain about empty translation 8607c478bd9Sstevel@tonic-gate * units 8617c478bd9Sstevel@tonic-gate */ 8627c478bd9Sstevel@tonic-gate break; 8637c478bd9Sstevel@tonic-gate } 8647c478bd9Sstevel@tonic-gate /* XX64 -- ignore all -erroff= options, for now */ 8657c478bd9Sstevel@tonic-gate if (strncmp(arg, "-erroff=", 8) == 0) 8667c478bd9Sstevel@tonic-gate break; 8677c478bd9Sstevel@tonic-gate if (strcmp(arg, "-errtags=yes") == 0) { 86880ab886dSwesolows warnings(ctx->i_ae); 8697c478bd9Sstevel@tonic-gate break; 8707c478bd9Sstevel@tonic-gate } 8717c478bd9Sstevel@tonic-gate if (strcmp(arg, "-errwarn=%all") == 0) { 87280ab886dSwesolows newae(ctx->i_ae, "-Werror"); 8737c478bd9Sstevel@tonic-gate break; 8747c478bd9Sstevel@tonic-gate } 8757c478bd9Sstevel@tonic-gate error(arg); 8767c478bd9Sstevel@tonic-gate break; 8777c478bd9Sstevel@tonic-gate case 'f': 8787c478bd9Sstevel@tonic-gate if (strcmp(arg, "-flags") == 0) { 87980ab886dSwesolows newae(ctx->i_ae, "--help"); 8807c478bd9Sstevel@tonic-gate break; 8817c478bd9Sstevel@tonic-gate } 8820e62f92eSMark Logan if (strncmp(arg, "-features=zla", 13) == 0) { 8830e62f92eSMark Logan /* 8840e62f92eSMark Logan * Accept but ignore this -- gcc allows 8850e62f92eSMark Logan * zero length arrays. 8860e62f92eSMark Logan */ 8870e62f92eSMark Logan break; 8880e62f92eSMark Logan } 8897c478bd9Sstevel@tonic-gate error(arg); 8907c478bd9Sstevel@tonic-gate break; 8917c478bd9Sstevel@tonic-gate case 'G': 89280ab886dSwesolows newae(ctx->i_ae, "-shared"); 8937c478bd9Sstevel@tonic-gate nolibc = 1; 8947c478bd9Sstevel@tonic-gate break; 8957c478bd9Sstevel@tonic-gate case 'k': 8967c478bd9Sstevel@tonic-gate if (strcmp(arg, "-keeptmp") == 0) { 89780ab886dSwesolows newae(ctx->i_ae, "-save-temps"); 8987c478bd9Sstevel@tonic-gate break; 8997c478bd9Sstevel@tonic-gate } 9007c478bd9Sstevel@tonic-gate error(arg); 9017c478bd9Sstevel@tonic-gate break; 9027c478bd9Sstevel@tonic-gate case 'K': 9037c478bd9Sstevel@tonic-gate if (arglen == 1) { 90480ab886dSwesolows if ((arg = *++ctx->i_oldargv) == NULL || 90580ab886dSwesolows *arg == '\0') 9067c478bd9Sstevel@tonic-gate error("-K"); 90780ab886dSwesolows ctx->i_oldargc--; 9087c478bd9Sstevel@tonic-gate } else { 9097c478bd9Sstevel@tonic-gate arg += 2; 9107c478bd9Sstevel@tonic-gate } 9117c478bd9Sstevel@tonic-gate if (strcmp(arg, "pic") == 0) { 91280ab886dSwesolows newae(ctx->i_ae, "-fpic"); 9137c478bd9Sstevel@tonic-gate pic = 1; 9147c478bd9Sstevel@tonic-gate break; 9157c478bd9Sstevel@tonic-gate } 9167c478bd9Sstevel@tonic-gate if (strcmp(arg, "PIC") == 0) { 91780ab886dSwesolows newae(ctx->i_ae, "-fPIC"); 9187c478bd9Sstevel@tonic-gate pic = 1; 9197c478bd9Sstevel@tonic-gate break; 9207c478bd9Sstevel@tonic-gate } 9217c478bd9Sstevel@tonic-gate error("-K"); 9227c478bd9Sstevel@tonic-gate break; 9237c478bd9Sstevel@tonic-gate case 'm': 9247c478bd9Sstevel@tonic-gate if (strcmp(arg, "-mt") == 0) { 92580ab886dSwesolows newae(ctx->i_ae, "-D_REENTRANT"); 9267c478bd9Sstevel@tonic-gate break; 9277c478bd9Sstevel@tonic-gate } 928e521259dSpetede if (strcmp(arg, "-m64") == 0) { 929e521259dSpetede newae(ctx->i_ae, "-m64"); 930e521259dSpetede #if defined(__x86) 931e521259dSpetede newae(ctx->i_ae, "-mtune=opteron"); 932e521259dSpetede #endif 933e521259dSpetede mflag |= M64; 934e521259dSpetede break; 935e521259dSpetede } 936e521259dSpetede if (strcmp(arg, "-m32") == 0) { 937e521259dSpetede newae(ctx->i_ae, "-m32"); 938e521259dSpetede mflag |= M32; 939e521259dSpetede break; 940e521259dSpetede } 9417c478bd9Sstevel@tonic-gate error(arg); 9427c478bd9Sstevel@tonic-gate break; 9437c478bd9Sstevel@tonic-gate case 'B': /* linker options */ 9447c478bd9Sstevel@tonic-gate case 'M': 9457c478bd9Sstevel@tonic-gate case 'z': 9467c478bd9Sstevel@tonic-gate { 9477c478bd9Sstevel@tonic-gate char *opt; 9487c478bd9Sstevel@tonic-gate size_t len; 9497c478bd9Sstevel@tonic-gate char *s; 9507c478bd9Sstevel@tonic-gate 9517c478bd9Sstevel@tonic-gate if (arglen == 1) { 95280ab886dSwesolows opt = *++ctx->i_oldargv; 9537c478bd9Sstevel@tonic-gate if (opt == NULL || *opt == '\0') 9547c478bd9Sstevel@tonic-gate error(arg); 95580ab886dSwesolows ctx->i_oldargc--; 9567c478bd9Sstevel@tonic-gate } else { 9577c478bd9Sstevel@tonic-gate opt = arg + 2; 9587c478bd9Sstevel@tonic-gate } 9597c478bd9Sstevel@tonic-gate len = strlen(opt) + 7; 96080ab886dSwesolows if ((s = malloc(len)) == NULL) 96180ab886dSwesolows nomem(); 9627c478bd9Sstevel@tonic-gate (void) snprintf(s, len, "-Wl,-%c%s", c, opt); 96380ab886dSwesolows newae(ctx->i_ae, s); 9647c478bd9Sstevel@tonic-gate free(s); 9657c478bd9Sstevel@tonic-gate } 9667c478bd9Sstevel@tonic-gate break; 9677c478bd9Sstevel@tonic-gate case 'n': 9687c478bd9Sstevel@tonic-gate if (strcmp(arg, "-noqueue") == 0) { 9697c478bd9Sstevel@tonic-gate /* 9707c478bd9Sstevel@tonic-gate * Horrid license server stuff - n/a 9717c478bd9Sstevel@tonic-gate */ 9727c478bd9Sstevel@tonic-gate break; 9737c478bd9Sstevel@tonic-gate } 9747c478bd9Sstevel@tonic-gate error(arg); 9757c478bd9Sstevel@tonic-gate break; 9767c478bd9Sstevel@tonic-gate case 'O': 9777c478bd9Sstevel@tonic-gate if (arglen == 1) { 97880ab886dSwesolows newae(ctx->i_ae, "-O"); 9797c478bd9Sstevel@tonic-gate break; 9807c478bd9Sstevel@tonic-gate } 9817c478bd9Sstevel@tonic-gate error(arg); 9827c478bd9Sstevel@tonic-gate break; 9837c478bd9Sstevel@tonic-gate case 'P': 9847c478bd9Sstevel@tonic-gate /* 9857c478bd9Sstevel@tonic-gate * We could do '-E -o filename.i', but that's hard, 9867c478bd9Sstevel@tonic-gate * and we don't need it for the case that's triggering 9877c478bd9Sstevel@tonic-gate * this addition. We'll require the user to specify 9887c478bd9Sstevel@tonic-gate * -o in the Makefile. If they don't they'll find out 9897c478bd9Sstevel@tonic-gate * in a hurry. 9907c478bd9Sstevel@tonic-gate */ 99180ab886dSwesolows newae(ctx->i_ae, "-E"); 99280ab886dSwesolows op = CW_O_PREPROCESS; 9937c478bd9Sstevel@tonic-gate nolibc = 1; 9947c478bd9Sstevel@tonic-gate break; 9957c478bd9Sstevel@tonic-gate case 'q': 9967c478bd9Sstevel@tonic-gate if (strcmp(arg, "-qp") == 0) { 99780ab886dSwesolows newae(ctx->i_ae, "-p"); 9987c478bd9Sstevel@tonic-gate break; 9997c478bd9Sstevel@tonic-gate } 10007c478bd9Sstevel@tonic-gate error(arg); 10017c478bd9Sstevel@tonic-gate break; 10027c478bd9Sstevel@tonic-gate case 's': 10037c478bd9Sstevel@tonic-gate if (arglen == 1) { 100480ab886dSwesolows newae(ctx->i_ae, "-Wl,-s"); 10057c478bd9Sstevel@tonic-gate break; 10067c478bd9Sstevel@tonic-gate } 10077c478bd9Sstevel@tonic-gate error(arg); 10087c478bd9Sstevel@tonic-gate break; 1009159cf8a6Swesolows case 't': 1010159cf8a6Swesolows if (arglen == 1) { 101180ab886dSwesolows newae(ctx->i_ae, "-Wl,-t"); 1012159cf8a6Swesolows break; 1013159cf8a6Swesolows } 1014159cf8a6Swesolows error(arg); 1015159cf8a6Swesolows break; 10167c478bd9Sstevel@tonic-gate case 'V': 10177c478bd9Sstevel@tonic-gate if (arglen == 1) { 101880ab886dSwesolows ctx->i_flags &= ~CW_F_ECHO; 101980ab886dSwesolows newae(ctx->i_ae, "--version"); 10207c478bd9Sstevel@tonic-gate break; 10217c478bd9Sstevel@tonic-gate } 10227c478bd9Sstevel@tonic-gate error(arg); 10237c478bd9Sstevel@tonic-gate break; 10247c478bd9Sstevel@tonic-gate case 'v': 10257c478bd9Sstevel@tonic-gate if (arglen == 1) { 102680ab886dSwesolows warnings(ctx->i_ae); 10277c478bd9Sstevel@tonic-gate break; 10287c478bd9Sstevel@tonic-gate } 10297c478bd9Sstevel@tonic-gate error(arg); 10307c478bd9Sstevel@tonic-gate break; 10317c478bd9Sstevel@tonic-gate case 'W': 10327c478bd9Sstevel@tonic-gate if (strncmp(arg, "-Wp,-xc99", 9) == 0) { 10337c478bd9Sstevel@tonic-gate /* 10347c478bd9Sstevel@tonic-gate * gcc's preprocessor will accept c99 10357c478bd9Sstevel@tonic-gate * regardless, so accept and ignore. 10367c478bd9Sstevel@tonic-gate */ 10377c478bd9Sstevel@tonic-gate break; 10387c478bd9Sstevel@tonic-gate } 10397c478bd9Sstevel@tonic-gate if (strncmp(arg, "-Wa,", 4) == 0 || 10407c478bd9Sstevel@tonic-gate strncmp(arg, "-Wp,", 4) == 0 || 10417c478bd9Sstevel@tonic-gate strncmp(arg, "-Wl,", 4) == 0) { 104280ab886dSwesolows newae(ctx->i_ae, arg); 10437c478bd9Sstevel@tonic-gate break; 10447c478bd9Sstevel@tonic-gate } 10457c478bd9Sstevel@tonic-gate if (strcmp(arg, "-W0,-xc99=pragma") == 0) { 10467c478bd9Sstevel@tonic-gate /* (undocumented) enables _Pragma */ 10477c478bd9Sstevel@tonic-gate break; 10487c478bd9Sstevel@tonic-gate } 10497c478bd9Sstevel@tonic-gate if (strcmp(arg, "-W0,-xc99=%none") == 0) { 10507c478bd9Sstevel@tonic-gate /* 10517c478bd9Sstevel@tonic-gate * This is a polite way of saying 10527c478bd9Sstevel@tonic-gate * "no c99 constructs allowed!" 10537c478bd9Sstevel@tonic-gate * For now, just accept and ignore this. 10547c478bd9Sstevel@tonic-gate */ 10557c478bd9Sstevel@tonic-gate break; 10567c478bd9Sstevel@tonic-gate } 10574afe1ab8Sesaxe if (strcmp(arg, "-W0,-noglobal") == 0 || 10584afe1ab8Sesaxe strcmp(arg, "-W0,-xglobalstatic") == 0) { 10597c478bd9Sstevel@tonic-gate /* 10607c478bd9Sstevel@tonic-gate * gcc doesn't prefix local symbols 10617c478bd9Sstevel@tonic-gate * in debug mode, so this is not needed. 10627c478bd9Sstevel@tonic-gate */ 10637c478bd9Sstevel@tonic-gate break; 10647c478bd9Sstevel@tonic-gate } 10657c478bd9Sstevel@tonic-gate if (strcmp(arg, "-W0,-Lt") == 0) { 10667c478bd9Sstevel@tonic-gate /* 10677c478bd9Sstevel@tonic-gate * Generate tests at the top of loops. 10687c478bd9Sstevel@tonic-gate * There is no direct gcc equivalent, ignore. 10697c478bd9Sstevel@tonic-gate */ 10707c478bd9Sstevel@tonic-gate break; 10717c478bd9Sstevel@tonic-gate } 10728c1a3716Ssherrym if (strcmp(arg, "-W0,-xdbggen=no%usedonly") == 0) { 107380ab886dSwesolows newae(ctx->i_ae, 107480ab886dSwesolows "-fno-eliminate-unused-debug-symbols"); 107580ab886dSwesolows newae(ctx->i_ae, 107680ab886dSwesolows "-fno-eliminate-unused-debug-types"); 10778c1a3716Ssherrym break; 10788c1a3716Ssherrym } 10799dd82889Spetede if (strcmp(arg, "-W2,-xwrap_int") == 0) { 10809dd82889Spetede /* 10819dd82889Spetede * Use the legacy behaviour (pre-SS11) 10829dd82889Spetede * for integer wrapping. 10839dd82889Spetede * gcc does not need this. 10849dd82889Spetede */ 10859dd82889Spetede break; 10869dd82889Spetede } 10877c478bd9Sstevel@tonic-gate if (strcmp(arg, "-W2,-Rcond_elim") == 0) { 10887c478bd9Sstevel@tonic-gate /* 10897c478bd9Sstevel@tonic-gate * Elimination and expansion of conditionals; 10907c478bd9Sstevel@tonic-gate * gcc has no direct equivalent. 10917c478bd9Sstevel@tonic-gate */ 10927c478bd9Sstevel@tonic-gate break; 10937c478bd9Sstevel@tonic-gate } 10947c478bd9Sstevel@tonic-gate if (strcmp(arg, "-Wd,-xsafe=unboundsym") == 0) { 10957c478bd9Sstevel@tonic-gate /* 10967c478bd9Sstevel@tonic-gate * Prevents optimizing away checks for 10977c478bd9Sstevel@tonic-gate * unbound weak symbol addresses. gcc does 10987c478bd9Sstevel@tonic-gate * not do this, so it's not needed. 10997c478bd9Sstevel@tonic-gate */ 11007c478bd9Sstevel@tonic-gate break; 11017c478bd9Sstevel@tonic-gate } 11027c478bd9Sstevel@tonic-gate if (strncmp(arg, "-Wc,-xcode=", 11) == 0) { 110380ab886dSwesolows xlate(ctx->i_ae, arg + 11, xcode_tbl); 11047c478bd9Sstevel@tonic-gate if (strncmp(arg + 11, "pic", 3) == 0) 11057c478bd9Sstevel@tonic-gate pic = 1; 11067c478bd9Sstevel@tonic-gate break; 11077c478bd9Sstevel@tonic-gate } 11087c478bd9Sstevel@tonic-gate if (strncmp(arg, "-Wc,-Qiselect", 13) == 0) { 11097c478bd9Sstevel@tonic-gate /* 11107c478bd9Sstevel@tonic-gate * Prevents insertion of register symbols. 11117c478bd9Sstevel@tonic-gate * gcc doesn't do this, so ignore it. 11127c478bd9Sstevel@tonic-gate */ 11137c478bd9Sstevel@tonic-gate break; 11147c478bd9Sstevel@tonic-gate } 11159dd82889Spetede if (strcmp(arg, "-Wc,-Qassembler-ounrefsym=0") == 0) { 11169dd82889Spetede /* 11179dd82889Spetede * Prevents optimizing away of static variables. 11189dd82889Spetede * gcc does not do this, so it's not needed. 11199dd82889Spetede */ 11209dd82889Spetede break; 11219dd82889Spetede } 11227c478bd9Sstevel@tonic-gate #if defined(__x86) 11237c478bd9Sstevel@tonic-gate if (strcmp(arg, "-Wu,-xmodel=kernel") == 0) { 112480ab886dSwesolows newae(ctx->i_ae, "-ffreestanding"); 112580ab886dSwesolows newae(ctx->i_ae, "-mno-red-zone"); 11267c478bd9Sstevel@tonic-gate model = "-mcmodel=kernel"; 11277c478bd9Sstevel@tonic-gate nolibc = 1; 11287c478bd9Sstevel@tonic-gate break; 11297c478bd9Sstevel@tonic-gate } 1130d430274bSsherrym if (strcmp(arg, "-Wu,-save_args") == 0) { 113180ab886dSwesolows newae(ctx->i_ae, "-msave-args"); 1132d430274bSsherrym break; 1133d430274bSsherrym } 11347c478bd9Sstevel@tonic-gate #endif /* __x86 */ 11357c478bd9Sstevel@tonic-gate error(arg); 11367c478bd9Sstevel@tonic-gate break; 11377c478bd9Sstevel@tonic-gate case 'X': 11387c478bd9Sstevel@tonic-gate if (strcmp(arg, "-Xa") == 0 || 11397c478bd9Sstevel@tonic-gate strcmp(arg, "-Xt") == 0) { 114080ab886dSwesolows Xamode(ctx->i_ae); 11417c478bd9Sstevel@tonic-gate break; 11427c478bd9Sstevel@tonic-gate } 11437c478bd9Sstevel@tonic-gate if (strcmp(arg, "-Xc") == 0) { 114480ab886dSwesolows Xcmode(ctx->i_ae); 11457c478bd9Sstevel@tonic-gate break; 11467c478bd9Sstevel@tonic-gate } 11477c478bd9Sstevel@tonic-gate if (strcmp(arg, "-Xs") == 0) { 114880ab886dSwesolows Xsmode(ctx->i_ae); 11497c478bd9Sstevel@tonic-gate break; 11507c478bd9Sstevel@tonic-gate } 11517c478bd9Sstevel@tonic-gate error(arg); 11527c478bd9Sstevel@tonic-gate break; 11537c478bd9Sstevel@tonic-gate case 'x': 11547c478bd9Sstevel@tonic-gate if (arglen == 1) 11557c478bd9Sstevel@tonic-gate error(arg); 11567c478bd9Sstevel@tonic-gate switch (arg[2]) { 11577c478bd9Sstevel@tonic-gate #if defined(__x86) 11587c478bd9Sstevel@tonic-gate case '3': 11597c478bd9Sstevel@tonic-gate if (strcmp(arg, "-x386") == 0) { 116080ab886dSwesolows newae(ctx->i_ae, "-march=i386"); 11617c478bd9Sstevel@tonic-gate break; 11627c478bd9Sstevel@tonic-gate } 11637c478bd9Sstevel@tonic-gate error(arg); 11647c478bd9Sstevel@tonic-gate break; 11657c478bd9Sstevel@tonic-gate case '4': 11667c478bd9Sstevel@tonic-gate if (strcmp(arg, "-x486") == 0) { 116780ab886dSwesolows newae(ctx->i_ae, "-march=i486"); 11687c478bd9Sstevel@tonic-gate break; 11697c478bd9Sstevel@tonic-gate } 11707c478bd9Sstevel@tonic-gate error(arg); 11717c478bd9Sstevel@tonic-gate break; 11727c478bd9Sstevel@tonic-gate #endif /* __x86 */ 11737c478bd9Sstevel@tonic-gate case 'a': 11747c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xarch=", 7) == 0) { 1175e521259dSpetede mflag |= xlate_xtb(ctx->i_ae, arg + 7); 11767c478bd9Sstevel@tonic-gate break; 11777c478bd9Sstevel@tonic-gate } 11787c478bd9Sstevel@tonic-gate error(arg); 11797c478bd9Sstevel@tonic-gate break; 118002e56f3fSwesolows case 'b': 118102e56f3fSwesolows if (strncmp(arg, "-xbuiltin=", 10) == 0) { 118202e56f3fSwesolows if (strcmp(arg + 10, "%all")) 118380ab886dSwesolows newae(ctx->i_ae, "-fbuiltin"); 118402e56f3fSwesolows break; 118502e56f3fSwesolows } 118602e56f3fSwesolows error(arg); 118702e56f3fSwesolows break; 11887c478bd9Sstevel@tonic-gate case 'C': 11897c478bd9Sstevel@tonic-gate /* Accept C++ style comments -- ignore */ 11907c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xCC") == 0) 11917c478bd9Sstevel@tonic-gate break; 11927c478bd9Sstevel@tonic-gate error(arg); 11937c478bd9Sstevel@tonic-gate break; 11947c478bd9Sstevel@tonic-gate case 'c': 11957c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xc99=%all", 10) == 0) { 119680ab886dSwesolows newae(ctx->i_ae, "-std=gnu99"); 11977c478bd9Sstevel@tonic-gate break; 11987c478bd9Sstevel@tonic-gate } 11997c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xc99=%none", 11) == 0) { 120080ab886dSwesolows newae(ctx->i_ae, "-std=gnu89"); 12017c478bd9Sstevel@tonic-gate break; 12027c478bd9Sstevel@tonic-gate } 12037c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xchip=", 7) == 0) { 120480ab886dSwesolows xlate(ctx->i_ae, arg + 7, xchip_tbl); 12057c478bd9Sstevel@tonic-gate break; 12067c478bd9Sstevel@tonic-gate } 12077c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xcode=", 7) == 0) { 120880ab886dSwesolows xlate(ctx->i_ae, arg + 7, xcode_tbl); 12097c478bd9Sstevel@tonic-gate if (strncmp(arg + 7, "pic", 3) == 0) 12107c478bd9Sstevel@tonic-gate pic = 1; 12117c478bd9Sstevel@tonic-gate break; 12127c478bd9Sstevel@tonic-gate } 12137c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xcache=", 8) == 0) 12147c478bd9Sstevel@tonic-gate break; 1215159cf8a6Swesolows if (strncmp(arg, "-xcrossfile", 11) == 0) 1216159cf8a6Swesolows break; 12177c478bd9Sstevel@tonic-gate error(arg); 12187c478bd9Sstevel@tonic-gate break; 12197c478bd9Sstevel@tonic-gate case 'd': 12207c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xdepend") == 0) 12217c478bd9Sstevel@tonic-gate break; 12228c1a3716Ssherrym if (strncmp(arg, "-xdebugformat=", 14) == 0) 12238c1a3716Ssherrym break; 12247c478bd9Sstevel@tonic-gate error(arg); 12257c478bd9Sstevel@tonic-gate break; 12267c478bd9Sstevel@tonic-gate case 'F': 1227f795e658Srie /* 1228f795e658Srie * Compile for mapfile reordering, or unused 1229f795e658Srie * section elimination, syntax can be -xF or 1230f795e658Srie * more complex, like -xF=%all -- ignore. 1231f795e658Srie */ 1232f795e658Srie if (strncmp(arg, "-xF", 3) == 0) 12337c478bd9Sstevel@tonic-gate break; 12347c478bd9Sstevel@tonic-gate error(arg); 12357c478bd9Sstevel@tonic-gate break; 12367c478bd9Sstevel@tonic-gate case 'i': 12377c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xinline", 8) == 0) 12387c478bd9Sstevel@tonic-gate /* No inlining; ignore */ 12397c478bd9Sstevel@tonic-gate break; 12407c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xildon") == 0 || 12417c478bd9Sstevel@tonic-gate strcmp(arg, "-xildoff") == 0) 12427c478bd9Sstevel@tonic-gate /* No incremental linking; ignore */ 12437c478bd9Sstevel@tonic-gate break; 12447c478bd9Sstevel@tonic-gate error(arg); 12457c478bd9Sstevel@tonic-gate break; 124654836668Spetede #if defined(__x86) 124754836668Spetede case 'm': 124854836668Spetede if (strcmp(arg, "-xmodel=kernel") == 0) { 124954836668Spetede newae(ctx->i_ae, "-ffreestanding"); 125054836668Spetede newae(ctx->i_ae, "-mno-red-zone"); 125154836668Spetede model = "-mcmodel=kernel"; 125254836668Spetede nolibc = 1; 125354836668Spetede break; 125454836668Spetede } 125554836668Spetede error(arg); 125654836668Spetede break; 125754836668Spetede #endif /* __x86 */ 12587c478bd9Sstevel@tonic-gate case 'M': 12597c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xM") == 0) { 126080ab886dSwesolows newae(ctx->i_ae, "-M"); 12617c478bd9Sstevel@tonic-gate break; 12627c478bd9Sstevel@tonic-gate } 12637c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xM1") == 0) { 126480ab886dSwesolows newae(ctx->i_ae, "-MM"); 12657c478bd9Sstevel@tonic-gate break; 12667c478bd9Sstevel@tonic-gate } 12677c478bd9Sstevel@tonic-gate error(arg); 12687c478bd9Sstevel@tonic-gate break; 12697c478bd9Sstevel@tonic-gate case 'n': 12707c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xnolib") == 0) { 12717c478bd9Sstevel@tonic-gate nolibc = 1; 12727c478bd9Sstevel@tonic-gate break; 12737c478bd9Sstevel@tonic-gate } 12747c478bd9Sstevel@tonic-gate error(arg); 12757c478bd9Sstevel@tonic-gate break; 12767c478bd9Sstevel@tonic-gate case 'O': 12777c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xO", 3) == 0) { 12787c478bd9Sstevel@tonic-gate size_t len = strlen(arg); 1279538ff303SToomas Soome char *s = NULL; 12807c478bd9Sstevel@tonic-gate int c = *(arg + 3); 12817c478bd9Sstevel@tonic-gate int level; 12827c478bd9Sstevel@tonic-gate 12837c478bd9Sstevel@tonic-gate if (len != 4 || !isdigit(c)) 12847c478bd9Sstevel@tonic-gate error(arg); 12857c478bd9Sstevel@tonic-gate 12867c478bd9Sstevel@tonic-gate level = atoi(arg + 3); 12877c478bd9Sstevel@tonic-gate if (level > 5) 12887c478bd9Sstevel@tonic-gate error(arg); 12897c478bd9Sstevel@tonic-gate if (level >= 2) { 12907c478bd9Sstevel@tonic-gate /* 12917c478bd9Sstevel@tonic-gate * For gcc-3.4.x at -O2 we 12927c478bd9Sstevel@tonic-gate * need to disable optimizations 12937c478bd9Sstevel@tonic-gate * that break ON. 12947c478bd9Sstevel@tonic-gate */ 129580ab886dSwesolows optim_disable(ctx->i_ae, level); 12967c478bd9Sstevel@tonic-gate /* 12977c478bd9Sstevel@tonic-gate * limit -xO3 to -O2 as well. 12987c478bd9Sstevel@tonic-gate */ 12997c478bd9Sstevel@tonic-gate level = 2; 13007c478bd9Sstevel@tonic-gate } 1301538ff303SToomas Soome if (asprintf(&s, "-O%d", level) == -1) 1302538ff303SToomas Soome nomem(); 130380ab886dSwesolows newae(ctx->i_ae, s); 13047c478bd9Sstevel@tonic-gate free(s); 13057c478bd9Sstevel@tonic-gate break; 13067c478bd9Sstevel@tonic-gate } 13077c478bd9Sstevel@tonic-gate error(arg); 13087c478bd9Sstevel@tonic-gate break; 13097c478bd9Sstevel@tonic-gate case 'p': 13107c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xpentium") == 0) { 131180ab886dSwesolows newae(ctx->i_ae, "-march=pentium"); 13127c478bd9Sstevel@tonic-gate break; 13137c478bd9Sstevel@tonic-gate } 13147c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xpg") == 0) { 131580ab886dSwesolows newae(ctx->i_ae, "-pg"); 13167c478bd9Sstevel@tonic-gate break; 13177c478bd9Sstevel@tonic-gate } 13187c478bd9Sstevel@tonic-gate error(arg); 13197c478bd9Sstevel@tonic-gate break; 13207c478bd9Sstevel@tonic-gate case 'r': 13217c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xregs=", 7) == 0) { 132280ab886dSwesolows xlate(ctx->i_ae, arg + 7, xregs_tbl); 13237c478bd9Sstevel@tonic-gate break; 13247c478bd9Sstevel@tonic-gate } 13257c478bd9Sstevel@tonic-gate error(arg); 13267c478bd9Sstevel@tonic-gate break; 13277c478bd9Sstevel@tonic-gate case 's': 13287c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xs") == 0 || 13297c478bd9Sstevel@tonic-gate strcmp(arg, "-xspace") == 0 || 13307c478bd9Sstevel@tonic-gate strcmp(arg, "-xstrconst") == 0) 13317c478bd9Sstevel@tonic-gate break; 13327c478bd9Sstevel@tonic-gate error(arg); 13337c478bd9Sstevel@tonic-gate break; 13347c478bd9Sstevel@tonic-gate case 't': 13357c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xtransition") == 0) { 133680ab886dSwesolows newae(ctx->i_ae, "-Wtransition"); 13377c478bd9Sstevel@tonic-gate break; 13387c478bd9Sstevel@tonic-gate } 13397c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xtrigraphs=yes") == 0) { 134080ab886dSwesolows newae(ctx->i_ae, "-trigraphs"); 13417c478bd9Sstevel@tonic-gate break; 13427c478bd9Sstevel@tonic-gate } 13437c478bd9Sstevel@tonic-gate if (strcmp(arg, "-xtrigraphs=no") == 0) { 134480ab886dSwesolows newae(ctx->i_ae, "-notrigraphs"); 13457c478bd9Sstevel@tonic-gate break; 13467c478bd9Sstevel@tonic-gate } 13477c478bd9Sstevel@tonic-gate if (strncmp(arg, "-xtarget=", 9) == 0) { 134880ab886dSwesolows xlate(ctx->i_ae, arg + 9, xtarget_tbl); 13497c478bd9Sstevel@tonic-gate break; 13507c478bd9Sstevel@tonic-gate } 13517c478bd9Sstevel@tonic-gate error(arg); 13527c478bd9Sstevel@tonic-gate break; 13537c478bd9Sstevel@tonic-gate case 'e': 13547c478bd9Sstevel@tonic-gate case 'h': 13557c478bd9Sstevel@tonic-gate case 'l': 13567c478bd9Sstevel@tonic-gate default: 13577c478bd9Sstevel@tonic-gate error(arg); 13587c478bd9Sstevel@tonic-gate break; 13597c478bd9Sstevel@tonic-gate } 13607c478bd9Sstevel@tonic-gate break; 13617c478bd9Sstevel@tonic-gate case 'Y': 13627c478bd9Sstevel@tonic-gate if (arglen == 1) { 136380ab886dSwesolows if ((arg = *++ctx->i_oldargv) == NULL || 136480ab886dSwesolows *arg == '\0') 13657c478bd9Sstevel@tonic-gate error("-Y"); 136680ab886dSwesolows ctx->i_oldargc--; 13677c478bd9Sstevel@tonic-gate arglen = strlen(arg + 1); 13687c478bd9Sstevel@tonic-gate } else { 13697c478bd9Sstevel@tonic-gate arg += 2; 13707c478bd9Sstevel@tonic-gate } 13717c478bd9Sstevel@tonic-gate /* Just ignore -YS,... for now */ 13727c478bd9Sstevel@tonic-gate if (strncmp(arg, "S,", 2) == 0) 13737c478bd9Sstevel@tonic-gate break; 13747c478bd9Sstevel@tonic-gate if (strncmp(arg, "l,", 2) == 0) { 13757c478bd9Sstevel@tonic-gate char *s = strdup(arg); 13767c478bd9Sstevel@tonic-gate s[0] = '-'; 13777c478bd9Sstevel@tonic-gate s[1] = 'B'; 137880ab886dSwesolows newae(ctx->i_ae, s); 13797c478bd9Sstevel@tonic-gate free(s); 13807c478bd9Sstevel@tonic-gate break; 13817c478bd9Sstevel@tonic-gate } 13827c478bd9Sstevel@tonic-gate if (strncmp(arg, "I,", 2) == 0) { 13837c478bd9Sstevel@tonic-gate char *s = strdup(arg); 13847c478bd9Sstevel@tonic-gate s[0] = '-'; 13857c478bd9Sstevel@tonic-gate s[1] = 'I'; 138680ab886dSwesolows newae(ctx->i_ae, "-nostdinc"); 138780ab886dSwesolows newae(ctx->i_ae, s); 13887c478bd9Sstevel@tonic-gate free(s); 13897c478bd9Sstevel@tonic-gate break; 13907c478bd9Sstevel@tonic-gate } 13917c478bd9Sstevel@tonic-gate error(arg); 13927c478bd9Sstevel@tonic-gate break; 13937c478bd9Sstevel@tonic-gate case 'Q': 13947c478bd9Sstevel@tonic-gate /* 13957c478bd9Sstevel@tonic-gate * We could map -Qy into -Wl,-Qy etc. 13967c478bd9Sstevel@tonic-gate */ 13977c478bd9Sstevel@tonic-gate default: 13987c478bd9Sstevel@tonic-gate error(arg); 13997c478bd9Sstevel@tonic-gate break; 14007c478bd9Sstevel@tonic-gate } 14017c478bd9Sstevel@tonic-gate } 14027c478bd9Sstevel@tonic-gate 1403*aa9ef484SJohn Levon free(nameflag); 1404*aa9ef484SJohn Levon 140580ab886dSwesolows if (c_files > 1 && (ctx->i_flags & CW_F_SHADOW) && 140680ab886dSwesolows op != CW_O_PREPROCESS) { 1407*aa9ef484SJohn Levon errx(2, "multiple source files are " 1408*aa9ef484SJohn Levon "allowed only with -E or -P"); 140980ab886dSwesolows } 1410e521259dSpetede 1411e521259dSpetede /* 1412e521259dSpetede * Make sure that we do not have any unintended interactions between 1413e521259dSpetede * the xarch options passed in and the version of the Studio compiler 1414e521259dSpetede * used. 1415e521259dSpetede */ 1416e521259dSpetede if ((mflag & (SS11|SS12)) == (SS11|SS12)) { 1417*aa9ef484SJohn Levon errx(2, 1418e521259dSpetede "Conflicting \"-xarch=\" flags (both Studio 11 and 12)\n"); 1419e521259dSpetede } 1420e521259dSpetede 1421e521259dSpetede switch (mflag) { 1422e521259dSpetede case 0: 1423e521259dSpetede /* FALLTHROUGH */ 1424e521259dSpetede case M32: 1425e521259dSpetede #if defined(__sparc) 1426e521259dSpetede /* 1427e521259dSpetede * Only -m32 is defined and so put in the missing xarch 1428e521259dSpetede * translation. 1429e521259dSpetede */ 1430e521259dSpetede newae(ctx->i_ae, "-mcpu=v8"); 1431e521259dSpetede newae(ctx->i_ae, "-mno-v8plus"); 1432e521259dSpetede #endif 1433e521259dSpetede break; 1434e521259dSpetede case M64: 1435e521259dSpetede #if defined(__sparc) 1436e521259dSpetede /* 1437e521259dSpetede * Only -m64 is defined and so put in the missing xarch 1438e521259dSpetede * translation. 1439e521259dSpetede */ 1440e521259dSpetede newae(ctx->i_ae, "-mcpu=v9"); 1441e521259dSpetede #endif 1442e521259dSpetede break; 1443e521259dSpetede case SS12: 1444e521259dSpetede #if defined(__sparc) 1445e521259dSpetede /* no -m32/-m64 flag used - this is an error for sparc builds */ 1446e521259dSpetede (void) fprintf(stderr, "No -m32/-m64 flag defined\n"); 1447e521259dSpetede exit(2); 1448e521259dSpetede #endif 1449e521259dSpetede break; 1450e521259dSpetede case SS11: 1451e521259dSpetede /* FALLTHROUGH */ 1452e521259dSpetede case (SS11|M32): 1453e521259dSpetede case (SS11|M64): 1454e521259dSpetede break; 1455e521259dSpetede case (SS12|M32): 1456e521259dSpetede #if defined(__sparc) 1457e521259dSpetede /* 1458e521259dSpetede * Need to add in further 32 bit options because with SS12 1459e521259dSpetede * the xarch=sparcvis option can be applied to 32 or 64 1460e521259dSpetede * bit, and so the translatation table (xtbl) cannot handle 1461e521259dSpetede * that. 1462e521259dSpetede */ 1463e521259dSpetede newae(ctx->i_ae, "-mv8plus"); 1464e521259dSpetede #endif 1465e521259dSpetede break; 1466e521259dSpetede case (SS12|M64): 1467e521259dSpetede break; 1468e521259dSpetede default: 1469e521259dSpetede (void) fprintf(stderr, 14707a6460b6Spetede "Incompatible -xarch= and/or -m32/-m64 options used.\n"); 1471e521259dSpetede exit(2); 1472e521259dSpetede } 1473*aa9ef484SJohn Levon 1474*aa9ef484SJohn Levon if ((op == CW_O_LINK || op == CW_O_PREPROCESS) && 1475*aa9ef484SJohn Levon (ctx->i_flags & CW_F_SHADOW)) 147680ab886dSwesolows exit(0); 147780ab886dSwesolows 14787c478bd9Sstevel@tonic-gate if (model && !pic) 147980ab886dSwesolows newae(ctx->i_ae, model); 14807c478bd9Sstevel@tonic-gate if (!nolibc) 148180ab886dSwesolows newae(ctx->i_ae, "-lc"); 148280ab886dSwesolows if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) { 148380ab886dSwesolows newae(ctx->i_ae, "-o"); 148480ab886dSwesolows newae(ctx->i_ae, ctx->i_discard); 148580ab886dSwesolows } 148680ab886dSwesolows } 148780ab886dSwesolows 148880ab886dSwesolows static void 148980ab886dSwesolows do_cc(cw_ictx_t *ctx) 149080ab886dSwesolows { 149180ab886dSwesolows int in_output = 0, seen_o = 0; 149280ab886dSwesolows cw_op_t op = CW_O_LINK; 1493*aa9ef484SJohn Levon char *nameflag; 149480ab886dSwesolows 14951912d2c4Swesolows if (ctx->i_flags & CW_F_PROG) { 14961912d2c4Swesolows newae(ctx->i_ae, "-V"); 14971912d2c4Swesolows return; 14981912d2c4Swesolows } 14991912d2c4Swesolows 1500*aa9ef484SJohn Levon if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->c_name) == -1) 1501*aa9ef484SJohn Levon nomem(); 1502*aa9ef484SJohn Levon 150380ab886dSwesolows while (--ctx->i_oldargc > 0) { 150480ab886dSwesolows char *arg = *++ctx->i_oldargv; 150580ab886dSwesolows 1506*aa9ef484SJohn Levon if (strncmp(arg, "-_CC=", 5) == 0) { 1507*aa9ef484SJohn Levon newae(ctx->i_ae, strchr(arg, '=') + 1); 1508*aa9ef484SJohn Levon continue; 1509*aa9ef484SJohn Levon } 1510*aa9ef484SJohn Levon 151180ab886dSwesolows if (*arg != '-') { 151280ab886dSwesolows if (in_output == 0 || !(ctx->i_flags & CW_F_SHADOW)) { 151380ab886dSwesolows newae(ctx->i_ae, arg); 151480ab886dSwesolows } else { 151580ab886dSwesolows in_output = 0; 151680ab886dSwesolows newae(ctx->i_ae, ctx->i_discard); 151780ab886dSwesolows } 151880ab886dSwesolows continue; 151980ab886dSwesolows } 152080ab886dSwesolows switch (*(arg + 1)) { 152180ab886dSwesolows case '_': 1522*aa9ef484SJohn Levon if ((strncmp(arg, nameflag, strlen(nameflag)) == 0) || 1523*aa9ef484SJohn Levon (strncmp(arg, "-_cc=", 5) == 0) || 1524*aa9ef484SJohn Levon (strncmp(arg, "-_sun=", 6) == 0)) { 1525*aa9ef484SJohn Levon newae(ctx->i_ae, strchr(arg, '=') + 1); 152680ab886dSwesolows } 152780ab886dSwesolows break; 1528*aa9ef484SJohn Levon 152980ab886dSwesolows case 'V': 153080ab886dSwesolows ctx->i_flags &= ~CW_F_ECHO; 153180ab886dSwesolows newae(ctx->i_ae, arg); 153280ab886dSwesolows break; 153380ab886dSwesolows case 'o': 153480ab886dSwesolows seen_o = 1; 153580ab886dSwesolows if (strlen(arg) == 2) { 153680ab886dSwesolows in_output = 1; 153780ab886dSwesolows newae(ctx->i_ae, arg); 153880ab886dSwesolows } else if (ctx->i_flags & CW_F_SHADOW) { 153980ab886dSwesolows newae(ctx->i_ae, "-o"); 154080ab886dSwesolows newae(ctx->i_ae, ctx->i_discard); 154180ab886dSwesolows } else { 154280ab886dSwesolows newae(ctx->i_ae, arg); 154380ab886dSwesolows } 154480ab886dSwesolows break; 154580ab886dSwesolows case 'c': 154680ab886dSwesolows case 'S': 15470bb3415fSrie if (strlen(arg) == 2) 15480bb3415fSrie op = CW_O_COMPILE; 154980ab886dSwesolows newae(ctx->i_ae, arg); 155080ab886dSwesolows break; 155180ab886dSwesolows case 'E': 155280ab886dSwesolows case 'P': 15530bb3415fSrie if (strlen(arg) == 2) 15540bb3415fSrie op = CW_O_PREPROCESS; 155580ab886dSwesolows /*FALLTHROUGH*/ 155680ab886dSwesolows default: 155780ab886dSwesolows newae(ctx->i_ae, arg); 155880ab886dSwesolows } 155980ab886dSwesolows } 156080ab886dSwesolows 1561*aa9ef484SJohn Levon free(nameflag); 1562*aa9ef484SJohn Levon 156380ab886dSwesolows if ((op == CW_O_LINK || op == CW_O_PREPROCESS) && 156480ab886dSwesolows (ctx->i_flags & CW_F_SHADOW)) 156580ab886dSwesolows exit(0); 156680ab886dSwesolows 156780ab886dSwesolows if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) { 156880ab886dSwesolows newae(ctx->i_ae, "-o"); 156980ab886dSwesolows newae(ctx->i_ae, ctx->i_discard); 157080ab886dSwesolows } 15717c478bd9Sstevel@tonic-gate } 15727c478bd9Sstevel@tonic-gate 15737c478bd9Sstevel@tonic-gate static void 157480ab886dSwesolows prepctx(cw_ictx_t *ctx) 15757c478bd9Sstevel@tonic-gate { 1576*aa9ef484SJohn Levon newae(ctx->i_ae, ctx->i_compiler->c_path); 157780ab886dSwesolows 15781912d2c4Swesolows if (ctx->i_flags & CW_F_PROG) { 15791912d2c4Swesolows (void) printf("%s: %s\n", (ctx->i_flags & CW_F_SHADOW) ? 1580*aa9ef484SJohn Levon "shadow" : "primary", ctx->i_compiler->c_path); 15811912d2c4Swesolows (void) fflush(stdout); 15821912d2c4Swesolows } 15831912d2c4Swesolows 158480ab886dSwesolows if (!(ctx->i_flags & CW_F_XLATE)) 158580ab886dSwesolows return; 158680ab886dSwesolows 1587*aa9ef484SJohn Levon switch (ctx->i_compiler->c_style) { 1588*aa9ef484SJohn Levon case SUN: 158980ab886dSwesolows do_cc(ctx); 159080ab886dSwesolows break; 1591*aa9ef484SJohn Levon case GNU: 159280ab886dSwesolows do_gcc(ctx); 159380ab886dSwesolows break; 159480ab886dSwesolows } 159580ab886dSwesolows } 159680ab886dSwesolows 159780ab886dSwesolows static int 159880ab886dSwesolows invoke(cw_ictx_t *ctx) 159980ab886dSwesolows { 160080ab886dSwesolows char **newargv; 160180ab886dSwesolows int ac; 160280ab886dSwesolows struct ae *a; 160380ab886dSwesolows 160480ab886dSwesolows if ((newargv = calloc(sizeof (*newargv), ctx->i_ae->ael_argc + 1)) == 160580ab886dSwesolows NULL) 160680ab886dSwesolows nomem(); 160780ab886dSwesolows 160880ab886dSwesolows if (ctx->i_flags & CW_F_ECHO) 160980ab886dSwesolows (void) fprintf(stderr, "+ "); 161080ab886dSwesolows 161180ab886dSwesolows for (ac = 0, a = ctx->i_ae->ael_head; a; a = a->ae_next, ac++) { 161280ab886dSwesolows newargv[ac] = a->ae_arg; 161380ab886dSwesolows if (ctx->i_flags & CW_F_ECHO) 161480ab886dSwesolows (void) fprintf(stderr, "%s ", a->ae_arg); 161580ab886dSwesolows if (a == ctx->i_ae->ael_tail) 161680ab886dSwesolows break; 161780ab886dSwesolows } 161880ab886dSwesolows 161980ab886dSwesolows if (ctx->i_flags & CW_F_ECHO) { 162080ab886dSwesolows (void) fprintf(stderr, "\n"); 162180ab886dSwesolows (void) fflush(stderr); 162280ab886dSwesolows } 162380ab886dSwesolows 162480ab886dSwesolows if (!(ctx->i_flags & CW_F_EXEC)) 162580ab886dSwesolows return (0); 162680ab886dSwesolows 16277c478bd9Sstevel@tonic-gate /* 1628*aa9ef484SJohn Levon * We must fix up the environment here so that the dependency files are 1629*aa9ef484SJohn Levon * not trampled by the shadow compiler. Also take care of GCC 1630*aa9ef484SJohn Levon * environment variables that will throw off gcc. This assumes a primary 1631*aa9ef484SJohn Levon * gcc. 16327c478bd9Sstevel@tonic-gate */ 163380ab886dSwesolows if ((ctx->i_flags & CW_F_SHADOW) && 163480ab886dSwesolows (unsetenv("SUNPRO_DEPENDENCIES") != 0 || 1635*aa9ef484SJohn Levon unsetenv("DEPENDENCIES_OUTPUT") != 0 || 1636*aa9ef484SJohn Levon unsetenv("GCC_ROOT") != 0)) { 163780ab886dSwesolows (void) fprintf(stderr, "error: environment setup failed: %s\n", 163880ab886dSwesolows strerror(errno)); 163980ab886dSwesolows return (-1); 164080ab886dSwesolows } 16417c478bd9Sstevel@tonic-gate 164280ab886dSwesolows (void) execv(newargv[0], newargv); 1643*aa9ef484SJohn Levon warn("couldn't run %s", newargv[0]); 16447c478bd9Sstevel@tonic-gate 164580ab886dSwesolows return (-1); 164680ab886dSwesolows } 164780ab886dSwesolows 164880ab886dSwesolows static int 164980ab886dSwesolows reap(cw_ictx_t *ctx) 165080ab886dSwesolows { 16511912d2c4Swesolows int status, ret = 0; 165280ab886dSwesolows char buf[1024]; 165380ab886dSwesolows struct stat s; 165480ab886dSwesolows 1655c3f177eaSPeter Dennis - Sustaining Engineer /* 1656c3f177eaSPeter Dennis - Sustaining Engineer * Only wait for one specific child. 1657c3f177eaSPeter Dennis - Sustaining Engineer */ 1658c3f177eaSPeter Dennis - Sustaining Engineer if (ctx->i_pid <= 0) 1659c3f177eaSPeter Dennis - Sustaining Engineer return (-1); 1660c3f177eaSPeter Dennis - Sustaining Engineer 166180ab886dSwesolows do { 1662c3f177eaSPeter Dennis - Sustaining Engineer if (waitpid(ctx->i_pid, &status, 0) < 0) { 1663*aa9ef484SJohn Levon warn("cannot reap child"); 1664c3f177eaSPeter Dennis - Sustaining Engineer return (-1); 1665c3f177eaSPeter Dennis - Sustaining Engineer } 16661912d2c4Swesolows if (status != 0) { 16671912d2c4Swesolows if (WIFSIGNALED(status)) { 16681912d2c4Swesolows ret = -WTERMSIG(status); 166980ab886dSwesolows break; 16701912d2c4Swesolows } else if (WIFEXITED(status)) { 16711912d2c4Swesolows ret = WEXITSTATUS(status); 167280ab886dSwesolows break; 167380ab886dSwesolows } 16747c478bd9Sstevel@tonic-gate } 16751912d2c4Swesolows } while (!WIFEXITED(status) && !WIFSIGNALED(status)); 167680ab886dSwesolows 167780ab886dSwesolows (void) unlink(ctx->i_discard); 167880ab886dSwesolows 16791912d2c4Swesolows if (stat(ctx->i_stderr, &s) < 0) { 1680*aa9ef484SJohn Levon warn("stat failed on child cleanup"); 168180ab886dSwesolows return (-1); 16827c478bd9Sstevel@tonic-gate } 168380ab886dSwesolows if (s.st_size != 0) { 16841912d2c4Swesolows FILE *f; 168580ab886dSwesolows 16861912d2c4Swesolows if ((f = fopen(ctx->i_stderr, "r")) != NULL) { 16871912d2c4Swesolows while (fgets(buf, sizeof (buf), f)) 16881912d2c4Swesolows (void) fprintf(stderr, "%s", buf); 16891912d2c4Swesolows (void) fflush(stderr); 16901912d2c4Swesolows (void) fclose(f); 16911912d2c4Swesolows } 169280ab886dSwesolows } 16931912d2c4Swesolows (void) unlink(ctx->i_stderr); 16941912d2c4Swesolows free(ctx->i_stderr); 16951912d2c4Swesolows 16961912d2c4Swesolows /* 16971912d2c4Swesolows * cc returns an error code when given -V; we want that to succeed. 16981912d2c4Swesolows */ 16991912d2c4Swesolows if (ctx->i_flags & CW_F_PROG) 17001912d2c4Swesolows return (0); 170180ab886dSwesolows 170280ab886dSwesolows return (ret); 170380ab886dSwesolows } 170480ab886dSwesolows 170580ab886dSwesolows static int 170680ab886dSwesolows exec_ctx(cw_ictx_t *ctx, int block) 170780ab886dSwesolows { 170880ab886dSwesolows char *file; 170980ab886dSwesolows 171080ab886dSwesolows /* 171180ab886dSwesolows * To avoid offending cc's sensibilities, the name of its output 171280ab886dSwesolows * file must end in '.o'. 171380ab886dSwesolows */ 171480ab886dSwesolows if ((file = tempnam(NULL, ".cw")) == NULL) { 171580ab886dSwesolows nomem(); 171680ab886dSwesolows return (-1); 171780ab886dSwesolows } 171880ab886dSwesolows (void) strlcpy(ctx->i_discard, file, MAXPATHLEN); 171980ab886dSwesolows (void) strlcat(ctx->i_discard, ".o", MAXPATHLEN); 172080ab886dSwesolows free(file); 172180ab886dSwesolows 17221912d2c4Swesolows if ((ctx->i_stderr = tempnam(NULL, ".cw")) == NULL) { 17231912d2c4Swesolows nomem(); 172480ab886dSwesolows return (-1); 172580ab886dSwesolows } 172680ab886dSwesolows 172780ab886dSwesolows if ((ctx->i_pid = fork()) == 0) { 17281912d2c4Swesolows int fd; 17291912d2c4Swesolows 173080ab886dSwesolows (void) fclose(stderr); 17311912d2c4Swesolows if ((fd = open(ctx->i_stderr, O_WRONLY | O_CREAT | O_EXCL, 17321912d2c4Swesolows 0666)) < 0) { 1733*aa9ef484SJohn Levon err(1, "open failed for standard error"); 17341912d2c4Swesolows } 17351912d2c4Swesolows if (dup2(fd, 2) < 0) { 1736*aa9ef484SJohn Levon err(1, "dup2 failed for standard error"); 173780ab886dSwesolows } 17381912d2c4Swesolows if (fd != 2) 17391912d2c4Swesolows (void) close(fd); 174080ab886dSwesolows if (freopen("/dev/fd/2", "w", stderr) == NULL) { 1741*aa9ef484SJohn Levon err(1, "freopen failed for /dev/fd/2"); 174280ab886dSwesolows } 1743*aa9ef484SJohn Levon 174480ab886dSwesolows prepctx(ctx); 174580ab886dSwesolows exit(invoke(ctx)); 174680ab886dSwesolows } 174780ab886dSwesolows 174880ab886dSwesolows if (ctx->i_pid < 0) { 1749*aa9ef484SJohn Levon err(1, "fork failed"); 175080ab886dSwesolows } 175180ab886dSwesolows 175280ab886dSwesolows if (block) 175380ab886dSwesolows return (reap(ctx)); 175480ab886dSwesolows 175580ab886dSwesolows return (0); 17567c478bd9Sstevel@tonic-gate } 17577c478bd9Sstevel@tonic-gate 1758*aa9ef484SJohn Levon static void 1759*aa9ef484SJohn Levon parse_compiler(const char *spec, cw_compiler_t *compiler) 17607c478bd9Sstevel@tonic-gate { 1761*aa9ef484SJohn Levon char *tspec, *token; 17627c478bd9Sstevel@tonic-gate 1763*aa9ef484SJohn Levon if ((tspec = strdup(spec)) == NULL) 176480ab886dSwesolows nomem(); 176580ab886dSwesolows 1766*aa9ef484SJohn Levon if ((token = strsep(&tspec, ",")) == NULL) 1767*aa9ef484SJohn Levon errx(1, "Compiler is missing a name: %s", spec); 1768*aa9ef484SJohn Levon compiler->c_name = token; 17697c478bd9Sstevel@tonic-gate 1770*aa9ef484SJohn Levon if ((token = strsep(&tspec, ",")) == NULL) 1771*aa9ef484SJohn Levon errx(1, "Compiler is missing a path: %s", spec); 1772*aa9ef484SJohn Levon compiler->c_path = token; 17737c478bd9Sstevel@tonic-gate 1774*aa9ef484SJohn Levon if ((token = strsep(&tspec, ",")) == NULL) 1775*aa9ef484SJohn Levon errx(1, "Compiler is missing a style: %s", spec); 17767c478bd9Sstevel@tonic-gate 1777*aa9ef484SJohn Levon if ((strcasecmp(token, "gnu") == 0) || 1778*aa9ef484SJohn Levon (strcasecmp(token, "gcc") == 0)) 1779*aa9ef484SJohn Levon compiler->c_style = GNU; 1780*aa9ef484SJohn Levon else if ((strcasecmp(token, "sun") == 0) || 1781*aa9ef484SJohn Levon (strcasecmp(token, "cc") == 0)) 1782*aa9ef484SJohn Levon compiler->c_style = SUN; 1783*aa9ef484SJohn Levon else 1784*aa9ef484SJohn Levon errx(1, "unknown compiler style: %s", token); 178580ab886dSwesolows 1786*aa9ef484SJohn Levon if (tspec != NULL) 1787*aa9ef484SJohn Levon errx(1, "Excess tokens in compiler: %s", spec); 1788*aa9ef484SJohn Levon } 17897c478bd9Sstevel@tonic-gate 1790*aa9ef484SJohn Levon int 1791*aa9ef484SJohn Levon main(int argc, char **argv) 1792*aa9ef484SJohn Levon { 1793*aa9ef484SJohn Levon int ch; 1794*aa9ef484SJohn Levon cw_compiler_t primary = { NULL, NULL, 0 }; 1795*aa9ef484SJohn Levon cw_compiler_t shadows[10]; 1796*aa9ef484SJohn Levon int nshadows = 0; 1797*aa9ef484SJohn Levon int ret = 0; 1798*aa9ef484SJohn Levon boolean_t do_serial = B_FALSE; 1799*aa9ef484SJohn Levon boolean_t do_exec = B_FALSE; 1800*aa9ef484SJohn Levon boolean_t vflg = B_FALSE; 1801*aa9ef484SJohn Levon boolean_t Cflg = B_FALSE; 1802*aa9ef484SJohn Levon boolean_t cflg = B_FALSE; 1803*aa9ef484SJohn Levon boolean_t nflg = B_FALSE; 1804*aa9ef484SJohn Levon 1805*aa9ef484SJohn Levon cw_ictx_t *main_ctx; 1806*aa9ef484SJohn Levon 1807*aa9ef484SJohn Levon static struct option longopts[] = { 1808*aa9ef484SJohn Levon { "compiler", no_argument, NULL, 'c' }, 1809*aa9ef484SJohn Levon { "noecho", no_argument, NULL, 'n' }, 1810*aa9ef484SJohn Levon { "primary", required_argument, NULL, 'p' }, 1811*aa9ef484SJohn Levon { "shadow", required_argument, NULL, 's' }, 1812*aa9ef484SJohn Levon { "versions", no_argument, NULL, 'v' }, 1813*aa9ef484SJohn Levon { NULL, 0, NULL, 0 }, 1814*aa9ef484SJohn Levon }; 1815*aa9ef484SJohn Levon 1816*aa9ef484SJohn Levon 1817*aa9ef484SJohn Levon if ((main_ctx = newictx()) == NULL) 1818*aa9ef484SJohn Levon nomem(); 1819*aa9ef484SJohn Levon 1820*aa9ef484SJohn Levon while ((ch = getopt_long(argc, argv, "C", longopts, NULL)) != -1) { 1821*aa9ef484SJohn Levon switch (ch) { 1822*aa9ef484SJohn Levon case 'c': 1823*aa9ef484SJohn Levon cflg = B_TRUE; 1824*aa9ef484SJohn Levon break; 1825*aa9ef484SJohn Levon case 'C': 1826*aa9ef484SJohn Levon Cflg = B_TRUE; 1827*aa9ef484SJohn Levon break; 1828*aa9ef484SJohn Levon case 'n': 1829*aa9ef484SJohn Levon nflg = B_TRUE; 1830*aa9ef484SJohn Levon break; 1831*aa9ef484SJohn Levon case 'p': 1832*aa9ef484SJohn Levon if (primary.c_path != NULL) { 1833*aa9ef484SJohn Levon warnx("Only one primary compiler may " 1834*aa9ef484SJohn Levon "be specified"); 1835*aa9ef484SJohn Levon usage(); 1836*aa9ef484SJohn Levon } 1837*aa9ef484SJohn Levon 1838*aa9ef484SJohn Levon parse_compiler(optarg, &primary); 1839*aa9ef484SJohn Levon break; 1840*aa9ef484SJohn Levon case 's': 1841*aa9ef484SJohn Levon if (nshadows >= 10) 1842*aa9ef484SJohn Levon errx(1, "May only use 10 shadows at " 1843*aa9ef484SJohn Levon "the moment"); 1844*aa9ef484SJohn Levon parse_compiler(optarg, &shadows[nshadows]); 1845*aa9ef484SJohn Levon nshadows++; 1846*aa9ef484SJohn Levon break; 1847*aa9ef484SJohn Levon case 'v': 1848*aa9ef484SJohn Levon vflg = B_TRUE; 1849*aa9ef484SJohn Levon break; 1850*aa9ef484SJohn Levon default: 1851*aa9ef484SJohn Levon (void) fprintf(stderr, "Did you forget '--'?\n"); 1852*aa9ef484SJohn Levon usage(); 1853*aa9ef484SJohn Levon } 1854*aa9ef484SJohn Levon } 1855*aa9ef484SJohn Levon 1856*aa9ef484SJohn Levon if (primary.c_path == NULL) { 1857*aa9ef484SJohn Levon warnx("A primary compiler must be specified"); 18587c478bd9Sstevel@tonic-gate usage(); 18597c478bd9Sstevel@tonic-gate } 18607c478bd9Sstevel@tonic-gate 1861*aa9ef484SJohn Levon do_serial = (getenv("CW_SHADOW_SERIAL") == NULL) ? B_FALSE : B_TRUE; 1862*aa9ef484SJohn Levon do_exec = (getenv("CW_NO_EXEC") == NULL) ? B_TRUE : B_FALSE; 1863*aa9ef484SJohn Levon 1864*aa9ef484SJohn Levon /* Leave room for argv[0] */ 1865*aa9ef484SJohn Levon argc -= (optind - 1); 1866*aa9ef484SJohn Levon argv += (optind - 1); 1867*aa9ef484SJohn Levon 1868*aa9ef484SJohn Levon main_ctx->i_oldargc = argc; 1869*aa9ef484SJohn Levon main_ctx->i_oldargv = argv; 1870*aa9ef484SJohn Levon main_ctx->i_flags = CW_F_XLATE; 1871*aa9ef484SJohn Levon if (nflg == 0) 1872*aa9ef484SJohn Levon main_ctx->i_flags |= CW_F_ECHO; 1873*aa9ef484SJohn Levon if (do_exec) 1874*aa9ef484SJohn Levon main_ctx->i_flags |= CW_F_EXEC; 1875*aa9ef484SJohn Levon if (Cflg) 1876*aa9ef484SJohn Levon main_ctx->i_flags |= CW_F_CXX; 1877*aa9ef484SJohn Levon main_ctx->i_compiler = &primary; 1878*aa9ef484SJohn Levon 1879*aa9ef484SJohn Levon if (cflg) { 1880*aa9ef484SJohn Levon (void) fputs(primary.c_path, stdout); 18817c478bd9Sstevel@tonic-gate } 18827c478bd9Sstevel@tonic-gate 1883*aa9ef484SJohn Levon if (vflg) { 1884*aa9ef484SJohn Levon (void) printf("cw version %s\n", CW_VERSION); 18851912d2c4Swesolows (void) fflush(stdout); 1886*aa9ef484SJohn Levon main_ctx->i_flags &= ~CW_F_ECHO; 1887*aa9ef484SJohn Levon main_ctx->i_flags |= CW_F_PROG | CW_F_EXEC; 18881912d2c4Swesolows do_serial = 1; 18891912d2c4Swesolows } 18901912d2c4Swesolows 1891*aa9ef484SJohn Levon ret |= exec_ctx(main_ctx, do_serial); 18921912d2c4Swesolows 1893*aa9ef484SJohn Levon for (int i = 0; i < nshadows; i++) { 1894*aa9ef484SJohn Levon int r; 1895*aa9ef484SJohn Levon cw_ictx_t *shadow_ctx; 189680ab886dSwesolows 1897*aa9ef484SJohn Levon if ((shadow_ctx = newictx()) == NULL) 1898*aa9ef484SJohn Levon nomem(); 1899*aa9ef484SJohn Levon 1900*aa9ef484SJohn Levon memcpy(shadow_ctx, main_ctx, sizeof (cw_ictx_t)); 1901*aa9ef484SJohn Levon 1902*aa9ef484SJohn Levon shadow_ctx->i_flags |= CW_F_SHADOW; 1903*aa9ef484SJohn Levon shadow_ctx->i_compiler = &shadows[i]; 1904*aa9ef484SJohn Levon 1905*aa9ef484SJohn Levon r = exec_ctx(shadow_ctx, do_serial); 1906*aa9ef484SJohn Levon if (r == 0) { 1907*aa9ef484SJohn Levon shadow_ctx->i_next = main_ctx->i_next; 1908*aa9ef484SJohn Levon main_ctx->i_next = shadow_ctx; 1909*aa9ef484SJohn Levon } 1910*aa9ef484SJohn Levon ret |= r; 19117c478bd9Sstevel@tonic-gate } 19127c478bd9Sstevel@tonic-gate 1913*aa9ef484SJohn Levon if (!do_serial) { 1914*aa9ef484SJohn Levon cw_ictx_t *next = main_ctx; 1915*aa9ef484SJohn Levon while (next != NULL) { 1916*aa9ef484SJohn Levon cw_ictx_t *toreap = next; 1917*aa9ef484SJohn Levon next = next->i_next; 1918*aa9ef484SJohn Levon ret |= reap(toreap); 1919*aa9ef484SJohn Levon } 1920*aa9ef484SJohn Levon } 19217c478bd9Sstevel@tonic-gate 192280ab886dSwesolows return (ret); 19237c478bd9Sstevel@tonic-gate } 1924