]> rtime.felk.cvut.cz Git - omk.git/commitdiff
Merge branch 'devel-cherrypick'
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 19 Feb 2009 08:16:09 +0000 (09:16 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 19 Feb 2009 08:16:09 +0000 (09:16 +0100)
25 files changed:
Makefile
omkbuild.py
rulesdef.py [deleted file]
snippets/Makefile
snippets/Makefile.rules.linux [new file with mode: 0644]
snippets/Makefile.rules.rtems [new file with mode: 0644]
snippets/Makefile.rules.sdcc [new file with mode: 0644]
snippets/Makefile.rules.sysless [new file with mode: 0644]
snippets/Makefile.rules.sysless-keil16x [new file with mode: 0644]
snippets/Makefile.rules.sysless-keil51 [new file with mode: 0644]
snippets/Makefile.rules.vxworks [new file with mode: 0644]
snippets/base.omk [moved from snippets/base with 99% similarity]
snippets/config_h.omk [moved from snippets/config_h with 98% similarity]
snippets/gcc.omk [moved from snippets/gcc with 99% similarity]
snippets/include.omk [moved from snippets/include with 98% similarity]
snippets/keil16x.omk [moved from snippets/keil16x with 99% similarity]
snippets/keil51.omk [moved from snippets/keil51 with 99% similarity]
snippets/linux.omk [moved from snippets/linux with 99% similarity]
snippets/localeval.omk [moved from snippets/localeval with 84% similarity]
snippets/qt.omk [moved from snippets/qt with 97% similarity]
snippets/rtems.omk [moved from snippets/rtems with 99% similarity]
snippets/sdcc.omk [moved from snippets/sdcc with 99% similarity]
snippets/sources-list.omk [moved from snippets/sources-list with 98% similarity]
snippets/sysless.omk [moved from snippets/sysless with 99% similarity]
snippets/vxworks.omk [moved from snippets/vxworks with 99% similarity]

index ef2541eda365d3d33f6f9fdca9c9357ab1d360c3..4c2f7261a468eb23071a5f8031bc181b806bcd5d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,12 +4,10 @@
 all: buildrules
 
 buildrules:
-       chmod +x omkbuild.py
-       ./omkbuild.py --all
+       $(MAKE) -C snippets $@
 
 split:
-       chmod +x omkbuild.py
-       cd snippets; ../omkbuild.py --split=../Makefile.rules
+       $(MAKE) -C snippets $@ RULES_TO_SPLIT=../Makefile.rules
 
 test tests:
        $(MAKE) -C tests
index facccc21d39e42edc433f298a85e9480ef6c5cb5..f4095637e98d59985aa3ad53198f5566002ca35e 100755 (executable)
@@ -23,10 +23,16 @@ 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 mark of the form #OMK@<snippet file name><EOL>. This mark
-     is used for splitting modified Makefile.rules back to the
-     original snippets. If <snippet file name> starts with __, it is
-     ignored during splitting.
+     special mark of the form:
+
+       #OMK:<snippet file name>[@<included from snippet>]<EOL>
+
+     This mark is used for splitting modified Makefile.rules back to
+     the original snippets. If <snippet file name> starts with __, it
+     is ignored during splitting.
+
+   * Toplevel snippet has name in the forb Makefile.rules.* and no
+     other (included) snippet has such name.
 """
 
 from optparse import OptionParser
@@ -103,11 +109,15 @@ class Snippet:
             if currentPart == self.legal:
                 if line.strip() == "#": counter += 1
                 else: counter = 0
-                if counter == 2: currentPart = self.doc
             if line[0] != "#": currentPart = self.code
 
             currentPart.append(line)
 
+            if counter == 2:
+                currentPart = self.doc
+                counter = 0
+
+
         if not self.doc:
             self.doc = self.legal
             self.legal = LineList()
@@ -195,24 +205,71 @@ class Snippets:
                 s += snip.getDiff(other[snip.name])
         return s
 
+# Include directoves matching this r.e. will be replaced by this script
+reInclude = re.compile("^include ([^ ]*) #omkbuild")
+
 class MakefileRules(LineList):
     def __init__(self):
         self.snippets = Snippets()
         self.rules = LineList()
 
-    def combine(self):
-        """Combine self.snippets and produces self.rules"""
+    def _includeSnippets(self, filename, baseFileName="", onlyLoadSnippets=False):
+        """Recursively traverses snippets according to include
+        directives. If onlyLoadSnippets is True, self.rules is not
+        modified ..."""
+
+        if onlyLoadSnippets:
+            if filename in self.snippets:
+                sys.stderr.write("Error: Snippet included more than once\n")
+                # This is not allowed becouse it would cause problems
+                # during spliting
+                sys.exit(1)
+            self.snippets += Snippet(filename)
+
+        lines = self.snippets[filename]['code']
+
+        addMarker = 1 # The first line of the snippet should be marked
+        for line in lines:
+            match = reInclude.match(line)
+            if match:
+                # Include other snippet
+                self._includeSnippets(match.group(1).strip(),\
+                                      filename,
+                                      onlyLoadSnippets)
+                addMarker = 2 # The next line after include should be marked
+            else:
+                # Add this line to rules
+                if addMarker:
+                    if addMarker==1:
+                        line = string.rstrip(line).ljust(80)+" #OMK:%s@%s\n"%(filename,baseFileName)
+                    elif addMarker==2:
+                        line = string.rstrip(line).ljust(80)+" #OMK:%s\n"%(filename)
+                    addMarker = 0
+                if not onlyLoadSnippets:
+                    self.rules += [line]
+
+    def combineFrom(self, topLevelSnippet, onlyCheck=False):
+        """Produces self.rules from the topLevelSnippet and all
+        snippets included directly or indirectly from it."""
         self.rules = LineList()
 
-        for type in ['legal', 'doc', 'code']:
+        if not onlyCheck:
+            self._includeSnippets(topLevelSnippet, onlyLoadSnippets=True)
+
+        # Append legal and doc parts
+        for type in ['legal', 'doc']:
             for snip in self.snippets:
                 lines = snip[type]
                 if len(lines) == 0: continue
                 firstLine = string.rstrip(lines[0])
-                self.rules += [firstLine.ljust(60)+" #OMK@%s\n"%snip.name]
+                self.rules += [firstLine.ljust(80)+" #OMK:%s\n"%snip.name]
                 self.rules += lines[1:]
                 #self.rules += ['a'] # test error
 
+        # Append code parts
+        self._includeSnippets(topLevelSnippet)
+
+
     def split(self):
         """Split self.rules to the original snippets in self.snippets."""
         self.snippets = Snippets()
@@ -222,7 +279,7 @@ class MakefileRules(LineList):
     def _getSnipDicts(self):
         """Split self.rules to the original snippets, which are
         returened as dictionary of LineLists."""
-        snipBegin = re.compile("^(.*)#OMK@(.*)$")
+        snipBegin = re.compile("^(.*)#OMK:([^@]*)(?:@(.*))?\n$")
         snipDict = dict()
         currentLinesList = None
 
@@ -231,6 +288,11 @@ class MakefileRules(LineList):
             if match:
                 line = match.group(1).rstrip() + "\n"
                 snipName = match.group(2)
+                includedFrom = match.group(3)
+                if includedFrom:
+                    if not includedFrom in snipDict: snipDict[includedFrom] = LineList()
+                    snipDict[includedFrom].append("include %s #omkbuild\n" % snipName);
+
                 if not snipName in snipDict:
                     snipDict[snipName] = LineList()
                 currentLinesList = snipDict[snipName]
@@ -243,7 +305,7 @@ class MakefileRules(LineList):
 
 def parseCommandLine():
     parser = OptionParser(usage = """
-    %prog [-o FILE] snippet1 snippet2 ...      build Makefile.rules from snippets
+    %prog [-o FILE] top-level-snippet      build Makefile.rules from the top-level-snippet and included ones
     %prog [-o - ] -s Makfile.rules
     """)
     parser.add_option("-s", "--split",
@@ -252,19 +314,15 @@ def parseCommandLine():
     parser.add_option("-o", "--output",
                       action="store", dest="output", default=False, metavar="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()
+    if len(args) > 1:
+        parser.print_help()
+        sys.exit(1)
     return options, args
 
-def buildRules(fnames, output, name):
+def buildRules(topLevelSnippet, output):
     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()
+    rules.combineFrom(topLevelSnippet)
 
     rulesCheck = MakefileRules()
     rulesCheck.rules = rules.rules
@@ -276,7 +334,10 @@ def buildRules(fnames, output, name):
         sys.stderr.write(diff)
         sys.exit(1)
         
-    if output: f = open(output,"w+")
+    if output:
+        try: os.makedirs(os.path.dirname(output))
+        except: pass
+        f = open(output,"w+")
     else: f = sys.stdout
     f.writelines(rules.rules)
     f.close()
@@ -288,10 +349,19 @@ def splitRules(rulesFN, output):
 
     rulesCheck = MakefileRules()
     rulesCheck.snippets = rules.snippets
-    rulesCheck.combine()
+
+    topLevelSnippet = None
+    for snip in rules.snippets:
+        if snip.name.startswith("Makefile.rules."):
+            topLevelSnippet = snip.name
+    if not topLevelSnippet:
+        sys.stderr.write("No toplevel snippet (Makefile.rules.*) found\n")
+        sys.exit(1)
+        
+    rulesCheck.combineFrom(topLevelSnippet, onlyCheck=True)
 
     # The comparsion is not that simple. The order of rules might be
-    # different.
+    # different. FIXME: Is this still true?
 #     if rules.rules != rulesCheck.rules:
 #         sys.stderr.write("Consistency error:\n")
 #         diff = rules.rules.getDiff(rulesCheck.rules)
@@ -308,23 +378,12 @@ def splitRules(rulesFN, output):
         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'), rules)
-
 def main():
     (options, args) = parseCommandLine()
-    if options.all:
-        buildAllRules()
-    elif options.split:
+    if options.split:
         splitRules(options.split, options.output)
     else:
-        buildRules(args, options.output)
+        buildRules(args[0], options.output)
 
 
 if __name__ == "__main__": main()
diff --git a/rulesdef.py b/rulesdef.py
deleted file mode 100755 (executable)
index 6ab6374..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-rules = {
-    'sysless': [ 'base', 'gcc', 'include', 'sysless', 'config_h', 'sources-list', 'localeval' ],
-    'sysless-keil51': [ 'base', 'keil51', 'include', 'sysless', 'config_h', 'sources-list', 'localeval' ],
-    'sysless-keil16x': [ 'base', 'keil16x', 'include', 'sysless', 'config_h', 'sources-list', 'localeval' ],
-    'linux':   [ 'base', 'include', 'linux', 'config_h', 'qt', 'sources-list' ],
-    'rtems':   [ 'base', 'include', 'rtems', 'config_h', 'sources-list' ],
-    'sdcc':    [ 'base', 'include', 'sdcc', 'config_h', 'sources-list', 'localeval' ],
-    'vxworks':   [ 'base', 'include', 'vxworks', 'config_h', 'sources-list' ],
-    }
index 409b863e3b07831194a468345835702293e7a013..b4ed27939d52635debc33ac60f825f51eea0d037 100644 (file)
@@ -1,2 +1,20 @@
-all:
-       $(MAKE) -C ..
\ No newline at end of file
+all: buildrules
+
+.PHONY: FORCE
+
+version := $(patsubst v%,%,$(shell git describe))
+
+../rules/%/Makefile.rules: Makefile.rules.% FORCE
+       python ../omkbuild.py -o $@.tmp $<
+       sed -i -e "s/@git-describe@/$(version)/g" $@.tmp
+       mv $@.tmp $@
+
+TOP_LEVEL_SNIPPETS = $(filter-out %~,$(wildcard Makefile.rules.*))
+RULE_TYPES = $(TOP_LEVEL_SNIPPETS:Makefile.rules.%=%)
+
+buildrules: $(RULE_TYPES:%=../rules/%/Makefile.rules)
+
+RULES_TO_SPLIT ?= Makefile.rules
+
+split:
+       python ../omkbuild.py --split=$(RULES_TO_SPLIT)
diff --git a/snippets/Makefile.rules.linux b/snippets/Makefile.rules.linux
new file mode 100644 (file)
index 0000000..761b1e8
--- /dev/null
@@ -0,0 +1,7 @@
+OMK_RULES_TYPE=linux
+include base.omk #omkbuild
+include include.omk #omkbuild
+include linux.omk #omkbuild
+include config_h.omk #omkbuild
+include qt.omk #omkbuild
+include sources-list.omk #omkbuild
diff --git a/snippets/Makefile.rules.rtems b/snippets/Makefile.rules.rtems
new file mode 100644 (file)
index 0000000..231865f
--- /dev/null
@@ -0,0 +1,6 @@
+OMK_RULES_TYPE=rtems
+include base.omk #omkbuild
+include include.omk #omkbuild
+include rtems.omk #omkbuild
+include config_h.omk #omkbuild
+include sources-list.omk #omkbuild
diff --git a/snippets/Makefile.rules.sdcc b/snippets/Makefile.rules.sdcc
new file mode 100644 (file)
index 0000000..231c9aa
--- /dev/null
@@ -0,0 +1,7 @@
+OMK_RULES_TYPE=sdcc
+include base.omk #omkbuild
+include include.omk #omkbuild
+include sdcc.omk #omkbuild
+include config_h.omk #omkbuild
+include sources-list.omk #omkbuild
+include localeval.omk #omkbuild
diff --git a/snippets/Makefile.rules.sysless b/snippets/Makefile.rules.sysless
new file mode 100644 (file)
index 0000000..3b6162d
--- /dev/null
@@ -0,0 +1,8 @@
+OMK_RULES_TYPE=sysless
+include base.omk #omkbuild
+include gcc.omk #omkbuild
+include include.omk #omkbuild
+include sysless.omk #omkbuild
+include config_h.omk #omkbuild
+include sources-list.omk #omkbuild
+include localeval.omk #omkbuild
diff --git a/snippets/Makefile.rules.sysless-keil16x b/snippets/Makefile.rules.sysless-keil16x
new file mode 100644 (file)
index 0000000..edad220
--- /dev/null
@@ -0,0 +1,8 @@
+OMK_RULES_TYPE=sysless-keil16x
+include base.omk #omkbuild
+include keil16x.omk #omkbuild
+include include.omk #omkbuild
+include sysless.omk #omkbuild
+include config_h.omk #omkbuild
+include sources-list.omk #omkbuild
+include localeval.omk #omkbuild
diff --git a/snippets/Makefile.rules.sysless-keil51 b/snippets/Makefile.rules.sysless-keil51
new file mode 100644 (file)
index 0000000..2afaab2
--- /dev/null
@@ -0,0 +1,8 @@
+OMK_RULES_TYPE=sysless-keil51
+include base.omk #omkbuild
+include keil51.omk #omkbuild
+include include.omk #omkbuild
+include sysless.omk #omkbuild
+include config_h.omk #omkbuild
+include sources-list.omk #omkbuild
+include localeval.omk #omkbuild
diff --git a/snippets/Makefile.rules.vxworks b/snippets/Makefile.rules.vxworks
new file mode 100644 (file)
index 0000000..ed9eb64
--- /dev/null
@@ -0,0 +1,6 @@
+OMK_RULES_TYPE=vxworks
+include base.omk #omkbuild
+include include.omk #omkbuild
+include vxworks.omk #omkbuild
+include config_h.omk #omkbuild
+include sources-list.omk #omkbuild
similarity index 99%
rename from snippets/base
rename to snippets/base.omk
index bb1af3b2ed2ff678ff5e7f06a641f0c77dce2a06..f0f7a88194bb957c79e3f892bd146e118d2bde9b 100644 (file)
@@ -1,13 +1,15 @@
-#  Makefile.rules - OCERA make framework common project rules -*- makefile -*-
+#  Makefile.rules - OCERA make framework common project rules -*- makefile-gmake -*-
 #
 #  (C) Copyright 2003 by Pavel Pisa - OCERA team member
 #  (C) Copyright 2006 by Michal Sojka - Czech Technical University, FEE, DCE
 #
 #  Homepage: http://rtime.felk.cvut.cz/omk/
+#  Version:  @git-describe@
 #
 # The OMK build system is distributed under the GNU General Public
 # License.  See file COPYING for details.
 #
+#
 # input variables
 # V                .. if set to 1, full command text is shown else short form is used
 # W                .. whole tree - if set to 1, make is always called from the top-level directory
similarity index 98%
rename from snippets/config_h
rename to snippets/config_h.omk
index 98f717f452eac50e0132c229f0b3caccf6c4ef49..9718d85b0d4cb4c3477c7f331191be11a30ea4c9 100644 (file)
@@ -78,8 +78,3 @@ clean-local-config-h:
        @$(foreach confh,$(config_h_stamp_files) $(kern_config_h_stamp_files),\
            if [ -e $(confh) ] ; then rm $(confh) ; fi ; \
        )
-
-
-# Local Variables:
-# mode:makefile
-# End:
similarity index 99%
rename from snippets/gcc
rename to snippets/gcc.omk
index a6d7c5184a46dbae50afd98e3185d8f5a19c62d1..f438cfd9de558a72fe359becdd3fdc35272dce2a 100644 (file)
@@ -210,7 +210,3 @@ $(LIB_DIR)/lib$(1).so: $$($(1)_OBJSLO)
        @$(QUIET_CMD_ECHO) "  LINK    $$@"
        $(Q) $(LD) --shared --soname=lib$(1).so -o $$@ $$^
 endef
-
-# Local Variables:
-# mode:makefile
-# End:
similarity index 98%
rename from snippets/include
rename to snippets/include.omk
index 2c781f22443a6cba4e24caa1fb1802fb74052b67..05978789cf2cefd1eed58950a6bd581844c68c33 100644 (file)
@@ -36,7 +36,3 @@ include-pass-local-$(2): $$($(2)_GEN_HEADERS) $$(foreach f,$$(renamed_$(2)_GEN_H
           cmp --quiet $$$${srcfname} $(1)/$$$${destfname} \
           || ( mkdir -p `dirname $(1)/$$$${destfname}` && $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$$${srcfname},$(1)/$$$${destfname}) ) || exit 1 ; )
 endef
-
-# Local Variables:
-# mode:makefile
-# End:
similarity index 99%
rename from snippets/keil16x
rename to snippets/keil16x.omk
index ea1943c7b621ef67daf62c763e2f7a3e9800188f..61899b3b6932f20743e412e019d5f32e6546e01b 100644 (file)
@@ -142,7 +142,3 @@ $(USER_LIB_DIR)/$(LIB_PREF)$(1)$(LIB_EXT): $$($(1)_OBJS)
        $(AR) ADD $$$${S// /,} TO $$$$L $(FILTER_KEIL_LIB_OUTPUT)
        @touch $(USER_LIB_DIR)/timestamp
 endef
-
-# Local Variables:
-# mode:makefile
-# End:
similarity index 99%
rename from snippets/keil51
rename to snippets/keil51.omk
index 222e859163f6a096c44a4243e15af98589623ff0..8eae753cf8393726f56a4d9257484d2ce86e4eaf 100644 (file)
@@ -169,7 +169,3 @@ $(USER_LIB_DIR)/$(LIB_PREF)$(1)$(LIB_EXT): $$($(1)_OBJS)
        for i in $$^ ; do $(AR) ADD $$$$i TO $$@ ; done
        @touch $(USER_LIB_DIR)/timestamp
 endef
-
-# Local Variables:
-# mode:makefile
-# End:
similarity index 99%
rename from snippets/linux
rename to snippets/linux.omk
index 048d5ef86b92af94be1c5932b3e987eef099cebd..b45dc099d40569d6d46eb73e2e903b1e57ece6cd 100644 (file)
@@ -821,7 +821,3 @@ ifndef OMIT_KERNEL_PASSES
 # Also make kernel passes if not disabled
 default: kernel-lib-pass kernel-pass
 endif
-
-# Local Variables:
-# mode:makefile
-# End:
similarity index 84%
rename from snippets/localeval
rename to snippets/localeval.omk
index 9cf7e5e8c2cf4da147528c2c4e6c1c81a9d4d76b..cb3b6bfafe69eebbba75ce1b12c4050e589453f1 100644 (file)
@@ -5,7 +5,3 @@ ifneq ($(local_EVALUATE),)
 #$(warning $(local_EVALUATE))
 $(eval $(local_EVALUATE))
 endif
-
-# Local Variables:
-# mode:makefile
-# End:
similarity index 97%
rename from snippets/qt
rename to snippets/qt.omk
index df11bc0199ceae78a5215a76ccf56cf25219fca3..b9212970c86993534ac31adad74ead00c169f83c 100644 (file)
@@ -46,7 +46,3 @@ $(foreach pro,$(QT_PROJECTS), $(eval $(call qt_project_template,$(pro))))
 $(foreach pro,$(foreach dir,$(QT_SUBDIRS), $(wildcard $(dir)/*.pro)), $(eval $(call qt_project_template,$(pro))))
 
 endif
-
-# Local Variables:
-# mode:makefile
-# End:
similarity index 99%
rename from snippets/rtems
rename to snippets/rtems.omk
index 2ab968bd9975b40bd20142ed48d217ecd0f1ddc7..ad5d47f4a6c069bc84268a569fc884c690320df1 100644 (file)
@@ -351,7 +351,3 @@ clean-local:
 
 
 default: include-pass library-pass binary-pass
-
-# Local Variables:
-# mode:makefile
-# End:
similarity index 99%
rename from snippets/sdcc
rename to snippets/sdcc.omk
index 952817c6ab78717c99b96c71610cd73505dc4fb6..86247a7d3aff570d091fba8664ab8d8bc05df6fb 100644 (file)
@@ -369,7 +369,3 @@ check-dir::
 include-pass-submakes: extra-rules-subdirs
 # Which passes to pass
 default: include-pass library-pass binary-pass utils-pass
-
-# Local Variables:
-# mode:makefile
-# End:
similarity index 98%
rename from snippets/sources-list
rename to snippets/sources-list.omk
index c74286596db32b600b47c20f0a5f04acef1b7a55..f13545131043ceb3c7d372bbb2f47e2ede05aabf 100644 (file)
@@ -77,7 +77,3 @@ cscope: $(SOURCES_LIST)
        @$(QUIET_CMD_ECHO) "  CSCOPE  < $(SOURCES_LIST_FN)"
        $(Q)sed -e '/^#/d' $(SOURCES_LIST)|cscope -b -i-
 #FIXME: see doc to -i in cscope(1)
-
-# Local Variables:
-# mode:makefile
-# End:
similarity index 99%
rename from snippets/sysless
rename to snippets/sysless.omk
index fd535f6b1b8a4ce9265a3d658937ff170c6454b3..288205ffe51b2ef0e3289ed42d816684c4ea67b0 100644 (file)
@@ -276,7 +276,3 @@ check-dir::
 include-pass-submakes: extra-rules-subdirs
 # Which passes to pass
 default: include-pass library-pass binary-pass utils-pass
-
-# Local Variables:
-# mode:makefile
-# End:
similarity index 99%
rename from snippets/vxworks
rename to snippets/vxworks.omk
index 988286b9a4f8c4faafd9cbf605866d5acc4bca89..6b4bbbfb24cb3e41555d906527c592198f5c0a2b 100644 (file)
@@ -208,7 +208,3 @@ check-dir::
 
 
 default: include-pass library-pass binary-pass
-
-# Local Variables:
-# mode:makefile
-# End: