144584a44Smrg#! /bin/sh 244584a44Smrg# Wrapper for compilers which do not understand '-c -o'. 344584a44Smrg 44940c694Smrgscriptversion=2018-03-07.03; # UTC 544584a44Smrg 64e8f48c7Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 744584a44Smrg# Written by Tom Tromey <tromey@cygnus.com>. 844584a44Smrg# 944584a44Smrg# This program is free software; you can redistribute it and/or modify 1044584a44Smrg# it under the terms of the GNU General Public License as published by 1144584a44Smrg# the Free Software Foundation; either version 2, or (at your option) 1244584a44Smrg# any later version. 1344584a44Smrg# 1444584a44Smrg# This program is distributed in the hope that it will be useful, 1544584a44Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1644584a44Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1744584a44Smrg# GNU General Public License for more details. 1844584a44Smrg# 1944584a44Smrg# You should have received a copy of the GNU General Public License 204940c694Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2144584a44Smrg 2244584a44Smrg# As a special exception to the GNU General Public License, if you 2344584a44Smrg# distribute this file as part of a program that contains a 2444584a44Smrg# configuration script generated by Autoconf, you may include it under 2544584a44Smrg# the same distribution terms that you use for the rest of that program. 2644584a44Smrg 2744584a44Smrg# This file is maintained in Automake, please report 2844584a44Smrg# bugs to <bug-automake@gnu.org> or send patches to 2944584a44Smrg# <automake-patches@gnu.org>. 3044584a44Smrg 3144584a44Smrgnl=' 3244584a44Smrg' 3344584a44Smrg 3444584a44Smrg# We need space, tab and new line, in precisely that order. Quoting is 3544584a44Smrg# there to prevent tools from complaining about whitespace usage. 3644584a44SmrgIFS=" "" $nl" 3744584a44Smrg 3844584a44Smrgfile_conv= 3944584a44Smrg 4044584a44Smrg# func_file_conv build_file lazy 4144584a44Smrg# Convert a $build file to $host form and store it in $file 4244584a44Smrg# Currently only supports Windows hosts. If the determined conversion 4344584a44Smrg# type is listed in (the comma separated) LAZY, no conversion will 4444584a44Smrg# take place. 4544584a44Smrgfunc_file_conv () 4644584a44Smrg{ 4744584a44Smrg file=$1 4844584a44Smrg case $file in 4944584a44Smrg / | /[!/]*) # absolute file, and not a UNC file 5044584a44Smrg if test -z "$file_conv"; then 5144584a44Smrg # lazily determine how to convert abs files 5244584a44Smrg case `uname -s` in 5344584a44Smrg MINGW*) 5444584a44Smrg file_conv=mingw 5544584a44Smrg ;; 564e8f48c7Smrg CYGWIN* | MSYS*) 5744584a44Smrg file_conv=cygwin 5844584a44Smrg ;; 5944584a44Smrg *) 6044584a44Smrg file_conv=wine 6144584a44Smrg ;; 6244584a44Smrg esac 6344584a44Smrg fi 6444584a44Smrg case $file_conv/,$2, in 6544584a44Smrg *,$file_conv,*) 6644584a44Smrg ;; 6744584a44Smrg mingw/*) 6844584a44Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6944584a44Smrg ;; 704e8f48c7Smrg cygwin/* | msys/*) 7144584a44Smrg file=`cygpath -m "$file" || echo "$file"` 7244584a44Smrg ;; 7344584a44Smrg wine/*) 7444584a44Smrg file=`winepath -w "$file" || echo "$file"` 7544584a44Smrg ;; 7644584a44Smrg esac 7744584a44Smrg ;; 7844584a44Smrg esac 7944584a44Smrg} 8044584a44Smrg 8144584a44Smrg# func_cl_dashL linkdir 8244584a44Smrg# Make cl look for libraries in LINKDIR 8344584a44Smrgfunc_cl_dashL () 8444584a44Smrg{ 8544584a44Smrg func_file_conv "$1" 8644584a44Smrg if test -z "$lib_path"; then 8744584a44Smrg lib_path=$file 8844584a44Smrg else 8944584a44Smrg lib_path="$lib_path;$file" 9044584a44Smrg fi 9144584a44Smrg linker_opts="$linker_opts -LIBPATH:$file" 9244584a44Smrg} 9344584a44Smrg 9444584a44Smrg# func_cl_dashl library 9544584a44Smrg# Do a library search-path lookup for cl 9644584a44Smrgfunc_cl_dashl () 9744584a44Smrg{ 9844584a44Smrg lib=$1 9944584a44Smrg found=no 10044584a44Smrg save_IFS=$IFS 10144584a44Smrg IFS=';' 10244584a44Smrg for dir in $lib_path $LIB 10344584a44Smrg do 10444584a44Smrg IFS=$save_IFS 10544584a44Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 10644584a44Smrg found=yes 10744584a44Smrg lib=$dir/$lib.dll.lib 10844584a44Smrg break 10944584a44Smrg fi 11044584a44Smrg if test -f "$dir/$lib.lib"; then 11144584a44Smrg found=yes 11244584a44Smrg lib=$dir/$lib.lib 11344584a44Smrg break 11444584a44Smrg fi 11544584a44Smrg if test -f "$dir/lib$lib.a"; then 11644584a44Smrg found=yes 11744584a44Smrg lib=$dir/lib$lib.a 11844584a44Smrg break 11944584a44Smrg fi 12044584a44Smrg done 12144584a44Smrg IFS=$save_IFS 12244584a44Smrg 12344584a44Smrg if test "$found" != yes; then 12444584a44Smrg lib=$lib.lib 12544584a44Smrg fi 12644584a44Smrg} 12744584a44Smrg 12844584a44Smrg# func_cl_wrapper cl arg... 12944584a44Smrg# Adjust compile command to suit cl 13044584a44Smrgfunc_cl_wrapper () 13144584a44Smrg{ 13244584a44Smrg # Assume a capable shell 13344584a44Smrg lib_path= 13444584a44Smrg shared=: 13544584a44Smrg linker_opts= 13644584a44Smrg for arg 13744584a44Smrg do 13844584a44Smrg if test -n "$eat"; then 13944584a44Smrg eat= 14044584a44Smrg else 14144584a44Smrg case $1 in 14244584a44Smrg -o) 14344584a44Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 14444584a44Smrg eat=1 14544584a44Smrg case $2 in 14644584a44Smrg *.o | *.[oO][bB][jJ]) 14744584a44Smrg func_file_conv "$2" 14844584a44Smrg set x "$@" -Fo"$file" 14944584a44Smrg shift 15044584a44Smrg ;; 15144584a44Smrg *) 15244584a44Smrg func_file_conv "$2" 15344584a44Smrg set x "$@" -Fe"$file" 15444584a44Smrg shift 15544584a44Smrg ;; 15644584a44Smrg esac 15744584a44Smrg ;; 15844584a44Smrg -I) 15944584a44Smrg eat=1 16044584a44Smrg func_file_conv "$2" mingw 16144584a44Smrg set x "$@" -I"$file" 16244584a44Smrg shift 16344584a44Smrg ;; 16444584a44Smrg -I*) 16544584a44Smrg func_file_conv "${1#-I}" mingw 16644584a44Smrg set x "$@" -I"$file" 16744584a44Smrg shift 16844584a44Smrg ;; 16944584a44Smrg -l) 17044584a44Smrg eat=1 17144584a44Smrg func_cl_dashl "$2" 17244584a44Smrg set x "$@" "$lib" 17344584a44Smrg shift 17444584a44Smrg ;; 17544584a44Smrg -l*) 17644584a44Smrg func_cl_dashl "${1#-l}" 17744584a44Smrg set x "$@" "$lib" 17844584a44Smrg shift 17944584a44Smrg ;; 18044584a44Smrg -L) 18144584a44Smrg eat=1 18244584a44Smrg func_cl_dashL "$2" 18344584a44Smrg ;; 18444584a44Smrg -L*) 18544584a44Smrg func_cl_dashL "${1#-L}" 18644584a44Smrg ;; 18744584a44Smrg -static) 18844584a44Smrg shared=false 18944584a44Smrg ;; 19044584a44Smrg -Wl,*) 19144584a44Smrg arg=${1#-Wl,} 19244584a44Smrg save_ifs="$IFS"; IFS=',' 19344584a44Smrg for flag in $arg; do 19444584a44Smrg IFS="$save_ifs" 19544584a44Smrg linker_opts="$linker_opts $flag" 19644584a44Smrg done 19744584a44Smrg IFS="$save_ifs" 19844584a44Smrg ;; 19944584a44Smrg -Xlinker) 20044584a44Smrg eat=1 20144584a44Smrg linker_opts="$linker_opts $2" 20244584a44Smrg ;; 20344584a44Smrg -*) 20444584a44Smrg set x "$@" "$1" 20544584a44Smrg shift 20644584a44Smrg ;; 20744584a44Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20844584a44Smrg func_file_conv "$1" 20944584a44Smrg set x "$@" -Tp"$file" 21044584a44Smrg shift 21144584a44Smrg ;; 21244584a44Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21344584a44Smrg func_file_conv "$1" mingw 21444584a44Smrg set x "$@" "$file" 21544584a44Smrg shift 21644584a44Smrg ;; 21744584a44Smrg *) 21844584a44Smrg set x "$@" "$1" 21944584a44Smrg shift 22044584a44Smrg ;; 22144584a44Smrg esac 22244584a44Smrg fi 22344584a44Smrg shift 22444584a44Smrg done 22544584a44Smrg if test -n "$linker_opts"; then 22644584a44Smrg linker_opts="-link$linker_opts" 22744584a44Smrg fi 22844584a44Smrg exec "$@" $linker_opts 22944584a44Smrg exit 1 23044584a44Smrg} 23144584a44Smrg 23244584a44Smrgeat= 23344584a44Smrg 23444584a44Smrgcase $1 in 23544584a44Smrg '') 23644584a44Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 23744584a44Smrg exit 1; 23844584a44Smrg ;; 23944584a44Smrg -h | --h*) 24044584a44Smrg cat <<\EOF 24144584a44SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 24244584a44Smrg 24344584a44SmrgWrapper for compilers which do not understand '-c -o'. 24444584a44SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24544584a44Smrgarguments, and rename the output as expected. 24644584a44Smrg 24744584a44SmrgIf you are trying to build a whole package this is not the 24844584a44Smrgright script to run: please start by reading the file 'INSTALL'. 24944584a44Smrg 25044584a44SmrgReport bugs to <bug-automake@gnu.org>. 25144584a44SmrgEOF 25244584a44Smrg exit $? 25344584a44Smrg ;; 25444584a44Smrg -v | --v*) 25544584a44Smrg echo "compile $scriptversion" 25644584a44Smrg exit $? 25744584a44Smrg ;; 2584940c694Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 2594940c694Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 26044584a44Smrg func_cl_wrapper "$@" # Doesn't return... 26144584a44Smrg ;; 26244584a44Smrgesac 26344584a44Smrg 26444584a44Smrgofile= 26544584a44Smrgcfile= 26644584a44Smrg 26744584a44Smrgfor arg 26844584a44Smrgdo 26944584a44Smrg if test -n "$eat"; then 27044584a44Smrg eat= 27144584a44Smrg else 27244584a44Smrg case $1 in 27344584a44Smrg -o) 27444584a44Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 27544584a44Smrg # So we strip '-o arg' only if arg is an object. 27644584a44Smrg eat=1 27744584a44Smrg case $2 in 27844584a44Smrg *.o | *.obj) 27944584a44Smrg ofile=$2 28044584a44Smrg ;; 28144584a44Smrg *) 28244584a44Smrg set x "$@" -o "$2" 28344584a44Smrg shift 28444584a44Smrg ;; 28544584a44Smrg esac 28644584a44Smrg ;; 28744584a44Smrg *.c) 28844584a44Smrg cfile=$1 28944584a44Smrg set x "$@" "$1" 29044584a44Smrg shift 29144584a44Smrg ;; 29244584a44Smrg *) 29344584a44Smrg set x "$@" "$1" 29444584a44Smrg shift 29544584a44Smrg ;; 29644584a44Smrg esac 29744584a44Smrg fi 29844584a44Smrg shift 29944584a44Smrgdone 30044584a44Smrg 30144584a44Smrgif test -z "$ofile" || test -z "$cfile"; then 30244584a44Smrg # If no '-o' option was seen then we might have been invoked from a 30344584a44Smrg # pattern rule where we don't need one. That is ok -- this is a 30444584a44Smrg # normal compilation that the losing compiler can handle. If no 30544584a44Smrg # '.c' file was seen then we are probably linking. That is also 30644584a44Smrg # ok. 30744584a44Smrg exec "$@" 30844584a44Smrgfi 30944584a44Smrg 31044584a44Smrg# Name of file we expect compiler to create. 31144584a44Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31244584a44Smrg 31344584a44Smrg# Create the lock directory. 31444584a44Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31544584a44Smrg# that we are using for the .o file. Also, base the name on the expected 31644584a44Smrg# object file name, since that is what matters with a parallel build. 31744584a44Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31844584a44Smrgwhile true; do 31944584a44Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 32044584a44Smrg break 32144584a44Smrg fi 32244584a44Smrg sleep 1 32344584a44Smrgdone 32444584a44Smrg# FIXME: race condition here if user kills between mkdir and trap. 32544584a44Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 32644584a44Smrg 32744584a44Smrg# Run the compile. 32844584a44Smrg"$@" 32944584a44Smrgret=$? 33044584a44Smrg 33144584a44Smrgif test -f "$cofile"; then 33244584a44Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33344584a44Smrgelif test -f "${cofile}bj"; then 33444584a44Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33544584a44Smrgfi 33644584a44Smrg 33744584a44Smrgrmdir "$lockdir" 33844584a44Smrgexit $ret 33944584a44Smrg 34044584a44Smrg# Local Variables: 34144584a44Smrg# mode: shell-script 34244584a44Smrg# sh-indentation: 2 3434940c694Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 34444584a44Smrg# time-stamp-start: "scriptversion=" 34544584a44Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 3464940c694Smrg# time-stamp-time-zone: "UTC0" 34744584a44Smrg# time-stamp-end: "; # UTC" 34844584a44Smrg# End: 349