Blame compile

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