180f56f3aSmrg#! /bin/sh 280f56f3aSmrg# Wrapper for compilers which do not understand '-c -o'. 380f56f3aSmrg 4138a9f8aSmrgscriptversion=2018-03-07.03; # UTC 580f56f3aSmrg 6138a9f8aSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 780f56f3aSmrg# Written by Tom Tromey <tromey@cygnus.com>. 880f56f3aSmrg# 980f56f3aSmrg# This program is free software; you can redistribute it and/or modify 1080f56f3aSmrg# it under the terms of the GNU General Public License as published by 1180f56f3aSmrg# the Free Software Foundation; either version 2, or (at your option) 1280f56f3aSmrg# any later version. 1380f56f3aSmrg# 1480f56f3aSmrg# This program is distributed in the hope that it will be useful, 1580f56f3aSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1680f56f3aSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1780f56f3aSmrg# GNU General Public License for more details. 1880f56f3aSmrg# 1980f56f3aSmrg# You should have received a copy of the GNU General Public License 20138a9f8aSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2180f56f3aSmrg 2280f56f3aSmrg# As a special exception to the GNU General Public License, if you 2380f56f3aSmrg# distribute this file as part of a program that contains a 2480f56f3aSmrg# configuration script generated by Autoconf, you may include it under 2580f56f3aSmrg# the same distribution terms that you use for the rest of that program. 2680f56f3aSmrg 2780f56f3aSmrg# This file is maintained in Automake, please report 2880f56f3aSmrg# bugs to <bug-automake@gnu.org> or send patches to 2980f56f3aSmrg# <automake-patches@gnu.org>. 3080f56f3aSmrg 3180f56f3aSmrgnl=' 3280f56f3aSmrg' 3380f56f3aSmrg 3480f56f3aSmrg# We need space, tab and new line, in precisely that order. Quoting is 3580f56f3aSmrg# there to prevent tools from complaining about whitespace usage. 3680f56f3aSmrgIFS=" "" $nl" 3780f56f3aSmrg 3880f56f3aSmrgfile_conv= 3980f56f3aSmrg 4080f56f3aSmrg# func_file_conv build_file lazy 4180f56f3aSmrg# Convert a $build file to $host form and store it in $file 4280f56f3aSmrg# Currently only supports Windows hosts. If the determined conversion 4380f56f3aSmrg# type is listed in (the comma separated) LAZY, no conversion will 4480f56f3aSmrg# take place. 4580f56f3aSmrgfunc_file_conv () 4680f56f3aSmrg{ 4780f56f3aSmrg file=$1 4880f56f3aSmrg case $file in 4980f56f3aSmrg / | /[!/]*) # absolute file, and not a UNC file 5080f56f3aSmrg if test -z "$file_conv"; then 5180f56f3aSmrg # lazily determine how to convert abs files 5280f56f3aSmrg case `uname -s` in 5380f56f3aSmrg MINGW*) 5480f56f3aSmrg file_conv=mingw 5580f56f3aSmrg ;; 56138a9f8aSmrg CYGWIN* | MSYS*) 5780f56f3aSmrg file_conv=cygwin 5880f56f3aSmrg ;; 5980f56f3aSmrg *) 6080f56f3aSmrg file_conv=wine 6180f56f3aSmrg ;; 6280f56f3aSmrg esac 6380f56f3aSmrg fi 6480f56f3aSmrg case $file_conv/,$2, in 6580f56f3aSmrg *,$file_conv,*) 6680f56f3aSmrg ;; 6780f56f3aSmrg mingw/*) 6880f56f3aSmrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6980f56f3aSmrg ;; 70138a9f8aSmrg cygwin/* | msys/*) 7180f56f3aSmrg file=`cygpath -m "$file" || echo "$file"` 7280f56f3aSmrg ;; 7380f56f3aSmrg wine/*) 7480f56f3aSmrg file=`winepath -w "$file" || echo "$file"` 7580f56f3aSmrg ;; 7680f56f3aSmrg esac 7780f56f3aSmrg ;; 7880f56f3aSmrg esac 7980f56f3aSmrg} 8080f56f3aSmrg 8180f56f3aSmrg# func_cl_dashL linkdir 8280f56f3aSmrg# Make cl look for libraries in LINKDIR 8380f56f3aSmrgfunc_cl_dashL () 8480f56f3aSmrg{ 8580f56f3aSmrg func_file_conv "$1" 8680f56f3aSmrg if test -z "$lib_path"; then 8780f56f3aSmrg lib_path=$file 8880f56f3aSmrg else 8980f56f3aSmrg lib_path="$lib_path;$file" 9080f56f3aSmrg fi 9180f56f3aSmrg linker_opts="$linker_opts -LIBPATH:$file" 9280f56f3aSmrg} 9380f56f3aSmrg 9480f56f3aSmrg# func_cl_dashl library 9580f56f3aSmrg# Do a library search-path lookup for cl 9680f56f3aSmrgfunc_cl_dashl () 9780f56f3aSmrg{ 9880f56f3aSmrg lib=$1 9980f56f3aSmrg found=no 10080f56f3aSmrg save_IFS=$IFS 10180f56f3aSmrg IFS=';' 10280f56f3aSmrg for dir in $lib_path $LIB 10380f56f3aSmrg do 10480f56f3aSmrg IFS=$save_IFS 10580f56f3aSmrg if $shared && test -f "$dir/$lib.dll.lib"; then 10680f56f3aSmrg found=yes 10780f56f3aSmrg lib=$dir/$lib.dll.lib 10880f56f3aSmrg break 10980f56f3aSmrg fi 11080f56f3aSmrg if test -f "$dir/$lib.lib"; then 11180f56f3aSmrg found=yes 11280f56f3aSmrg lib=$dir/$lib.lib 11380f56f3aSmrg break 11480f56f3aSmrg fi 11580f56f3aSmrg if test -f "$dir/lib$lib.a"; then 11680f56f3aSmrg found=yes 11780f56f3aSmrg lib=$dir/lib$lib.a 11880f56f3aSmrg break 11980f56f3aSmrg fi 12080f56f3aSmrg done 12180f56f3aSmrg IFS=$save_IFS 12280f56f3aSmrg 12380f56f3aSmrg if test "$found" != yes; then 12480f56f3aSmrg lib=$lib.lib 12580f56f3aSmrg fi 12680f56f3aSmrg} 12780f56f3aSmrg 12880f56f3aSmrg# func_cl_wrapper cl arg... 12980f56f3aSmrg# Adjust compile command to suit cl 13080f56f3aSmrgfunc_cl_wrapper () 13180f56f3aSmrg{ 13280f56f3aSmrg # Assume a capable shell 13380f56f3aSmrg lib_path= 13480f56f3aSmrg shared=: 13580f56f3aSmrg linker_opts= 13680f56f3aSmrg for arg 13780f56f3aSmrg do 13880f56f3aSmrg if test -n "$eat"; then 13980f56f3aSmrg eat= 14080f56f3aSmrg else 14180f56f3aSmrg case $1 in 14280f56f3aSmrg -o) 14380f56f3aSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 14480f56f3aSmrg eat=1 14580f56f3aSmrg case $2 in 14680f56f3aSmrg *.o | *.[oO][bB][jJ]) 14780f56f3aSmrg func_file_conv "$2" 14880f56f3aSmrg set x "$@" -Fo"$file" 14980f56f3aSmrg shift 15080f56f3aSmrg ;; 15180f56f3aSmrg *) 15280f56f3aSmrg func_file_conv "$2" 15380f56f3aSmrg set x "$@" -Fe"$file" 15480f56f3aSmrg shift 15580f56f3aSmrg ;; 15680f56f3aSmrg esac 15780f56f3aSmrg ;; 15880f56f3aSmrg -I) 15980f56f3aSmrg eat=1 16080f56f3aSmrg func_file_conv "$2" mingw 16180f56f3aSmrg set x "$@" -I"$file" 16280f56f3aSmrg shift 16380f56f3aSmrg ;; 16480f56f3aSmrg -I*) 16580f56f3aSmrg func_file_conv "${1#-I}" mingw 16680f56f3aSmrg set x "$@" -I"$file" 16780f56f3aSmrg shift 16880f56f3aSmrg ;; 16980f56f3aSmrg -l) 17080f56f3aSmrg eat=1 17180f56f3aSmrg func_cl_dashl "$2" 17280f56f3aSmrg set x "$@" "$lib" 17380f56f3aSmrg shift 17480f56f3aSmrg ;; 17580f56f3aSmrg -l*) 17680f56f3aSmrg func_cl_dashl "${1#-l}" 17780f56f3aSmrg set x "$@" "$lib" 17880f56f3aSmrg shift 17980f56f3aSmrg ;; 18080f56f3aSmrg -L) 18180f56f3aSmrg eat=1 18280f56f3aSmrg func_cl_dashL "$2" 18380f56f3aSmrg ;; 18480f56f3aSmrg -L*) 18580f56f3aSmrg func_cl_dashL "${1#-L}" 18680f56f3aSmrg ;; 18780f56f3aSmrg -static) 18880f56f3aSmrg shared=false 18980f56f3aSmrg ;; 19080f56f3aSmrg -Wl,*) 19180f56f3aSmrg arg=${1#-Wl,} 19280f56f3aSmrg save_ifs="$IFS"; IFS=',' 19380f56f3aSmrg for flag in $arg; do 19480f56f3aSmrg IFS="$save_ifs" 19580f56f3aSmrg linker_opts="$linker_opts $flag" 19680f56f3aSmrg done 19780f56f3aSmrg IFS="$save_ifs" 19880f56f3aSmrg ;; 19980f56f3aSmrg -Xlinker) 20080f56f3aSmrg eat=1 20180f56f3aSmrg linker_opts="$linker_opts $2" 20280f56f3aSmrg ;; 20380f56f3aSmrg -*) 20480f56f3aSmrg set x "$@" "$1" 20580f56f3aSmrg shift 20680f56f3aSmrg ;; 20780f56f3aSmrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20880f56f3aSmrg func_file_conv "$1" 20980f56f3aSmrg set x "$@" -Tp"$file" 21080f56f3aSmrg shift 21180f56f3aSmrg ;; 21280f56f3aSmrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21380f56f3aSmrg func_file_conv "$1" mingw 21480f56f3aSmrg set x "$@" "$file" 21580f56f3aSmrg shift 21680f56f3aSmrg ;; 21780f56f3aSmrg *) 21880f56f3aSmrg set x "$@" "$1" 21980f56f3aSmrg shift 22080f56f3aSmrg ;; 22180f56f3aSmrg esac 22280f56f3aSmrg fi 22380f56f3aSmrg shift 22480f56f3aSmrg done 22580f56f3aSmrg if test -n "$linker_opts"; then 22680f56f3aSmrg linker_opts="-link$linker_opts" 22780f56f3aSmrg fi 22880f56f3aSmrg exec "$@" $linker_opts 22980f56f3aSmrg exit 1 23080f56f3aSmrg} 23180f56f3aSmrg 23280f56f3aSmrgeat= 23380f56f3aSmrg 23480f56f3aSmrgcase $1 in 23580f56f3aSmrg '') 23680f56f3aSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 23780f56f3aSmrg exit 1; 23880f56f3aSmrg ;; 23980f56f3aSmrg -h | --h*) 24080f56f3aSmrg cat <<\EOF 24180f56f3aSmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 24280f56f3aSmrg 24380f56f3aSmrgWrapper for compilers which do not understand '-c -o'. 24480f56f3aSmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24580f56f3aSmrgarguments, and rename the output as expected. 24680f56f3aSmrg 24780f56f3aSmrgIf you are trying to build a whole package this is not the 24880f56f3aSmrgright script to run: please start by reading the file 'INSTALL'. 24980f56f3aSmrg 25080f56f3aSmrgReport bugs to <bug-automake@gnu.org>. 25180f56f3aSmrgEOF 25280f56f3aSmrg exit $? 25380f56f3aSmrg ;; 25480f56f3aSmrg -v | --v*) 25580f56f3aSmrg echo "compile $scriptversion" 25680f56f3aSmrg exit $? 25780f56f3aSmrg ;; 258138a9f8aSmrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 259138a9f8aSmrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 26080f56f3aSmrg func_cl_wrapper "$@" # Doesn't return... 26180f56f3aSmrg ;; 26280f56f3aSmrgesac 26380f56f3aSmrg 26480f56f3aSmrgofile= 26580f56f3aSmrgcfile= 26680f56f3aSmrg 26780f56f3aSmrgfor arg 26880f56f3aSmrgdo 26980f56f3aSmrg if test -n "$eat"; then 27080f56f3aSmrg eat= 27180f56f3aSmrg else 27280f56f3aSmrg case $1 in 27380f56f3aSmrg -o) 27480f56f3aSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 27580f56f3aSmrg # So we strip '-o arg' only if arg is an object. 27680f56f3aSmrg eat=1 27780f56f3aSmrg case $2 in 27880f56f3aSmrg *.o | *.obj) 27980f56f3aSmrg ofile=$2 28080f56f3aSmrg ;; 28180f56f3aSmrg *) 28280f56f3aSmrg set x "$@" -o "$2" 28380f56f3aSmrg shift 28480f56f3aSmrg ;; 28580f56f3aSmrg esac 28680f56f3aSmrg ;; 28780f56f3aSmrg *.c) 28880f56f3aSmrg cfile=$1 28980f56f3aSmrg set x "$@" "$1" 29080f56f3aSmrg shift 29180f56f3aSmrg ;; 29280f56f3aSmrg *) 29380f56f3aSmrg set x "$@" "$1" 29480f56f3aSmrg shift 29580f56f3aSmrg ;; 29680f56f3aSmrg esac 29780f56f3aSmrg fi 29880f56f3aSmrg shift 29980f56f3aSmrgdone 30080f56f3aSmrg 30180f56f3aSmrgif test -z "$ofile" || test -z "$cfile"; then 30280f56f3aSmrg # If no '-o' option was seen then we might have been invoked from a 30380f56f3aSmrg # pattern rule where we don't need one. That is ok -- this is a 30480f56f3aSmrg # normal compilation that the losing compiler can handle. If no 30580f56f3aSmrg # '.c' file was seen then we are probably linking. That is also 30680f56f3aSmrg # ok. 30780f56f3aSmrg exec "$@" 30880f56f3aSmrgfi 30980f56f3aSmrg 31080f56f3aSmrg# Name of file we expect compiler to create. 31180f56f3aSmrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31280f56f3aSmrg 31380f56f3aSmrg# Create the lock directory. 31480f56f3aSmrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31580f56f3aSmrg# that we are using for the .o file. Also, base the name on the expected 31680f56f3aSmrg# object file name, since that is what matters with a parallel build. 31780f56f3aSmrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31880f56f3aSmrgwhile true; do 31980f56f3aSmrg if mkdir "$lockdir" >/dev/null 2>&1; then 32080f56f3aSmrg break 32180f56f3aSmrg fi 32280f56f3aSmrg sleep 1 32380f56f3aSmrgdone 32480f56f3aSmrg# FIXME: race condition here if user kills between mkdir and trap. 32580f56f3aSmrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 32680f56f3aSmrg 32780f56f3aSmrg# Run the compile. 32880f56f3aSmrg"$@" 32980f56f3aSmrgret=$? 33080f56f3aSmrg 33180f56f3aSmrgif test -f "$cofile"; then 33280f56f3aSmrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33380f56f3aSmrgelif test -f "${cofile}bj"; then 33480f56f3aSmrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33580f56f3aSmrgfi 33680f56f3aSmrg 33780f56f3aSmrgrmdir "$lockdir" 33880f56f3aSmrgexit $ret 33980f56f3aSmrg 34080f56f3aSmrg# Local Variables: 34180f56f3aSmrg# mode: shell-script 34280f56f3aSmrg# sh-indentation: 2 343138a9f8aSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 34480f56f3aSmrg# time-stamp-start: "scriptversion=" 34580f56f3aSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 346138a9f8aSmrg# time-stamp-time-zone: "UTC0" 34780f56f3aSmrg# time-stamp-end: "; # UTC" 34880f56f3aSmrg# End: 349