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