Blame compile

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