Blame compile

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