1a733a5bfSmrg#! /bin/sh 2a733a5bfSmrg# Wrapper for compilers which do not understand '-c -o'. 3a733a5bfSmrg 46eaa481cSmrgscriptversion=2018-03-07.03; # UTC 5a733a5bfSmrg 66eaa481cSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7a733a5bfSmrg# Written by Tom Tromey <tromey@cygnus.com>. 8a733a5bfSmrg# 9a733a5bfSmrg# This program is free software; you can redistribute it and/or modify 10a733a5bfSmrg# it under the terms of the GNU General Public License as published by 11a733a5bfSmrg# the Free Software Foundation; either version 2, or (at your option) 12a733a5bfSmrg# any later version. 13a733a5bfSmrg# 14a733a5bfSmrg# This program is distributed in the hope that it will be useful, 15a733a5bfSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 16a733a5bfSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17a733a5bfSmrg# GNU General Public License for more details. 18a733a5bfSmrg# 19a733a5bfSmrg# You should have received a copy of the GNU General Public License 206eaa481cSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 21a733a5bfSmrg 22a733a5bfSmrg# As a special exception to the GNU General Public License, if you 23a733a5bfSmrg# distribute this file as part of a program that contains a 24a733a5bfSmrg# configuration script generated by Autoconf, you may include it under 25a733a5bfSmrg# the same distribution terms that you use for the rest of that program. 26a733a5bfSmrg 27a733a5bfSmrg# This file is maintained in Automake, please report 28a733a5bfSmrg# bugs to <bug-automake@gnu.org> or send patches to 29a733a5bfSmrg# <automake-patches@gnu.org>. 30a733a5bfSmrg 31a733a5bfSmrgnl=' 32a733a5bfSmrg' 33a733a5bfSmrg 34a733a5bfSmrg# We need space, tab and new line, in precisely that order. Quoting is 35a733a5bfSmrg# there to prevent tools from complaining about whitespace usage. 36a733a5bfSmrgIFS=" "" $nl" 37a733a5bfSmrg 38a733a5bfSmrgfile_conv= 39a733a5bfSmrg 40a733a5bfSmrg# func_file_conv build_file lazy 41a733a5bfSmrg# Convert a $build file to $host form and store it in $file 42a733a5bfSmrg# Currently only supports Windows hosts. If the determined conversion 43a733a5bfSmrg# type is listed in (the comma separated) LAZY, no conversion will 44a733a5bfSmrg# take place. 45a733a5bfSmrgfunc_file_conv () 46a733a5bfSmrg{ 47a733a5bfSmrg file=$1 48a733a5bfSmrg case $file in 49a733a5bfSmrg / | /[!/]*) # absolute file, and not a UNC file 50a733a5bfSmrg if test -z "$file_conv"; then 51a733a5bfSmrg # lazily determine how to convert abs files 52a733a5bfSmrg case `uname -s` in 53a733a5bfSmrg MINGW*) 54a733a5bfSmrg file_conv=mingw 55a733a5bfSmrg ;; 566eaa481cSmrg CYGWIN* | MSYS*) 57a733a5bfSmrg file_conv=cygwin 58a733a5bfSmrg ;; 59a733a5bfSmrg *) 60a733a5bfSmrg file_conv=wine 61a733a5bfSmrg ;; 62a733a5bfSmrg esac 63a733a5bfSmrg fi 64a733a5bfSmrg case $file_conv/,$2, in 65a733a5bfSmrg *,$file_conv,*) 66a733a5bfSmrg ;; 67a733a5bfSmrg mingw/*) 68a733a5bfSmrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69a733a5bfSmrg ;; 706eaa481cSmrg cygwin/* | msys/*) 71a733a5bfSmrg file=`cygpath -m "$file" || echo "$file"` 72a733a5bfSmrg ;; 73a733a5bfSmrg wine/*) 74a733a5bfSmrg file=`winepath -w "$file" || echo "$file"` 75a733a5bfSmrg ;; 76a733a5bfSmrg esac 77a733a5bfSmrg ;; 78a733a5bfSmrg esac 79a733a5bfSmrg} 80a733a5bfSmrg 81a733a5bfSmrg# func_cl_dashL linkdir 82a733a5bfSmrg# Make cl look for libraries in LINKDIR 83a733a5bfSmrgfunc_cl_dashL () 84a733a5bfSmrg{ 85a733a5bfSmrg func_file_conv "$1" 86a733a5bfSmrg if test -z "$lib_path"; then 87a733a5bfSmrg lib_path=$file 88a733a5bfSmrg else 89a733a5bfSmrg lib_path="$lib_path;$file" 90a733a5bfSmrg fi 91a733a5bfSmrg linker_opts="$linker_opts -LIBPATH:$file" 92a733a5bfSmrg} 93a733a5bfSmrg 94a733a5bfSmrg# func_cl_dashl library 95a733a5bfSmrg# Do a library search-path lookup for cl 96a733a5bfSmrgfunc_cl_dashl () 97a733a5bfSmrg{ 98a733a5bfSmrg lib=$1 99a733a5bfSmrg found=no 100a733a5bfSmrg save_IFS=$IFS 101a733a5bfSmrg IFS=';' 102a733a5bfSmrg for dir in $lib_path $LIB 103a733a5bfSmrg do 104a733a5bfSmrg IFS=$save_IFS 105a733a5bfSmrg if $shared && test -f "$dir/$lib.dll.lib"; then 106a733a5bfSmrg found=yes 107a733a5bfSmrg lib=$dir/$lib.dll.lib 108a733a5bfSmrg break 109a733a5bfSmrg fi 110a733a5bfSmrg if test -f "$dir/$lib.lib"; then 111a733a5bfSmrg found=yes 112a733a5bfSmrg lib=$dir/$lib.lib 113a733a5bfSmrg break 114a733a5bfSmrg fi 115a733a5bfSmrg if test -f "$dir/lib$lib.a"; then 116a733a5bfSmrg found=yes 117a733a5bfSmrg lib=$dir/lib$lib.a 118a733a5bfSmrg break 119a733a5bfSmrg fi 120a733a5bfSmrg done 121a733a5bfSmrg IFS=$save_IFS 122a733a5bfSmrg 123a733a5bfSmrg if test "$found" != yes; then 124a733a5bfSmrg lib=$lib.lib 125a733a5bfSmrg fi 126a733a5bfSmrg} 127a733a5bfSmrg 128a733a5bfSmrg# func_cl_wrapper cl arg... 129a733a5bfSmrg# Adjust compile command to suit cl 130a733a5bfSmrgfunc_cl_wrapper () 131a733a5bfSmrg{ 132a733a5bfSmrg # Assume a capable shell 133a733a5bfSmrg lib_path= 134a733a5bfSmrg shared=: 135a733a5bfSmrg linker_opts= 136a733a5bfSmrg for arg 137a733a5bfSmrg do 138a733a5bfSmrg if test -n "$eat"; then 139a733a5bfSmrg eat= 140a733a5bfSmrg else 141a733a5bfSmrg case $1 in 142a733a5bfSmrg -o) 143a733a5bfSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 144a733a5bfSmrg eat=1 145a733a5bfSmrg case $2 in 146a733a5bfSmrg *.o | *.[oO][bB][jJ]) 147a733a5bfSmrg func_file_conv "$2" 148a733a5bfSmrg set x "$@" -Fo"$file" 149a733a5bfSmrg shift 150a733a5bfSmrg ;; 151a733a5bfSmrg *) 152a733a5bfSmrg func_file_conv "$2" 153a733a5bfSmrg set x "$@" -Fe"$file" 154a733a5bfSmrg shift 155a733a5bfSmrg ;; 156a733a5bfSmrg esac 157a733a5bfSmrg ;; 158a733a5bfSmrg -I) 159a733a5bfSmrg eat=1 160a733a5bfSmrg func_file_conv "$2" mingw 161a733a5bfSmrg set x "$@" -I"$file" 162a733a5bfSmrg shift 163a733a5bfSmrg ;; 164a733a5bfSmrg -I*) 165a733a5bfSmrg func_file_conv "${1#-I}" mingw 166a733a5bfSmrg set x "$@" -I"$file" 167a733a5bfSmrg shift 168a733a5bfSmrg ;; 169a733a5bfSmrg -l) 170a733a5bfSmrg eat=1 171a733a5bfSmrg func_cl_dashl "$2" 172a733a5bfSmrg set x "$@" "$lib" 173a733a5bfSmrg shift 174a733a5bfSmrg ;; 175a733a5bfSmrg -l*) 176a733a5bfSmrg func_cl_dashl "${1#-l}" 177a733a5bfSmrg set x "$@" "$lib" 178a733a5bfSmrg shift 179a733a5bfSmrg ;; 180a733a5bfSmrg -L) 181a733a5bfSmrg eat=1 182a733a5bfSmrg func_cl_dashL "$2" 183a733a5bfSmrg ;; 184a733a5bfSmrg -L*) 185a733a5bfSmrg func_cl_dashL "${1#-L}" 186a733a5bfSmrg ;; 187a733a5bfSmrg -static) 188a733a5bfSmrg shared=false 189a733a5bfSmrg ;; 190a733a5bfSmrg -Wl,*) 191a733a5bfSmrg arg=${1#-Wl,} 192a733a5bfSmrg save_ifs="$IFS"; IFS=',' 193a733a5bfSmrg for flag in $arg; do 194a733a5bfSmrg IFS="$save_ifs" 195a733a5bfSmrg linker_opts="$linker_opts $flag" 196a733a5bfSmrg done 197a733a5bfSmrg IFS="$save_ifs" 198a733a5bfSmrg ;; 199a733a5bfSmrg -Xlinker) 200a733a5bfSmrg eat=1 201a733a5bfSmrg linker_opts="$linker_opts $2" 202a733a5bfSmrg ;; 203a733a5bfSmrg -*) 204a733a5bfSmrg set x "$@" "$1" 205a733a5bfSmrg shift 206a733a5bfSmrg ;; 207a733a5bfSmrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208a733a5bfSmrg func_file_conv "$1" 209a733a5bfSmrg set x "$@" -Tp"$file" 210a733a5bfSmrg shift 211a733a5bfSmrg ;; 212a733a5bfSmrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213a733a5bfSmrg func_file_conv "$1" mingw 214a733a5bfSmrg set x "$@" "$file" 215a733a5bfSmrg shift 216a733a5bfSmrg ;; 217a733a5bfSmrg *) 218a733a5bfSmrg set x "$@" "$1" 219a733a5bfSmrg shift 220a733a5bfSmrg ;; 221a733a5bfSmrg esac 222a733a5bfSmrg fi 223a733a5bfSmrg shift 224a733a5bfSmrg done 225a733a5bfSmrg if test -n "$linker_opts"; then 226a733a5bfSmrg linker_opts="-link$linker_opts" 227a733a5bfSmrg fi 228a733a5bfSmrg exec "$@" $linker_opts 229a733a5bfSmrg exit 1 230a733a5bfSmrg} 231a733a5bfSmrg 232a733a5bfSmrgeat= 233a733a5bfSmrg 234a733a5bfSmrgcase $1 in 235a733a5bfSmrg '') 236a733a5bfSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 237a733a5bfSmrg exit 1; 238a733a5bfSmrg ;; 239a733a5bfSmrg -h | --h*) 240a733a5bfSmrg cat <<\EOF 241a733a5bfSmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 242a733a5bfSmrg 243a733a5bfSmrgWrapper for compilers which do not understand '-c -o'. 244a733a5bfSmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 245a733a5bfSmrgarguments, and rename the output as expected. 246a733a5bfSmrg 247a733a5bfSmrgIf you are trying to build a whole package this is not the 248a733a5bfSmrgright script to run: please start by reading the file 'INSTALL'. 249a733a5bfSmrg 250a733a5bfSmrgReport bugs to <bug-automake@gnu.org>. 251a733a5bfSmrgEOF 252a733a5bfSmrg exit $? 253a733a5bfSmrg ;; 254a733a5bfSmrg -v | --v*) 255a733a5bfSmrg echo "compile $scriptversion" 256a733a5bfSmrg exit $? 257a733a5bfSmrg ;; 2586eaa481cSmrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 2596eaa481cSmrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 260a733a5bfSmrg func_cl_wrapper "$@" # Doesn't return... 261a733a5bfSmrg ;; 262a733a5bfSmrgesac 263a733a5bfSmrg 264a733a5bfSmrgofile= 265a733a5bfSmrgcfile= 266a733a5bfSmrg 267a733a5bfSmrgfor arg 268a733a5bfSmrgdo 269a733a5bfSmrg if test -n "$eat"; then 270a733a5bfSmrg eat= 271a733a5bfSmrg else 272a733a5bfSmrg case $1 in 273a733a5bfSmrg -o) 274a733a5bfSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 275a733a5bfSmrg # So we strip '-o arg' only if arg is an object. 276a733a5bfSmrg eat=1 277a733a5bfSmrg case $2 in 278a733a5bfSmrg *.o | *.obj) 279a733a5bfSmrg ofile=$2 280a733a5bfSmrg ;; 281a733a5bfSmrg *) 282a733a5bfSmrg set x "$@" -o "$2" 283a733a5bfSmrg shift 284a733a5bfSmrg ;; 285a733a5bfSmrg esac 286a733a5bfSmrg ;; 287a733a5bfSmrg *.c) 288a733a5bfSmrg cfile=$1 289a733a5bfSmrg set x "$@" "$1" 290a733a5bfSmrg shift 291a733a5bfSmrg ;; 292a733a5bfSmrg *) 293a733a5bfSmrg set x "$@" "$1" 294a733a5bfSmrg shift 295a733a5bfSmrg ;; 296a733a5bfSmrg esac 297a733a5bfSmrg fi 298a733a5bfSmrg shift 299a733a5bfSmrgdone 300a733a5bfSmrg 301a733a5bfSmrgif test -z "$ofile" || test -z "$cfile"; then 302a733a5bfSmrg # If no '-o' option was seen then we might have been invoked from a 303a733a5bfSmrg # pattern rule where we don't need one. That is ok -- this is a 304a733a5bfSmrg # normal compilation that the losing compiler can handle. If no 305a733a5bfSmrg # '.c' file was seen then we are probably linking. That is also 306a733a5bfSmrg # ok. 307a733a5bfSmrg exec "$@" 308a733a5bfSmrgfi 309a733a5bfSmrg 310a733a5bfSmrg# Name of file we expect compiler to create. 311a733a5bfSmrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 312a733a5bfSmrg 313a733a5bfSmrg# Create the lock directory. 314a733a5bfSmrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 315a733a5bfSmrg# that we are using for the .o file. Also, base the name on the expected 316a733a5bfSmrg# object file name, since that is what matters with a parallel build. 317a733a5bfSmrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 318a733a5bfSmrgwhile true; do 319a733a5bfSmrg if mkdir "$lockdir" >/dev/null 2>&1; then 320a733a5bfSmrg break 321a733a5bfSmrg fi 322a733a5bfSmrg sleep 1 323a733a5bfSmrgdone 324a733a5bfSmrg# FIXME: race condition here if user kills between mkdir and trap. 325a733a5bfSmrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 326a733a5bfSmrg 327a733a5bfSmrg# Run the compile. 328a733a5bfSmrg"$@" 329a733a5bfSmrgret=$? 330a733a5bfSmrg 331a733a5bfSmrgif test -f "$cofile"; then 332a733a5bfSmrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 333a733a5bfSmrgelif test -f "${cofile}bj"; then 334a733a5bfSmrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 335a733a5bfSmrgfi 336a733a5bfSmrg 337a733a5bfSmrgrmdir "$lockdir" 338a733a5bfSmrgexit $ret 339a733a5bfSmrg 340a733a5bfSmrg# Local Variables: 341a733a5bfSmrg# mode: shell-script 342a733a5bfSmrg# sh-indentation: 2 3436eaa481cSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 344a733a5bfSmrg# time-stamp-start: "scriptversion=" 345a733a5bfSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 3466eaa481cSmrg# time-stamp-time-zone: "UTC0" 347a733a5bfSmrg# time-stamp-end: "; # UTC" 348a733a5bfSmrg# End: 349