160786Sps#! /bin/sh 260786Sps# Wrapper for compilers which do not understand '-c -o'. 360786Sps 460786Spsscriptversion=2012-10-14.11; # UTC 560786Sps 660786Sps# Copyright (C) 1999-2014 Free Software Foundation, Inc. 760786Sps# Written by Tom Tromey <tromey@cygnus.com>. 860786Sps# 960786Sps# This program is free software; you can redistribute it and/or modify 1060786Sps# it under the terms of the GNU General Public License as published by 1160786Sps# the Free Software Foundation; either version 2, or (at your option) 1260786Sps# any later version. 1360786Sps# 1460786Sps# This program is distributed in the hope that it will be useful, 1560786Sps# but WITHOUT ANY WARRANTY; without even the implied warranty of 1660786Sps# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1760786Sps# GNU General Public License for more details. 1860786Sps# 1960786Sps# You should have received a copy of the GNU General Public License 2060786Sps# along with this program. If not, see <http://www.gnu.org/licenses/>. 2160786Sps 2260786Sps# As a special exception to the GNU General Public License, if you 2360786Sps# distribute this file as part of a program that contains a 2460786Sps# configuration script generated by Autoconf, you may include it under 2560786Sps# the same distribution terms that you use for the rest of that program. 2660786Sps 2760786Sps# This file is maintained in Automake, please report 2860786Sps# bugs to <bug-automake@gnu.org> or send patches to 2960786Sps# <automake-patches@gnu.org>. 3060786Sps 3160786Spsnl=' 3260786Sps' 3360786Sps 3460786Sps# We need space, tab and new line, in precisely that order. Quoting is 3560786Sps# there to prevent tools from complaining about whitespace usage. 3660786SpsIFS=" "" $nl" 3760786Sps 3860786Spsfile_conv= 3960786Sps 4060786Sps# func_file_conv build_file lazy 4160786Sps# Convert a $build file to $host form and store it in $file 4260786Sps# Currently only supports Windows hosts. If the determined conversion 4360786Sps# type is listed in (the comma separated) LAZY, no conversion will 4460786Sps# take place. 4560786Spsfunc_file_conv () 4660786Sps{ 4760786Sps file=$1 4860786Sps case $file in 4960786Sps / | /[!/]*) # absolute file, and not a UNC file 5060786Sps if test -z "$file_conv"; then 5160786Sps # lazily determine how to convert abs files 5260786Sps case `uname -s` in 5360786Sps MINGW*) 5460786Sps file_conv=mingw 5560786Sps ;; 5660786Sps CYGWIN*) 5760786Sps file_conv=cygwin 5860786Sps ;; 5960786Sps *) 6060786Sps file_conv=wine 6160786Sps ;; 6260786Sps esac 6360786Sps fi 6460786Sps case $file_conv/,$2, in 6560786Sps *,$file_conv,*) 6660786Sps ;; 6760786Sps mingw/*) 6860786Sps file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6960786Sps ;; 7060786Sps cygwin/*) 7160786Sps file=`cygpath -m "$file" || echo "$file"` 7260786Sps ;; 7360786Sps wine/*) 7460786Sps file=`winepath -w "$file" || echo "$file"` 7560786Sps ;; 7660786Sps esac 7760786Sps ;; 7860786Sps esac 7960786Sps} 8060786Sps 8160786Sps# func_cl_dashL linkdir 8260786Sps# Make cl look for libraries in LINKDIR 8360786Spsfunc_cl_dashL () 8460786Sps{ 8560786Sps func_file_conv "$1" 8660786Sps if test -z "$lib_path"; then 8760786Sps lib_path=$file 8860786Sps else 8960786Sps lib_path="$lib_path;$file" 9060786Sps fi 9160786Sps linker_opts="$linker_opts -LIBPATH:$file" 9260786Sps} 9360786Sps 9460786Sps# func_cl_dashl library 9560786Sps# Do a library search-path lookup for cl 9660786Spsfunc_cl_dashl () 9760786Sps{ 9860786Sps lib=$1 9960786Sps found=no 10060786Sps save_IFS=$IFS 10160786Sps IFS=';' 10260786Sps for dir in $lib_path $LIB 10360786Sps do 10460786Sps IFS=$save_IFS 10560786Sps if $shared && test -f "$dir/$lib.dll.lib"; then 10660786Sps found=yes 10760786Sps lib=$dir/$lib.dll.lib 10860786Sps break 10960786Sps fi 11060786Sps if test -f "$dir/$lib.lib"; then 11160786Sps found=yes 11260786Sps lib=$dir/$lib.lib 11360786Sps break 11460786Sps fi 11560786Sps if test -f "$dir/lib$lib.a"; then 11660786Sps found=yes 11760786Sps lib=$dir/lib$lib.a 11860786Sps break 11960786Sps fi 12060786Sps done 12160786Sps IFS=$save_IFS 12260786Sps 12360786Sps if test "$found" != yes; then 12460786Sps lib=$lib.lib 12560786Sps fi 12660786Sps} 12760786Sps 12860786Sps# func_cl_wrapper cl arg... 12960786Sps# Adjust compile command to suit cl 13060786Spsfunc_cl_wrapper () 13160786Sps{ 13260786Sps # Assume a capable shell 13360786Sps lib_path= 13460786Sps shared=: 13560786Sps linker_opts= 13660786Sps for arg 13760786Sps do 13860786Sps if test -n "$eat"; then 13960786Sps eat= 14060786Sps else 14160786Sps case $1 in 14260786Sps -o) 14360786Sps # configure might choose to run compile as 'compile cc -o foo foo.c'. 14460786Sps eat=1 14560786Sps case $2 in 14660786Sps *.o | *.[oO][bB][jJ]) 14760786Sps func_file_conv "$2" 14860786Sps set x "$@" -Fo"$file" 14960786Sps shift 15060786Sps ;; 15160786Sps *) 15260786Sps func_file_conv "$2" 15360786Sps set x "$@" -Fe"$file" 15460786Sps shift 15560786Sps ;; 15660786Sps esac 15760786Sps ;; 15860786Sps -I) 15960786Sps eat=1 16060786Sps func_file_conv "$2" mingw 16160786Sps set x "$@" -I"$file" 16260786Sps shift 16360786Sps ;; 16460786Sps -I*) 16560786Sps func_file_conv "${1#-I}" mingw 16660786Sps set x "$@" -I"$file" 16760786Sps shift 16860786Sps ;; 16960786Sps -l) 17060786Sps eat=1 17160786Sps func_cl_dashl "$2" 17260786Sps set x "$@" "$lib" 17360786Sps shift 17460786Sps ;; 17560786Sps -l*) 17660786Sps func_cl_dashl "${1#-l}" 17760786Sps set x "$@" "$lib" 17860786Sps shift 17960786Sps ;; 18060786Sps -L) 18160786Sps eat=1 18260786Sps func_cl_dashL "$2" 18360786Sps ;; 18460786Sps -L*) 18560786Sps func_cl_dashL "${1#-L}" 18660786Sps ;; 18760786Sps -static) 18860786Sps shared=false 18960786Sps ;; 19060786Sps -Wl,*) 19160786Sps arg=${1#-Wl,} 19260786Sps save_ifs="$IFS"; IFS=',' 19360786Sps for flag in $arg; do 19460786Sps IFS="$save_ifs" 19560786Sps linker_opts="$linker_opts $flag" 19660786Sps done 19760786Sps IFS="$save_ifs" 19860786Sps ;; 19960786Sps -Xlinker) 20060786Sps eat=1 20160786Sps linker_opts="$linker_opts $2" 20260786Sps ;; 20360786Sps -*) 20460786Sps set x "$@" "$1" 20560786Sps shift 20660786Sps ;; 20760786Sps *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20860786Sps func_file_conv "$1" 20960786Sps set x "$@" -Tp"$file" 21060786Sps shift 21160786Sps ;; 21260786Sps *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21360786Sps func_file_conv "$1" mingw 21460786Sps set x "$@" "$file" 21560786Sps shift 21660786Sps ;; 21760786Sps *) 21860786Sps set x "$@" "$1" 21960786Sps shift 22060786Sps ;; 22160786Sps esac 22260786Sps fi 22360786Sps shift 22460786Sps done 22560786Sps if test -n "$linker_opts"; then 22660786Sps linker_opts="-link$linker_opts" 22760786Sps fi 22860786Sps exec "$@" $linker_opts 22960786Sps exit 1 23060786Sps} 23160786Sps 23260786Spseat= 23360786Sps 23460786Spscase $1 in 23560786Sps '') 23660786Sps echo "$0: No command. Try '$0 --help' for more information." 1>&2 23760786Sps exit 1; 23860786Sps ;; 23960786Sps -h | --h*) 24060786Sps cat <<\EOF 24160786SpsUsage: compile [--help] [--version] PROGRAM [ARGS] 24260786Sps 24360786SpsWrapper for compilers which do not understand '-c -o'. 24460786SpsRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24560786Spsarguments, and rename the output as expected. 24660786Sps 24760786SpsIf you are trying to build a whole package this is not the 24860786Spsright script to run: please start by reading the file 'INSTALL'. 24960786Sps 25060786SpsReport bugs to <bug-automake@gnu.org>. 25160786SpsEOF 25260786Sps exit $? 25360786Sps ;; 25460786Sps -v | --v*) 25560786Sps echo "compile $scriptversion" 25660786Sps exit $? 25760786Sps ;; 25860786Sps cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 25960786Sps func_cl_wrapper "$@" # Doesn't return... 26060786Sps ;; 26160786Spsesac 26260786Sps 26360786Spsofile= 26460786Spscfile= 26560786Sps 26660786Spsfor arg 26760786Spsdo 26860786Sps if test -n "$eat"; then 26960786Sps eat= 27060786Sps else 27160786Sps case $1 in 27260786Sps -o) 27360786Sps # configure might choose to run compile as 'compile cc -o foo foo.c'. 27460786Sps # So we strip '-o arg' only if arg is an object. 27560786Sps eat=1 27660786Sps case $2 in 27760786Sps *.o | *.obj) 27860786Sps ofile=$2 27960786Sps ;; 28060786Sps *) 28160786Sps set x "$@" -o "$2" 28260786Sps shift 28360786Sps ;; 28460786Sps esac 28560786Sps ;; 28660786Sps *.c) 28760786Sps cfile=$1 28860786Sps set x "$@" "$1" 28960786Sps shift 29060786Sps ;; 29160786Sps *) 29260786Sps set x "$@" "$1" 29360786Sps shift 29460786Sps ;; 29560786Sps esac 29660786Sps fi 29760786Sps shift 29860786Spsdone 29960786Sps 30060786Spsif test -z "$ofile" || test -z "$cfile"; then 30160786Sps # If no '-o' option was seen then we might have been invoked from a 30260786Sps # pattern rule where we don't need one. That is ok -- this is a 30360786Sps # normal compilation that the losing compiler can handle. If no 30460786Sps # '.c' file was seen then we are probably linking. That is also 30560786Sps # ok. 30660786Sps exec "$@" 30760786Spsfi 30860786Sps 30960786Sps# Name of file we expect compiler to create. 31060786Spscofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31160786Sps 31260786Sps# Create the lock directory. 31360786Sps# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31460786Sps# that we are using for the .o file. Also, base the name on the expected 31560786Sps# object file name, since that is what matters with a parallel build. 31660786Spslockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31760786Spswhile true; do 31860786Sps if mkdir "$lockdir" >/dev/null 2>&1; then 31960786Sps break 32060786Sps fi 32160786Sps sleep 1 32260786Spsdone 32360786Sps# FIXME: race condition here if user kills between mkdir and trap. 32460786Spstrap "rmdir '$lockdir'; exit 1" 1 2 15 32560786Sps 32660786Sps# Run the compile. 32760786Sps"$@" 32860786Spsret=$? 32960786Sps 33060786Spsif test -f "$cofile"; then 33160786Sps test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33260786Spselif test -f "${cofile}bj"; then 33360786Sps test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33460786Spsfi 33560786Sps 33660786Spsrmdir "$lockdir" 33760786Spsexit $ret 33860786Sps 33960786Sps# Local Variables: 34060786Sps# mode: shell-script 34160786Sps# sh-indentation: 2 34260786Sps# eval: (add-hook 'write-file-hooks 'time-stamp) 34360786Sps# time-stamp-start: "scriptversion=" 34460786Sps# time-stamp-format: "%:y-%02m-%02d.%02H" 34560786Sps# time-stamp-time-zone: "UTC" 34660786Sps# time-stamp-end: "; # UTC" 34760786Sps# End: 34860786Sps