]> git.donarmstrong.com Git - cran2deb.git/blob - tags/pre-dual/R/debianpkg.R
reprepro version before the massacre
[cran2deb.git] / tags / pre-dual / R / debianpkg.R
1 append_build_from_pkg <- function(pkg, builds) {
2     pkg_build <- data.frame(id = -1     # never used
3                            ,package = pkg$name
4                            ,system = which_system
5                            ,r_version = version_upstream(pkg$debversion)
6                            ,deb_epoch = version_epoch(pkg$debversion)
7                            ,deb_revision = version_revision(pkg$debversion)
8                            ,db_version = db_get_version()
9                            ,date_stamp = pkg$date_stamp
10                            ,scm_revision = scm_revision
11                            ,success = 1 # never used
12                            ,log = ''    # never used
13                            )
14     return(cbind(data.frame(srcname=pkg$srcname), rbind(builds, pkg_build)))
15 }
16
17 generate_changelog <- function(pkg) {
18     # TODO: ``Writing R extensions'' mentions that a package may also have
19     # {NEWS,ChangeLog} files.
20     builds <- append_build_from_pkg(pkg, db_builds(pkg$name))
21     sapply(rev(rownames(builds)), function(b, changelog) generate_changelog_entry(builds[b,], changelog), pkg$debfile('changelog.in'))
22 }
23
24 generate_changelog_entry <- function(build, changelog) {
25     # TODO: should say 'New upstream release' when necessary
26     debversion <- version_new(build$r_version, build$deb_revision, build$deb_epoch)
27     cat(paste(paste(build$srcname,' (',debversion,') testing; urgency=low',sep='')
28              ,'' ,paste('  * cran2deb ',build$scm_revision
29                        ,' with DB version ',as.integer(build$db_version),'.',sep='')
30              ,'',paste(' --',maintainer,'',format(build$date_stamp,'%a, %d %b %Y %H:%M:%S %z'))
31              ,'','','',sep='\n'),file=changelog, append=TRUE)
32 }
33
34 generate_rules <- function(pkg) {
35     cat(paste('#!/usr/bin/make -f'
36              ,paste('debRreposname :=',pkg$repo)
37              ,'include /usr/share/R/debian/r-cran.mk'
38              ,'',sep='\n')
39        ,file=pkg$debfile('rules'))
40     Sys.chmod(pkg$debfile('rules'),'0700')
41 }
42
43 generate_copyright <- function(pkg) {
44     # generate_copyright file; we trust DESCRIPTION
45
46     # if maintainer is missing then try to use author
47     if (!('Maintainer' %in% colnames(pkg$description))) {
48         if ('Author' %in% colnames(pkg$description)) {
49             maintainer = pkg$description[1,'Author']
50         } else {
51             fail('Maintainer and Author not defined in R DESCRIPTION')
52         }
53     } else {
54         maintainer = pkg$description[1,'Maintainer']
55     }
56     # likewise if author is missing then try to use maintainer
57     if (!('Author' %in% colnames(pkg$description))) {
58         author = maintainer
59     } else {
60         author = pkg$description[1,'Author']
61     }
62
63     writeLines(strwrap(
64         paste('This Debian package of the GNU R package',pkg$name
65              ,'was generated automatically using cran2deb by'
66              ,paste(maintainer,'.',sep='')
67              ,''
68              ,'The original GNU R package is Copyright (C) '
69              # TODO: copyright start date, true copyright date
70              ,format(Sys.time(),'%Y')
71              ,author
72              ,'and possibly others.'
73              ,''
74              ,'The original GNU R package is maintained by'
75              ,maintainer,'and was obtained from:'
76              ,''
77              ,pkg$repoURL
78              ,''
79              ,''
80              ,'The GNU R package DESCRIPTION offers a'
81              ,'Copyright licenses under the terms of the license:'
82              ,pkg$license,'.  On a Debian GNU/Linux system, common'
83              ,'licenses are included in the directory'
84              ,'/usr/share/common-licenses/.'
85              ,''
86              ,'The DESCRIPTION file for the original GNU R package '
87              ,'can be found in '
88              ,file.path('/usr/lib/R/site-library'
89                    ,pkg$debname
90                    ,'DESCRIPTION'
91                    )
92              ,sep='\n'), width=72), con=pkg$debfile('copyright.in'))
93 }
94
95 prepare_new_debian <- function(pkg,extra_deps) {
96     # generate Debian version and name
97     pkg$debversion = new_build_version(pkg$name)
98
99     # make the debian/ directory
100     debdir <- file.path(pkg$path,'debian')
101     pkg$debfile <- function(x) { file.path(debdir,x) }
102     unlink(debdir,recursive=T)
103     dir.create(debdir)
104
105     # see if this is an architecture-dependent package.
106     # heuristic: if /src/ exists in pkg$path, then this is an
107     #            architecture-dependent package.
108     # CRAN2DEB.pm is a bit fancier about this but ``Writing R extensions''
109     # says: ``The sources and headers for the compiled code are in src, plus
110     # optionally file Makevars or Makefile.'' It seems unlikely that
111     # architecture independent code would end up here.
112     pkg$archdep = file.exists(file.path(pkg$path,'src'))
113     pkg$arch <- 'all'
114     if (pkg$archdep) {
115         pkg$arch <- host_arch()
116     }
117
118     pkg$license <- accept_license(pkg)
119     pkg$depends <- get_dependencies(pkg,extra_deps)
120     apply_patches(pkg)
121     generate_lintian(pkg)
122     generate_changelog(pkg)
123     generate_rules(pkg)
124     generate_copyright(pkg)
125     generate_control(pkg)
126     ## debdir <- file.path(pkg$path,'debian')
127     ## system(paste("ls ", debdir, "; ls -l ", debdir, "/patches/*", sep=""))
128
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         log_system('iconv -o ',shQuote(pkg$debfile(file))
133                     ,' -t utf8 -c '
134                     ,shQuote(pkg$debfile(paste(file,'in',sep='.'))))
135         file.remove(pkg$debfile(paste(file,'in',sep='.')))
136     }
137     return(pkg)
138 }