a) Added arch support for [Defines] section for R8 modules
authorjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Fri, 18 Jan 2008 07:12:12 +0000 (07:12 +0000)
committerjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Fri, 18 Jan 2008 07:12:12 +0000 (07:12 +0000)
b) Added macro replacement in the INF files of R8 modules
c) Fixed EDK_SOURCE and EFI_SOURCE environment issue
d) Fixed tool flags conversion issue when there're more than one lines of for the same tool under [nmake] section
e) Fixed incorrect relative include path in [includes] section of R8 INF file.
f) Fixed more than one time of output for the same message in EdkLogger

git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@949 7335b38e-4728-0410-8992-fb3ffe349368

15 files changed:
Source/Python/AutoGen/AutoGen.py
Source/Python/AutoGen/GenC.py
Source/Python/Common/DataType.py
Source/Python/Common/DscClassObject.py
Source/Python/Common/EdkIIWorkspaceBuild.py
Source/Python/Common/EdkLogger.py
Source/Python/Common/InfClassObject.py
Source/Python/Common/Misc.py
Source/Python/Common/String.py
Source/Python/Common/TargetTxtClassObject.py
Source/Python/CommonDataClass/ModuleClass.py
Source/Python/GenFds/AprioriSection.py
Source/Python/GenFds/FfsInfStatement.py
Source/Python/GenFds/GenFds.py
Source/Python/build/build.py

index 558f3b5..a7a1099 100755 (executable)
@@ -893,7 +893,11 @@ class ModuleAutoGen(object):
             if Target == "*" or Target == self.BuildTarget:\r
                 if Tag == "*" or Tag == self.ToolChain:\r
                     if Arch == "*" or Arch == self.Arch:\r
-                        OptionList[Tool] = BuildOption[Key]\r
+                        if Tool not in OptionList:\r
+                            OptionList[Tool] = BuildOption[Key]\r
+                        else:\r
+                            # append options for the same tool\r
+                            OptionList[Tool] = OptionList[Tool] + " " + BuildOption[Key]\r
         # for those tools that have no option in module file, give it a empty string\r
         for Tool in PlatformInfo.ToolOption:\r
             if Tool not in OptionList:\r
@@ -1094,8 +1098,9 @@ class ModuleAutoGen(object):
     def GetIncludePathList(self, DependentPackageList):\r
         IncludePathList = []\r
         for Inc in self.Module.Includes:\r
-            if Inc == ".":\r
-                continue\r
+            # '.' means "relative to module directory".\r
+            if Inc[0] == ".":\r
+                Inc = os.path.join(self.BuildInfo.SourceDir, Inc)\r
             IncludePathList.append(Inc)\r
             # for r8 modules\r
             IncludePathList.append(os.path.join(Inc, self.Arch.capitalize()))\r
index 0fb9d54..00f66eb 100644 (file)
@@ -1425,7 +1425,8 @@ def CreateModuleEntryPointCode(Info, AutoGenC, AutoGenH):
 \r
     if Info.ModuleType in ['PEI_CORE', 'DXE_CORE']:\r
         if NumEntryPoints != 1:\r
-            EdkLogger.error("AutoGen", AUTOGEN_ERROR, '%s must have exactly one entry point' % Info.ModuleType)\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, '%s must have exactly one entry point' % Info.ModuleType,\r
+                            ExtraData=", ".join(Info.Module.ModuleEntryPointList))\r
     if Info.ModuleType == 'PEI_CORE':\r
         AutoGenC.Append(gPeiCoreEntryPointString, Dict)\r
     elif Info.ModuleType == 'DXE_CORE':\r
index 4a73e9b..be86b08 100644 (file)
@@ -274,7 +274,7 @@ TAB_INF_DEFINES_DESTRUCTOR = 'DESTRUCTOR'
 TAB_INF_DEFINES_DEFINE = 'DEFINE'\r
 TAB_INF_DEFINES_SPEC = 'SPEC'\r
 TAB_INF_DEFINES_CUSTOM_MAKEFILE = 'CUSTOM_MAKEFILE'\r
-TAB_INF_DEFINES_MACRO_NAME = 'MacroName'\r
+TAB_INF_DEFINES_MACRO = '__MACROS__'\r
 TAB_INF_DEFINES_SHADOW = 'SHADOW'\r
 TAB_INF_FIXED_PCD = 'FixedPcd'\r
 TAB_INF_FEATURE_PCD = 'FeaturePcd'\r
index 7910b8e..a50732f 100755 (executable)
@@ -24,6 +24,7 @@ from CommonDataClass.PlatformClass import *
 from CommonDataClass.CommonClass import SkuInfoClass\r
 from BuildToolError import *\r
 from Misc import sdict\r
+import GlobalData\r
 \r
 ## DscObject\r
 #\r
@@ -62,7 +63,8 @@ class DscDefines(DscObject):
             TAB_DSC_DEFINES_MAKEFILE_NAME                         : [''],\r
             TAB_DSC_DEFINES_BS_BASE_ADDRESS                       : [''],\r
             TAB_DSC_DEFINES_RT_BASE_ADDRESS                       : [''],\r
-            TAB_DSC_DEFINES_DEFINE                                : ['']\r
+            TAB_DSC_DEFINES_DEFINE                                : [''],\r
+            TAB_INF_DEFINES_MACRO                                 : {}\r
         }\r
 \r
 ## DscSkuId\r
@@ -151,6 +153,7 @@ class Dsc(DscObject):
         self.UserExtensions = ''\r
         self.Platform = PlatformClass()\r
         self.WorkspaceDir = WorkspaceDir\r
+        self._Macro = {}    # for inf file local replacement\r
 \r
         for Arch in DataType.ARCH_LIST_FULL:\r
             self.Contents[Arch] = DscContents()\r
@@ -248,6 +251,9 @@ class Dsc(DscObject):
                                 eval(Command)\r
                                 continue\r
 \r
+        self._Macro = self.Defines.DefinesDictionary[TAB_INF_DEFINES_MACRO]\r
+        self._Macro.update(GlobalData.gGlobalDefines)\r
+\r
     ## Transfer to Platform Object\r
     # \r
     # Transfer all contents of an Inf file to a standard Module Object\r
@@ -267,7 +273,7 @@ class Dsc(DscObject):
         self.Platform.Header.SkuIdName = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_SKUID_IDENTIFIER]\r
         self.Platform.Header.SupArchList = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES]\r
         self.Platform.Header.BuildTargets = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_BUILD_TARGETS]\r
-        self.Platform.Header.OutputDirectory = NormPath(self.Defines.DefinesDictionary[TAB_DSC_DEFINES_OUTPUT_DIRECTORY][0])\r
+        self.Platform.Header.OutputDirectory = NormPath(self.Defines.DefinesDictionary[TAB_DSC_DEFINES_OUTPUT_DIRECTORY][0], self._Macro)\r
         self.Platform.Header.BuildNumber = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_BUILD_NUMBER][0]\r
         self.Platform.Header.MakefileName = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_MAKEFILE_NAME][0]\r
 \r
@@ -286,7 +292,7 @@ class Dsc(DscObject):
                     self.Platform.Header.Define[CleanString(List[0])] = CleanString(List[1])\r
 \r
         Fdf = PlatformFlashDefinitionFileClass()\r
-        Fdf.FilePath = NormPath(self.Defines.DefinesDictionary[TAB_DSC_DEFINES_FLASH_DEFINITION][0])\r
+        Fdf.FilePath = NormPath(self.Defines.DefinesDictionary[TAB_DSC_DEFINES_FLASH_DEFINITION][0], self._Macro)\r
         self.Platform.FlashDefinitionFile = Fdf\r
 \r
         #\r
@@ -370,7 +376,7 @@ class Dsc(DscObject):
         self.Platform.Libraries.IncludeFiles = IncludeFiles\r
         for Key in Libraries.keys():\r
             Library = PlatformLibraryClass()\r
-            Library.FilePath = NormPath(Key)\r
+            Library.FilePath = NormPath(Key, self._Macro)\r
             Library.Define = Defines\r
             Library.SupArchList = Libraries[Key]\r
             self.Platform.Libraries.LibraryList.append(Library)\r
@@ -411,7 +417,7 @@ class Dsc(DscObject):
         for Key in LibraryClasses.keys():\r
             Library = PlatformLibraryClass()\r
             Library.Name = Key[0]\r
-            Library.FilePath = NormPath(Key[1])\r
+            Library.FilePath = NormPath(Key[1], self._Macro)\r
             Library.SupModuleList = list(Key[2:])\r
             Library.Define = Defines\r
             Library.SupArchList = LibraryClasses[Key]\r
@@ -502,25 +508,25 @@ class Dsc(DscObject):
     #\r
     def GenComponent(self, Item, ContainerFile):\r
         (InfFilename, ExecFilename) = GetExec(Item[0])\r
-        CheckFileType(InfFilename, '.Inf', ContainerFile, 'component name', Item[0])\r
-        CheckFileExist(self.WorkspaceDir, InfFilename, ContainerFile, 'component', Item[0])\r
         LibraryClasses = Item[1]\r
         BuildOptions = Item[2]\r
         Pcds = Item[3]\r
         Component = PlatformModuleClass()\r
-        Component.FilePath = NormPath(InfFilename)\r
-        Component.ExecFilePath = NormPath(ExecFilename)\r
+        Component.FilePath = NormPath(InfFilename, self._Macro)\r
+        Component.ExecFilePath = NormPath(ExecFilename, self._Macro)\r
+        CheckFileType(Component.FilePath, '.Inf', ContainerFile, 'component name', Item[0])\r
+        CheckFileExist(self.WorkspaceDir, Component.FilePath, ContainerFile, 'component', Item[0])\r
         for Lib in LibraryClasses:\r
             List = GetSplitValueList(Lib)\r
             if len(List) != 2:\r
                 RaiseParserError(Lib, 'LibraryClasses', ContainerFile, '<ClassName>|<InfFilename>')\r
             LibName = List[0]\r
-            LibFile = NormPath(List[1])\r
+            LibFile = NormPath(List[1], self._Macro)\r
             if LibName == "" or LibName == "NULL":\r
                 LibName = "NULL%d" % self._NullClassIndex\r
                 self._NullClassIndex += 1\r
             CheckFileType(List[1], '.Inf', ContainerFile, 'library instance of component ', Lib)\r
-            CheckFileExist(self.WorkspaceDir, List[1], ContainerFile, 'library instance of component', Lib)\r
+            CheckFileExist(self.WorkspaceDir, LibFile, ContainerFile, 'library instance of component', Lib)\r
             Component.LibraryClasses.LibraryList.append(PlatformLibraryClass(LibName, LibFile))\r
         for BuildOption in BuildOptions:\r
             Key = GetBuildOption(BuildOption, ContainerFile)\r
index 3820fb3..7949033 100755 (executable)
@@ -572,7 +572,7 @@ class WorkspaceBuild(object):
                 for Item in Platform.Libraries.LibraryList:\r
                     for Arch in Item.SupArchList:\r
                         Library = self.InfDatabase[Item.FilePath]\r
-                        Pb.Libraries[Library.Module.Header.Name] = Item.FilePath\r
+                        Pb.Libraries[Library.Module.Header[Arch].Name] = Item.FilePath\r
                 \r
                 #\r
                 # Pcds\r
@@ -700,50 +700,51 @@ class WorkspaceBuild(object):
             Module = self.InfDatabase[Inf].Module\r
 \r
             for Arch in self.SupArchList:\r
-                if not self.IsModuleDefinedInPlatform(Inf, Arch, InfList):\r
+                if not self.IsModuleDefinedInPlatform(Inf, Arch, InfList) or Arch not in Module.Header:\r
                     continue\r
 \r
+                ModuleHeader = Module.Header[Arch]\r
                 Pb = ModuleBuildClassObject()\r
 \r
                 #\r
                 # Defines\r
                 #\r
                 Pb.DescFilePath = Inf\r
-                Pb.BaseName = Module.Header.Name\r
-                Pb.Guid = Module.Header.Guid\r
-                Pb.Version = Module.Header.Version\r
-                Pb.ModuleType = Module.Header.ModuleType\r
-                Pb.PcdIsDriver = Module.Header.PcdIsDriver\r
-                Pb.BinaryModule = Module.Header.BinaryModule\r
-                Pb.CustomMakefile = Module.Header.CustomMakefile\r
-                Pb.Shadow = Module.Header.Shadow\r
+                Pb.BaseName = ModuleHeader.Name\r
+                Pb.Guid = ModuleHeader.Guid\r
+                Pb.Version = ModuleHeader.Version\r
+                Pb.ModuleType = ModuleHeader.ModuleType\r
+                Pb.PcdIsDriver = ModuleHeader.PcdIsDriver\r
+                Pb.BinaryModule = ModuleHeader.BinaryModule\r
+                Pb.CustomMakefile = ModuleHeader.CustomMakefile\r
+                Pb.Shadow = ModuleHeader.Shadow\r
 \r
                 #\r
                 # Specs os Defines\r
                 #\r
-                Pb.Specification = Module.Header.Specification\r
-                Pb.Specification[TAB_INF_DEFINES_EDK_RELEASE_VERSION] = Module.Header.EdkReleaseVersion\r
-                Pb.Specification[TAB_INF_DEFINES_EFI_SPECIFICATION_VERSION] = Module.Header.EfiSpecificationVersion\r
-                Pb.AutoGenVersion = int(Module.Header.InfVersion, 0)\r
+                Pb.Specification = ModuleHeader.Specification\r
+                Pb.Specification[TAB_INF_DEFINES_EDK_RELEASE_VERSION] = ModuleHeader.EdkReleaseVersion\r
+                Pb.Specification[TAB_INF_DEFINES_EFI_SPECIFICATION_VERSION] = ModuleHeader.EfiSpecificationVersion\r
+                Pb.AutoGenVersion = int(ModuleHeader.InfVersion, 0)\r
 \r
                 #\r
                 # LibraryClass of Defines\r
                 #\r
-                for Item in Module.Header.LibraryClass:\r
+                for Item in ModuleHeader.LibraryClass:\r
                     Pb.LibraryClass.append(LibraryClassObject(Item.LibraryClass, Item.SupModuleList, None))\r
 \r
                 #\r
                 # Module image and library of Defines\r
                 #\r
                 for Item in Module.ExternImages:\r
-                    if Item.ModuleEntryPoint != '':\r
+                    if Item.ModuleEntryPoint != '' and Item.ModuleEntryPoint not in Pb.ModuleEntryPointList:\r
                         Pb.ModuleEntryPointList.append(Item.ModuleEntryPoint)\r
-                    if Item.ModuleUnloadImage != '':\r
+                    if Item.ModuleUnloadImage != '' and Item.ModuleUnloadImage not in Pb.ModuleUnloadImageList:\r
                         Pb.ModuleUnloadImageList.append(Item.ModuleUnloadImage)\r
                 for Item in Module.ExternLibraries:\r
-                    if Item.Constructor != '':\r
+                    if Item.Constructor != '' and Item.Constructor not in Pb.ConstructorList:\r
                         Pb.ConstructorList.append(Item.Constructor)\r
-                    if Item.Destructor != '':\r
+                    if Item.Destructor != '' and Item.Destructor not in Pb.DestructorList:\r
                         Pb.DestructorList.append(Item.Destructor)\r
 \r
                 #\r
@@ -809,7 +810,11 @@ class WorkspaceBuild(object):
                 #\r
                 for Item in Module.BuildOptions:\r
                     if Arch in Item.SupArchList:\r
-                        Pb.BuildOptions[(Item.ToolChainFamily, Item.ToolChain)] = Item.Option\r
+                        if (Item.ToolChainFamily, Item.ToolChain) not in Pb.BuildOptions:\r
+                            Pb.BuildOptions[(Item.ToolChainFamily, Item.ToolChain)] = Item.Option\r
+                        else:\r
+                            OptionString = Pb.BuildOptions[(Item.ToolChainFamily, Item.ToolChain)]\r
+                            Pb.BuildOptions[(Item.ToolChainFamily, Item.ToolChain)] = OptionString + " " + Item.Option\r
                 self.FindBuildOptions(Arch, Inf, Pb.BuildOptions)\r
 \r
                 #\r
@@ -904,6 +909,9 @@ class WorkspaceBuild(object):
             EdkLogger.verbose("")\r
             EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), Arch))\r
             LibraryConsumerList = [Module]\r
+\r
+            # "CompilerStub" is a must for R8 modules\r
+            Module.Libraries.append("CompilerStub")\r
             while len(LibraryConsumerList) > 0:\r
                 M = LibraryConsumerList.pop()\r
                 for LibraryName in M.Libraries:\r
@@ -1166,7 +1174,7 @@ class WorkspaceBuild(object):
         # Update the library instance itself to add this libraryclass name\r
         #\r
         LibraryModule = self.InfDatabase[InstanceFilePath].Module\r
-        LibList = LibraryModule.Header.LibraryClass\r
+        LibList = LibraryModule.Header[Arch].LibraryClass\r
         NotFound = True\r
         for Lib in LibList:\r
             #\r
@@ -1178,8 +1186,8 @@ class WorkspaceBuild(object):
         if NotFound:\r
             NewLib = LibraryClassClass()\r
             NewLib.LibraryClass = LibraryClass\r
-            NewLib.SupModuleList = LibraryModule.Header.ModuleType.split()\r
-            LibraryModule.Header.LibraryClass.append(NewLib)\r
+            NewLib.SupModuleList = LibraryModule.Header[Arch].ModuleType.split()\r
+            LibraryModule.Header[Arch].LibraryClass.append(NewLib)\r
 \r
         #\r
         # Add it to LibraryClasses Section for the module which is using the library\r
index dc37e75..2a2091d 100644 (file)
@@ -196,6 +196,7 @@ def error(ToolName, ErrorCode, Message=None, File=None, Line=None, ExtraData=Non
 # Log information which should be always put out
 quiet   = _ErrorLogger.error
 
+## Initialize log system
 def Initialize():
     #
     # Since we use different format to log different levels of message into differen
index 25a9057..15b0c1c 100755 (executable)
@@ -24,6 +24,8 @@ from DataType import *
 from Identification import *\r
 from Dictionary import *\r
 from BuildToolError import *\r
+from Misc import sdict\r
+import GlobalData\r
 \r
 gComponentType2ModuleType = {\r
     "LIBRARY"               :   "BASE",\r
@@ -39,9 +41,10 @@ gComponentType2ModuleType = {
 #    "BS_DRIVER"             :   "DXE_SMM_DRIVER",\r
 #    "BS_DRIVER"             :   "UEFI_DRIVER",\r
     "APPLICATION"           :   "UEFI_APPLICATION",\r
+    "LOGO"                  :   "BASE",\r
 }\r
 \r
-gNmakeFlagPattern = re.compile("(?:EBC_)?([A-Z])+_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re.UNICODE)\r
+gNmakeFlagPattern = re.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re.UNICODE)\r
 gNmakeFlagName2ToolCode = {\r
     "C"         :   "CC",\r
     "LIB"       :   "SLINK",\r
@@ -103,9 +106,20 @@ class InfDefines(InfObject):
             TAB_INF_DEFINES_DEFINE                                  : [''],\r
             TAB_INF_DEFINES_SPEC                                    : [''],\r
             TAB_INF_DEFINES_CUSTOM_MAKEFILE                         : [''],\r
-            TAB_INF_DEFINES_SHADOW                                  : ['']\r
+            TAB_INF_DEFINES_SHADOW                                  : [''],\r
+            TAB_INF_DEFINES_MACRO                                   : {}\r
         }\r
 \r
+    def extend(self, InfDefinesObj):\r
+        for Item in InfDefinesObj.DefinesDictionary:\r
+            if Item == TAB_INF_DEFINES_MACRO:\r
+                self.DefinesDictionary[Item].update(InfDefinesObj.DefinesDictionary[Item])\r
+            else:\r
+                if InfDefinesObj.DefinesDictionary[Item][0] != '':\r
+                    if self.DefinesDictionary[Item][0] == '':\r
+                        self.DefinesDictionary[Item] = []\r
+                    self.DefinesDictionary[Item].extend(InfDefinesObj.DefinesDictionary[Item])\r
+\r
 ## InfContents\r
 #\r
 # This class defined basic Contents used in Inf object\r
@@ -175,18 +189,21 @@ class InfContents(InfObject):
 class Inf(InfObject):\r
     def __init__(self, Filename = None, IsMergeAllArches = False, IsToModule = False, WorkspaceDir = None):\r
         self.Identification = Identification()\r
-        self.Defines = InfDefines()\r
+        self.Defines = {} # InfDefines()\r
         self.Contents = {}\r
         self.UserExtensions = ''\r
         self.Module = ModuleClass()\r
         self.WorkspaceDir = WorkspaceDir\r
-        \r
+        self._Macro = {}    # for inf file local replacement\r
+\r
         for Arch in DataType.ARCH_LIST_FULL:\r
             self.Contents[Arch] = InfContents()\r
 \r
         self.KeyList = [\r
-            TAB_SOURCES, TAB_BUILD_OPTIONS, TAB_BINARIES, TAB_INCLUDES, TAB_GUIDS, TAB_PROTOCOLS, TAB_PPIS, TAB_LIBRARY_CLASSES, TAB_PACKAGES, TAB_LIBRARIES, \\r
-            TAB_INF_FIXED_PCD, TAB_INF_PATCH_PCD, TAB_INF_FEATURE_PCD, TAB_INF_PCD, TAB_INF_PCD_EX, TAB_DEPEX, TAB_NMAKE\r
+            TAB_SOURCES, TAB_BUILD_OPTIONS, TAB_BINARIES, TAB_INCLUDES, TAB_GUIDS, \r
+            TAB_PROTOCOLS, TAB_PPIS, TAB_LIBRARY_CLASSES, TAB_PACKAGES, TAB_LIBRARIES, \r
+            TAB_INF_FIXED_PCD, TAB_INF_PATCH_PCD, TAB_INF_FEATURE_PCD, TAB_INF_PCD, \r
+            TAB_INF_PCD_EX, TAB_DEPEX, TAB_NMAKE\r
         ]\r
 \r
         #\r
@@ -212,6 +229,14 @@ class Inf(InfObject):
     # Find the contents defined in all arches and merge them to all\r
     #\r
     def MergeAllArches(self):\r
+        for Arch in DataType.ARCH_LIST:\r
+            if Arch not in self.Defines:\r
+                self.Defines[Arch] = InfDefines()\r
+            self.Defines[Arch].extend(self.Defines[DataType.TAB_ARCH_COMMON.upper()])\r
+            self._Macro.update(self.Defines[Arch].DefinesDictionary[TAB_INF_DEFINES_MACRO])\r
+        self._Macro.update(GlobalData.gGlobalDefines)\r
+        # print "###",self._Macro\r
+\r
         for Key in self.KeyList:\r
             for Arch in DataType.ARCH_LIST:\r
                 Command = "self.Contents[Arch]." + Key + ".extend(" + "self.Contents['" + DataType.TAB_ARCH_COMMON + "']." + Key + ")"\r
@@ -233,69 +258,77 @@ class Inf(InfObject):
         else:\r
             GetMultipleValuesOfKeyFromLines(Lines, Key, KeyField, TAB_COMMENT_SPLIT)\r
 \r
-    ## Transfer to Module Object\r
-    # \r
-    # Transfer all contents of an Inf file to a standard Module Object\r
+    ## Convert [Defines] section content to ModuleHeaderClass\r
     #\r
-    def InfToModule(self):\r
+    # Convert [Defines] section content to ModuleHeaderClass\r
+    #\r
+    # @param Defines        The content under [Defines] section\r
+    # @param ModuleHeader   An object of ModuleHeaderClass\r
+    # @param Arch           The supported ARCH\r
+    #\r
+    def DefinesToModuleHeader(self, Defines, ModuleHeader, Arch):\r
+        ModuleHeader.SupArchList.append(Arch)\r
+        # macro definitions\r
+        ModuleHeader.MacroDefines.update(Defines.DefinesDictionary[TAB_INF_DEFINES_MACRO])\r
+        ModuleHeader.MacroDefines.update(GlobalData.gGlobalDefines)\r
         #\r
         # Get value for Header\r
         #\r
-        self.Module.Header.InfVersion = self.Defines.DefinesDictionary[TAB_INF_DEFINES_INF_VERSION][0]\r
-        self.Module.Header.Name = self.Defines.DefinesDictionary[TAB_INF_DEFINES_BASE_NAME][0]\r
-        self.Module.Header.Guid = self.Defines.DefinesDictionary[TAB_INF_DEFINES_FILE_GUID][0]\r
+        ModuleHeader.InfVersion = Defines.DefinesDictionary[TAB_INF_DEFINES_INF_VERSION][0]\r
+        ModuleHeader.Name = Defines.DefinesDictionary[TAB_INF_DEFINES_BASE_NAME][0]\r
+        ModuleHeader.Guid = Defines.DefinesDictionary[TAB_INF_DEFINES_FILE_GUID][0]\r
         \r
-        self.Module.Header.FileName = self.Identification.FileName\r
-        self.Module.Header.FullPath = self.Identification.FileFullPath\r
-        File = self.Module.Header.FullPath\r
+        ModuleHeader.FileName = self.Identification.FileName\r
+        ModuleHeader.FullPath = self.Identification.FileFullPath\r
+        File = ModuleHeader.FullPath\r
         \r
-        self.Module.Header.EfiSpecificationVersion = self.Defines.DefinesDictionary[TAB_INF_DEFINES_EFI_SPECIFICATION_VERSION][0]\r
-        self.Module.Header.EdkReleaseVersion = self.Defines.DefinesDictionary[TAB_INF_DEFINES_EDK_RELEASE_VERSION][0]\r
-                \r
-        self.Module.Header.ModuleType = self.Defines.DefinesDictionary[TAB_INF_DEFINES_MODULE_TYPE][0]\r
-        self.Module.Header.BinaryModule = self.Defines.DefinesDictionary[TAB_INF_DEFINES_BINARY_MODULE][0]\r
-        self.Module.Header.ComponentType = self.Defines.DefinesDictionary[TAB_INF_DEFINES_COMPONENT_TYPE][0]\r
-        self.Module.Header.MakefileName = self.Defines.DefinesDictionary[TAB_INF_DEFINES_MAKEFILE_NAME][0]\r
-        self.Module.Header.BuildNumber = self.Defines.DefinesDictionary[TAB_INF_DEFINES_BUILD_NUMBER][0]\r
-        self.Module.Header.BuildType = self.Defines.DefinesDictionary[TAB_INF_DEFINES_BUILD_TYPE][0]\r
-        self.Module.Header.FfsExt = self.Defines.DefinesDictionary[TAB_INF_DEFINES_FFS_EXT][0]\r
-        self.Module.Header.FvExt = self.Defines.DefinesDictionary[TAB_INF_DEFINES_FV_EXT][0]\r
-        self.Module.Header.SourceFv = self.Defines.DefinesDictionary[TAB_INF_DEFINES_SOURCE_FV][0]\r
-        self.Module.Header.PcdIsDriver = self.Defines.DefinesDictionary[TAB_INF_DEFINES_PCD_IS_DRIVER][0]\r
-        self.Module.Header.TianoR8FlashMap_h = self.Defines.DefinesDictionary[TAB_INF_DEFINES_TIANO_R8_FLASHMAP_H][0]\r
-        self.Module.Header.Shadow = self.Defines.DefinesDictionary[TAB_INF_DEFINES_SHADOW][0]\r
+        ModuleHeader.EfiSpecificationVersion = Defines.DefinesDictionary[TAB_INF_DEFINES_EFI_SPECIFICATION_VERSION][0]\r
+        ModuleHeader.EdkReleaseVersion = Defines.DefinesDictionary[TAB_INF_DEFINES_EDK_RELEASE_VERSION][0]\r
+           \r
+        ModuleHeader.ModuleType = Defines.DefinesDictionary[TAB_INF_DEFINES_MODULE_TYPE][0]\r
+        ModuleHeader.BinaryModule = Defines.DefinesDictionary[TAB_INF_DEFINES_BINARY_MODULE][0]\r
+        ModuleHeader.ComponentType = Defines.DefinesDictionary[TAB_INF_DEFINES_COMPONENT_TYPE][0]\r
+        ModuleHeader.MakefileName = Defines.DefinesDictionary[TAB_INF_DEFINES_MAKEFILE_NAME][0]\r
+        ModuleHeader.BuildNumber = Defines.DefinesDictionary[TAB_INF_DEFINES_BUILD_NUMBER][0]\r
+        ModuleHeader.BuildType = Defines.DefinesDictionary[TAB_INF_DEFINES_BUILD_TYPE][0]\r
+        ModuleHeader.FfsExt = Defines.DefinesDictionary[TAB_INF_DEFINES_FFS_EXT][0]\r
+        ModuleHeader.FvExt = Defines.DefinesDictionary[TAB_INF_DEFINES_FV_EXT][0]\r
+        ModuleHeader.SourceFv = Defines.DefinesDictionary[TAB_INF_DEFINES_SOURCE_FV][0]\r
+        ModuleHeader.PcdIsDriver = Defines.DefinesDictionary[TAB_INF_DEFINES_PCD_IS_DRIVER][0]\r
+        ModuleHeader.TianoR8FlashMap_h = Defines.DefinesDictionary[TAB_INF_DEFINES_TIANO_R8_FLASHMAP_H][0]\r
+        ModuleHeader.Shadow = Defines.DefinesDictionary[TAB_INF_DEFINES_SHADOW][0]\r
         \r
         #\r
         # Get version of INF\r
         #\r
-        if self.Module.Header.InfVersion != "":\r
+        if ModuleHeader.InfVersion != "":\r
             # R9 inf\r
-            VersionNumber = self.Defines.DefinesDictionary[TAB_INF_DEFINES_VERSION_NUMBER][0]\r
-            VersionString = self.Defines.DefinesDictionary[TAB_INF_DEFINES_VERSION_STRING][0]\r
+            VersionNumber = Defines.DefinesDictionary[TAB_INF_DEFINES_VERSION_NUMBER][0]\r
+            VersionString = Defines.DefinesDictionary[TAB_INF_DEFINES_VERSION_STRING][0]\r
             if len(VersionNumber) > 0 and len(VersionString) == 0:\r
                 EdkLogger.warn(2000, 'VERSION_NUMBER depricated; INF file %s should be modified to use VERSION_STRING instead.' % self.Identification.FileFullPath)\r
-                self.Module.Header.Version = VersionNumber\r
+                ModuleHeader.Version = VersionNumber\r
             if len(VersionString) > 0:\r
                 if len(VersionNumber) > 0:\r
                     EdkLogger.warn(2001, 'INF file %s defines both VERSION_NUMBER and VERSION_STRING, using VERSION_STRING' % self.Identification.FileFullPath)\r
-                self.Module.Header.Version = VersionString\r
+                ModuleHeader.Version = VersionString\r
         else:\r
             # R8 inf\r
-            self.Module.Header.InfVersion = "0x00010000"\r
-            VersionNumber = self.Defines.DefinesDictionary[TAB_INF_DEFINES_VERSION][0]\r
-            VersionString = self.Defines.DefinesDictionary[TAB_INF_DEFINES_VERSION_STRING][0]\r
+            ModuleHeader.InfVersion = "0x00010000"\r
+            VersionNumber = Defines.DefinesDictionary[TAB_INF_DEFINES_VERSION][0]\r
+            VersionString = Defines.DefinesDictionary[TAB_INF_DEFINES_VERSION_STRING][0]\r
             if VersionString == '' and VersionNumber != '':\r
                 VersionString = VersionNumber\r
-            if self.Module.Header.ComponentType in gComponentType2ModuleType:\r
-                self.Module.Header.ModuleType = gComponentType2ModuleType[self.Module.Header.ComponentType]\r
-            else:\r
-                EdkLogger.error("Parser", PARSER_ERROR, "Unsupported R8 component type [%s]" % self.Module.Header.ComponentType,\r
+            if ModuleHeader.ComponentType in gComponentType2ModuleType:\r
+                ModuleHeader.ModuleType = gComponentType2ModuleType[ModuleHeader.ComponentType]\r
+            elif ModuleHeader.ComponentType != '':\r
+                EdkLogger.error("Parser", PARSER_ERROR, "Unsupported R8 component type [%s]" % ModuleHeader.ComponentType,\r
                                 ExtraData=File)\r
         #\r
         # LibraryClass of Defines\r
         #\r
-        if self.Defines.DefinesDictionary[TAB_INF_DEFINES_LIBRARY_CLASS][0] != '':\r
-            for Item in self.Defines.DefinesDictionary[TAB_INF_DEFINES_LIBRARY_CLASS]:\r
+        if Defines.DefinesDictionary[TAB_INF_DEFINES_LIBRARY_CLASS][0] != '':\r
+            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_LIBRARY_CLASS]:\r
                 List = GetSplitValueList(Item, DataType.TAB_VALUE_SPLIT, 1)\r
                 Lib = LibraryClassClass()\r
                 Lib.LibraryClass = CleanString(List[0])\r
@@ -303,34 +336,34 @@ class Inf(InfObject):
                     Lib.SupModuleList = DataType.SUP_MODULE_LIST\r
                 elif len(List) == 2:\r
                     Lib.SupModuleList = GetSplitValueList(CleanString(List[1]), ' ')\r
-                self.Module.Header.LibraryClass.append(Lib)\r
-        elif self.Module.Header.ComponentType == "LIBRARY":\r
+                ModuleHeader.LibraryClass.append(Lib)\r
+        elif ModuleHeader.ComponentType == "LIBRARY":\r
             Lib = LibraryClassClass()\r
-            Lib.LibraryClass = self.Module.Header.Name\r
+            Lib.LibraryClass = ModuleHeader.Name\r
             Lib.SupModuleList = DataType.SUP_MODULE_LIST\r
-            self.Module.Header.LibraryClass.append(Lib)\r
+            ModuleHeader.LibraryClass.append(Lib)\r
         \r
         #\r
         # Custom makefile of Defines\r
         #\r
-        if self.Defines.DefinesDictionary[TAB_INF_DEFINES_CUSTOM_MAKEFILE][0] != '':\r
-            for Item in self.Defines.DefinesDictionary[TAB_INF_DEFINES_CUSTOM_MAKEFILE]:\r
+        if Defines.DefinesDictionary[TAB_INF_DEFINES_CUSTOM_MAKEFILE][0] != '':\r
+            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_CUSTOM_MAKEFILE]:\r
                 List = Item.split(DataType.TAB_VALUE_SPLIT)\r
                 if len(List) == 2:\r
-                    self.Module.Header.CustomMakefile[CleanString(List[0])] = CleanString(List[1])\r
+                    ModuleHeader.CustomMakefile[CleanString(List[0])] = CleanString(List[1])\r
                 else:\r
                     RaiseParserError(Item, 'CUSTOM_MAKEFILE of Defines', File, 'CUSTOM_MAKEFILE=<Family>|<Filename>')\r
         \r
         #\r
         # EntryPoint and UnloadImage of Defines\r
         #\r
-        if self.Defines.DefinesDictionary[TAB_INF_DEFINES_ENTRY_POINT][0] != '':\r
-            for Item in self.Defines.DefinesDictionary[TAB_INF_DEFINES_ENTRY_POINT]:\r
+        if Defines.DefinesDictionary[TAB_INF_DEFINES_ENTRY_POINT][0] != '':\r
+            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_ENTRY_POINT]:\r
                 Image = ModuleExternImageClass()\r
                 Image.ModuleEntryPoint = CleanString(Item)\r
                 self.Module.ExternImages.append(Image)\r
-        if self.Defines.DefinesDictionary[TAB_INF_DEFINES_UNLOAD_IMAGE][0] != '':\r
-            for Item in self.Defines.DefinesDictionary[TAB_INF_DEFINES_UNLOAD_IMAGE]:\r
+        if Defines.DefinesDictionary[TAB_INF_DEFINES_UNLOAD_IMAGE][0] != '':\r
+            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_UNLOAD_IMAGE]:\r
                 Image = ModuleExternImageClass()\r
                 Image.ModuleUnloadImage = CleanString(Item)\r
                 self.Module.ExternImages.append(Image)\r
@@ -338,13 +371,13 @@ class Inf(InfObject):
         #\r
         # Constructor and Destructor of Defines\r
         #\r
-        if self.Defines.DefinesDictionary[TAB_INF_DEFINES_CONSTRUCTOR][0] != '':\r
-            for Item in self.Defines.DefinesDictionary[TAB_INF_DEFINES_CONSTRUCTOR]:\r
+        if Defines.DefinesDictionary[TAB_INF_DEFINES_CONSTRUCTOR][0] != '':\r
+            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_CONSTRUCTOR]:\r
                 LibraryClass = ModuleExternLibraryClass()\r
                 LibraryClass.Constructor = CleanString(Item)\r
                 self.Module.ExternLibraries.append(LibraryClass)\r
-        if self.Defines.DefinesDictionary[TAB_INF_DEFINES_DESTRUCTOR][0] != '':\r
-            for Item in self.Defines.DefinesDictionary[TAB_INF_DEFINES_DESTRUCTOR]:\r
+        if Defines.DefinesDictionary[TAB_INF_DEFINES_DESTRUCTOR][0] != '':\r
+            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_DESTRUCTOR]:\r
                 LibraryClass = ModuleExternLibraryClass()\r
                 LibraryClass.Destructor = CleanString(Item)\r
                 self.Module.ExternLibraries.append(LibraryClass)\r
@@ -352,25 +385,36 @@ class Inf(InfObject):
         #\r
         # Define of Defines\r
         #\r
-        if self.Defines.DefinesDictionary[TAB_INF_DEFINES_DEFINE][0] != '':\r
-            for Item in self.Defines.DefinesDictionary[TAB_INF_DEFINES_DEFINE]:\r
+        if Defines.DefinesDictionary[TAB_INF_DEFINES_DEFINE][0] != '':\r
+            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_DEFINE]:\r
                 List = Item.split(DataType.TAB_EQUAL_SPLIT)\r
                 if len(List) != 2:\r
                     RaiseParserError(Item, 'DEFINE of Defines', File, 'DEFINE <Word> = <Word>')\r
                 else:\r
-                    self.Module.Header.Define[CleanString(List[0])] = CleanString(List[1])\r
+                    ModuleHeader.Define[CleanString(List[0])] = CleanString(List[1])\r
         \r
         #\r
         # Spec\r
         #\r
-        if self.Defines.DefinesDictionary[TAB_INF_DEFINES_SPEC][0] != '':\r
-            for Item in self.Defines.DefinesDictionary[TAB_INF_DEFINES_SPEC]:\r
+        if Defines.DefinesDictionary[TAB_INF_DEFINES_SPEC][0] != '':\r
+            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_SPEC]:\r
                 List = Item.split(DataType.TAB_EQUAL_SPLIT)\r
                 if len(List) != 2:\r
                     RaiseParserError(Item, 'SPEC of Defines', File, 'SPEC <Word> = <Version>')\r
                 else:\r
-                    self.Module.Header.Specification[CleanString(List[0])] = CleanString(List[1])\r
+                    ModuleHeader.Specification[CleanString(List[0])] = CleanString(List[1])\r
                 \r
+\r
+    ## Transfer to Module Object\r
+    # \r
+    # Transfer all contents of an Inf file to a standard Module Object\r
+    #\r
+    def InfToModule(self):\r
+        File = self.Identification.FileFullPath\r
+        for Arch in DataType.ARCH_LIST:\r
+            ModuleHeader = ModuleHeaderClass()\r
+            self.DefinesToModuleHeader(self.Defines[Arch], ModuleHeader, Arch)\r
+            self.Module.Header[Arch] = ModuleHeader\r
         #\r
         # BuildOptions\r
         # [<Family>:]<ToolFlag>=Flag\r
@@ -387,13 +431,13 @@ class Inf(InfObject):
         #\r
         # Includes\r
         #\r
-        Includes = {}\r
+        Includes = sdict()\r
         for Arch in DataType.ARCH_LIST:\r
             for Item in self.Contents[Arch].Includes:\r
                 MergeArches(Includes, Item, Arch)\r
         for Key in Includes.keys():\r
             Include = IncludeClass()\r
-            Include.FilePath = NormPath(Key)\r
+            Include.FilePath = NormPath(Key, self._Macro)\r
             Include.SupArchList = Includes[Key]\r
             self.Module.Includes.append(Include)\r
         \r
@@ -406,7 +450,7 @@ class Inf(InfObject):
                 MergeArches(Libraries, Item, Arch)\r
         for Key in Libraries.keys():\r
             Library = ModuleLibraryClass()\r
-            Library.Library = Key\r
+            Library.Library = ReplaceMacro(Key, self._Macro)\r
             Library.SupArchList = Libraries[Key]\r
             self.Module.Libraries.append(Library)\r
         \r
@@ -437,8 +481,8 @@ class Inf(InfObject):
                     # { (LibraryClass, Instance, PcdFeatureFlag, ModuleType1|ModuleType2|ModuleType3) : [Arch1, Arch2, ...] }\r
                     #\r
                     ItemList = GetSplitValueList((Item[0] + DataType.TAB_VALUE_SPLIT * 2))\r
-                    CheckFileType(ItemList[1], '.Inf', self.Module.Header.FullPath, 'LibraryClasses', Item[0])\r
-                    CheckFileExist(self.WorkspaceDir, ItemList[1], self.Module.Header.FullPath, 'LibraryClasses', Item[0])\r
+                    CheckFileType(ItemList[1], '.Inf', File, 'LibraryClasses', Item[0])\r
+                    CheckFileExist(self.WorkspaceDir, ItemList[1], File, 'LibraryClasses', Item[0])\r
                     CheckPcdTokenInfo(ItemList[2], 'LibraryClasses', File)\r
                     MergeArches(LibraryClasses, (ItemList[0], ItemList[1], ItemList[2], DataType.TAB_VALUE_SPLIT.join(Item[1])), Arch)\r
         for Key in LibraryClasses.keys():\r
@@ -446,7 +490,7 @@ class Inf(InfObject):
             LibraryClass = LibraryClassClass()\r
             LibraryClass.Define = Defines\r
             LibraryClass.LibraryClass = Key[0]\r
-            LibraryClass.RecommendedInstance = NormPath(Key[1])\r
+            LibraryClass.RecommendedInstance = NormPath(Key[1], self._Macro)\r
             LibraryClass.FeatureFlag = Key[2]\r
             LibraryClass.SupArchList = LibraryClasses[Key]\r
             if Key[3] != '':\r
@@ -477,20 +521,20 @@ class Inf(InfObject):
                 # Not find DEFINE statement\r
                 #\r
                 elif Status == 1:\r
-                    CheckFileType(Item, '.Dec', self.Module.Header.FullPath, 'package', Item)\r
-                    CheckFileExist(self.WorkspaceDir, Item, self.Module.Header.FullPath, 'Packages', Item)\r
+                    CheckFileType(Item, '.Dec', File, 'package', Item)\r
+                    CheckFileExist(self.WorkspaceDir, Item, File, 'Packages', Item)\r
                     MergeArches(Packages, Item, Arch)\r
         for Key in Packages.keys():\r
             Package = ModulePackageDependencyClass()\r
             Package.Define = Defines\r
-            Package.FilePath = NormPath(Key)\r
+            Package.FilePath = NormPath(Key, self._Macro)\r
             Package.SupArchList = Packages[Key]\r
             self.Module.PackageDependencies.append(Package)\r
             \r
         #\r
         # Nmake\r
         #\r
-        Nmakes = {}\r
+        Nmakes = sdict()\r
         for Arch in DataType.ARCH_LIST:\r
             for Item in self.Contents[Arch].Nmake:\r
                 MergeArches(Nmakes, Item, Arch)\r
@@ -510,7 +554,7 @@ class Inf(InfObject):
                 Image.ModuleEntryPoint = Nmake.Value\r
                 self.Module.ExternImages.append(Image)\r
             elif Nmake.Name == "DPX_SOURCE":\r
-                Source = ModuleSourceFileClass(NormPath(Nmake.Value), "", "", "", "", Nmake.SupArchList)\r
+                Source = ModuleSourceFileClass(NormPath(Nmake.Value, self._Macro), "", "", "", "", Nmake.SupArchList)\r
                 self.Module.Sources.append(Source)\r
             else:\r
                 ToolList = gNmakeFlagPattern.findall(Nmake.Name)\r
@@ -536,7 +580,7 @@ class Inf(InfObject):
                 #\r
                 # Library should not have FixedPcd\r
                 #\r
-                if self.Module.Header.LibraryClass != {}:\r
+                if self.Module.Header[Arch].LibraryClass != {}:\r
                     pass\r
                 MergeArches(Pcds, self.GetPcdOfInf(Item, TAB_PCDS_FIXED_AT_BUILD, File), Arch)\r
             \r
@@ -576,11 +620,12 @@ class Inf(InfObject):
                 List = GetSplitValueList(ItemNew)\r
                 if len(List) < 5 or len(List) > 9:\r
                     RaiseParserError(Item, 'Sources', File, '<Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]')\r
+                List[0] = NormPath(List[0], self._Macro)\r
                 CheckFileExist(self.Identification.FileRelativePath, List[0], File, 'Sources', Item)\r
                 CheckPcdTokenInfo(List[4], 'Sources', File)\r
                 MergeArches(Sources, (List[0], List[1], List[2], List[3], List[4]), Arch)\r
         for Key in Sources.keys():\r
-            Source = ModuleSourceFileClass(NormPath(Key[0]), Key[2], Key[3], Key[1], Key[4], Sources[Key])\r
+            Source = ModuleSourceFileClass(Key[0], Key[2], Key[3], Key[1], Key[4], Sources[Key])\r
             self.Module.Sources.append(Source)\r
 \r
         #\r
@@ -685,7 +730,7 @@ class Inf(InfObject):
                     CheckPcdTokenInfo(List[3], 'Binaries', File)\r
                     MergeArches(Binaries, (List[0], List[1], List[2], List[3]), Arch)\r
         for Key in Binaries.keys():\r
-            Binary = ModuleBinaryFileClass(NormPath(Key[1]), Key[0], Key[2], Key[3], Binaries[Key])\r
+            Binary = ModuleBinaryFileClass(NormPath(Key[1], self._Macro), Key[0], Key[2], Key[3], Binaries[Key])\r
             self.Module.Binaries.append(Binary)\r
         \r
     ## Get Pcd Values of Inf\r
@@ -725,6 +770,28 @@ class Inf(InfObject):
 \r
         return (TokenInfo[0], TokenInfo[1], List[1], Type)\r
 \r
+    ## Parse [Defines] section\r
+    #\r
+    # Parse [Defines] section into InfDefines object\r
+    #\r
+    # @param InfFile    The path of the INF file\r
+    # @param Section    The title of "Defines" section\r
+    # @param Lines      The content of "Defines" section\r
+    #\r
+    def ParseDefines(self, InfFile, Section, Lines):\r
+        TokenList = Section.split(TAB_SPLIT)\r
+        if len(TokenList) == 3:\r
+            RaiseParserError(Section, "Defines", InfFile, "[xx.yy.%s] format (with platform) is not supported")\r
+        if len(TokenList) == 2:\r
+            Arch = TokenList[1].upper()\r
+        else:\r
+            Arch = TAB_ARCH_COMMON.upper()\r
+\r
+        if Arch not in self.Defines:\r
+            self.Defines[Arch] = InfDefines()\r
+        GetSingleValueOfKeyFromLines(Lines, self.Defines[Arch].DefinesDictionary, \r
+                                     TAB_COMMENT_SPLIT, TAB_EQUAL_SPLIT, False, None)\r
+\r
     ## Load Inf file\r
     #\r
     # Load the file if it exists\r
@@ -742,9 +809,10 @@ class Inf(InfObject):
         Sects = F.split(DataType.TAB_SECTION_START)\r
         for Sect in Sects:\r
             TabList = GetSplitValueList(Sect.split(TAB_SECTION_END, 1)[0], DataType.TAB_COMMA_SPLIT)\r
-            for Tab in TabList:            \r
-                if Tab.upper() == TAB_INF_DEFINES.upper():\r
-                    GetSingleValueOfKeyFromLines(Sect, self.Defines.DefinesDictionary, TAB_COMMENT_SPLIT, TAB_EQUAL_SPLIT, False, None)\r
+            for Tab in TabList:\r
+                if Tab.upper().find(TAB_INF_DEFINES.upper()) > -1:\r
+                    self.ParseDefines(Filename, Tab, Sect)\r
+                    # GetSingleValueOfKeyFromLines(Sect, self.Defines.DefinesDictionary, TAB_COMMENT_SPLIT, TAB_EQUAL_SPLIT, False, None)\r
                     continue\r
                 if Tab.upper().find(DataType.TAB_USER_EXTENSIONS.upper()) > -1:\r
                     self.UserExtensions = Sect\r
index c8ef6a5..83c713f 100755 (executable)
@@ -467,3 +467,48 @@ class sdict(dict):
         self.__delitem__(key)\r
         return key, value\r
 \r
+## Dictionary with restricted keys\r
+#\r
+class rdict(dict):\r
+    ## Constructor\r
+    def __init__(self, KeyList):\r
+        for Key in KeyList:\r
+            dict.__setitem__(self, Key, "")\r
+\r
+    ## []= operator\r
+    def __setitem__(self, key, value):\r
+        if key not in self:\r
+            EdkLogger.error("RestrictedDict", ATTRIBUTE_SET_FAILURE, "Key [%s] is not allowed" % key, \r
+                            ExtraData=", ".join(dict.keys(self)))\r
+        dict.__setitem__(self, key, value)\r
+\r
+    ## =[] operator\r
+    def __getitem__(self, key):\r
+        if key not in self:\r
+            return ""\r
+        return dict.__getitem__(self, key)\r
+\r
+    ## del operator\r
+    def __delitem__(self, key):\r
+        EdkLogger.error("RestrictedDict", ATTRIBUTE_ACCESS_DENIED, ExtraData="del")\r
+\r
+    ## Empty the dict\r
+    def clear(self):\r
+        for Key in self:\r
+            self.__setitem__(Key, "")\r
+\r
+    ## Return value related to a key, and remove the (key, value) from the dict\r
+    def pop(self, key, *dv):\r
+        EdkLogger.error("RestrictedDict", ATTRIBUTE_ACCESS_DENIED, ExtraData="pop")\r
+\r
+    ## Return (key, value) pair, and remove the (key, value) from the dict\r
+    def popitem(self):\r
+        EdkLogger.error("RestrictedDict", ATTRIBUTE_ACCESS_DENIED, ExtraData="popitem")\r
+\r
+##\r
+#\r
+# This acts like the main() function for the script, unless it is 'import'ed into another\r
+# script.\r
+#\r
+if __name__ == '__main__':\r
+    pass\r
index 528e1a3..3e36aa2 100644 (file)
 ##\r
 # Import Modules\r
 #\r
+import re\r
 import DataType\r
 import os.path\r
 import string\r
 import EdkLogger as EdkLogger\r
+\r
 from BuildToolError import *\r
 \r
+## Regular expression for matching macro used in DSC/DEC/INF file inclusion\r
+gMacroPattern = re.compile("\$\(([_A-Z][_A-Z0-9]*)\)", re.UNICODE)\r
+\r
 ## GetSplitValueList\r
 #\r
 # Get a value list from a string with multiple values splited with SplitTag\r
@@ -315,6 +320,35 @@ def SplitModuleType(Key):
 \r
     return ReturnValue\r
 \r
+## Replace macro in string\r
+#\r
+# This method replace macros used in given string. The macros are given in a\r
+# dictionary.\r
+# \r
+# @param String             String to be processed\r
+# @param MacroDefinitions   The macro definitions in the form of dictionary\r
+#\r
+# @retval string            The string whose macros are replaced\r
+#\r
+def ReplaceMacro(String, MacroDefinitions={}):\r
+    LastString = String\r
+    while MacroDefinitions != None and len(MacroDefinitions) > 0:\r
+        MacroUsed = gMacroPattern.findall(String)\r
+        # no macro found in String, stop replacing\r
+        if len(MacroUsed) == 0:\r
+            break\r
+\r
+        for Macro in MacroUsed:\r
+            if Macro not in MacroDefinitions:\r
+                continue\r
+            String = String.replace("$(%s)" % Macro, MacroDefinitions[Macro])\r
+        # in case there's macro not defined\r
+        if String == LastString:\r
+            break\r
+        LastString = String\r
+\r
+    return String\r
+\r
 ## NormPath\r
 #\r
 # Create a normal path\r
@@ -326,44 +360,27 @@ def SplitModuleType(Key):
 # @retval Path Formatted path\r
 #\r
 def NormPath(Path, Defines = {}):\r
+    IsRelativePath = False\r
     if Path != '':\r
+        if Path[0] == '.':\r
+            IsRelativePath = True\r
+    \r
         #\r
         # Replace with Define\r
         #\r
-        for Key in Defines.keys():\r
-            Path = Path.replace(Key, Defines[Key])\r
-\r
-        #\r
-        # Remove ${WORKSPACE}, $(EDK_SOURCE), $(EFI_SOURCE)\r
-        #\r
-        if DataType.TAB_EDK_SOURCE in os.environ:\r
-            EdkSource = os.environ[DataType.TAB_EDK_SOURCE]\r
-        else:\r
-            EdkSource = "EdkCompatibilityPkg"\r
-\r
-        if DataType.TAB_EFI_SOURCE in os.environ:\r
-            EfiSource = os.environ[DataType.TAB_EFI_SOURCE]\r
-        else:\r
-            EfiSource = os.path.join("EdkCompatibilityPkg", "Foundation")\r
-    \r
-        if Path.find(DataType.TAB_WORKSPACE) > -1:\r
-            Path = Path.replace(DataType.TAB_WORKSPACE, '')\r
+        if len(Defines) > 0:\r
+            Path = ReplaceMacro(Path, Defines)\r
+            # Remove leading path separator\r
             if len(Path) > 0 and Path[0] in [DataType.TAB_SLASH, DataType.TAB_BACK_SLASH] == 0:\r
                 Path = Path[1:]\r
-        elif Path.find(DataType.TAB_EDK_SOURCE) > -1:\r
-            Path = Path.replace(DataType.TAB_EDK_SOURCE, EdkSource)\r
-            if len(Path) > 0 and Path[0] in [DataType.TAB_SLASH, DataType.TAB_BACK_SLASH] == 0:\r
-                Path = Path[1:]\r
-        elif Path.find(DataType.TAB_EFI_SOURCE) > -1:\r
-            Path = Path.replace(DataType.TAB_EFI_SOURCE, EfiSource)\r
-            if len(Path) > 0 and Path[0] in [DataType.TAB_SLASH, DataType.TAB_BACK_SLASH] == 0:\r
-                Path = Path[1:]\r
-\r
         #\r
         # To local path format\r
         #\r
         Path = os.path.normpath(Path)\r
 \r
+    if IsRelativePath and Path[0] != '.':\r
+        Path = os.path.join('.', Path)\r
+\r
     return Path\r
 \r
 ## CleanString\r
@@ -483,16 +500,19 @@ def GetSingleValueOfKeyFromLines(Lines, Dictionary, CommentCharacter, KeySplitCh
                 else:\r
                     Value = CleanString(LineList[1], CommentCharacter).splitlines()\r
 \r
-                if Key[0] not in Keys:\r
-                    Dictionary[Key[0]] = Value\r
-                    Keys.append(Key[0])\r
+                if Key[0] in Dictionary:\r
+                    if Key[0] not in Keys:\r
+                        Dictionary[Key[0]] = Value\r
+                        Keys.append(Key[0])\r
+                    else:\r
+                        Dictionary[Key[0]].extend(Value)\r
                 else:\r
-                    Dictionary[Key[0]].extend(Value)\r
+                    Dictionary[DataType.TAB_INF_DEFINES_MACRO][Key[0]] = Value[0]\r
 \r
     if DefineValues == []:\r
-        DefineValues == ['']\r
+        DefineValues = ['']\r
     if SpecValues == []:\r
-        SpecValues == ['']\r
+        SpecValues = ['']\r
     Dictionary[DataType.TAB_INF_DEFINES_DEFINE] = DefineValues\r
     Dictionary[DataType.TAB_INF_DEFINES_SPEC] = SpecValues\r
 \r
index 5ac8b32..cf9f267 100644 (file)
@@ -18,6 +18,7 @@ import os
 import EdkLogger\r
 import DataType\r
 from BuildToolError import *\r
+import GlobalData\r
 \r
 ## TargetTxtClassObject\r
 #\r
@@ -75,19 +76,27 @@ class TargetTxtClassObject(object):
         try:\r
             F = open(FileName,'r')\r
             for Line in F:\r
-                if Line.startswith(CommentCharacter) or Line.strip() == '':\r
+                Line = Line.strip()\r
+                if Line.startswith(CommentCharacter) or Line == '':\r
                     continue\r
-                LineList = Line.split(KeySplitCharacter,1)\r
-                if len(LineList) >= 2:\r
-                    Key = LineList[0].strip()\r
-                    if Key.startswith(CommentCharacter) == False and Key in self.TargetTxtDictionary.keys():\r
-                        if Key == DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM or Key == DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF \\r
-                          or Key == DataType.TAB_TAT_DEFINES_MULTIPLE_THREAD or Key == DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER \\r
-                          or Key == DataType.TAB_TAT_DEFINES_ACTIVE_MODULE:\r
-                            self.TargetTxtDictionary[Key] = LineList[1].replace('\\', '/').strip()\r
-                        elif Key == DataType.TAB_TAT_DEFINES_TARGET or Key == DataType.TAB_TAT_DEFINES_TARGET_ARCH \\r
-                          or Key == DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG:\r
-                            self.TargetTxtDictionary[Key] = LineList[1].split()\r
+\r
+                LineList = Line.split(KeySplitCharacter, 1)\r
+                Key = LineList[0].strip()\r
+                if len(LineList) == 2:\r
+                    Value = LineList[1].strip()\r
+                else:\r
+                    Value = ""\r
+\r
+                if Key == DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM or Key == DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF \\r
+                  or Key == DataType.TAB_TAT_DEFINES_MULTIPLE_THREAD or Key == DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER \\r
+                  or Key == DataType.TAB_TAT_DEFINES_ACTIVE_MODULE:\r
+                    self.TargetTxtDictionary[Key] = Value.replace('\\', '/')\r
+                elif Key == DataType.TAB_TAT_DEFINES_TARGET or Key == DataType.TAB_TAT_DEFINES_TARGET_ARCH \\r
+                  or Key == DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG:\r
+                    self.TargetTxtDictionary[Key] = Value.split()\r
+                elif Key not in GlobalData.gGlobalDefines:\r
+                    GlobalData.gGlobalDefines[Key] = Value\r
+\r
             F.close()\r
             return 0\r
         except:\r
index 5f66bcb..6ddf978 100755 (executable)
@@ -75,6 +75,7 @@ class ModuleHeaderClass(IdentificationClass, CommonHeaderClass, DefineClass):
         self.SourceFv = ''\r
         self.CustomMakefile = {}\r
         self.Shadow = ''\r
+        self.MacroDefines = {}\r
 \r
 ## ModuleSourceFileClass\r
 #\r
@@ -413,7 +414,7 @@ class ModuleNmakeClass(CommonClass):
 #\r
 class ModuleClass(object):\r
     def __init__(self):\r
-        self.Header = ModuleHeaderClass()\r
+        self.Header = {}            # {ARCH: ModuleHeaderClass()}\r
         self.LibraryClasses = []\r
         self.Libraries = []\r
         self.Sources = []\r
index 7d58d8a..82d3190 100755 (executable)
@@ -84,7 +84,7 @@ class AprioriSection (AprioriSectionClassObject):
         \r
                 elif InfFileName in GenFdsGlobalVariable.WorkSpace.InfDatabase.keys():\r
                     Inf = GenFdsGlobalVariable.WorkSpace.InfDatabase[InfFileName]\r
-                    Guid = Inf.Module.Header.Guid\r
+                    Guid = Inf.Module.Header[Arch].Guid\r
                     \r
                     self.BinFileList = Inf.Module.Binaries\r
                     if self.BinFileList == []:\r
index f96a298..4d9bfb7 100644 (file)
@@ -77,10 +77,10 @@ class FfsInfStatement(FfsInfStatementClassObject):
         \r
         elif self.InfFileName in GenFdsGlobalVariable.WorkSpace.InfDatabase.keys():\r
             Inf = GenFdsGlobalVariable.WorkSpace.InfDatabase[self.InfFileName]\r
-            self.BaseName = Inf.Module.Header.Name\r
-            self.ModuleGuid = Inf.Module.Header.Guid\r
-            self.ModuleType = Inf.Module.Header.ModuleType\r
-            self.VersionString = Inf.Module.Header.Version\r
+            self.BaseName = Inf.Module.Header[self.CurrentArch].Name\r
+            self.ModuleGuid = Inf.Module.Header[self.CurrentArch].Guid\r
+            self.ModuleType = Inf.Module.Header[self.CurrentArch].ModuleType\r
+            self.VersionString = Inf.Module.Header[self.CurrentArch].Version\r
             self.BinFileList = Inf.Module.Binaries\r
             if self.BinFileList == []:\r
                 raise Exception ("INF %s specified in FDF could not be found in build ARCH %s!" % (self.InfFileName, GenFdsGlobalVariable.ArchList))\r
index 910fe3a..e1e47f2 100644 (file)
@@ -51,6 +51,7 @@ def main():
     Workspace = ""\r
     ArchList = None\r
     try:\r
+        EdkLogger.Initialize()\r
         if Options.verbose != None:\r
             EdkLogger.SetLevel(EdkLogger.VERBOSE)\r
             GenFdsGlobalVariable.VerboseMode = True\r
index b752123..20d9a69 100644 (file)
@@ -33,8 +33,9 @@ from Common.DataType import *
 from AutoGen.AutoGen import *\r
 from GenFds.FdfParser import *\r
 from Common.BuildToolError import *\r
-#from Common.Misc import *\r
+\r
 import Common.EdkLogger\r
+import Common.GlobalData as GlobalData\r
 \r
 # Version and Copyright\r
 VersionNumber = "0.02"\r
@@ -78,21 +79,52 @@ def IsToolInPath(tool):
 def CheckEnvVariable():\r
     # check WORKSPACE\r
     if "WORKSPACE" not in os.environ:\r
-        EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Please set environment variable: WORKSPACE!\n")\r
+        EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found", \r
+                        ExtraData="WORKSPACE")\r
 \r
-    if "EDK_SOURCE" not in os.environ:\r
-        os.environ["EDK_SOURCE"] = "EdkCompatibilityPkg"\r
+    WorkspaceDir = os.path.normpath(os.environ["WORKSPACE"])\r
+    if not os.path.exists(WorkspaceDir):\r
+        EdkLogger.error("build", FILE_NOT_FOUND, ExtraData="WORKSPACE = %s" % WorkspaceDir)\r
+    os.environ["WORKSPACE"] = WorkspaceDir\r
 \r
-    if "EFI_SOURCE" not in os.environ:\r
-        os.environ["EFI_SOURCE"] = os.path.join("EdkCompatibilityPkg", "Foundation")\r
+    #\r
+    # Check EFI_SOURCE and EDK_SOURCE. If EFI_SOURCE is not set but EDK_SOURCE\r
+    # is set, set EFI_SOURCE to EDK_SOURCE (R8 build convention)\r
+    # \r
+    if "EFI_SOURCE" not in os.environ and "EDK_SOURCE" not in os.environ:\r
+        os.environ["EFI_SOURCE"] = os.path.join(WorkspaceDir, GlobalData.gEdkCompatibilityPkg)\r
+        os.environ["EDK_SOURCE"] = os.path.join(WorkspaceDir, GlobalData.gEdkCompatibilityPkg)\r
+    elif "EFI_SOURCE" in os.environ and "EDK_SOURCE" not in os.environ:\r
+        os.environ["EDK_SOURCE"] = os.path.join(os.environ["EFI_SOURCE"], GlobalData.gEdkSource)\r
+    elif "EFI_SOURCE" not in os.environ and "EDK_SOURCE" in os.environ:\r
+        os.environ["EFI_SOURCE"] = os.environ["EDK_SOURCE"]\r
+\r
+    EfiSourceDir = os.path.normpath(os.environ["EFI_SOURCE"])\r
+    EdkSourceDir = os.path.normpath(os.environ["EDK_SOURCE"])\r
+    if not os.path.exists(EfiSourceDir):\r
+        EdkLogger.warn("build", "EFI_SOURCE = %s doesn't exist. R8 modules could not be built." % EfiSourceDir)\r
+    if not os.path.exists(EdkSourceDir):\r
+        EdkLogger.warn("build", "EDK_SOURCE = %s doesn't exist. R8 modules could not be built." % EdkSourceDir)\r
+\r
+    # change absolute path to relative path to WORKSPACE\r
+    if EfiSourceDir.upper().find(WorkspaceDir.upper()) != 0:\r
+        EdkLogger.error("build", PARAMETER_INVALID, "EFI_SOURCE is not under WORKSPACE", \r
+                        ExtraData="WORKSPACE = %s\n    EFI_SOURCE = %s" % (WorkspaceDir, EfiSourceDir))\r
+    if EdkSourceDir.upper().find(WorkspaceDir.upper()) != 0:\r
+        EdkLogger.error("build", PARAMETER_INVALID, "EDK_SOURCE is not under WORKSPACE", \r
+                        ExtraData="WORKSPACE = %s\n    EDK_SOURCE = %s" % (WorkspaceDir, EdkSourceDir))\r
+    EfiSourceDir = EfiSourceDir[len(WorkspaceDir)+1:]\r
+    EdkSourceDir = EdkSourceDir[len(WorkspaceDir)+1:]\r
 \r
     # check EDK_TOOLS_PATH\r
-    if "EDK_TOOLS_PATH" not in os.environ == None:\r
-        EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Please set environment variable: EDK_TOOLS_PATH!\n")\r
+    if "EDK_TOOLS_PATH" not in os.environ:\r
+        EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found", \r
+                        ExtraData="EDK_TOOLS_PATH")\r
 \r
     # check PATH\r
     if "PATH" not in os.environ:\r
-        EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Please set environment variable: PATH!\n")\r
+        EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found", \r
+                        ExtraData="PATH")\r
 \r
     PathString = os.environ["PATH"]\r
     ToolPath = os.path.normpath(os.path.join(os.environ["EDK_TOOLS_PATH"], 'Bin', sys.platform.title()))\r
@@ -103,6 +135,13 @@ def CheckEnvVariable():
         EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Please execute %s to set %s in environment variable: PATH!\n"\r
                             % (os.path.normpath(os.path.join(PathString, 'edksetup.bat')), ToolPath))\r
 \r
+    # for macro replacement in R9 DSC/DEC/INF file\r
+    GlobalData.gGlobalDefines["WORKSPACE"] = ""\r
+\r
+    # for macro replacement in R8 INF file\r
+    GlobalData.gGlobalDefines["EFI_SOURCE"] = EfiSourceDir\r
+    GlobalData.gGlobalDefines["EDK_SOURCE"] = EdkSourceDir\r
+\r
 ## Get normalized file path\r
 #\r
 # Convert the path to be local format, and remove the WORKSPACE path at the\r
@@ -593,8 +632,9 @@ class Build():
     #   @param  SpawnMode           Indicate multi-thread build mode\r
     #   @param  ThreadNumber        The maximum number of thread if in multi-thread build mode\r
     #\r
-    def __init__(self, Target, WorkspaceDir, Platform, Module, Arch, ToolChain, BuildTarget,\r
-                 FlashDefinition, FdList=[], FvList=[], MakefileType="nmake", SpawnMode=False, ThreadNumber=2):\r
+    def __init__(self, Target, WorkspaceDir, Platform, Module, Arch, ToolChain, \r
+                 BuildTarget, FlashDefinition, FdList=[], FvList=[], \r
+                 MakefileType="nmake", SpawnMode=False, ThreadNumber=2):\r
 \r
         self.WorkspaceDir = WorkspaceDir\r
 \r
@@ -628,8 +668,10 @@ class Build():
         self.Progress.Stop("done!")\r
 \r
         # print current build environment and configuration\r
-        EdkLogger.info('')\r
+        EdkLogger.quiet('')\r
         EdkLogger.quiet("%-24s = %s" % ("WORKSPACE", os.environ["WORKSPACE"]))\r
+        EdkLogger.quiet("%-24s = %s" % ("EFI_SOURCE", os.environ["EFI_SOURCE"]))\r
+        EdkLogger.quiet("%-24s = %s" % ("EDK_SOURCE", os.environ["EDK_SOURCE"]))\r
         EdkLogger.quiet("%-24s = %s" % ("EDK_TOOLS_PATH", os.environ["EDK_TOOLS_PATH"]))\r
         EdkLogger.info('')\r
         EdkLogger.info('%-24s = %s' % ("TARGET_ARCH", ' '.join(self.ArchList)))\r
@@ -1067,6 +1109,17 @@ class Build():
             if Utils.gDependencyDatabase == None:\r
                 Utils.gDependencyDatabase = {}\r
 \r
+def ParseDefines(DefineList=[]):\r
+    DefineDict = {}\r
+    if DefineList != None:\r
+        for Define in DefineList:\r
+            DefineTokenList = Define.split("=", 1)\r
+            if len(DefineTokenList) == 1:\r
+                DefineDict[DefineTokenList[0]] = ""\r
+            else:\r
+                DefineDict[DefineTokenList[0]] = DefineTokenList[1].strip()\r
+    return DefineDict\r
+\r
 ## Parse command line options\r
 #\r
 # Using standard Python module optparse to parse command line option of this tool.\r
@@ -1099,6 +1152,8 @@ def MyOptionParser():
     Parser.add_option("-k", "--msft", action="store_const", dest="MakefileType", const="nmake", help="Make Option: Generate only NMAKE Makefiles: Makefile")\r
     Parser.add_option("-g", "--gcc", action="store_const", dest="MakefileType", const="gmake", help="Make Option: Generate only GMAKE Makefiles: GNUmakefile")\r
     Parser.add_option("-l", "--all", action="store_const", dest="MakefileType", const="all", help="Make Option: Generate both NMAKE and GMAKE makefiles.")\r
+    Parser.add_option("-D", action="append", dest="Defines", metavar="NAME[=[VALUE]]",\r
+        help="Define global macro which can be used in DSC/DEC/INF files.")\r
 \r
     Parser.add_option("-w", "--warning-as-error", action="store_true", dest="WarningAsError", help="Treat warning in tools as error.")\r
     Parser.add_option("-j", "--log", action="store", dest="LogFile", help="Putlog in specified file as well as on console.")\r
@@ -1122,6 +1177,10 @@ def MyOptionParser():
 #\r
 def Main():\r
     StartTime = time.clock()\r
+\r
+    # Initialize log system\r
+    EdkLogger.Initialize()\r
+\r
     #\r
     # Parse the options and args\r
     #\r
@@ -1135,6 +1194,7 @@ def Main():
     else:\r
         Target = Target[0].lower()\r
 \r
+    # Set log level\r
     if Option.verbose != None:\r
         EdkLogger.SetLevel(EdkLogger.VERBOSE)\r
     elif Option.quiet != None:\r
@@ -1154,6 +1214,7 @@ def Main():
     ReturnCode = 0\r
     MyBuild = None\r
     try:\r
+        GlobalData.gGlobalDefines = ParseDefines(Option.Defines)\r
         #\r
         # Check environment variable: EDK_TOOLS_PATH, WORKSPACE, PATH\r
         #\r