193d9adc1Smrg#! /bin/sh 293d9adc1Smrg# Wrapper for compilers which do not understand '-c -o'. 393d9adc1Smrg 493d9adc1Smrgscriptversion=2012-10-14.11; # UTC 593d9adc1Smrg 693d9adc1Smrg# Copyright (C) 1999-2014 Free Software Foundation, Inc. 793d9adc1Smrg# Written by Tom Tromey <tromey@cygnus.com>. 893d9adc1Smrg# 993d9adc1Smrg# This program is free software; you can redistribute it and/or modify 1093d9adc1Smrg# it under the terms of the GNU General Public License as published by 1193d9adc1Smrg# the Free Software Foundation; either version 2, or (at your option) 1293d9adc1Smrg# any later version. 1393d9adc1Smrg# 1493d9adc1Smrg# This program is distributed in the hope that it will be useful, 1593d9adc1Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1693d9adc1Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1793d9adc1Smrg# GNU General Public License for more details. 1893d9adc1Smrg# 1993d9adc1Smrg# You should have received a copy of the GNU General Public License 2093d9adc1Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 2193d9adc1Smrg 2293d9adc1Smrg# As a special exception to the GNU General Public License, if you 2393d9adc1Smrg# distribute this file as part of a program that contains a 2493d9adc1Smrg# configuration script generated by Autoconf, you may include it under 2593d9adc1Smrg# the same distribution terms that you use for the rest of that program. 2693d9adc1Smrg 2793d9adc1Smrg# This file is maintained in Automake, please report 2893d9adc1Smrg# bugs to <bug-automake@gnu.org> or send patches to 2993d9adc1Smrg# <automake-patches@gnu.org>. 3093d9adc1Smrg 3193d9adc1Smrgnl=' 3293d9adc1Smrg' 3393d9adc1Smrg 3493d9adc1Smrg# We need space, tab and new line, in precisely that order. Quoting is 3593d9adc1Smrg# there to prevent tools from complaining about whitespace usage. 3693d9adc1SmrgIFS=" "" $nl" 3793d9adc1Smrg 3893d9adc1Smrgfile_conv= 3993d9adc1Smrg 4093d9adc1Smrg# func_file_conv build_file lazy 4193d9adc1Smrg# Convert a $build file to $host form and store it in $file 4293d9adc1Smrg# Currently only supports Windows hosts. If the determined conversion 4393d9adc1Smrg# type is listed in (the comma separated) LAZY, no conversion will 4493d9adc1Smrg# take place. 4593d9adc1Smrgfunc_file_conv () 4693d9adc1Smrg{ 4793d9adc1Smrg file=$1 4893d9adc1Smrg case $file in 4993d9adc1Smrg / | /[!/]*) # absolute file, and not a UNC file 5093d9adc1Smrg if test -z "$file_conv"; then 5193d9adc1Smrg # lazily determine how to convert abs files 5293d9adc1Smrg case `uname -s` in 5393d9adc1Smrg MINGW*) 5493d9adc1Smrg file_conv=mingw 5593d9adc1Smrg ;; 5693d9adc1Smrg CYGWIN*) 5793d9adc1Smrg file_conv=cygwin 5893d9adc1Smrg ;; 5993d9adc1Smrg *) 6093d9adc1Smrg file_conv=wine 6193d9adc1Smrg ;; 6293d9adc1Smrg esac 6393d9adc1Smrg fi 6493d9adc1Smrg case $file_conv/,$2, in 6593d9adc1Smrg *,$file_conv,*) 6693d9adc1Smrg ;; 6793d9adc1Smrg mingw/*) 6893d9adc1Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6993d9adc1Smrg ;; 7093d9adc1Smrg cygwin/*) 7193d9adc1Smrg file=`cygpath -m "$file" || echo "$file"` 7293d9adc1Smrg ;; 7393d9adc1Smrg wine/*) 7493d9adc1Smrg file=`winepath -w "$file" || echo "$file"` 7593d9adc1Smrg ;; 7693d9adc1Smrg esac 7793d9adc1Smrg ;; 7893d9adc1Smrg esac 7993d9adc1Smrg} 8093d9adc1Smrg 8193d9adc1Smrg# func_cl_dashL linkdir 8293d9adc1Smrg# Make cl look for libraries in LINKDIR 8393d9adc1Smrgfunc_cl_dashL () 8493d9adc1Smrg{ 8593d9adc1Smrg func_file_conv "$1" 8693d9adc1Smrg if test -z "$lib_path"; then 8793d9adc1Smrg lib_path=$file 8893d9adc1Smrg else 8993d9adc1Smrg lib_path="$lib_path;$file" 9093d9adc1Smrg fi 9193d9adc1Smrg linker_opts="$linker_opts -LIBPATH:$file" 9293d9adc1Smrg} 9393d9adc1Smrg 9493d9adc1Smrg# func_cl_dashl library 9593d9adc1Smrg# Do a library search-path lookup for cl 9693d9adc1Smrgfunc_cl_dashl () 9793d9adc1Smrg{ 9893d9adc1Smrg lib=$1 9993d9adc1Smrg found=no 10093d9adc1Smrg save_IFS=$IFS 10193d9adc1Smrg IFS=';' 10293d9adc1Smrg for dir in $lib_path $LIB 10393d9adc1Smrg do 10493d9adc1Smrg IFS=$save_IFS 10593d9adc1Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 10693d9adc1Smrg found=yes 10793d9adc1Smrg lib=$dir/$lib.dll.lib 10893d9adc1Smrg break 10993d9adc1Smrg fi 11093d9adc1Smrg if test -f "$dir/$lib.lib"; then 11193d9adc1Smrg found=yes 11293d9adc1Smrg lib=$dir/$lib.lib 11393d9adc1Smrg break 11493d9adc1Smrg fi 11593d9adc1Smrg if test -f "$dir/lib$lib.a"; then 11693d9adc1Smrg found=yes 11793d9adc1Smrg lib=$dir/lib$lib.a 11893d9adc1Smrg break 11993d9adc1Smrg fi 12093d9adc1Smrg done 12193d9adc1Smrg IFS=$save_IFS 12293d9adc1Smrg 12393d9adc1Smrg if test "$found" != yes; then 12493d9adc1Smrg lib=$lib.lib 12593d9adc1Smrg fi 12693d9adc1Smrg} 12793d9adc1Smrg 12893d9adc1Smrg# func_cl_wrapper cl arg... 12993d9adc1Smrg# Adjust compile command to suit cl 13093d9adc1Smrgfunc_cl_wrapper () 13193d9adc1Smrg{ 13293d9adc1Smrg # Assume a capable shell 13393d9adc1Smrg lib_path= 13493d9adc1Smrg shared=: 13593d9adc1Smrg linker_opts= 13693d9adc1Smrg for arg 13793d9adc1Smrg do 13893d9adc1Smrg if test -n "$eat"; then 13993d9adc1Smrg eat= 14093d9adc1Smrg else 14193d9adc1Smrg case $1 in 14293d9adc1Smrg -o) 14393d9adc1Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 14493d9adc1Smrg eat=1 14593d9adc1Smrg case $2 in 14693d9adc1Smrg *.o | *.[oO][bB][jJ]) 14793d9adc1Smrg func_file_conv "$2" 14893d9adc1Smrg set x "$@" -Fo"$file" 14993d9adc1Smrg shift 15093d9adc1Smrg ;; 15193d9adc1Smrg *) 15293d9adc1Smrg func_file_conv "$2" 15393d9adc1Smrg set x "$@" -Fe"$file" 15493d9adc1Smrg shift 15593d9adc1Smrg ;; 15693d9adc1Smrg esac 15793d9adc1Smrg ;; 15893d9adc1Smrg -I) 15993d9adc1Smrg eat=1 16093d9adc1Smrg func_file_conv "$2" mingw 16193d9adc1Smrg set x "$@" -I"$file" 16293d9adc1Smrg shift 16393d9adc1Smrg ;; 16493d9adc1Smrg -I*) 16593d9adc1Smrg func_file_conv "${1#-I}" mingw 16693d9adc1Smrg set x "$@" -I"$file" 16793d9adc1Smrg shift 16893d9adc1Smrg ;; 16993d9adc1Smrg -l) 17093d9adc1Smrg eat=1 17193d9adc1Smrg func_cl_dashl "$2" 17293d9adc1Smrg set x "$@" "$lib" 17393d9adc1Smrg shift 17493d9adc1Smrg ;; 17593d9adc1Smrg -l*) 17693d9adc1Smrg func_cl_dashl "${1#-l}" 17793d9adc1Smrg set x "$@" "$lib" 17893d9adc1Smrg shift 17993d9adc1Smrg ;; 18093d9adc1Smrg -L) 18193d9adc1Smrg eat=1 18293d9adc1Smrg func_cl_dashL "$2" 18393d9adc1Smrg ;; 18493d9adc1Smrg -L*) 18593d9adc1Smrg func_cl_dashL "${1#-L}" 18693d9adc1Smrg ;; 18793d9adc1Smrg -static) 18893d9adc1Smrg shared=false 18993d9adc1Smrg ;; 19093d9adc1Smrg -Wl,*) 19193d9adc1Smrg arg=${1#-Wl,} 19293d9adc1Smrg save_ifs="$IFS"; IFS=',' 19393d9adc1Smrg for flag in $arg; do 19493d9adc1Smrg IFS="$save_ifs" 19593d9adc1Smrg linker_opts="$linker_opts $flag" 19693d9adc1Smrg done 19793d9adc1Smrg IFS="$save_ifs" 19893d9adc1Smrg ;; 19993d9adc1Smrg -Xlinker) 20093d9adc1Smrg eat=1 20193d9adc1Smrg linker_opts="$linker_opts $2" 20293d9adc1Smrg ;; 20393d9adc1Smrg -*) 20493d9adc1Smrg set x "$@" "$1" 20593d9adc1Smrg shift 20693d9adc1Smrg ;; 20793d9adc1Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20893d9adc1Smrg func_file_conv "$1" 20993d9adc1Smrg set x "$@" -Tp"$file" 21093d9adc1Smrg shift 21193d9adc1Smrg ;; 21293d9adc1Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21393d9adc1Smrg func_file_conv "$1" mingw 21493d9adc1Smrg set x "$@" "$file" 21593d9adc1Smrg shift 21693d9adc1Smrg ;; 21793d9adc1Smrg *) 21893d9adc1Smrg set x "$@" "$1" 21993d9adc1Smrg shift 22093d9adc1Smrg ;; 22193d9adc1Smrg esac 22293d9adc1Smrg fi 22393d9adc1Smrg shift 22493d9adc1Smrg done 22593d9adc1Smrg if test -n "$linker_opts"; then 22693d9adc1Smrg linker_opts="-link$linker_opts" 22793d9adc1Smrg fi 22893d9adc1Smrg exec "$@" $linker_opts 22993d9adc1Smrg exit 1 23093d9adc1Smrg} 23193d9adc1Smrg 23293d9adc1Smrgeat= 23393d9adc1Smrg 23493d9adc1Smrgcase $1 in 23593d9adc1Smrg '') 23693d9adc1Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 23793d9adc1Smrg exit 1; 23893d9adc1Smrg ;; 23993d9adc1Smrg -h | --h*) 24093d9adc1Smrg cat <<\EOF 24193d9adc1SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 24293d9adc1Smrg 24393d9adc1SmrgWrapper for compilers which do not understand '-c -o'. 24493d9adc1SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24593d9adc1Smrgarguments, and rename the output as expected. 24693d9adc1Smrg 24793d9adc1SmrgIf you are trying to build a whole package this is not the 24893d9adc1Smrgright script to run: please start by reading the file 'INSTALL'. 24993d9adc1Smrg 25093d9adc1SmrgReport bugs to <bug-automake@gnu.org>. 25193d9adc1SmrgEOF 25293d9adc1Smrg exit $? 25393d9adc1Smrg ;; 25493d9adc1Smrg -v | --v*) 25593d9adc1Smrg echo "compile $scriptversion" 25693d9adc1Smrg exit $? 25793d9adc1Smrg ;; 25893d9adc1Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 25993d9adc1Smrg func_cl_wrapper "$@" # Doesn't return... 26093d9adc1Smrg ;; 26193d9adc1Smrgesac 26293d9adc1Smrg 26393d9adc1Smrgofile= 26493d9adc1Smrgcfile= 26593d9adc1Smrg 26693d9adc1Smrgfor arg 26793d9adc1Smrgdo 26893d9adc1Smrg if test -n "$eat"; then 26993d9adc1Smrg eat= 27093d9adc1Smrg else 27193d9adc1Smrg case $1 in 27293d9adc1Smrg -o) 27393d9adc1Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 27493d9adc1Smrg # So we strip '-o arg' only if arg is an object. 27593d9adc1Smrg eat=1 27693d9adc1Smrg case $2 in 27793d9adc1Smrg *.o | *.obj) 27893d9adc1Smrg ofile=$2 27993d9adc1Smrg ;; 28093d9adc1Smrg *) 28193d9adc1Smrg set x "$@" -o "$2" 28293d9adc1Smrg shift 28393d9adc1Smrg ;; 28493d9adc1Smrg esac 28593d9adc1Smrg ;; 28693d9adc1Smrg *.c) 28793d9adc1Smrg cfile=$1 28893d9adc1Smrg set x "$@" "$1" 28993d9adc1Smrg shift 29093d9adc1Smrg ;; 29193d9adc1Smrg *) 29293d9adc1Smrg set x "$@" "$1" 29393d9adc1Smrg shift 29493d9adc1Smrg ;; 29593d9adc1Smrg esac 29693d9adc1Smrg fi 29793d9adc1Smrg shift 29893d9adc1Smrgdone 29993d9adc1Smrg 30093d9adc1Smrgif test -z "$ofile" || test -z "$cfile"; then 30193d9adc1Smrg # If no '-o' option was seen then we might have been invoked from a 30293d9adc1Smrg # pattern rule where we don't need one. That is ok -- this is a 30393d9adc1Smrg # normal compilation that the losing compiler can handle. If no 30493d9adc1Smrg # '.c' file was seen then we are probably linking. That is also 30593d9adc1Smrg # ok. 30693d9adc1Smrg exec "$@" 30793d9adc1Smrgfi 30893d9adc1Smrg 30993d9adc1Smrg# Name of file we expect compiler to create. 31093d9adc1Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31193d9adc1Smrg 31293d9adc1Smrg# Create the lock directory. 31393d9adc1Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31493d9adc1Smrg# that we are using for the .o file. Also, base the name on the expected 31593d9adc1Smrg# object file name, since that is what matters with a parallel build. 31693d9adc1Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31793d9adc1Smrgwhile true; do 31893d9adc1Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 31993d9adc1Smrg break 32093d9adc1Smrg fi 32193d9adc1Smrg sleep 1 32293d9adc1Smrgdone 32393d9adc1Smrg# FIXME: race condition here if user kills between mkdir and trap. 32493d9adc1Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 32593d9adc1Smrg 32693d9adc1Smrg# Run the compile. 32793d9adc1Smrg"$@" 32893d9adc1Smrgret=$? 32993d9adc1Smrg 33093d9adc1Smrgif test -f "$cofile"; then 33193d9adc1Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33293d9adc1Smrgelif test -f "${cofile}bj"; then 33393d9adc1Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33493d9adc1Smrgfi 33593d9adc1Smrg 33693d9adc1Smrgrmdir "$lockdir" 33793d9adc1Smrgexit $ret 33893d9adc1Smrg 33993d9adc1Smrg# Local Variables: 34093d9adc1Smrg# mode: shell-script 34193d9adc1Smrg# sh-indentation: 2 34293d9adc1Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 34393d9adc1Smrg# time-stamp-start: "scriptversion=" 34493d9adc1Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 34593d9adc1Smrg# time-stamp-time-zone: "UTC" 34693d9adc1Smrg# time-stamp-end: "; # UTC" 34793d9adc1Smrg# End: 348