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