Blame compile

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