compile revision 7d2c738b
1818534a1Smrg#! /bin/sh 2818534a1Smrg# Wrapper for compilers which do not understand '-c -o'. 3818534a1Smrg 47d2c738bSmrgscriptversion=2018-03-07.03; # UTC 5818534a1Smrg 67d2c738bSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7818534a1Smrg# Written by Tom Tromey <tromey@cygnus.com>. 8818534a1Smrg# 9818534a1Smrg# This program is free software; you can redistribute it and/or modify 10818534a1Smrg# it under the terms of the GNU General Public License as published by 11818534a1Smrg# the Free Software Foundation; either version 2, or (at your option) 12818534a1Smrg# any later version. 13818534a1Smrg# 14818534a1Smrg# This program is distributed in the hope that it will be useful, 15818534a1Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 16818534a1Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17818534a1Smrg# GNU General Public License for more details. 18818534a1Smrg# 19818534a1Smrg# You should have received a copy of the GNU General Public License 207d2c738bSmrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 21818534a1Smrg 22818534a1Smrg# As a special exception to the GNU General Public License, if you 23818534a1Smrg# distribute this file as part of a program that contains a 24818534a1Smrg# configuration script generated by Autoconf, you may include it under 25818534a1Smrg# the same distribution terms that you use for the rest of that program. 26818534a1Smrg 27818534a1Smrg# This file is maintained in Automake, please report 28818534a1Smrg# bugs to <bug-automake@gnu.org> or send patches to 29818534a1Smrg# <automake-patches@gnu.org>. 30818534a1Smrg 31818534a1Smrgnl=' 32818534a1Smrg' 33818534a1Smrg 34818534a1Smrg# We need space, tab and new line, in precisely that order. Quoting is 35818534a1Smrg# there to prevent tools from complaining about whitespace usage. 36818534a1SmrgIFS=" "" $nl" 37818534a1Smrg 38818534a1Smrgfile_conv= 39818534a1Smrg 40818534a1Smrg# func_file_conv build_file lazy 41818534a1Smrg# Convert a $build file to $host form and store it in $file 42818534a1Smrg# Currently only supports Windows hosts. If the determined conversion 43818534a1Smrg# type is listed in (the comma separated) LAZY, no conversion will 44818534a1Smrg# take place. 45818534a1Smrgfunc_file_conv () 46818534a1Smrg{ 47818534a1Smrg file=$1 48818534a1Smrg case $file in 49818534a1Smrg / | /[!/]*) # absolute file, and not a UNC file 50818534a1Smrg if test -z "$file_conv"; then 51818534a1Smrg # lazily determine how to convert abs files 52818534a1Smrg case `uname -s` in 53818534a1Smrg MINGW*) 54818534a1Smrg file_conv=mingw 55818534a1Smrg ;; 567d2c738bSmrg CYGWIN* | MSYS*) 57818534a1Smrg file_conv=cygwin 58818534a1Smrg ;; 59818534a1Smrg *) 60818534a1Smrg file_conv=wine 61818534a1Smrg ;; 62818534a1Smrg esac 63818534a1Smrg fi 64818534a1Smrg case $file_conv/,$2, in 65818534a1Smrg *,$file_conv,*) 66818534a1Smrg ;; 67818534a1Smrg mingw/*) 68818534a1Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69818534a1Smrg ;; 707d2c738bSmrg cygwin/* | msys/*) 71818534a1Smrg file=`cygpath -m "$file" || echo "$file"` 72818534a1Smrg ;; 73818534a1Smrg wine/*) 74818534a1Smrg file=`winepath -w "$file" || echo "$file"` 75818534a1Smrg ;; 76818534a1Smrg esac 77818534a1Smrg ;; 78818534a1Smrg esac 79818534a1Smrg} 80818534a1Smrg 81818534a1Smrg# func_cl_dashL linkdir 82818534a1Smrg# Make cl look for libraries in LINKDIR 83818534a1Smrgfunc_cl_dashL () 84818534a1Smrg{ 85818534a1Smrg func_file_conv "$1" 86818534a1Smrg if test -z "$lib_path"; then 87818534a1Smrg lib_path=$file 88818534a1Smrg else 89818534a1Smrg lib_path="$lib_path;$file" 90818534a1Smrg fi 91818534a1Smrg linker_opts="$linker_opts -LIBPATH:$file" 92818534a1Smrg} 93818534a1Smrg 94818534a1Smrg# func_cl_dashl library 95818534a1Smrg# Do a library search-path lookup for cl 96818534a1Smrgfunc_cl_dashl () 97818534a1Smrg{ 98818534a1Smrg lib=$1 99818534a1Smrg found=no 100818534a1Smrg save_IFS=$IFS 101818534a1Smrg IFS=';' 102818534a1Smrg for dir in $lib_path $LIB 103818534a1Smrg do 104818534a1Smrg IFS=$save_IFS 105818534a1Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 106818534a1Smrg found=yes 107818534a1Smrg lib=$dir/$lib.dll.lib 108818534a1Smrg break 109818534a1Smrg fi 110818534a1Smrg if test -f "$dir/$lib.lib"; then 111818534a1Smrg found=yes 112818534a1Smrg lib=$dir/$lib.lib 113818534a1Smrg break 114818534a1Smrg fi 115818534a1Smrg if test -f "$dir/lib$lib.a"; then 116818534a1Smrg found=yes 117818534a1Smrg lib=$dir/lib$lib.a 118818534a1Smrg break 119818534a1Smrg fi 120818534a1Smrg done 121818534a1Smrg IFS=$save_IFS 122818534a1Smrg 123818534a1Smrg if test "$found" != yes; then 124818534a1Smrg lib=$lib.lib 125818534a1Smrg fi 126818534a1Smrg} 127818534a1Smrg 128818534a1Smrg# func_cl_wrapper cl arg... 129818534a1Smrg# Adjust compile command to suit cl 130818534a1Smrgfunc_cl_wrapper () 131818534a1Smrg{ 132818534a1Smrg # Assume a capable shell 133818534a1Smrg lib_path= 134818534a1Smrg shared=: 135818534a1Smrg linker_opts= 136818534a1Smrg for arg 137818534a1Smrg do 138818534a1Smrg if test -n "$eat"; then 139818534a1Smrg eat= 140818534a1Smrg else 141818534a1Smrg case $1 in 142818534a1Smrg -o) 143818534a1Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 144818534a1Smrg eat=1 145818534a1Smrg case $2 in 146818534a1Smrg *.o | *.[oO][bB][jJ]) 147818534a1Smrg func_file_conv "$2" 148818534a1Smrg set x "$@" -Fo"$file" 149818534a1Smrg shift 150818534a1Smrg ;; 151818534a1Smrg *) 152818534a1Smrg func_file_conv "$2" 153818534a1Smrg set x "$@" -Fe"$file" 154818534a1Smrg shift 155818534a1Smrg ;; 156818534a1Smrg esac 157818534a1Smrg ;; 158818534a1Smrg -I) 159818534a1Smrg eat=1 160818534a1Smrg func_file_conv "$2" mingw 161818534a1Smrg set x "$@" -I"$file" 162818534a1Smrg shift 163818534a1Smrg ;; 164818534a1Smrg -I*) 165818534a1Smrg func_file_conv "${1#-I}" mingw 166818534a1Smrg set x "$@" -I"$file" 167818534a1Smrg shift 168818534a1Smrg ;; 169818534a1Smrg -l) 170818534a1Smrg eat=1 171818534a1Smrg func_cl_dashl "$2" 172818534a1Smrg set x "$@" "$lib" 173818534a1Smrg shift 174818534a1Smrg ;; 175818534a1Smrg -l*) 176818534a1Smrg func_cl_dashl "${1#-l}" 177818534a1Smrg set x "$@" "$lib" 178818534a1Smrg shift 179818534a1Smrg ;; 180818534a1Smrg -L) 181818534a1Smrg eat=1 182818534a1Smrg func_cl_dashL "$2" 183818534a1Smrg ;; 184818534a1Smrg -L*) 185818534a1Smrg func_cl_dashL "${1#-L}" 186818534a1Smrg ;; 187818534a1Smrg -static) 188818534a1Smrg shared=false 189818534a1Smrg ;; 190818534a1Smrg -Wl,*) 191818534a1Smrg arg=${1#-Wl,} 192818534a1Smrg save_ifs="$IFS"; IFS=',' 193818534a1Smrg for flag in $arg; do 194818534a1Smrg IFS="$save_ifs" 195818534a1Smrg linker_opts="$linker_opts $flag" 196818534a1Smrg done 197818534a1Smrg IFS="$save_ifs" 198818534a1Smrg ;; 199818534a1Smrg -Xlinker) 200818534a1Smrg eat=1 201818534a1Smrg linker_opts="$linker_opts $2" 202818534a1Smrg ;; 203818534a1Smrg -*) 204818534a1Smrg set x "$@" "$1" 205818534a1Smrg shift 206818534a1Smrg ;; 207818534a1Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208818534a1Smrg func_file_conv "$1" 209818534a1Smrg set x "$@" -Tp"$file" 210818534a1Smrg shift 211818534a1Smrg ;; 212818534a1Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213818534a1Smrg func_file_conv "$1" mingw 214818534a1Smrg set x "$@" "$file" 215818534a1Smrg shift 216818534a1Smrg ;; 217818534a1Smrg *) 218818534a1Smrg set x "$@" "$1" 219818534a1Smrg shift 220818534a1Smrg ;; 221818534a1Smrg esac 222818534a1Smrg fi 223818534a1Smrg shift 224818534a1Smrg done 225818534a1Smrg if test -n "$linker_opts"; then 226818534a1Smrg linker_opts="-link$linker_opts" 227818534a1Smrg fi 228818534a1Smrg exec "$@" $linker_opts 229818534a1Smrg exit 1 230818534a1Smrg} 231818534a1Smrg 232818534a1Smrgeat= 233818534a1Smrg 234818534a1Smrgcase $1 in 235818534a1Smrg '') 236818534a1Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 237818534a1Smrg exit 1; 238818534a1Smrg ;; 239818534a1Smrg -h | --h*) 240818534a1Smrg cat <<\EOF 241818534a1SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 242818534a1Smrg 243818534a1SmrgWrapper for compilers which do not understand '-c -o'. 244818534a1SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 245818534a1Smrgarguments, and rename the output as expected. 246818534a1Smrg 247818534a1SmrgIf you are trying to build a whole package this is not the 248818534a1Smrgright script to run: please start by reading the file 'INSTALL'. 249818534a1Smrg 250818534a1SmrgReport bugs to <bug-automake@gnu.org>. 251818534a1SmrgEOF 252818534a1Smrg exit $? 253818534a1Smrg ;; 254818534a1Smrg -v | --v*) 255818534a1Smrg echo "compile $scriptversion" 256818534a1Smrg exit $? 257818534a1Smrg ;; 2587d2c738bSmrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 2597d2c738bSmrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 260818534a1Smrg func_cl_wrapper "$@" # Doesn't return... 261818534a1Smrg ;; 262818534a1Smrgesac 263818534a1Smrg 264818534a1Smrgofile= 265818534a1Smrgcfile= 266818534a1Smrg 267818534a1Smrgfor arg 268818534a1Smrgdo 269818534a1Smrg if test -n "$eat"; then 270818534a1Smrg eat= 271818534a1Smrg else 272818534a1Smrg case $1 in 273818534a1Smrg -o) 274818534a1Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 275818534a1Smrg # So we strip '-o arg' only if arg is an object. 276818534a1Smrg eat=1 277818534a1Smrg case $2 in 278818534a1Smrg *.o | *.obj) 279818534a1Smrg ofile=$2 280818534a1Smrg ;; 281818534a1Smrg *) 282818534a1Smrg set x "$@" -o "$2" 283818534a1Smrg shift 284818534a1Smrg ;; 285818534a1Smrg esac 286818534a1Smrg ;; 287818534a1Smrg *.c) 288818534a1Smrg cfile=$1 289818534a1Smrg set x "$@" "$1" 290818534a1Smrg shift 291818534a1Smrg ;; 292818534a1Smrg *) 293818534a1Smrg set x "$@" "$1" 294818534a1Smrg shift 295818534a1Smrg ;; 296818534a1Smrg esac 297818534a1Smrg fi 298818534a1Smrg shift 299818534a1Smrgdone 300818534a1Smrg 301818534a1Smrgif test -z "$ofile" || test -z "$cfile"; then 302818534a1Smrg # If no '-o' option was seen then we might have been invoked from a 303818534a1Smrg # pattern rule where we don't need one. That is ok -- this is a 304818534a1Smrg # normal compilation that the losing compiler can handle. If no 305818534a1Smrg # '.c' file was seen then we are probably linking. That is also 306818534a1Smrg # ok. 307818534a1Smrg exec "$@" 308818534a1Smrgfi 309818534a1Smrg 310818534a1Smrg# Name of file we expect compiler to create. 311818534a1Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 312818534a1Smrg 313818534a1Smrg# Create the lock directory. 314818534a1Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 315818534a1Smrg# that we are using for the .o file. Also, base the name on the expected 316818534a1Smrg# object file name, since that is what matters with a parallel build. 317818534a1Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 318818534a1Smrgwhile true; do 319818534a1Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 320818534a1Smrg break 321818534a1Smrg fi 322818534a1Smrg sleep 1 323818534a1Smrgdone 324818534a1Smrg# FIXME: race condition here if user kills between mkdir and trap. 325818534a1Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 326818534a1Smrg 327818534a1Smrg# Run the compile. 328818534a1Smrg"$@" 329818534a1Smrgret=$? 330818534a1Smrg 331818534a1Smrgif test -f "$cofile"; then 332818534a1Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 333818534a1Smrgelif test -f "${cofile}bj"; then 334818534a1Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 335818534a1Smrgfi 336818534a1Smrg 337818534a1Smrgrmdir "$lockdir" 338818534a1Smrgexit $ret 339818534a1Smrg 340818534a1Smrg# Local Variables: 341818534a1Smrg# mode: shell-script 342818534a1Smrg# sh-indentation: 2 3437d2c738bSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 344818534a1Smrg# time-stamp-start: "scriptversion=" 345818534a1Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 3467d2c738bSmrg# time-stamp-time-zone: "UTC0" 347818534a1Smrg# time-stamp-end: "; # UTC" 348818534a1Smrg# End: 349