Blame compile

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