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 pkg$debversion = version_new(pkg$version)
58 if (!length(grep('^[A-Za-z0-9][A-Za-z0-9+.-]+$',pkg$name))) {
59 stop(paste('Cannot convert package name into a Debian name',pkg$name))
61 pkg$srcname = tolower(pkg$name)
62 pkg$debname = pkgname_as_debian(pkg$name,repo=pkg$repo)
64 if (!length(grep('\\.tar\\.gz',pkg$archive))) {
65 stop('archive is not tarball')
68 # re-pack into a Debian-named archive with a Debian-named directory.
69 debpath = file.path(dirname(pkg$archive)
70 ,paste(pkg$srcname,'-'
73 file.rename(pkg$path, debpath)
75 debarchive = file.path(dirname(pkg$archive)
76 ,paste(pkg$srcname,'_'
77 ,pkg$version,'.orig.tar.gz'
80 setwd(dirname(pkg$path))
81 # remove them pesky +x files
82 system(paste('find',shQuote(basename(pkg$path))
83 ,'-type f -exec chmod -x {} \\;'))
85 system(paste('tar -czf',shQuote(debarchive),shQuote(basename(pkg$path))))
87 file.remove(pkg$archive)
88 pkg$archive = debarchive
90 # make the debian/ directory
91 debdir <- file.path(pkg$path,'debian')
92 pkg$debfile <- function(x) { file.path(debdir,x) }
93 unlink(debdir,recursive=T)
96 # see if this is an architecture-dependent package.
97 # heuristic: if /src/ exists in pkg$path, then this is an
98 # architecture-dependent package.
99 # CRAN2DEB.pm is a bit fancier about this but ``Writing R extensions''
100 # says: ``The sources and headers for the compiled code are in src, plus
101 # optionally file Makevars or Makefile.'' It seems unlikely that
102 # architecture independent code would end up here.
104 # if it's a bundle, check each of the packages
106 for (pkgname in r_bundle_contains(pkg$name)) {
107 pkg$archdep = file.exists(file.path(pkg$path,pkgname,'src'))
113 pkg$archdep = file.exists(file.path(pkg$path,'src'))
117 pkg$arch <- host_arch()
120 pkg$license <- accept_license(pkg)
121 pkg$depends <- get_dependencies(pkg,extra_deps)
122 generate_changelog(pkg)
124 generate_copyright(pkg)
125 generate_control(pkg)
127 # TODO: debian/watch from pkg$repoURL
129 # convert text to utf8 (who knows what the original character set is --
130 # let's hope iconv DTRT).
131 for (file in c('control','changelog','copyright')) {
132 system(paste('iconv -o ',shQuote(pkg$debfile(file))
134 ,shQuote(pkg$debfile(paste(file,'in',sep='.')))))
135 file.remove(pkg$debfile(paste(file,'in',sep='.')))
140 build_debian <- function(pkg) {
143 message(paste('N: building Debian package'
145 ,paste('(',pkg$debversion,')',sep='')
147 ret = system(paste('pdebuild --configfile',shQuote(pbuilder_config)))
150 stop('Failed to build package.')