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