11.1Sriastrad#! /bin/sh 21.1Sriastrad# Wrapper for compilers which do not understand '-c -o'. 31.1Sriastrad 41.1Sriastradscriptversion=2016-01-11.22; # UTC 51.1Sriastrad 61.1Sriastrad# Copyright (C) 1999-2017 Free Software Foundation, Inc. 71.1Sriastrad# Written by Tom Tromey <tromey@cygnus.com>. 81.1Sriastrad# 91.1Sriastrad# This program is free software; you can redistribute it and/or modify 101.1Sriastrad# it under the terms of the GNU General Public License as published by 111.1Sriastrad# the Free Software Foundation; either version 2, or (at your option) 121.1Sriastrad# any later version. 131.1Sriastrad# 141.1Sriastrad# This program is distributed in the hope that it will be useful, 151.1Sriastrad# but WITHOUT ANY WARRANTY; without even the implied warranty of 161.1Sriastrad# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 171.1Sriastrad# GNU General Public License for more details. 181.1Sriastrad# 191.1Sriastrad# You should have received a copy of the GNU General Public License 201.1Sriastrad# along with this program. If not, see <http://www.gnu.org/licenses/>. 211.1Sriastrad 221.1Sriastrad# As a special exception to the GNU General Public License, if you 231.1Sriastrad# distribute this file as part of a program that contains a 241.1Sriastrad# configuration script generated by Autoconf, you may include it under 251.1Sriastrad# the same distribution terms that you use for the rest of that program. 261.1Sriastrad 271.1Sriastrad# This file is maintained in Automake, please report 281.1Sriastrad# bugs to <bug-automake@gnu.org> or send patches to 291.1Sriastrad# <automake-patches@gnu.org>. 301.1Sriastrad 311.1Sriastradnl=' 321.1Sriastrad' 331.1Sriastrad 341.1Sriastrad# We need space, tab and new line, in precisely that order. Quoting is 351.1Sriastrad# there to prevent tools from complaining about whitespace usage. 361.1SriastradIFS=" "" $nl" 371.1Sriastrad 381.1Sriastradfile_conv= 391.1Sriastrad 401.1Sriastrad# func_file_conv build_file lazy 411.1Sriastrad# Convert a $build file to $host form and store it in $file 421.1Sriastrad# Currently only supports Windows hosts. If the determined conversion 431.1Sriastrad# type is listed in (the comma separated) LAZY, no conversion will 441.1Sriastrad# take place. 451.1Sriastradfunc_file_conv () 461.1Sriastrad{ 471.1Sriastrad file=$1 481.1Sriastrad case $file in 491.1Sriastrad / | /[!/]*) # absolute file, and not a UNC file 501.1Sriastrad if test -z "$file_conv"; then 511.1Sriastrad # lazily determine how to convert abs files 521.1Sriastrad case `uname -s` in 531.1Sriastrad MINGW*) 541.1Sriastrad file_conv=mingw 551.1Sriastrad ;; 561.1Sriastrad CYGWIN*) 571.1Sriastrad file_conv=cygwin 581.1Sriastrad ;; 591.1Sriastrad *) 601.1Sriastrad file_conv=wine 611.1Sriastrad ;; 621.1Sriastrad esac 631.1Sriastrad fi 641.1Sriastrad case $file_conv/,$2, in 651.1Sriastrad *,$file_conv,*) 661.1Sriastrad ;; 671.1Sriastrad mingw/*) 681.1Sriastrad file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 691.1Sriastrad ;; 701.1Sriastrad cygwin/*) 711.1Sriastrad file=`cygpath -m "$file" || echo "$file"` 721.1Sriastrad ;; 731.1Sriastrad wine/*) 741.1Sriastrad file=`winepath -w "$file" || echo "$file"` 751.1Sriastrad ;; 761.1Sriastrad esac 771.1Sriastrad ;; 781.1Sriastrad esac 791.1Sriastrad} 801.1Sriastrad 811.1Sriastrad# func_cl_dashL linkdir 821.1Sriastrad# Make cl look for libraries in LINKDIR 831.1Sriastradfunc_cl_dashL () 841.1Sriastrad{ 851.1Sriastrad func_file_conv "$1" 861.1Sriastrad if test -z "$lib_path"; then 871.1Sriastrad lib_path=$file 881.1Sriastrad else 891.1Sriastrad lib_path="$lib_path;$file" 901.1Sriastrad fi 911.1Sriastrad linker_opts="$linker_opts -LIBPATH:$file" 921.1Sriastrad} 931.1Sriastrad 941.1Sriastrad# func_cl_dashl library 951.1Sriastrad# Do a library search-path lookup for cl 961.1Sriastradfunc_cl_dashl () 971.1Sriastrad{ 981.1Sriastrad lib=$1 991.1Sriastrad found=no 1001.1Sriastrad save_IFS=$IFS 1011.1Sriastrad IFS=';' 1021.1Sriastrad for dir in $lib_path $LIB 1031.1Sriastrad do 1041.1Sriastrad IFS=$save_IFS 1051.1Sriastrad if $shared && test -f "$dir/$lib.dll.lib"; then 1061.1Sriastrad found=yes 1071.1Sriastrad lib=$dir/$lib.dll.lib 1081.1Sriastrad break 1091.1Sriastrad fi 1101.1Sriastrad if test -f "$dir/$lib.lib"; then 1111.1Sriastrad found=yes 1121.1Sriastrad lib=$dir/$lib.lib 1131.1Sriastrad break 1141.1Sriastrad fi 1151.1Sriastrad if test -f "$dir/lib$lib.a"; then 1161.1Sriastrad found=yes 1171.1Sriastrad lib=$dir/lib$lib.a 1181.1Sriastrad break 1191.1Sriastrad fi 1201.1Sriastrad done 1211.1Sriastrad IFS=$save_IFS 1221.1Sriastrad 1231.1Sriastrad if test "$found" != yes; then 1241.1Sriastrad lib=$lib.lib 1251.1Sriastrad fi 1261.1Sriastrad} 1271.1Sriastrad 1281.1Sriastrad# func_cl_wrapper cl arg... 1291.1Sriastrad# Adjust compile command to suit cl 1301.1Sriastradfunc_cl_wrapper () 1311.1Sriastrad{ 1321.1Sriastrad # Assume a capable shell 1331.1Sriastrad lib_path= 1341.1Sriastrad shared=: 1351.1Sriastrad linker_opts= 1361.1Sriastrad for arg 1371.1Sriastrad do 1381.1Sriastrad if test -n "$eat"; then 1391.1Sriastrad eat= 1401.1Sriastrad else 1411.1Sriastrad case $1 in 1421.1Sriastrad -o) 1431.1Sriastrad # configure might choose to run compile as 'compile cc -o foo foo.c'. 1441.1Sriastrad eat=1 1451.1Sriastrad case $2 in 1461.1Sriastrad *.o | *.[oO][bB][jJ]) 1471.1Sriastrad func_file_conv "$2" 1481.1Sriastrad set x "$@" -Fo"$file" 1491.1Sriastrad shift 1501.1Sriastrad ;; 1511.1Sriastrad *) 1521.1Sriastrad func_file_conv "$2" 1531.1Sriastrad set x "$@" -Fe"$file" 1541.1Sriastrad shift 1551.1Sriastrad ;; 1561.1Sriastrad esac 1571.1Sriastrad ;; 1581.1Sriastrad -I) 1591.1Sriastrad eat=1 1601.1Sriastrad func_file_conv "$2" mingw 1611.1Sriastrad set x "$@" -I"$file" 1621.1Sriastrad shift 1631.1Sriastrad ;; 1641.1Sriastrad -I*) 1651.1Sriastrad func_file_conv "${1#-I}" mingw 1661.1Sriastrad set x "$@" -I"$file" 1671.1Sriastrad shift 1681.1Sriastrad ;; 1691.1Sriastrad -l) 1701.1Sriastrad eat=1 1711.1Sriastrad func_cl_dashl "$2" 1721.1Sriastrad set x "$@" "$lib" 1731.1Sriastrad shift 1741.1Sriastrad ;; 1751.1Sriastrad -l*) 1761.1Sriastrad func_cl_dashl "${1#-l}" 1771.1Sriastrad set x "$@" "$lib" 1781.1Sriastrad shift 1791.1Sriastrad ;; 1801.1Sriastrad -L) 1811.1Sriastrad eat=1 1821.1Sriastrad func_cl_dashL "$2" 1831.1Sriastrad ;; 1841.1Sriastrad -L*) 1851.1Sriastrad func_cl_dashL "${1#-L}" 1861.1Sriastrad ;; 1871.1Sriastrad -static) 1881.1Sriastrad shared=false 1891.1Sriastrad ;; 1901.1Sriastrad -Wl,*) 1911.1Sriastrad arg=${1#-Wl,} 1921.1Sriastrad save_ifs="$IFS"; IFS=',' 1931.1Sriastrad for flag in $arg; do 1941.1Sriastrad IFS="$save_ifs" 1951.1Sriastrad linker_opts="$linker_opts $flag" 1961.1Sriastrad done 1971.1Sriastrad IFS="$save_ifs" 1981.1Sriastrad ;; 1991.1Sriastrad -Xlinker) 2001.1Sriastrad eat=1 2011.1Sriastrad linker_opts="$linker_opts $2" 2021.1Sriastrad ;; 2031.1Sriastrad -*) 2041.1Sriastrad set x "$@" "$1" 2051.1Sriastrad shift 2061.1Sriastrad ;; 2071.1Sriastrad *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 2081.1Sriastrad func_file_conv "$1" 2091.1Sriastrad set x "$@" -Tp"$file" 2101.1Sriastrad shift 2111.1Sriastrad ;; 2121.1Sriastrad *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2131.1Sriastrad func_file_conv "$1" mingw 2141.1Sriastrad set x "$@" "$file" 2151.1Sriastrad shift 2161.1Sriastrad ;; 2171.1Sriastrad *) 2181.1Sriastrad set x "$@" "$1" 2191.1Sriastrad shift 2201.1Sriastrad ;; 2211.1Sriastrad esac 2221.1Sriastrad fi 2231.1Sriastrad shift 2241.1Sriastrad done 2251.1Sriastrad if test -n "$linker_opts"; then 2261.1Sriastrad linker_opts="-link$linker_opts" 2271.1Sriastrad fi 2281.1Sriastrad exec "$@" $linker_opts 2291.1Sriastrad exit 1 2301.1Sriastrad} 2311.1Sriastrad 2321.1Sriastradeat= 2331.1Sriastrad 2341.1Sriastradcase $1 in 2351.1Sriastrad '') 2361.1Sriastrad echo "$0: No command. Try '$0 --help' for more information." 1>&2 2371.1Sriastrad exit 1; 2381.1Sriastrad ;; 2391.1Sriastrad -h | --h*) 2401.1Sriastrad cat <<\EOF 2411.1SriastradUsage: compile [--help] [--version] PROGRAM [ARGS] 2421.1Sriastrad 2431.1SriastradWrapper for compilers which do not understand '-c -o'. 2441.1SriastradRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 2451.1Sriastradarguments, and rename the output as expected. 2461.1Sriastrad 2471.1SriastradIf you are trying to build a whole package this is not the 2481.1Sriastradright script to run: please start by reading the file 'INSTALL'. 2491.1Sriastrad 2501.1SriastradReport bugs to <bug-automake@gnu.org>. 2511.1SriastradEOF 2521.1Sriastrad exit $? 2531.1Sriastrad ;; 2541.1Sriastrad -v | --v*) 2551.1Sriastrad echo "compile $scriptversion" 2561.1Sriastrad exit $? 2571.1Sriastrad ;; 2581.1Sriastrad cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 2591.1Sriastrad icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 2601.1Sriastrad func_cl_wrapper "$@" # Doesn't return... 2611.1Sriastrad ;; 2621.1Sriastradesac 2631.1Sriastrad 2641.1Sriastradofile= 2651.1Sriastradcfile= 2661.1Sriastrad 2671.1Sriastradfor arg 2681.1Sriastraddo 2691.1Sriastrad if test -n "$eat"; then 2701.1Sriastrad eat= 2711.1Sriastrad else 2721.1Sriastrad case $1 in 2731.1Sriastrad -o) 2741.1Sriastrad # configure might choose to run compile as 'compile cc -o foo foo.c'. 2751.1Sriastrad # So we strip '-o arg' only if arg is an object. 2761.1Sriastrad eat=1 2771.1Sriastrad case $2 in 2781.1Sriastrad *.o | *.obj) 2791.1Sriastrad ofile=$2 2801.1Sriastrad ;; 2811.1Sriastrad *) 2821.1Sriastrad set x "$@" -o "$2" 2831.1Sriastrad shift 2841.1Sriastrad ;; 2851.1Sriastrad esac 2861.1Sriastrad ;; 2871.1Sriastrad *.c) 2881.1Sriastrad cfile=$1 2891.1Sriastrad set x "$@" "$1" 2901.1Sriastrad shift 2911.1Sriastrad ;; 2921.1Sriastrad *) 2931.1Sriastrad set x "$@" "$1" 2941.1Sriastrad shift 2951.1Sriastrad ;; 2961.1Sriastrad esac 2971.1Sriastrad fi 2981.1Sriastrad shift 2991.1Sriastraddone 3001.1Sriastrad 3011.1Sriastradif test -z "$ofile" || test -z "$cfile"; then 3021.1Sriastrad # If no '-o' option was seen then we might have been invoked from a 3031.1Sriastrad # pattern rule where we don't need one. That is ok -- this is a 3041.1Sriastrad # normal compilation that the losing compiler can handle. If no 3051.1Sriastrad # '.c' file was seen then we are probably linking. That is also 3061.1Sriastrad # ok. 3071.1Sriastrad exec "$@" 3081.1Sriastradfi 3091.1Sriastrad 3101.1Sriastrad# Name of file we expect compiler to create. 3111.1Sriastradcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 3121.1Sriastrad 3131.1Sriastrad# Create the lock directory. 3141.1Sriastrad# Note: use '[/\\:.-]' here to ensure that we don't use the same name 3151.1Sriastrad# that we are using for the .o file. Also, base the name on the expected 3161.1Sriastrad# object file name, since that is what matters with a parallel build. 3171.1Sriastradlockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 3181.1Sriastradwhile true; do 3191.1Sriastrad if mkdir "$lockdir" >/dev/null 2>&1; then 3201.1Sriastrad break 3211.1Sriastrad fi 3221.1Sriastrad sleep 1 3231.1Sriastraddone 3241.1Sriastrad# FIXME: race condition here if user kills between mkdir and trap. 3251.1Sriastradtrap "rmdir '$lockdir'; exit 1" 1 2 15 3261.1Sriastrad 3271.1Sriastrad# Run the compile. 3281.1Sriastrad"$@" 3291.1Sriastradret=$? 3301.1Sriastrad 3311.1Sriastradif test -f "$cofile"; then 3321.1Sriastrad test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 3331.1Sriastradelif test -f "${cofile}bj"; then 3341.1Sriastrad test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 3351.1Sriastradfi 3361.1Sriastrad 3371.1Sriastradrmdir "$lockdir" 3381.1Sriastradexit $ret 3391.1Sriastrad 3401.1Sriastrad# Local Variables: 3411.1Sriastrad# mode: shell-script 3421.1Sriastrad# sh-indentation: 2 3431.1Sriastrad# eval: (add-hook 'write-file-hooks 'time-stamp) 3441.1Sriastrad# time-stamp-start: "scriptversion=" 3451.1Sriastrad# time-stamp-format: "%:y-%02m-%02d.%02H" 3461.1Sriastrad# time-stamp-time-zone: "UTC0" 3471.1Sriastrad# time-stamp-end: "; # UTC" 3481.1Sriastrad# End: 349