csomh / source-git / rpm

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