compile revision 6c3c2bce
140c5344fSmrg#! /bin/sh 240c5344fSmrg# Wrapper for compilers which do not understand '-c -o'. 340c5344fSmrg 46c3c2bceSmrgscriptversion=2018-03-07.03; # UTC 540c5344fSmrg 66c3c2bceSmrg# Copyright (C) 1999-2018 Free Software Foundation, Inc. 740c5344fSmrg# Written by Tom Tromey <tromey@cygnus.com>. 840c5344fSmrg# 940c5344fSmrg# This program is free software; you can redistribute it and/or modify 1040c5344fSmrg# it under the terms of the GNU General Public License as published by 1140c5344fSmrg# the Free Software Foundation; either version 2, or (at your option) 1240c5344fSmrg# any later version. 1340c5344fSmrg# 1440c5344fSmrg# This program is distributed in the hope that it will be useful, 1540c5344fSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1640c5344fSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1740c5344fSmrg# GNU General Public License for more details. 1840c5344fSmrg# 1940c5344fSmrg# You should have received a copy of the GNU General Public License 206c3c2bceSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2140c5344fSmrg 2240c5344fSmrg# As a special exception to the GNU General Public License, if you 2340c5344fSmrg# distribute this file as part of a program that contains a 2440c5344fSmrg# configuration script generated by Autoconf, you may include it under 2540c5344fSmrg# the same distribution terms that you use for the rest of that program. 2640c5344fSmrg 2740c5344fSmrg# This file is maintained in Automake, please report 2840c5344fSmrg# bugs to <bug-automake@gnu.org> or send patches to 2940c5344fSmrg# <automake-patches@gnu.org>. 3040c5344fSmrg 3140c5344fSmrgnl=' 3240c5344fSmrg' 3340c5344fSmrg 3440c5344fSmrg# We need space, tab and new line, in precisely that order. Quoting is 3540c5344fSmrg# there to prevent tools from complaining about whitespace usage. 3640c5344fSmrgIFS=" "" $nl" 3740c5344fSmrg 3840c5344fSmrgfile_conv= 3940c5344fSmrg 4040c5344fSmrg# func_file_conv build_file lazy 4140c5344fSmrg# Convert a $build file to $host form and store it in $file 4240c5344fSmrg# Currently only supports Windows hosts. If the determined conversion 4340c5344fSmrg# type is listed in (the comma separated) LAZY, no conversion will 4440c5344fSmrg# take place. 4540c5344fSmrgfunc_file_conv () 4640c5344fSmrg{ 4740c5344fSmrg file=$1 4840c5344fSmrg case $file in 4940c5344fSmrg / | /[!/]*) # absolute file, and not a UNC file 5040c5344fSmrg if test -z "$file_conv"; then 5140c5344fSmrg # lazily determine how to convert abs files 5240c5344fSmrg case `uname -s` in 5340c5344fSmrg MINGW*) 5440c5344fSmrg file_conv=mingw 5540c5344fSmrg ;; 5640c5344fSmrg CYGWIN*) 5740c5344fSmrg file_conv=cygwin 5840c5344fSmrg ;; 5940c5344fSmrg *) 6040c5344fSmrg file_conv=wine 6140c5344fSmrg ;; 6240c5344fSmrg esac 6340c5344fSmrg fi 6440c5344fSmrg case $file_conv/,$2, in 6540c5344fSmrg *,$file_conv,*) 6640c5344fSmrg ;; 6740c5344fSmrg mingw/*) 6840c5344fSmrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6940c5344fSmrg ;; 7040c5344fSmrg cygwin/*) 7140c5344fSmrg file=`cygpath -m "$file" || echo "$file"` 7240c5344fSmrg ;; 7340c5344fSmrg wine/*) 7440c5344fSmrg file=`winepath -w "$file" || echo "$file"` 7540c5344fSmrg ;; 7640c5344fSmrg esac 7740c5344fSmrg ;; 7840c5344fSmrg esac 7940c5344fSmrg} 8040c5344fSmrg 8140c5344fSmrg# func_cl_dashL linkdir 8240c5344fSmrg# Make cl look for libraries in LINKDIR 8340c5344fSmrgfunc_cl_dashL () 8440c5344fSmrg{ 8540c5344fSmrg func_file_conv "$1" 8640c5344fSmrg if test -z "$lib_path"; then 8740c5344fSmrg lib_path=$file 8840c5344fSmrg else 8940c5344fSmrg lib_path="$lib_path;$file" 9040c5344fSmrg fi 9140c5344fSmrg linker_opts="$linker_opts -LIBPATH:$file" 9240c5344fSmrg} 9340c5344fSmrg 9440c5344fSmrg# func_cl_dashl library 9540c5344fSmrg# Do a library search-path lookup for cl 9640c5344fSmrgfunc_cl_dashl () 9740c5344fSmrg{ 9840c5344fSmrg lib=$1 9940c5344fSmrg found=no 10040c5344fSmrg save_IFS=$IFS 10140c5344fSmrg IFS=';' 10240c5344fSmrg for dir in $lib_path $LIB 10340c5344fSmrg do 10440c5344fSmrg IFS=$save_IFS 10540c5344fSmrg if $shared && test -f "$dir/$lib.dll.lib"; then 10640c5344fSmrg found=yes 10740c5344fSmrg lib=$dir/$lib.dll.lib 10840c5344fSmrg break 10940c5344fSmrg fi 11040c5344fSmrg if test -f "$dir/$lib.lib"; then 11140c5344fSmrg found=yes 11240c5344fSmrg lib=$dir/$lib.lib 11340c5344fSmrg break 11440c5344fSmrg fi 11540c5344fSmrg if test -f "$dir/lib$lib.a"; then 11640c5344fSmrg found=yes 11740c5344fSmrg lib=$dir/lib$lib.a 11840c5344fSmrg break 11940c5344fSmrg fi 12040c5344fSmrg done 12140c5344fSmrg IFS=$save_IFS 12240c5344fSmrg 12340c5344fSmrg if test "$found" != yes; then 12440c5344fSmrg lib=$lib.lib 12540c5344fSmrg fi 12640c5344fSmrg} 12740c5344fSmrg 12840c5344fSmrg# func_cl_wrapper cl arg... 12940c5344fSmrg# Adjust compile command to suit cl 13040c5344fSmrgfunc_cl_wrapper () 13140c5344fSmrg{ 13240c5344fSmrg # Assume a capable shell 13340c5344fSmrg lib_path= 13440c5344fSmrg shared=: 13540c5344fSmrg linker_opts= 13640c5344fSmrg for arg 13740c5344fSmrg do 13840c5344fSmrg if test -n "$eat"; then 13940c5344fSmrg eat= 14040c5344fSmrg else 14140c5344fSmrg case $1 in 14240c5344fSmrg -o) 14340c5344fSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 14440c5344fSmrg eat=1 14540c5344fSmrg case $2 in 14640c5344fSmrg *.o | *.[oO][bB][jJ]) 14740c5344fSmrg func_file_conv "$2" 14840c5344fSmrg set x "$@" -Fo"$file" 14940c5344fSmrg shift 15040c5344fSmrg ;; 15140c5344fSmrg *) 15240c5344fSmrg func_file_conv "$2" 15340c5344fSmrg set x "$@" -Fe"$file" 15440c5344fSmrg shift 15540c5344fSmrg ;; 15640c5344fSmrg esac 15740c5344fSmrg ;; 15840c5344fSmrg -I) 15940c5344fSmrg eat=1 16040c5344fSmrg func_file_conv "$2" mingw 16140c5344fSmrg set x "$@" -I"$file" 16240c5344fSmrg shift 16340c5344fSmrg ;; 16440c5344fSmrg -I*) 16540c5344fSmrg func_file_conv "${1#-I}" mingw 16640c5344fSmrg set x "$@" -I"$file" 16740c5344fSmrg shift 16840c5344fSmrg ;; 16940c5344fSmrg -l) 17040c5344fSmrg eat=1 17140c5344fSmrg func_cl_dashl "$2" 17240c5344fSmrg set x "$@" "$lib" 17340c5344fSmrg shift 17440c5344fSmrg ;; 17540c5344fSmrg -l*) 17640c5344fSmrg func_cl_dashl "${1#-l}" 17740c5344fSmrg set x "$@" "$lib" 17840c5344fSmrg shift 17940c5344fSmrg ;; 18040c5344fSmrg -L) 18140c5344fSmrg eat=1 18240c5344fSmrg func_cl_dashL "$2" 18340c5344fSmrg ;; 18440c5344fSmrg -L*) 18540c5344fSmrg func_cl_dashL "${1#-L}" 18640c5344fSmrg ;; 18740c5344fSmrg -static) 18840c5344fSmrg shared=false 18940c5344fSmrg ;; 19040c5344fSmrg -Wl,*) 19140c5344fSmrg arg=${1#-Wl,} 19240c5344fSmrg save_ifs="$IFS"; IFS=',' 19340c5344fSmrg for flag in $arg; do 19440c5344fSmrg IFS="$save_ifs" 19540c5344fSmrg linker_opts="$linker_opts $flag" 19640c5344fSmrg done 19740c5344fSmrg IFS="$save_ifs" 19840c5344fSmrg ;; 19940c5344fSmrg -Xlinker) 20040c5344fSmrg eat=1 20140c5344fSmrg linker_opts="$linker_opts $2" 20240c5344fSmrg ;; 20340c5344fSmrg -*) 20440c5344fSmrg set x "$@" "$1" 20540c5344fSmrg shift 20640c5344fSmrg ;; 20740c5344fSmrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20840c5344fSmrg func_file_conv "$1" 20940c5344fSmrg set x "$@" -Tp"$file" 21040c5344fSmrg shift 21140c5344fSmrg ;; 21240c5344fSmrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21340c5344fSmrg func_file_conv "$1" mingw 21440c5344fSmrg set x "$@" "$file" 21540c5344fSmrg shift 21640c5344fSmrg ;; 21740c5344fSmrg *) 21840c5344fSmrg set x "$@" "$1" 21940c5344fSmrg shift 22040c5344fSmrg ;; 22140c5344fSmrg esac 22240c5344fSmrg fi 22340c5344fSmrg shift 22440c5344fSmrg done 22540c5344fSmrg if test -n "$linker_opts"; then 22640c5344fSmrg linker_opts="-link$linker_opts" 22740c5344fSmrg fi 22840c5344fSmrg exec "$@" $linker_opts 22940c5344fSmrg exit 1 23040c5344fSmrg} 23140c5344fSmrg 23240c5344fSmrgeat= 23340c5344fSmrg 23440c5344fSmrgcase $1 in 23540c5344fSmrg '') 23640c5344fSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 23740c5344fSmrg exit 1; 23840c5344fSmrg ;; 23940c5344fSmrg -h | --h*) 24040c5344fSmrg cat <<\EOF 24140c5344fSmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 24240c5344fSmrg 24340c5344fSmrgWrapper for compilers which do not understand '-c -o'. 24440c5344fSmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24540c5344fSmrgarguments, and rename the output as expected. 24640c5344fSmrg 24740c5344fSmrgIf you are trying to build a whole package this is not the 24840c5344fSmrgright script to run: please start by reading the file 'INSTALL'. 24940c5344fSmrg 25040c5344fSmrgReport bugs to <bug-automake@gnu.org>. 25140c5344fSmrgEOF 25240c5344fSmrg exit $? 25340c5344fSmrg ;; 25440c5344fSmrg -v | --v*) 25540c5344fSmrg echo "compile $scriptversion" 25640c5344fSmrg exit $? 25740c5344fSmrg ;; 2586c3c2bceSmrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 2596c3c2bceSmrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 26040c5344fSmrg func_cl_wrapper "$@" # Doesn't return... 26140c5344fSmrg ;; 26240c5344fSmrgesac 26340c5344fSmrg 26440c5344fSmrgofile= 26540c5344fSmrgcfile= 26640c5344fSmrg 26740c5344fSmrgfor arg 26840c5344fSmrgdo 26940c5344fSmrg if test -n "$eat"; then 27040c5344fSmrg eat= 27140c5344fSmrg else 27240c5344fSmrg case $1 in 27340c5344fSmrg -o) 27440c5344fSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 27540c5344fSmrg # So we strip '-o arg' only if arg is an object. 27640c5344fSmrg eat=1 27740c5344fSmrg case $2 in 27840c5344fSmrg *.o | *.obj) 27940c5344fSmrg ofile=$2 28040c5344fSmrg ;; 28140c5344fSmrg *) 28240c5344fSmrg set x "$@" -o "$2" 28340c5344fSmrg shift 28440c5344fSmrg ;; 28540c5344fSmrg esac 28640c5344fSmrg ;; 28740c5344fSmrg *.c) 28840c5344fSmrg cfile=$1 28940c5344fSmrg set x "$@" "$1" 29040c5344fSmrg shift 29140c5344fSmrg ;; 29240c5344fSmrg *) 29340c5344fSmrg set x "$@" "$1" 29440c5344fSmrg shift 29540c5344fSmrg ;; 29640c5344fSmrg esac 29740c5344fSmrg fi 29840c5344fSmrg shift 29940c5344fSmrgdone 30040c5344fSmrg 30140c5344fSmrgif test -z "$ofile" || test -z "$cfile"; then 30240c5344fSmrg # If no '-o' option was seen then we might have been invoked from a 30340c5344fSmrg # pattern rule where we don't need one. That is ok -- this is a 30440c5344fSmrg # normal compilation that the losing compiler can handle. If no 30540c5344fSmrg # '.c' file was seen then we are probably linking. That is also 30640c5344fSmrg # ok. 30740c5344fSmrg exec "$@" 30840c5344fSmrgfi 30940c5344fSmrg 31040c5344fSmrg# Name of file we expect compiler to create. 31140c5344fSmrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31240c5344fSmrg 31340c5344fSmrg# Create the lock directory. 31440c5344fSmrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31540c5344fSmrg# that we are using for the .o file. Also, base the name on the expected 31640c5344fSmrg# object file name, since that is what matters with a parallel build. 31740c5344fSmrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31840c5344fSmrgwhile true; do 31940c5344fSmrg if mkdir "$lockdir" >/dev/null 2>&1; then 32040c5344fSmrg break 32140c5344fSmrg fi 32240c5344fSmrg sleep 1 32340c5344fSmrgdone 32440c5344fSmrg# FIXME: race condition here if user kills between mkdir and trap. 32540c5344fSmrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 32640c5344fSmrg 32740c5344fSmrg# Run the compile. 32840c5344fSmrg"$@" 32940c5344fSmrgret=$? 33040c5344fSmrg 33140c5344fSmrgif test -f "$cofile"; then 33240c5344fSmrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33340c5344fSmrgelif test -f "${cofile}bj"; then 33440c5344fSmrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33540c5344fSmrgfi 33640c5344fSmrg 33740c5344fSmrgrmdir "$lockdir" 33840c5344fSmrgexit $ret 33940c5344fSmrg 34040c5344fSmrg# Local Variables: 34140c5344fSmrg# mode: shell-script 34240c5344fSmrg# sh-indentation: 2 3436c3c2bceSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 34440c5344fSmrg# time-stamp-start: "scriptversion=" 34540c5344fSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 3466c3c2bceSmrg# time-stamp-time-zone: "UTC0" 34740c5344fSmrg# time-stamp-end: "; # UTC" 34840c5344fSmrg# End: 349