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