]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
Sync tool code to BuildTools project r1739.
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index 028c4e34e3542f3e992f13819af2c9282f3b302c..9594ef0caee5544af213a4e143e0a57d0c9ef5a4 100644 (file)
@@ -21,6 +21,7 @@ import copy
 import GenC
 import GenMake
 import GenDepex
+from StringIO import StringIO
 
 from StrGather import *
 from BuildEngine import BuildRule
@@ -48,8 +49,8 @@ gBuildRuleFile = 'Conf/build_rule.txt'
 gAutoGenCodeFileName = "AutoGen.c"
 gAutoGenHeaderFileName = "AutoGen.h"
 gAutoGenStringFileName = "%(module_name)sStrDefs.h"
+gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"
 gAutoGenDepexFileName = "%(module_name)s.depex"
-gAutoGenSmmDepexFileName = "%(module_name)s.smm"
 
 ## Base class for AutoGen
 #
@@ -137,7 +138,8 @@ class WorkspaceAutoGen(AutoGen):
     #   @param  SkuId                   SKU id from command line
     #
     def _Init(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,
-              BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=[], Fvs=[], SkuId=''):
+              BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=[], Fvs=[], SkuId='', 
+              ReportFile=None, ReportType=None):
         self.MetaFile       = ActivePlatform.MetaFile
         self.WorkspaceDir   = WorkspaceDir
         self.Platform       = ActivePlatform
@@ -145,6 +147,8 @@ class WorkspaceAutoGen(AutoGen):
         self.ToolChain      = Toolchain
         self.ArchList       = ArchList
         self.SkuId          = SkuId
+        self.ReportFile     = ReportFile
+        self.ReportType     = ReportType
 
         self.BuildDatabase  = MetaFileDb
         self.TargetTxt      = BuildConfig
@@ -181,6 +185,325 @@ class WorkspaceAutoGen(AutoGen):
             Pa.CollectPlatformDynamicPcds()
             self.AutoGenObjectList.append(Pa)
 
+        AllPcds = {}
+        MaxLen = 0
+        for Pcd in Pa._DynaPcdList_ + Pa._NonDynaPcdList_:
+          if Pcd.TokenSpaceGuidCName not in AllPcds:
+            AllPcds[Pcd.TokenSpaceGuidCName] = {}
+          if Pcd.Type not in AllPcds[Pcd.TokenSpaceGuidCName]:
+            AllPcds[Pcd.TokenSpaceGuidCName][Pcd.Type] = []
+          AllPcds[Pcd.TokenSpaceGuidCName][Pcd.Type] += [Pcd]
+          if len(Pcd.TokenCName) > MaxLen:
+            MaxLen = len(Pcd.TokenCName)
+
+        if self.ReportFile <> None:
+          try:
+            if os.path.exists(self.ReportFile):
+              os.remove(self.ReportFile)
+
+            Fd = open(self.ReportFile, "w")
+       
+            Fd.write ('===============================================================================\n')
+            Fd.write ('Platform Configuration Database Report\n')
+            Fd.write ('===============================================================================\n')
+            Fd.write ('  *P  - Platform scoped PCD override in DSC file\n')
+            Fd.write ('  *F  - Platform scoped PCD override in FDF file\n')
+            Fd.write ('  *M  - Module scoped PCD override in DSC file\n')
+            Fd.write ('  *C  - Library has a constructor\n')
+            Fd.write ('  *D  - Library has a destructor\n')
+            Fd.write ('  *CD - Library has both a constructor and a destructor\n')
+            Fd.write ('===============================================================================\n')
+            Fd.write ('\n')
+            Fd.write ('===============================================================================\n')
+            Fd.write ('PLATFORM: %s\n' % (ActivePlatform.MetaFile))
+            Fd.write ('===============================================================================\n')
+            for Key in AllPcds:
+              Fd.write ('%s\n' % (Key))
+              for Type in AllPcds[Key]:
+                TypeName = ''
+                DecType = Type
+                if Type == 'FixedAtBuild':
+                  TypeName = 'FIXED'
+                if Type == 'PatchableInModule':
+                  TypeName = 'PATCH'
+                if Type == 'FeatureFlag':
+                  TypeName = 'FLAG'
+                if Type == 'Dynamic':
+                  TypeName = 'DYN'
+                if Type == 'DynamicHii':
+                  TypeName = 'DYNHII'
+                  DecType = 'Dynamic'
+                if Type == 'DynamicVpd':
+                  TypeName = 'DYNVPD'
+                  DecType = 'Dynamic'
+                if Type == 'DynamicEx':
+                  TypeName = 'DEX'
+                  DecType = 'Dynamic'
+                if Type == 'DynamicExHii':
+                  TypeName = 'DEXHII'
+                  DecType = 'Dynamic'
+                if Type == 'DynamicExVpd':
+                  TypeName = 'DEXVPD'
+                  DecType = 'Dynamic'
+                for Pcd in AllPcds[Key][Type]:
+                
+                  DecDefaultValue = None
+                  for F in Pa.Platform.Modules.keys():
+                    for Package in Pa.Platform.Modules[F].M.Module.Packages:
+                      if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, DecType) in Package.Pcds:
+                        if DecDefaultValue == None:
+                          DecDefaultValue = Package.Pcds[Pcd.TokenCName, Pcd.TokenSpaceGuidCName, DecType].DefaultValue
+
+                  DscDefaultValue = None
+                  if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in self.BuildDatabase.WorkspaceDb.PlatformList[0].Pcds:
+                    DscDefaultValue = self.BuildDatabase.WorkspaceDb.PlatformList[0].Pcds[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)].DefaultValue
+
+                  if Pcd.DatumType in ('UINT8', 'UINT16', 'UINT32', 'UINT64'):
+                    if Pcd.DefaultValue.strip()[0:2].upper() == '0X':
+                      PcdDefaultValueNumber = int(Pcd.DefaultValue.strip(), 16)
+                    else:
+                      PcdDefaultValueNumber = int(Pcd.DefaultValue.strip())
+                  
+                    if DecDefaultValue == None:
+                      DecMatch = True
+                    else:
+                      if DecDefaultValue.strip()[0:2].upper() == '0X':
+                        DecDefaultValueNumber = int(DecDefaultValue.strip(), 16)
+                      else:
+                        DecDefaultValueNumber = int(DecDefaultValue.strip())
+                      DecMatch = (DecDefaultValueNumber == PcdDefaultValueNumber)
+                      
+                    if DscDefaultValue == None:
+                      DscMatch = True
+                    else:
+                      if DscDefaultValue.strip()[0:2].upper() == '0X':
+                        DscDefaultValueNumber = int(DscDefaultValue.strip(), 16)
+                      else:
+                        DscDefaultValueNumber = int(DscDefaultValue.strip())
+                      DscMatch = (DscDefaultValueNumber == PcdDefaultValueNumber)
+                  else:
+                    if DecDefaultValue == None:
+                      DecMatch = True
+                    else:
+                      DecMatch = (DecDefaultValue == Pcd.DefaultValue)
+                      
+                    if DscDefaultValue == None:
+                      DscMatch = True
+                    else:
+                      DscMatch = (DscDefaultValue == Pcd.DefaultValue)
+     
+                  if DecMatch:
+                    Fd.write ('    %-*s: %6s %10s = %-22s\n' % (MaxLen + 2, Pcd.TokenCName, TypeName, '('+Pcd.DatumType+')', Pcd.DefaultValue))
+                  else:
+                    if DscMatch:
+                      if (Pcd.TokenCName, Key) in PcdSet:
+                        Fd.write (' *F %-*s: %6s %10s = %-22s\n' % (MaxLen + 2, Pcd.TokenCName, TypeName, '('+Pcd.DatumType+')', Pcd.DefaultValue))
+                      else:
+                        Fd.write (' *P %-*s: %6s %10s = %-22s\n' % (MaxLen + 2, Pcd.TokenCName, TypeName, '('+Pcd.DatumType+')', Pcd.DefaultValue))
+
+                  for F in Pa.Platform.Modules.keys():
+                    for ModulePcd in Pa.Platform.Modules[F].M.ModulePcdList + Pa.Platform.Modules[F].M.LibraryPcdList:
+                      if ModulePcd.TokenSpaceGuidCName <> Pcd.TokenSpaceGuidCName:
+                        continue
+                      if ModulePcd.TokenCName <> Pcd.TokenCName:
+                        continue
+                      if Pcd.DatumType in ('UINT8', 'UINT16', 'UINT32', 'UINT64'):
+                        if ModulePcd.DefaultValue.strip()[0:2].upper() == '0X':
+                          ModulePcdDefaultValueNumber = int(ModulePcd.DefaultValue.strip(), 16)
+                        else:
+                          ModulePcdDefaultValueNumber = int(ModulePcd.DefaultValue.strip())
+                        Match = (ModulePcdDefaultValueNumber == PcdDefaultValueNumber)
+                      else:
+                        Match = (ModulePcd.DefaultValue == Pcd.DefaultValue)
+                      if Match:
+                        continue
+                      Fd.write (' *M %*s = %s\n' % (MaxLen + 21, str(F).split('\\')[-1], ModulePcd.DefaultValue))
+                      
+                  if not DecMatch and DscMatch and DecDefaultValue <> None:
+                    Fd.write ('    %*s = %s\n' % (MaxLen + 21, 'DEC DEFAULT', DecDefaultValue))
+                      
+              Fd.write ('\n')
+
+            Fd.write ('===============================================================================\n')
+            Fd.write ('===============================================================================\n')
+            
+            for F in Pa.Platform.Modules.keys():
+              Fd.write ('\n')
+              Fd.write ('===============================================================================\n')
+              Fd.write ('MODULE: %s\n' % (F))
+              Fd.write ('===============================================================================\n')
+              
+              Fd.write ('PLATFORM CONFIGURATION DATABASE\n')
+              Fd.write ('-------------------------------------------------------------------------------\n')
+              ModuleFirst = True
+              for Key in AllPcds:
+                First = True
+                for Type in AllPcds[Key]:
+                  TypeName = ''
+                  DecType = Type
+                  if Type == 'FixedAtBuild':
+                    TypeName = 'FIXED'
+                  if Type == 'PatchableInModule':
+                    TypeName = 'PATCH'
+                  if Type == 'FeatureFlag':
+                    TypeName = 'FLAG'
+                  if Type == 'Dynamic':
+                    TypeName = 'DYN'
+                  if Type == 'DynamicHii':
+                    TypeName = 'DYNHII'
+                    DecType = 'Dynamic'
+                  if Type == 'DynamicVpd':
+                    TypeName = 'DYNVPD'
+                    DecType = 'Dynamic'
+                  if Type == 'DynamicEx':
+                    TypeName = 'DEX'
+                    DecType = 'Dynamic'
+                  if Type == 'DynamicExHii':
+                    TypeName = 'DEXHII'
+                    DecType = 'Dynamic'
+                  if Type == 'DynamicExVpd':
+                    TypeName = 'DEXVPD'
+                    DecType = 'Dynamic'
+                  for Pcd in AllPcds[Key][Type]:
+                    for ModulePcd in Pa.Platform.Modules[F].M.ModulePcdList + Pa.Platform.Modules[F].M.LibraryPcdList:
+                      if ModulePcd.TokenSpaceGuidCName <> Pcd.TokenSpaceGuidCName:
+                        continue
+                      if ModulePcd.TokenCName <> Pcd.TokenCName:
+                        continue
+                      if ModulePcd.Type <> Pcd.Type:
+                        continue
+                      if First:
+                        if ModuleFirst:
+                          ModuleFirst = False
+                        else:
+                          Fd.write ('\n')
+                        Fd.write ('%s\n' % (Key))
+                        First = False
+
+                      InfDefaultValue = ModulePcd.InfDefaultValue
+                      if InfDefaultValue == '':
+                        InfDefaultValue = None
+
+                      DecDefaultValue = None
+                      for Package in Pa.Platform.Modules[F].M.Module.Packages:
+                        if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, DecType) in Package.Pcds:
+                          if DecDefaultValue == None:
+                            DecDefaultValue = Package.Pcds[Pcd.TokenCName, Pcd.TokenSpaceGuidCName, DecType].DefaultValue
+
+                      DscDefaultValue = None
+                      if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in self.BuildDatabase.WorkspaceDb.PlatformList[0].Pcds:
+                        DscDefaultValue = self.BuildDatabase.WorkspaceDb.PlatformList[0].Pcds[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)].DefaultValue
+
+                      DscModuleOverrideDefaultValue = None
+                      if F in self.BuildDatabase.WorkspaceDb.PlatformList[0].Modules:
+                        if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in self.BuildDatabase.WorkspaceDb.PlatformList[0].Modules[F].Pcds:
+                          DscModuleOverrideDefaultValue = self.BuildDatabase.WorkspaceDb.PlatformList[0].Modules[F].Pcds[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)].DefaultValue
+                      
+                      if Pcd.DatumType in ('UINT8', 'UINT16', 'UINT32', 'UINT64'):
+                        if ModulePcd.DefaultValue.strip()[0:2].upper() == '0X':
+                          ModulePcdDefaultValueNumber = int(ModulePcd.DefaultValue.strip(), 16)
+                        else:
+                          ModulePcdDefaultValueNumber = int(ModulePcd.DefaultValue.strip())
+                          
+                        if DecDefaultValue == None:
+                          DecMatch = True
+                        else:
+                          if DecDefaultValue.strip()[0:2].upper() == '0X':
+                            DecDefaultValueNumber = int(DecDefaultValue.strip(), 16)
+                          else:
+                            DecDefaultValueNumber = int(DecDefaultValue.strip())
+                          DecMatch = (DecDefaultValueNumber == ModulePcdDefaultValueNumber)
+                          
+                        if InfDefaultValue == None:
+                          InfMatch = True
+                        else:
+                          if InfDefaultValue.strip()[0:2].upper() == '0X':
+                            InfDefaultValueNumber = int(InfDefaultValue.strip(), 16)
+                          else:
+                            InfDefaultValueNumber = int(InfDefaultValue.strip())
+                          InfMatch = (InfDefaultValueNumber == ModulePcdDefaultValueNumber)
+
+                        if DscDefaultValue == None:
+                          DscMatch = True
+                        else:
+                          if DscDefaultValue.strip()[0:2].upper() == '0X':
+                            DscDefaultValueNumber = int(DscDefaultValue.strip(), 16)
+                          else:
+                            DscDefaultValueNumber = int(DscDefaultValue.strip())
+                          DscMatch = (DscDefaultValueNumber == ModulePcdDefaultValueNumber)
+                      else:
+                        if DecDefaultValue == None:
+                          DecMatch = True
+                        else:
+                          DecMatch = (DecDefaultValue == ModulePcd.DefaultValue)
+                          
+                        if InfDefaultValue == None:
+                          InfMatch = True
+                        else:
+                          InfMatch = (InfDefaultValue == ModulePcd.DefaultValue)
+                          
+                        if DscDefaultValue == None:
+                          DscMatch = True
+                        else:
+                          DscMatch = (DscDefaultValue == ModulePcd.DefaultValue)
+                          
+                      if DecMatch and InfMatch:
+                        Fd.write ('    %-*s: %6s %10s = %-22s\n' % (MaxLen, Pcd.TokenCName, TypeName, '('+Pcd.DatumType+')', ModulePcd.DefaultValue))
+                      else:
+                        if DscMatch and DscModuleOverrideDefaultValue == None:
+                          if (Pcd.TokenCName, Key) in PcdSet:
+                            Fd.write (' *F %-*s: %6s %10s = %-22s\n' % (MaxLen, Pcd.TokenCName, TypeName, '('+Pcd.DatumType+')', ModulePcd.DefaultValue))
+                          else:
+                            Fd.write (' *P %-*s: %6s %10s = %-22s\n' % (MaxLen, Pcd.TokenCName, TypeName, '('+Pcd.DatumType+')', ModulePcd.DefaultValue))
+                        else:
+                          Fd.write (' *M %-*s: %6s %10s = %-22s\n' % (MaxLen, Pcd.TokenCName, TypeName, '('+Pcd.DatumType+')', ModulePcd.DefaultValue))
+                          if DscDefaultValue <> None:
+                            Fd.write ('    %*s = %s\n' % (MaxLen + 19, 'DSC DEFAULT', DscDefaultValue))
+                        if InfDefaultValue <> None:
+                          Fd.write ('    %*s = %s\n' % (MaxLen + 19, 'INF DEFAULT', InfDefaultValue))
+                        if DecDefaultValue <> None and not DecMatch:
+                          Fd.write ('    %*s = %s\n' % (MaxLen + 19, 'DEC DEFAULT', DecDefaultValue))
+              Fd.write ('-------------------------------------------------------------------------------\n')
+              Fd.write ('LIBRARIES\n')
+              Fd.write ('-------------------------------------------------------------------------------\n')
+              for Lib in Pa.Platform.Modules[F].M.DependentLibraryList:
+                if len(Lib.ConstructorList) > 0:
+                  if  len(Lib.DestructorList) > 0:
+                    Fd.write (' *CD')
+                  else:
+                    Fd.write (' *C ')
+                else:
+                  if  len(Lib.DestructorList) > 0:
+                    Fd.write (' *D ')
+                  else:
+                    Fd.write ('    ')
+                Fd.write (' %s\n' % (Lib))
+                for Depex in Lib.DepexExpression[Pa.Platform.Modules[F].M.Arch, Pa.Platform.Modules[F].M.ModuleType]:
+                  Fd.write ('       DEPEX = %s\n' % (Depex))
+              Fd.write ('-------------------------------------------------------------------------------\n')
+
+              Fd.write ('MODULE DEPENDENCY EXPRESSION\n')
+              if len(Pa.Platform.Modules[F].M.Module.DepexExpression[Pa.Platform.Modules[F].M.Arch, Pa.Platform.Modules[F].M.ModuleType]) == 0:
+                Fd.write ('  NONE\n')
+              else:
+                for Depex in Pa.Platform.Modules[F].M.Module.DepexExpression[Pa.Platform.Modules[F].M.Arch, Pa.Platform.Modules[F].M.ModuleType]:
+                  Fd.write ('  %s\n' % (Depex))
+              Fd.write ('-------------------------------------------------------------------------------\n')
+
+              Fd.write ('MODULE + LIBRARY DEPENDENCY EXPRESSION\n')
+              if Pa.Platform.Modules[F].M.ModuleType in Pa.Platform.Modules[F].M.DepexExpressionList:
+                if Pa.Platform.Modules[F].M.DepexExpressionList[Pa.Platform.Modules[F].M.ModuleType] == '': 
+                  Fd.write ('  NONE\n')
+                else:
+                  Fd.write ('  %s\n' % (Pa.Platform.Modules[F].M.DepexExpressionList[Pa.Platform.Modules[F].M.ModuleType]))
+              else:
+                Fd.write ('  NONE\n')
+              Fd.write ('-------------------------------------------------------------------------------\n')
+              
+            Fd.close()
+          except:
+            EdkLogger.error(None, FILE_OPEN_FAILURE, ExtraData=self.ReportFile)
+                  
         self._BuildDir = None
         self._FvDir = None
         self._MakeFileDir = None
@@ -421,6 +744,9 @@ class PlatformAutoGen(AutoGen):
         for F in self.Platform.Modules.keys():
             M = ModuleAutoGen(self.Workspace, F, self.BuildTarget, self.ToolChain, self.Arch, self.MetaFile)
             #GuidValue.update(M.Guids)
+            
+            self.Platform.Modules[F].M = M
+            
             for PcdFromModule in M.ModulePcdList+M.LibraryPcdList:
                 # make sure that the "VOID*" kind of datum has MaxDatumSize set
                 if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize == None:
@@ -1061,12 +1387,45 @@ class PlatformAutoGen(AutoGen):
     #
     def _ExpandBuildOption(self, Options):
         BuildOptions = {}
+        FamilyMatch  = False
+        FamilyIsNull = True
+        for Key in Options:
+            Family = Key[0]
+            Target, Tag, Arch, Tool, Attr = Key[1].split("_")
+            # if tool chain family doesn't match, skip it
+            if Tool in self.ToolDefinition and Family != "":
+                FamilyIsNull = False
+                if self.ToolDefinition[Tool].get(TAB_TOD_DEFINES_BUILDRULEFAMILY, "") != "":
+                    if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_BUILDRULEFAMILY]:
+                        continue
+                elif Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:
+                    continue
+                FamilyMatch = True
+            # expand any wildcard
+            if Target == "*" or Target == self.BuildTarget:
+                if Tag == "*" or Tag == self.ToolChain:
+                    if Arch == "*" or Arch == self.Arch:
+                        if Tool not in BuildOptions:
+                            BuildOptions[Tool] = {}
+                        if Attr != "FLAGS" or Attr not in BuildOptions[Tool]:
+                            BuildOptions[Tool][Attr] = Options[Key]
+                        else:
+                            # append options for the same tool
+                            BuildOptions[Tool][Attr] += " " + Options[Key]
+        # Build Option Family has been checked, which need't to be checked again for family.
+        if FamilyMatch or FamilyIsNull:
+            return BuildOptions
+        
         for Key in Options:
             Family = Key[0]
             Target, Tag, Arch, Tool, Attr = Key[1].split("_")
             # if tool chain family doesn't match, skip it
-            if Family and Tool in self.ToolDefinition and Family != self.ToolDefinition[Tool]["FAMILY"]:
+            if Tool not in self.ToolDefinition or Family =="":
                 continue
+            # option has been added before
+            if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:
+                continue
+
             # expand any wildcard
             if Target == "*" or Target == self.BuildTarget:
                 if Tag == "*" or Tag == self.ToolChain:
@@ -1227,6 +1586,7 @@ class ModuleAutoGen(AutoGen):
         self._ProtocolList            = None
         self._PpiList                 = None
         self._DepexList               = None
+        self._DepexExpressionList     = None
         self._BuildOption             = None
         self._BuildTargets            = None
         self._IntroBuildTargetList    = None
@@ -1400,11 +1760,7 @@ class ModuleAutoGen(AutoGen):
             if self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:
                 return self._DepexList
 
-            if self.ModuleType == "DXE_SMM_DRIVER":
-                self._DepexList["DXE_DRIVER"] = []
-                self._DepexList["SMM_DRIVER"] = []
-            else:
-                self._DepexList[self.ModuleType] = []
+            self._DepexList[self.ModuleType] = []
 
             for ModuleType in self._DepexList:
                 DepexList = self._DepexList[ModuleType]
@@ -1430,6 +1786,42 @@ class ModuleAutoGen(AutoGen):
                     EdkLogger.verbose('')
         return self._DepexList
 
+    ## Merge dependency expression
+    #
+    #   @retval     list    The token list of the dependency expression after parsed
+    #
+    def _GetDepexExpressionTokenList(self):
+        if self._DepexExpressionList == None:
+            self._DepexExpressionList = {}
+            if self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:
+                return self._DepexExpressionList
+
+            self._DepexExpressionList[self.ModuleType] = ''
+
+            for ModuleType in self._DepexExpressionList:
+                DepexExpressionList = self._DepexExpressionList[ModuleType]
+                #
+                # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
+                #
+                for M in [self.Module] + self.DependentLibraryList:
+                    Inherited = False
+                    for D in M.DepexExpression[self.Arch, ModuleType]:
+                        if DepexExpressionList != '':
+                            DepexExpressionList += ' AND '
+                        DepexExpressionList += '('
+                        DepexExpressionList += D
+                        DepexExpressionList = DepexExpressionList.rstrip('END').strip()
+                        DepexExpressionList += ')'
+                        Inherited = True
+                    if Inherited:
+                        EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexExpressionList))
+                    if 'BEFORE' in DepexExpressionList or 'AFTER' in DepexExpressionList:
+                        break
+                if len(DepexExpressionList) > 0:
+                    EdkLogger.verbose('')
+                self._DepexExpressionList[ModuleType] = DepexExpressionList
+        return self._DepexExpressionList
+
     ## Return the list of specification version required for the module
     #
     #   @retval     list    The list of specification defined in module file
@@ -1547,12 +1939,12 @@ class ModuleAutoGen(AutoGen):
             if Source != File:
                 CreateDirectory(Source.Dir)
 
-            if FileType in self.BuildRules:
+            if File.IsBinary and File == Source:
+                RuleObject = self.BuildRules[TAB_DEFAULT_BINARY_FILE]
+            elif FileType in self.BuildRules:
                 RuleObject = self.BuildRules[FileType]
             elif Source.Ext in self.BuildRules:
                 RuleObject = self.BuildRules[Source.Ext]
-            elif File.IsBinary and File == Source:
-                RuleObject = self.BuildRules[TAB_DEFAULT_BINARY_FILE]
             else:
                 # stop at no more rules
                 if LastTarget:
@@ -1566,7 +1958,8 @@ class ModuleAutoGen(AutoGen):
 
             # stop at STATIC_LIBRARY for library
             if self.IsLibrary and FileType == TAB_STATIC_LIBRARY:
-                self._FinalBuildTargetList.add(LastTarget)
+                if LastTarget:
+                    self._FinalBuildTargetList.add(LastTarget)
                 break
 
             Target = RuleObject.Apply(Source)
@@ -1635,12 +2028,17 @@ class ModuleAutoGen(AutoGen):
     #   @retval     list        The list of auto-generated file
     #
     def _GetAutoGenFileList(self):
+        UniStringAutoGenC = True
+        UniStringBinBuffer = None
+        if self.BuildType == 'UEFI_HII':
+            UniStringBinBuffer = StringIO()
+            UniStringAutoGenC = False
         if self._AutoGenFileList == None:
             self._AutoGenFileList = {}
             AutoGenC = TemplateString()
             AutoGenH = TemplateString()
             StringH = TemplateString()
-            GenC.CreateCode(self, AutoGenC, AutoGenH, StringH)
+            GenC.CreateCode(self, AutoGenC, AutoGenH, StringH, UniStringAutoGenC, UniStringBinBuffer)
             if str(AutoGenC) != "" and TAB_C_CODE_FILE in self.FileTypes:
                 AutoFile = PathClass(gAutoGenCodeFileName, self.DebugDir)
                 self._AutoGenFileList[AutoFile] = str(AutoGenC)
@@ -1653,6 +2051,13 @@ class ModuleAutoGen(AutoGen):
                 AutoFile = PathClass(gAutoGenStringFileName % {"module_name":self.Name}, self.DebugDir)
                 self._AutoGenFileList[AutoFile] = str(StringH)
                 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
+            if UniStringBinBuffer != None and UniStringBinBuffer.getvalue() != "":
+                AutoFile = PathClass(gAutoGenStringFormFileName % {"module_name":self.Name}, self.OutputDir)
+                self._AutoGenFileList[AutoFile] = UniStringBinBuffer.getvalue()\r
+                AutoFile.IsBinary = True
+                self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
+            if UniStringBinBuffer != None:\r
+                UniStringBinBuffer.close()\r
         return self._AutoGenFileList
 
     ## Return the list of library modules explicitly or implicityly used by this module
@@ -1805,7 +2210,7 @@ class ModuleAutoGen(AutoGen):
         IgoredAutoGenList = []
 
         for File in self.AutoGenFileList:
-            if GenC.Generate(File.Path, self.AutoGenFileList[File]):
+            if GenC.Generate(File.Path, self.AutoGenFileList[File], File.IsBinary):
                 #Ignore R8 AutoGen.c
                 if self.AutoGenVersion < 0x00010005 and File.Name == 'AutoGen.c':
                         continue
@@ -1822,10 +2227,7 @@ class ModuleAutoGen(AutoGen):
             if len(self.DepexList[ModuleType]) == 0:
                 continue
             Dpx = GenDepex.DependencyExpression(self.DepexList[ModuleType], ModuleType, True)
-            if ModuleType == 'SMM_DRIVER':
-                DpxFile = gAutoGenSmmDepexFileName % {"module_name" : self.Name}
-            else:
-                DpxFile = gAutoGenDepexFileName % {"module_name" : self.Name}
+            DpxFile = gAutoGenDepexFileName % {"module_name" : self.Name}
 
             if Dpx.Generate(path.join(self.OutputDir, DpxFile)):
                 AutoGenList.append(str(DpxFile))
@@ -1914,6 +2316,7 @@ class ModuleAutoGen(AutoGen):
     ProtocolList            = property(_GetProtocolList)
     PpiList                 = property(_GetPpiList)
     DepexList               = property(_GetDepexTokenList)
+    DepexExpressionList     = property(_GetDepexExpressionTokenList)
     BuildOption             = property(_GetModuleBuildOption)
     BuildCommand            = property(_GetBuildCommand)