14f00d7e1Smrg#! /bin/sh 24f00d7e1Smrg# Wrapper for compilers which do not understand '-c -o'. 34f00d7e1Smrg 44f00d7e1Smrgscriptversion=2012-10-14.11; # UTC 54f00d7e1Smrg 64f00d7e1Smrg# Copyright (C) 1999-2014 Free Software Foundation, Inc. 74f00d7e1Smrg# Written by Tom Tromey <tromey@cygnus.com>. 84f00d7e1Smrg# 94f00d7e1Smrg# This program is free software; you can redistribute it and/or modify 104f00d7e1Smrg# it under the terms of the GNU General Public License as published by 114f00d7e1Smrg# the Free Software Foundation; either version 2, or (at your option) 124f00d7e1Smrg# any later version. 134f00d7e1Smrg# 144f00d7e1Smrg# This program is distributed in the hope that it will be useful, 154f00d7e1Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 164f00d7e1Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 174f00d7e1Smrg# GNU General Public License for more details. 184f00d7e1Smrg# 194f00d7e1Smrg# You should have received a copy of the GNU General Public License 204f00d7e1Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 214f00d7e1Smrg 224f00d7e1Smrg# As a special exception to the GNU General Public License, if you 234f00d7e1Smrg# distribute this file as part of a program that contains a 244f00d7e1Smrg# configuration script generated by Autoconf, you may include it under 254f00d7e1Smrg# the same distribution terms that you use for the rest of that program. 264f00d7e1Smrg 274f00d7e1Smrg# This file is maintained in Automake, please report 284f00d7e1Smrg# bugs to <bug-automake@gnu.org> or send patches to 294f00d7e1Smrg# <automake-patches@gnu.org>. 304f00d7e1Smrg 314f00d7e1Smrgnl=' 324f00d7e1Smrg' 334f00d7e1Smrg 344f00d7e1Smrg# We need space, tab and new line, in precisely that order. Quoting is 354f00d7e1Smrg# there to prevent tools from complaining about whitespace usage. 364f00d7e1SmrgIFS=" "" $nl" 374f00d7e1Smrg 384f00d7e1Smrgfile_conv= 394f00d7e1Smrg 404f00d7e1Smrg# func_file_conv build_file lazy 414f00d7e1Smrg# Convert a $build file to $host form and store it in $file 424f00d7e1Smrg# Currently only supports Windows hosts. If the determined conversion 434f00d7e1Smrg# type is listed in (the comma separated) LAZY, no conversion will 444f00d7e1Smrg# take place. 454f00d7e1Smrgfunc_file_conv () 464f00d7e1Smrg{ 474f00d7e1Smrg file=$1 484f00d7e1Smrg case $file in 494f00d7e1Smrg / | /[!/]*) # absolute file, and not a UNC file 504f00d7e1Smrg if test -z "$file_conv"; then 514f00d7e1Smrg # lazily determine how to convert abs files 524f00d7e1Smrg case `uname -s` in 534f00d7e1Smrg MINGW*) 544f00d7e1Smrg file_conv=mingw 554f00d7e1Smrg ;; 564f00d7e1Smrg CYGWIN*) 574f00d7e1Smrg file_conv=cygwin 584f00d7e1Smrg ;; 594f00d7e1Smrg *) 604f00d7e1Smrg file_conv=wine 614f00d7e1Smrg ;; 624f00d7e1Smrg esac 634f00d7e1Smrg fi 644f00d7e1Smrg case $file_conv/,$2, in 654f00d7e1Smrg *,$file_conv,*) 664f00d7e1Smrg ;; 674f00d7e1Smrg mingw/*) 684f00d7e1Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 694f00d7e1Smrg ;; 704f00d7e1Smrg cygwin/*) 714f00d7e1Smrg file=`cygpath -m "$file" || echo "$file"` 724f00d7e1Smrg ;; 734f00d7e1Smrg wine/*) 744f00d7e1Smrg file=`winepath -w "$file" || echo "$file"` 754f00d7e1Smrg ;; 764f00d7e1Smrg esac 774f00d7e1Smrg ;; 784f00d7e1Smrg esac 794f00d7e1Smrg} 804f00d7e1Smrg 814f00d7e1Smrg# func_cl_dashL linkdir 824f00d7e1Smrg# Make cl look for libraries in LINKDIR 834f00d7e1Smrgfunc_cl_dashL () 844f00d7e1Smrg{ 854f00d7e1Smrg func_file_conv "$1" 864f00d7e1Smrg if test -z "$lib_path"; then 874f00d7e1Smrg lib_path=$file 884f00d7e1Smrg else 894f00d7e1Smrg lib_path="$lib_path;$file" 904f00d7e1Smrg fi 914f00d7e1Smrg linker_opts="$linker_opts -LIBPATH:$file" 924f00d7e1Smrg} 934f00d7e1Smrg 944f00d7e1Smrg# func_cl_dashl library 954f00d7e1Smrg# Do a library search-path lookup for cl 964f00d7e1Smrgfunc_cl_dashl () 974f00d7e1Smrg{ 984f00d7e1Smrg lib=$1 994f00d7e1Smrg found=no 1004f00d7e1Smrg save_IFS=$IFS 1014f00d7e1Smrg IFS=';' 1024f00d7e1Smrg for dir in $lib_path $LIB 1034f00d7e1Smrg do 1044f00d7e1Smrg IFS=$save_IFS 1054f00d7e1Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 1064f00d7e1Smrg found=yes 1074f00d7e1Smrg lib=$dir/$lib.dll.lib 1084f00d7e1Smrg break 1094f00d7e1Smrg fi 1104f00d7e1Smrg if test -f "$dir/$lib.lib"; then 1114f00d7e1Smrg found=yes 1124f00d7e1Smrg lib=$dir/$lib.lib 1134f00d7e1Smrg break 1144f00d7e1Smrg fi 1154f00d7e1Smrg if test -f "$dir/lib$lib.a"; then 1164f00d7e1Smrg found=yes 1174f00d7e1Smrg lib=$dir/lib$lib.a 1184f00d7e1Smrg break 1194f00d7e1Smrg fi 1204f00d7e1Smrg done 1214f00d7e1Smrg IFS=$save_IFS 1224f00d7e1Smrg 1234f00d7e1Smrg if test "$found" != yes; then 1244f00d7e1Smrg lib=$lib.lib 1254f00d7e1Smrg fi 1264f00d7e1Smrg} 1274f00d7e1Smrg 1284f00d7e1Smrg# func_cl_wrapper cl arg... 1294f00d7e1Smrg# Adjust compile command to suit cl 1304f00d7e1Smrgfunc_cl_wrapper () 1314f00d7e1Smrg{ 1324f00d7e1Smrg # Assume a capable shell 1334f00d7e1Smrg lib_path= 1344f00d7e1Smrg shared=: 1354f00d7e1Smrg linker_opts= 1364f00d7e1Smrg for arg 1374f00d7e1Smrg do 1384f00d7e1Smrg if test -n "$eat"; then 1394f00d7e1Smrg eat= 1404f00d7e1Smrg else 1414f00d7e1Smrg case $1 in 1424f00d7e1Smrg -o) 1434f00d7e1Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 1444f00d7e1Smrg eat=1 1454f00d7e1Smrg case $2 in 1464f00d7e1Smrg *.o | *.[oO][bB][jJ]) 1474f00d7e1Smrg func_file_conv "$2" 1484f00d7e1Smrg set x "$@" -Fo"$file" 1494f00d7e1Smrg shift 1504f00d7e1Smrg ;; 1514f00d7e1Smrg *) 1524f00d7e1Smrg func_file_conv "$2" 1534f00d7e1Smrg set x "$@" -Fe"$file" 1544f00d7e1Smrg shift 1554f00d7e1Smrg ;; 1564f00d7e1Smrg esac 1574f00d7e1Smrg ;; 1584f00d7e1Smrg -I) 1594f00d7e1Smrg eat=1 1604f00d7e1Smrg func_file_conv "$2" mingw 1614f00d7e1Smrg set x "$@" -I"$file" 1624f00d7e1Smrg shift 1634f00d7e1Smrg ;; 1644f00d7e1Smrg -I*) 1654f00d7e1Smrg func_file_conv "${1#-I}" mingw 1664f00d7e1Smrg set x "$@" -I"$file" 1674f00d7e1Smrg shift 1684f00d7e1Smrg ;; 1694f00d7e1Smrg -l) 1704f00d7e1Smrg eat=1 1714f00d7e1Smrg func_cl_dashl "$2" 1724f00d7e1Smrg set x "$@" "$lib" 1734f00d7e1Smrg shift 1744f00d7e1Smrg ;; 1754f00d7e1Smrg -l*) 1764f00d7e1Smrg func_cl_dashl "${1#-l}" 1774f00d7e1Smrg set x "$@" "$lib" 1784f00d7e1Smrg shift 1794f00d7e1Smrg ;; 1804f00d7e1Smrg -L) 1814f00d7e1Smrg eat=1 1824f00d7e1Smrg func_cl_dashL "$2" 1834f00d7e1Smrg ;; 1844f00d7e1Smrg -L*) 1854f00d7e1Smrg func_cl_dashL "${1#-L}" 1864f00d7e1Smrg ;; 1874f00d7e1Smrg -static) 1884f00d7e1Smrg shared=false 1894f00d7e1Smrg ;; 1904f00d7e1Smrg -Wl,*) 1914f00d7e1Smrg arg=${1#-Wl,} 1924f00d7e1Smrg save_ifs="$IFS"; IFS=',' 1934f00d7e1Smrg for flag in $arg; do 1944f00d7e1Smrg IFS="$save_ifs" 1954f00d7e1Smrg linker_opts="$linker_opts $flag" 1964f00d7e1Smrg done 1974f00d7e1Smrg IFS="$save_ifs" 1984f00d7e1Smrg ;; 1994f00d7e1Smrg -Xlinker) 2004f00d7e1Smrg eat=1 2014f00d7e1Smrg linker_opts="$linker_opts $2" 2024f00d7e1Smrg ;; 2034f00d7e1Smrg -*) 2044f00d7e1Smrg set x "$@" "$1" 2054f00d7e1Smrg shift 2064f00d7e1Smrg ;; 2074f00d7e1Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 2084f00d7e1Smrg func_file_conv "$1" 2094f00d7e1Smrg set x "$@" -Tp"$file" 2104f00d7e1Smrg shift 2114f00d7e1Smrg ;; 2124f00d7e1Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2134f00d7e1Smrg func_file_conv "$1" mingw 2144f00d7e1Smrg set x "$@" "$file" 2154f00d7e1Smrg shift 2164f00d7e1Smrg ;; 2174f00d7e1Smrg *) 2184f00d7e1Smrg set x "$@" "$1" 2194f00d7e1Smrg shift 2204f00d7e1Smrg ;; 2214f00d7e1Smrg esac 2224f00d7e1Smrg fi 2234f00d7e1Smrg shift 2244f00d7e1Smrg done 2254f00d7e1Smrg if test -n "$linker_opts"; then 2264f00d7e1Smrg linker_opts="-link$linker_opts" 2274f00d7e1Smrg fi 2284f00d7e1Smrg exec "$@" $linker_opts 2294f00d7e1Smrg exit 1 2304f00d7e1Smrg} 2314f00d7e1Smrg 2324f00d7e1Smrgeat= 2334f00d7e1Smrg 2344f00d7e1Smrgcase $1 in 2354f00d7e1Smrg '') 2364f00d7e1Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 2374f00d7e1Smrg exit 1; 2384f00d7e1Smrg ;; 2394f00d7e1Smrg -h | --h*) 2404f00d7e1Smrg cat <<\EOF 2414f00d7e1SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 2424f00d7e1Smrg 2434f00d7e1SmrgWrapper for compilers which do not understand '-c -o'. 2444f00d7e1SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 2454f00d7e1Smrgarguments, and rename the output as expected. 2464f00d7e1Smrg 2474f00d7e1SmrgIf you are trying to build a whole package this is not the 2484f00d7e1Smrgright script to run: please start by reading the file 'INSTALL'. 2494f00d7e1Smrg 2504f00d7e1SmrgReport bugs to <bug-automake@gnu.org>. 2514f00d7e1SmrgEOF 2524f00d7e1Smrg exit $? 2534f00d7e1Smrg ;; 2544f00d7e1Smrg -v | --v*) 2554f00d7e1Smrg echo "compile $scriptversion" 2564f00d7e1Smrg exit $? 2574f00d7e1Smrg ;; 2584f00d7e1Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 2594f00d7e1Smrg func_cl_wrapper "$@" # Doesn't return... 2604f00d7e1Smrg ;; 2614f00d7e1Smrgesac 2624f00d7e1Smrg 2634f00d7e1Smrgofile= 2644f00d7e1Smrgcfile= 2654f00d7e1Smrg 2664f00d7e1Smrgfor arg 2674f00d7e1Smrgdo 2684f00d7e1Smrg if test -n "$eat"; then 2694f00d7e1Smrg eat= 2704f00d7e1Smrg else 2714f00d7e1Smrg case $1 in 2724f00d7e1Smrg -o) 2734f00d7e1Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 2744f00d7e1Smrg # So we strip '-o arg' only if arg is an object. 2754f00d7e1Smrg eat=1 2764f00d7e1Smrg case $2 in 2774f00d7e1Smrg *.o | *.obj) 2784f00d7e1Smrg ofile=$2 2794f00d7e1Smrg ;; 2804f00d7e1Smrg *) 2814f00d7e1Smrg set x "$@" -o "$2" 2824f00d7e1Smrg shift 2834f00d7e1Smrg ;; 2844f00d7e1Smrg esac 2854f00d7e1Smrg ;; 2864f00d7e1Smrg *.c) 2874f00d7e1Smrg cfile=$1 2884f00d7e1Smrg set x "$@" "$1" 2894f00d7e1Smrg shift 2904f00d7e1Smrg ;; 2914f00d7e1Smrg *) 2924f00d7e1Smrg set x "$@" "$1" 2934f00d7e1Smrg shift 2944f00d7e1Smrg ;; 2954f00d7e1Smrg esac 2964f00d7e1Smrg fi 2974f00d7e1Smrg shift 2984f00d7e1Smrgdone 2994f00d7e1Smrg 3004f00d7e1Smrgif test -z "$ofile" || test -z "$cfile"; then 3014f00d7e1Smrg # If no '-o' option was seen then we might have been invoked from a 3024f00d7e1Smrg # pattern rule where we don't need one. That is ok -- this is a 3034f00d7e1Smrg # normal compilation that the losing compiler can handle. If no 3044f00d7e1Smrg # '.c' file was seen then we are probably linking. That is also 3054f00d7e1Smrg # ok. 3064f00d7e1Smrg exec "$@" 3074f00d7e1Smrgfi 3084f00d7e1Smrg 3094f00d7e1Smrg# Name of file we expect compiler to create. 3104f00d7e1Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 3114f00d7e1Smrg 3124f00d7e1Smrg# Create the lock directory. 3134f00d7e1Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 3144f00d7e1Smrg# that we are using for the .o file. Also, base the name on the expected 3154f00d7e1Smrg# object file name, since that is what matters with a parallel build. 3164f00d7e1Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 3174f00d7e1Smrgwhile true; do 3184f00d7e1Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 3194f00d7e1Smrg break 3204f00d7e1Smrg fi 3214f00d7e1Smrg sleep 1 3224f00d7e1Smrgdone 3234f00d7e1Smrg# FIXME: race condition here if user kills between mkdir and trap. 3244f00d7e1Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 3254f00d7e1Smrg 3264f00d7e1Smrg# Run the compile. 3274f00d7e1Smrg"$@" 3284f00d7e1Smrgret=$? 3294f00d7e1Smrg 3304f00d7e1Smrgif test -f "$cofile"; then 3314f00d7e1Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 3324f00d7e1Smrgelif test -f "${cofile}bj"; then 3334f00d7e1Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 3344f00d7e1Smrgfi 3354f00d7e1Smrg 3364f00d7e1Smrgrmdir "$lockdir" 3374f00d7e1Smrgexit $ret 3384f00d7e1Smrg 3394f00d7e1Smrg# Local Variables: 3404f00d7e1Smrg# mode: shell-script 3414f00d7e1Smrg# sh-indentation: 2 3424f00d7e1Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 3434f00d7e1Smrg# time-stamp-start: "scriptversion=" 3444f00d7e1Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 3454f00d7e1Smrg# time-stamp-time-zone: "UTC" 3464f00d7e1Smrg# time-stamp-end: "; # UTC" 3474f00d7e1Smrg# End: 348