1fdb3d228Smrg#! /bin/sh 2585aa3f7Smrg# Wrapper for compilers which do not understand '-c -o'. 3fdb3d228Smrg 474b35aa8Smrgscriptversion=2018-03-07.03; # UTC 5fdb3d228Smrg 674b35aa8Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7fdb3d228Smrg# Written by Tom Tromey <tromey@cygnus.com>. 8fdb3d228Smrg# 9fdb3d228Smrg# This program is free software; you can redistribute it and/or modify 10fdb3d228Smrg# it under the terms of the GNU General Public License as published by 11fdb3d228Smrg# the Free Software Foundation; either version 2, or (at your option) 12fdb3d228Smrg# any later version. 13fdb3d228Smrg# 14fdb3d228Smrg# This program is distributed in the hope that it will be useful, 15fdb3d228Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 16fdb3d228Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17fdb3d228Smrg# GNU General Public License for more details. 18fdb3d228Smrg# 19fdb3d228Smrg# You should have received a copy of the GNU General Public License 2074b35aa8Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 21fdb3d228Smrg 22fdb3d228Smrg# As a special exception to the GNU General Public License, if you 23fdb3d228Smrg# distribute this file as part of a program that contains a 24fdb3d228Smrg# configuration script generated by Autoconf, you may include it under 25fdb3d228Smrg# the same distribution terms that you use for the rest of that program. 26fdb3d228Smrg 27585aa3f7Smrg# This file is maintained in Automake, please report 28585aa3f7Smrg# bugs to <bug-automake@gnu.org> or send patches to 29585aa3f7Smrg# <automake-patches@gnu.org>. 30fdb3d228Smrg 31585aa3f7Smrgnl=' 32585aa3f7Smrg' 33585aa3f7Smrg 34585aa3f7Smrg# We need space, tab and new line, in precisely that order. Quoting is 35585aa3f7Smrg# there to prevent tools from complaining about whitespace usage. 36585aa3f7SmrgIFS=" "" $nl" 37585aa3f7Smrg 38585aa3f7Smrgfile_conv= 39585aa3f7Smrg 40585aa3f7Smrg# func_file_conv build_file lazy 41585aa3f7Smrg# Convert a $build file to $host form and store it in $file 42585aa3f7Smrg# Currently only supports Windows hosts. If the determined conversion 43585aa3f7Smrg# type is listed in (the comma separated) LAZY, no conversion will 44585aa3f7Smrg# take place. 45585aa3f7Smrgfunc_file_conv () 46585aa3f7Smrg{ 47585aa3f7Smrg file=$1 48585aa3f7Smrg case $file in 49585aa3f7Smrg / | /[!/]*) # absolute file, and not a UNC file 50585aa3f7Smrg if test -z "$file_conv"; then 51585aa3f7Smrg # lazily determine how to convert abs files 52585aa3f7Smrg case `uname -s` in 53585aa3f7Smrg MINGW*) 54585aa3f7Smrg file_conv=mingw 55585aa3f7Smrg ;; 5674b35aa8Smrg CYGWIN* | MSYS*) 57585aa3f7Smrg file_conv=cygwin 58585aa3f7Smrg ;; 59585aa3f7Smrg *) 60585aa3f7Smrg file_conv=wine 61585aa3f7Smrg ;; 62585aa3f7Smrg esac 63585aa3f7Smrg fi 64585aa3f7Smrg case $file_conv/,$2, in 65585aa3f7Smrg *,$file_conv,*) 66585aa3f7Smrg ;; 67585aa3f7Smrg mingw/*) 68585aa3f7Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69585aa3f7Smrg ;; 7074b35aa8Smrg cygwin/* | msys/*) 71585aa3f7Smrg file=`cygpath -m "$file" || echo "$file"` 72585aa3f7Smrg ;; 73585aa3f7Smrg wine/*) 74585aa3f7Smrg file=`winepath -w "$file" || echo "$file"` 75585aa3f7Smrg ;; 76585aa3f7Smrg esac 77585aa3f7Smrg ;; 78585aa3f7Smrg esac 79585aa3f7Smrg} 80585aa3f7Smrg 81585aa3f7Smrg# func_cl_dashL linkdir 82585aa3f7Smrg# Make cl look for libraries in LINKDIR 83585aa3f7Smrgfunc_cl_dashL () 84585aa3f7Smrg{ 85585aa3f7Smrg func_file_conv "$1" 86585aa3f7Smrg if test -z "$lib_path"; then 87585aa3f7Smrg lib_path=$file 88585aa3f7Smrg else 89585aa3f7Smrg lib_path="$lib_path;$file" 90585aa3f7Smrg fi 91585aa3f7Smrg linker_opts="$linker_opts -LIBPATH:$file" 92585aa3f7Smrg} 93585aa3f7Smrg 94585aa3f7Smrg# func_cl_dashl library 95585aa3f7Smrg# Do a library search-path lookup for cl 96585aa3f7Smrgfunc_cl_dashl () 97585aa3f7Smrg{ 98585aa3f7Smrg lib=$1 99585aa3f7Smrg found=no 100585aa3f7Smrg save_IFS=$IFS 101585aa3f7Smrg IFS=';' 102585aa3f7Smrg for dir in $lib_path $LIB 103585aa3f7Smrg do 104585aa3f7Smrg IFS=$save_IFS 105585aa3f7Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 106585aa3f7Smrg found=yes 107585aa3f7Smrg lib=$dir/$lib.dll.lib 108585aa3f7Smrg break 109585aa3f7Smrg fi 110585aa3f7Smrg if test -f "$dir/$lib.lib"; then 111585aa3f7Smrg found=yes 112585aa3f7Smrg lib=$dir/$lib.lib 113585aa3f7Smrg break 114585aa3f7Smrg fi 115585aa3f7Smrg if test -f "$dir/lib$lib.a"; then 116585aa3f7Smrg found=yes 117585aa3f7Smrg lib=$dir/lib$lib.a 118585aa3f7Smrg break 119585aa3f7Smrg fi 120585aa3f7Smrg done 121585aa3f7Smrg IFS=$save_IFS 122585aa3f7Smrg 123585aa3f7Smrg if test "$found" != yes; then 124585aa3f7Smrg lib=$lib.lib 125585aa3f7Smrg fi 126585aa3f7Smrg} 127585aa3f7Smrg 128585aa3f7Smrg# func_cl_wrapper cl arg... 129585aa3f7Smrg# Adjust compile command to suit cl 130585aa3f7Smrgfunc_cl_wrapper () 131585aa3f7Smrg{ 132585aa3f7Smrg # Assume a capable shell 133585aa3f7Smrg lib_path= 134585aa3f7Smrg shared=: 135585aa3f7Smrg linker_opts= 136585aa3f7Smrg for arg 137585aa3f7Smrg do 138585aa3f7Smrg if test -n "$eat"; then 139585aa3f7Smrg eat= 140585aa3f7Smrg else 141585aa3f7Smrg case $1 in 142585aa3f7Smrg -o) 143585aa3f7Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 144585aa3f7Smrg eat=1 145585aa3f7Smrg case $2 in 146585aa3f7Smrg *.o | *.[oO][bB][jJ]) 147585aa3f7Smrg func_file_conv "$2" 148585aa3f7Smrg set x "$@" -Fo"$file" 149585aa3f7Smrg shift 150585aa3f7Smrg ;; 151585aa3f7Smrg *) 152585aa3f7Smrg func_file_conv "$2" 153585aa3f7Smrg set x "$@" -Fe"$file" 154585aa3f7Smrg shift 155585aa3f7Smrg ;; 156585aa3f7Smrg esac 157585aa3f7Smrg ;; 158585aa3f7Smrg -I) 159585aa3f7Smrg eat=1 160585aa3f7Smrg func_file_conv "$2" mingw 161585aa3f7Smrg set x "$@" -I"$file" 162585aa3f7Smrg shift 163585aa3f7Smrg ;; 164585aa3f7Smrg -I*) 165585aa3f7Smrg func_file_conv "${1#-I}" mingw 166585aa3f7Smrg set x "$@" -I"$file" 167585aa3f7Smrg shift 168585aa3f7Smrg ;; 169585aa3f7Smrg -l) 170585aa3f7Smrg eat=1 171585aa3f7Smrg func_cl_dashl "$2" 172585aa3f7Smrg set x "$@" "$lib" 173585aa3f7Smrg shift 174585aa3f7Smrg ;; 175585aa3f7Smrg -l*) 176585aa3f7Smrg func_cl_dashl "${1#-l}" 177585aa3f7Smrg set x "$@" "$lib" 178585aa3f7Smrg shift 179585aa3f7Smrg ;; 180585aa3f7Smrg -L) 181585aa3f7Smrg eat=1 182585aa3f7Smrg func_cl_dashL "$2" 183585aa3f7Smrg ;; 184585aa3f7Smrg -L*) 185585aa3f7Smrg func_cl_dashL "${1#-L}" 186585aa3f7Smrg ;; 187585aa3f7Smrg -static) 188585aa3f7Smrg shared=false 189585aa3f7Smrg ;; 190585aa3f7Smrg -Wl,*) 191585aa3f7Smrg arg=${1#-Wl,} 192585aa3f7Smrg save_ifs="$IFS"; IFS=',' 193585aa3f7Smrg for flag in $arg; do 194585aa3f7Smrg IFS="$save_ifs" 195585aa3f7Smrg linker_opts="$linker_opts $flag" 196585aa3f7Smrg done 197585aa3f7Smrg IFS="$save_ifs" 198585aa3f7Smrg ;; 199585aa3f7Smrg -Xlinker) 200585aa3f7Smrg eat=1 201585aa3f7Smrg linker_opts="$linker_opts $2" 202585aa3f7Smrg ;; 203585aa3f7Smrg -*) 204585aa3f7Smrg set x "$@" "$1" 205585aa3f7Smrg shift 206585aa3f7Smrg ;; 207585aa3f7Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208585aa3f7Smrg func_file_conv "$1" 209585aa3f7Smrg set x "$@" -Tp"$file" 210585aa3f7Smrg shift 211585aa3f7Smrg ;; 212585aa3f7Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213585aa3f7Smrg func_file_conv "$1" mingw 214585aa3f7Smrg set x "$@" "$file" 215585aa3f7Smrg shift 216585aa3f7Smrg ;; 217585aa3f7Smrg *) 218585aa3f7Smrg set x "$@" "$1" 219585aa3f7Smrg shift 220585aa3f7Smrg ;; 221585aa3f7Smrg esac 222585aa3f7Smrg fi 223585aa3f7Smrg shift 224585aa3f7Smrg done 225585aa3f7Smrg if test -n "$linker_opts"; then 226585aa3f7Smrg linker_opts="-link$linker_opts" 227585aa3f7Smrg fi 228585aa3f7Smrg exec "$@" $linker_opts 229585aa3f7Smrg exit 1 230585aa3f7Smrg} 231585aa3f7Smrg 232585aa3f7Smrgeat= 233585aa3f7Smrg 234585aa3f7Smrgcase $1 in 235585aa3f7Smrg '') 236585aa3f7Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 237585aa3f7Smrg exit 1; 238585aa3f7Smrg ;; 239585aa3f7Smrg -h | --h*) 240585aa3f7Smrg cat <<\EOF 241585aa3f7SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 242585aa3f7Smrg 243585aa3f7SmrgWrapper for compilers which do not understand '-c -o'. 244585aa3f7SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 245585aa3f7Smrgarguments, and rename the output as expected. 246585aa3f7Smrg 247585aa3f7SmrgIf you are trying to build a whole package this is not the 248585aa3f7Smrgright script to run: please start by reading the file 'INSTALL'. 249585aa3f7Smrg 250585aa3f7SmrgReport bugs to <bug-automake@gnu.org>. 251585aa3f7SmrgEOF 252585aa3f7Smrg exit $? 253585aa3f7Smrg ;; 254585aa3f7Smrg -v | --v*) 255585aa3f7Smrg echo "compile $scriptversion" 256585aa3f7Smrg exit $? 257585aa3f7Smrg ;; 25874b35aa8Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 25974b35aa8Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 260585aa3f7Smrg func_cl_wrapper "$@" # Doesn't return... 261585aa3f7Smrg ;; 262585aa3f7Smrgesac 263fdb3d228Smrg 264fdb3d228Smrgofile= 265fdb3d228Smrgcfile= 266585aa3f7Smrg 267585aa3f7Smrgfor arg 268585aa3f7Smrgdo 269585aa3f7Smrg if test -n "$eat"; then 270585aa3f7Smrg eat= 271585aa3f7Smrg else 272585aa3f7Smrg case $1 in 273585aa3f7Smrg -o) 274585aa3f7Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 275585aa3f7Smrg # So we strip '-o arg' only if arg is an object. 276585aa3f7Smrg eat=1 277585aa3f7Smrg case $2 in 278585aa3f7Smrg *.o | *.obj) 279585aa3f7Smrg ofile=$2 280585aa3f7Smrg ;; 281585aa3f7Smrg *) 282585aa3f7Smrg set x "$@" -o "$2" 283585aa3f7Smrg shift 284585aa3f7Smrg ;; 285585aa3f7Smrg esac 286585aa3f7Smrg ;; 287585aa3f7Smrg *.c) 288585aa3f7Smrg cfile=$1 289585aa3f7Smrg set x "$@" "$1" 290585aa3f7Smrg shift 291585aa3f7Smrg ;; 292585aa3f7Smrg *) 293585aa3f7Smrg set x "$@" "$1" 294585aa3f7Smrg shift 295585aa3f7Smrg ;; 296585aa3f7Smrg esac 297585aa3f7Smrg fi 298585aa3f7Smrg shift 299fdb3d228Smrgdone 300fdb3d228Smrg 301fdb3d228Smrgif test -z "$ofile" || test -z "$cfile"; then 302585aa3f7Smrg # If no '-o' option was seen then we might have been invoked from a 303585aa3f7Smrg # pattern rule where we don't need one. That is ok -- this is a 304585aa3f7Smrg # normal compilation that the losing compiler can handle. If no 305585aa3f7Smrg # '.c' file was seen then we are probably linking. That is also 306585aa3f7Smrg # ok. 307585aa3f7Smrg exec "$@" 308fdb3d228Smrgfi 309fdb3d228Smrg 310fdb3d228Smrg# Name of file we expect compiler to create. 311585aa3f7Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 312fdb3d228Smrg 313fdb3d228Smrg# Create the lock directory. 314585aa3f7Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 315fdb3d228Smrg# that we are using for the .o file. Also, base the name on the expected 316fdb3d228Smrg# object file name, since that is what matters with a parallel build. 317585aa3f7Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 318fdb3d228Smrgwhile true; do 319585aa3f7Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 320585aa3f7Smrg break 321585aa3f7Smrg fi 322585aa3f7Smrg sleep 1 323fdb3d228Smrgdone 324fdb3d228Smrg# FIXME: race condition here if user kills between mkdir and trap. 325585aa3f7Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 326fdb3d228Smrg 327fdb3d228Smrg# Run the compile. 328585aa3f7Smrg"$@" 329585aa3f7Smrgret=$? 330fdb3d228Smrg 331fdb3d228Smrgif test -f "$cofile"; then 332585aa3f7Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 333585aa3f7Smrgelif test -f "${cofile}bj"; then 334585aa3f7Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 335fdb3d228Smrgfi 336fdb3d228Smrg 337585aa3f7Smrgrmdir "$lockdir" 338585aa3f7Smrgexit $ret 339585aa3f7Smrg 340585aa3f7Smrg# Local Variables: 341585aa3f7Smrg# mode: shell-script 342585aa3f7Smrg# sh-indentation: 2 34374b35aa8Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 344585aa3f7Smrg# time-stamp-start: "scriptversion=" 345585aa3f7Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 34674b35aa8Smrg# time-stamp-time-zone: "UTC0" 347585aa3f7Smrg# time-stamp-end: "; # UTC" 348585aa3f7Smrg# End: 349