]> rtime.felk.cvut.cz Git - omk.git/blobdiff - omkbuild.py
Allow to specify libraries which should be used be included into shared library.
[omk.git] / omkbuild.py
index 5dc7c3a9982ee996cfc89a5799c39f50217655f6..52cb54fc2105b61456f1e47006d5a879d787d10c 100755 (executable)
@@ -23,18 +23,22 @@ Snippet syntax:
      as they are in snippets i.e. copyrights, documentations and rules.
 
    * On the first line of each part of the Makefile.rules, there is
-     special mart of the form #OMK@<snippet file name><EOL>. This mark
-     is used for splitting Makefile.rules back to the original
-     snippets.
+     special mark of the form #OMK@<snippet file name><EOL>. This mark
+     is used for splitting modified Makefile.rules back to the
+     original snippets.
 
 """
 
 from optparse import OptionParser
 import os
+import os.path
 import sys
 import string
 import re
 
+rulesDir = "rules"
+snippetsDir = "snippets"
+
 class LineList(list):
     """List of text lines"""
     def getDiff(self, other):
@@ -54,8 +58,13 @@ class LineList(list):
 
     def loadFromFile(self, fname):
         """Loads itself from file."""
-        f = open(fname, "r")
-        self.expand(f.readlines())
+        try:
+            f = open(fname, "r")
+        except IOError:
+            sys.stderr.write("Cannot open %s\n" % fname)
+            sys.exit(1)
+            
+        self.extend(f.readlines())
         f.close
 
 class Snippet:
@@ -231,7 +240,10 @@ def parseCommandLine():
                       help="Split given Makefile.rules to the original snippets")
     parser.add_option("-o", "--output",
                       action="store", dest="output", default=False, metavar="RULES",
-                      help="Output built Makefile.rules to file RULES")
+                      help="Write Makefile.rules to file RULES")
+    parser.add_option("-a", "--all",
+                      action="store_true", dest="all",
+                      help="Rebuild all rules acording to rulesdef.py")
     (options, args) = parser.parse_args()
     return options, args
 
@@ -264,17 +276,36 @@ def splitRules(rulesFN, output):
     rulesCheck.snippets = rules.snippets
     rulesCheck.combine()
 
-    if rules.rules != rulesCheck.rules:
-        sys.stderr.write("Consistency error:\n")
-        diff = rules.rules.getDiff(rulesCheck.rules)
-        sys.stderr.write(diff)
-        sys.exit(1)
-
-    #TODO: Store snippets to files
+    # The comparsion is not that simple. The order of rules might be
+    # different.
+#     if rules.rules != rulesCheck.rules:
+#         sys.stderr.write("Consistency error:\n")
+#         diff = rules.rules.getDiff(rulesCheck.rules)
+#         sys.stderr.write(diff)
+#         sys.exit(1)
+
+    for snip in rules.snippets:
+        print snip.name
+        f = None
+        if output == "-": f = sys.stdout
+        else: f = open(snip.name, "w+")
+        f.writelines(snip.asLinesList())
+        f.close()
+
+def buildAllRules():
+    import rulesdef
+    os.chdir(snippetsDir)
+    for rules in rulesdef.rules:
+        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'))
 
 def main():
     (options, args) = parseCommandLine()
-    if options.split:
+    if options.all:
+        buildAllRules()
+    elif options.split:
         splitRules(options.split, options.output)
     else:
         buildRules(args, options.output)