]>
git.proxmox.com Git - grub2.git/blob - gentpl.py
2 # GRUB -- GRand Unified Bootloader
3 # Copyright (C) 2010,2011,2012,2013 Free Software Foundation, Inc.
5 # GRUB is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # GRUB is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
18 from __future__
import print_function
22 from optparse
import OptionParser
26 # This is the python script used to generate Makefile.*.am
29 GRUB_PLATFORMS
= [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
30 "i386_multiboot", "i386_ieee1275", "x86_64_efi",
31 "i386_xen", "x86_64_xen", "i386_xen_pvh",
32 "mips_loongson", "sparc64_ieee1275",
33 "powerpc_ieee1275", "mips_arc", "ia64_efi",
34 "mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi",
35 "arm_coreboot", "riscv32_efi", "riscv64_efi" ]
39 GROUPS
["common"] = GRUB_PLATFORMS
[:]
42 GROUPS
["i386"] = [ "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275" ]
43 GROUPS
["x86_64"] = [ "x86_64_efi" ]
44 GROUPS
["x86"] = GROUPS
["i386"] + GROUPS
["x86_64"]
45 GROUPS
["mips"] = [ "mips_loongson", "mips_qemu_mips", "mips_arc" ]
46 GROUPS
["sparc64"] = [ "sparc64_ieee1275" ]
47 GROUPS
["powerpc"] = [ "powerpc_ieee1275" ]
48 GROUPS
["arm"] = [ "arm_uboot", "arm_efi", "arm_coreboot" ]
49 GROUPS
["arm64"] = [ "arm64_efi" ]
50 GROUPS
["riscv32"] = [ "riscv32_efi" ]
51 GROUPS
["riscv64"] = [ "riscv64_efi" ]
53 # Groups based on firmware
54 GROUPS
["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi",
55 "riscv32_efi", "riscv64_efi" ]
56 GROUPS
["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ]
57 GROUPS
["uboot"] = [ "arm_uboot" ]
58 GROUPS
["xen"] = [ "i386_xen", "x86_64_xen" ]
59 GROUPS
["coreboot"] = [ "i386_coreboot", "arm_coreboot" ]
61 # emu is a special case so many core functionality isn't needed on this platform
62 GROUPS
["noemu"] = GRUB_PLATFORMS
[:]; GROUPS
["noemu"].remove("emu")
64 # Groups based on hardware features
65 GROUPS
["cmos"] = GROUPS
["x86"][:] + ["mips_loongson", "mips_qemu_mips",
66 "sparc64_ieee1275", "powerpc_ieee1275"]
67 GROUPS
["cmos"].remove("i386_efi"); GROUPS
["cmos"].remove("x86_64_efi");
68 GROUPS
["pci"] = GROUPS
["x86"] + ["mips_loongson"]
69 GROUPS
["usb"] = GROUPS
["pci"] + ["arm_coreboot"]
71 # If gfxterm is main output console integrate it into kernel
72 GROUPS
["videoinkernel"] = ["mips_loongson", "i386_coreboot", "arm_coreboot" ]
73 GROUPS
["videomodules"] = GRUB_PLATFORMS
[:];
74 for i
in GROUPS
["videoinkernel"]: GROUPS
["videomodules"].remove(i
)
76 # Similar for terminfo
77 GROUPS
["terminfoinkernel"] = [ "emu", "mips_loongson", "mips_arc", "mips_qemu_mips", "i386_xen_pvh" ] + GROUPS
["xen"] + GROUPS
["ieee1275"] + GROUPS
["uboot"];
78 GROUPS
["terminfomodule"] = GRUB_PLATFORMS
[:];
79 for i
in GROUPS
["terminfoinkernel"]: GROUPS
["terminfomodule"].remove(i
)
81 # Flattened Device Trees (FDT)
82 GROUPS
["fdt"] = [ "arm64_efi", "arm_uboot", "arm_efi", "riscv32_efi", "riscv64_efi" ]
84 # Needs software helpers for division
85 # Must match GRUB_DIVISION_IN_SOFTWARE in misc.h
86 GROUPS
["softdiv"] = GROUPS
["arm"] + ["ia64_efi"] + GROUPS
["riscv32"]
87 GROUPS
["no_softdiv"] = GRUB_PLATFORMS
[:]
88 for i
in GROUPS
["softdiv"]: GROUPS
["no_softdiv"].remove(i
)
90 # Miscellaneous groups scheduled to disappear in future
91 GROUPS
["i386_coreboot_multiboot_qemu"] = ["i386_coreboot", "i386_multiboot", "i386_qemu"]
92 GROUPS
["nopc"] = GRUB_PLATFORMS
[:]; GROUPS
["nopc"].remove("i386_pc")
95 # Create platform => groups reverse map, where groups covering that
96 # platform are ordered by their sizes
99 for platform
in GRUB_PLATFORMS
:
100 # initialize with platform itself as a group
101 RMAP
[platform
] = [ platform
]
103 for k
in GROUPS
.keys():
105 # skip groups that don't cover this platform
106 if platform
not in v
: continue
110 # partition currently known groups based on their size
111 for group
in RMAP
[platform
]:
112 if group
in GRUB_PLATFORMS
: smaller
.append(group
)
113 elif len(GROUPS
[group
]) < len(v
): smaller
.append(group
)
114 else: bigger
.append(group
)
115 # insert in the middle
116 RMAP
[platform
] = smaller
+ [ k
] + bigger
122 # We support a subset of the AutoGen definitions file syntax. Specifically,
123 # compound names are disallowed; some preprocessing directives are
124 # disallowed (though #if/#endif are allowed; note that, like AutoGen, #if
125 # skips everything to the next #endif regardless of the value of the
126 # conditional); and shell-generated strings, Scheme-generated strings, and
127 # here strings are disallowed.
130 (autogen
, definitions
, eof
, var_name
, other_name
, string
, number
,
131 semicolon
, equals
, comma
, lbrace
, rbrace
, lbracket
, rbracket
) = range(14)
134 (init
, need_def
, need_tpl
, need_semi
, need_name
, have_name
, need_value
,
135 need_idx
, need_rbracket
, indx_name
, have_value
, done
) = range(12)
137 class AutogenParseError(Exception):
138 def __init__(self
, message
, path
, line
):
139 super(AutogenParseError
, self
).__init
__(message
)
145 super(AutogenParseError
, self
).__str
__() +
146 " at file %s line %d" % (self
.path
, self
.line
))
148 class AutogenDefinition(list):
149 def __getitem__(self
, key
):
151 return super(AutogenDefinition
, self
).__getitem
__(key
)
153 for name
, value
in self
:
157 def __contains__(self
, key
):
158 for name
, value
in self
:
163 def get(self
, key
, default
):
164 for name
, value
in self
:
170 def find_all(self
, key
):
171 for name
, value
in self
:
177 self
.definitions
= AutogenDefinition()
178 self
.def_stack
= [("", self
.definitions
)]
185 def is_unquotable_char(c
):
186 return (ord(c
) in range(ord("!"), ord("~") + 1) and
187 c
not in "#,;<=>[\\]`{}?*'\"()")
190 def is_value_name_char(c
):
191 return c
in ":^-_" or c
.isalnum()
193 def error(self
, message
):
194 raise AutogenParseError(message
, self
.cur_file
, self
.cur_line
)
196 def read_tokens(self
, f
):
201 while offset
< end
and data
[offset
].isspace():
202 if data
[offset
] == "\n":
211 end_directive
= data
.index("\n", offset
)
212 directive
= data
[offset
:end_directive
]
213 offset
= end_directive
215 directive
= data
[offset
:]
217 name
, value
= directive
.split(None, 1)
220 end_if
= data
.index("\n#endif", offset
)
221 new_offset
= end_if
+ len("\n#endif")
222 self
.cur_line
+= data
[offset
:new_offset
].count("\n")
225 self
.error("#if without matching #endif")
227 self
.error("Unhandled directive '#%s'" % name
)
229 yield AutogenToken
.lbrace
, c
232 yield AutogenToken
.equals
, c
235 yield AutogenToken
.rbrace
, c
238 yield AutogenToken
.lbracket
, c
241 yield AutogenToken
.rbracket
, c
244 yield AutogenToken
.semicolon
, c
247 yield AutogenToken
.comma
, c
249 elif c
in ("'", '"'):
254 self
.error("EOF in quoted string")
255 if data
[offset
] == "\n":
257 if data
[offset
] == "\\":
260 self
.error("EOF in quoted string")
261 if data
[offset
] == "\n":
263 # Proper escaping unimplemented; this can be filled
266 s
.append(data
[offset
])
267 elif data
[offset
] == c
:
271 s
.append(data
[offset
])
272 yield AutogenToken
.string
, "".join(s
)
275 if data
[offset
] == "*":
278 end_comment
= data
.index("*/", offset
)
279 new_offset
= end_comment
+ len("*/")
280 self
.cur_line
+= data
[offset
:new_offset
].count("\n")
283 self
.error("/* without matching */")
284 elif data
[offset
] == "/":
286 offset
= data
.index("\n", offset
)
290 (c
== "-" and offset
< end
- 1 and
291 data
[offset
+ 1].isdigit())):
292 end_number
= offset
+ 1
293 while end_number
< end
and data
[end_number
].isdigit():
295 yield AutogenToken
.number
, data
[offset
:end_number
]
297 elif self
.is_unquotable_char(c
):
299 while (end_name
< end
and
300 self
.is_value_name_char(data
[end_name
])):
302 if end_name
< end
and self
.is_unquotable_char(data
[end_name
]):
303 while (end_name
< end
and
304 self
.is_unquotable_char(data
[end_name
])):
306 yield AutogenToken
.other_name
, data
[offset
:end_name
]
309 s
= data
[offset
:end_name
]
310 if s
.lower() == "autogen":
311 yield AutogenToken
.autogen
, s
312 elif s
.lower() == "definitions":
313 yield AutogenToken
.definitions
, s
315 yield AutogenToken
.var_name
, s
318 self
.error("Invalid input character '%s'" % c
)
319 yield AutogenToken
.eof
, None
321 def do_need_name_end(self
, token
):
322 if len(self
.def_stack
) > 1:
323 self
.error("Definition blocks were left open")
325 def do_need_name_var_name(self
, token
):
326 self
.new_name
= token
328 def do_end_block(self
, token
):
329 if len(self
.def_stack
) <= 1:
330 self
.error("Too many close braces")
331 new_name
, parent_def
= self
.def_stack
.pop()
332 parent_def
.append((new_name
, self
.curdef
))
333 self
.curdef
= parent_def
335 def do_empty_val(self
, token
):
336 self
.curdef
.append((self
.new_name
, ""))
338 def do_str_value(self
, token
):
339 self
.curdef
.append((self
.new_name
, token
))
341 def do_start_block(self
, token
):
342 self
.def_stack
.append((self
.new_name
, self
.curdef
))
343 self
.curdef
= AutogenDefinition()
345 def do_indexed_name(self
, token
):
346 self
.new_name
= token
348 def read_definitions_file(self
, f
):
349 self
.curdef
= self
.definitions
351 state
= AutogenState
.init
353 # The following transition table was reduced from the Autogen
355 # info -f autogen -n 'Full Syntax'
358 AutogenToken
.autogen
: (AutogenState
.need_def
, None),
360 AutogenState
.need_def
: {
361 AutogenToken
.definitions
: (AutogenState
.need_tpl
, None),
363 AutogenState
.need_tpl
: {
364 AutogenToken
.var_name
: (AutogenState
.need_semi
, None),
365 AutogenToken
.other_name
: (AutogenState
.need_semi
, None),
366 AutogenToken
.string
: (AutogenState
.need_semi
, None),
368 AutogenState
.need_semi
: {
369 AutogenToken
.semicolon
: (AutogenState
.need_name
, None),
371 AutogenState
.need_name
: {
372 AutogenToken
.autogen
: (AutogenState
.need_def
, None),
373 AutogenToken
.eof
: (AutogenState
.done
, self
.do_need_name_end
),
374 AutogenToken
.var_name
: (
375 AutogenState
.have_name
, self
.do_need_name_var_name
),
376 AutogenToken
.rbrace
: (
377 AutogenState
.have_value
, self
.do_end_block
),
379 AutogenState
.have_name
: {
380 AutogenToken
.semicolon
: (
381 AutogenState
.need_name
, self
.do_empty_val
),
382 AutogenToken
.equals
: (AutogenState
.need_value
, None),
383 AutogenToken
.lbracket
: (AutogenState
.need_idx
, None),
385 AutogenState
.need_value
: {
386 AutogenToken
.var_name
: (
387 AutogenState
.have_value
, self
.do_str_value
),
388 AutogenToken
.other_name
: (
389 AutogenState
.have_value
, self
.do_str_value
),
390 AutogenToken
.string
: (
391 AutogenState
.have_value
, self
.do_str_value
),
392 AutogenToken
.number
: (
393 AutogenState
.have_value
, self
.do_str_value
),
394 AutogenToken
.lbrace
: (
395 AutogenState
.need_name
, self
.do_start_block
),
397 AutogenState
.need_idx
: {
398 AutogenToken
.var_name
: (
399 AutogenState
.need_rbracket
, self
.do_indexed_name
),
400 AutogenToken
.number
: (
401 AutogenState
.need_rbracket
, self
.do_indexed_name
),
403 AutogenState
.need_rbracket
: {
404 AutogenToken
.rbracket
: (AutogenState
.indx_name
, None),
406 AutogenState
.indx_name
: {
407 AutogenToken
.semicolon
: (
408 AutogenState
.need_name
, self
.do_empty_val
),
409 AutogenToken
.equals
: (AutogenState
.need_value
, None),
411 AutogenState
.have_value
: {
412 AutogenToken
.semicolon
: (AutogenState
.need_name
, None),
413 AutogenToken
.comma
: (AutogenState
.need_value
, None),
417 for code
, token
in self
.read_tokens(f
):
418 if code
in transitions
[state
]:
419 state
, handler
= transitions
[state
][code
]
420 if handler
is not None:
424 "Parse error in state %s: unexpected token '%s'" % (
426 if state
== AutogenState
.done
:
429 def read_definitions(self
, path
):
431 with
open(path
) as f
:
432 self
.read_definitions_file(f
)
434 defparser
= AutogenParser()
442 def output(s
, section
=''):
445 outputs
.setdefault(section
, [])
446 outputs
[section
].append(s
)
448 def write_output(section
=''):
449 for s
in outputs
.get(section
, []):
456 def gvar_add(var
, value
):
457 output(var
+ " += " + value
+ "\n")
460 # Per PROGRAM/SCRIPT variables
465 def vars_init(defn
, *var_list
):
468 if name
not in seen_target
and name
not in seen_vars
:
470 output(var
+ " = \n", section
='decl')
473 def var_set(var
, value
):
474 output(var
+ " = " + value
+ "\n")
476 def var_add(var
, value
):
477 output(var
+ " += " + value
+ "\n")
480 # Variable names and rules
483 canonical_name_re
= re
.compile(r
'[^0-9A-Za-z@_]')
484 canonical_name_suffix
= ""
486 def set_canonical_name_suffix(suffix
):
487 global canonical_name_suffix
488 canonical_name_suffix
= suffix
491 return canonical_name_re
.sub('_', defn
['name'] + canonical_name_suffix
)
493 def rule(target
, source
, cmd
):
495 output("\n" + target
+ ": " + source
+ cmd
.replace("\n", "\n\t") + "\n")
497 output("\n" + target
+ ": " + source
+ "\n\t" + cmd
.replace("\n", "\n\t") + "\n")
500 # Handle keys with platform names as values, for example:
507 def platform_tagged(defn
, platform
, tag
):
508 for value
in defn
.find_all(tag
):
509 for group
in RMAP
[platform
]:
514 def if_platform_tagged(defn
, platform
, tag
, snippet_if
, snippet_else
=None):
515 if platform_tagged(defn
, platform
, tag
):
517 elif snippet_else
is not None:
521 # Handle tagged values
529 def foreach_value(defn
, tag
, closure
):
531 for value
in defn
.find_all(tag
):
532 r
.append(closure(value
))
536 # Handle best matched values for a platform, for example:
540 # emu_cflags = '-Wall -DGRUB_EMU=1';
544 def foreach_platform_specific_value(defn
, platform
, suffix
, nonetag
, closure
):
546 for group
in RMAP
[platform
]:
547 values
= list(defn
.find_all(group
+ suffix
))
550 r
.append(closure(value
))
553 for value
in defn
.find_all(nonetag
):
554 r
.append(closure(value
))
558 # Handle values from sum of all groups for a platform, for example:
561 # common = kern/misc.c;
562 # emu = kern/emu/misc.c;
566 def foreach_platform_value(defn
, platform
, suffix
, closure
):
568 for group
in RMAP
[platform
]:
569 for value
in defn
.find_all(group
+ suffix
):
570 r
.append(closure(value
))
573 def platform_conditional(platform
, closure
):
574 output("\nif COND_" + platform
+ "\n")
579 # Handle guarding with platform-specific "enable" keys, for example:
584 # emu = bus/emu/pci.c;
585 # emu = commands/lspci.c;
590 # enable = i386_ieee1275;
591 # enable = i386_coreboot;
594 def foreach_enabled_platform(defn
, closure
):
596 for platform
in GRUB_PLATFORMS
:
597 if platform_tagged(defn
, platform
, "enable"):
598 platform_conditional(platform
, closure
)
600 for platform
in GRUB_PLATFORMS
:
601 platform_conditional(platform
, closure
)
604 # Handle guarding with platform-specific automake conditionals, for example:
608 # common = bus/usb/usb.c;
609 # noemu = bus/usb/usbtrans.c;
610 # noemu = bus/usb/usbhub.c;
613 # enable = mips_loongson;
614 # emu_condition = COND_GRUB_EMU_SDL;
617 def under_platform_specific_conditionals(defn
, platform
, closure
):
618 output(foreach_platform_specific_value(defn
, platform
, "_condition", "condition", lambda cond
: "if " + cond
+ "\n"))
619 closure(defn
, platform
)
620 output(foreach_platform_specific_value(defn
, platform
, "_condition", "condition", lambda cond
: "endif " + cond
+ "\n"))
622 def platform_specific_values(defn
, platform
, suffix
, nonetag
):
623 return foreach_platform_specific_value(defn
, platform
, suffix
, nonetag
,
624 lambda value
: value
+ " ")
626 def platform_values(defn
, platform
, suffix
):
627 return foreach_platform_value(defn
, platform
, suffix
, lambda value
: value
+ " ")
629 def extra_dist(defn
):
630 return foreach_value(defn
, "extra_dist", lambda value
: value
+ " ")
632 def platform_sources(defn
, p
): return platform_values(defn
, p
, "")
633 def platform_nodist_sources(defn
, p
): return platform_values(defn
, p
, "_nodist")
635 def platform_startup(defn
, p
): return platform_specific_values(defn
, p
, "_startup", "startup")
636 def platform_ldadd(defn
, p
): return platform_specific_values(defn
, p
, "_ldadd", "ldadd")
637 def platform_dependencies(defn
, p
): return platform_specific_values(defn
, p
, "_dependencies", "dependencies")
638 def platform_cflags(defn
, p
): return platform_specific_values(defn
, p
, "_cflags", "cflags")
639 def platform_ldflags(defn
, p
): return platform_specific_values(defn
, p
, "_ldflags", "ldflags")
640 def platform_cppflags(defn
, p
): return platform_specific_values(defn
, p
, "_cppflags", "cppflags")
641 def platform_ccasflags(defn
, p
): return platform_specific_values(defn
, p
, "_ccasflags", "ccasflags")
642 def platform_stripflags(defn
, p
): return platform_specific_values(defn
, p
, "_stripflags", "stripflags")
643 def platform_objcopyflags(defn
, p
): return platform_specific_values(defn
, p
, "_objcopyflags", "objcopyflags")
646 # Emit snippet only the first time through for the current name.
650 def first_time(defn
, snippet
):
651 if defn
['name'] not in seen_target
:
655 def is_platform_independent(defn
):
658 for suffix
in [ "", "_nodist" ]:
659 template
= platform_values(defn
, GRUB_PLATFORMS
[0], suffix
)
660 for platform
in GRUB_PLATFORMS
[1:]:
661 if template
!= platform_values(defn
, platform
, suffix
):
664 for suffix
in [ "startup", "ldadd", "dependencies", "cflags", "ldflags", "cppflags", "ccasflags", "stripflags", "objcopyflags", "condition" ]:
665 template
= platform_specific_values(defn
, GRUB_PLATFORMS
[0], "_" + suffix
, suffix
)
666 for platform
in GRUB_PLATFORMS
[1:]:
667 if template
!= platform_specific_values(defn
, platform
, "_" + suffix
, suffix
):
669 for tag
in [ "nostrip" ]:
670 template
= platform_tagged(defn
, GRUB_PLATFORMS
[0], tag
)
671 for platform
in GRUB_PLATFORMS
[1:]:
672 if template
!= platform_tagged(defn
, platform
, tag
):
677 def module(defn
, platform
):
679 set_canonical_name_suffix(".module")
681 gvar_add("platform_PROGRAMS", name
+ ".module")
682 gvar_add("MODULE_FILES", name
+ ".module$(EXEEXT)")
684 var_set(cname(defn
) + "_SOURCES", platform_sources(defn
, platform
) + " ## platform sources")
685 var_set("nodist_" + cname(defn
) + "_SOURCES", platform_nodist_sources(defn
, platform
) + " ## platform nodist sources")
686 var_set(cname(defn
) + "_LDADD", platform_ldadd(defn
, platform
))
687 var_set(cname(defn
) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_MODULE) " + platform_cflags(defn
, platform
))
688 var_set(cname(defn
) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_MODULE) " + platform_ldflags(defn
, platform
))
689 var_set(cname(defn
) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_MODULE) " + platform_cppflags(defn
, platform
))
690 var_set(cname(defn
) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_MODULE) " + platform_ccasflags(defn
, platform
))
691 var_set(cname(defn
) + "_DEPENDENCIES", "$(TARGET_OBJ2ELF) " + platform_dependencies(defn
, platform
))
693 gvar_add("dist_noinst_DATA", extra_dist(defn
))
694 gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn
) + "_SOURCES)")
695 gvar_add("CLEANFILES", "$(nodist_" + cname(defn
) + "_SOURCES)")
697 gvar_add("MOD_FILES", name
+ ".mod")
698 gvar_add("MARKER_FILES", name
+ ".marker")
699 gvar_add("CLEANFILES", name
+ ".marker")
701 """ + name
+ """.marker: $(""" + cname(defn
) + """_SOURCES) $(nodist_""" + cname(defn
) + """_SOURCES)
702 $(TARGET_CPP) -DGRUB_LST_GENERATOR $(CPPFLAGS_MARKER) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(""" + cname(defn
) + """_CPPFLAGS) $(CPPFLAGS) $^ > $@.new || (rm -f $@; exit 1)
703 grep 'MARKER' $@.new > $@; rm -f $@.new
706 def kernel(defn
, platform
):
708 set_canonical_name_suffix(".exec")
709 gvar_add("platform_PROGRAMS", name
+ ".exec")
710 var_set(cname(defn
) + "_SOURCES", platform_startup(defn
, platform
))
711 var_add(cname(defn
) + "_SOURCES", platform_sources(defn
, platform
))
712 var_set("nodist_" + cname(defn
) + "_SOURCES", platform_nodist_sources(defn
, platform
) + " ## platform nodist sources")
713 var_set(cname(defn
) + "_LDADD", platform_ldadd(defn
, platform
))
714 var_set(cname(defn
) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_KERNEL) " + platform_cflags(defn
, platform
))
715 var_set(cname(defn
) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_KERNEL) " + platform_ldflags(defn
, platform
))
716 var_set(cname(defn
) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) " + platform_cppflags(defn
, platform
))
717 var_set(cname(defn
) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_KERNEL) " + platform_ccasflags(defn
, platform
))
718 var_set(cname(defn
) + "_STRIPFLAGS", "$(AM_STRIPFLAGS) $(STRIPFLAGS_KERNEL) " + platform_stripflags(defn
, platform
))
719 var_set(cname(defn
) + "_DEPENDENCIES", "$(TARGET_OBJ2ELF)")
721 gvar_add("dist_noinst_DATA", extra_dist(defn
))
722 gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn
) + "_SOURCES)")
723 gvar_add("CLEANFILES", "$(nodist_" + cname(defn
) + "_SOURCES)")
725 gvar_add("platform_DATA", name
+ ".img")
726 gvar_add("CLEANFILES", name
+ ".img")
727 rule(name
+ ".img", name
+ ".exec$(EXEEXT)",
728 if_platform_tagged(defn
, platform
, "nostrip",
729 """if test x$(TARGET_APPLE_LINKER) = x1; then \
730 $(TARGET_OBJCONV) -f$(TARGET_MODULE_FORMAT) -nr:_grub_mod_init:grub_mod_init -nr:_grub_mod_fini:grub_mod_fini -ed2022 -wd1106 -nu -nd $< $@; \
731 elif test ! -z '$(TARGET_OBJ2ELF)'; then \
732 $(TARGET_OBJ2ELF) $< $@ || (rm -f $@; exit 1); \
733 else cp $< $@; fi""",
734 """if test x$(TARGET_APPLE_LINKER) = x1; then \
735 $(TARGET_STRIP) -S -x $(""" + cname(defn
) + """) -o $@.bin $<; \
736 $(TARGET_OBJCONV) -f$(TARGET_MODULE_FORMAT) -nr:_grub_mod_init:grub_mod_init -nr:_grub_mod_fini:grub_mod_fini -ed2022 -ed2016 -wd1106 -nu -nd $@.bin $@; \
738 elif test ! -z '$(TARGET_OBJ2ELF)'; then \
739 """ + "$(TARGET_STRIP) $(" + cname(defn
) + "_STRIPFLAGS) -o $@.bin $< && \
740 $(TARGET_OBJ2ELF) $@.bin $@ || (rm -f $@; rm -f $@.bin; exit 1); \
742 else """ + "$
(TARGET_STRIP
) $
(" + cname(defn) + "_STRIPFLAGS
) -o $
@ $
<; \
745 def image(defn, platform):
747 set_canonical_name_suffix(".image")
748 gvar_add("platform_PROGRAMS", name + ".image")
749 var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform))
750 var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + "## platform nodist sources")
751 var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
752 var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_IMAGE) " + platform_cflags(defn, platform))
753 var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_IMAGE) " + platform_ldflags(defn, platform))
754 var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_IMAGE) " + platform_cppflags(defn, platform))
755 var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_IMAGE) " + platform_ccasflags(defn, platform))
756 var_set(cname(defn) + "_OBJCOPYFLAGS", "$(OBJCOPYFLAGS_IMAGE) " + platform_objcopyflags(defn, platform))
757 # var_set(cname(defn) + "_DEPENDENCIES", platform_dependencies(defn, platform) + " " + platform_ldadd(defn, platform))
759 gvar_add("dist_noinst_DATA", extra_dist(defn))
760 gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
761 gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
763 gvar_add("platform_DATA", name + ".img")
764 gvar_add("CLEANFILES", name + ".img")
765 rule(name + ".img", name + ".image$(EXEEXT)", """
766 if test x$
(TARGET_APPLE_LINKER
) = x1
; then \
767 $
(MACHO2IMG
) $
< $
@; \
769 $
(TARGET_OBJCOPY
) $
(""" + cname(defn) + """_OBJCOPYFLAGS
) --strip
-unneeded
-R
.note
-R
.comment
-R
.note
.gnu
.build
-id -R
.MIPS
.abiflags
-R
.reginfo
-R
.rel
.dyn
-R
.note
.gnu
.gold
-version
-R
.ARM
.exidx $
< $
@; \
773 def library(defn, platform):
775 set_canonical_name_suffix("")
778 cname(defn) + "_SOURCES",
779 "nodist_" + cname(defn) + "_SOURCES",
780 cname(defn) + "_CFLAGS",
781 cname(defn) + "_CPPFLAGS",
782 cname(defn) + "_CCASFLAGS")
783 # cname(defn) + "_DEPENDENCIES")
785 if name not in seen_target:
786 gvar_add("noinst_LIBRARIES", name)
787 var_add(cname(defn) + "_SOURCES", platform_sources(defn, platform))
788 var_add("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform))
789 var_add(cname(defn) + "_CFLAGS", first_time(defn, "$(AM_CFLAGS) $(CFLAGS_LIBRARY) ") + platform_cflags(defn, platform))
790 var_add(cname(defn) + "_CPPFLAGS", first_time(defn, "$(AM_CPPFLAGS) $(CPPFLAGS_LIBRARY) ") + platform_cppflags(defn, platform))
791 var_add(cname(defn) + "_CCASFLAGS", first_time(defn, "$(AM_CCASFLAGS) $(CCASFLAGS_LIBRARY) ") + platform_ccasflags(defn, platform))
792 # var_add(cname(defn) + "_DEPENDENCIES", platform_dependencies(defn, platform) + " " + platform_ldadd(defn, platform))
794 gvar_add("dist_noinst_DATA", extra_dist(defn))
795 if name not in seen_target:
796 gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
797 gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
799 def installdir(defn, default="bin"):
800 return defn.get('installdir', default)
802 def manpage(defn, adddeps):
804 mansection = defn['mansection']
806 output("if COND_MAN_PAGES\n")
807 gvar_add("man_MANS", name + "." + mansection)
808 rule(name + "." + mansection, name + " " + adddeps, """
809 chmod a
+x
""" + name + """
810 PATH
=$
(builddir
):$$PATH pkgdatadir
=$
(builddir
) $
(HELP2MAN
) --section
=""" + mansection + """ -i $
(top_srcdir
)/docs
/man
/""" + name + """.h2m
-o $
@ """ + name + """
812 gvar_add("CLEANFILES", name + "." + mansection)
815 def program(defn, platform, test=False):
817 set_canonical_name_suffix("")
819 if 'testcase' in defn:
820 gvar_add("check_PROGRAMS", name)
821 gvar_add("TESTS", name)
823 var_add(installdir(defn) + "_PROGRAMS", name)
824 if 'mansection' in defn:
827 var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform))
828 var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform))
829 var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
830 var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_PROGRAM) " + platform_cflags(defn, platform))
831 var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_PROGRAM) " + platform_ldflags(defn, platform))
832 var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_PROGRAM) " + platform_cppflags(defn, platform))
833 var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_PROGRAM) " + platform_ccasflags(defn, platform))
834 # var_set(cname(defn) + "_DEPENDENCIES", platform_dependencies(defn, platform) + " " + platform_ldadd(defn, platform))
836 gvar_add("dist_noinst_DATA", extra_dist(defn))
837 gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
838 gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
840 def data(defn, platform):
841 var_add("dist_" + installdir(defn) + "_DATA", platform_sources(defn, platform))
842 gvar_add("dist_noinst_DATA", extra_dist(defn))
844 def transform_data(defn, platform):
847 var_add(installdir(defn) + "_DATA", name)
849 rule(name, "$(top_builddir)/config.status " + platform_sources(defn, platform) + platform_dependencies(defn, platform), """
850 (for x
in """ + platform_sources(defn, platform) + """; do cat $
(srcdir
)/"$$x"; done
) | $
(top_builddir
)/config
.status
--file=$
@:-
851 chmod a
+x
""" + name + """
854 gvar_add("CLEANFILES", name)
855 gvar_add("EXTRA_DIST", extra_dist(defn))
856 gvar_add("dist_noinst_DATA", platform_sources(defn, platform))
858 def script(defn, platform):
861 if 'testcase' in defn:
862 gvar_add("check_SCRIPTS", name)
863 gvar_add ("TESTS", name)
865 var_add(installdir(defn) + "_SCRIPTS", name)
866 if 'mansection' in defn:
867 manpage(defn, "grub-mkconfig_lib")
869 rule(name, "$(top_builddir)/config.status " + platform_sources(defn, platform) + platform_dependencies(defn, platform), """
870 (for x
in """ + platform_sources(defn, platform) + """; do cat $
(srcdir
)/"$$x"; done
) | $
(top_builddir
)/config
.status
--file=$
@:-
871 chmod a
+x
""" + name + """
874 gvar_add("CLEANFILES", name)
875 gvar_add("EXTRA_DIST", extra_dist(defn))
876 gvar_add("dist_noinst_DATA", platform_sources(defn, platform))
878 def rules(target, closure):
882 for defn in defparser.definitions.find_all(target):
883 if is_platform_independent(defn):
884 under_platform_specific_conditionals(defn, GRUB_PLATFORMS[0], closure)
886 foreach_enabled_platform(
888 lambda p: under_platform_specific_conditionals(defn, p, closure))
889 # Remember that we've seen this target.
890 seen_target.add(defn['name'])
892 parser = OptionParser(usage="%prog DEFINITION-FILES")
893 _, args = parser.parse_args()
896 defparser.read_definitions(arg)
898 rules("module", module)
899 rules("kernel", kernel)
900 rules("image", image)
901 rules("library", library)
902 rules("program", program)
903 rules("script", script)
905 rules("transform_data", transform_data)
907 write_output(section='decl')