Blame compile

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