compile revision 93d9adc1
11.242Ssimonb#! /bin/sh 21.92Smikel# Wrapper for compilers which do not understand '-c -o'. 31.1Scgd 41.188Stvscriptversion=2012-10-14.11; # UTC 51.207Sthorpej 61.219Sthorpej# Copyright (C) 1999-2014 Free Software Foundation, Inc. 71.227Slukem# Written by Tom Tromey <tromey@cygnus.com>. 81.227Slukem# 91.97Smycroft# This program is free software; you can redistribute it and/or modify 101.188Stv# it under the terms of the GNU General Public License as published by 111.143Serh# the Free Software Foundation; either version 2, or (at your option) 121.143Serh# any later version. 131.183Stv# 141.232Serh# This program is distributed in the hope that it will be useful, 151.232Serh# but WITHOUT ANY WARRANTY; without even the implied warranty of 161.232Serh# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 171.232Serh# GNU General Public License for more details. 181.232Serh# 191.232Serh# You should have received a copy of the GNU General Public License 201.233Serh# along with this program. If not, see <http://www.gnu.org/licenses/>. 211.233Serh 221.1Scgd# As a special exception to the GNU General Public License, if you 231.188Stv# distribute this file as part of a program that contains a 241.240Sdsl# configuration script generated by Autoconf, you may include it under 251.192Sthorpej# the same distribution terms that you use for the rest of that program. 261.225Smrg 271.190Stv# This file is maintained in Automake, please report 281.184Stv# bugs to <bug-automake@gnu.org> or send patches to 291.154Ssimonb# <automake-patches@gnu.org>. 301.154Ssimonb 311.171Schristosnl=' 321.143Serh' 331.143Serh 341.145Serh# We need space, tab and new line, in precisely that order. Quoting is 351.201Slukem# there to prevent tools from complaining about whitespace usage. 361.143SerhIFS=" "" $nl" 371.144Serh 381.239Slukemfile_conv= 391.195Slukem 401.173Schristos# func_file_conv build_file lazy 411.173Schristos# Convert a $build file to $host form and store it in $file 421.173Schristos# Currently only supports Windows hosts. If the determined conversion 431.173Schristos# type is listed in (the comma separated) LAZY, no conversion will 441.143Serh# take place. 451.143Serhfunc_file_conv () 461.173Schristos{ 471.169Sthorpej file=$1 481.185Stv case $file in 491.169Sthorpej / | /[!/]*) # absolute file, and not a UNC file 501.173Schristos if test -z "$file_conv"; then 511.173Schristos # lazily determine how to convert abs files 521.173Schristos case `uname -s` in 531.169Sthorpej MINGW*) 541.169Sthorpej file_conv=mingw 551.185Stv ;; 561.169Sthorpej CYGWIN*) 571.173Schristos file_conv=cygwin 581.173Schristos ;; 591.173Schristos *) 601.171Schristos file_conv=wine 611.171Schristos ;; 621.185Stv esac 631.171Schristos fi 641.143Serh case $file_conv/,$2, in 651.169Sthorpej *,$file_conv,*) 661.173Schristos ;; 671.169Sthorpej mingw/*) 681.173Schristos file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 691.173Schristos ;; 701.173Schristos cygwin/*) 711.173Schristos file=`cygpath -m "$file" || echo "$file"` 721.173Schristos ;; 731.173Schristos wine/*) 741.173Schristos file=`winepath -w "$file" || echo "$file"` 751.173Schristos ;; 761.173Schristos esac 771.173Schristos ;; 781.35Spk esac 791.1Scgd} 801.101Smycroft 811.101Smycroft# func_cl_dashL linkdir 821.101Smycroft# Make cl look for libraries in LINKDIR 831.223Slukemfunc_cl_dashL () 841.118Slukem{ 851.82Smikel func_file_conv "$1" 861.86Sjonathan if test -z "$lib_path"; then 871.86Sjonathan lib_path=$file 881.86Sjonathan else 891.86Sjonathan lib_path="$lib_path;$file" 901.164Ssimonb fi 911.86Sjonathan linker_opts="$linker_opts -LIBPATH:$file" 921.125Sjonathan} 931.164Ssimonb 941.164Ssimonb# func_cl_dashl library 951.173Schristos# Do a library search-path lookup for cl 961.173Schristosfunc_cl_dashl () 971.164Ssimonb{ 981.123Sjonathan lib=$1 991.123Sjonathan found=no 1001.123Sjonathan save_IFS=$IFS 1011.179Sdmcmahil IFS=';' 1021.164Ssimonb for dir in $lib_path $LIB 1031.205Syamt do 1041.205Syamt IFS=$save_IFS 1051.205Syamt if $shared && test -f "$dir/$lib.dll.lib"; then 1061.205Syamt found=yes 1071.107Sjonathan lib=$dir/$lib.dll.lib 1081.164Ssimonb break 1091.86Sjonathan fi 1101.148Slukem if test -f "$dir/$lib.lib"; then 1111.209Sthorpej found=yes 1121.179Sdmcmahil lib=$dir/$lib.lib 1131.165Sdmcmahil break 1141.222Slukem fi 1151.107Sjonathan if test -f "$dir/lib$lib.a"; then 1161.107Sjonathan found=yes 1171.209Sthorpej lib=$dir/lib$lib.a 1181.175Smrg break 1191.175Smrg fi 1201.209Sthorpej done 1211.222Slukem IFS=$save_IFS 1221.202Seeh 1231.179Sdmcmahil if test "$found" != yes; then 1241.165Sdmcmahil lib=$lib.lib 1251.202Seeh fi 1261.150Schristos} 1271.203Seeh 1281.204Sfredette# func_cl_wrapper cl arg... 1291.204Sfredette# Adjust compile command to suit cl 1301.204Sfredettefunc_cl_wrapper () 1311.204Sfredette{ 1321.204Sfredette # Assume a capable shell 1331.222Slukem lib_path= 1341.204Sfredette shared=: 1351.204Sfredette linker_opts= 1361.204Sfredette for arg 1371.204Sfredette do 1381.241Smatt if test -n "$eat"; then 1391.242Ssimonb eat= 1401.242Ssimonb else 1411.242Ssimonb case $1 in 1421.242Ssimonb -o) 1431.242Ssimonb # configure might choose to run compile as 'compile cc -o foo foo.c'. 1441.242Ssimonb eat=1 1451.242Ssimonb case $2 in 1461.242Ssimonb *.o | *.[oO][bB][jJ]) 1471.242Ssimonb func_file_conv "$2" 1481.86Sjonathan set x "$@" -Fo"$file" 1491.86Sjonathan shift 1501.86Sjonathan ;; 1511.187Snathanw *) 1521.171Schristos func_file_conv "$2" 1531.125Sjonathan set x "$@" -Fe"$file" 1541.179Sdmcmahil shift 1551.165Sdmcmahil ;; 1561.222Slukem esac 1571.107Sjonathan ;; 1581.107Sjonathan -I) 1591.86Sjonathan eat=1 1601.86Sjonathan func_file_conv "$2" mingw 1611.160Ssimonb set x "$@" -I"$file" 1621.205Syamt shift 1631.205Syamt ;; 1641.205Syamt -I*) 1651.205Syamt func_file_conv "${1#-I}" mingw 1661.205Syamt set x "$@" -I"$file" 1671.205Syamt shift 1681.205Syamt ;; 1691.205Syamt -l) 1701.205Syamt eat=1 1711.205Syamt func_cl_dashl "$2" 1721.123Sjonathan set x "$@" "$lib" 1731.148Slukem shift 1741.182Smrg ;; 1751.221Sdrochner -l*) 1761.219Sthorpej func_cl_dashl "${1#-l}" 1771.219Sthorpej set x "$@" "$lib" 1781.123Sjonathan shift 1791.86Sjonathan ;; 1801.82Smikel -L) 1811.179Sdmcmahil eat=1 1821.1Scgd func_cl_dashL "$2" 1831.1Scgd ;; 1841.238Slukem -L*) 1851.228Slukem func_cl_dashL "${1#-L}" 1861.153Schristos ;; 1871.228Slukem -static) 1881.153Schristos shared=false 1891.228Slukem ;; 1901.228Slukem -Wl,*) 1911.153Schristos arg=${1#-Wl,} 1921.1Scgd save_ifs="$IFS"; IFS=',' 1931.1Scgd for flag in $arg; do 1941.238Slukem IFS="$save_ifs" 1951.228Slukem linker_opts="$linker_opts $flag" 1961.153Schristos done 1971.228Slukem IFS="$save_ifs" 1981.153Schristos ;; 1991.228Slukem -Xlinker) 2001.228Slukem eat=1 2011.153Schristos linker_opts="$linker_opts $2" 2021.17Smycroft ;; 2031.27Spk -*) 2041.238Slukem set x "$@" "$1" 2051.228Slukem shift 2061.153Schristos ;; 2071.228Slukem *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 2081.153Schristos func_file_conv "$1" 2091.228Slukem set x "$@" -Tp"$file" 2101.228Slukem shift 2111.153Schristos ;; 2121.27Spk *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2131.58Scgd func_file_conv "$1" mingw 2141.238Slukem set x "$@" "$file" 2151.224Slukem shift 2161.58Scgd ;; 2171.223Slukem *) 2181.238Slukem set x "$@" "$1" 2191.228Slukem shift 2201.153Schristos ;; 2211.228Slukem esac 2221.153Schristos fi 2231.228Slukem shift 2241.228Slukem done 2251.153Schristos if test -n "$linker_opts"; then 2261.17Smycroft linker_opts="-link$linker_opts" 2271.223Slukem fi 2281.238Slukem exec "$@" $linker_opts 2291.228Slukem exit 1 2301.153Schristos} 2311.228Slukem 2321.153Schristoseat= 2331.228Slukem 2341.228Slukemcase $1 in 2351.153Schristos '') 2361.28Scgd echo "$0: No command. Try '$0 --help' for more information." 1>&2 2371.223Slukem exit 1; 2381.238Slukem ;; 2391.228Slukem -h | --h*) 2401.153Schristos cat <<\EOF 2411.228SlukemUsage: compile [--help] [--version] PROGRAM [ARGS] 2421.153Schristos 2431.228SlukemWrapper for compilers which do not understand '-c -o'. 2441.228SlukemRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 2451.153Schristosarguments, and rename the output as expected. 2461.118Slukem 2471.179SdmcmahilIf you are trying to build a whole package this is not the 2481.238Slukemright script to run: please start by reading the file 'INSTALL'. 2491.228Slukem 2501.179SdmcmahilReport bugs to <bug-automake@gnu.org>. 2511.228SlukemEOF 2521.179Sdmcmahil exit $? 2531.228Slukem ;; 2541.228Slukem -v | --v*) 2551.179Sdmcmahil echo "compile $scriptversion" 2561.179Sdmcmahil exit $? 2571.179Sdmcmahil ;; 2581.238Slukem cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 2591.228Slukem func_cl_wrapper "$@" # Doesn't return... 2601.179Sdmcmahil ;; 2611.228Slukemesac 2621.179Sdmcmahil 2631.228Slukemofile= 2641.228Slukemcfile= 2651.179Sdmcmahil 2661.179Sdmcmahilfor arg 2671.179Sdmcmahildo 2681.238Slukem if test -n "$eat"; then 2691.228Slukem eat= 2701.179Sdmcmahil else 2711.228Slukem case $1 in 2721.179Sdmcmahil -o) 2731.228Slukem # configure might choose to run compile as 'compile cc -o foo foo.c'. 2741.228Slukem # So we strip '-o arg' only if arg is an object. 2751.179Sdmcmahil eat=1 2761.179Sdmcmahil case $2 in 2771.179Sdmcmahil *.o | *.obj) 2781.238Slukem ofile=$2 2791.217Swiz ;; 2801.179Sdmcmahil *) 2811.118Slukem set x "$@" -o "$2" 2821.238Slukem shift 2831.228Slukem ;; 2841.153Schristos esac 2851.228Slukem ;; 2861.153Schristos *.c) 2871.228Slukem cfile=$1 2881.228Slukem set x "$@" "$1" 2891.153Schristos shift 2901.118Slukem ;; 2911.118Slukem *) 2921.238Slukem set x "$@" "$1" 2931.228Slukem shift 2941.153Schristos ;; 2951.228Slukem esac 2961.153Schristos fi 2971.228Slukem shift 2981.228Slukemdone 2991.153Schristos 3001.118Slukemif test -z "$ofile" || test -z "$cfile"; then 3011.118Slukem # If no '-o' option was seen then we might have been invoked from a 3021.238Slukem # pattern rule where we don't need one. That is ok -- this is a 3031.228Slukem # normal compilation that the losing compiler can handle. If no 3041.153Schristos # '.c' file was seen then we are probably linking. That is also 3051.228Slukem # ok. 3061.153Schristos exec "$@" 3071.228Slukemfi 3081.228Slukem 3091.153Schristos# Name of file we expect compiler to create. 3101.1Scgdcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 3111.40Scgd 3121.238Slukem# Create the lock directory. 3131.228Slukem# Note: use '[/\\:.-]' here to ensure that we don't use the same name 3141.228Slukem# that we are using for the .o file. Also, base the name on the expected 3151.228Slukem# object file name, since that is what matters with a parallel build. 3161.1Scgdlockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 3171.40Scgdwhile true; do 3181.238Slukem if mkdir "$lockdir" >/dev/null 2>&1; then 3191.228Slukem break 3201.228Slukem fi 3211.228Slukem sleep 1 3221.1Scgddone 3231.40Scgd# FIXME: race condition here if user kills between mkdir and trap. 3241.238Slukemtrap "rmdir '$lockdir'; exit 1" 1 2 15 3251.228Slukem 3261.228Slukem# Run the compile. 3271.228Slukem"$@" 3281.27Spkret=$? 3291.215Schristos 3301.234Slukemif test -f "$cofile"; then 3311.234Slukem test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 3321.130Stvelif test -f "${cofile}bj"; then 3331.130Stv test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 3341.130Stvfi 3351.130Stv 3361.58Scgdrmdir "$lockdir" 3371.167Smattexit $ret 3381.158Schristos 3391.149Slukem# Local Variables: 3401.130Stv# mode: shell-script 3411.167Smatt# sh-indentation: 2 3421.1Scgd# eval: (add-hook 'write-file-hooks 'time-stamp) 3431.1Scgd# time-stamp-start: "scriptversion=" 3441.148Slukem# time-stamp-format: "%:y-%02m-%02d.%02H" 3451.160Ssimonb# time-stamp-time-zone: "UTC" 3461.205Syamt# time-stamp-end: "; # UTC" 3471.205Syamt# End: 3481.205Syamt