compile revision 084f91cc
1084f91ccSmrg#! /bin/sh 2084f91ccSmrg# Wrapper for compilers which do not understand '-c -o'. 3084f91ccSmrg 4084f91ccSmrgscriptversion=2018-03-07.03; # UTC 5084f91ccSmrg 6084f91ccSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7084f91ccSmrg# Written by Tom Tromey <tromey@cygnus.com>. 8084f91ccSmrg# 9084f91ccSmrg# This program is free software; you can redistribute it and/or modify 10084f91ccSmrg# it under the terms of the GNU General Public License as published by 11084f91ccSmrg# the Free Software Foundation; either version 2, or (at your option) 12084f91ccSmrg# any later version. 13084f91ccSmrg# 14084f91ccSmrg# This program is distributed in the hope that it will be useful, 15084f91ccSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 16084f91ccSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17084f91ccSmrg# GNU General Public License for more details. 18084f91ccSmrg# 19084f91ccSmrg# You should have received a copy of the GNU General Public License 20084f91ccSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 21084f91ccSmrg 22084f91ccSmrg# As a special exception to the GNU General Public License, if you 23084f91ccSmrg# distribute this file as part of a program that contains a 24084f91ccSmrg# configuration script generated by Autoconf, you may include it under 25084f91ccSmrg# the same distribution terms that you use for the rest of that program. 26084f91ccSmrg 27084f91ccSmrg# This file is maintained in Automake, please report 28084f91ccSmrg# bugs to <bug-automake@gnu.org> or send patches to 29084f91ccSmrg# <automake-patches@gnu.org>. 30084f91ccSmrg 31084f91ccSmrgnl=' 32084f91ccSmrg' 33084f91ccSmrg 34084f91ccSmrg# We need space, tab and new line, in precisely that order. Quoting is 35084f91ccSmrg# there to prevent tools from complaining about whitespace usage. 36084f91ccSmrgIFS=" "" $nl" 37084f91ccSmrg 38084f91ccSmrgfile_conv= 39084f91ccSmrg 40084f91ccSmrg# func_file_conv build_file lazy 41084f91ccSmrg# Convert a $build file to $host form and store it in $file 42084f91ccSmrg# Currently only supports Windows hosts. If the determined conversion 43084f91ccSmrg# type is listed in (the comma separated) LAZY, no conversion will 44084f91ccSmrg# take place. 45084f91ccSmrgfunc_file_conv () 46084f91ccSmrg{ 47084f91ccSmrg file=$1 48084f91ccSmrg case $file in 49084f91ccSmrg / | /[!/]*) # absolute file, and not a UNC file 50084f91ccSmrg if test -z "$file_conv"; then 51084f91ccSmrg # lazily determine how to convert abs files 52084f91ccSmrg case `uname -s` in 53084f91ccSmrg MINGW*) 54084f91ccSmrg file_conv=mingw 55084f91ccSmrg ;; 56084f91ccSmrg CYGWIN* | MSYS*) 57084f91ccSmrg file_conv=cygwin 58084f91ccSmrg ;; 59084f91ccSmrg *) 60084f91ccSmrg file_conv=wine 61084f91ccSmrg ;; 62084f91ccSmrg esac 63084f91ccSmrg fi 64084f91ccSmrg case $file_conv/,$2, in 65084f91ccSmrg *,$file_conv,*) 66084f91ccSmrg ;; 67084f91ccSmrg mingw/*) 68084f91ccSmrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69084f91ccSmrg ;; 70084f91ccSmrg cygwin/* | msys/*) 71084f91ccSmrg file=`cygpath -m "$file" || echo "$file"` 72084f91ccSmrg ;; 73084f91ccSmrg wine/*) 74084f91ccSmrg file=`winepath -w "$file" || echo "$file"` 75084f91ccSmrg ;; 76084f91ccSmrg esac 77084f91ccSmrg ;; 78084f91ccSmrg esac 79084f91ccSmrg} 80084f91ccSmrg 81084f91ccSmrg# func_cl_dashL linkdir 82084f91ccSmrg# Make cl look for libraries in LINKDIR 83084f91ccSmrgfunc_cl_dashL () 84084f91ccSmrg{ 85084f91ccSmrg func_file_conv "$1" 86084f91ccSmrg if test -z "$lib_path"; then 87084f91ccSmrg lib_path=$file 88084f91ccSmrg else 89084f91ccSmrg lib_path="$lib_path;$file" 90084f91ccSmrg fi 91084f91ccSmrg linker_opts="$linker_opts -LIBPATH:$file" 92084f91ccSmrg} 93084f91ccSmrg 94084f91ccSmrg# func_cl_dashl library 95084f91ccSmrg# Do a library search-path lookup for cl 96084f91ccSmrgfunc_cl_dashl () 97084f91ccSmrg{ 98084f91ccSmrg lib=$1 99084f91ccSmrg found=no 100084f91ccSmrg save_IFS=$IFS 101084f91ccSmrg IFS=';' 102084f91ccSmrg for dir in $lib_path $LIB 103084f91ccSmrg do 104084f91ccSmrg IFS=$save_IFS 105084f91ccSmrg if $shared && test -f "$dir/$lib.dll.lib"; then 106084f91ccSmrg found=yes 107084f91ccSmrg lib=$dir/$lib.dll.lib 108084f91ccSmrg break 109084f91ccSmrg fi 110084f91ccSmrg if test -f "$dir/$lib.lib"; then 111084f91ccSmrg found=yes 112084f91ccSmrg lib=$dir/$lib.lib 113084f91ccSmrg break 114084f91ccSmrg fi 115084f91ccSmrg if test -f "$dir/lib$lib.a"; then 116084f91ccSmrg found=yes 117084f91ccSmrg lib=$dir/lib$lib.a 118084f91ccSmrg break 119084f91ccSmrg fi 120084f91ccSmrg done 121084f91ccSmrg IFS=$save_IFS 122084f91ccSmrg 123084f91ccSmrg if test "$found" != yes; then 124084f91ccSmrg lib=$lib.lib 125084f91ccSmrg fi 126084f91ccSmrg} 127084f91ccSmrg 128084f91ccSmrg# func_cl_wrapper cl arg... 129084f91ccSmrg# Adjust compile command to suit cl 130084f91ccSmrgfunc_cl_wrapper () 131084f91ccSmrg{ 132084f91ccSmrg # Assume a capable shell 133084f91ccSmrg lib_path= 134084f91ccSmrg shared=: 135084f91ccSmrg linker_opts= 136084f91ccSmrg for arg 137084f91ccSmrg do 138084f91ccSmrg if test -n "$eat"; then 139084f91ccSmrg eat= 140084f91ccSmrg else 141084f91ccSmrg case $1 in 142084f91ccSmrg -o) 143084f91ccSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 144084f91ccSmrg eat=1 145084f91ccSmrg case $2 in 146084f91ccSmrg *.o | *.[oO][bB][jJ]) 147084f91ccSmrg func_file_conv "$2" 148084f91ccSmrg set x "$@" -Fo"$file" 149084f91ccSmrg shift 150084f91ccSmrg ;; 151084f91ccSmrg *) 152084f91ccSmrg func_file_conv "$2" 153084f91ccSmrg set x "$@" -Fe"$file" 154084f91ccSmrg shift 155084f91ccSmrg ;; 156084f91ccSmrg esac 157084f91ccSmrg ;; 158084f91ccSmrg -I) 159084f91ccSmrg eat=1 160084f91ccSmrg func_file_conv "$2" mingw 161084f91ccSmrg set x "$@" -I"$file" 162084f91ccSmrg shift 163084f91ccSmrg ;; 164084f91ccSmrg -I*) 165084f91ccSmrg func_file_conv "${1#-I}" mingw 166084f91ccSmrg set x "$@" -I"$file" 167084f91ccSmrg shift 168084f91ccSmrg ;; 169084f91ccSmrg -l) 170084f91ccSmrg eat=1 171084f91ccSmrg func_cl_dashl "$2" 172084f91ccSmrg set x "$@" "$lib" 173084f91ccSmrg shift 174084f91ccSmrg ;; 175084f91ccSmrg -l*) 176084f91ccSmrg func_cl_dashl "${1#-l}" 177084f91ccSmrg set x "$@" "$lib" 178084f91ccSmrg shift 179084f91ccSmrg ;; 180084f91ccSmrg -L) 181084f91ccSmrg eat=1 182084f91ccSmrg func_cl_dashL "$2" 183084f91ccSmrg ;; 184084f91ccSmrg -L*) 185084f91ccSmrg func_cl_dashL "${1#-L}" 186084f91ccSmrg ;; 187084f91ccSmrg -static) 188084f91ccSmrg shared=false 189084f91ccSmrg ;; 190084f91ccSmrg -Wl,*) 191084f91ccSmrg arg=${1#-Wl,} 192084f91ccSmrg save_ifs="$IFS"; IFS=',' 193084f91ccSmrg for flag in $arg; do 194084f91ccSmrg IFS="$save_ifs" 195084f91ccSmrg linker_opts="$linker_opts $flag" 196084f91ccSmrg done 197084f91ccSmrg IFS="$save_ifs" 198084f91ccSmrg ;; 199084f91ccSmrg -Xlinker) 200084f91ccSmrg eat=1 201084f91ccSmrg linker_opts="$linker_opts $2" 202084f91ccSmrg ;; 203084f91ccSmrg -*) 204084f91ccSmrg set x "$@" "$1" 205084f91ccSmrg shift 206084f91ccSmrg ;; 207084f91ccSmrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208084f91ccSmrg func_file_conv "$1" 209084f91ccSmrg set x "$@" -Tp"$file" 210084f91ccSmrg shift 211084f91ccSmrg ;; 212084f91ccSmrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213084f91ccSmrg func_file_conv "$1" mingw 214084f91ccSmrg set x "$@" "$file" 215084f91ccSmrg shift 216084f91ccSmrg ;; 217084f91ccSmrg *) 218084f91ccSmrg set x "$@" "$1" 219084f91ccSmrg shift 220084f91ccSmrg ;; 221084f91ccSmrg esac 222084f91ccSmrg fi 223084f91ccSmrg shift 224084f91ccSmrg done 225084f91ccSmrg if test -n "$linker_opts"; then 226084f91ccSmrg linker_opts="-link$linker_opts" 227084f91ccSmrg fi 228084f91ccSmrg exec "$@" $linker_opts 229084f91ccSmrg exit 1 230084f91ccSmrg} 231084f91ccSmrg 232084f91ccSmrgeat= 233084f91ccSmrg 234084f91ccSmrgcase $1 in 235084f91ccSmrg '') 236084f91ccSmrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 237084f91ccSmrg exit 1; 238084f91ccSmrg ;; 239084f91ccSmrg -h | --h*) 240084f91ccSmrg cat <<\EOF 241084f91ccSmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 242084f91ccSmrg 243084f91ccSmrgWrapper for compilers which do not understand '-c -o'. 244084f91ccSmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 245084f91ccSmrgarguments, and rename the output as expected. 246084f91ccSmrg 247084f91ccSmrgIf you are trying to build a whole package this is not the 248084f91ccSmrgright script to run: please start by reading the file 'INSTALL'. 249084f91ccSmrg 250084f91ccSmrgReport bugs to <bug-automake@gnu.org>. 251084f91ccSmrgEOF 252084f91ccSmrg exit $? 253084f91ccSmrg ;; 254084f91ccSmrg -v | --v*) 255084f91ccSmrg echo "compile $scriptversion" 256084f91ccSmrg exit $? 257084f91ccSmrg ;; 258084f91ccSmrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 259084f91ccSmrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 260084f91ccSmrg func_cl_wrapper "$@" # Doesn't return... 261084f91ccSmrg ;; 262084f91ccSmrgesac 263084f91ccSmrg 264084f91ccSmrgofile= 265084f91ccSmrgcfile= 266084f91ccSmrg 267084f91ccSmrgfor arg 268084f91ccSmrgdo 269084f91ccSmrg if test -n "$eat"; then 270084f91ccSmrg eat= 271084f91ccSmrg else 272084f91ccSmrg case $1 in 273084f91ccSmrg -o) 274084f91ccSmrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 275084f91ccSmrg # So we strip '-o arg' only if arg is an object. 276084f91ccSmrg eat=1 277084f91ccSmrg case $2 in 278084f91ccSmrg *.o | *.obj) 279084f91ccSmrg ofile=$2 280084f91ccSmrg ;; 281084f91ccSmrg *) 282084f91ccSmrg set x "$@" -o "$2" 283084f91ccSmrg shift 284084f91ccSmrg ;; 285084f91ccSmrg esac 286084f91ccSmrg ;; 287084f91ccSmrg *.c) 288084f91ccSmrg cfile=$1 289084f91ccSmrg set x "$@" "$1" 290084f91ccSmrg shift 291084f91ccSmrg ;; 292084f91ccSmrg *) 293084f91ccSmrg set x "$@" "$1" 294084f91ccSmrg shift 295084f91ccSmrg ;; 296084f91ccSmrg esac 297084f91ccSmrg fi 298084f91ccSmrg shift 299084f91ccSmrgdone 300084f91ccSmrg 301084f91ccSmrgif test -z "$ofile" || test -z "$cfile"; then 302084f91ccSmrg # If no '-o' option was seen then we might have been invoked from a 303084f91ccSmrg # pattern rule where we don't need one. That is ok -- this is a 304084f91ccSmrg # normal compilation that the losing compiler can handle. If no 305084f91ccSmrg # '.c' file was seen then we are probably linking. That is also 306084f91ccSmrg # ok. 307084f91ccSmrg exec "$@" 308084f91ccSmrgfi 309084f91ccSmrg 310084f91ccSmrg# Name of file we expect compiler to create. 311084f91ccSmrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 312084f91ccSmrg 313084f91ccSmrg# Create the lock directory. 314084f91ccSmrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 315084f91ccSmrg# that we are using for the .o file. Also, base the name on the expected 316084f91ccSmrg# object file name, since that is what matters with a parallel build. 317084f91ccSmrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 318084f91ccSmrgwhile true; do 319084f91ccSmrg if mkdir "$lockdir" >/dev/null 2>&1; then 320084f91ccSmrg break 321084f91ccSmrg fi 322084f91ccSmrg sleep 1 323084f91ccSmrgdone 324084f91ccSmrg# FIXME: race condition here if user kills between mkdir and trap. 325084f91ccSmrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 326084f91ccSmrg 327084f91ccSmrg# Run the compile. 328084f91ccSmrg"$@" 329084f91ccSmrgret=$? 330084f91ccSmrg 331084f91ccSmrgif test -f "$cofile"; then 332084f91ccSmrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 333084f91ccSmrgelif test -f "${cofile}bj"; then 334084f91ccSmrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 335084f91ccSmrgfi 336084f91ccSmrg 337084f91ccSmrgrmdir "$lockdir" 338084f91ccSmrgexit $ret 339084f91ccSmrg 340084f91ccSmrg# Local Variables: 341084f91ccSmrg# mode: shell-script 342084f91ccSmrg# sh-indentation: 2 343084f91ccSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 344084f91ccSmrg# time-stamp-start: "scriptversion=" 345084f91ccSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 346084f91ccSmrg# time-stamp-time-zone: "UTC0" 347084f91ccSmrg# time-stamp-end: "; # UTC" 348084f91ccSmrg# End: 349