114c0a534Smrg#! /bin/sh 224047306Smrg# Wrapper for compilers which do not understand '-c -o'. 314c0a534Smrg 47015785aSmrgscriptversion=2024-06-19.01; # UTC 514c0a534Smrg 67015785aSmrg# Copyright (C) 1999-2024 Free Software Foundation, Inc. 714c0a534Smrg# Written by Tom Tromey <tromey@cygnus.com>. 814c0a534Smrg# 914c0a534Smrg# This program is free software; you can redistribute it and/or modify 1014c0a534Smrg# it under the terms of the GNU General Public License as published by 1114c0a534Smrg# the Free Software Foundation; either version 2, or (at your option) 1214c0a534Smrg# any later version. 1314c0a534Smrg# 1414c0a534Smrg# This program is distributed in the hope that it will be useful, 1514c0a534Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1614c0a534Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1714c0a534Smrg# GNU General Public License for more details. 1814c0a534Smrg# 1914c0a534Smrg# You should have received a copy of the GNU General Public License 20bdc460c5Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2114c0a534Smrg 2214c0a534Smrg# As a special exception to the GNU General Public License, if you 2314c0a534Smrg# distribute this file as part of a program that contains a 2414c0a534Smrg# configuration script generated by Autoconf, you may include it under 2514c0a534Smrg# the same distribution terms that you use for the rest of that program. 2614c0a534Smrg 2714c0a534Smrg# This file is maintained in Automake, please report 2814c0a534Smrg# bugs to <bug-automake@gnu.org> or send patches to 2914c0a534Smrg# <automake-patches@gnu.org>. 3014c0a534Smrg 3124047306Smrgnl=' 3224047306Smrg' 3324047306Smrg 3424047306Smrg# We need space, tab and new line, in precisely that order. Quoting is 3524047306Smrg# there to prevent tools from complaining about whitespace usage. 3624047306SmrgIFS=" "" $nl" 3724047306Smrg 3824047306Smrgfile_conv= 3924047306Smrg 4024047306Smrg# func_file_conv build_file lazy 4124047306Smrg# Convert a $build file to $host form and store it in $file 4224047306Smrg# Currently only supports Windows hosts. If the determined conversion 4324047306Smrg# type is listed in (the comma separated) LAZY, no conversion will 4424047306Smrg# take place. 4524047306Smrgfunc_file_conv () 4624047306Smrg{ 4724047306Smrg file=$1 4824047306Smrg case $file in 4924047306Smrg / | /[!/]*) # absolute file, and not a UNC file 5024047306Smrg if test -z "$file_conv"; then 5124047306Smrg # lazily determine how to convert abs files 5224047306Smrg case `uname -s` in 5324047306Smrg MINGW*) 5424047306Smrg file_conv=mingw 5524047306Smrg ;; 56bdc460c5Smrg CYGWIN* | MSYS*) 5724047306Smrg file_conv=cygwin 5824047306Smrg ;; 5924047306Smrg *) 6024047306Smrg file_conv=wine 6124047306Smrg ;; 6224047306Smrg esac 6324047306Smrg fi 6424047306Smrg case $file_conv/,$2, in 6524047306Smrg *,$file_conv,*) 6624047306Smrg ;; 6724047306Smrg mingw/*) 6824047306Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6924047306Smrg ;; 70bdc460c5Smrg cygwin/* | msys/*) 7124047306Smrg file=`cygpath -m "$file" || echo "$file"` 7224047306Smrg ;; 7324047306Smrg wine/*) 7424047306Smrg file=`winepath -w "$file" || echo "$file"` 7524047306Smrg ;; 7624047306Smrg esac 7724047306Smrg ;; 7824047306Smrg esac 7924047306Smrg} 8024047306Smrg 8124047306Smrg# func_cl_dashL linkdir 8224047306Smrg# Make cl look for libraries in LINKDIR 8324047306Smrgfunc_cl_dashL () 8424047306Smrg{ 8524047306Smrg func_file_conv "$1" 8624047306Smrg if test -z "$lib_path"; then 8724047306Smrg lib_path=$file 8824047306Smrg else 8924047306Smrg lib_path="$lib_path;$file" 9024047306Smrg fi 9124047306Smrg linker_opts="$linker_opts -LIBPATH:$file" 9224047306Smrg} 9324047306Smrg 9424047306Smrg# func_cl_dashl library 9524047306Smrg# Do a library search-path lookup for cl 9624047306Smrgfunc_cl_dashl () 9724047306Smrg{ 9824047306Smrg lib=$1 9924047306Smrg found=no 10024047306Smrg save_IFS=$IFS 10124047306Smrg IFS=';' 10224047306Smrg for dir in $lib_path $LIB 10324047306Smrg do 10424047306Smrg IFS=$save_IFS 10524047306Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 10624047306Smrg found=yes 10724047306Smrg lib=$dir/$lib.dll.lib 10824047306Smrg break 10924047306Smrg fi 11024047306Smrg if test -f "$dir/$lib.lib"; then 11124047306Smrg found=yes 11224047306Smrg lib=$dir/$lib.lib 11324047306Smrg break 11424047306Smrg fi 11524047306Smrg if test -f "$dir/lib$lib.a"; then 11624047306Smrg found=yes 11724047306Smrg lib=$dir/lib$lib.a 11824047306Smrg break 11924047306Smrg fi 12024047306Smrg done 12124047306Smrg IFS=$save_IFS 12224047306Smrg 12324047306Smrg if test "$found" != yes; then 12424047306Smrg lib=$lib.lib 12524047306Smrg fi 12624047306Smrg} 12724047306Smrg 12824047306Smrg# func_cl_wrapper cl arg... 12924047306Smrg# Adjust compile command to suit cl 13024047306Smrgfunc_cl_wrapper () 13124047306Smrg{ 13224047306Smrg # Assume a capable shell 13324047306Smrg lib_path= 13424047306Smrg shared=: 13524047306Smrg linker_opts= 13624047306Smrg for arg 13724047306Smrg do 13824047306Smrg if test -n "$eat"; then 13924047306Smrg eat= 14024047306Smrg else 14124047306Smrg case $1 in 14224047306Smrg -o) 14324047306Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 14424047306Smrg eat=1 14524047306Smrg case $2 in 1467015785aSmrg *.o | *.lo | *.[oO][bB][jJ]) 14724047306Smrg func_file_conv "$2" 14824047306Smrg set x "$@" -Fo"$file" 14924047306Smrg shift 15024047306Smrg ;; 15124047306Smrg *) 15224047306Smrg func_file_conv "$2" 15324047306Smrg set x "$@" -Fe"$file" 15424047306Smrg shift 15524047306Smrg ;; 15624047306Smrg esac 15724047306Smrg ;; 15824047306Smrg -I) 15924047306Smrg eat=1 16024047306Smrg func_file_conv "$2" mingw 16124047306Smrg set x "$@" -I"$file" 16224047306Smrg shift 16324047306Smrg ;; 16424047306Smrg -I*) 16524047306Smrg func_file_conv "${1#-I}" mingw 16624047306Smrg set x "$@" -I"$file" 16724047306Smrg shift 16824047306Smrg ;; 16924047306Smrg -l) 17024047306Smrg eat=1 17124047306Smrg func_cl_dashl "$2" 17224047306Smrg set x "$@" "$lib" 17324047306Smrg shift 17424047306Smrg ;; 17524047306Smrg -l*) 17624047306Smrg func_cl_dashl "${1#-l}" 17724047306Smrg set x "$@" "$lib" 17824047306Smrg shift 17924047306Smrg ;; 18024047306Smrg -L) 18124047306Smrg eat=1 18224047306Smrg func_cl_dashL "$2" 18324047306Smrg ;; 18424047306Smrg -L*) 18524047306Smrg func_cl_dashL "${1#-L}" 18624047306Smrg ;; 18724047306Smrg -static) 18824047306Smrg shared=false 18924047306Smrg ;; 19024047306Smrg -Wl,*) 19124047306Smrg arg=${1#-Wl,} 19224047306Smrg save_ifs="$IFS"; IFS=',' 19324047306Smrg for flag in $arg; do 19424047306Smrg IFS="$save_ifs" 19524047306Smrg linker_opts="$linker_opts $flag" 19624047306Smrg done 19724047306Smrg IFS="$save_ifs" 19824047306Smrg ;; 19924047306Smrg -Xlinker) 20024047306Smrg eat=1 20124047306Smrg linker_opts="$linker_opts $2" 20224047306Smrg ;; 20324047306Smrg -*) 20424047306Smrg set x "$@" "$1" 20524047306Smrg shift 20624047306Smrg ;; 20724047306Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20824047306Smrg func_file_conv "$1" 20924047306Smrg set x "$@" -Tp"$file" 21024047306Smrg shift 21124047306Smrg ;; 21224047306Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21324047306Smrg func_file_conv "$1" mingw 21424047306Smrg set x "$@" "$file" 21524047306Smrg shift 21624047306Smrg ;; 21724047306Smrg *) 21824047306Smrg set x "$@" "$1" 21924047306Smrg shift 22024047306Smrg ;; 22124047306Smrg esac 22224047306Smrg fi 22324047306Smrg shift 22424047306Smrg done 22524047306Smrg if test -n "$linker_opts"; then 22624047306Smrg linker_opts="-link$linker_opts" 22724047306Smrg fi 22824047306Smrg exec "$@" $linker_opts 22924047306Smrg exit 1 23024047306Smrg} 23124047306Smrg 23224047306Smrgeat= 23324047306Smrg 23414c0a534Smrgcase $1 in 23514c0a534Smrg '') 23624047306Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 23714c0a534Smrg exit 1; 23814c0a534Smrg ;; 23914c0a534Smrg -h | --h*) 24014c0a534Smrg cat <<\EOF 24114c0a534SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 24214c0a534Smrg 24324047306SmrgWrapper for compilers which do not understand '-c -o'. 24424047306SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24514c0a534Smrgarguments, and rename the output as expected. 24614c0a534Smrg 24714c0a534SmrgIf you are trying to build a whole package this is not the 24824047306Smrgright script to run: please start by reading the file 'INSTALL'. 24914c0a534Smrg 25014c0a534SmrgReport bugs to <bug-automake@gnu.org>. 2517015785aSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 2527015785aSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 25314c0a534SmrgEOF 25414c0a534Smrg exit $? 25514c0a534Smrg ;; 25614c0a534Smrg -v | --v*) 2577015785aSmrg echo "compile (GNU Automake) $scriptversion" 25814c0a534Smrg exit $? 25914c0a534Smrg ;; 260bdc460c5Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 2617015785aSmrg clang-cl | *[/\\]clang-cl | clang-cl.exe | *[/\\]clang-cl.exe | \ 262bdc460c5Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 26324047306Smrg func_cl_wrapper "$@" # Doesn't return... 26424047306Smrg ;; 26514c0a534Smrgesac 26614c0a534Smrg 26714c0a534Smrgofile= 26814c0a534Smrgcfile= 26914c0a534Smrg 27014c0a534Smrgfor arg 27114c0a534Smrgdo 27214c0a534Smrg if test -n "$eat"; then 27314c0a534Smrg eat= 27414c0a534Smrg else 27514c0a534Smrg case $1 in 27614c0a534Smrg -o) 27724047306Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 27824047306Smrg # So we strip '-o arg' only if arg is an object. 27914c0a534Smrg eat=1 28014c0a534Smrg case $2 in 28114c0a534Smrg *.o | *.obj) 28214c0a534Smrg ofile=$2 28314c0a534Smrg ;; 28414c0a534Smrg *) 28514c0a534Smrg set x "$@" -o "$2" 28614c0a534Smrg shift 28714c0a534Smrg ;; 28814c0a534Smrg esac 28914c0a534Smrg ;; 29014c0a534Smrg *.c) 29114c0a534Smrg cfile=$1 29214c0a534Smrg set x "$@" "$1" 29314c0a534Smrg shift 29414c0a534Smrg ;; 29514c0a534Smrg *) 29614c0a534Smrg set x "$@" "$1" 29714c0a534Smrg shift 29814c0a534Smrg ;; 29914c0a534Smrg esac 30014c0a534Smrg fi 30114c0a534Smrg shift 30214c0a534Smrgdone 30314c0a534Smrg 30414c0a534Smrgif test -z "$ofile" || test -z "$cfile"; then 30524047306Smrg # If no '-o' option was seen then we might have been invoked from a 30614c0a534Smrg # pattern rule where we don't need one. That is ok -- this is a 30714c0a534Smrg # normal compilation that the losing compiler can handle. If no 30824047306Smrg # '.c' file was seen then we are probably linking. That is also 30914c0a534Smrg # ok. 31014c0a534Smrg exec "$@" 31114c0a534Smrgfi 31214c0a534Smrg 31314c0a534Smrg# Name of file we expect compiler to create. 31424047306Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31514c0a534Smrg 31614c0a534Smrg# Create the lock directory. 31724047306Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31814c0a534Smrg# that we are using for the .o file. Also, base the name on the expected 31914c0a534Smrg# object file name, since that is what matters with a parallel build. 32024047306Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 32114c0a534Smrgwhile true; do 32214c0a534Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 32314c0a534Smrg break 32414c0a534Smrg fi 32514c0a534Smrg sleep 1 32614c0a534Smrgdone 32714c0a534Smrg# FIXME: race condition here if user kills between mkdir and trap. 32814c0a534Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 32914c0a534Smrg 33014c0a534Smrg# Run the compile. 33114c0a534Smrg"$@" 33214c0a534Smrgret=$? 33314c0a534Smrg 33414c0a534Smrgif test -f "$cofile"; then 33524047306Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33614c0a534Smrgelif test -f "${cofile}bj"; then 33724047306Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33814c0a534Smrgfi 33914c0a534Smrg 34014c0a534Smrgrmdir "$lockdir" 34114c0a534Smrgexit $ret 34214c0a534Smrg 34314c0a534Smrg# Local Variables: 34414c0a534Smrg# mode: shell-script 34514c0a534Smrg# sh-indentation: 2 346bdc460c5Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 34714c0a534Smrg# time-stamp-start: "scriptversion=" 34814c0a534Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 349bdc460c5Smrg# time-stamp-time-zone: "UTC0" 35024047306Smrg# time-stamp-end: "; # UTC" 35114c0a534Smrg# End: 352