X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FAutoGen%2FGenMake.py;h=10913661907e9466460763d51baedbe204d87e00;hb=db4d47fd3ae9cb4a80399b7ea4cfd55f1b22d180;hp=3dc5ac2cf383ad0f0914f569511d5d3663d77777;hpb=0f78fd73496f26d45516f6c453a66f35edca6ab0;p=mirror_edk2.git diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py index 3dc5ac2cf3..1091366190 100644 --- a/BaseTools/Source/Python/AutoGen/GenMake.py +++ b/BaseTools/Source/Python/AutoGen/GenMake.py @@ -2,13 +2,7 @@ # Create makefile for MS nmake and GNU make # # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
-# This program and the accompanying materials -# are licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# SPDX-License-Identifier: BSD-2-Clause-Patent # ## Import Modules @@ -27,9 +21,10 @@ from Common.StringUtils import * from .BuildEngine import * import Common.GlobalData as GlobalData from collections import OrderedDict +from Common.DataType import TAB_COMPILER_MSFT ## Regular expression for finding header file inclusions -gIncludePattern = re.compile(r"^[ \t]*#?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() \t]+)(?:[ \t]*[\">]?\)?)", re.MULTILINE | re.UNICODE | re.IGNORECASE) +gIncludePattern = re.compile(r"^[ \t]*[#%]?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() \t]+)(?:[ \t]*[\">]?\)?)", re.MULTILINE | re.UNICODE | re.IGNORECASE) ## Regular expression for matching macro used in header file inclusion gMacroPattern = re.compile("([_A-Z][_A-Z0-9]*)[ \t]*\((.+)\)", re.UNICODE) @@ -166,7 +161,7 @@ class BuildFile(object): "gmake" : "include" } - _INC_FLAG_ = {"MSFT" : "/I", "GCC" : "-I", "INTEL" : "-I", "RVCT" : "-I"} + _INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", "RVCT" : "-I", "NASM" : "-I"} ## Constructor of BuildFile # @@ -454,7 +449,8 @@ cleanlib: self.FfsOutputFileList = [] # Compose a dict object containing information used to do replacement in template - def _CreateTemplateDict(self): + @property + def _TemplateDict(self): if self._FileType not in self._SEP_: EdkLogger.error("build", PARAMETER_INVALID, "Invalid Makefile type [%s]" % self._FileType, ExtraData="[%s]" % str(self._AutoGenObject)) @@ -474,23 +470,16 @@ cleanlib: else: ModuleEntryPoint = "_ModuleEntryPoint" - # Intel EBC compiler enforces EfiMain - if MyAgo.AutoGenVersion < 0x00010005 and MyAgo.Arch == "EBC": - ArchEntryPoint = "EfiMain" - else: - ArchEntryPoint = ModuleEntryPoint + ArchEntryPoint = ModuleEntryPoint if MyAgo.Arch == "EBC": # EBC compiler always use "EfiStart" as entry point. Only applies to EdkII modules ImageEntryPoint = "EfiStart" - elif MyAgo.AutoGenVersion < 0x00010005: - # Edk modules use entry point specified in INF file - ImageEntryPoint = ModuleEntryPoint else: # EdkII modules always use "_ModuleEntryPoint" as entry point ImageEntryPoint = "_ModuleEntryPoint" - for k, v in MyAgo.Module.Defines.iteritems(): + for k, v in MyAgo.Module.Defines.items(): if k not in MyAgo.Macros: MyAgo.Macros[k] = v @@ -502,7 +491,7 @@ cleanlib: MyAgo.Macros['IMAGE_ENTRY_POINT'] = ImageEntryPoint PCI_COMPRESS_Flag = False - for k, v in MyAgo.Module.Defines.iteritems(): + for k, v in MyAgo.Module.Defines.items(): if 'PCI_COMPRESS' == k and 'TRUE' == v: PCI_COMPRESS_Flag = True @@ -553,8 +542,8 @@ cleanlib: NewRespStr = ' '.join(NewStr) SaveFileOnChange(RespFile, NewRespStr, False) ToolsDef.append("%s = %s" % (Resp, UnexpandMacroStr + ' @' + RespFile)) - RespFileListContent += '@' + RespFile + os.linesep - RespFileListContent += NewRespStr + os.linesep + RespFileListContent += '@' + RespFile + TAB_LINE_BREAK + RespFileListContent += NewRespStr + TAB_LINE_BREAK SaveFileOnChange(RespFileList, RespFileListContent, False) else: if os.path.exists(RespFileList): @@ -594,6 +583,24 @@ cleanlib: } ) FileMacroList.append(FileMacro) + # Add support when compiling .nasm source files + for File in self.FileCache.keys(): + if not str(File).endswith('.nasm'): + continue + IncludePathList = [] + for P in MyAgo.IncludePathList: + IncludePath = self._INC_FLAG_['NASM'] + self.PlaceMacro(P, self.Macros) + if IncludePath.endswith(os.sep): + IncludePath = IncludePath.rstrip(os.sep) + # When compiling .nasm files, need to add a literal backslash at each path + # To specify a literal backslash at the end of the line, precede it with a caret (^) + if P == MyAgo.IncludePathList[-1] and os.sep == '\\': + IncludePath = ''.join([IncludePath, '^', os.sep]) + else: + IncludePath = os.path.join(IncludePath, '') + IncludePathList.append(IncludePath) + FileMacroList.append(self._FILE_MACRO_TEMPLATE.Replace({"macro_name": "NASM_INC", "source_file": IncludePathList})) + break # Generate macros used to represent files containing list of input files for ListFileMacro in self.ListFileMacros: @@ -605,11 +612,6 @@ cleanlib: False ) - # Edk modules need StrDefs.h for string ID - #if MyAgo.AutoGenVersion < 0x00010005 and len(MyAgo.UnicodeFileList) > 0: - # BcTargetList = ['strdefs'] - #else: - # BcTargetList = [] BcTargetList = [] MakefileName = self._FILE_NAME_[self._FileType] @@ -653,7 +655,7 @@ cleanlib: "module_relative_directory" : MyAgo.SourceDir, "module_dir" : mws.join (self.Macros["WORKSPACE"], MyAgo.SourceDir), "package_relative_directory": package_rel_dir, - "module_extra_defines" : ["%s = %s" % (k, v) for k, v in MyAgo.Module.Defines.iteritems()], + "module_extra_defines" : ["%s = %s" % (k, v) for k, v in MyAgo.Module.Defines.items()], "architecture" : MyAgo.Arch, "toolchain_tag" : MyAgo.ToolChain, @@ -667,8 +669,8 @@ cleanlib: "separator" : Separator, "module_tool_definitions" : ToolsDef, - "shell_command_code" : self._SHELL_CMD_[self._FileType].keys(), - "shell_command" : self._SHELL_CMD_[self._FileType].values(), + "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()), + "shell_command" : list(self._SHELL_CMD_[self._FileType].values()), "module_entry_point" : ModuleEntryPoint, "image_entry_point" : ImageEntryPoint, @@ -708,7 +710,7 @@ cleanlib: for index, Str in enumerate(FfsCmdList): if '-o' == Str: OutputFile = FfsCmdList[index + 1] - if '-i' == Str: + if '-i' == Str or "-oi" == Str: if DepsFileList == []: DepsFileList = [FfsCmdList[index + 1]] else: @@ -798,14 +800,14 @@ cleanlib: Tool = Flag break if Tool: - if 'PATH' not in self._AutoGenObject._BuildOption[Tool]: + if 'PATH' not in self._AutoGenObject.BuildOption[Tool]: 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)) - SingleCommandLength += len(self._AutoGenObject._BuildOption[Tool]['PATH']) + SingleCommandLength += len(self._AutoGenObject.BuildOption[Tool]['PATH']) for item in SingleCommandList[1:]: if FlagDict[Tool]['Macro'] in item: - if 'FLAGS' not in self._AutoGenObject._BuildOption[Tool]: + if 'FLAGS' not in self._AutoGenObject.BuildOption[Tool]: 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)) - Str = self._AutoGenObject._BuildOption[Tool]['FLAGS'] + Str = self._AutoGenObject.BuildOption[Tool]['FLAGS'] for Option in self._AutoGenObject.BuildOption: for Attr in self._AutoGenObject.BuildOption[Option]: if Str.find(Option + '_' + Attr) != -1: @@ -820,7 +822,7 @@ cleanlib: break SingleCommandLength += len(Str) elif '$(INC)' in item: - SingleCommandLength += self._AutoGenObject.IncludePathLength + len(IncPrefix) * len(self._AutoGenObject._IncludePathList) + SingleCommandLength += self._AutoGenObject.IncludePathLength + len(IncPrefix) * len(self._AutoGenObject.IncludePathList) elif item.find('$(') != -1: Str = item for Option in self._AutoGenObject.BuildOption: @@ -846,7 +848,7 @@ cleanlib: Key = Flag + '_RESP' RespMacro = FlagDict[Flag]['Macro'].replace('FLAGS', 'RESP') Value = self._AutoGenObject.BuildOption[Flag]['FLAGS'] - for inc in self._AutoGenObject._IncludePathList: + for inc in self._AutoGenObject.IncludePathList: Value += ' ' + IncPrefix + inc for Option in self._AutoGenObject.BuildOption: for Attr in self._AutoGenObject.BuildOption[Option]: @@ -951,7 +953,7 @@ cleanlib: NewFile = self.PlaceMacro(str(F), self.Macros) # In order to use file list macro as dependency if T.GenListFile: - # gnu tools need forward slash path separater, even on Windows + # gnu tools need forward slash path separator, even on Windows self.ListFileMacros[T.ListFileMacro].append(str(F).replace ('\\', '/')) self.FileListMacros[T.FileListMacro].append(NewFile) elif T.GenFileListMacro: @@ -975,7 +977,7 @@ cleanlib: ## For creating makefile targets for dependent libraries def ProcessDependentLibrary(self): for LibraryAutoGen in self._AutoGenObject.LibraryAutoGenList: - if not LibraryAutoGen.IsBinaryModule: + if not LibraryAutoGen.IsBinaryModule and not LibraryAutoGen.CanSkipbyHash(): self.LibraryBuildDirectoryList.append(self.PlaceMacro(LibraryAutoGen.BuildDir, self.Macros)) ## Return a list containing source file's dependencies @@ -995,7 +997,7 @@ cleanlib: ## Find dependencies for one source file # # By searching recursively "#include" directive in file, find out all the - # files needed by given source file. The dependecies will be only searched + # files needed by given source file. The dependencies will be only searched # in given search path list. # # @param File The source file @@ -1030,17 +1032,21 @@ cleanlib: CurrentFileDependencyList = DepDb[F] else: try: - Fd = open(F.Path, 'r') + Fd = open(F.Path, 'rb') + FileContent = Fd.read() + Fd.close() except BaseException as X: EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F.Path + "\n\t" + str(X)) - - FileContent = Fd.read() - Fd.close() if len(FileContent) == 0: continue - - if FileContent[0] == 0xff or FileContent[0] == 0xfe: - FileContent = unicode(FileContent, "utf-16") + try: + if FileContent[0] == 0xff or FileContent[0] == 0xfe: + FileContent = FileContent.decode('utf-16') + else: + FileContent = FileContent.decode() + except: + # The file is not txt file. for example .mcb file + continue IncludedFileList = gIncludePattern.findall(FileContent) for Inc in IncludedFileList: @@ -1094,8 +1100,6 @@ cleanlib: return DependencyList - _TemplateDict = property(_CreateTemplateDict) - ## CustomMakefile class # # This class encapsules makefie and its generation for module. It uses template to generate @@ -1204,7 +1208,8 @@ ${BEGIN}\t-@${create_directory_command}\n${END}\ self.IntermediateDirectoryList = ["$(DEBUG_DIR)", "$(OUTPUT_DIR)"] # Compose a dict object containing information used to do replacement in template - def _CreateTemplateDict(self): + @property + def _TemplateDict(self): Separator = self._SEP_[self._FileType] MyAgo = self._AutoGenObject if self._FileType not in MyAgo.CustomMakefile: @@ -1268,8 +1273,8 @@ ${BEGIN}\t-@${create_directory_command}\n${END}\ "separator" : Separator, "module_tool_definitions" : ToolsDef, - "shell_command_code" : self._SHELL_CMD_[self._FileType].keys(), - "shell_command" : self._SHELL_CMD_[self._FileType].values(), + "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()), + "shell_command" : list(self._SHELL_CMD_[self._FileType].values()), "create_directory_command" : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList), "custom_makefile_content" : CustomMakefile @@ -1277,8 +1282,6 @@ ${BEGIN}\t-@${create_directory_command}\n${END}\ return MakefileTemplateDict - _TemplateDict = property(_CreateTemplateDict) - ## PlatformMakefile class # # This class encapsules makefie and its generation for platform. It uses @@ -1395,7 +1398,8 @@ cleanlib: self.LibraryMakeCommandList = [] # Compose a dict object containing information used to do replacement in template - def _CreateTemplateDict(self): + @property + def _TemplateDict(self): Separator = self._SEP_[self._FileType] MyAgo = self._AutoGenObject @@ -1443,8 +1447,8 @@ cleanlib: "toolchain_tag" : MyAgo.ToolChain, "build_target" : MyAgo.BuildTarget, - "shell_command_code" : self._SHELL_CMD_[self._FileType].keys(), - "shell_command" : self._SHELL_CMD_[self._FileType].values(), + "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()), + "shell_command" : list(self._SHELL_CMD_[self._FileType].values()), "build_architecture_list" : MyAgo.Arch, "architecture" : MyAgo.Arch, "separator" : Separator, @@ -1476,12 +1480,10 @@ cleanlib: def GetLibraryBuildDirectoryList(self): DirList = [] for LibraryAutoGen in self._AutoGenObject.LibraryAutoGenList: - if not LibraryAutoGen.IsBinaryModule: + if not LibraryAutoGen.IsBinaryModule and not LibraryAutoGen.CanSkipbyHash(): DirList.append(os.path.join(self._AutoGenObject.BuildDir, LibraryAutoGen.BuildDir)) return DirList - _TemplateDict = property(_CreateTemplateDict) - ## TopLevelMakefile class # # This class encapsules makefie and its generation for entrance makefile. It @@ -1501,7 +1503,8 @@ class TopLevelMakefile(BuildFile): self.IntermediateDirectoryList = [] # Compose a dict object containing information used to do replacement in template - def _CreateTemplateDict(self): + @property + def _TemplateDict(self): Separator = self._SEP_[self._FileType] # any platform autogen object is ok because we just need common information @@ -1520,13 +1523,9 @@ class TopLevelMakefile(BuildFile): if MyAgo.FdfFile is not None and MyAgo.FdfFile != "": FdfFileList = [MyAgo.FdfFile] # macros passed to GenFds - MacroList.append('"%s=%s"' % ("EFI_SOURCE", GlobalData.gEfiSource.replace('\\', '\\\\'))) - MacroList.append('"%s=%s"' % ("EDK_SOURCE", GlobalData.gEdkSource.replace('\\', '\\\\'))) MacroDict = {} MacroDict.update(GlobalData.gGlobalDefines) MacroDict.update(GlobalData.gCommandLineDefines) - MacroDict.pop("EFI_SOURCE", "dummy") - MacroDict.pop("EDK_SOURCE", "dummy") for MacroName in MacroDict: if MacroDict[MacroName] != "": MacroList.append('"%s=%s"' % (MacroName, MacroDict[MacroName].replace('\\', '\\\\'))) @@ -1580,8 +1579,8 @@ class TopLevelMakefile(BuildFile): "toolchain_tag" : MyAgo.ToolChain, "build_target" : MyAgo.BuildTarget, - "shell_command_code" : self._SHELL_CMD_[self._FileType].keys(), - "shell_command" : self._SHELL_CMD_[self._FileType].values(), + "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()), + "shell_command" : list(self._SHELL_CMD_[self._FileType].values()), 'arch' : list(MyAgo.ArchList), "build_architecture_list" : ','.join(MyAgo.ArchList), "separator" : Separator, @@ -1617,12 +1616,10 @@ class TopLevelMakefile(BuildFile): def GetLibraryBuildDirectoryList(self): DirList = [] for LibraryAutoGen in self._AutoGenObject.LibraryAutoGenList: - if not LibraryAutoGen.IsBinaryModule: + if not LibraryAutoGen.IsBinaryModule and not LibraryAutoGen.CanSkipbyHash(): DirList.append(os.path.join(self._AutoGenObject.BuildDir, LibraryAutoGen.BuildDir)) return DirList - _TemplateDict = property(_CreateTemplateDict) - # This acts like the main() function for the script, unless it is 'import'ed into another script. if __name__ == '__main__': pass