compile revision 9d0b5e55
19d0b5e55Smrg#! /bin/sh 29d0b5e55Smrg# Wrapper for compilers which do not understand '-c -o'. 39d0b5e55Smrg 49d0b5e55Smrgscriptversion=2012-10-14.11; # UTC 59d0b5e55Smrg 69d0b5e55Smrg# Copyright (C) 1999-2013 Free Software Foundation, Inc. 79d0b5e55Smrg# Written by Tom Tromey <tromey@cygnus.com>. 89d0b5e55Smrg# 99d0b5e55Smrg# This program is free software; you can redistribute it and/or modify 109d0b5e55Smrg# it under the terms of the GNU General Public License as published by 119d0b5e55Smrg# the Free Software Foundation; either version 2, or (at your option) 129d0b5e55Smrg# any later version. 139d0b5e55Smrg# 149d0b5e55Smrg# This program is distributed in the hope that it will be useful, 159d0b5e55Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 169d0b5e55Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 179d0b5e55Smrg# GNU General Public License for more details. 189d0b5e55Smrg# 199d0b5e55Smrg# You should have received a copy of the GNU General Public License 209d0b5e55Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 219d0b5e55Smrg 229d0b5e55Smrg# As a special exception to the GNU General Public License, if you 239d0b5e55Smrg# distribute this file as part of a program that contains a 249d0b5e55Smrg# configuration script generated by Autoconf, you may include it under 259d0b5e55Smrg# the same distribution terms that you use for the rest of that program. 269d0b5e55Smrg 279d0b5e55Smrg# This file is maintained in Automake, please report 289d0b5e55Smrg# bugs to <bug-automake@gnu.org> or send patches to 299d0b5e55Smrg# <automake-patches@gnu.org>. 309d0b5e55Smrg 319d0b5e55Smrgnl=' 329d0b5e55Smrg' 339d0b5e55Smrg 349d0b5e55Smrg# We need space, tab and new line, in precisely that order. Quoting is 359d0b5e55Smrg# there to prevent tools from complaining about whitespace usage. 369d0b5e55SmrgIFS=" "" $nl" 379d0b5e55Smrg 389d0b5e55Smrgfile_conv= 399d0b5e55Smrg 409d0b5e55Smrg# func_file_conv build_file lazy 419d0b5e55Smrg# Convert a $build file to $host form and store it in $file 429d0b5e55Smrg# Currently only supports Windows hosts. If the determined conversion 439d0b5e55Smrg# type is listed in (the comma separated) LAZY, no conversion will 449d0b5e55Smrg# take place. 459d0b5e55Smrgfunc_file_conv () 469d0b5e55Smrg{ 479d0b5e55Smrg file=$1 489d0b5e55Smrg case $file in 499d0b5e55Smrg / | /[!/]*) # absolute file, and not a UNC file 509d0b5e55Smrg if test -z "$file_conv"; then 519d0b5e55Smrg # lazily determine how to convert abs files 529d0b5e55Smrg case `uname -s` in 539d0b5e55Smrg MINGW*) 549d0b5e55Smrg file_conv=mingw 559d0b5e55Smrg ;; 569d0b5e55Smrg CYGWIN*) 579d0b5e55Smrg file_conv=cygwin 589d0b5e55Smrg ;; 599d0b5e55Smrg *) 609d0b5e55Smrg file_conv=wine 619d0b5e55Smrg ;; 629d0b5e55Smrg esac 639d0b5e55Smrg fi 649d0b5e55Smrg case $file_conv/,$2, in 659d0b5e55Smrg *,$file_conv,*) 669d0b5e55Smrg ;; 679d0b5e55Smrg mingw/*) 689d0b5e55Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 699d0b5e55Smrg ;; 709d0b5e55Smrg cygwin/*) 719d0b5e55Smrg file=`cygpath -m "$file" || echo "$file"` 729d0b5e55Smrg ;; 739d0b5e55Smrg wine/*) 749d0b5e55Smrg file=`winepath -w "$file" || echo "$file"` 759d0b5e55Smrg ;; 769d0b5e55Smrg esac 779d0b5e55Smrg ;; 789d0b5e55Smrg esac 799d0b5e55Smrg} 809d0b5e55Smrg 819d0b5e55Smrg# func_cl_dashL linkdir 829d0b5e55Smrg# Make cl look for libraries in LINKDIR 839d0b5e55Smrgfunc_cl_dashL () 849d0b5e55Smrg{ 859d0b5e55Smrg func_file_conv "$1" 869d0b5e55Smrg if test -z "$lib_path"; then 879d0b5e55Smrg lib_path=$file 889d0b5e55Smrg else 899d0b5e55Smrg lib_path="$lib_path;$file" 909d0b5e55Smrg fi 919d0b5e55Smrg linker_opts="$linker_opts -LIBPATH:$file" 929d0b5e55Smrg} 939d0b5e55Smrg 949d0b5e55Smrg# func_cl_dashl library 959d0b5e55Smrg# Do a library search-path lookup for cl 969d0b5e55Smrgfunc_cl_dashl () 979d0b5e55Smrg{ 989d0b5e55Smrg lib=$1 999d0b5e55Smrg found=no 1009d0b5e55Smrg save_IFS=$IFS 1019d0b5e55Smrg IFS=';' 1029d0b5e55Smrg for dir in $lib_path $LIB 1039d0b5e55Smrg do 1049d0b5e55Smrg IFS=$save_IFS 1059d0b5e55Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 1069d0b5e55Smrg found=yes 1079d0b5e55Smrg lib=$dir/$lib.dll.lib 1089d0b5e55Smrg break 1099d0b5e55Smrg fi 1109d0b5e55Smrg if test -f "$dir/$lib.lib"; then 1119d0b5e55Smrg found=yes 1129d0b5e55Smrg lib=$dir/$lib.lib 1139d0b5e55Smrg break 1149d0b5e55Smrg fi 1159d0b5e55Smrg if test -f "$dir/lib$lib.a"; then 1169d0b5e55Smrg found=yes 1179d0b5e55Smrg lib=$dir/lib$lib.a 1189d0b5e55Smrg break 1199d0b5e55Smrg fi 1209d0b5e55Smrg done 1219d0b5e55Smrg IFS=$save_IFS 1229d0b5e55Smrg 1239d0b5e55Smrg if test "$found" != yes; then 1249d0b5e55Smrg lib=$lib.lib 1259d0b5e55Smrg fi 1269d0b5e55Smrg} 1279d0b5e55Smrg 1289d0b5e55Smrg# func_cl_wrapper cl arg... 1299d0b5e55Smrg# Adjust compile command to suit cl 1309d0b5e55Smrgfunc_cl_wrapper () 1319d0b5e55Smrg{ 1329d0b5e55Smrg # Assume a capable shell 1339d0b5e55Smrg lib_path= 1349d0b5e55Smrg shared=: 1359d0b5e55Smrg linker_opts= 1369d0b5e55Smrg for arg 1379d0b5e55Smrg do 1389d0b5e55Smrg if test -n "$eat"; then 1399d0b5e55Smrg eat= 1409d0b5e55Smrg else 1419d0b5e55Smrg case $1 in 1429d0b5e55Smrg -o) 1439d0b5e55Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 1449d0b5e55Smrg eat=1 1459d0b5e55Smrg case $2 in 1469d0b5e55Smrg *.o | *.[oO][bB][jJ]) 1479d0b5e55Smrg func_file_conv "$2" 1489d0b5e55Smrg set x "$@" -Fo"$file" 1499d0b5e55Smrg shift 1509d0b5e55Smrg ;; 1519d0b5e55Smrg *) 1529d0b5e55Smrg func_file_conv "$2" 1539d0b5e55Smrg set x "$@" -Fe"$file" 1549d0b5e55Smrg shift 1559d0b5e55Smrg ;; 1569d0b5e55Smrg esac 1579d0b5e55Smrg ;; 1589d0b5e55Smrg -I) 1599d0b5e55Smrg eat=1 1609d0b5e55Smrg func_file_conv "$2" mingw 1619d0b5e55Smrg set x "$@" -I"$file" 1629d0b5e55Smrg shift 1639d0b5e55Smrg ;; 1649d0b5e55Smrg -I*) 1659d0b5e55Smrg func_file_conv "${1#-I}" mingw 1669d0b5e55Smrg set x "$@" -I"$file" 1679d0b5e55Smrg shift 1689d0b5e55Smrg ;; 1699d0b5e55Smrg -l) 1709d0b5e55Smrg eat=1 1719d0b5e55Smrg func_cl_dashl "$2" 1729d0b5e55Smrg set x "$@" "$lib" 1739d0b5e55Smrg shift 1749d0b5e55Smrg ;; 1759d0b5e55Smrg -l*) 1769d0b5e55Smrg func_cl_dashl "${1#-l}" 1779d0b5e55Smrg set x "$@" "$lib" 1789d0b5e55Smrg shift 1799d0b5e55Smrg ;; 1809d0b5e55Smrg -L) 1819d0b5e55Smrg eat=1 1829d0b5e55Smrg func_cl_dashL "$2" 1839d0b5e55Smrg ;; 1849d0b5e55Smrg -L*) 1859d0b5e55Smrg func_cl_dashL "${1#-L}" 1869d0b5e55Smrg ;; 1879d0b5e55Smrg -static) 1889d0b5e55Smrg shared=false 1899d0b5e55Smrg ;; 1909d0b5e55Smrg -Wl,*) 1919d0b5e55Smrg arg=${1#-Wl,} 1929d0b5e55Smrg save_ifs="$IFS"; IFS=',' 1939d0b5e55Smrg for flag in $arg; do 1949d0b5e55Smrg IFS="$save_ifs" 1959d0b5e55Smrg linker_opts="$linker_opts $flag" 1969d0b5e55Smrg done 1979d0b5e55Smrg IFS="$save_ifs" 1989d0b5e55Smrg ;; 1999d0b5e55Smrg -Xlinker) 2009d0b5e55Smrg eat=1 2019d0b5e55Smrg linker_opts="$linker_opts $2" 2029d0b5e55Smrg ;; 2039d0b5e55Smrg -*) 2049d0b5e55Smrg set x "$@" "$1" 2059d0b5e55Smrg shift 2069d0b5e55Smrg ;; 2079d0b5e55Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 2089d0b5e55Smrg func_file_conv "$1" 2099d0b5e55Smrg set x "$@" -Tp"$file" 2109d0b5e55Smrg shift 2119d0b5e55Smrg ;; 2129d0b5e55Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2139d0b5e55Smrg func_file_conv "$1" mingw 2149d0b5e55Smrg set x "$@" "$file" 2159d0b5e55Smrg shift 2169d0b5e55Smrg ;; 2179d0b5e55Smrg *) 2189d0b5e55Smrg set x "$@" "$1" 2199d0b5e55Smrg shift 2209d0b5e55Smrg ;; 2219d0b5e55Smrg esac 2229d0b5e55Smrg fi 2239d0b5e55Smrg shift 2249d0b5e55Smrg done 2259d0b5e55Smrg if test -n "$linker_opts"; then 2269d0b5e55Smrg linker_opts="-link$linker_opts" 2279d0b5e55Smrg fi 2289d0b5e55Smrg exec "$@" $linker_opts 2299d0b5e55Smrg exit 1 2309d0b5e55Smrg} 2319d0b5e55Smrg 2329d0b5e55Smrgeat= 2339d0b5e55Smrg 2349d0b5e55Smrgcase $1 in 2359d0b5e55Smrg '') 2369d0b5e55Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 2379d0b5e55Smrg exit 1; 2389d0b5e55Smrg ;; 2399d0b5e55Smrg -h | --h*) 2409d0b5e55Smrg cat <<\EOF 2419d0b5e55SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 2429d0b5e55Smrg 2439d0b5e55SmrgWrapper for compilers which do not understand '-c -o'. 2449d0b5e55SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 2459d0b5e55Smrgarguments, and rename the output as expected. 2469d0b5e55Smrg 2479d0b5e55SmrgIf you are trying to build a whole package this is not the 2489d0b5e55Smrgright script to run: please start by reading the file 'INSTALL'. 2499d0b5e55Smrg 2509d0b5e55SmrgReport bugs to <bug-automake@gnu.org>. 2519d0b5e55SmrgEOF 2529d0b5e55Smrg exit $? 2539d0b5e55Smrg ;; 2549d0b5e55Smrg -v | --v*) 2559d0b5e55Smrg echo "compile $scriptversion" 2569d0b5e55Smrg exit $? 2579d0b5e55Smrg ;; 2589d0b5e55Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 2599d0b5e55Smrg func_cl_wrapper "$@" # Doesn't return... 2609d0b5e55Smrg ;; 2619d0b5e55Smrgesac 2629d0b5e55Smrg 2639d0b5e55Smrgofile= 2649d0b5e55Smrgcfile= 2659d0b5e55Smrg 2669d0b5e55Smrgfor arg 2679d0b5e55Smrgdo 2689d0b5e55Smrg if test -n "$eat"; then 2699d0b5e55Smrg eat= 2709d0b5e55Smrg else 2719d0b5e55Smrg case $1 in 2729d0b5e55Smrg -o) 2739d0b5e55Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 2749d0b5e55Smrg # So we strip '-o arg' only if arg is an object. 2759d0b5e55Smrg eat=1 2769d0b5e55Smrg case $2 in 2779d0b5e55Smrg *.o | *.obj) 2789d0b5e55Smrg ofile=$2 2799d0b5e55Smrg ;; 2809d0b5e55Smrg *) 2819d0b5e55Smrg set x "$@" -o "$2" 2829d0b5e55Smrg shift 2839d0b5e55Smrg ;; 2849d0b5e55Smrg esac 2859d0b5e55Smrg ;; 2869d0b5e55Smrg *.c) 2879d0b5e55Smrg cfile=$1 2889d0b5e55Smrg set x "$@" "$1" 2899d0b5e55Smrg shift 2909d0b5e55Smrg ;; 2919d0b5e55Smrg *) 2929d0b5e55Smrg set x "$@" "$1" 2939d0b5e55Smrg shift 2949d0b5e55Smrg ;; 2959d0b5e55Smrg esac 2969d0b5e55Smrg fi 2979d0b5e55Smrg shift 2989d0b5e55Smrgdone 2999d0b5e55Smrg 3009d0b5e55Smrgif test -z "$ofile" || test -z "$cfile"; then 3019d0b5e55Smrg # If no '-o' option was seen then we might have been invoked from a 3029d0b5e55Smrg # pattern rule where we don't need one. That is ok -- this is a 3039d0b5e55Smrg # normal compilation that the losing compiler can handle. If no 3049d0b5e55Smrg # '.c' file was seen then we are probably linking. That is also 3059d0b5e55Smrg # ok. 3069d0b5e55Smrg exec "$@" 3079d0b5e55Smrgfi 3089d0b5e55Smrg 3099d0b5e55Smrg# Name of file we expect compiler to create. 3109d0b5e55Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 3119d0b5e55Smrg 3129d0b5e55Smrg# Create the lock directory. 3139d0b5e55Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 3149d0b5e55Smrg# that we are using for the .o file. Also, base the name on the expected 3159d0b5e55Smrg# object file name, since that is what matters with a parallel build. 3169d0b5e55Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 3179d0b5e55Smrgwhile true; do 3189d0b5e55Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 3199d0b5e55Smrg break 3209d0b5e55Smrg fi 3219d0b5e55Smrg sleep 1 3229d0b5e55Smrgdone 3239d0b5e55Smrg# FIXME: race condition here if user kills between mkdir and trap. 3249d0b5e55Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 3259d0b5e55Smrg 3269d0b5e55Smrg# Run the compile. 3279d0b5e55Smrg"$@" 3289d0b5e55Smrgret=$? 3299d0b5e55Smrg 3309d0b5e55Smrgif test -f "$cofile"; then 3319d0b5e55Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 3329d0b5e55Smrgelif test -f "${cofile}bj"; then 3339d0b5e55Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 3349d0b5e55Smrgfi 3359d0b5e55Smrg 3369d0b5e55Smrgrmdir "$lockdir" 3379d0b5e55Smrgexit $ret 3389d0b5e55Smrg 3399d0b5e55Smrg# Local Variables: 3409d0b5e55Smrg# mode: shell-script 3419d0b5e55Smrg# sh-indentation: 2 3429d0b5e55Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 3439d0b5e55Smrg# time-stamp-start: "scriptversion=" 3449d0b5e55Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 3459d0b5e55Smrg# time-stamp-time-zone: "UTC" 3469d0b5e55Smrg# time-stamp-end: "; # UTC" 3479d0b5e55Smrg# End: 348