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