1 generate_changelog <- function(pkg) {
2 # construct a dummy changelog
3 # TODO: ``Writing R extensions'' mentions that a package may also have
4 # {NEWS,ChangeLog} files.
5 cat(paste(paste(pkg$srcname,' (',pkg$debversion,') unstable; urgency=low',sep='')
6 ,'' ,' * Initial release.',''
7 ,paste(' --',maintainer,'',format(Sys.time(),'%a, %d %b %Y %H:%M:%S %z'))
8 ,'',sep='\n'),file=pkg$debfile('changelog.in'))
11 generate_rules <- function(pkg) {
12 cat(paste('#!/usr/bin/make -f'
13 ,paste('debRreposname :=',pkg$repo)
14 ,'include /usr/share/R/debian/r-cran.mk'
16 ,file=pkg$debfile('rules'))
17 Sys.chmod(pkg$debfile('rules'),'0700')
20 generate_copyright <- function(pkg) {
21 # generate_copyright file; we trust DESCRIPTION
23 paste('This Debian package of the GNU R package',pkg$name
24 ,'was generated automatically using cran2deb by'
25 ,paste(maintainer,'.',sep='')
27 ,'The original GNU R package is Copyright (C) '
28 # TODO: copyright start date, true copyright date
29 ,format(Sys.time(),'%Y')
30 ,pkg$description[1,'Author']
31 ,'and possibly others.'
33 ,'The original GNU R package is maintained by'
34 ,pkg$description[1,'Maintainer'],'and was obtained from:'
39 ,'The GNU R package DESCRIPTION offers a'
40 ,'Copyright licenses under the terms of the',pkg$license
41 ,'license. On a Debian GNU/Linux system, common'
42 ,'licenses are included in the directory'
43 ,'/usr/share/common-licenses/.'
45 ,'The DESCRIPTION file for the original GNU R package '
47 ,file.path('/usr/lib/R/site-library'
51 ,sep='\n'), width=72), con=pkg$debfile('copyright.in'))
54 prepare_new_debian <- function(pkg,extra_deps) {
55 # generate Debian version and name
56 pkg$repo = repourl_as_debian(pkg$repoURL)
57 if (pkg$version != available[pkg$name,'Version']) {
58 # should never happen since available is the basis upon which the
59 # package is retrieved.
60 error('available version:',available[pkg$name,'Version'])
61 error('package version:',pkg$version)
62 fail('inconsistency between R package version and cached R version')
64 pkg$debversion = new_build_version(pkg$name)
65 if (!length(grep('^[A-Za-z0-9][A-Za-z0-9+.-]+$',pkg$name))) {
66 fail('Cannot convert package name into a Debian name',pkg$name)
68 pkg$srcname = tolower(pkg$name)
69 pkg$debname = pkgname_as_debian(pkg$name,repo=pkg$repo)
71 if (!length(grep('\\.tar\\.gz',pkg$archive))) {
72 fail('archive is not tarball')
75 # re-pack into a Debian-named archive with a Debian-named directory.
76 debpath = file.path(dirname(pkg$archive)
77 ,paste(pkg$srcname,'-'
80 file.rename(pkg$path, debpath)
82 debarchive = file.path(dirname(pkg$archive)
83 ,paste(pkg$srcname,'_'
84 ,pkg$version,'.orig.tar.gz'
87 setwd(dirname(pkg$path))
88 # remove them pesky +x files
89 system(paste('find',shQuote(basename(pkg$path))
90 ,'-type f -exec chmod -x {} \\;'))
92 system(paste('tar -czf',shQuote(debarchive),shQuote(basename(pkg$path))))
94 file.remove(pkg$archive)
95 pkg$archive = debarchive
97 # make the debian/ directory
98 debdir <- file.path(pkg$path,'debian')
99 pkg$debfile <- function(x) { file.path(debdir,x) }
100 unlink(debdir,recursive=T)
103 # see if this is an architecture-dependent package.
104 # heuristic: if /src/ exists in pkg$path, then this is an
105 # architecture-dependent package.
106 # CRAN2DEB.pm is a bit fancier about this but ``Writing R extensions''
107 # says: ``The sources and headers for the compiled code are in src, plus
108 # optionally file Makevars or Makefile.'' It seems unlikely that
109 # architecture independent code would end up here.
111 # if it's a bundle, check each of the packages
113 for (pkgname in r_bundle_contains(pkg$name)) {
114 pkg$archdep = file.exists(file.path(pkg$path,pkgname,'src'))
120 pkg$archdep = file.exists(file.path(pkg$path,'src'))
124 pkg$arch <- host_arch()
127 pkg$license <- accept_license(pkg)
128 pkg$depends <- get_dependencies(pkg,extra_deps)
129 generate_changelog(pkg)
131 generate_copyright(pkg)
132 generate_control(pkg)
134 # TODO: debian/watch from pkg$repoURL
136 # convert text to utf8 (who knows what the original character set is --
137 # let's hope iconv DTRT).
138 for (file in c('control','changelog','copyright')) {
139 system(paste('iconv -o ',shQuote(pkg$debfile(file))
141 ,shQuote(pkg$debfile(paste(file,'in',sep='.')))))
142 file.remove(pkg$debfile(paste(file,'in',sep='.')))