Blame compile

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