Code cleanup.
authortnagy1024 <tnagy1024@f0382ac9-c320-0410-b3f0-b508d59f5a85>
Fri, 6 Jun 2008 20:29:00 +0000 (20:29 +0000)
committertnagy1024 <tnagy1024@f0382ac9-c320-0410-b3f0-b508d59f5a85>
Fri, 6 Jun 2008 20:29:00 +0000 (20:29 +0000)
git-svn-id: https://waf.googlecode.com/svn/trunk@3557 f0382ac9-c320-0410-b3f0-b508d59f5a85

utils/amtool.py

index 8ad17206bf69048721f53319573d992f9ecc6a90..0b3a2e8bff9f2a97ea1a5c4ee5d73e60cbf94fc6 100644 (file)
@@ -1,17 +1,17 @@
 #! /usr/bin/env python\r
 \r
-## \r
-# @file \r
+##\r
+# @file\r
 # waf Makefile.am related classed\r
-# \r
-# note: may be a future base of a Makefile.am to scons converter if someone like to write it \r
+#\r
+# note: may be a future base of a Makefile.am to scons converter if someone like to write it\r
 #\r
 # (@) 2005 Ralf Habacker  - published under the GPL license\r
 #\r
\r
+\r
 import os, re, types, sys, string, shutil, stat, glob\r
 \r
-## print a dictionary \r
+## print a dictionary\r
 def printDict(dict,sep=' = ' ):\r
        for key in dict.keys():\r
                print key  + sep + dict[key]\r
@@ -19,14 +19,14 @@ def printDict(dict,sep=' = ' ):
 \r
 ## Makefile.am support class\r
 #\r
-# The class provides methods for the following tasks: \r
-#              - parsing Makefile.am's and collecting targets and defines into class members \r
+# The class provides methods for the following tasks:\r
+#              - parsing Makefile.am's and collecting targets and defines into class members\r
 #              - extracting library dependencies and linker flags keyed by the related targets\r
 #              - extracting target libraries and programs\r
 #              - collecting detailled lists of libraries dependencies\r
 #\r
 #\r
-class AMFile: \r
+class AMFile:\r
        def __init__(self):\r
                self.defines = {}\r
                self.targets = {}\r
@@ -41,28 +41,28 @@ class AMFile:
                self.datadirs= {}\r
                self.path    = ''\r
                self.subdirs = ''\r
-               \r
-       ## read and parse a Makefile.am \r
+\r
+       ## read and parse a Makefile.am\r
        #\r
        # The resulting lines are stored in the defines and targets class member.\r
        # note: Multiple lines in a target are separated by '###'\r
        # @param path - path for Makefile.am\r
-       # @return 0 if file couldn't be read \r
-       # \r
+       # @return 0 if file couldn't be read\r
+       #\r
        def read(self,path):\r
                try:\r
                        src=open(path, 'r')\r
                except:\r
                        return 0\r
                self.path = path\r
-               \r
+\r
                file  = src.read()\r
                lines = file.replace('\n\t','###')\r
                list = lines.replace('\\\n',' ').split('\n')\r
                for line in list:\r
                        if line[:1] == '#' or len(line) == 0:\r
                                continue\r
-                       \r
+\r
                        index = 0\r
                        while line[index].count('#'):\r
                                index = line[index].index('#')\r
@@ -76,7 +76,7 @@ class AMFile:
                                target = line.split(':')\r
                                if len(target) == 2:\r
                                        single_target = target[1].strip().replace("'",'')\r
-                                       # TODO: (rh) split into list \r
+                                       # TODO: (rh) split into list\r
                                        self.targets[str(target[0]).strip()] = single_target\r
                self.getLibraries()\r
                self.getPrograms()\r
@@ -89,22 +89,22 @@ class AMFile:
                self.getData()\r
 \r
                return 1\r
-               \r
-       ## adds library dependencies from another AMFile instance \r
+\r
+       ## adds library dependencies from another AMFile instance\r
        #\r
-       # This method is mainly used for an instance collecting definitions \r
-       # from instances from lower levels \r
-       # @param src - AMFile instance, from which the dependencies are imported \r
+       # This method is mainly used for an instance collecting definitions\r
+       # from instances from lower levels\r
+       # @param src - AMFile instance, from which the dependencies are imported\r
        #\r
        def addLibraryDeps(self,src):\r
                for key in src.libadds.keys():\r
                        self.libadds[key] = src.libadds[key]\r
-                               \r
-       ## adds linker flags from another AMFile instance \r
+\r
+       ## adds linker flags from another AMFile instance\r
        #\r
-       # This method is mainly used for an instance collecting definitions \r
-       # from instances from lower levels \r
-       # @param src - AMFile instance, from which the flags are imported \r
+       # This method is mainly used for an instance collecting definitions\r
+       # from instances from lower levels\r
+       # @param src - AMFile instance, from which the flags are imported\r
        #\r
        def addLinkerFlags(self,src):\r
                for key in src.ldflags.keys():\r
@@ -122,15 +122,15 @@ class AMFile:
                if self.defines.has_key('SUBDIRS'):\r
                        self.subdirs = self.defines['SUBDIRS']\r
                        del self.defines['SUBDIRS']\r
-       ## collect all LIBADDS definitions \r
+       ## collect all LIBADDS definitions\r
        #\r
-       # the function store the definitions in the libadds class member keyed \r
+       # the function store the definitions in the libadds class member keyed\r
        # by the relating target\r
-       # @return definition list \r
+       # @return definition list\r
        #\r
        def getLibraryDeps(self):\r
                reg = re.compile("(.*?)_(?:l?a_)?LIBADD$")\r
-               # TODO (rh) fix relative library pathes \r
+               # TODO (rh) fix relative library pathes\r
                for key in self.defines.keys():\r
                        result=reg.match(key)\r
                        if result:\r
@@ -142,11 +142,11 @@ class AMFile:
                                del self.defines[key]\r
                return self.libadds\r
 \r
-       ## collect all LDFLAGS definitions \r
+       ## collect all LDFLAGS definitions\r
        #\r
-       # the function store the definitions in the ldflags class member keyed \r
-       # by the relating target \r
-       # @return definition list \r
+       # the function store the definitions in the ldflags class member keyed\r
+       # by the relating target\r
+       # @return definition list\r
        #\r
        def getLinkerFlags(self):\r
                reg = re.compile("(.*?)_(?:l?a_)?LDFLAGS$")\r
@@ -161,11 +161,11 @@ class AMFile:
                                del self.defines[key]\r
                return self.ldflags\r
 \r
-       ## collect all LTLIBRARIES definitions \r
+       ## collect all LTLIBRARIES definitions\r
        #\r
-       # the function store the definitions in the libraries class member keyed \r
-       # by the relating target \r
-       # @return definition list \r
+       # the function store the definitions in the libraries class member keyed\r
+       # by the relating target\r
+       # @return definition list\r
        #\r
        def getLibraries(self):\r
                def stripLibname(val):\r
@@ -214,25 +214,25 @@ class AMFile:
                                del self.defines[name+"dir"]\r
                        else:\r
                                del self.data[name]\r
-               \r
+\r
                return self.data\r
 \r
-       ## collect all SOURCES definitions \r
+       ## collect all SOURCES definitions\r
        #\r
-       # the function store the definitions in the sources class member keyed \r
+       # the function store the definitions in the sources class member keyed\r
        # by the relating target\r
        # this function should be called after getPrograms and getLibraries\r
-       # @return definition list \r
+       # @return definition list\r
        #\r
        def getSources(self):\r
                reg = re.compile("(.*?)METASOURCES$")\r
                reg = re.compile("(.*?)_(?:l?a_)?SOURCES$")\r
-               # TODO (rh) fix relative library pathes \r
+               # TODO (rh) fix relative library paths\r
                for key in self.defines.keys():\r
                        if key.endswith('METASOURCES') and self.defines[key] == "AUTO":\r
                                del self.defines[key]\r
                                continue\r
-                       \r
+\r
                        result=reg.match(key)\r
                        if result:\r
                                source = self.findRealTargetname(str(result.group(1)))\r
@@ -258,14 +258,14 @@ class AMFile:
                        else:\r
                                target = ""\r
                return target\r
-       \r
+\r
        def getIncludes(self):\r
                #if we've got a dir global includes, save it in self.includes['_DIR_GLOBAL_']\r
                if self.defines.has_key('INCLUDES'):\r
                        self.defines['_DIR_GLOBAL__INCLUDES'] = self.defines['INCLUDES']\r
                        del self.defines['INCLUDES']\r
                reg = re.compile("(.*?)_(?:l?a_)?INCLUDES")\r
-               # TODO (rh) fix relative library pathes \r
+               # TODO (rh) fix relative library pathes\r
                for key in self.defines.keys():\r
                        result=reg.match(key)\r
                        if result:\r
@@ -289,7 +289,7 @@ class AMFile:
                        self.defines['_DIR_GLOBAL__HEADERS'] = self.defines['HEADERS']\r
                        del self.defines['HEADERS']\r
                reg = re.compile("(.*?)_(?:l?a_)?HEADERS")\r
-               # TODO (rh) fix relative library pathes \r
+               # TODO (rh) fix relative library paths\r
                for key in self.defines.keys():\r
                        result=reg.match(key)\r
                        if result:\r
@@ -299,12 +299,12 @@ class AMFile:
                                self.headers[header] = self.defines[key]\r
                                del self.defines[key]\r
                return self.headers\r
-                       \r
-       ## return a reverse usage list of dependencies \r
+\r
+       ## return a reverse usage list of dependencies\r
        #\r
        # The function scannes the recent library definitions and reorganice\r
        # the resulting list keyed by the used library\r
-       # @return dependency list \r
+       # @return dependency list\r
        #\r
        def getReverseLibraryDeps(self):\r
                alist = {}\r
@@ -315,17 +315,17 @@ class AMFile:
                                else:\r
                                        alist[str(lib)] = key\r
                return alist\r
-       \r
+\r
        def printDefines(self):\r
-               print "### DEFINES:" \r
+               print "### DEFINES:"\r
                printDict(self.defines,' = ')\r
-       \r
+\r
        def printTargets(self):\r
-               print "### TARGETS:" \r
+               print "### TARGETS:"\r
                printDict(self.targets,' : ')\r
 \r
        def printLibraryDeps(self):\r
-               print "### LIBADD:" \r
+               print "### LIBADD:"\r
                printDict(self.libadds,' : ')\r
 \r
        def printLinkerFlags(self):\r
@@ -351,15 +351,15 @@ def amview():
        sources = 0\r
        if len(sys.argv) == 1:\r
                print "amtool [options] Makefile.am [Makefile.am] ..."\r
-               print "list Makefile.am content" \r
-               print "options:" \r
-               print "    --uses print where a library is used" \r
-               print "    --libadd print all LIBADD depenencies " \r
-               print "    --ldflags print all LDFLAGS definitions" \r
-               print "    --defines print all Makefile variables" \r
-               print "    --targets print all Makefile targets" \r
-               print "    --libs print all library definitions" \r
-               print "    --sources print all source definitions" \r
+               print "list Makefile.am content"\r
+               print "options:"\r
+               print "    --uses print where a library is used"\r
+               print "    --libadd print all LIBADD depenencies "\r
+               print "    --ldflags print all LDFLAGS definitions"\r
+               print "    --defines print all Makefile variables"\r
+               print "    --targets print all Makefile targets"\r
+               print "    --libs print all library definitions"\r
+               print "    --sources print all source definitions"\r
        else:\r
                all_ams = AMFile()\r
                for a in range(1,len(sys.argv)):\r
@@ -370,27 +370,27 @@ def amview():
                        elif sys.argv[a][:9] == '--defines':\r
                                defines = 1\r
                        elif sys.argv[a][:9] == '--targets':\r
-                               targets = 1                     \r
+                               targets = 1\r
                        elif sys.argv[a][:9] == '--ldflags':\r
                                ldflags = 1\r
                        elif sys.argv[a][:6] == '--libs':\r
                                libs = 1\r
                        elif sys.argv[a][:9] == '--sources':\r
                                sources = 1\r
-                       if  libadds or defines or targets or ldflags or libs or sources:        \r
+                       if  libadds or defines or targets or ldflags or libs or sources:\r
                                uses = 2\r
-                                                       \r
+\r
                for a in range(1,len(sys.argv)):\r
                        if sys.argv[a][:2] == '--':\r
                                continue\r
                        am_file = AMFile()\r
-       \r
-                       if not am_file.read(sys.argv[a]): \r
+\r
+                       if not am_file.read(sys.argv[a]):\r
                                continue\r
-       \r
+\r
                        if uses == 2:\r
                                print "### " + sys.argv[a]\r
-       \r
+\r
                        if defines:\r
                                am_file.printDefines()\r
                        if targets:\r
@@ -403,14 +403,15 @@ def amview():
                                am_file.printLibraries()\r
                        if sources:\r
                                am_file.printSources()\r
-       \r
+\r
                        all_ams.addLibraryDeps(am_file)\r
                        all_ams.addLinkerFlags(am_file)\r
                        all_ams.addSources(am_file)\r
                        all_ams.addLibraries(am_file)\r
-       \r
+\r
                if uses == 0:\r
                        all_ams.printLibraryDeps()\r
                elif uses == 1:\r
                        a = all_ams.getReverseLibraryDeps()\r
                        printDict(a)\r
+\r