182275908Smrg#! /bin/sh 282275908Smrg# Wrapper for compilers which do not understand '-c -o'. 382275908Smrg 472af6995Smrgscriptversion=2018-03-07.03; # UTC 582275908Smrg 6a773ec55Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 782275908Smrg# Written by Tom Tromey <tromey@cygnus.com>. 882275908Smrg# 982275908Smrg# This program is free software; you can redistribute it and/or modify 1082275908Smrg# it under the terms of the GNU General Public License as published by 1182275908Smrg# the Free Software Foundation; either version 2, or (at your option) 1282275908Smrg# any later version. 1382275908Smrg# 1482275908Smrg# This program is distributed in the hope that it will be useful, 1582275908Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1682275908Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1782275908Smrg# GNU General Public License for more details. 1882275908Smrg# 1982275908Smrg# You should have received a copy of the GNU General Public License 2072af6995Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2182275908Smrg 2282275908Smrg# As a special exception to the GNU General Public License, if you 2382275908Smrg# distribute this file as part of a program that contains a 2482275908Smrg# configuration script generated by Autoconf, you may include it under 2582275908Smrg# the same distribution terms that you use for the rest of that program. 2682275908Smrg 2782275908Smrg# This file is maintained in Automake, please report 2882275908Smrg# bugs to <bug-automake@gnu.org> or send patches to 2982275908Smrg# <automake-patches@gnu.org>. 3082275908Smrg 3182275908Smrgnl=' 3282275908Smrg' 3382275908Smrg 3482275908Smrg# We need space, tab and new line, in precisely that order. Quoting is 3582275908Smrg# there to prevent tools from complaining about whitespace usage. 3682275908SmrgIFS=" "" $nl" 3782275908Smrg 3882275908Smrgfile_conv= 3982275908Smrg 4082275908Smrg# func_file_conv build_file lazy 4182275908Smrg# Convert a $build file to $host form and store it in $file 4282275908Smrg# Currently only supports Windows hosts. If the determined conversion 4382275908Smrg# type is listed in (the comma separated) LAZY, no conversion will 4482275908Smrg# take place. 4582275908Smrgfunc_file_conv () 4682275908Smrg{ 4782275908Smrg file=$1 4882275908Smrg case $file in 4982275908Smrg / | /[!/]*) # absolute file, and not a UNC file 5082275908Smrg if test -z "$file_conv"; then 5182275908Smrg # lazily determine how to convert abs files 5282275908Smrg case `uname -s` in 5382275908Smrg MINGW*) 5482275908Smrg file_conv=mingw 5582275908Smrg ;; 56362b94d5Smrg CYGWIN* | MSYS*) 5782275908Smrg file_conv=cygwin 5882275908Smrg ;; 5982275908Smrg *) 6082275908Smrg file_conv=wine 6182275908Smrg ;; 6282275908Smrg esac 6382275908Smrg fi 6482275908Smrg case $file_conv/,$2, in 6582275908Smrg *,$file_conv,*) 6682275908Smrg ;; 6782275908Smrg mingw/*) 6882275908Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6982275908Smrg ;; 70362b94d5Smrg cygwin/* | msys/*) 7182275908Smrg file=`cygpath -m "$file" || echo "$file"` 7282275908Smrg ;; 7382275908Smrg wine/*) 7482275908Smrg file=`winepath -w "$file" || echo "$file"` 7582275908Smrg ;; 7682275908Smrg esac 7782275908Smrg ;; 7882275908Smrg esac 7982275908Smrg} 8082275908Smrg 8182275908Smrg# func_cl_dashL linkdir 8282275908Smrg# Make cl look for libraries in LINKDIR 8382275908Smrgfunc_cl_dashL () 8482275908Smrg{ 8582275908Smrg func_file_conv "$1" 8682275908Smrg if test -z "$lib_path"; then 8782275908Smrg lib_path=$file 8882275908Smrg else 8982275908Smrg lib_path="$lib_path;$file" 9082275908Smrg fi 9182275908Smrg linker_opts="$linker_opts -LIBPATH:$file" 9282275908Smrg} 9382275908Smrg 9482275908Smrg# func_cl_dashl library 9582275908Smrg# Do a library search-path lookup for cl 9682275908Smrgfunc_cl_dashl () 9782275908Smrg{ 9882275908Smrg lib=$1 9982275908Smrg found=no 10082275908Smrg save_IFS=$IFS 10182275908Smrg IFS=';' 10282275908Smrg for dir in $lib_path $LIB 10382275908Smrg do 10482275908Smrg IFS=$save_IFS 10582275908Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 10682275908Smrg found=yes 10782275908Smrg lib=$dir/$lib.dll.lib 10882275908Smrg break 10982275908Smrg fi 11082275908Smrg if test -f "$dir/$lib.lib"; then 11182275908Smrg found=yes 11282275908Smrg lib=$dir/$lib.lib 11382275908Smrg break 11482275908Smrg fi 11582275908Smrg if test -f "$dir/lib$lib.a"; then 11682275908Smrg found=yes 11782275908Smrg lib=$dir/lib$lib.a 11882275908Smrg break 11982275908Smrg fi 12082275908Smrg done 12182275908Smrg IFS=$save_IFS 12282275908Smrg 12382275908Smrg if test "$found" != yes; then 12482275908Smrg lib=$lib.lib 12582275908Smrg fi 12682275908Smrg} 12782275908Smrg 12882275908Smrg# func_cl_wrapper cl arg... 12982275908Smrg# Adjust compile command to suit cl 13082275908Smrgfunc_cl_wrapper () 13182275908Smrg{ 13282275908Smrg # Assume a capable shell 13382275908Smrg lib_path= 13482275908Smrg shared=: 13582275908Smrg linker_opts= 13682275908Smrg for arg 13782275908Smrg do 13882275908Smrg if test -n "$eat"; then 13982275908Smrg eat= 14082275908Smrg else 14182275908Smrg case $1 in 14282275908Smrg -o) 14382275908Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 14482275908Smrg eat=1 14582275908Smrg case $2 in 14682275908Smrg *.o | *.[oO][bB][jJ]) 14782275908Smrg func_file_conv "$2" 14882275908Smrg set x "$@" -Fo"$file" 14982275908Smrg shift 15082275908Smrg ;; 15182275908Smrg *) 15282275908Smrg func_file_conv "$2" 15382275908Smrg set x "$@" -Fe"$file" 15482275908Smrg shift 15582275908Smrg ;; 15682275908Smrg esac 15782275908Smrg ;; 15882275908Smrg -I) 15982275908Smrg eat=1 16082275908Smrg func_file_conv "$2" mingw 16182275908Smrg set x "$@" -I"$file" 16282275908Smrg shift 16382275908Smrg ;; 16482275908Smrg -I*) 16582275908Smrg func_file_conv "${1#-I}" mingw 16682275908Smrg set x "$@" -I"$file" 16782275908Smrg shift 16882275908Smrg ;; 16982275908Smrg -l) 17082275908Smrg eat=1 17182275908Smrg func_cl_dashl "$2" 17282275908Smrg set x "$@" "$lib" 17382275908Smrg shift 17482275908Smrg ;; 17582275908Smrg -l*) 17682275908Smrg func_cl_dashl "${1#-l}" 17782275908Smrg set x "$@" "$lib" 17882275908Smrg shift 17982275908Smrg ;; 18082275908Smrg -L) 18182275908Smrg eat=1 18282275908Smrg func_cl_dashL "$2" 18382275908Smrg ;; 18482275908Smrg -L*) 18582275908Smrg func_cl_dashL "${1#-L}" 18682275908Smrg ;; 18782275908Smrg -static) 18882275908Smrg shared=false 18982275908Smrg ;; 19082275908Smrg -Wl,*) 19182275908Smrg arg=${1#-Wl,} 19282275908Smrg save_ifs="$IFS"; IFS=',' 19382275908Smrg for flag in $arg; do 19482275908Smrg IFS="$save_ifs" 19582275908Smrg linker_opts="$linker_opts $flag" 19682275908Smrg done 19782275908Smrg IFS="$save_ifs" 19882275908Smrg ;; 19982275908Smrg -Xlinker) 20082275908Smrg eat=1 20182275908Smrg linker_opts="$linker_opts $2" 20282275908Smrg ;; 20382275908Smrg -*) 20482275908Smrg set x "$@" "$1" 20582275908Smrg shift 20682275908Smrg ;; 20782275908Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20882275908Smrg func_file_conv "$1" 20982275908Smrg set x "$@" -Tp"$file" 21082275908Smrg shift 21182275908Smrg ;; 21282275908Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21382275908Smrg func_file_conv "$1" mingw 21482275908Smrg set x "$@" "$file" 21582275908Smrg shift 21682275908Smrg ;; 21782275908Smrg *) 21882275908Smrg set x "$@" "$1" 21982275908Smrg shift 22082275908Smrg ;; 22182275908Smrg esac 22282275908Smrg fi 22382275908Smrg shift 22482275908Smrg done 22582275908Smrg if test -n "$linker_opts"; then 22682275908Smrg linker_opts="-link$linker_opts" 22782275908Smrg fi 22882275908Smrg exec "$@" $linker_opts 22982275908Smrg exit 1 23082275908Smrg} 23182275908Smrg 23282275908Smrgeat= 23382275908Smrg 23482275908Smrgcase $1 in 23582275908Smrg '') 23682275908Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 23782275908Smrg exit 1; 23882275908Smrg ;; 23982275908Smrg -h | --h*) 24082275908Smrg cat <<\EOF 24182275908SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 24282275908Smrg 24382275908SmrgWrapper for compilers which do not understand '-c -o'. 24482275908SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24582275908Smrgarguments, and rename the output as expected. 24682275908Smrg 24782275908SmrgIf you are trying to build a whole package this is not the 24882275908Smrgright script to run: please start by reading the file 'INSTALL'. 24982275908Smrg 25082275908SmrgReport bugs to <bug-automake@gnu.org>. 25182275908SmrgEOF 25282275908Smrg exit $? 25382275908Smrg ;; 25482275908Smrg -v | --v*) 25582275908Smrg echo "compile $scriptversion" 25682275908Smrg exit $? 25782275908Smrg ;; 25872af6995Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 25972af6995Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 26082275908Smrg func_cl_wrapper "$@" # Doesn't return... 26182275908Smrg ;; 26282275908Smrgesac 26382275908Smrg 26482275908Smrgofile= 26582275908Smrgcfile= 26682275908Smrg 26782275908Smrgfor arg 26882275908Smrgdo 26982275908Smrg if test -n "$eat"; then 27082275908Smrg eat= 27182275908Smrg else 27282275908Smrg case $1 in 27382275908Smrg -o) 27482275908Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 27582275908Smrg # So we strip '-o arg' only if arg is an object. 27682275908Smrg eat=1 27782275908Smrg case $2 in 27882275908Smrg *.o | *.obj) 27982275908Smrg ofile=$2 28082275908Smrg ;; 28182275908Smrg *) 28282275908Smrg set x "$@" -o "$2" 28382275908Smrg shift 28482275908Smrg ;; 28582275908Smrg esac 28682275908Smrg ;; 28782275908Smrg *.c) 28882275908Smrg cfile=$1 28982275908Smrg set x "$@" "$1" 29082275908Smrg shift 29182275908Smrg ;; 29282275908Smrg *) 29382275908Smrg set x "$@" "$1" 29482275908Smrg shift 29582275908Smrg ;; 29682275908Smrg esac 29782275908Smrg fi 29882275908Smrg shift 29982275908Smrgdone 30082275908Smrg 30182275908Smrgif test -z "$ofile" || test -z "$cfile"; then 30282275908Smrg # If no '-o' option was seen then we might have been invoked from a 30382275908Smrg # pattern rule where we don't need one. That is ok -- this is a 30482275908Smrg # normal compilation that the losing compiler can handle. If no 30582275908Smrg # '.c' file was seen then we are probably linking. That is also 30682275908Smrg # ok. 30782275908Smrg exec "$@" 30882275908Smrgfi 30982275908Smrg 31082275908Smrg# Name of file we expect compiler to create. 31182275908Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31282275908Smrg 31382275908Smrg# Create the lock directory. 31482275908Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31582275908Smrg# that we are using for the .o file. Also, base the name on the expected 31682275908Smrg# object file name, since that is what matters with a parallel build. 31782275908Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31882275908Smrgwhile true; do 31982275908Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 32082275908Smrg break 32182275908Smrg fi 32282275908Smrg sleep 1 32382275908Smrgdone 32482275908Smrg# FIXME: race condition here if user kills between mkdir and trap. 32582275908Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 32682275908Smrg 32782275908Smrg# Run the compile. 32882275908Smrg"$@" 32982275908Smrgret=$? 33082275908Smrg 33182275908Smrgif test -f "$cofile"; then 33282275908Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33382275908Smrgelif test -f "${cofile}bj"; then 33482275908Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33582275908Smrgfi 33682275908Smrg 33782275908Smrgrmdir "$lockdir" 33882275908Smrgexit $ret 33982275908Smrg 34082275908Smrg# Local Variables: 34182275908Smrg# mode: shell-script 34282275908Smrg# sh-indentation: 2 34372af6995Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 34482275908Smrg# time-stamp-start: "scriptversion=" 34582275908Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 34672af6995Smrg# time-stamp-time-zone: "UTC0" 34782275908Smrg# time-stamp-end: "; # UTC" 34882275908Smrg# End: 349