-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdebian.jam
254 lines (211 loc) · 7.49 KB
/
debian.jam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#==============================================================================
# Brief : Debian Package Tool
# Authors : Bruno Santos <[email protected]>
#------------------------------------------------------------------------------
# ODTONE - Open Dot Twenty One
#
# Copyright (C) 2009-2013 Universidade Aveiro
# Copyright (C) 2009-2013 Instituto de Telecomunicações - Pólo Aveiro
#
# This software is distributed under a license. The full license
# agreement can be found in the file LICENSE in this distribution.
# This software may not be copied, modified, sold or distributed
# other than expressed in the named license agreement.
#
# This software is distributed without any warranty.
#==============================================================================
import "class" : new ;
import type ;
import print ;
import project ;
import targets ;
import feature ;
import sequence ;
import path ;
type.register DEB : deb ;
feature.feature package : : free ;
feature.feature section : : free ;
feature.feature package-arch : : free ;
feature.feature homepage : : free ;
feature.feature maintainer-name : : free ;
feature.feature maintainer-email : : free ;
feature.feature description : : free ;
feature.feature changelog : : free ;
class deb-dir-target : basic-target {
import path ;
import regex ;
import utility ;
rule __init__ ( name : project : sources * : requirements * : default-build * : usage-requirements * )
{
basic-target.__init__ $(name) : $(project) : :
$(requirements) : $(default-build) : $(usage-requirements) ;
# The grist is used to encode path location in the debian package, util I figure some better way
self.sources = $(sources) ;
}
local rule package-path ( grist )
{
return [ path.join $(self.name) [ utility.ungrist $(grist) ] ] ;
}
rule generate-dependencies ( dependencies * : property-set : result-var usage-requirements-var )
{
for local dependency in $(dependencies) {
local grist = $(dependency:G) ;
local id = $(dependency:G=) ;
local result = [ targets.generate-from-reference $(id) :
$(self.project) : $(property-set) ] ;
$(result-var) += $(result[2-]) ;
$(usage-requirements-var) += [ $(result[1]).raw ] ;
for local t in $(result[2-]) {
self.package-paths.$(t) = [ package-path $(grist) ] ;
}
}
}
rule construct ( name : source-targets * : property-set )
{
local t ;
for local src in $(source-targets) {
local n = [ $(src).name ] ;
local d = [ path.join $(self.package-paths.$(src)) $(n:D=) ] ;
t += [ new file-target $(d) : : $(self.project)
: [ new action $(src) : common.copy : $(property-set) ] ] ;
}
t += [ new file-target [ path.join $(name) "DEBIAN/control" ] : : $(self.project)
: [ new action $(source-targets) : debian.control : $(property-set) ] ] ;
return [ property-set.empty ] [ sequence.transform virtual-target.register : $(t) ] ;
}
}
class deb-target : basic-target {
rule __init__ ( name : project : sources * : requirements * : default-build * : usage-requirements * )
{
basic-target.__init__ $(name) : $(project) : $(sources) : $(requirements)
: $(default-build) : $(usage-requirements) ;
}
rule construct ( name : source-targets * : property-set )
{
local r = [ property-set.empty ] ;
r += [ virtual-target.register
[ new file-target $(self.name) : DEB : $(self.project)
: [ new action $(source-targets) : debian.make : $(property-set) ] ] ] ;
return $(r) ;
}
}
rule make
{
local path = [ path.join [ on $(<) return $(LOCATE) ] $(<:G=:S=.dir) ] ;
local exists = [ path.glob-tree $(path) : * ] ;
local sources = $(path:B=:S=)"/"$(>:G=) ;
local exclude ;
local result ;
for local s in $(exists) {
exclude += [ path.all-parents $(s) : $(path) ] ;
}
exclude = [ sequence.unique $(exclude) ] ;
for local s in $(exists) {
if ! $(s) in $(exclude) {
result += $(s) ;
}
}
exists = $(result) ;
result = ;
for local s in $(exists) {
if ! $(s) in $(sources) {
result += $(s) ;
}
}
DELETE on $(<) = $(result) ;
}
actions make
{
rm -rf "$(DELETE)"
dpkg-deb -b "$(<:S=.dir)" "$(<)"
}
rule control ( target : sources * : properties * )
{
local text ;
local package = [ feature.get-values <package> : $(properties) ] ;
local architecture = [ feature.get-values <package-arch> : $(properties) ] ;
local version = [ feature.get-values <version> : $(properties) ] ;
local section = [ feature.get-values <section> : $(properties) ] ;
local homepage = [ feature.get-values <homepage> : $(properties) ] ;
local maintainer-name = [ feature.get-values <maintainer-name> : $(properties) ] ;
local maintainer-email = [ feature.get-values <maintainer-email> : $(properties) ] ;
local description = [ feature.get-values <description> : $(properties) ] ;
if ! $(package) {
errors.error "debian: missing package property" ;
}
if ! $(maintainer-name) {
errors.error "debian: missing maintainer name property" ;
}
if ! $(maintainer-email) {
errors.error "debian: missing maintainer email property" ;
}
if ! $(description) {
errors.error "debian: missing description property" ;
}
text += "Package: $(package)" ;
if $(version) {
text += "Version: $(version)" ;
}
if ! $(architecture) {
architecture = all ;
}
text += "Architecture: $(architecture)" ;
#
# FIXME: hardcoded options
#
text += "Essential: no" ;
text += "Depends: libstdc++6, libgcc1, libc6" ;
text += "Conflict: $(package)" ;
text += "Replaces: $(package)" ;
text += "Provides: $(package)" ;
if $(section) {
text += "Section: $(section)" ;
}
text += "Priority: optional" ;
if $(homepage) {
text += "Homepage: $(homepage)" ;
}
text += "Maintainer: $(maintainer-name) [$(maintainer-email)]" ;
text += "Description: $(description)" ;
text += "" ;
print.output $(target) plain ;
print.text $(text) : true ;
}
local rule path-grist-sources ( package-name : sources * )
{
local result ;
local path = "" ;
for local src in $(sources) {
switch $(src) {
case <bin> : path = "usr/bin" ;
case <lib> : path = "usr/lib/$(package-name)" ;
case <etc> : path = "usr/etc/$(package-name)" ;
case <share> : path = "usr/share/$(package-name)" ;
case <path> : path = "" ;
case <path>* : path = $(src:G=) ;
case * : result += $(src:G=$(path)) ;
}
}
return $(result) ;
}
rule debian ( name package-name ? : sources * : requirements * : default-build * : usage-requirements * )
{
local project = [ project.current ] ;
package-name ?= $(name) ;
requirements += <package>$(package-name) ;
sources = [ path-grist-sources $(package-name) : $(sources) ] ;
targets.main-target-alternative
[ new deb-dir-target $(name:S=.dir) : $(project)
: [ targets.main-target-sources $(sources) : $(name:S=.dir) ]
: [ targets.main-target-requirements $(requirements) : $(project) ]
: [ targets.main-target-default-build $(default-build) : $(project) ]
: [ targets.main-target-usage-requirements $(usage-requirements) : $(project) ] ] ;
$(project).mark-target-as-explicit $(debian:S=.dir) ;
targets.main-target-alternative
[ new deb-target $(name) : $(project)
: $(name:S=.dir)
: [ targets.main-target-requirements $(requirements) : $(project) ]
: [ targets.main-target-default-build $(default-build) : $(project) ]
: [ targets.main-target-usage-requirements $(usage-requirements) : $(project) ] ] ;
}
IMPORT $(__name__) : debian : : debian ;