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