compile revision a747113422afaa29ce72d2c5ba7f0b7ea9ec2054
341N/A#! /bin/sh
341N/A# Wrapper for compilers which do not understand '-c -o'.
341N/A
341N/Ascriptversion=2012-03-05.13; # UTC
943N/A
341N/A# Copyright (C) 1999-2012 Free Software Foundation, Inc.
341N/A# Written by Tom Tromey <tromey@cygnus.com>.
919N/A#
919N/A# This program is free software; you can redistribute it and/or modify
919N/A# it under the terms of the GNU General Public License as published by
919N/A# the Free Software Foundation; either version 2, or (at your option)
919N/A# any later version.
919N/A#
919N/A# This program is distributed in the hope that it will be useful,
919N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
919N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
919N/A# GNU General Public License for more details.
919N/A#
919N/A# You should have received a copy of the GNU General Public License
919N/A# along with this program. If not, see <http://www.gnu.org/licenses/>.
919N/A
919N/A# As a special exception to the GNU General Public License, if you
919N/A# distribute this file as part of a program that contains a
919N/A# configuration script generated by Autoconf, you may include it under
341N/A# the same distribution terms that you use for the rest of that program.
341N/A
341N/A# This file is maintained in Automake, please report
341N/A# bugs to <bug-automake@gnu.org> or send patches to
493N/A# <automake-patches@gnu.org>.
341N/A
341N/Anl='
962N/A'
341N/A
911N/A# We need space, tab and new line, in precisely that order. Quoting is
962N/A# there to prevent tools from complaining about whitespace usage.
962N/AIFS=" "" $nl"
911N/A
341N/Afile_conv=
341N/A
341N/A# func_file_conv build_file lazy
341N/A# Convert a $build file to $host form and store it in $file
341N/A# Currently only supports Windows hosts. If the determined conversion
341N/A# type is listed in (the comma separated) LAZY, no conversion will
341N/A# take place.
341N/Afunc_file_conv ()
341N/A{
341N/A file=$1
392N/A case $file in
604N/A / | /[!/]*) # absolute file, and not a UNC file
646N/A if test -z "$file_conv"; then
812N/A # lazily determine how to convert abs files
688N/A case `uname -s` in
688N/A MINGW*)
688N/A file_conv=mingw
688N/A ;;
688N/A CYGWIN*)
688N/A file_conv=cygwin
688N/A ;;
688N/A *)
688N/A file_conv=wine
688N/A ;;
688N/A esac
688N/A fi
688N/A case $file_conv/,$2, in
688N/A *,$file_conv,*)
688N/A ;;
688N/A mingw/*)
688N/A file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
688N/A ;;
688N/A cygwin/*)
688N/A file=`cygpath -m "$file" || echo "$file"`
688N/A ;;
688N/A wine/*)
688N/A file=`winepath -w "$file" || echo "$file"`
688N/A ;;
688N/A esac
688N/A ;;
688N/A esac
851N/A}
688N/A
688N/A# func_cl_dashL linkdir
688N/A# Make cl look for libraries in LINKDIR
688N/Afunc_cl_dashL ()
688N/A{
688N/A func_file_conv "$1"
688N/A if test -z "$lib_path"; then
688N/A lib_path=$file
688N/A else
688N/A lib_path="$lib_path;$file"
688N/A fi
688N/A linker_opts="$linker_opts -LIBPATH:$file"
688N/A}
688N/A
688N/A# func_cl_dashl library
816N/A# Do a library search-path lookup for cl
962N/Afunc_cl_dashl ()
341N/A{
341N/A lib=$1
341N/A found=no
341N/A save_IFS=$IFS
970N/A IFS=';'
970N/A for dir in $lib_path $LIB
970N/A do
970N/A IFS=$save_IFS
970N/A if $shared && test -f "$dir/$lib.dll.lib"; then
970N/A found=yes
970N/A lib=$dir/$lib.dll.lib
970N/A break
970N/A fi
970N/A if test -f "$dir/$lib.lib"; then
970N/A found=yes
970N/A lib=$dir/$lib.lib
970N/A break
970N/A fi
341N/A done
341N/A IFS=$save_IFS
493N/A
969N/A if test "$found" != yes; then
341N/A lib=$lib.lib
341N/A fi
493N/A}
851N/A
341N/A# func_cl_wrapper cl arg...
341N/A# Adjust compile command to suit cl
341N/Afunc_cl_wrapper ()
341N/A{
341N/A # Assume a capable shell
493N/A lib_path=
341N/A shared=:
341N/A linker_opts=
341N/A for arg
341N/A do
493N/A if test -n "$eat"; then
341N/A eat=
965N/A else
965N/A case $1 in
851N/A -o)
851N/A # configure might choose to run compile as 'compile cc -o foo foo.c'.
851N/A eat=1
851N/A case $2 in
851N/A *.o | *.[oO][bB][jJ])
341N/A func_file_conv "$2"
493N/A set x "$@" -Fo"$file"
341N/A shift
341N/A ;;
341N/A *)
341N/A func_file_conv "$2"
341N/A set x "$@" -Fe"$file"
341N/A shift
341N/A ;;
493N/A esac
341N/A ;;
341N/A -I)
341N/A eat=1
341N/A func_file_conv "$2" mingw
341N/A set x "$@" -I"$file"
493N/A shift
493N/A ;;
493N/A -I*)
493N/A func_file_conv "${1#-I}" mingw
341N/A set x "$@" -I"$file"
341N/A shift
341N/A ;;
922N/A -l)
922N/A eat=1
910N/A func_cl_dashl "$2"
970N/A set x "$@" "$lib"
970N/A shift
963N/A ;;
963N/A -l*)
970N/A func_cl_dashl "${1#-l}"
970N/A set x "$@" "$lib"
970N/A shift
922N/A ;;
922N/A -L)
922N/A eat=1
851N/A func_cl_dashL "$2"
851N/A ;;
851N/A -L*)
341N/A func_cl_dashL "${1#-L}"
851N/A ;;
922N/A -static)
851N/A shared=false
963N/A ;;
970N/A -Wl,*)
963N/A arg=${1#-Wl,}
963N/A save_ifs="$IFS"; IFS=','
963N/A for flag in $arg; do
963N/A IFS="$save_ifs"
963N/A linker_opts="$linker_opts $flag"
963N/A done
963N/A IFS="$save_ifs"
;;
-Xlinker)
eat=1
linker_opts="$linker_opts $2"
;;
-*)
set x "$@" "$1"
shift
;;
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
func_file_conv "$1"
set x "$@" -Tp"$file"
shift
;;
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
func_file_conv "$1" mingw
set x "$@" "$file"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -n "$linker_opts"; then
linker_opts="-link$linker_opts"
fi
exec "$@" $linker_opts
exit 1
}
eat=
case $1 in
'')
echo "$0: No command. Try '$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
cat <<\EOF
Usage: compile [--help] [--version] PROGRAM [ARGS]
Wrapper for compilers which do not understand '-c -o'.
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
arguments, and rename the output as expected.
If you are trying to build a whole package this is not the
right script to run: please start by reading the file 'INSTALL'.
Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
-v | --v*)
echo "compile $scriptversion"
exit $?
;;
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
func_cl_wrapper "$@" # Doesn't return...
;;
esac
ofile=
cfile=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as 'compile cc -o foo foo.c'.
# So we strip '-o arg' only if arg is an object.
eat=1
case $2 in
*.o | *.obj)
ofile=$2
;;
*)
set x "$@" -o "$2"
shift
;;
esac
;;
*.c)
cfile=$1
set x "$@" "$1"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -z "$ofile" || test -z "$cfile"; then
# If no '-o' option was seen then we might have been invoked from a
# pattern rule where we don't need one. That is ok -- this is a
# normal compilation that the losing compiler can handle. If no
# '.c' file was seen then we are probably linking. That is also
# ok.
exec "$@"
fi
# Name of file we expect compiler to create.
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
# Create the lock directory.
# Note: use '[/\\:.-]' here to ensure that we don't use the same name
# that we are using for the .o file. Also, base the name on the expected
# object file name, since that is what matters with a parallel build.
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
while true; do
if mkdir "$lockdir" >/dev/null 2>&1; then
break
fi
sleep 1
done
# FIXME: race condition here if user kills between mkdir and trap.
trap "rmdir '$lockdir'; exit 1" 1 2 15
# Run the compile.
"$@"
ret=$?
if test -f "$cofile"; then
test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
elif test -f "${cofile}bj"; then
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
fi
rmdir "$lockdir"
exit $ret
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End: