compile revision a67f45c3
176910425Smrg#! /bin/sh 29ff100acSmrg# Wrapper for compilers which do not understand '-c -o'. 376910425Smrg 4a67f45c3Smrgscriptversion=2018-03-07.03; # UTC 576910425Smrg 6a67f45c3Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 776910425Smrg# Written by Tom Tromey <tromey@cygnus.com>. 876910425Smrg# 976910425Smrg# This program is free software; you can redistribute it and/or modify 1076910425Smrg# it under the terms of the GNU General Public License as published by 1176910425Smrg# the Free Software Foundation; either version 2, or (at your option) 1276910425Smrg# any later version. 1376910425Smrg# 1476910425Smrg# This program is distributed in the hope that it will be useful, 1576910425Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1676910425Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1776910425Smrg# GNU General Public License for more details. 1876910425Smrg# 1976910425Smrg# You should have received a copy of the GNU General Public License 20a67f45c3Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2176910425Smrg 2276910425Smrg# As a special exception to the GNU General Public License, if you 2376910425Smrg# distribute this file as part of a program that contains a 2476910425Smrg# configuration script generated by Autoconf, you may include it under 2576910425Smrg# the same distribution terms that you use for the rest of that program. 2676910425Smrg 2776910425Smrg# This file is maintained in Automake, please report 2876910425Smrg# bugs to <bug-automake@gnu.org> or send patches to 2976910425Smrg# <automake-patches@gnu.org>. 3076910425Smrg 319ff100acSmrgnl=' 329ff100acSmrg' 339ff100acSmrg 349ff100acSmrg# We need space, tab and new line, in precisely that order. Quoting is 359ff100acSmrg# there to prevent tools from complaining about whitespace usage. 369ff100acSmrgIFS=" "" $nl" 379ff100acSmrg 389ff100acSmrgfile_conv= 399ff100acSmrg 409ff100acSmrg# func_file_conv build_file lazy 419ff100acSmrg# Convert a $build file to $host form and store it in $file 429ff100acSmrg# Currently only supports Windows hosts. If the determined conversion 439ff100acSmrg# type is listed in (the comma separated) LAZY, no conversion will 449ff100acSmrg# take place. 459ff100acSmrgfunc_file_conv () 469ff100acSmrg{ 479ff100acSmrg file=$1 489ff100acSmrg case $file in 499ff100acSmrg / | /[!/]*) # absolute file, and not a UNC file 509ff100acSmrg if test -z "$file_conv"; then 519ff100acSmrg # lazily determine how to convert abs files 529ff100acSmrg case `uname -s` in 539ff100acSmrg MINGW*) 549ff100acSmrg file_conv=mingw 559ff100acSmrg ;; 56a67f45c3Smrg CYGWIN* | MSYS*) 579ff100acSmrg file_conv=cygwin 589ff100acSmrg ;; 599ff100acSmrg *) 609ff100acSmrg file_conv=wine 619ff100acSmrg ;; 629ff100acSmrg esac 639ff100acSmrg fi 649ff100acSmrg case $file_conv/,$2, in 659ff100acSmrg *,$file_conv,*) 669ff100acSmrg ;; 679ff100acSmrg mingw/*) 689ff100acSmrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 699ff100acSmrg ;; 70a67f45c3Smrg cygwin/* | msys/*) 719ff100acSmrg file=`cygpath -m "$file" || echo "$file"` 729ff100acSmrg ;; 739ff100acSmrg wine/*) 749ff100acSmrg file=`winepath -w "$file" || echo "$file"` 759ff100acSmrg ;; 769ff100acSmrg esac 779ff100acSmrg ;; 789ff100acSmrg esac 799ff100acSmrg} 809ff100acSmrg 819ff100acSmrg# func_cl_dashL linkdir 829ff100acSmrg# Make cl look for libraries in LINKDIR 839ff100acSmrgfunc_cl_dashL () 849ff100acSmrg{ 859ff100acSmrg func_file_conv "$1" 869ff100acSmrg if test -z "$lib_path"; then 879ff100acSmrg lib_path=$file 889ff100acSmrg else 899ff100acSmrg lib_path="$lib_path;$file" 909ff100acSmrg fi 919ff100acSmrg linker_opts="$linker_opts -LIBPATH:$file" 929ff100acSmrg} 939ff100acSmrg 949ff100acSmrg# func_cl_dashl library 959ff100acSmrg# Do a library search-path lookup for cl 969ff100acSmrgfunc_cl_dashl () 979ff100acSmrg{ 989ff100acSmrg lib=$1 999ff100acSmrg found=no 1009ff100acSmrg save_IFS=$IFS 1019ff100acSmrg IFS=';' 1029ff100acSmrg for dir in $lib_path $LIB 1039ff100acSmrg do 1049ff100acSmrg IFS=$save_IFS 1059ff100acSmrg if $shared && test -f "$dir/$lib.dll.lib"; then 1069ff100acSmrg found=yes 1079ff100acSmrg lib=$dir/$lib.dll.lib 1089ff100acSmrg break 1099ff100acSmrg fi 1109ff100acSmrg if test -f "$dir/$lib.lib"; then 1119ff100acSmrg found=yes 1129ff100acSmrg lib=$dir/$lib.lib 1139ff100acSmrg break 1149ff100acSmrg fi 1159ff100acSmrg if test -f "$dir/lib$lib.a"; then 1169ff100acSmrg found=yes 1179ff100acSmrg lib=$dir/lib$lib.a 1189ff100acSmrg break 1199ff100acSmrg fi 1209ff100acSmrg done 1219ff100acSmrg IFS=$save_IFS 1229ff100acSmrg 1239ff100acSmrg if test "$found" != yes; then 1249ff100acSmrg lib=$lib.lib 1259ff100acSmrg fi 1269ff100acSmrg} 1279ff100acSmrg 1289ff100acSmrg# func_cl_wrapper cl arg... 1299ff100acSmrg# Adjust compile command to suit cl 1309ff100acSmrgfunc_cl_wrapper () 1319ff100acSmrg{ 1329ff100acSmrg # Assume a capable shell 1339ff100acSmrg lib_path= 1349ff100acSmrg shared=: 1359ff100acSmrg linker_opts= 1369ff100acSmrg for arg 1379ff100acSmrg do 1389ff100acSmrg if test -n "$eat"; then 1399ff100acSmrg eat= 1409ff100acSmrg else 1419ff100acSmrg case $1 in 1429ff100acSmrg -o) 1439ff100acSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 1449ff100acSmrg eat=1 1459ff100acSmrg case $2 in 1469ff100acSmrg *.o | *.[oO][bB][jJ]) 1479ff100acSmrg func_file_conv "$2" 1489ff100acSmrg set x "$@" -Fo"$file" 1499ff100acSmrg shift 1509ff100acSmrg ;; 1519ff100acSmrg *) 1529ff100acSmrg func_file_conv "$2" 1539ff100acSmrg set x "$@" -Fe"$file" 1549ff100acSmrg shift 1559ff100acSmrg ;; 1569ff100acSmrg esac 1579ff100acSmrg ;; 1589ff100acSmrg -I) 1599ff100acSmrg eat=1 1609ff100acSmrg func_file_conv "$2" mingw 1619ff100acSmrg set x "$@" -I"$file" 1629ff100acSmrg shift 1639ff100acSmrg ;; 1649ff100acSmrg -I*) 1659ff100acSmrg func_file_conv "${1#-I}" mingw 1669ff100acSmrg set x "$@" -I"$file" 1679ff100acSmrg shift 1689ff100acSmrg ;; 1699ff100acSmrg -l) 1709ff100acSmrg eat=1 1719ff100acSmrg func_cl_dashl "$2" 1729ff100acSmrg set x "$@" "$lib" 1739ff100acSmrg shift 1749ff100acSmrg ;; 1759ff100acSmrg -l*) 1769ff100acSmrg func_cl_dashl "${1#-l}" 1779ff100acSmrg set x "$@" "$lib" 1789ff100acSmrg shift 1799ff100acSmrg ;; 1809ff100acSmrg -L) 1819ff100acSmrg eat=1 1829ff100acSmrg func_cl_dashL "$2" 1839ff100acSmrg ;; 1849ff100acSmrg -L*) 1859ff100acSmrg func_cl_dashL "${1#-L}" 1869ff100acSmrg ;; 1879ff100acSmrg -static) 1889ff100acSmrg shared=false 1899ff100acSmrg ;; 1909ff100acSmrg -Wl,*) 1919ff100acSmrg arg=${1#-Wl,} 1929ff100acSmrg save_ifs="$IFS"; IFS=',' 1939ff100acSmrg for flag in $arg; do 1949ff100acSmrg IFS="$save_ifs" 1959ff100acSmrg linker_opts="$linker_opts $flag" 1969ff100acSmrg done 1979ff100acSmrg IFS="$save_ifs" 1989ff100acSmrg ;; 1999ff100acSmrg -Xlinker) 2009ff100acSmrg eat=1 2019ff100acSmrg linker_opts="$linker_opts $2" 2029ff100acSmrg ;; 2039ff100acSmrg -*) 2049ff100acSmrg set x "$@" "$1" 2059ff100acSmrg shift 2069ff100acSmrg ;; 2079ff100acSmrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 2089ff100acSmrg func_file_conv "$1" 2099ff100acSmrg set x "$@" -Tp"$file" 2109ff100acSmrg shift 2119ff100acSmrg ;; 2129ff100acSmrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2139ff100acSmrg func_file_conv "$1" mingw 2149ff100acSmrg set x "$@" "$file" 2159ff100acSmrg shift 2169ff100acSmrg ;; 2179ff100acSmrg *) 2189ff100acSmrg set x "$@" "$1" 2199ff100acSmrg shift 2209ff100acSmrg ;; 2219ff100acSmrg esac 2229ff100acSmrg fi 2239ff100acSmrg shift 2249ff100acSmrg done 2259ff100acSmrg if test -n "$linker_opts"; then 2269ff100acSmrg linker_opts="-link$linker_opts" 2279ff100acSmrg fi 2289ff100acSmrg exec "$@" $linker_opts 2299ff100acSmrg exit 1 2309ff100acSmrg} 2319ff100acSmrg 2329ff100acSmrgeat= 2339ff100acSmrg 23476910425Smrgcase $1 in 23576910425Smrg '') 2369ff100acSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 23776910425Smrg exit 1; 23876910425Smrg ;; 23976910425Smrg -h | --h*) 24076910425Smrg cat <<\EOF 24176910425SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 24276910425Smrg 2439ff100acSmrgWrapper for compilers which do not understand '-c -o'. 2449ff100acSmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24576910425Smrgarguments, and rename the output as expected. 24676910425Smrg 24776910425SmrgIf you are trying to build a whole package this is not the 2489ff100acSmrgright script to run: please start by reading the file 'INSTALL'. 24976910425Smrg 25076910425SmrgReport bugs to <bug-automake@gnu.org>. 25176910425SmrgEOF 25276910425Smrg exit $? 25376910425Smrg ;; 25476910425Smrg -v | --v*) 25576910425Smrg echo "compile $scriptversion" 25676910425Smrg exit $? 25776910425Smrg ;; 258a67f45c3Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 259a67f45c3Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 2609ff100acSmrg func_cl_wrapper "$@" # Doesn't return... 2619ff100acSmrg ;; 26276910425Smrgesac 26376910425Smrg 26476910425Smrgofile= 26576910425Smrgcfile= 26676910425Smrg 26776910425Smrgfor arg 26876910425Smrgdo 26976910425Smrg if test -n "$eat"; then 27076910425Smrg eat= 27176910425Smrg else 27276910425Smrg case $1 in 27376910425Smrg -o) 2749ff100acSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 2759ff100acSmrg # So we strip '-o arg' only if arg is an object. 27676910425Smrg eat=1 27776910425Smrg case $2 in 27876910425Smrg *.o | *.obj) 27976910425Smrg ofile=$2 28076910425Smrg ;; 28176910425Smrg *) 28276910425Smrg set x "$@" -o "$2" 28376910425Smrg shift 28476910425Smrg ;; 28576910425Smrg esac 28676910425Smrg ;; 28776910425Smrg *.c) 28876910425Smrg cfile=$1 28976910425Smrg set x "$@" "$1" 29076910425Smrg shift 29176910425Smrg ;; 29276910425Smrg *) 29376910425Smrg set x "$@" "$1" 29476910425Smrg shift 29576910425Smrg ;; 29676910425Smrg esac 29776910425Smrg fi 29876910425Smrg shift 29976910425Smrgdone 30076910425Smrg 30176910425Smrgif test -z "$ofile" || test -z "$cfile"; then 3029ff100acSmrg # If no '-o' option was seen then we might have been invoked from a 30376910425Smrg # pattern rule where we don't need one. That is ok -- this is a 30476910425Smrg # normal compilation that the losing compiler can handle. If no 3059ff100acSmrg # '.c' file was seen then we are probably linking. That is also 30676910425Smrg # ok. 30776910425Smrg exec "$@" 30876910425Smrgfi 30976910425Smrg 31076910425Smrg# Name of file we expect compiler to create. 3119ff100acSmrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31276910425Smrg 31376910425Smrg# Create the lock directory. 3149ff100acSmrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31576910425Smrg# that we are using for the .o file. Also, base the name on the expected 31676910425Smrg# object file name, since that is what matters with a parallel build. 3179ff100acSmrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31876910425Smrgwhile true; do 31976910425Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 32076910425Smrg break 32176910425Smrg fi 32276910425Smrg sleep 1 32376910425Smrgdone 32476910425Smrg# FIXME: race condition here if user kills between mkdir and trap. 32576910425Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 32676910425Smrg 32776910425Smrg# Run the compile. 32876910425Smrg"$@" 32976910425Smrgret=$? 33076910425Smrg 33176910425Smrgif test -f "$cofile"; then 3329ff100acSmrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33376910425Smrgelif test -f "${cofile}bj"; then 3349ff100acSmrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33576910425Smrgfi 33676910425Smrg 33776910425Smrgrmdir "$lockdir" 33876910425Smrgexit $ret 33976910425Smrg 34076910425Smrg# Local Variables: 34176910425Smrg# mode: shell-script 34276910425Smrg# sh-indentation: 2 343a67f45c3Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 34476910425Smrg# time-stamp-start: "scriptversion=" 34576910425Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 346a67f45c3Smrg# time-stamp-time-zone: "UTC0" 3479ff100acSmrg# time-stamp-end: "; # UTC" 34876910425Smrg# End: 349