#!/bin/sh
#
# ${R_HOME}/bin/SHLIB

# @configure_input@

revision='$Revision: 1.14 $'
version=`set - ${revision}; echo ${2}`
version="R shared library builder ${version}"

usage="Usage: R SHLIB [options] files

Build a shared library for dynamic loading from the specified source or
object files (which are automagically made from their sources).  If not
given via \`--output', the name for the library is determined from the
first file.

Options:
  -h, --help		print short help message and exit
  -o, --output=LIB	use LIB as (full) name for the built library
  -v, --version		print version info and exit

Report bugs to <R-bugs@lists.r-project.org>."

lib=
objs=
MAKE=${MAKE-@MAKE@}
makefiles="-f ${R_HOME}/etc/Makeconf"
SHLIB_CXXLD=@SHLIB_CXXLD@
SHLIB_CXXLDFLAGS=@SHLIB_CXXLDFLAGS@
with_cxx=false

while test -n "${1}"; do
  case ${1} in
    -h|--help)
       echo "${usage}"; exit 0 ;;
    -v|--version)
       echo "${version}"; exit 0 ;;
    -o)
      lib=${2}; shift ;;
    --output=*)
      lib=`echo "${1}" | sed -e 's/[^=]*=//'` ;;
    *.cc|*.cpp|.*C)
      with_cxx=true
      if test -z "${lib}"; then
	lib="`echo ${1} | sed 's/\.[^\.][^\.]*$/.@SHLIB_EXT@/'`"
      fi
      objs="${objs} `echo ${1} | sed 's/\.[^\.][^\.]*$/.o/'`"
      ;;
    *.[cfo])
      if test -z "${lib}"; then
	lib="`echo ${1} | sed 's/\.[^\.][^\.]*$/.@SHLIB_EXT@/'`"
      fi
      objs="${objs} `echo ${1} | sed 's/\.[^\.][^\.]*$/.o/'`"
      ;;
  esac
  shift
done

if test -r Makevars; then
  makefiles="-f Makevars ${makefiles}"
fi

if ${with_cxx}; then
  ${MAKE} ${makefiles} SHLIB_LD="${SHLIB_CXXLD}" SHLIB_LDFLAGS="${SHLIB_CXXLDFLAGS}" SHLIB="${lib}" OBJS="${objs}"
else
  ${MAKE} ${makefiles} SHLIB="${lib}" OBJS="${objs}"
fi

### Local Variables: ***
### mode: sh ***
### sh-indentation: 2 ***
### End: ***