136e956c5Smrg#! /bin/sh 236e956c5Smrg# Wrapper for compilers which do not understand '-c -o'. 336e956c5Smrg 436e956c5Smrgscriptversion=2012-10-14.11; # UTC 536e956c5Smrg 636e956c5Smrg# Copyright (C) 1999-2014 Free Software Foundation, Inc. 736e956c5Smrg# Written by Tom Tromey <tromey@cygnus.com>. 836e956c5Smrg# 936e956c5Smrg# This program is free software; you can redistribute it and/or modify 1036e956c5Smrg# it under the terms of the GNU General Public License as published by 1136e956c5Smrg# the Free Software Foundation; either version 2, or (at your option) 1236e956c5Smrg# any later version. 1336e956c5Smrg# 1436e956c5Smrg# This program is distributed in the hope that it will be useful, 1536e956c5Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1636e956c5Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1736e956c5Smrg# GNU General Public License for more details. 1836e956c5Smrg# 1936e956c5Smrg# You should have received a copy of the GNU General Public License 2036e956c5Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 2136e956c5Smrg 2236e956c5Smrg# As a special exception to the GNU General Public License, if you 2336e956c5Smrg# distribute this file as part of a program that contains a 2436e956c5Smrg# configuration script generated by Autoconf, you may include it under 2536e956c5Smrg# the same distribution terms that you use for the rest of that program. 2636e956c5Smrg 2736e956c5Smrg# This file is maintained in Automake, please report 2836e956c5Smrg# bugs to <bug-automake@gnu.org> or send patches to 2936e956c5Smrg# <automake-patches@gnu.org>. 3036e956c5Smrg 3136e956c5Smrgnl=' 3236e956c5Smrg' 3336e956c5Smrg 3436e956c5Smrg# We need space, tab and new line, in precisely that order. Quoting is 3536e956c5Smrg# there to prevent tools from complaining about whitespace usage. 3636e956c5SmrgIFS=" "" $nl" 3736e956c5Smrg 3836e956c5Smrgfile_conv= 3936e956c5Smrg 4036e956c5Smrg# func_file_conv build_file lazy 4136e956c5Smrg# Convert a $build file to $host form and store it in $file 4236e956c5Smrg# Currently only supports Windows hosts. If the determined conversion 4336e956c5Smrg# type is listed in (the comma separated) LAZY, no conversion will 4436e956c5Smrg# take place. 4536e956c5Smrgfunc_file_conv () 4636e956c5Smrg{ 4736e956c5Smrg file=$1 4836e956c5Smrg case $file in 4936e956c5Smrg / | /[!/]*) # absolute file, and not a UNC file 5036e956c5Smrg if test -z "$file_conv"; then 5136e956c5Smrg # lazily determine how to convert abs files 5236e956c5Smrg case `uname -s` in 5336e956c5Smrg MINGW*) 5436e956c5Smrg file_conv=mingw 5536e956c5Smrg ;; 5636e956c5Smrg CYGWIN*) 5736e956c5Smrg file_conv=cygwin 5836e956c5Smrg ;; 5936e956c5Smrg *) 6036e956c5Smrg file_conv=wine 6136e956c5Smrg ;; 6236e956c5Smrg esac 6336e956c5Smrg fi 6436e956c5Smrg case $file_conv/,$2, in 6536e956c5Smrg *,$file_conv,*) 6636e956c5Smrg ;; 6736e956c5Smrg mingw/*) 6836e956c5Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6936e956c5Smrg ;; 7036e956c5Smrg cygwin/*) 7136e956c5Smrg file=`cygpath -m "$file" || echo "$file"` 7236e956c5Smrg ;; 7336e956c5Smrg wine/*) 7436e956c5Smrg file=`winepath -w "$file" || echo "$file"` 7536e956c5Smrg ;; 7636e956c5Smrg esac 7736e956c5Smrg ;; 7836e956c5Smrg esac 7936e956c5Smrg} 8036e956c5Smrg 8136e956c5Smrg# func_cl_dashL linkdir 8236e956c5Smrg# Make cl look for libraries in LINKDIR 8336e956c5Smrgfunc_cl_dashL () 8436e956c5Smrg{ 8536e956c5Smrg func_file_conv "$1" 8636e956c5Smrg if test -z "$lib_path"; then 8736e956c5Smrg lib_path=$file 8836e956c5Smrg else 8936e956c5Smrg lib_path="$lib_path;$file" 9036e956c5Smrg fi 9136e956c5Smrg linker_opts="$linker_opts -LIBPATH:$file" 9236e956c5Smrg} 9336e956c5Smrg 9436e956c5Smrg# func_cl_dashl library 9536e956c5Smrg# Do a library search-path lookup for cl 9636e956c5Smrgfunc_cl_dashl () 9736e956c5Smrg{ 9836e956c5Smrg lib=$1 9936e956c5Smrg found=no 10036e956c5Smrg save_IFS=$IFS 10136e956c5Smrg IFS=';' 10236e956c5Smrg for dir in $lib_path $LIB 10336e956c5Smrg do 10436e956c5Smrg IFS=$save_IFS 10536e956c5Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 10636e956c5Smrg found=yes 10736e956c5Smrg lib=$dir/$lib.dll.lib 10836e956c5Smrg break 10936e956c5Smrg fi 11036e956c5Smrg if test -f "$dir/$lib.lib"; then 11136e956c5Smrg found=yes 11236e956c5Smrg lib=$dir/$lib.lib 11336e956c5Smrg break 11436e956c5Smrg fi 11536e956c5Smrg if test -f "$dir/lib$lib.a"; then 11636e956c5Smrg found=yes 11736e956c5Smrg lib=$dir/lib$lib.a 11836e956c5Smrg break 11936e956c5Smrg fi 12036e956c5Smrg done 12136e956c5Smrg IFS=$save_IFS 12236e956c5Smrg 12336e956c5Smrg if test "$found" != yes; then 12436e956c5Smrg lib=$lib.lib 12536e956c5Smrg fi 12636e956c5Smrg} 12736e956c5Smrg 12836e956c5Smrg# func_cl_wrapper cl arg... 12936e956c5Smrg# Adjust compile command to suit cl 13036e956c5Smrgfunc_cl_wrapper () 13136e956c5Smrg{ 13236e956c5Smrg # Assume a capable shell 13336e956c5Smrg lib_path= 13436e956c5Smrg shared=: 13536e956c5Smrg linker_opts= 13636e956c5Smrg for arg 13736e956c5Smrg do 13836e956c5Smrg if test -n "$eat"; then 13936e956c5Smrg eat= 14036e956c5Smrg else 14136e956c5Smrg case $1 in 14236e956c5Smrg -o) 14336e956c5Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 14436e956c5Smrg eat=1 14536e956c5Smrg case $2 in 14636e956c5Smrg *.o | *.[oO][bB][jJ]) 14736e956c5Smrg func_file_conv "$2" 14836e956c5Smrg set x "$@" -Fo"$file" 14936e956c5Smrg shift 15036e956c5Smrg ;; 15136e956c5Smrg *) 15236e956c5Smrg func_file_conv "$2" 15336e956c5Smrg set x "$@" -Fe"$file" 15436e956c5Smrg shift 15536e956c5Smrg ;; 15636e956c5Smrg esac 15736e956c5Smrg ;; 15836e956c5Smrg -I) 15936e956c5Smrg eat=1 16036e956c5Smrg func_file_conv "$2" mingw 16136e956c5Smrg set x "$@" -I"$file" 16236e956c5Smrg shift 16336e956c5Smrg ;; 16436e956c5Smrg -I*) 16536e956c5Smrg func_file_conv "${1#-I}" mingw 16636e956c5Smrg set x "$@" -I"$file" 16736e956c5Smrg shift 16836e956c5Smrg ;; 16936e956c5Smrg -l) 17036e956c5Smrg eat=1 17136e956c5Smrg func_cl_dashl "$2" 17236e956c5Smrg set x "$@" "$lib" 17336e956c5Smrg shift 17436e956c5Smrg ;; 17536e956c5Smrg -l*) 17636e956c5Smrg func_cl_dashl "${1#-l}" 17736e956c5Smrg set x "$@" "$lib" 17836e956c5Smrg shift 17936e956c5Smrg ;; 18036e956c5Smrg -L) 18136e956c5Smrg eat=1 18236e956c5Smrg func_cl_dashL "$2" 18336e956c5Smrg ;; 18436e956c5Smrg -L*) 18536e956c5Smrg func_cl_dashL "${1#-L}" 18636e956c5Smrg ;; 18736e956c5Smrg -static) 18836e956c5Smrg shared=false 18936e956c5Smrg ;; 19036e956c5Smrg -Wl,*) 19136e956c5Smrg arg=${1#-Wl,} 19236e956c5Smrg save_ifs="$IFS"; IFS=',' 19336e956c5Smrg for flag in $arg; do 19436e956c5Smrg IFS="$save_ifs" 19536e956c5Smrg linker_opts="$linker_opts $flag" 19636e956c5Smrg done 19736e956c5Smrg IFS="$save_ifs" 19836e956c5Smrg ;; 19936e956c5Smrg -Xlinker) 20036e956c5Smrg eat=1 20136e956c5Smrg linker_opts="$linker_opts $2" 20236e956c5Smrg ;; 20336e956c5Smrg -*) 20436e956c5Smrg set x "$@" "$1" 20536e956c5Smrg shift 20636e956c5Smrg ;; 20736e956c5Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20836e956c5Smrg func_file_conv "$1" 20936e956c5Smrg set x "$@" -Tp"$file" 21036e956c5Smrg shift 21136e956c5Smrg ;; 21236e956c5Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21336e956c5Smrg func_file_conv "$1" mingw 21436e956c5Smrg set x "$@" "$file" 21536e956c5Smrg shift 21636e956c5Smrg ;; 21736e956c5Smrg *) 21836e956c5Smrg set x "$@" "$1" 21936e956c5Smrg shift 22036e956c5Smrg ;; 22136e956c5Smrg esac 22236e956c5Smrg fi 22336e956c5Smrg shift 22436e956c5Smrg done 22536e956c5Smrg if test -n "$linker_opts"; then 22636e956c5Smrg linker_opts="-link$linker_opts" 22736e956c5Smrg fi 22836e956c5Smrg exec "$@" $linker_opts 22936e956c5Smrg exit 1 23036e956c5Smrg} 23136e956c5Smrg 23236e956c5Smrgeat= 23336e956c5Smrg 23436e956c5Smrgcase $1 in 23536e956c5Smrg '') 23636e956c5Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 23736e956c5Smrg exit 1; 23836e956c5Smrg ;; 23936e956c5Smrg -h | --h*) 24036e956c5Smrg cat <<\EOF 24136e956c5SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 24236e956c5Smrg 24336e956c5SmrgWrapper for compilers which do not understand '-c -o'. 24436e956c5SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24536e956c5Smrgarguments, and rename the output as expected. 24636e956c5Smrg 24736e956c5SmrgIf you are trying to build a whole package this is not the 24836e956c5Smrgright script to run: please start by reading the file 'INSTALL'. 24936e956c5Smrg 25036e956c5SmrgReport bugs to <bug-automake@gnu.org>. 25136e956c5SmrgEOF 25236e956c5Smrg exit $? 25336e956c5Smrg ;; 25436e956c5Smrg -v | --v*) 25536e956c5Smrg echo "compile $scriptversion" 25636e956c5Smrg exit $? 25736e956c5Smrg ;; 25836e956c5Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 25936e956c5Smrg func_cl_wrapper "$@" # Doesn't return... 26036e956c5Smrg ;; 26136e956c5Smrgesac 26236e956c5Smrg 26336e956c5Smrgofile= 26436e956c5Smrgcfile= 26536e956c5Smrg 26636e956c5Smrgfor arg 26736e956c5Smrgdo 26836e956c5Smrg if test -n "$eat"; then 26936e956c5Smrg eat= 27036e956c5Smrg else 27136e956c5Smrg case $1 in 27236e956c5Smrg -o) 27336e956c5Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 27436e956c5Smrg # So we strip '-o arg' only if arg is an object. 27536e956c5Smrg eat=1 27636e956c5Smrg case $2 in 27736e956c5Smrg *.o | *.obj) 27836e956c5Smrg ofile=$2 27936e956c5Smrg ;; 28036e956c5Smrg *) 28136e956c5Smrg set x "$@" -o "$2" 28236e956c5Smrg shift 28336e956c5Smrg ;; 28436e956c5Smrg esac 28536e956c5Smrg ;; 28636e956c5Smrg *.c) 28736e956c5Smrg cfile=$1 28836e956c5Smrg set x "$@" "$1" 28936e956c5Smrg shift 29036e956c5Smrg ;; 29136e956c5Smrg *) 29236e956c5Smrg set x "$@" "$1" 29336e956c5Smrg shift 29436e956c5Smrg ;; 29536e956c5Smrg esac 29636e956c5Smrg fi 29736e956c5Smrg shift 29836e956c5Smrgdone 29936e956c5Smrg 30036e956c5Smrgif test -z "$ofile" || test -z "$cfile"; then 30136e956c5Smrg # If no '-o' option was seen then we might have been invoked from a 30236e956c5Smrg # pattern rule where we don't need one. That is ok -- this is a 30336e956c5Smrg # normal compilation that the losing compiler can handle. If no 30436e956c5Smrg # '.c' file was seen then we are probably linking. That is also 30536e956c5Smrg # ok. 30636e956c5Smrg exec "$@" 30736e956c5Smrgfi 30836e956c5Smrg 30936e956c5Smrg# Name of file we expect compiler to create. 31036e956c5Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31136e956c5Smrg 31236e956c5Smrg# Create the lock directory. 31336e956c5Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31436e956c5Smrg# that we are using for the .o file. Also, base the name on the expected 31536e956c5Smrg# object file name, since that is what matters with a parallel build. 31636e956c5Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31736e956c5Smrgwhile true; do 31836e956c5Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 31936e956c5Smrg break 32036e956c5Smrg fi 32136e956c5Smrg sleep 1 32236e956c5Smrgdone 32336e956c5Smrg# FIXME: race condition here if user kills between mkdir and trap. 32436e956c5Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 32536e956c5Smrg 32636e956c5Smrg# Run the compile. 32736e956c5Smrg"$@" 32836e956c5Smrgret=$? 32936e956c5Smrg 33036e956c5Smrgif test -f "$cofile"; then 33136e956c5Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33236e956c5Smrgelif test -f "${cofile}bj"; then 33336e956c5Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33436e956c5Smrgfi 33536e956c5Smrg 33636e956c5Smrgrmdir "$lockdir" 33736e956c5Smrgexit $ret 33836e956c5Smrg 33936e956c5Smrg# Local Variables: 34036e956c5Smrg# mode: shell-script 34136e956c5Smrg# sh-indentation: 2 34236e956c5Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 34336e956c5Smrg# time-stamp-start: "scriptversion=" 34436e956c5Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 34536e956c5Smrg# time-stamp-time-zone: "UTC" 34636e956c5Smrg# time-stamp-end: "; # UTC" 34736e956c5Smrg# End: 348