compile revision 302408
11573Srgrimes#! /bin/sh 21573Srgrimes# Wrapper for compilers which do not understand '-c -o'. 31573Srgrimes 41573Srgrimesscriptversion=2012-10-14.11; # UTC 51573Srgrimes 61573Srgrimes# Copyright (C) 1999-2014 Free Software Foundation, Inc. 71573Srgrimes# Written by Tom Tromey <tromey@cygnus.com>. 8227753Stheraven# 9227753Stheraven# This program is free software; you can redistribute it and/or modify 10227753Stheraven# it under the terms of the GNU General Public License as published by 11227753Stheraven# the Free Software Foundation; either version 2, or (at your option) 12227753Stheraven# any later version. 131573Srgrimes# 141573Srgrimes# This program is distributed in the hope that it will be useful, 151573Srgrimes# but WITHOUT ANY WARRANTY; without even the implied warranty of 161573Srgrimes# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 171573Srgrimes# GNU General Public License for more details. 181573Srgrimes# 191573Srgrimes# You should have received a copy of the GNU General Public License 201573Srgrimes# along with this program. If not, see <http://www.gnu.org/licenses/>. 211573Srgrimes 221573Srgrimes# As a special exception to the GNU General Public License, if you 231573Srgrimes# distribute this file as part of a program that contains a 241573Srgrimes# configuration script generated by Autoconf, you may include it under 251573Srgrimes# the same distribution terms that you use for the rest of that program. 261573Srgrimes 271573Srgrimes# This file is maintained in Automake, please report 281573Srgrimes# bugs to <bug-automake@gnu.org> or send patches to 291573Srgrimes# <automake-patches@gnu.org>. 301573Srgrimes 311573Srgrimesnl=' 321573Srgrimes' 331573Srgrimes 341573Srgrimes# We need space, tab and new line, in precisely that order. Quoting is 351573Srgrimes# there to prevent tools from complaining about whitespace usage. 361573SrgrimesIFS=" "" $nl" 371573Srgrimes 381573Srgrimesfile_conv= 391573Srgrimes 401573Srgrimes# func_file_conv build_file lazy 4190045Sobrien# Convert a $build file to $host form and store it in $file 4290045Sobrien# Currently only supports Windows hosts. If the determined conversion 431573Srgrimes# type is listed in (the comma separated) LAZY, no conversion will 441573Srgrimes# take place. 451573Srgrimesfunc_file_conv () 461573Srgrimes{ 471573Srgrimes file=$1 481573Srgrimes case $file in 49132812Stjr / | /[!/]*) # absolute file, and not a UNC file 50132812Stjr if test -z "$file_conv"; then 51132812Stjr # lazily determine how to convert abs files 52132812Stjr case `uname -s` in 53132812Stjr MINGW*) 54132812Stjr file_conv=mingw 55132812Stjr ;; 56132812Stjr CYGWIN*) 57132812Stjr file_conv=cygwin 58132812Stjr ;; 59132812Stjr *) 601573Srgrimes file_conv=wine 61132812Stjr ;; 621573Srgrimes esac 63132812Stjr fi 64132812Stjr case $file_conv/,$2, in 651573Srgrimes *,$file_conv,*) 6619276Sache ;; 6719276Sache mingw/*) 681573Srgrimes file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 691573Srgrimes ;; 7026484Sache cygwin/*) 7126484Sache file=`cygpath -m "$file" || echo "$file"` 7226484Sache ;; 731573Srgrimes wine/*) 74132812Stjr file=`winepath -w "$file" || echo "$file"` 75206711Sjilles ;; 76206711Sjilles esac 7726484Sache ;; 781573Srgrimes esac 791573Srgrimes} 801573Srgrimes 811573Srgrimes# func_cl_dashL linkdir 821573Srgrimes# Make cl look for libraries in LINKDIR 83132812Stjrfunc_cl_dashL () 84132812Stjr{ 85206711Sjilles func_file_conv "$1" 86132812Stjr if test -z "$lib_path"; then 87132812Stjr lib_path=$file 88132812Stjr else 89206711Sjilles lib_path="$lib_path;$file" 90206711Sjilles fi 91132812Stjr linker_opts="$linker_opts -LIBPATH:$file" 92132812Stjr} 93132812Stjr 9426484Sache# func_cl_dashl library 95132812Stjr# Do a library search-path lookup for cl 96132812Stjrfunc_cl_dashl () 97132812Stjr{ 981573Srgrimes lib=$1 99206711Sjilles found=no 100132812Stjr save_IFS=$IFS 101132812Stjr IFS=';' 102132812Stjr for dir in $lib_path $LIB 103132812Stjr do 104132812Stjr IFS=$save_IFS 105132812Stjr if $shared && test -f "$dir/$lib.dll.lib"; then 106132812Stjr found=yes 107132812Stjr lib=$dir/$lib.dll.lib 108132812Stjr break 109132812Stjr fi 110132812Stjr if test -f "$dir/$lib.lib"; then 1111573Srgrimes found=yes 112132812Stjr lib=$dir/$lib.lib 11319132Sache break 114132812Stjr fi 1151573Srgrimes if test -f "$dir/lib$lib.a"; then 116132812Stjr found=yes 1171573Srgrimes lib=$dir/lib$lib.a 118132812Stjr break 1191573Srgrimes fi 120132812Stjr done 1211573Srgrimes IFS=$save_IFS 1221573Srgrimes 1231573Srgrimes if test "$found" != yes; then 124132812Stjr lib=$lib.lib 1251573Srgrimes fi 1261573Srgrimes} 1271573Srgrimes 1281573Srgrimes# func_cl_wrapper cl arg... 1291573Srgrimes# Adjust compile command to suit cl 1301573Srgrimesfunc_cl_wrapper () 1311573Srgrimes{ 132132812Stjr # Assume a capable shell 1331573Srgrimes lib_path= 1341573Srgrimes shared=: 1351573Srgrimes linker_opts= 1361573Srgrimes for arg 1371573Srgrimes do 1381573Srgrimes if test -n "$eat"; then 1391573Srgrimes eat= 14025269Sjdp else 14125269Sjdp case $1 in 1421573Srgrimes -o) 1431573Srgrimes # configure might choose to run compile as 'compile cc -o foo foo.c'. 1441573Srgrimes eat=1 1451573Srgrimes case $2 in 1461573Srgrimes *.o | *.[oO][bB][jJ]) 1471573Srgrimes func_file_conv "$2" 1481573Srgrimes set x "$@" -Fo"$file" 1491573Srgrimes shift 1501573Srgrimes ;; 1511573Srgrimes *) 152132812Stjr func_file_conv "$2" 153206711Sjilles set x "$@" -Fe"$file" 154206711Sjilles shift 1551573Srgrimes ;; 156132812Stjr esac 157132812Stjr ;; 158132812Stjr -I) 159132812Stjr eat=1 160132812Stjr func_file_conv "$2" mingw 161132812Stjr set x "$@" -I"$file" 162132812Stjr shift 163132812Stjr ;; 164132812Stjr -I*) 1651573Srgrimes func_file_conv "${1#-I}" mingw 166132812Stjr set x "$@" -I"$file" 1671573Srgrimes shift 1681573Srgrimes ;; 1691573Srgrimes -l) 170132812Stjr eat=1 1711573Srgrimes func_cl_dashl "$2" 172132812Stjr set x "$@" "$lib" 1731573Srgrimes shift 174132812Stjr ;; 17526486Sache -l*) 17626486Sache func_cl_dashl "${1#-l}" 17726486Sache set x "$@" "$lib" 17826486Sache shift 179132812Stjr ;; 180132812Stjr -L) 18126484Sache eat=1 18226484Sache func_cl_dashL "$2" 18326484Sache ;; 18426484Sache -L*) 18526484Sache func_cl_dashL "${1#-L}" 18626484Sache ;; 1871573Srgrimes -static) 18826484Sache shared=false 189132812Stjr ;; 1901573Srgrimes -Wl,*) 1911573Srgrimes arg=${1#-Wl,} 1921573Srgrimes save_ifs="$IFS"; IFS=',' 193132812Stjr for flag in $arg; do 194132812Stjr IFS="$save_ifs" 195132812Stjr linker_opts="$linker_opts $flag" 196132812Stjr done 197132812Stjr IFS="$save_ifs" 198132812Stjr ;; 199132812Stjr -Xlinker) 2001573Srgrimes eat=1 2011573Srgrimes linker_opts="$linker_opts $2" 2021573Srgrimes ;; 20326484Sache -*) 204132812Stjr set x "$@" "$1" 20519059Swosch shift 20619132Sache ;; 207132812Stjr *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20819059Swosch func_file_conv "$1" 20919059Swosch set x "$@" -Tp"$file" 2101573Srgrimes shift 211132812Stjr ;; 2121573Srgrimes *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2131573Srgrimes func_file_conv "$1" mingw 214132812Stjr set x "$@" "$file" 2151573Srgrimes shift 2161573Srgrimes ;; 2171573Srgrimes *) 21826484Sache set x "$@" "$1" 219132812Stjr shift 2201573Srgrimes ;; 221132812Stjr esac 22219132Sache fi 22326484Sache shift 224132812Stjr done 2251573Srgrimes if test -n "$linker_opts"; then 22626492Sache linker_opts="-link$linker_opts" 227132812Stjr fi 228132812Stjr exec "$@" $linker_opts 229132812Stjr exit 1 230227753Stheraven} 231227753Stheraven 2321573Srgrimeseat= 2331573Srgrimes 2341573Srgrimescase $1 in 2351573Srgrimes '') 2361573Srgrimes echo "$0: No command. Try '$0 --help' for more information." 1>&2 2371573Srgrimes exit 1; 2381573Srgrimes ;; 2391573Srgrimes -h | --h*) 24026486Sache cat <<\EOF 2411573SrgrimesUsage: compile [--help] [--version] PROGRAM [ARGS] 2428870Srgrimes 24319132SacheWrapper for compilers which do not understand '-c -o'. 244132812StjrRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24519059Swoscharguments, and rename the output as expected. 24626484Sache 24726484SacheIf you are trying to build a whole package this is not the 24826484Sacheright script to run: please start by reading the file 'INSTALL'. 24926484Sache 25026484SacheReport bugs to <bug-automake@gnu.org>. 25126492SacheEOF 252132812Stjr exit $? 253132812Stjr ;; 254132812Stjr -v | --v*) 255132812Stjr echo "compile $scriptversion" 256132812Stjr exit $? 257132812Stjr ;; 25826484Sache cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 259132812Stjr func_cl_wrapper "$@" # Doesn't return... 26026486Sache ;; 261132812Stjresac 262132812Stjr 263132812Stjrofile= 264132812Stjrcfile= 265132812Stjr 266132812Stjrfor arg 26726486Sachedo 26819132Sache if test -n "$eat"; then 269132812Stjr eat= 27019059Swosch else 271132812Stjr case $1 in 272132812Stjr -o) 273132812Stjr # configure might choose to run compile as 'compile cc -o foo foo.c'. 274132812Stjr # So we strip '-o arg' only if arg is an object. 275132812Stjr eat=1 276132812Stjr case $2 in 277132812Stjr *.o | *.obj) 278132812Stjr ofile=$2 279132812Stjr ;; 2801573Srgrimes *) 28126484Sache set x "$@" -o "$2" 28219059Swosch shift 28319132Sache ;; 284132812Stjr esac 28519059Swosch ;; 286227753Stheraven *.c) 28724632Sache cfile=$1 288227753Stheraven set x "$@" "$1" 289227753Stheraven shift 29017533Sache ;; 2911573Srgrimes *) 2921573Srgrimes set x "$@" "$1" 2931573Srgrimes shift 294132812Stjr ;; 29526492Sache esac 29626484Sache fi 29726484Sache shift 2981573Srgrimesdone 299 300if test -z "$ofile" || test -z "$cfile"; then 301 # If no '-o' option was seen then we might have been invoked from a 302 # pattern rule where we don't need one. That is ok -- this is a 303 # normal compilation that the losing compiler can handle. If no 304 # '.c' file was seen then we are probably linking. That is also 305 # ok. 306 exec "$@" 307fi 308 309# Name of file we expect compiler to create. 310cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 311 312# Create the lock directory. 313# Note: use '[/\\:.-]' here to ensure that we don't use the same name 314# that we are using for the .o file. Also, base the name on the expected 315# object file name, since that is what matters with a parallel build. 316lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 317while true; do 318 if mkdir "$lockdir" >/dev/null 2>&1; then 319 break 320 fi 321 sleep 1 322done 323# FIXME: race condition here if user kills between mkdir and trap. 324trap "rmdir '$lockdir'; exit 1" 1 2 15 325 326# Run the compile. 327"$@" 328ret=$? 329 330if test -f "$cofile"; then 331 test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 332elif test -f "${cofile}bj"; then 333 test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 334fi 335 336rmdir "$lockdir" 337exit $ret 338 339# Local Variables: 340# mode: shell-script 341# sh-indentation: 2 342# eval: (add-hook 'write-file-hooks 'time-stamp) 343# time-stamp-start: "scriptversion=" 344# time-stamp-format: "%:y-%02m-%02d.%02H" 345# time-stamp-time-zone: "UTC" 346# time-stamp-end: "; # UTC" 347# End: 348