Blame compile

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