Blame compile

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