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