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