Rev 25954 | Blame | Last modification | View Log | Download | RSS feed
#! /bin/sh## ${R_HOME}/bin/INSTALL for installing add-on packages# @configure_input@revision='$Revision: 1.137 $'version=`set - ${revision}; echo ${2}`version="R add-on package installer ${version}Copyright (C) 2000-2003 The R Core Development Team.This is free software; see the GNU General Public Licence version 2or later for copying conditions. There is NO warranty."usage="Usage: R CMD INSTALL [options] pkgsInstall the add-on packages specified by pkgs. The elements of pkgs canbe relative or absolute paths to directories with the package (bundle)sources, or to gzipped package 'tar' archives. The library tree toinstall to can be specified via '--library'. By default, packages areinstalled in the library tree rooted at the first directory given in theenvironment variable R_LIBS if this is set and non-null, and into thedefault R library tree (${R_HOME}/library) otherwise.Options:-h, --help print short help message and exit-v, --version print version info and exit--configure-args=ARGSset arguments for the package's configure script(if any)--configure-vars=VARSset variables for the configure script (if any)-c, --clean remove all files created during installation-s, --save[=ARGS] save the package source as an image file, andarrange for this file to be loaded when thepackage is attached; if given, ARGS are passedto R when creating the save image--no-save do not save the package source as an image file-d, --debug turn on shell and build-help debugging-l, --library=LIB install packages to library tree LIB--no-configure do not use the package's configure script--no-docs do not build and install documentation--with-package-versionsallow for multiple versions of the same package--use-zip-data collect data files in zip archive--use-zip-help collect help and examples into zip archives--use-zip combine '--use-zip-data' and '--use-zip-help'--fake do minimal install for testing purposesReport bugs to <r-bugs@r-project.org>."## <NOTE>## This is a *shell* script.## According to the R Coding Standards (see R-exts), Perl can be assumed## for *source*, but not for *binary* installations.## </NOTE>## <FIXME>## This uses## mkdir -p## basename## which are not portable.## We could fix this using suitable shell replacements, but we should## really redo as much as we can using R code.## </FIXME>## <NOTE>## We try to be defensive about possible white space in file names,## hence all the strange quoting ...## </NOTE>umask 022R_VERSION='@VERSION@'GETWD='@GETWD@'MAKE=${MAKE-'@MAKE@'}NO_PERL5=@NO_PERL5@NO_PERL5_MSG="\*** Formatting and installing R help pages needs Perl version 5, which*** does not seem to be installed on your system or is not in your path.*** Please install either Perl 5 on your system and re-configure R or*** get the PDF reference manual from the nearest CRAN server.*** The CRAN master site can be found at*** http://cran.r-project.org/"startdir=`${GETWD}`tmpdir="${TMPDIR-/tmp}/R.INSTALL.$$"if (test -d "${tmpdir}" && test -w "${tmpdir}") || \mkdir -p "${tmpdir}" 2> /dev/null; thentmpdir=`cd "${tmpdir}" && ${GETWD}`elseecho "ERROR: cannot write to or create temporary directory '${tmpdir}'"exit 1fi: ${R_OSTYPE=unix}## <NOTE>## Unix only ... but Windows has INSTALL as a Perl script.R_EXE="${R_HOME}/bin/R"## </NOTE>## <NOTE>## It might make sense to abstract error and warnings into functions## like## warning () { echo "WARNING: $*" }## error () { echo "ERROR: $*" }## and maybe even redirect this to stderr on Unix.## </NOTE>## <NOTE>## This could be made a bit more general: if R CMD INSTALL is run by## another tool (e.g., when building or checking a package, its messages## should be a section level deeper (at least). So we could have an## argument to set the initial secnumdepth (0 by default), and work## against this ...message () { echo "${stars} $*"; }stars="*"## </NOTE>. "${R_HOME}/share/sh/dcf.sh" # get_dcf_field()get_packages () {## get the full path names to all packages contained in $1.## NOTE: modifies pkgs!if grep "^Contains:" "${1}/DESCRIPTION" >/dev/null; thenbundlepkg=`get_dcf_field Contains "${1}/DESCRIPTION"`for p in ${bundlepkg}; dopkgs="${pkgs} \"`cd "${1}/${p}" && ${GETWD}`\""if test -f "${1}/${p}/DESCRIPTION.in"; thencat "${1}/${p}/DESCRIPTION.in" > "${1}/${p}/DESCRIPTION"grep -v "^Contains:" "${1}/DESCRIPTION" >> "${1}/${p}/DESCRIPTION"fidoneelsepkgs="${pkgs} \"`cd "${1}" && ${GETWD}`\""fi}###### Setup and command line processing.if test -n "${R_LIBS}"; thenlib=`echo "${R_LIBS}" | cut -f1 -d:`elselib="${R_HOME}/library"fipkgs=clean=falsedebug=falseerror=falsebuild_text=truebuild_html=truebuild_latex=truebuild_example=truebuild_help=truebuild_help_opts=use_configure=trueuse_zip_data=use_zip_help=configure_args=configure_vars=with_package_versions=falsesave="CHECK"save_args=fake=falsewhile test -n "${1}"; docase ${1} in-h|--help)echo "${usage}"; exit 0 ;;-v|--version)echo "${version}"; exit 0 ;;-c|--clean)clean=true ;;-s|--save)save=true;;--save=*)save_args=`echo "${1}" | sed -e 's/[^=]*=//'` ;;--no-save)save=false ;;-d|--debug)debug=true ;;--with-package-versions)with_package_versions=true ;;--no-configure)use_configure=false ;;--no-docs)build_text=falsebuild_html=falsebuild_latex=falsebuild_example=false ;;--no-text)build_text=false ;;--no-html)build_html=false ;;--no-latex)build_latex=false ;;--no-example)build_example=false ;;--use-zip)use_zip_data=trueuse_zip_help=true ;;--use-zip-data)use_zip_data=true ;;--use-zip-help)use_zip_help=true ;;-l|--library)lib="${2}"; shift ;;--library=*)lib=`echo "${1}" | sed -e 's/[^=]*=//'` ;;--configure-args=*)configure_args=`echo "${1}" | sed -e 's/[^=]*=//'` ;;--configure-vars=*)configure_vars=`echo "${1}" | sed -e 's/[^=]*=//'` ;;--fake)fake=true ;;*)if test -f "${1}"; thenpkgname=`basename "${1}"`## Also allow for 'package.tgz' ...pkgname=`basename "${pkgname}" .tgz`pkgname=`echo "${pkgname}" | sed 's/_.*//'`## Note that we use '-m' so that modification dates are *not*## preserved when untarring the sources. This is necessary to## ensure that the preformatted help pages are always rebuilt.## Otherwise, the build date for an older version may be newer## than the modification date for the new sources as recorded in## the tarball ...gzip -dc "${1}" | (cd "${tmpdir}" && tar -mxf -)if test -f "${tmpdir}/${pkgname}/DESCRIPTION"; thenget_packages "${tmpdir}/${pkgname}"elseecho "ERROR: cannot extract package from '${1}'"exit 1fielif test -f "${1}/DESCRIPTION"; thenget_packages "${1}"elseecho "WARNING: invalid package '${1}'"fi;;esacshiftdoneif test -z "${pkgs}"; thenecho "ERROR: no packages specified"exit 1fiif (test -d "${lib}" && test -w "${lib}") || \mkdir -p "${lib}" 2> /dev/null; thenlib=`cd "${lib}" && ${GETWD}`elseecho "ERROR: cannot write to or create directory '${lib}'"exit 2filockdir="${lib}/00LOCK"if test -d "${lockdir}" || test -f "${lockdir}"; thenecho "ERROR: failed to lock directory '${lib}' for modifying"echo "Try removing '${lockdir}'"exit 3elsemkdir -p "${lockdir}"if test ${?} -ne 0; then## This should not really happen ...echo "ERROR: failed to lock directory '${lib}' for modifying"exit 3fifiif ${fake}; thenuse_configure=falsebuild_text=truebuild_html=falsebuild_latex=truebuild_example=falsefiif ${build_text}; thenbuild_help_opts="${build_help_opts} --txt"fiif ${build_html}; thenbuild_help_opts="${build_help_opts} --html"fiif ${build_latex}; thenbuild_help_opts="${build_help_opts} --latex"fiif ${build_example}; thenbuild_help_opts="${build_help_opts} --example"fiif test -z "${build_help_opts}"; thenbuild_help=falseelif ${debug}; thenbuild_help_opts="--debug ${build_help_opts}"fiis_first_package=yes###### Install a *binary* package from the current directory.do_install_binary () {pkg="${1}"R_PACKAGE_DIR="${2}"R_PACKAGE_NAME="${3}"if test "${pkg}" = "${R_PACKAGE_NAME}"; thenmessage "Installing *binary* package '${pkg}' ..."elsemessage "Installing *binary* package '${pkg}' as '${R_PACKAGE_NAME}' ..."fiif test -f "${R_PACKAGE_DIR}/DESCRIPTION"; then## Back up previous version.mv "${R_PACKAGE_DIR}" "${lockdir}/${R_PACKAGE_NAME}"mkdir -p "${R_PACKAGE_DIR}"ficp -r . "${R_PACKAGE_DIR}"if test ${?} -ne 0; thenecho "ERROR: installing binary package failed"do_exit_on_errorfi}###### Install a *source* package from the current directory.do_install_source () {pkg_name="${1}"pkg_dir="${4}"## (The basename of ${pkg_dir} might be different from ${pkg_name},## e.g., when building Debian packages from R packages.)## Make the destination directories available to the developer's## installation scripts (e.g. configure, etc.)R_PACKAGE_DIR="${2}"R_PACKAGE_NAME="${3}"R_LIBRARY_DIR="${lib}"export R_LIBRARY_DIRexport R_PACKAGE_DIRexport R_PACKAGE_NAMEif test "${pkg_name}" = "${R_PACKAGE_NAME}"; thenmessage "Installing *source* package '${pkg_name}' ..."elsemessage "Installing *source* package '${pkg_name}' as '${R_PACKAGE_NAME}' ..."fistars="**"if test -f "${R_PACKAGE_DIR}/DESCRIPTION"; then## Back up previous version.mv "${R_PACKAGE_DIR}" "${lockdir}/${R_PACKAGE_NAME}"mkdir -p "${R_PACKAGE_DIR}"## Preserve man pages to speed up installation? Only makes sense## if we install from a non-temporary directory.if test "`cd .. && ${GETWD}`" != \"`cd \"${tmpdir}\" && ${GETWD}`"; then(cd "${lockdir}/${R_PACKAGE_NAME}" \&& tar cf - R-ex help html latex) | \(cd "${R_PACKAGE_DIR}" && tar xf -)fifiif ${use_configure} && test -x ./configure ; theneval ${configure_vars} ./configure ${configure_args}if test ${?} -ne 0; thenecho "ERROR: configuration failed for package '${pkg_name}'"do_exit_on_errorfififor f in COPYING NAMESPACE; doif test -f "${f}"; then cp "${f}" "${R_PACKAGE_DIR}"; fidone## Copy DESCRIPTION file, stamp with build information, and remove## blank lines. (Need to add an empty line to deal with missing## trailing newlines at EOF.)## As from 1.7.0, packages without compiled code are not marked## as being from any platform.echo ".installPackageDescription(\".\", \"${R_PACKAGE_DIR}\")" | \R_DEFAULT_PACKAGES=tools ${R_EXE} --vanilla >/dev/nullif test ${?} -ne 0; thenecho "ERROR: installing package DESCRIPTION failed"do_exit_on_errorfiif test -d src && test "${fake}" != "true"; thenmessage "libs"if ${debug}; then set -x; fimkdir -p "${R_PACKAGE_DIR}/libs"if test -f src/Makefile; thencd src;makefiles="-f \"${R_HOME}\"/share/make/shlib.mk -f Makefile"if test -r Makevars; thenmakefiles="-f Makevars ${makefiles}"fieval ${MAKE} ${makefiles} \&& cp *@SHLIB_EXT@ "${R_PACKAGE_DIR}/libs" \|| error=true; \if ${clean}; then${MAKE} cleanficd ..elsecd src;srcs=`ls *.[cfC] *.cc *.cpp 2>/dev/null`if test -n "${srcs}"; thensh "${R_HOME}/bin/SHLIB" -o "${pkg_name}@SHLIB_EXT@" ${srcs} \&& cp *@SHLIB_EXT@ "${R_PACKAGE_DIR}/libs" \|| error=true; \if ${clean}; thenrm -rf .libs _libsrm -f *.o *@SHLIB_EXT@fielseecho "WARNING: no source files found"ficd ..fiif ${error}; thenecho "ERROR: compilation failed for package '${pkg_name}'"do_exit_on_errorfiif ${debug}; then set +x; fifiif test -d R; thenmessage "R"mkdir -p "${R_PACKAGE_DIR}/R"rm -f "${R_PACKAGE_DIR}/R/"*echo ".installPackageCodeFiles(\".\", \"${R_PACKAGE_DIR}\")" | \R_DEFAULT_PACKAGES=tools ${R_EXE} --vanilla >/dev/nullif test ${?} -ne 0; thenecho "ERROR: unable to collate files for package '${pkg_name}'"do_exit_on_errorfiif ${fake}; thenif test -f NAMESPACE; thenecho ".onLoad <- function(list, pkg) NULL" >> \"${R_PACKAGE_DIR}/R/${R_PACKAGE_NAME}"sed -e '/useDynLib/d' NAMESPACE > "${R_PACKAGE_DIR}/NAMESPACE"elseecho ".First.lib <- function(lib, pkg) NULL" >> \"${R_PACKAGE_DIR}/R/${R_PACKAGE_NAME}"fififiif test -d data; thenmessage "data"mkdir -p "${R_PACKAGE_DIR}/data"rm -f "${R_PACKAGE_DIR}/data/"*cp data/* "${R_PACKAGE_DIR}/data" 2>/dev/nullchmod 644 "${R_PACKAGE_DIR}/data/"*if test -n "${use_zip_data}" \&& test -n "${R_UNZIPCMD}" \&& test -n "${R_ZIPCMD}"; then(cd "${R_PACKAGE_DIR}/data";find . -type f -print > filelist${R_ZIPCMD} -m Rdata * -x filelist 00Index)fifiif test -d demo && test "${fake}" != "true"; thenmessage "demo"mkdir -p "${R_PACKAGE_DIR}/demo"rm -f "${R_PACKAGE_DIR}/demo/"*cp demo/* "${R_PACKAGE_DIR}/demo" 2>/dev/nullchmod 644 "${R_PACKAGE_DIR}/demo/"*fiif test -d exec && test "${fake}" != "true"; thenmessage "exec"mkdir -p "${R_PACKAGE_DIR}/exec"rm -f "${R_PACKAGE_DIR}/exec/"*cp exec/* "${R_PACKAGE_DIR}/exec" 2>/dev/nullchmod 755 "${R_PACKAGE_DIR}/exec/"*fiif test -d inst && test "${fake}" != "true"; thenmessage "inst"cp -r inst/* "${R_PACKAGE_DIR}"ficase ${save} inCHECK)if test -r install.R; thenR_SAVE_IMAGE=true;elseR_SAVE_IMAGE=false;fi;;*)R_SAVE_IMAGE=${save} ;;esacexport R_SAVE_IMAGEif ${R_SAVE_IMAGE}; thenmessage "save image"## <NOTE>## We want R to run as quietly as possible when creating the save## image. But this is tricky: sending options(echo=FALSE) to R via## stdin (as opposed to writing to a file and reading from it)## echoes what we sent before shutting up R, which is not what we## want. Option '--slave' gets around this but also turns off## saving ... hence we call R with '--slave --save' (in case there## is no namespace). Argh.## </NOTE>save_image_defaults="list(compress=TRUE, safe=FALSE)"code_file="${R_PACKAGE_DIR}/R/${R_PACKAGE_NAME}"rda_file="${R_PACKAGE_DIR}/R/all.rda"if test -f NAMESPACE; thencode_cmd="echo saveNamespaceImage(\"${pkg_name}\", \"${rda_file}\", \"${lib}\")"loader_file=nsrdaload.RR_SAVE_EXE="${R_EXE} --vanilla --slave"elsecode_cmd="eval cat \"${code_file}\""loader_file=firstlib.RR_SAVE_EXE="${R_EXE} --vanilla --slave --save"fi(echo "options(save.image.defaults=${save_image_defaults})"; \if test -s R_PROFILE.R; then cat R_PROFILE.R; fi; \echo "invisible(.libPaths(c(\"${lib}\", .libPaths())))"; \${code_cmd}) | R_DEFAULT_PACKAGES=NULL ${R_SAVE_EXE} ${save_args}if test ${?} -ne 0; thenecho "ERROR: execution of package source for '${pkg_name}' failed"do_exit_on_errorfitest -f NAMESPACE || mv .RData "${rda_file}"mv "${code_file}" "${R_PACKAGE_DIR}/R/${pkg_name}.R"cat "${R_HOME}/share/R/${loader_file}" > "${code_file}"## If install.R is non-empty, arrange to evaluate the R code it## contains after the package source (maybe for some kind of## cleanup).if test -s install.R; thencat install.R >> "${R_PACKAGE_DIR}/R/${R_PACKAGE_NAME}"fifiif test -d man; thenmessage "help"## Install man sources ...Rdfiles=`ls man/*.[Rr]d man/${R_OSTYPE}/*.[Rr]d 2>/dev/null`if test -n "${Rdfiles}"; thenmkdir -p "${R_PACKAGE_DIR}/man"rm -f "${R_PACKAGE_DIR}/man/"*for f in ${Rdfiles}; do cat "${f}"; echo; echo '\eof'; done \> "${R_PACKAGE_DIR}/man/${pkg_name}.Rd"chmod 644 "${R_PACKAGE_DIR}/man/${pkg_name}.Rd"fi## Maybe build preformatted help pages ...if ${build_help}; thenif ${NO_PERL5}; thenecho "${NO_PERL5_MSG}"elseif ${debug}; thenecho "DEBUG: build-help ${BUILD_HELP_OPTS} ${pkg_dir} ${lib} ${R_PACKAGE_DIR} ${pkg_name}"fi${R_CMD} perl "${R_HOME}/share/perl/build-help.pl" \${build_help_opts} \"${pkg_dir}" "${lib}" "${R_PACKAGE_DIR}" "${pkg_name}"if test ${?} -ne 0; thenecho "ERROR: building help failed for package '${pkg_name}'"do_exit_on_errorfifiif test -n "${use_zip_help}" \&& test -n "${R_UNZIPCMD}" \&& test -n "${R_ZIPCMD}"; then(cd "${R_PACKAGE_DIR}"if test -d R-ex; then(cd R-ex; ${R_ZIPCMD} -m Rex *.R)fi## NOT YET:## if test -d latex; then## (cd latex; ${R_ZIPCMD} -m Rhelp *.tex)## fiif test -d help; then(cd help; ${R_ZIPCMD} -m Rhelp * -x AnIndex);fi)fifielseecho "No man pages found in package '${pkg_name}'"fiecho ".installPackageIndices(\".\", \"${R_PACKAGE_DIR}\")" | \R_DEFAULT_PACKAGES=tools ${R_EXE} --vanilla >/dev/nullif test ${?} -ne 0; thenecho "ERROR: installing package indices failed"do_exit_on_errorfi## <FIXME>## Remove stuff we should not have installed in the first place.## When installing from a source directory under CVS control, we## should really exclude the CVS subdirs. (In fact, we should also## exclude everything in @file{.Rbuildignore}, but that's another## story ...)find "${R_PACKAGE_DIR}" -name CVS -exec rm -rf \{\} \; 2>/dev/null## </FIXME>if ${clean}; thenif test -x ./cleanup ; then./cleanupfifistars="*"}###### Install a package.do_install () {cd "${1}"pkg_dir="${1}"pkg_name=`get_dcf_field Package DESCRIPTION`## (The basename of ${pkg_dir} might be different from ${pkg_name},## e.g., when building Debian packages from R packages.)## Set R_PACKAGE_DIR here at the top level. If a version is being## specified, tack that on.if ${with_package_versions}; thenversion=`get_dcf_field Version DESCRIPTION`R_PACKAGE_NAME="${pkg_name}_${version}"R_PACKAGE_DIR="${lib}/${pkg_name}_${version}"elseR_PACKAGE_NAME="${pkg_name}"R_PACKAGE_DIR="${lib}/${pkg_name}"fiexport R_PACKAGE_DIRexport R_PACKAGE_NAMEdepends=`get_dcf_field Depends DESCRIPTION`depends=`echo "${depends}" | grep 'R *('`if test "${depends}"; thendepends=`echo "${depends}" | sed 's/.*R *(\([^)]*\)).*/\1/;s/=/= /'`dep_operator=`set - ${depends}; echo ${1}`dep_version=`set - ${depends}; echo ${2}`## Currently, only operators '<=' and '>=' are supported. Hence we## check this, and also whether we found a version string.if (test "${dep_operator}" = "<=" \|| test "${dep_operator}" = ">=") \&& test -n "${dep_version}"; thendep_ok=`expr ${R_VERSION} ${dep_operator} ${dep_version} `if test ${dep_ok} -eq 0; thenecho "ERROR: This R is version ${R_VERSION}"echo " package '${pkg_name}' depends on R ${dep_version}"do_exit_on_error;fielseecho "WARNING: malformed 'Depends' field in 'DESCRIPTION'"fifimkdir -p "${R_PACKAGE_DIR}" || do_exit_on_error no## Make sure we do not attempt installing to srcdir.if test "`cd \"${R_PACKAGE_DIR}\" && ${GETWD}`" = "`${GETWD}`"; thenecho "ERROR: cannot install to srcdir"do_exit_on_error nofi## Figure out whether this is a source or binary package.## <NOTE>## If DESCRIPTION has a @samp{Built:} entry, this is a binary package.## This is the right test, but not available for packages installed## prior to R 1.4. For some time, we thus checked for the existence## of a 'man' subdir if no build information was found in DESCRIPTION,## using the fact that versions of R prior to 1.4 also did not install## documentation sources, and assuming that all source packages would## have some documentation, which caused problems for people who had## not yet written any docs ... hence, from R 1.6 on only DESCRIPTION## is looked at.## </NOTE>if grep "^Built:" DESCRIPTION >/dev/null ; then## If DESCRIPTION has a @samp{Built:} entry this is a binary## package. This is the right test, but not available for packages## installed prior to 1.4.0.is_source_package=falseelseis_source_package=truefitest "${is_first_package}" = no && echoif ${is_source_package}; then## This is a source package ... hopefully.do_install_source \"${pkg_name}" "${R_PACKAGE_DIR}" "${R_PACKAGE_NAME}" "${pkg_dir}"else## This is a binary package ... hopefully.do_install_binary \"${pkg_name}" "${R_PACKAGE_DIR}" "${R_PACKAGE_NAME}"fichmod -R a+r "${R_PACKAGE_DIR}"message "DONE (${pkg_name})"is_first_package=no}###### Exit and cleanup.do_exit_on_error () {remove_R_package_dir=${1-yes}if test "${remove_R_package_dir}" = yes; thenmessage "Removing '${R_PACKAGE_DIR}'"rm -rf "${R_PACKAGE_DIR}"fiif test -d "${lockdir}/${R_PACKAGE_NAME}"; thenmessage "Restoring previous '${R_PACKAGE_DIR}'"mv "${lockdir}/${R_PACKAGE_NAME}" "${R_PACKAGE_DIR}"fido_cleanupexit 1}do_cleanup () {## Solaris will not remove any directory in the current pathcd "${startdir}"if test -d "${tmpdir}"; thenrm -rf "${tmpdir}"fiif test "${is_first_package}" = no; then## Only need to do this in case we successfully installed at least## *one* package ...cp "${R_HOME}/doc/html/R.css" "${lib}"if test "${lib}" = `cd "${R_HOME}/library" && ${GETWD}`; thencat "${R_HOME}"/library/*/CONTENTS \> "${R_HOME}"/doc/html/search/index.txtif ${build_help} && test "${NO_PERL5}" = "false"; then${R_CMD} perl "${R_HOME}/share/perl/build-help.pl" --htmllistsfififirm -rf "${lockdir}"}###### Main loop.eval "for pkg in ${pkgs}; do do_install \"\${pkg}\"; done"do_cleanup### Local Variables: ***### mode: sh ***### sh-indentation: 2 ***### End: ***