Blame build-aux/compile

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