compile revision 5748e6ec
15788ca14Smrg#! /bin/sh 25788ca14Smrg# Wrapper for compilers which do not understand '-c -o'. 35788ca14Smrg 45748e6ecSmrgscriptversion=2012-10-14.11; # UTC 55788ca14Smrg 65748e6ecSmrg# Copyright (C) 1999-2014 Free Software Foundation, Inc. 75788ca14Smrg# Written by Tom Tromey <tromey@cygnus.com>. 85788ca14Smrg# 95788ca14Smrg# This program is free software; you can redistribute it and/or modify 105788ca14Smrg# it under the terms of the GNU General Public License as published by 115788ca14Smrg# the Free Software Foundation; either version 2, or (at your option) 125788ca14Smrg# any later version. 135788ca14Smrg# 145788ca14Smrg# This program is distributed in the hope that it will be useful, 155788ca14Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 165788ca14Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 175788ca14Smrg# GNU General Public License for more details. 185788ca14Smrg# 195788ca14Smrg# You should have received a copy of the GNU General Public License 205788ca14Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 215788ca14Smrg 225788ca14Smrg# As a special exception to the GNU General Public License, if you 235788ca14Smrg# distribute this file as part of a program that contains a 245788ca14Smrg# configuration script generated by Autoconf, you may include it under 255788ca14Smrg# the same distribution terms that you use for the rest of that program. 265788ca14Smrg 275788ca14Smrg# This file is maintained in Automake, please report 285788ca14Smrg# bugs to <bug-automake@gnu.org> or send patches to 295788ca14Smrg# <automake-patches@gnu.org>. 305788ca14Smrg 315788ca14Smrgnl=' 325788ca14Smrg' 335788ca14Smrg 345788ca14Smrg# We need space, tab and new line, in precisely that order. Quoting is 355788ca14Smrg# there to prevent tools from complaining about whitespace usage. 365788ca14SmrgIFS=" "" $nl" 375788ca14Smrg 385788ca14Smrgfile_conv= 395788ca14Smrg 405788ca14Smrg# func_file_conv build_file lazy 415788ca14Smrg# Convert a $build file to $host form and store it in $file 425788ca14Smrg# Currently only supports Windows hosts. If the determined conversion 435788ca14Smrg# type is listed in (the comma separated) LAZY, no conversion will 445788ca14Smrg# take place. 455788ca14Smrgfunc_file_conv () 465788ca14Smrg{ 475788ca14Smrg file=$1 485788ca14Smrg case $file in 495788ca14Smrg / | /[!/]*) # absolute file, and not a UNC file 505788ca14Smrg if test -z "$file_conv"; then 515788ca14Smrg # lazily determine how to convert abs files 525788ca14Smrg case `uname -s` in 535788ca14Smrg MINGW*) 545788ca14Smrg file_conv=mingw 555788ca14Smrg ;; 565788ca14Smrg CYGWIN*) 575788ca14Smrg file_conv=cygwin 585788ca14Smrg ;; 595788ca14Smrg *) 605788ca14Smrg file_conv=wine 615788ca14Smrg ;; 625788ca14Smrg esac 635788ca14Smrg fi 645788ca14Smrg case $file_conv/,$2, in 655788ca14Smrg *,$file_conv,*) 665788ca14Smrg ;; 675788ca14Smrg mingw/*) 685788ca14Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 695788ca14Smrg ;; 705788ca14Smrg cygwin/*) 715788ca14Smrg file=`cygpath -m "$file" || echo "$file"` 725788ca14Smrg ;; 735788ca14Smrg wine/*) 745788ca14Smrg file=`winepath -w "$file" || echo "$file"` 755788ca14Smrg ;; 765788ca14Smrg esac 775788ca14Smrg ;; 785788ca14Smrg esac 795788ca14Smrg} 805788ca14Smrg 815748e6ecSmrg# func_cl_dashL linkdir 825748e6ecSmrg# Make cl look for libraries in LINKDIR 835748e6ecSmrgfunc_cl_dashL () 845748e6ecSmrg{ 855748e6ecSmrg func_file_conv "$1" 865748e6ecSmrg if test -z "$lib_path"; then 875748e6ecSmrg lib_path=$file 885748e6ecSmrg else 895748e6ecSmrg lib_path="$lib_path;$file" 905748e6ecSmrg fi 915748e6ecSmrg linker_opts="$linker_opts -LIBPATH:$file" 925748e6ecSmrg} 935748e6ecSmrg 945748e6ecSmrg# func_cl_dashl library 955748e6ecSmrg# Do a library search-path lookup for cl 965748e6ecSmrgfunc_cl_dashl () 975748e6ecSmrg{ 985748e6ecSmrg lib=$1 995748e6ecSmrg found=no 1005748e6ecSmrg save_IFS=$IFS 1015748e6ecSmrg IFS=';' 1025748e6ecSmrg for dir in $lib_path $LIB 1035748e6ecSmrg do 1045748e6ecSmrg IFS=$save_IFS 1055748e6ecSmrg if $shared && test -f "$dir/$lib.dll.lib"; then 1065748e6ecSmrg found=yes 1075748e6ecSmrg lib=$dir/$lib.dll.lib 1085748e6ecSmrg break 1095748e6ecSmrg fi 1105748e6ecSmrg if test -f "$dir/$lib.lib"; then 1115748e6ecSmrg found=yes 1125748e6ecSmrg lib=$dir/$lib.lib 1135748e6ecSmrg break 1145748e6ecSmrg fi 1155748e6ecSmrg if test -f "$dir/lib$lib.a"; then 1165748e6ecSmrg found=yes 1175748e6ecSmrg lib=$dir/lib$lib.a 1185748e6ecSmrg break 1195748e6ecSmrg fi 1205748e6ecSmrg done 1215748e6ecSmrg IFS=$save_IFS 1225748e6ecSmrg 1235748e6ecSmrg if test "$found" != yes; then 1245748e6ecSmrg lib=$lib.lib 1255748e6ecSmrg fi 1265748e6ecSmrg} 1275748e6ecSmrg 1285788ca14Smrg# func_cl_wrapper cl arg... 1295788ca14Smrg# Adjust compile command to suit cl 1305788ca14Smrgfunc_cl_wrapper () 1315788ca14Smrg{ 1325788ca14Smrg # Assume a capable shell 1335788ca14Smrg lib_path= 1345788ca14Smrg shared=: 1355788ca14Smrg linker_opts= 1365788ca14Smrg for arg 1375788ca14Smrg do 1385788ca14Smrg if test -n "$eat"; then 1395788ca14Smrg eat= 1405788ca14Smrg else 1415788ca14Smrg case $1 in 1425788ca14Smrg -o) 1435788ca14Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 1445788ca14Smrg eat=1 1455788ca14Smrg case $2 in 1465788ca14Smrg *.o | *.[oO][bB][jJ]) 1475788ca14Smrg func_file_conv "$2" 1485788ca14Smrg set x "$@" -Fo"$file" 1495788ca14Smrg shift 1505788ca14Smrg ;; 1515788ca14Smrg *) 1525788ca14Smrg func_file_conv "$2" 1535788ca14Smrg set x "$@" -Fe"$file" 1545788ca14Smrg shift 1555788ca14Smrg ;; 1565788ca14Smrg esac 1575788ca14Smrg ;; 1585748e6ecSmrg -I) 1595748e6ecSmrg eat=1 1605748e6ecSmrg func_file_conv "$2" mingw 1615748e6ecSmrg set x "$@" -I"$file" 1625748e6ecSmrg shift 1635748e6ecSmrg ;; 1645788ca14Smrg -I*) 1655788ca14Smrg func_file_conv "${1#-I}" mingw 1665788ca14Smrg set x "$@" -I"$file" 1675788ca14Smrg shift 1685788ca14Smrg ;; 1695748e6ecSmrg -l) 1705748e6ecSmrg eat=1 1715748e6ecSmrg func_cl_dashl "$2" 1725748e6ecSmrg set x "$@" "$lib" 1735748e6ecSmrg shift 1745748e6ecSmrg ;; 1755788ca14Smrg -l*) 1765748e6ecSmrg func_cl_dashl "${1#-l}" 1775748e6ecSmrg set x "$@" "$lib" 1785788ca14Smrg shift 1795788ca14Smrg ;; 1805748e6ecSmrg -L) 1815748e6ecSmrg eat=1 1825748e6ecSmrg func_cl_dashL "$2" 1835748e6ecSmrg ;; 1845788ca14Smrg -L*) 1855748e6ecSmrg func_cl_dashL "${1#-L}" 1865788ca14Smrg ;; 1875788ca14Smrg -static) 1885788ca14Smrg shared=false 1895788ca14Smrg ;; 1905788ca14Smrg -Wl,*) 1915788ca14Smrg arg=${1#-Wl,} 1925788ca14Smrg save_ifs="$IFS"; IFS=',' 1935788ca14Smrg for flag in $arg; do 1945788ca14Smrg IFS="$save_ifs" 1955788ca14Smrg linker_opts="$linker_opts $flag" 1965788ca14Smrg done 1975788ca14Smrg IFS="$save_ifs" 1985788ca14Smrg ;; 1995788ca14Smrg -Xlinker) 2005788ca14Smrg eat=1 2015788ca14Smrg linker_opts="$linker_opts $2" 2025788ca14Smrg ;; 2035788ca14Smrg -*) 2045788ca14Smrg set x "$@" "$1" 2055788ca14Smrg shift 2065788ca14Smrg ;; 2075788ca14Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 2085788ca14Smrg func_file_conv "$1" 2095788ca14Smrg set x "$@" -Tp"$file" 2105788ca14Smrg shift 2115788ca14Smrg ;; 2125788ca14Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2135788ca14Smrg func_file_conv "$1" mingw 2145788ca14Smrg set x "$@" "$file" 2155788ca14Smrg shift 2165788ca14Smrg ;; 2175788ca14Smrg *) 2185788ca14Smrg set x "$@" "$1" 2195788ca14Smrg shift 2205788ca14Smrg ;; 2215788ca14Smrg esac 2225788ca14Smrg fi 2235788ca14Smrg shift 2245788ca14Smrg done 2255788ca14Smrg if test -n "$linker_opts"; then 2265788ca14Smrg linker_opts="-link$linker_opts" 2275788ca14Smrg fi 2285788ca14Smrg exec "$@" $linker_opts 2295788ca14Smrg exit 1 2305788ca14Smrg} 2315788ca14Smrg 2325788ca14Smrgeat= 2335788ca14Smrg 2345788ca14Smrgcase $1 in 2355788ca14Smrg '') 2365788ca14Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 2375788ca14Smrg exit 1; 2385788ca14Smrg ;; 2395788ca14Smrg -h | --h*) 2405788ca14Smrg cat <<\EOF 2415788ca14SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 2425788ca14Smrg 2435788ca14SmrgWrapper for compilers which do not understand '-c -o'. 2445788ca14SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 2455788ca14Smrgarguments, and rename the output as expected. 2465788ca14Smrg 2475788ca14SmrgIf you are trying to build a whole package this is not the 2485788ca14Smrgright script to run: please start by reading the file 'INSTALL'. 2495788ca14Smrg 2505788ca14SmrgReport bugs to <bug-automake@gnu.org>. 2515788ca14SmrgEOF 2525788ca14Smrg exit $? 2535788ca14Smrg ;; 2545788ca14Smrg -v | --v*) 2555788ca14Smrg echo "compile $scriptversion" 2565788ca14Smrg exit $? 2575788ca14Smrg ;; 2585788ca14Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 2595788ca14Smrg func_cl_wrapper "$@" # Doesn't return... 2605788ca14Smrg ;; 2615788ca14Smrgesac 2625788ca14Smrg 2635788ca14Smrgofile= 2645788ca14Smrgcfile= 2655788ca14Smrg 2665788ca14Smrgfor arg 2675788ca14Smrgdo 2685788ca14Smrg if test -n "$eat"; then 2695788ca14Smrg eat= 2705788ca14Smrg else 2715788ca14Smrg case $1 in 2725788ca14Smrg -o) 2735788ca14Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 2745788ca14Smrg # So we strip '-o arg' only if arg is an object. 2755788ca14Smrg eat=1 2765788ca14Smrg case $2 in 2775788ca14Smrg *.o | *.obj) 2785788ca14Smrg ofile=$2 2795788ca14Smrg ;; 2805788ca14Smrg *) 2815788ca14Smrg set x "$@" -o "$2" 2825788ca14Smrg shift 2835788ca14Smrg ;; 2845788ca14Smrg esac 2855788ca14Smrg ;; 2865788ca14Smrg *.c) 2875788ca14Smrg cfile=$1 2885788ca14Smrg set x "$@" "$1" 2895788ca14Smrg shift 2905788ca14Smrg ;; 2915788ca14Smrg *) 2925788ca14Smrg set x "$@" "$1" 2935788ca14Smrg shift 2945788ca14Smrg ;; 2955788ca14Smrg esac 2965788ca14Smrg fi 2975788ca14Smrg shift 2985788ca14Smrgdone 2995788ca14Smrg 3005788ca14Smrgif test -z "$ofile" || test -z "$cfile"; then 3015788ca14Smrg # If no '-o' option was seen then we might have been invoked from a 3025788ca14Smrg # pattern rule where we don't need one. That is ok -- this is a 3035788ca14Smrg # normal compilation that the losing compiler can handle. If no 3045788ca14Smrg # '.c' file was seen then we are probably linking. That is also 3055788ca14Smrg # ok. 3065788ca14Smrg exec "$@" 3075788ca14Smrgfi 3085788ca14Smrg 3095788ca14Smrg# Name of file we expect compiler to create. 3105788ca14Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 3115788ca14Smrg 3125788ca14Smrg# Create the lock directory. 3135788ca14Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 3145788ca14Smrg# that we are using for the .o file. Also, base the name on the expected 3155788ca14Smrg# object file name, since that is what matters with a parallel build. 3165788ca14Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 3175788ca14Smrgwhile true; do 3185788ca14Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 3195788ca14Smrg break 3205788ca14Smrg fi 3215788ca14Smrg sleep 1 3225788ca14Smrgdone 3235788ca14Smrg# FIXME: race condition here if user kills between mkdir and trap. 3245788ca14Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 3255788ca14Smrg 3265788ca14Smrg# Run the compile. 3275788ca14Smrg"$@" 3285788ca14Smrgret=$? 3295788ca14Smrg 3305788ca14Smrgif test -f "$cofile"; then 3315788ca14Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 3325788ca14Smrgelif test -f "${cofile}bj"; then 3335788ca14Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 3345788ca14Smrgfi 3355788ca14Smrg 3365788ca14Smrgrmdir "$lockdir" 3375788ca14Smrgexit $ret 3385788ca14Smrg 3395788ca14Smrg# Local Variables: 3405788ca14Smrg# mode: shell-script 3415788ca14Smrg# sh-indentation: 2 3425788ca14Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 3435788ca14Smrg# time-stamp-start: "scriptversion=" 3445788ca14Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 3455788ca14Smrg# time-stamp-time-zone: "UTC" 3465788ca14Smrg# time-stamp-end: "; # UTC" 3475788ca14Smrg# End: 348