190a8ff21Smrg#!/bin/sh 290a8ff21Smrg# Wrapper for compilers which do not understand '-c -o'. 390a8ff21Smrg 490a8ff21Smrgscriptversion=2018-03-07.03; # UTC 590a8ff21Smrg 6*367b8279Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 790a8ff21Smrg# Written by Tom Tromey <tromey@cygnus.com>. 890a8ff21Smrg# 990a8ff21Smrg# This program is free software; you can redistribute it and/or modify 1090a8ff21Smrg# it under the terms of the GNU General Public License as published by 1190a8ff21Smrg# the Free Software Foundation; either version 2, or (at your option) 1290a8ff21Smrg# any later version. 1390a8ff21Smrg# 1490a8ff21Smrg# This program is distributed in the hope that it will be useful, 1590a8ff21Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1690a8ff21Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1790a8ff21Smrg# GNU General Public License for more details. 1890a8ff21Smrg# 1990a8ff21Smrg# You should have received a copy of the GNU General Public License 2090a8ff21Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 2190a8ff21Smrg 2290a8ff21Smrg# As a special exception to the GNU General Public License, if you 2390a8ff21Smrg# distribute this file as part of a program that contains a 2490a8ff21Smrg# configuration script generated by Autoconf, you may include it under 2590a8ff21Smrg# the same distribution terms that you use for the rest of that program. 2690a8ff21Smrg 2790a8ff21Smrg# This file is maintained in Automake, please report 2890a8ff21Smrg# bugs to <bug-automake@gnu.org> or send patches to 2990a8ff21Smrg# <automake-patches@gnu.org>. 3090a8ff21Smrg 3190a8ff21Smrgnl=' 3290a8ff21Smrg' 3390a8ff21Smrg 3490a8ff21Smrg# We need space, tab and new line, in precisely that order. Quoting is 3590a8ff21Smrg# there to prevent tools from complaining about whitespace usage. 3690a8ff21SmrgIFS=" "" $nl" 3790a8ff21Smrg 3890a8ff21Smrgfile_conv= 3990a8ff21Smrg 4090a8ff21Smrg# func_file_conv build_file lazy 4190a8ff21Smrg# Convert a $build file to $host form and store it in $file 4290a8ff21Smrg# Currently only supports Windows hosts. If the determined conversion 4390a8ff21Smrg# type is listed in (the comma separated) LAZY, no conversion will 4490a8ff21Smrg# take place. 4590a8ff21Smrgfunc_file_conv () 4690a8ff21Smrg{ 4790a8ff21Smrg file=$1 4890a8ff21Smrg case $file in 4990a8ff21Smrg / | /[!/]*) # absolute file, and not a UNC file 5090a8ff21Smrg if test -z "$file_conv"; then 5190a8ff21Smrg # lazily determine how to convert abs files 5290a8ff21Smrg case `uname -s` in 5390a8ff21Smrg MINGW*) 5490a8ff21Smrg file_conv=mingw 5590a8ff21Smrg ;; 5690a8ff21Smrg CYGWIN* | MSYS*) 5790a8ff21Smrg file_conv=cygwin 5890a8ff21Smrg ;; 5990a8ff21Smrg *) 6090a8ff21Smrg file_conv=wine 6190a8ff21Smrg ;; 6290a8ff21Smrg esac 6390a8ff21Smrg fi 6490a8ff21Smrg case $file_conv/,$2, in 6590a8ff21Smrg *,$file_conv,*) 6690a8ff21Smrg ;; 6790a8ff21Smrg mingw/*) 6890a8ff21Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6990a8ff21Smrg ;; 7090a8ff21Smrg cygwin/* | msys/*) 7190a8ff21Smrg file=`cygpath -m "$file" || echo "$file"` 7290a8ff21Smrg ;; 7390a8ff21Smrg wine/*) 7490a8ff21Smrg file=`winepath -w "$file" || echo "$file"` 7590a8ff21Smrg ;; 7690a8ff21Smrg esac 7790a8ff21Smrg ;; 7890a8ff21Smrg esac 7990a8ff21Smrg} 8090a8ff21Smrg 8190a8ff21Smrg# func_cl_dashL linkdir 8290a8ff21Smrg# Make cl look for libraries in LINKDIR 8390a8ff21Smrgfunc_cl_dashL () 8490a8ff21Smrg{ 8590a8ff21Smrg func_file_conv "$1" 8690a8ff21Smrg if test -z "$lib_path"; then 8790a8ff21Smrg lib_path=$file 8890a8ff21Smrg else 8990a8ff21Smrg lib_path="$lib_path;$file" 9090a8ff21Smrg fi 9190a8ff21Smrg linker_opts="$linker_opts -LIBPATH:$file" 9290a8ff21Smrg} 9390a8ff21Smrg 9490a8ff21Smrg# func_cl_dashl library 9590a8ff21Smrg# Do a library search-path lookup for cl 9690a8ff21Smrgfunc_cl_dashl () 9790a8ff21Smrg{ 9890a8ff21Smrg lib=$1 9990a8ff21Smrg found=no 10090a8ff21Smrg save_IFS=$IFS 10190a8ff21Smrg IFS=';' 10290a8ff21Smrg for dir in $lib_path $LIB 10390a8ff21Smrg do 10490a8ff21Smrg IFS=$save_IFS 10590a8ff21Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 10690a8ff21Smrg found=yes 10790a8ff21Smrg lib=$dir/$lib.dll.lib 10890a8ff21Smrg break 10990a8ff21Smrg fi 11090a8ff21Smrg if test -f "$dir/$lib.lib"; then 11190a8ff21Smrg found=yes 11290a8ff21Smrg lib=$dir/$lib.lib 11390a8ff21Smrg break 11490a8ff21Smrg fi 11590a8ff21Smrg if test -f "$dir/lib$lib.a"; then 11690a8ff21Smrg found=yes 11790a8ff21Smrg lib=$dir/lib$lib.a 11890a8ff21Smrg break 11990a8ff21Smrg fi 12090a8ff21Smrg done 12190a8ff21Smrg IFS=$save_IFS 12290a8ff21Smrg 12390a8ff21Smrg if test "$found" != yes; then 12490a8ff21Smrg lib=$lib.lib 12590a8ff21Smrg fi 12690a8ff21Smrg} 12790a8ff21Smrg 12890a8ff21Smrg# func_cl_wrapper cl arg... 12990a8ff21Smrg# Adjust compile command to suit cl 13090a8ff21Smrgfunc_cl_wrapper () 13190a8ff21Smrg{ 13290a8ff21Smrg # Assume a capable shell 13390a8ff21Smrg lib_path= 13490a8ff21Smrg shared=: 13590a8ff21Smrg linker_opts= 13690a8ff21Smrg for arg 13790a8ff21Smrg do 13890a8ff21Smrg if test -n "$eat"; then 13990a8ff21Smrg eat= 14090a8ff21Smrg else 14190a8ff21Smrg case $1 in 14290a8ff21Smrg -o) 14390a8ff21Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 14490a8ff21Smrg eat=1 14590a8ff21Smrg case $2 in 14690a8ff21Smrg *.o | *.[oO][bB][jJ]) 14790a8ff21Smrg func_file_conv "$2" 14890a8ff21Smrg set x "$@" -Fo"$file" 14990a8ff21Smrg shift 15090a8ff21Smrg ;; 15190a8ff21Smrg *) 15290a8ff21Smrg func_file_conv "$2" 15390a8ff21Smrg set x "$@" -Fe"$file" 15490a8ff21Smrg shift 15590a8ff21Smrg ;; 15690a8ff21Smrg esac 15790a8ff21Smrg ;; 15890a8ff21Smrg -I) 15990a8ff21Smrg eat=1 16090a8ff21Smrg func_file_conv "$2" mingw 16190a8ff21Smrg set x "$@" -I"$file" 16290a8ff21Smrg shift 16390a8ff21Smrg ;; 16490a8ff21Smrg -I*) 16590a8ff21Smrg func_file_conv "${1#-I}" mingw 16690a8ff21Smrg set x "$@" -I"$file" 16790a8ff21Smrg shift 16890a8ff21Smrg ;; 16990a8ff21Smrg -l) 17090a8ff21Smrg eat=1 17190a8ff21Smrg func_cl_dashl "$2" 17290a8ff21Smrg set x "$@" "$lib" 17390a8ff21Smrg shift 17490a8ff21Smrg ;; 17590a8ff21Smrg -l*) 17690a8ff21Smrg func_cl_dashl "${1#-l}" 17790a8ff21Smrg set x "$@" "$lib" 17890a8ff21Smrg shift 17990a8ff21Smrg ;; 18090a8ff21Smrg -L) 18190a8ff21Smrg eat=1 18290a8ff21Smrg func_cl_dashL "$2" 18390a8ff21Smrg ;; 18490a8ff21Smrg -L*) 18590a8ff21Smrg func_cl_dashL "${1#-L}" 18690a8ff21Smrg ;; 18790a8ff21Smrg -static) 18890a8ff21Smrg shared=false 18990a8ff21Smrg ;; 19090a8ff21Smrg -Wl,*) 19190a8ff21Smrg arg=${1#-Wl,} 19290a8ff21Smrg save_ifs="$IFS"; IFS=',' 19390a8ff21Smrg for flag in $arg; do 19490a8ff21Smrg IFS="$save_ifs" 19590a8ff21Smrg linker_opts="$linker_opts $flag" 19690a8ff21Smrg done 19790a8ff21Smrg IFS="$save_ifs" 19890a8ff21Smrg ;; 19990a8ff21Smrg -Xlinker) 20090a8ff21Smrg eat=1 20190a8ff21Smrg linker_opts="$linker_opts $2" 20290a8ff21Smrg ;; 20390a8ff21Smrg -*) 20490a8ff21Smrg set x "$@" "$1" 20590a8ff21Smrg shift 20690a8ff21Smrg ;; 20790a8ff21Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20890a8ff21Smrg func_file_conv "$1" 20990a8ff21Smrg set x "$@" -Tp"$file" 21090a8ff21Smrg shift 21190a8ff21Smrg ;; 21290a8ff21Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21390a8ff21Smrg func_file_conv "$1" mingw 21490a8ff21Smrg set x "$@" "$file" 21590a8ff21Smrg shift 21690a8ff21Smrg ;; 21790a8ff21Smrg *) 21890a8ff21Smrg set x "$@" "$1" 21990a8ff21Smrg shift 22090a8ff21Smrg ;; 22190a8ff21Smrg esac 22290a8ff21Smrg fi 22390a8ff21Smrg shift 22490a8ff21Smrg done 22590a8ff21Smrg if test -n "$linker_opts"; then 22690a8ff21Smrg linker_opts="-link$linker_opts" 22790a8ff21Smrg fi 22890a8ff21Smrg exec "$@" $linker_opts 22990a8ff21Smrg exit 1 23090a8ff21Smrg} 23190a8ff21Smrg 23290a8ff21Smrgeat= 23390a8ff21Smrg 23490a8ff21Smrgcase $1 in 23590a8ff21Smrg '') 23690a8ff21Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 23790a8ff21Smrg exit 1; 23890a8ff21Smrg ;; 23990a8ff21Smrg -h | --h*) 24090a8ff21Smrg cat <<\EOF 24190a8ff21SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 24290a8ff21Smrg 24390a8ff21SmrgWrapper for compilers which do not understand '-c -o'. 24490a8ff21SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24590a8ff21Smrgarguments, and rename the output as expected. 24690a8ff21Smrg 24790a8ff21SmrgIf you are trying to build a whole package this is not the 24890a8ff21Smrgright script to run: please start by reading the file 'INSTALL'. 24990a8ff21Smrg 25090a8ff21SmrgReport bugs to <bug-automake@gnu.org>. 25190a8ff21SmrgEOF 25290a8ff21Smrg exit $? 25390a8ff21Smrg ;; 25490a8ff21Smrg -v | --v*) 25590a8ff21Smrg echo "compile $scriptversion" 25690a8ff21Smrg exit $? 25790a8ff21Smrg ;; 25890a8ff21Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 25990a8ff21Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 26090a8ff21Smrg func_cl_wrapper "$@" # Doesn't return... 26190a8ff21Smrg ;; 26290a8ff21Smrgesac 26390a8ff21Smrg 26490a8ff21Smrgofile= 26590a8ff21Smrgcfile= 26690a8ff21Smrg 26790a8ff21Smrgfor arg 26890a8ff21Smrgdo 26990a8ff21Smrg if test -n "$eat"; then 27090a8ff21Smrg eat= 27190a8ff21Smrg else 27290a8ff21Smrg case $1 in 27390a8ff21Smrg -o) 27490a8ff21Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 27590a8ff21Smrg # So we strip '-o arg' only if arg is an object. 27690a8ff21Smrg eat=1 27790a8ff21Smrg case $2 in 27890a8ff21Smrg *.o | *.obj) 27990a8ff21Smrg ofile=$2 28090a8ff21Smrg ;; 28190a8ff21Smrg *) 28290a8ff21Smrg set x "$@" -o "$2" 28390a8ff21Smrg shift 28490a8ff21Smrg ;; 28590a8ff21Smrg esac 28690a8ff21Smrg ;; 28790a8ff21Smrg *.c) 28890a8ff21Smrg cfile=$1 28990a8ff21Smrg set x "$@" "$1" 29090a8ff21Smrg shift 29190a8ff21Smrg ;; 29290a8ff21Smrg *) 29390a8ff21Smrg set x "$@" "$1" 29490a8ff21Smrg shift 29590a8ff21Smrg ;; 29690a8ff21Smrg esac 29790a8ff21Smrg fi 29890a8ff21Smrg shift 29990a8ff21Smrgdone 30090a8ff21Smrg 30190a8ff21Smrgif test -z "$ofile" || test -z "$cfile"; then 30290a8ff21Smrg # If no '-o' option was seen then we might have been invoked from a 30390a8ff21Smrg # pattern rule where we don't need one. That is ok -- this is a 30490a8ff21Smrg # normal compilation that the losing compiler can handle. If no 30590a8ff21Smrg # '.c' file was seen then we are probably linking. That is also 30690a8ff21Smrg # ok. 30790a8ff21Smrg exec "$@" 30890a8ff21Smrgfi 30990a8ff21Smrg 31090a8ff21Smrg# Name of file we expect compiler to create. 31190a8ff21Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31290a8ff21Smrg 31390a8ff21Smrg# Create the lock directory. 31490a8ff21Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31590a8ff21Smrg# that we are using for the .o file. Also, base the name on the expected 31690a8ff21Smrg# object file name, since that is what matters with a parallel build. 31790a8ff21Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31890a8ff21Smrgwhile true; do 31990a8ff21Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 32090a8ff21Smrg break 32190a8ff21Smrg fi 32290a8ff21Smrg sleep 1 32390a8ff21Smrgdone 32490a8ff21Smrg# FIXME: race condition here if user kills between mkdir and trap. 32590a8ff21Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 32690a8ff21Smrg 32790a8ff21Smrg# Run the compile. 32890a8ff21Smrg"$@" 32990a8ff21Smrgret=$? 33090a8ff21Smrg 33190a8ff21Smrgif test -f "$cofile"; then 33290a8ff21Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33390a8ff21Smrgelif test -f "${cofile}bj"; then 33490a8ff21Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33590a8ff21Smrgfi 33690a8ff21Smrg 33790a8ff21Smrgrmdir "$lockdir" 33890a8ff21Smrgexit $ret 33990a8ff21Smrg 34090a8ff21Smrg# Local Variables: 34190a8ff21Smrg# mode: shell-script 34290a8ff21Smrg# sh-indentation: 2 34390a8ff21Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 34490a8ff21Smrg# time-stamp-start: "scriptversion=" 34590a8ff21Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 34690a8ff21Smrg# time-stamp-time-zone: "UTC0" 34790a8ff21Smrg# time-stamp-end: "; # UTC" 34890a8ff21Smrg# End: 349