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