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