Blame config/compile

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