Ticket #3798: Jamfile

File Jamfile, 4.0 KB (added by bonefish, 12 years ago)

Test Jamfile with rules for new build features syntax.

Line 
1SubDir HAIKU_TOP ;
2
3
4rule FSplitString string : delimiterChar
5{
6 local result ;
7
8 while $(string) {
9 local split = [ Match $(delimiterChar)*([^$(delimiterChar)]+)(.*)
10 : $(string) ] ;
11 result += $(split[1]) ;
12 string = $(split[2-]) ;
13 }
14
15 return $(result) ;
16}
17
18
19HAIKU_ARCH = x86 ;
20HAIKU_BUILD_FEATURES = ;
21
22rule FMatchesSet elements : set
23{
24 local hasPositive ;
25 local hasNegative ;
26 local positiveMatch ;
27 local element ;
28 for element in $(elements) {
29 switch $(element) {
30 case !* :
31 {
32 hasNegative = 1 ;
33 element = [ Match "!(.*)" : $(element) ] ;
34 if $(element) in $(set) {
35 return ;
36 }
37 }
38 case * :
39 {
40 hasPositive = 1 ;
41 if $(element) in $(set) {
42 positiveMatch = 1 ;
43 }
44 }
45 }
46 }
47
48 if $(hasPositive) {
49 return $(positiveMatch) ;
50 }
51 return $(hasNegative) ;
52}
53
54rule FIsBuildFeatureEnabled feature
55{
56 if $(feature) in $(HAIKU_BUILD_FEATURES) {
57 return 1 ;
58 }
59
60 return ;
61}
62
63rule FMatchesBuildFeatures specification
64{
65 local splitSpecification ;
66 local element ;
67 for element in $(specification) {
68 splitSpecification += [ FSplitString $(element) : "," ] ;
69 }
70 return [ FMatchesSet $(splitSpecification) : $(HAIKU_BUILD_FEATURES) ] ;
71}
72
73rule FFilterByBuildFeatures list
74{
75 local filteredList ;
76
77 # Since we must look ahead one element to be able to decide whether an
78 # element is a regular list element or a features specification for a
79 # subsequent "@{". Hence we always process an element other than "@{" and
80 # "}@" in the next iteration. We append a dummy element to the list so we
81 # don't need special handling for the last element.
82 local evaluationStack = 1 ;
83 local previousElement ;
84 local element ;
85 for element in $(list) dummy {
86 local stackTop = $(evaluationStack[1]) ;
87 local processElement = $(previousElement) ;
88 switch $(element) {
89 case }@ :
90 {
91 # Pop the topmost specificaton off the stack.
92 evaluationStack = $(evaluationStack[2-]) ;
93 if ! $(evaluationStack) {
94 Exit "FFilterByBuildFeatures: Unbalanced @( in: " $(list) ;
95 }
96
97 processElement = $(previousElement) ;
98 previousElement = ;
99 }
100 case @{ :
101 {
102 if ! $(previousElement) {
103 Exit "FFilterByBuildFeatures: No feature specification"
104 "after )@ in: " $(list) ;
105 }
106
107 if $(evaluationStack[1]) = 1
108 && [ FMatchesBuildFeatures $(previousElement) ] {
109 evaluationStack = 1 $(evaluationStack) ;
110 } else {
111 evaluationStack = 0 $(evaluationStack) ;
112 }
113
114 processElement = ;
115 previousElement = ;
116 }
117 case * :
118 {
119 processElement = $(previousElement) ;
120 previousElement = $(element) ;
121 }
122 }
123
124 if $(processElement) && $(stackTop) = 1 {
125 local splitElement = [ Match "(.*)@([^@]*)" : $(processElement) ] ;
126 if $(splitElement) {
127 if [ FMatchesBuildFeatures $(splitElement[2]) ] {
128 filteredList += $(splitElement[1]) ;
129 }
130 } else {
131 filteredList += $(processElement) ;
132 }
133 }
134 }
135
136 if $(evaluationStack[2-]) {
137 Exit "FFilterByBuildFeatures: Unbalanced )@ in: " $(list) ;
138 }
139
140 return $(filteredList) ;
141}
142
143rule EnableBuildFeatures features : architectures
144{
145 if ! $(architectures)
146 || [ FMatchesSet $(architectures) : $(HAIKU_BUILD_FEATURES) ] {
147 local feature ;
148 for feature in $(features) {
149 HAIKU_BUILD_FEATURES += $(feature) ;
150 HAIKU_$(feature:U)_ENABLED = 1 ;
151 }
152 }
153}
154
155EnableBuildFeatures $(HAIKU_ARCH) ;
156
157EnableBuildFeatures opengl ffmpeg freebsd_network : x86 ;
158
159Echo HAIKU_BUILD_FEATURES: $(HAIKU_BUILD_FEATURES) ;
160
161local testSpecifications =
162 x86
163 !x86
164 ppc
165 !ppc
166 !ppc,!arm
167 !ppc,!x86
168 opengl
169 !ffmpeg,x86
170 freebsd_network,!ppc,!arm
171;
172
173local testSpecification ;
174for testSpecification in $(testSpecifications) {
175 Echo $(testSpecification) "->"
176 [ FMatchesBuildFeatures $(testSpecification) ] ;
177}
178
179local testList1 =
180 foo
181 bar@ppc
182 foobar@x86
183;
184
185local testList2 =
186 foo
187 opengl @(
188 bar@ppc
189 foobar@x86
190 )@
191;
192
193local testList3 =
194 a
195 b
196
197 opengl @{
198 c
199 !ppc @{
200 d@x86
201 e
202 }@ #
203 f
204 }@ # opengl
205
206 arm @{
207 g
208 h
209 }@ # arm
210
211 i
212 j
213;
214
215local i ;
216for i in 1 2 3 {
217 local testList = $(testList$(i)) ;
218 Echo testList$(i): $(testList) ;
219 Echo " ->" [ FFilterByBuildFeatures $(testList) ] ;
220}