12007c8b2Snia#! /bin/sh 22007c8b2Snia# Wrapper for compilers which do not understand '-c -o'. 32007c8b2Snia 42007c8b2Sniascriptversion=2012-10-14.11; # UTC 52007c8b2Snia 62007c8b2Snia# Copyright (C) 1999-2014 Free Software Foundation, Inc. 72007c8b2Snia# Written by Tom Tromey <tromey@cygnus.com>. 82007c8b2Snia# 92007c8b2Snia# This program is free software; you can redistribute it and/or modify 102007c8b2Snia# it under the terms of the GNU General Public License as published by 112007c8b2Snia# the Free Software Foundation; either version 2, or (at your option) 122007c8b2Snia# any later version. 132007c8b2Snia# 142007c8b2Snia# This program is distributed in the hope that it will be useful, 152007c8b2Snia# but WITHOUT ANY WARRANTY; without even the implied warranty of 162007c8b2Snia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 172007c8b2Snia# GNU General Public License for more details. 182007c8b2Snia# 192007c8b2Snia# You should have received a copy of the GNU General Public License 202007c8b2Snia# along with this program. If not, see <http://www.gnu.org/licenses/>. 212007c8b2Snia 222007c8b2Snia# As a special exception to the GNU General Public License, if you 232007c8b2Snia# distribute this file as part of a program that contains a 242007c8b2Snia# configuration script generated by Autoconf, you may include it under 252007c8b2Snia# the same distribution terms that you use for the rest of that program. 262007c8b2Snia 272007c8b2Snia# This file is maintained in Automake, please report 282007c8b2Snia# bugs to <bug-automake@gnu.org> or send patches to 292007c8b2Snia# <automake-patches@gnu.org>. 302007c8b2Snia 312007c8b2Snianl=' 322007c8b2Snia' 332007c8b2Snia 342007c8b2Snia# We need space, tab and new line, in precisely that order. Quoting is 352007c8b2Snia# there to prevent tools from complaining about whitespace usage. 362007c8b2SniaIFS=" "" $nl" 372007c8b2Snia 382007c8b2Sniafile_conv= 392007c8b2Snia 402007c8b2Snia# func_file_conv build_file lazy 412007c8b2Snia# Convert a $build file to $host form and store it in $file 422007c8b2Snia# Currently only supports Windows hosts. If the determined conversion 432007c8b2Snia# type is listed in (the comma separated) LAZY, no conversion will 442007c8b2Snia# take place. 452007c8b2Sniafunc_file_conv () 462007c8b2Snia{ 472007c8b2Snia file=$1 482007c8b2Snia case $file in 492007c8b2Snia / | /[!/]*) # absolute file, and not a UNC file 502007c8b2Snia if test -z "$file_conv"; then 512007c8b2Snia # lazily determine how to convert abs files 522007c8b2Snia case `uname -s` in 532007c8b2Snia MINGW*) 542007c8b2Snia file_conv=mingw 552007c8b2Snia ;; 562007c8b2Snia CYGWIN*) 572007c8b2Snia file_conv=cygwin 582007c8b2Snia ;; 592007c8b2Snia *) 602007c8b2Snia file_conv=wine 612007c8b2Snia ;; 622007c8b2Snia esac 632007c8b2Snia fi 642007c8b2Snia case $file_conv/,$2, in 652007c8b2Snia *,$file_conv,*) 662007c8b2Snia ;; 672007c8b2Snia mingw/*) 682007c8b2Snia file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 692007c8b2Snia ;; 702007c8b2Snia cygwin/*) 712007c8b2Snia file=`cygpath -m "$file" || echo "$file"` 722007c8b2Snia ;; 732007c8b2Snia wine/*) 742007c8b2Snia file=`winepath -w "$file" || echo "$file"` 752007c8b2Snia ;; 762007c8b2Snia esac 772007c8b2Snia ;; 782007c8b2Snia esac 792007c8b2Snia} 802007c8b2Snia 812007c8b2Snia# func_cl_dashL linkdir 822007c8b2Snia# Make cl look for libraries in LINKDIR 832007c8b2Sniafunc_cl_dashL () 842007c8b2Snia{ 852007c8b2Snia func_file_conv "$1" 862007c8b2Snia if test -z "$lib_path"; then 872007c8b2Snia lib_path=$file 882007c8b2Snia else 892007c8b2Snia lib_path="$lib_path;$file" 902007c8b2Snia fi 912007c8b2Snia linker_opts="$linker_opts -LIBPATH:$file" 922007c8b2Snia} 932007c8b2Snia 942007c8b2Snia# func_cl_dashl library 952007c8b2Snia# Do a library search-path lookup for cl 962007c8b2Sniafunc_cl_dashl () 972007c8b2Snia{ 982007c8b2Snia lib=$1 992007c8b2Snia found=no 1002007c8b2Snia save_IFS=$IFS 1012007c8b2Snia IFS=';' 1022007c8b2Snia for dir in $lib_path $LIB 1032007c8b2Snia do 1042007c8b2Snia IFS=$save_IFS 1052007c8b2Snia if $shared && test -f "$dir/$lib.dll.lib"; then 1062007c8b2Snia found=yes 1072007c8b2Snia lib=$dir/$lib.dll.lib 1082007c8b2Snia break 1092007c8b2Snia fi 1102007c8b2Snia if test -f "$dir/$lib.lib"; then 1112007c8b2Snia found=yes 1122007c8b2Snia lib=$dir/$lib.lib 1132007c8b2Snia break 1142007c8b2Snia fi 1152007c8b2Snia if test -f "$dir/lib$lib.a"; then 1162007c8b2Snia found=yes 1172007c8b2Snia lib=$dir/lib$lib.a 1182007c8b2Snia break 1192007c8b2Snia fi 1202007c8b2Snia done 1212007c8b2Snia IFS=$save_IFS 1222007c8b2Snia 1232007c8b2Snia if test "$found" != yes; then 1242007c8b2Snia lib=$lib.lib 1252007c8b2Snia fi 1262007c8b2Snia} 1272007c8b2Snia 1282007c8b2Snia# func_cl_wrapper cl arg... 1292007c8b2Snia# Adjust compile command to suit cl 1302007c8b2Sniafunc_cl_wrapper () 1312007c8b2Snia{ 1322007c8b2Snia # Assume a capable shell 1332007c8b2Snia lib_path= 1342007c8b2Snia shared=: 1352007c8b2Snia linker_opts= 1362007c8b2Snia for arg 1372007c8b2Snia do 1382007c8b2Snia if test -n "$eat"; then 1392007c8b2Snia eat= 1402007c8b2Snia else 1412007c8b2Snia case $1 in 1422007c8b2Snia -o) 1432007c8b2Snia # configure might choose to run compile as 'compile cc -o foo foo.c'. 1442007c8b2Snia eat=1 1452007c8b2Snia case $2 in 1462007c8b2Snia *.o | *.[oO][bB][jJ]) 1472007c8b2Snia func_file_conv "$2" 1482007c8b2Snia set x "$@" -Fo"$file" 1492007c8b2Snia shift 1502007c8b2Snia ;; 1512007c8b2Snia *) 1522007c8b2Snia func_file_conv "$2" 1532007c8b2Snia set x "$@" -Fe"$file" 1542007c8b2Snia shift 1552007c8b2Snia ;; 1562007c8b2Snia esac 1572007c8b2Snia ;; 1582007c8b2Snia -I) 1592007c8b2Snia eat=1 1602007c8b2Snia func_file_conv "$2" mingw 1612007c8b2Snia set x "$@" -I"$file" 1622007c8b2Snia shift 1632007c8b2Snia ;; 1642007c8b2Snia -I*) 1652007c8b2Snia func_file_conv "${1#-I}" mingw 1662007c8b2Snia set x "$@" -I"$file" 1672007c8b2Snia shift 1682007c8b2Snia ;; 1692007c8b2Snia -l) 1702007c8b2Snia eat=1 1712007c8b2Snia func_cl_dashl "$2" 1722007c8b2Snia set x "$@" "$lib" 1732007c8b2Snia shift 1742007c8b2Snia ;; 1752007c8b2Snia -l*) 1762007c8b2Snia func_cl_dashl "${1#-l}" 1772007c8b2Snia set x "$@" "$lib" 1782007c8b2Snia shift 1792007c8b2Snia ;; 1802007c8b2Snia -L) 1812007c8b2Snia eat=1 1822007c8b2Snia func_cl_dashL "$2" 1832007c8b2Snia ;; 1842007c8b2Snia -L*) 1852007c8b2Snia func_cl_dashL "${1#-L}" 1862007c8b2Snia ;; 1872007c8b2Snia -static) 1882007c8b2Snia shared=false 1892007c8b2Snia ;; 1902007c8b2Snia -Wl,*) 1912007c8b2Snia arg=${1#-Wl,} 1922007c8b2Snia save_ifs="$IFS"; IFS=',' 1932007c8b2Snia for flag in $arg; do 1942007c8b2Snia IFS="$save_ifs" 1952007c8b2Snia linker_opts="$linker_opts $flag" 1962007c8b2Snia done 1972007c8b2Snia IFS="$save_ifs" 1982007c8b2Snia ;; 1992007c8b2Snia -Xlinker) 2002007c8b2Snia eat=1 2012007c8b2Snia linker_opts="$linker_opts $2" 2022007c8b2Snia ;; 2032007c8b2Snia -*) 2042007c8b2Snia set x "$@" "$1" 2052007c8b2Snia shift 2062007c8b2Snia ;; 2072007c8b2Snia *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 2082007c8b2Snia func_file_conv "$1" 2092007c8b2Snia set x "$@" -Tp"$file" 2102007c8b2Snia shift 2112007c8b2Snia ;; 2122007c8b2Snia *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2132007c8b2Snia func_file_conv "$1" mingw 2142007c8b2Snia set x "$@" "$file" 2152007c8b2Snia shift 2162007c8b2Snia ;; 2172007c8b2Snia *) 2182007c8b2Snia set x "$@" "$1" 2192007c8b2Snia shift 2202007c8b2Snia ;; 2212007c8b2Snia esac 2222007c8b2Snia fi 2232007c8b2Snia shift 2242007c8b2Snia done 2252007c8b2Snia if test -n "$linker_opts"; then 2262007c8b2Snia linker_opts="-link$linker_opts" 2272007c8b2Snia fi 2282007c8b2Snia exec "$@" $linker_opts 2292007c8b2Snia exit 1 2302007c8b2Snia} 2312007c8b2Snia 2322007c8b2Sniaeat= 2332007c8b2Snia 2342007c8b2Sniacase $1 in 2352007c8b2Snia '') 2362007c8b2Snia echo "$0: No command. Try '$0 --help' for more information." 1>&2 2372007c8b2Snia exit 1; 2382007c8b2Snia ;; 2392007c8b2Snia -h | --h*) 2402007c8b2Snia cat <<\EOF 2412007c8b2SniaUsage: compile [--help] [--version] PROGRAM [ARGS] 2422007c8b2Snia 2432007c8b2SniaWrapper for compilers which do not understand '-c -o'. 2442007c8b2SniaRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 2452007c8b2Sniaarguments, and rename the output as expected. 2462007c8b2Snia 2472007c8b2SniaIf you are trying to build a whole package this is not the 2482007c8b2Sniaright script to run: please start by reading the file 'INSTALL'. 2492007c8b2Snia 2502007c8b2SniaReport bugs to <bug-automake@gnu.org>. 2512007c8b2SniaEOF 2522007c8b2Snia exit $? 2532007c8b2Snia ;; 2542007c8b2Snia -v | --v*) 2552007c8b2Snia echo "compile $scriptversion" 2562007c8b2Snia exit $? 2572007c8b2Snia ;; 2582007c8b2Snia cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 2592007c8b2Snia func_cl_wrapper "$@" # Doesn't return... 2602007c8b2Snia ;; 2612007c8b2Sniaesac 2622007c8b2Snia 2632007c8b2Sniaofile= 2642007c8b2Sniacfile= 2652007c8b2Snia 2662007c8b2Sniafor arg 2672007c8b2Sniado 2682007c8b2Snia if test -n "$eat"; then 2692007c8b2Snia eat= 2702007c8b2Snia else 2712007c8b2Snia case $1 in 2722007c8b2Snia -o) 2732007c8b2Snia # configure might choose to run compile as 'compile cc -o foo foo.c'. 2742007c8b2Snia # So we strip '-o arg' only if arg is an object. 2752007c8b2Snia eat=1 2762007c8b2Snia case $2 in 2772007c8b2Snia *.o | *.obj) 2782007c8b2Snia ofile=$2 2792007c8b2Snia ;; 2802007c8b2Snia *) 2812007c8b2Snia set x "$@" -o "$2" 2822007c8b2Snia shift 2832007c8b2Snia ;; 2842007c8b2Snia esac 2852007c8b2Snia ;; 2862007c8b2Snia *.c) 2872007c8b2Snia cfile=$1 2882007c8b2Snia set x "$@" "$1" 2892007c8b2Snia shift 2902007c8b2Snia ;; 2912007c8b2Snia *) 2922007c8b2Snia set x "$@" "$1" 2932007c8b2Snia shift 2942007c8b2Snia ;; 2952007c8b2Snia esac 2962007c8b2Snia fi 2972007c8b2Snia shift 2982007c8b2Sniadone 2992007c8b2Snia 3002007c8b2Sniaif test -z "$ofile" || test -z "$cfile"; then 3012007c8b2Snia # If no '-o' option was seen then we might have been invoked from a 3022007c8b2Snia # pattern rule where we don't need one. That is ok -- this is a 3032007c8b2Snia # normal compilation that the losing compiler can handle. If no 3042007c8b2Snia # '.c' file was seen then we are probably linking. That is also 3052007c8b2Snia # ok. 3062007c8b2Snia exec "$@" 3072007c8b2Sniafi 3082007c8b2Snia 3092007c8b2Snia# Name of file we expect compiler to create. 3102007c8b2Sniacofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 3112007c8b2Snia 3122007c8b2Snia# Create the lock directory. 3132007c8b2Snia# Note: use '[/\\:.-]' here to ensure that we don't use the same name 3142007c8b2Snia# that we are using for the .o file. Also, base the name on the expected 3152007c8b2Snia# object file name, since that is what matters with a parallel build. 3162007c8b2Snialockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 3172007c8b2Sniawhile true; do 3182007c8b2Snia if mkdir "$lockdir" >/dev/null 2>&1; then 3192007c8b2Snia break 3202007c8b2Snia fi 3212007c8b2Snia sleep 1 3222007c8b2Sniadone 3232007c8b2Snia# FIXME: race condition here if user kills between mkdir and trap. 3242007c8b2Sniatrap "rmdir '$lockdir'; exit 1" 1 2 15 3252007c8b2Snia 3262007c8b2Snia# Run the compile. 3272007c8b2Snia"$@" 3282007c8b2Sniaret=$? 3292007c8b2Snia 3302007c8b2Sniaif test -f "$cofile"; then 3312007c8b2Snia test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 3322007c8b2Sniaelif test -f "${cofile}bj"; then 3332007c8b2Snia test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 3342007c8b2Sniafi 3352007c8b2Snia 3362007c8b2Sniarmdir "$lockdir" 3372007c8b2Sniaexit $ret 3382007c8b2Snia 3392007c8b2Snia# Local Variables: 3402007c8b2Snia# mode: shell-script 3412007c8b2Snia# sh-indentation: 2 3422007c8b2Snia# eval: (add-hook 'write-file-hooks 'time-stamp) 3432007c8b2Snia# time-stamp-start: "scriptversion=" 3442007c8b2Snia# time-stamp-format: "%:y-%02m-%02d.%02H" 3452007c8b2Snia# time-stamp-time-zone: "UTC" 3462007c8b2Snia# time-stamp-end: "; # UTC" 3472007c8b2Snia# End: 348