Blame build-aux/compile

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