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