Merged from old code
authorjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 25 Jul 2007 09:27:00 +0000 (09:27 +0000)
committerjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 25 Jul 2007 09:27:00 +0000 (09:27 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@395 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/AutoGen/AutoGen.py
Source/Python/AutoGen/BuildInfo.py
Source/Python/AutoGen/GenC.py
Source/Python/AutoGen/GenMake.py

index 97a9bee..ed1c034 100644 (file)
@@ -32,6 +32,36 @@ gWorkspaceDir = ""
 gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")
 gMakeTypeMap = {"MSFT":"nmake", "GCC":"gmake"}
 
+gDefaultOutputFlag = "-o "
+
+gOutputFlag = {
+    ("MSFT", "CC", "OUTPUT")      :   "/Fo",
+    ("MSFT", "SLINK", "OUTPUT")   :   "/OUT:",
+    ("MSFT", "DLINK", "OUTPUT")   :   "/OUT:",
+    ("MSFT", "ASMLINK", "OUTPUT") :   "/OUT:",
+    ("MSFT", "PCH", "OUTPUT")     :   "/Fp",
+    ("MSFT", "ASM", "OUTPUT")     :   "/Fo",
+
+    ("INTEL", "CC", "OUTPUT")          :   "/Fo",
+    ("INTEL", "SLINK", "OUTPUT")       :   "/OUT:",
+    ("INTEL", "DLINK", "OUTPUT")       :   "/OUT:",
+    ("INTEL", "ASMLINK", "OUTPUT")     :   "/OUT:",
+    ("INTEL", "PCH", "OUTPUT")         :   "/Fp",
+    ("INTEL", "ASM", "OUTPUT")         :   "/Fo",
+#    ("INTEL", "IPF", "ASM", "OUTPUT")  :   "-o ",
+
+    ("GCC", "CC", "OUTPUT")        :   "-o ",
+    ("GCC", "SLINK", "OUTPUT")     :   "-cr ",
+    ("GCC", "DLINK", "OUTPUT")     :   "-o ",
+    ("GCC", "ASMLINK", "OUTPUT")   :   "-o ",
+    ("GCC", "PCH", "OUTPUT")       :   "-o ",
+    ("GCC", "ASM", "OUTPUT")       :   "-o ",
+
+#   ("OUTPUT")                     :    "-o "
+}
+
+gIncludeFlag = {"MSFT" : "/I", "GCC" : "-I", "INTEL" : "-I"}
+
 def FindModuleOwnerPackage(module, pkgdb):
     for pkg in pkgdb:
         pkgDir = path.dirname(pkg)
@@ -177,8 +207,8 @@ class AutoGen(object):
         info.DependentPackageList = self.GetDependentPackageList()
 
         info.BuildOption = self.GetModuleBuildOption(info.PlatformInfo)
-        if "DLINK" in platformInfo.ToolStaticLib:
-            info.SystemLibraryList = platformInfo.ToolStaticLib["DLINK"]
+        if "DLINK" in info.PlatformInfo.ToolStaticLib:
+            info.SystemLibraryList = info.PlatformInfo.ToolStaticLib["DLINK"]
 
         info.PcdIsDriver = self.Module.PcdIsDriver
         info.PcdList = self.GetPcdList(info.DependentLibraryList)
@@ -307,6 +337,7 @@ class AutoGen(object):
             key = "%s_DPATH" % keyBaseString
             if key in toolDefinition:
                 dll = toolDefinition[key]
+                os.environ["PATH"] = dll + os.pathsep + os.environ["PATH"]
             else:
                 dll = ""
                 
@@ -316,11 +347,25 @@ class AutoGen(object):
             else:
                 lib = ""
 
+            key = keyBaseString + "_OUTPUT"
+            if key in toolDefinition:
+                oflag = toolDefinition[key]
+            elif (family, tool, "OUTPUT") in gOutputFlag:
+                oflag = gOutputFlag[family, tool, "OUTPUT"]
+                if oflag[0] == '"' and oflag[-1] == '"':
+                    oflag = oflag[1:-1]
+            else:
+                oflag = gDefaultOutputFlag
+
+            iflag = gIncludeFlag[family]
+                
             info.ToolPath[tool] = os.path.join(path, name)
             info.ToolDynamicLib[tool] = dll
             info.ToolStaticLib[tool] = lib
             info.ToolChainFamily[tool] = family
             info.DefaultToolOption[tool] = option
+            info.OutputFlag[tool] = oflag
+            info.IncludeFlag[tool] = iflag
 
         if self.IsPlatformAutoGen:
             buildOptions = self.Platform[info.Arch].BuildOptions
@@ -386,19 +431,49 @@ class AutoGen(object):
             
             # skip file which needs a tool having no matching toolchain family
             fileType = buildRule.FileTypeMapping[ext]
+            if fileType == "Unicode-Text":
+                self.BuildInfo.UnicodeFileList.append(os.path.join(gWorkspaceDir, self.BuildInfo.SourceDir, f.SourceFile))
+                continue
+
             if f.ToolCode != "":
-                toolCode = f.ToolCode
+                toolCodeList = [f.ToolCode]
             else:
-                toolCode = buildRule.ToolCodeMapping[fileType]
+                if fileType in buildRule.ToolCodeMapping:
+                    toolCodeList = buildRule.ToolCodeMapping[fileType]
+                else:
+                    toolCodeList = []
+
             # get the toolchain family from tools definition
-            if f.ToolChainFamily != "" and f.ToolChainFamily != platformInfo.ToolChainFamily[toolCode]:
-                EdkLogger.verbose("File %s for toolchain family %s is not supported" % (f.SourceFile, f.ToolChainFamily))
+            buildable = True
+            if f.ToolChainFamily != "":
+                for toolCode in toolCodeList:
+                    if f.ToolChainFamily != platformInfo.ToolChainFamily[toolCode]:
+                        EdkLogger.verbose("File %s for toolchain family %s is not supported" % (f.SourceFile, f.ToolChainFamily))
+                        buildable = False
+                        break
+            else:
+                if toolCodeList != []:
+                    f.ToolChainFamily = platformInfo.ToolChainFamily[toolCodeList[0]]
+                else:
+                    buildable = False
+
+            if not buildable:
                 continue
-            if fileType == "Unicode-Text":
-                self.BuildInfo.UnicodeFileList.append(os.path.join(gWorkspaceDir, self.BuildInfo.SourceDir, f.SourceFile))
-            buildFileList.append(f.SourceFile)
+
+            #buildFileList.append(f.SourceFile)
+            buildFileList.append(f)
+
         return buildFileList
 
+    def IsToolChainFamilySupported(self):
+        pass
+
+    def IsToolCodeSupported(self):
+        pass
+
+    def IsToolChainSupported(self):
+        pass
+    
     def GetDependentPackageList(self):
         if self.Package not in self.Module.Packages:
             self.Module.Packages.insert(0, str(self.Package))
@@ -441,7 +516,7 @@ class AutoGen(object):
             module = libraryConsumerList.pop()
             for libc, libf in module.LibraryClasses.iteritems():
                 if moduleType not in libc:
-                    EdkLogger.debug(EdkLogger.DEBUG_5, "\t%s for module type %s is not supported" % libc)
+                    EdkLogger.debug(EdkLogger.DEBUG_3, "\t%s for module type %s is not supported" % libc)
                     continue
                 if libf == None or libf == "":
                     EdkLogger.info("\tLibrary instance of library class %s is not found" % libc[0])
@@ -552,19 +627,38 @@ class AutoGen(object):
 
     def GetDynamicPcdList(self, platform, arch):
         pcdList = []
+        notFoundPcdList = set()
+        noDatumTypePcdList = set()
+        pcdConsumerList = set()
         for f in gModuleDatabase[arch]:
             m = gModuleDatabase[arch][f]
             for key in m.Pcds:
                 if key not in platform.Pcds:
-                    raise AutoGenError(msg="PCD [%s %s] not found in platform" % key)
+                    notFoundPcdList.add(" | ".join(key))
+                    pcdConsumerList.add(str(m))
+                    continue
+                    # raise AutoGenError(msg="PCD [%s %s] not found in platform" % key)
                 mPcd = m.Pcds[key]
                 pPcd = platform.Pcds[key]
+                if mPcd.DatumType == "VOID*" and pPcd.MaxDatumSize == None:
+                    noDatumTypePcdList.add(" | ".join(key))
+                    pcdConsumerList.add(str(m))
+                    #raise AutoGenError(msg="No MaxDatumSize specified for PCD %s|%s" % (pPcd.TokenCName, pPcd.TokenSpaceGuidCName))
+
                 if pPcd.Type in GenC.gDynamicPcd + GenC.gDynamicExPcd:
                     if m.ModuleType in ["PEIM", "PEI_CORE"]:
                         pPcd.Phase = "PEI"
                     if pPcd not in pcdList:
                         pPcd.DatumType = mPcd.DatumType
                         pcdList.append(pPcd)
+        if len(notFoundPcdList) > 0 or len(noDatumTypePcdList) > 0:
+            notFoundPcdListString = "\n\t\t".join(notFoundPcdList)
+            noDatumTypePcdListString = "\n\t\t".join(noDatumTypePcdList)
+            moduleListString = "\n\t\t".join(pcdConsumerList)
+            raise AutoGenError(msg="\n\tPCD(s) not found in platform:\n\t\t%s\
+                                    \n\tPCD(s) without MaxDatumSize:\n\t\t%s\
+                                    \n\tUsed by:\n\t\t%s\n"
+                                    % (notFoundPcdListString, noDatumTypePcdListString, moduleListString))
         return pcdList
 
     def GeneratePcdTokenNumber(self, platform, dynamicPcdList):
@@ -585,7 +679,6 @@ class AutoGen(object):
         platformPcds = platform.Pcds
         for key in platformPcds:
             pcd = platformPcds[key]
-            #print "###",key
             if key not in pcdTokenNumber:
                 pcdTokenNumber[key] = tokenNumber
                 tokenNumber += 1
@@ -598,15 +691,15 @@ class AutoGen(object):
         for m in dependentLibraryList + [self.Module]:
             for pcdKey in m.Pcds:
                 pcd = m.Pcds[pcdKey]
+                #if pcdKey not in platformPcds:
+                #    EdkLogger.info("%s / %s not in current platform" % pcdKey)
                 if (pcd.Type in GenC.gDynamicPcd + GenC.gDynamicExPcd) and self.Module.ModuleType in ["PEIM", "PEI_CORE"]:
-                    #platformPcds[pcdKey].Phase = "PEI"
                     pcd.Phase = "PEI"
                 if pcd not in pcdList:
                     pcdList.append(pcd)
         return pcdList
 
     def GetGuidList(self):
-        packageListString = "\n\t".join([p.PackageName for p in self.BuildInfo.DependentPackageList])
         guid = {}
         Key = ""
         for Key in self.Module.Guids:
@@ -621,6 +714,7 @@ class AutoGen(object):
                     guid[Key] = p.Ppis[Key]
                     break
             else:
+                packageListString = "\n\t".join([p.PackageName for p in self.BuildInfo.DependentPackageList])
                 raise AutoGenError(msg='GUID [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, self.BuildInfo.Name, packageListString))
 
         for lib in self.BuildInfo.DependentLibraryList:
@@ -641,11 +735,11 @@ class AutoGen(object):
                         guid[Key] = p.Ppis[Key]
                         break
                 else:
+                    packageListString = "\n\t".join([p.PackageName for p in self.BuildInfo.DependentPackageList])
                     raise AutoGenError(msg='GUID [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, lib.BaseName, packageListString))
         return guid
 
     def GetProtocolGuidList(self):
-        packageListString = "\n\t".join([p.PackageName for p in self.BuildInfo.DependentPackageList])
         guid = {}
         Key = ""
         for Key in self.Module.Protocols:
@@ -660,6 +754,7 @@ class AutoGen(object):
                         guid[Key] = p.Ppis[Key]
                         break
             else:
+                packageListString = "\n\t".join([p.PackageName for p in self.BuildInfo.DependentPackageList])
                 raise AutoGenError(msg='Protocol [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, self.BuildInfo.Name, packageListString))
 
         for lib in self.BuildInfo.DependentLibraryList:
@@ -678,12 +773,12 @@ class AutoGen(object):
                         guid[Key] = p.Ppis[Key]
                         break
                 else:
+                    packageListString = "\n\t".join([p.PackageName for p in self.BuildInfo.DependentPackageList])
                     raise AutoGenError(msg='Protocol [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, lib.BaseName, packageListString))
 
         return guid
 
     def GetPpiGuidList(self):
-        packageListString = "\n\t".join([p.PackageName for p in self.BuildInfo.DependentPackageList])
         guid = {}
         Key = ""
         for Key in self.Module.Ppis:
@@ -698,6 +793,7 @@ class AutoGen(object):
                     guid[Key] = p.Ppis[Key]
                     break
             else:
+                packageListString = "\n\t".join([p.PackageName for p in self.BuildInfo.DependentPackageList])
                 raise AutoGenError(msg='PPI [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, self.BuildInfo.Name, packageListString))
 
         for lib in self.BuildInfo.DependentLibraryList:
@@ -716,6 +812,7 @@ class AutoGen(object):
                         guid[Key] = p.Ppis[Key]
                         break
                 else:
+                    packageListString = "\n\t".join([p.PackageName for p in self.BuildInfo.DependentPackageList])
                     raise AutoGenError(msg='PPI [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, lib.BaseName, packageListString))
         return guid
 
@@ -762,7 +859,7 @@ class AutoGen(object):
                 platformInfo.LibraryAutoGenList.append(self)
 
             for lib in self.BuildInfo.DependentLibraryList:
-                EdkLogger.debug(EdkLogger.DEBUG_2, "###" + str(lib))
+                EdkLogger.debug(EdkLogger.DEBUG_1, "###" + str(lib))
                 key = (self.BuildTarget, self.ToolChain, self.Arch, lib)
                 libraryAutoGen = None
                 if key not in gAutoGenDatabase:
index 3bedcae..45b50c8 100644 (file)
@@ -64,8 +64,6 @@ class ModuleBuildInfo(BuildInfo):
         self.MacroList = []
         self.DepexList = []
 
-        self.SystemLibraryList = []
-
 class PackageBuildInfo(BuildInfo):
     def __init__(self, package):
         BuildInfo.__init__(self, package)
@@ -112,4 +110,6 @@ class PlatformBuildInfo(BuildInfo):
         self.ToolStaticLib = {}     # toolcode : lib path
         self.ToolChainFamily = {}   # toolcode : tool chain family
         self.BuildOption = {}       # toolcode : option
+        self.OutputFlag = {}        # toolcode : output flag
+        self.IncludeFlag = {}        # toolcode : include flag
         self.DefaultToolOption = {}
index 0c8d2de..1f8b919 100644 (file)
@@ -127,7 +127,7 @@ PcdDatabaseAutoGenH = """
 #define ${PHASE}_EXMAP_TABLE_EMPTY              ${EXMAP_TABLE_EMPTY}
 
 typedef struct {
-${BEGIN}  UINT64             ${INIT_CNAME_DECL_UITN64}_${INIT_GUID_DECL_UINT64}[${INIT_NUMSKUS_DECL_UINT64}];
+${BEGIN}  UINT64             ${INIT_CNAME_DECL_UINT64}_${INIT_GUID_DECL_UINT64}[${INIT_NUMSKUS_DECL_UINT64}];
 ${END}
 ${BEGIN}  UINT64             ${VARDEF_CNAME_UINT64}_${VARDEF_GUID_UINT64}_VariableDefault_${VARDEF_SKUID_UINT64};
 ${END}
@@ -155,7 +155,7 @@ ${BEGIN}  UINT8              ${INIT_CNAME_DECL_UINT8}_${INIT_GUID_DECL_UINT8}[${
 ${END}
 ${BEGIN}  UINT8              ${VARDEF_CNAME_UINT8}_${VARDEF_GUID_UINT8}_VariableDefault_${VARDEF_SKUID_UINT8};
 ${END}
-${BEGIN}  BOOLEAN            ${INIT_CNAME_DECL_BOOLEAN}_${INIT_GUID_DECL_BOOLEAN}[${INIT_NUMSKUS_BOOLEAN}];
+${BEGIN}  BOOLEAN            ${INIT_CNAME_DECL_BOOLEAN}_${INIT_GUID_DECL_BOOLEAN}[${INIT_NUMSKUS_DECL_BOOLEAN}];
 ${END}
 ${BEGIN}  BOOLEAN            ${VARDEF_CNAME_BOOLEAN}_${VARDEF_GUID_BOOLEAN}_VariableDefault_${VARDEF_SKUID_BOOLEAN};
 ${END}
@@ -253,7 +253,7 @@ ${BEGIN}  ${STRING_TABLE_VALUE}, /* ${STRING_TABLE_CNAME}_${STRING_TABLE_GUID} *
 ${END}
   /* SizeTable */
   {
-${BEGIN}    ${SIZE_TABLE_CURRENT_LENGTH}, ${SIZE_TABLE_MAXIMUM_LENGTH}, /* ${SIZE_TABLE_CNAME}_${SIZE_TABLE_GUID} */
+${BEGIN}    ${SIZE_TABLE_MAXIMUM_LENGTH}, ${SIZE_TABLE_CURRENT_LENGTH}, /* ${SIZE_TABLE_CNAME}_${SIZE_TABLE_GUID} */
 ${END}
   },
 ${BEGIN}  { ${INIT_VALUE_UINT16} }, /*  ${INIT_CNAME_DECL_UINT16}_${INIT_GUID_DECL_UINT16}[${INIT_NUMSKUS_DECL_UINT16}] */
@@ -839,7 +839,8 @@ def GetGuidValue(packages, cname):
         if cname in p.Ppis:
             return p.Ppis[cname]
     else:
-        raise AutoGenError(msg="Cannot find GUID value for %s in any package" % cname)
+        packageListString = "\n\t".join([str(p) for p in packages])
+        raise AutoGenError(msg="Cannot find GUID value for %s in all given packages:\n\t%s" % (cname, packageListString))
 
 class AutoGenString(object):
   def __init__(self):
@@ -890,14 +891,16 @@ def CreateModulePcdCode(info, autoGenC, autoGenH, pcd):
     if pcd.Type in gDynamicExPcd:
         tokenNumber = pcd.TokenValue
     else:
+        if (pcd.TokenCName, pcd.TokenSpaceGuidCName) not in pcdTokenNumber:
+            raise AutoGenError(msg="No generated token number for %s|%s\n" % (pcd.TokenCName, pcd.TokenSpaceGuidCName))
         tokenNumber = pcdTokenNumber[pcd.TokenCName, pcd.TokenSpaceGuidCName]
     autoGenH.Append('#define %s  %d\n' % (pcdTokenName, tokenNumber))
 
-    EdkLogger.debug(EdkLogger.DEBUG_7, "Creating code for " + pcd.TokenCName + "/" + pcd.TokenSpaceGuidCName)
+    EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + pcd.TokenCName + "|" + pcd.TokenSpaceGuidCName)
     if pcd.Type not in ItemTypeStringDatabase:
-        raise AutoGenError(msg="Unknown PCD type [%s] of PCD %s/%s" % (pcd.Type, pcd.TokenCName, pcd.TokenSpaceGuidCName))
+        raise AutoGenError(msg="Unknown PCD type [%s] of PCD %s|%s" % (pcd.Type, pcd.TokenCName, pcd.TokenSpaceGuidCName))
     if pcd.DatumType not in DatumSizeStringDatabase:
-        raise AutoGenError(msg="Unknown datum type [%s] of PCD %s/%s" % (pcd.DatumType, pcd.TokenCName, pcd.TokenSpaceGuidCName))
+        raise AutoGenError(msg="Unknown datum type [%s] of PCD %s|%s" % (pcd.DatumType, pcd.TokenCName, pcd.TokenSpaceGuidCName))
 
     datumSize = DatumSizeStringDatabase[pcd.DatumType]
     datumSizeLib = DatumSizeStringDatabaseLib[pcd.DatumType]
@@ -927,6 +930,9 @@ def CreateModulePcdCode(info, autoGenC, autoGenH, pcd):
         if pcd.DatumType == 'UINT64':
             Value += 'ULL'
         if pcd.DatumType == 'VOID*':
+            if pcd.MaxDatumSize == None:
+                raise AutoGenError(msg="Unknown MaxDatumSize of PCD %s|%s" % (pcd.TokenCName, pcd.TokenSpaceGuidCName))
+
             ArraySize = int(pcd.MaxDatumSize)
             if Value[0] == '{':
                 Type = '(VOID *)'
@@ -975,12 +981,14 @@ def CreateLibraryPcdCode(info, autoGenC, autoGenH, pcd):
     pcdTokenNumber = info.PlatformInfo.PcdTokenNumber
     tokenSpaceGuidCName = pcd.TokenSpaceGuidCName
     tokenCName  = pcd.TokenCName
+    if (pcd.TokenCName, pcd.TokenSpaceGuidCName) not in pcdTokenNumber:
+        raise AutoGenError(msg="No generated token number for %s|%s\n" % (pcd.TokenCName, pcd.TokenSpaceGuidCName))
     tokenNumber = pcdTokenNumber[tokenCName, tokenSpaceGuidCName]
     
     if pcd.Type not in ItemTypeStringDatabase:
-        raise AutoGenError(msg="Unknown PCD type [%s] of PCD %s/%s" % (pcd.Type, pcd.TokenCName, pcd.TokenSpaceGuidCName))
+        raise AutoGenError(msg="Unknown PCD type [%s] of PCD %s|%s" % (pcd.Type, pcd.TokenCName, pcd.TokenSpaceGuidCName))
     if pcd.DatumType not in DatumSizeStringDatabase:
-        raise AutoGenError(msg="Unknown datum type [%s] of PCD %s/%s" % (pcd.DatumType, pcd.TokenCName, pcd.TokenSpaceGuidCName))
+        raise AutoGenError(msg="Unknown datum type [%s] of PCD %s|%s" % (pcd.DatumType, pcd.TokenCName, pcd.TokenSpaceGuidCName))
 
     datumType   = pcd.DatumType
     datumSize   = DatumSizeStringDatabaseH[datumType]
@@ -1101,7 +1109,10 @@ def CreatePcdDatabasePhaseSpecificAutoGen (platform, phase):
     for Pcd in platform.DynamicPcdList:
         CName = Pcd.TokenCName
         TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName
-        EdkLogger.debug(EdkLogger.DEBUG_5, "PCD: %s %s (%s : %s)" % (CName, TokenSpaceGuidCName, Pcd.Phase, phase))
+
+        EdkLogger.debug(EdkLogger.DEBUG_3, "PCD: %s %s (%s : %s)" % (CName, TokenSpaceGuidCName, Pcd.Phase, phase))
+        if Pcd.DatumType not in DatumSizeStringDatabase:
+            raise AutoGenError(msg="Unknown datum type [%s] of PCD %s|%s" % (Pcd.DatumType, Pcd.TokenCName, Pcd.TokenSpaceGuidCName))
 
         if Pcd.Phase == 'PEI':
             NumberOfPeiLocalTokens += 1
@@ -1196,7 +1207,7 @@ def CreatePcdDatabasePhaseSpecificAutoGen (platform, phase):
                         else:
                             Dict['STRING_TABLE_INDEX'].append('_%d' % StringTableIndex)
                         if Sku.DefaultValue[0] == 'L':
-                            Size = len(Sku.DefaultValue) - 3
+                            Size = (len(Sku.DefaultValue) - 3) * 2
                             Dict['STRING_TABLE_VALUE'].append(Sku.DefaultValue)
                         elif Sku.DefaultValue[0] == '"':
                             Size = len(Sku.DefaultValue) - 2
@@ -1212,9 +1223,9 @@ def CreatePcdDatabasePhaseSpecificAutoGen (platform, phase):
                         Dict['SIZE_TABLE_MAXIMUM_LENGTH'].append(Pcd.MaxDatumSize)
                         if Pcd.MaxDatumSize != '' and Pcd.MaxDatumSize > Size:
                             Size = int(Pcd.MaxDatumSize)
-                        Dict['STRING_TABLE_LENGTH'].append(Size)
+                        Dict['STRING_TABLE_LENGTH'].append(Size / 2 + 1)
                         StringTableIndex += 1
-                        StringTableSize += Size
+                        StringTableSize += (Size / 2 + 1)
                 else:
                     Pcd.TokenTypeList += ['PCD_TYPE_DATA']
                     if Sku.DefaultValue == 'TRUE':
@@ -1273,7 +1284,7 @@ def CreatePcdDatabasePhaseSpecificAutoGen (platform, phase):
         if phase == 'DXE':
             GeneratedTokenNumber -= NumberOfPeiLocalTokens
 
-        EdkLogger.debug(EdkLogger.DEBUG_1, "PCD = %s / %s" % (CName, TokenSpaceGuidCName))
+        EdkLogger.debug(EdkLogger.DEBUG_1, "PCD = %s | %s" % (CName, TokenSpaceGuidCName))
         EdkLogger.debug(EdkLogger.DEBUG_1, "phase = %s" % phase)
         EdkLogger.debug(EdkLogger.DEBUG_1, "GeneratedTokenNumber = %s" % str(GeneratedTokenNumber))
 
@@ -1338,6 +1349,9 @@ def CreatePcdDatabasePhaseSpecificAutoGen (platform, phase):
 def CreatePcdDatabaseCode (info, autoGenC, autoGenH):
     if info.PcdIsDriver == "":
         return
+    if info.PcdIsDriver not in PcdPhaseMap:
+        raise AutoGenError(msg="Not supported PcdIsDriver type:%s\n" % info.PcdIsDriver)
+    
     autoGenH.Append(PcdDatabaseCommonAutoGenH)
     additionalAutoGenH, additionalAutoGenC = CreatePcdDatabasePhaseSpecificAutoGen (info.PlatformInfo, 'PEI')
     autoGenH.Append(additionalAutoGenH.String)
@@ -1402,7 +1416,7 @@ def CreateLibraryDestructorCode(info, autoGenC, autoGenH):
 
 
 def CreateModuleEntryPointCode(info, autoGenC, autoGenH):
-    if info.IsLibrary:
+    if info.IsLibrary or info.ModuleType == "USER_DEFINED":
         return
     #
     # Module Entry Points
@@ -1435,7 +1449,7 @@ def CreateModuleEntryPointCode(info, autoGenC, autoGenH):
                 autoGenC.Append(UefiEntryPointString[2], Dict)
 
 def CreateModuleUnloadImageCode(info, autoGenC, autoGenH):
-    if info.IsLibrary:
+    if info.IsLibrary or info.ModuleType == "USER_DEFINED":
         return
     #
     # Unload Image Handlers
@@ -1450,29 +1464,47 @@ def CreateModuleUnloadImageCode(info, autoGenC, autoGenH):
 def CreateGuidDefinitionCode(info, autoGenC, autoGenH):
     if info.IsLibrary:
         return
+
+    if info.ModuleType in ["USER_DEFINED", "BASE"]:
+        GuidType = "GUID"
+    else:
+        GuidType = "EFI_GUID"
+
     #
     # GUIDs
     #
     for Key in info.GuidList:
-        autoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID  %s = %s;\n' % (Key, info.GuidList[Key]))
+        autoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, info.GuidList[Key]))
 
 def CreateProtocolDefinitionCode(info, autoGenC, autoGenH):
     if info.IsLibrary:
         return
+
+    if info.ModuleType in ["USER_DEFINED", "BASE"]:
+        GuidType = "GUID"
+    else:
+        GuidType = "EFI_GUID"
+
     #
     # Protocol GUIDs
     #
     for Key in info.ProtocolList:
-        autoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID  %s = %s;\n' % (Key, info.ProtocolList[Key]))
+        autoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, info.ProtocolList[Key]))
 
 def CreatePpiDefinitionCode(info, autoGenC, autoGenH):
     if info.IsLibrary:
         return
+
+    if info.ModuleType in ["USER_DEFINED", "BASE"]:
+        GuidType = "GUID"
+    else:
+        GuidType = "EFI_GUID"
+
     #
     # PPI GUIDs
     #
     for Key in info.PpiList:
-        autoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID  %s = %s;\n' % (Key, info.PpiList[Key]))
+        autoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType, Key, info.PpiList[Key]))
 
 def CreatePcdCode(info, autoGenC, autoGenH):
     if info.IsLibrary:
@@ -1508,7 +1540,8 @@ def CreateHeaderCode(info, autoGenC, autoGenH):
     # specification macros
     autoGenH.Append(SpecificationString,   {'Specification':info.MacroList})
     # header files includes
-    autoGenH.Append("#include <%s>\n" % BasicHeaderFile)
+    autoGenH.Append("#include <%s>\n\n" % BasicHeaderFile)
+    #autoGenH.Append("\n#define ASM_PFX(name) _##name\n\n")
 
     if info.IsLibrary:
         return
@@ -1522,10 +1555,9 @@ def CreateHeaderCode(info, autoGenC, autoGenH):
     #
     # Publish the CallerId Guid
     #
-    if info.ModuleType == 'BASE':
-        autoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID  gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(info.Guid))
-    else:
-        autoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID  gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(info.Guid))
+    autoGenH.Append("#define EFI_CALLER_ID_GUID \\\n  %s\n" % GuidStringToGuidStructureString(info.Guid))
+    autoGenH.Append('\nextern GUID  gEfiCallerIdGuid;\n\n')
+    autoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(info.Guid))
 
 def CreateFooterCode(info, autoGenC, autoGenH):
     autoGenH.Append(AutoGenHEpilogueString)
index c99a3e8..709feb6 100644 (file)
@@ -95,8 +95,15 @@ gDirectorySeparator = {"nmake" : "\\", "gmake" : "/"}
 gCreateDirectoryCommand = {"nmake" : "mkdir", "gmake" : "mkdir -p"}\r
 gRemoveDirectoryCommand = {"nmake" : "rmdir /s /q", "gmake" : "rm -r -f"}\r
 gRemoveFileCommand = {"nmake" : "del /f /q", "gmake" : "rm -f"}\r
+gCopyFileCommand = {"nmake" : "copy /y", "gmake" : "cp -f"}\r
+gCreateDirectoryCommandTemplate = {"nmake" : "if not exist %(dir)s mkdir %(dir)s",\r
+                                   "gmake" : "test ! -e %(dir)s && mkdir -p %(dir)s"}\r
+gRemoveDirectoryCommandTemplate = {"nmake" : "if exist %(dir)s rmdir /s /q %(dir)s",\r
+                                   "gmake" : "test -e %(dir)s && rm -r -f %(dir)s"}\r
 \r
-OutputFlag = {\r
+gDefaultOutputFlag = "-o "\r
+\r
+gOutputFlag = {\r
     ("MSFT", "CC", "OUTPUT")      :   "/Fo",\r
     ("MSFT", "SLINK", "OUTPUT")   :   "/OUT:",\r
     ("MSFT", "DLINK", "OUTPUT")   :   "/OUT:",\r
@@ -110,7 +117,7 @@ OutputFlag = {
     ("INTEL", "ASMLINK", "OUTPUT")     :   "/OUT:",\r
     ("INTEL", "PCH", "OUTPUT")         :   "/Fp",\r
     ("INTEL", "ASM", "OUTPUT")         :   "/Fo",\r
-    ("INTEL", "IPF", "ASM", "OUTPUT")  :   "-o ",\r
+#    ("INTEL", "IPF", "ASM", "OUTPUT")  :   "-o ",\r
 \r
     ("GCC", "CC", "OUTPUT")        :   "-o ",\r
     ("GCC", "SLINK", "OUTPUT")     :   "-cr ",\r
@@ -119,10 +126,13 @@ OutputFlag = {
     ("GCC", "PCH", "OUTPUT")       :   "-o ",\r
     ("GCC", "ASM", "OUTPUT")       :   "-o ",\r
 \r
-    ("OUTPUT")                     : "-o "\r
+#   ("OUTPUT")                     :    "-o "\r
 }\r
 \r
-IncludeFlag = {"MSFT" : "/I", "GCC" : "-I"}\r
+gIncludeFlag = {"MSFT" : "/I", "GCC" : "-I", "INTEL" : "-I"}\r
+\r
+gStartGroupFlag = {"MSFT" : "", "GCC" : "-(", "INTEL" : ""}\r
+gEndGroupFlag = {"MSFT" : "", "GCC" : "-)", "INTEL" : ""}\r
 \r
 gCustomMakefileTemplate = '''\r
 ${makefile_header}\r
@@ -237,9 +247,7 @@ mbuild: init all
 #\r
 init:\r
 \t-@echo Building ... $(MODULE_NAME)-$(MODULE_VERSION) [$(ARCH)] in package $(PACKAGE_NAME)-$(PACKAGE_VERSION)\r
-\t-${create_directory_command} $(DEBUG_DIR) > NUL 2>&1\r
-\t-${create_directory_command} $(OUTPUT_DIR) > NUL 2>&1\r
-\t${BEGIN}-${create_directory_command} $(OUTPUT_DIR)${separator}${directory_to_be_created} > NUL 2>&1\r
+\t${BEGIN}${create_directory_command}\r
 \t${END}\r
 \r
 '''\r
@@ -336,6 +344,9 @@ SOURCE_FILES = ${BEGIN}$(MODULE_DIR)${separator}${source_file} \\
                ${END}${BEGIN}$(DEBUG_DIR)${separator}${auto_generated_file}\r
                ${END}\r
 \r
+TARGET_FILES = ${BEGIN}$(OUTPUT_DIR)${separator}${target_file} \\\r
+               ${END}\r
+\r
 INC = ${BEGIN}${include_path_prefix}$(WORKSPACE)${separator}${include_path} \\\r
       ${END}\r
 \r
@@ -343,8 +354,7 @@ OBJECTS = ${BEGIN}$(OUTPUT_DIR)${separator}${object_file} \\
           ${END}\r
 \r
 LIBS = ${BEGIN}$(LIB_DIR)${separator}${library_file} \\\r
-       ${END}\r
-       ${BEGIN}${system_library} \\\r
+       ${END}${BEGIN}${system_library} \\\r
        ${END}\r
 \r
 COMMON_DEPS = ${BEGIN}$(WORKSPACE)${separator}${common_dependency_file} \\\r
@@ -359,7 +369,7 @@ PCH_FILE = $(OUTPUT_DIR)\$(MODULE_NAME).pch
 LIB_FILE = $(LIB_DIR)\$(MODULE_NAME).lib\r
 LLIB_FILE = $(OUTPUT_DIR)\$(MODULE_NAME)Local.lib\r
 DLL_FILE = $(DEBUG_DIR)\$(MODULE_NAME).dll\r
-EFI_FILE = $(OUTPUT_DIR)\$(MODULE_NAME).efi\r
+EFI_FILE = $(DEBUG_DIR)\$(MODULE_NAME).efi\r
 \r
 #\r
 # Overridable Target Macro Definitions\r
@@ -367,6 +377,7 @@ EFI_FILE = $(OUTPUT_DIR)\$(MODULE_NAME).efi
 INIT_TARGET = init\r
 PCH_TARGET =\r
 LLIB_TARGET = $(LLIB_FILE)\r
+CODA_TARGET = ${remaining_build_target}\r
 \r
 #\r
 # Default target, which will build dependent libraries in addition to source files\r
@@ -379,7 +390,7 @@ all: ${build_type}
 # Target used when called from platform makefile, which will bypass the build of dependent libraries\r
 #\r
 \r
-pbuild: $(INIT_TARGET) $(PCH_TARGET) gen_obj $(LLIB_TARGET) $(EFI_FILE) $(DLL_FILE)\r
+pbuild: $(INIT_TARGET) $(PCH_TARGET) gen_obj $(CODA_TARGET)\r
 \r
 \r
 #\r
@@ -393,7 +404,7 @@ lbuild: $(INIT_TARGET) $(PCH_TARGET) gen_obj $(LIB_FILE)
 # ModuleTarget\r
 #\r
 \r
-mbuild: $(INIT_TARGET) gen_libs $(PCH_TARGET) gen_obj $(LLIB_TARGET) $(EFI_FILE) $(DLL_FILE)\r
+mbuild: $(INIT_TARGET) gen_libs $(PCH_TARGET) gen_obj $(CODA_TARGET)\r
 \r
 \r
 #\r
@@ -401,51 +412,49 @@ mbuild: $(INIT_TARGET) gen_libs $(PCH_TARGET) gen_obj $(LLIB_TARGET) $(EFI_FILE)
 #\r
 init:\r
 \t-@echo Building ... $(MODULE_NAME)-$(MODULE_VERSION) [$(ARCH)] in package $(PACKAGE_NAME)-$(PACKAGE_VERSION)\r
-\t-${create_directory_command} $(DEBUG_DIR) > NUL 2>&1\r
-\t-${create_directory_command} $(OUTPUT_DIR) > NUL 2>&1\r
-\t${BEGIN}-${create_directory_command} $(OUTPUT_DIR)${separator}${directory_to_be_created} > NUL 2>&1\r
+\t${BEGIN}${create_directory_command}\r
 \t${END}\r
 \r
 #\r
 # PCH Target\r
 #\r
-pch: $(PCH_FILE)\r
+pch: $(INIT_TARGET) $(PCH_FILE)\r
 \r
 \r
 #\r
 # Libs Target\r
 #\r
-libs: gen_libs\r
+libs: $(INIT_TARGET) gen_libs\r
 \r
 \r
 #\r
 # Vfr Target\r
 #\r
-vfr: gen_vfr\r
+vfr: $(INIT_TARGET) gen_vfr\r
 \r
 \r
 #\r
 # Obj Target\r
 #\r
-obj: $(PCH_TARGET) gen_obj\r
+obj: $(INIT_TARGET) $(PCH_TARGET) gen_obj\r
 \r
 \r
 #\r
 # LocalLib Target\r
 #\r
-locallib: $(PCH_TARGET) gen_obj $(LLIB_FILE)\r
+locallib: $(INIT_TARGET) $(PCH_TARGET) gen_obj $(LLIB_FILE)\r
 \r
 \r
 #\r
 # Dll Target\r
 #\r
-dll: gen_libs $(PCH_TARGET) gen_obj $(LLIB_TARGET) $(DLL_FILE)\r
+dll: $(INIT_TARGET) gen_libs $(PCH_TARGET) gen_obj $(LLIB_TARGET) $(DLL_FILE)\r
 \r
 \r
 #\r
 # Efi Target\r
 #\r
-efi: gen_libs $(PCH_TARGET) gen_obj $(LLIB_TARGET) $(DLL_FILE) $(EFI_FILE)\r
+efi: $(INIT_TARGET) gen_libs $(PCH_TARGET) gen_obj $(LLIB_TARGET) $(DLL_FILE) $(EFI_FILE)\r
 \r
 \r
 #\r
@@ -467,7 +476,7 @@ gen_vfr:
 # Phony targets for objects\r
 #\r
 \r
-gen_obj: $(PCH_TARGET) $(OBJECTS)\r
+gen_obj: $(PCH_TARGET) $(TARGET_FILES)\r
 \r
 \r
 #\r
@@ -482,30 +491,29 @@ $(PCH_FILE): $(DEP_FILES)
 #\r
 \r
 $(LLIB_FILE): $(OBJECTS)\r
-\t"$(SLINK)" $(SLINK_FLAGS) /OUT:$(LLIB_FILE) $(OBJECTS)\r
+\t"$(SLINK)" $(SLINK_FLAGS) ${slink_output_flag}$(LLIB_FILE) $(OBJECTS)\r
 \r
 #\r
 # Library file build target\r
 #\r
 \r
 $(LIB_FILE): $(OBJECTS)\r
-\t"$(SLINK)" $(SLINK_FLAGS) /OUT:$(LIB_FILE) $(OBJECTS)\r
+\t"$(SLINK)" $(SLINK_FLAGS) ${slink_output_flag}$(LIB_FILE) $(OBJECTS)\r
 \r
 #\r
 # DLL file build target\r
 #\r
 \r
 $(DLL_FILE): $(LIBS) $(LLIB_FILE)\r
-\t"$(DLINK)" $(DLINK_FLAGS) /OUT:$(DLL_FILE) $(DLINK_SPATH) $(LIBS) $(LLIB_FILE)\r
+\t"$(DLINK)" ${dlink_output_flag}$(DLL_FILE) $(DLINK_FLAGS) ${start_group_flag} $(DLINK_SPATH) $(LIBS) $(LLIB_FILE) ${end_group_flag}\r
 \r
 #\r
 # EFI file build target\r
 #\r
-\r
-$(EFI_FILE): $(LIBS) $(LLIB_FILE)\r
-\t"$(DLINK)" $(DLINK_FLAGS) /OUT:$(EFI_FILE) $(DLINK_SPATH) $(LIBS) $(LLIB_FILE)\r
-\tGenFw -e ${module_type} -o $(EFI_FILE) $(EFI_FILE)\r
-\tcopy /y $(EFI_FILE) $(BIN_DIR)\r
+$(EFI_FILE): $(DLL_FILE)\r
+\tGenFw -e ${module_type} -o $(EFI_FILE) $(DLL_FILE)\r
+\t${copy_file_command} $(EFI_FILE) $(OUTPUT_DIR)\r
+\t${copy_file_command} $(EFI_FILE) $(BIN_DIR)\r
 \r
 #\r
 # Individual Object Build Targets\r
@@ -519,15 +527,16 @@ ${END}
 #\r
 \r
 clean:\r
-\t${remove_directory_command} $(OUTPUT_DIR) > NUL 2>&1\r
+\t${BEGIN}${clean_command}\r
+\t${END}\r
 \r
 #\r
 # clean all generated files\r
 #\r
 \r
 cleanall:\r
-\t${remove_directory_command} $(OUTPUT_DIR) $(DEBUG_DIR) > NUL 2>&1\r
-\t${remove_file_command} *.pdb *.idb > NUL 2>&1\r
+\t${BEGIN}${cleanall_command}\r
+\t${END}${remove_file_command} *.pdb *.idb > NUL 2>&1\r
 \r
 #\r
 # clean pre-compiled header files\r
@@ -582,10 +591,7 @@ all: init build_libraries build_modules build_fds
 #\r
 init:\r
 \t-@echo Building ... $(PLATFORM_NAME)-$(PLATFORM_VERSION) [${build_architecture_list}]\r
-\t-${create_directory_command} $(FV_DIR) > NUL 2>&1\r
-\t${BEGIN}-${create_directory_command} $(BUILD_DIR)${separator}${architecture} > NUL 2>&1\r
-\t${END}\r
-\t${BEGIN}-${create_directory_command} $(BUILD_DIR)${separator}${directory_to_be_created} > NUL 2>&1\r
+\t${BEGIN}${create_directory_command}\r
 \t${END}\r
 #\r
 # library build target\r
@@ -647,8 +653,7 @@ clean:
 # Clean all generated files except to makefile\r
 #\r
 cleanall:\r
-\t${remove_directory_command} $(FV_DIR) > NUL 2>&1\r
-\t${BEGIN}${remove_directory_command} $(BUILD_DIR)${separator}${architecture} > NUL 2>&1\r
+\t${BEGIN}${cleanall_command}\r
 \t${END}\r
 \r
 #\r
@@ -669,11 +674,9 @@ class Makefile(object):
             self.PackageInfo = info.PackageInfo\r
             self.ModuleBuild = True\r
             \r
-            self.BuildType = "mbuild"\r
-            if self.ModuleInfo.IsLibrary:\r
-                self.BuildType = "lbuild"\r
-                \r
+            self.BuildType = "obj"\r
             self.BuildFileList = []\r
+            self.TargetFileList = []\r
             self.ObjectFileList = []\r
             self.ObjectBuildTargetList = []\r
 \r
@@ -714,14 +717,20 @@ class Makefile(object):
     def GeneratePlatformMakefile(self, file=None, makeType=gMakeType):\r
         separator = gDirectorySeparator[makeType]\r
 \r
-        activePlatform = self.PlatformInfo.values()[0].Platform\r
         platformInfo = self.PlatformInfo.values()[0]\r
+        activePlatform = platformInfo.Platform\r
         \r
         outputDir = platformInfo.OutputDir\r
         if os.path.isabs(outputDir):\r
             self.PlatformBuildDirectory = outputDir\r
+            CreateDirectory(self.PlatformBuildDirectory)\r
         else:\r
             self.PlatformBuildDirectory = "$(WORKSPACE)" + separator + outputDir\r
+            CreateDirectory(os.path.join(platformInfo.WorkspaceDir, outputDir))\r
+\r
+\r
+        self.IntermediateDirectoryList = ["$(BUILD_DIR)%s%s" % (separator, arch) for arch in self.PlatformInfo]\r
+        self.IntermediateDirectoryList.append("$(FV_DIR)")\r
 \r
         makefileName = gMakefileName[makeType]\r
         makefileTemplateDict = {\r
@@ -738,10 +747,10 @@ class Makefile(object):
             "build_architecture_list"   : " ".join(self.PlatformInfo.keys()),\r
             "architecture"              : self.PlatformInfo.keys(),\r
             "separator"                 : separator,\r
-            "create_directory_command"  : gCreateDirectoryCommand[makeType],\r
+            "create_directory_command"  : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList, makeType),\r
             "remove_directory_command"  : gRemoveDirectoryCommand[makeType],\r
             "remove_file_command"       : gRemoveFileCommand[makeType],\r
-            "directory_to_be_created"   : self.IntermediateDirectoryList,\r
+            "cleanall_command"          : self.GetRemoveDirectoryCommand(self.IntermediateDirectoryList, makeType),\r
             "library_build_directory"   : self.LibraryBuildDirectoryList,\r
             "module_build_directory"    : self.ModuleBuildDirectoryList,\r
             "fdf_file"                  : platformInfo.FdfFileList,\r
@@ -778,7 +787,8 @@ class Makefile(object):
         self.ProcessDependentLibrary(makeType)\r
 \r
         if "DLINK" in self.PlatformInfo.ToolStaticLib:\r
-            self.SystemLibraryList = self.PlatformInfo.ToolStaticLib[DLINK]\r
+            EdkLogger.debug(EdkLogger.DEBUG_5, "Static library: " + self.PlatformInfo.ToolStaticLib["DLINK"])\r
+            self.SystemLibraryList.append(self.PlatformInfo.ToolStaticLib["DLINK"])\r
 \r
         entryPoint = "_ModuleEntryPoint"\r
         if self.ModuleInfo.Arch == "EBC":\r
@@ -787,7 +797,23 @@ class Makefile(object):
         defaultToolFlag = self.PlatformInfo.DefaultToolOption.values()\r
         if self.ModuleInfo.ModuleType == "USER_DEFINED":\r
             defaultToolFlag = ["" for p in defaultToolFlag]\r
-            \r
+\r
+        if "CC" not in self.PlatformInfo.ToolChainFamily:\r
+            raise AutoGenError(msg="[CC] is not supported [%s, %s, %s]" % (self.ModuleInfo.BuildTarget,\r
+                                    self.ModuleInfo.ToolChain, self.ModuleInfo.Arch))\r
+        if  "DLINK" not in self.PlatformInfo.ToolChainFamily:\r
+            raise AutoGenError(msg="[DLINK] is not supported [%s, %s, %s]" % (self.ModuleInfo.BuildTarget,\r
+                                    self.ModuleInfo.ToolChain, self.ModuleInfo.Arch))\r
+\r
+        if self.ModuleInfo.IsLibrary:\r
+            resultFile = "$(LIB_FILE)"\r
+        elif self.BuildType == "obj":\r
+            resultFile = ""\r
+        elif self.ModuleInfo.ModuleType == "USER_DEFINED":\r
+            resultFile = "$(LLIB_FILE) $(DLL_FILE)"\r
+        else:\r
+            resultFile = "$(LLIB_FILE) $(DLL_FILE) $(EFI_FILE)"\r
+\r
         makefileName = gMakefileName[makeType]\r
         makefileTemplateDict = {\r
             "makefile_header"           : MakefileHeader % makefileName,\r
@@ -826,18 +852,25 @@ class Makefile(object):
             "module_entry_point"        : entryPoint,\r
             "source_file"               : self.BuildFileList,\r
             #"auto_generated_file"       : self.AutoGenBuildFileList,\r
-            "include_path_prefix"       : "-I",\r
+            "include_path_prefix"       : gIncludeFlag[self.PlatformInfo.ToolChainFamily["CC"]],\r
+            "dlink_output_flag"         : self.PlatformInfo.OutputFlag["DLINK"],\r
+            "slink_output_flag"         : self.PlatformInfo.OutputFlag["SLINK"],\r
+            "start_group_flag"          : gStartGroupFlag[self.PlatformInfo.ToolChainFamily["DLINK"]],\r
+            "end_group_flag"            : gEndGroupFlag[self.PlatformInfo.ToolChainFamily["DLINK"]],\r
             "include_path"              : self.ModuleInfo.IncludePathList,\r
+            "target_file"               : self.TargetFileList,\r
             "object_file"               : self.ObjectFileList,\r
             "library_file"              : self.LibraryFileList,\r
+            "remaining_build_target"    : resultFile,\r
             "system_library"            : self.SystemLibraryList,\r
             "common_dependency_file"    : self.CommonFileDependency,\r
-            "create_directory_command"  : gCreateDirectoryCommand[makeType],\r
+            "create_directory_command"  : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList, makeType),\r
             "remove_directory_command"  : gRemoveDirectoryCommand[makeType],\r
             "remove_file_command"       : gRemoveFileCommand[makeType],\r
-            "directory_to_be_created"   : self.IntermediateDirectoryList,\r
+            "copy_file_command"         : gCopyFileCommand[makeType],\r
+            "clean_command"             : self.GetRemoveDirectoryCommand(["$(OUTPUT_DIR)"], makeType),\r
+            "cleanall_command"          : self.GetRemoveDirectoryCommand(["$(DEBUG_DIR)", "$(OUTPUT_DIR)"], makeType),\r
             "dependent_library_build_directory" : self.LibraryBuildDirectoryList,\r
-            #"dependent_library_makefile"        : [path.join(bdir, makefileName) for bdir in self.LibraryBuildDirectoryList],\r
             "object_build_target"               : self.ObjectBuildTargetList,\r
             "build_type"                        : self.BuildType,\r
         }\r
@@ -902,7 +935,7 @@ class Makefile(object):
             "tool_code"                 : self.PlatformInfo.ToolPath.keys(),\r
             "tool_path"                 : self.PlatformInfo.ToolPath.values(),\r
 \r
-            "create_directory_command"  : "-@mkdir",\r
+            "create_directory_command"  : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList, makeType),\r
             "directory_to_be_created"   : self.IntermediateDirectoryList,\r
             "dependent_library_build_directory" : self.LibraryBuildDirectoryList,\r
             "custom_makefile_content"   : customMakefile\r
@@ -944,7 +977,7 @@ class Makefile(object):
         self.ObjectFileList = []\r
         self.ObjectBuildTargetList = []\r
         self.AutoGenBuildFileList = []\r
-        self.IntermediateDirectoryList = []\r
+        self.IntermediateDirectoryList = ["$(DEBUG_DIR)", "$(OUTPUT_DIR)"]\r
 \r
         fileBuildTemplatetList = []\r
         forceIncludedFile = []\r
@@ -960,14 +993,38 @@ class Makefile(object):
             ftype = rule.FileTypeMapping[fext]\r
             if ftype == "C-Header":\r
                 forceIncludedFile.append(fpath)\r
-            if ftype not in rule.Makefile[makeType]:\r
+\r
+            if ftype in rule.ToolCodeMapping:\r
+                toolCodeList = rule.ToolCodeMapping[ftype]\r
+            else:\r
+                toolCodeList = []\r
+\r
+            family = None\r
+            for tool in toolCodeList:\r
+                if tool in self.PlatformInfo.ToolChainFamily:\r
+                    family = self.PlatformInfo.ToolChainFamily[tool]\r
+                    break\r
+            else:\r
+                if makeType == "nmake":\r
+                    family = "MSFT"\r
+                else:\r
+                    family = "GCC"\r
+\r
+            if family not in rule.Makefile:\r
+                raise AutoGenError(msg="Tool chain family [%s] is not supported: %s" % (family, f))\r
+\r
+            if ftype not in rule.Makefile[family]:\r
                 continue\r
 \r
             self.BuildFileList.append(fpath)\r
-            self.ObjectFileList.append(fdir + separator + fbase + ".obj")\r
+            ext = rule.ObjectFileMapping[ftype]\r
+            tf = fdir + separator + fbase + ext\r
+            self.TargetFileList.append(tf)\r
+            if ext == ".obj":\r
+                self.ObjectFileList.append(tf)\r
 \r
             fileBuildTemplatetList.append({\r
-                                   "string" : rule.Makefile[makeType][ftype],\r
+                                   "string" : rule.Makefile[family][ftype],\r
                                    "ftype"  : ftype,\r
                                    "fpath"  : fpath,\r
                                    "fdir"   : fdir,\r
@@ -975,30 +1032,54 @@ class Makefile(object):
                                    "fbase"  : fbase,\r
                                    "fext"   : fext,\r
                                    "fdep"   : "",\r
-                                   "sep"    : separator,\r
+                                   "_sep_"    : separator,\r
                                    })\r
 \r
         fileList = self.ModuleInfo.SourceFileList\r
+        if len(fileList) == 0:\r
+            raise AutoGenError(msg="No files to be built in module [%s, %s, %s]:\n\t%s" % (self.ModuleInfo.BuildTarget,\r
+                                    self.ModuleInfo.ToolChain, self.ModuleInfo.Arch, str(self.ModuleInfo.Module)))\r
+        \r
         for f in fileList:\r
-            fpath = os.path.join(self.ModuleInfo.SourceDir, f)\r
+            family = f.ToolChainFamily\r
+            if family == None or family == "":\r
+                EdkLogger.verbose("Tool chain family not found for file:%s" % str(f))\r
+                if makeType == "nmake":\r
+                    family = "MSFT"\r
+                else:\r
+                    family = "GCC"\r
+\r
+            if family not in rule.Makefile:\r
+                raise AutoGenError(msg="Tool chain family [%s] is not supported: %s" % (family, str(f)))\r
+\r
+            f = str(f)\r
+            fpath = self.ModuleInfo.SourceDir + separator + f\r
             fname = path.basename(f)\r
             fbase, fext = path.splitext(fname)\r
             fdir = path.dirname(f)\r
-            \r
+\r
             if fdir == "":\r
                 fdir = "."\r
-            elif fdir not in self.IntermediateDirectoryList:\r
-                self.IntermediateDirectoryList.append(fdir)\r
+            else:\r
+                p = "$(OUTPUT_DIR)" + separator + fdir\r
+                if p not in self.IntermediateDirectoryList:\r
+                    self.IntermediateDirectoryList.append(p)\r
                 \r
             ftype = rule.FileTypeMapping[fext]\r
-            if ftype not in rule.Makefile[makeType]:\r
+            if ftype not in rule.Makefile[family]:\r
                 continue\r
+            if ftype == "C-Code":\r
+                self.BuildType = "mbuild"\r
 \r
             self.BuildFileList.append(fpath)\r
-            self.ObjectFileList.append(fdir + separator + fbase + ".obj")\r
+            ext = rule.ObjectFileMapping[ftype]\r
+            tf = fdir + separator + fbase + ext\r
+            self.TargetFileList.append(tf)\r
+            if ext == ".obj":\r
+                self.ObjectFileList.append(tf)\r
             \r
             fileBuildTemplatetList.append({\r
-                                   "string" : rule.Makefile[makeType][ftype],\r
+                                   "string" : rule.Makefile[family][ftype],\r
                                    "ftype"  : ftype,\r
                                    "fpath"  : fpath,\r
                                    "fdir"   : fdir,\r
@@ -1006,7 +1087,7 @@ class Makefile(object):
                                    "fbase"  : fbase,\r
                                    "fext"   : fext,\r
                                    "fdep"   : "",\r
-                                   "sep"    : separator,\r
+                                   "_sep_"    : separator,\r
                                    })\r
 \r
         #\r
@@ -1076,7 +1157,11 @@ class Makefile(object):
                     if dep not in fileStack and dep not in dependencyList:\r
                         fileStack.append(dep)\r
             else:\r
-                fd = open(f, 'r')\r
+                try:\r
+                    fd = open(f, 'r')\r
+                except:\r
+                    raise AutoGenError(FILE_OPEN_FAILURE, name=f)\r
+\r
                 fileContent = fd.read()\r
                 fd.close()\r
                 if len(fileContent) == 0:\r
@@ -1122,6 +1207,12 @@ class Makefile(object):
                 dirList.append(la.BuildInfo.BuildDir)\r
         return dirList\r
 \r
+    def GetCreateDirectoryCommand(self, dirs, make=gMakeType):\r
+        return [gCreateDirectoryCommandTemplate[make] % {'dir':dir} for dir in dirs]\r
+\r
+    def GetRemoveDirectoryCommand(self, dirs, make=gMakeType):\r
+        return [gRemoveDirectoryCommandTemplate[make] % {'dir':dir} for dir in dirs]\r
+\r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r
 # script.\r
 if __name__ == '__main__':\r