Blame build-aux/compile

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