compile revision 5ec34c4c
1994689c1Smrg#! /bin/sh 2c889a3bfSmrg# Wrapper for compilers which do not understand '-c -o'. 3994689c1Smrg 45ec34c4cSmrgscriptversion=2018-03-07.03; # UTC 5994689c1Smrg 65ec34c4cSmrg# Copyright (C) 1999-2020 Free Software Foundation, Inc. 7994689c1Smrg# Written by Tom Tromey <tromey@cygnus.com>. 8994689c1Smrg# 9994689c1Smrg# This program is free software; you can redistribute it and/or modify 10994689c1Smrg# it under the terms of the GNU General Public License as published by 11994689c1Smrg# the Free Software Foundation; either version 2, or (at your option) 12994689c1Smrg# any later version. 13994689c1Smrg# 14994689c1Smrg# This program is distributed in the hope that it will be useful, 15994689c1Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 16994689c1Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17994689c1Smrg# GNU General Public License for more details. 18994689c1Smrg# 19994689c1Smrg# You should have received a copy of the GNU General Public License 205ec34c4cSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 21994689c1Smrg 22994689c1Smrg# As a special exception to the GNU General Public License, if you 23994689c1Smrg# distribute this file as part of a program that contains a 24994689c1Smrg# configuration script generated by Autoconf, you may include it under 25994689c1Smrg# the same distribution terms that you use for the rest of that program. 26994689c1Smrg 27994689c1Smrg# This file is maintained in Automake, please report 28994689c1Smrg# bugs to <bug-automake@gnu.org> or send patches to 29994689c1Smrg# <automake-patches@gnu.org>. 30994689c1Smrg 31421c997bSmrgnl=' 32421c997bSmrg' 33421c997bSmrg 34421c997bSmrg# We need space, tab and new line, in precisely that order. Quoting is 35421c997bSmrg# there to prevent tools from complaining about whitespace usage. 36421c997bSmrgIFS=" "" $nl" 37421c997bSmrg 38421c997bSmrgfile_conv= 39421c997bSmrg 40421c997bSmrg# func_file_conv build_file lazy 41421c997bSmrg# Convert a $build file to $host form and store it in $file 42c889a3bfSmrg# Currently only supports Windows hosts. If the determined conversion 43421c997bSmrg# type is listed in (the comma separated) LAZY, no conversion will 44421c997bSmrg# take place. 45421c997bSmrgfunc_file_conv () 46421c997bSmrg{ 47421c997bSmrg file=$1 48421c997bSmrg case $file in 49421c997bSmrg / | /[!/]*) # absolute file, and not a UNC file 50421c997bSmrg if test -z "$file_conv"; then 51421c997bSmrg # lazily determine how to convert abs files 52421c997bSmrg case `uname -s` in 53421c997bSmrg MINGW*) 54421c997bSmrg file_conv=mingw 55421c997bSmrg ;; 565ec34c4cSmrg CYGWIN* | MSYS*) 57421c997bSmrg file_conv=cygwin 58421c997bSmrg ;; 59421c997bSmrg *) 60421c997bSmrg file_conv=wine 61421c997bSmrg ;; 62421c997bSmrg esac 63421c997bSmrg fi 64421c997bSmrg case $file_conv/,$2, in 65421c997bSmrg *,$file_conv,*) 66421c997bSmrg ;; 67421c997bSmrg mingw/*) 68421c997bSmrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69421c997bSmrg ;; 705ec34c4cSmrg cygwin/* | msys/*) 71421c997bSmrg file=`cygpath -m "$file" || echo "$file"` 72421c997bSmrg ;; 73421c997bSmrg wine/*) 74421c997bSmrg file=`winepath -w "$file" || echo "$file"` 75421c997bSmrg ;; 76421c997bSmrg esac 77421c997bSmrg ;; 78421c997bSmrg esac 79421c997bSmrg} 80421c997bSmrg 81c889a3bfSmrg# func_cl_dashL linkdir 82c889a3bfSmrg# Make cl look for libraries in LINKDIR 83c889a3bfSmrgfunc_cl_dashL () 84c889a3bfSmrg{ 85c889a3bfSmrg func_file_conv "$1" 86c889a3bfSmrg if test -z "$lib_path"; then 87c889a3bfSmrg lib_path=$file 88c889a3bfSmrg else 89c889a3bfSmrg lib_path="$lib_path;$file" 90c889a3bfSmrg fi 91c889a3bfSmrg linker_opts="$linker_opts -LIBPATH:$file" 92c889a3bfSmrg} 93c889a3bfSmrg 94c889a3bfSmrg# func_cl_dashl library 95c889a3bfSmrg# Do a library search-path lookup for cl 96c889a3bfSmrgfunc_cl_dashl () 97c889a3bfSmrg{ 98c889a3bfSmrg lib=$1 99c889a3bfSmrg found=no 100c889a3bfSmrg save_IFS=$IFS 101c889a3bfSmrg IFS=';' 102c889a3bfSmrg for dir in $lib_path $LIB 103c889a3bfSmrg do 104c889a3bfSmrg IFS=$save_IFS 105c889a3bfSmrg if $shared && test -f "$dir/$lib.dll.lib"; then 106c889a3bfSmrg found=yes 107c889a3bfSmrg lib=$dir/$lib.dll.lib 108c889a3bfSmrg break 109c889a3bfSmrg fi 110c889a3bfSmrg if test -f "$dir/$lib.lib"; then 111c889a3bfSmrg found=yes 112c889a3bfSmrg lib=$dir/$lib.lib 113c889a3bfSmrg break 114c889a3bfSmrg fi 115c889a3bfSmrg if test -f "$dir/lib$lib.a"; then 116c889a3bfSmrg found=yes 117c889a3bfSmrg lib=$dir/lib$lib.a 118c889a3bfSmrg break 119c889a3bfSmrg fi 120c889a3bfSmrg done 121c889a3bfSmrg IFS=$save_IFS 122c889a3bfSmrg 123c889a3bfSmrg if test "$found" != yes; then 124c889a3bfSmrg lib=$lib.lib 125c889a3bfSmrg fi 126c889a3bfSmrg} 127c889a3bfSmrg 128421c997bSmrg# func_cl_wrapper cl arg... 129421c997bSmrg# Adjust compile command to suit cl 130421c997bSmrgfunc_cl_wrapper () 131421c997bSmrg{ 132421c997bSmrg # Assume a capable shell 133421c997bSmrg lib_path= 134421c997bSmrg shared=: 135421c997bSmrg linker_opts= 136421c997bSmrg for arg 137421c997bSmrg do 138421c997bSmrg if test -n "$eat"; then 139421c997bSmrg eat= 140421c997bSmrg else 141421c997bSmrg case $1 in 142421c997bSmrg -o) 143c889a3bfSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 144421c997bSmrg eat=1 145421c997bSmrg case $2 in 146421c997bSmrg *.o | *.[oO][bB][jJ]) 147421c997bSmrg func_file_conv "$2" 148421c997bSmrg set x "$@" -Fo"$file" 149421c997bSmrg shift 150421c997bSmrg ;; 151421c997bSmrg *) 152421c997bSmrg func_file_conv "$2" 153421c997bSmrg set x "$@" -Fe"$file" 154421c997bSmrg shift 155421c997bSmrg ;; 156421c997bSmrg esac 157421c997bSmrg ;; 158c889a3bfSmrg -I) 159c889a3bfSmrg eat=1 160c889a3bfSmrg func_file_conv "$2" mingw 161c889a3bfSmrg set x "$@" -I"$file" 162c889a3bfSmrg shift 163c889a3bfSmrg ;; 164421c997bSmrg -I*) 165421c997bSmrg func_file_conv "${1#-I}" mingw 166421c997bSmrg set x "$@" -I"$file" 167421c997bSmrg shift 168421c997bSmrg ;; 169c889a3bfSmrg -l) 170c889a3bfSmrg eat=1 171c889a3bfSmrg func_cl_dashl "$2" 172c889a3bfSmrg set x "$@" "$lib" 173c889a3bfSmrg shift 174c889a3bfSmrg ;; 175421c997bSmrg -l*) 176c889a3bfSmrg func_cl_dashl "${1#-l}" 177c889a3bfSmrg set x "$@" "$lib" 178421c997bSmrg shift 179421c997bSmrg ;; 180c889a3bfSmrg -L) 181c889a3bfSmrg eat=1 182c889a3bfSmrg func_cl_dashL "$2" 183c889a3bfSmrg ;; 184421c997bSmrg -L*) 185c889a3bfSmrg func_cl_dashL "${1#-L}" 186421c997bSmrg ;; 187421c997bSmrg -static) 188421c997bSmrg shared=false 189421c997bSmrg ;; 190421c997bSmrg -Wl,*) 191421c997bSmrg arg=${1#-Wl,} 192421c997bSmrg save_ifs="$IFS"; IFS=',' 193421c997bSmrg for flag in $arg; do 194421c997bSmrg IFS="$save_ifs" 195421c997bSmrg linker_opts="$linker_opts $flag" 196421c997bSmrg done 197421c997bSmrg IFS="$save_ifs" 198421c997bSmrg ;; 199421c997bSmrg -Xlinker) 200421c997bSmrg eat=1 201421c997bSmrg linker_opts="$linker_opts $2" 202421c997bSmrg ;; 203421c997bSmrg -*) 204421c997bSmrg set x "$@" "$1" 205421c997bSmrg shift 206421c997bSmrg ;; 207421c997bSmrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208421c997bSmrg func_file_conv "$1" 209421c997bSmrg set x "$@" -Tp"$file" 210421c997bSmrg shift 211421c997bSmrg ;; 212421c997bSmrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213421c997bSmrg func_file_conv "$1" mingw 214421c997bSmrg set x "$@" "$file" 215421c997bSmrg shift 216421c997bSmrg ;; 217421c997bSmrg *) 218421c997bSmrg set x "$@" "$1" 219421c997bSmrg shift 220421c997bSmrg ;; 221421c997bSmrg esac 222421c997bSmrg fi 223421c997bSmrg shift 224421c997bSmrg done 225421c997bSmrg if test -n "$linker_opts"; then 226421c997bSmrg linker_opts="-link$linker_opts" 227421c997bSmrg fi 228421c997bSmrg exec "$@" $linker_opts 229421c997bSmrg exit 1 230421c997bSmrg} 231421c997bSmrg 232421c997bSmrgeat= 233421c997bSmrg 234994689c1Smrgcase $1 in 235994689c1Smrg '') 236c889a3bfSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 237994689c1Smrg exit 1; 238994689c1Smrg ;; 239994689c1Smrg -h | --h*) 240994689c1Smrg cat <<\EOF 241994689c1SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 242994689c1Smrg 243c889a3bfSmrgWrapper for compilers which do not understand '-c -o'. 244c889a3bfSmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 245994689c1Smrgarguments, and rename the output as expected. 246994689c1Smrg 247994689c1SmrgIf you are trying to build a whole package this is not the 248c889a3bfSmrgright script to run: please start by reading the file 'INSTALL'. 249994689c1Smrg 250994689c1SmrgReport bugs to <bug-automake@gnu.org>. 251994689c1SmrgEOF 252994689c1Smrg exit $? 253994689c1Smrg ;; 254994689c1Smrg -v | --v*) 255994689c1Smrg echo "compile $scriptversion" 256994689c1Smrg exit $? 257994689c1Smrg ;; 2585ec34c4cSmrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 2595ec34c4cSmrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 260421c997bSmrg func_cl_wrapper "$@" # Doesn't return... 261421c997bSmrg ;; 262994689c1Smrgesac 263994689c1Smrg 264994689c1Smrgofile= 265994689c1Smrgcfile= 266994689c1Smrg 267994689c1Smrgfor arg 268994689c1Smrgdo 269994689c1Smrg if test -n "$eat"; then 270994689c1Smrg eat= 271994689c1Smrg else 272994689c1Smrg case $1 in 273994689c1Smrg -o) 274c889a3bfSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 275c889a3bfSmrg # So we strip '-o arg' only if arg is an object. 276994689c1Smrg eat=1 277994689c1Smrg case $2 in 278994689c1Smrg *.o | *.obj) 279994689c1Smrg ofile=$2 280994689c1Smrg ;; 281994689c1Smrg *) 282994689c1Smrg set x "$@" -o "$2" 283994689c1Smrg shift 284994689c1Smrg ;; 285994689c1Smrg esac 286994689c1Smrg ;; 287994689c1Smrg *.c) 288994689c1Smrg cfile=$1 289994689c1Smrg set x "$@" "$1" 290994689c1Smrg shift 291994689c1Smrg ;; 292994689c1Smrg *) 293994689c1Smrg set x "$@" "$1" 294994689c1Smrg shift 295994689c1Smrg ;; 296994689c1Smrg esac 297994689c1Smrg fi 298994689c1Smrg shift 299994689c1Smrgdone 300994689c1Smrg 301994689c1Smrgif test -z "$ofile" || test -z "$cfile"; then 302c889a3bfSmrg # If no '-o' option was seen then we might have been invoked from a 303994689c1Smrg # pattern rule where we don't need one. That is ok -- this is a 304994689c1Smrg # normal compilation that the losing compiler can handle. If no 305c889a3bfSmrg # '.c' file was seen then we are probably linking. That is also 306994689c1Smrg # ok. 307994689c1Smrg exec "$@" 308994689c1Smrgfi 309994689c1Smrg 310994689c1Smrg# Name of file we expect compiler to create. 311994689c1Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 312994689c1Smrg 313994689c1Smrg# Create the lock directory. 314c889a3bfSmrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 315994689c1Smrg# that we are using for the .o file. Also, base the name on the expected 316994689c1Smrg# object file name, since that is what matters with a parallel build. 317994689c1Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 318994689c1Smrgwhile true; do 319994689c1Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 320994689c1Smrg break 321994689c1Smrg fi 322994689c1Smrg sleep 1 323994689c1Smrgdone 324994689c1Smrg# FIXME: race condition here if user kills between mkdir and trap. 325994689c1Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 326994689c1Smrg 327994689c1Smrg# Run the compile. 328994689c1Smrg"$@" 329994689c1Smrgret=$? 330994689c1Smrg 331994689c1Smrgif test -f "$cofile"; then 332994689c1Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 333994689c1Smrgelif test -f "${cofile}bj"; then 334994689c1Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 335994689c1Smrgfi 336994689c1Smrg 337994689c1Smrgrmdir "$lockdir" 338994689c1Smrgexit $ret 339994689c1Smrg 340994689c1Smrg# Local Variables: 341994689c1Smrg# mode: shell-script 342994689c1Smrg# sh-indentation: 2 3435ec34c4cSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 344994689c1Smrg# time-stamp-start: "scriptversion=" 345994689c1Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 3465ec34c4cSmrg# time-stamp-time-zone: "UTC0" 347994689c1Smrg# time-stamp-end: "; # UTC" 348994689c1Smrg# End: 349