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