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