compile revision 81440437
181440437Smrg#! /bin/sh 281440437Smrg# Wrapper for compilers which do not understand '-c -o'. 381440437Smrg 481440437Smrgscriptversion=2012-10-14.11; # UTC 581440437Smrg 681440437Smrg# Copyright (C) 1999-2013 Free Software Foundation, Inc. 781440437Smrg# Written by Tom Tromey <tromey@cygnus.com>. 881440437Smrg# 981440437Smrg# This program is free software; you can redistribute it and/or modify 1081440437Smrg# it under the terms of the GNU General Public License as published by 1181440437Smrg# the Free Software Foundation; either version 2, or (at your option) 1281440437Smrg# any later version. 1381440437Smrg# 1481440437Smrg# This program is distributed in the hope that it will be useful, 1581440437Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1681440437Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1781440437Smrg# GNU General Public License for more details. 1881440437Smrg# 1981440437Smrg# You should have received a copy of the GNU General Public License 2081440437Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 2181440437Smrg 2281440437Smrg# As a special exception to the GNU General Public License, if you 2381440437Smrg# distribute this file as part of a program that contains a 2481440437Smrg# configuration script generated by Autoconf, you may include it under 2581440437Smrg# the same distribution terms that you use for the rest of that program. 2681440437Smrg 2781440437Smrg# This file is maintained in Automake, please report 2881440437Smrg# bugs to <bug-automake@gnu.org> or send patches to 2981440437Smrg# <automake-patches@gnu.org>. 3081440437Smrg 3181440437Smrgnl=' 3281440437Smrg' 3381440437Smrg 3481440437Smrg# We need space, tab and new line, in precisely that order. Quoting is 3581440437Smrg# there to prevent tools from complaining about whitespace usage. 3681440437SmrgIFS=" "" $nl" 3781440437Smrg 3881440437Smrgfile_conv= 3981440437Smrg 4081440437Smrg# func_file_conv build_file lazy 4181440437Smrg# Convert a $build file to $host form and store it in $file 4281440437Smrg# Currently only supports Windows hosts. If the determined conversion 4381440437Smrg# type is listed in (the comma separated) LAZY, no conversion will 4481440437Smrg# take place. 4581440437Smrgfunc_file_conv () 4681440437Smrg{ 4781440437Smrg file=$1 4881440437Smrg case $file in 4981440437Smrg / | /[!/]*) # absolute file, and not a UNC file 5081440437Smrg if test -z "$file_conv"; then 5181440437Smrg # lazily determine how to convert abs files 5281440437Smrg case `uname -s` in 5381440437Smrg MINGW*) 5481440437Smrg file_conv=mingw 5581440437Smrg ;; 5681440437Smrg CYGWIN*) 5781440437Smrg file_conv=cygwin 5881440437Smrg ;; 5981440437Smrg *) 6081440437Smrg file_conv=wine 6181440437Smrg ;; 6281440437Smrg esac 6381440437Smrg fi 6481440437Smrg case $file_conv/,$2, in 6581440437Smrg *,$file_conv,*) 6681440437Smrg ;; 6781440437Smrg mingw/*) 6881440437Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6981440437Smrg ;; 7081440437Smrg cygwin/*) 7181440437Smrg file=`cygpath -m "$file" || echo "$file"` 7281440437Smrg ;; 7381440437Smrg wine/*) 7481440437Smrg file=`winepath -w "$file" || echo "$file"` 7581440437Smrg ;; 7681440437Smrg esac 7781440437Smrg ;; 7881440437Smrg esac 7981440437Smrg} 8081440437Smrg 8181440437Smrg# func_cl_dashL linkdir 8281440437Smrg# Make cl look for libraries in LINKDIR 8381440437Smrgfunc_cl_dashL () 8481440437Smrg{ 8581440437Smrg func_file_conv "$1" 8681440437Smrg if test -z "$lib_path"; then 8781440437Smrg lib_path=$file 8881440437Smrg else 8981440437Smrg lib_path="$lib_path;$file" 9081440437Smrg fi 9181440437Smrg linker_opts="$linker_opts -LIBPATH:$file" 9281440437Smrg} 9381440437Smrg 9481440437Smrg# func_cl_dashl library 9581440437Smrg# Do a library search-path lookup for cl 9681440437Smrgfunc_cl_dashl () 9781440437Smrg{ 9881440437Smrg lib=$1 9981440437Smrg found=no 10081440437Smrg save_IFS=$IFS 10181440437Smrg IFS=';' 10281440437Smrg for dir in $lib_path $LIB 10381440437Smrg do 10481440437Smrg IFS=$save_IFS 10581440437Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 10681440437Smrg found=yes 10781440437Smrg lib=$dir/$lib.dll.lib 10881440437Smrg break 10981440437Smrg fi 11081440437Smrg if test -f "$dir/$lib.lib"; then 11181440437Smrg found=yes 11281440437Smrg lib=$dir/$lib.lib 11381440437Smrg break 11481440437Smrg fi 11581440437Smrg if test -f "$dir/lib$lib.a"; then 11681440437Smrg found=yes 11781440437Smrg lib=$dir/lib$lib.a 11881440437Smrg break 11981440437Smrg fi 12081440437Smrg done 12181440437Smrg IFS=$save_IFS 12281440437Smrg 12381440437Smrg if test "$found" != yes; then 12481440437Smrg lib=$lib.lib 12581440437Smrg fi 12681440437Smrg} 12781440437Smrg 12881440437Smrg# func_cl_wrapper cl arg... 12981440437Smrg# Adjust compile command to suit cl 13081440437Smrgfunc_cl_wrapper () 13181440437Smrg{ 13281440437Smrg # Assume a capable shell 13381440437Smrg lib_path= 13481440437Smrg shared=: 13581440437Smrg linker_opts= 13681440437Smrg for arg 13781440437Smrg do 13881440437Smrg if test -n "$eat"; then 13981440437Smrg eat= 14081440437Smrg else 14181440437Smrg case $1 in 14281440437Smrg -o) 14381440437Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 14481440437Smrg eat=1 14581440437Smrg case $2 in 14681440437Smrg *.o | *.[oO][bB][jJ]) 14781440437Smrg func_file_conv "$2" 14881440437Smrg set x "$@" -Fo"$file" 14981440437Smrg shift 15081440437Smrg ;; 15181440437Smrg *) 15281440437Smrg func_file_conv "$2" 15381440437Smrg set x "$@" -Fe"$file" 15481440437Smrg shift 15581440437Smrg ;; 15681440437Smrg esac 15781440437Smrg ;; 15881440437Smrg -I) 15981440437Smrg eat=1 16081440437Smrg func_file_conv "$2" mingw 16181440437Smrg set x "$@" -I"$file" 16281440437Smrg shift 16381440437Smrg ;; 16481440437Smrg -I*) 16581440437Smrg func_file_conv "${1#-I}" mingw 16681440437Smrg set x "$@" -I"$file" 16781440437Smrg shift 16881440437Smrg ;; 16981440437Smrg -l) 17081440437Smrg eat=1 17181440437Smrg func_cl_dashl "$2" 17281440437Smrg set x "$@" "$lib" 17381440437Smrg shift 17481440437Smrg ;; 17581440437Smrg -l*) 17681440437Smrg func_cl_dashl "${1#-l}" 17781440437Smrg set x "$@" "$lib" 17881440437Smrg shift 17981440437Smrg ;; 18081440437Smrg -L) 18181440437Smrg eat=1 18281440437Smrg func_cl_dashL "$2" 18381440437Smrg ;; 18481440437Smrg -L*) 18581440437Smrg func_cl_dashL "${1#-L}" 18681440437Smrg ;; 18781440437Smrg -static) 18881440437Smrg shared=false 18981440437Smrg ;; 19081440437Smrg -Wl,*) 19181440437Smrg arg=${1#-Wl,} 19281440437Smrg save_ifs="$IFS"; IFS=',' 19381440437Smrg for flag in $arg; do 19481440437Smrg IFS="$save_ifs" 19581440437Smrg linker_opts="$linker_opts $flag" 19681440437Smrg done 19781440437Smrg IFS="$save_ifs" 19881440437Smrg ;; 19981440437Smrg -Xlinker) 20081440437Smrg eat=1 20181440437Smrg linker_opts="$linker_opts $2" 20281440437Smrg ;; 20381440437Smrg -*) 20481440437Smrg set x "$@" "$1" 20581440437Smrg shift 20681440437Smrg ;; 20781440437Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20881440437Smrg func_file_conv "$1" 20981440437Smrg set x "$@" -Tp"$file" 21081440437Smrg shift 21181440437Smrg ;; 21281440437Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21381440437Smrg func_file_conv "$1" mingw 21481440437Smrg set x "$@" "$file" 21581440437Smrg shift 21681440437Smrg ;; 21781440437Smrg *) 21881440437Smrg set x "$@" "$1" 21981440437Smrg shift 22081440437Smrg ;; 22181440437Smrg esac 22281440437Smrg fi 22381440437Smrg shift 22481440437Smrg done 22581440437Smrg if test -n "$linker_opts"; then 22681440437Smrg linker_opts="-link$linker_opts" 22781440437Smrg fi 22881440437Smrg exec "$@" $linker_opts 22981440437Smrg exit 1 23081440437Smrg} 23181440437Smrg 23281440437Smrgeat= 23381440437Smrg 23481440437Smrgcase $1 in 23581440437Smrg '') 23681440437Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 23781440437Smrg exit 1; 23881440437Smrg ;; 23981440437Smrg -h | --h*) 24081440437Smrg cat <<\EOF 24181440437SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 24281440437Smrg 24381440437SmrgWrapper for compilers which do not understand '-c -o'. 24481440437SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24581440437Smrgarguments, and rename the output as expected. 24681440437Smrg 24781440437SmrgIf you are trying to build a whole package this is not the 24881440437Smrgright script to run: please start by reading the file 'INSTALL'. 24981440437Smrg 25081440437SmrgReport bugs to <bug-automake@gnu.org>. 25181440437SmrgEOF 25281440437Smrg exit $? 25381440437Smrg ;; 25481440437Smrg -v | --v*) 25581440437Smrg echo "compile $scriptversion" 25681440437Smrg exit $? 25781440437Smrg ;; 25881440437Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 25981440437Smrg func_cl_wrapper "$@" # Doesn't return... 26081440437Smrg ;; 26181440437Smrgesac 26281440437Smrg 26381440437Smrgofile= 26481440437Smrgcfile= 26581440437Smrg 26681440437Smrgfor arg 26781440437Smrgdo 26881440437Smrg if test -n "$eat"; then 26981440437Smrg eat= 27081440437Smrg else 27181440437Smrg case $1 in 27281440437Smrg -o) 27381440437Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 27481440437Smrg # So we strip '-o arg' only if arg is an object. 27581440437Smrg eat=1 27681440437Smrg case $2 in 27781440437Smrg *.o | *.obj) 27881440437Smrg ofile=$2 27981440437Smrg ;; 28081440437Smrg *) 28181440437Smrg set x "$@" -o "$2" 28281440437Smrg shift 28381440437Smrg ;; 28481440437Smrg esac 28581440437Smrg ;; 28681440437Smrg *.c) 28781440437Smrg cfile=$1 28881440437Smrg set x "$@" "$1" 28981440437Smrg shift 29081440437Smrg ;; 29181440437Smrg *) 29281440437Smrg set x "$@" "$1" 29381440437Smrg shift 29481440437Smrg ;; 29581440437Smrg esac 29681440437Smrg fi 29781440437Smrg shift 29881440437Smrgdone 29981440437Smrg 30081440437Smrgif test -z "$ofile" || test -z "$cfile"; then 30181440437Smrg # If no '-o' option was seen then we might have been invoked from a 30281440437Smrg # pattern rule where we don't need one. That is ok -- this is a 30381440437Smrg # normal compilation that the losing compiler can handle. If no 30481440437Smrg # '.c' file was seen then we are probably linking. That is also 30581440437Smrg # ok. 30681440437Smrg exec "$@" 30781440437Smrgfi 30881440437Smrg 30981440437Smrg# Name of file we expect compiler to create. 31081440437Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31181440437Smrg 31281440437Smrg# Create the lock directory. 31381440437Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31481440437Smrg# that we are using for the .o file. Also, base the name on the expected 31581440437Smrg# object file name, since that is what matters with a parallel build. 31681440437Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31781440437Smrgwhile true; do 31881440437Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 31981440437Smrg break 32081440437Smrg fi 32181440437Smrg sleep 1 32281440437Smrgdone 32381440437Smrg# FIXME: race condition here if user kills between mkdir and trap. 32481440437Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 32581440437Smrg 32681440437Smrg# Run the compile. 32781440437Smrg"$@" 32881440437Smrgret=$? 32981440437Smrg 33081440437Smrgif test -f "$cofile"; then 33181440437Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33281440437Smrgelif test -f "${cofile}bj"; then 33381440437Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33481440437Smrgfi 33581440437Smrg 33681440437Smrgrmdir "$lockdir" 33781440437Smrgexit $ret 33881440437Smrg 33981440437Smrg# Local Variables: 34081440437Smrg# mode: shell-script 34181440437Smrg# sh-indentation: 2 34281440437Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 34381440437Smrg# time-stamp-start: "scriptversion=" 34481440437Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 34581440437Smrg# time-stamp-time-zone: "UTC" 34681440437Smrg# time-stamp-end: "; # UTC" 34781440437Smrg# End: 348