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