]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/GenMake.py
BaseTools: Various typo
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenMake.py
index f1dc14754154fce247701bb0465b9d79a4bd359a..53c5b8577d0947bd57808e16b2b4e237c02a8f08 100644 (file)
@@ -27,9 +27,10 @@ from Common.StringUtils import *
 from .BuildEngine import *\r
 import Common.GlobalData as GlobalData\r
 from collections import OrderedDict\r
+from Common.DataType import TAB_COMPILER_MSFT\r
 \r
 ## Regular expression for finding header file inclusions\r
-gIncludePattern = re.compile(r"^[ \t]*#?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() \t]+)(?:[ \t]*[\">]?\)?)", re.MULTILINE | re.UNICODE | re.IGNORECASE)\r
+gIncludePattern = re.compile(r"^[ \t]*[#%]?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() \t]+)(?:[ \t]*[\">]?\)?)", re.MULTILINE | re.UNICODE | re.IGNORECASE)\r
 \r
 ## Regular expression for matching macro used in header file inclusion\r
 gMacroPattern = re.compile("([_A-Z][_A-Z0-9]*)[ \t]*\((.+)\)", re.UNICODE)\r
@@ -166,7 +167,7 @@ class BuildFile(object):
         "gmake" :   "include"\r
     }\r
 \r
-    _INC_FLAG_ = {"MSFT" : "/I", "GCC" : "-I", "INTEL" : "-I", "RVCT" : "-I"}\r
+    _INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", "RVCT" : "-I", "NASM" : "-I"}\r
 \r
     ## Constructor of BuildFile\r
     #\r
@@ -436,7 +437,6 @@ cleanlib:
         self.ListFileMacros = {}\r
 \r
         self.FileCache = {}\r
-        self.FileDependency = []\r
         self.LibraryBuildCommandList = []\r
         self.LibraryFileList = []\r
         self.LibraryMakefileList = []\r
@@ -455,7 +455,8 @@ cleanlib:
         self.FfsOutputFileList = []\r
 \r
     # Compose a dict object containing information used to do replacement in template\r
-    def _CreateTemplateDict(self):\r
+    @property\r
+    def _TemplateDict(self):\r
         if self._FileType not in self._SEP_:\r
             EdkLogger.error("build", PARAMETER_INVALID, "Invalid Makefile type [%s]" % self._FileType,\r
                             ExtraData="[%s]" % str(self._AutoGenObject))\r
@@ -475,23 +476,16 @@ cleanlib:
         else:\r
             ModuleEntryPoint = "_ModuleEntryPoint"\r
 \r
-        # Intel EBC compiler enforces EfiMain\r
-        if MyAgo.AutoGenVersion < 0x00010005 and MyAgo.Arch == "EBC":\r
-            ArchEntryPoint = "EfiMain"\r
-        else:\r
-            ArchEntryPoint = ModuleEntryPoint\r
+        ArchEntryPoint = ModuleEntryPoint\r
 \r
         if MyAgo.Arch == "EBC":\r
             # EBC compiler always use "EfiStart" as entry point. Only applies to EdkII modules\r
             ImageEntryPoint = "EfiStart"\r
-        elif MyAgo.AutoGenVersion < 0x00010005:\r
-            # Edk modules use entry point specified in INF file\r
-            ImageEntryPoint = ModuleEntryPoint\r
         else:\r
             # EdkII modules always use "_ModuleEntryPoint" as entry point\r
             ImageEntryPoint = "_ModuleEntryPoint"\r
 \r
-        for k, v in MyAgo.Module.Defines.iteritems():\r
+        for k, v in MyAgo.Module.Defines.items():\r
             if k not in MyAgo.Macros:\r
                 MyAgo.Macros[k] = v\r
 \r
@@ -503,7 +497,7 @@ cleanlib:
             MyAgo.Macros['IMAGE_ENTRY_POINT'] = ImageEntryPoint\r
 \r
         PCI_COMPRESS_Flag = False\r
-        for k, v in MyAgo.Module.Defines.iteritems():\r
+        for k, v in MyAgo.Module.Defines.items():\r
             if 'PCI_COMPRESS' == k and 'TRUE' == v:\r
                 PCI_COMPRESS_Flag = True\r
 \r
@@ -554,8 +548,8 @@ cleanlib:
                 NewRespStr = ' '.join(NewStr)\r
                 SaveFileOnChange(RespFile, NewRespStr, False)\r
                 ToolsDef.append("%s = %s" % (Resp, UnexpandMacroStr + ' @' + RespFile))\r
-                RespFileListContent += '@' + RespFile + os.linesep\r
-                RespFileListContent += NewRespStr + os.linesep\r
+                RespFileListContent += '@' + RespFile + TAB_LINE_BREAK\r
+                RespFileListContent += NewRespStr + TAB_LINE_BREAK\r
             SaveFileOnChange(RespFileList, RespFileListContent, False)\r
         else:\r
             if os.path.exists(RespFileList):\r
@@ -595,6 +589,24 @@ cleanlib:
                                                 }\r
                                                 )\r
         FileMacroList.append(FileMacro)\r
+        # Add support when compiling .nasm source files\r
+        for File in self.FileCache.keys():\r
+            if not str(File).endswith('.nasm'):\r
+                continue\r
+            IncludePathList = []\r
+            for P in  MyAgo.IncludePathList:\r
+                IncludePath = self._INC_FLAG_['NASM'] + self.PlaceMacro(P, self.Macros)\r
+                if IncludePath.endswith(os.sep):\r
+                    IncludePath = IncludePath.rstrip(os.sep)\r
+                # When compiling .nasm files, need to add a literal backslash at each path\r
+                # To specify a literal backslash at the end of the line, precede it with a caret (^)\r
+                if P == MyAgo.IncludePathList[-1] and os.sep == '\\':\r
+                    IncludePath = ''.join([IncludePath, '^', os.sep])\r
+                else:\r
+                    IncludePath = os.path.join(IncludePath, '')\r
+                IncludePathList.append(IncludePath)\r
+            FileMacroList.append(self._FILE_MACRO_TEMPLATE.Replace({"macro_name": "NASM_INC", "source_file": IncludePathList}))\r
+            break\r
 \r
         # Generate macros used to represent files containing list of input files\r
         for ListFileMacro in self.ListFileMacros:\r
@@ -606,11 +618,6 @@ cleanlib:
                 False\r
                 )\r
 \r
-        # Edk modules need <BaseName>StrDefs.h for string ID\r
-        #if MyAgo.AutoGenVersion < 0x00010005 and len(MyAgo.UnicodeFileList) > 0:\r
-        #    BcTargetList = ['strdefs']\r
-        #else:\r
-        #    BcTargetList = []\r
         BcTargetList = []\r
 \r
         MakefileName = self._FILE_NAME_[self._FileType]\r
@@ -654,7 +661,7 @@ cleanlib:
             "module_relative_directory" : MyAgo.SourceDir,\r
             "module_dir"                : mws.join (self.Macros["WORKSPACE"], MyAgo.SourceDir),\r
             "package_relative_directory": package_rel_dir,\r
-            "module_extra_defines"      : ["%s = %s" % (k, v) for k, v in MyAgo.Module.Defines.iteritems()],\r
+            "module_extra_defines"      : ["%s = %s" % (k, v) for k, v in MyAgo.Module.Defines.items()],\r
 \r
             "architecture"              : MyAgo.Arch,\r
             "toolchain_tag"             : MyAgo.ToolChain,\r
@@ -668,8 +675,8 @@ cleanlib:
             "separator"                 : Separator,\r
             "module_tool_definitions"   : ToolsDef,\r
 \r
-            "shell_command_code"        : self._SHELL_CMD_[self._FileType].keys(),\r
-            "shell_command"             : self._SHELL_CMD_[self._FileType].values(),\r
+            "shell_command_code"        : list(self._SHELL_CMD_[self._FileType].keys()),\r
+            "shell_command"             : list(self._SHELL_CMD_[self._FileType].values()),\r
 \r
             "module_entry_point"        : ModuleEntryPoint,\r
             "image_entry_point"         : ImageEntryPoint,\r
@@ -799,14 +806,14 @@ cleanlib:
                                     Tool = Flag\r
                                     break\r
                         if Tool:\r
-                            if 'PATH' not in self._AutoGenObject._BuildOption[Tool]:\r
+                            if 'PATH' not in self._AutoGenObject.BuildOption[Tool]:\r
                                 EdkLogger.error("build", AUTOGEN_ERROR, "%s_PATH doesn't exist in %s ToolChain and %s Arch." %(Tool, self._AutoGenObject.ToolChain, self._AutoGenObject.Arch), ExtraData="[%s]" % str(self._AutoGenObject))\r
-                            SingleCommandLength += len(self._AutoGenObject._BuildOption[Tool]['PATH'])\r
+                            SingleCommandLength += len(self._AutoGenObject.BuildOption[Tool]['PATH'])\r
                             for item in SingleCommandList[1:]:\r
                                 if FlagDict[Tool]['Macro'] in item:\r
-                                    if 'FLAGS' not in self._AutoGenObject._BuildOption[Tool]:\r
+                                    if 'FLAGS' not in self._AutoGenObject.BuildOption[Tool]:\r
                                         EdkLogger.error("build", AUTOGEN_ERROR, "%s_FLAGS doesn't exist in %s ToolChain and %s Arch." %(Tool, self._AutoGenObject.ToolChain, self._AutoGenObject.Arch), ExtraData="[%s]" % str(self._AutoGenObject))\r
-                                    Str = self._AutoGenObject._BuildOption[Tool]['FLAGS']\r
+                                    Str = self._AutoGenObject.BuildOption[Tool]['FLAGS']\r
                                     for Option in self._AutoGenObject.BuildOption:\r
                                         for Attr in self._AutoGenObject.BuildOption[Option]:\r
                                             if Str.find(Option + '_' + Attr) != -1:\r
@@ -821,7 +828,7 @@ cleanlib:
                                             break\r
                                     SingleCommandLength += len(Str)\r
                                 elif '$(INC)' in item:\r
-                                    SingleCommandLength += self._AutoGenObject.IncludePathLength + len(IncPrefix) * len(self._AutoGenObject._IncludePathList)\r
+                                    SingleCommandLength += self._AutoGenObject.IncludePathLength + len(IncPrefix) * len(self._AutoGenObject.IncludePathList)\r
                                 elif item.find('$(') != -1:\r
                                     Str = item\r
                                     for Option in self._AutoGenObject.BuildOption:\r
@@ -847,7 +854,7 @@ cleanlib:
                         Key = Flag + '_RESP'\r
                         RespMacro = FlagDict[Flag]['Macro'].replace('FLAGS', 'RESP')\r
                         Value = self._AutoGenObject.BuildOption[Flag]['FLAGS']\r
-                        for inc in self._AutoGenObject._IncludePathList:\r
+                        for inc in self._AutoGenObject.IncludePathList:\r
                             Value += ' ' + IncPrefix + inc\r
                         for Option in self._AutoGenObject.BuildOption:\r
                             for Attr in self._AutoGenObject.BuildOption[Option]:\r
@@ -891,26 +898,26 @@ cleanlib:
                 if Item in SourceFileList:\r
                     SourceFileList.remove(Item)\r
 \r
-        self.FileDependency = self.GetFileDependency(\r
+        FileDependencyDict = self.GetFileDependency(\r
                                     SourceFileList,\r
                                     ForceIncludedFile,\r
                                     self._AutoGenObject.IncludePathList + self._AutoGenObject.BuildOptionIncPathList\r
                                     )\r
         DepSet = None\r
-        for File in self.FileDependency:\r
-            if not self.FileDependency[File]:\r
-                self.FileDependency[File] = ['$(FORCE_REBUILD)']\r
+        for File,Dependency in FileDependencyDict.items():\r
+            if not Dependency:\r
+                FileDependencyDict[File] = ['$(FORCE_REBUILD)']\r
                 continue\r
 \r
-            self._AutoGenObject.AutoGenDepSet |= set(self.FileDependency[File])\r
+            self._AutoGenObject.AutoGenDepSet |= set(Dependency)\r
 \r
             # skip non-C files\r
             if File.Ext not in [".c", ".C"] or File.Name == "AutoGen.c":\r
                 continue\r
             elif DepSet is None:\r
-                DepSet = set(self.FileDependency[File])\r
+                DepSet = set(Dependency)\r
             else:\r
-                DepSet &= set(self.FileDependency[File])\r
+                DepSet &= set(Dependency)\r
         # in case nothing in SourceFileList\r
         if DepSet is None:\r
             DepSet = set()\r
@@ -920,13 +927,13 @@ cleanlib:
         for File in DepSet:\r
             self.CommonFileDependency.append(self.PlaceMacro(File.Path, self.Macros))\r
 \r
-        for File in self.FileDependency:\r
+        for File in FileDependencyDict:\r
             # skip non-C files\r
             if File.Ext not in [".c", ".C"] or File.Name == "AutoGen.c":\r
                 continue\r
-            NewDepSet = set(self.FileDependency[File])\r
+            NewDepSet = set(FileDependencyDict[File])\r
             NewDepSet -= DepSet\r
-            self.FileDependency[File] = ["$(COMMON_DEPS)"] + list(NewDepSet)\r
+            FileDependencyDict[File] = ["$(COMMON_DEPS)"] + list(NewDepSet)\r
 \r
         # Convert target description object to target string in makefile\r
         for Type in self._AutoGenObject.Targets:\r
@@ -944,15 +951,15 @@ cleanlib:
                 for Dep in T.Dependencies:\r
                     Deps.append(self.PlaceMacro(str(Dep), self.Macros))\r
                 # Add inclusion-dependencies\r
-                if len(T.Inputs) == 1 and T.Inputs[0] in self.FileDependency:\r
-                    for F in self.FileDependency[T.Inputs[0]]:\r
+                if len(T.Inputs) == 1 and T.Inputs[0] in FileDependencyDict:\r
+                    for F in FileDependencyDict[T.Inputs[0]]:\r
                         Deps.append(self.PlaceMacro(str(F), self.Macros))\r
                 # Add source-dependencies\r
                 for F in T.Inputs:\r
                     NewFile = self.PlaceMacro(str(F), self.Macros)\r
                     # In order to use file list macro as dependency\r
                     if T.GenListFile:\r
-                        # gnu tools need forward slash path separater, even on Windows\r
+                        # gnu tools need forward slash path separator, even on Windows\r
                         self.ListFileMacros[T.ListFileMacro].append(str(F).replace ('\\', '/'))\r
                         self.FileListMacros[T.FileListMacro].append(NewFile)\r
                     elif T.GenFileListMacro:\r
@@ -996,7 +1003,7 @@ cleanlib:
     ## Find dependencies for one source file\r
     #\r
     #  By searching recursively "#include" directive in file, find out all the\r
-    #  files needed by given source file. The dependecies will be only searched\r
+    #  files needed by given source file. The dependencies will be only searched\r
     #  in given search path list.\r
     #\r
     #   @param      File            The source file\r
@@ -1031,17 +1038,21 @@ cleanlib:
                 CurrentFileDependencyList = DepDb[F]\r
             else:\r
                 try:\r
-                    Fd = open(F.Path, 'r')\r
+                    Fd = open(F.Path, 'rb')\r
+                    FileContent = Fd.read()\r
+                    Fd.close()\r
                 except BaseException as X:\r
                     EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F.Path + "\n\t" + str(X))\r
-\r
-                FileContent = Fd.read()\r
-                Fd.close()\r
                 if len(FileContent) == 0:\r
                     continue\r
 \r
                 if FileContent[0] == 0xff or FileContent[0] == 0xfe:\r
-                    FileContent = unicode(FileContent, "utf-16")\r
+                    FileContent = FileContent.decode('utf-16')\r
+                else:\r
+                    try:\r
+                        FileContent = str(FileContent)\r
+                    except:\r
+                        pass\r
                 IncludedFileList = gIncludePattern.findall(FileContent)\r
 \r
                 for Inc in IncludedFileList:\r
@@ -1095,8 +1106,6 @@ cleanlib:
 \r
         return DependencyList\r
 \r
-    _TemplateDict = property(_CreateTemplateDict)\r
-\r
 ## CustomMakefile class\r
 #\r
 #  This class encapsules makefie and its generation for module. It uses template to generate\r
@@ -1205,7 +1214,8 @@ ${BEGIN}\t-@${create_directory_command}\n${END}\
         self.IntermediateDirectoryList = ["$(DEBUG_DIR)", "$(OUTPUT_DIR)"]\r
 \r
     # Compose a dict object containing information used to do replacement in template\r
-    def _CreateTemplateDict(self):\r
+    @property\r
+    def _TemplateDict(self):\r
         Separator = self._SEP_[self._FileType]\r
         MyAgo = self._AutoGenObject\r
         if self._FileType not in MyAgo.CustomMakefile:\r
@@ -1269,8 +1279,8 @@ ${BEGIN}\t-@${create_directory_command}\n${END}\
             "separator"                 : Separator,\r
             "module_tool_definitions"   : ToolsDef,\r
 \r
-            "shell_command_code"        : self._SHELL_CMD_[self._FileType].keys(),\r
-            "shell_command"             : self._SHELL_CMD_[self._FileType].values(),\r
+            "shell_command_code"        : list(self._SHELL_CMD_[self._FileType].keys()),\r
+            "shell_command"             : list(self._SHELL_CMD_[self._FileType].values()),\r
 \r
             "create_directory_command"  : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList),\r
             "custom_makefile_content"   : CustomMakefile\r
@@ -1278,8 +1288,6 @@ ${BEGIN}\t-@${create_directory_command}\n${END}\
 \r
         return MakefileTemplateDict\r
 \r
-    _TemplateDict = property(_CreateTemplateDict)\r
-\r
 ## PlatformMakefile class\r
 #\r
 #  This class encapsules makefie and its generation for platform. It uses\r
@@ -1396,7 +1404,8 @@ cleanlib:
         self.LibraryMakeCommandList = []\r
 \r
     # Compose a dict object containing information used to do replacement in template\r
-    def _CreateTemplateDict(self):\r
+    @property\r
+    def _TemplateDict(self):\r
         Separator = self._SEP_[self._FileType]\r
 \r
         MyAgo = self._AutoGenObject\r
@@ -1444,8 +1453,8 @@ cleanlib:
 \r
             "toolchain_tag"             : MyAgo.ToolChain,\r
             "build_target"              : MyAgo.BuildTarget,\r
-            "shell_command_code"        : self._SHELL_CMD_[self._FileType].keys(),\r
-            "shell_command"             : self._SHELL_CMD_[self._FileType].values(),\r
+            "shell_command_code"        : list(self._SHELL_CMD_[self._FileType].keys()),\r
+            "shell_command"             : list(self._SHELL_CMD_[self._FileType].values()),\r
             "build_architecture_list"   : MyAgo.Arch,\r
             "architecture"              : MyAgo.Arch,\r
             "separator"                 : Separator,\r
@@ -1481,8 +1490,6 @@ cleanlib:
                 DirList.append(os.path.join(self._AutoGenObject.BuildDir, LibraryAutoGen.BuildDir))\r
         return DirList\r
 \r
-    _TemplateDict = property(_CreateTemplateDict)\r
-\r
 ## TopLevelMakefile class\r
 #\r
 #  This class encapsules makefie and its generation for entrance makefile. It\r
@@ -1502,7 +1509,8 @@ class TopLevelMakefile(BuildFile):
         self.IntermediateDirectoryList = []\r
 \r
     # Compose a dict object containing information used to do replacement in template\r
-    def _CreateTemplateDict(self):\r
+    @property\r
+    def _TemplateDict(self):\r
         Separator = self._SEP_[self._FileType]\r
 \r
         # any platform autogen object is ok because we just need common information\r
@@ -1521,13 +1529,9 @@ class TopLevelMakefile(BuildFile):
         if MyAgo.FdfFile is not None and MyAgo.FdfFile != "":\r
             FdfFileList = [MyAgo.FdfFile]\r
             # macros passed to GenFds\r
-            MacroList.append('"%s=%s"' % ("EFI_SOURCE", GlobalData.gEfiSource.replace('\\', '\\\\')))\r
-            MacroList.append('"%s=%s"' % ("EDK_SOURCE", GlobalData.gEdkSource.replace('\\', '\\\\')))\r
             MacroDict = {}\r
             MacroDict.update(GlobalData.gGlobalDefines)\r
             MacroDict.update(GlobalData.gCommandLineDefines)\r
-            MacroDict.pop("EFI_SOURCE", "dummy")\r
-            MacroDict.pop("EDK_SOURCE", "dummy")\r
             for MacroName in MacroDict:\r
                 if MacroDict[MacroName] != "":\r
                     MacroList.append('"%s=%s"' % (MacroName, MacroDict[MacroName].replace('\\', '\\\\')))\r
@@ -1581,8 +1585,8 @@ class TopLevelMakefile(BuildFile):
 \r
             "toolchain_tag"             : MyAgo.ToolChain,\r
             "build_target"              : MyAgo.BuildTarget,\r
-            "shell_command_code"        : self._SHELL_CMD_[self._FileType].keys(),\r
-            "shell_command"             : self._SHELL_CMD_[self._FileType].values(),\r
+            "shell_command_code"        : list(self._SHELL_CMD_[self._FileType].keys()),\r
+            "shell_command"             : list(self._SHELL_CMD_[self._FileType].values()),\r
             'arch'                      : list(MyAgo.ArchList),\r
             "build_architecture_list"   : ','.join(MyAgo.ArchList),\r
             "separator"                 : Separator,\r
@@ -1622,8 +1626,6 @@ class TopLevelMakefile(BuildFile):
                 DirList.append(os.path.join(self._AutoGenObject.BuildDir, LibraryAutoGen.BuildDir))\r
         return DirList\r
 \r
-    _TemplateDict = property(_CreateTemplateDict)\r
-\r
 # This acts like the main() function for the script, unless it is 'import'ed into another script.\r
 if __name__ == '__main__':\r
     pass\r