Blame compile

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