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