The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2195 hornik 1
#! /bin/sh
7219 hornik 2
#
4580 hornik 3
# ${R_HOME}/bin/INSTALL for installing add-on packages
2195 hornik 4
 
5
# @configure_input@
6
 
27636 ripley 7
revision='$Revision: 1.145 $'
7356 hornik 8
version=`set - ${revision}; echo ${2}`
11515 hornik 9
version="R add-on package installer ${version}
2195 hornik 10
 
22638 hornik 11
Copyright (C) 2000-2003 The R Core Development Team.
11515 hornik 12
This is free software; see the GNU General Public Licence version 2
13
or later for copying conditions.  There is NO warranty."
2195 hornik 14
 
11515 hornik 15
usage="Usage: R CMD INSTALL [options] pkgs
16
 
13907 hornik 17
Install the add-on packages specified by pkgs.  The elements of pkgs can
18
be relative or absolute paths to directories with the package (bundle)
18521 hornik 19
sources, or to gzipped package 'tar' archives.  The library tree to
20
install to can be specified via '--library'.  By default, packages are
13907 hornik 21
installed in the library tree rooted at the first directory given in the
22
environment variable R_LIBS if this is set and non-null, and into the
23
default R library tree (${R_HOME}/library) otherwise.
4562 pd 24
 
7356 hornik 25
Options:
11515 hornik 26
  -h, --help		print short help message and exit
27
  -v, --version		print version info and exit
28
      --configure-args=ARGS
21741 hornik 29
                        set arguments for the package's configure script
30
			(if any)
14500 hornik 31
      --configure-vars=VARS
32
                        set variables for the configure script (if any)
7356 hornik 33
  -c, --clean		remove all files created during installation
17396 hornik 34
  -s, --save[=ARGS]     save the package source as an image file, and
13907 hornik 35
                        arrange for this file to be loaded when the
17396 hornik 36
                        package is attached; if given, ARGS are passed
37
                        to R when creating the save image
13907 hornik 38
      --no-save         do not save the package source as an image file
7356 hornik 39
  -d, --debug		turn on shell and build-help debugging
40
  -l, --library=LIB	install packages to library tree LIB
11515 hornik 41
      --no-configure    do not use the package's configure script
7356 hornik 42
      --no-docs		do not build and install documentation
23577 hornik 43
      --with-package-versions
44
                        allow for multiple versions of the same package
9263 bates 45
      --use-zip-data	collect data files in zip archive
9114 hornik 46
      --use-zip-help	collect help and examples into zip archives
18521 hornik 47
      --use-zip		combine '--use-zip-data' and '--use-zip-help'
25588 hornik 48
      --fake		do minimal install for testing purposes
7356 hornik 49
 
10633 hornik 50
Report bugs to <r-bugs@r-project.org>."
7356 hornik 51
 
18521 hornik 52
## <NOTE>
53
## This is a *shell* script.
54
## According to the R Coding Standards (see R-exts), Perl can be assumed
55
## for *source*, but not for *binary* installations.
56
## </NOTE>
57
 
25330 hornik 58
## <NOTE>
59
## We try to be defensive about possible white space in file names,
60
## hence all the strange quoting ...
61
## </NOTE>
62
 
18521 hornik 63
umask 022
64
 
7698 leisch 65
R_VERSION='@VERSION@'
17789 ripley 66
GETWD='@GETWD@'
26356 hornik 67
## <FIXME>
68
## Should already be set via Rcmd.
17371 hornik 69
MAKE=${MAKE-'@MAKE@'}
26356 hornik 70
TAR=${TAR='@TAR@'}
71
## </FIXME>
2195 hornik 72
NO_PERL5=@NO_PERL5@
73
NO_PERL5_MSG="\
74
*** Formatting and installing R help pages needs Perl version 5, which
75
*** does not seem to be installed on your system or is not in your path.
76
*** Please install either Perl 5 on your system and re-configure R or
7577 leisch 77
*** get the PDF reference manual from the nearest CRAN server.
2195 hornik 78
*** The CRAN master site can be found at
7356 hornik 79
***    http://cran.r-project.org/"
26331 hornik 80
 
81
if mkdir -p . 2>/dev/null; then
82
  MKDIR_P="mkdir -p"
83
else
84
  MKDIR_P="${R_HOME}/bin/mkinstalldirs"
85
fi
86
 
27371 hornik 87
warning () { echo "WARNING: $*" >&2 ; }
88
error ()   { echo "ERROR: $*" >&2 ; }
89
 
25234 hornik 90
startdir=`${GETWD}`
11550 hornik 91
tmpdir="${TMPDIR-/tmp}/R.INSTALL.$$"
25260 hornik 92
if (test -d "${tmpdir}" && test -w "${tmpdir}") || \
26331 hornik 93
    ${MKDIR_P} "${tmpdir}" 2> /dev/null; then
25260 hornik 94
  tmpdir=`cd "${tmpdir}" && ${GETWD}`
95
else
27371 hornik 96
  error "cannot write to or create temporary directory '${tmpdir}'"
25260 hornik 97
  exit 1
98
fi
2195 hornik 99
 
18521 hornik 100
: ${R_OSTYPE=unix}
19011 hornik 101
## <NOTE>
102
## Unix only ... but Windows has INSTALL as a Perl script.
18521 hornik 103
R_EXE="${R_HOME}/bin/R"
19011 hornik 104
## </NOTE>
2195 hornik 105
 
18521 hornik 106
## <NOTE>
107
## This could be made a bit more general: if R CMD INSTALL is run by
108
## another tool (e.g., when building or checking a package, its messages
109
## should be a section level deeper (at least).  So we could have an
110
## argument to set the initial secnumdepth (0 by default), and work
111
## against this ...
112
message () { echo "${stars} $*"; }
113
stars="*"
114
## </NOTE>
115
 
116
. "${R_HOME}/share/sh/dcf.sh"	# get_dcf_field()
117
 
6994 pd 118
get_packages () {
13963 hornik 119
  ## get the full path names to all packages contained in $1.
120
  ## NOTE: modifies pkgs!
22505 hornik 121
  if grep "^Contains:" "${1}/DESCRIPTION" >/dev/null; then
7698 leisch 122
    bundlepkg=`get_dcf_field Contains "${1}/DESCRIPTION"`
7356 hornik 123
    for p in ${bundlepkg}; do
18521 hornik 124
      pkgs="${pkgs} \"`cd "${1}/${p}" && ${GETWD}`\""
6994 pd 125
      if test -f "${1}/${p}/DESCRIPTION.in"; then
26321 hornik 126
        ## Try being defensive about missing final newlines, or extra
127
	## empty lines.
128
        (cat "${1}/${p}/DESCRIPTION.in"
129
	  echo
130
          grep -v "^Contains:" "${1}/DESCRIPTION"
131
	  echo) | sed '/^ *$/d' > "${1}/${p}/DESCRIPTION"
6994 pd 132
      fi
133
    done
134
  else 
18521 hornik 135
    pkgs="${pkgs} \"`cd "${1}" && ${GETWD}`\""
6994 pd 136
  fi
137
}
138
 
22638 hornik 139
### 
140
### Setup and command line processing.
141
 
21741 hornik 142
if test -n "${R_LIBS}"; then
143
  lib=`echo "${R_LIBS}" | cut -f1 -d:`
144
else
145
  lib="${R_HOME}/library"
146
fi
147
 
7356 hornik 148
pkgs=
149
clean=false
150
debug=false
151
error=false
152
build_text=true
153
build_html=true
154
build_latex=true
155
build_example=true
156
build_help=true
157
build_help_opts=
11515 hornik 158
use_configure=true
9114 hornik 159
use_zip_data=
160
use_zip_help=
14500 hornik 161
configure_args=
162
configure_vars=
23577 hornik 163
with_package_versions=false
13853 jmc 164
save="CHECK"
26216 hornik 165
save_args=
25560 hornik 166
fake=false
13853 jmc 167
 
2195 hornik 168
while test -n "${1}"; do
169
  case ${1} in
7356 hornik 170
    -h|--help)
171
      echo "${usage}"; exit 0 ;;
172
    -v|--version)
173
      echo "${version}"; exit 0 ;;
3279 pd 174
    -c|--clean)
7356 hornik 175
      clean=true ;;
13853 jmc 176
    -s|--save)
15355 jmc 177
      save=true;;
178
    --save=*)
179
      save_args=`echo "${1}" | sed -e 's/[^=]*=//'` ;;
13853 jmc 180
    --no-save)
181
      save=false ;;
7356 hornik 182
    -d|--debug)
183
      debug=true ;;
23520 rgentlem 184
    --with-package-versions)
23577 hornik 185
      with_package_versions=true ;;
11515 hornik 186
    --no-configure)
187
      use_configure=false ;;
2195 hornik 188
    --no-docs)
7356 hornik 189
      build_text=false
190
      build_html=false
191
      build_latex=false
192
      build_example=false ;;
2195 hornik 193
    --no-text)
7356 hornik 194
      build_text=false ;;
2195 hornik 195
    --no-html)
7356 hornik 196
      build_html=false ;;
2195 hornik 197
    --no-latex)
7356 hornik 198
      build_latex=false ;;
3076 pd 199
    --no-example)
7356 hornik 200
      build_example=false ;;
4562 pd 201
    --use-zip)
9114 hornik 202
      use_zip_data=true
203
      use_zip_help=true ;;
204
    --use-zip-data)
205
      use_zip_data=true ;;
206
    --use-zip-help)
207
      use_zip_help=true ;;
3279 pd 208
    -l|--library)
18521 hornik 209
      lib="${2}"; shift ;;
7356 hornik 210
    --library=*)
211
      lib=`echo "${1}" | sed -e 's/[^=]*=//'` ;;
7825 hornik 212
    --configure-args=*)
213
      configure_args=`echo "${1}" | sed -e 's/[^=]*=//'` ;;
14500 hornik 214
    --configure-vars=*)
215
      configure_vars=`echo "${1}" | sed -e 's/[^=]*=//'` ;;
25560 hornik 216
    --fake)
217
      fake=true ;;
2195 hornik 218
    *)
6098 pd 219
      if test -f "${1}"; then
7356 hornik 220
	pkgname=`basename "${1}"`
21459 pd 221
	## Also allow for 'package.tgz' ...
222
	pkgname=`basename "${pkgname}" .tgz`
7356 hornik 223
	pkgname=`echo "${pkgname}" | sed 's/_.*//'`
21459 pd 224
	## Note that we use '-m' so that modification dates are *not*
225
	## preserved when untarring the sources.  This is necessary to
226
	## ensure that the preformatted help pages are always rebuilt.
227
	## Otherwise, the build date for an older version may be newer
228
	## than the modification date for the new sources as recorded in
229
	## the tarball ...
26356 hornik 230
	gzip -dc "${1}" | (cd "${tmpdir}" && ${TAR} -mxf -)
25234 hornik 231
	if test -f "${tmpdir}/${pkgname}/DESCRIPTION"; then
7356 hornik 232
	  get_packages "${tmpdir}/${pkgname}"
6098 pd 233
	else
27371 hornik 234
	  error "cannot extract package from '${1}'"
6098 pd 235
	  exit 1
236
	fi    
25234 hornik 237
      elif test -f "${1}/DESCRIPTION"; then
6994 pd 238
        get_packages "${1}"
6143 pd 239
      else
27371 hornik 240
	warning "invalid package '${1}'"
6143 pd 241
      fi
242
      ;;
243
  esac
244
  shift
245
done
246
 
7356 hornik 247
if test -z "${pkgs}"; then
27371 hornik 248
  error "no packages specified"
6143 pd 249
  exit 1
250
fi
251
 
25250 hornik 252
if (test -d "${lib}" && test -w "${lib}") || \
26331 hornik 253
    ${MKDIR_P} "${lib}" 2> /dev/null; then
19011 hornik 254
  lib=`cd "${lib}" && ${GETWD}`
6143 pd 255
else
27371 hornik 256
  error "cannot write to or create directory '${lib}'"
6143 pd 257
  exit 2
258
fi
25234 hornik 259
lockdir="${lib}/00LOCK"
25310 hornik 260
if test -d "${lockdir}" || test -f "${lockdir}"; then
27371 hornik 261
  error "failed to lock directory '${lib}' for modifying"
262
  echo "Try removing '${lockdir}'" >&2
25234 hornik 263
  exit 3
264
else
26331 hornik 265
  ${MKDIR_P} "${lockdir}"
25234 hornik 266
  if test ${?} -ne 0; then
267
    ## This should not really happen ...
27371 hornik 268
    error "failed to lock directory '${lib}' for modifying"
25234 hornik 269
    exit 3
270
  fi
271
fi
6143 pd 272
 
25588 hornik 273
if ${fake}; then
274
  use_configure=false
275
  build_text=true
276
  build_html=false
277
  build_latex=true
278
  build_example=false
279
fi
280
 
7356 hornik 281
if ${build_text}; then
8252 ripley 282
  build_help_opts="${build_help_opts} --txt"
6143 pd 283
fi
7356 hornik 284
if ${build_html}; then
285
  build_help_opts="${build_help_opts} --html"
6143 pd 286
fi
7356 hornik 287
if ${build_latex}; then
288
  build_help_opts="${build_help_opts} --latex"
6143 pd 289
fi
7356 hornik 290
if ${build_example}; then
291
  build_help_opts="${build_help_opts} --example"
6143 pd 292
fi
7356 hornik 293
if test -z "${build_help_opts}"; then
294
  build_help=false
295
elif ${debug}; then
296
  build_help_opts="--debug ${build_help_opts}"
6143 pd 297
fi
298
 
25260 hornik 299
is_first_package=yes
300
 
22638 hornik 301
### 
302
### Install a *binary* package from the current directory. 
303
 
22423 hornik 304
do_install_binary () {
305
  pkg="${1}"
23520 rgentlem 306
  R_PACKAGE_DIR="${2}"
23577 hornik 307
  R_PACKAGE_NAME="${3}"
23520 rgentlem 308
 
23577 hornik 309
  if test "${pkg}" = "${R_PACKAGE_NAME}"; then
310
    message "Installing *binary* package '${pkg}' ..."
311
  else
312
    message "Installing *binary* package '${pkg}' as '${R_PACKAGE_NAME}' ..."
25250 hornik 313
  fi
314
 
315
  if test -f "${R_PACKAGE_DIR}/DESCRIPTION"; then
316
    ## Back up previous version.
317
    mv "${R_PACKAGE_DIR}" "${lockdir}/${R_PACKAGE_NAME}"
26331 hornik 318
    ${MKDIR_P} "${R_PACKAGE_DIR}"
25250 hornik 319
  fi
320
 
26356 hornik 321
  cp -r . "${R_PACKAGE_DIR}" || \
322
    (${TAR} cf - . | (cd "${R_PACKAGE_DIR}" && ${TAR} xf -))
25250 hornik 323
 
25260 hornik 324
  if test ${?} -ne 0; then
27371 hornik 325
    error "installing binary package failed"
25250 hornik 326
    do_exit_on_error
327
  fi
22423 hornik 328
}
329
 
22638 hornik 330
### 
331
### Install a *source* package from the current directory.
332
 
22423 hornik 333
do_install_source () {
25808 hornik 334
  pkg_name="${1}"
335
  pkg_dir="${4}"
336
  ## (The basename of ${pkg_dir} might be different from ${pkg_name},
337
  ## e.g., when building Debian packages from R packages.)
22423 hornik 338
 
339
  ## Make the destination directories available to the developer's
340
  ## installation scripts (e.g. configure, etc.)
23520 rgentlem 341
  R_PACKAGE_DIR="${2}"
23577 hornik 342
  R_PACKAGE_NAME="${3}"
22423 hornik 343
  R_LIBRARY_DIR="${lib}"
344
  export R_LIBRARY_DIR
345
  export R_PACKAGE_DIR
346
  export R_PACKAGE_NAME
347
 
25808 hornik 348
  if test "${pkg_name}" = "${R_PACKAGE_NAME}"; then
349
    message "Installing *source* package '${pkg_name}' ..."
23577 hornik 350
  else
25808 hornik 351
    message "Installing *source* package '${pkg_name}' as '${R_PACKAGE_NAME}' ..."
25234 hornik 352
  fi
353
 
23553 hornik 354
  stars="**"
23520 rgentlem 355
 
25250 hornik 356
  if test -f "${R_PACKAGE_DIR}/DESCRIPTION"; then
357
    ## Back up previous version.
358
    mv "${R_PACKAGE_DIR}" "${lockdir}/${R_PACKAGE_NAME}"
26331 hornik 359
    ${MKDIR_P} "${R_PACKAGE_DIR}"
25250 hornik 360
    ## Preserve man pages to speed up installation?  Only makes sense
361
    ## if we install from a non-temporary directory.
25260 hornik 362
    if test "`cd .. && ${GETWD}`" != \
363
            "`cd \"${tmpdir}\" && ${GETWD}`"; then
25250 hornik 364
      (cd "${lockdir}/${R_PACKAGE_NAME}" \
26356 hornik 365
          && ${TAR} cf - R-ex help html latex) | \
366
	(cd "${R_PACKAGE_DIR}" && ${TAR} xf -)
25234 hornik 367
    fi
368
  fi
24205 ripley 369
 
22423 hornik 370
  if ${use_configure} && test -x ./configure ; then
371
    eval ${configure_vars} ./configure ${configure_args}
372
    if test ${?} -ne 0; then
27371 hornik 373
      error "configuration failed for package '${pkg_name}'"
25234 hornik 374
      do_exit_on_error
22423 hornik 375
    fi
376
  fi
377
 
23553 hornik 378
  for f in COPYING NAMESPACE; do
26356 hornik 379
    if test -f "${f}"; then
380
      cp "${f}" "${R_PACKAGE_DIR}"
381
      chmod 644 "${R_PACKAGE_DIR}/${f}"
382
    fi
23553 hornik 383
  done
384
 
25954 hornik 385
  ## Copy DESCRIPTION file, stamp with build information, and remove
386
  ## blank lines.  (Need to add an empty line to deal with missing
387
  ## trailing newlines at EOF.)
388
  ## As from 1.7.0, packages without compiled code are not marked
389
  ## as being from any platform.
390
  echo ".installPackageDescription(\".\", \"${R_PACKAGE_DIR}\")" | \
391
    R_DEFAULT_PACKAGES=tools ${R_EXE} --vanilla >/dev/null
392
  if test ${?} -ne 0; then
27371 hornik 393
    error "installing package DESCRIPTION failed"
25954 hornik 394
    do_exit_on_error
395
  fi
396
 
25588 hornik 397
  if test -d src && test "${fake}" != "true"; then
22423 hornik 398
    message "libs"
399
    if ${debug}; then set -x; fi
26331 hornik 400
    ${MKDIR_P} "${R_PACKAGE_DIR}/libs"
22423 hornik 401
    if test -f src/Makefile; then
402
      cd src;
403
      makefiles="-f \"${R_HOME}\"/share/make/shlib.mk -f Makefile"
404
      if test -r Makevars; then
405
	makefiles="-f Makevars ${makefiles}"
406
      fi
407
      eval ${MAKE} ${makefiles} \
23520 rgentlem 408
	&& cp *@SHLIB_EXT@ "${R_PACKAGE_DIR}/libs" \
22423 hornik 409
        || error=true; \
410
      if ${clean}; then
411
	${MAKE} clean
412
      fi
413
      cd ..
414
    else
415
      cd src;
416
      srcs=`ls *.[cfC] *.cc *.cpp 2>/dev/null`
417
      if test -n "${srcs}"; then
25808 hornik 418
	sh "${R_HOME}/bin/SHLIB" -o "${pkg_name}@SHLIB_EXT@" ${srcs} \
23520 rgentlem 419
          && cp *@SHLIB_EXT@ "${R_PACKAGE_DIR}/libs" \
22423 hornik 420
	  || error=true; \
421
	if ${clean}; then
422
	  rm -rf .libs _libs
423
	  rm -f *.o *@SHLIB_EXT@
424
	fi
425
      else
27371 hornik 426
	warning "no source files found"
22423 hornik 427
      fi
428
      cd ..
429
    fi
430
    if ${error}; then
27371 hornik 431
      error "compilation failed for package '${pkg_name}'"
25234 hornik 432
      do_exit_on_error
22423 hornik 433
    fi
26356 hornik 434
    chmod 755 "${R_PACKAGE_DIR}/libs/"*
22423 hornik 435
    if ${debug}; then set +x; fi
436
  fi
437
 
438
  if test -d R; then
439
    message "R"
26331 hornik 440
      ${MKDIR_P} "${R_PACKAGE_DIR}/R"
25954 hornik 441
      rm -f "${R_PACKAGE_DIR}/R/"*
442
      echo ".installPackageCodeFiles(\".\", \"${R_PACKAGE_DIR}\")" | \
443
        R_DEFAULT_PACKAGES=tools ${R_EXE} --vanilla >/dev/null
444
      if test ${?} -ne 0; then
27371 hornik 445
        error "unable to collate files for package '${pkg_name}'"
25954 hornik 446
        do_exit_on_error
447
      fi
25560 hornik 448
    if ${fake}; then
449
      if test -f NAMESPACE; then
450
        echo ".onLoad <- function(list, pkg) NULL" >> \
451
	  "${R_PACKAGE_DIR}/R/${R_PACKAGE_NAME}"
25588 hornik 452
	sed -e '/useDynLib/d' NAMESPACE > "${R_PACKAGE_DIR}/NAMESPACE"
25560 hornik 453
      else
454
        echo ".First.lib <- function(lib, pkg) NULL" >> \
455
          "${R_PACKAGE_DIR}/R/${R_PACKAGE_NAME}"
456
      fi
457
    fi
22423 hornik 458
  fi
459
 
460
  if test -d data; then
461
    message "data"
26331 hornik 462
    ${MKDIR_P} "${R_PACKAGE_DIR}/data"
23520 rgentlem 463
    rm -f "${R_PACKAGE_DIR}/data/"*
464
    cp data/* "${R_PACKAGE_DIR}/data" 2>/dev/null
465
    chmod 644 "${R_PACKAGE_DIR}/data/"*
22423 hornik 466
    if test -n "${use_zip_data}" \
25250 hornik 467
        && test -n "${R_UNZIPCMD}" \
468
        && test -n "${R_ZIPCMD}"; then
23520 rgentlem 469
      (cd "${R_PACKAGE_DIR}/data";
22423 hornik 470
        find . -type f -print > filelist
471
        ${R_ZIPCMD} -m Rdata * -x filelist 00Index)
472
    fi
473
  fi
474
 
25588 hornik 475
  if test -d demo && test "${fake}" != "true"; then
22423 hornik 476
    message "demo"
26331 hornik 477
    ${MKDIR_P} "${R_PACKAGE_DIR}/demo"
23520 rgentlem 478
    rm -f "${R_PACKAGE_DIR}/demo/"*
479
    cp demo/* "${R_PACKAGE_DIR}/demo" 2>/dev/null
480
    chmod 644 "${R_PACKAGE_DIR}/demo/"*
22423 hornik 481
  fi
482
 
25588 hornik 483
  if test -d exec && test "${fake}" != "true"; then
22423 hornik 484
    message "exec"
26331 hornik 485
    ${MKDIR_P} "${R_PACKAGE_DIR}/exec"
23520 rgentlem 486
    rm -f "${R_PACKAGE_DIR}/exec/"*
487
    cp exec/* "${R_PACKAGE_DIR}/exec" 2>/dev/null
488
    chmod 755 "${R_PACKAGE_DIR}/exec/"*
22423 hornik 489
  fi
490
 
25588 hornik 491
  if test -d inst && test "${fake}" != "true"; then
22423 hornik 492
    message "inst"
26356 hornik 493
    cp -r inst/* "${R_PACKAGE_DIR}" || \
494
      (cd inst && ${TAR} cf - . | \
495
        (cd "${R_PACKAGE_DIR}" && ${TAR} xf -))
22423 hornik 496
  fi
497
 
498
  case ${save} in
499
    CHECK)
500
      if test -r install.R; then
501
	R_SAVE_IMAGE=true;
502
      else
503
	R_SAVE_IMAGE=false;
504
      fi
505
      ;;
506
    *)
507
      R_SAVE_IMAGE=${save} ;;
508
  esac
509
  export R_SAVE_IMAGE
510
 
511
  if ${R_SAVE_IMAGE}; then
512
    message "save image"
513
    ## <NOTE>
514
    ## We want R to run as quietly as possible when creating the save
515
    ## image.  But this is tricky: sending options(echo=FALSE) to R via
516
    ## stdin (as opposed to writing to a file and reading from it)
517
    ## echoes what we sent before shutting up R, which is not what we
518
    ## want.  Option '--slave' gets around this but also turns off
26216 hornik 519
    ## saving ... hence we call R with '--slave --save' (in case there
520
    ## is no namespace).  Argh.
24948 luke 521
    ## </NOTE>
22423 hornik 522
    save_image_defaults="list(compress=TRUE, safe=FALSE)"
24948 luke 523
    code_file="${R_PACKAGE_DIR}/R/${R_PACKAGE_NAME}"
524
    rda_file="${R_PACKAGE_DIR}/R/all.rda"
525
    if test -f NAMESPACE; then
25808 hornik 526
      code_cmd="echo saveNamespaceImage(\"${pkg_name}\", \"${rda_file}\", \"${lib}\")"
25330 hornik 527
      loader_file=nsrdaload.R
26216 hornik 528
      R_SAVE_EXE="${R_EXE} --vanilla --slave"
24948 luke 529
    else
25330 hornik 530
      code_cmd="eval cat \"${code_file}\""
531
      loader_file=firstlib.R
26216 hornik 532
      R_SAVE_EXE="${R_EXE} --vanilla --slave --save"
24948 luke 533
    fi
22423 hornik 534
    (echo "options(save.image.defaults=${save_image_defaults})"; \
535
      if test -s R_PROFILE.R; then cat R_PROFILE.R; fi; \
536
      echo "invisible(.libPaths(c(\"${lib}\", .libPaths())))"; \
26286 hornik 537
      ${code_cmd}) | R_DEFAULT_PACKAGES= ${R_SAVE_EXE} ${save_args}
22423 hornik 538
    if test ${?} -ne 0; then
27371 hornik 539
      error "execution of package source for '${pkg_name}' failed"
25234 hornik 540
      do_exit_on_error
22423 hornik 541
    fi
25250 hornik 542
    test -f NAMESPACE || mv .RData "${rda_file}"
27636 ripley 543
    ## we used to install the dumped code but this seems a waste of space
544
    rm "${code_file}"
545
    # mv "${code_file}" "${R_PACKAGE_DIR}/R/${pkg_name}.R"
24948 luke 546
    cat "${R_HOME}/share/R/${loader_file}" > "${code_file}"
22423 hornik 547
    ## If install.R is non-empty, arrange to evaluate the R code it
548
    ## contains after the package source (maybe for some kind of
549
    ## cleanup).
550
    if test -s install.R; then
24123 rgentlem 551
      cat install.R >> "${R_PACKAGE_DIR}/R/${R_PACKAGE_NAME}"
22423 hornik 552
    fi
553
  fi
554
 
555
  if test -d man; then
556
    message "help"
557
    ## Install man sources ...
558
    Rdfiles=`ls man/*.[Rr]d man/${R_OSTYPE}/*.[Rr]d 2>/dev/null`
559
    if test -n "${Rdfiles}"; then
26331 hornik 560
      ${MKDIR_P} "${R_PACKAGE_DIR}/man"
23520 rgentlem 561
      rm -f "${R_PACKAGE_DIR}/man/"*
25557 hornik 562
      for f in ${Rdfiles}; do cat "${f}"; echo; echo '\eof'; done \
25808 hornik 563
        > "${R_PACKAGE_DIR}/man/${pkg_name}.Rd"
564
      chmod 644 "${R_PACKAGE_DIR}/man/${pkg_name}.Rd"
22423 hornik 565
    fi
566
    ## Maybe build preformatted help pages ...
567
    if ${build_help}; then
568
      if ${NO_PERL5}; then
569
	echo "${NO_PERL5_MSG}"
570
      else
571
	if ${debug}; then
25808 hornik 572
	  echo "DEBUG: build-help ${BUILD_HELP_OPTS} ${pkg_dir} ${lib} ${R_PACKAGE_DIR} ${pkg_name}"
22423 hornik 573
	fi
574
	${R_CMD} perl "${R_HOME}/share/perl/build-help.pl" \
25808 hornik 575
	  ${build_help_opts} \
576
	  "${pkg_dir}" "${lib}" "${R_PACKAGE_DIR}" "${pkg_name}"
22423 hornik 577
	if test ${?} -ne 0; then
27371 hornik 578
	  error "building help failed for package '${pkg_name}'"
25234 hornik 579
	  do_exit_on_error
22423 hornik 580
        fi
581
      fi
582
      if test -n "${use_zip_help}" \
25250 hornik 583
	  && test -n "${R_UNZIPCMD}" \
584
	  && test -n "${R_ZIPCMD}"; then
23520 rgentlem 585
	(cd "${R_PACKAGE_DIR}"
22423 hornik 586
	  if test -d R-ex; then
587
	    (cd R-ex; ${R_ZIPCMD} -m Rex *.R)
588
	  fi
589
          ## NOT YET:
590
          ## if test -d latex; then
591
          ##   (cd latex; ${R_ZIPCMD} -m Rhelp *.tex)
592
          ## fi
593
	  if test -d help; then
594
	    (cd help; ${R_ZIPCMD} -m Rhelp * -x AnIndex);
595
	  fi)
596
      fi
597
    fi
598
  else
25808 hornik 599
    echo "No man pages found in package '${pkg_name}'"
22423 hornik 600
  fi
601
 
23520 rgentlem 602
  echo ".installPackageIndices(\".\", \"${R_PACKAGE_DIR}\")" | \
24579 hornik 603
    R_DEFAULT_PACKAGES=tools ${R_EXE} --vanilla >/dev/null
24205 ripley 604
  if test ${?} -ne 0; then
27371 hornik 605
    error "installing package indices failed"
25234 hornik 606
    do_exit_on_error
24205 ripley 607
  fi
22423 hornik 608
 
27595 ripley 609
  ## Install a dump of the parsed NAMESPACE file
610
  if test -f NAMESPACE; then
611
      echo ".installPackageNamespaceInfo(\".\", \"${R_PACKAGE_DIR}\")" | \
612
        R_DEFAULT_PACKAGES=tools ${R_EXE} --vanilla >/dev/null
613
    if test ${?} -ne 0; then
614
      error "installing namespace metadata failed"
615
      do_exit_on_error
616
    fi
617
  fi
618
 
24221 hornik 619
  ## <FIXME>
620
  ## Remove stuff we should not have installed in the first place.
621
  ## When installing from a source directory under CVS control, we
622
  ## should really exclude the CVS subdirs.  (In fact, we should also
623
  ## exclude everything in @file{.Rbuildignore}, but that's another
624
  ## story ...)
24641 hornik 625
  find "${R_PACKAGE_DIR}" -name CVS -exec rm -rf \{\} \; 2>/dev/null
24221 hornik 626
  ## </FIXME>
627
 
22423 hornik 628
  if ${clean}; then
629
    if test -x ./cleanup ; then
630
      ./cleanup
631
    fi
632
  fi
633
 
634
  stars="*"
635
}
636
 
22638 hornik 637
### 
638
### Install a package.
639
 
6143 pd 640
do_install () {
641
  cd "${1}"
25808 hornik 642
  pkg_dir="${1}"
643
  pkg_name=`get_dcf_field Package DESCRIPTION`
644
  ## (The basename of ${pkg_dir} might be different from ${pkg_name},
645
  ## e.g., when building Debian packages from R packages.)
26535 hornik 646
  if test -z "${pkg_name}"; then
27371 hornik 647
    error "no 'Package' field in 'DESCRIPTION'"
26535 hornik 648
    do_exit_on_error no
649
  fi
6143 pd 650
 
23577 hornik 651
  ## Set R_PACKAGE_DIR here at the top level.  If a version is being
652
  ## specified, tack that on.
653
  if ${with_package_versions}; then
23520 rgentlem 654
    version=`get_dcf_field Version DESCRIPTION`
26535 hornik 655
    if test -z "${version}"; then
27371 hornik 656
      error "no 'Version' field in 'DESCRIPTION'"
26535 hornik 657
      do_exit_on_error no
658
    fi
25808 hornik 659
    R_PACKAGE_NAME="${pkg_name}_${version}"
660
    R_PACKAGE_DIR="${lib}/${pkg_name}_${version}"
23520 rgentlem 661
  else
25808 hornik 662
    R_PACKAGE_NAME="${pkg_name}"
663
    R_PACKAGE_DIR="${lib}/${pkg_name}"
23520 rgentlem 664
  fi
665
  export R_PACKAGE_DIR
23577 hornik 666
  export R_PACKAGE_NAME
23520 rgentlem 667
 
23577 hornik 668
  depends=`get_dcf_field Depends DESCRIPTION`
669
  depends=`echo "${depends}" | grep 'R *('`
670
  if test "${depends}"; then
671
    depends=`echo "${depends}" | sed 's/.*R *(\([^)]*\)).*/\1/;s/=/= /'`
672
    dep_operator=`set - ${depends}; echo ${1}`
673
    dep_version=`set - ${depends}; echo ${2}`
674
    ## Currently, only operators '<=' and '>=' are supported.  Hence we
675
    ## check this, and also whether we found a version string.
676
    if (test "${dep_operator}" = "<=" \
25260 hornik 677
           || test "${dep_operator}" = ">=") \
23577 hornik 678
         && test -n "${dep_version}"; then
679
      dep_ok=`expr ${R_VERSION} ${dep_operator} ${dep_version} `
680
      if test ${dep_ok} -eq 0; then
27371 hornik 681
        error "This R is version ${R_VERSION}"
682
        echo "       package '${pkg_name}' depends on R ${dep_version}" >&2
26535 hornik 683
        do_exit_on_error
14053 hornik 684
      fi
23577 hornik 685
    else
27371 hornik 686
      warning "malformed 'Depends' field in 'DESCRIPTION'"
7698 leisch 687
    fi
688
  fi
689
 
26331 hornik 690
  ${MKDIR_P} "${R_PACKAGE_DIR}" || do_exit_on_error no
6143 pd 691
 
17789 ripley 692
  ## Make sure we do not attempt installing to srcdir.
23520 rgentlem 693
  if test "`cd \"${R_PACKAGE_DIR}\" && ${GETWD}`" = "`${GETWD}`"; then
27371 hornik 694
    error "cannot install to srcdir"
25234 hornik 695
    do_exit_on_error no
17789 ripley 696
  fi  
697
 
17282 hornik 698
  ## Figure out whether this is a source or binary package.
20300 hornik 699
  ## <NOTE>
700
  ## If DESCRIPTION has a @samp{Built:} entry, this is a binary package.
701
  ## This is the right test, but not available for packages installed
702
  ## prior to R 1.4.  For some time, we thus checked for the existence
703
  ## of a 'man' subdir if no build information was found in DESCRIPTION,
704
  ## using the fact that versions of R prior to 1.4 also did not install
705
  ## documentation sources, and assuming that all source packages would
706
  ## have some documentation, which caused problems for people who had
707
  ## not yet written any docs ... hence, from R 1.6 on only DESCRIPTION
708
  ## is looked at.
709
  ## </NOTE>
17282 hornik 710
  if grep "^Built:" DESCRIPTION >/dev/null ; then
18521 hornik 711
    ## If DESCRIPTION has a @samp{Built:} entry this is a binary
20300 hornik 712
    ## package.  This is the right test, but not available for packages
713
    ## installed prior to 1.4.0.
17282 hornik 714
    is_source_package=false
20300 hornik 715
  else
17282 hornik 716
    is_source_package=true
717
  fi
9909 duncan 718
 
25260 hornik 719
  test "${is_first_package}" = no && echo
720
 
17282 hornik 721
  if ${is_source_package}; then
722
    ## This is a source package ... hopefully.
25808 hornik 723
    do_install_source \
724
      "${pkg_name}" "${R_PACKAGE_DIR}" "${R_PACKAGE_NAME}" "${pkg_dir}"
9997 hornik 725
  else  
17282 hornik 726
    ## This is a binary package ... hopefully.
25808 hornik 727
    do_install_binary \
728
      "${pkg_name}" "${R_PACKAGE_DIR}" "${R_PACKAGE_NAME}"
6143 pd 729
  fi
730
 
26356 hornik 731
  find "${R_PACKAGE_DIR}" -exec chmod a+r \{\} \;
22638 hornik 732
 
25808 hornik 733
  message "DONE (${pkg_name})"
25260 hornik 734
  is_first_package=no
25234 hornik 735
}
736
 
737
### 
738
### Exit and cleanup.
739
 
740
do_exit_on_error () {
741
  remove_R_package_dir=${1-yes}
26535 hornik 742
  if test "${remove_R_package_dir}" = yes \
743
      && test -n "${R_PACKAGE_DIR}"; then
25234 hornik 744
    message "Removing '${R_PACKAGE_DIR}'"
745
    rm -rf "${R_PACKAGE_DIR}"
746
  fi
26535 hornik 747
  if test -n "${R_PACKAGE_NAME}" \
748
      && test -d "${lockdir}/${R_PACKAGE_NAME}"; then
25250 hornik 749
    message "Restoring previous '${R_PACKAGE_DIR}'"
750
    mv "${lockdir}/${R_PACKAGE_NAME}" "${R_PACKAGE_DIR}"
25234 hornik 751
  fi
752
  do_cleanup
753
  exit 1
754
}
755
 
756
do_cleanup () {
757
  ## Solaris will not remove any directory in the current path
758
  cd "${startdir}"
759
  if test -d "${tmpdir}"; then
760
    rm -rf "${tmpdir}"
761
  fi
762
 
25260 hornik 763
  if test "${is_first_package}" = no; then
764
    ## Only need to do this in case we successfully installed  at least
765
    ## *one* package ... 
766
    cp "${R_HOME}/doc/html/R.css" "${lib}"
26356 hornik 767
    chmod 644 "${lib}/R.css"
25260 hornik 768
    if test "${lib}" = `cd "${R_HOME}/library" && ${GETWD}`; then
769
      cat "${R_HOME}"/library/*/CONTENTS \
770
        > "${R_HOME}"/doc/html/search/index.txt
771
      if ${build_help} && test "${NO_PERL5}" = "false"; then
772
        ${R_CMD} perl "${R_HOME}/share/perl/build-help.pl" --htmllists
773
      fi
25234 hornik 774
    fi
22423 hornik 775
  fi
6143 pd 776
 
25234 hornik 777
  rm -rf "${lockdir}"
6098 pd 778
}
2195 hornik 779
 
22638 hornik 780
### 
25234 hornik 781
### Main loop.
22638 hornik 782
 
7356 hornik 783
eval "for pkg in ${pkgs}; do do_install \"\${pkg}\"; done"
25234 hornik 784
do_cleanup
2195 hornik 785
 
786
### Local Variables: ***
787
### mode: sh ***
7218 hornik 788
### sh-indentation: 2 ***
2195 hornik 789
### End: ***