141667ceaSmrg#! /bin/sh 241667ceaSmrg# Wrapper for compilers which do not understand '-c -o'. 341667ceaSmrg 47fb93f23Smrgscriptversion=2018-03-07.03; # UTC 541667ceaSmrg 67fb93f23Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 741667ceaSmrg# Written by Tom Tromey <tromey@cygnus.com>. 841667ceaSmrg# 941667ceaSmrg# This program is free software; you can redistribute it and/or modify 1041667ceaSmrg# it under the terms of the GNU General Public License as published by 1141667ceaSmrg# the Free Software Foundation; either version 2, or (at your option) 1241667ceaSmrg# any later version. 1341667ceaSmrg# 1441667ceaSmrg# This program is distributed in the hope that it will be useful, 1541667ceaSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1641667ceaSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1741667ceaSmrg# GNU General Public License for more details. 1841667ceaSmrg# 1941667ceaSmrg# You should have received a copy of the GNU General Public License 207fb93f23Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2141667ceaSmrg 2241667ceaSmrg# As a special exception to the GNU General Public License, if you 2341667ceaSmrg# distribute this file as part of a program that contains a 2441667ceaSmrg# configuration script generated by Autoconf, you may include it under 2541667ceaSmrg# the same distribution terms that you use for the rest of that program. 2641667ceaSmrg 2741667ceaSmrg# This file is maintained in Automake, please report 2841667ceaSmrg# bugs to <bug-automake@gnu.org> or send patches to 2941667ceaSmrg# <automake-patches@gnu.org>. 3041667ceaSmrg 3141667ceaSmrgnl=' 3241667ceaSmrg' 3341667ceaSmrg 3441667ceaSmrg# We need space, tab and new line, in precisely that order. Quoting is 3541667ceaSmrg# there to prevent tools from complaining about whitespace usage. 3641667ceaSmrgIFS=" "" $nl" 3741667ceaSmrg 3841667ceaSmrgfile_conv= 3941667ceaSmrg 4041667ceaSmrg# func_file_conv build_file lazy 4141667ceaSmrg# Convert a $build file to $host form and store it in $file 4241667ceaSmrg# Currently only supports Windows hosts. If the determined conversion 4341667ceaSmrg# type is listed in (the comma separated) LAZY, no conversion will 4441667ceaSmrg# take place. 4541667ceaSmrgfunc_file_conv () 4641667ceaSmrg{ 4741667ceaSmrg file=$1 4841667ceaSmrg case $file in 4941667ceaSmrg / | /[!/]*) # absolute file, and not a UNC file 5041667ceaSmrg if test -z "$file_conv"; then 5141667ceaSmrg # lazily determine how to convert abs files 5241667ceaSmrg case `uname -s` in 5341667ceaSmrg MINGW*) 5441667ceaSmrg file_conv=mingw 5541667ceaSmrg ;; 567fb93f23Smrg CYGWIN* | MSYS*) 5741667ceaSmrg file_conv=cygwin 5841667ceaSmrg ;; 5941667ceaSmrg *) 6041667ceaSmrg file_conv=wine 6141667ceaSmrg ;; 6241667ceaSmrg esac 6341667ceaSmrg fi 6441667ceaSmrg case $file_conv/,$2, in 6541667ceaSmrg *,$file_conv,*) 6641667ceaSmrg ;; 6741667ceaSmrg mingw/*) 6841667ceaSmrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6941667ceaSmrg ;; 707fb93f23Smrg cygwin/* | msys/*) 7141667ceaSmrg file=`cygpath -m "$file" || echo "$file"` 7241667ceaSmrg ;; 7341667ceaSmrg wine/*) 7441667ceaSmrg file=`winepath -w "$file" || echo "$file"` 7541667ceaSmrg ;; 7641667ceaSmrg esac 7741667ceaSmrg ;; 7841667ceaSmrg esac 7941667ceaSmrg} 8041667ceaSmrg 8141667ceaSmrg# func_cl_dashL linkdir 8241667ceaSmrg# Make cl look for libraries in LINKDIR 8341667ceaSmrgfunc_cl_dashL () 8441667ceaSmrg{ 8541667ceaSmrg func_file_conv "$1" 8641667ceaSmrg if test -z "$lib_path"; then 8741667ceaSmrg lib_path=$file 8841667ceaSmrg else 8941667ceaSmrg lib_path="$lib_path;$file" 9041667ceaSmrg fi 9141667ceaSmrg linker_opts="$linker_opts -LIBPATH:$file" 9241667ceaSmrg} 9341667ceaSmrg 9441667ceaSmrg# func_cl_dashl library 9541667ceaSmrg# Do a library search-path lookup for cl 9641667ceaSmrgfunc_cl_dashl () 9741667ceaSmrg{ 9841667ceaSmrg lib=$1 9941667ceaSmrg found=no 10041667ceaSmrg save_IFS=$IFS 10141667ceaSmrg IFS=';' 10241667ceaSmrg for dir in $lib_path $LIB 10341667ceaSmrg do 10441667ceaSmrg IFS=$save_IFS 10541667ceaSmrg if $shared && test -f "$dir/$lib.dll.lib"; then 10641667ceaSmrg found=yes 10741667ceaSmrg lib=$dir/$lib.dll.lib 10841667ceaSmrg break 10941667ceaSmrg fi 11041667ceaSmrg if test -f "$dir/$lib.lib"; then 11141667ceaSmrg found=yes 11241667ceaSmrg lib=$dir/$lib.lib 11341667ceaSmrg break 11441667ceaSmrg fi 11541667ceaSmrg if test -f "$dir/lib$lib.a"; then 11641667ceaSmrg found=yes 11741667ceaSmrg lib=$dir/lib$lib.a 11841667ceaSmrg break 11941667ceaSmrg fi 12041667ceaSmrg done 12141667ceaSmrg IFS=$save_IFS 12241667ceaSmrg 12341667ceaSmrg if test "$found" != yes; then 12441667ceaSmrg lib=$lib.lib 12541667ceaSmrg fi 12641667ceaSmrg} 12741667ceaSmrg 12841667ceaSmrg# func_cl_wrapper cl arg... 12941667ceaSmrg# Adjust compile command to suit cl 13041667ceaSmrgfunc_cl_wrapper () 13141667ceaSmrg{ 13241667ceaSmrg # Assume a capable shell 13341667ceaSmrg lib_path= 13441667ceaSmrg shared=: 13541667ceaSmrg linker_opts= 13641667ceaSmrg for arg 13741667ceaSmrg do 13841667ceaSmrg if test -n "$eat"; then 13941667ceaSmrg eat= 14041667ceaSmrg else 14141667ceaSmrg case $1 in 14241667ceaSmrg -o) 14341667ceaSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 14441667ceaSmrg eat=1 14541667ceaSmrg case $2 in 14641667ceaSmrg *.o | *.[oO][bB][jJ]) 14741667ceaSmrg func_file_conv "$2" 14841667ceaSmrg set x "$@" -Fo"$file" 14941667ceaSmrg shift 15041667ceaSmrg ;; 15141667ceaSmrg *) 15241667ceaSmrg func_file_conv "$2" 15341667ceaSmrg set x "$@" -Fe"$file" 15441667ceaSmrg shift 15541667ceaSmrg ;; 15641667ceaSmrg esac 15741667ceaSmrg ;; 15841667ceaSmrg -I) 15941667ceaSmrg eat=1 16041667ceaSmrg func_file_conv "$2" mingw 16141667ceaSmrg set x "$@" -I"$file" 16241667ceaSmrg shift 16341667ceaSmrg ;; 16441667ceaSmrg -I*) 16541667ceaSmrg func_file_conv "${1#-I}" mingw 16641667ceaSmrg set x "$@" -I"$file" 16741667ceaSmrg shift 16841667ceaSmrg ;; 16941667ceaSmrg -l) 17041667ceaSmrg eat=1 17141667ceaSmrg func_cl_dashl "$2" 17241667ceaSmrg set x "$@" "$lib" 17341667ceaSmrg shift 17441667ceaSmrg ;; 17541667ceaSmrg -l*) 17641667ceaSmrg func_cl_dashl "${1#-l}" 17741667ceaSmrg set x "$@" "$lib" 17841667ceaSmrg shift 17941667ceaSmrg ;; 18041667ceaSmrg -L) 18141667ceaSmrg eat=1 18241667ceaSmrg func_cl_dashL "$2" 18341667ceaSmrg ;; 18441667ceaSmrg -L*) 18541667ceaSmrg func_cl_dashL "${1#-L}" 18641667ceaSmrg ;; 18741667ceaSmrg -static) 18841667ceaSmrg shared=false 18941667ceaSmrg ;; 19041667ceaSmrg -Wl,*) 19141667ceaSmrg arg=${1#-Wl,} 19241667ceaSmrg save_ifs="$IFS"; IFS=',' 19341667ceaSmrg for flag in $arg; do 19441667ceaSmrg IFS="$save_ifs" 19541667ceaSmrg linker_opts="$linker_opts $flag" 19641667ceaSmrg done 19741667ceaSmrg IFS="$save_ifs" 19841667ceaSmrg ;; 19941667ceaSmrg -Xlinker) 20041667ceaSmrg eat=1 20141667ceaSmrg linker_opts="$linker_opts $2" 20241667ceaSmrg ;; 20341667ceaSmrg -*) 20441667ceaSmrg set x "$@" "$1" 20541667ceaSmrg shift 20641667ceaSmrg ;; 20741667ceaSmrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20841667ceaSmrg func_file_conv "$1" 20941667ceaSmrg set x "$@" -Tp"$file" 21041667ceaSmrg shift 21141667ceaSmrg ;; 21241667ceaSmrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21341667ceaSmrg func_file_conv "$1" mingw 21441667ceaSmrg set x "$@" "$file" 21541667ceaSmrg shift 21641667ceaSmrg ;; 21741667ceaSmrg *) 21841667ceaSmrg set x "$@" "$1" 21941667ceaSmrg shift 22041667ceaSmrg ;; 22141667ceaSmrg esac 22241667ceaSmrg fi 22341667ceaSmrg shift 22441667ceaSmrg done 22541667ceaSmrg if test -n "$linker_opts"; then 22641667ceaSmrg linker_opts="-link$linker_opts" 22741667ceaSmrg fi 22841667ceaSmrg exec "$@" $linker_opts 22941667ceaSmrg exit 1 23041667ceaSmrg} 23141667ceaSmrg 23241667ceaSmrgeat= 23341667ceaSmrg 23441667ceaSmrgcase $1 in 23541667ceaSmrg '') 23641667ceaSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 23741667ceaSmrg exit 1; 23841667ceaSmrg ;; 23941667ceaSmrg -h | --h*) 24041667ceaSmrg cat <<\EOF 24141667ceaSmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 24241667ceaSmrg 24341667ceaSmrgWrapper for compilers which do not understand '-c -o'. 24441667ceaSmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24541667ceaSmrgarguments, and rename the output as expected. 24641667ceaSmrg 24741667ceaSmrgIf you are trying to build a whole package this is not the 24841667ceaSmrgright script to run: please start by reading the file 'INSTALL'. 24941667ceaSmrg 25041667ceaSmrgReport bugs to <bug-automake@gnu.org>. 25141667ceaSmrgEOF 25241667ceaSmrg exit $? 25341667ceaSmrg ;; 25441667ceaSmrg -v | --v*) 25541667ceaSmrg echo "compile $scriptversion" 25641667ceaSmrg exit $? 25741667ceaSmrg ;; 2587fb93f23Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 2597fb93f23Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 26041667ceaSmrg func_cl_wrapper "$@" # Doesn't return... 26141667ceaSmrg ;; 26241667ceaSmrgesac 26341667ceaSmrg 26441667ceaSmrgofile= 26541667ceaSmrgcfile= 26641667ceaSmrg 26741667ceaSmrgfor arg 26841667ceaSmrgdo 26941667ceaSmrg if test -n "$eat"; then 27041667ceaSmrg eat= 27141667ceaSmrg else 27241667ceaSmrg case $1 in 27341667ceaSmrg -o) 27441667ceaSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 27541667ceaSmrg # So we strip '-o arg' only if arg is an object. 27641667ceaSmrg eat=1 27741667ceaSmrg case $2 in 27841667ceaSmrg *.o | *.obj) 27941667ceaSmrg ofile=$2 28041667ceaSmrg ;; 28141667ceaSmrg *) 28241667ceaSmrg set x "$@" -o "$2" 28341667ceaSmrg shift 28441667ceaSmrg ;; 28541667ceaSmrg esac 28641667ceaSmrg ;; 28741667ceaSmrg *.c) 28841667ceaSmrg cfile=$1 28941667ceaSmrg set x "$@" "$1" 29041667ceaSmrg shift 29141667ceaSmrg ;; 29241667ceaSmrg *) 29341667ceaSmrg set x "$@" "$1" 29441667ceaSmrg shift 29541667ceaSmrg ;; 29641667ceaSmrg esac 29741667ceaSmrg fi 29841667ceaSmrg shift 29941667ceaSmrgdone 30041667ceaSmrg 30141667ceaSmrgif test -z "$ofile" || test -z "$cfile"; then 30241667ceaSmrg # If no '-o' option was seen then we might have been invoked from a 30341667ceaSmrg # pattern rule where we don't need one. That is ok -- this is a 30441667ceaSmrg # normal compilation that the losing compiler can handle. If no 30541667ceaSmrg # '.c' file was seen then we are probably linking. That is also 30641667ceaSmrg # ok. 30741667ceaSmrg exec "$@" 30841667ceaSmrgfi 30941667ceaSmrg 31041667ceaSmrg# Name of file we expect compiler to create. 31141667ceaSmrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31241667ceaSmrg 31341667ceaSmrg# Create the lock directory. 31441667ceaSmrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31541667ceaSmrg# that we are using for the .o file. Also, base the name on the expected 31641667ceaSmrg# object file name, since that is what matters with a parallel build. 31741667ceaSmrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31841667ceaSmrgwhile true; do 31941667ceaSmrg if mkdir "$lockdir" >/dev/null 2>&1; then 32041667ceaSmrg break 32141667ceaSmrg fi 32241667ceaSmrg sleep 1 32341667ceaSmrgdone 32441667ceaSmrg# FIXME: race condition here if user kills between mkdir and trap. 32541667ceaSmrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 32641667ceaSmrg 32741667ceaSmrg# Run the compile. 32841667ceaSmrg"$@" 32941667ceaSmrgret=$? 33041667ceaSmrg 33141667ceaSmrgif test -f "$cofile"; then 33241667ceaSmrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33341667ceaSmrgelif test -f "${cofile}bj"; then 33441667ceaSmrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33541667ceaSmrgfi 33641667ceaSmrg 33741667ceaSmrgrmdir "$lockdir" 33841667ceaSmrgexit $ret 33941667ceaSmrg 34041667ceaSmrg# Local Variables: 34141667ceaSmrg# mode: shell-script 34241667ceaSmrg# sh-indentation: 2 3437fb93f23Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 34441667ceaSmrg# time-stamp-start: "scriptversion=" 34541667ceaSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 3467fb93f23Smrg# time-stamp-time-zone: "UTC0" 34741667ceaSmrg# time-stamp-end: "; # UTC" 34841667ceaSmrg# End: 349