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