2010-05-06 06:04:04 +00:00
|
|
|
#! /usr/bin/python
|
2012-02-11 10:31:13 +00:00
|
|
|
# GRUB -- GRand Unified Bootloader
|
2013-11-13 12:42:24 +00:00
|
|
|
# Copyright (C) 2010,2011,2012,2013 Free Software Foundation, Inc.
|
2012-02-11 10:31:13 +00:00
|
|
|
#
|
|
|
|
# GRUB is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# GRUB is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-06 06:04:04 +00:00
|
|
|
|
2013-11-13 12:42:24 +00:00
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
from optparse import OptionParser
|
|
|
|
import re
|
|
|
|
|
2010-05-06 06:04:04 +00:00
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
# This is the python script used to generate Makefile.*.am
|
2010-05-06 06:04:04 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
|
2010-05-10 08:20:43 +00:00
|
|
|
"i386_multiboot", "i386_ieee1275", "x86_64_efi",
|
2013-11-09 20:29:11 +00:00
|
|
|
"i386_xen", "x86_64_xen",
|
2011-02-19 12:18:05 +00:00
|
|
|
"mips_loongson", "sparc64_ieee1275",
|
2011-05-17 12:02:18 +00:00
|
|
|
"powerpc_ieee1275", "mips_arc", "ia64_efi",
|
2013-04-07 00:41:07 +00:00
|
|
|
"mips_qemu_mips", "arm_uboot", "arm_efi" ]
|
2010-05-06 06:04:04 +00:00
|
|
|
|
|
|
|
GROUPS = {}
|
2010-08-30 13:13:38 +00:00
|
|
|
|
|
|
|
GROUPS["common"] = GRUB_PLATFORMS[:]
|
|
|
|
|
|
|
|
# Groups based on CPU
|
2010-08-21 08:57:31 +00:00
|
|
|
GROUPS["i386"] = [ "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275" ]
|
|
|
|
GROUPS["x86_64"] = [ "x86_64_efi" ]
|
|
|
|
GROUPS["x86"] = GROUPS["i386"] + GROUPS["x86_64"]
|
2011-05-17 12:02:18 +00:00
|
|
|
GROUPS["mips"] = [ "mips_loongson", "mips_qemu_mips", "mips_arc" ]
|
2010-08-21 08:57:31 +00:00
|
|
|
GROUPS["sparc64"] = [ "sparc64_ieee1275" ]
|
|
|
|
GROUPS["powerpc"] = [ "powerpc_ieee1275" ]
|
2013-04-07 00:41:07 +00:00
|
|
|
GROUPS["arm"] = [ "arm_uboot", "arm_efi" ]
|
2010-08-21 08:57:31 +00:00
|
|
|
|
2010-08-30 13:13:38 +00:00
|
|
|
# Groups based on firmware
|
2013-04-07 00:41:07 +00:00
|
|
|
GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi" ]
|
2010-08-21 08:57:31 +00:00
|
|
|
GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ]
|
2013-04-07 00:41:07 +00:00
|
|
|
GROUPS["uboot"] = [ "arm_uboot" ]
|
2013-11-09 20:29:11 +00:00
|
|
|
GROUPS["xen"] = [ "i386_xen", "x86_64_xen" ]
|
2010-08-21 08:57:31 +00:00
|
|
|
|
2010-08-30 13:13:38 +00:00
|
|
|
# emu is a special case so many core functionality isn't needed on this platform
|
|
|
|
GROUPS["noemu"] = GRUB_PLATFORMS[:]; GROUPS["noemu"].remove("emu")
|
|
|
|
|
|
|
|
# Groups based on hardware features
|
2011-07-05 18:24:20 +00:00
|
|
|
GROUPS["cmos"] = GROUPS["x86"][:] + ["mips_loongson", "mips_qemu_mips",
|
|
|
|
"sparc64_ieee1275", "powerpc_ieee1275"]
|
2013-11-09 20:29:11 +00:00
|
|
|
GROUPS["cmos"].remove("i386_efi"); GROUPS["cmos"].remove("x86_64_efi");
|
2011-05-15 00:23:36 +00:00
|
|
|
GROUPS["pci"] = GROUPS["x86"] + ["mips_loongson"]
|
2010-08-30 13:13:38 +00:00
|
|
|
GROUPS["usb"] = GROUPS["pci"]
|
2010-08-21 08:57:31 +00:00
|
|
|
|
2010-08-30 13:13:38 +00:00
|
|
|
# If gfxterm is main output console integrate it into kernel
|
2013-05-30 22:42:33 +00:00
|
|
|
GROUPS["videoinkernel"] = ["mips_loongson", "i386_coreboot" ]
|
2010-08-30 13:13:38 +00:00
|
|
|
GROUPS["videomodules"] = GRUB_PLATFORMS[:];
|
|
|
|
for i in GROUPS["videoinkernel"]: GROUPS["videomodules"].remove(i)
|
2010-08-21 08:57:31 +00:00
|
|
|
|
2010-09-30 15:50:01 +00:00
|
|
|
# Similar for terminfo
|
2013-11-09 20:29:11 +00:00
|
|
|
GROUPS["terminfoinkernel"] = [ "emu", "mips_loongson", "mips_arc", "mips_qemu_mips" ] + GROUPS["xen"] + GROUPS["ieee1275"] + GROUPS["uboot"];
|
2010-09-30 15:50:01 +00:00
|
|
|
GROUPS["terminfomodule"] = GRUB_PLATFORMS[:];
|
|
|
|
for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i)
|
|
|
|
|
2013-04-07 00:41:07 +00:00
|
|
|
# Flattened Device Trees (FDT)
|
|
|
|
GROUPS["fdt"] = [ "arm_uboot", "arm_efi" ]
|
|
|
|
|
2010-08-30 13:13:38 +00:00
|
|
|
# Miscelaneous groups schedulded to disappear in future
|
|
|
|
GROUPS["i386_coreboot_multiboot_qemu"] = ["i386_coreboot", "i386_multiboot", "i386_qemu"]
|
|
|
|
GROUPS["nopc"] = GRUB_PLATFORMS[:]; GROUPS["nopc"].remove("i386_pc")
|
2010-05-06 06:04:04 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Create platform => groups reverse map, where groups covering that
|
|
|
|
# platform are ordered by their sizes
|
|
|
|
#
|
|
|
|
RMAP = {}
|
|
|
|
for platform in GRUB_PLATFORMS:
|
|
|
|
# initialize with platform itself as a group
|
|
|
|
RMAP[platform] = [ platform ]
|
|
|
|
|
|
|
|
for k in GROUPS.keys():
|
|
|
|
v = GROUPS[k]
|
|
|
|
# skip groups that don't cover this platform
|
|
|
|
if platform not in v: continue
|
|
|
|
|
|
|
|
bigger = []
|
|
|
|
smaller = []
|
|
|
|
# partition currently known groups based on their size
|
|
|
|
for group in RMAP[platform]:
|
|
|
|
if group in GRUB_PLATFORMS: smaller.append(group)
|
|
|
|
elif len(GROUPS[group]) < len(v): smaller.append(group)
|
|
|
|
else: bigger.append(group)
|
|
|
|
# insert in the middle
|
|
|
|
RMAP[platform] = smaller + [ k ] + bigger
|
|
|
|
|
2013-11-13 12:42:24 +00:00
|
|
|
#
|
|
|
|
# Input
|
|
|
|
#
|
|
|
|
|
|
|
|
# We support a subset of the AutoGen definitions file syntax. Specifically,
|
2013-11-26 17:48:20 +00:00
|
|
|
# compound names are disallowed; some preprocessing directives are
|
|
|
|
# disallowed (though #if/#endif are allowed; note that, like AutoGen, #if
|
|
|
|
# skips everything to the next #endif regardless of the value of the
|
|
|
|
# conditional); and shell-generated strings, Scheme-generated strings, and
|
|
|
|
# here strings are disallowed.
|
2013-11-13 12:42:24 +00:00
|
|
|
|
|
|
|
class AutogenToken:
|
|
|
|
(autogen, definitions, eof, var_name, other_name, string, number,
|
|
|
|
semicolon, equals, comma, lbrace, rbrace, lbracket, rbracket) = range(14)
|
|
|
|
|
|
|
|
class AutogenState:
|
|
|
|
(init, need_def, need_tpl, need_semi, need_name, have_name, need_value,
|
|
|
|
need_idx, need_rbracket, indx_name, have_value, done) = range(12)
|
|
|
|
|
|
|
|
class AutogenParseError(Exception):
|
2013-11-26 17:42:56 +00:00
|
|
|
def __init__(self, message, path, line):
|
2013-11-13 12:42:24 +00:00
|
|
|
super(AutogenParseError, self).__init__(message)
|
2013-11-26 17:42:56 +00:00
|
|
|
self.path = path
|
2013-11-13 12:42:24 +00:00
|
|
|
self.line = line
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return (
|
|
|
|
super(AutogenParseError, self).__str__() +
|
2013-11-26 17:42:56 +00:00
|
|
|
" at file %s line %d" % (self.path, self.line))
|
2013-11-13 12:42:24 +00:00
|
|
|
|
|
|
|
class AutogenDefinition(list):
|
|
|
|
def __getitem__(self, key):
|
|
|
|
try:
|
|
|
|
return super(AutogenDefinition, self).__getitem__(key)
|
|
|
|
except TypeError:
|
|
|
|
for name, value in self:
|
|
|
|
if name == key:
|
|
|
|
return value
|
|
|
|
|
|
|
|
def __contains__(self, key):
|
|
|
|
for name, value in self:
|
|
|
|
if name == key:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get(self, key, default):
|
|
|
|
for name, value in self:
|
|
|
|
if name == key:
|
|
|
|
return value
|
|
|
|
else:
|
|
|
|
return default
|
|
|
|
|
|
|
|
def find_all(self, key):
|
|
|
|
for name, value in self:
|
|
|
|
if name == key:
|
|
|
|
yield value
|
|
|
|
|
|
|
|
class AutogenParser:
|
|
|
|
def __init__(self):
|
|
|
|
self.definitions = AutogenDefinition()
|
|
|
|
self.def_stack = [("", self.definitions)]
|
|
|
|
self.curdef = None
|
|
|
|
self.new_name = None
|
2013-11-26 17:42:56 +00:00
|
|
|
self.cur_path = None
|
2013-11-13 12:42:24 +00:00
|
|
|
self.cur_line = 0
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_unquotable_char(c):
|
|
|
|
return (ord(c) in range(ord("!"), ord("~") + 1) and
|
|
|
|
c not in "#,;<=>[\\]`{}?*'\"()")
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_value_name_char(c):
|
|
|
|
return c in ":^-_" or c.isalnum()
|
|
|
|
|
2013-11-26 17:42:56 +00:00
|
|
|
def error(self, message):
|
|
|
|
raise AutogenParseError(message, self.cur_file, self.cur_line)
|
|
|
|
|
2013-11-13 12:42:24 +00:00
|
|
|
def read_tokens(self, f):
|
|
|
|
data = f.read()
|
|
|
|
end = len(data)
|
|
|
|
offset = 0
|
|
|
|
while offset < end:
|
|
|
|
while offset < end and data[offset].isspace():
|
|
|
|
if data[offset] == "\n":
|
|
|
|
self.cur_line += 1
|
|
|
|
offset += 1
|
|
|
|
if offset >= end:
|
|
|
|
break
|
|
|
|
c = data[offset]
|
2013-11-26 17:48:20 +00:00
|
|
|
if c == "#":
|
|
|
|
offset += 1
|
|
|
|
try:
|
|
|
|
end_directive = data.index("\n", offset)
|
|
|
|
directive = data[offset:end_directive]
|
|
|
|
offset = end_directive
|
|
|
|
except ValueError:
|
|
|
|
directive = data[offset:]
|
|
|
|
offset = end
|
|
|
|
name, value = directive.split(None, 1)
|
|
|
|
if name == "if":
|
|
|
|
try:
|
|
|
|
end_if = data.index("\n#endif", offset)
|
|
|
|
new_offset = end_if + len("\n#endif")
|
|
|
|
self.cur_line += data[offset:new_offset].count("\n")
|
|
|
|
offset = new_offset
|
|
|
|
except ValueError:
|
|
|
|
self.error("#if without matching #endif")
|
|
|
|
else:
|
|
|
|
self.error("Unhandled directive '#%s'" % name)
|
|
|
|
elif c == "{":
|
2013-11-13 12:42:24 +00:00
|
|
|
yield AutogenToken.lbrace, c
|
|
|
|
offset += 1
|
|
|
|
elif c == "=":
|
|
|
|
yield AutogenToken.equals, c
|
|
|
|
offset += 1
|
|
|
|
elif c == "}":
|
|
|
|
yield AutogenToken.rbrace, c
|
|
|
|
offset += 1
|
|
|
|
elif c == "[":
|
|
|
|
yield AutogenToken.lbracket, c
|
|
|
|
offset += 1
|
|
|
|
elif c == "]":
|
|
|
|
yield AutogenToken.rbracket, c
|
|
|
|
offset += 1
|
|
|
|
elif c == ";":
|
|
|
|
yield AutogenToken.semicolon, c
|
|
|
|
offset += 1
|
|
|
|
elif c == ",":
|
|
|
|
yield AutogenToken.comma, c
|
|
|
|
offset += 1
|
|
|
|
elif c in ("'", '"'):
|
|
|
|
s = []
|
|
|
|
while True:
|
|
|
|
offset += 1
|
|
|
|
if offset >= end:
|
2013-11-26 17:42:56 +00:00
|
|
|
self.error("EOF in quoted string")
|
2013-11-13 12:42:24 +00:00
|
|
|
if data[offset] == "\n":
|
|
|
|
self.cur_line += 1
|
|
|
|
if data[offset] == "\\":
|
|
|
|
offset += 1
|
|
|
|
if offset >= end:
|
2013-11-26 17:42:56 +00:00
|
|
|
self.error("EOF in quoted string")
|
2013-11-13 12:42:24 +00:00
|
|
|
if data[offset] == "\n":
|
|
|
|
self.cur_line += 1
|
|
|
|
# Proper escaping unimplemented; this can be filled
|
|
|
|
# out if needed.
|
|
|
|
s.append("\\")
|
|
|
|
s.append(data[offset])
|
|
|
|
elif data[offset] == c:
|
|
|
|
offset += 1
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
s.append(data[offset])
|
|
|
|
yield AutogenToken.string, "".join(s)
|
2013-11-26 17:48:20 +00:00
|
|
|
elif c == "/":
|
|
|
|
offset += 1
|
|
|
|
if data[offset] == "*":
|
|
|
|
offset += 1
|
|
|
|
try:
|
|
|
|
end_comment = data.index("*/", offset)
|
|
|
|
new_offset = end_comment + len("*/")
|
|
|
|
self.cur_line += data[offset:new_offset].count("\n")
|
|
|
|
offset = new_offset
|
|
|
|
except ValueError:
|
|
|
|
self.error("/* without matching */")
|
|
|
|
elif data[offset] == "/":
|
|
|
|
try:
|
|
|
|
offset = data.index("\n", offset)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2013-11-13 12:42:24 +00:00
|
|
|
elif (c.isdigit() or
|
|
|
|
(c == "-" and offset < end - 1 and
|
|
|
|
data[offset + 1].isdigit())):
|
|
|
|
end_number = offset + 1
|
|
|
|
while end_number < end and data[end_number].isdigit():
|
|
|
|
end_number += 1
|
|
|
|
yield AutogenToken.number, data[offset:end_number]
|
|
|
|
offset = end_number
|
|
|
|
elif self.is_unquotable_char(c):
|
|
|
|
end_name = offset
|
|
|
|
while (end_name < end and
|
|
|
|
self.is_value_name_char(data[end_name])):
|
|
|
|
end_name += 1
|
|
|
|
if end_name < end and self.is_unquotable_char(data[end_name]):
|
|
|
|
while (end_name < end and
|
|
|
|
self.is_unquotable_char(data[end_name])):
|
|
|
|
end_name += 1
|
|
|
|
yield AutogenToken.other_name, data[offset:end_name]
|
|
|
|
offset = end_name
|
|
|
|
else:
|
|
|
|
s = data[offset:end_name]
|
|
|
|
if s.lower() == "autogen":
|
|
|
|
yield AutogenToken.autogen, s
|
|
|
|
elif s.lower() == "definitions":
|
|
|
|
yield AutogenToken.definitions, s
|
|
|
|
else:
|
|
|
|
yield AutogenToken.var_name, s
|
|
|
|
offset = end_name
|
|
|
|
else:
|
2013-11-26 17:42:56 +00:00
|
|
|
self.error("Invalid input character '%s'" % c)
|
2013-11-13 12:42:24 +00:00
|
|
|
yield AutogenToken.eof, None
|
|
|
|
|
|
|
|
def do_need_name_end(self, token):
|
|
|
|
if len(self.def_stack) > 1:
|
2013-11-26 17:42:56 +00:00
|
|
|
self.error("Definition blocks were left open")
|
2013-11-13 12:42:24 +00:00
|
|
|
|
|
|
|
def do_need_name_var_name(self, token):
|
|
|
|
self.new_name = token
|
|
|
|
|
|
|
|
def do_end_block(self, token):
|
|
|
|
if len(self.def_stack) <= 1:
|
2013-11-26 17:42:56 +00:00
|
|
|
self.error("Too many close braces")
|
2013-11-13 12:42:24 +00:00
|
|
|
new_name, parent_def = self.def_stack.pop()
|
|
|
|
parent_def.append((new_name, self.curdef))
|
|
|
|
self.curdef = parent_def
|
|
|
|
|
|
|
|
def do_empty_val(self, token):
|
|
|
|
self.curdef.append((self.new_name, ""))
|
|
|
|
|
|
|
|
def do_str_value(self, token):
|
|
|
|
self.curdef.append((self.new_name, token))
|
|
|
|
|
|
|
|
def do_start_block(self, token):
|
|
|
|
self.def_stack.append((self.new_name, self.curdef))
|
|
|
|
self.curdef = AutogenDefinition()
|
|
|
|
|
|
|
|
def do_indexed_name(self, token):
|
|
|
|
self.new_name = token
|
|
|
|
|
2013-11-26 17:42:56 +00:00
|
|
|
def read_definitions_file(self, f):
|
2013-11-13 12:42:24 +00:00
|
|
|
self.curdef = self.definitions
|
|
|
|
self.cur_line = 0
|
|
|
|
state = AutogenState.init
|
|
|
|
|
|
|
|
# The following transition table was reduced from the Autogen
|
|
|
|
# documentation:
|
|
|
|
# info -f autogen -n 'Full Syntax'
|
|
|
|
transitions = {
|
|
|
|
AutogenState.init: {
|
|
|
|
AutogenToken.autogen: (AutogenState.need_def, None),
|
|
|
|
},
|
|
|
|
AutogenState.need_def: {
|
|
|
|
AutogenToken.definitions: (AutogenState.need_tpl, None),
|
|
|
|
},
|
|
|
|
AutogenState.need_tpl: {
|
|
|
|
AutogenToken.var_name: (AutogenState.need_semi, None),
|
|
|
|
AutogenToken.other_name: (AutogenState.need_semi, None),
|
|
|
|
AutogenToken.string: (AutogenState.need_semi, None),
|
|
|
|
},
|
|
|
|
AutogenState.need_semi: {
|
|
|
|
AutogenToken.semicolon: (AutogenState.need_name, None),
|
|
|
|
},
|
|
|
|
AutogenState.need_name: {
|
|
|
|
AutogenToken.autogen: (AutogenState.need_def, None),
|
|
|
|
AutogenToken.eof: (AutogenState.done, self.do_need_name_end),
|
|
|
|
AutogenToken.var_name: (
|
|
|
|
AutogenState.have_name, self.do_need_name_var_name),
|
|
|
|
AutogenToken.rbrace: (
|
|
|
|
AutogenState.have_value, self.do_end_block),
|
|
|
|
},
|
|
|
|
AutogenState.have_name: {
|
|
|
|
AutogenToken.semicolon: (
|
|
|
|
AutogenState.need_name, self.do_empty_val),
|
|
|
|
AutogenToken.equals: (AutogenState.need_value, None),
|
|
|
|
AutogenToken.lbracket: (AutogenState.need_idx, None),
|
|
|
|
},
|
|
|
|
AutogenState.need_value: {
|
|
|
|
AutogenToken.var_name: (
|
|
|
|
AutogenState.have_value, self.do_str_value),
|
|
|
|
AutogenToken.other_name: (
|
|
|
|
AutogenState.have_value, self.do_str_value),
|
|
|
|
AutogenToken.string: (
|
|
|
|
AutogenState.have_value, self.do_str_value),
|
|
|
|
AutogenToken.number: (
|
|
|
|
AutogenState.have_value, self.do_str_value),
|
|
|
|
AutogenToken.lbrace: (
|
|
|
|
AutogenState.need_name, self.do_start_block),
|
|
|
|
},
|
|
|
|
AutogenState.need_idx: {
|
|
|
|
AutogenToken.var_name: (
|
|
|
|
AutogenState.need_rbracket, self.do_indexed_name),
|
|
|
|
AutogenToken.number: (
|
|
|
|
AutogenState.need_rbracket, self.do_indexed_name),
|
|
|
|
},
|
|
|
|
AutogenState.need_rbracket: {
|
|
|
|
AutogenToken.rbracket: (AutogenState.indx_name, None),
|
|
|
|
},
|
|
|
|
AutogenState.indx_name: {
|
|
|
|
AutogenToken.semicolon: (
|
|
|
|
AutogenState.need_name, self.do_empty_val),
|
|
|
|
AutogenToken.equals: (AutogenState.need_value, None),
|
|
|
|
},
|
|
|
|
AutogenState.have_value: {
|
|
|
|
AutogenToken.semicolon: (AutogenState.need_name, None),
|
|
|
|
AutogenToken.comma: (AutogenState.need_value, None),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for code, token in self.read_tokens(f):
|
|
|
|
if code in transitions[state]:
|
|
|
|
state, handler = transitions[state][code]
|
|
|
|
if handler is not None:
|
|
|
|
handler(token)
|
|
|
|
else:
|
2013-11-26 17:42:56 +00:00
|
|
|
self.error(
|
2013-11-13 12:42:24 +00:00
|
|
|
"Parse error in state %s: unexpected token '%s'" % (
|
2013-11-26 17:42:56 +00:00
|
|
|
state, token))
|
2013-11-13 12:42:24 +00:00
|
|
|
if state == AutogenState.done:
|
|
|
|
break
|
|
|
|
|
2013-11-26 17:42:56 +00:00
|
|
|
def read_definitions(self, path):
|
|
|
|
self.cur_file = path
|
|
|
|
with open(path) as f:
|
|
|
|
self.read_definitions_file(f)
|
|
|
|
|
2013-11-13 12:42:24 +00:00
|
|
|
defparser = AutogenParser()
|
|
|
|
|
|
|
|
#
|
|
|
|
# Output
|
|
|
|
#
|
|
|
|
|
|
|
|
outputs = {}
|
|
|
|
|
|
|
|
def output(s, section=''):
|
|
|
|
if s == "":
|
|
|
|
return
|
|
|
|
outputs.setdefault(section, [])
|
|
|
|
outputs[section].append(s)
|
|
|
|
|
|
|
|
def write_output(section=''):
|
|
|
|
for s in outputs.get(section, []):
|
|
|
|
print s,
|
|
|
|
|
2010-05-06 06:04:04 +00:00
|
|
|
#
|
|
|
|
# Global variables
|
|
|
|
#
|
|
|
|
|
|
|
|
def gvar_add(var, value):
|
2013-11-13 12:42:24 +00:00
|
|
|
output(var + " += " + value + "\n")
|
2010-05-06 06:04:04 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Per PROGRAM/SCRIPT variables
|
|
|
|
#
|
|
|
|
|
2013-11-13 12:42:24 +00:00
|
|
|
seen_vars = set()
|
|
|
|
|
|
|
|
def vars_init(defn, *var_list):
|
|
|
|
name = defn['name']
|
|
|
|
|
|
|
|
if name not in seen_target and name not in seen_vars:
|
|
|
|
for var in var_list:
|
|
|
|
output(var + " = \n", section='decl')
|
|
|
|
seen_vars.add(name)
|
2010-09-24 08:48:27 +00:00
|
|
|
|
2010-05-06 06:04:04 +00:00
|
|
|
def var_set(var, value):
|
2013-11-13 12:42:24 +00:00
|
|
|
output(var + " = " + value + "\n")
|
2010-05-06 06:04:04 +00:00
|
|
|
|
|
|
|
def var_add(var, value):
|
2013-11-13 12:42:24 +00:00
|
|
|
output(var + " += " + value + "\n")
|
2010-05-06 06:04:04 +00:00
|
|
|
|
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
# Variable names and rules
|
2010-05-06 06:04:04 +00:00
|
|
|
#
|
|
|
|
|
2013-11-13 12:42:24 +00:00
|
|
|
canonical_name_re = re.compile(r'[^0-9A-Za-z@_]')
|
|
|
|
canonical_name_suffix = ""
|
|
|
|
|
|
|
|
def set_canonical_name_suffix(suffix):
|
|
|
|
global canonical_name_suffix
|
|
|
|
canonical_name_suffix = suffix
|
|
|
|
|
|
|
|
def cname(defn):
|
|
|
|
return canonical_name_re.sub('_', defn['name'] + canonical_name_suffix)
|
2010-05-06 06:04:04 +00:00
|
|
|
|
2010-07-13 18:05:24 +00:00
|
|
|
def rule(target, source, cmd):
|
|
|
|
if cmd[0] == "\n":
|
2013-11-13 12:42:24 +00:00
|
|
|
output("\n" + target + ": " + source + cmd.replace("\n", "\n\t") + "\n")
|
2010-07-13 18:05:24 +00:00
|
|
|
else:
|
2013-11-13 12:42:24 +00:00
|
|
|
output("\n" + target + ": " + source + "\n\t" + cmd.replace("\n", "\n\t") + "\n")
|
2010-05-06 06:04:04 +00:00
|
|
|
|
2010-07-14 20:32:01 +00:00
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
# Handle keys with platform names as values, for example:
|
2010-07-14 20:32:01 +00:00
|
|
|
#
|
|
|
|
# kernel = {
|
|
|
|
# nostrip = emu;
|
2010-07-16 20:02:36 +00:00
|
|
|
# ...
|
2010-07-14 20:32:01 +00:00
|
|
|
# }
|
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
def platform_tagged(defn, platform, tag):
|
|
|
|
for value in defn.find_all(tag):
|
|
|
|
for group in RMAP[platform]:
|
|
|
|
if value == group:
|
|
|
|
return True
|
|
|
|
return False
|
2010-05-06 06:04:04 +00:00
|
|
|
|
2013-11-13 12:42:24 +00:00
|
|
|
def if_platform_tagged(defn, platform, tag, snippet_if, snippet_else=None):
|
|
|
|
if platform_tagged(defn, platform, tag):
|
|
|
|
return snippet_if
|
|
|
|
elif snippet_else is not None:
|
|
|
|
return snippet_else
|
2010-05-06 06:04:04 +00:00
|
|
|
|
2010-07-14 20:32:01 +00:00
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
# Handle tagged values
|
2010-08-21 08:57:31 +00:00
|
|
|
#
|
|
|
|
# module = {
|
|
|
|
# extra_dist = ...
|
|
|
|
# extra_dist = ...
|
|
|
|
# ...
|
|
|
|
# };
|
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
def foreach_value(defn, tag, closure):
|
|
|
|
r = []
|
|
|
|
for value in defn.find_all(tag):
|
|
|
|
r.append(closure(value))
|
|
|
|
return ''.join(r)
|
2010-08-21 08:57:31 +00:00
|
|
|
|
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
# Handle best matched values for a platform, for example:
|
2010-07-14 20:32:01 +00:00
|
|
|
#
|
|
|
|
# module = {
|
|
|
|
# cflags = '-Wall';
|
|
|
|
# emu_cflags = '-Wall -DGRUB_EMU=1';
|
2010-07-16 20:02:36 +00:00
|
|
|
# ...
|
2010-07-14 20:32:01 +00:00
|
|
|
# }
|
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
def foreach_platform_specific_value(defn, platform, suffix, nonetag, closure):
|
|
|
|
r = []
|
2010-07-13 18:05:24 +00:00
|
|
|
for group in RMAP[platform]:
|
2013-11-13 12:42:24 +00:00
|
|
|
values = list(defn.find_all(group + suffix))
|
|
|
|
if values:
|
|
|
|
for value in values:
|
|
|
|
r.append(closure(value))
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
for value in defn.find_all(nonetag):
|
|
|
|
r.append(closure(value))
|
|
|
|
return ''.join(r)
|
2011-10-01 01:49:37 +00:00
|
|
|
|
2010-08-21 08:57:31 +00:00
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
# Handle values from sum of all groups for a platform, for example:
|
2010-08-21 08:57:31 +00:00
|
|
|
#
|
|
|
|
# module = {
|
|
|
|
# common = kern/misc.c;
|
|
|
|
# emu = kern/emu/misc.c;
|
|
|
|
# ...
|
|
|
|
# }
|
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
def foreach_platform_value(defn, platform, suffix, closure):
|
|
|
|
r = []
|
2010-08-21 08:57:31 +00:00
|
|
|
for group in RMAP[platform]:
|
2013-11-13 12:42:24 +00:00
|
|
|
for value in defn.find_all(group + suffix):
|
|
|
|
r.append(closure(value))
|
|
|
|
return ''.join(r)
|
2010-08-21 08:57:31 +00:00
|
|
|
|
2013-11-13 12:42:24 +00:00
|
|
|
def platform_conditional(platform, closure):
|
|
|
|
output("\nif COND_" + platform + "\n")
|
|
|
|
closure(platform)
|
|
|
|
output("endif\n")
|
2010-05-06 06:04:04 +00:00
|
|
|
|
2010-08-21 08:57:31 +00:00
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
# Handle guarding with platform-specific "enable" keys, for example:
|
2010-08-21 08:57:31 +00:00
|
|
|
#
|
|
|
|
# module = {
|
|
|
|
# name = pci;
|
|
|
|
# noemu = bus/pci.c;
|
|
|
|
# emu = bus/emu/pci.c;
|
|
|
|
# emu = commands/lspci.c;
|
|
|
|
#
|
|
|
|
# enable = emu;
|
|
|
|
# enable = i386_pc;
|
|
|
|
# enable = x86_efi;
|
|
|
|
# enable = i386_ieee1275;
|
|
|
|
# enable = i386_coreboot;
|
|
|
|
# };
|
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
def foreach_enabled_platform(defn, closure):
|
|
|
|
if 'enable' in defn:
|
|
|
|
for platform in GRUB_PLATFORMS:
|
|
|
|
if platform_tagged(defn, platform, "enable"):
|
|
|
|
platform_conditional(platform, closure)
|
|
|
|
else:
|
|
|
|
for platform in GRUB_PLATFORMS:
|
|
|
|
platform_conditional(platform, closure)
|
2010-07-14 20:32:01 +00:00
|
|
|
|
2010-08-21 08:57:31 +00:00
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
# Handle guarding with platform-specific automake conditionals, for example:
|
2010-08-21 08:57:31 +00:00
|
|
|
#
|
|
|
|
# module = {
|
|
|
|
# name = usb;
|
|
|
|
# common = bus/usb/usb.c;
|
|
|
|
# noemu = bus/usb/usbtrans.c;
|
|
|
|
# noemu = bus/usb/usbhub.c;
|
|
|
|
# enable = emu;
|
|
|
|
# enable = i386;
|
2011-02-19 12:18:05 +00:00
|
|
|
# enable = mips_loongson;
|
2010-08-21 08:57:31 +00:00
|
|
|
# emu_condition = COND_GRUB_EMU_USB;
|
|
|
|
# };
|
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
def under_platform_specific_conditionals(defn, platform, closure):
|
|
|
|
output(foreach_platform_specific_value(defn, platform, "_condition", "condition", lambda cond: "if " + cond + "\n"))
|
|
|
|
closure(defn, platform)
|
|
|
|
output(foreach_platform_specific_value(defn, platform, "_condition", "condition", lambda cond: "endif " + cond + "\n"))
|
|
|
|
|
|
|
|
def platform_specific_values(defn, platform, suffix, nonetag):
|
|
|
|
return foreach_platform_specific_value(defn, platform, suffix, nonetag,
|
2010-08-21 08:57:31 +00:00
|
|
|
lambda value: value + " ")
|
2010-07-13 18:05:24 +00:00
|
|
|
|
2013-11-13 12:42:24 +00:00
|
|
|
def platform_values(defn, platform, suffix):
|
|
|
|
return foreach_platform_value(defn, platform, suffix, lambda value: value + " ")
|
|
|
|
|
|
|
|
def extra_dist(defn):
|
|
|
|
return foreach_value(defn, "extra_dist", lambda value: value + " ")
|
|
|
|
|
|
|
|
def platform_sources(defn, p): return platform_values(defn, p, "")
|
|
|
|
def platform_nodist_sources(defn, p): return platform_values(defn, p, "_nodist")
|
|
|
|
|
|
|
|
def platform_startup(defn, p): return platform_specific_values(defn, p, "_startup", "startup")
|
|
|
|
def platform_ldadd(defn, p): return platform_specific_values(defn, p, "_ldadd", "ldadd")
|
|
|
|
def platform_dependencies(defn, p): return platform_specific_values(defn, p, "_dependencies", "dependencies")
|
|
|
|
def platform_cflags(defn, p): return platform_specific_values(defn, p, "_cflags", "cflags")
|
|
|
|
def platform_ldflags(defn, p): return platform_specific_values(defn, p, "_ldflags", "ldflags")
|
|
|
|
def platform_cppflags(defn, p): return platform_specific_values(defn, p, "_cppflags", "cppflags")
|
|
|
|
def platform_ccasflags(defn, p): return platform_specific_values(defn, p, "_ccasflags", "ccasflags")
|
|
|
|
def platform_stripflags(defn, p): return platform_specific_values(defn, p, "_stripflags", "stripflags")
|
|
|
|
def platform_objcopyflags(defn, p): return platform_specific_values(defn, p, "_objcopyflags", "objcopyflags")
|
2010-05-06 06:04:04 +00:00
|
|
|
|
2010-09-24 08:48:27 +00:00
|
|
|
#
|
|
|
|
# Emit snippet only the first time through for the current name.
|
|
|
|
#
|
2013-11-13 12:42:24 +00:00
|
|
|
seen_target = set()
|
|
|
|
|
|
|
|
def first_time(defn, snippet):
|
|
|
|
if defn['name'] not in seen_target:
|
|
|
|
return snippet
|
|
|
|
return ''
|
|
|
|
|
2013-11-27 13:06:14 +00:00
|
|
|
def is_platform_independent(defn):
|
|
|
|
if 'enable' in defn:
|
|
|
|
return False
|
|
|
|
for suffix in [ "", "_nodist" ]:
|
|
|
|
template = platform_values(defn, GRUB_PLATFORMS[0], suffix)
|
|
|
|
for platform in GRUB_PLATFORMS[1:]:
|
|
|
|
if template != platform_values(defn, platform, suffix):
|
|
|
|
return False
|
|
|
|
|
|
|
|
for suffix in [ "startup", "ldadd", "dependencies", "cflags", "ldflags", "cppflags", "ccasflags", "stripflags", "objcopyflags", "condition" ]:
|
|
|
|
template = platform_specific_values(defn, GRUB_PLATFORMS[0], "_" + suffix, suffix)
|
|
|
|
for platform in GRUB_PLATFORMS[1:]:
|
|
|
|
if template != platform_specific_values(defn, platform, "_" + suffix, suffix):
|
|
|
|
return False
|
|
|
|
for tag in [ "nostrip" ]:
|
|
|
|
template = platform_tagged(defn, GRUB_PLATFORMS[0], tag)
|
|
|
|
for platform in GRUB_PLATFORMS[1:]:
|
|
|
|
if template != platform_tagged(defn, platform, tag):
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2013-11-13 12:42:24 +00:00
|
|
|
def module(defn, platform):
|
|
|
|
name = defn['name']
|
|
|
|
set_canonical_name_suffix(".module")
|
|
|
|
|
|
|
|
gvar_add("platform_PROGRAMS", name + ".module")
|
|
|
|
gvar_add("MODULE_FILES", name + ".module$(EXEEXT)")
|
|
|
|
|
|
|
|
var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform) + " ## platform sources")
|
|
|
|
var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + " ## platform nodist sources")
|
|
|
|
var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
|
|
|
|
var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_MODULE) " + platform_cflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_MODULE) " + platform_ldflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_MODULE) " + platform_cppflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_MODULE) " + platform_ccasflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_DEPENDENCIES", "$(TARGET_OBJ2ELF) " + platform_dependencies(defn, platform))
|
|
|
|
|
|
|
|
gvar_add("dist_noinst_DATA", extra_dist(defn))
|
|
|
|
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
|
|
|
|
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
|
|
|
|
|
|
|
|
gvar_add("MOD_FILES", name + ".mod")
|
|
|
|
gvar_add("MARKER_FILES", name + ".marker")
|
|
|
|
gvar_add("CLEANFILES", name + ".marker")
|
|
|
|
output("""
|
|
|
|
""" + name + """.marker: $(""" + cname(defn) + """_SOURCES) $(nodist_""" + cname(defn) + """_SOURCES)
|
|
|
|
$(TARGET_CPP) -DGRUB_LST_GENERATOR $(CPPFLAGS_MARKER) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(""" + cname(defn) + """_CPPFLAGS) $(CPPFLAGS) $^ > $@.new || (rm -f $@; exit 1)
|
2010-08-29 15:52:41 +00:00
|
|
|
grep 'MARKER' $@.new > $@; rm -f $@.new
|
2013-11-13 12:42:24 +00:00
|
|
|
""")
|
|
|
|
|
|
|
|
def kernel(defn, platform):
|
|
|
|
name = defn['name']
|
|
|
|
set_canonical_name_suffix(".exec")
|
|
|
|
gvar_add("platform_PROGRAMS", name + ".exec")
|
|
|
|
var_set(cname(defn) + "_SOURCES", platform_startup(defn, platform))
|
|
|
|
var_add(cname(defn) + "_SOURCES", platform_sources(defn, platform))
|
|
|
|
var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + " ## platform nodist sources")
|
|
|
|
var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
|
|
|
|
var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_KERNEL) " + platform_cflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_KERNEL) " + platform_ldflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) " + platform_cppflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_KERNEL) " + platform_ccasflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_STRIPFLAGS", "$(AM_STRIPFLAGS) $(STRIPFLAGS_KERNEL) " + platform_stripflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_DEPENDENCIES", "$(TARGET_OBJ2ELF)")
|
|
|
|
|
|
|
|
gvar_add("dist_noinst_DATA", extra_dist(defn))
|
|
|
|
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
|
|
|
|
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
|
|
|
|
|
|
|
|
gvar_add("platform_DATA", name + ".img")
|
|
|
|
gvar_add("CLEANFILES", name + ".img")
|
|
|
|
rule(name + ".img", name + ".exec$(EXEEXT)",
|
|
|
|
if_platform_tagged(defn, platform, "nostrip",
|
2013-11-14 22:17:18 +00:00
|
|
|
"""if test x$(TARGET_APPLE_LINKER) = x1; then \
|
2013-08-21 23:56:28 +00:00
|
|
|
$(TARGET_OBJCONV) -f$(TARGET_MODULE_FORMAT) -nr:_grub_mod_init:grub_mod_init -nr:_grub_mod_fini:grub_mod_fini -ed2022 -wd1106 -nu -nd $< $@; \
|
2012-02-29 18:07:32 +00:00
|
|
|
elif test ! -z '$(TARGET_OBJ2ELF)'; then \
|
|
|
|
cp $< $@.bin; $(TARGET_OBJ2ELF) $@.bin && cp $@.bin $@ || (rm -f $@.bin; exit 1); \
|
|
|
|
else cp $< $@; fi""",
|
2013-11-14 22:17:18 +00:00
|
|
|
"""if test x$(TARGET_APPLE_LINKER) = x1; then \
|
2013-11-13 12:42:24 +00:00
|
|
|
$(TARGET_STRIP) -S -x $(""" + cname(defn) + """) -o $@.bin $<; \
|
2013-11-25 04:53:20 +00:00
|
|
|
$(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 $@; \
|
2013-11-13 12:42:24 +00:00
|
|
|
else """ + "$(TARGET_STRIP) $(" + cname(defn) + "_STRIPFLAGS) -o $@ $<; \
|
2012-02-29 18:07:32 +00:00
|
|
|
fi"""))
|
2013-11-13 12:42:24 +00:00
|
|
|
|
|
|
|
def image(defn, platform):
|
|
|
|
name = defn['name']
|
|
|
|
set_canonical_name_suffix(".image")
|
|
|
|
gvar_add("platform_PROGRAMS", name + ".image")
|
|
|
|
var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform))
|
|
|
|
var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + "## platform nodist sources")
|
|
|
|
var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
|
|
|
|
var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_IMAGE) " + platform_cflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_IMAGE) " + platform_ldflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_IMAGE) " + platform_cppflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_IMAGE) " + platform_ccasflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_OBJCOPYFLAGS", "$(OBJCOPYFLAGS_IMAGE) " + platform_objcopyflags(defn, platform))
|
|
|
|
# var_set(cname(defn) + "_DEPENDENCIES", platform_dependencies(defn, platform) + " " + platform_ldadd(defn, platform))
|
|
|
|
|
|
|
|
gvar_add("dist_noinst_DATA", extra_dist(defn))
|
|
|
|
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
|
|
|
|
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
|
|
|
|
|
|
|
|
gvar_add("platform_DATA", name + ".img")
|
|
|
|
gvar_add("CLEANFILES", name + ".img")
|
|
|
|
rule(name + ".img", name + ".image$(EXEEXT)", """
|
2013-11-14 22:17:18 +00:00
|
|
|
if test x$(TARGET_APPLE_LINKER) = x1; then \
|
2010-05-06 06:04:04 +00:00
|
|
|
$(MACHO2IMG) $< $@; \
|
|
|
|
else \
|
2013-11-13 12:42:24 +00:00
|
|
|
$(TARGET_OBJCOPY) $(""" + cname(defn) + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version $< $@; \
|
2010-05-06 06:04:04 +00:00
|
|
|
fi
|
|
|
|
""")
|
2013-11-13 12:42:24 +00:00
|
|
|
|
|
|
|
def library(defn, platform):
|
|
|
|
name = defn['name']
|
|
|
|
set_canonical_name_suffix("")
|
|
|
|
|
|
|
|
vars_init(defn,
|
|
|
|
cname(defn) + "_SOURCES",
|
|
|
|
"nodist_" + cname(defn) + "_SOURCES",
|
|
|
|
cname(defn) + "_CFLAGS",
|
|
|
|
cname(defn) + "_CPPFLAGS",
|
|
|
|
cname(defn) + "_CCASFLAGS")
|
|
|
|
# cname(defn) + "_DEPENDENCIES")
|
|
|
|
|
|
|
|
if name not in seen_target:
|
|
|
|
gvar_add("noinst_LIBRARIES", name)
|
|
|
|
var_add(cname(defn) + "_SOURCES", platform_sources(defn, platform))
|
|
|
|
var_add("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform))
|
|
|
|
var_add(cname(defn) + "_CFLAGS", first_time(defn, "$(AM_CFLAGS) $(CFLAGS_LIBRARY) ") + platform_cflags(defn, platform))
|
|
|
|
var_add(cname(defn) + "_CPPFLAGS", first_time(defn, "$(AM_CPPFLAGS) $(CPPFLAGS_LIBRARY) ") + platform_cppflags(defn, platform))
|
|
|
|
var_add(cname(defn) + "_CCASFLAGS", first_time(defn, "$(AM_CCASFLAGS) $(CCASFLAGS_LIBRARY) ") + platform_ccasflags(defn, platform))
|
|
|
|
# var_add(cname(defn) + "_DEPENDENCIES", platform_dependencies(defn, platform) + " " + platform_ldadd(defn, platform))
|
|
|
|
|
|
|
|
gvar_add("dist_noinst_DATA", extra_dist(defn))
|
|
|
|
if name not in seen_target:
|
|
|
|
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
|
|
|
|
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
|
|
|
|
|
|
|
|
def installdir(defn, default="bin"):
|
|
|
|
return defn.get('installdir', default)
|
|
|
|
|
|
|
|
def manpage(defn, adddeps):
|
|
|
|
name = defn['name']
|
|
|
|
mansection = defn['mansection']
|
|
|
|
|
|
|
|
output("if COND_MAN_PAGES\n")
|
|
|
|
gvar_add("man_MANS", name + "." + mansection)
|
|
|
|
rule(name + "." + mansection, name + " " + adddeps, """
|
|
|
|
chmod a+x """ + name + """
|
|
|
|
PATH=$(builddir):$$PATH pkgdatadir=$(builddir) $(HELP2MAN) --section=""" + mansection + """ -i $(top_srcdir)/docs/man/""" + name + """.h2m -o $@ """ + name + """
|
2010-05-06 06:04:04 +00:00
|
|
|
""")
|
2013-11-13 12:42:24 +00:00
|
|
|
gvar_add("CLEANFILES", name + "." + mansection)
|
|
|
|
output("endif\n")
|
|
|
|
|
|
|
|
def program(defn, platform, test=False):
|
|
|
|
name = defn['name']
|
|
|
|
set_canonical_name_suffix("")
|
|
|
|
|
|
|
|
if 'testcase' in defn:
|
|
|
|
gvar_add("check_PROGRAMS", name)
|
|
|
|
gvar_add("TESTS", name)
|
|
|
|
else:
|
|
|
|
var_add(installdir(defn) + "_PROGRAMS", name)
|
|
|
|
if 'mansection' in defn:
|
|
|
|
manpage(defn, "")
|
|
|
|
|
|
|
|
var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform))
|
|
|
|
var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform))
|
|
|
|
var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
|
|
|
|
var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_PROGRAM) " + platform_cflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_PROGRAM) " + platform_ldflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_PROGRAM) " + platform_cppflags(defn, platform))
|
|
|
|
var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_PROGRAM) " + platform_ccasflags(defn, platform))
|
|
|
|
# var_set(cname(defn) + "_DEPENDENCIES", platform_dependencies(defn, platform) + " " + platform_ldadd(defn, platform))
|
|
|
|
|
|
|
|
gvar_add("dist_noinst_DATA", extra_dist(defn))
|
|
|
|
gvar_add("BUILT_SOURCES", "$(nodist_" + cname(defn) + "_SOURCES)")
|
|
|
|
gvar_add("CLEANFILES", "$(nodist_" + cname(defn) + "_SOURCES)")
|
|
|
|
|
|
|
|
def data(defn, platform):
|
|
|
|
var_add("dist_" + installdir(defn) + "_DATA", platform_sources(defn, platform))
|
|
|
|
gvar_add("dist_noinst_DATA", extra_dist(defn))
|
|
|
|
|
|
|
|
def script(defn, platform):
|
|
|
|
name = defn['name']
|
|
|
|
|
|
|
|
if 'testcase' in defn:
|
|
|
|
gvar_add("check_SCRIPTS", name)
|
|
|
|
gvar_add ("TESTS", name)
|
|
|
|
else:
|
|
|
|
var_add(installdir(defn) + "_SCRIPTS", name)
|
|
|
|
if 'mansection' in defn:
|
|
|
|
manpage(defn, "grub-mkconfig_lib")
|
|
|
|
|
|
|
|
rule(name, "$(top_builddir)/config.status " + platform_sources(defn, platform) + platform_dependencies(defn, platform), """
|
|
|
|
(for x in """ + platform_sources(defn, platform) + """; do cat $(srcdir)/"$$x"; done) | $(top_builddir)/config.status --file=$@:-
|
|
|
|
chmod a+x """ + name + """
|
2010-05-06 06:04:04 +00:00
|
|
|
""")
|
|
|
|
|
2013-11-13 12:42:24 +00:00
|
|
|
gvar_add("CLEANFILES", name)
|
|
|
|
gvar_add("EXTRA_DIST", extra_dist(defn))
|
|
|
|
gvar_add("dist_noinst_DATA", platform_sources(defn, platform))
|
2010-05-06 06:04:04 +00:00
|
|
|
|
2010-09-24 08:48:27 +00:00
|
|
|
def rules(target, closure):
|
2013-11-13 12:42:24 +00:00
|
|
|
seen_target.clear()
|
|
|
|
seen_vars.clear()
|
|
|
|
|
|
|
|
for defn in defparser.definitions.find_all(target):
|
2013-11-27 13:06:14 +00:00
|
|
|
if is_platform_independent(defn):
|
|
|
|
under_platform_specific_conditionals(defn, GRUB_PLATFORMS[0], closure)
|
|
|
|
else:
|
|
|
|
foreach_enabled_platform(
|
|
|
|
defn,
|
|
|
|
lambda p: under_platform_specific_conditionals(defn, p, closure))
|
2013-11-13 12:42:24 +00:00
|
|
|
# Remember that we've seen this target.
|
|
|
|
seen_target.add(defn['name'])
|
|
|
|
|
|
|
|
parser = OptionParser(usage="%prog DEFINITION-FILES")
|
|
|
|
_, args = parser.parse_args()
|
|
|
|
|
|
|
|
for arg in args:
|
2013-11-26 17:42:56 +00:00
|
|
|
defparser.read_definitions(arg)
|
2013-11-13 12:42:24 +00:00
|
|
|
|
|
|
|
rules("module", module)
|
|
|
|
rules("kernel", kernel)
|
|
|
|
rules("image", image)
|
|
|
|
rules("library", library)
|
|
|
|
rules("program", program)
|
|
|
|
rules("script", script)
|
|
|
|
rules("data", data)
|
|
|
|
|
|
|
|
write_output(section='decl')
|
|
|
|
write_output()
|