1*affba8c7SCy Schubert#! /bin/sh 2*affba8c7SCy Schubert# Wrapper for compilers which do not understand '-c -o'. 3*affba8c7SCy Schubert 4*affba8c7SCy Schubertscriptversion=2012-10-14.11; # UTC 5*affba8c7SCy Schubert 6*affba8c7SCy Schubert# Copyright (C) 1999-2014 Free Software Foundation, Inc. 7*affba8c7SCy Schubert# Written by Tom Tromey <[email protected]>. 8*affba8c7SCy Schubert# 9*affba8c7SCy Schubert# This program is free software; you can redistribute it and/or modify 10*affba8c7SCy Schubert# it under the terms of the GNU General Public License as published by 11*affba8c7SCy Schubert# the Free Software Foundation; either version 2, or (at your option) 12*affba8c7SCy Schubert# any later version. 13*affba8c7SCy Schubert# 14*affba8c7SCy Schubert# This program is distributed in the hope that it will be useful, 15*affba8c7SCy Schubert# but WITHOUT ANY WARRANTY; without even the implied warranty of 16*affba8c7SCy Schubert# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*affba8c7SCy Schubert# GNU General Public License for more details. 18*affba8c7SCy Schubert# 19*affba8c7SCy Schubert# You should have received a copy of the GNU General Public License 20*affba8c7SCy Schubert# along with this program. If not, see <http://www.gnu.org/licenses/>. 21*affba8c7SCy Schubert 22*affba8c7SCy Schubert# As a special exception to the GNU General Public License, if you 23*affba8c7SCy Schubert# distribute this file as part of a program that contains a 24*affba8c7SCy Schubert# configuration script generated by Autoconf, you may include it under 25*affba8c7SCy Schubert# the same distribution terms that you use for the rest of that program. 26*affba8c7SCy Schubert 27*affba8c7SCy Schubert# This file is maintained in Automake, please report 28*affba8c7SCy Schubert# bugs to <[email protected]> or send patches to 29*affba8c7SCy Schubert# <[email protected]>. 30*affba8c7SCy Schubert 31*affba8c7SCy Schubertnl=' 32*affba8c7SCy Schubert' 33*affba8c7SCy Schubert 34*affba8c7SCy Schubert# We need space, tab and new line, in precisely that order. Quoting is 35*affba8c7SCy Schubert# there to prevent tools from complaining about whitespace usage. 36*affba8c7SCy SchubertIFS=" "" $nl" 37*affba8c7SCy Schubert 38*affba8c7SCy Schubertfile_conv= 39*affba8c7SCy Schubert 40*affba8c7SCy Schubert# func_file_conv build_file lazy 41*affba8c7SCy Schubert# Convert a $build file to $host form and store it in $file 42*affba8c7SCy Schubert# Currently only supports Windows hosts. If the determined conversion 43*affba8c7SCy Schubert# type is listed in (the comma separated) LAZY, no conversion will 44*affba8c7SCy Schubert# take place. 45*affba8c7SCy Schubertfunc_file_conv () 46*affba8c7SCy Schubert{ 47*affba8c7SCy Schubert file=$1 48*affba8c7SCy Schubert case $file in 49*affba8c7SCy Schubert / | /[!/]*) # absolute file, and not a UNC file 50*affba8c7SCy Schubert if test -z "$file_conv"; then 51*affba8c7SCy Schubert # lazily determine how to convert abs files 52*affba8c7SCy Schubert case `uname -s` in 53*affba8c7SCy Schubert MINGW*) 54*affba8c7SCy Schubert file_conv=mingw 55*affba8c7SCy Schubert ;; 56*affba8c7SCy Schubert CYGWIN*) 57*affba8c7SCy Schubert file_conv=cygwin 58*affba8c7SCy Schubert ;; 59*affba8c7SCy Schubert *) 60*affba8c7SCy Schubert file_conv=wine 61*affba8c7SCy Schubert ;; 62*affba8c7SCy Schubert esac 63*affba8c7SCy Schubert fi 64*affba8c7SCy Schubert case $file_conv/,$2, in 65*affba8c7SCy Schubert *,$file_conv,*) 66*affba8c7SCy Schubert ;; 67*affba8c7SCy Schubert mingw/*) 68*affba8c7SCy Schubert file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69*affba8c7SCy Schubert ;; 70*affba8c7SCy Schubert cygwin/*) 71*affba8c7SCy Schubert file=`cygpath -m "$file" || echo "$file"` 72*affba8c7SCy Schubert ;; 73*affba8c7SCy Schubert wine/*) 74*affba8c7SCy Schubert file=`winepath -w "$file" || echo "$file"` 75*affba8c7SCy Schubert ;; 76*affba8c7SCy Schubert esac 77*affba8c7SCy Schubert ;; 78*affba8c7SCy Schubert esac 79*affba8c7SCy Schubert} 80*affba8c7SCy Schubert 81*affba8c7SCy Schubert# func_cl_dashL linkdir 82*affba8c7SCy Schubert# Make cl look for libraries in LINKDIR 83*affba8c7SCy Schubertfunc_cl_dashL () 84*affba8c7SCy Schubert{ 85*affba8c7SCy Schubert func_file_conv "$1" 86*affba8c7SCy Schubert if test -z "$lib_path"; then 87*affba8c7SCy Schubert lib_path=$file 88*affba8c7SCy Schubert else 89*affba8c7SCy Schubert lib_path="$lib_path;$file" 90*affba8c7SCy Schubert fi 91*affba8c7SCy Schubert linker_opts="$linker_opts -LIBPATH:$file" 92*affba8c7SCy Schubert} 93*affba8c7SCy Schubert 94*affba8c7SCy Schubert# func_cl_dashl library 95*affba8c7SCy Schubert# Do a library search-path lookup for cl 96*affba8c7SCy Schubertfunc_cl_dashl () 97*affba8c7SCy Schubert{ 98*affba8c7SCy Schubert lib=$1 99*affba8c7SCy Schubert found=no 100*affba8c7SCy Schubert save_IFS=$IFS 101*affba8c7SCy Schubert IFS=';' 102*affba8c7SCy Schubert for dir in $lib_path $LIB 103*affba8c7SCy Schubert do 104*affba8c7SCy Schubert IFS=$save_IFS 105*affba8c7SCy Schubert if $shared && test -f "$dir/$lib.dll.lib"; then 106*affba8c7SCy Schubert found=yes 107*affba8c7SCy Schubert lib=$dir/$lib.dll.lib 108*affba8c7SCy Schubert break 109*affba8c7SCy Schubert fi 110*affba8c7SCy Schubert if test -f "$dir/$lib.lib"; then 111*affba8c7SCy Schubert found=yes 112*affba8c7SCy Schubert lib=$dir/$lib.lib 113*affba8c7SCy Schubert break 114*affba8c7SCy Schubert fi 115*affba8c7SCy Schubert if test -f "$dir/lib$lib.a"; then 116*affba8c7SCy Schubert found=yes 117*affba8c7SCy Schubert lib=$dir/lib$lib.a 118*affba8c7SCy Schubert break 119*affba8c7SCy Schubert fi 120*affba8c7SCy Schubert done 121*affba8c7SCy Schubert IFS=$save_IFS 122*affba8c7SCy Schubert 123*affba8c7SCy Schubert if test "$found" != yes; then 124*affba8c7SCy Schubert lib=$lib.lib 125*affba8c7SCy Schubert fi 126*affba8c7SCy Schubert} 127*affba8c7SCy Schubert 128*affba8c7SCy Schubert# func_cl_wrapper cl arg... 129*affba8c7SCy Schubert# Adjust compile command to suit cl 130*affba8c7SCy Schubertfunc_cl_wrapper () 131*affba8c7SCy Schubert{ 132*affba8c7SCy Schubert # Assume a capable shell 133*affba8c7SCy Schubert lib_path= 134*affba8c7SCy Schubert shared=: 135*affba8c7SCy Schubert linker_opts= 136*affba8c7SCy Schubert for arg 137*affba8c7SCy Schubert do 138*affba8c7SCy Schubert if test -n "$eat"; then 139*affba8c7SCy Schubert eat= 140*affba8c7SCy Schubert else 141*affba8c7SCy Schubert case $1 in 142*affba8c7SCy Schubert -o) 143*affba8c7SCy Schubert # configure might choose to run compile as 'compile cc -o foo foo.c'. 144*affba8c7SCy Schubert eat=1 145*affba8c7SCy Schubert case $2 in 146*affba8c7SCy Schubert *.o | *.[oO][bB][jJ]) 147*affba8c7SCy Schubert func_file_conv "$2" 148*affba8c7SCy Schubert set x "$@" -Fo"$file" 149*affba8c7SCy Schubert shift 150*affba8c7SCy Schubert ;; 151*affba8c7SCy Schubert *) 152*affba8c7SCy Schubert func_file_conv "$2" 153*affba8c7SCy Schubert set x "$@" -Fe"$file" 154*affba8c7SCy Schubert shift 155*affba8c7SCy Schubert ;; 156*affba8c7SCy Schubert esac 157*affba8c7SCy Schubert ;; 158*affba8c7SCy Schubert -I) 159*affba8c7SCy Schubert eat=1 160*affba8c7SCy Schubert func_file_conv "$2" mingw 161*affba8c7SCy Schubert set x "$@" -I"$file" 162*affba8c7SCy Schubert shift 163*affba8c7SCy Schubert ;; 164*affba8c7SCy Schubert -I*) 165*affba8c7SCy Schubert func_file_conv "${1#-I}" mingw 166*affba8c7SCy Schubert set x "$@" -I"$file" 167*affba8c7SCy Schubert shift 168*affba8c7SCy Schubert ;; 169*affba8c7SCy Schubert -l) 170*affba8c7SCy Schubert eat=1 171*affba8c7SCy Schubert func_cl_dashl "$2" 172*affba8c7SCy Schubert set x "$@" "$lib" 173*affba8c7SCy Schubert shift 174*affba8c7SCy Schubert ;; 175*affba8c7SCy Schubert -l*) 176*affba8c7SCy Schubert func_cl_dashl "${1#-l}" 177*affba8c7SCy Schubert set x "$@" "$lib" 178*affba8c7SCy Schubert shift 179*affba8c7SCy Schubert ;; 180*affba8c7SCy Schubert -L) 181*affba8c7SCy Schubert eat=1 182*affba8c7SCy Schubert func_cl_dashL "$2" 183*affba8c7SCy Schubert ;; 184*affba8c7SCy Schubert -L*) 185*affba8c7SCy Schubert func_cl_dashL "${1#-L}" 186*affba8c7SCy Schubert ;; 187*affba8c7SCy Schubert -static) 188*affba8c7SCy Schubert shared=false 189*affba8c7SCy Schubert ;; 190*affba8c7SCy Schubert -Wl,*) 191*affba8c7SCy Schubert arg=${1#-Wl,} 192*affba8c7SCy Schubert save_ifs="$IFS"; IFS=',' 193*affba8c7SCy Schubert for flag in $arg; do 194*affba8c7SCy Schubert IFS="$save_ifs" 195*affba8c7SCy Schubert linker_opts="$linker_opts $flag" 196*affba8c7SCy Schubert done 197*affba8c7SCy Schubert IFS="$save_ifs" 198*affba8c7SCy Schubert ;; 199*affba8c7SCy Schubert -Xlinker) 200*affba8c7SCy Schubert eat=1 201*affba8c7SCy Schubert linker_opts="$linker_opts $2" 202*affba8c7SCy Schubert ;; 203*affba8c7SCy Schubert -*) 204*affba8c7SCy Schubert set x "$@" "$1" 205*affba8c7SCy Schubert shift 206*affba8c7SCy Schubert ;; 207*affba8c7SCy Schubert *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208*affba8c7SCy Schubert func_file_conv "$1" 209*affba8c7SCy Schubert set x "$@" -Tp"$file" 210*affba8c7SCy Schubert shift 211*affba8c7SCy Schubert ;; 212*affba8c7SCy Schubert *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213*affba8c7SCy Schubert func_file_conv "$1" mingw 214*affba8c7SCy Schubert set x "$@" "$file" 215*affba8c7SCy Schubert shift 216*affba8c7SCy Schubert ;; 217*affba8c7SCy Schubert *) 218*affba8c7SCy Schubert set x "$@" "$1" 219*affba8c7SCy Schubert shift 220*affba8c7SCy Schubert ;; 221*affba8c7SCy Schubert esac 222*affba8c7SCy Schubert fi 223*affba8c7SCy Schubert shift 224*affba8c7SCy Schubert done 225*affba8c7SCy Schubert if test -n "$linker_opts"; then 226*affba8c7SCy Schubert linker_opts="-link$linker_opts" 227*affba8c7SCy Schubert fi 228*affba8c7SCy Schubert exec "$@" $linker_opts 229*affba8c7SCy Schubert exit 1 230*affba8c7SCy Schubert} 231*affba8c7SCy Schubert 232*affba8c7SCy Schuberteat= 233*affba8c7SCy Schubert 234*affba8c7SCy Schubertcase $1 in 235*affba8c7SCy Schubert '') 236*affba8c7SCy Schubert echo "$0: No command. Try '$0 --help' for more information." 1>&2 237*affba8c7SCy Schubert exit 1; 238*affba8c7SCy Schubert ;; 239*affba8c7SCy Schubert -h | --h*) 240*affba8c7SCy Schubert cat <<\EOF 241*affba8c7SCy SchubertUsage: compile [--help] [--version] PROGRAM [ARGS] 242*affba8c7SCy Schubert 243*affba8c7SCy SchubertWrapper for compilers which do not understand '-c -o'. 244*affba8c7SCy SchubertRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 245*affba8c7SCy Schubertarguments, and rename the output as expected. 246*affba8c7SCy Schubert 247*affba8c7SCy SchubertIf you are trying to build a whole package this is not the 248*affba8c7SCy Schubertright script to run: please start by reading the file 'INSTALL'. 249*affba8c7SCy Schubert 250*affba8c7SCy SchubertReport bugs to <bug-automake@gnu.org>. 251*affba8c7SCy SchubertEOF 252*affba8c7SCy Schubert exit $? 253*affba8c7SCy Schubert ;; 254*affba8c7SCy Schubert -v | --v*) 255*affba8c7SCy Schubert echo "compile $scriptversion" 256*affba8c7SCy Schubert exit $? 257*affba8c7SCy Schubert ;; 258*affba8c7SCy Schubert cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 259*affba8c7SCy Schubert func_cl_wrapper "$@" # Doesn't return... 260*affba8c7SCy Schubert ;; 261*affba8c7SCy Schubertesac 262*affba8c7SCy Schubert 263*affba8c7SCy Schubertofile= 264*affba8c7SCy Schubertcfile= 265*affba8c7SCy Schubert 266*affba8c7SCy Schubertfor arg 267*affba8c7SCy Schubertdo 268*affba8c7SCy Schubert if test -n "$eat"; then 269*affba8c7SCy Schubert eat= 270*affba8c7SCy Schubert else 271*affba8c7SCy Schubert case $1 in 272*affba8c7SCy Schubert -o) 273*affba8c7SCy Schubert # configure might choose to run compile as 'compile cc -o foo foo.c'. 274*affba8c7SCy Schubert # So we strip '-o arg' only if arg is an object. 275*affba8c7SCy Schubert eat=1 276*affba8c7SCy Schubert case $2 in 277*affba8c7SCy Schubert *.o | *.obj) 278*affba8c7SCy Schubert ofile=$2 279*affba8c7SCy Schubert ;; 280*affba8c7SCy Schubert *) 281*affba8c7SCy Schubert set x "$@" -o "$2" 282*affba8c7SCy Schubert shift 283*affba8c7SCy Schubert ;; 284*affba8c7SCy Schubert esac 285*affba8c7SCy Schubert ;; 286*affba8c7SCy Schubert *.c) 287*affba8c7SCy Schubert cfile=$1 288*affba8c7SCy Schubert set x "$@" "$1" 289*affba8c7SCy Schubert shift 290*affba8c7SCy Schubert ;; 291*affba8c7SCy Schubert *) 292*affba8c7SCy Schubert set x "$@" "$1" 293*affba8c7SCy Schubert shift 294*affba8c7SCy Schubert ;; 295*affba8c7SCy Schubert esac 296*affba8c7SCy Schubert fi 297*affba8c7SCy Schubert shift 298*affba8c7SCy Schubertdone 299*affba8c7SCy Schubert 300*affba8c7SCy Schubertif test -z "$ofile" || test -z "$cfile"; then 301*affba8c7SCy Schubert # If no '-o' option was seen then we might have been invoked from a 302*affba8c7SCy Schubert # pattern rule where we don't need one. That is ok -- this is a 303*affba8c7SCy Schubert # normal compilation that the losing compiler can handle. If no 304*affba8c7SCy Schubert # '.c' file was seen then we are probably linking. That is also 305*affba8c7SCy Schubert # ok. 306*affba8c7SCy Schubert exec "$@" 307*affba8c7SCy Schubertfi 308*affba8c7SCy Schubert 309*affba8c7SCy Schubert# Name of file we expect compiler to create. 310*affba8c7SCy Schubertcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 311*affba8c7SCy Schubert 312*affba8c7SCy Schubert# Create the lock directory. 313*affba8c7SCy Schubert# Note: use '[/\\:.-]' here to ensure that we don't use the same name 314*affba8c7SCy Schubert# that we are using for the .o file. Also, base the name on the expected 315*affba8c7SCy Schubert# object file name, since that is what matters with a parallel build. 316*affba8c7SCy Schubertlockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 317*affba8c7SCy Schubertwhile true; do 318*affba8c7SCy Schubert if mkdir "$lockdir" >/dev/null 2>&1; then 319*affba8c7SCy Schubert break 320*affba8c7SCy Schubert fi 321*affba8c7SCy Schubert sleep 1 322*affba8c7SCy Schubertdone 323*affba8c7SCy Schubert# FIXME: race condition here if user kills between mkdir and trap. 324*affba8c7SCy Schuberttrap "rmdir '$lockdir'; exit 1" 1 2 15 325*affba8c7SCy Schubert 326*affba8c7SCy Schubert# Run the compile. 327*affba8c7SCy Schubert"$@" 328*affba8c7SCy Schubertret=$? 329*affba8c7SCy Schubert 330*affba8c7SCy Schubertif test -f "$cofile"; then 331*affba8c7SCy Schubert test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 332*affba8c7SCy Schubertelif test -f "${cofile}bj"; then 333*affba8c7SCy Schubert test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 334*affba8c7SCy Schubertfi 335*affba8c7SCy Schubert 336*affba8c7SCy Schubertrmdir "$lockdir" 337*affba8c7SCy Schubertexit $ret 338*affba8c7SCy Schubert 339*affba8c7SCy Schubert# Local Variables: 340*affba8c7SCy Schubert# mode: shell-script 341*affba8c7SCy Schubert# sh-indentation: 2 342*affba8c7SCy Schubert# eval: (add-hook 'write-file-hooks 'time-stamp) 343*affba8c7SCy Schubert# time-stamp-start: "scriptversion=" 344*affba8c7SCy Schubert# time-stamp-format: "%:y-%02m-%02d.%02H" 345*affba8c7SCy Schubert# time-stamp-time-zone: "UTC" 346*affba8c7SCy Schubert# time-stamp-end: "; # UTC" 347*affba8c7SCy Schubert# End: 348