1e34c20c8SJon Dugan#! /bin/sh 2487ee810SBruce A. Mah# Wrapper for compilers which do not understand '-c -o'. 3e34c20c8SJon Dugan 46e9d8525SBruce A. Mahscriptversion=2018-03-07.03; # UTC 556a97f93Sjef 6*76bd67f6SSarah Larsen# Copyright (C) 1999-2021 Free Software Foundation, Inc. 7e34c20c8SJon Dugan# Written by Tom Tromey <[email protected]>. 8e34c20c8SJon Dugan# 9e34c20c8SJon Dugan# This program is free software; you can redistribute it and/or modify 10e34c20c8SJon Dugan# it under the terms of the GNU General Public License as published by 11e34c20c8SJon Dugan# the Free Software Foundation; either version 2, or (at your option) 12e34c20c8SJon Dugan# any later version. 13e34c20c8SJon Dugan# 14e34c20c8SJon Dugan# This program is distributed in the hope that it will be useful, 15e34c20c8SJon Dugan# but WITHOUT ANY WARRANTY; without even the implied warranty of 16e34c20c8SJon Dugan# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17e34c20c8SJon Dugan# GNU General Public License for more details. 18e34c20c8SJon Dugan# 19e34c20c8SJon Dugan# You should have received a copy of the GNU General Public License 20ff1ea4e5SBruce A. Mah# along with this program. If not, see <https://www.gnu.org/licenses/>. 21e34c20c8SJon Dugan 22e34c20c8SJon Dugan# As a special exception to the GNU General Public License, if you 23e34c20c8SJon Dugan# distribute this file as part of a program that contains a 24e34c20c8SJon Dugan# configuration script generated by Autoconf, you may include it under 25e34c20c8SJon Dugan# the same distribution terms that you use for the rest of that program. 26e34c20c8SJon Dugan 2756a97f93Sjef# This file is maintained in Automake, please report 2856a97f93Sjef# bugs to <[email protected]> or send patches to 2956a97f93Sjef# <[email protected]>. 30e34c20c8SJon Dugan 31487ee810SBruce A. Mahnl=' 32487ee810SBruce A. Mah' 33487ee810SBruce A. Mah 34487ee810SBruce A. Mah# We need space, tab and new line, in precisely that order. Quoting is 35487ee810SBruce A. Mah# there to prevent tools from complaining about whitespace usage. 36487ee810SBruce A. MahIFS=" "" $nl" 37487ee810SBruce A. Mah 38487ee810SBruce A. Mahfile_conv= 39487ee810SBruce A. Mah 40487ee810SBruce A. Mah# func_file_conv build_file lazy 41487ee810SBruce A. Mah# Convert a $build file to $host form and store it in $file 42487ee810SBruce A. Mah# Currently only supports Windows hosts. If the determined conversion 43487ee810SBruce A. Mah# type is listed in (the comma separated) LAZY, no conversion will 44487ee810SBruce A. Mah# take place. 45487ee810SBruce A. Mahfunc_file_conv () 46487ee810SBruce A. Mah{ 47487ee810SBruce A. Mah file=$1 48487ee810SBruce A. Mah case $file in 49487ee810SBruce A. Mah / | /[!/]*) # absolute file, and not a UNC file 50487ee810SBruce A. Mah if test -z "$file_conv"; then 51487ee810SBruce A. Mah # lazily determine how to convert abs files 52487ee810SBruce A. Mah case `uname -s` in 53487ee810SBruce A. Mah MINGW*) 54487ee810SBruce A. Mah file_conv=mingw 55487ee810SBruce A. Mah ;; 5606280a6dSBruce A. Mah CYGWIN* | MSYS*) 57487ee810SBruce A. Mah file_conv=cygwin 58487ee810SBruce A. Mah ;; 59487ee810SBruce A. Mah *) 60487ee810SBruce A. Mah file_conv=wine 61487ee810SBruce A. Mah ;; 62487ee810SBruce A. Mah esac 63487ee810SBruce A. Mah fi 64487ee810SBruce A. Mah case $file_conv/,$2, in 65487ee810SBruce A. Mah *,$file_conv,*) 66487ee810SBruce A. Mah ;; 67487ee810SBruce A. Mah mingw/*) 68487ee810SBruce A. Mah file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69487ee810SBruce A. Mah ;; 7006280a6dSBruce A. Mah cygwin/* | msys/*) 71487ee810SBruce A. Mah file=`cygpath -m "$file" || echo "$file"` 72487ee810SBruce A. Mah ;; 73487ee810SBruce A. Mah wine/*) 74487ee810SBruce A. Mah file=`winepath -w "$file" || echo "$file"` 75487ee810SBruce A. Mah ;; 76487ee810SBruce A. Mah esac 77487ee810SBruce A. Mah ;; 78487ee810SBruce A. Mah esac 79487ee810SBruce A. Mah} 80487ee810SBruce A. Mah 81487ee810SBruce A. Mah# func_cl_dashL linkdir 82487ee810SBruce A. Mah# Make cl look for libraries in LINKDIR 83487ee810SBruce A. Mahfunc_cl_dashL () 84487ee810SBruce A. Mah{ 85487ee810SBruce A. Mah func_file_conv "$1" 86487ee810SBruce A. Mah if test -z "$lib_path"; then 87487ee810SBruce A. Mah lib_path=$file 88487ee810SBruce A. Mah else 89487ee810SBruce A. Mah lib_path="$lib_path;$file" 90487ee810SBruce A. Mah fi 91487ee810SBruce A. Mah linker_opts="$linker_opts -LIBPATH:$file" 92487ee810SBruce A. Mah} 93487ee810SBruce A. Mah 94487ee810SBruce A. Mah# func_cl_dashl library 95487ee810SBruce A. Mah# Do a library search-path lookup for cl 96487ee810SBruce A. Mahfunc_cl_dashl () 97487ee810SBruce A. Mah{ 98487ee810SBruce A. Mah lib=$1 99487ee810SBruce A. Mah found=no 100487ee810SBruce A. Mah save_IFS=$IFS 101487ee810SBruce A. Mah IFS=';' 102487ee810SBruce A. Mah for dir in $lib_path $LIB 103487ee810SBruce A. Mah do 104487ee810SBruce A. Mah IFS=$save_IFS 105487ee810SBruce A. Mah if $shared && test -f "$dir/$lib.dll.lib"; then 106487ee810SBruce A. Mah found=yes 107487ee810SBruce A. Mah lib=$dir/$lib.dll.lib 108487ee810SBruce A. Mah break 109487ee810SBruce A. Mah fi 110487ee810SBruce A. Mah if test -f "$dir/$lib.lib"; then 111487ee810SBruce A. Mah found=yes 112487ee810SBruce A. Mah lib=$dir/$lib.lib 113487ee810SBruce A. Mah break 114487ee810SBruce A. Mah fi 115487ee810SBruce A. Mah if test -f "$dir/lib$lib.a"; then 116487ee810SBruce A. Mah found=yes 117487ee810SBruce A. Mah lib=$dir/lib$lib.a 118487ee810SBruce A. Mah break 119487ee810SBruce A. Mah fi 120487ee810SBruce A. Mah done 121487ee810SBruce A. Mah IFS=$save_IFS 122487ee810SBruce A. Mah 123487ee810SBruce A. Mah if test "$found" != yes; then 124487ee810SBruce A. Mah lib=$lib.lib 125487ee810SBruce A. Mah fi 126487ee810SBruce A. Mah} 127487ee810SBruce A. Mah 128487ee810SBruce A. Mah# func_cl_wrapper cl arg... 129487ee810SBruce A. Mah# Adjust compile command to suit cl 130487ee810SBruce A. Mahfunc_cl_wrapper () 131487ee810SBruce A. Mah{ 132487ee810SBruce A. Mah # Assume a capable shell 133487ee810SBruce A. Mah lib_path= 134487ee810SBruce A. Mah shared=: 135487ee810SBruce A. Mah linker_opts= 136487ee810SBruce A. Mah for arg 137487ee810SBruce A. Mah do 138487ee810SBruce A. Mah if test -n "$eat"; then 139487ee810SBruce A. Mah eat= 140487ee810SBruce A. Mah else 141487ee810SBruce A. Mah case $1 in 142487ee810SBruce A. Mah -o) 143487ee810SBruce A. Mah # configure might choose to run compile as 'compile cc -o foo foo.c'. 144487ee810SBruce A. Mah eat=1 145487ee810SBruce A. Mah case $2 in 146487ee810SBruce A. Mah *.o | *.[oO][bB][jJ]) 147487ee810SBruce A. Mah func_file_conv "$2" 148487ee810SBruce A. Mah set x "$@" -Fo"$file" 149487ee810SBruce A. Mah shift 150487ee810SBruce A. Mah ;; 151487ee810SBruce A. Mah *) 152487ee810SBruce A. Mah func_file_conv "$2" 153487ee810SBruce A. Mah set x "$@" -Fe"$file" 154487ee810SBruce A. Mah shift 155487ee810SBruce A. Mah ;; 156487ee810SBruce A. Mah esac 157487ee810SBruce A. Mah ;; 158487ee810SBruce A. Mah -I) 159487ee810SBruce A. Mah eat=1 160487ee810SBruce A. Mah func_file_conv "$2" mingw 161487ee810SBruce A. Mah set x "$@" -I"$file" 162487ee810SBruce A. Mah shift 163487ee810SBruce A. Mah ;; 164487ee810SBruce A. Mah -I*) 165487ee810SBruce A. Mah func_file_conv "${1#-I}" mingw 166487ee810SBruce A. Mah set x "$@" -I"$file" 167487ee810SBruce A. Mah shift 168487ee810SBruce A. Mah ;; 169487ee810SBruce A. Mah -l) 170487ee810SBruce A. Mah eat=1 171487ee810SBruce A. Mah func_cl_dashl "$2" 172487ee810SBruce A. Mah set x "$@" "$lib" 173487ee810SBruce A. Mah shift 174487ee810SBruce A. Mah ;; 175487ee810SBruce A. Mah -l*) 176487ee810SBruce A. Mah func_cl_dashl "${1#-l}" 177487ee810SBruce A. Mah set x "$@" "$lib" 178487ee810SBruce A. Mah shift 179487ee810SBruce A. Mah ;; 180487ee810SBruce A. Mah -L) 181487ee810SBruce A. Mah eat=1 182487ee810SBruce A. Mah func_cl_dashL "$2" 183487ee810SBruce A. Mah ;; 184487ee810SBruce A. Mah -L*) 185487ee810SBruce A. Mah func_cl_dashL "${1#-L}" 186487ee810SBruce A. Mah ;; 187487ee810SBruce A. Mah -static) 188487ee810SBruce A. Mah shared=false 189487ee810SBruce A. Mah ;; 190487ee810SBruce A. Mah -Wl,*) 191487ee810SBruce A. Mah arg=${1#-Wl,} 192487ee810SBruce A. Mah save_ifs="$IFS"; IFS=',' 193487ee810SBruce A. Mah for flag in $arg; do 194487ee810SBruce A. Mah IFS="$save_ifs" 195487ee810SBruce A. Mah linker_opts="$linker_opts $flag" 196487ee810SBruce A. Mah done 197487ee810SBruce A. Mah IFS="$save_ifs" 198487ee810SBruce A. Mah ;; 199487ee810SBruce A. Mah -Xlinker) 200487ee810SBruce A. Mah eat=1 201487ee810SBruce A. Mah linker_opts="$linker_opts $2" 202487ee810SBruce A. Mah ;; 203487ee810SBruce A. Mah -*) 204487ee810SBruce A. Mah set x "$@" "$1" 205487ee810SBruce A. Mah shift 206487ee810SBruce A. Mah ;; 207487ee810SBruce A. Mah *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208487ee810SBruce A. Mah func_file_conv "$1" 209487ee810SBruce A. Mah set x "$@" -Tp"$file" 210487ee810SBruce A. Mah shift 211487ee810SBruce A. Mah ;; 212487ee810SBruce A. Mah *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213487ee810SBruce A. Mah func_file_conv "$1" mingw 214487ee810SBruce A. Mah set x "$@" "$file" 215487ee810SBruce A. Mah shift 216487ee810SBruce A. Mah ;; 217487ee810SBruce A. Mah *) 218487ee810SBruce A. Mah set x "$@" "$1" 219487ee810SBruce A. Mah shift 220487ee810SBruce A. Mah ;; 221487ee810SBruce A. Mah esac 222487ee810SBruce A. Mah fi 223487ee810SBruce A. Mah shift 224487ee810SBruce A. Mah done 225487ee810SBruce A. Mah if test -n "$linker_opts"; then 226487ee810SBruce A. Mah linker_opts="-link$linker_opts" 227487ee810SBruce A. Mah fi 228487ee810SBruce A. Mah exec "$@" $linker_opts 229487ee810SBruce A. Mah exit 1 230487ee810SBruce A. Mah} 231487ee810SBruce A. Mah 232487ee810SBruce A. Maheat= 233487ee810SBruce A. Mah 23456a97f93Sjefcase $1 in 23556a97f93Sjef '') 236487ee810SBruce A. Mah echo "$0: No command. Try '$0 --help' for more information." 1>&2 23756a97f93Sjef exit 1; 23856a97f93Sjef ;; 23956a97f93Sjef -h | --h*) 24056a97f93Sjef cat <<\EOF 24156a97f93SjefUsage: compile [--help] [--version] PROGRAM [ARGS] 24256a97f93Sjef 243487ee810SBruce A. MahWrapper for compilers which do not understand '-c -o'. 244487ee810SBruce A. MahRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24556a97f93Sjefarguments, and rename the output as expected. 24656a97f93Sjef 24756a97f93SjefIf you are trying to build a whole package this is not the 248487ee810SBruce A. Mahright script to run: please start by reading the file 'INSTALL'. 24956a97f93Sjef 25056a97f93SjefReport bugs to <bug-automake@gnu.org>. 25156a97f93SjefEOF 25256a97f93Sjef exit $? 25356a97f93Sjef ;; 25456a97f93Sjef -v | --v*) 25556a97f93Sjef echo "compile $scriptversion" 25656a97f93Sjef exit $? 25756a97f93Sjef ;; 2587cf95d20SBruce A. Mah cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ 2597cf95d20SBruce A. Mah icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) 260487ee810SBruce A. Mah func_cl_wrapper "$@" # Doesn't return... 261487ee810SBruce A. Mah ;; 26256a97f93Sjefesac 263e34c20c8SJon Dugan 264e34c20c8SJon Duganofile= 265e34c20c8SJon Dugancfile= 26656a97f93Sjef 26756a97f93Sjeffor arg 26856a97f93Sjefdo 26956a97f93Sjef if test -n "$eat"; then 27056a97f93Sjef eat= 27156a97f93Sjef else 27256a97f93Sjef case $1 in 273e34c20c8SJon Dugan -o) 274487ee810SBruce A. Mah # configure might choose to run compile as 'compile cc -o foo foo.c'. 275487ee810SBruce A. Mah # So we strip '-o arg' only if arg is an object. 27656a97f93Sjef eat=1 27756a97f93Sjef case $2 in 278e34c20c8SJon Dugan *.o | *.obj) 27956a97f93Sjef ofile=$2 280e34c20c8SJon Dugan ;; 281e34c20c8SJon Dugan *) 28256a97f93Sjef set x "$@" -o "$2" 28356a97f93Sjef shift 284e34c20c8SJon Dugan ;; 285e34c20c8SJon Dugan esac 286e34c20c8SJon Dugan ;; 287e34c20c8SJon Dugan *.c) 288e34c20c8SJon Dugan cfile=$1 28956a97f93Sjef set x "$@" "$1" 29056a97f93Sjef shift 291e34c20c8SJon Dugan ;; 292e34c20c8SJon Dugan *) 29356a97f93Sjef set x "$@" "$1" 29456a97f93Sjef shift 295e34c20c8SJon Dugan ;; 296e34c20c8SJon Dugan esac 29756a97f93Sjef fi 298e34c20c8SJon Dugan shift 299e34c20c8SJon Dugandone 300e34c20c8SJon Dugan 301e34c20c8SJon Duganif test -z "$ofile" || test -z "$cfile"; then 302487ee810SBruce A. Mah # If no '-o' option was seen then we might have been invoked from a 303e34c20c8SJon Dugan # pattern rule where we don't need one. That is ok -- this is a 304e34c20c8SJon Dugan # normal compilation that the losing compiler can handle. If no 305487ee810SBruce A. Mah # '.c' file was seen then we are probably linking. That is also 306e34c20c8SJon Dugan # ok. 30756a97f93Sjef exec "$@" 308e34c20c8SJon Duganfi 309e34c20c8SJon Dugan 310e34c20c8SJon Dugan# Name of file we expect compiler to create. 311487ee810SBruce A. Mahcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 312e34c20c8SJon Dugan 313e34c20c8SJon Dugan# Create the lock directory. 314487ee810SBruce A. Mah# Note: use '[/\\:.-]' here to ensure that we don't use the same name 315e34c20c8SJon Dugan# that we are using for the .o file. Also, base the name on the expected 316e34c20c8SJon Dugan# object file name, since that is what matters with a parallel build. 317487ee810SBruce A. Mahlockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 318e34c20c8SJon Duganwhile true; do 31956a97f93Sjef if mkdir "$lockdir" >/dev/null 2>&1; then 320e34c20c8SJon Dugan break 321e34c20c8SJon Dugan fi 322e34c20c8SJon Dugan sleep 1 323e34c20c8SJon Dugandone 324e34c20c8SJon Dugan# FIXME: race condition here if user kills between mkdir and trap. 32556a97f93Sjeftrap "rmdir '$lockdir'; exit 1" 1 2 15 326e34c20c8SJon Dugan 327e34c20c8SJon Dugan# Run the compile. 32856a97f93Sjef"$@" 32956a97f93Sjefret=$? 330e34c20c8SJon Dugan 331e34c20c8SJon Duganif test -f "$cofile"; then 332487ee810SBruce A. Mah test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33356a97f93Sjefelif test -f "${cofile}bj"; then 334487ee810SBruce A. Mah test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 335e34c20c8SJon Duganfi 336e34c20c8SJon Dugan 33756a97f93Sjefrmdir "$lockdir" 33856a97f93Sjefexit $ret 33956a97f93Sjef 34056a97f93Sjef# Local Variables: 34156a97f93Sjef# mode: shell-script 34256a97f93Sjef# sh-indentation: 2 3436e9d8525SBruce A. Mah# eval: (add-hook 'before-save-hook 'time-stamp) 34456a97f93Sjef# time-stamp-start: "scriptversion=" 34556a97f93Sjef# time-stamp-format: "%:y-%02m-%02d.%02H" 3467cf95d20SBruce A. Mah# time-stamp-time-zone: "UTC0" 347487ee810SBruce A. Mah# time-stamp-end: "; # UTC" 34856a97f93Sjef# End: 349