Blame compile

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