Blame build-aux/compile

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