Blame compile

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