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