Blame build-aux/compile

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