Rev 7284 | Blame | Last modification | View Log | Download | RSS feed
#!/bin/sh## ${R_HOME}/bin/buildREVISION='$Revision: 1.4 $'VERSION=`set - ${REVISION}; echo ${2}`VERSION="R package builder version ${VERSION}Copyright (C) 1999 R Development Core Team.There is NO warranty. You may redistribute this software under theterms of the GNU General Public License.For more information about these matters, see the files named COPYING."USAGE_MSG="Usage: R CMD build [options] pkgdir_1 ... pkgdir_nBuild R packages from package sources in the PKGDIR_i directories.A variety of diagnostic checks and cleanups are performed prior tobuilding the packages.Options:-h, --help Display this help and exit successfully.-v, --version Display version information and exit successfully.--vsize=N Set R's vector heap size to N bytes.--nsize=N Set R's number of cons cells to N.--force Force overwriting of (index) files.Email bug reports to <r-bugs@lists.r-project.org>."R_opts="--vanilla"DEBUG=falseFORCE=falsePKGS=START_DIR=`pwd`## Parse argument command linewhile test -n "${1}"; docase ${1} in-h|--help)echo "${USAGE_MSG}"; exit 0 ;;-v|--version)echo "${VERSION}"; exit 0 ;;-d|--debug)DEBUG=true ;;--force)FORCE=true ;;--nsize=*)R_NSIZE=`echo "${1}" | sed -e 's/[^=]*=//'` ;;--vsize=*)R_VSIZE=`echo "${1}" | sed -e 's/[^=]*=//'` ;;*)PKGS="${PKGS} ${1}" ;;esacshiftdone## Determine whether echo can suppress newlines.if echo "testing\c" | grep c >/dev/null; thenif echo -n "testing" | sed s/-n/xn/ | grep xn >/dev/null; thenECHO_N= ECHO_C= ECHO_T=' 'elseECHO_N=-n ECHO_C= ECHO_T=fielseECHO_N= ECHO_C='\c' ECHO_T=fi## A few useful output functionschecking () { echo ${ECHO_N} "* checking $@ ...${ECHO_C}"; }message () { echo "* $@"; }result () { echo "${ECHO_T} $@"; }## For updating `INDEX' and `data/00Index;updateIndex () {oldindex=${1}newindex=${TMPDIR:-/tmp}/Rbuild${$}R CMD Rdindex ${Rdfiles} > ${newindex}if cmp ${newindex} ${oldindex} > /dev/null; thenresult "OK"elseresult "NO"if ${FORCE}; thenecho "overwriting \`${oldindex}' as \`--force' was given"cp ${newindex} ${oldindex}elseecho "use \`--force' to overwrite the existing \`${oldindex}'"fifirm -f ${newindex}}## The work horsebuildpkg () {echo "Building package \`${1}' ..."cd ${START_DIR}checking "package dir"if test -d ${1}; thendir=`cd ${1}; pwd`elseresult "ERROR: package dir \`${1}' does not exist"exit 1firesult "OK"## Check whether `DESCRIPTION' exists and contains required fieldschecking "for \`DESCRIPTION'"if test -r ${dir}/DESCRIPTION; thencd ${dir}elseresult "ERROR: file \`DESCRIPTION' not found"exit 1firesult "OK"checking "\`DESCRIPTION' license entry"foo=`grep "^License" DESCRIPTION`foo=`set - ${foo}; echo ${2}`if test -z ${foo}; thenresult "ERROR: no license entry in \`DESCRIPTION'"exit 1firesult "OK"checking "\`DESCRIPTION' package entry"foo=`grep "^Package" DESCRIPTION`package=`set - ${foo}; echo ${2}`if test -z ${package}; thenresult "ERROR: no package entry in \`DESCRIPTION'"exit 1fiif test "${package}" != `basename ${dir}`; thenresult "ERROR: package field in \`DESCRIPTION' differs from dir name"exit 1firesult "OK"checking "\`DESCRIPTION' version entry"foo=`grep "^Version" DESCRIPTION`version=`set - ${foo}; echo ${2}`if test -z ${version}; thenresult "ERROR: no version entry in \`DESCRIPTION'"exit 1firesult "OK"## Check for `TITLE'checking "for \`TITLE'"if test -r TITLE; thenresult "OK"elseresult "ERROR: file \`TITLE' not found"exit 1fi## Check R documentation filesif test -d man; thenRdfiles=`find man -name "*.[Rr]d" -print | sort`checking "Rd files"any=for tag in name alias title description keyword; dobadfiles=`grep -L "^\\\\\\\\${tag}" ${Rdfiles} 2>/dev/null`if test -n "${badfiles}"; thenif test -z "${any}"; thenresult "WARNING:"fiany="${any} ${tag}"echo "Rd files without ${tag}:"echo "${badfiles}"fidoneif test -z "${any}"; thenresult "OK"fielseresult "WARNING: no Rd files found"fi## Check for `INDEX'checking "for \`INDEX'"if test -r INDEX; thenresult "OK"if test -n "${Rdfiles}"; thenchecking "whether \`INDEX' is up-to-date"updateIndex "INDEX"fielseresult "NO"if test -n "${Rdfiles}"; thenmessage "creating \`INDEX' from Rd files"R CMD Rdindex ${Rdfiles} > INDEXif test ${?} -ne 0; thenresult "ERROR"exit 1elseresult "OK"fielseresult "ERROR: no \`INDEX' and no Rd files found."exit 1fifi## Update `data/00Index'if test -d data; thenRdfiles=`grep -l "\\\\keyword{datasets}" ${Rdfiles}`checking "for \`data/00Index'"if test -r data/00Index; thenresult "OK"if test -n "${Rdfiles}"; thenchecking "whether \`data/00Index' is up-to-date"updateIndex "data/00Index"fielseresult "NO"if test -n "${Rdfiles}"; thenmessage "creating \`data/00Index' from Rd files"R CMD Rdindex ${Rdfiles} > data/00Indexif test ${?} -ne 0; thenresult "ERROR"exit 1elseresult "OK"fielseresult "ERROR: no \`data/00Index' and no Rd files found."exit 1fififi## Check for undocumented objectschecking "for undocumented objects"if test -n "${R_NSIZE}"; thenR_opts="${R_opts} --nsize ${R_NSIZE}"fiif test -n "${R_VSIZE}"; thenR_opts="${R_opts} --vsize ${R_VSIZE}"fiout=`echo "undoc(dir = \"${dir}\")" | R ${R_opts} | \grep "^Error\\|^ *\\["`err=`echo "${out}" | grep "^Error"`if test -z "${err}"; thenif test -n "${out}"; thenresult "WARNING:"echo "${out}"elseresult "OK"fielseerr=`echo "${err}" | sed -e 's/^Error *//'`result "ERROR:"echo "${err}"exit 1fi## Clean up `src'if test -d src; thenmessage "cleaning \`src'"if test -r src/Makefile; then(cd src && make clean)elserm -f *.o *.s[lo]fifi## Other cleanupsfor f in .Rdata .Rhistory; dojunk=`find . -name ${f}`if test -n "${junk}"; thenmessage "removing left-over \`${f}' files"rm -f ${junk}fidoneif test -x cleanup; thenmessage "running \`cleanup'"./cleanupfi## And finally build the packagecd ..message "building \`${START_DIR}/${package}_${version}.tar.gz'"tar zcf ${START_DIR}/${package}_${version}.tar.gz ${package}}## The main loopfor p in ${PKGS}; do buildpkg ${p}; echo; done### Local Variables: ***### mode: sh ***### sh-indentation: 2 ***### End: ***