]> git.proxmox.com Git - grub2.git/blame - gentpl.py
Make qemu-mips compile again. Still no grub-mkimage support
[grub2.git] / gentpl.py
CommitLineData
8c411768
BC
1#! /usr/bin/python
2
3#
4# This is the python script used to generate Makefile.tpl
5#
6
7GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
062cdbc1 8 "i386_multiboot", "i386_ieee1275", "x86_64_efi",
f440c33f 9 "mips_yeeloong", "mips_qemu_mips", "sparc64_ieee1275",
8c411768
BC
10 "powerpc_ieee1275" ]
11
12GROUPS = {}
eefe8abd
VS
13
14GROUPS["common"] = GRUB_PLATFORMS[:]
15
16# Groups based on CPU
8427685f
BC
17GROUPS["i386"] = [ "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275" ]
18GROUPS["x86_64"] = [ "x86_64_efi" ]
19GROUPS["x86"] = GROUPS["i386"] + GROUPS["x86_64"]
f440c33f 20GROUPS["mips"] = [ "mips_yeeloong", "mips_qemu_mips" ]
8427685f
BC
21GROUPS["sparc64"] = [ "sparc64_ieee1275" ]
22GROUPS["powerpc"] = [ "powerpc_ieee1275" ]
23
eefe8abd
VS
24# Groups based on firmware
25GROUPS["x86_efi"] = [ "i386_efi", "x86_64_efi" ]
8427685f 26GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ]
8427685f 27
eefe8abd
VS
28# emu is a special case so many core functionality isn't needed on this platform
29GROUPS["noemu"] = GRUB_PLATFORMS[:]; GROUPS["noemu"].remove("emu")
30
31# Groups based on hardware features
f440c33f
VS
32GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_yeeloong", "mips_qemu_mips" ]; GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi")
33GROUPS["pci"] = GROUPS["x86"] + ["mips_yeeloong"]
eefe8abd 34GROUPS["usb"] = GROUPS["pci"]
8427685f 35
eefe8abd
VS
36# If gfxterm is main output console integrate it into kernel
37GROUPS["videoinkernel"] = ["mips_yeeloong"]
38GROUPS["videomodules"] = GRUB_PLATFORMS[:];
39for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i)
8427685f 40
ee74fa48
VS
41# Similar for terminfo
42GROUPS["terminfoinkernel"] = ["mips_yeeloong"] + GROUPS["ieee1275"];
43GROUPS["terminfomodule"] = GRUB_PLATFORMS[:];
44for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i)
45
eefe8abd
VS
46# Miscelaneous groups schedulded to disappear in future
47GROUPS["nosparc64"] = GRUB_PLATFORMS[:]; GROUPS["nosparc64"].remove("sparc64_ieee1275")
48GROUPS["i386_coreboot_multiboot_qemu"] = ["i386_coreboot", "i386_multiboot", "i386_qemu"]
49GROUPS["nopc"] = GRUB_PLATFORMS[:]; GROUPS["nopc"].remove("i386_pc")
8c411768
BC
50
51#
52# Create platform => groups reverse map, where groups covering that
53# platform are ordered by their sizes
54#
55RMAP = {}
56for platform in GRUB_PLATFORMS:
57 # initialize with platform itself as a group
58 RMAP[platform] = [ platform ]
59
60 for k in GROUPS.keys():
61 v = GROUPS[k]
62 # skip groups that don't cover this platform
63 if platform not in v: continue
64
65 bigger = []
66 smaller = []
67 # partition currently known groups based on their size
68 for group in RMAP[platform]:
69 if group in GRUB_PLATFORMS: smaller.append(group)
70 elif len(GROUPS[group]) < len(v): smaller.append(group)
71 else: bigger.append(group)
72 # insert in the middle
73 RMAP[platform] = smaller + [ k ] + bigger
74
75#
76# Global variables
77#
e1fd1939 78GVARS = set()
8c411768
BC
79
80def gvar_add(var, value):
e1fd1939 81 GVARS.add(var)
8c411768
BC
82 return var + " += " + value + "\n"
83
84def global_variable_initializers():
85 r = ""
e1fd1939 86 for var in sorted(GVARS):
8c411768
BC
87 r += var + " ?= \n"
88 return r
89
90#
91# Per PROGRAM/SCRIPT variables
92#
93
e1fd1939
CW
94def vars_init(*var_list):
95 r = "[+ IF (if (not (assoc-ref seen-vars (get \".name\"))) \"seen\") +]"
96 r += "[+ (out-suspend \"v\") +]"
97 for var in var_list:
98 r += var + " = \n"
99 r += "[+ (out-resume \"v\") +]"
100 r += "[+ (set! seen-vars (assoc-set! seen-vars (get \".name\") 0)) +]"
101 r += "[+ ENDIF +]"
102 return first_time(r)
103
8c411768
BC
104def var_set(var, value):
105 return var + " = " + value + "\n"
106
107def var_add(var, value):
108 return var + " += " + value + "\n"
109
110#
111# Autogen constructs
112#
113
9e860d54 114def set_canonical_name_suffix(suffix): return "[+ % name `export cname=$(echo %s" + suffix + " | sed -e 's/[^0-9A-Za-z@_]/_/g')` +]"
911bd640 115def cname(): return "[+ % name `echo $cname` +]"
8c411768 116
911bd640
BC
117def rule(target, source, cmd):
118 if cmd[0] == "\n":
119 return "\n" + target + ": " + source + cmd.replace("\n", "\n\t") + "\n"
120 else:
121 return "\n" + target + ": " + source + "\n\t" + cmd.replace("\n", "\n\t") + "\n"
8c411768 122
d9b78bce
BC
123#
124# Template for keys with platform names as values, for example:
125#
126# kernel = {
127# nostrip = emu;
f6023b61 128# ...
d9b78bce
BC
129# }
130#
131def if_platform_tagged(platform, tag, snippet_if, snippet_else=None):
911bd640
BC
132 r = ""
133 r += "[+ IF " + tag + " defined +]"
134 r += "[+ FOR " + tag + " +][+ CASE " + tag + " +]"
8c411768 135 for group in RMAP[platform]:
d9b78bce
BC
136 r += "[+ = \"" + group + "\" +]" + snippet_if
137
02a6605e 138 if snippet_else != None: r += "[+ * +]" + snippet_else
911bd640 139 r += "[+ ESAC +][+ ENDFOR +]"
8c411768 140
d9b78bce 141 if snippet_else == None:
8c411768 142 r += "[+ ENDIF +]"
911bd640 143 return r
8c411768 144
d9b78bce 145 r += "[+ ELSE +]" + snippet_else + "[+ ENDIF +]"
8c411768
BC
146 return r
147
d9b78bce 148#
8427685f
BC
149# Template for tagged values
150#
151# module = {
152# extra_dist = ...
153# extra_dist = ...
154# ...
155# };
156#
157def foreach_value(tag, closure):
158 return "[+ FOR " + tag + " +]" + closure("[+ ." + tag + " +]") + "[+ ENDFOR +]"
159
160#
161# Template for handling best matched values for a platform, for example:
d9b78bce
BC
162#
163# module = {
164# cflags = '-Wall';
165# emu_cflags = '-Wall -DGRUB_EMU=1';
f6023b61 166# ...
d9b78bce
BC
167# }
168#
8427685f 169def foreach_platform_specific_value(platform, suffix, nonetag, closure):
8c411768 170 r = ""
911bd640 171 for group in RMAP[platform]:
d9b78bce 172 gtag = group + suffix
911bd640
BC
173
174 if group == RMAP[platform][0]:
175 r += "[+ IF " + gtag + " +]"
176 else:
177 r += "[+ ELIF " + gtag + " +]"
178
d9b78bce 179 r += "[+ FOR " + gtag + " +]" + closure("[+ ." + gtag + " +]") + "[+ ENDFOR +]"
8427685f
BC
180 r += "[+ ELSE +][+ FOR " + nonetag + " +]" + closure("[+ ." + nonetag + " +]") + "[+ ENDFOR +][+ ENDIF +]"
181 return r
182
183#
184# Template for handling values from sum of all groups for a platform,
185# for example:
186#
187# module = {
188# common = kern/misc.c;
189# emu = kern/emu/misc.c;
190# ...
191# }
192#
193def foreach_platform_value (platform, suffix, closure):
194 r = ""
195 for group in RMAP[platform]:
196 gtag = group + suffix
197
198 r += "[+ IF " + gtag + " +]"
199 r += "[+ FOR " + gtag + " +]" + closure("[+ ." + gtag + " +]") + "[+ ENDFOR +]"
200 r += "[+ ENDIF +]"
8c411768
BC
201 return r
202
8427685f
BC
203#
204# Template for gaurding with platform specific "enable" keys, for example:
205#
206# module = {
207# name = pci;
208# noemu = bus/pci.c;
209# emu = bus/emu/pci.c;
210# emu = commands/lspci.c;
211#
212# enable = emu;
213# enable = i386_pc;
214# enable = x86_efi;
215# enable = i386_ieee1275;
216# enable = i386_coreboot;
217# };
218#
219def foreach_enabled_platform(closure):
911bd640
BC
220 r = "[+ IF - enable undefined +]"
221 for platform in GRUB_PLATFORMS:
222 r += "\nif COND_" + platform + "\n" + closure(platform) + "endif\n"
223 r += "[+ ELSE +]"
224 for platform in GRUB_PLATFORMS:
225 x = "\nif COND_" + platform + "\n" + closure(platform) + "endif\n"
d9b78bce 226 r += if_platform_tagged(platform, "enable", x)
911bd640 227 r += "[+ ENDIF +]"
d9b78bce
BC
228 return r
229
8427685f
BC
230#
231# Template for gaurding with platform specific automake conditionals,
232# for example:
233#
234# module = {
235# name = usb;
236# common = bus/usb/usb.c;
237# noemu = bus/usb/usbtrans.c;
238# noemu = bus/usb/usbhub.c;
239# enable = emu;
240# enable = i386;
241# enable = mips_yeeloong;
242# emu_condition = COND_GRUB_EMU_USB;
243# };
244#
d9b78bce 245def under_platform_specific_conditionals(platform, snippet):
8427685f 246 r = foreach_platform_specific_value(platform, "_condition", "condition", lambda cond: "if " + cond + "\n")
d9b78bce 247 r += snippet
8427685f 248 r += foreach_platform_specific_value(platform, "_condition", "condition", lambda cond: "endif " + cond + "\n")
d9b78bce
BC
249 return r
250
8427685f
BC
251def platform_specific_values(platform, suffix, nonetag):
252 return foreach_platform_specific_value(platform, suffix, nonetag,
253 lambda value: value + " ")
911bd640 254
8427685f
BC
255def platform_values(platform, suffix):
256 return foreach_platform_value(platform, suffix, lambda value: value + " ")
911bd640 257
8427685f
BC
258def extra_dist():
259 return foreach_value("extra_dist", lambda value: value + " ")
911bd640 260
8427685f
BC
261def platform_sources(p): return platform_values(p, "")
262def platform_nodist_sources(p): return platform_values(p, "_nodist")
263def platform_dependencies(p): return platform_values(p, "dependencies", "_dependencies")
264
265def platform_startup(p): return platform_specific_values(p, "_startup", "startup")
266def platform_ldadd(p): return platform_specific_values(p, "_ldadd", "ldadd")
267def platform_cflags(p): return platform_specific_values(p, "_cflags", "cflags")
268def platform_ldflags(p): return platform_specific_values(p, "_ldflags", "ldflags")
269def platform_cppflags(p): return platform_specific_values(p, "_cppflags", "cppflags")
270def platform_ccasflags(p): return platform_specific_values(p, "_ccasflags", "ccasflags")
271def platform_stripflags(p): return platform_specific_values(p, "_stripflags", "stripflags")
272def platform_objcopyflags(p): return platform_specific_values(p, "_objcopyflags", "objcopyflags")
8c411768 273
e1fd1939
CW
274#
275# Emit snippet only the first time through for the current name.
276#
277def first_time(snippet):
278 r = "[+ IF (if (not (assoc-ref seen-target (get \".name\"))) \"seen\") +]"
279 r += snippet
280 r += "[+ ENDIF +]"
281 return r
282
8c411768 283def module(platform):
911bd640
BC
284 r = set_canonical_name_suffix(".module")
285
286 r += gvar_add("noinst_PROGRAMS", "[+ name +].module")
e235a228 287 r += gvar_add("MODULE_FILES", "[+ name +].module$(EXEEXT)")
8c411768 288
911bd640 289 r += var_set(cname() + "_SOURCES", platform_sources(platform) + " ## platform sources")
911bd640 290 r += var_set("nodist_" + cname() + "_SOURCES", platform_nodist_sources(platform) + " ## platform nodist sources")
911bd640
BC
291 r += var_set(cname() + "_LDADD", platform_ldadd(platform))
292 r += var_set(cname() + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_MODULE) " + platform_cflags(platform))
293 r += var_set(cname() + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_MODULE) " + platform_ldflags(platform))
294 r += var_set(cname() + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_MODULE) " + platform_cppflags(platform))
295 r += var_set(cname() + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_MODULE) " + platform_ccasflags(platform))
02c9030a 296 # r += var_set(cname() + "_DEPENDENCIES", platform_dependencies(platform) + " " + platform_ldadd(platform))
8c411768 297
8427685f 298 r += gvar_add("EXTRA_DIST", extra_dist())
911bd640
BC
299 r += gvar_add("BUILT_SOURCES", "$(nodist_" + cname() + "_SOURCES)")
300 r += gvar_add("CLEANFILES", "$(nodist_" + cname() + "_SOURCES)")
8c411768 301
8c411768 302 r += gvar_add("MOD_FILES", "[+ name +].mod")
6568636e
BC
303 r += gvar_add("MARKER_FILES", "[+ name +].marker")
304 r += gvar_add("CLEANFILES", "[+ name +].marker")
8c411768 305 r += """
6568636e
BC
306[+ name +].marker: $(""" + cname() + """_SOURCES) $(nodist_""" + cname() + """_SOURCES)
307 $(TARGET_CPP) -DGRUB_LST_GENERATOR $(CPPFLAGS_MARKER) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(""" + cname() + """_CPPFLAGS) $(CPPFLAGS) $^ > $@.new || (rm -f $@; exit 1)
308 grep 'MARKER' $@.new > $@; rm -f $@.new
8c411768
BC
309"""
310 return r
311
8c411768 312def kernel(platform):
911bd640
BC
313 r = set_canonical_name_suffix(".exec")
314 r += gvar_add("noinst_PROGRAMS", "[+ name +].exec")
8427685f
BC
315 r += var_set(cname() + "_SOURCES", platform_startup(platform))
316 r += var_add(cname() + "_SOURCES", platform_sources(platform))
911bd640 317 r += var_set("nodist_" + cname() + "_SOURCES", platform_nodist_sources(platform) + " ## platform nodist sources")
911bd640
BC
318 r += var_set(cname() + "_LDADD", platform_ldadd(platform))
319 r += var_set(cname() + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_KERNEL) " + platform_cflags(platform))
320 r += var_set(cname() + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_KERNEL) " + platform_ldflags(platform))
321 r += var_set(cname() + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) " + platform_cppflags(platform))
322 r += var_set(cname() + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_KERNEL) " + platform_ccasflags(platform))
323 r += var_set(cname() + "_STRIPFLAGS", "$(AM_STRIPFLAGS) $(STRIPFLAGS_KERNEL) " + platform_stripflags(platform))
02c9030a 324 # r += var_set(cname() + "_DEPENDENCIES", platform_dependencies(platform) + " " + platform_ldadd(platform))
8c411768 325
8427685f 326 r += gvar_add("EXTRA_DIST", extra_dist())
911bd640
BC
327 r += gvar_add("BUILT_SOURCES", "$(nodist_" + cname() + "_SOURCES)")
328 r += gvar_add("CLEANFILES", "$(nodist_" + cname() + "_SOURCES)")
8c411768
BC
329
330 r += gvar_add("platform_DATA", "[+ name +].img")
911bd640
BC
331 r += gvar_add("CLEANFILES", "[+ name +].img")
332 r += rule("[+ name +].img", "[+ name +].exec$(EXEEXT)",
d9b78bce
BC
333 if_platform_tagged(platform, "nostrip", "cp $< $@",
334 "$(STRIP) $(" + cname() + "_STRIPFLAGS) -o $@ $<"))
8c411768
BC
335 return r
336
337def image(platform):
911bd640
BC
338 r = set_canonical_name_suffix(".image")
339 r += gvar_add("noinst_PROGRAMS", "[+ name +].image")
340 r += var_set(cname() + "_SOURCES", platform_sources(platform))
911bd640 341 r += var_set("nodist_" + cname() + "_SOURCES", platform_nodist_sources(platform) + "## platform nodist sources")
911bd640
BC
342 r += var_set(cname() + "_LDADD", platform_ldadd(platform))
343 r += var_set(cname() + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_IMAGE) " + platform_cflags(platform))
344 r += var_set(cname() + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_IMAGE) " + platform_ldflags(platform))
345 r += var_set(cname() + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_IMAGE) " + platform_cppflags(platform))
346 r += var_set(cname() + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_IMAGE) " + platform_ccasflags(platform))
d9b78bce 347 r += var_set(cname() + "_OBJCOPYFLAGS", "$(OBJCOPYFLAGS_IMAGE) " + platform_objcopyflags(platform))
02c9030a 348 # r += var_set(cname() + "_DEPENDENCIES", platform_dependencies(platform) + " " + platform_ldadd(platform))
8c411768 349
8427685f 350 r += gvar_add("EXTRA_DIST", extra_dist())
911bd640
BC
351 r += gvar_add("BUILT_SOURCES", "$(nodist_" + cname() + "_SOURCES)")
352 r += gvar_add("CLEANFILES", "$(nodist_" + cname() + "_SOURCES)")
8c411768
BC
353
354 r += gvar_add("platform_DATA", "[+ name +].img")
a60f6ee1 355 r += gvar_add("CLEANFILES", "[+ name +].img")
e235a228 356 r += rule("[+ name +].img", "[+ name +].image$(EXEEXT)", """
8c411768
BC
357if test x$(USE_APPLE_CC_FIXES) = xyes; then \
358 $(MACHO2IMG) $< $@; \
359else \
d9b78bce 360 $(OBJCOPY) $(""" + cname() + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn $< $@; \
8c411768
BC
361fi
362""")
363 return r
364
365def library(platform):
911bd640 366 r = set_canonical_name_suffix("")
8c411768 367
e1fd1939
CW
368 r += vars_init(cname() + "_SOURCES",
369 "nodist_" + cname() + "_SOURCES",
370 cname() + "_CFLAGS",
371 cname() + "_CPPFLAGS",
372 cname() + "_CCASFLAGS")
373 # cname() + "_DEPENDENCIES")
8c411768 374
e1fd1939
CW
375 r += first_time(gvar_add("noinst_LIBRARIES", "[+ name +]"))
376 r += var_add(cname() + "_SOURCES", platform_sources(platform))
377 r += var_add("nodist_" + cname() + "_SOURCES", platform_nodist_sources(platform))
378 r += var_add(cname() + "_CFLAGS", first_time("$(AM_CFLAGS) $(CFLAGS_LIBRARY) ") + platform_cflags(platform))
379 r += var_add(cname() + "_CPPFLAGS", first_time("$(AM_CPPFLAGS) $(CPPFLAGS_LIBRARY) ") + platform_cppflags(platform))
380 r += var_add(cname() + "_CCASFLAGS", first_time("$(AM_CCASFLAGS) $(CCASFLAGS_LIBRARY) ") + platform_ccasflags(platform))
381 # r += var_add(cname() + "_DEPENDENCIES", platform_dependencies(platform) + " " + platform_ldadd(platform))
382
383 r += gvar_add("EXTRA_DIST", extra_dist())
384 r += first_time(gvar_add("BUILT_SOURCES", "$(nodist_" + cname() + "_SOURCES)"))
385 r += first_time(gvar_add("CLEANFILES", "$(nodist_" + cname() + "_SOURCES)"))
8c411768
BC
386 return r
387
388def installdir(default="bin"):
389 return "[+ IF installdir +][+ installdir +][+ ELSE +]" + default + "[+ ENDIF +]"
390
391def manpage():
392 r = "if COND_MAN_PAGES\n"
2e33ae0d 393 r += gvar_add("man_MANS", "[+ name +].[+ mansection +]\n")
0a4fc180 394 r += rule("[+ name +].[+ mansection +]", "[+ name +]", """
8c411768 395chmod a+x [+ name +]
297f0c2b 396PATH=$(builddir):$$PATH $(HELP2MAN) --section=[+ mansection +] -i $(top_srcdir)/docs/man/[+ name +].h2m -o $@ [+ name +]
8c411768
BC
397""")
398 r += gvar_add("CLEANFILES", "[+ name +].[+ mansection +]")
399 r += "endif\n"
400 return r
401
402def program(platform, test=False):
911bd640
BC
403 r = set_canonical_name_suffix("")
404
405 r += "[+ IF testcase defined +]"
406 r += gvar_add("check_PROGRAMS", "[+ name +]")
407 r += gvar_add("TESTS", "[+ name +]")
408 r += "[+ ELSE +]"
e1fd1939 409 r += var_add(installdir() + "_PROGRAMS", "[+ name +]")
911bd640
BC
410 r += "[+ IF mansection +]" + manpage() + "[+ ENDIF +]"
411 r += "[+ ENDIF +]"
412
413 r += var_set(cname() + "_SOURCES", platform_sources(platform))
911bd640 414 r += var_set("nodist_" + cname() + "_SOURCES", platform_nodist_sources(platform))
911bd640
BC
415 r += var_set(cname() + "_LDADD", platform_ldadd(platform))
416 r += var_set(cname() + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_PROGRAM) " + platform_cflags(platform))
417 r += var_set(cname() + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_PROGRAM) " + platform_ldflags(platform))
418 r += var_set(cname() + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_PROGRAM) " + platform_cppflags(platform))
419 r += var_set(cname() + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_PROGRAM) " + platform_ccasflags(platform))
02c9030a 420 # r += var_set(cname() + "_DEPENDENCIES", platform_dependencies(platform) + " " + platform_ldadd(platform))
8c411768 421
8427685f 422 r += gvar_add("EXTRA_DIST", extra_dist())
911bd640
BC
423 r += gvar_add("BUILT_SOURCES", "$(nodist_" + cname() + "_SOURCES)")
424 r += gvar_add("CLEANFILES", "$(nodist_" + cname() + "_SOURCES)")
8c411768
BC
425 return r
426
8c411768 427def data(platform):
a60f6ee1 428 r = gvar_add("EXTRA_DIST", platform_sources(platform))
8427685f 429 r += gvar_add("EXTRA_DIST", extra_dist())
e1fd1939 430 r += var_add(installdir() + "_DATA", platform_sources(platform))
a60f6ee1 431 return r
8c411768 432
911bd640
BC
433def script(platform):
434 r = "[+ IF testcase defined +]"
435 r += gvar_add("check_SCRIPTS", "[+ name +]")
436 r += gvar_add ("TESTS", "[+ name +]")
437 r += "[+ ELSE +]"
e1fd1939 438 r += var_add(installdir() + "_SCRIPTS", "[+ name +]")
911bd640
BC
439 r += "[+ IF mansection +]" + manpage() + "[+ ENDIF +]"
440 r += "[+ ENDIF +]"
8c411768 441
0d4552fa
BC
442 r += rule("[+ name +]", platform_sources(platform) + " $(top_builddir)/config.status", """
443$(top_builddir)/config.status --file=-:$< | sed -e 's,@pkglib_DATA@,$(pkglib_DATA),g' > $@
8c411768
BC
444chmod a+x [+ name +]
445""")
446
447 r += gvar_add("CLEANFILES", "[+ name +]")
6556eba9 448 r += gvar_add("dist_noinst_DATA", platform_sources(platform))
8c411768
BC
449 return r
450
e1fd1939
CW
451def rules(target, closure):
452 # Create association lists for the benefit of first_time and vars_init.
453 r = "[+ (define seen-target '()) +]"
454 r += "[+ (define seen-vars '()) +]"
455 # Most output goes to a diversion. This allows us to emit variable
456 # initializations before everything else.
457 r += "[+ (out-push-new) +]"
458
459 r += "[+ FOR " + target + " +]"
460 r += foreach_enabled_platform(
461 lambda p: under_platform_specific_conditionals(p, closure(p)))
462 # Remember that we've seen this target.
463 r += "[+ (set! seen-target (assoc-set! seen-target (get \".name\") 0)) +]"
464 r += "[+ ENDFOR +]"
465 r += "[+ (out-pop #t) +]"
466 return r
467
8c411768 468def module_rules():
e1fd1939 469 return rules("module", module)
8c411768
BC
470
471def kernel_rules():
e1fd1939 472 return rules("kernel", kernel)
8c411768
BC
473
474def image_rules():
e1fd1939 475 return rules("image", image)
8c411768
BC
476
477def library_rules():
e1fd1939 478 return rules("library", library)
8c411768
BC
479
480def program_rules():
e1fd1939 481 return rules("program", program)
8c411768
BC
482
483def script_rules():
e1fd1939 484 return rules("script", script)
8c411768
BC
485
486def data_rules():
e1fd1939 487 return rules("data", data)
8c411768
BC
488
489print "[+ AutoGen5 template +]\n"
490a = module_rules()
491b = kernel_rules()
492c = image_rules()
493d = library_rules()
494e = program_rules()
495f = script_rules()
496g = data_rules()
8c411768
BC
497z = global_variable_initializers()
498
911bd640 499# print z # initializer for all vars
8c411768
BC
500print a
501print b
502print c
503print d
504print e
505print f
506print g