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