16b526288Smrg#!/bin/sh 26b526288Smrg# Wrapper for compilers which do not understand '-c -o'. 36b526288Smrg 46b526288Smrgscriptversion=2016-01-11.22; # UTC 56b526288Smrg 66b526288Smrg# Copyright (C) 1999-2017 Free Software Foundation, Inc. 76b526288Smrg# Written by Tom Tromey <tromey@cygnus.com>. 86b526288Smrg# 96b526288Smrg# This program is free software; you can redistribute it and/or modify 106b526288Smrg# it under the terms of the GNU General Public License as published by 116b526288Smrg# the Free Software Foundation; either version 2, or (at your option) 126b526288Smrg# any later version. 136b526288Smrg# 146b526288Smrg# This program is distributed in the hope that it will be useful, 156b526288Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 166b526288Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 176b526288Smrg# GNU General Public License for more details. 186b526288Smrg# 196b526288Smrg# You should have received a copy of the GNU General Public License 206b526288Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 216b526288Smrg 226b526288Smrg# As a special exception to the GNU General Public License, if you 236b526288Smrg# distribute this file as part of a program that contains a 246b526288Smrg# configuration script generated by Autoconf, you may include it under 256b526288Smrg# the same distribution terms that you use for the rest of that program. 266b526288Smrg 276b526288Smrg# This file is maintained in Automake, please report 286b526288Smrg# bugs to <bug-automake@gnu.org> or send patches to 296b526288Smrg# <automake-patches@gnu.org>. 306b526288Smrg 316b526288Smrgnl=' 326b526288Smrg' 336b526288Smrg 346b526288Smrg# We need space, tab and new line, in precisely that order. Quoting is 356b526288Smrg# there to prevent tools from complaining about whitespace usage. 366b526288SmrgIFS=" "" $nl" 376b526288Smrg 386b526288Smrgfile_conv= 396b526288Smrg 406b526288Smrg# func_file_conv build_file lazy 416b526288Smrg# Convert a $build file to $host form and store it in $file 426b526288Smrg# Currently only supports Windows hosts. If the determined conversion 436b526288Smrg# type is listed in (the comma separated) LAZY, no conversion will 446b526288Smrg# take place. 456b526288Smrgfunc_file_conv () 466b526288Smrg{ 476b526288Smrg file=$1 486b526288Smrg case $file in 496b526288Smrg / | /[!/]*) # absolute file, and not a UNC file 506b526288Smrg if test -z "$file_conv"; then 516b526288Smrg # lazily determine how to convert abs files 526b526288Smrg case `uname -s` in 536b526288Smrg MINGW*) 546b526288Smrg file_conv=mingw 556b526288Smrg ;; 566b526288Smrg CYGWIN*) 576b526288Smrg file_conv=cygwin 586b526288Smrg ;; 596b526288Smrg *) 606b526288Smrg file_conv=wine 616b526288Smrg ;; 626b526288Smrg esac 636b526288Smrg fi 646b526288Smrg case $file_conv/,$2, in 656b526288Smrg *,$file_conv,*) 666b526288Smrg ;; 676b526288Smrg mingw/*) 686b526288Smrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 696b526288Smrg ;; 706b526288Smrg cygwin/*) 716b526288Smrg file=`cygpath -m "$file" || echo "$file"` 726b526288Smrg ;; 736b526288Smrg wine/*) 746b526288Smrg file=`winepath -w "$file" || echo "$file"` 756b526288Smrg ;; 766b526288Smrg esac 776b526288Smrg ;; 786b526288Smrg esac 796b526288Smrg} 806b526288Smrg 816b526288Smrg# func_cl_dashL linkdir 826b526288Smrg# Make cl look for libraries in LINKDIR 836b526288Smrgfunc_cl_dashL () 846b526288Smrg{ 856b526288Smrg func_file_conv "$1" 866b526288Smrg if test -z "$lib_path"; then 876b526288Smrg lib_path=$file 886b526288Smrg else 896b526288Smrg lib_path="$lib_path;$file" 906b526288Smrg fi 916b526288Smrg linker_opts="$linker_opts -LIBPATH:$file" 926b526288Smrg} 936b526288Smrg 946b526288Smrg# func_cl_dashl library 956b526288Smrg# Do a library search-path lookup for cl 966b526288Smrgfunc_cl_dashl () 976b526288Smrg{ 986b526288Smrg lib=$1 996b526288Smrg found=no 1006b526288Smrg save_IFS=$IFS 1016b526288Smrg IFS=';' 1026b526288Smrg for dir in $lib_path $LIB 1036b526288Smrg do 1046b526288Smrg IFS=$save_IFS 1056b526288Smrg if $shared && test -f "$dir/$lib.dll.lib"; then 1066b526288Smrg found=yes 1076b526288Smrg lib=$dir/$lib.dll.lib 1086b526288Smrg break 1096b526288Smrg fi 1106b526288Smrg if test -f "$dir/$lib.lib"; then 1116b526288Smrg found=yes 1126b526288Smrg lib=$dir/$lib.lib 1136b526288Smrg break 1146b526288Smrg fi 1156b526288Smrg if test -f "$dir/lib$lib.a"; then 1166b526288Smrg found=yes 1176b526288Smrg lib=$dir/lib$lib.a 1186b526288Smrg break 1196b526288Smrg fi 1206b526288Smrg done 1216b526288Smrg IFS=$save_IFS 1226b526288Smrg 1236b526288Smrg if test "$found" != yes; then 1246b526288Smrg lib=$lib.lib 1256b526288Smrg fi 1266b526288Smrg} 1276b526288Smrg 1286b526288Smrg# func_cl_wrapper cl arg... 1296b526288Smrg# Adjust compile command to suit cl 1306b526288Smrgfunc_cl_wrapper () 1316b526288Smrg{ 1326b526288Smrg # Assume a capable shell 1336b526288Smrg lib_path= 1346b526288Smrg shared=: 1356b526288Smrg linker_opts= 1366b526288Smrg for arg 1376b526288Smrg do 1386b526288Smrg if test -n "$eat"; then 1396b526288Smrg eat= 1406b526288Smrg else 1416b526288Smrg case $1 in 1426b526288Smrg -o) 1436b526288Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 1446b526288Smrg eat=1 1456b526288Smrg case $2 in 1466b526288Smrg *.o | *.[oO][bB][jJ]) 1476b526288Smrg func_file_conv "$2" 1486b526288Smrg set x "$@" -Fo"$file" 1496b526288Smrg shift 1506b526288Smrg ;; 1516b526288Smrg *) 1526b526288Smrg func_file_conv "$2" 1536b526288Smrg set x "$@" -Fe"$file" 1546b526288Smrg shift 1556b526288Smrg ;; 1566b526288Smrg esac 1576b526288Smrg ;; 1586b526288Smrg -I) 1596b526288Smrg eat=1 1606b526288Smrg func_file_conv "$2" mingw 1616b526288Smrg set x "$@" -I"$file" 1626b526288Smrg shift 1636b526288Smrg ;; 1646b526288Smrg -I*) 1656b526288Smrg func_file_conv "${1#-I}" mingw 1666b526288Smrg set x "$@" -I"$file" 1676b526288Smrg shift 1686b526288Smrg ;; 1696b526288Smrg -l) 1706b526288Smrg eat=1 1716b526288Smrg func_cl_dashl "$2" 1726b526288Smrg set x "$@" "$lib" 1736b526288Smrg shift 1746b526288Smrg ;; 1756b526288Smrg -l*) 1766b526288Smrg func_cl_dashl "${1#-l}" 1776b526288Smrg set x "$@" "$lib" 1786b526288Smrg shift 1796b526288Smrg ;; 1806b526288Smrg -L) 1816b526288Smrg eat=1 1826b526288Smrg func_cl_dashL "$2" 1836b526288Smrg ;; 1846b526288Smrg -L*) 1856b526288Smrg func_cl_dashL "${1#-L}" 1866b526288Smrg ;; 1876b526288Smrg -static) 1886b526288Smrg shared=false 1896b526288Smrg ;; 1906b526288Smrg -Wl,*) 1916b526288Smrg arg=${1#-Wl,} 1926b526288Smrg save_ifs="$IFS"; IFS=',' 1936b526288Smrg for flag in $arg; do 1946b526288Smrg IFS="$save_ifs" 1956b526288Smrg linker_opts="$linker_opts $flag" 1966b526288Smrg done 1976b526288Smrg IFS="$save_ifs" 1986b526288Smrg ;; 1996b526288Smrg -Xlinker) 2006b526288Smrg eat=1 2016b526288Smrg linker_opts="$linker_opts $2" 2026b526288Smrg ;; 2036b526288Smrg -*) 2046b526288Smrg set x "$@" "$1" 2056b526288Smrg shift 2066b526288Smrg ;; 2076b526288Smrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 2086b526288Smrg func_file_conv "$1" 2096b526288Smrg set x "$@" -Tp"$file" 2106b526288Smrg shift 2116b526288Smrg ;; 2126b526288Smrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 2136b526288Smrg func_file_conv "$1" mingw 2146b526288Smrg set x "$@" "$file" 2156b526288Smrg shift 2166b526288Smrg ;; 2176b526288Smrg *) 2186b526288Smrg set x "$@" "$1" 2196b526288Smrg shift 2206b526288Smrg ;; 2216b526288Smrg esac 2226b526288Smrg fi 2236b526288Smrg shift 2246b526288Smrg done 2256b526288Smrg if test -n "$linker_opts"; then 2266b526288Smrg linker_opts="-link$linker_opts" 2276b526288Smrg fi 2286b526288Smrg exec "$@" $linker_opts 2296b526288Smrg exit 1 2306b526288Smrg} 2316b526288Smrg 2326b526288Smrgeat= 2336b526288Smrg 2346b526288Smrgcase $1 in 2356b526288Smrg '') 2366b526288Smrg echo "$0: No command. Try '$0 --help' for more information." 1>&2 2376b526288Smrg exit 1; 2386b526288Smrg ;; 2396b526288Smrg -h | --h*) 2406b526288Smrg cat <<\EOF 2416b526288SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 2426b526288Smrg 2436b526288SmrgWrapper for compilers which do not understand '-c -o'. 2446b526288SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 2456b526288Smrgarguments, and rename the output as expected. 2466b526288Smrg 2476b526288SmrgIf you are trying to build a whole package this is not the 2486b526288Smrgright script to run: please start by reading the file 'INSTALL'. 2496b526288Smrg 2506b526288SmrgReport bugs to <bug-automake@gnu.org>. 2516b526288SmrgEOF 2526b526288Smrg exit $? 2536b526288Smrg ;; 2546b526288Smrg -v | --v*) 2556b526288Smrg echo "compile $scriptversion" 2566b526288Smrg exit $? 2576b526288Smrg ;; 2586b526288Smrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 2596b526288Smrg icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 2606b526288Smrg func_cl_wrapper "$@" # Doesn't return... 2616b526288Smrg ;; 2626b526288Smrgesac 2636b526288Smrg 2646b526288Smrgofile= 2656b526288Smrgcfile= 2666b526288Smrg 2676b526288Smrgfor arg 2686b526288Smrgdo 2696b526288Smrg if test -n "$eat"; then 2706b526288Smrg eat= 2716b526288Smrg else 2726b526288Smrg case $1 in 2736b526288Smrg -o) 2746b526288Smrg # configure might choose to run compile as 'compile cc -o foo foo.c'. 2756b526288Smrg # So we strip '-o arg' only if arg is an object. 2766b526288Smrg eat=1 2776b526288Smrg case $2 in 2786b526288Smrg *.o | *.obj) 2796b526288Smrg ofile=$2 2806b526288Smrg ;; 2816b526288Smrg *) 2826b526288Smrg set x "$@" -o "$2" 2836b526288Smrg shift 2846b526288Smrg ;; 2856b526288Smrg esac 2866b526288Smrg ;; 2876b526288Smrg *.c) 2886b526288Smrg cfile=$1 2896b526288Smrg set x "$@" "$1" 2906b526288Smrg shift 2916b526288Smrg ;; 2926b526288Smrg *) 2936b526288Smrg set x "$@" "$1" 2946b526288Smrg shift 2956b526288Smrg ;; 2966b526288Smrg esac 2976b526288Smrg fi 2986b526288Smrg shift 2996b526288Smrgdone 3006b526288Smrg 3016b526288Smrgif test -z "$ofile" || test -z "$cfile"; then 3026b526288Smrg # If no '-o' option was seen then we might have been invoked from a 3036b526288Smrg # pattern rule where we don't need one. That is ok -- this is a 3046b526288Smrg # normal compilation that the losing compiler can handle. If no 3056b526288Smrg # '.c' file was seen then we are probably linking. That is also 3066b526288Smrg # ok. 3076b526288Smrg exec "$@" 3086b526288Smrgfi 3096b526288Smrg 3106b526288Smrg# Name of file we expect compiler to create. 3116b526288Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 3126b526288Smrg 3136b526288Smrg# Create the lock directory. 3146b526288Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name 3156b526288Smrg# that we are using for the .o file. Also, base the name on the expected 3166b526288Smrg# object file name, since that is what matters with a parallel build. 3176b526288Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 3186b526288Smrgwhile true; do 3196b526288Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 3206b526288Smrg break 3216b526288Smrg fi 3226b526288Smrg sleep 1 3236b526288Smrgdone 3246b526288Smrg# FIXME: race condition here if user kills between mkdir and trap. 3256b526288Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 3266b526288Smrg 3276b526288Smrg# Run the compile. 3286b526288Smrg"$@" 3296b526288Smrgret=$? 3306b526288Smrg 3316b526288Smrgif test -f "$cofile"; then 3326b526288Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 3336b526288Smrgelif test -f "${cofile}bj"; then 3346b526288Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 3356b526288Smrgfi 3366b526288Smrg 3376b526288Smrgrmdir "$lockdir" 3386b526288Smrgexit $ret 3396b526288Smrg 3406b526288Smrg# Local Variables: 3416b526288Smrg# mode: shell-script 3426b526288Smrg# sh-indentation: 2 3436b526288Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 3446b526288Smrg# time-stamp-start: "scriptversion=" 3456b526288Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 3466b526288Smrg# time-stamp-time-zone: "UTC0" 3476b526288Smrg# time-stamp-end: "; # UTC" 3486b526288Smrg# End: 349