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