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