Blame config.aux/compile

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