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