1603fc0a3Smrg#! /bin/sh 2603fc0a3Smrg# Wrapper for compilers which do not understand '-c -o'. 3603fc0a3Smrg 4603fc0a3Smrgscriptversion=2018-03-07.03; # UTC 5603fc0a3Smrg 6603fc0a3Smrg# Copyright (C) 1999-2018 Free Software Foundation, Inc. 7603fc0a3Smrg# Written by Tom Tromey <tromey@cygnus.com>. 8603fc0a3Smrg# 9603fc0a3Smrg# This program is free software; you can redistribute it and/or modify 10603fc0a3Smrg# it under the terms of the GNU General Public License as published by 11603fc0a3Smrg# the Free Software Foundation; either version 2, or (at your option) 12603fc0a3Smrg# any later version. 13603fc0a3Smrg# 14603fc0a3Smrg# This program is distributed in the hope that it will be useful, 15603fc0a3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 16603fc0a3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17603fc0a3Smrg# GNU General Public License for more details. 18603fc0a3Smrg# 19603fc0a3Smrg# You should have received a copy of the GNU General Public License 20603fc0a3Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 21603fc0a3Smrg 22603fc0a3Smrg# As a special exception to the GNU General Public License, if you 23603fc0a3Smrg# distribute this file as part of a program that contains a 24603fc0a3Smrg# configuration script generated by Autoconf, you may include it under 25603fc0a3Smrg# the same distribution terms that you use for the rest of that program. 26603fc0a3Smrg 27603fc0a3Smrg# This file is maintained in Automake, please report 28603fc0a3Smrg# bugs to <bug-automake@gnu.org> or send patches to 29603fc0a3Smrg# <automake-patches@gnu.org>. 30603fc0a3Smrg 31603fc0a3Smrgnl=' 32603fc0a3Smrg' 33603fc0a3Smrg 34603fc0a3Smrg# We need space, tab and new line, in precisely that order. Quoting is 35603fc0a3Smrg# there to prevent tools from complaining about whitespace usage. 36603fc0a3SmrgIFS=" "" $nl" 37603fc0a3Smrg 38603fc0a3Smrgfile_conv= 39603fc0a3Smrg 40603fc0a3Smrg# func_file_conv build_file lazy 41603fc0a3Smrg# Convert a $build file to $host form and store it in $file 42603fc0a3Smrg# Currently only supports Windows hosts. If the determined conversion 43603fc0a3Smrg# type is listed in (the comma separated) LAZY, no conversion will 44603fc0a3Smrg# take place. 45603fc0a3Smrgfunc_file_conv () 46603fc0a3Smrg{ 47603fc0a3Smrg file=$1 48603fc0a3Smrg case $file in 49603fc0a3Smrg / | /[!/]*) # absolute file, and not a UNC file 50603fc0a3Smrg if test -z "$file_conv"; then 51603fc0a3Smrg # lazily determine how to convert abs files 52603fc0a3Smrg case `uname -s` in 53603fc0a3Smrg MINGW*) 54603fc0a3Smrg file_conv=mingw 55603fc0a3Smrg ;; 56603fc0a3Smrg CYGWIN*) 57603fc0a3Smrg file_conv=cygwin 58603fc0a3Smrg ;; 59603fc0a3Smrg *) 60603fc0a3Smrg file_conv=wine 61603fc0a3Smrg ;; 62603fc0a3Smrg esac 63603fc0a3Smrg fi 64603fc0a3Smrg case $file_conv/,$2, in 65603fc0a3Smrg *,$file_conv,*) 66603fc0a3Smrg ;; 67603fc0a3Smrg mingw/*) 68603fc0a3Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69603fc0a3Smrg ;; 70603fc0a3Smrg cygwin/*) 71603fc0a3Smrg file=`cygpath -m "$file" || echo "$file"` 72603fc0a3Smrg ;; 73603fc0a3Smrg wine/*) 74603fc0a3Smrg file=`winepath -w "$file" || echo "$file"` 75603fc0a3Smrg ;; 76603fc0a3Smrg esac 77603fc0a3Smrg ;; 78603fc0a3Smrg esac 79603fc0a3Smrg} 80603fc0a3Smrg 81603fc0a3Smrg# func_cl_dashL linkdir 82603fc0a3Smrg# Make cl look for libraries in LINKDIR 83603fc0a3Smrgfunc_cl_dashL () 84603fc0a3Smrg{ 85603fc0a3Smrg func_file_conv "$1" 86603fc0a3Smrg if test -z "$lib_path"; then 87603fc0a3Smrg lib_path=$file 88603fc0a3Smrg else 89603fc0a3Smrg lib_path="$lib_path;$file" 90603fc0a3Smrg fi 91603fc0a3Smrg linker_opts="$linker_opts -LIBPATH:$file" 92603fc0a3Smrg} 93603fc0a3Smrg 94603fc0a3Smrg# func_cl_dashl library 95603fc0a3Smrg# Do a library search-path lookup for cl 96603fc0a3Smrgfunc_cl_dashl () 97603fc0a3Smrg{ 98603fc0a3Smrg lib=$1 99603fc0a3Smrg found=no 100603fc0a3Smrg save_IFS=$IFS 101603fc0a3Smrg IFS=';' 102603fc0a3Smrg for dir in $lib_path $LIB 103603fc0a3Smrg do 104603fc0a3Smrg IFS=$save_IFS 105603fc0a3Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 106603fc0a3Smrg found=yes 107603fc0a3Smrg lib=$dir/$lib.dll.lib 108603fc0a3Smrg break 109603fc0a3Smrg fi 110603fc0a3Smrg if test -f "$dir/$lib.lib"; then 111603fc0a3Smrg found=yes 112603fc0a3Smrg lib=$dir/$lib.lib 113603fc0a3Smrg break 114603fc0a3Smrg fi 115603fc0a3Smrg if test -f "$dir/lib$lib.a"; then 116603fc0a3Smrg found=yes 117603fc0a3Smrg lib=$dir/lib$lib.a 118603fc0a3Smrg break 119603fc0a3Smrg fi 120603fc0a3Smrg done 121603fc0a3Smrg IFS=$save_IFS 122603fc0a3Smrg 123603fc0a3Smrg if test "$found" != yes; then 124603fc0a3Smrg lib=$lib.lib 125603fc0a3Smrg fi 126603fc0a3Smrg} 127603fc0a3Smrg 128603fc0a3Smrg# func_cl_wrapper cl arg... 129603fc0a3Smrg# Adjust compile command to suit cl 130603fc0a3Smrgfunc_cl_wrapper () 131603fc0a3Smrg{ 132603fc0a3Smrg # Assume a capable shell 133603fc0a3Smrg lib_path= 134603fc0a3Smrg shared=: 135603fc0a3Smrg linker_opts= 136603fc0a3Smrg for arg 137603fc0a3Smrg do 138603fc0a3Smrg if test -n "$eat"; then 139603fc0a3Smrg eat= 140603fc0a3Smrg else 141603fc0a3Smrg case $1 in 142603fc0a3Smrg -o) 143603fc0a3Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 144603fc0a3Smrg eat=1 145603fc0a3Smrg case $2 in 146603fc0a3Smrg *.o | *.[oO][bB][jJ]) 147603fc0a3Smrg func_file_conv "$2" 148603fc0a3Smrg set x "$@" -Fo"$file" 149603fc0a3Smrg shift 150603fc0a3Smrg ;; 151603fc0a3Smrg *) 152603fc0a3Smrg func_file_conv "$2" 153603fc0a3Smrg set x "$@" -Fe"$file" 154603fc0a3Smrg shift 155603fc0a3Smrg ;; 156603fc0a3Smrg esac 157603fc0a3Smrg ;; 158603fc0a3Smrg -I) 159603fc0a3Smrg eat=1 160603fc0a3Smrg func_file_conv "$2" mingw 161603fc0a3Smrg set x "$@" -I"$file" 162603fc0a3Smrg shift 163603fc0a3Smrg ;; 164603fc0a3Smrg -I*) 165603fc0a3Smrg func_file_conv "${1#-I}" mingw 166603fc0a3Smrg set x "$@" -I"$file" 167603fc0a3Smrg shift 168603fc0a3Smrg ;; 169603fc0a3Smrg -l) 170603fc0a3Smrg eat=1 171603fc0a3Smrg func_cl_dashl "$2" 172603fc0a3Smrg set x "$@" "$lib" 173603fc0a3Smrg shift 174603fc0a3Smrg ;; 175603fc0a3Smrg -l*) 176603fc0a3Smrg func_cl_dashl "${1#-l}" 177603fc0a3Smrg set x "$@" "$lib" 178603fc0a3Smrg shift 179603fc0a3Smrg ;; 180603fc0a3Smrg -L) 181603fc0a3Smrg eat=1 182603fc0a3Smrg func_cl_dashL "$2" 183603fc0a3Smrg ;; 184603fc0a3Smrg -L*) 185603fc0a3Smrg func_cl_dashL "${1#-L}" 186603fc0a3Smrg ;; 187603fc0a3Smrg -static) 188603fc0a3Smrg shared=false 189603fc0a3Smrg ;; 190603fc0a3Smrg -Wl,*) 191603fc0a3Smrg arg=${1#-Wl,} 192603fc0a3Smrg save_ifs="$IFS"; IFS=',' 193603fc0a3Smrg for flag in $arg; do 194603fc0a3Smrg IFS="$save_ifs" 195603fc0a3Smrg linker_opts="$linker_opts $flag" 196603fc0a3Smrg done 197603fc0a3Smrg IFS="$save_ifs" 198603fc0a3Smrg ;; 199603fc0a3Smrg -Xlinker) 200603fc0a3Smrg eat=1 201603fc0a3Smrg linker_opts="$linker_opts $2" 202603fc0a3Smrg ;; 203603fc0a3Smrg -*) 204603fc0a3Smrg set x "$@" "$1" 205603fc0a3Smrg shift 206603fc0a3Smrg ;; 207603fc0a3Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208603fc0a3Smrg func_file_conv "$1" 209603fc0a3Smrg set x "$@" -Tp"$file" 210603fc0a3Smrg shift 211603fc0a3Smrg ;; 212603fc0a3Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213603fc0a3Smrg func_file_conv "$1" mingw 214603fc0a3Smrg set x "$@" "$file" 215603fc0a3Smrg shift 216603fc0a3Smrg ;; 217603fc0a3Smrg *) 218603fc0a3Smrg set x "$@" "$1" 219603fc0a3Smrg shift 220603fc0a3Smrg ;; 221603fc0a3Smrg esac 222603fc0a3Smrg fi 223603fc0a3Smrg shift 224603fc0a3Smrg done 225603fc0a3Smrg if test -n "$linker_opts"; then 226603fc0a3Smrg linker_opts="-link$linker_opts" 227603fc0a3Smrg fi 228603fc0a3Smrg exec "$@" $linker_opts 229603fc0a3Smrg exit 1 230603fc0a3Smrg} 231603fc0a3Smrg 232603fc0a3Smrgeat= 233603fc0a3Smrg 234603fc0a3Smrgcase $1 in 235603fc0a3Smrg '') 236603fc0a3Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 237603fc0a3Smrg exit 1; 238603fc0a3Smrg ;; 239603fc0a3Smrg -h | --h*) 240603fc0a3Smrg cat <<\EOF 241603fc0a3SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 242603fc0a3Smrg 243603fc0a3SmrgWrapper for compilers which do not understand '-c -o'. 244603fc0a3SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 245603fc0a3Smrgarguments, and rename the output as expected. 246603fc0a3Smrg 247603fc0a3SmrgIf you are trying to build a whole package this is not the 248603fc0a3Smrgright script to run: please start by reading the file 'INSTALL'. 249603fc0a3Smrg 250603fc0a3SmrgReport bugs to <bug-automake@gnu.org>. 251603fc0a3SmrgEOF 252603fc0a3Smrg exit $? 253603fc0a3Smrg ;; 254603fc0a3Smrg -v | --v*) 255603fc0a3Smrg echo "compile $scriptversion" 256603fc0a3Smrg exit $? 257603fc0a3Smrg ;; 258603fc0a3Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 259603fc0a3Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 260603fc0a3Smrg func_cl_wrapper "$@" # Doesn't return... 261603fc0a3Smrg ;; 262603fc0a3Smrgesac 263603fc0a3Smrg 264603fc0a3Smrgofile= 265603fc0a3Smrgcfile= 266603fc0a3Smrg 267603fc0a3Smrgfor arg 268603fc0a3Smrgdo 269603fc0a3Smrg if test -n "$eat"; then 270603fc0a3Smrg eat= 271603fc0a3Smrg else 272603fc0a3Smrg case $1 in 273603fc0a3Smrg -o) 274603fc0a3Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 275603fc0a3Smrg # So we strip '-o arg' only if arg is an object. 276603fc0a3Smrg eat=1 277603fc0a3Smrg case $2 in 278603fc0a3Smrg *.o | *.obj) 279603fc0a3Smrg ofile=$2 280603fc0a3Smrg ;; 281603fc0a3Smrg *) 282603fc0a3Smrg set x "$@" -o "$2" 283603fc0a3Smrg shift 284603fc0a3Smrg ;; 285603fc0a3Smrg esac 286603fc0a3Smrg ;; 287603fc0a3Smrg *.c) 288603fc0a3Smrg cfile=$1 289603fc0a3Smrg set x "$@" "$1" 290603fc0a3Smrg shift 291603fc0a3Smrg ;; 292603fc0a3Smrg *) 293603fc0a3Smrg set x "$@" "$1" 294603fc0a3Smrg shift 295603fc0a3Smrg ;; 296603fc0a3Smrg esac 297603fc0a3Smrg fi 298603fc0a3Smrg shift 299603fc0a3Smrgdone 300603fc0a3Smrg 301603fc0a3Smrgif test -z "$ofile" || test -z "$cfile"; then 302603fc0a3Smrg # If no '-o' option was seen then we might have been invoked from a 303603fc0a3Smrg # pattern rule where we don't need one. That is ok -- this is a 304603fc0a3Smrg # normal compilation that the losing compiler can handle. If no 305603fc0a3Smrg # '.c' file was seen then we are probably linking. That is also 306603fc0a3Smrg # ok. 307603fc0a3Smrg exec "$@" 308603fc0a3Smrgfi 309603fc0a3Smrg 310603fc0a3Smrg# Name of file we expect compiler to create. 311603fc0a3Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 312603fc0a3Smrg 313603fc0a3Smrg# Create the lock directory. 314603fc0a3Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 315603fc0a3Smrg# that we are using for the .o file. Also, base the name on the expected 316603fc0a3Smrg# object file name, since that is what matters with a parallel build. 317603fc0a3Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 318603fc0a3Smrgwhile true; do 319603fc0a3Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 320603fc0a3Smrg break 321603fc0a3Smrg fi 322603fc0a3Smrg sleep 1 323603fc0a3Smrgdone 324603fc0a3Smrg# FIXME: race condition here if user kills between mkdir and trap. 325603fc0a3Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 326603fc0a3Smrg 327603fc0a3Smrg# Run the compile. 328603fc0a3Smrg"$@" 329603fc0a3Smrgret=$? 330603fc0a3Smrg 331603fc0a3Smrgif test -f "$cofile"; then 332603fc0a3Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 333603fc0a3Smrgelif test -f "${cofile}bj"; then 334603fc0a3Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 335603fc0a3Smrgfi 336603fc0a3Smrg 337603fc0a3Smrgrmdir "$lockdir" 338603fc0a3Smrgexit $ret 339603fc0a3Smrg 340603fc0a3Smrg# Local Variables: 341603fc0a3Smrg# mode: shell-script 342603fc0a3Smrg# sh-indentation: 2 343603fc0a3Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 344603fc0a3Smrg# time-stamp-start: "scriptversion=" 345603fc0a3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 346603fc0a3Smrg# time-stamp-time-zone: "UTC0" 347603fc0a3Smrg# time-stamp-end: "; # UTC" 348603fc0a3Smrg# End: 349