#
# This is the python script used to generate Makefile.tpl
#
"i386_multiboot", "i386_ieee1275", "x86_64_efi",
"mips_loongson", "sparc64_ieee1275",
"powerpc_ieee1275", "mips_arc", "ia64_efi",
"mips_qemu_mips" ]
GROUPS = {}
# Groups based on CPU
GROUPS["i386"] = [ "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot", "i386_multiboot", "i386_ieee1275" ]
# Groups based on firmware
# emu is a special case so many core functionality isn't needed on this platform
# Groups based on hardware features
"sparc64_ieee1275", "powerpc_ieee1275"]
# If gfxterm is main output console integrate it into kernel
# Similar for terminfo
# Miscelaneous groups schedulded to disappear in future
#
# 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
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
# insert in the middle
#
# Global variables
#
def global_variable_initializers():
r = ""
r += var + " ?= \n"
return r
#
#
r = "[+ IF (if (not (assoc-ref seen-vars (get \".name\"))) \"seen\") +]"
r += "[+ (out-suspend \"v\") +]"
r += var + " = \n"
r += "[+ (out-resume \"v\") +]"
r += "[+ (set! seen-vars (assoc-set! seen-vars (get \".name\") 0)) +]"
r += "[+ ENDIF +]"
return first_time(r)
#
# Autogen constructs
#
def set_canonical_name_suffix(suffix): return "[+ % name `export cname=$(echo %s" + suffix + " | sed -e 's/[^0-9A-Za-z@_]/_/g')` +]"
else:
#
# Template for keys with platform names as values, for example:
#
# kernel = {
# nostrip = emu;
# ...
# }
#
r = ""
r += "[+ ESAC +][+ ENDFOR +]"
if snippet_else == None:
r += "[+ ENDIF +]"
return r
return r
#
# Template for tagged values
#
# module = {
# extra_dist = ...
# extra_dist = ...
# ...
# };
#
#
# Template for handling best matched values for a platform, for example:
#
# module = {
# cflags = '-Wall';
# emu_cflags = '-Wall -DGRUB_EMU=1';
# ...
# }
#
r = ""
else:
r += "[+ ELSE +][+ FOR " + nonetag + " +]" + closure("[+ ." + nonetag + " +]") + "[+ ENDFOR +][+ ENDIF +]"
return r
#
# Returns autogen code that defines an autogen macro using the
# definition given in the 'snippet'.
#
r = ""
r += snippet
r += "[+ ENDDEF +]\n"
return r
#
# Template for handling values from sum of all groups for a platform,
# for example:
#
# module = {
# ...
# }
#
r = ""
r += "[+ ENDIF +]"
return r
#
# Template for gaurding with platform specific "enable" keys, for example:
#
# module = {
# name = pci;
#
# enable = emu;
# enable = i386_pc;
# enable = x86_efi;
# enable = i386_ieee1275;
# enable = i386_coreboot;
# };
#
r = "[+ IF - enable undefined +]"
for platform in GRUB_PLATFORMS:
r += "[+ ELSE +]"
for platform in GRUB_PLATFORMS:
r += "[+ ENDIF +]"
return r
#
# Template for gaurding with platform specific automake conditionals,
# for example:
#
# module = {
# name = usb;
# noemu = bus/usb/usbtrans.c;
# enable = emu;
# enable = i386;
# enable = mips_loongson;
# emu_condition = COND_GRUB_EMU_USB;
# };
#
return define_autogen_macro(
"if_" + p + "_conditionals",
foreach_platform_specific_value(platform, "_condition", "condition", lambda cond: "if " + cond + "\n"))
return define_autogen_macro(
"endif_" + p + "_conditionals",
foreach_platform_specific_value(platform, "_condition", "condition", lambda cond: "endif " + cond + "\n"))
r += snippet
return r
def extra_dist():
return define_autogen_macro(
"get_" + p + "_sources",
platform_values(p, ""))
return define_autogen_macro(
"get_" + p + "_nodist_sources",
platform_values(p, "_nodist"))
return define_autogen_macro(
"get_" + p + "_dependencies",
#
# Returns Autogen code which defines the autogen macros that collect
# platform specific values for cflags, ldflags, etc. tags.
#
return define_autogen_macro(
"get_" + p + "_startup",
def define_macro_for_platform_cflags(p):
return define_autogen_macro(
"get_" + p + "_cflags",
def define_macro_for_platform_ldadd(p):
return define_autogen_macro(
"get_" + p + "_ldadd",
return define_autogen_macro(
"get_" + p + "_ldflags",
return define_autogen_macro(
"get_" + p + "_cppflags",
return define_autogen_macro(
"get_" + p + "_ccasflags",
return define_autogen_macro(
"get_" + p + "_stripflags",
return define_autogen_macro(
"get_" + p + "_objcopyflags",
#
# Autogen calls to invoke the above macros.
#
#
# Emit snippet only the first time through for the current name.
#
r = "[+ IF (if (not (assoc-ref seen-target (get \".name\"))) \"seen\") +]"
r += snippet
r += "[+ ENDIF +]"
return r
r = set_canonical_name_suffix(".module")
r += var_set("nodist_" + cname() + "_SOURCES", platform_nodist_sources(platform) + " ## platform nodist sources")
r += var_set(cname() + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_MODULE) " + platform_cppflags(platform))
r += var_set(cname() + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_MODULE) " + platform_ccasflags(platform))
# r += var_set(cname() + "_DEPENDENCIES", platform_dependencies(platform) + " " + platform_ldadd(platform))
r += """
$(TARGET_CPP) -DGRUB_LST_GENERATOR $(CPPFLAGS_MARKER) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(""" + cname() + """_CPPFLAGS) $(CPPFLAGS) $^ > $@.new || (rm -f $@; exit 1)
grep 'MARKER' $@.new > $@; rm -f $@.new
"""
return r
r = set_canonical_name_suffix(".exec")
r += var_set("nodist_" + cname() + "_SOURCES", platform_nodist_sources(platform) + " ## platform nodist sources")
r += var_set(cname() + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) " + platform_cppflags(platform))
r += var_set(cname() + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_KERNEL) " + platform_ccasflags(platform))
r += var_set(cname() + "_STRIPFLAGS", "$(AM_STRIPFLAGS) $(STRIPFLAGS_KERNEL) " + platform_stripflags(platform))
# r += var_set(cname() + "_DEPENDENCIES", platform_dependencies(platform) + " " + platform_ldadd(platform))
"""if test x$(TARGET_SOLARIS_LD) = x1; then \
cp $< $@; \
$(MCS_KERNEL) $@; \
return r
r = set_canonical_name_suffix(".image")
r += var_set("nodist_" + cname() + "_SOURCES", platform_nodist_sources(platform) + "## platform nodist sources")
r += var_set(cname() + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_IMAGE) " + platform_cppflags(platform))
r += var_set(cname() + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_IMAGE) " + platform_ccasflags(platform))
# r += var_set(cname() + "_DEPENDENCIES", platform_dependencies(platform) + " " + platform_ldadd(platform))
if test x$(USE_APPLE_CC_FIXES) = xyes; then \
$(MACHO2IMG) $< $@; \
else \
$(OBJCOPY) $(""" + cname() + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .interp -R .dynamic -R .hash -R .SUNW_ldynsym -R .dynsym -R .dynstr -R .SUNW_dynsymsort $< $@; \
fi
""")
return r
r = set_canonical_name_suffix("")
cname() + "_CFLAGS",
cname() + "_CPPFLAGS",
cname() + "_CCASFLAGS")
# cname() + "_DEPENDENCIES")
r += var_add(cname() + "_CFLAGS", first_time("$(AM_CFLAGS) $(CFLAGS_LIBRARY) ") + platform_cflags(platform))
r += var_add(cname() + "_CPPFLAGS", first_time("$(AM_CPPFLAGS) $(CPPFLAGS_LIBRARY) ") + platform_cppflags(platform))
r += var_add(cname() + "_CCASFLAGS", first_time("$(AM_CCASFLAGS) $(CCASFLAGS_LIBRARY) ") + platform_ccasflags(platform))
# r += var_add(cname() + "_DEPENDENCIES", platform_dependencies(platform) + " " + platform_ldadd(platform))
return r
def manpage():
r = "if COND_MAN_PAGES\n"
chmod a+x [+ name +]
PATH=$(builddir):$$PATH $(HELP2MAN) --section=[+ mansection +] -i $(top_srcdir)/docs/man/[+ name +].h2m -o $@ [+ name +]
""")
r += "endif\n"
return r
r = set_canonical_name_suffix("")
r += "[+ IF testcase defined +]"
r += "[+ ELSE +]"
r += "[+ ENDIF +]"
r += var_set(cname() + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_PROGRAM) " + platform_ldflags(platform))
r += var_set(cname() + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_PROGRAM) " + platform_cppflags(platform))
r += var_set(cname() + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_PROGRAM) " + platform_ccasflags(platform))
# r += var_set(cname() + "_DEPENDENCIES", platform_dependencies(platform) + " " + platform_ldadd(platform))
return r
return r
r = "[+ IF testcase defined +]"
r += "[+ ELSE +]"
r += "[+ ENDIF +]"
$(top_builddir)/config.status --file=-:$< | sed -e 's,@pkglib_DATA@,$(pkglib_DATA),g' > $@
chmod a+x [+ name +]
""")
return r
# Create association lists for the benefit of first_time and vars_init.
r = "[+ (define seen-target '()) +]"
r += "[+ (define seen-vars '()) +]"
# Most output goes to a diversion. This allows us to emit variable
# initializations before everything else.
r += "[+ (out-push-new) +]"
r += foreach_enabled_platform(
lambda p: under_platform_specific_conditionals(p, closure(p)))
# Remember that we've seen this target.
r += "[+ (set! seen-target (assoc-set! seen-target (get \".name\") 0)) +]"
r += "[+ ENDFOR +]"
r += "[+ (out-pop #t) +]"
return r
def module_rules():
def kernel_rules():
def image_rules():
def library_rules():
def program_rules():
def script_rules():
def data_rules():
a = module_rules()
b = kernel_rules()
c = image_rules()
d = library_rules()
e = program_rules()
f = script_rules()
g = data_rules()
print ("[+ AutoGen5 template +]\n")
for p in GRUB_PLATFORMS:
print (define_macro_for_platform_sources(p))
print (define_macro_for_platform_nodist_sources(p))
# print define_macro_for_platform_dependencies(p)
print (define_macro_for_platform_startup(p))
print (define_macro_for_platform_cflags(p))
print (define_macro_for_platform_ldadd(p))
print (define_macro_for_platform_ldflags(p))
print (define_macro_for_platform_cppflags(p))
print (define_macro_for_platform_ccasflags(p))
print (define_macro_for_platform_stripflags(p))
print (define_macro_for_platform_objcopyflags(p))
# print z # initializer for all vars
print (a)
print (b)
print (c)
print (d)
print (e)
print (f)
print (g)