15fbb4066Smrg#! /bin/sh 25fbb4066Smrg# Wrapper for compilers which do not understand '-c -o'. 35fbb4066Smrg 48ae5c7d9Smrgscriptversion=2018-03-07.03; # UTC 55fbb4066Smrg 68ae5c7d9Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc. 75fbb4066Smrg# Written by Tom Tromey <tromey@cygnus.com>. 85fbb4066Smrg# 95fbb4066Smrg# This program is free software; you can redistribute it and/or modify 105fbb4066Smrg# it under the terms of the GNU General Public License as published by 115fbb4066Smrg# the Free Software Foundation; either version 2, or (at your option) 125fbb4066Smrg# any later version. 135fbb4066Smrg# 145fbb4066Smrg# This program is distributed in the hope that it will be useful, 155fbb4066Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 165fbb4066Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 175fbb4066Smrg# GNU General Public License for more details. 185fbb4066Smrg# 195fbb4066Smrg# You should have received a copy of the GNU General Public License 208ae5c7d9Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 215fbb4066Smrg 225fbb4066Smrg# As a special exception to the GNU General Public License, if you 235fbb4066Smrg# distribute this file as part of a program that contains a 245fbb4066Smrg# configuration script generated by Autoconf, you may include it under 255fbb4066Smrg# the same distribution terms that you use for the rest of that program. 265fbb4066Smrg 275fbb4066Smrg# This file is maintained in Automake, please report 285fbb4066Smrg# bugs to <bug-automake@gnu.org> or send patches to 295fbb4066Smrg# <automake-patches@gnu.org>. 305fbb4066Smrg 315fbb4066Smrgnl=' 325fbb4066Smrg' 335fbb4066Smrg 345fbb4066Smrg# We need space, tab and new line, in precisely that order. Quoting is 355fbb4066Smrg# there to prevent tools from complaining about whitespace usage. 365fbb4066SmrgIFS=" "" $nl" 375fbb4066Smrg 385fbb4066Smrgfile_conv= 395fbb4066Smrg 405fbb4066Smrg# func_file_conv build_file lazy 415fbb4066Smrg# Convert a $build file to $host form and store it in $file 425fbb4066Smrg# Currently only supports Windows hosts. If the determined conversion 435fbb4066Smrg# type is listed in (the comma separated) LAZY, no conversion will 445fbb4066Smrg# take place. 455fbb4066Smrgfunc_file_conv () 465fbb4066Smrg{ 475fbb4066Smrg file=$1 485fbb4066Smrg case $file in 495fbb4066Smrg / | /[!/]*) # absolute file, and not a UNC file 505fbb4066Smrg if test -z "$file_conv"; then 515fbb4066Smrg # lazily determine how to convert abs files 525fbb4066Smrg case `uname -s` in 535fbb4066Smrg MINGW*) 545fbb4066Smrg file_conv=mingw 555fbb4066Smrg ;; 568ae5c7d9Smrg CYGWIN* | MSYS*) 575fbb4066Smrg file_conv=cygwin 585fbb4066Smrg ;; 595fbb4066Smrg *) 605fbb4066Smrg file_conv=wine 615fbb4066Smrg ;; 625fbb4066Smrg esac 635fbb4066Smrg fi 645fbb4066Smrg case $file_conv/,$2, in 655fbb4066Smrg *,$file_conv,*) 665fbb4066Smrg ;; 675fbb4066Smrg mingw/*) 685fbb4066Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 695fbb4066Smrg ;; 708ae5c7d9Smrg cygwin/* | msys/*) 715fbb4066Smrg file=`cygpath -m "$file" || echo "$file"` 725fbb4066Smrg ;; 735fbb4066Smrg wine/*) 745fbb4066Smrg file=`winepath -w "$file" || echo "$file"` 755fbb4066Smrg ;; 765fbb4066Smrg esac 775fbb4066Smrg ;; 785fbb4066Smrg esac 795fbb4066Smrg} 805fbb4066Smrg 815fbb4066Smrg# func_cl_dashL linkdir 825fbb4066Smrg# Make cl look for libraries in LINKDIR 835fbb4066Smrgfunc_cl_dashL () 845fbb4066Smrg{ 855fbb4066Smrg func_file_conv "$1" 865fbb4066Smrg if test -z "$lib_path"; then 875fbb4066Smrg lib_path=$file 885fbb4066Smrg else 895fbb4066Smrg lib_path="$lib_path;$file" 905fbb4066Smrg fi 915fbb4066Smrg linker_opts="$linker_opts -LIBPATH:$file" 925fbb4066Smrg} 935fbb4066Smrg 945fbb4066Smrg# func_cl_dashl library 955fbb4066Smrg# Do a library search-path lookup for cl 965fbb4066Smrgfunc_cl_dashl () 975fbb4066Smrg{ 985fbb4066Smrg lib=$1 995fbb4066Smrg found=no 1005fbb4066Smrg save_IFS=$IFS 1015fbb4066Smrg IFS=';' 1025fbb4066Smrg for dir in $lib_path $LIB 1035fbb4066Smrg do 1045fbb4066Smrg IFS=$save_IFS 1055fbb4066Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 1065fbb4066Smrg found=yes 1075fbb4066Smrg lib=$dir/$lib.dll.lib 1085fbb4066Smrg break 1095fbb4066Smrg fi 1105fbb4066Smrg if test -f "$dir/$lib.lib"; then 1115fbb4066Smrg found=yes 1125fbb4066Smrg lib=$dir/$lib.lib 1135fbb4066Smrg break 1145fbb4066Smrg fi 1155fbb4066Smrg if test -f "$dir/lib$lib.a"; then 1165fbb4066Smrg found=yes 1175fbb4066Smrg lib=$dir/lib$lib.a 1185fbb4066Smrg break 1195fbb4066Smrg fi 1205fbb4066Smrg done 1215fbb4066Smrg IFS=$save_IFS 1225fbb4066Smrg 1235fbb4066Smrg if test "$found" != yes; then 1245fbb4066Smrg lib=$lib.lib 1255fbb4066Smrg fi 1265fbb4066Smrg} 1275fbb4066Smrg 1285fbb4066Smrg# func_cl_wrapper cl arg... 1295fbb4066Smrg# Adjust compile command to suit cl 1305fbb4066Smrgfunc_cl_wrapper () 1315fbb4066Smrg{ 1325fbb4066Smrg # Assume a capable shell 1335fbb4066Smrg lib_path= 1345fbb4066Smrg shared=: 1355fbb4066Smrg linker_opts= 1365fbb4066Smrg for arg 1375fbb4066Smrg do 1385fbb4066Smrg if test -n "$eat"; then 1395fbb4066Smrg eat= 1405fbb4066Smrg else 1415fbb4066Smrg case $1 in 1425fbb4066Smrg -o) 1435fbb4066Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 1445fbb4066Smrg eat=1 1455fbb4066Smrg case $2 in 1465fbb4066Smrg *.o | *.[oO][bB][jJ]) 1475fbb4066Smrg func_file_conv "$2" 1485fbb4066Smrg set x "$@" -Fo"$file" 1495fbb4066Smrg shift 1505fbb4066Smrg ;; 1515fbb4066Smrg *) 1525fbb4066Smrg func_file_conv "$2" 1535fbb4066Smrg set x "$@" -Fe"$file" 1545fbb4066Smrg shift 1555fbb4066Smrg ;; 1565fbb4066Smrg esac 1575fbb4066Smrg ;; 1585fbb4066Smrg -I) 1595fbb4066Smrg eat=1 1605fbb4066Smrg func_file_conv "$2" mingw 1615fbb4066Smrg set x "$@" -I"$file" 1625fbb4066Smrg shift 1635fbb4066Smrg ;; 1645fbb4066Smrg -I*) 1655fbb4066Smrg func_file_conv "${1#-I}" mingw 1665fbb4066Smrg set x "$@" -I"$file" 1675fbb4066Smrg shift 1685fbb4066Smrg ;; 1695fbb4066Smrg -l) 1705fbb4066Smrg eat=1 1715fbb4066Smrg func_cl_dashl "$2" 1725fbb4066Smrg set x "$@" "$lib" 1735fbb4066Smrg shift 1745fbb4066Smrg ;; 1755fbb4066Smrg -l*) 1765fbb4066Smrg func_cl_dashl "${1#-l}" 1775fbb4066Smrg set x "$@" "$lib" 1785fbb4066Smrg shift 1795fbb4066Smrg ;; 1805fbb4066Smrg -L) 1815fbb4066Smrg eat=1 1825fbb4066Smrg func_cl_dashL "$2" 1835fbb4066Smrg ;; 1845fbb4066Smrg -L*) 1855fbb4066Smrg func_cl_dashL "${1#-L}" 1865fbb4066Smrg ;; 1875fbb4066Smrg -static) 1885fbb4066Smrg shared=false 1895fbb4066Smrg ;; 1905fbb4066Smrg -Wl,*) 1915fbb4066Smrg arg=${1#-Wl,} 1925fbb4066Smrg save_ifs="$IFS"; IFS=',' 1935fbb4066Smrg for flag in $arg; do 1945fbb4066Smrg IFS="$save_ifs" 1955fbb4066Smrg linker_opts="$linker_opts $flag" 1965fbb4066Smrg done 1975fbb4066Smrg IFS="$save_ifs" 1985fbb4066Smrg ;; 1995fbb4066Smrg -Xlinker) 2005fbb4066Smrg eat=1 2015fbb4066Smrg linker_opts="$linker_opts $2" 2025fbb4066Smrg ;; 2035fbb4066Smrg -*) 2045fbb4066Smrg set x "$@" "$1" 2055fbb4066Smrg shift 2065fbb4066Smrg ;; 2075fbb4066Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 2085fbb4066Smrg func_file_conv "$1" 2095fbb4066Smrg set x "$@" -Tp"$file" 2105fbb4066Smrg shift 2115fbb4066Smrg ;; 2125fbb4066Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2135fbb4066Smrg func_file_conv "$1" mingw 2145fbb4066Smrg set x "$@" "$file" 2155fbb4066Smrg shift 2165fbb4066Smrg ;; 2175fbb4066Smrg *) 2185fbb4066Smrg set x "$@" "$1" 2195fbb4066Smrg shift 2205fbb4066Smrg ;; 2215fbb4066Smrg esac 2225fbb4066Smrg fi 2235fbb4066Smrg shift 2245fbb4066Smrg done 2255fbb4066Smrg if test -n "$linker_opts"; then 2265fbb4066Smrg linker_opts="-link$linker_opts" 2275fbb4066Smrg fi 2285fbb4066Smrg exec "$@" $linker_opts 2295fbb4066Smrg exit 1 2305fbb4066Smrg} 2315fbb4066Smrg 2325fbb4066Smrgeat= 2335fbb4066Smrg 2345fbb4066Smrgcase $1 in 2355fbb4066Smrg '') 2365fbb4066Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 2375fbb4066Smrg exit 1; 2385fbb4066Smrg ;; 2395fbb4066Smrg -h | --h*) 2405fbb4066Smrg cat <<\EOF 2415fbb4066SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 2425fbb4066Smrg 2435fbb4066SmrgWrapper for compilers which do not understand '-c -o'. 2445fbb4066SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 2455fbb4066Smrgarguments, and rename the output as expected. 2465fbb4066Smrg 2475fbb4066SmrgIf you are trying to build a whole package this is not the 2485fbb4066Smrgright script to run: please start by reading the file 'INSTALL'. 2495fbb4066Smrg 2505fbb4066SmrgReport bugs to <bug-automake@gnu.org>. 2515fbb4066SmrgEOF 2525fbb4066Smrg exit $? 2535fbb4066Smrg ;; 2545fbb4066Smrg -v | --v*) 2555fbb4066Smrg echo "compile $scriptversion" 2565fbb4066Smrg exit $? 2575fbb4066Smrg ;; 2588ae5c7d9Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 2598ae5c7d9Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 2605fbb4066Smrg func_cl_wrapper "$@" # Doesn't return... 2615fbb4066Smrg ;; 2625fbb4066Smrgesac 2635fbb4066Smrg 2645fbb4066Smrgofile= 2655fbb4066Smrgcfile= 2665fbb4066Smrg 2675fbb4066Smrgfor arg 2685fbb4066Smrgdo 2695fbb4066Smrg if test -n "$eat"; then 2705fbb4066Smrg eat= 2715fbb4066Smrg else 2725fbb4066Smrg case $1 in 2735fbb4066Smrg -o) 2745fbb4066Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 2755fbb4066Smrg # So we strip '-o arg' only if arg is an object. 2765fbb4066Smrg eat=1 2775fbb4066Smrg case $2 in 2785fbb4066Smrg *.o | *.obj) 2795fbb4066Smrg ofile=$2 2805fbb4066Smrg ;; 2815fbb4066Smrg *) 2825fbb4066Smrg set x "$@" -o "$2" 2835fbb4066Smrg shift 2845fbb4066Smrg ;; 2855fbb4066Smrg esac 2865fbb4066Smrg ;; 2875fbb4066Smrg *.c) 2885fbb4066Smrg cfile=$1 2895fbb4066Smrg set x "$@" "$1" 2905fbb4066Smrg shift 2915fbb4066Smrg ;; 2925fbb4066Smrg *) 2935fbb4066Smrg set x "$@" "$1" 2945fbb4066Smrg shift 2955fbb4066Smrg ;; 2965fbb4066Smrg esac 2975fbb4066Smrg fi 2985fbb4066Smrg shift 2995fbb4066Smrgdone 3005fbb4066Smrg 3015fbb4066Smrgif test -z "$ofile" || test -z "$cfile"; then 3025fbb4066Smrg # If no '-o' option was seen then we might have been invoked from a 3035fbb4066Smrg # pattern rule where we don't need one. That is ok -- this is a 3045fbb4066Smrg # normal compilation that the losing compiler can handle. If no 3055fbb4066Smrg # '.c' file was seen then we are probably linking. That is also 3065fbb4066Smrg # ok. 3075fbb4066Smrg exec "$@" 3085fbb4066Smrgfi 3095fbb4066Smrg 3105fbb4066Smrg# Name of file we expect compiler to create. 3115fbb4066Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 3125fbb4066Smrg 3135fbb4066Smrg# Create the lock directory. 3145fbb4066Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 3155fbb4066Smrg# that we are using for the .o file. Also, base the name on the expected 3165fbb4066Smrg# object file name, since that is what matters with a parallel build. 3175fbb4066Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 3185fbb4066Smrgwhile true; do 3195fbb4066Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 3205fbb4066Smrg break 3215fbb4066Smrg fi 3225fbb4066Smrg sleep 1 3235fbb4066Smrgdone 3245fbb4066Smrg# FIXME: race condition here if user kills between mkdir and trap. 3255fbb4066Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 3265fbb4066Smrg 3275fbb4066Smrg# Run the compile. 3285fbb4066Smrg"$@" 3295fbb4066Smrgret=$? 3305fbb4066Smrg 3315fbb4066Smrgif test -f "$cofile"; then 3325fbb4066Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 3335fbb4066Smrgelif test -f "${cofile}bj"; then 3345fbb4066Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 3355fbb4066Smrgfi 3365fbb4066Smrg 3375fbb4066Smrgrmdir "$lockdir" 3385fbb4066Smrgexit $ret 3395fbb4066Smrg 3405fbb4066Smrg# Local Variables: 3415fbb4066Smrg# mode: shell-script 3425fbb4066Smrg# sh-indentation: 2 3438ae5c7d9Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 3445fbb4066Smrg# time-stamp-start: "scriptversion=" 3455fbb4066Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 3468ae5c7d9Smrg# time-stamp-time-zone: "UTC0" 3475fbb4066Smrg# time-stamp-end: "; # UTC" 3485fbb4066Smrg# End: 349