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