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