12a6b7db3Sskrll#! /bin/sh 2*9573673dSchristos# Wrapper for compilers which do not understand '-c -o'. 32a6b7db3Sskrll 4*9573673dSchristosscriptversion=2012-10-14.11; # UTC 52a6b7db3Sskrll 6*9573673dSchristos# Copyright (C) 1999-2014 Free Software Foundation, Inc. 72a6b7db3Sskrll# Written by Tom Tromey <tromey@cygnus.com>. 82a6b7db3Sskrll# 92a6b7db3Sskrll# This program is free software; you can redistribute it and/or modify 102a6b7db3Sskrll# it under the terms of the GNU General Public License as published by 112a6b7db3Sskrll# the Free Software Foundation; either version 2, or (at your option) 122a6b7db3Sskrll# any later version. 132a6b7db3Sskrll# 142a6b7db3Sskrll# This program is distributed in the hope that it will be useful, 152a6b7db3Sskrll# but WITHOUT ANY WARRANTY; without even the implied warranty of 162a6b7db3Sskrll# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 172a6b7db3Sskrll# GNU General Public License for more details. 182a6b7db3Sskrll# 192a6b7db3Sskrll# You should have received a copy of the GNU General Public License 20be9ac0eaSchristos# along with this program. If not, see <http://www.gnu.org/licenses/>. 212a6b7db3Sskrll 222a6b7db3Sskrll# As a special exception to the GNU General Public License, if you 232a6b7db3Sskrll# distribute this file as part of a program that contains a 242a6b7db3Sskrll# configuration script generated by Autoconf, you may include it under 252a6b7db3Sskrll# the same distribution terms that you use for the rest of that program. 262a6b7db3Sskrll 272a6b7db3Sskrll# This file is maintained in Automake, please report 282a6b7db3Sskrll# bugs to <bug-automake@gnu.org> or send patches to 292a6b7db3Sskrll# <automake-patches@gnu.org>. 302a6b7db3Sskrll 31*9573673dSchristosnl=' 32*9573673dSchristos' 33*9573673dSchristos 34*9573673dSchristos# We need space, tab and new line, in precisely that order. Quoting is 35*9573673dSchristos# there to prevent tools from complaining about whitespace usage. 36*9573673dSchristosIFS=" "" $nl" 37*9573673dSchristos 38*9573673dSchristosfile_conv= 39*9573673dSchristos 40*9573673dSchristos# func_file_conv build_file lazy 41*9573673dSchristos# Convert a $build file to $host form and store it in $file 42*9573673dSchristos# Currently only supports Windows hosts. If the determined conversion 43*9573673dSchristos# type is listed in (the comma separated) LAZY, no conversion will 44*9573673dSchristos# take place. 45*9573673dSchristosfunc_file_conv () 46*9573673dSchristos{ 47*9573673dSchristos file=$1 48*9573673dSchristos case $file in 49*9573673dSchristos / | /[!/]*) # absolute file, and not a UNC file 50*9573673dSchristos if test -z "$file_conv"; then 51*9573673dSchristos # lazily determine how to convert abs files 52*9573673dSchristos case `uname -s` in 53*9573673dSchristos MINGW*) 54*9573673dSchristos file_conv=mingw 55*9573673dSchristos ;; 56*9573673dSchristos CYGWIN*) 57*9573673dSchristos file_conv=cygwin 58*9573673dSchristos ;; 59*9573673dSchristos *) 60*9573673dSchristos file_conv=wine 61*9573673dSchristos ;; 62*9573673dSchristos esac 63*9573673dSchristos fi 64*9573673dSchristos case $file_conv/,$2, in 65*9573673dSchristos *,$file_conv,*) 66*9573673dSchristos ;; 67*9573673dSchristos mingw/*) 68*9573673dSchristos file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69*9573673dSchristos ;; 70*9573673dSchristos cygwin/*) 71*9573673dSchristos file=`cygpath -m "$file" || echo "$file"` 72*9573673dSchristos ;; 73*9573673dSchristos wine/*) 74*9573673dSchristos file=`winepath -w "$file" || echo "$file"` 75*9573673dSchristos ;; 76*9573673dSchristos esac 77*9573673dSchristos ;; 78*9573673dSchristos esac 79*9573673dSchristos} 80*9573673dSchristos 81*9573673dSchristos# func_cl_dashL linkdir 82*9573673dSchristos# Make cl look for libraries in LINKDIR 83*9573673dSchristosfunc_cl_dashL () 84*9573673dSchristos{ 85*9573673dSchristos func_file_conv "$1" 86*9573673dSchristos if test -z "$lib_path"; then 87*9573673dSchristos lib_path=$file 88*9573673dSchristos else 89*9573673dSchristos lib_path="$lib_path;$file" 90*9573673dSchristos fi 91*9573673dSchristos linker_opts="$linker_opts -LIBPATH:$file" 92*9573673dSchristos} 93*9573673dSchristos 94*9573673dSchristos# func_cl_dashl library 95*9573673dSchristos# Do a library search-path lookup for cl 96*9573673dSchristosfunc_cl_dashl () 97*9573673dSchristos{ 98*9573673dSchristos lib=$1 99*9573673dSchristos found=no 100*9573673dSchristos save_IFS=$IFS 101*9573673dSchristos IFS=';' 102*9573673dSchristos for dir in $lib_path $LIB 103*9573673dSchristos do 104*9573673dSchristos IFS=$save_IFS 105*9573673dSchristos if $shared && test -f "$dir/$lib.dll.lib"; then 106*9573673dSchristos found=yes 107*9573673dSchristos lib=$dir/$lib.dll.lib 108*9573673dSchristos break 109*9573673dSchristos fi 110*9573673dSchristos if test -f "$dir/$lib.lib"; then 111*9573673dSchristos found=yes 112*9573673dSchristos lib=$dir/$lib.lib 113*9573673dSchristos break 114*9573673dSchristos fi 115*9573673dSchristos if test -f "$dir/lib$lib.a"; then 116*9573673dSchristos found=yes 117*9573673dSchristos lib=$dir/lib$lib.a 118*9573673dSchristos break 119*9573673dSchristos fi 120*9573673dSchristos done 121*9573673dSchristos IFS=$save_IFS 122*9573673dSchristos 123*9573673dSchristos if test "$found" != yes; then 124*9573673dSchristos lib=$lib.lib 125*9573673dSchristos fi 126*9573673dSchristos} 127*9573673dSchristos 128*9573673dSchristos# func_cl_wrapper cl arg... 129*9573673dSchristos# Adjust compile command to suit cl 130*9573673dSchristosfunc_cl_wrapper () 131*9573673dSchristos{ 132*9573673dSchristos # Assume a capable shell 133*9573673dSchristos lib_path= 134*9573673dSchristos shared=: 135*9573673dSchristos linker_opts= 136*9573673dSchristos for arg 137*9573673dSchristos do 138*9573673dSchristos if test -n "$eat"; then 139*9573673dSchristos eat= 140*9573673dSchristos else 141*9573673dSchristos case $1 in 142*9573673dSchristos -o) 143*9573673dSchristos # configure might choose to run compile as 'compile cc -o foo foo.c'. 144*9573673dSchristos eat=1 145*9573673dSchristos case $2 in 146*9573673dSchristos *.o | *.[oO][bB][jJ]) 147*9573673dSchristos func_file_conv "$2" 148*9573673dSchristos set x "$@" -Fo"$file" 149*9573673dSchristos shift 150*9573673dSchristos ;; 151*9573673dSchristos *) 152*9573673dSchristos func_file_conv "$2" 153*9573673dSchristos set x "$@" -Fe"$file" 154*9573673dSchristos shift 155*9573673dSchristos ;; 156*9573673dSchristos esac 157*9573673dSchristos ;; 158*9573673dSchristos -I) 159*9573673dSchristos eat=1 160*9573673dSchristos func_file_conv "$2" mingw 161*9573673dSchristos set x "$@" -I"$file" 162*9573673dSchristos shift 163*9573673dSchristos ;; 164*9573673dSchristos -I*) 165*9573673dSchristos func_file_conv "${1#-I}" mingw 166*9573673dSchristos set x "$@" -I"$file" 167*9573673dSchristos shift 168*9573673dSchristos ;; 169*9573673dSchristos -l) 170*9573673dSchristos eat=1 171*9573673dSchristos func_cl_dashl "$2" 172*9573673dSchristos set x "$@" "$lib" 173*9573673dSchristos shift 174*9573673dSchristos ;; 175*9573673dSchristos -l*) 176*9573673dSchristos func_cl_dashl "${1#-l}" 177*9573673dSchristos set x "$@" "$lib" 178*9573673dSchristos shift 179*9573673dSchristos ;; 180*9573673dSchristos -L) 181*9573673dSchristos eat=1 182*9573673dSchristos func_cl_dashL "$2" 183*9573673dSchristos ;; 184*9573673dSchristos -L*) 185*9573673dSchristos func_cl_dashL "${1#-L}" 186*9573673dSchristos ;; 187*9573673dSchristos -static) 188*9573673dSchristos shared=false 189*9573673dSchristos ;; 190*9573673dSchristos -Wl,*) 191*9573673dSchristos arg=${1#-Wl,} 192*9573673dSchristos save_ifs="$IFS"; IFS=',' 193*9573673dSchristos for flag in $arg; do 194*9573673dSchristos IFS="$save_ifs" 195*9573673dSchristos linker_opts="$linker_opts $flag" 196*9573673dSchristos done 197*9573673dSchristos IFS="$save_ifs" 198*9573673dSchristos ;; 199*9573673dSchristos -Xlinker) 200*9573673dSchristos eat=1 201*9573673dSchristos linker_opts="$linker_opts $2" 202*9573673dSchristos ;; 203*9573673dSchristos -*) 204*9573673dSchristos set x "$@" "$1" 205*9573673dSchristos shift 206*9573673dSchristos ;; 207*9573673dSchristos *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208*9573673dSchristos func_file_conv "$1" 209*9573673dSchristos set x "$@" -Tp"$file" 210*9573673dSchristos shift 211*9573673dSchristos ;; 212*9573673dSchristos *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213*9573673dSchristos func_file_conv "$1" mingw 214*9573673dSchristos set x "$@" "$file" 215*9573673dSchristos shift 216*9573673dSchristos ;; 217*9573673dSchristos *) 218*9573673dSchristos set x "$@" "$1" 219*9573673dSchristos shift 220*9573673dSchristos ;; 221*9573673dSchristos esac 222*9573673dSchristos fi 223*9573673dSchristos shift 224*9573673dSchristos done 225*9573673dSchristos if test -n "$linker_opts"; then 226*9573673dSchristos linker_opts="-link$linker_opts" 227*9573673dSchristos fi 228*9573673dSchristos exec "$@" $linker_opts 229*9573673dSchristos exit 1 230*9573673dSchristos} 231*9573673dSchristos 232*9573673dSchristoseat= 233*9573673dSchristos 2342a6b7db3Sskrllcase $1 in 2352a6b7db3Sskrll '') 236*9573673dSchristos echo "$0: No command. Try '$0 --help' for more information." 1>&2 2372a6b7db3Sskrll exit 1; 2382a6b7db3Sskrll ;; 2392a6b7db3Sskrll -h | --h*) 2402a6b7db3Sskrll cat <<\EOF 2412a6b7db3SskrllUsage: compile [--help] [--version] PROGRAM [ARGS] 2422a6b7db3Sskrll 243*9573673dSchristosWrapper for compilers which do not understand '-c -o'. 244*9573673dSchristosRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 2452a6b7db3Sskrllarguments, and rename the output as expected. 2462a6b7db3Sskrll 2472a6b7db3SskrllIf you are trying to build a whole package this is not the 248*9573673dSchristosright script to run: please start by reading the file 'INSTALL'. 2492a6b7db3Sskrll 2502a6b7db3SskrllReport bugs to <bug-automake@gnu.org>. 2512a6b7db3SskrllEOF 2522a6b7db3Sskrll exit $? 2532a6b7db3Sskrll ;; 2542a6b7db3Sskrll -v | --v*) 2552a6b7db3Sskrll echo "compile $scriptversion" 2562a6b7db3Sskrll exit $? 2572a6b7db3Sskrll ;; 258*9573673dSchristos cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 259*9573673dSchristos func_cl_wrapper "$@" # Doesn't return... 260*9573673dSchristos ;; 2612a6b7db3Sskrllesac 2622a6b7db3Sskrll 2632a6b7db3Sskrllofile= 2642a6b7db3Sskrllcfile= 2652a6b7db3Sskrll 2662a6b7db3Sskrllfor arg 2672a6b7db3Sskrlldo 2682a6b7db3Sskrll if test -n "$eat"; then 2692a6b7db3Sskrll eat= 2702a6b7db3Sskrll else 2712a6b7db3Sskrll case $1 in 2722a6b7db3Sskrll -o) 273*9573673dSchristos # configure might choose to run compile as 'compile cc -o foo foo.c'. 274*9573673dSchristos # So we strip '-o arg' only if arg is an object. 2752a6b7db3Sskrll eat=1 2762a6b7db3Sskrll case $2 in 2772a6b7db3Sskrll *.o | *.obj) 2782a6b7db3Sskrll ofile=$2 2792a6b7db3Sskrll ;; 2802a6b7db3Sskrll *) 2812a6b7db3Sskrll set x "$@" -o "$2" 2822a6b7db3Sskrll shift 2832a6b7db3Sskrll ;; 2842a6b7db3Sskrll esac 2852a6b7db3Sskrll ;; 2862a6b7db3Sskrll *.c) 2872a6b7db3Sskrll cfile=$1 2882a6b7db3Sskrll set x "$@" "$1" 2892a6b7db3Sskrll shift 2902a6b7db3Sskrll ;; 2912a6b7db3Sskrll *) 2922a6b7db3Sskrll set x "$@" "$1" 2932a6b7db3Sskrll shift 2942a6b7db3Sskrll ;; 2952a6b7db3Sskrll esac 2962a6b7db3Sskrll fi 2972a6b7db3Sskrll shift 2982a6b7db3Sskrlldone 2992a6b7db3Sskrll 3002a6b7db3Sskrllif test -z "$ofile" || test -z "$cfile"; then 301*9573673dSchristos # If no '-o' option was seen then we might have been invoked from a 3022a6b7db3Sskrll # pattern rule where we don't need one. That is ok -- this is a 3032a6b7db3Sskrll # normal compilation that the losing compiler can handle. If no 304*9573673dSchristos # '.c' file was seen then we are probably linking. That is also 3052a6b7db3Sskrll # ok. 3062a6b7db3Sskrll exec "$@" 3072a6b7db3Sskrllfi 3082a6b7db3Sskrll 3092a6b7db3Sskrll# Name of file we expect compiler to create. 310be9ac0eaSchristoscofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 3112a6b7db3Sskrll 3122a6b7db3Sskrll# Create the lock directory. 313*9573673dSchristos# Note: use '[/\\:.-]' here to ensure that we don't use the same name 3142a6b7db3Sskrll# that we are using for the .o file. Also, base the name on the expected 3152a6b7db3Sskrll# object file name, since that is what matters with a parallel build. 316be9ac0eaSchristoslockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 3172a6b7db3Sskrllwhile true; do 3182a6b7db3Sskrll if mkdir "$lockdir" >/dev/null 2>&1; then 3192a6b7db3Sskrll break 3202a6b7db3Sskrll fi 3212a6b7db3Sskrll sleep 1 3222a6b7db3Sskrlldone 3232a6b7db3Sskrll# FIXME: race condition here if user kills between mkdir and trap. 3242a6b7db3Sskrlltrap "rmdir '$lockdir'; exit 1" 1 2 15 3252a6b7db3Sskrll 3262a6b7db3Sskrll# Run the compile. 3272a6b7db3Sskrll"$@" 3282a6b7db3Sskrllret=$? 3292a6b7db3Sskrll 3302a6b7db3Sskrllif test -f "$cofile"; then 331*9573673dSchristos test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 3322a6b7db3Sskrllelif test -f "${cofile}bj"; then 333*9573673dSchristos test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 3342a6b7db3Sskrllfi 3352a6b7db3Sskrll 3362a6b7db3Sskrllrmdir "$lockdir" 3372a6b7db3Sskrllexit $ret 3382a6b7db3Sskrll 3392a6b7db3Sskrll# Local Variables: 3402a6b7db3Sskrll# mode: shell-script 3412a6b7db3Sskrll# sh-indentation: 2 3422a6b7db3Sskrll# eval: (add-hook 'write-file-hooks 'time-stamp) 3432a6b7db3Sskrll# time-stamp-start: "scriptversion=" 3442a6b7db3Sskrll# time-stamp-format: "%:y-%02m-%02d.%02H" 345be9ac0eaSchristos# time-stamp-time-zone: "UTC" 346be9ac0eaSchristos# time-stamp-end: "; # UTC" 3472a6b7db3Sskrll# End: 348