compile revision 414bd68f
1414bd68fSmrg#! /bin/sh 2414bd68fSmrg# Wrapper for compilers which do not understand '-c -o'. 3414bd68fSmrg 4414bd68fSmrgscriptversion=2012-10-14.11; # UTC 5414bd68fSmrg 6414bd68fSmrg# Copyright (C) 1999-2014 Free Software Foundation, Inc. 7414bd68fSmrg# Written by Tom Tromey <tromey@cygnus.com>. 8414bd68fSmrg# 9414bd68fSmrg# This program is free software; you can redistribute it and/or modify 10414bd68fSmrg# it under the terms of the GNU General Public License as published by 11414bd68fSmrg# the Free Software Foundation; either version 2, or (at your option) 12414bd68fSmrg# any later version. 13414bd68fSmrg# 14414bd68fSmrg# This program is distributed in the hope that it will be useful, 15414bd68fSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 16414bd68fSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17414bd68fSmrg# GNU General Public License for more details. 18414bd68fSmrg# 19414bd68fSmrg# You should have received a copy of the GNU General Public License 20414bd68fSmrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 21414bd68fSmrg 22414bd68fSmrg# As a special exception to the GNU General Public License, if you 23414bd68fSmrg# distribute this file as part of a program that contains a 24414bd68fSmrg# configuration script generated by Autoconf, you may include it under 25414bd68fSmrg# the same distribution terms that you use for the rest of that program. 26414bd68fSmrg 27414bd68fSmrg# This file is maintained in Automake, please report 28414bd68fSmrg# bugs to <bug-automake@gnu.org> or send patches to 29414bd68fSmrg# <automake-patches@gnu.org>. 30414bd68fSmrg 31414bd68fSmrgnl=' 32414bd68fSmrg' 33414bd68fSmrg 34414bd68fSmrg# We need space, tab and new line, in precisely that order. Quoting is 35414bd68fSmrg# there to prevent tools from complaining about whitespace usage. 36414bd68fSmrgIFS=" "" $nl" 37414bd68fSmrg 38414bd68fSmrgfile_conv= 39414bd68fSmrg 40414bd68fSmrg# func_file_conv build_file lazy 41414bd68fSmrg# Convert a $build file to $host form and store it in $file 42414bd68fSmrg# Currently only supports Windows hosts. If the determined conversion 43414bd68fSmrg# type is listed in (the comma separated) LAZY, no conversion will 44414bd68fSmrg# take place. 45414bd68fSmrgfunc_file_conv () 46414bd68fSmrg{ 47414bd68fSmrg file=$1 48414bd68fSmrg case $file in 49414bd68fSmrg / | /[!/]*) # absolute file, and not a UNC file 50414bd68fSmrg if test -z "$file_conv"; then 51414bd68fSmrg # lazily determine how to convert abs files 52414bd68fSmrg case `uname -s` in 53414bd68fSmrg MINGW*) 54414bd68fSmrg file_conv=mingw 55414bd68fSmrg ;; 56414bd68fSmrg CYGWIN*) 57414bd68fSmrg file_conv=cygwin 58414bd68fSmrg ;; 59414bd68fSmrg *) 60414bd68fSmrg file_conv=wine 61414bd68fSmrg ;; 62414bd68fSmrg esac 63414bd68fSmrg fi 64414bd68fSmrg case $file_conv/,$2, in 65414bd68fSmrg *,$file_conv,*) 66414bd68fSmrg ;; 67414bd68fSmrg mingw/*) 68414bd68fSmrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69414bd68fSmrg ;; 70414bd68fSmrg cygwin/*) 71414bd68fSmrg file=`cygpath -m "$file" || echo "$file"` 72414bd68fSmrg ;; 73414bd68fSmrg wine/*) 74414bd68fSmrg file=`winepath -w "$file" || echo "$file"` 75414bd68fSmrg ;; 76414bd68fSmrg esac 77414bd68fSmrg ;; 78414bd68fSmrg esac 79414bd68fSmrg} 80414bd68fSmrg 81414bd68fSmrg# func_cl_dashL linkdir 82414bd68fSmrg# Make cl look for libraries in LINKDIR 83414bd68fSmrgfunc_cl_dashL () 84414bd68fSmrg{ 85414bd68fSmrg func_file_conv "$1" 86414bd68fSmrg if test -z "$lib_path"; then 87414bd68fSmrg lib_path=$file 88414bd68fSmrg else 89414bd68fSmrg lib_path="$lib_path;$file" 90414bd68fSmrg fi 91414bd68fSmrg linker_opts="$linker_opts -LIBPATH:$file" 92414bd68fSmrg} 93414bd68fSmrg 94414bd68fSmrg# func_cl_dashl library 95414bd68fSmrg# Do a library search-path lookup for cl 96414bd68fSmrgfunc_cl_dashl () 97414bd68fSmrg{ 98414bd68fSmrg lib=$1 99414bd68fSmrg found=no 100414bd68fSmrg save_IFS=$IFS 101414bd68fSmrg IFS=';' 102414bd68fSmrg for dir in $lib_path $LIB 103414bd68fSmrg do 104414bd68fSmrg IFS=$save_IFS 105414bd68fSmrg if $shared && test -f "$dir/$lib.dll.lib"; then 106414bd68fSmrg found=yes 107414bd68fSmrg lib=$dir/$lib.dll.lib 108414bd68fSmrg break 109414bd68fSmrg fi 110414bd68fSmrg if test -f "$dir/$lib.lib"; then 111414bd68fSmrg found=yes 112414bd68fSmrg lib=$dir/$lib.lib 113414bd68fSmrg break 114414bd68fSmrg fi 115414bd68fSmrg if test -f "$dir/lib$lib.a"; then 116414bd68fSmrg found=yes 117414bd68fSmrg lib=$dir/lib$lib.a 118414bd68fSmrg break 119414bd68fSmrg fi 120414bd68fSmrg done 121414bd68fSmrg IFS=$save_IFS 122414bd68fSmrg 123414bd68fSmrg if test "$found" != yes; then 124414bd68fSmrg lib=$lib.lib 125414bd68fSmrg fi 126414bd68fSmrg} 127414bd68fSmrg 128414bd68fSmrg# func_cl_wrapper cl arg... 129414bd68fSmrg# Adjust compile command to suit cl 130414bd68fSmrgfunc_cl_wrapper () 131414bd68fSmrg{ 132414bd68fSmrg # Assume a capable shell 133414bd68fSmrg lib_path= 134414bd68fSmrg shared=: 135414bd68fSmrg linker_opts= 136414bd68fSmrg for arg 137414bd68fSmrg do 138414bd68fSmrg if test -n "$eat"; then 139414bd68fSmrg eat= 140414bd68fSmrg else 141414bd68fSmrg case $1 in 142414bd68fSmrg -o) 143414bd68fSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 144414bd68fSmrg eat=1 145414bd68fSmrg case $2 in 146414bd68fSmrg *.o | *.[oO][bB][jJ]) 147414bd68fSmrg func_file_conv "$2" 148414bd68fSmrg set x "$@" -Fo"$file" 149414bd68fSmrg shift 150414bd68fSmrg ;; 151414bd68fSmrg *) 152414bd68fSmrg func_file_conv "$2" 153414bd68fSmrg set x "$@" -Fe"$file" 154414bd68fSmrg shift 155414bd68fSmrg ;; 156414bd68fSmrg esac 157414bd68fSmrg ;; 158414bd68fSmrg -I) 159414bd68fSmrg eat=1 160414bd68fSmrg func_file_conv "$2" mingw 161414bd68fSmrg set x "$@" -I"$file" 162414bd68fSmrg shift 163414bd68fSmrg ;; 164414bd68fSmrg -I*) 165414bd68fSmrg func_file_conv "${1#-I}" mingw 166414bd68fSmrg set x "$@" -I"$file" 167414bd68fSmrg shift 168414bd68fSmrg ;; 169414bd68fSmrg -l) 170414bd68fSmrg eat=1 171414bd68fSmrg func_cl_dashl "$2" 172414bd68fSmrg set x "$@" "$lib" 173414bd68fSmrg shift 174414bd68fSmrg ;; 175414bd68fSmrg -l*) 176414bd68fSmrg func_cl_dashl "${1#-l}" 177414bd68fSmrg set x "$@" "$lib" 178414bd68fSmrg shift 179414bd68fSmrg ;; 180414bd68fSmrg -L) 181414bd68fSmrg eat=1 182414bd68fSmrg func_cl_dashL "$2" 183414bd68fSmrg ;; 184414bd68fSmrg -L*) 185414bd68fSmrg func_cl_dashL "${1#-L}" 186414bd68fSmrg ;; 187414bd68fSmrg -static) 188414bd68fSmrg shared=false 189414bd68fSmrg ;; 190414bd68fSmrg -Wl,*) 191414bd68fSmrg arg=${1#-Wl,} 192414bd68fSmrg save_ifs="$IFS"; IFS=',' 193414bd68fSmrg for flag in $arg; do 194414bd68fSmrg IFS="$save_ifs" 195414bd68fSmrg linker_opts="$linker_opts $flag" 196414bd68fSmrg done 197414bd68fSmrg IFS="$save_ifs" 198414bd68fSmrg ;; 199414bd68fSmrg -Xlinker) 200414bd68fSmrg eat=1 201414bd68fSmrg linker_opts="$linker_opts $2" 202414bd68fSmrg ;; 203414bd68fSmrg -*) 204414bd68fSmrg set x "$@" "$1" 205414bd68fSmrg shift 206414bd68fSmrg ;; 207414bd68fSmrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208414bd68fSmrg func_file_conv "$1" 209414bd68fSmrg set x "$@" -Tp"$file" 210414bd68fSmrg shift 211414bd68fSmrg ;; 212414bd68fSmrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213414bd68fSmrg func_file_conv "$1" mingw 214414bd68fSmrg set x "$@" "$file" 215414bd68fSmrg shift 216414bd68fSmrg ;; 217414bd68fSmrg *) 218414bd68fSmrg set x "$@" "$1" 219414bd68fSmrg shift 220414bd68fSmrg ;; 221414bd68fSmrg esac 222414bd68fSmrg fi 223414bd68fSmrg shift 224414bd68fSmrg done 225414bd68fSmrg if test -n "$linker_opts"; then 226414bd68fSmrg linker_opts="-link$linker_opts" 227414bd68fSmrg fi 228414bd68fSmrg exec "$@" $linker_opts 229414bd68fSmrg exit 1 230414bd68fSmrg} 231414bd68fSmrg 232414bd68fSmrgeat= 233414bd68fSmrg 234414bd68fSmrgcase $1 in 235414bd68fSmrg '') 236414bd68fSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 237414bd68fSmrg exit 1; 238414bd68fSmrg ;; 239414bd68fSmrg -h | --h*) 240414bd68fSmrg cat <<\EOF 241414bd68fSmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 242414bd68fSmrg 243414bd68fSmrgWrapper for compilers which do not understand '-c -o'. 244414bd68fSmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 245414bd68fSmrgarguments, and rename the output as expected. 246414bd68fSmrg 247414bd68fSmrgIf you are trying to build a whole package this is not the 248414bd68fSmrgright script to run: please start by reading the file 'INSTALL'. 249414bd68fSmrg 250414bd68fSmrgReport bugs to <bug-automake@gnu.org>. 251414bd68fSmrgEOF 252414bd68fSmrg exit $? 253414bd68fSmrg ;; 254414bd68fSmrg -v | --v*) 255414bd68fSmrg echo "compile $scriptversion" 256414bd68fSmrg exit $? 257414bd68fSmrg ;; 258414bd68fSmrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 259414bd68fSmrg func_cl_wrapper "$@" # Doesn't return... 260414bd68fSmrg ;; 261414bd68fSmrgesac 262414bd68fSmrg 263414bd68fSmrgofile= 264414bd68fSmrgcfile= 265414bd68fSmrg 266414bd68fSmrgfor arg 267414bd68fSmrgdo 268414bd68fSmrg if test -n "$eat"; then 269414bd68fSmrg eat= 270414bd68fSmrg else 271414bd68fSmrg case $1 in 272414bd68fSmrg -o) 273414bd68fSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 274414bd68fSmrg # So we strip '-o arg' only if arg is an object. 275414bd68fSmrg eat=1 276414bd68fSmrg case $2 in 277414bd68fSmrg *.o | *.obj) 278414bd68fSmrg ofile=$2 279414bd68fSmrg ;; 280414bd68fSmrg *) 281414bd68fSmrg set x "$@" -o "$2" 282414bd68fSmrg shift 283414bd68fSmrg ;; 284414bd68fSmrg esac 285414bd68fSmrg ;; 286414bd68fSmrg *.c) 287414bd68fSmrg cfile=$1 288414bd68fSmrg set x "$@" "$1" 289414bd68fSmrg shift 290414bd68fSmrg ;; 291414bd68fSmrg *) 292414bd68fSmrg set x "$@" "$1" 293414bd68fSmrg shift 294414bd68fSmrg ;; 295414bd68fSmrg esac 296414bd68fSmrg fi 297414bd68fSmrg shift 298414bd68fSmrgdone 299414bd68fSmrg 300414bd68fSmrgif test -z "$ofile" || test -z "$cfile"; then 301414bd68fSmrg # If no '-o' option was seen then we might have been invoked from a 302414bd68fSmrg # pattern rule where we don't need one. That is ok -- this is a 303414bd68fSmrg # normal compilation that the losing compiler can handle. If no 304414bd68fSmrg # '.c' file was seen then we are probably linking. That is also 305414bd68fSmrg # ok. 306414bd68fSmrg exec "$@" 307414bd68fSmrgfi 308414bd68fSmrg 309414bd68fSmrg# Name of file we expect compiler to create. 310414bd68fSmrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 311414bd68fSmrg 312414bd68fSmrg# Create the lock directory. 313414bd68fSmrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 314414bd68fSmrg# that we are using for the .o file. Also, base the name on the expected 315414bd68fSmrg# object file name, since that is what matters with a parallel build. 316414bd68fSmrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 317414bd68fSmrgwhile true; do 318414bd68fSmrg if mkdir "$lockdir" >/dev/null 2>&1; then 319414bd68fSmrg break 320414bd68fSmrg fi 321414bd68fSmrg sleep 1 322414bd68fSmrgdone 323414bd68fSmrg# FIXME: race condition here if user kills between mkdir and trap. 324414bd68fSmrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 325414bd68fSmrg 326414bd68fSmrg# Run the compile. 327414bd68fSmrg"$@" 328414bd68fSmrgret=$? 329414bd68fSmrg 330414bd68fSmrgif test -f "$cofile"; then 331414bd68fSmrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 332414bd68fSmrgelif test -f "${cofile}bj"; then 333414bd68fSmrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 334414bd68fSmrgfi 335414bd68fSmrg 336414bd68fSmrgrmdir "$lockdir" 337414bd68fSmrgexit $ret 338414bd68fSmrg 339414bd68fSmrg# Local Variables: 340414bd68fSmrg# mode: shell-script 341414bd68fSmrg# sh-indentation: 2 342414bd68fSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 343414bd68fSmrg# time-stamp-start: "scriptversion=" 344414bd68fSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 345414bd68fSmrg# time-stamp-time-zone: "UTC" 346414bd68fSmrg# time-stamp-end: "; # UTC" 347414bd68fSmrg# End: 348