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