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