]> git.donarmstrong.com Git - cran2deb.git/blob - pkg/trunk/R/debcontrol.R
8ff18908e527254d90867b2f22a524b010ed3053
[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,build) {
7         return(pkgname_as_debian(paste(dependencies[r,]$name)
8                                 ,version=dependencies[r,]$version
9                                 ,repopref=pkg$repo
10                                 ,build=build))
11     }
12     depends$bin <- lapply(rownames(dependencies), as_deb, build=F)
13     depends$build <- lapply(rownames(dependencies), as_deb, build=T)
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',build=T))
27         depends$bin   = c(depends$bin,  pkgname_as_debian('R',version='>= 2.7.0',build=F))
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 = r_dependency_closure(dependencies)
44     # append command line dependencies
45     depends$r = c(extra_deps$r, depends$r)
46     return(depends)
47 }
48
49 sysreqs_as_debian <- function(sysreq_text) {
50     # form of this field is unspecified (ugh) but most people seem to stick
51     # with this
52     debs <- c()
53     for (sysreq in strsplit(sysreq_text,'[[:space:]]*,[[:space:]]*')[[1]]) {
54         startreq = sysreq
55         # constant case
56         sysreq = tolower(sysreq)
57         # drop version information/comments for now
58         sysreq = gsub('[\\([][^])]*[]\\)]','',sysreq)
59         sysreq = gsub('version','',sysreq)
60         sysreq = gsub('from','',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         if (deb == 'build-essential') {
74             # already in any build environment so no explicit depend.
75             message(paste('N: SystemRequirement',startreq,'dropped'))
76         } else {
77             debs = c(debs,deb)
78         }
79     }
80     return(debs)
81 }
82
83 generate_control <- function(pkg) {
84     # construct control file
85     control = data.frame()
86     control[1,'Source'] = pkg$srcname
87     control[1,'Section'] = 'math'
88     control[1,'Priority'] = 'optional'
89     control[1,'Maintainer'] = maintainer
90     control[1,'Build-Depends'] = paste(pkg$depends$build,collapse=', ')
91     control[1,'Standards-Version'] = '3.8.0'
92
93     control[2,'Package'] = pkg$debname
94     control[2,'Architecture'] = 'all'
95     if (pkg$archdep) {
96         control[2,'Architecture'] = 'any'
97     }
98     control[2,'Depends'] = paste(pkg$depends$bin,collapse=', ')
99
100     # bundles provide virtual packages of their contents
101     if (pkg$is_bundle) {
102         control[2,'Provides'] = paste(
103                     lapply(r_bundle_contains(pkg$name)
104                           ,function(name) return(pkgname_as_debian(paste(name)
105                                                                   ,repopref=pkg$repo)))
106                           ,collapse=', ')
107     }
108
109     # generate the description
110     descr = 'GNU R package "'
111     if ('Title' %in% colnames(pkg$description)) {
112         descr = paste(descr,pkg$description[1,'Title'],sep='')
113     } else {
114         descr = paste(descr,pkg$name,sep='')
115     }
116     if (pkg$is_bundle) {
117         long_descr <- pkg$description[1,'BundleDescription']
118     } else {
119         long_descr <- pkg$description[1,'Description']
120     }
121     # using \n\n.\n\n is not very nice, but is necessary to make sure
122     # the longer description does not begin on the synopsis line --- R's
123     # write.dcf does not appear to have a nicer way of doing this.
124     descr = paste(descr,'"\n\n', long_descr, sep='')
125     if ('URL' %in% colnames(pkg$description)) {
126         descr = paste(descr,'\n\nURL: ',pkg$description[1,'URL'],sep='')
127     }
128     control[2,'Description'] = descr
129
130     # Debian policy says 72 char width; indent minimally
131     write.dcf(control,file=pkg$debfile('control.in'),indent=1,width=72)
132     write.dcf(control,indent=1,width=72)
133 }
134