compile revision 493f84f4
1493f84f4Smrg#! /bin/sh 2493f84f4Smrg# Wrapper for compilers which do not understand '-c -o'. 3493f84f4Smrg 4493f84f4Smrgscriptversion=2012-10-14.11; # UTC 5493f84f4Smrg 6493f84f4Smrg# Copyright (C) 1999-2013 Free Software Foundation, Inc. 7493f84f4Smrg# Written by Tom Tromey <tromey@cygnus.com>. 8493f84f4Smrg# 9493f84f4Smrg# This program is free software; you can redistribute it and/or modify 10493f84f4Smrg# it under the terms of the GNU General Public License as published by 11493f84f4Smrg# the Free Software Foundation; either version 2, or (at your option) 12493f84f4Smrg# any later version. 13493f84f4Smrg# 14493f84f4Smrg# This program is distributed in the hope that it will be useful, 15493f84f4Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 16493f84f4Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17493f84f4Smrg# GNU General Public License for more details. 18493f84f4Smrg# 19493f84f4Smrg# You should have received a copy of the GNU General Public License 20493f84f4Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 21493f84f4Smrg 22493f84f4Smrg# As a special exception to the GNU General Public License, if you 23493f84f4Smrg# distribute this file as part of a program that contains a 24493f84f4Smrg# configuration script generated by Autoconf, you may include it under 25493f84f4Smrg# the same distribution terms that you use for the rest of that program. 26493f84f4Smrg 27493f84f4Smrg# This file is maintained in Automake, please report 28493f84f4Smrg# bugs to <bug-automake@gnu.org> or send patches to 29493f84f4Smrg# <automake-patches@gnu.org>. 30493f84f4Smrg 31493f84f4Smrgnl=' 32493f84f4Smrg' 33493f84f4Smrg 34493f84f4Smrg# We need space, tab and new line, in precisely that order. Quoting is 35493f84f4Smrg# there to prevent tools from complaining about whitespace usage. 36493f84f4SmrgIFS=" "" $nl" 37493f84f4Smrg 38493f84f4Smrgfile_conv= 39493f84f4Smrg 40493f84f4Smrg# func_file_conv build_file lazy 41493f84f4Smrg# Convert a $build file to $host form and store it in $file 42493f84f4Smrg# Currently only supports Windows hosts. If the determined conversion 43493f84f4Smrg# type is listed in (the comma separated) LAZY, no conversion will 44493f84f4Smrg# take place. 45493f84f4Smrgfunc_file_conv () 46493f84f4Smrg{ 47493f84f4Smrg file=$1 48493f84f4Smrg case $file in 49493f84f4Smrg / | /[!/]*) # absolute file, and not a UNC file 50493f84f4Smrg if test -z "$file_conv"; then 51493f84f4Smrg # lazily determine how to convert abs files 52493f84f4Smrg case `uname -s` in 53493f84f4Smrg MINGW*) 54493f84f4Smrg file_conv=mingw 55493f84f4Smrg ;; 56493f84f4Smrg CYGWIN*) 57493f84f4Smrg file_conv=cygwin 58493f84f4Smrg ;; 59493f84f4Smrg *) 60493f84f4Smrg file_conv=wine 61493f84f4Smrg ;; 62493f84f4Smrg esac 63493f84f4Smrg fi 64493f84f4Smrg case $file_conv/,$2, in 65493f84f4Smrg *,$file_conv,*) 66493f84f4Smrg ;; 67493f84f4Smrg mingw/*) 68493f84f4Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69493f84f4Smrg ;; 70493f84f4Smrg cygwin/*) 71493f84f4Smrg file=`cygpath -m "$file" || echo "$file"` 72493f84f4Smrg ;; 73493f84f4Smrg wine/*) 74493f84f4Smrg file=`winepath -w "$file" || echo "$file"` 75493f84f4Smrg ;; 76493f84f4Smrg esac 77493f84f4Smrg ;; 78493f84f4Smrg esac 79493f84f4Smrg} 80493f84f4Smrg 81493f84f4Smrg# func_cl_dashL linkdir 82493f84f4Smrg# Make cl look for libraries in LINKDIR 83493f84f4Smrgfunc_cl_dashL () 84493f84f4Smrg{ 85493f84f4Smrg func_file_conv "$1" 86493f84f4Smrg if test -z "$lib_path"; then 87493f84f4Smrg lib_path=$file 88493f84f4Smrg else 89493f84f4Smrg lib_path="$lib_path;$file" 90493f84f4Smrg fi 91493f84f4Smrg linker_opts="$linker_opts -LIBPATH:$file" 92493f84f4Smrg} 93493f84f4Smrg 94493f84f4Smrg# func_cl_dashl library 95493f84f4Smrg# Do a library search-path lookup for cl 96493f84f4Smrgfunc_cl_dashl () 97493f84f4Smrg{ 98493f84f4Smrg lib=$1 99493f84f4Smrg found=no 100493f84f4Smrg save_IFS=$IFS 101493f84f4Smrg IFS=';' 102493f84f4Smrg for dir in $lib_path $LIB 103493f84f4Smrg do 104493f84f4Smrg IFS=$save_IFS 105493f84f4Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 106493f84f4Smrg found=yes 107493f84f4Smrg lib=$dir/$lib.dll.lib 108493f84f4Smrg break 109493f84f4Smrg fi 110493f84f4Smrg if test -f "$dir/$lib.lib"; then 111493f84f4Smrg found=yes 112493f84f4Smrg lib=$dir/$lib.lib 113493f84f4Smrg break 114493f84f4Smrg fi 115493f84f4Smrg if test -f "$dir/lib$lib.a"; then 116493f84f4Smrg found=yes 117493f84f4Smrg lib=$dir/lib$lib.a 118493f84f4Smrg break 119493f84f4Smrg fi 120493f84f4Smrg done 121493f84f4Smrg IFS=$save_IFS 122493f84f4Smrg 123493f84f4Smrg if test "$found" != yes; then 124493f84f4Smrg lib=$lib.lib 125493f84f4Smrg fi 126493f84f4Smrg} 127493f84f4Smrg 128493f84f4Smrg# func_cl_wrapper cl arg... 129493f84f4Smrg# Adjust compile command to suit cl 130493f84f4Smrgfunc_cl_wrapper () 131493f84f4Smrg{ 132493f84f4Smrg # Assume a capable shell 133493f84f4Smrg lib_path= 134493f84f4Smrg shared=: 135493f84f4Smrg linker_opts= 136493f84f4Smrg for arg 137493f84f4Smrg do 138493f84f4Smrg if test -n "$eat"; then 139493f84f4Smrg eat= 140493f84f4Smrg else 141493f84f4Smrg case $1 in 142493f84f4Smrg -o) 143493f84f4Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 144493f84f4Smrg eat=1 145493f84f4Smrg case $2 in 146493f84f4Smrg *.o | *.[oO][bB][jJ]) 147493f84f4Smrg func_file_conv "$2" 148493f84f4Smrg set x "$@" -Fo"$file" 149493f84f4Smrg shift 150493f84f4Smrg ;; 151493f84f4Smrg *) 152493f84f4Smrg func_file_conv "$2" 153493f84f4Smrg set x "$@" -Fe"$file" 154493f84f4Smrg shift 155493f84f4Smrg ;; 156493f84f4Smrg esac 157493f84f4Smrg ;; 158493f84f4Smrg -I) 159493f84f4Smrg eat=1 160493f84f4Smrg func_file_conv "$2" mingw 161493f84f4Smrg set x "$@" -I"$file" 162493f84f4Smrg shift 163493f84f4Smrg ;; 164493f84f4Smrg -I*) 165493f84f4Smrg func_file_conv "${1#-I}" mingw 166493f84f4Smrg set x "$@" -I"$file" 167493f84f4Smrg shift 168493f84f4Smrg ;; 169493f84f4Smrg -l) 170493f84f4Smrg eat=1 171493f84f4Smrg func_cl_dashl "$2" 172493f84f4Smrg set x "$@" "$lib" 173493f84f4Smrg shift 174493f84f4Smrg ;; 175493f84f4Smrg -l*) 176493f84f4Smrg func_cl_dashl "${1#-l}" 177493f84f4Smrg set x "$@" "$lib" 178493f84f4Smrg shift 179493f84f4Smrg ;; 180493f84f4Smrg -L) 181493f84f4Smrg eat=1 182493f84f4Smrg func_cl_dashL "$2" 183493f84f4Smrg ;; 184493f84f4Smrg -L*) 185493f84f4Smrg func_cl_dashL "${1#-L}" 186493f84f4Smrg ;; 187493f84f4Smrg -static) 188493f84f4Smrg shared=false 189493f84f4Smrg ;; 190493f84f4Smrg -Wl,*) 191493f84f4Smrg arg=${1#-Wl,} 192493f84f4Smrg save_ifs="$IFS"; IFS=',' 193493f84f4Smrg for flag in $arg; do 194493f84f4Smrg IFS="$save_ifs" 195493f84f4Smrg linker_opts="$linker_opts $flag" 196493f84f4Smrg done 197493f84f4Smrg IFS="$save_ifs" 198493f84f4Smrg ;; 199493f84f4Smrg -Xlinker) 200493f84f4Smrg eat=1 201493f84f4Smrg linker_opts="$linker_opts $2" 202493f84f4Smrg ;; 203493f84f4Smrg -*) 204493f84f4Smrg set x "$@" "$1" 205493f84f4Smrg shift 206493f84f4Smrg ;; 207493f84f4Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208493f84f4Smrg func_file_conv "$1" 209493f84f4Smrg set x "$@" -Tp"$file" 210493f84f4Smrg shift 211493f84f4Smrg ;; 212493f84f4Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213493f84f4Smrg func_file_conv "$1" mingw 214493f84f4Smrg set x "$@" "$file" 215493f84f4Smrg shift 216493f84f4Smrg ;; 217493f84f4Smrg *) 218493f84f4Smrg set x "$@" "$1" 219493f84f4Smrg shift 220493f84f4Smrg ;; 221493f84f4Smrg esac 222493f84f4Smrg fi 223493f84f4Smrg shift 224493f84f4Smrg done 225493f84f4Smrg if test -n "$linker_opts"; then 226493f84f4Smrg linker_opts="-link$linker_opts" 227493f84f4Smrg fi 228493f84f4Smrg exec "$@" $linker_opts 229493f84f4Smrg exit 1 230493f84f4Smrg} 231493f84f4Smrg 232493f84f4Smrgeat= 233493f84f4Smrg 234493f84f4Smrgcase $1 in 235493f84f4Smrg '') 236493f84f4Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 237493f84f4Smrg exit 1; 238493f84f4Smrg ;; 239493f84f4Smrg -h | --h*) 240493f84f4Smrg cat <<\EOF 241493f84f4SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 242493f84f4Smrg 243493f84f4SmrgWrapper for compilers which do not understand '-c -o'. 244493f84f4SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 245493f84f4Smrgarguments, and rename the output as expected. 246493f84f4Smrg 247493f84f4SmrgIf you are trying to build a whole package this is not the 248493f84f4Smrgright script to run: please start by reading the file 'INSTALL'. 249493f84f4Smrg 250493f84f4SmrgReport bugs to <bug-automake@gnu.org>. 251493f84f4SmrgEOF 252493f84f4Smrg exit $? 253493f84f4Smrg ;; 254493f84f4Smrg -v | --v*) 255493f84f4Smrg echo "compile $scriptversion" 256493f84f4Smrg exit $? 257493f84f4Smrg ;; 258493f84f4Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 259493f84f4Smrg func_cl_wrapper "$@" # Doesn't return... 260493f84f4Smrg ;; 261493f84f4Smrgesac 262493f84f4Smrg 263493f84f4Smrgofile= 264493f84f4Smrgcfile= 265493f84f4Smrg 266493f84f4Smrgfor arg 267493f84f4Smrgdo 268493f84f4Smrg if test -n "$eat"; then 269493f84f4Smrg eat= 270493f84f4Smrg else 271493f84f4Smrg case $1 in 272493f84f4Smrg -o) 273493f84f4Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 274493f84f4Smrg # So we strip '-o arg' only if arg is an object. 275493f84f4Smrg eat=1 276493f84f4Smrg case $2 in 277493f84f4Smrg *.o | *.obj) 278493f84f4Smrg ofile=$2 279493f84f4Smrg ;; 280493f84f4Smrg *) 281493f84f4Smrg set x "$@" -o "$2" 282493f84f4Smrg shift 283493f84f4Smrg ;; 284493f84f4Smrg esac 285493f84f4Smrg ;; 286493f84f4Smrg *.c) 287493f84f4Smrg cfile=$1 288493f84f4Smrg set x "$@" "$1" 289493f84f4Smrg shift 290493f84f4Smrg ;; 291493f84f4Smrg *) 292493f84f4Smrg set x "$@" "$1" 293493f84f4Smrg shift 294493f84f4Smrg ;; 295493f84f4Smrg esac 296493f84f4Smrg fi 297493f84f4Smrg shift 298493f84f4Smrgdone 299493f84f4Smrg 300493f84f4Smrgif test -z "$ofile" || test -z "$cfile"; then 301493f84f4Smrg # If no '-o' option was seen then we might have been invoked from a 302493f84f4Smrg # pattern rule where we don't need one. That is ok -- this is a 303493f84f4Smrg # normal compilation that the losing compiler can handle. If no 304493f84f4Smrg # '.c' file was seen then we are probably linking. That is also 305493f84f4Smrg # ok. 306493f84f4Smrg exec "$@" 307493f84f4Smrgfi 308493f84f4Smrg 309493f84f4Smrg# Name of file we expect compiler to create. 310493f84f4Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 311493f84f4Smrg 312493f84f4Smrg# Create the lock directory. 313493f84f4Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 314493f84f4Smrg# that we are using for the .o file. Also, base the name on the expected 315493f84f4Smrg# object file name, since that is what matters with a parallel build. 316493f84f4Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 317493f84f4Smrgwhile true; do 318493f84f4Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 319493f84f4Smrg break 320493f84f4Smrg fi 321493f84f4Smrg sleep 1 322493f84f4Smrgdone 323493f84f4Smrg# FIXME: race condition here if user kills between mkdir and trap. 324493f84f4Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 325493f84f4Smrg 326493f84f4Smrg# Run the compile. 327493f84f4Smrg"$@" 328493f84f4Smrgret=$? 329493f84f4Smrg 330493f84f4Smrgif test -f "$cofile"; then 331493f84f4Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 332493f84f4Smrgelif test -f "${cofile}bj"; then 333493f84f4Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 334493f84f4Smrgfi 335493f84f4Smrg 336493f84f4Smrgrmdir "$lockdir" 337493f84f4Smrgexit $ret 338493f84f4Smrg 339493f84f4Smrg# Local Variables: 340493f84f4Smrg# mode: shell-script 341493f84f4Smrg# sh-indentation: 2 342493f84f4Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 343493f84f4Smrg# time-stamp-start: "scriptversion=" 344493f84f4Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 345493f84f4Smrg# time-stamp-time-zone: "UTC" 346493f84f4Smrg# time-stamp-end: "; # UTC" 347493f84f4Smrg# End: 348