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