126372658Smrg#! /bin/sh 226372658Smrg# Wrapper for compilers which do not understand '-c -o'. 326372658Smrg 4c3e29c03Smrgscriptversion=2018-03-07.03; # UTC 526372658Smrg 6c3e29c03Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 726372658Smrg# Written by Tom Tromey <tromey@cygnus.com>. 826372658Smrg# 926372658Smrg# This program is free software; you can redistribute it and/or modify 1026372658Smrg# it under the terms of the GNU General Public License as published by 1126372658Smrg# the Free Software Foundation; either version 2, or (at your option) 1226372658Smrg# any later version. 1326372658Smrg# 1426372658Smrg# This program is distributed in the hope that it will be useful, 1526372658Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1626372658Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1726372658Smrg# GNU General Public License for more details. 1826372658Smrg# 1926372658Smrg# You should have received a copy of the GNU General Public License 20c3e29c03Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2126372658Smrg 2226372658Smrg# As a special exception to the GNU General Public License, if you 2326372658Smrg# distribute this file as part of a program that contains a 2426372658Smrg# configuration script generated by Autoconf, you may include it under 2526372658Smrg# the same distribution terms that you use for the rest of that program. 2626372658Smrg 2726372658Smrg# This file is maintained in Automake, please report 2826372658Smrg# bugs to <bug-automake@gnu.org> or send patches to 2926372658Smrg# <automake-patches@gnu.org>. 3026372658Smrg 3126372658Smrgnl=' 3226372658Smrg' 3326372658Smrg 3426372658Smrg# We need space, tab and new line, in precisely that order. Quoting is 3526372658Smrg# there to prevent tools from complaining about whitespace usage. 3626372658SmrgIFS=" "" $nl" 3726372658Smrg 3826372658Smrgfile_conv= 3926372658Smrg 4026372658Smrg# func_file_conv build_file lazy 4126372658Smrg# Convert a $build file to $host form and store it in $file 4226372658Smrg# Currently only supports Windows hosts. If the determined conversion 4326372658Smrg# type is listed in (the comma separated) LAZY, no conversion will 4426372658Smrg# take place. 4526372658Smrgfunc_file_conv () 4626372658Smrg{ 4726372658Smrg file=$1 4826372658Smrg case $file in 4926372658Smrg / | /[!/]*) # absolute file, and not a UNC file 5026372658Smrg if test -z "$file_conv"; then 5126372658Smrg # lazily determine how to convert abs files 5226372658Smrg case `uname -s` in 5326372658Smrg MINGW*) 5426372658Smrg file_conv=mingw 5526372658Smrg ;; 56c3e29c03Smrg CYGWIN* | MSYS*) 5726372658Smrg file_conv=cygwin 5826372658Smrg ;; 5926372658Smrg *) 6026372658Smrg file_conv=wine 6126372658Smrg ;; 6226372658Smrg esac 6326372658Smrg fi 6426372658Smrg case $file_conv/,$2, in 6526372658Smrg *,$file_conv,*) 6626372658Smrg ;; 6726372658Smrg mingw/*) 6826372658Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6926372658Smrg ;; 70c3e29c03Smrg cygwin/* | msys/*) 7126372658Smrg file=`cygpath -m "$file" || echo "$file"` 7226372658Smrg ;; 7326372658Smrg wine/*) 7426372658Smrg file=`winepath -w "$file" || echo "$file"` 7526372658Smrg ;; 7626372658Smrg esac 7726372658Smrg ;; 7826372658Smrg esac 7926372658Smrg} 8026372658Smrg 8126372658Smrg# func_cl_dashL linkdir 8226372658Smrg# Make cl look for libraries in LINKDIR 8326372658Smrgfunc_cl_dashL () 8426372658Smrg{ 8526372658Smrg func_file_conv "$1" 8626372658Smrg if test -z "$lib_path"; then 8726372658Smrg lib_path=$file 8826372658Smrg else 8926372658Smrg lib_path="$lib_path;$file" 9026372658Smrg fi 9126372658Smrg linker_opts="$linker_opts -LIBPATH:$file" 9226372658Smrg} 9326372658Smrg 9426372658Smrg# func_cl_dashl library 9526372658Smrg# Do a library search-path lookup for cl 9626372658Smrgfunc_cl_dashl () 9726372658Smrg{ 9826372658Smrg lib=$1 9926372658Smrg found=no 10026372658Smrg save_IFS=$IFS 10126372658Smrg IFS=';' 10226372658Smrg for dir in $lib_path $LIB 10326372658Smrg do 10426372658Smrg IFS=$save_IFS 10526372658Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 10626372658Smrg found=yes 10726372658Smrg lib=$dir/$lib.dll.lib 10826372658Smrg break 10926372658Smrg fi 11026372658Smrg if test -f "$dir/$lib.lib"; then 11126372658Smrg found=yes 11226372658Smrg lib=$dir/$lib.lib 11326372658Smrg break 11426372658Smrg fi 11526372658Smrg if test -f "$dir/lib$lib.a"; then 11626372658Smrg found=yes 11726372658Smrg lib=$dir/lib$lib.a 11826372658Smrg break 11926372658Smrg fi 12026372658Smrg done 12126372658Smrg IFS=$save_IFS 12226372658Smrg 12326372658Smrg if test "$found" != yes; then 12426372658Smrg lib=$lib.lib 12526372658Smrg fi 12626372658Smrg} 12726372658Smrg 12826372658Smrg# func_cl_wrapper cl arg... 12926372658Smrg# Adjust compile command to suit cl 13026372658Smrgfunc_cl_wrapper () 13126372658Smrg{ 13226372658Smrg # Assume a capable shell 13326372658Smrg lib_path= 13426372658Smrg shared=: 13526372658Smrg linker_opts= 13626372658Smrg for arg 13726372658Smrg do 13826372658Smrg if test -n "$eat"; then 13926372658Smrg eat= 14026372658Smrg else 14126372658Smrg case $1 in 14226372658Smrg -o) 14326372658Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 14426372658Smrg eat=1 14526372658Smrg case $2 in 14626372658Smrg *.o | *.[oO][bB][jJ]) 14726372658Smrg func_file_conv "$2" 14826372658Smrg set x "$@" -Fo"$file" 14926372658Smrg shift 15026372658Smrg ;; 15126372658Smrg *) 15226372658Smrg func_file_conv "$2" 15326372658Smrg set x "$@" -Fe"$file" 15426372658Smrg shift 15526372658Smrg ;; 15626372658Smrg esac 15726372658Smrg ;; 15826372658Smrg -I) 15926372658Smrg eat=1 16026372658Smrg func_file_conv "$2" mingw 16126372658Smrg set x "$@" -I"$file" 16226372658Smrg shift 16326372658Smrg ;; 16426372658Smrg -I*) 16526372658Smrg func_file_conv "${1#-I}" mingw 16626372658Smrg set x "$@" -I"$file" 16726372658Smrg shift 16826372658Smrg ;; 16926372658Smrg -l) 17026372658Smrg eat=1 17126372658Smrg func_cl_dashl "$2" 17226372658Smrg set x "$@" "$lib" 17326372658Smrg shift 17426372658Smrg ;; 17526372658Smrg -l*) 17626372658Smrg func_cl_dashl "${1#-l}" 17726372658Smrg set x "$@" "$lib" 17826372658Smrg shift 17926372658Smrg ;; 18026372658Smrg -L) 18126372658Smrg eat=1 18226372658Smrg func_cl_dashL "$2" 18326372658Smrg ;; 18426372658Smrg -L*) 18526372658Smrg func_cl_dashL "${1#-L}" 18626372658Smrg ;; 18726372658Smrg -static) 18826372658Smrg shared=false 18926372658Smrg ;; 19026372658Smrg -Wl,*) 19126372658Smrg arg=${1#-Wl,} 19226372658Smrg save_ifs="$IFS"; IFS=',' 19326372658Smrg for flag in $arg; do 19426372658Smrg IFS="$save_ifs" 19526372658Smrg linker_opts="$linker_opts $flag" 19626372658Smrg done 19726372658Smrg IFS="$save_ifs" 19826372658Smrg ;; 19926372658Smrg -Xlinker) 20026372658Smrg eat=1 20126372658Smrg linker_opts="$linker_opts $2" 20226372658Smrg ;; 20326372658Smrg -*) 20426372658Smrg set x "$@" "$1" 20526372658Smrg shift 20626372658Smrg ;; 20726372658Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20826372658Smrg func_file_conv "$1" 20926372658Smrg set x "$@" -Tp"$file" 21026372658Smrg shift 21126372658Smrg ;; 21226372658Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21326372658Smrg func_file_conv "$1" mingw 21426372658Smrg set x "$@" "$file" 21526372658Smrg shift 21626372658Smrg ;; 21726372658Smrg *) 21826372658Smrg set x "$@" "$1" 21926372658Smrg shift 22026372658Smrg ;; 22126372658Smrg esac 22226372658Smrg fi 22326372658Smrg shift 22426372658Smrg done 22526372658Smrg if test -n "$linker_opts"; then 22626372658Smrg linker_opts="-link$linker_opts" 22726372658Smrg fi 22826372658Smrg exec "$@" $linker_opts 22926372658Smrg exit 1 23026372658Smrg} 23126372658Smrg 23226372658Smrgeat= 23326372658Smrg 23426372658Smrgcase $1 in 23526372658Smrg '') 23626372658Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 23726372658Smrg exit 1; 23826372658Smrg ;; 23926372658Smrg -h | --h*) 24026372658Smrg cat <<\EOF 24126372658SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 24226372658Smrg 24326372658SmrgWrapper for compilers which do not understand '-c -o'. 24426372658SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24526372658Smrgarguments, and rename the output as expected. 24626372658Smrg 24726372658SmrgIf you are trying to build a whole package this is not the 24826372658Smrgright script to run: please start by reading the file 'INSTALL'. 24926372658Smrg 25026372658SmrgReport bugs to <bug-automake@gnu.org>. 25126372658SmrgEOF 25226372658Smrg exit $? 25326372658Smrg ;; 25426372658Smrg -v | --v*) 25526372658Smrg echo "compile $scriptversion" 25626372658Smrg exit $? 25726372658Smrg ;; 258c3e29c03Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 259c3e29c03Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 26026372658Smrg func_cl_wrapper "$@" # Doesn't return... 26126372658Smrg ;; 26226372658Smrgesac 26326372658Smrg 26426372658Smrgofile= 26526372658Smrgcfile= 26626372658Smrg 26726372658Smrgfor arg 26826372658Smrgdo 26926372658Smrg if test -n "$eat"; then 27026372658Smrg eat= 27126372658Smrg else 27226372658Smrg case $1 in 27326372658Smrg -o) 27426372658Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 27526372658Smrg # So we strip '-o arg' only if arg is an object. 27626372658Smrg eat=1 27726372658Smrg case $2 in 27826372658Smrg *.o | *.obj) 27926372658Smrg ofile=$2 28026372658Smrg ;; 28126372658Smrg *) 28226372658Smrg set x "$@" -o "$2" 28326372658Smrg shift 28426372658Smrg ;; 28526372658Smrg esac 28626372658Smrg ;; 28726372658Smrg *.c) 28826372658Smrg cfile=$1 28926372658Smrg set x "$@" "$1" 29026372658Smrg shift 29126372658Smrg ;; 29226372658Smrg *) 29326372658Smrg set x "$@" "$1" 29426372658Smrg shift 29526372658Smrg ;; 29626372658Smrg esac 29726372658Smrg fi 29826372658Smrg shift 29926372658Smrgdone 30026372658Smrg 30126372658Smrgif test -z "$ofile" || test -z "$cfile"; then 30226372658Smrg # If no '-o' option was seen then we might have been invoked from a 30326372658Smrg # pattern rule where we don't need one. That is ok -- this is a 30426372658Smrg # normal compilation that the losing compiler can handle. If no 30526372658Smrg # '.c' file was seen then we are probably linking. That is also 30626372658Smrg # ok. 30726372658Smrg exec "$@" 30826372658Smrgfi 30926372658Smrg 31026372658Smrg# Name of file we expect compiler to create. 31126372658Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31226372658Smrg 31326372658Smrg# Create the lock directory. 31426372658Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31526372658Smrg# that we are using for the .o file. Also, base the name on the expected 31626372658Smrg# object file name, since that is what matters with a parallel build. 31726372658Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31826372658Smrgwhile true; do 31926372658Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 32026372658Smrg break 32126372658Smrg fi 32226372658Smrg sleep 1 32326372658Smrgdone 32426372658Smrg# FIXME: race condition here if user kills between mkdir and trap. 32526372658Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 32626372658Smrg 32726372658Smrg# Run the compile. 32826372658Smrg"$@" 32926372658Smrgret=$? 33026372658Smrg 33126372658Smrgif test -f "$cofile"; then 33226372658Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33326372658Smrgelif test -f "${cofile}bj"; then 33426372658Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33526372658Smrgfi 33626372658Smrg 33726372658Smrgrmdir "$lockdir" 33826372658Smrgexit $ret 33926372658Smrg 34026372658Smrg# Local Variables: 34126372658Smrg# mode: shell-script 34226372658Smrg# sh-indentation: 2 343c3e29c03Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 34426372658Smrg# time-stamp-start: "scriptversion=" 34526372658Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 346c3e29c03Smrg# time-stamp-time-zone: "UTC0" 34726372658Smrg# time-stamp-end: "; # UTC" 34826372658Smrg# End: 349