## @file\r
# Create makefile for MS nmake and GNU make\r
#\r
-# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.<BR>\r
# SPDX-License-Identifier: BSD-2-Clause-Patent\r
#\r
\r
"EFI_PPI_DEPENDENCY" : gPpiDefinition,\r
}\r
\r
-## default makefile type\r
-gMakeType = ""\r
-if sys.platform == "win32":\r
- gMakeType = "nmake"\r
-else:\r
- gMakeType = "gmake"\r
-\r
+NMAKE_FILETYPE = "nmake"\r
+GMAKE_FILETYPE = "gmake"\r
+WIN32_PLATFORM = "win32"\r
+POSIX_PLATFORM = "posix"\r
\r
## BuildFile class\r
#\r
\r
## default file name for each type of build file\r
_FILE_NAME_ = {\r
- "nmake" : "Makefile",\r
- "gmake" : "GNUmakefile"\r
+ NMAKE_FILETYPE : "Makefile",\r
+ GMAKE_FILETYPE : "GNUmakefile"\r
}\r
\r
+ # Get Makefile name.\r
+ def getMakefileName(self):\r
+ if not self._FileType:\r
+ return self._DEFAULT_FILE_NAME_\r
+ else:\r
+ return self._FILE_NAME_[self._FileType]\r
+\r
## Fixed header string for makefile\r
_MAKEFILE_HEADER = '''#\r
# DO NOT EDIT\r
\r
## Header string for each type of build file\r
_FILE_HEADER_ = {\r
- "nmake" : _MAKEFILE_HEADER % _FILE_NAME_["nmake"],\r
- "gmake" : _MAKEFILE_HEADER % _FILE_NAME_["gmake"]\r
+ NMAKE_FILETYPE : _MAKEFILE_HEADER % _FILE_NAME_[NMAKE_FILETYPE],\r
+ GMAKE_FILETYPE : _MAKEFILE_HEADER % _FILE_NAME_[GMAKE_FILETYPE]\r
}\r
\r
## shell commands which can be used in build file in the form of macro\r
# $(RD) remove dir command\r
#\r
_SHELL_CMD_ = {\r
- "nmake" : {\r
+ WIN32_PLATFORM : {\r
"CP" : "copy /y",\r
"MV" : "move /y",\r
"RM" : "del /f /q",\r
"RD" : "rmdir /s /q",\r
},\r
\r
- "gmake" : {\r
- "CP" : "cp -f",\r
+ POSIX_PLATFORM : {\r
+ "CP" : "cp -p -f",\r
"MV" : "mv -f",\r
"RM" : "rm -f",\r
"MD" : "mkdir -p",\r
\r
## directory separator\r
_SEP_ = {\r
- "nmake" : "\\",\r
- "gmake" : "/"\r
+ WIN32_PLATFORM : "\\",\r
+ POSIX_PLATFORM : "/"\r
}\r
\r
## directory creation template\r
_MD_TEMPLATE_ = {\r
- "nmake" : 'if not exist %(dir)s $(MD) %(dir)s',\r
- "gmake" : "$(MD) %(dir)s"\r
+ WIN32_PLATFORM : 'if not exist %(dir)s $(MD) %(dir)s',\r
+ POSIX_PLATFORM : "$(MD) %(dir)s"\r
}\r
\r
## directory removal template\r
_RD_TEMPLATE_ = {\r
- "nmake" : 'if exist %(dir)s $(RD) %(dir)s',\r
- "gmake" : "$(RD) %(dir)s"\r
+ WIN32_PLATFORM : 'if exist %(dir)s $(RD) %(dir)s',\r
+ POSIX_PLATFORM : "$(RD) %(dir)s"\r
}\r
## cp if exist\r
_CP_TEMPLATE_ = {\r
- "nmake" : 'if exist %(Src)s $(CP) %(Src)s %(Dst)s',\r
- "gmake" : "test -f %(Src)s && $(CP) %(Src)s %(Dst)s"\r
+ WIN32_PLATFORM : 'if exist %(Src)s $(CP) %(Src)s %(Dst)s',\r
+ POSIX_PLATFORM : "test -f %(Src)s && $(CP) %(Src)s %(Dst)s"\r
}\r
\r
_CD_TEMPLATE_ = {\r
- "nmake" : 'if exist %(dir)s cd %(dir)s',\r
- "gmake" : "test -e %(dir)s && cd %(dir)s"\r
+ WIN32_PLATFORM : 'if exist %(dir)s cd %(dir)s',\r
+ POSIX_PLATFORM : "test -e %(dir)s && cd %(dir)s"\r
}\r
\r
_MAKE_TEMPLATE_ = {\r
- "nmake" : 'if exist %(file)s "$(MAKE)" $(MAKE_FLAGS) -f %(file)s',\r
- "gmake" : 'test -e %(file)s && "$(MAKE)" $(MAKE_FLAGS) -f %(file)s'\r
+ WIN32_PLATFORM : 'if exist %(file)s "$(MAKE)" $(MAKE_FLAGS) -f %(file)s',\r
+ POSIX_PLATFORM : 'test -e %(file)s && "$(MAKE)" $(MAKE_FLAGS) -f %(file)s'\r
}\r
\r
_INCLUDE_CMD_ = {\r
- "nmake" : '!INCLUDE',\r
- "gmake" : "include"\r
+ NMAKE_FILETYPE : '!INCLUDE',\r
+ GMAKE_FILETYPE : "include"\r
}\r
\r
- _INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", "RVCT" : "-I", "NASM" : "-I"}\r
+ _INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", "NASM" : "-I"}\r
\r
## Constructor of BuildFile\r
#\r
#\r
def __init__(self, AutoGenObject):\r
self._AutoGenObject = AutoGenObject\r
- self._FileType = gMakeType\r
\r
- ## Create build file\r
+ MakePath = AutoGenObject.BuildOption.get('MAKE', {}).get('PATH')\r
+ if not MakePath:\r
+ MakePath = AutoGenObject.ToolDefinition.get('MAKE', {}).get('PATH')\r
+ if "nmake" in MakePath:\r
+ self._FileType = NMAKE_FILETYPE\r
+ else:\r
+ self._FileType = GMAKE_FILETYPE\r
+\r
+ if sys.platform == "win32":\r
+ self._Platform = WIN32_PLATFORM\r
+ else:\r
+ self._Platform = POSIX_PLATFORM\r
+\r
+ ## Create build file.\r
#\r
- # @param FileType Type of build file. Only nmake and gmake are supported now.\r
+ # Only nmake and gmake are supported.\r
#\r
- # @retval TRUE The build file is created or re-created successfully\r
- # @retval FALSE The build file exists and is the same as the one to be generated\r
+ # @retval TRUE The build file is created or re-created successfully.\r
+ # @retval FALSE The build file exists and is the same as the one to be generated.\r
#\r
- def Generate(self, FileType=gMakeType):\r
- if FileType not in self._FILE_NAME_:\r
- EdkLogger.error("build", PARAMETER_INVALID, "Invalid build type [%s]" % FileType,\r
- ExtraData="[%s]" % str(self._AutoGenObject))\r
- self._FileType = FileType\r
+ def Generate(self):\r
FileContent = self._TEMPLATE_.Replace(self._TemplateDict)\r
- FileName = self._FILE_NAME_[FileType]\r
+ FileName = self.getMakefileName()\r
+ if not os.path.exists(os.path.join(self._AutoGenObject.MakeFileDir, "deps.txt")):\r
+ with open(os.path.join(self._AutoGenObject.MakeFileDir, "deps.txt"),"w+") as fd:\r
+ fd.write("")\r
+ if not os.path.exists(os.path.join(self._AutoGenObject.MakeFileDir, "dependency")):\r
+ with open(os.path.join(self._AutoGenObject.MakeFileDir, "dependency"),"w+") as fd:\r
+ fd.write("")\r
+ if not os.path.exists(os.path.join(self._AutoGenObject.MakeFileDir, "deps_target")):\r
+ with open(os.path.join(self._AutoGenObject.MakeFileDir, "deps_target"),"w+") as fd:\r
+ fd.write("")\r
return SaveFileOnChange(os.path.join(self._AutoGenObject.MakeFileDir, FileName), FileContent, False)\r
\r
## Return a list of directory creation command string\r
# @retval list The directory creation command list\r
#\r
def GetCreateDirectoryCommand(self, DirList):\r
- return [self._MD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]\r
+ return [self._MD_TEMPLATE_[self._Platform] % {'dir':Dir} for Dir in DirList]\r
\r
## Return a list of directory removal command string\r
#\r
# @retval list The directory removal command list\r
#\r
def GetRemoveDirectoryCommand(self, DirList):\r
- return [self._RD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]\r
+ return [self._RD_TEMPLATE_[self._Platform] % {'dir':Dir} for Dir in DirList]\r
\r
def PlaceMacro(self, Path, MacroDefinitions=None):\r
if Path.startswith("$("):\r
${BEGIN}${file_macro}\r
${END}\r
\r
-COMMON_DEPS = ${BEGIN}${common_dependency_file} \\\r
- ${END}\r
-\r
#\r
# Overridable Target Macro Definitions\r
#\r
\t@"$(MAKE)" $(MAKE_FLAGS) -f $(BUILD_DIR)${separator}${makefile_name} fds\r
\t@cd $(MODULE_BUILD_DIR)\r
\r
+${INCLUDETAG}\r
+\r
#\r
# Individual Object Build Targets\r
#\r
# Compose a dict object containing information used to do replacement in template\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
MyAgo = self._AutoGenObject\r
- Separator = self._SEP_[self._FileType]\r
+ Separator = self._SEP_[self._Platform]\r
\r
# break build if no source files and binary files are found\r
if len(MyAgo.SourceFileList) == 0 and len(MyAgo.BinaryFileList) == 0:\r
# tools definitions\r
ToolsDef = []\r
IncPrefix = self._INC_FLAG_[MyAgo.ToolChainFamily]\r
- for Tool in MyAgo.BuildOption:\r
- for Attr in MyAgo.BuildOption[Tool]:\r
+ for Tool in sorted(list(MyAgo.BuildOption)):\r
+ Appended = False\r
+ for Attr in sorted(list(MyAgo.BuildOption[Tool])):\r
Value = MyAgo.BuildOption[Tool][Attr]\r
if Attr == "FAMILY":\r
continue\r
elif Attr == "PATH":\r
ToolsDef.append("%s = %s" % (Tool, Value))\r
+ Appended = True\r
else:\r
# Don't generate MAKE_FLAGS in makefile. It's put in environment variable.\r
if Tool == "MAKE":\r
# Remove duplicated include path, if any\r
if Attr == "FLAGS":\r
Value = RemoveDupOption(Value, IncPrefix, MyAgo.IncludePathList)\r
- if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and Tool == 'CC' and '/GM' in Value:\r
- Value = Value.replace(' /MP', '')\r
- MyAgo.BuildOption[Tool][Attr] = Value\r
if Tool == "OPTROM" and PCI_COMPRESS_Flag:\r
ValueList = Value.split()\r
if ValueList:\r
Value = ' '.join(ValueList)\r
\r
ToolsDef.append("%s_%s = %s" % (Tool, Attr, Value))\r
- ToolsDef.append("")\r
+ Appended = True\r
+ if Appended:\r
+ ToolsDef.append("")\r
\r
# generate the Response file and Response flag\r
RespDict = self.CommandExceedLimit()\r
UnexpandMacro = []\r
NewStr = []\r
for Str in StrList:\r
- if '$' in Str:\r
+ if '$' in Str or '-MMD' in Str or '-MF' in Str:\r
UnexpandMacro.append(Str)\r
else:\r
NewStr.append(Str)\r
EdkLogger.error("build", AUTOGEN_ERROR, "Nothing to build",\r
ExtraData="[%s]" % str(MyAgo))\r
\r
- self.ProcessBuildTargetList()\r
+ self.ProcessBuildTargetList(MyAgo.OutputDir, ToolsDef)\r
self.ParserGenerateFfsCmd()\r
\r
# Generate macros used to represent input files\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
+ IncludePathList = []\r
+ asmsource = [item for item in MyAgo.SourceFileList if item.File.upper().endswith((".NASM",".ASM",".NASMB","S"))]\r
+ if asmsource:\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
+ # When compiling .nasm files, need to add a literal backslash at each path.\r
+ # In nmake makfiles, a trailing literal backslash must be escaped with a caret ('^').\r
+ # It is otherwise replaced with a space (' '). This is not necessary for GNU makfefiles.\r
+ if P == MyAgo.IncludePathList[-1] and self._Platform == WIN32_PLATFORM and self._FileType == NMAKE_FILETYPE:\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
\r
BcTargetList = []\r
\r
- MakefileName = self._FILE_NAME_[self._FileType]\r
+ MakefileName = self.getMakefileName()\r
LibraryMakeCommandList = []\r
for D in self.LibraryBuildDirectoryList:\r
- Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":os.path.join(D, MakefileName)}\r
+ Command = self._MAKE_TEMPLATE_[self._Platform] % {"file":os.path.join(D, MakefileName)}\r
LibraryMakeCommandList.append(Command)\r
\r
package_rel_dir = MyAgo.SourceDir\r
"separator" : Separator,\r
"module_tool_definitions" : ToolsDef,\r
\r
- "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),\r
- "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),\r
+ "shell_command_code" : list(self._SHELL_CMD_[self._Platform].keys()),\r
+ "shell_command" : list(self._SHELL_CMD_[self._Platform].values()),\r
\r
"module_entry_point" : ModuleEntryPoint,\r
"image_entry_point" : ImageEntryPoint,\r
"file_macro" : FileMacroList,\r
"file_build_target" : self.BuildTargetList,\r
"backward_compatible_target": BcTargetList,\r
+ "INCLUDETAG" : "\n".join([self._INCLUDE_CMD_[self._FileType] + " " + os.path.join("$(MODULE_BUILD_DIR)","dependency"),\r
+ self._INCLUDE_CMD_[self._FileType] + " " + os.path.join("$(MODULE_BUILD_DIR)","deps_target")\r
+ ])\r
}\r
\r
return MakefileTemplateDict\r
if Dst not in self.ResultFileList:\r
self.ResultFileList.append(Dst)\r
if '%s :' %(Dst) not in self.BuildTargetList:\r
- self.BuildTargetList.append("%s :" %(Dst))\r
- self.BuildTargetList.append('\t' + self._CP_TEMPLATE_[self._FileType] %{'Src': Src, 'Dst': Dst})\r
+ self.BuildTargetList.append("%s : %s" %(Dst,Src))\r
+ self.BuildTargetList.append('\t' + self._CP_TEMPLATE_[self._Platform] %{'Src': Src, 'Dst': Dst})\r
\r
FfsCmdList = Cmd[0]\r
for index, Str in enumerate(FfsCmdList):\r
\r
def ReplaceMacro(self, str):\r
for Macro in self.MacroList:\r
- if self._AutoGenObject.Macros[Macro] and self._AutoGenObject.Macros[Macro] in str:\r
- str = str.replace(self._AutoGenObject.Macros[Macro], '$(' + Macro + ')')\r
+ if self._AutoGenObject.Macros[Macro] and os.path.normcase(self._AutoGenObject.Macros[Macro]) in os.path.normcase(str):\r
+ replace_dir = str[os.path.normcase(str).index(os.path.normcase(self._AutoGenObject.Macros[Macro])): os.path.normcase(str).index(\r
+ os.path.normcase(self._AutoGenObject.Macros[Macro])) + len(self._AutoGenObject.Macros[Macro])]\r
+ str = str.replace(replace_dir, '$(' + Macro + ')')\r
return str\r
\r
def CommandExceedLimit(self):\r
BuildTargets[Target].Commands[i] = SingleCommand.replace('$(INC)', '').replace(FlagDict[Flag]['Macro'], RespMacro)\r
return RespDict\r
\r
- def ProcessBuildTargetList(self):\r
+ def ProcessBuildTargetList(self, RespFile, ToolsDef):\r
#\r
# Search dependency file list for each source file\r
#\r
if Item in SourceFileList:\r
SourceFileList.remove(Item)\r
\r
- FileDependencyDict = self.GetFileDependency(\r
- SourceFileList,\r
- ForceIncludedFile,\r
- self._AutoGenObject.IncludePathList + self._AutoGenObject.BuildOptionIncPathList\r
- )\r
+ FileDependencyDict = {item:ForceIncludedFile for item in SourceFileList}\r
\r
-\r
- if FileDependencyDict:\r
- for Dependency in FileDependencyDict.values():\r
- self.DependencyHeaderFileSet.update(set(Dependency))\r
+ for Dependency in FileDependencyDict.values():\r
+ self.DependencyHeaderFileSet.update(set(Dependency))\r
\r
# Get a set of unique package includes from MetaFile\r
parentMetaFileIncludes = set()\r
ExtraData = "Local Header: " + aFile + " not found in " + self._AutoGenObject.MetaFile.Path\r
)\r
\r
- DepSet = None\r
for File,Dependency in FileDependencyDict.items():\r
if not Dependency:\r
- FileDependencyDict[File] = ['$(FORCE_REBUILD)']\r
continue\r
\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(Dependency)\r
- else:\r
- DepSet &= set(Dependency)\r
- # in case nothing in SourceFileList\r
- if DepSet is None:\r
- DepSet = set()\r
- #\r
- # Extract common files list in the dependency files\r
- #\r
- for File in DepSet:\r
- self.CommonFileDependency.append(self.PlaceMacro(File.Path, self.Macros))\r
-\r
CmdSumDict = {}\r
CmdTargetDict = {}\r
CmdCppDict = {}\r
DependencyDict = FileDependencyDict.copy()\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(FileDependencyDict[File])\r
- NewDepSet -= DepSet\r
- FileDependencyDict[File] = ["$(COMMON_DEPS)"] + list(NewDepSet)\r
- DependencyDict[File] = list(NewDepSet)\r
\r
# Convert target description object to target string in makefile\r
if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and TAB_C_CODE_FILE in self._AutoGenObject.Targets:\r
self.ObjTargetDict[T.Target.SubDir] = set()\r
self.ObjTargetDict[T.Target.SubDir].add(NewFile)\r
for Type in self._AutoGenObject.Targets:\r
+ resp_file_number = 0\r
for T in self._AutoGenObject.Targets[Type]:\r
# Generate related macros if needed\r
if T.GenFileListMacro and T.FileListMacro not in self.FileListMacros:\r
Deps.append("$(%s)" % T.ListFileMacro)\r
\r
if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and Type == TAB_C_CODE_FILE:\r
- T, CmdTarget, CmdTargetDict, CmdCppDict = self.ParserCCodeFile(T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict)\r
+ T, CmdTarget, CmdTargetDict, CmdCppDict = self.ParserCCodeFile(T, Type, CmdSumDict, CmdTargetDict,\r
+ CmdCppDict, DependencyDict, RespFile,\r
+ ToolsDef, resp_file_number)\r
+ resp_file_number += 1\r
TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": CCodeDeps}\r
CmdLine = self._BUILD_TARGET_TEMPLATE.Replace(TargetDict).rstrip().replace('\t$(OBJLIST', '$(OBJLIST')\r
if T.Commands:\r
TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": Deps}\r
self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(TargetDict))\r
\r
- def ParserCCodeFile(self, T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict):\r
+ # Add a Makefile rule for targets generating multiple files.\r
+ # The main output is a prerequisite for the other output files.\r
+ for i in T.Outputs[1:]:\r
+ AnnexeTargetDict = {"target": self.PlaceMacro(i.Path, self.Macros), "cmd": "", "deps": self.PlaceMacro(T.Target.Path, self.Macros)}\r
+ self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(AnnexeTargetDict))\r
+\r
+ def ParserCCodeFile(self, T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict, RespFile, ToolsDef,\r
+ resp_file_number):\r
+ SaveFilePath = os.path.join(RespFile, "cc_resp_%s.txt" % resp_file_number)\r
if not CmdSumDict:\r
for item in self._AutoGenObject.Targets[Type]:\r
CmdSumDict[item.Target.SubDir] = item.Target.BaseName\r
else:\r
CmdCppDict[item.Target.SubDir] = ['$(MAKE_FILE)', Path]\r
if CppPath.Path in DependencyDict:\r
- if '$(FORCE_REBUILD)' in DependencyDict[CppPath.Path]:\r
- if '$(FORCE_REBUILD)' not in (self.CommonFileDependency + CmdCppDict[item.Target.SubDir]):\r
- CmdCppDict[item.Target.SubDir].append('$(FORCE_REBUILD)')\r
- else:\r
- for Temp in DependencyDict[CppPath.Path]:\r
- try:\r
- Path = self.PlaceMacro(Temp.Path, self.Macros)\r
- except:\r
- continue\r
- if Path not in (self.CommonFileDependency + CmdCppDict[item.Target.SubDir]):\r
- CmdCppDict[item.Target.SubDir].append(Path)\r
+ for Temp in DependencyDict[CppPath.Path]:\r
+ try:\r
+ Path = self.PlaceMacro(Temp.Path, self.Macros)\r
+ except:\r
+ continue\r
+ if Path not in (self.CommonFileDependency + CmdCppDict[item.Target.SubDir]):\r
+ CmdCppDict[item.Target.SubDir].append(Path)\r
if T.Commands:\r
CommandList = T.Commands[:]\r
for Item in CommandList[:]:\r
if Temp.startswith('/Fo'):\r
CmdSign = '%s%s' % (Temp.rsplit(TAB_SLASH, 1)[0], TAB_SLASH)\r
break\r
- else: continue\r
+ else:\r
+ continue\r
if CmdSign not in list(CmdTargetDict.keys()):\r
- CmdTargetDict[CmdSign] = Item.replace(Temp, CmdSign)\r
+ cmd = Item.replace(Temp, CmdSign)\r
+ if SingleCommandList[-1] in cmd:\r
+ CmdTargetDict[CmdSign] = [cmd.replace(SingleCommandList[-1], "").rstrip(), SingleCommandList[-1]]\r
else:\r
- CmdTargetDict[CmdSign] = "%s %s" % (CmdTargetDict[CmdSign], SingleCommandList[-1])\r
+ # CmdTargetDict[CmdSign] = "%s %s" % (CmdTargetDict[CmdSign], SingleCommandList[-1])\r
+ CmdTargetDict[CmdSign].append(SingleCommandList[-1])\r
Index = CommandList.index(Item)\r
CommandList.pop(Index)\r
- if SingleCommandList[-1].endswith("%s%s.c" % (TAB_SLASH, CmdSumDict[CmdSign[3:].rsplit(TAB_SLASH, 1)[0]])):\r
+ BaseName = SingleCommandList[-1].rsplit('.',1)[0]\r
+ if BaseName.endswith("%s%s" % (TAB_SLASH, CmdSumDict[CmdSign[3:].rsplit(TAB_SLASH, 1)[0]])):\r
Cpplist = CmdCppDict[T.Target.SubDir]\r
- Cpplist.insert(0, '$(OBJLIST_%d): $(COMMON_DEPS)' % list(self.ObjTargetDict.keys()).index(T.Target.SubDir))\r
- T.Commands[Index] = '%s\n\t%s' % (' \\\n\t'.join(Cpplist), CmdTargetDict[CmdSign])\r
+ Cpplist.insert(0, '$(OBJLIST_%d): ' % list(self.ObjTargetDict.keys()).index(T.Target.SubDir))\r
+ source_files = CmdTargetDict[CmdSign][1:]\r
+ source_files.insert(0, " ")\r
+ if len(source_files)>2:\r
+ SaveFileOnChange(SaveFilePath, " ".join(source_files), False)\r
+ T.Commands[Index] = '%s\n\t%s $(cc_resp_%s)' % (\r
+ ' \\\n\t'.join(Cpplist), CmdTargetDict[CmdSign][0], resp_file_number)\r
+ ToolsDef.append("cc_resp_%s = @%s" % (resp_file_number, SaveFilePath))\r
+\r
+ elif len(source_files)<=2 and len(" ".join(CmdTargetDict[CmdSign][:2]))>GlobalData.gCommandMaxLength:\r
+ SaveFileOnChange(SaveFilePath, " ".join(source_files), False)\r
+ T.Commands[Index] = '%s\n\t%s $(cc_resp_%s)' % (\r
+ ' \\\n\t'.join(Cpplist), CmdTargetDict[CmdSign][0], resp_file_number)\r
+ ToolsDef.append("cc_resp_%s = @%s" % (resp_file_number, SaveFilePath))\r
+\r
+ else:\r
+ T.Commands[Index] = '%s\n\t%s' % (' \\\n\t'.join(Cpplist), " ".join(CmdTargetDict[CmdSign]))\r
else:\r
T.Commands.pop(Index)\r
return T, CmdSumDict, CmdTargetDict, CmdCppDict\r
# Compose a dict object containing information used to do replacement in template\r
@property\r
def _TemplateDict(self):\r
- Separator = self._SEP_[self._FileType]\r
+ Separator = self._SEP_[self._Platform]\r
MyAgo = self._AutoGenObject\r
if self._FileType not in MyAgo.CustomMakefile:\r
EdkLogger.error('build', OPTION_NOT_SUPPORTED, "No custom makefile for %s" % self._FileType,\r
ToolsDef.append("%s_%s = %s" % (Tool, Attr, MyAgo.BuildOption[Tool][Attr]))\r
ToolsDef.append("")\r
\r
- MakefileName = self._FILE_NAME_[self._FileType]\r
+ MakefileName = self.getMakefileName()\r
MakefileTemplateDict = {\r
"makefile_header" : self._FILE_HEADER_[self._FileType],\r
"makefile_path" : os.path.join("$(MODULE_BUILD_DIR)", MakefileName),\r
"separator" : Separator,\r
"module_tool_definitions" : ToolsDef,\r
\r
- "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),\r
- "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),\r
+ "shell_command_code" : list(self._SHELL_CMD_[self._Platform].keys()),\r
+ "shell_command" : list(self._SHELL_CMD_[self._Platform].values()),\r
\r
"create_directory_command" : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList),\r
"custom_makefile_content" : CustomMakefile\r
# Compose a dict object containing information used to do replacement in template\r
@property\r
def _TemplateDict(self):\r
- Separator = self._SEP_[self._FileType]\r
+ Separator = self._SEP_[self._Platform]\r
\r
MyAgo = self._AutoGenObject\r
if "MAKE" not in MyAgo.ToolDefinition or "PATH" not in MyAgo.ToolDefinition["MAKE"]:\r
self.ModuleBuildDirectoryList = self.GetModuleBuildDirectoryList()\r
self.LibraryBuildDirectoryList = self.GetLibraryBuildDirectoryList()\r
\r
- MakefileName = self._FILE_NAME_[self._FileType]\r
+ MakefileName = self.getMakefileName()\r
LibraryMakefileList = []\r
LibraryMakeCommandList = []\r
for D in self.LibraryBuildDirectoryList:\r
D = self.PlaceMacro(D, {"BUILD_DIR":MyAgo.BuildDir})\r
Makefile = os.path.join(D, MakefileName)\r
- Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":Makefile}\r
+ Command = self._MAKE_TEMPLATE_[self._Platform] % {"file":Makefile}\r
LibraryMakefileList.append(Makefile)\r
LibraryMakeCommandList.append(Command)\r
self.LibraryMakeCommandList = LibraryMakeCommandList\r
for D in self.ModuleBuildDirectoryList:\r
D = self.PlaceMacro(D, {"BUILD_DIR":MyAgo.BuildDir})\r
Makefile = os.path.join(D, MakefileName)\r
- Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":Makefile}\r
+ Command = self._MAKE_TEMPLATE_[self._Platform] % {"file":Makefile}\r
ModuleMakefileList.append(Makefile)\r
ModuleMakeCommandList.append(Command)\r
\r
\r
"toolchain_tag" : MyAgo.ToolChain,\r
"build_target" : MyAgo.BuildTarget,\r
- "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),\r
- "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),\r
+ "shell_command_code" : list(self._SHELL_CMD_[self._Platform].keys()),\r
+ "shell_command" : list(self._SHELL_CMD_[self._Platform].values()),\r
"build_architecture_list" : MyAgo.Arch,\r
"architecture" : MyAgo.Arch,\r
"separator" : Separator,\r
# Compose a dict object containing information used to do replacement in template\r
@property\r
def _TemplateDict(self):\r
- Separator = self._SEP_[self._FileType]\r
+ Separator = self._SEP_[self._Platform]\r
\r
# any platform autogen object is ok because we just need common information\r
MyAgo = self._AutoGenObject\r
else:\r
ExtraOption += " --pcd " + pcdname + '=' + pcd[3]\r
\r
- MakefileName = self._FILE_NAME_[self._FileType]\r
+ MakefileName = self.getMakefileName()\r
SubBuildCommandList = []\r
for A in MyAgo.ArchList:\r
- Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":os.path.join("$(BUILD_DIR)", A, MakefileName)}\r
+ Command = self._MAKE_TEMPLATE_[self._Platform] % {"file":os.path.join("$(BUILD_DIR)", A, MakefileName)}\r
SubBuildCommandList.append(Command)\r
\r
MakefileTemplateDict = {\r
\r
"toolchain_tag" : MyAgo.ToolChain,\r
"build_target" : MyAgo.BuildTarget,\r
- "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),\r
- "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),\r
+ "shell_command_code" : list(self._SHELL_CMD_[self._Platform].keys()),\r
+ "shell_command" : list(self._SHELL_CMD_[self._Platform].values()),\r
'arch' : list(MyAgo.ArchList),\r
"build_architecture_list" : ','.join(MyAgo.ArchList),\r
"separator" : Separator,\r