1b3307321Smrg#! /bin/sh 274a3f230Smrg# Wrapper for compilers which do not understand '-c -o'. 3b3307321Smrg 474b97a6cSmrgscriptversion=2018-03-07.03; # UTC 5afe13c8eSmrg 674b97a6cSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7b3307321Smrg# Written by Tom Tromey <tromey@cygnus.com>. 8b3307321Smrg# 9b3307321Smrg# This program is free software; you can redistribute it and/or modify 10b3307321Smrg# it under the terms of the GNU General Public License as published by 11b3307321Smrg# the Free Software Foundation; either version 2, or (at your option) 12b3307321Smrg# any later version. 13b3307321Smrg# 14b3307321Smrg# This program is distributed in the hope that it will be useful, 15b3307321Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 16b3307321Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17b3307321Smrg# GNU General Public License for more details. 18b3307321Smrg# 19b3307321Smrg# You should have received a copy of the GNU General Public License 2074b97a6cSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 21b3307321Smrg 22b3307321Smrg# As a special exception to the GNU General Public License, if you 23b3307321Smrg# distribute this file as part of a program that contains a 24b3307321Smrg# configuration script generated by Autoconf, you may include it under 25b3307321Smrg# the same distribution terms that you use for the rest of that program. 26b3307321Smrg 27afe13c8eSmrg# This file is maintained in Automake, please report 28afe13c8eSmrg# bugs to <bug-automake@gnu.org> or send patches to 29afe13c8eSmrg# <automake-patches@gnu.org>. 30afe13c8eSmrg 3174a3f230Smrgnl=' 3274a3f230Smrg' 3374a3f230Smrg 3474a3f230Smrg# We need space, tab and new line, in precisely that order. Quoting is 3574a3f230Smrg# there to prevent tools from complaining about whitespace usage. 3674a3f230SmrgIFS=" "" $nl" 3774a3f230Smrg 3874a3f230Smrgfile_conv= 3974a3f230Smrg 4074a3f230Smrg# func_file_conv build_file lazy 4174a3f230Smrg# Convert a $build file to $host form and store it in $file 4274a3f230Smrg# Currently only supports Windows hosts. If the determined conversion 4374a3f230Smrg# type is listed in (the comma separated) LAZY, no conversion will 4474a3f230Smrg# take place. 4574a3f230Smrgfunc_file_conv () 4674a3f230Smrg{ 4774a3f230Smrg file=$1 4874a3f230Smrg case $file in 4974a3f230Smrg / | /[!/]*) # absolute file, and not a UNC file 5074a3f230Smrg if test -z "$file_conv"; then 5174a3f230Smrg # lazily determine how to convert abs files 5274a3f230Smrg case `uname -s` in 5374a3f230Smrg MINGW*) 5474a3f230Smrg file_conv=mingw 5574a3f230Smrg ;; 5674b97a6cSmrg CYGWIN* | MSYS*) 5774a3f230Smrg file_conv=cygwin 5874a3f230Smrg ;; 5974a3f230Smrg *) 6074a3f230Smrg file_conv=wine 6174a3f230Smrg ;; 6274a3f230Smrg esac 6374a3f230Smrg fi 6474a3f230Smrg case $file_conv/,$2, in 6574a3f230Smrg *,$file_conv,*) 6674a3f230Smrg ;; 6774a3f230Smrg mingw/*) 6874a3f230Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6974a3f230Smrg ;; 7074b97a6cSmrg cygwin/* | msys/*) 7174a3f230Smrg file=`cygpath -m "$file" || echo "$file"` 7274a3f230Smrg ;; 7374a3f230Smrg wine/*) 7474a3f230Smrg file=`winepath -w "$file" || echo "$file"` 7574a3f230Smrg ;; 7674a3f230Smrg esac 7774a3f230Smrg ;; 7874a3f230Smrg esac 7974a3f230Smrg} 8074a3f230Smrg 8174a3f230Smrg# func_cl_dashL linkdir 8274a3f230Smrg# Make cl look for libraries in LINKDIR 8374a3f230Smrgfunc_cl_dashL () 8474a3f230Smrg{ 8574a3f230Smrg func_file_conv "$1" 8674a3f230Smrg if test -z "$lib_path"; then 8774a3f230Smrg lib_path=$file 8874a3f230Smrg else 8974a3f230Smrg lib_path="$lib_path;$file" 9074a3f230Smrg fi 9174a3f230Smrg linker_opts="$linker_opts -LIBPATH:$file" 9274a3f230Smrg} 9374a3f230Smrg 9474a3f230Smrg# func_cl_dashl library 9574a3f230Smrg# Do a library search-path lookup for cl 9674a3f230Smrgfunc_cl_dashl () 9774a3f230Smrg{ 9874a3f230Smrg lib=$1 9974a3f230Smrg found=no 10074a3f230Smrg save_IFS=$IFS 10174a3f230Smrg IFS=';' 10274a3f230Smrg for dir in $lib_path $LIB 10374a3f230Smrg do 10474a3f230Smrg IFS=$save_IFS 10574a3f230Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 10674a3f230Smrg found=yes 10774a3f230Smrg lib=$dir/$lib.dll.lib 10874a3f230Smrg break 10974a3f230Smrg fi 11074a3f230Smrg if test -f "$dir/$lib.lib"; then 11174a3f230Smrg found=yes 11274a3f230Smrg lib=$dir/$lib.lib 11374a3f230Smrg break 11474a3f230Smrg fi 11574a3f230Smrg if test -f "$dir/lib$lib.a"; then 11674a3f230Smrg found=yes 11774a3f230Smrg lib=$dir/lib$lib.a 11874a3f230Smrg break 11974a3f230Smrg fi 12074a3f230Smrg done 12174a3f230Smrg IFS=$save_IFS 12274a3f230Smrg 12374a3f230Smrg if test "$found" != yes; then 12474a3f230Smrg lib=$lib.lib 12574a3f230Smrg fi 12674a3f230Smrg} 12774a3f230Smrg 12874a3f230Smrg# func_cl_wrapper cl arg... 12974a3f230Smrg# Adjust compile command to suit cl 13074a3f230Smrgfunc_cl_wrapper () 13174a3f230Smrg{ 13274a3f230Smrg # Assume a capable shell 13374a3f230Smrg lib_path= 13474a3f230Smrg shared=: 13574a3f230Smrg linker_opts= 13674a3f230Smrg for arg 13774a3f230Smrg do 13874a3f230Smrg if test -n "$eat"; then 13974a3f230Smrg eat= 14074a3f230Smrg else 14174a3f230Smrg case $1 in 14274a3f230Smrg -o) 14374a3f230Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 14474a3f230Smrg eat=1 14574a3f230Smrg case $2 in 14674a3f230Smrg *.o | *.[oO][bB][jJ]) 14774a3f230Smrg func_file_conv "$2" 14874a3f230Smrg set x "$@" -Fo"$file" 14974a3f230Smrg shift 15074a3f230Smrg ;; 15174a3f230Smrg *) 15274a3f230Smrg func_file_conv "$2" 15374a3f230Smrg set x "$@" -Fe"$file" 15474a3f230Smrg shift 15574a3f230Smrg ;; 15674a3f230Smrg esac 15774a3f230Smrg ;; 15874a3f230Smrg -I) 15974a3f230Smrg eat=1 16074a3f230Smrg func_file_conv "$2" mingw 16174a3f230Smrg set x "$@" -I"$file" 16274a3f230Smrg shift 16374a3f230Smrg ;; 16474a3f230Smrg -I*) 16574a3f230Smrg func_file_conv "${1#-I}" mingw 16674a3f230Smrg set x "$@" -I"$file" 16774a3f230Smrg shift 16874a3f230Smrg ;; 16974a3f230Smrg -l) 17074a3f230Smrg eat=1 17174a3f230Smrg func_cl_dashl "$2" 17274a3f230Smrg set x "$@" "$lib" 17374a3f230Smrg shift 17474a3f230Smrg ;; 17574a3f230Smrg -l*) 17674a3f230Smrg func_cl_dashl "${1#-l}" 17774a3f230Smrg set x "$@" "$lib" 17874a3f230Smrg shift 17974a3f230Smrg ;; 18074a3f230Smrg -L) 18174a3f230Smrg eat=1 18274a3f230Smrg func_cl_dashL "$2" 18374a3f230Smrg ;; 18474a3f230Smrg -L*) 18574a3f230Smrg func_cl_dashL "${1#-L}" 18674a3f230Smrg ;; 18774a3f230Smrg -static) 18874a3f230Smrg shared=false 18974a3f230Smrg ;; 19074a3f230Smrg -Wl,*) 19174a3f230Smrg arg=${1#-Wl,} 19274a3f230Smrg save_ifs="$IFS"; IFS=',' 19374a3f230Smrg for flag in $arg; do 19474a3f230Smrg IFS="$save_ifs" 19574a3f230Smrg linker_opts="$linker_opts $flag" 19674a3f230Smrg done 19774a3f230Smrg IFS="$save_ifs" 19874a3f230Smrg ;; 19974a3f230Smrg -Xlinker) 20074a3f230Smrg eat=1 20174a3f230Smrg linker_opts="$linker_opts $2" 20274a3f230Smrg ;; 20374a3f230Smrg -*) 20474a3f230Smrg set x "$@" "$1" 20574a3f230Smrg shift 20674a3f230Smrg ;; 20774a3f230Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20874a3f230Smrg func_file_conv "$1" 20974a3f230Smrg set x "$@" -Tp"$file" 21074a3f230Smrg shift 21174a3f230Smrg ;; 21274a3f230Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21374a3f230Smrg func_file_conv "$1" mingw 21474a3f230Smrg set x "$@" "$file" 21574a3f230Smrg shift 21674a3f230Smrg ;; 21774a3f230Smrg *) 21874a3f230Smrg set x "$@" "$1" 21974a3f230Smrg shift 22074a3f230Smrg ;; 22174a3f230Smrg esac 22274a3f230Smrg fi 22374a3f230Smrg shift 22474a3f230Smrg done 22574a3f230Smrg if test -n "$linker_opts"; then 22674a3f230Smrg linker_opts="-link$linker_opts" 22774a3f230Smrg fi 22874a3f230Smrg exec "$@" $linker_opts 22974a3f230Smrg exit 1 23074a3f230Smrg} 23174a3f230Smrg 23274a3f230Smrgeat= 23374a3f230Smrg 234afe13c8eSmrgcase $1 in 235afe13c8eSmrg '') 23674a3f230Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 237afe13c8eSmrg exit 1; 238afe13c8eSmrg ;; 239afe13c8eSmrg -h | --h*) 240afe13c8eSmrg cat <<\EOF 241afe13c8eSmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 242afe13c8eSmrg 24374a3f230SmrgWrapper for compilers which do not understand '-c -o'. 24474a3f230SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 245afe13c8eSmrgarguments, and rename the output as expected. 246b3307321Smrg 247afe13c8eSmrgIf you are trying to build a whole package this is not the 24874a3f230Smrgright script to run: please start by reading the file 'INSTALL'. 249afe13c8eSmrg 250afe13c8eSmrgReport bugs to <bug-automake@gnu.org>. 251afe13c8eSmrgEOF 252afe13c8eSmrg exit $? 253afe13c8eSmrg ;; 254afe13c8eSmrg -v | --v*) 255afe13c8eSmrg echo "compile $scriptversion" 256afe13c8eSmrg exit $? 257afe13c8eSmrg ;; 25874b97a6cSmrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 25974b97a6cSmrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 26074a3f230Smrg func_cl_wrapper "$@" # Doesn't return... 26174a3f230Smrg ;; 262afe13c8eSmrgesac 263b3307321Smrg 264b3307321Smrgofile= 265b3307321Smrgcfile= 266afe13c8eSmrg 267afe13c8eSmrgfor arg 268afe13c8eSmrgdo 269afe13c8eSmrg if test -n "$eat"; then 270afe13c8eSmrg eat= 271afe13c8eSmrg else 272afe13c8eSmrg case $1 in 273afe13c8eSmrg -o) 27474a3f230Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 27574a3f230Smrg # So we strip '-o arg' only if arg is an object. 276afe13c8eSmrg eat=1 277afe13c8eSmrg case $2 in 278afe13c8eSmrg *.o | *.obj) 279afe13c8eSmrg ofile=$2 280afe13c8eSmrg ;; 281afe13c8eSmrg *) 282afe13c8eSmrg set x "$@" -o "$2" 283afe13c8eSmrg shift 284afe13c8eSmrg ;; 285afe13c8eSmrg esac 286afe13c8eSmrg ;; 287afe13c8eSmrg *.c) 288afe13c8eSmrg cfile=$1 289afe13c8eSmrg set x "$@" "$1" 290afe13c8eSmrg shift 291afe13c8eSmrg ;; 292afe13c8eSmrg *) 293afe13c8eSmrg set x "$@" "$1" 294afe13c8eSmrg shift 295afe13c8eSmrg ;; 296afe13c8eSmrg esac 297afe13c8eSmrg fi 298afe13c8eSmrg shift 299b3307321Smrgdone 300b3307321Smrg 301b3307321Smrgif test -z "$ofile" || test -z "$cfile"; then 30274a3f230Smrg # If no '-o' option was seen then we might have been invoked from a 303afe13c8eSmrg # pattern rule where we don't need one. That is ok -- this is a 304afe13c8eSmrg # normal compilation that the losing compiler can handle. If no 30574a3f230Smrg # '.c' file was seen then we are probably linking. That is also 306afe13c8eSmrg # ok. 307afe13c8eSmrg exec "$@" 308b3307321Smrgfi 309b3307321Smrg 310b3307321Smrg# Name of file we expect compiler to create. 31174a3f230Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 312b3307321Smrg 313b3307321Smrg# Create the lock directory. 31474a3f230Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 315b3307321Smrg# that we are using for the .o file. Also, base the name on the expected 316b3307321Smrg# object file name, since that is what matters with a parallel build. 31774a3f230Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 318b3307321Smrgwhile true; do 319afe13c8eSmrg if mkdir "$lockdir" >/dev/null 2>&1; then 320afe13c8eSmrg break 321afe13c8eSmrg fi 322afe13c8eSmrg sleep 1 323b3307321Smrgdone 324b3307321Smrg# FIXME: race condition here if user kills between mkdir and trap. 325afe13c8eSmrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 326b3307321Smrg 327b3307321Smrg# Run the compile. 328afe13c8eSmrg"$@" 329afe13c8eSmrgret=$? 330b3307321Smrg 331b3307321Smrgif test -f "$cofile"; then 33274a3f230Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 333afe13c8eSmrgelif test -f "${cofile}bj"; then 33474a3f230Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 335b3307321Smrgfi 336b3307321Smrg 337afe13c8eSmrgrmdir "$lockdir" 338afe13c8eSmrgexit $ret 339afe13c8eSmrg 340afe13c8eSmrg# Local Variables: 341afe13c8eSmrg# mode: shell-script 342afe13c8eSmrg# sh-indentation: 2 34374b97a6cSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 344afe13c8eSmrg# time-stamp-start: "scriptversion=" 345afe13c8eSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 34674b97a6cSmrg# time-stamp-time-zone: "UTC0" 34774a3f230Smrg# time-stamp-end: "; # UTC" 348afe13c8eSmrg# End: 349