From 1b1387493fefd2da060bafd3086f77e7f3097666 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Thu, 3 Apr 2008 10:54:00 +0000 Subject: [PATCH] Added OMK_RULES_TYPE variable This variable is automatically generated by the omkbuild.py on top of the Makefile.rules. Its value is the name of rules target. It can be used for example in config.target to distinguish between targets. darcs-hash:20080403105414-f2ef6-acb33cb34ac1dc08ed93ad57d7978c7761bac647.gz --- doc/omk-manual.texinfo | 8 ++++++++ omkbuild.py | 38 +++++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/doc/omk-manual.texinfo b/doc/omk-manual.texinfo index db8e9e8..4afdd86 100644 --- a/doc/omk-manual.texinfo +++ b/doc/omk-manual.texinfo @@ -815,6 +815,14 @@ path to the directory containing @file{Makefile.rules} currently used during compilation. @end defvar +@defvar{OMK_RULES_TYPE} +Identification the type of @file{Makefile.rules} used for +compilation. Values are like @samp{linux}, @samp{rtems}, @samp{sysless}, +... This variable is automatically generated during creation of +@file{Makefile.rules} and can be used in configuration files (see +@ref{Configuration and Conditional Compilation}) or in +@file{Makefile.omk} to tweak compilation for specific targets. +@end defvar @node Properties of Specific Makefile.rules, Running OMK under Windows OS, Advanced OMK Features, OMK User's Manual @section Properties of Specific Makefile.rules diff --git a/omkbuild.py b/omkbuild.py index 52cb54f..facccc2 100755 --- a/omkbuild.py +++ b/omkbuild.py @@ -13,9 +13,9 @@ Snippet syntax: documentation := comment* rules ::= text - comment ::= '#' text - empty-comment ::= '#' - text ::= [^#] ... + comment ::= '#' text '\n' + empty-comment ::= '#' '\n' + text ::= [^#] ... '\n' Makefile.rules policies: @@ -25,8 +25,8 @@ Snippet syntax: * On the first line of each part of the Makefile.rules, there is special mark of the form #OMK@. This mark is used for splitting modified Makefile.rules back to the - original snippets. - + original snippets. If starts with __, it is + ignored during splitting. """ from optparse import OptionParser @@ -44,6 +44,11 @@ class LineList(list): def getDiff(self, other): s = '' for i in range(len(self)): + if i >= len(other): + s += (" Line %d differs!\n" % i) + s += " -"+self[i].rstrip() + "\n" + s += " +\n" + break if self[i] != other[i]: s += (" Line %d differs!\n" % i) s += " -"+self[i].rstrip() + "\n" @@ -68,10 +73,10 @@ class LineList(list): f.close class Snippet: - def __init__(self, fname = None): + def __init__(self, fname = None, name = ""): """Initializes the snippet and if fname is given, reads it from file""" - self.name = "" + self.name = name self.legal = LineList() self.doc = LineList() self.code = LineList() @@ -86,6 +91,9 @@ class Snippet: f.close + def addCodeLine(self, line): + self.code.append(line) + def readLines(self, lines): """Parses the snippet given as a list and stores it in itself.""" currentPart = self.legal @@ -181,6 +189,7 @@ class Snippets: assert isinstance(other, Snippets) s = '' for snip in self: + if (snip.name[0:2] == '__'): continue if (snip != other[snip.name]): s += "Snippet %s:\n" % snip.name s += snip.getDiff(other[snip.name]) @@ -225,8 +234,10 @@ class MakefileRules(LineList): if not snipName in snipDict: snipDict[snipName] = LineList() currentLinesList = snipDict[snipName] - - currentLinesList.append(line); + + if currentLinesList != None: + currentLinesList.append(line); + return snipDict @@ -247,8 +258,11 @@ def parseCommandLine(): (options, args) = parser.parse_args() return options, args -def buildRules(fnames, output): +def buildRules(fnames, output, name): rules = MakefileRules() + snip_rule_type = Snippet(name="__type") + snip_rule_type.addCodeLine("OMK_RULES_TYPE=%s\n" % name) + rules.snippets += snip_rule_type rules.snippets.loadFromFiles(fnames) rules.combine() @@ -285,6 +299,8 @@ def splitRules(rulesFN, output): # sys.exit(1) for snip in rules.snippets: + if snip.name[0:2] == "__": + continue print snip.name f = None if output == "-": f = sys.stdout @@ -299,7 +315,7 @@ def buildAllRules(): print 'Building rules: %s' % rules outputDir = os.path.join(sys.path[0], rulesDir, rules) if not os.path.isdir(outputDir): os.makedirs(outputDir) - buildRules(rulesdef.rules[rules], os.path.join(outputDir, 'Makefile.rules')) + buildRules(rulesdef.rules[rules], os.path.join(outputDir, 'Makefile.rules'), rules) def main(): (options, args) = parseCommandLine() -- 2.39.2