X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FAutoGen%2FGenMake.py;h=212ca0fa7f9f16da1eeb8ecfd7aebb35537c9a33;hp=2f6fe06764773788e533cb87d021c5ef81755158;hb=48b0bf6476a215a8e399af3c5905c17f94f2c63d;hpb=8be15c61e88709c55970c5d5272d19bd9bba67fb diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py index 2f6fe06764..212ca0fa7f 100644 --- a/BaseTools/Source/Python/AutoGen/GenMake.py +++ b/BaseTools/Source/Python/AutoGen/GenMake.py @@ -2,17 +2,12 @@ # 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 # +from __future__ import absolute_import import Common.LongFilePathOs as os import sys import string @@ -29,7 +24,7 @@ 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_ = {TAB_COMPILER_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 # @@ -434,7 +429,7 @@ cleanlib: self.CommonFileDependency = [] self.FileListMacros = {} self.ListFileMacros = {} - + self.ObjTargetDict = OrderedDict() self.FileCache = {} self.LibraryBuildCommandList = [] self.LibraryFileList = [] @@ -475,18 +470,11 @@ 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" @@ -524,6 +512,9 @@ cleanlib: # Remove duplicated include path, if any if Attr == "FLAGS": Value = RemoveDupOption(Value, IncPrefix, MyAgo.IncludePathList) + if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and Tool == 'CC' and '/GM' in Value: + Value = Value.replace(' /MP', '') + MyAgo.BuildOption[Tool][Attr] = Value if Tool == "OPTROM" and PCI_COMPRESS_Flag: ValueList = Value.split() if ValueList: @@ -554,8 +545,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): @@ -595,6 +586,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: @@ -606,11 +615,11 @@ cleanlib: False ) - # Edk modules need StrDefs.h for string ID - #if MyAgo.AutoGenVersion < 0x00010005 and len(MyAgo.UnicodeFileList) > 0: - # BcTargetList = ['strdefs'] - #else: - # BcTargetList = [] + # Generate objlist used to create .obj file + for Type in self.ObjTargetDict: + NewLine = ' '.join(list(self.ObjTargetDict[Type])) + FileMacroList.append("OBJLIST_%s = %s" % (list(self.ObjTargetDict.keys()).index(Type), NewLine)) + BcTargetList = [] MakefileName = self._FILE_NAME_[self._FileType] @@ -709,7 +718,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: @@ -896,6 +905,50 @@ cleanlib: ForceIncludedFile, self._AutoGenObject.IncludePathList + self._AutoGenObject.BuildOptionIncPathList ) + + # Check if header files are listed in metafile + # Get a list of unique module header source files from MetaFile + headerFilesInMetaFileSet = set() + for aFile in self._AutoGenObject.SourceFileList: + aFileName = str(aFile) + if not aFileName.endswith('.h'): + continue + headerFilesInMetaFileSet.add(aFileName.lower()) + + # Get a list of unique module autogen files + localAutoGenFileSet = set() + for aFile in self._AutoGenObject.AutoGenFileList: + localAutoGenFileSet.add(str(aFile).lower()) + + # Get a list of unique module dependency header files + # Exclude autogen files and files not in the source directory + headerFileDependencySet = set() + localSourceDir = str(self._AutoGenObject.SourceDir).lower() + for Dependency in FileDependencyDict.values(): + for aFile in Dependency: + aFileName = str(aFile).lower() + if not aFileName.endswith('.h'): + continue + if aFileName in localAutoGenFileSet: + continue + if localSourceDir not in aFileName: + continue + headerFileDependencySet.add(aFileName) + + # Ensure that gModuleBuildTracking has been initialized per architecture + if self._AutoGenObject.Arch not in GlobalData.gModuleBuildTracking: + GlobalData.gModuleBuildTracking[self._AutoGenObject.Arch] = dict() + + # Check if a module dependency header file is missing from the module's MetaFile + for aFile in headerFileDependencySet: + if aFile in headerFilesInMetaFileSet: + continue + if GlobalData.gUseHashCache: + GlobalData.gModuleBuildTracking[self._AutoGenObject.Arch][self._AutoGenObject] = 'FAIL_METAFILE' + EdkLogger.warn("build","Module MetaFile [Sources] is missing local header!", + ExtraData = "Local Header: " + aFile + " not found in " + self._AutoGenObject.MetaFile.Path + ) + DepSet = None for File,Dependency in FileDependencyDict.items(): if not Dependency: @@ -917,20 +970,31 @@ cleanlib: # # Extract common files list in the dependency files # - for File in sorted(DepSet, key=lambda x: str(x)): + for File in DepSet: self.CommonFileDependency.append(self.PlaceMacro(File.Path, self.Macros)) + CmdSumDict = {} + CmdTargetDict = {} + CmdCppDict = {} + DependencyDict = FileDependencyDict.copy() for File in FileDependencyDict: # skip non-C files if File.Ext not in [".c", ".C"] or File.Name == "AutoGen.c": continue NewDepSet = set(FileDependencyDict[File]) NewDepSet -= DepSet - FileDependencyDict[File] = ["$(COMMON_DEPS)"] + sorted(NewDepSet, key=lambda x: str(x)) + FileDependencyDict[File] = ["$(COMMON_DEPS)"] + list(NewDepSet) + DependencyDict[File] = list(NewDepSet) # Convert target description object to target string in makefile + if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and TAB_C_CODE_FILE in self._AutoGenObject.Targets: + for T in self._AutoGenObject.Targets[TAB_C_CODE_FILE]: + NewFile = self.PlaceMacro(str(T), self.Macros) + if not self.ObjTargetDict.get(T.Target.SubDir): + self.ObjTargetDict[T.Target.SubDir] = set() + self.ObjTargetDict[T.Target.SubDir].add(NewFile) for Type in self._AutoGenObject.Targets: - for T in sorted(self._AutoGenObject.Targets[Type], key=lambda x: str(x)): + for T in self._AutoGenObject.Targets[Type]: # Generate related macros if needed if T.GenFileListMacro and T.FileListMacro not in self.FileListMacros: self.FileListMacros[T.FileListMacro] = [] @@ -940,9 +1004,12 @@ cleanlib: self.ListFileMacros[T.IncListFileMacro] = [] Deps = [] + CCodeDeps = [] # Add force-dependencies for Dep in T.Dependencies: Deps.append(self.PlaceMacro(str(Dep), self.Macros)) + if Dep != '$(MAKE_FILE)': + CCodeDeps.append(self.PlaceMacro(str(Dep), self.Macros)) # Add inclusion-dependencies if len(T.Inputs) == 1 and T.Inputs[0] in FileDependencyDict: for F in FileDependencyDict[T.Inputs[0]]: @@ -952,7 +1019,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: @@ -966,17 +1033,69 @@ cleanlib: if Type in [TAB_OBJECT_FILE, TAB_STATIC_LIBRARY]: Deps.append("$(%s)" % T.ListFileMacro) - TargetDict = { - "target" : self.PlaceMacro(T.Target.Path, self.Macros), - "cmd" : "\n\t".join(T.Commands), - "deps" : Deps - } - self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(TargetDict)) - + if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and Type == TAB_C_CODE_FILE: + T, CmdTarget, CmdTargetDict, CmdCppDict = self.ParserCCodeFile(T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict) + TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": CCodeDeps} + CmdLine = self._BUILD_TARGET_TEMPLATE.Replace(TargetDict).rstrip().replace('\t$(OBJLIST', '$(OBJLIST') + if T.Commands: + CmdLine = '%s%s' %(CmdLine, TAB_LINE_BREAK) + if CCodeDeps or CmdLine: + self.BuildTargetList.append(CmdLine) + else: + TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": Deps} + self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(TargetDict)) + + def ParserCCodeFile(self, T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict): + if not CmdSumDict: + for item in self._AutoGenObject.Targets[Type]: + CmdSumDict[item.Target.SubDir] = item.Target.BaseName + for CppPath in item.Inputs: + Path = self.PlaceMacro(CppPath.Path, self.Macros) + if CmdCppDict.get(item.Target.SubDir): + CmdCppDict[item.Target.SubDir].append(Path) + else: + CmdCppDict[item.Target.SubDir] = ['$(MAKE_FILE)', Path] + if CppPath.Path in DependencyDict: + for Temp in DependencyDict[CppPath.Path]: + try: + Path = self.PlaceMacro(Temp.Path, self.Macros) + except: + continue + if Path not in (self.CommonFileDependency + CmdCppDict[item.Target.SubDir]): + CmdCppDict[item.Target.SubDir].append(Path) + if T.Commands: + CommandList = T.Commands[:] + for Item in CommandList[:]: + SingleCommandList = Item.split() + if len(SingleCommandList) > 0 and self.CheckCCCmd(SingleCommandList): + for Temp in SingleCommandList: + if Temp.startswith('/Fo'): + CmdSign = '%s%s' % (Temp.rsplit(TAB_SLASH, 1)[0], TAB_SLASH) + break + else: continue + if CmdSign not in list(CmdTargetDict.keys()): + CmdTargetDict[CmdSign] = Item.replace(Temp, CmdSign) + else: + CmdTargetDict[CmdSign] = "%s %s" % (CmdTargetDict[CmdSign], SingleCommandList[-1]) + Index = CommandList.index(Item) + CommandList.pop(Index) + if SingleCommandList[-1].endswith("%s%s.c" % (TAB_SLASH, CmdSumDict[CmdSign.lstrip('/Fo').rsplit(TAB_SLASH, 1)[0]])): + Cpplist = CmdCppDict[T.Target.SubDir] + Cpplist.insert(0, '$(OBJLIST_%d): $(COMMON_DEPS)' % list(self.ObjTargetDict.keys()).index(T.Target.SubDir)) + T.Commands[Index] = '%s\n\t%s' % (' \\\n\t'.join(Cpplist), CmdTargetDict[CmdSign]) + else: + T.Commands.pop(Index) + return T, CmdSumDict, CmdTargetDict, CmdCppDict + + def CheckCCCmd(self, CommandList): + for cmd in CommandList: + if '$(CC)' in cmd: + return True + return False ## 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 @@ -996,7 +1115,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 @@ -1032,23 +1151,21 @@ cleanlib: else: try: 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 = str(FileContent, encoding="utf-16") - IncludedFileList = gIncludePattern.findall(FileContent) - else: - try: - FileContent = str(FileContent, encoding="utf-8") - IncludedFileList = gIncludePattern.findall(FileContent) - except: - continue + 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: Inc = Inc.strip() @@ -1097,7 +1214,7 @@ cleanlib: DependencySet.update(ForceList) if File in DependencySet: DependencySet.remove(File) - DependencyList = sorted(DependencySet, key=lambda x: str(x)) # remove duplicate ones + DependencyList = list(DependencySet) # remove duplicate ones return DependencyList @@ -1481,7 +1598,7 @@ 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 @@ -1524,13 +1641,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('\\', '\\\\'))) @@ -1621,7 +1734,7 @@ 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