10a6b08f8Smrg#! /bin/sh 20a6b08f8Smrg# Wrapper for compilers which do not understand '-c -o'. 30a6b08f8Smrg 46bea0e4fSmrgscriptversion=2024-06-19.01; # UTC 50a6b08f8Smrg 66bea0e4fSmrg# Copyright (C) 1999-2024 Free Software Foundation, Inc. 70a6b08f8Smrg# Written by Tom Tromey <tromey@cygnus.com>. 80a6b08f8Smrg# 90a6b08f8Smrg# This program is free software; you can redistribute it and/or modify 100a6b08f8Smrg# it under the terms of the GNU General Public License as published by 110a6b08f8Smrg# the Free Software Foundation; either version 2, or (at your option) 120a6b08f8Smrg# any later version. 130a6b08f8Smrg# 140a6b08f8Smrg# This program is distributed in the hope that it will be useful, 150a6b08f8Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 160a6b08f8Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 170a6b08f8Smrg# GNU General Public License for more details. 180a6b08f8Smrg# 190a6b08f8Smrg# You should have received a copy of the GNU General Public License 203fb97780Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 210a6b08f8Smrg 220a6b08f8Smrg# As a special exception to the GNU General Public License, if you 230a6b08f8Smrg# distribute this file as part of a program that contains a 240a6b08f8Smrg# configuration script generated by Autoconf, you may include it under 250a6b08f8Smrg# the same distribution terms that you use for the rest of that program. 260a6b08f8Smrg 270a6b08f8Smrg# This file is maintained in Automake, please report 280a6b08f8Smrg# bugs to <bug-automake@gnu.org> or send patches to 290a6b08f8Smrg# <automake-patches@gnu.org>. 300a6b08f8Smrg 310a6b08f8Smrgnl=' 320a6b08f8Smrg' 330a6b08f8Smrg 340a6b08f8Smrg# We need space, tab and new line, in precisely that order. Quoting is 350a6b08f8Smrg# there to prevent tools from complaining about whitespace usage. 360a6b08f8SmrgIFS=" "" $nl" 370a6b08f8Smrg 380a6b08f8Smrgfile_conv= 390a6b08f8Smrg 400a6b08f8Smrg# func_file_conv build_file lazy 410a6b08f8Smrg# Convert a $build file to $host form and store it in $file 420a6b08f8Smrg# Currently only supports Windows hosts. If the determined conversion 430a6b08f8Smrg# type is listed in (the comma separated) LAZY, no conversion will 440a6b08f8Smrg# take place. 450a6b08f8Smrgfunc_file_conv () 460a6b08f8Smrg{ 470a6b08f8Smrg file=$1 480a6b08f8Smrg case $file in 490a6b08f8Smrg / | /[!/]*) # absolute file, and not a UNC file 500a6b08f8Smrg if test -z "$file_conv"; then 510a6b08f8Smrg # lazily determine how to convert abs files 520a6b08f8Smrg case `uname -s` in 530a6b08f8Smrg MINGW*) 540a6b08f8Smrg file_conv=mingw 550a6b08f8Smrg ;; 563fb97780Smrg CYGWIN* | MSYS*) 570a6b08f8Smrg file_conv=cygwin 580a6b08f8Smrg ;; 590a6b08f8Smrg *) 600a6b08f8Smrg file_conv=wine 610a6b08f8Smrg ;; 620a6b08f8Smrg esac 630a6b08f8Smrg fi 640a6b08f8Smrg case $file_conv/,$2, in 650a6b08f8Smrg *,$file_conv,*) 660a6b08f8Smrg ;; 670a6b08f8Smrg mingw/*) 680a6b08f8Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 690a6b08f8Smrg ;; 703fb97780Smrg cygwin/* | msys/*) 710a6b08f8Smrg file=`cygpath -m "$file" || echo "$file"` 720a6b08f8Smrg ;; 730a6b08f8Smrg wine/*) 740a6b08f8Smrg file=`winepath -w "$file" || echo "$file"` 750a6b08f8Smrg ;; 760a6b08f8Smrg esac 770a6b08f8Smrg ;; 780a6b08f8Smrg esac 790a6b08f8Smrg} 800a6b08f8Smrg 810a6b08f8Smrg# func_cl_dashL linkdir 820a6b08f8Smrg# Make cl look for libraries in LINKDIR 830a6b08f8Smrgfunc_cl_dashL () 840a6b08f8Smrg{ 850a6b08f8Smrg func_file_conv "$1" 860a6b08f8Smrg if test -z "$lib_path"; then 870a6b08f8Smrg lib_path=$file 880a6b08f8Smrg else 890a6b08f8Smrg lib_path="$lib_path;$file" 900a6b08f8Smrg fi 910a6b08f8Smrg linker_opts="$linker_opts -LIBPATH:$file" 920a6b08f8Smrg} 930a6b08f8Smrg 940a6b08f8Smrg# func_cl_dashl library 950a6b08f8Smrg# Do a library search-path lookup for cl 960a6b08f8Smrgfunc_cl_dashl () 970a6b08f8Smrg{ 980a6b08f8Smrg lib=$1 990a6b08f8Smrg found=no 1000a6b08f8Smrg save_IFS=$IFS 1010a6b08f8Smrg IFS=';' 1020a6b08f8Smrg for dir in $lib_path $LIB 1030a6b08f8Smrg do 1040a6b08f8Smrg IFS=$save_IFS 1050a6b08f8Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 1060a6b08f8Smrg found=yes 1070a6b08f8Smrg lib=$dir/$lib.dll.lib 1080a6b08f8Smrg break 1090a6b08f8Smrg fi 1100a6b08f8Smrg if test -f "$dir/$lib.lib"; then 1110a6b08f8Smrg found=yes 1120a6b08f8Smrg lib=$dir/$lib.lib 1130a6b08f8Smrg break 1140a6b08f8Smrg fi 1150a6b08f8Smrg if test -f "$dir/lib$lib.a"; then 1160a6b08f8Smrg found=yes 1170a6b08f8Smrg lib=$dir/lib$lib.a 1180a6b08f8Smrg break 1190a6b08f8Smrg fi 1200a6b08f8Smrg done 1210a6b08f8Smrg IFS=$save_IFS 1220a6b08f8Smrg 1230a6b08f8Smrg if test "$found" != yes; then 1240a6b08f8Smrg lib=$lib.lib 1250a6b08f8Smrg fi 1260a6b08f8Smrg} 1270a6b08f8Smrg 1280a6b08f8Smrg# func_cl_wrapper cl arg... 1290a6b08f8Smrg# Adjust compile command to suit cl 1300a6b08f8Smrgfunc_cl_wrapper () 1310a6b08f8Smrg{ 1320a6b08f8Smrg # Assume a capable shell 1330a6b08f8Smrg lib_path= 1340a6b08f8Smrg shared=: 1350a6b08f8Smrg linker_opts= 1360a6b08f8Smrg for arg 1370a6b08f8Smrg do 1380a6b08f8Smrg if test -n "$eat"; then 1390a6b08f8Smrg eat= 1400a6b08f8Smrg else 1410a6b08f8Smrg case $1 in 1420a6b08f8Smrg -o) 1430a6b08f8Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 1440a6b08f8Smrg eat=1 1450a6b08f8Smrg case $2 in 1466bea0e4fSmrg *.o | *.lo | *.[oO][bB][jJ]) 1470a6b08f8Smrg func_file_conv "$2" 1480a6b08f8Smrg set x "$@" -Fo"$file" 1490a6b08f8Smrg shift 1500a6b08f8Smrg ;; 1510a6b08f8Smrg *) 1520a6b08f8Smrg func_file_conv "$2" 1530a6b08f8Smrg set x "$@" -Fe"$file" 1540a6b08f8Smrg shift 1550a6b08f8Smrg ;; 1560a6b08f8Smrg esac 1570a6b08f8Smrg ;; 1580a6b08f8Smrg -I) 1590a6b08f8Smrg eat=1 1600a6b08f8Smrg func_file_conv "$2" mingw 1610a6b08f8Smrg set x "$@" -I"$file" 1620a6b08f8Smrg shift 1630a6b08f8Smrg ;; 1640a6b08f8Smrg -I*) 1650a6b08f8Smrg func_file_conv "${1#-I}" mingw 1660a6b08f8Smrg set x "$@" -I"$file" 1670a6b08f8Smrg shift 1680a6b08f8Smrg ;; 1690a6b08f8Smrg -l) 1700a6b08f8Smrg eat=1 1710a6b08f8Smrg func_cl_dashl "$2" 1720a6b08f8Smrg set x "$@" "$lib" 1730a6b08f8Smrg shift 1740a6b08f8Smrg ;; 1750a6b08f8Smrg -l*) 1760a6b08f8Smrg func_cl_dashl "${1#-l}" 1770a6b08f8Smrg set x "$@" "$lib" 1780a6b08f8Smrg shift 1790a6b08f8Smrg ;; 1800a6b08f8Smrg -L) 1810a6b08f8Smrg eat=1 1820a6b08f8Smrg func_cl_dashL "$2" 1830a6b08f8Smrg ;; 1840a6b08f8Smrg -L*) 1850a6b08f8Smrg func_cl_dashL "${1#-L}" 1860a6b08f8Smrg ;; 1870a6b08f8Smrg -static) 1880a6b08f8Smrg shared=false 1890a6b08f8Smrg ;; 1900a6b08f8Smrg -Wl,*) 1910a6b08f8Smrg arg=${1#-Wl,} 1920a6b08f8Smrg save_ifs="$IFS"; IFS=',' 1930a6b08f8Smrg for flag in $arg; do 1940a6b08f8Smrg IFS="$save_ifs" 1950a6b08f8Smrg linker_opts="$linker_opts $flag" 1960a6b08f8Smrg done 1970a6b08f8Smrg IFS="$save_ifs" 1980a6b08f8Smrg ;; 1990a6b08f8Smrg -Xlinker) 2000a6b08f8Smrg eat=1 2010a6b08f8Smrg linker_opts="$linker_opts $2" 2020a6b08f8Smrg ;; 2030a6b08f8Smrg -*) 2040a6b08f8Smrg set x "$@" "$1" 2050a6b08f8Smrg shift 2060a6b08f8Smrg ;; 2070a6b08f8Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 2080a6b08f8Smrg func_file_conv "$1" 2090a6b08f8Smrg set x "$@" -Tp"$file" 2100a6b08f8Smrg shift 2110a6b08f8Smrg ;; 2120a6b08f8Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2130a6b08f8Smrg func_file_conv "$1" mingw 2140a6b08f8Smrg set x "$@" "$file" 2150a6b08f8Smrg shift 2160a6b08f8Smrg ;; 2170a6b08f8Smrg *) 2180a6b08f8Smrg set x "$@" "$1" 2190a6b08f8Smrg shift 2200a6b08f8Smrg ;; 2210a6b08f8Smrg esac 2220a6b08f8Smrg fi 2230a6b08f8Smrg shift 2240a6b08f8Smrg done 2250a6b08f8Smrg if test -n "$linker_opts"; then 2260a6b08f8Smrg linker_opts="-link$linker_opts" 2270a6b08f8Smrg fi 2280a6b08f8Smrg exec "$@" $linker_opts 2290a6b08f8Smrg exit 1 2300a6b08f8Smrg} 2310a6b08f8Smrg 2320a6b08f8Smrgeat= 2330a6b08f8Smrg 2340a6b08f8Smrgcase $1 in 2350a6b08f8Smrg '') 2360a6b08f8Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 2370a6b08f8Smrg exit 1; 2380a6b08f8Smrg ;; 2390a6b08f8Smrg -h | --h*) 2400a6b08f8Smrg cat <<\EOF 2410a6b08f8SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 2420a6b08f8Smrg 2430a6b08f8SmrgWrapper for compilers which do not understand '-c -o'. 2440a6b08f8SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 2450a6b08f8Smrgarguments, and rename the output as expected. 2460a6b08f8Smrg 2470a6b08f8SmrgIf you are trying to build a whole package this is not the 2480a6b08f8Smrgright script to run: please start by reading the file 'INSTALL'. 2490a6b08f8Smrg 2500a6b08f8SmrgReport bugs to <bug-automake@gnu.org>. 2516bea0e4fSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 2526bea0e4fSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 2530a6b08f8SmrgEOF 2540a6b08f8Smrg exit $? 2550a6b08f8Smrg ;; 2560a6b08f8Smrg -v | --v*) 2576bea0e4fSmrg echo "compile (GNU Automake) $scriptversion" 2580a6b08f8Smrg exit $? 2590a6b08f8Smrg ;; 2603fb97780Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 2616bea0e4fSmrg clang-cl | *[/\\]clang-cl | clang-cl.exe | *[/\\]clang-cl.exe | \ 2623fb97780Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 2630a6b08f8Smrg func_cl_wrapper "$@" # Doesn't return... 2640a6b08f8Smrg ;; 2650a6b08f8Smrgesac 2660a6b08f8Smrg 2670a6b08f8Smrgofile= 2680a6b08f8Smrgcfile= 2690a6b08f8Smrg 2700a6b08f8Smrgfor arg 2710a6b08f8Smrgdo 2720a6b08f8Smrg if test -n "$eat"; then 2730a6b08f8Smrg eat= 2740a6b08f8Smrg else 2750a6b08f8Smrg case $1 in 2760a6b08f8Smrg -o) 2770a6b08f8Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 2780a6b08f8Smrg # So we strip '-o arg' only if arg is an object. 2790a6b08f8Smrg eat=1 2800a6b08f8Smrg case $2 in 2810a6b08f8Smrg *.o | *.obj) 2820a6b08f8Smrg ofile=$2 2830a6b08f8Smrg ;; 2840a6b08f8Smrg *) 2850a6b08f8Smrg set x "$@" -o "$2" 2860a6b08f8Smrg shift 2870a6b08f8Smrg ;; 2880a6b08f8Smrg esac 2890a6b08f8Smrg ;; 2900a6b08f8Smrg *.c) 2910a6b08f8Smrg cfile=$1 2920a6b08f8Smrg set x "$@" "$1" 2930a6b08f8Smrg shift 2940a6b08f8Smrg ;; 2950a6b08f8Smrg *) 2960a6b08f8Smrg set x "$@" "$1" 2970a6b08f8Smrg shift 2980a6b08f8Smrg ;; 2990a6b08f8Smrg esac 3000a6b08f8Smrg fi 3010a6b08f8Smrg shift 3020a6b08f8Smrgdone 3030a6b08f8Smrg 3040a6b08f8Smrgif test -z "$ofile" || test -z "$cfile"; then 3050a6b08f8Smrg # If no '-o' option was seen then we might have been invoked from a 3060a6b08f8Smrg # pattern rule where we don't need one. That is ok -- this is a 3070a6b08f8Smrg # normal compilation that the losing compiler can handle. If no 3080a6b08f8Smrg # '.c' file was seen then we are probably linking. That is also 3090a6b08f8Smrg # ok. 3100a6b08f8Smrg exec "$@" 3110a6b08f8Smrgfi 3120a6b08f8Smrg 3130a6b08f8Smrg# Name of file we expect compiler to create. 3140a6b08f8Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 3150a6b08f8Smrg 3160a6b08f8Smrg# Create the lock directory. 3170a6b08f8Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 3180a6b08f8Smrg# that we are using for the .o file. Also, base the name on the expected 3190a6b08f8Smrg# object file name, since that is what matters with a parallel build. 3200a6b08f8Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 3210a6b08f8Smrgwhile true; do 3220a6b08f8Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 3230a6b08f8Smrg break 3240a6b08f8Smrg fi 3250a6b08f8Smrg sleep 1 3260a6b08f8Smrgdone 3270a6b08f8Smrg# FIXME: race condition here if user kills between mkdir and trap. 3280a6b08f8Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 3290a6b08f8Smrg 3300a6b08f8Smrg# Run the compile. 3310a6b08f8Smrg"$@" 3320a6b08f8Smrgret=$? 3330a6b08f8Smrg 3340a6b08f8Smrgif test -f "$cofile"; then 3350a6b08f8Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 3360a6b08f8Smrgelif test -f "${cofile}bj"; then 3370a6b08f8Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 3380a6b08f8Smrgfi 3390a6b08f8Smrg 3400a6b08f8Smrgrmdir "$lockdir" 3410a6b08f8Smrgexit $ret 3420a6b08f8Smrg 3430a6b08f8Smrg# Local Variables: 3440a6b08f8Smrg# mode: shell-script 3450a6b08f8Smrg# sh-indentation: 2 3463fb97780Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 3470a6b08f8Smrg# time-stamp-start: "scriptversion=" 3480a6b08f8Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 3493fb97780Smrg# time-stamp-time-zone: "UTC0" 3500a6b08f8Smrg# time-stamp-end: "; # UTC" 3510a6b08f8Smrg# End: 352