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