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