Blame compile

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