Blame compile

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