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