11f13f311SSkyrpex#! /bin/sh 21f13f311SSkyrpex# Wrapper for compilers which do not understand '-c -o'. 31f13f311SSkyrpex 41f13f311SSkyrpexscriptversion=2012-10-14.11; # UTC 51f13f311SSkyrpex 6*275def9cSCristian Pallarés# Copyright (C) 1999-2014 Free Software Foundation, Inc. 71f13f311SSkyrpex# Written by Tom Tromey <[email protected]>. 81f13f311SSkyrpex# 91f13f311SSkyrpex# This program is free software; you can redistribute it and/or modify 101f13f311SSkyrpex# it under the terms of the GNU General Public License as published by 111f13f311SSkyrpex# the Free Software Foundation; either version 2, or (at your option) 121f13f311SSkyrpex# any later version. 131f13f311SSkyrpex# 141f13f311SSkyrpex# This program is distributed in the hope that it will be useful, 151f13f311SSkyrpex# but WITHOUT ANY WARRANTY; without even the implied warranty of 161f13f311SSkyrpex# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 171f13f311SSkyrpex# GNU General Public License for more details. 181f13f311SSkyrpex# 191f13f311SSkyrpex# You should have received a copy of the GNU General Public License 201f13f311SSkyrpex# along with this program. If not, see <http://www.gnu.org/licenses/>. 211f13f311SSkyrpex 221f13f311SSkyrpex# As a special exception to the GNU General Public License, if you 231f13f311SSkyrpex# distribute this file as part of a program that contains a 241f13f311SSkyrpex# configuration script generated by Autoconf, you may include it under 251f13f311SSkyrpex# the same distribution terms that you use for the rest of that program. 261f13f311SSkyrpex 271f13f311SSkyrpex# This file is maintained in Automake, please report 281f13f311SSkyrpex# bugs to <[email protected]> or send patches to 291f13f311SSkyrpex# <[email protected]>. 301f13f311SSkyrpex 311f13f311SSkyrpexnl=' 321f13f311SSkyrpex' 331f13f311SSkyrpex 341f13f311SSkyrpex# We need space, tab and new line, in precisely that order. Quoting is 351f13f311SSkyrpex# there to prevent tools from complaining about whitespace usage. 361f13f311SSkyrpexIFS=" "" $nl" 371f13f311SSkyrpex 381f13f311SSkyrpexfile_conv= 391f13f311SSkyrpex 401f13f311SSkyrpex# func_file_conv build_file lazy 411f13f311SSkyrpex# Convert a $build file to $host form and store it in $file 421f13f311SSkyrpex# Currently only supports Windows hosts. If the determined conversion 431f13f311SSkyrpex# type is listed in (the comma separated) LAZY, no conversion will 441f13f311SSkyrpex# take place. 451f13f311SSkyrpexfunc_file_conv () 461f13f311SSkyrpex{ 471f13f311SSkyrpex file=$1 481f13f311SSkyrpex case $file in 491f13f311SSkyrpex / | /[!/]*) # absolute file, and not a UNC file 501f13f311SSkyrpex if test -z "$file_conv"; then 511f13f311SSkyrpex # lazily determine how to convert abs files 521f13f311SSkyrpex case `uname -s` in 531f13f311SSkyrpex MINGW*) 541f13f311SSkyrpex file_conv=mingw 551f13f311SSkyrpex ;; 561f13f311SSkyrpex CYGWIN*) 571f13f311SSkyrpex file_conv=cygwin 581f13f311SSkyrpex ;; 591f13f311SSkyrpex *) 601f13f311SSkyrpex file_conv=wine 611f13f311SSkyrpex ;; 621f13f311SSkyrpex esac 631f13f311SSkyrpex fi 641f13f311SSkyrpex case $file_conv/,$2, in 651f13f311SSkyrpex *,$file_conv,*) 661f13f311SSkyrpex ;; 671f13f311SSkyrpex mingw/*) 681f13f311SSkyrpex file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 691f13f311SSkyrpex ;; 701f13f311SSkyrpex cygwin/*) 711f13f311SSkyrpex file=`cygpath -m "$file" || echo "$file"` 721f13f311SSkyrpex ;; 731f13f311SSkyrpex wine/*) 741f13f311SSkyrpex file=`winepath -w "$file" || echo "$file"` 751f13f311SSkyrpex ;; 761f13f311SSkyrpex esac 771f13f311SSkyrpex ;; 781f13f311SSkyrpex esac 791f13f311SSkyrpex} 801f13f311SSkyrpex 811f13f311SSkyrpex# func_cl_dashL linkdir 821f13f311SSkyrpex# Make cl look for libraries in LINKDIR 831f13f311SSkyrpexfunc_cl_dashL () 841f13f311SSkyrpex{ 851f13f311SSkyrpex func_file_conv "$1" 861f13f311SSkyrpex if test -z "$lib_path"; then 871f13f311SSkyrpex lib_path=$file 881f13f311SSkyrpex else 891f13f311SSkyrpex lib_path="$lib_path;$file" 901f13f311SSkyrpex fi 911f13f311SSkyrpex linker_opts="$linker_opts -LIBPATH:$file" 921f13f311SSkyrpex} 931f13f311SSkyrpex 941f13f311SSkyrpex# func_cl_dashl library 951f13f311SSkyrpex# Do a library search-path lookup for cl 961f13f311SSkyrpexfunc_cl_dashl () 971f13f311SSkyrpex{ 981f13f311SSkyrpex lib=$1 991f13f311SSkyrpex found=no 1001f13f311SSkyrpex save_IFS=$IFS 1011f13f311SSkyrpex IFS=';' 1021f13f311SSkyrpex for dir in $lib_path $LIB 1031f13f311SSkyrpex do 1041f13f311SSkyrpex IFS=$save_IFS 1051f13f311SSkyrpex if $shared && test -f "$dir/$lib.dll.lib"; then 1061f13f311SSkyrpex found=yes 1071f13f311SSkyrpex lib=$dir/$lib.dll.lib 1081f13f311SSkyrpex break 1091f13f311SSkyrpex fi 1101f13f311SSkyrpex if test -f "$dir/$lib.lib"; then 1111f13f311SSkyrpex found=yes 1121f13f311SSkyrpex lib=$dir/$lib.lib 1131f13f311SSkyrpex break 1141f13f311SSkyrpex fi 1151f13f311SSkyrpex if test -f "$dir/lib$lib.a"; then 1161f13f311SSkyrpex found=yes 1171f13f311SSkyrpex lib=$dir/lib$lib.a 1181f13f311SSkyrpex break 1191f13f311SSkyrpex fi 1201f13f311SSkyrpex done 1211f13f311SSkyrpex IFS=$save_IFS 1221f13f311SSkyrpex 1231f13f311SSkyrpex if test "$found" != yes; then 1241f13f311SSkyrpex lib=$lib.lib 1251f13f311SSkyrpex fi 1261f13f311SSkyrpex} 1271f13f311SSkyrpex 1281f13f311SSkyrpex# func_cl_wrapper cl arg... 1291f13f311SSkyrpex# Adjust compile command to suit cl 1301f13f311SSkyrpexfunc_cl_wrapper () 1311f13f311SSkyrpex{ 1321f13f311SSkyrpex # Assume a capable shell 1331f13f311SSkyrpex lib_path= 1341f13f311SSkyrpex shared=: 1351f13f311SSkyrpex linker_opts= 1361f13f311SSkyrpex for arg 1371f13f311SSkyrpex do 1381f13f311SSkyrpex if test -n "$eat"; then 1391f13f311SSkyrpex eat= 1401f13f311SSkyrpex else 1411f13f311SSkyrpex case $1 in 1421f13f311SSkyrpex -o) 1431f13f311SSkyrpex # configure might choose to run compile as 'compile cc -o foo foo.c'. 1441f13f311SSkyrpex eat=1 1451f13f311SSkyrpex case $2 in 1461f13f311SSkyrpex *.o | *.[oO][bB][jJ]) 1471f13f311SSkyrpex func_file_conv "$2" 1481f13f311SSkyrpex set x "$@" -Fo"$file" 1491f13f311SSkyrpex shift 1501f13f311SSkyrpex ;; 1511f13f311SSkyrpex *) 1521f13f311SSkyrpex func_file_conv "$2" 1531f13f311SSkyrpex set x "$@" -Fe"$file" 1541f13f311SSkyrpex shift 1551f13f311SSkyrpex ;; 1561f13f311SSkyrpex esac 1571f13f311SSkyrpex ;; 1581f13f311SSkyrpex -I) 1591f13f311SSkyrpex eat=1 1601f13f311SSkyrpex func_file_conv "$2" mingw 1611f13f311SSkyrpex set x "$@" -I"$file" 1621f13f311SSkyrpex shift 1631f13f311SSkyrpex ;; 1641f13f311SSkyrpex -I*) 1651f13f311SSkyrpex func_file_conv "${1#-I}" mingw 1661f13f311SSkyrpex set x "$@" -I"$file" 1671f13f311SSkyrpex shift 1681f13f311SSkyrpex ;; 1691f13f311SSkyrpex -l) 1701f13f311SSkyrpex eat=1 1711f13f311SSkyrpex func_cl_dashl "$2" 1721f13f311SSkyrpex set x "$@" "$lib" 1731f13f311SSkyrpex shift 1741f13f311SSkyrpex ;; 1751f13f311SSkyrpex -l*) 1761f13f311SSkyrpex func_cl_dashl "${1#-l}" 1771f13f311SSkyrpex set x "$@" "$lib" 1781f13f311SSkyrpex shift 1791f13f311SSkyrpex ;; 1801f13f311SSkyrpex -L) 1811f13f311SSkyrpex eat=1 1821f13f311SSkyrpex func_cl_dashL "$2" 1831f13f311SSkyrpex ;; 1841f13f311SSkyrpex -L*) 1851f13f311SSkyrpex func_cl_dashL "${1#-L}" 1861f13f311SSkyrpex ;; 1871f13f311SSkyrpex -static) 1881f13f311SSkyrpex shared=false 1891f13f311SSkyrpex ;; 1901f13f311SSkyrpex -Wl,*) 1911f13f311SSkyrpex arg=${1#-Wl,} 1921f13f311SSkyrpex save_ifs="$IFS"; IFS=',' 1931f13f311SSkyrpex for flag in $arg; do 1941f13f311SSkyrpex IFS="$save_ifs" 1951f13f311SSkyrpex linker_opts="$linker_opts $flag" 1961f13f311SSkyrpex done 1971f13f311SSkyrpex IFS="$save_ifs" 1981f13f311SSkyrpex ;; 1991f13f311SSkyrpex -Xlinker) 2001f13f311SSkyrpex eat=1 2011f13f311SSkyrpex linker_opts="$linker_opts $2" 2021f13f311SSkyrpex ;; 2031f13f311SSkyrpex -*) 2041f13f311SSkyrpex set x "$@" "$1" 2051f13f311SSkyrpex shift 2061f13f311SSkyrpex ;; 2071f13f311SSkyrpex *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 2081f13f311SSkyrpex func_file_conv "$1" 2091f13f311SSkyrpex set x "$@" -Tp"$file" 2101f13f311SSkyrpex shift 2111f13f311SSkyrpex ;; 2121f13f311SSkyrpex *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2131f13f311SSkyrpex func_file_conv "$1" mingw 2141f13f311SSkyrpex set x "$@" "$file" 2151f13f311SSkyrpex shift 2161f13f311SSkyrpex ;; 2171f13f311SSkyrpex *) 2181f13f311SSkyrpex set x "$@" "$1" 2191f13f311SSkyrpex shift 2201f13f311SSkyrpex ;; 2211f13f311SSkyrpex esac 2221f13f311SSkyrpex fi 2231f13f311SSkyrpex shift 2241f13f311SSkyrpex done 2251f13f311SSkyrpex if test -n "$linker_opts"; then 2261f13f311SSkyrpex linker_opts="-link$linker_opts" 2271f13f311SSkyrpex fi 2281f13f311SSkyrpex exec "$@" $linker_opts 2291f13f311SSkyrpex exit 1 2301f13f311SSkyrpex} 2311f13f311SSkyrpex 2321f13f311SSkyrpexeat= 2331f13f311SSkyrpex 2341f13f311SSkyrpexcase $1 in 2351f13f311SSkyrpex '') 2361f13f311SSkyrpex echo "$0: No command. Try '$0 --help' for more information." 1>&2 2371f13f311SSkyrpex exit 1; 2381f13f311SSkyrpex ;; 2391f13f311SSkyrpex -h | --h*) 2401f13f311SSkyrpex cat <<\EOF 2411f13f311SSkyrpexUsage: compile [--help] [--version] PROGRAM [ARGS] 2421f13f311SSkyrpex 2431f13f311SSkyrpexWrapper for compilers which do not understand '-c -o'. 2441f13f311SSkyrpexRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 2451f13f311SSkyrpexarguments, and rename the output as expected. 2461f13f311SSkyrpex 2471f13f311SSkyrpexIf you are trying to build a whole package this is not the 2481f13f311SSkyrpexright script to run: please start by reading the file 'INSTALL'. 2491f13f311SSkyrpex 2501f13f311SSkyrpexReport bugs to <bug-automake@gnu.org>. 2511f13f311SSkyrpexEOF 2521f13f311SSkyrpex exit $? 2531f13f311SSkyrpex ;; 2541f13f311SSkyrpex -v | --v*) 2551f13f311SSkyrpex echo "compile $scriptversion" 2561f13f311SSkyrpex exit $? 2571f13f311SSkyrpex ;; 2581f13f311SSkyrpex cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 2591f13f311SSkyrpex func_cl_wrapper "$@" # Doesn't return... 2601f13f311SSkyrpex ;; 2611f13f311SSkyrpexesac 2621f13f311SSkyrpex 2631f13f311SSkyrpexofile= 2641f13f311SSkyrpexcfile= 2651f13f311SSkyrpex 2661f13f311SSkyrpexfor arg 2671f13f311SSkyrpexdo 2681f13f311SSkyrpex if test -n "$eat"; then 2691f13f311SSkyrpex eat= 2701f13f311SSkyrpex else 2711f13f311SSkyrpex case $1 in 2721f13f311SSkyrpex -o) 2731f13f311SSkyrpex # configure might choose to run compile as 'compile cc -o foo foo.c'. 2741f13f311SSkyrpex # So we strip '-o arg' only if arg is an object. 2751f13f311SSkyrpex eat=1 2761f13f311SSkyrpex case $2 in 2771f13f311SSkyrpex *.o | *.obj) 2781f13f311SSkyrpex ofile=$2 2791f13f311SSkyrpex ;; 2801f13f311SSkyrpex *) 2811f13f311SSkyrpex set x "$@" -o "$2" 2821f13f311SSkyrpex shift 2831f13f311SSkyrpex ;; 2841f13f311SSkyrpex esac 2851f13f311SSkyrpex ;; 2861f13f311SSkyrpex *.c) 2871f13f311SSkyrpex cfile=$1 2881f13f311SSkyrpex set x "$@" "$1" 2891f13f311SSkyrpex shift 2901f13f311SSkyrpex ;; 2911f13f311SSkyrpex *) 2921f13f311SSkyrpex set x "$@" "$1" 2931f13f311SSkyrpex shift 2941f13f311SSkyrpex ;; 2951f13f311SSkyrpex esac 2961f13f311SSkyrpex fi 2971f13f311SSkyrpex shift 2981f13f311SSkyrpexdone 2991f13f311SSkyrpex 3001f13f311SSkyrpexif test -z "$ofile" || test -z "$cfile"; then 3011f13f311SSkyrpex # If no '-o' option was seen then we might have been invoked from a 3021f13f311SSkyrpex # pattern rule where we don't need one. That is ok -- this is a 3031f13f311SSkyrpex # normal compilation that the losing compiler can handle. If no 3041f13f311SSkyrpex # '.c' file was seen then we are probably linking. That is also 3051f13f311SSkyrpex # ok. 3061f13f311SSkyrpex exec "$@" 3071f13f311SSkyrpexfi 3081f13f311SSkyrpex 3091f13f311SSkyrpex# Name of file we expect compiler to create. 3101f13f311SSkyrpexcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 3111f13f311SSkyrpex 3121f13f311SSkyrpex# Create the lock directory. 3131f13f311SSkyrpex# Note: use '[/\\:.-]' here to ensure that we don't use the same name 3141f13f311SSkyrpex# that we are using for the .o file. Also, base the name on the expected 3151f13f311SSkyrpex# object file name, since that is what matters with a parallel build. 3161f13f311SSkyrpexlockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 3171f13f311SSkyrpexwhile true; do 3181f13f311SSkyrpex if mkdir "$lockdir" >/dev/null 2>&1; then 3191f13f311SSkyrpex break 3201f13f311SSkyrpex fi 3211f13f311SSkyrpex sleep 1 3221f13f311SSkyrpexdone 3231f13f311SSkyrpex# FIXME: race condition here if user kills between mkdir and trap. 3241f13f311SSkyrpextrap "rmdir '$lockdir'; exit 1" 1 2 15 3251f13f311SSkyrpex 3261f13f311SSkyrpex# Run the compile. 3271f13f311SSkyrpex"$@" 3281f13f311SSkyrpexret=$? 3291f13f311SSkyrpex 3301f13f311SSkyrpexif test -f "$cofile"; then 3311f13f311SSkyrpex test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 3321f13f311SSkyrpexelif test -f "${cofile}bj"; then 3331f13f311SSkyrpex test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 3341f13f311SSkyrpexfi 3351f13f311SSkyrpex 3361f13f311SSkyrpexrmdir "$lockdir" 3371f13f311SSkyrpexexit $ret 3381f13f311SSkyrpex 3391f13f311SSkyrpex# Local Variables: 3401f13f311SSkyrpex# mode: shell-script 3411f13f311SSkyrpex# sh-indentation: 2 3421f13f311SSkyrpex# eval: (add-hook 'write-file-hooks 'time-stamp) 3431f13f311SSkyrpex# time-stamp-start: "scriptversion=" 3441f13f311SSkyrpex# time-stamp-format: "%:y-%02m-%02d.%02H" 3451f13f311SSkyrpex# time-stamp-time-zone: "UTC" 3461f13f311SSkyrpex# time-stamp-end: "; # UTC" 3471f13f311SSkyrpex# End: 348