The R Project SVN R

Rev

Rev 27595 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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