]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/AutoGen/GenMake.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenMake.py
... / ...
CommitLineData
1## @file\r
2# Create makefile for MS nmake and GNU make\r
3#\r
4# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
5# SPDX-License-Identifier: BSD-2-Clause-Patent\r
6#\r
7\r
8## Import Modules\r
9#\r
10from __future__ import absolute_import\r
11import Common.LongFilePathOs as os\r
12import sys\r
13import string\r
14import re\r
15import os.path as path\r
16from Common.LongFilePathSupport import OpenLongFilePath as open\r
17from Common.MultipleWorkspace import MultipleWorkspace as mws\r
18from Common.BuildToolError import *\r
19from Common.Misc import *\r
20from Common.StringUtils import *\r
21from .BuildEngine import *\r
22import Common.GlobalData as GlobalData\r
23from collections import OrderedDict\r
24from Common.DataType import TAB_COMPILER_MSFT\r
25\r
26## Regular expression for finding header file inclusions\r
27gIncludePattern = re.compile(r"^[ \t]*[#%]?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() \t]+)(?:[ \t]*[\">]?\)?)", re.MULTILINE | re.UNICODE | re.IGNORECASE)\r
28\r
29## Regular expression for matching macro used in header file inclusion\r
30gMacroPattern = re.compile("([_A-Z][_A-Z0-9]*)[ \t]*\((.+)\)", re.UNICODE)\r
31\r
32gIsFileMap = {}\r
33\r
34## pattern for include style in Edk.x code\r
35gProtocolDefinition = "Protocol/%(HeaderKey)s/%(HeaderKey)s.h"\r
36gGuidDefinition = "Guid/%(HeaderKey)s/%(HeaderKey)s.h"\r
37gArchProtocolDefinition = "ArchProtocol/%(HeaderKey)s/%(HeaderKey)s.h"\r
38gPpiDefinition = "Ppi/%(HeaderKey)s/%(HeaderKey)s.h"\r
39gIncludeMacroConversion = {\r
40 "EFI_PROTOCOL_DEFINITION" : gProtocolDefinition,\r
41 "EFI_GUID_DEFINITION" : gGuidDefinition,\r
42 "EFI_ARCH_PROTOCOL_DEFINITION" : gArchProtocolDefinition,\r
43 "EFI_PROTOCOL_PRODUCER" : gProtocolDefinition,\r
44 "EFI_PROTOCOL_CONSUMER" : gProtocolDefinition,\r
45 "EFI_PROTOCOL_DEPENDENCY" : gProtocolDefinition,\r
46 "EFI_ARCH_PROTOCOL_PRODUCER" : gArchProtocolDefinition,\r
47 "EFI_ARCH_PROTOCOL_CONSUMER" : gArchProtocolDefinition,\r
48 "EFI_ARCH_PROTOCOL_DEPENDENCY" : gArchProtocolDefinition,\r
49 "EFI_PPI_DEFINITION" : gPpiDefinition,\r
50 "EFI_PPI_PRODUCER" : gPpiDefinition,\r
51 "EFI_PPI_CONSUMER" : gPpiDefinition,\r
52 "EFI_PPI_DEPENDENCY" : gPpiDefinition,\r
53}\r
54\r
55## default makefile type\r
56gMakeType = ""\r
57if sys.platform == "win32":\r
58 gMakeType = "nmake"\r
59else:\r
60 gMakeType = "gmake"\r
61\r
62\r
63## BuildFile class\r
64#\r
65# This base class encapsules build file and its generation. It uses template to generate\r
66# the content of build file. The content of build file will be got from AutoGen objects.\r
67#\r
68class BuildFile(object):\r
69 ## template used to generate the build file (i.e. makefile if using make)\r
70 _TEMPLATE_ = TemplateString('')\r
71\r
72 _DEFAULT_FILE_NAME_ = "Makefile"\r
73\r
74 ## default file name for each type of build file\r
75 _FILE_NAME_ = {\r
76 "nmake" : "Makefile",\r
77 "gmake" : "GNUmakefile"\r
78 }\r
79\r
80 ## Fixed header string for makefile\r
81 _MAKEFILE_HEADER = '''#\r
82# DO NOT EDIT\r
83# This file is auto-generated by build utility\r
84#\r
85# Module Name:\r
86#\r
87# %s\r
88#\r
89# Abstract:\r
90#\r
91# Auto-generated makefile for building modules, libraries or platform\r
92#\r
93 '''\r
94\r
95 ## Header string for each type of build file\r
96 _FILE_HEADER_ = {\r
97 "nmake" : _MAKEFILE_HEADER % _FILE_NAME_["nmake"],\r
98 "gmake" : _MAKEFILE_HEADER % _FILE_NAME_["gmake"]\r
99 }\r
100\r
101 ## shell commands which can be used in build file in the form of macro\r
102 # $(CP) copy file command\r
103 # $(MV) move file command\r
104 # $(RM) remove file command\r
105 # $(MD) create dir command\r
106 # $(RD) remove dir command\r
107 #\r
108 _SHELL_CMD_ = {\r
109 "nmake" : {\r
110 "CP" : "copy /y",\r
111 "MV" : "move /y",\r
112 "RM" : "del /f /q",\r
113 "MD" : "mkdir",\r
114 "RD" : "rmdir /s /q",\r
115 },\r
116\r
117 "gmake" : {\r
118 "CP" : "cp -f",\r
119 "MV" : "mv -f",\r
120 "RM" : "rm -f",\r
121 "MD" : "mkdir -p",\r
122 "RD" : "rm -r -f",\r
123 }\r
124 }\r
125\r
126 ## directory separator\r
127 _SEP_ = {\r
128 "nmake" : "\\",\r
129 "gmake" : "/"\r
130 }\r
131\r
132 ## directory creation template\r
133 _MD_TEMPLATE_ = {\r
134 "nmake" : 'if not exist %(dir)s $(MD) %(dir)s',\r
135 "gmake" : "$(MD) %(dir)s"\r
136 }\r
137\r
138 ## directory removal template\r
139 _RD_TEMPLATE_ = {\r
140 "nmake" : 'if exist %(dir)s $(RD) %(dir)s',\r
141 "gmake" : "$(RD) %(dir)s"\r
142 }\r
143 ## cp if exist\r
144 _CP_TEMPLATE_ = {\r
145 "nmake" : 'if exist %(Src)s $(CP) %(Src)s %(Dst)s',\r
146 "gmake" : "test -f %(Src)s && $(CP) %(Src)s %(Dst)s"\r
147 }\r
148\r
149 _CD_TEMPLATE_ = {\r
150 "nmake" : 'if exist %(dir)s cd %(dir)s',\r
151 "gmake" : "test -e %(dir)s && cd %(dir)s"\r
152 }\r
153\r
154 _MAKE_TEMPLATE_ = {\r
155 "nmake" : 'if exist %(file)s "$(MAKE)" $(MAKE_FLAGS) -f %(file)s',\r
156 "gmake" : 'test -e %(file)s && "$(MAKE)" $(MAKE_FLAGS) -f %(file)s'\r
157 }\r
158\r
159 _INCLUDE_CMD_ = {\r
160 "nmake" : '!INCLUDE',\r
161 "gmake" : "include"\r
162 }\r
163\r
164 _INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", "RVCT" : "-I", "NASM" : "-I"}\r
165\r
166 ## Constructor of BuildFile\r
167 #\r
168 # @param AutoGenObject Object of AutoGen class\r
169 #\r
170 def __init__(self, AutoGenObject):\r
171 self._AutoGenObject = AutoGenObject\r
172 self._FileType = gMakeType\r
173\r
174 ## Create build file\r
175 #\r
176 # @param FileType Type of build file. Only nmake and gmake are supported now.\r
177 #\r
178 # @retval TRUE The build file is created or re-created successfully\r
179 # @retval FALSE The build file exists and is the same as the one to be generated\r
180 #\r
181 def Generate(self, FileType=gMakeType):\r
182 if FileType not in self._FILE_NAME_:\r
183 EdkLogger.error("build", PARAMETER_INVALID, "Invalid build type [%s]" % FileType,\r
184 ExtraData="[%s]" % str(self._AutoGenObject))\r
185 self._FileType = FileType\r
186 FileContent = self._TEMPLATE_.Replace(self._TemplateDict)\r
187 FileName = self._FILE_NAME_[FileType]\r
188 return SaveFileOnChange(os.path.join(self._AutoGenObject.MakeFileDir, FileName), FileContent, False)\r
189\r
190 ## Return a list of directory creation command string\r
191 #\r
192 # @param DirList The list of directory to be created\r
193 #\r
194 # @retval list The directory creation command list\r
195 #\r
196 def GetCreateDirectoryCommand(self, DirList):\r
197 return [self._MD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]\r
198\r
199 ## Return a list of directory removal command string\r
200 #\r
201 # @param DirList The list of directory to be removed\r
202 #\r
203 # @retval list The directory removal command list\r
204 #\r
205 def GetRemoveDirectoryCommand(self, DirList):\r
206 return [self._RD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]\r
207\r
208 def PlaceMacro(self, Path, MacroDefinitions={}):\r
209 if Path.startswith("$("):\r
210 return Path\r
211 else:\r
212 PathLength = len(Path)\r
213 for MacroName in MacroDefinitions:\r
214 MacroValue = MacroDefinitions[MacroName]\r
215 MacroValueLength = len(MacroValue)\r
216 if MacroValueLength == 0:\r
217 continue\r
218 if MacroValueLength <= PathLength and Path.startswith(MacroValue):\r
219 Path = "$(%s)%s" % (MacroName, Path[MacroValueLength:])\r
220 break\r
221 return Path\r
222\r
223## ModuleMakefile class\r
224#\r
225# This class encapsules makefie and its generation for module. It uses template to generate\r
226# the content of makefile. The content of makefile will be got from ModuleAutoGen object.\r
227#\r
228class ModuleMakefile(BuildFile):\r
229 ## template used to generate the makefile for module\r
230 _TEMPLATE_ = TemplateString('''\\r
231${makefile_header}\r
232\r
233#\r
234# Platform Macro Definition\r
235#\r
236PLATFORM_NAME = ${platform_name}\r
237PLATFORM_GUID = ${platform_guid}\r
238PLATFORM_VERSION = ${platform_version}\r
239PLATFORM_RELATIVE_DIR = ${platform_relative_directory}\r
240PLATFORM_DIR = ${platform_dir}\r
241PLATFORM_OUTPUT_DIR = ${platform_output_directory}\r
242\r
243#\r
244# Module Macro Definition\r
245#\r
246MODULE_NAME = ${module_name}\r
247MODULE_GUID = ${module_guid}\r
248MODULE_NAME_GUID = ${module_name_guid}\r
249MODULE_VERSION = ${module_version}\r
250MODULE_TYPE = ${module_type}\r
251MODULE_FILE = ${module_file}\r
252MODULE_FILE_BASE_NAME = ${module_file_base_name}\r
253BASE_NAME = $(MODULE_NAME)\r
254MODULE_RELATIVE_DIR = ${module_relative_directory}\r
255PACKAGE_RELATIVE_DIR = ${package_relative_directory}\r
256MODULE_DIR = ${module_dir}\r
257FFS_OUTPUT_DIR = ${ffs_output_directory}\r
258\r
259MODULE_ENTRY_POINT = ${module_entry_point}\r
260ARCH_ENTRY_POINT = ${arch_entry_point}\r
261IMAGE_ENTRY_POINT = ${image_entry_point}\r
262\r
263${BEGIN}${module_extra_defines}\r
264${END}\r
265#\r
266# Build Configuration Macro Definition\r
267#\r
268ARCH = ${architecture}\r
269TOOLCHAIN = ${toolchain_tag}\r
270TOOLCHAIN_TAG = ${toolchain_tag}\r
271TARGET = ${build_target}\r
272\r
273#\r
274# Build Directory Macro Definition\r
275#\r
276# PLATFORM_BUILD_DIR = ${platform_build_directory}\r
277BUILD_DIR = ${platform_build_directory}\r
278BIN_DIR = $(BUILD_DIR)${separator}${architecture}\r
279LIB_DIR = $(BIN_DIR)\r
280MODULE_BUILD_DIR = ${module_build_directory}\r
281OUTPUT_DIR = ${module_output_directory}\r
282DEBUG_DIR = ${module_debug_directory}\r
283DEST_DIR_OUTPUT = $(OUTPUT_DIR)\r
284DEST_DIR_DEBUG = $(DEBUG_DIR)\r
285\r
286#\r
287# Shell Command Macro\r
288#\r
289${BEGIN}${shell_command_code} = ${shell_command}\r
290${END}\r
291\r
292#\r
293# Tools definitions specific to this module\r
294#\r
295${BEGIN}${module_tool_definitions}\r
296${END}\r
297MAKE_FILE = ${makefile_path}\r
298\r
299#\r
300# Build Macro\r
301#\r
302${BEGIN}${file_macro}\r
303${END}\r
304\r
305COMMON_DEPS = ${BEGIN}${common_dependency_file} \\\r
306 ${END}\r
307\r
308#\r
309# Overridable Target Macro Definitions\r
310#\r
311FORCE_REBUILD = force_build\r
312INIT_TARGET = init\r
313PCH_TARGET =\r
314BC_TARGET = ${BEGIN}${backward_compatible_target} ${END}\r
315CODA_TARGET = ${BEGIN}${remaining_build_target} \\\r
316 ${END}\r
317\r
318#\r
319# Default target, which will build dependent libraries in addition to source files\r
320#\r
321\r
322all: mbuild\r
323\r
324\r
325#\r
326# Target used when called from platform makefile, which will bypass the build of dependent libraries\r
327#\r
328\r
329pbuild: $(INIT_TARGET) $(BC_TARGET) $(PCH_TARGET) $(CODA_TARGET)\r
330\r
331#\r
332# ModuleTarget\r
333#\r
334\r
335mbuild: $(INIT_TARGET) $(BC_TARGET) gen_libs $(PCH_TARGET) $(CODA_TARGET)\r
336\r
337#\r
338# Build Target used in multi-thread build mode, which will bypass the init and gen_libs targets\r
339#\r
340\r
341tbuild: $(BC_TARGET) $(PCH_TARGET) $(CODA_TARGET)\r
342\r
343#\r
344# Phony target which is used to force executing commands for a target\r
345#\r
346force_build:\r
347\t-@\r
348\r
349#\r
350# Target to update the FD\r
351#\r
352\r
353fds: mbuild gen_fds\r
354\r
355#\r
356# Initialization target: print build information and create necessary directories\r
357#\r
358init: info dirs\r
359\r
360info:\r
361\t-@echo Building ... $(MODULE_DIR)${separator}$(MODULE_FILE) [$(ARCH)]\r
362\r
363dirs:\r
364${BEGIN}\t-@${create_directory_command}\n${END}\r
365\r
366strdefs:\r
367\t-@$(CP) $(DEBUG_DIR)${separator}AutoGen.h $(DEBUG_DIR)${separator}$(MODULE_NAME)StrDefs.h\r
368\r
369#\r
370# GenLibsTarget\r
371#\r
372gen_libs:\r
373\t${BEGIN}@"$(MAKE)" $(MAKE_FLAGS) -f ${dependent_library_build_directory}${separator}${makefile_name}\r
374\t${END}@cd $(MODULE_BUILD_DIR)\r
375\r
376#\r
377# Build Flash Device Image\r
378#\r
379gen_fds:\r
380\t@"$(MAKE)" $(MAKE_FLAGS) -f $(BUILD_DIR)${separator}${makefile_name} fds\r
381\t@cd $(MODULE_BUILD_DIR)\r
382\r
383#\r
384# Individual Object Build Targets\r
385#\r
386${BEGIN}${file_build_target}\r
387${END}\r
388\r
389#\r
390# clean all intermediate files\r
391#\r
392clean:\r
393\t${BEGIN}${clean_command}\r
394\t${END}\t$(RM) AutoGenTimeStamp\r
395\r
396#\r
397# clean all generated files\r
398#\r
399cleanall:\r
400${BEGIN}\t${cleanall_command}\r
401${END}\t$(RM) *.pdb *.idb > NUL 2>&1\r
402\t$(RM) $(BIN_DIR)${separator}$(MODULE_NAME).efi\r
403\t$(RM) AutoGenTimeStamp\r
404\r
405#\r
406# clean all dependent libraries built\r
407#\r
408cleanlib:\r
409\t${BEGIN}-@${library_build_command} cleanall\r
410\t${END}@cd $(MODULE_BUILD_DIR)\n\n''')\r
411\r
412 _FILE_MACRO_TEMPLATE = TemplateString("${macro_name} = ${BEGIN} \\\n ${source_file}${END}\n")\r
413 _BUILD_TARGET_TEMPLATE = TemplateString("${BEGIN}${target} : ${deps}\n${END}\t${cmd}\n")\r
414\r
415 ## Constructor of ModuleMakefile\r
416 #\r
417 # @param ModuleAutoGen Object of ModuleAutoGen class\r
418 #\r
419 def __init__(self, ModuleAutoGen):\r
420 BuildFile.__init__(self, ModuleAutoGen)\r
421 self.PlatformInfo = self._AutoGenObject.PlatformInfo\r
422\r
423 self.ResultFileList = []\r
424 self.IntermediateDirectoryList = ["$(DEBUG_DIR)", "$(OUTPUT_DIR)"]\r
425\r
426 self.FileBuildTargetList = [] # [(src, target string)]\r
427 self.BuildTargetList = [] # [target string]\r
428 self.PendingBuildTargetList = [] # [FileBuildRule objects]\r
429 self.CommonFileDependency = []\r
430 self.FileListMacros = {}\r
431 self.ListFileMacros = {}\r
432\r
433 self.FileCache = {}\r
434 self.LibraryBuildCommandList = []\r
435 self.LibraryFileList = []\r
436 self.LibraryMakefileList = []\r
437 self.LibraryBuildDirectoryList = []\r
438 self.SystemLibraryList = []\r
439 self.Macros = OrderedDict()\r
440 self.Macros["OUTPUT_DIR" ] = self._AutoGenObject.Macros["OUTPUT_DIR"]\r
441 self.Macros["DEBUG_DIR" ] = self._AutoGenObject.Macros["DEBUG_DIR"]\r
442 self.Macros["MODULE_BUILD_DIR"] = self._AutoGenObject.Macros["MODULE_BUILD_DIR"]\r
443 self.Macros["BIN_DIR" ] = self._AutoGenObject.Macros["BIN_DIR"]\r
444 self.Macros["BUILD_DIR" ] = self._AutoGenObject.Macros["BUILD_DIR"]\r
445 self.Macros["WORKSPACE" ] = self._AutoGenObject.Macros["WORKSPACE"]\r
446 self.Macros["FFS_OUTPUT_DIR" ] = self._AutoGenObject.Macros["FFS_OUTPUT_DIR"]\r
447 self.GenFfsList = ModuleAutoGen.GenFfsList\r
448 self.MacroList = ['FFS_OUTPUT_DIR', 'MODULE_GUID', 'OUTPUT_DIR']\r
449 self.FfsOutputFileList = []\r
450\r
451 # Compose a dict object containing information used to do replacement in template\r
452 @property\r
453 def _TemplateDict(self):\r
454 if self._FileType not in self._SEP_:\r
455 EdkLogger.error("build", PARAMETER_INVALID, "Invalid Makefile type [%s]" % self._FileType,\r
456 ExtraData="[%s]" % str(self._AutoGenObject))\r
457 MyAgo = self._AutoGenObject\r
458 Separator = self._SEP_[self._FileType]\r
459\r
460 # break build if no source files and binary files are found\r
461 if len(MyAgo.SourceFileList) == 0 and len(MyAgo.BinaryFileList) == 0:\r
462 EdkLogger.error("build", AUTOGEN_ERROR, "No files to be built in module [%s, %s, %s]"\r
463 % (MyAgo.BuildTarget, MyAgo.ToolChain, MyAgo.Arch),\r
464 ExtraData="[%s]" % str(MyAgo))\r
465\r
466 # convert dependent libraries to build command\r
467 self.ProcessDependentLibrary()\r
468 if len(MyAgo.Module.ModuleEntryPointList) > 0:\r
469 ModuleEntryPoint = MyAgo.Module.ModuleEntryPointList[0]\r
470 else:\r
471 ModuleEntryPoint = "_ModuleEntryPoint"\r
472\r
473 ArchEntryPoint = ModuleEntryPoint\r
474\r
475 if MyAgo.Arch == "EBC":\r
476 # EBC compiler always use "EfiStart" as entry point. Only applies to EdkII modules\r
477 ImageEntryPoint = "EfiStart"\r
478 else:\r
479 # EdkII modules always use "_ModuleEntryPoint" as entry point\r
480 ImageEntryPoint = "_ModuleEntryPoint"\r
481\r
482 for k, v in MyAgo.Module.Defines.items():\r
483 if k not in MyAgo.Macros:\r
484 MyAgo.Macros[k] = v\r
485\r
486 if 'MODULE_ENTRY_POINT' not in MyAgo.Macros:\r
487 MyAgo.Macros['MODULE_ENTRY_POINT'] = ModuleEntryPoint\r
488 if 'ARCH_ENTRY_POINT' not in MyAgo.Macros:\r
489 MyAgo.Macros['ARCH_ENTRY_POINT'] = ArchEntryPoint\r
490 if 'IMAGE_ENTRY_POINT' not in MyAgo.Macros:\r
491 MyAgo.Macros['IMAGE_ENTRY_POINT'] = ImageEntryPoint\r
492\r
493 PCI_COMPRESS_Flag = False\r
494 for k, v in MyAgo.Module.Defines.items():\r
495 if 'PCI_COMPRESS' == k and 'TRUE' == v:\r
496 PCI_COMPRESS_Flag = True\r
497\r
498 # tools definitions\r
499 ToolsDef = []\r
500 IncPrefix = self._INC_FLAG_[MyAgo.ToolChainFamily]\r
501 for Tool in MyAgo.BuildOption:\r
502 for Attr in MyAgo.BuildOption[Tool]:\r
503 Value = MyAgo.BuildOption[Tool][Attr]\r
504 if Attr == "FAMILY":\r
505 continue\r
506 elif Attr == "PATH":\r
507 ToolsDef.append("%s = %s" % (Tool, Value))\r
508 else:\r
509 # Don't generate MAKE_FLAGS in makefile. It's put in environment variable.\r
510 if Tool == "MAKE":\r
511 continue\r
512 # Remove duplicated include path, if any\r
513 if Attr == "FLAGS":\r
514 Value = RemoveDupOption(Value, IncPrefix, MyAgo.IncludePathList)\r
515 if Tool == "OPTROM" and PCI_COMPRESS_Flag:\r
516 ValueList = Value.split()\r
517 if ValueList:\r
518 for i, v in enumerate(ValueList):\r
519 if '-e' == v:\r
520 ValueList[i] = '-ec'\r
521 Value = ' '.join(ValueList)\r
522\r
523 ToolsDef.append("%s_%s = %s" % (Tool, Attr, Value))\r
524 ToolsDef.append("")\r
525\r
526 # generate the Response file and Response flag\r
527 RespDict = self.CommandExceedLimit()\r
528 RespFileList = os.path.join(MyAgo.OutputDir, 'respfilelist.txt')\r
529 if RespDict:\r
530 RespFileListContent = ''\r
531 for Resp in RespDict:\r
532 RespFile = os.path.join(MyAgo.OutputDir, str(Resp).lower() + '.txt')\r
533 StrList = RespDict[Resp].split(' ')\r
534 UnexpandMacro = []\r
535 NewStr = []\r
536 for Str in StrList:\r
537 if '$' in Str:\r
538 UnexpandMacro.append(Str)\r
539 else:\r
540 NewStr.append(Str)\r
541 UnexpandMacroStr = ' '.join(UnexpandMacro)\r
542 NewRespStr = ' '.join(NewStr)\r
543 SaveFileOnChange(RespFile, NewRespStr, False)\r
544 ToolsDef.append("%s = %s" % (Resp, UnexpandMacroStr + ' @' + RespFile))\r
545 RespFileListContent += '@' + RespFile + TAB_LINE_BREAK\r
546 RespFileListContent += NewRespStr + TAB_LINE_BREAK\r
547 SaveFileOnChange(RespFileList, RespFileListContent, False)\r
548 else:\r
549 if os.path.exists(RespFileList):\r
550 os.remove(RespFileList)\r
551\r
552 # convert source files and binary files to build targets\r
553 self.ResultFileList = [str(T.Target) for T in MyAgo.CodaTargetList]\r
554 if len(self.ResultFileList) == 0 and len(MyAgo.SourceFileList) != 0:\r
555 EdkLogger.error("build", AUTOGEN_ERROR, "Nothing to build",\r
556 ExtraData="[%s]" % str(MyAgo))\r
557\r
558 self.ProcessBuildTargetList()\r
559 self.ParserGenerateFfsCmd()\r
560\r
561 # Generate macros used to represent input files\r
562 FileMacroList = [] # macro name = file list\r
563 for FileListMacro in self.FileListMacros:\r
564 FileMacro = self._FILE_MACRO_TEMPLATE.Replace(\r
565 {\r
566 "macro_name" : FileListMacro,\r
567 "source_file" : self.FileListMacros[FileListMacro]\r
568 }\r
569 )\r
570 FileMacroList.append(FileMacro)\r
571\r
572 # INC_LIST is special\r
573 FileMacro = ""\r
574 IncludePathList = []\r
575 for P in MyAgo.IncludePathList:\r
576 IncludePathList.append(IncPrefix + self.PlaceMacro(P, self.Macros))\r
577 if FileBuildRule.INC_LIST_MACRO in self.ListFileMacros:\r
578 self.ListFileMacros[FileBuildRule.INC_LIST_MACRO].append(IncPrefix + P)\r
579 FileMacro += self._FILE_MACRO_TEMPLATE.Replace(\r
580 {\r
581 "macro_name" : "INC",\r
582 "source_file" : IncludePathList\r
583 }\r
584 )\r
585 FileMacroList.append(FileMacro)\r
586 # Add support when compiling .nasm source files\r
587 for File in self.FileCache.keys():\r
588 if not str(File).endswith('.nasm'):\r
589 continue\r
590 IncludePathList = []\r
591 for P in MyAgo.IncludePathList:\r
592 IncludePath = self._INC_FLAG_['NASM'] + self.PlaceMacro(P, self.Macros)\r
593 if IncludePath.endswith(os.sep):\r
594 IncludePath = IncludePath.rstrip(os.sep)\r
595 # When compiling .nasm files, need to add a literal backslash at each path\r
596 # To specify a literal backslash at the end of the line, precede it with a caret (^)\r
597 if P == MyAgo.IncludePathList[-1] and os.sep == '\\':\r
598 IncludePath = ''.join([IncludePath, '^', os.sep])\r
599 else:\r
600 IncludePath = os.path.join(IncludePath, '')\r
601 IncludePathList.append(IncludePath)\r
602 FileMacroList.append(self._FILE_MACRO_TEMPLATE.Replace({"macro_name": "NASM_INC", "source_file": IncludePathList}))\r
603 break\r
604\r
605 # Generate macros used to represent files containing list of input files\r
606 for ListFileMacro in self.ListFileMacros:\r
607 ListFileName = os.path.join(MyAgo.OutputDir, "%s.lst" % ListFileMacro.lower()[:len(ListFileMacro) - 5])\r
608 FileMacroList.append("%s = %s" % (ListFileMacro, ListFileName))\r
609 SaveFileOnChange(\r
610 ListFileName,\r
611 "\n".join(self.ListFileMacros[ListFileMacro]),\r
612 False\r
613 )\r
614\r
615 BcTargetList = []\r
616\r
617 MakefileName = self._FILE_NAME_[self._FileType]\r
618 LibraryMakeCommandList = []\r
619 for D in self.LibraryBuildDirectoryList:\r
620 Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":os.path.join(D, MakefileName)}\r
621 LibraryMakeCommandList.append(Command)\r
622\r
623 package_rel_dir = MyAgo.SourceDir\r
624 current_dir = self.Macros["WORKSPACE"]\r
625 found = False\r
626 while not found and os.sep in package_rel_dir:\r
627 index = package_rel_dir.index(os.sep)\r
628 current_dir = mws.join(current_dir, package_rel_dir[:index])\r
629 if os.path.exists(current_dir):\r
630 for fl in os.listdir(current_dir):\r
631 if fl.endswith('.dec'):\r
632 found = True\r
633 break\r
634 package_rel_dir = package_rel_dir[index + 1:]\r
635\r
636 MakefileTemplateDict = {\r
637 "makefile_header" : self._FILE_HEADER_[self._FileType],\r
638 "makefile_path" : os.path.join("$(MODULE_BUILD_DIR)", MakefileName),\r
639 "makefile_name" : MakefileName,\r
640 "platform_name" : self.PlatformInfo.Name,\r
641 "platform_guid" : self.PlatformInfo.Guid,\r
642 "platform_version" : self.PlatformInfo.Version,\r
643 "platform_relative_directory": self.PlatformInfo.SourceDir,\r
644 "platform_output_directory" : self.PlatformInfo.OutputDir,\r
645 "ffs_output_directory" : MyAgo.Macros["FFS_OUTPUT_DIR"],\r
646 "platform_dir" : MyAgo.Macros["PLATFORM_DIR"],\r
647\r
648 "module_name" : MyAgo.Name,\r
649 "module_guid" : MyAgo.Guid,\r
650 "module_name_guid" : MyAgo.UniqueBaseName,\r
651 "module_version" : MyAgo.Version,\r
652 "module_type" : MyAgo.ModuleType,\r
653 "module_file" : MyAgo.MetaFile.Name,\r
654 "module_file_base_name" : MyAgo.MetaFile.BaseName,\r
655 "module_relative_directory" : MyAgo.SourceDir,\r
656 "module_dir" : mws.join (self.Macros["WORKSPACE"], MyAgo.SourceDir),\r
657 "package_relative_directory": package_rel_dir,\r
658 "module_extra_defines" : ["%s = %s" % (k, v) for k, v in MyAgo.Module.Defines.items()],\r
659\r
660 "architecture" : MyAgo.Arch,\r
661 "toolchain_tag" : MyAgo.ToolChain,\r
662 "build_target" : MyAgo.BuildTarget,\r
663\r
664 "platform_build_directory" : self.PlatformInfo.BuildDir,\r
665 "module_build_directory" : MyAgo.BuildDir,\r
666 "module_output_directory" : MyAgo.OutputDir,\r
667 "module_debug_directory" : MyAgo.DebugDir,\r
668\r
669 "separator" : Separator,\r
670 "module_tool_definitions" : ToolsDef,\r
671\r
672 "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),\r
673 "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),\r
674\r
675 "module_entry_point" : ModuleEntryPoint,\r
676 "image_entry_point" : ImageEntryPoint,\r
677 "arch_entry_point" : ArchEntryPoint,\r
678 "remaining_build_target" : self.ResultFileList,\r
679 "common_dependency_file" : self.CommonFileDependency,\r
680 "create_directory_command" : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList),\r
681 "clean_command" : self.GetRemoveDirectoryCommand(["$(OUTPUT_DIR)"]),\r
682 "cleanall_command" : self.GetRemoveDirectoryCommand(["$(DEBUG_DIR)", "$(OUTPUT_DIR)"]),\r
683 "dependent_library_build_directory" : self.LibraryBuildDirectoryList,\r
684 "library_build_command" : LibraryMakeCommandList,\r
685 "file_macro" : FileMacroList,\r
686 "file_build_target" : self.BuildTargetList,\r
687 "backward_compatible_target": BcTargetList,\r
688 }\r
689\r
690 return MakefileTemplateDict\r
691\r
692 def ParserGenerateFfsCmd(self):\r
693 #Add Ffs cmd to self.BuildTargetList\r
694 OutputFile = ''\r
695 DepsFileList = []\r
696\r
697 for Cmd in self.GenFfsList:\r
698 if Cmd[2]:\r
699 for CopyCmd in Cmd[2]:\r
700 Src, Dst = CopyCmd\r
701 Src = self.ReplaceMacro(Src)\r
702 Dst = self.ReplaceMacro(Dst)\r
703 if Dst not in self.ResultFileList:\r
704 self.ResultFileList.append(Dst)\r
705 if '%s :' %(Dst) not in self.BuildTargetList:\r
706 self.BuildTargetList.append("%s :" %(Dst))\r
707 self.BuildTargetList.append('\t' + self._CP_TEMPLATE_[self._FileType] %{'Src': Src, 'Dst': Dst})\r
708\r
709 FfsCmdList = Cmd[0]\r
710 for index, Str in enumerate(FfsCmdList):\r
711 if '-o' == Str:\r
712 OutputFile = FfsCmdList[index + 1]\r
713 if '-i' == Str:\r
714 if DepsFileList == []:\r
715 DepsFileList = [FfsCmdList[index + 1]]\r
716 else:\r
717 DepsFileList.append(FfsCmdList[index + 1])\r
718 DepsFileString = ' '.join(DepsFileList).strip()\r
719 if DepsFileString == '':\r
720 continue\r
721 OutputFile = self.ReplaceMacro(OutputFile)\r
722 self.ResultFileList.append(OutputFile)\r
723 DepsFileString = self.ReplaceMacro(DepsFileString)\r
724 self.BuildTargetList.append('%s : %s' % (OutputFile, DepsFileString))\r
725 CmdString = ' '.join(FfsCmdList).strip()\r
726 CmdString = self.ReplaceMacro(CmdString)\r
727 self.BuildTargetList.append('\t%s' % CmdString)\r
728\r
729 self.ParseSecCmd(DepsFileList, Cmd[1])\r
730 for SecOutputFile, SecDepsFile, SecCmd in self.FfsOutputFileList :\r
731 self.BuildTargetList.append('%s : %s' % (self.ReplaceMacro(SecOutputFile), self.ReplaceMacro(SecDepsFile)))\r
732 self.BuildTargetList.append('\t%s' % self.ReplaceMacro(SecCmd))\r
733 self.FfsOutputFileList = []\r
734\r
735 def ParseSecCmd(self, OutputFileList, CmdTuple):\r
736 for OutputFile in OutputFileList:\r
737 for SecCmdStr in CmdTuple:\r
738 SecDepsFileList = []\r
739 SecCmdList = SecCmdStr.split()\r
740 CmdName = SecCmdList[0]\r
741 for index, CmdItem in enumerate(SecCmdList):\r
742 if '-o' == CmdItem and OutputFile == SecCmdList[index + 1]:\r
743 index = index + 1\r
744 while index + 1 < len(SecCmdList):\r
745 if not SecCmdList[index+1].startswith('-'):\r
746 SecDepsFileList.append(SecCmdList[index + 1])\r
747 index = index + 1\r
748 if CmdName == 'Trim':\r
749 SecDepsFileList.append(os.path.join('$(DEBUG_DIR)', os.path.basename(OutputFile).replace('offset', 'efi')))\r
750 if OutputFile.endswith('.ui') or OutputFile.endswith('.ver'):\r
751 SecDepsFileList.append(os.path.join('$(MODULE_DIR)', '$(MODULE_FILE)'))\r
752 self.FfsOutputFileList.append((OutputFile, ' '.join(SecDepsFileList), SecCmdStr))\r
753 if len(SecDepsFileList) > 0:\r
754 self.ParseSecCmd(SecDepsFileList, CmdTuple)\r
755 break\r
756 else:\r
757 continue\r
758\r
759 def ReplaceMacro(self, str):\r
760 for Macro in self.MacroList:\r
761 if self._AutoGenObject.Macros[Macro] and self._AutoGenObject.Macros[Macro] in str:\r
762 str = str.replace(self._AutoGenObject.Macros[Macro], '$(' + Macro + ')')\r
763 return str\r
764\r
765 def CommandExceedLimit(self):\r
766 FlagDict = {\r
767 'CC' : { 'Macro' : '$(CC_FLAGS)', 'Value' : False},\r
768 'PP' : { 'Macro' : '$(PP_FLAGS)', 'Value' : False},\r
769 'APP' : { 'Macro' : '$(APP_FLAGS)', 'Value' : False},\r
770 'ASLPP' : { 'Macro' : '$(ASLPP_FLAGS)', 'Value' : False},\r
771 'VFRPP' : { 'Macro' : '$(VFRPP_FLAGS)', 'Value' : False},\r
772 'ASM' : { 'Macro' : '$(ASM_FLAGS)', 'Value' : False},\r
773 'ASLCC' : { 'Macro' : '$(ASLCC_FLAGS)', 'Value' : False},\r
774 }\r
775\r
776 RespDict = {}\r
777 FileTypeList = []\r
778 IncPrefix = self._INC_FLAG_[self._AutoGenObject.ToolChainFamily]\r
779\r
780 # base on the source files to decide the file type\r
781 for File in self._AutoGenObject.SourceFileList:\r
782 for type in self._AutoGenObject.FileTypes:\r
783 if File in self._AutoGenObject.FileTypes[type]:\r
784 if type not in FileTypeList:\r
785 FileTypeList.append(type)\r
786\r
787 # calculate the command-line length\r
788 if FileTypeList:\r
789 for type in FileTypeList:\r
790 BuildTargets = self._AutoGenObject.BuildRules[type].BuildTargets\r
791 for Target in BuildTargets:\r
792 CommandList = BuildTargets[Target].Commands\r
793 for SingleCommand in CommandList:\r
794 Tool = ''\r
795 SingleCommandLength = len(SingleCommand)\r
796 SingleCommandList = SingleCommand.split()\r
797 if len(SingleCommandList) > 0:\r
798 for Flag in FlagDict:\r
799 if '$('+ Flag +')' in SingleCommandList[0]:\r
800 Tool = Flag\r
801 break\r
802 if Tool:\r
803 if 'PATH' not in self._AutoGenObject.BuildOption[Tool]:\r
804 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
805 SingleCommandLength += len(self._AutoGenObject.BuildOption[Tool]['PATH'])\r
806 for item in SingleCommandList[1:]:\r
807 if FlagDict[Tool]['Macro'] in item:\r
808 if 'FLAGS' not in self._AutoGenObject.BuildOption[Tool]:\r
809 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
810 Str = self._AutoGenObject.BuildOption[Tool]['FLAGS']\r
811 for Option in self._AutoGenObject.BuildOption:\r
812 for Attr in self._AutoGenObject.BuildOption[Option]:\r
813 if Str.find(Option + '_' + Attr) != -1:\r
814 Str = Str.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr])\r
815 while(Str.find('$(') != -1):\r
816 for macro in self._AutoGenObject.Macros:\r
817 MacroName = '$('+ macro + ')'\r
818 if (Str.find(MacroName) != -1):\r
819 Str = Str.replace(MacroName, self._AutoGenObject.Macros[macro])\r
820 break\r
821 else:\r
822 break\r
823 SingleCommandLength += len(Str)\r
824 elif '$(INC)' in item:\r
825 SingleCommandLength += self._AutoGenObject.IncludePathLength + len(IncPrefix) * len(self._AutoGenObject.IncludePathList)\r
826 elif item.find('$(') != -1:\r
827 Str = item\r
828 for Option in self._AutoGenObject.BuildOption:\r
829 for Attr in self._AutoGenObject.BuildOption[Option]:\r
830 if Str.find(Option + '_' + Attr) != -1:\r
831 Str = Str.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr])\r
832 while(Str.find('$(') != -1):\r
833 for macro in self._AutoGenObject.Macros:\r
834 MacroName = '$('+ macro + ')'\r
835 if (Str.find(MacroName) != -1):\r
836 Str = Str.replace(MacroName, self._AutoGenObject.Macros[macro])\r
837 break\r
838 else:\r
839 break\r
840 SingleCommandLength += len(Str)\r
841\r
842 if SingleCommandLength > GlobalData.gCommandMaxLength:\r
843 FlagDict[Tool]['Value'] = True\r
844\r
845 # generate the response file content by combine the FLAGS and INC\r
846 for Flag in FlagDict:\r
847 if FlagDict[Flag]['Value']:\r
848 Key = Flag + '_RESP'\r
849 RespMacro = FlagDict[Flag]['Macro'].replace('FLAGS', 'RESP')\r
850 Value = self._AutoGenObject.BuildOption[Flag]['FLAGS']\r
851 for inc in self._AutoGenObject.IncludePathList:\r
852 Value += ' ' + IncPrefix + inc\r
853 for Option in self._AutoGenObject.BuildOption:\r
854 for Attr in self._AutoGenObject.BuildOption[Option]:\r
855 if Value.find(Option + '_' + Attr) != -1:\r
856 Value = Value.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr])\r
857 while (Value.find('$(') != -1):\r
858 for macro in self._AutoGenObject.Macros:\r
859 MacroName = '$('+ macro + ')'\r
860 if (Value.find(MacroName) != -1):\r
861 Value = Value.replace(MacroName, self._AutoGenObject.Macros[macro])\r
862 break\r
863 else:\r
864 break\r
865\r
866 if self._AutoGenObject.ToolChainFamily == 'GCC':\r
867 RespDict[Key] = Value.replace('\\', '/')\r
868 else:\r
869 RespDict[Key] = Value\r
870 for Target in BuildTargets:\r
871 for i, SingleCommand in enumerate(BuildTargets[Target].Commands):\r
872 if FlagDict[Flag]['Macro'] in SingleCommand:\r
873 BuildTargets[Target].Commands[i] = SingleCommand.replace('$(INC)', '').replace(FlagDict[Flag]['Macro'], RespMacro)\r
874 return RespDict\r
875\r
876 def ProcessBuildTargetList(self):\r
877 #\r
878 # Search dependency file list for each source file\r
879 #\r
880 ForceIncludedFile = []\r
881 for File in self._AutoGenObject.AutoGenFileList:\r
882 if File.Ext == '.h':\r
883 ForceIncludedFile.append(File)\r
884 SourceFileList = []\r
885 OutPutFileList = []\r
886 for Target in self._AutoGenObject.IntroTargetList:\r
887 SourceFileList.extend(Target.Inputs)\r
888 OutPutFileList.extend(Target.Outputs)\r
889\r
890 if OutPutFileList:\r
891 for Item in OutPutFileList:\r
892 if Item in SourceFileList:\r
893 SourceFileList.remove(Item)\r
894\r
895 FileDependencyDict = self.GetFileDependency(\r
896 SourceFileList,\r
897 ForceIncludedFile,\r
898 self._AutoGenObject.IncludePathList + self._AutoGenObject.BuildOptionIncPathList\r
899 )\r
900 DepSet = None\r
901 for File,Dependency in FileDependencyDict.items():\r
902 if not Dependency:\r
903 FileDependencyDict[File] = ['$(FORCE_REBUILD)']\r
904 continue\r
905\r
906 self._AutoGenObject.AutoGenDepSet |= set(Dependency)\r
907\r
908 # skip non-C files\r
909 if File.Ext not in [".c", ".C"] or File.Name == "AutoGen.c":\r
910 continue\r
911 elif DepSet is None:\r
912 DepSet = set(Dependency)\r
913 else:\r
914 DepSet &= set(Dependency)\r
915 # in case nothing in SourceFileList\r
916 if DepSet is None:\r
917 DepSet = set()\r
918 #\r
919 # Extract common files list in the dependency files\r
920 #\r
921 for File in DepSet:\r
922 self.CommonFileDependency.append(self.PlaceMacro(File.Path, self.Macros))\r
923\r
924 for File in FileDependencyDict:\r
925 # skip non-C files\r
926 if File.Ext not in [".c", ".C"] or File.Name == "AutoGen.c":\r
927 continue\r
928 NewDepSet = set(FileDependencyDict[File])\r
929 NewDepSet -= DepSet\r
930 FileDependencyDict[File] = ["$(COMMON_DEPS)"] + list(NewDepSet)\r
931\r
932 # Convert target description object to target string in makefile\r
933 for Type in self._AutoGenObject.Targets:\r
934 for T in self._AutoGenObject.Targets[Type]:\r
935 # Generate related macros if needed\r
936 if T.GenFileListMacro and T.FileListMacro not in self.FileListMacros:\r
937 self.FileListMacros[T.FileListMacro] = []\r
938 if T.GenListFile and T.ListFileMacro not in self.ListFileMacros:\r
939 self.ListFileMacros[T.ListFileMacro] = []\r
940 if T.GenIncListFile and T.IncListFileMacro not in self.ListFileMacros:\r
941 self.ListFileMacros[T.IncListFileMacro] = []\r
942\r
943 Deps = []\r
944 # Add force-dependencies\r
945 for Dep in T.Dependencies:\r
946 Deps.append(self.PlaceMacro(str(Dep), self.Macros))\r
947 # Add inclusion-dependencies\r
948 if len(T.Inputs) == 1 and T.Inputs[0] in FileDependencyDict:\r
949 for F in FileDependencyDict[T.Inputs[0]]:\r
950 Deps.append(self.PlaceMacro(str(F), self.Macros))\r
951 # Add source-dependencies\r
952 for F in T.Inputs:\r
953 NewFile = self.PlaceMacro(str(F), self.Macros)\r
954 # In order to use file list macro as dependency\r
955 if T.GenListFile:\r
956 # gnu tools need forward slash path separator, even on Windows\r
957 self.ListFileMacros[T.ListFileMacro].append(str(F).replace ('\\', '/'))\r
958 self.FileListMacros[T.FileListMacro].append(NewFile)\r
959 elif T.GenFileListMacro:\r
960 self.FileListMacros[T.FileListMacro].append(NewFile)\r
961 else:\r
962 Deps.append(NewFile)\r
963\r
964 # Use file list macro as dependency\r
965 if T.GenFileListMacro:\r
966 Deps.append("$(%s)" % T.FileListMacro)\r
967 if Type in [TAB_OBJECT_FILE, TAB_STATIC_LIBRARY]:\r
968 Deps.append("$(%s)" % T.ListFileMacro)\r
969\r
970 TargetDict = {\r
971 "target" : self.PlaceMacro(T.Target.Path, self.Macros),\r
972 "cmd" : "\n\t".join(T.Commands),\r
973 "deps" : Deps\r
974 }\r
975 self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(TargetDict))\r
976\r
977 ## For creating makefile targets for dependent libraries\r
978 def ProcessDependentLibrary(self):\r
979 for LibraryAutoGen in self._AutoGenObject.LibraryAutoGenList:\r
980 if not LibraryAutoGen.IsBinaryModule:\r
981 self.LibraryBuildDirectoryList.append(self.PlaceMacro(LibraryAutoGen.BuildDir, self.Macros))\r
982\r
983 ## Return a list containing source file's dependencies\r
984 #\r
985 # @param FileList The list of source files\r
986 # @param ForceInculeList The list of files which will be included forcely\r
987 # @param SearchPathList The list of search path\r
988 #\r
989 # @retval dict The mapping between source file path and its dependencies\r
990 #\r
991 def GetFileDependency(self, FileList, ForceInculeList, SearchPathList):\r
992 Dependency = {}\r
993 for F in FileList:\r
994 Dependency[F] = self.GetDependencyList(F, ForceInculeList, SearchPathList)\r
995 return Dependency\r
996\r
997 ## Find dependencies for one source file\r
998 #\r
999 # By searching recursively "#include" directive in file, find out all the\r
1000 # files needed by given source file. The dependencies will be only searched\r
1001 # in given search path list.\r
1002 #\r
1003 # @param File The source file\r
1004 # @param ForceInculeList The list of files which will be included forcely\r
1005 # @param SearchPathList The list of search path\r
1006 #\r
1007 # @retval list The list of files the given source file depends on\r
1008 #\r
1009 def GetDependencyList(self, File, ForceList, SearchPathList):\r
1010 EdkLogger.debug(EdkLogger.DEBUG_1, "Try to get dependency files for %s" % File)\r
1011 FileStack = [File] + ForceList\r
1012 DependencySet = set()\r
1013\r
1014 if self._AutoGenObject.Arch not in gDependencyDatabase:\r
1015 gDependencyDatabase[self._AutoGenObject.Arch] = {}\r
1016 DepDb = gDependencyDatabase[self._AutoGenObject.Arch]\r
1017\r
1018 while len(FileStack) > 0:\r
1019 F = FileStack.pop()\r
1020\r
1021 FullPathDependList = []\r
1022 if F in self.FileCache:\r
1023 for CacheFile in self.FileCache[F]:\r
1024 FullPathDependList.append(CacheFile)\r
1025 if CacheFile not in DependencySet:\r
1026 FileStack.append(CacheFile)\r
1027 DependencySet.update(FullPathDependList)\r
1028 continue\r
1029\r
1030 CurrentFileDependencyList = []\r
1031 if F in DepDb:\r
1032 CurrentFileDependencyList = DepDb[F]\r
1033 else:\r
1034 try:\r
1035 Fd = open(F.Path, 'rb')\r
1036 FileContent = Fd.read()\r
1037 Fd.close()\r
1038 except BaseException as X:\r
1039 EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F.Path + "\n\t" + str(X))\r
1040 if len(FileContent) == 0:\r
1041 continue\r
1042 try:\r
1043 if FileContent[0] == 0xff or FileContent[0] == 0xfe:\r
1044 FileContent = FileContent.decode('utf-16')\r
1045 else:\r
1046 FileContent = FileContent.decode()\r
1047 except:\r
1048 # The file is not txt file. for example .mcb file\r
1049 continue\r
1050 IncludedFileList = gIncludePattern.findall(FileContent)\r
1051\r
1052 for Inc in IncludedFileList:\r
1053 Inc = Inc.strip()\r
1054 # if there's macro used to reference header file, expand it\r
1055 HeaderList = gMacroPattern.findall(Inc)\r
1056 if len(HeaderList) == 1 and len(HeaderList[0]) == 2:\r
1057 HeaderType = HeaderList[0][0]\r
1058 HeaderKey = HeaderList[0][1]\r
1059 if HeaderType in gIncludeMacroConversion:\r
1060 Inc = gIncludeMacroConversion[HeaderType] % {"HeaderKey" : HeaderKey}\r
1061 else:\r
1062 # not known macro used in #include, always build the file by\r
1063 # returning a empty dependency\r
1064 self.FileCache[File] = []\r
1065 return []\r
1066 Inc = os.path.normpath(Inc)\r
1067 CurrentFileDependencyList.append(Inc)\r
1068 DepDb[F] = CurrentFileDependencyList\r
1069\r
1070 CurrentFilePath = F.Dir\r
1071 PathList = [CurrentFilePath] + SearchPathList\r
1072 for Inc in CurrentFileDependencyList:\r
1073 for SearchPath in PathList:\r
1074 FilePath = os.path.join(SearchPath, Inc)\r
1075 if FilePath in gIsFileMap:\r
1076 if not gIsFileMap[FilePath]:\r
1077 continue\r
1078 # If isfile is called too many times, the performance is slow down.\r
1079 elif not os.path.isfile(FilePath):\r
1080 gIsFileMap[FilePath] = False\r
1081 continue\r
1082 else:\r
1083 gIsFileMap[FilePath] = True\r
1084 FilePath = PathClass(FilePath)\r
1085 FullPathDependList.append(FilePath)\r
1086 if FilePath not in DependencySet:\r
1087 FileStack.append(FilePath)\r
1088 break\r
1089 else:\r
1090 EdkLogger.debug(EdkLogger.DEBUG_9, "%s included by %s was not found "\\r
1091 "in any given path:\n\t%s" % (Inc, F, "\n\t".join(SearchPathList)))\r
1092\r
1093 self.FileCache[F] = FullPathDependList\r
1094 DependencySet.update(FullPathDependList)\r
1095\r
1096 DependencySet.update(ForceList)\r
1097 if File in DependencySet:\r
1098 DependencySet.remove(File)\r
1099 DependencyList = list(DependencySet) # remove duplicate ones\r
1100\r
1101 return DependencyList\r
1102\r
1103## CustomMakefile class\r
1104#\r
1105# This class encapsules makefie and its generation for module. It uses template to generate\r
1106# the content of makefile. The content of makefile will be got from ModuleAutoGen object.\r
1107#\r
1108class CustomMakefile(BuildFile):\r
1109 ## template used to generate the makefile for module with custom makefile\r
1110 _TEMPLATE_ = TemplateString('''\\r
1111${makefile_header}\r
1112\r
1113#\r
1114# Platform Macro Definition\r
1115#\r
1116PLATFORM_NAME = ${platform_name}\r
1117PLATFORM_GUID = ${platform_guid}\r
1118PLATFORM_VERSION = ${platform_version}\r
1119PLATFORM_RELATIVE_DIR = ${platform_relative_directory}\r
1120PLATFORM_DIR = ${platform_dir}\r
1121PLATFORM_OUTPUT_DIR = ${platform_output_directory}\r
1122\r
1123#\r
1124# Module Macro Definition\r
1125#\r
1126MODULE_NAME = ${module_name}\r
1127MODULE_GUID = ${module_guid}\r
1128MODULE_NAME_GUID = ${module_name_guid}\r
1129MODULE_VERSION = ${module_version}\r
1130MODULE_TYPE = ${module_type}\r
1131MODULE_FILE = ${module_file}\r
1132MODULE_FILE_BASE_NAME = ${module_file_base_name}\r
1133BASE_NAME = $(MODULE_NAME)\r
1134MODULE_RELATIVE_DIR = ${module_relative_directory}\r
1135MODULE_DIR = ${module_dir}\r
1136\r
1137#\r
1138# Build Configuration Macro Definition\r
1139#\r
1140ARCH = ${architecture}\r
1141TOOLCHAIN = ${toolchain_tag}\r
1142TOOLCHAIN_TAG = ${toolchain_tag}\r
1143TARGET = ${build_target}\r
1144\r
1145#\r
1146# Build Directory Macro Definition\r
1147#\r
1148# PLATFORM_BUILD_DIR = ${platform_build_directory}\r
1149BUILD_DIR = ${platform_build_directory}\r
1150BIN_DIR = $(BUILD_DIR)${separator}${architecture}\r
1151LIB_DIR = $(BIN_DIR)\r
1152MODULE_BUILD_DIR = ${module_build_directory}\r
1153OUTPUT_DIR = ${module_output_directory}\r
1154DEBUG_DIR = ${module_debug_directory}\r
1155DEST_DIR_OUTPUT = $(OUTPUT_DIR)\r
1156DEST_DIR_DEBUG = $(DEBUG_DIR)\r
1157\r
1158#\r
1159# Tools definitions specific to this module\r
1160#\r
1161${BEGIN}${module_tool_definitions}\r
1162${END}\r
1163MAKE_FILE = ${makefile_path}\r
1164\r
1165#\r
1166# Shell Command Macro\r
1167#\r
1168${BEGIN}${shell_command_code} = ${shell_command}\r
1169${END}\r
1170\r
1171${custom_makefile_content}\r
1172\r
1173#\r
1174# Target used when called from platform makefile, which will bypass the build of dependent libraries\r
1175#\r
1176\r
1177pbuild: init all\r
1178\r
1179\r
1180#\r
1181# ModuleTarget\r
1182#\r
1183\r
1184mbuild: init all\r
1185\r
1186#\r
1187# Build Target used in multi-thread build mode, which no init target is needed\r
1188#\r
1189\r
1190tbuild: all\r
1191\r
1192#\r
1193# Initialization target: print build information and create necessary directories\r
1194#\r
1195init:\r
1196\t-@echo Building ... $(MODULE_DIR)${separator}$(MODULE_FILE) [$(ARCH)]\r
1197${BEGIN}\t-@${create_directory_command}\n${END}\\r
1198\r
1199''')\r
1200\r
1201 ## Constructor of CustomMakefile\r
1202 #\r
1203 # @param ModuleAutoGen Object of ModuleAutoGen class\r
1204 #\r
1205 def __init__(self, ModuleAutoGen):\r
1206 BuildFile.__init__(self, ModuleAutoGen)\r
1207 self.PlatformInfo = self._AutoGenObject.PlatformInfo\r
1208 self.IntermediateDirectoryList = ["$(DEBUG_DIR)", "$(OUTPUT_DIR)"]\r
1209\r
1210 # Compose a dict object containing information used to do replacement in template\r
1211 @property\r
1212 def _TemplateDict(self):\r
1213 Separator = self._SEP_[self._FileType]\r
1214 MyAgo = self._AutoGenObject\r
1215 if self._FileType not in MyAgo.CustomMakefile:\r
1216 EdkLogger.error('build', OPTION_NOT_SUPPORTED, "No custom makefile for %s" % self._FileType,\r
1217 ExtraData="[%s]" % str(MyAgo))\r
1218 MakefilePath = mws.join(\r
1219 MyAgo.WorkspaceDir,\r
1220 MyAgo.CustomMakefile[self._FileType]\r
1221 )\r
1222 try:\r
1223 CustomMakefile = open(MakefilePath, 'r').read()\r
1224 except:\r
1225 EdkLogger.error('build', FILE_OPEN_FAILURE, File=str(MyAgo),\r
1226 ExtraData=MyAgo.CustomMakefile[self._FileType])\r
1227\r
1228 # tools definitions\r
1229 ToolsDef = []\r
1230 for Tool in MyAgo.BuildOption:\r
1231 # Don't generate MAKE_FLAGS in makefile. It's put in environment variable.\r
1232 if Tool == "MAKE":\r
1233 continue\r
1234 for Attr in MyAgo.BuildOption[Tool]:\r
1235 if Attr == "FAMILY":\r
1236 continue\r
1237 elif Attr == "PATH":\r
1238 ToolsDef.append("%s = %s" % (Tool, MyAgo.BuildOption[Tool][Attr]))\r
1239 else:\r
1240 ToolsDef.append("%s_%s = %s" % (Tool, Attr, MyAgo.BuildOption[Tool][Attr]))\r
1241 ToolsDef.append("")\r
1242\r
1243 MakefileName = self._FILE_NAME_[self._FileType]\r
1244 MakefileTemplateDict = {\r
1245 "makefile_header" : self._FILE_HEADER_[self._FileType],\r
1246 "makefile_path" : os.path.join("$(MODULE_BUILD_DIR)", MakefileName),\r
1247 "platform_name" : self.PlatformInfo.Name,\r
1248 "platform_guid" : self.PlatformInfo.Guid,\r
1249 "platform_version" : self.PlatformInfo.Version,\r
1250 "platform_relative_directory": self.PlatformInfo.SourceDir,\r
1251 "platform_output_directory" : self.PlatformInfo.OutputDir,\r
1252 "platform_dir" : MyAgo.Macros["PLATFORM_DIR"],\r
1253\r
1254 "module_name" : MyAgo.Name,\r
1255 "module_guid" : MyAgo.Guid,\r
1256 "module_name_guid" : MyAgo.UniqueBaseName,\r
1257 "module_version" : MyAgo.Version,\r
1258 "module_type" : MyAgo.ModuleType,\r
1259 "module_file" : MyAgo.MetaFile,\r
1260 "module_file_base_name" : MyAgo.MetaFile.BaseName,\r
1261 "module_relative_directory" : MyAgo.SourceDir,\r
1262 "module_dir" : mws.join (MyAgo.WorkspaceDir, MyAgo.SourceDir),\r
1263\r
1264 "architecture" : MyAgo.Arch,\r
1265 "toolchain_tag" : MyAgo.ToolChain,\r
1266 "build_target" : MyAgo.BuildTarget,\r
1267\r
1268 "platform_build_directory" : self.PlatformInfo.BuildDir,\r
1269 "module_build_directory" : MyAgo.BuildDir,\r
1270 "module_output_directory" : MyAgo.OutputDir,\r
1271 "module_debug_directory" : MyAgo.DebugDir,\r
1272\r
1273 "separator" : Separator,\r
1274 "module_tool_definitions" : ToolsDef,\r
1275\r
1276 "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),\r
1277 "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),\r
1278\r
1279 "create_directory_command" : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList),\r
1280 "custom_makefile_content" : CustomMakefile\r
1281 }\r
1282\r
1283 return MakefileTemplateDict\r
1284\r
1285## PlatformMakefile class\r
1286#\r
1287# This class encapsules makefie and its generation for platform. It uses\r
1288# template to generate the content of makefile. The content of makefile will be\r
1289# got from PlatformAutoGen object.\r
1290#\r
1291class PlatformMakefile(BuildFile):\r
1292 ## template used to generate the makefile for platform\r
1293 _TEMPLATE_ = TemplateString('''\\r
1294${makefile_header}\r
1295\r
1296#\r
1297# Platform Macro Definition\r
1298#\r
1299PLATFORM_NAME = ${platform_name}\r
1300PLATFORM_GUID = ${platform_guid}\r
1301PLATFORM_VERSION = ${platform_version}\r
1302PLATFORM_FILE = ${platform_file}\r
1303PLATFORM_DIR = ${platform_dir}\r
1304PLATFORM_OUTPUT_DIR = ${platform_output_directory}\r
1305\r
1306#\r
1307# Build Configuration Macro Definition\r
1308#\r
1309TOOLCHAIN = ${toolchain_tag}\r
1310TOOLCHAIN_TAG = ${toolchain_tag}\r
1311TARGET = ${build_target}\r
1312\r
1313#\r
1314# Build Directory Macro Definition\r
1315#\r
1316BUILD_DIR = ${platform_build_directory}\r
1317FV_DIR = ${platform_build_directory}${separator}FV\r
1318\r
1319#\r
1320# Shell Command Macro\r
1321#\r
1322${BEGIN}${shell_command_code} = ${shell_command}\r
1323${END}\r
1324\r
1325MAKE = ${make_path}\r
1326MAKE_FILE = ${makefile_path}\r
1327\r
1328#\r
1329# Default target\r
1330#\r
1331all: init build_libraries build_modules\r
1332\r
1333#\r
1334# Initialization target: print build information and create necessary directories\r
1335#\r
1336init:\r
1337\t-@echo Building ... $(PLATFORM_FILE) [${build_architecture_list}]\r
1338\t${BEGIN}-@${create_directory_command}\r
1339\t${END}\r
1340#\r
1341# library build target\r
1342#\r
1343libraries: init build_libraries\r
1344\r
1345#\r
1346# module build target\r
1347#\r
1348modules: init build_libraries build_modules\r
1349\r
1350#\r
1351# Build all libraries:\r
1352#\r
1353build_libraries:\r
1354${BEGIN}\t@"$(MAKE)" $(MAKE_FLAGS) -f ${library_makefile_list} pbuild\r
1355${END}\t@cd $(BUILD_DIR)\r
1356\r
1357#\r
1358# Build all modules:\r
1359#\r
1360build_modules:\r
1361${BEGIN}\t@"$(MAKE)" $(MAKE_FLAGS) -f ${module_makefile_list} pbuild\r
1362${END}\t@cd $(BUILD_DIR)\r
1363\r
1364#\r
1365# Clean intermediate files\r
1366#\r
1367clean:\r
1368\t${BEGIN}-@${library_build_command} clean\r
1369\t${END}${BEGIN}-@${module_build_command} clean\r
1370\t${END}@cd $(BUILD_DIR)\r
1371\r
1372#\r
1373# Clean all generated files except to makefile\r
1374#\r
1375cleanall:\r
1376${BEGIN}\t${cleanall_command}\r
1377${END}\r
1378\r
1379#\r
1380# Clean all library files\r
1381#\r
1382cleanlib:\r
1383\t${BEGIN}-@${library_build_command} cleanall\r
1384\t${END}@cd $(BUILD_DIR)\n\r
1385''')\r
1386\r
1387 ## Constructor of PlatformMakefile\r
1388 #\r
1389 # @param ModuleAutoGen Object of PlatformAutoGen class\r
1390 #\r
1391 def __init__(self, PlatformAutoGen):\r
1392 BuildFile.__init__(self, PlatformAutoGen)\r
1393 self.ModuleBuildCommandList = []\r
1394 self.ModuleMakefileList = []\r
1395 self.IntermediateDirectoryList = []\r
1396 self.ModuleBuildDirectoryList = []\r
1397 self.LibraryBuildDirectoryList = []\r
1398 self.LibraryMakeCommandList = []\r
1399\r
1400 # Compose a dict object containing information used to do replacement in template\r
1401 @property\r
1402 def _TemplateDict(self):\r
1403 Separator = self._SEP_[self._FileType]\r
1404\r
1405 MyAgo = self._AutoGenObject\r
1406 if "MAKE" not in MyAgo.ToolDefinition or "PATH" not in MyAgo.ToolDefinition["MAKE"]:\r
1407 EdkLogger.error("build", OPTION_MISSING, "No MAKE command defined. Please check your tools_def.txt!",\r
1408 ExtraData="[%s]" % str(MyAgo))\r
1409\r
1410 self.IntermediateDirectoryList = ["$(BUILD_DIR)"]\r
1411 self.ModuleBuildDirectoryList = self.GetModuleBuildDirectoryList()\r
1412 self.LibraryBuildDirectoryList = self.GetLibraryBuildDirectoryList()\r
1413\r
1414 MakefileName = self._FILE_NAME_[self._FileType]\r
1415 LibraryMakefileList = []\r
1416 LibraryMakeCommandList = []\r
1417 for D in self.LibraryBuildDirectoryList:\r
1418 D = self.PlaceMacro(D, {"BUILD_DIR":MyAgo.BuildDir})\r
1419 Makefile = os.path.join(D, MakefileName)\r
1420 Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":Makefile}\r
1421 LibraryMakefileList.append(Makefile)\r
1422 LibraryMakeCommandList.append(Command)\r
1423 self.LibraryMakeCommandList = LibraryMakeCommandList\r
1424\r
1425 ModuleMakefileList = []\r
1426 ModuleMakeCommandList = []\r
1427 for D in self.ModuleBuildDirectoryList:\r
1428 D = self.PlaceMacro(D, {"BUILD_DIR":MyAgo.BuildDir})\r
1429 Makefile = os.path.join(D, MakefileName)\r
1430 Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":Makefile}\r
1431 ModuleMakefileList.append(Makefile)\r
1432 ModuleMakeCommandList.append(Command)\r
1433\r
1434 MakefileTemplateDict = {\r
1435 "makefile_header" : self._FILE_HEADER_[self._FileType],\r
1436 "makefile_path" : os.path.join("$(BUILD_DIR)", MakefileName),\r
1437 "make_path" : MyAgo.ToolDefinition["MAKE"]["PATH"],\r
1438 "makefile_name" : MakefileName,\r
1439 "platform_name" : MyAgo.Name,\r
1440 "platform_guid" : MyAgo.Guid,\r
1441 "platform_version" : MyAgo.Version,\r
1442 "platform_file" : MyAgo.MetaFile,\r
1443 "platform_relative_directory": MyAgo.SourceDir,\r
1444 "platform_output_directory" : MyAgo.OutputDir,\r
1445 "platform_build_directory" : MyAgo.BuildDir,\r
1446 "platform_dir" : MyAgo.Macros["PLATFORM_DIR"],\r
1447\r
1448 "toolchain_tag" : MyAgo.ToolChain,\r
1449 "build_target" : MyAgo.BuildTarget,\r
1450 "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),\r
1451 "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),\r
1452 "build_architecture_list" : MyAgo.Arch,\r
1453 "architecture" : MyAgo.Arch,\r
1454 "separator" : Separator,\r
1455 "create_directory_command" : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList),\r
1456 "cleanall_command" : self.GetRemoveDirectoryCommand(self.IntermediateDirectoryList),\r
1457 "library_makefile_list" : LibraryMakefileList,\r
1458 "module_makefile_list" : ModuleMakefileList,\r
1459 "library_build_command" : LibraryMakeCommandList,\r
1460 "module_build_command" : ModuleMakeCommandList,\r
1461 }\r
1462\r
1463 return MakefileTemplateDict\r
1464\r
1465 ## Get the root directory list for intermediate files of all modules build\r
1466 #\r
1467 # @retval list The list of directory\r
1468 #\r
1469 def GetModuleBuildDirectoryList(self):\r
1470 DirList = []\r
1471 for ModuleAutoGen in self._AutoGenObject.ModuleAutoGenList:\r
1472 if not ModuleAutoGen.IsBinaryModule:\r
1473 DirList.append(os.path.join(self._AutoGenObject.BuildDir, ModuleAutoGen.BuildDir))\r
1474 return DirList\r
1475\r
1476 ## Get the root directory list for intermediate files of all libraries build\r
1477 #\r
1478 # @retval list The list of directory\r
1479 #\r
1480 def GetLibraryBuildDirectoryList(self):\r
1481 DirList = []\r
1482 for LibraryAutoGen in self._AutoGenObject.LibraryAutoGenList:\r
1483 if not LibraryAutoGen.IsBinaryModule:\r
1484 DirList.append(os.path.join(self._AutoGenObject.BuildDir, LibraryAutoGen.BuildDir))\r
1485 return DirList\r
1486\r
1487## TopLevelMakefile class\r
1488#\r
1489# This class encapsules makefie and its generation for entrance makefile. It\r
1490# uses template to generate the content of makefile. The content of makefile\r
1491# will be got from WorkspaceAutoGen object.\r
1492#\r
1493class TopLevelMakefile(BuildFile):\r
1494 ## template used to generate toplevel makefile\r
1495 _TEMPLATE_ = TemplateString('''${BEGIN}\tGenFds -f ${fdf_file} --conf=${conf_directory} -o ${platform_build_directory} -t ${toolchain_tag} -b ${build_target} -p ${active_platform} -a ${build_architecture_list} ${extra_options}${END}${BEGIN} -r ${fd} ${END}${BEGIN} -i ${fv} ${END}${BEGIN} -C ${cap} ${END}${BEGIN} -D ${macro} ${END}''')\r
1496\r
1497 ## Constructor of TopLevelMakefile\r
1498 #\r
1499 # @param Workspace Object of WorkspaceAutoGen class\r
1500 #\r
1501 def __init__(self, Workspace):\r
1502 BuildFile.__init__(self, Workspace)\r
1503 self.IntermediateDirectoryList = []\r
1504\r
1505 # Compose a dict object containing information used to do replacement in template\r
1506 @property\r
1507 def _TemplateDict(self):\r
1508 Separator = self._SEP_[self._FileType]\r
1509\r
1510 # any platform autogen object is ok because we just need common information\r
1511 MyAgo = self._AutoGenObject\r
1512\r
1513 if "MAKE" not in MyAgo.ToolDefinition or "PATH" not in MyAgo.ToolDefinition["MAKE"]:\r
1514 EdkLogger.error("build", OPTION_MISSING, "No MAKE command defined. Please check your tools_def.txt!",\r
1515 ExtraData="[%s]" % str(MyAgo))\r
1516\r
1517 for Arch in MyAgo.ArchList:\r
1518 self.IntermediateDirectoryList.append(Separator.join(["$(BUILD_DIR)", Arch]))\r
1519 self.IntermediateDirectoryList.append("$(FV_DIR)")\r
1520\r
1521 # TRICK: for not generating GenFds call in makefile if no FDF file\r
1522 MacroList = []\r
1523 if MyAgo.FdfFile is not None and MyAgo.FdfFile != "":\r
1524 FdfFileList = [MyAgo.FdfFile]\r
1525 # macros passed to GenFds\r
1526 MacroDict = {}\r
1527 MacroDict.update(GlobalData.gGlobalDefines)\r
1528 MacroDict.update(GlobalData.gCommandLineDefines)\r
1529 for MacroName in MacroDict:\r
1530 if MacroDict[MacroName] != "":\r
1531 MacroList.append('"%s=%s"' % (MacroName, MacroDict[MacroName].replace('\\', '\\\\')))\r
1532 else:\r
1533 MacroList.append('"%s"' % MacroName)\r
1534 else:\r
1535 FdfFileList = []\r
1536\r
1537 # pass extra common options to external program called in makefile, currently GenFds.exe\r
1538 ExtraOption = ''\r
1539 LogLevel = EdkLogger.GetLevel()\r
1540 if LogLevel == EdkLogger.VERBOSE:\r
1541 ExtraOption += " -v"\r
1542 elif LogLevel <= EdkLogger.DEBUG_9:\r
1543 ExtraOption += " -d %d" % (LogLevel - 1)\r
1544 elif LogLevel == EdkLogger.QUIET:\r
1545 ExtraOption += " -q"\r
1546\r
1547 if GlobalData.gCaseInsensitive:\r
1548 ExtraOption += " -c"\r
1549 if GlobalData.gEnableGenfdsMultiThread:\r
1550 ExtraOption += " --genfds-multi-thread"\r
1551 if GlobalData.gIgnoreSource:\r
1552 ExtraOption += " --ignore-sources"\r
1553\r
1554 for pcd in GlobalData.BuildOptionPcd:\r
1555 if pcd[2]:\r
1556 pcdname = '.'.join(pcd[0:3])\r
1557 else:\r
1558 pcdname = '.'.join(pcd[0:2])\r
1559 if pcd[3].startswith('{'):\r
1560 ExtraOption += " --pcd " + pcdname + '=' + 'H' + '"' + pcd[3] + '"'\r
1561 else:\r
1562 ExtraOption += " --pcd " + pcdname + '=' + pcd[3]\r
1563\r
1564 MakefileName = self._FILE_NAME_[self._FileType]\r
1565 SubBuildCommandList = []\r
1566 for A in MyAgo.ArchList:\r
1567 Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":os.path.join("$(BUILD_DIR)", A, MakefileName)}\r
1568 SubBuildCommandList.append(Command)\r
1569\r
1570 MakefileTemplateDict = {\r
1571 "makefile_header" : self._FILE_HEADER_[self._FileType],\r
1572 "makefile_path" : os.path.join("$(BUILD_DIR)", MakefileName),\r
1573 "make_path" : MyAgo.ToolDefinition["MAKE"]["PATH"],\r
1574 "platform_name" : MyAgo.Name,\r
1575 "platform_guid" : MyAgo.Guid,\r
1576 "platform_version" : MyAgo.Version,\r
1577 "platform_build_directory" : MyAgo.BuildDir,\r
1578 "conf_directory" : GlobalData.gConfDirectory,\r
1579\r
1580 "toolchain_tag" : MyAgo.ToolChain,\r
1581 "build_target" : MyAgo.BuildTarget,\r
1582 "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),\r
1583 "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),\r
1584 'arch' : list(MyAgo.ArchList),\r
1585 "build_architecture_list" : ','.join(MyAgo.ArchList),\r
1586 "separator" : Separator,\r
1587 "create_directory_command" : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList),\r
1588 "cleanall_command" : self.GetRemoveDirectoryCommand(self.IntermediateDirectoryList),\r
1589 "sub_build_command" : SubBuildCommandList,\r
1590 "fdf_file" : FdfFileList,\r
1591 "active_platform" : str(MyAgo),\r
1592 "fd" : MyAgo.FdTargetList,\r
1593 "fv" : MyAgo.FvTargetList,\r
1594 "cap" : MyAgo.CapTargetList,\r
1595 "extra_options" : ExtraOption,\r
1596 "macro" : MacroList,\r
1597 }\r
1598\r
1599 return MakefileTemplateDict\r
1600\r
1601 ## Get the root directory list for intermediate files of all modules build\r
1602 #\r
1603 # @retval list The list of directory\r
1604 #\r
1605 def GetModuleBuildDirectoryList(self):\r
1606 DirList = []\r
1607 for ModuleAutoGen in self._AutoGenObject.ModuleAutoGenList:\r
1608 if not ModuleAutoGen.IsBinaryModule:\r
1609 DirList.append(os.path.join(self._AutoGenObject.BuildDir, ModuleAutoGen.BuildDir))\r
1610 return DirList\r
1611\r
1612 ## Get the root directory list for intermediate files of all libraries build\r
1613 #\r
1614 # @retval list The list of directory\r
1615 #\r
1616 def GetLibraryBuildDirectoryList(self):\r
1617 DirList = []\r
1618 for LibraryAutoGen in self._AutoGenObject.LibraryAutoGenList:\r
1619 if not LibraryAutoGen.IsBinaryModule:\r
1620 DirList.append(os.path.join(self._AutoGenObject.BuildDir, LibraryAutoGen.BuildDir))\r
1621 return DirList\r
1622\r
1623# This acts like the main() function for the script, unless it is 'import'ed into another script.\r
1624if __name__ == '__main__':\r
1625 pass\r
1626\r