| 25573 |
ripley |
1 |
#-*- perl -*-
|
| 27901 |
ripley |
2 |
# Copyright (C) 2000-4 R Development Core Team
|
| 25573 |
ripley |
3 |
#
|
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
|
6 |
# the Free Software Foundation; either version 2, or (at your option)
|
|
|
7 |
# any later version.
|
|
|
8 |
#
|
|
|
9 |
# This program is distributed in the hope that it will be useful, but
|
|
|
10 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
12 |
# General Public License for more details.
|
|
|
13 |
#
|
|
|
14 |
# A copy of the GNU General Public License is available via WWW at
|
|
|
15 |
# http://www.gnu.org/copyleft/gpl.html. You can also obtain it by
|
|
|
16 |
# writing to the Free Software Foundation, Inc., 59 Temple Place,
|
|
|
17 |
# Suite 330, Boston, MA 02111-1307 USA.
|
|
|
18 |
|
|
|
19 |
# Send any bug reports to r-bugs@r-project.org
|
|
|
20 |
|
|
|
21 |
use Cwd;
|
|
|
22 |
use File::Basename;
|
|
|
23 |
use File::Path;
|
|
|
24 |
use Getopt::Long;
|
|
|
25 |
use R::Dcf;
|
|
|
26 |
use R::Utils;
|
|
|
27 |
|
|
|
28 |
|
| 28277 |
murdoch |
29 |
my $revision = ' $Revision: 1.40 $ ';
|
| 25573 |
ripley |
30 |
my $version;
|
|
|
31 |
my $name;
|
|
|
32 |
$revision =~ / ([\d\.]*) /;
|
|
|
33 |
$version = $1;
|
|
|
34 |
($name = $0) =~ s|.*/||;
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
my @knownoptions = ("help|h", "version|v", "debug|d", "library|l:s",
|
|
|
38 |
"clean|c", "docs:s", "save|s", "no-save",
|
| 27784 |
ripley |
39 |
"with-package-versions",
|
| 25573 |
ripley |
40 |
"use-zip", "use-zip-data", "use-zip-help",
|
|
|
41 |
"auto-zip", "build", "fake");
|
|
|
42 |
|
|
|
43 |
## topLevelFiles will be files that sit in the top level of a
|
|
|
44 |
## zip/tarball along with any included directories.
|
|
|
45 |
## This needs to be fixed: this file shouldn't do binary builds,
|
|
|
46 |
## that's what build.in is for - DJM
|
| 27901 |
ripley |
47 |
## No, that is what INSTALL --build is for, pace DJM
|
| 25573 |
ripley |
48 |
|
|
|
49 |
my $topLevelFiles = "DESCRIPTION";
|
|
|
50 |
|
|
|
51 |
GetOptions (@knownoptions) || usage();
|
|
|
52 |
R_version($name, $version) if $opt_version;
|
|
|
53 |
|
|
|
54 |
my $R_HOME = $ENV{'R_HOME'} ||
|
|
|
55 |
die "Error: Environment variable R_HOME not found\n";
|
|
|
56 |
usage() if $opt_help;
|
|
|
57 |
|
|
|
58 |
my $startdir = cwd();
|
| 27903 |
ripley |
59 |
my $library;
|
| 25573 |
ripley |
60 |
if($opt_library){
|
| 28078 |
ripley |
61 |
# remove quotes around the library path
|
|
|
62 |
$opt_library =~ s/^['"]//; $opt_library =~ s/['"]$//; #'"
|
| 25573 |
ripley |
63 |
chdir($opt_library) ||
|
|
|
64 |
die "Error: cannot change to directory \`$opt_library'\n";
|
| 27903 |
ripley |
65 |
$library = cwd();
|
|
|
66 |
$library = Win32::GetShortPathName($library) if $library =~ / /;
|
| 25573 |
ripley |
67 |
chdir($startdir);
|
|
|
68 |
} else {
|
|
|
69 |
$library = $R_HOME . "/library";
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
my $helpflags = "HELP=YES WINHELP=CHM";
|
|
|
73 |
if($opt_docs) {
|
|
|
74 |
if ($opt_docs eq "none") {
|
|
|
75 |
$helpflags = "HELP=NO";
|
|
|
76 |
} elsif ($opt_docs eq "normal") {
|
|
|
77 |
$helpflags = "HELP=YES WINHELP=NO";
|
| 27901 |
ripley |
78 |
} elsif ($opt_docs eq "chm"|| ($opt_docs eq "all")) {
|
| 25573 |
ripley |
79 |
$helpflags = "HELP=YES WINHELP=CHM";
|
|
|
80 |
} else {
|
|
|
81 |
die "ERROR: invalid --docs value `$opt_docs'\n";
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
|
| 28277 |
murdoch |
85 |
if((-e "$R_HOME/doc/html/R.css") && !(-e "$library/R.css")) {
|
|
|
86 |
printf "installing R.css in $library\n";
|
|
|
87 |
system("cp $R_HOME/doc/html/R.css $library/R.css");
|
|
|
88 |
}
|
|
|
89 |
|
| 25573 |
ripley |
90 |
## this is the main loop over all packages to be installed
|
|
|
91 |
my $pkg;
|
|
|
92 |
foreach $pkg (@ARGV){
|
|
|
93 |
# remove misguided trailing separator (/ or \)
|
|
|
94 |
$pkg =~ s/\/$//; $pkg =~ s/\\$//;
|
|
|
95 |
my $pkgname = basename($pkg);
|
|
|
96 |
my $is_bundle = 0;
|
|
|
97 |
my $istar = 0;
|
|
|
98 |
|
|
|
99 |
if (!(-e $pkg)) {
|
|
|
100 |
warn "`$pkg' does not exist: skipping\n";
|
|
|
101 |
next;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
## is this a tar archive?
|
|
|
105 |
if($pkgname =~ /\.tar\.gz$/) {
|
|
|
106 |
$pkgname =~ s/\.tar\.gz$//;
|
|
|
107 |
$pkgname =~ s/_[0-9\.-]*$//;
|
|
|
108 |
my $dir = "R.INSTALL";
|
|
|
109 |
mkdir($dir, 755);
|
| 27901 |
ripley |
110 |
## workaround for paths in Cygwin tar
|
|
|
111 |
$pkg =~ s+^([A-Za-x]):+/cygdrive/\1+;
|
|
|
112 |
if(system("tar -zxf '$pkg' -C $dir")) {
|
| 25573 |
ripley |
113 |
die "Error: cannot untar the package\n";}
|
|
|
114 |
$pkg = $dir."/".$pkgname;
|
|
|
115 |
$istar = 1;
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
chdir($pkg) || die "Error: cannot change to directory \`$pkg'\n";;
|
|
|
119 |
my $canonpkg = cwd();
|
|
|
120 |
chdir("..");
|
|
|
121 |
my $pkgdir = cwd();
|
|
|
122 |
chdir($startdir);
|
|
|
123 |
|
|
|
124 |
die "no valid package name found\n" unless length($pkgname) > 0;
|
|
|
125 |
my $pkgoutdir = "$library/$pkgname";
|
|
|
126 |
die " *** can't install into source directory ***\n"
|
|
|
127 |
if $canonpkg eq $pkgoutdir;
|
|
|
128 |
rmtree($pkgoutdir) if (-d $pkgoutdir);
|
| 27903 |
ripley |
129 |
$pkgdir = Win32::GetShortPathName($pkgdir) if $pkgdir =~ / /;
|
| 25573 |
ripley |
130 |
|
|
|
131 |
my $makecmd = "pkg";
|
|
|
132 |
$makecmd = "pkgfake" if $opt_fake;
|
|
|
133 |
if(-r "$pkg/DESCRIPTION"){
|
|
|
134 |
$description = new R::Dcf("$pkg/DESCRIPTION");
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
my $zippkgs = $pkgname;
|
|
|
138 |
if($description->{"Contains"}) {
|
|
|
139 |
print "\nLooks like \`${pkg}' is a package bundle\n";
|
|
|
140 |
$makecmd = "bundle";
|
|
|
141 |
$is_bundle = 1;
|
|
|
142 |
@bundlepkgs = split(/\s+/, $description->{"Contains"});
|
|
|
143 |
$zippkgs = join(" ", @bundlepkgs);
|
|
|
144 |
}
|
|
|
145 |
print "\n";
|
|
|
146 |
|
|
|
147 |
if($description->{"Depends"}) {
|
|
|
148 |
my $depends = $description->{"Depends"};
|
|
|
149 |
if($depends =~ /\bR *\(([^) ]+) *([^) ]+)\)/) { # regexp from check
|
|
|
150 |
my $op = $1;
|
|
|
151 |
my $ver = $2;
|
|
|
152 |
my $Rversion = $ENV{'R_VERSION'};
|
|
|
153 |
if ($op eq ">=" && $ver) {
|
|
|
154 |
die "This R is version $Rversion\n".
|
|
|
155 |
" package \`$pkgname' requires R $ver or later\n"
|
|
|
156 |
unless $Rversion ge $ver;
|
|
|
157 |
} elsif ($op eq "<=" && $ver) {
|
|
|
158 |
die "This R is version $Rversion\n".
|
|
|
159 |
" package \`$pkgname' requires R $ver or earlier\n"
|
|
|
160 |
unless $Rversion le $ver;
|
|
|
161 |
} else {
|
|
|
162 |
printf "unsupported operator in dependence \"$depends\"\n";
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
my $save = "CHECK";
|
|
|
168 |
$save = "false" if $opt_no_save;
|
|
|
169 |
$save = "true" if $opt_save;
|
|
|
170 |
my $opt = "";
|
| 27784 |
ripley |
171 |
my $dpkg = $library. "/" . $pkgname;
|
|
|
172 |
if($opt_with_package_versions) {
|
|
|
173 |
$dpkg = $dpkg . "_" . $description->{"Version"};
|
|
|
174 |
}
|
| 25573 |
ripley |
175 |
if(!$is_bundle) {
|
|
|
176 |
if($opt_auto_zip || $opt_build) {
|
|
|
177 |
my $dir = $pkgdir. "/" . $pkgname . "/data";
|
|
|
178 |
if(-d $dir &&
|
|
|
179 |
$pkgname ne "RadioSonde" && $pkgname ne "dichromat"
|
|
|
180 |
&& $pkgname ne "pls.pcr") {
|
|
|
181 |
my $Rout = "datacnt";
|
|
|
182 |
system("ls -s1 $dir > $Rout");
|
|
|
183 |
my $out, $nodups=1, $prev="";
|
|
|
184 |
open ROUT, "< $Rout";
|
|
|
185 |
while(<ROUT>) {
|
|
|
186 |
if(/^total/) {
|
|
|
187 |
s/^total //;
|
|
|
188 |
$out = $_;
|
|
|
189 |
} else {
|
|
|
190 |
chomp;
|
|
|
191 |
s/\s*[0-9]+\ //;
|
|
|
192 |
s/\.[a-zA-Z]+$//;
|
|
|
193 |
$nodups = 0 if $_ eq $prev;
|
|
|
194 |
$prev = $_;
|
|
|
195 |
}
|
|
|
196 |
}
|
|
|
197 |
close ROUT;
|
|
|
198 |
unlink $Rout;
|
|
|
199 |
$opt = "$pkgname-ZIPDATA=zip" if $out > 100 && $nodups;
|
|
|
200 |
}
|
|
|
201 |
$dir = $pkgdir. "/" . $pkgname . "/man";
|
|
|
202 |
if(-d $dir) {
|
|
|
203 |
opendir(DIR, $dir) or die "cannot opendir $dir: $!";
|
|
|
204 |
@files = grep{ /\.Rd$/ } readdir(DIR);
|
|
|
205 |
closedir(DIR);
|
|
|
206 |
$opt = $opt . " $pkgname-HELP=ziponly" if @files > 20;
|
|
|
207 |
}
|
|
|
208 |
print "Using auto-selected zip options '$opt'\n";
|
|
|
209 |
} else {
|
|
|
210 |
$opt = "$pkgname-ZIPDATA=zip"
|
|
|
211 |
if ($opt_use_zip || $opt_use_zip_data);
|
|
|
212 |
$opt = $opt . " $pkgname-HELP=ziponly"
|
|
|
213 |
if ($opt_use_zip || $opt_use_zip_help);
|
|
|
214 |
}
|
|
|
215 |
} else {
|
|
|
216 |
## note: --auto-zip is not supported for bundles
|
|
|
217 |
foreach $ppkg (@bundlepkgs) {
|
|
|
218 |
$opt = $opt . " $ppkg-ZIPDATA=zip" if ($opt_use_zip || $opt_use_zip_data);
|
|
|
219 |
$opt = $opt . " $ppkg-HELP=ziponly" if ($opt_use_zip || $opt_use_zip_help);
|
|
|
220 |
}
|
|
|
221 |
}
|
| 27897 |
ripley |
222 |
my $res = system("make --no-print-directory -C $R_HOME/src/gnuwin32 PKGDIR=$pkgdir RLIB=$library DPKG=$dpkg SAVE=$save $opt $helpflags $makecmd-$pkgname");
|
| 25573 |
ripley |
223 |
if($res) {
|
|
|
224 |
printf "*** Installation of $pkgname failed ***\n";
|
|
|
225 |
} else {
|
|
|
226 |
if($opt_build) {
|
|
|
227 |
my $filename = "${pkgname}_" . $description->{"Version"};
|
|
|
228 |
chdir($library);
|
| 27903 |
ripley |
229 |
$startdir = Win32::GetShortPathName($startdir) if $startdir =~ / /;
|
| 25573 |
ripley |
230 |
system("rm -f $startdir/$filename.zip");
|
|
|
231 |
system("zip -r9Xq $startdir/$filename.zip $zippkgs");
|
|
|
232 |
if ($is_bundle) {
|
|
|
233 |
## Need to get the toplevel files in there
|
|
|
234 |
$currentDir = cwd();
|
|
|
235 |
chdir($canonpkg);
|
|
|
236 |
system("zip $startdir/$filename.zip $topLevelFiles");
|
|
|
237 |
chdir($currentDir);
|
|
|
238 |
}
|
|
|
239 |
}
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
system("make --no-print-directory -C $R_HOME/src/gnuwin32 PKGDIR=$pkgdir RLIB=$library pkgclean-$pkgname") if ($opt_clean && $is_bundle == 0);
|
|
|
243 |
|
|
|
244 |
if($opt_clean && $is_bundle) {
|
|
|
245 |
foreach $ppkg (@bundlepkgs) {
|
|
|
246 |
system("make --no-print-directory -C $R_HOME/src/gnuwin32 PKGDIR=$pkgdir/$pkgname RLIB=$library pkgclean-$ppkg")
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
}
|
|
|
250 |
if ($istar > 0) {
|
|
|
251 |
chdir($startdir);
|
|
|
252 |
rmtree("R.INSTALL");
|
|
|
253 |
}
|
|
|
254 |
print("\n");
|
| 28275 |
murdoch |
255 |
if(!$res) {print("\* DONE");}
|
| 25573 |
ripley |
256 |
}
|
|
|
257 |
|
|
|
258 |
|
| 28277 |
murdoch |
259 |
|
| 25573 |
ripley |
260 |
sub usage {
|
|
|
261 |
print STDERR <<END;
|
|
|
262 |
Usage: Rcmd $name [options] pkgs
|
|
|
263 |
|
|
|
264 |
Install the add-on packages specified by pkgs into the default R library
|
|
|
265 |
tree ($R_HOME/library) or the tree specified via \`--library'. The
|
|
|
266 |
elements of pkgs can be relative or absolute paths to directories with
|
|
|
267 |
the package (bundle) sources, or to gzipped package \`tar' archives.
|
|
|
268 |
Then optionally pack the installed package into a zip file.
|
|
|
269 |
|
|
|
270 |
Options:
|
|
|
271 |
-h, --help print short help message and exit
|
|
|
272 |
-v, --version print version info and exit
|
|
|
273 |
-c, --clean remove all files created during installation
|
|
|
274 |
-s, --save Save the package source as an image file, and arrange for
|
|
|
275 |
this file to be loaded when the library is attached.
|
|
|
276 |
--no-save Do not save the package source as an image file.
|
|
|
277 |
-d, --debug [x] turn on shell and build-help debugging
|
|
|
278 |
-l, --library=LIB install packages to library tree LIB
|
|
|
279 |
--docs=TYPE type(s) of documentation to build and install
|
| 27784 |
ripley |
280 |
--with-package-versions
|
|
|
281 |
allow for multiple versions of the same package
|
| 25573 |
ripley |
282 |
--use-zip-data collect data files in zip archive
|
|
|
283 |
--use-zip-help collect help and examples into zip archives
|
|
|
284 |
--use-zip combine \`--use-zip-data\' and \`--use-zip-help\'
|
|
|
285 |
--auto-zip select whether to zip automatically
|
|
|
286 |
--build zip-up the installation. Implies --auto-zip
|
|
|
287 |
--fake do minimal install for testing purposes
|
|
|
288 |
|
| 27901 |
ripley |
289 |
TYPE can be "none" or "normal" or "chm" (the default) or "all"
|
| 25573 |
ripley |
290 |
|
|
|
291 |
Report bugs to <r-bugs\@r-project.org>.
|
|
|
292 |
END
|
|
|
293 |
exit 0;
|
|
|
294 |
}
|