source: XSL/optimize.xsl@ e2dfa2c

experimental
Last change on this file since e2dfa2c was e2dfa2c, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Migrated optimizations support to XSL-based code.

  • Property mode set to 100644
File size: 14.6 KB
Line 
1<?xml version="1.0"?>
2
3<!-- $Id$ -->
4
5<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
6 version="1.0">
7
8<!-- ####################### PARAMETERS ################################### -->
9
10 <!-- ###### MAKEFLAGS ###### -->
11
12 <!-- Should MAKEFLAGS be set? y = yes, n = no -->
13 <xsl:param name="set_makeflags">y</xsl:param>
14
15
16 <!-- Jobs control level. Left it empty for no jobs control -->
17 <xsl:param name="jobs">-j3</xsl:param>
18
19
20 <!-- Jobs control black-listed packages. One in each line.
21 NOTE: This and other similar parameters uses the PKG_PHASE value -->
22 <xsl:param name="no_jobs">
23 keep_this_line
24 autoconf
25 dejagnu
26 gettext
27 groff
28 man-db
29 keep_this_line
30 </xsl:param>
31
32
33 <!-- Additional make flags. -->
34 <xsl:param name="makeflags"></xsl:param>
35
36
37 <!-- Additional make flags black-listed packages. One in each line. -->
38 <xsl:param name="no_mkflags">
39 keep_this_line
40 keep_this_line
41 </xsl:param>
42
43
44 <!-- ############################ -->
45
46 <!-- ###### COMPILER FLAGS ###### -->
47
48 <!-- Should compiler envars be set? y = yes, n = no -->
49 <xsl:param name="set_buildflags">y</xsl:param>
50
51
52 <!-- Compiler optimizations black-listed packages. One in each line. -->
53 <xsl:param name="no_buildflags">
54 keep_this_line
55 binutils
56 binutils-pass1
57 binutils-pass2
58 gcc
59 gcc-pass1
60 gcc-pass2
61 glibc
62 grub
63 keep_this_line
64 </xsl:param>
65
66
67 <!-- Default envars setting. Left empty to not set a variable. -->
68
69 <!-- Default CFLAGS -->
70 <xsl:param name="cflags">-O3 -pipe</xsl:param>
71
72
73 <!-- Default CXXFLAGS -->
74 <xsl:param name="cxxflags">$CFLAGS</xsl:param>
75
76
77 <!-- Default OTHER_CFLAGS -->
78 <xsl:param name="other_cflags">$CFLAGS</xsl:param>
79
80
81 <!-- Default OTHER_CXXFLAGS -->
82 <xsl:param name="other_cxxflags">$CXXFLAGS</xsl:param>
83
84
85 <!-- Default LDFLAGS -->
86 <xsl:param name="ldflags"></xsl:param>
87
88
89 <!-- Default OTHER_LDFLAGS -->
90 <xsl:param name="other_ldflags"></xsl:param>
91
92 <!-- -->
93
94 <!-- By-package additional settings. A pair "package value" on each line.
95 The values set here will be added to the ones set above -->
96
97 <!-- Extra CFLAGS -->
98 <xsl:param name="extra_cflags">
99 zlib -fPIC
100 </xsl:param>
101
102
103 <!-- Extra CXXFLAGS -->
104 <xsl:param name="extra_cxxflags">
105 </xsl:param>
106
107
108 <!-- Extra OTHER_CFLAGS -->
109 <xsl:param name="extra_other_cflags">
110 </xsl:param>
111
112
113 <!-- Extra OTHER_CXXFLAGS -->
114 <xsl:param name="extra_other_cxxflags">
115 </xsl:param>
116
117
118 <!-- Extra LDFLAGS -->
119 <xsl:param name="extra_ldflags">
120 </xsl:param>
121
122
123 <!-- Extra OTHER_LDFLAGS -->
124 <xsl:param name="extra_other_ldflags">
125 </xsl:param>
126
127 <!-- -->
128
129 <!-- By-package settings. A pair "package value" on each line.
130 The values set here will override the ones set above -->
131
132 <!-- Extra CFLAGS -->
133 <xsl:param name="override_cflags">
134 </xsl:param>
135
136
137 <!-- Extra CXXFLAGS -->
138 <xsl:param name="override_cxxflags">
139 </xsl:param>
140
141
142 <!-- Extra OTHER_CFLAGS -->
143 <xsl:param name="override_other_cflags">
144 </xsl:param>
145
146
147 <!-- Extra OTHER_CXXFLAGS -->
148 <xsl:param name="override_other_cxxflags">
149 </xsl:param>
150
151
152 <!-- Extra LDFLAGS -->
153 <xsl:param name="override_ldflags">
154 </xsl:param>
155
156
157 <!-- Extra OTHER_LDFLAGS -->
158 <xsl:param name="override_other_ldflags">
159 </xsl:param>
160
161
162<!-- ######################################################################## -->
163
164<!-- ########################### NAMED TEMPLATES ########################### -->
165
166 <!-- Master optimizations template -->
167 <xsl:template name="optimize">
168 <xsl:param name="package" select="foo"/>
169 <xsl:text>&#xA;&#xA;</xsl:text>
170 <xsl:if test="$set_makeflags = 'y'">
171 <xsl:call-template name="makeflags">
172 <xsl:with-param name="package" select="$package"/>
173 </xsl:call-template>
174 </xsl:if>
175 <xsl:if test="$set_buildflags = 'y' and
176 not(contains(normalize-space($no_buildflags),concat(' ',$package,' ')))">
177 <xsl:call-template name="buildflags">
178 <xsl:with-param name="package" select="$package"/>
179 </xsl:call-template>
180 </xsl:if>
181 </xsl:template>
182
183
184 <!-- MAKEFLAGS template -->
185 <xsl:template name="makeflags">
186 <xsl:param name="package" select="foo"/>
187 <!-- Test if jobs control must be set -->
188 <xsl:variable name="set_jobs">
189 <xsl:if test="$jobs != '' and
190 not(contains(normalize-space($no_jobs),concat(' ',$package,' ')))">1</xsl:if>
191 </xsl:variable>
192 <!-- Test if additional make flags must be set -->
193 <xsl:variable name="add_mkflags">
194 <xsl:if test="$makeflags != '' and
195 not(contains(normalize-space($no_mkflags),concat(' ',$package,' ')))">1</xsl:if>
196 </xsl:variable>
197 <!-- Write the envar -->
198 <xsl:if test="$set_jobs = '1' or $add_mkflags = '1'">
199 <xsl:text>MAKEFLAGS="</xsl:text>
200 <!-- Write jobs control value -->
201 <xsl:if test="$set_jobs = '1'">
202 <xsl:value-of select="$jobs"/>
203 </xsl:if>
204 <!-- If both values will be written, be sure that are space separated -->
205 <xsl:if test="$set_jobs = '1' and $add_mkflags = '1'">
206 <xsl:text> </xsl:text>
207 </xsl:if>
208 <!-- Write additional make flags value -->
209 <xsl:if test="$add_mkflags = '1'">
210 <xsl:value-of select="$makeflags"/>
211 </xsl:if>
212 <xsl:text>"&#xA;</xsl:text>
213 </xsl:if>
214 </xsl:template>
215
216
217 <!-- Master compiler flags template -->
218 <xsl:template name="buildflags">
219 <xsl:param name="package" select="foo"/>
220 <xsl:if test="$cflags != ''">
221 <xsl:call-template name="cflags">
222 <xsl:with-param name="package" select="$package"/>
223 </xsl:call-template>
224 </xsl:if>
225 <xsl:if test="$cxxflags != ''">
226 <xsl:call-template name="cxxflags">
227 <xsl:with-param name="package" select="$package"/>
228 </xsl:call-template>
229 </xsl:if>
230 <xsl:if test="$other_cflags != ''">
231 <xsl:call-template name="other_cflags">
232 <xsl:with-param name="package" select="$package"/>
233 </xsl:call-template>
234 </xsl:if>
235 <xsl:if test="$other_cxxflags != ''">
236 <xsl:call-template name="other_cxxflags">
237 <xsl:with-param name="package" select="$package"/>
238 </xsl:call-template>
239 </xsl:if>
240 <xsl:if test="$ldflags != ''">
241 <xsl:call-template name="ldflags">
242 <xsl:with-param name="package" select="$package"/>
243 </xsl:call-template>
244 </xsl:if>
245 <xsl:if test="$other_ldflags != ''">
246 <xsl:call-template name="other_ldflags">
247 <xsl:with-param name="package" select="$package"/>
248 </xsl:call-template>
249 </xsl:if>
250 </xsl:template>
251
252
253 <!-- CFLAGS template -->
254 <xsl:template name="cflags">
255 <xsl:param name="package" select="foo"/>
256 <!-- Find the override value, if any -->
257 <xsl:variable name="override">
258 <xsl:call-template name="lookup.key">
259 <xsl:with-param name="key" select="$package"/>
260 <xsl:with-param name="table" select="normalize-space($override_cflags)"/>
261 </xsl:call-template>
262 </xsl:variable>
263 <!-- Find the extra settings, if any -->
264 <xsl:variable name="extra">
265 <xsl:call-template name="lookup.key">
266 <xsl:with-param name="key" select="$package"/>
267 <xsl:with-param name="table" select="normalize-space($extra_cflags)"/>
268 </xsl:call-template>
269 </xsl:variable>
270 <!-- Writte the envar -->
271 <xsl:text>CFLAGS="</xsl:text>
272 <xsl:choose>
273 <xsl:when test="$override != ''">
274 <xsl:value-of select="$override"/>
275 </xsl:when>
276 <xsl:otherwise>
277 <xsl:value-of select="$cflags"/>
278 <xsl:if test="$extra != ''">
279 <xsl:value-of select="concat(' ',$extra)"/>
280 </xsl:if>
281 </xsl:otherwise>
282 </xsl:choose>
283 <xsl:text>"&#xA;</xsl:text>
284 </xsl:template>
285
286
287 <!-- CXXFLAGS template -->
288 <xsl:template name="cxxflags">
289 <xsl:param name="package" select="foo"/>
290 <!-- Find the override value, if any -->
291 <xsl:variable name="override">
292 <xsl:call-template name="lookup.key">
293 <xsl:with-param name="key" select="$package"/>
294 <xsl:with-param name="table" select="normalize-space($override_cxxflags)"/>
295 </xsl:call-template>
296 </xsl:variable>
297 <!-- Find the extra settings, if any -->
298 <xsl:variable name="extra">
299 <xsl:call-template name="lookup.key">
300 <xsl:with-param name="key" select="$package"/>
301 <xsl:with-param name="table" select="normalize-space($extra_cxxflags)"/>
302 </xsl:call-template>
303 </xsl:variable>
304 <!-- Writte the envar -->
305 <xsl:text>CXXFLAGS="</xsl:text>
306 <xsl:choose>
307 <xsl:when test="$override != ''">
308 <xsl:value-of select="$override"/>
309 </xsl:when>
310 <xsl:otherwise>
311 <xsl:value-of select="$cxxflags"/>
312 <xsl:if test="$extra != ''">
313 <xsl:value-of select="concat(' ',$extra)"/>
314 </xsl:if>
315 </xsl:otherwise>
316 </xsl:choose>
317 <xsl:text>"&#xA;</xsl:text>
318 </xsl:template>
319
320
321 <!-- OTHER_CFLAGS template -->
322 <xsl:template name="other_cflags">
323 <xsl:param name="package" select="foo"/>
324 <!-- Find the override value, if any -->
325 <xsl:variable name="override">
326 <xsl:call-template name="lookup.key">
327 <xsl:with-param name="key" select="$package"/>
328 <xsl:with-param name="table" select="normalize-space($override_other_cflags)"/>
329 </xsl:call-template>
330 </xsl:variable>
331 <!-- Find the extra settings, if any -->
332 <xsl:variable name="extra">
333 <xsl:call-template name="lookup.key">
334 <xsl:with-param name="key" select="$package"/>
335 <xsl:with-param name="table" select="normalize-space($extra_other_cflags)"/>
336 </xsl:call-template>
337 </xsl:variable>
338 <!-- Writte the envar -->
339 <xsl:text>OTHER_CFLAGS="</xsl:text>
340 <xsl:choose>
341 <xsl:when test="$override != ''">
342 <xsl:value-of select="$override"/>
343 </xsl:when>
344 <xsl:otherwise>
345 <xsl:value-of select="$other_cflags"/>
346 <xsl:if test="$extra != ''">
347 <xsl:value-of select="concat(' ',$extra)"/>
348 </xsl:if>
349 </xsl:otherwise>
350 </xsl:choose>
351 <xsl:text>"&#xA;</xsl:text>
352 </xsl:template>
353
354
355 <!-- OTHER_CXXFLAGS template -->
356 <xsl:template name="other_cxxflags">
357 <xsl:param name="package" select="foo"/>
358 <!-- Find the override value, if any -->
359 <xsl:variable name="override">
360 <xsl:call-template name="lookup.key">
361 <xsl:with-param name="key" select="$package"/>
362 <xsl:with-param name="table" select="normalize-space($override_other_cxxflags)"/>
363 </xsl:call-template>
364 </xsl:variable>
365 <!-- Find the extra settings, if any -->
366 <xsl:variable name="extra">
367 <xsl:call-template name="lookup.key">
368 <xsl:with-param name="key" select="$package"/>
369 <xsl:with-param name="table" select="normalize-space($extra_other_cxxflags)"/>
370 </xsl:call-template>
371 </xsl:variable>
372 <!-- Writte the envar -->
373 <xsl:text>OTHER_CXXFLAGS="</xsl:text>
374 <xsl:choose>
375 <xsl:when test="$override != ''">
376 <xsl:value-of select="$override"/>
377 </xsl:when>
378 <xsl:otherwise>
379 <xsl:value-of select="$other_cxxflags"/>
380 <xsl:if test="$extra != ''">
381 <xsl:value-of select="concat(' ',$extra)"/>
382 </xsl:if>
383 </xsl:otherwise>
384 </xsl:choose>
385 <xsl:text>"&#xA;</xsl:text>
386 </xsl:template>
387
388
389 <!-- LDFLAGS template -->
390 <xsl:template name="ldflags">
391 <xsl:param name="package" select="foo"/>
392 <!-- Find the override value, if any -->
393 <xsl:variable name="override">
394 <xsl:call-template name="lookup.key">
395 <xsl:with-param name="key" select="$package"/>
396 <xsl:with-param name="table" select="normalize-space($override_ldflags)"/>
397 </xsl:call-template>
398 </xsl:variable>
399 <!-- Find the extra settings, if any -->
400 <xsl:variable name="extra">
401 <xsl:call-template name="lookup.key">
402 <xsl:with-param name="key" select="$package"/>
403 <xsl:with-param name="table" select="normalize-space($extra_ldflags)"/>
404 </xsl:call-template>
405 </xsl:variable>
406 <!-- Writte the envar -->
407 <xsl:text>LDFLAGS="</xsl:text>
408 <xsl:choose>
409 <xsl:when test="$override != ''">
410 <xsl:value-of select="$override"/>
411 </xsl:when>
412 <xsl:otherwise>
413 <xsl:value-of select="$ldflags"/>
414 <xsl:if test="$extra != ''">
415 <xsl:value-of select="concat(' ',$extra)"/>
416 </xsl:if>
417 </xsl:otherwise>
418 </xsl:choose>
419 <xsl:text>"&#xA;</xsl:text>
420 </xsl:template>
421
422
423 <!-- OTHER_LDFLAGS template -->
424 <xsl:template name="other_ldflags">
425 <xsl:param name="package" select="foo"/>
426 <!-- Find the override value, if any -->
427 <xsl:variable name="override">
428 <xsl:call-template name="lookup.key">
429 <xsl:with-param name="key" select="$package"/>
430 <xsl:with-param name="table" select="normalize-space($override_other_ldflags)"/>
431 </xsl:call-template>
432 </xsl:variable>
433 <!-- Find the extra settings, if any -->
434 <xsl:variable name="extra">
435 <xsl:call-template name="lookup.key">
436 <xsl:with-param name="key" select="$package"/>
437 <xsl:with-param name="table" select="normalize-space($extra_other_ldflags)"/>
438 </xsl:call-template>
439 </xsl:variable>
440 <!-- Writte the envar -->
441 <xsl:text>OTHER_LDFLAGS="</xsl:text>
442 <xsl:choose>
443 <xsl:when test="$override != ''">
444 <xsl:value-of select="$override"/>
445 </xsl:when>
446 <xsl:otherwise>
447 <xsl:value-of select="$other_ldflags"/>
448 <xsl:if test="$extra != ''">
449 <xsl:value-of select="concat(' ',$extra)"/>
450 </xsl:if>
451 </xsl:otherwise>
452 </xsl:choose>
453 <xsl:text>"&#xA;</xsl:text>
454 </xsl:template>
455
456
457 <!-- Parses a table-like param finding a pair key-value.
458 Copied from DocBook-XSL -->
459 <xsl:template name="lookup.key">
460 <xsl:param name="key" select="''"/>
461 <xsl:param name="table" select="''"/>
462 <xsl:if test="contains($table, ' ')">
463 <xsl:choose>
464 <xsl:when test="substring-before($table, ' ') = $key">
465 <xsl:variable name="rest" select="substring-after($table, ' ')"/>
466 <xsl:choose>
467 <xsl:when test="contains($rest, ' ')">
468 <xsl:value-of select="substring-before($rest, ' ')"/>
469 </xsl:when>
470 <xsl:otherwise>
471 <xsl:value-of select="$rest"/>
472 </xsl:otherwise>
473 </xsl:choose>
474 </xsl:when>
475 <xsl:otherwise>
476 <xsl:call-template name="lookup.key">
477 <xsl:with-param name="key" select="$key"/>
478 <xsl:with-param name="table" select="substring-after(substring-after($table,' '), ' ')"/>
479 </xsl:call-template>
480 </xsl:otherwise>
481 </xsl:choose>
482 </xsl:if>
483 </xsl:template>
484
485</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.