12c7c4e3dSmrg#! /bin/sh 22becc446Smrg# Wrapper for compilers which do not understand '-c -o'. 32c7c4e3dSmrg 4c1e8faa6Smrgscriptversion=2024-06-19.01; # UTC 52c7c4e3dSmrg 6c1e8faa6Smrg# Copyright (C) 1999-2024 Free Software Foundation, Inc. 72c7c4e3dSmrg# Written by Tom Tromey <tromey@cygnus.com>. 82c7c4e3dSmrg# 92c7c4e3dSmrg# This program is free software; you can redistribute it and/or modify 102c7c4e3dSmrg# it under the terms of the GNU General Public License as published by 112c7c4e3dSmrg# the Free Software Foundation; either version 2, or (at your option) 122c7c4e3dSmrg# any later version. 132c7c4e3dSmrg# 142c7c4e3dSmrg# This program is distributed in the hope that it will be useful, 152c7c4e3dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 162c7c4e3dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 172c7c4e3dSmrg# GNU General Public License for more details. 182c7c4e3dSmrg# 192c7c4e3dSmrg# You should have received a copy of the GNU General Public License 203458e6c2Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 212c7c4e3dSmrg 222c7c4e3dSmrg# As a special exception to the GNU General Public License, if you 232c7c4e3dSmrg# distribute this file as part of a program that contains a 242c7c4e3dSmrg# configuration script generated by Autoconf, you may include it under 252c7c4e3dSmrg# the same distribution terms that you use for the rest of that program. 262c7c4e3dSmrg 272becc446Smrg# This file is maintained in Automake, please report 282becc446Smrg# bugs to <bug-automake@gnu.org> or send patches to 292becc446Smrg# <automake-patches@gnu.org>. 302c7c4e3dSmrg 312becc446Smrgnl=' 322becc446Smrg' 332becc446Smrg 342becc446Smrg# We need space, tab and new line, in precisely that order. Quoting is 352becc446Smrg# there to prevent tools from complaining about whitespace usage. 362becc446SmrgIFS=" "" $nl" 372becc446Smrg 382becc446Smrgfile_conv= 392becc446Smrg 402becc446Smrg# func_file_conv build_file lazy 412becc446Smrg# Convert a $build file to $host form and store it in $file 422becc446Smrg# Currently only supports Windows hosts. If the determined conversion 432becc446Smrg# type is listed in (the comma separated) LAZY, no conversion will 442becc446Smrg# take place. 452becc446Smrgfunc_file_conv () 462becc446Smrg{ 472becc446Smrg file=$1 482becc446Smrg case $file in 492becc446Smrg / | /[!/]*) # absolute file, and not a UNC file 502becc446Smrg if test -z "$file_conv"; then 512becc446Smrg # lazily determine how to convert abs files 522becc446Smrg case `uname -s` in 532becc446Smrg MINGW*) 542becc446Smrg file_conv=mingw 552becc446Smrg ;; 563458e6c2Smrg CYGWIN* | MSYS*) 572becc446Smrg file_conv=cygwin 582becc446Smrg ;; 592becc446Smrg *) 602becc446Smrg file_conv=wine 612becc446Smrg ;; 622becc446Smrg esac 632becc446Smrg fi 642becc446Smrg case $file_conv/,$2, in 652becc446Smrg *,$file_conv,*) 662becc446Smrg ;; 672becc446Smrg mingw/*) 682becc446Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 692becc446Smrg ;; 703458e6c2Smrg cygwin/* | msys/*) 712becc446Smrg file=`cygpath -m "$file" || echo "$file"` 722becc446Smrg ;; 732becc446Smrg wine/*) 742becc446Smrg file=`winepath -w "$file" || echo "$file"` 752becc446Smrg ;; 762becc446Smrg esac 772becc446Smrg ;; 782becc446Smrg esac 792becc446Smrg} 802becc446Smrg 812becc446Smrg# func_cl_dashL linkdir 822becc446Smrg# Make cl look for libraries in LINKDIR 832becc446Smrgfunc_cl_dashL () 842becc446Smrg{ 852becc446Smrg func_file_conv "$1" 862becc446Smrg if test -z "$lib_path"; then 872becc446Smrg lib_path=$file 882becc446Smrg else 892becc446Smrg lib_path="$lib_path;$file" 902becc446Smrg fi 912becc446Smrg linker_opts="$linker_opts -LIBPATH:$file" 922becc446Smrg} 932becc446Smrg 942becc446Smrg# func_cl_dashl library 952becc446Smrg# Do a library search-path lookup for cl 962becc446Smrgfunc_cl_dashl () 972becc446Smrg{ 982becc446Smrg lib=$1 992becc446Smrg found=no 1002becc446Smrg save_IFS=$IFS 1012becc446Smrg IFS=';' 1022becc446Smrg for dir in $lib_path $LIB 1032becc446Smrg do 1042becc446Smrg IFS=$save_IFS 1052becc446Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 1062becc446Smrg found=yes 1072becc446Smrg lib=$dir/$lib.dll.lib 1082becc446Smrg break 1092becc446Smrg fi 1102becc446Smrg if test -f "$dir/$lib.lib"; then 1112becc446Smrg found=yes 1122becc446Smrg lib=$dir/$lib.lib 1132becc446Smrg break 1142becc446Smrg fi 1152becc446Smrg if test -f "$dir/lib$lib.a"; then 1162becc446Smrg found=yes 1172becc446Smrg lib=$dir/lib$lib.a 1182becc446Smrg break 1192becc446Smrg fi 1202becc446Smrg done 1212becc446Smrg IFS=$save_IFS 1222becc446Smrg 1232becc446Smrg if test "$found" != yes; then 1242becc446Smrg lib=$lib.lib 1252becc446Smrg fi 1262becc446Smrg} 1272becc446Smrg 1282becc446Smrg# func_cl_wrapper cl arg... 1292becc446Smrg# Adjust compile command to suit cl 1302becc446Smrgfunc_cl_wrapper () 1312becc446Smrg{ 1322becc446Smrg # Assume a capable shell 1332becc446Smrg lib_path= 1342becc446Smrg shared=: 1352becc446Smrg linker_opts= 1362becc446Smrg for arg 1372becc446Smrg do 1382becc446Smrg if test -n "$eat"; then 1392becc446Smrg eat= 1402becc446Smrg else 1412becc446Smrg case $1 in 1422becc446Smrg -o) 1432becc446Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 1442becc446Smrg eat=1 1452becc446Smrg case $2 in 146c1e8faa6Smrg *.o | *.lo | *.[oO][bB][jJ]) 1472becc446Smrg func_file_conv "$2" 1482becc446Smrg set x "$@" -Fo"$file" 1492becc446Smrg shift 1502becc446Smrg ;; 1512becc446Smrg *) 1522becc446Smrg func_file_conv "$2" 1532becc446Smrg set x "$@" -Fe"$file" 1542becc446Smrg shift 1552becc446Smrg ;; 1562becc446Smrg esac 1572becc446Smrg ;; 1582becc446Smrg -I) 1592becc446Smrg eat=1 1602becc446Smrg func_file_conv "$2" mingw 1612becc446Smrg set x "$@" -I"$file" 1622becc446Smrg shift 1632becc446Smrg ;; 1642becc446Smrg -I*) 1652becc446Smrg func_file_conv "${1#-I}" mingw 1662becc446Smrg set x "$@" -I"$file" 1672becc446Smrg shift 1682becc446Smrg ;; 1692becc446Smrg -l) 1702becc446Smrg eat=1 1712becc446Smrg func_cl_dashl "$2" 1722becc446Smrg set x "$@" "$lib" 1732becc446Smrg shift 1742becc446Smrg ;; 1752becc446Smrg -l*) 1762becc446Smrg func_cl_dashl "${1#-l}" 1772becc446Smrg set x "$@" "$lib" 1782becc446Smrg shift 1792becc446Smrg ;; 1802becc446Smrg -L) 1812becc446Smrg eat=1 1822becc446Smrg func_cl_dashL "$2" 1832becc446Smrg ;; 1842becc446Smrg -L*) 1852becc446Smrg func_cl_dashL "${1#-L}" 1862becc446Smrg ;; 1872becc446Smrg -static) 1882becc446Smrg shared=false 1892becc446Smrg ;; 1902becc446Smrg -Wl,*) 1912becc446Smrg arg=${1#-Wl,} 1922becc446Smrg save_ifs="$IFS"; IFS=',' 1932becc446Smrg for flag in $arg; do 1942becc446Smrg IFS="$save_ifs" 1952becc446Smrg linker_opts="$linker_opts $flag" 1962becc446Smrg done 1972becc446Smrg IFS="$save_ifs" 1982becc446Smrg ;; 1992becc446Smrg -Xlinker) 2002becc446Smrg eat=1 2012becc446Smrg linker_opts="$linker_opts $2" 2022becc446Smrg ;; 2032becc446Smrg -*) 2042becc446Smrg set x "$@" "$1" 2052becc446Smrg shift 2062becc446Smrg ;; 2072becc446Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 2082becc446Smrg func_file_conv "$1" 2092becc446Smrg set x "$@" -Tp"$file" 2102becc446Smrg shift 2112becc446Smrg ;; 2122becc446Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2132becc446Smrg func_file_conv "$1" mingw 2142becc446Smrg set x "$@" "$file" 2152becc446Smrg shift 2162becc446Smrg ;; 2172becc446Smrg *) 2182becc446Smrg set x "$@" "$1" 2192becc446Smrg shift 2202becc446Smrg ;; 2212becc446Smrg esac 2222becc446Smrg fi 2232becc446Smrg shift 2242becc446Smrg done 2252becc446Smrg if test -n "$linker_opts"; then 2262becc446Smrg linker_opts="-link$linker_opts" 2272becc446Smrg fi 2282becc446Smrg exec "$@" $linker_opts 2292becc446Smrg exit 1 2302becc446Smrg} 2312becc446Smrg 2322becc446Smrgeat= 2332becc446Smrg 2342becc446Smrgcase $1 in 2352becc446Smrg '') 2362becc446Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 2372becc446Smrg exit 1; 2382becc446Smrg ;; 2392becc446Smrg -h | --h*) 2402becc446Smrg cat <<\EOF 2412becc446SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 2422becc446Smrg 2432becc446SmrgWrapper for compilers which do not understand '-c -o'. 2442becc446SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 2452becc446Smrgarguments, and rename the output as expected. 2462becc446Smrg 2472becc446SmrgIf you are trying to build a whole package this is not the 2482becc446Smrgright script to run: please start by reading the file 'INSTALL'. 2492becc446Smrg 2502becc446SmrgReport bugs to <bug-automake@gnu.org>. 251c1e8faa6SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 252c1e8faa6SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 2532becc446SmrgEOF 2542becc446Smrg exit $? 2552becc446Smrg ;; 2562becc446Smrg -v | --v*) 257c1e8faa6Smrg echo "compile (GNU Automake) $scriptversion" 2582becc446Smrg exit $? 2592becc446Smrg ;; 2603458e6c2Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 261c1e8faa6Smrg clang-cl | *[/\\]clang-cl | clang-cl.exe | *[/\\]clang-cl.exe | \ 2623458e6c2Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 2632becc446Smrg func_cl_wrapper "$@" # Doesn't return... 2642becc446Smrg ;; 2652becc446Smrgesac 2662c7c4e3dSmrg 2672c7c4e3dSmrgofile= 2682c7c4e3dSmrgcfile= 2692becc446Smrg 2702becc446Smrgfor arg 2712becc446Smrgdo 2722becc446Smrg if test -n "$eat"; then 2732becc446Smrg eat= 2742becc446Smrg else 2752becc446Smrg case $1 in 2762becc446Smrg -o) 2772becc446Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 2782becc446Smrg # So we strip '-o arg' only if arg is an object. 2792becc446Smrg eat=1 2802becc446Smrg case $2 in 2812becc446Smrg *.o | *.obj) 2822becc446Smrg ofile=$2 2832becc446Smrg ;; 2842becc446Smrg *) 2852becc446Smrg set x "$@" -o "$2" 2862becc446Smrg shift 2872becc446Smrg ;; 2882becc446Smrg esac 2892becc446Smrg ;; 2902becc446Smrg *.c) 2912becc446Smrg cfile=$1 2922becc446Smrg set x "$@" "$1" 2932becc446Smrg shift 2942becc446Smrg ;; 2952becc446Smrg *) 2962becc446Smrg set x "$@" "$1" 2972becc446Smrg shift 2982becc446Smrg ;; 2992becc446Smrg esac 3002becc446Smrg fi 3012becc446Smrg shift 3022c7c4e3dSmrgdone 3032c7c4e3dSmrg 3042c7c4e3dSmrgif test -z "$ofile" || test -z "$cfile"; then 3052becc446Smrg # If no '-o' option was seen then we might have been invoked from a 3062becc446Smrg # pattern rule where we don't need one. That is ok -- this is a 3072becc446Smrg # normal compilation that the losing compiler can handle. If no 3082becc446Smrg # '.c' file was seen then we are probably linking. That is also 3092becc446Smrg # ok. 3102becc446Smrg exec "$@" 3112c7c4e3dSmrgfi 3122c7c4e3dSmrg 3132c7c4e3dSmrg# Name of file we expect compiler to create. 3142becc446Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 3152c7c4e3dSmrg 3162c7c4e3dSmrg# Create the lock directory. 3172becc446Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 3182c7c4e3dSmrg# that we are using for the .o file. Also, base the name on the expected 3192c7c4e3dSmrg# object file name, since that is what matters with a parallel build. 3202becc446Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 3212c7c4e3dSmrgwhile true; do 3222becc446Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 3232becc446Smrg break 3242becc446Smrg fi 3252becc446Smrg sleep 1 3262c7c4e3dSmrgdone 3272c7c4e3dSmrg# FIXME: race condition here if user kills between mkdir and trap. 3282becc446Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 3292c7c4e3dSmrg 3302c7c4e3dSmrg# Run the compile. 3312becc446Smrg"$@" 3322becc446Smrgret=$? 3332c7c4e3dSmrg 3342c7c4e3dSmrgif test -f "$cofile"; then 3352becc446Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 3362becc446Smrgelif test -f "${cofile}bj"; then 3372becc446Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 3382c7c4e3dSmrgfi 3392c7c4e3dSmrg 3402becc446Smrgrmdir "$lockdir" 3412becc446Smrgexit $ret 3422becc446Smrg 3432becc446Smrg# Local Variables: 3442becc446Smrg# mode: shell-script 3452becc446Smrg# sh-indentation: 2 3463458e6c2Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 3472becc446Smrg# time-stamp-start: "scriptversion=" 3482becc446Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 3493458e6c2Smrg# time-stamp-time-zone: "UTC0" 3502becc446Smrg# time-stamp-end: "; # UTC" 3512becc446Smrg# End: 352