1ea1d6981Smrg#! /bin/sh 217ca54c3Smrg# Wrapper for compilers which do not understand '-c -o'. 317ca54c3Smrg 4ea1d6981Smrgscriptversion=2018-03-07.03; # UTC 517ca54c3Smrg 6ffe57424Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 717ca54c3Smrg# Written by Tom Tromey <tromey@cygnus.com>. 817ca54c3Smrg# 917ca54c3Smrg# This program is free software; you can redistribute it and/or modify 1017ca54c3Smrg# it under the terms of the GNU General Public License as published by 1117ca54c3Smrg# the Free Software Foundation; either version 2, or (at your option) 1217ca54c3Smrg# any later version. 1317ca54c3Smrg# 1417ca54c3Smrg# This program is distributed in the hope that it will be useful, 1517ca54c3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1617ca54c3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1717ca54c3Smrg# GNU General Public License for more details. 1817ca54c3Smrg# 1917ca54c3Smrg# You should have received a copy of the GNU General Public License 20ea1d6981Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2117ca54c3Smrg 2217ca54c3Smrg# As a special exception to the GNU General Public License, if you 2317ca54c3Smrg# distribute this file as part of a program that contains a 2417ca54c3Smrg# configuration script generated by Autoconf, you may include it under 2517ca54c3Smrg# the same distribution terms that you use for the rest of that program. 2617ca54c3Smrg 2717ca54c3Smrg# This file is maintained in Automake, please report 2817ca54c3Smrg# bugs to <bug-automake@gnu.org> or send patches to 2917ca54c3Smrg# <automake-patches@gnu.org>. 3017ca54c3Smrg 3117ca54c3Smrgnl=' 3217ca54c3Smrg' 3317ca54c3Smrg 3417ca54c3Smrg# We need space, tab and new line, in precisely that order. Quoting is 3517ca54c3Smrg# there to prevent tools from complaining about whitespace usage. 3617ca54c3SmrgIFS=" "" $nl" 3717ca54c3Smrg 3817ca54c3Smrgfile_conv= 3917ca54c3Smrg 4017ca54c3Smrg# func_file_conv build_file lazy 4117ca54c3Smrg# Convert a $build file to $host form and store it in $file 4217ca54c3Smrg# Currently only supports Windows hosts. If the determined conversion 4317ca54c3Smrg# type is listed in (the comma separated) LAZY, no conversion will 4417ca54c3Smrg# take place. 4517ca54c3Smrgfunc_file_conv () 4617ca54c3Smrg{ 4717ca54c3Smrg file=$1 4817ca54c3Smrg case $file in 4917ca54c3Smrg / | /[!/]*) # absolute file, and not a UNC file 5017ca54c3Smrg if test -z "$file_conv"; then 5117ca54c3Smrg # lazily determine how to convert abs files 5217ca54c3Smrg case `uname -s` in 5317ca54c3Smrg MINGW*) 5417ca54c3Smrg file_conv=mingw 5517ca54c3Smrg ;; 56ffe57424Smrg CYGWIN* | MSYS*) 5717ca54c3Smrg file_conv=cygwin 5817ca54c3Smrg ;; 5917ca54c3Smrg *) 6017ca54c3Smrg file_conv=wine 6117ca54c3Smrg ;; 6217ca54c3Smrg esac 6317ca54c3Smrg fi 6417ca54c3Smrg case $file_conv/,$2, in 6517ca54c3Smrg *,$file_conv,*) 6617ca54c3Smrg ;; 6717ca54c3Smrg mingw/*) 6817ca54c3Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6917ca54c3Smrg ;; 70ffe57424Smrg cygwin/* | msys/*) 7117ca54c3Smrg file=`cygpath -m "$file" || echo "$file"` 7217ca54c3Smrg ;; 7317ca54c3Smrg wine/*) 7417ca54c3Smrg file=`winepath -w "$file" || echo "$file"` 7517ca54c3Smrg ;; 7617ca54c3Smrg esac 7717ca54c3Smrg ;; 7817ca54c3Smrg esac 7917ca54c3Smrg} 8017ca54c3Smrg 8117ca54c3Smrg# func_cl_dashL linkdir 8217ca54c3Smrg# Make cl look for libraries in LINKDIR 8317ca54c3Smrgfunc_cl_dashL () 8417ca54c3Smrg{ 8517ca54c3Smrg func_file_conv "$1" 8617ca54c3Smrg if test -z "$lib_path"; then 8717ca54c3Smrg lib_path=$file 8817ca54c3Smrg else 8917ca54c3Smrg lib_path="$lib_path;$file" 9017ca54c3Smrg fi 9117ca54c3Smrg linker_opts="$linker_opts -LIBPATH:$file" 9217ca54c3Smrg} 9317ca54c3Smrg 9417ca54c3Smrg# func_cl_dashl library 9517ca54c3Smrg# Do a library search-path lookup for cl 9617ca54c3Smrgfunc_cl_dashl () 9717ca54c3Smrg{ 9817ca54c3Smrg lib=$1 9917ca54c3Smrg found=no 10017ca54c3Smrg save_IFS=$IFS 10117ca54c3Smrg IFS=';' 10217ca54c3Smrg for dir in $lib_path $LIB 10317ca54c3Smrg do 10417ca54c3Smrg IFS=$save_IFS 10517ca54c3Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 10617ca54c3Smrg found=yes 10717ca54c3Smrg lib=$dir/$lib.dll.lib 10817ca54c3Smrg break 10917ca54c3Smrg fi 11017ca54c3Smrg if test -f "$dir/$lib.lib"; then 11117ca54c3Smrg found=yes 11217ca54c3Smrg lib=$dir/$lib.lib 11317ca54c3Smrg break 11417ca54c3Smrg fi 11517ca54c3Smrg if test -f "$dir/lib$lib.a"; then 11617ca54c3Smrg found=yes 11717ca54c3Smrg lib=$dir/lib$lib.a 11817ca54c3Smrg break 11917ca54c3Smrg fi 12017ca54c3Smrg done 12117ca54c3Smrg IFS=$save_IFS 12217ca54c3Smrg 12317ca54c3Smrg if test "$found" != yes; then 12417ca54c3Smrg lib=$lib.lib 12517ca54c3Smrg fi 12617ca54c3Smrg} 12717ca54c3Smrg 12817ca54c3Smrg# func_cl_wrapper cl arg... 12917ca54c3Smrg# Adjust compile command to suit cl 13017ca54c3Smrgfunc_cl_wrapper () 13117ca54c3Smrg{ 13217ca54c3Smrg # Assume a capable shell 13317ca54c3Smrg lib_path= 13417ca54c3Smrg shared=: 13517ca54c3Smrg linker_opts= 13617ca54c3Smrg for arg 13717ca54c3Smrg do 13817ca54c3Smrg if test -n "$eat"; then 13917ca54c3Smrg eat= 14017ca54c3Smrg else 14117ca54c3Smrg case $1 in 14217ca54c3Smrg -o) 14317ca54c3Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 14417ca54c3Smrg eat=1 14517ca54c3Smrg case $2 in 14617ca54c3Smrg *.o | *.[oO][bB][jJ]) 14717ca54c3Smrg func_file_conv "$2" 14817ca54c3Smrg set x "$@" -Fo"$file" 14917ca54c3Smrg shift 15017ca54c3Smrg ;; 15117ca54c3Smrg *) 15217ca54c3Smrg func_file_conv "$2" 15317ca54c3Smrg set x "$@" -Fe"$file" 15417ca54c3Smrg shift 15517ca54c3Smrg ;; 15617ca54c3Smrg esac 15717ca54c3Smrg ;; 15817ca54c3Smrg -I) 15917ca54c3Smrg eat=1 16017ca54c3Smrg func_file_conv "$2" mingw 16117ca54c3Smrg set x "$@" -I"$file" 16217ca54c3Smrg shift 16317ca54c3Smrg ;; 16417ca54c3Smrg -I*) 16517ca54c3Smrg func_file_conv "${1#-I}" mingw 16617ca54c3Smrg set x "$@" -I"$file" 16717ca54c3Smrg shift 16817ca54c3Smrg ;; 16917ca54c3Smrg -l) 17017ca54c3Smrg eat=1 17117ca54c3Smrg func_cl_dashl "$2" 17217ca54c3Smrg set x "$@" "$lib" 17317ca54c3Smrg shift 17417ca54c3Smrg ;; 17517ca54c3Smrg -l*) 17617ca54c3Smrg func_cl_dashl "${1#-l}" 17717ca54c3Smrg set x "$@" "$lib" 17817ca54c3Smrg shift 17917ca54c3Smrg ;; 18017ca54c3Smrg -L) 18117ca54c3Smrg eat=1 18217ca54c3Smrg func_cl_dashL "$2" 18317ca54c3Smrg ;; 18417ca54c3Smrg -L*) 18517ca54c3Smrg func_cl_dashL "${1#-L}" 18617ca54c3Smrg ;; 18717ca54c3Smrg -static) 18817ca54c3Smrg shared=false 18917ca54c3Smrg ;; 19017ca54c3Smrg -Wl,*) 19117ca54c3Smrg arg=${1#-Wl,} 19217ca54c3Smrg save_ifs="$IFS"; IFS=',' 19317ca54c3Smrg for flag in $arg; do 19417ca54c3Smrg IFS="$save_ifs" 19517ca54c3Smrg linker_opts="$linker_opts $flag" 19617ca54c3Smrg done 19717ca54c3Smrg IFS="$save_ifs" 19817ca54c3Smrg ;; 19917ca54c3Smrg -Xlinker) 20017ca54c3Smrg eat=1 20117ca54c3Smrg linker_opts="$linker_opts $2" 20217ca54c3Smrg ;; 20317ca54c3Smrg -*) 20417ca54c3Smrg set x "$@" "$1" 20517ca54c3Smrg shift 20617ca54c3Smrg ;; 20717ca54c3Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20817ca54c3Smrg func_file_conv "$1" 20917ca54c3Smrg set x "$@" -Tp"$file" 21017ca54c3Smrg shift 21117ca54c3Smrg ;; 21217ca54c3Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21317ca54c3Smrg func_file_conv "$1" mingw 21417ca54c3Smrg set x "$@" "$file" 21517ca54c3Smrg shift 21617ca54c3Smrg ;; 21717ca54c3Smrg *) 21817ca54c3Smrg set x "$@" "$1" 21917ca54c3Smrg shift 22017ca54c3Smrg ;; 22117ca54c3Smrg esac 22217ca54c3Smrg fi 22317ca54c3Smrg shift 22417ca54c3Smrg done 22517ca54c3Smrg if test -n "$linker_opts"; then 22617ca54c3Smrg linker_opts="-link$linker_opts" 22717ca54c3Smrg fi 22817ca54c3Smrg exec "$@" $linker_opts 22917ca54c3Smrg exit 1 23017ca54c3Smrg} 23117ca54c3Smrg 23217ca54c3Smrgeat= 23317ca54c3Smrg 23417ca54c3Smrgcase $1 in 23517ca54c3Smrg '') 23617ca54c3Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 23717ca54c3Smrg exit 1; 23817ca54c3Smrg ;; 23917ca54c3Smrg -h | --h*) 24017ca54c3Smrg cat <<\EOF 24117ca54c3SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 24217ca54c3Smrg 24317ca54c3SmrgWrapper for compilers which do not understand '-c -o'. 24417ca54c3SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24517ca54c3Smrgarguments, and rename the output as expected. 24617ca54c3Smrg 24717ca54c3SmrgIf you are trying to build a whole package this is not the 24817ca54c3Smrgright script to run: please start by reading the file 'INSTALL'. 24917ca54c3Smrg 25017ca54c3SmrgReport bugs to <bug-automake@gnu.org>. 25117ca54c3SmrgEOF 25217ca54c3Smrg exit $? 25317ca54c3Smrg ;; 25417ca54c3Smrg -v | --v*) 25517ca54c3Smrg echo "compile $scriptversion" 25617ca54c3Smrg exit $? 25717ca54c3Smrg ;; 25817ca54c3Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 25917ca54c3Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 26017ca54c3Smrg func_cl_wrapper "$@" # Doesn't return... 26117ca54c3Smrg ;; 26217ca54c3Smrgesac 26317ca54c3Smrg 26417ca54c3Smrgofile= 26517ca54c3Smrgcfile= 26617ca54c3Smrg 26717ca54c3Smrgfor arg 26817ca54c3Smrgdo 26917ca54c3Smrg if test -n "$eat"; then 27017ca54c3Smrg eat= 27117ca54c3Smrg else 27217ca54c3Smrg case $1 in 27317ca54c3Smrg -o) 27417ca54c3Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 27517ca54c3Smrg # So we strip '-o arg' only if arg is an object. 27617ca54c3Smrg eat=1 27717ca54c3Smrg case $2 in 27817ca54c3Smrg *.o | *.obj) 27917ca54c3Smrg ofile=$2 28017ca54c3Smrg ;; 28117ca54c3Smrg *) 28217ca54c3Smrg set x "$@" -o "$2" 28317ca54c3Smrg shift 28417ca54c3Smrg ;; 28517ca54c3Smrg esac 28617ca54c3Smrg ;; 28717ca54c3Smrg *.c) 28817ca54c3Smrg cfile=$1 28917ca54c3Smrg set x "$@" "$1" 29017ca54c3Smrg shift 29117ca54c3Smrg ;; 29217ca54c3Smrg *) 29317ca54c3Smrg set x "$@" "$1" 29417ca54c3Smrg shift 29517ca54c3Smrg ;; 29617ca54c3Smrg esac 29717ca54c3Smrg fi 29817ca54c3Smrg shift 29917ca54c3Smrgdone 30017ca54c3Smrg 30117ca54c3Smrgif test -z "$ofile" || test -z "$cfile"; then 30217ca54c3Smrg # If no '-o' option was seen then we might have been invoked from a 30317ca54c3Smrg # pattern rule where we don't need one. That is ok -- this is a 30417ca54c3Smrg # normal compilation that the losing compiler can handle. If no 30517ca54c3Smrg # '.c' file was seen then we are probably linking. That is also 30617ca54c3Smrg # ok. 30717ca54c3Smrg exec "$@" 30817ca54c3Smrgfi 30917ca54c3Smrg 31017ca54c3Smrg# Name of file we expect compiler to create. 31117ca54c3Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31217ca54c3Smrg 31317ca54c3Smrg# Create the lock directory. 31417ca54c3Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31517ca54c3Smrg# that we are using for the .o file. Also, base the name on the expected 31617ca54c3Smrg# object file name, since that is what matters with a parallel build. 31717ca54c3Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31817ca54c3Smrgwhile true; do 31917ca54c3Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 32017ca54c3Smrg break 32117ca54c3Smrg fi 32217ca54c3Smrg sleep 1 32317ca54c3Smrgdone 32417ca54c3Smrg# FIXME: race condition here if user kills between mkdir and trap. 32517ca54c3Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 32617ca54c3Smrg 32717ca54c3Smrg# Run the compile. 32817ca54c3Smrg"$@" 32917ca54c3Smrgret=$? 33017ca54c3Smrg 33117ca54c3Smrgif test -f "$cofile"; then 33217ca54c3Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33317ca54c3Smrgelif test -f "${cofile}bj"; then 33417ca54c3Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33517ca54c3Smrgfi 33617ca54c3Smrg 33717ca54c3Smrgrmdir "$lockdir" 33817ca54c3Smrgexit $ret 33917ca54c3Smrg 34017ca54c3Smrg# Local Variables: 34117ca54c3Smrg# mode: shell-script 34217ca54c3Smrg# sh-indentation: 2 343ea1d6981Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 34417ca54c3Smrg# time-stamp-start: "scriptversion=" 34517ca54c3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 34617ca54c3Smrg# time-stamp-time-zone: "UTC0" 34717ca54c3Smrg# time-stamp-end: "; # UTC" 34817ca54c3Smrg# End: 349