]> git.donarmstrong.com Git - cran2deb.git/blob - pkg/trunk/R/debcontrol.R
cdbc4fb323c28bdef7400117ecf0e376695ce6fb
[cran2deb.git] / pkg / trunk / R / debcontrol.R
1 get.dependencies <- function(pkg,extra_deps) {
2     # determine dependencies
3     dependencies <- r.dependencies.of(description=pkg$description)
4     depends <- list()
5     # these are used for generating the Depends fields
6     as.deb <- function(r,binary) {
7         return(pkgname.as.debian(paste(dependencies[r,]$name)
8                                 ,version=dependencies[r,]$version
9                                 ,repopref=pkg$repo
10                                 ,binary=binary))
11     }
12     depends$bin <- lapply(rownames(dependencies), as.deb, binary=T)
13     depends$build <- lapply(rownames(dependencies), as.deb, binary=F)
14     # add the command line dependencies
15     depends$bin = c(extra_deps$deb,depends$bin)
16     depends$build = c(extra_deps$deb,depends$build)
17     # add the system requirements
18     if ('SystemRequirements' %in% colnames(pkg$description)) {
19         sysreq <- sysreqs.as.debian(pkg$description[1,'SystemRequirements'])
20         depends$bin = c(sysreq,depends$bin)
21         depends$build = c(sysreq,depends$build)
22     }
23
24     # make sure we depend upon R in some way...
25     if (!length(grep('^r-base',depends$build))) {
26         depends$build = c(depends$build,pkgname.as.debian('R',version='>= 2.7.0',binary=F))
27         depends$bin   = c(depends$bin,  pkgname.as.debian('R',version='>= 2.7.0',binary=T))
28     }
29     # also include stuff to allow tcltk to build (suggested by Dirk)
30     depends$build = c(depends$build,'xvfb','xauth','xfonts-base')
31
32     # remove duplicates
33     depends <- lapply(depends,unique)
34
35     # append the Debian dependencies
36     depends$build=c(depends$build,'debhelper (>> 4.1.0)','cdbs')
37     if (pkg$archdep) {
38         depends$bin=c(depends$bin,'${shlibs:Depends}')
39     }
40
41     # the names of dependent source packages (to find the .changes file to
42     # upload via dput). these can be found recursively.
43     depends$r = lapply(r.dependency.closure(dependencies)
44                       ,tolower)
45     # append command line dependencies
46     depends$r = c(extra_deps$r, depends$r)
47     return(depends)
48 }
49
50 sysreqs.as.debian <- function(sysreq_text) {
51     # form of this field is unspecified (ugh) but most people seem to stick
52     # with this
53     debs <- c()
54     for (sysreq in strsplit(sysreq_text,'[[:space:]]*,[[:space:]]*')[[1]]) {
55         startreq = sysreq
56         # constant case
57         sysreq = tolower(sysreq)
58         # drop version information/comments for now
59         sysreq = gsub('[\\([][^])]*[]\\)]','',sysreq)
60         sysreq = gsub('version','',sysreq)
61         sysreq = gsub('[<>=]*[[:space:]]*[[:digit:]]+[[:digit:].+:~-]*','',sysreq)
62         # byebye URLs
63         sysreq = gsub('(ht|f)tps?://[[:alnum:]!?*"\'(),%$_@.&+/=-]*','',sysreq)
64         # squish out space
65         sysreq = chomp(gsub('[[:space:]]+',' ',sysreq))
66         deb <- db.sysreq.override(sysreq)
67         if (is.na(deb)) {
68             message(paste('E: do not know what to do with SystemRequirement:',sysreq))
69             message(paste('E: original SystemRequirement:',startreq))
70             stop('unmet system requirement')
71         }
72         message(paste('N: mapped SystemRequirement',startreq,'onto',deb,'via',sysreq))
73         debs = c(debs,deb)
74     }
75     return(debs)
76 }
77
78 generate.control <- function(pkg) {
79     # construct control file
80     control = data.frame()
81     control[1,'Source'] = pkg$srcname
82     control[1,'Section'] = 'math'
83     control[1,'Priority'] = 'optional'
84     control[1,'Maintainer'] = maintainer
85     control[1,'Build-Depends'] = paste(pkg$depends$build,collapse=', ')
86     control[1,'Standards-Version'] = '3.8.0'
87
88     control[2,'Package'] = pkg$debname
89     control[2,'Architecture'] = 'all'
90     if (pkg$archdep) {
91         control[2,'Architecture'] = 'any'
92     }
93     control[2,'Depends'] = paste(pkg$depends$bin,collapse=', ')
94
95     # bundles provide virtual packages of their contents
96     if (pkg$is_bundle) {
97         control[2,'Provides'] = paste(
98                     lapply(r.bundle.contains(pkg$name)
99                           ,function(name) return(pkgname.as.debian(paste(name)
100                                                                   ,repopref=pkg$repo
101                                                                   ,binary=T)))
102                           ,collapse=', ')
103     }
104
105     # generate the description
106     descr = 'GNU R package "'
107     if ('Title' %in% colnames(pkg$description)) {
108         descr = paste(descr,pkg$description[1,'Title'],sep='')
109     } else {
110         descr = paste(descr,pkg$name,sep='')
111     }
112     if (pkg$is_bundle) {
113         long_descr <- pkg$description[1,'BundleDescription']
114     } else {
115         long_descr <- pkg$description[1,'Description']
116     }
117     # using \n\n.\n\n is not very nice, but is necessary to make sure
118     # the longer description does not begin on the synopsis line --- R's
119     # write.dcf does not appear to have a nicer way of doing this.
120     descr = paste(descr,'"\n\n', long_descr, sep='')
121     if ('URL' %in% colnames(pkg$description)) {
122         descr = paste(descr,'\n\nURL: ',pkg$description[1,'URL'],sep='')
123     }
124     control[2,'Description'] = descr
125
126     # Debian policy says 72 char width; indent minimally
127     write.dcf(control,file=pkg$debfile('control.in'),indent=1,width=72)
128     write.dcf(control,indent=1,width=72)
129 }
130