]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/AutoGen/GenMake.py
Revert BaseTools: PYTHON3 migration
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenMake.py
CommitLineData
f51461c8
LG
1## @file\r
2# Create makefile for MS nmake and GNU make\r
3#\r
70d0a754 4# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
f51461c8
LG
5# This program and the accompanying materials\r
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13\r
14## Import Modules\r
15#\r
1ccc4d89 16from __future__ import absolute_import\r
1be2ed90 17import Common.LongFilePathOs as os\r
f51461c8
LG
18import sys\r
19import string\r
20import re\r
21import os.path as path\r
1be2ed90 22from Common.LongFilePathSupport import OpenLongFilePath as open\r
05cc51ad 23from Common.MultipleWorkspace import MultipleWorkspace as mws\r
f51461c8
LG
24from Common.BuildToolError import *\r
25from Common.Misc import *\r
5a57246e 26from Common.StringUtils import *\r
0ff3b52e 27from .BuildEngine import *\r
f51461c8 28import Common.GlobalData as GlobalData\r
9006a2c6 29from collections import OrderedDict\r
94c04559 30from Common.DataType import TAB_COMPILER_MSFT\r
f51461c8
LG
31\r
32## Regular expression for finding header file inclusions\r
47fea6af 33gIncludePattern = re.compile(r"^[ \t]*#?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() \t]+)(?:[ \t]*[\">]?\)?)", re.MULTILINE | re.UNICODE | re.IGNORECASE)\r
f51461c8
LG
34\r
35## Regular expression for matching macro used in header file inclusion\r
36gMacroPattern = re.compile("([_A-Z][_A-Z0-9]*)[ \t]*\((.+)\)", re.UNICODE)\r
37\r
38gIsFileMap = {}\r
39\r
40## pattern for include style in Edk.x code\r
41gProtocolDefinition = "Protocol/%(HeaderKey)s/%(HeaderKey)s.h"\r
42gGuidDefinition = "Guid/%(HeaderKey)s/%(HeaderKey)s.h"\r
43gArchProtocolDefinition = "ArchProtocol/%(HeaderKey)s/%(HeaderKey)s.h"\r
44gPpiDefinition = "Ppi/%(HeaderKey)s/%(HeaderKey)s.h"\r
45gIncludeMacroConversion = {\r
46 "EFI_PROTOCOL_DEFINITION" : gProtocolDefinition,\r
47 "EFI_GUID_DEFINITION" : gGuidDefinition,\r
48 "EFI_ARCH_PROTOCOL_DEFINITION" : gArchProtocolDefinition,\r
49 "EFI_PROTOCOL_PRODUCER" : gProtocolDefinition,\r
50 "EFI_PROTOCOL_CONSUMER" : gProtocolDefinition,\r
51 "EFI_PROTOCOL_DEPENDENCY" : gProtocolDefinition,\r
52 "EFI_ARCH_PROTOCOL_PRODUCER" : gArchProtocolDefinition,\r
53 "EFI_ARCH_PROTOCOL_CONSUMER" : gArchProtocolDefinition,\r
54 "EFI_ARCH_PROTOCOL_DEPENDENCY" : gArchProtocolDefinition,\r
55 "EFI_PPI_DEFINITION" : gPpiDefinition,\r
56 "EFI_PPI_PRODUCER" : gPpiDefinition,\r
57 "EFI_PPI_CONSUMER" : gPpiDefinition,\r
58 "EFI_PPI_DEPENDENCY" : gPpiDefinition,\r
59}\r
60\r
61## default makefile type\r
62gMakeType = ""\r
63if sys.platform == "win32":\r
64 gMakeType = "nmake"\r
65else:\r
66 gMakeType = "gmake"\r
67\r
68\r
69## BuildFile class\r
70#\r
71# This base class encapsules build file and its generation. It uses template to generate\r
72# the content of build file. The content of build file will be got from AutoGen objects.\r
73#\r
74class BuildFile(object):\r
75 ## template used to generate the build file (i.e. makefile if using make)\r
76 _TEMPLATE_ = TemplateString('')\r
77\r
78 _DEFAULT_FILE_NAME_ = "Makefile"\r
79\r
80 ## default file name for each type of build file\r
81 _FILE_NAME_ = {\r
82 "nmake" : "Makefile",\r
83 "gmake" : "GNUmakefile"\r
84 }\r
85\r
86 ## Fixed header string for makefile\r
87 _MAKEFILE_HEADER = '''#\r
88# DO NOT EDIT\r
89# This file is auto-generated by build utility\r
90#\r
91# Module Name:\r
92#\r
93# %s\r
94#\r
95# Abstract:\r
96#\r
97# Auto-generated makefile for building modules, libraries or platform\r
98#\r
99 '''\r
100\r
101 ## Header string for each type of build file\r
102 _FILE_HEADER_ = {\r
103 "nmake" : _MAKEFILE_HEADER % _FILE_NAME_["nmake"],\r
104 "gmake" : _MAKEFILE_HEADER % _FILE_NAME_["gmake"]\r
105 }\r
106\r
107 ## shell commands which can be used in build file in the form of macro\r
108 # $(CP) copy file command\r
109 # $(MV) move file command\r
110 # $(RM) remove file command\r
111 # $(MD) create dir command\r
112 # $(RD) remove dir command\r
113 #\r
114 _SHELL_CMD_ = {\r
115 "nmake" : {\r
116 "CP" : "copy /y",\r
117 "MV" : "move /y",\r
118 "RM" : "del /f /q",\r
119 "MD" : "mkdir",\r
120 "RD" : "rmdir /s /q",\r
121 },\r
122\r
123 "gmake" : {\r
124 "CP" : "cp -f",\r
125 "MV" : "mv -f",\r
126 "RM" : "rm -f",\r
127 "MD" : "mkdir -p",\r
128 "RD" : "rm -r -f",\r
129 }\r
130 }\r
131\r
132 ## directory separator\r
133 _SEP_ = {\r
134 "nmake" : "\\",\r
135 "gmake" : "/"\r
136 }\r
137\r
138 ## directory creation template\r
139 _MD_TEMPLATE_ = {\r
140 "nmake" : 'if not exist %(dir)s $(MD) %(dir)s',\r
141 "gmake" : "$(MD) %(dir)s"\r
142 }\r
143\r
144 ## directory removal template\r
145 _RD_TEMPLATE_ = {\r
146 "nmake" : 'if exist %(dir)s $(RD) %(dir)s',\r
147 "gmake" : "$(RD) %(dir)s"\r
148 }\r
37de70b7
YZ
149 ## cp if exist\r
150 _CP_TEMPLATE_ = {\r
151 "nmake" : 'if exist %(Src)s $(CP) %(Src)s %(Dst)s',\r
152 "gmake" : "test -f %(Src)s && $(CP) %(Src)s %(Dst)s"\r
153 }\r
f51461c8
LG
154\r
155 _CD_TEMPLATE_ = {\r
156 "nmake" : 'if exist %(dir)s cd %(dir)s',\r
157 "gmake" : "test -e %(dir)s && cd %(dir)s"\r
158 }\r
159\r
160 _MAKE_TEMPLATE_ = {\r
161 "nmake" : 'if exist %(file)s "$(MAKE)" $(MAKE_FLAGS) -f %(file)s',\r
162 "gmake" : 'test -e %(file)s && "$(MAKE)" $(MAKE_FLAGS) -f %(file)s'\r
163 }\r
164\r
165 _INCLUDE_CMD_ = {\r
166 "nmake" : '!INCLUDE',\r
167 "gmake" : "include"\r
168 }\r
169\r
94c04559 170 _INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", "RVCT" : "-I"}\r
f51461c8
LG
171\r
172 ## Constructor of BuildFile\r
173 #\r
174 # @param AutoGenObject Object of AutoGen class\r
175 #\r
176 def __init__(self, AutoGenObject):\r
177 self._AutoGenObject = AutoGenObject\r
178 self._FileType = gMakeType\r
179\r
180 ## Create build file\r
181 #\r
182 # @param FileType Type of build file. Only nmake and gmake are supported now.\r
183 #\r
184 # @retval TRUE The build file is created or re-created successfully\r
185 # @retval FALSE The build file exists and is the same as the one to be generated\r
186 #\r
187 def Generate(self, FileType=gMakeType):\r
188 if FileType not in self._FILE_NAME_:\r
189 EdkLogger.error("build", PARAMETER_INVALID, "Invalid build type [%s]" % FileType,\r
190 ExtraData="[%s]" % str(self._AutoGenObject))\r
191 self._FileType = FileType\r
192 FileContent = self._TEMPLATE_.Replace(self._TemplateDict)\r
193 FileName = self._FILE_NAME_[FileType]\r
194 return SaveFileOnChange(os.path.join(self._AutoGenObject.MakeFileDir, FileName), FileContent, False)\r
195\r
196 ## Return a list of directory creation command string\r
197 #\r
198 # @param DirList The list of directory to be created\r
199 #\r
200 # @retval list The directory creation command list\r
201 #\r
202 def GetCreateDirectoryCommand(self, DirList):\r
203 return [self._MD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]\r
204\r
205 ## Return a list of directory removal command string\r
206 #\r
207 # @param DirList The list of directory to be removed\r
208 #\r
209 # @retval list The directory removal command list\r
210 #\r
211 def GetRemoveDirectoryCommand(self, DirList):\r
212 return [self._RD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]\r
213\r
214 def PlaceMacro(self, Path, MacroDefinitions={}):\r
215 if Path.startswith("$("):\r
216 return Path\r
217 else:\r
218 PathLength = len(Path)\r
219 for MacroName in MacroDefinitions:\r
220 MacroValue = MacroDefinitions[MacroName]\r
221 MacroValueLength = len(MacroValue)\r
37de70b7
YZ
222 if MacroValueLength == 0:\r
223 continue\r
f51461c8
LG
224 if MacroValueLength <= PathLength and Path.startswith(MacroValue):\r
225 Path = "$(%s)%s" % (MacroName, Path[MacroValueLength:])\r
226 break\r
227 return Path\r
228\r
229## ModuleMakefile class\r
230#\r
231# This class encapsules makefie and its generation for module. It uses template to generate\r
232# the content of makefile. The content of makefile will be got from ModuleAutoGen object.\r
233#\r
234class ModuleMakefile(BuildFile):\r
235 ## template used to generate the makefile for module\r
236 _TEMPLATE_ = TemplateString('''\\r
237${makefile_header}\r
238\r
239#\r
240# Platform Macro Definition\r
241#\r
242PLATFORM_NAME = ${platform_name}\r
243PLATFORM_GUID = ${platform_guid}\r
244PLATFORM_VERSION = ${platform_version}\r
245PLATFORM_RELATIVE_DIR = ${platform_relative_directory}\r
017fb1cd 246PLATFORM_DIR = ${platform_dir}\r
f51461c8
LG
247PLATFORM_OUTPUT_DIR = ${platform_output_directory}\r
248\r
249#\r
250# Module Macro Definition\r
251#\r
252MODULE_NAME = ${module_name}\r
253MODULE_GUID = ${module_guid}\r
867d1cd4 254MODULE_NAME_GUID = ${module_name_guid}\r
f51461c8
LG
255MODULE_VERSION = ${module_version}\r
256MODULE_TYPE = ${module_type}\r
257MODULE_FILE = ${module_file}\r
258MODULE_FILE_BASE_NAME = ${module_file_base_name}\r
259BASE_NAME = $(MODULE_NAME)\r
260MODULE_RELATIVE_DIR = ${module_relative_directory}\r
97fa0ee9 261PACKAGE_RELATIVE_DIR = ${package_relative_directory}\r
01e418d6 262MODULE_DIR = ${module_dir}\r
37de70b7 263FFS_OUTPUT_DIR = ${ffs_output_directory}\r
f51461c8
LG
264\r
265MODULE_ENTRY_POINT = ${module_entry_point}\r
266ARCH_ENTRY_POINT = ${arch_entry_point}\r
267IMAGE_ENTRY_POINT = ${image_entry_point}\r
268\r
269${BEGIN}${module_extra_defines}\r
270${END}\r
271#\r
272# Build Configuration Macro Definition\r
273#\r
274ARCH = ${architecture}\r
275TOOLCHAIN = ${toolchain_tag}\r
276TOOLCHAIN_TAG = ${toolchain_tag}\r
277TARGET = ${build_target}\r
278\r
279#\r
280# Build Directory Macro Definition\r
281#\r
282# PLATFORM_BUILD_DIR = ${platform_build_directory}\r
283BUILD_DIR = ${platform_build_directory}\r
284BIN_DIR = $(BUILD_DIR)${separator}${architecture}\r
285LIB_DIR = $(BIN_DIR)\r
286MODULE_BUILD_DIR = ${module_build_directory}\r
287OUTPUT_DIR = ${module_output_directory}\r
288DEBUG_DIR = ${module_debug_directory}\r
289DEST_DIR_OUTPUT = $(OUTPUT_DIR)\r
290DEST_DIR_DEBUG = $(DEBUG_DIR)\r
291\r
292#\r
293# Shell Command Macro\r
294#\r
295${BEGIN}${shell_command_code} = ${shell_command}\r
296${END}\r
297\r
298#\r
299# Tools definitions specific to this module\r
300#\r
301${BEGIN}${module_tool_definitions}\r
302${END}\r
303MAKE_FILE = ${makefile_path}\r
304\r
305#\r
306# Build Macro\r
307#\r
308${BEGIN}${file_macro}\r
309${END}\r
310\r
311COMMON_DEPS = ${BEGIN}${common_dependency_file} \\\r
312 ${END}\r
313\r
314#\r
315# Overridable Target Macro Definitions\r
316#\r
317FORCE_REBUILD = force_build\r
318INIT_TARGET = init\r
319PCH_TARGET =\r
320BC_TARGET = ${BEGIN}${backward_compatible_target} ${END}\r
321CODA_TARGET = ${BEGIN}${remaining_build_target} \\\r
322 ${END}\r
323\r
324#\r
325# Default target, which will build dependent libraries in addition to source files\r
326#\r
327\r
328all: mbuild\r
329\r
330\r
331#\r
332# Target used when called from platform makefile, which will bypass the build of dependent libraries\r
333#\r
334\r
335pbuild: $(INIT_TARGET) $(BC_TARGET) $(PCH_TARGET) $(CODA_TARGET)\r
336\r
337#\r
338# ModuleTarget\r
339#\r
340\r
341mbuild: $(INIT_TARGET) $(BC_TARGET) gen_libs $(PCH_TARGET) $(CODA_TARGET)\r
342\r
343#\r
344# Build Target used in multi-thread build mode, which will bypass the init and gen_libs targets\r
345#\r
346\r
347tbuild: $(BC_TARGET) $(PCH_TARGET) $(CODA_TARGET)\r
348\r
349#\r
350# Phony target which is used to force executing commands for a target\r
351#\r
352force_build:\r
353\t-@\r
354\r
355#\r
356# Target to update the FD\r
357#\r
358\r
359fds: mbuild gen_fds\r
360\r
361#\r
362# Initialization target: print build information and create necessary directories\r
363#\r
364init: info dirs\r
365\r
366info:\r
367\t-@echo Building ... $(MODULE_DIR)${separator}$(MODULE_FILE) [$(ARCH)]\r
368\r
369dirs:\r
370${BEGIN}\t-@${create_directory_command}\n${END}\r
371\r
372strdefs:\r
373\t-@$(CP) $(DEBUG_DIR)${separator}AutoGen.h $(DEBUG_DIR)${separator}$(MODULE_NAME)StrDefs.h\r
374\r
375#\r
376# GenLibsTarget\r
377#\r
378gen_libs:\r
379\t${BEGIN}@"$(MAKE)" $(MAKE_FLAGS) -f ${dependent_library_build_directory}${separator}${makefile_name}\r
380\t${END}@cd $(MODULE_BUILD_DIR)\r
381\r
382#\r
383# Build Flash Device Image\r
384#\r
385gen_fds:\r
386\t@"$(MAKE)" $(MAKE_FLAGS) -f $(BUILD_DIR)${separator}${makefile_name} fds\r
387\t@cd $(MODULE_BUILD_DIR)\r
388\r
389#\r
390# Individual Object Build Targets\r
391#\r
392${BEGIN}${file_build_target}\r
393${END}\r
394\r
395#\r
396# clean all intermediate files\r
397#\r
398clean:\r
399\t${BEGIN}${clean_command}\r
8ac3309f 400\t${END}\t$(RM) AutoGenTimeStamp\r
f51461c8
LG
401\r
402#\r
403# clean all generated files\r
404#\r
405cleanall:\r
406${BEGIN}\t${cleanall_command}\r
407${END}\t$(RM) *.pdb *.idb > NUL 2>&1\r
408\t$(RM) $(BIN_DIR)${separator}$(MODULE_NAME).efi\r
8ac3309f 409\t$(RM) AutoGenTimeStamp\r
f51461c8
LG
410\r
411#\r
412# clean all dependent libraries built\r
413#\r
414cleanlib:\r
415\t${BEGIN}-@${library_build_command} cleanall\r
416\t${END}@cd $(MODULE_BUILD_DIR)\n\n''')\r
417\r
418 _FILE_MACRO_TEMPLATE = TemplateString("${macro_name} = ${BEGIN} \\\n ${source_file}${END}\n")\r
419 _BUILD_TARGET_TEMPLATE = TemplateString("${BEGIN}${target} : ${deps}\n${END}\t${cmd}\n")\r
420\r
421 ## Constructor of ModuleMakefile\r
422 #\r
423 # @param ModuleAutoGen Object of ModuleAutoGen class\r
424 #\r
425 def __init__(self, ModuleAutoGen):\r
426 BuildFile.__init__(self, ModuleAutoGen)\r
427 self.PlatformInfo = self._AutoGenObject.PlatformInfo\r
428\r
429 self.ResultFileList = []\r
430 self.IntermediateDirectoryList = ["$(DEBUG_DIR)", "$(OUTPUT_DIR)"]\r
431\r
f51461c8
LG
432 self.FileBuildTargetList = [] # [(src, target string)]\r
433 self.BuildTargetList = [] # [target string]\r
434 self.PendingBuildTargetList = [] # [FileBuildRule objects]\r
435 self.CommonFileDependency = []\r
436 self.FileListMacros = {}\r
437 self.ListFileMacros = {}\r
438\r
439 self.FileCache = {}\r
f51461c8
LG
440 self.LibraryBuildCommandList = []\r
441 self.LibraryFileList = []\r
442 self.LibraryMakefileList = []\r
443 self.LibraryBuildDirectoryList = []\r
444 self.SystemLibraryList = []\r
9006a2c6 445 self.Macros = OrderedDict()\r
f51461c8
LG
446 self.Macros["OUTPUT_DIR" ] = self._AutoGenObject.Macros["OUTPUT_DIR"]\r
447 self.Macros["DEBUG_DIR" ] = self._AutoGenObject.Macros["DEBUG_DIR"]\r
448 self.Macros["MODULE_BUILD_DIR"] = self._AutoGenObject.Macros["MODULE_BUILD_DIR"]\r
449 self.Macros["BIN_DIR" ] = self._AutoGenObject.Macros["BIN_DIR"]\r
450 self.Macros["BUILD_DIR" ] = self._AutoGenObject.Macros["BUILD_DIR"]\r
451 self.Macros["WORKSPACE" ] = self._AutoGenObject.Macros["WORKSPACE"]\r
37de70b7
YZ
452 self.Macros["FFS_OUTPUT_DIR" ] = self._AutoGenObject.Macros["FFS_OUTPUT_DIR"]\r
453 self.GenFfsList = ModuleAutoGen.GenFfsList\r
454 self.MacroList = ['FFS_OUTPUT_DIR', 'MODULE_GUID', 'OUTPUT_DIR']\r
455 self.FfsOutputFileList = []\r
f51461c8
LG
456\r
457 # Compose a dict object containing information used to do replacement in template\r
4c92c81d
CJ
458 @property\r
459 def _TemplateDict(self):\r
f51461c8
LG
460 if self._FileType not in self._SEP_:\r
461 EdkLogger.error("build", PARAMETER_INVALID, "Invalid Makefile type [%s]" % self._FileType,\r
462 ExtraData="[%s]" % str(self._AutoGenObject))\r
7c12d613 463 MyAgo = self._AutoGenObject\r
f51461c8
LG
464 Separator = self._SEP_[self._FileType]\r
465\r
466 # break build if no source files and binary files are found\r
7c12d613 467 if len(MyAgo.SourceFileList) == 0 and len(MyAgo.BinaryFileList) == 0:\r
f51461c8 468 EdkLogger.error("build", AUTOGEN_ERROR, "No files to be built in module [%s, %s, %s]"\r
7c12d613
JC
469 % (MyAgo.BuildTarget, MyAgo.ToolChain, MyAgo.Arch),\r
470 ExtraData="[%s]" % str(MyAgo))\r
f51461c8
LG
471\r
472 # convert dependent libraries to build command\r
473 self.ProcessDependentLibrary()\r
7c12d613
JC
474 if len(MyAgo.Module.ModuleEntryPointList) > 0:\r
475 ModuleEntryPoint = MyAgo.Module.ModuleEntryPointList[0]\r
f51461c8
LG
476 else:\r
477 ModuleEntryPoint = "_ModuleEntryPoint"\r
478\r
479 # Intel EBC compiler enforces EfiMain\r
7c12d613 480 if MyAgo.AutoGenVersion < 0x00010005 and MyAgo.Arch == "EBC":\r
f51461c8
LG
481 ArchEntryPoint = "EfiMain"\r
482 else:\r
483 ArchEntryPoint = ModuleEntryPoint\r
484\r
7c12d613 485 if MyAgo.Arch == "EBC":\r
f51461c8
LG
486 # EBC compiler always use "EfiStart" as entry point. Only applies to EdkII modules\r
487 ImageEntryPoint = "EfiStart"\r
7c12d613 488 elif MyAgo.AutoGenVersion < 0x00010005:\r
f51461c8
LG
489 # Edk modules use entry point specified in INF file\r
490 ImageEntryPoint = ModuleEntryPoint\r
491 else:\r
492 # EdkII modules always use "_ModuleEntryPoint" as entry point\r
493 ImageEntryPoint = "_ModuleEntryPoint"\r
494\r
1ccc4d89 495 for k, v in MyAgo.Module.Defines.iteritems():\r
7c12d613
JC
496 if k not in MyAgo.Macros:\r
497 MyAgo.Macros[k] = v\r
3570e332 498\r
7c12d613
JC
499 if 'MODULE_ENTRY_POINT' not in MyAgo.Macros:\r
500 MyAgo.Macros['MODULE_ENTRY_POINT'] = ModuleEntryPoint\r
501 if 'ARCH_ENTRY_POINT' not in MyAgo.Macros:\r
502 MyAgo.Macros['ARCH_ENTRY_POINT'] = ArchEntryPoint\r
503 if 'IMAGE_ENTRY_POINT' not in MyAgo.Macros:\r
504 MyAgo.Macros['IMAGE_ENTRY_POINT'] = ImageEntryPoint\r
3570e332 505\r
9ccb26bc 506 PCI_COMPRESS_Flag = False\r
1ccc4d89 507 for k, v in MyAgo.Module.Defines.iteritems():\r
9ccb26bc
YZ
508 if 'PCI_COMPRESS' == k and 'TRUE' == v:\r
509 PCI_COMPRESS_Flag = True\r
510\r
f51461c8
LG
511 # tools definitions\r
512 ToolsDef = []\r
7c12d613
JC
513 IncPrefix = self._INC_FLAG_[MyAgo.ToolChainFamily]\r
514 for Tool in MyAgo.BuildOption:\r
515 for Attr in MyAgo.BuildOption[Tool]:\r
516 Value = MyAgo.BuildOption[Tool][Attr]\r
f51461c8
LG
517 if Attr == "FAMILY":\r
518 continue\r
519 elif Attr == "PATH":\r
520 ToolsDef.append("%s = %s" % (Tool, Value))\r
521 else:\r
522 # Don't generate MAKE_FLAGS in makefile. It's put in environment variable.\r
523 if Tool == "MAKE":\r
524 continue\r
525 # Remove duplicated include path, if any\r
526 if Attr == "FLAGS":\r
7c12d613 527 Value = RemoveDupOption(Value, IncPrefix, MyAgo.IncludePathList)\r
9ccb26bc
YZ
528 if Tool == "OPTROM" and PCI_COMPRESS_Flag:\r
529 ValueList = Value.split()\r
530 if ValueList:\r
531 for i, v in enumerate(ValueList):\r
532 if '-e' == v:\r
533 ValueList[i] = '-ec'\r
534 Value = ' '.join(ValueList)\r
535\r
f51461c8
LG
536 ToolsDef.append("%s_%s = %s" % (Tool, Attr, Value))\r
537 ToolsDef.append("")\r
538\r
725cdb8f
YZ
539 # generate the Response file and Response flag\r
540 RespDict = self.CommandExceedLimit()\r
7c12d613 541 RespFileList = os.path.join(MyAgo.OutputDir, 'respfilelist.txt')\r
725cdb8f
YZ
542 if RespDict:\r
543 RespFileListContent = ''\r
9eb87141 544 for Resp in RespDict:\r
7c12d613 545 RespFile = os.path.join(MyAgo.OutputDir, str(Resp).lower() + '.txt')\r
3570e332
YZ
546 StrList = RespDict[Resp].split(' ')\r
547 UnexpandMacro = []\r
548 NewStr = []\r
549 for Str in StrList:\r
550 if '$' in Str:\r
551 UnexpandMacro.append(Str)\r
552 else:\r
553 NewStr.append(Str)\r
554 UnexpandMacroStr = ' '.join(UnexpandMacro)\r
555 NewRespStr = ' '.join(NewStr)\r
556 SaveFileOnChange(RespFile, NewRespStr, False)\r
557 ToolsDef.append("%s = %s" % (Resp, UnexpandMacroStr + ' @' + RespFile))\r
725cdb8f 558 RespFileListContent += '@' + RespFile + os.linesep\r
3570e332 559 RespFileListContent += NewRespStr + os.linesep\r
725cdb8f
YZ
560 SaveFileOnChange(RespFileList, RespFileListContent, False)\r
561 else:\r
562 if os.path.exists(RespFileList):\r
563 os.remove(RespFileList)\r
564\r
f51461c8 565 # convert source files and binary files to build targets\r
7c12d613
JC
566 self.ResultFileList = [str(T.Target) for T in MyAgo.CodaTargetList]\r
567 if len(self.ResultFileList) == 0 and len(MyAgo.SourceFileList) != 0:\r
f51461c8 568 EdkLogger.error("build", AUTOGEN_ERROR, "Nothing to build",\r
7c12d613 569 ExtraData="[%s]" % str(MyAgo))\r
f51461c8
LG
570\r
571 self.ProcessBuildTargetList()\r
37de70b7 572 self.ParserGenerateFfsCmd()\r
f51461c8
LG
573\r
574 # Generate macros used to represent input files\r
575 FileMacroList = [] # macro name = file list\r
576 for FileListMacro in self.FileListMacros:\r
577 FileMacro = self._FILE_MACRO_TEMPLATE.Replace(\r
578 {\r
579 "macro_name" : FileListMacro,\r
580 "source_file" : self.FileListMacros[FileListMacro]\r
581 }\r
582 )\r
583 FileMacroList.append(FileMacro)\r
584\r
585 # INC_LIST is special\r
586 FileMacro = ""\r
587 IncludePathList = []\r
7c12d613 588 for P in MyAgo.IncludePathList:\r
47fea6af 589 IncludePathList.append(IncPrefix + self.PlaceMacro(P, self.Macros))\r
f51461c8 590 if FileBuildRule.INC_LIST_MACRO in self.ListFileMacros:\r
47fea6af 591 self.ListFileMacros[FileBuildRule.INC_LIST_MACRO].append(IncPrefix + P)\r
f51461c8
LG
592 FileMacro += self._FILE_MACRO_TEMPLATE.Replace(\r
593 {\r
594 "macro_name" : "INC",\r
595 "source_file" : IncludePathList\r
596 }\r
597 )\r
598 FileMacroList.append(FileMacro)\r
599\r
600 # Generate macros used to represent files containing list of input files\r
601 for ListFileMacro in self.ListFileMacros:\r
7c12d613 602 ListFileName = os.path.join(MyAgo.OutputDir, "%s.lst" % ListFileMacro.lower()[:len(ListFileMacro) - 5])\r
f51461c8
LG
603 FileMacroList.append("%s = %s" % (ListFileMacro, ListFileName))\r
604 SaveFileOnChange(\r
605 ListFileName,\r
606 "\n".join(self.ListFileMacros[ListFileMacro]),\r
607 False\r
608 )\r
609\r
610 # Edk modules need <BaseName>StrDefs.h for string ID\r
7c12d613 611 #if MyAgo.AutoGenVersion < 0x00010005 and len(MyAgo.UnicodeFileList) > 0:\r
f51461c8
LG
612 # BcTargetList = ['strdefs']\r
613 #else:\r
614 # BcTargetList = []\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
7c12d613 623 package_rel_dir = MyAgo.SourceDir\r
b442ad5c
YL
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
05cc51ad 628 current_dir = mws.join(current_dir, package_rel_dir[:index])\r
570ae1eb
YZ
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
b442ad5c 634 package_rel_dir = package_rel_dir[index + 1:]\r
97fa0ee9 635\r
f51461c8
LG
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
7c12d613
JC
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
97fa0ee9 657 "package_relative_directory": package_rel_dir,\r
1ccc4d89 658 "module_extra_defines" : ["%s = %s" % (k, v) for k, v in MyAgo.Module.Defines.iteritems()],\r
f51461c8 659\r
7c12d613
JC
660 "architecture" : MyAgo.Arch,\r
661 "toolchain_tag" : MyAgo.ToolChain,\r
662 "build_target" : MyAgo.BuildTarget,\r
f51461c8
LG
663\r
664 "platform_build_directory" : self.PlatformInfo.BuildDir,\r
7c12d613
JC
665 "module_build_directory" : MyAgo.BuildDir,\r
666 "module_output_directory" : MyAgo.OutputDir,\r
667 "module_debug_directory" : MyAgo.DebugDir,\r
f51461c8
LG
668\r
669 "separator" : Separator,\r
670 "module_tool_definitions" : ToolsDef,\r
671\r
1ccc4d89
LG
672 "shell_command_code" : self._SHELL_CMD_[self._FileType].keys(),\r
673 "shell_command" : self._SHELL_CMD_[self._FileType].values(),\r
f51461c8
LG
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
37de70b7
YZ
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
caf74495 704 self.ResultFileList.append(Dst)\r
37de70b7
YZ
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
caf74495 722 self.ResultFileList.append(OutputFile)\r
37de70b7
YZ
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
ccaa7754 751 SecDepsFileList.append(os.path.join('$(MODULE_DIR)', '$(MODULE_FILE)'))\r
37de70b7
YZ
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
725cdb8f
YZ
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
9eb87141 798 for Flag in FlagDict:\r
725cdb8f
YZ
799 if '$('+ Flag +')' in SingleCommandList[0]:\r
800 Tool = Flag\r
801 break\r
802 if Tool:\r
b23414f6 803 if 'PATH' not in self._AutoGenObject.BuildOption[Tool]:\r
70d0a754 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
b23414f6 805 SingleCommandLength += len(self._AutoGenObject.BuildOption[Tool]['PATH'])\r
725cdb8f
YZ
806 for item in SingleCommandList[1:]:\r
807 if FlagDict[Tool]['Macro'] in item:\r
b23414f6 808 if 'FLAGS' not in self._AutoGenObject.BuildOption[Tool]:\r
70d0a754 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
b23414f6 810 Str = self._AutoGenObject.BuildOption[Tool]['FLAGS']\r
9eb87141 811 for Option in self._AutoGenObject.BuildOption:\r
3570e332
YZ
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
725cdb8f 815 while(Str.find('$(') != -1):\r
9eb87141 816 for macro in self._AutoGenObject.Macros:\r
725cdb8f
YZ
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
3570e332 822 break\r
725cdb8f
YZ
823 SingleCommandLength += len(Str)\r
824 elif '$(INC)' in item:\r
b23414f6 825 SingleCommandLength += self._AutoGenObject.IncludePathLength + len(IncPrefix) * len(self._AutoGenObject.IncludePathList)\r
725cdb8f
YZ
826 elif item.find('$(') != -1:\r
827 Str = item\r
9eb87141 828 for Option in self._AutoGenObject.BuildOption:\r
725cdb8f
YZ
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
9eb87141 833 for macro in self._AutoGenObject.Macros:\r
725cdb8f
YZ
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
3570e332 839 break\r
725cdb8f
YZ
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
9eb87141 846 for Flag in FlagDict:\r
725cdb8f
YZ
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
b23414f6 851 for inc in self._AutoGenObject.IncludePathList:\r
725cdb8f 852 Value += ' ' + IncPrefix + inc\r
9eb87141 853 for Option in self._AutoGenObject.BuildOption:\r
3570e332
YZ
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
725cdb8f 857 while (Value.find('$(') != -1):\r
9eb87141 858 for macro in self._AutoGenObject.Macros:\r
725cdb8f
YZ
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
3570e332 864 break\r
669b6cc6
YZ
865\r
866 if self._AutoGenObject.ToolChainFamily == 'GCC':\r
867 RespDict[Key] = Value.replace('\\', '/')\r
868 else:\r
869 RespDict[Key] = Value\r
725cdb8f
YZ
870 for Target in BuildTargets:\r
871 for i, SingleCommand in enumerate(BuildTargets[Target].Commands):\r
872 if FlagDict[Flag]['Macro'] in SingleCommand:\r
ccaa7754 873 BuildTargets[Target].Commands[i] = SingleCommand.replace('$(INC)', '').replace(FlagDict[Flag]['Macro'], RespMacro)\r
725cdb8f
YZ
874 return RespDict\r
875\r
f51461c8
LG
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
a3a47370 885 OutPutFileList = []\r
f51461c8
LG
886 for Target in self._AutoGenObject.IntroTargetList:\r
887 SourceFileList.extend(Target.Inputs)\r
a3a47370
YZ
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
f51461c8 894\r
0f78fd73 895 FileDependencyDict = self.GetFileDependency(\r
f51461c8
LG
896 SourceFileList,\r
897 ForceIncludedFile,\r
898 self._AutoGenObject.IncludePathList + self._AutoGenObject.BuildOptionIncPathList\r
899 )\r
900 DepSet = None\r
0f78fd73
JC
901 for File,Dependency in FileDependencyDict.items():\r
902 if not Dependency:\r
903 FileDependencyDict[File] = ['$(FORCE_REBUILD)']\r
f51461c8 904 continue\r
c17956e0 905\r
0f78fd73 906 self._AutoGenObject.AutoGenDepSet |= set(Dependency)\r
c17956e0 907\r
f51461c8
LG
908 # skip non-C files\r
909 if File.Ext not in [".c", ".C"] or File.Name == "AutoGen.c":\r
910 continue\r
4231a819 911 elif DepSet is None:\r
0f78fd73 912 DepSet = set(Dependency)\r
f51461c8 913 else:\r
0f78fd73 914 DepSet &= set(Dependency)\r
f51461c8 915 # in case nothing in SourceFileList\r
4231a819 916 if DepSet is None:\r
f51461c8
LG
917 DepSet = set()\r
918 #\r
919 # Extract common files list in the dependency files\r
920 #\r
1ccc4d89 921 for File in DepSet:\r
f51461c8
LG
922 self.CommonFileDependency.append(self.PlaceMacro(File.Path, self.Macros))\r
923\r
0f78fd73 924 for File in FileDependencyDict:\r
f51461c8
LG
925 # skip non-C files\r
926 if File.Ext not in [".c", ".C"] or File.Name == "AutoGen.c":\r
927 continue\r
0f78fd73 928 NewDepSet = set(FileDependencyDict[File])\r
f51461c8 929 NewDepSet -= DepSet\r
1ccc4d89 930 FileDependencyDict[File] = ["$(COMMON_DEPS)"] + list(NewDepSet)\r
f51461c8
LG
931\r
932 # Convert target description object to target string in makefile\r
933 for Type in self._AutoGenObject.Targets:\r
1ccc4d89 934 for T in self._AutoGenObject.Targets[Type]:\r
f51461c8
LG
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
0f78fd73
JC
948 if len(T.Inputs) == 1 and T.Inputs[0] in FileDependencyDict:\r
949 for F in FileDependencyDict[T.Inputs[0]]:\r
f51461c8
LG
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
285a1754
SD
956 # gnu tools need forward slash path separater, even on Windows\r
957 self.ListFileMacros[T.ListFileMacro].append(str(F).replace ('\\', '/'))\r
f51461c8
LG
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
1c62af9e
YZ
967 if Type in [TAB_OBJECT_FILE, TAB_STATIC_LIBRARY]:\r
968 Deps.append("$(%s)" % T.ListFileMacro)\r
f51461c8
LG
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
8832c79d
YZ
980 if not LibraryAutoGen.IsBinaryModule:\r
981 self.LibraryBuildDirectoryList.append(self.PlaceMacro(LibraryAutoGen.BuildDir, self.Macros))\r
f51461c8
LG
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 dependecies 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
1ccc4d89 1035 Fd = open(F.Path, 'r')\r
5b0671c1 1036 except BaseException as X:\r
47fea6af 1037 EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F.Path + "\n\t" + str(X))\r
f51461c8
LG
1038\r
1039 FileContent = Fd.read()\r
1040 Fd.close()\r
1041 if len(FileContent) == 0:\r
1042 continue\r
1043\r
1044 if FileContent[0] == 0xff or FileContent[0] == 0xfe:\r
1ccc4d89
LG
1045 FileContent = unicode(FileContent, "utf-16")\r
1046 IncludedFileList = gIncludePattern.findall(FileContent)\r
f51461c8
LG
1047\r
1048 for Inc in IncludedFileList:\r
1049 Inc = Inc.strip()\r
1050 # if there's macro used to reference header file, expand it\r
1051 HeaderList = gMacroPattern.findall(Inc)\r
1052 if len(HeaderList) == 1 and len(HeaderList[0]) == 2:\r
1053 HeaderType = HeaderList[0][0]\r
1054 HeaderKey = HeaderList[0][1]\r
1055 if HeaderType in gIncludeMacroConversion:\r
1056 Inc = gIncludeMacroConversion[HeaderType] % {"HeaderKey" : HeaderKey}\r
1057 else:\r
1058 # not known macro used in #include, always build the file by\r
1059 # returning a empty dependency\r
1060 self.FileCache[File] = []\r
1061 return []\r
1062 Inc = os.path.normpath(Inc)\r
1063 CurrentFileDependencyList.append(Inc)\r
1064 DepDb[F] = CurrentFileDependencyList\r
1065\r
1066 CurrentFilePath = F.Dir\r
1067 PathList = [CurrentFilePath] + SearchPathList\r
1068 for Inc in CurrentFileDependencyList:\r
1069 for SearchPath in PathList:\r
1070 FilePath = os.path.join(SearchPath, Inc)\r
1071 if FilePath in gIsFileMap:\r
1072 if not gIsFileMap[FilePath]:\r
1073 continue\r
1074 # If isfile is called too many times, the performance is slow down.\r
1075 elif not os.path.isfile(FilePath):\r
1076 gIsFileMap[FilePath] = False\r
1077 continue\r
1078 else:\r
1079 gIsFileMap[FilePath] = True\r
1080 FilePath = PathClass(FilePath)\r
1081 FullPathDependList.append(FilePath)\r
1082 if FilePath not in DependencySet:\r
1083 FileStack.append(FilePath)\r
1084 break\r
1085 else:\r
1086 EdkLogger.debug(EdkLogger.DEBUG_9, "%s included by %s was not found "\\r
1087 "in any given path:\n\t%s" % (Inc, F, "\n\t".join(SearchPathList)))\r
1088\r
1089 self.FileCache[F] = FullPathDependList\r
1090 DependencySet.update(FullPathDependList)\r
1091\r
1092 DependencySet.update(ForceList)\r
1093 if File in DependencySet:\r
1094 DependencySet.remove(File)\r
1ccc4d89 1095 DependencyList = list(DependencySet) # remove duplicate ones\r
f51461c8
LG
1096\r
1097 return DependencyList\r
1098\r
f51461c8
LG
1099## CustomMakefile class\r
1100#\r
1101# This class encapsules makefie and its generation for module. It uses template to generate\r
1102# the content of makefile. The content of makefile will be got from ModuleAutoGen object.\r
1103#\r
1104class CustomMakefile(BuildFile):\r
1105 ## template used to generate the makefile for module with custom makefile\r
1106 _TEMPLATE_ = TemplateString('''\\r
1107${makefile_header}\r
1108\r
1109#\r
1110# Platform Macro Definition\r
1111#\r
1112PLATFORM_NAME = ${platform_name}\r
1113PLATFORM_GUID = ${platform_guid}\r
1114PLATFORM_VERSION = ${platform_version}\r
1115PLATFORM_RELATIVE_DIR = ${platform_relative_directory}\r
7a5f1426 1116PLATFORM_DIR = ${platform_dir}\r
f51461c8
LG
1117PLATFORM_OUTPUT_DIR = ${platform_output_directory}\r
1118\r
1119#\r
1120# Module Macro Definition\r
1121#\r
1122MODULE_NAME = ${module_name}\r
1123MODULE_GUID = ${module_guid}\r
867d1cd4 1124MODULE_NAME_GUID = ${module_name_guid}\r
f51461c8
LG
1125MODULE_VERSION = ${module_version}\r
1126MODULE_TYPE = ${module_type}\r
1127MODULE_FILE = ${module_file}\r
1128MODULE_FILE_BASE_NAME = ${module_file_base_name}\r
1129BASE_NAME = $(MODULE_NAME)\r
1130MODULE_RELATIVE_DIR = ${module_relative_directory}\r
01e418d6 1131MODULE_DIR = ${module_dir}\r
f51461c8
LG
1132\r
1133#\r
1134# Build Configuration Macro Definition\r
1135#\r
1136ARCH = ${architecture}\r
1137TOOLCHAIN = ${toolchain_tag}\r
1138TOOLCHAIN_TAG = ${toolchain_tag}\r
1139TARGET = ${build_target}\r
1140\r
1141#\r
1142# Build Directory Macro Definition\r
1143#\r
1144# PLATFORM_BUILD_DIR = ${platform_build_directory}\r
1145BUILD_DIR = ${platform_build_directory}\r
1146BIN_DIR = $(BUILD_DIR)${separator}${architecture}\r
1147LIB_DIR = $(BIN_DIR)\r
1148MODULE_BUILD_DIR = ${module_build_directory}\r
1149OUTPUT_DIR = ${module_output_directory}\r
1150DEBUG_DIR = ${module_debug_directory}\r
1151DEST_DIR_OUTPUT = $(OUTPUT_DIR)\r
1152DEST_DIR_DEBUG = $(DEBUG_DIR)\r
1153\r
1154#\r
1155# Tools definitions specific to this module\r
1156#\r
1157${BEGIN}${module_tool_definitions}\r
1158${END}\r
1159MAKE_FILE = ${makefile_path}\r
1160\r
1161#\r
1162# Shell Command Macro\r
1163#\r
1164${BEGIN}${shell_command_code} = ${shell_command}\r
1165${END}\r
1166\r
1167${custom_makefile_content}\r
1168\r
1169#\r
1170# Target used when called from platform makefile, which will bypass the build of dependent libraries\r
1171#\r
1172\r
1173pbuild: init all\r
1174\r
1175\r
1176#\r
1177# ModuleTarget\r
1178#\r
1179\r
1180mbuild: init all\r
1181\r
1182#\r
1183# Build Target used in multi-thread build mode, which no init target is needed\r
1184#\r
1185\r
1186tbuild: all\r
1187\r
1188#\r
1189# Initialization target: print build information and create necessary directories\r
1190#\r
1191init:\r
1192\t-@echo Building ... $(MODULE_DIR)${separator}$(MODULE_FILE) [$(ARCH)]\r
1193${BEGIN}\t-@${create_directory_command}\n${END}\\r
1194\r
1195''')\r
1196\r
1197 ## Constructor of CustomMakefile\r
1198 #\r
1199 # @param ModuleAutoGen Object of ModuleAutoGen class\r
1200 #\r
1201 def __init__(self, ModuleAutoGen):\r
1202 BuildFile.__init__(self, ModuleAutoGen)\r
1203 self.PlatformInfo = self._AutoGenObject.PlatformInfo\r
1204 self.IntermediateDirectoryList = ["$(DEBUG_DIR)", "$(OUTPUT_DIR)"]\r
1205\r
1206 # Compose a dict object containing information used to do replacement in template\r
4c92c81d
CJ
1207 @property\r
1208 def _TemplateDict(self):\r
f51461c8 1209 Separator = self._SEP_[self._FileType]\r
7c12d613
JC
1210 MyAgo = self._AutoGenObject\r
1211 if self._FileType not in MyAgo.CustomMakefile:\r
f51461c8 1212 EdkLogger.error('build', OPTION_NOT_SUPPORTED, "No custom makefile for %s" % self._FileType,\r
7c12d613 1213 ExtraData="[%s]" % str(MyAgo))\r
01e418d6 1214 MakefilePath = mws.join(\r
7c12d613
JC
1215 MyAgo.WorkspaceDir,\r
1216 MyAgo.CustomMakefile[self._FileType]\r
f51461c8
LG
1217 )\r
1218 try:\r
1219 CustomMakefile = open(MakefilePath, 'r').read()\r
1220 except:\r
7c12d613
JC
1221 EdkLogger.error('build', FILE_OPEN_FAILURE, File=str(MyAgo),\r
1222 ExtraData=MyAgo.CustomMakefile[self._FileType])\r
f51461c8
LG
1223\r
1224 # tools definitions\r
1225 ToolsDef = []\r
7c12d613 1226 for Tool in MyAgo.BuildOption:\r
f51461c8
LG
1227 # Don't generate MAKE_FLAGS in makefile. It's put in environment variable.\r
1228 if Tool == "MAKE":\r
1229 continue\r
7c12d613 1230 for Attr in MyAgo.BuildOption[Tool]:\r
f51461c8
LG
1231 if Attr == "FAMILY":\r
1232 continue\r
1233 elif Attr == "PATH":\r
7c12d613 1234 ToolsDef.append("%s = %s" % (Tool, MyAgo.BuildOption[Tool][Attr]))\r
f51461c8 1235 else:\r
7c12d613 1236 ToolsDef.append("%s_%s = %s" % (Tool, Attr, MyAgo.BuildOption[Tool][Attr]))\r
f51461c8
LG
1237 ToolsDef.append("")\r
1238\r
1239 MakefileName = self._FILE_NAME_[self._FileType]\r
1240 MakefileTemplateDict = {\r
1241 "makefile_header" : self._FILE_HEADER_[self._FileType],\r
1242 "makefile_path" : os.path.join("$(MODULE_BUILD_DIR)", MakefileName),\r
1243 "platform_name" : self.PlatformInfo.Name,\r
1244 "platform_guid" : self.PlatformInfo.Guid,\r
1245 "platform_version" : self.PlatformInfo.Version,\r
1246 "platform_relative_directory": self.PlatformInfo.SourceDir,\r
1247 "platform_output_directory" : self.PlatformInfo.OutputDir,\r
7c12d613
JC
1248 "platform_dir" : MyAgo.Macros["PLATFORM_DIR"],\r
1249\r
1250 "module_name" : MyAgo.Name,\r
1251 "module_guid" : MyAgo.Guid,\r
1252 "module_name_guid" : MyAgo.UniqueBaseName,\r
1253 "module_version" : MyAgo.Version,\r
1254 "module_type" : MyAgo.ModuleType,\r
1255 "module_file" : MyAgo.MetaFile,\r
1256 "module_file_base_name" : MyAgo.MetaFile.BaseName,\r
1257 "module_relative_directory" : MyAgo.SourceDir,\r
1258 "module_dir" : mws.join (MyAgo.WorkspaceDir, MyAgo.SourceDir),\r
1259\r
1260 "architecture" : MyAgo.Arch,\r
1261 "toolchain_tag" : MyAgo.ToolChain,\r
1262 "build_target" : MyAgo.BuildTarget,\r
f51461c8
LG
1263\r
1264 "platform_build_directory" : self.PlatformInfo.BuildDir,\r
7c12d613
JC
1265 "module_build_directory" : MyAgo.BuildDir,\r
1266 "module_output_directory" : MyAgo.OutputDir,\r
1267 "module_debug_directory" : MyAgo.DebugDir,\r
f51461c8
LG
1268\r
1269 "separator" : Separator,\r
1270 "module_tool_definitions" : ToolsDef,\r
1271\r
1ccc4d89
LG
1272 "shell_command_code" : self._SHELL_CMD_[self._FileType].keys(),\r
1273 "shell_command" : self._SHELL_CMD_[self._FileType].values(),\r
f51461c8
LG
1274\r
1275 "create_directory_command" : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList),\r
1276 "custom_makefile_content" : CustomMakefile\r
1277 }\r
1278\r
1279 return MakefileTemplateDict\r
1280\r
f51461c8
LG
1281## PlatformMakefile class\r
1282#\r
1283# This class encapsules makefie and its generation for platform. It uses\r
1284# template to generate the content of makefile. The content of makefile will be\r
1285# got from PlatformAutoGen object.\r
1286#\r
1287class PlatformMakefile(BuildFile):\r
1288 ## template used to generate the makefile for platform\r
1289 _TEMPLATE_ = TemplateString('''\\r
1290${makefile_header}\r
1291\r
1292#\r
1293# Platform Macro Definition\r
1294#\r
1295PLATFORM_NAME = ${platform_name}\r
1296PLATFORM_GUID = ${platform_guid}\r
1297PLATFORM_VERSION = ${platform_version}\r
1298PLATFORM_FILE = ${platform_file}\r
7a5f1426 1299PLATFORM_DIR = ${platform_dir}\r
f51461c8
LG
1300PLATFORM_OUTPUT_DIR = ${platform_output_directory}\r
1301\r
1302#\r
1303# Build Configuration Macro Definition\r
1304#\r
1305TOOLCHAIN = ${toolchain_tag}\r
1306TOOLCHAIN_TAG = ${toolchain_tag}\r
1307TARGET = ${build_target}\r
1308\r
1309#\r
1310# Build Directory Macro Definition\r
1311#\r
1312BUILD_DIR = ${platform_build_directory}\r
1313FV_DIR = ${platform_build_directory}${separator}FV\r
1314\r
1315#\r
1316# Shell Command Macro\r
1317#\r
1318${BEGIN}${shell_command_code} = ${shell_command}\r
1319${END}\r
1320\r
1321MAKE = ${make_path}\r
1322MAKE_FILE = ${makefile_path}\r
1323\r
1324#\r
1325# Default target\r
1326#\r
1327all: init build_libraries build_modules\r
1328\r
1329#\r
1330# Initialization target: print build information and create necessary directories\r
1331#\r
1332init:\r
1333\t-@echo Building ... $(PLATFORM_FILE) [${build_architecture_list}]\r
1334\t${BEGIN}-@${create_directory_command}\r
1335\t${END}\r
1336#\r
1337# library build target\r
1338#\r
1339libraries: init build_libraries\r
1340\r
1341#\r
1342# module build target\r
1343#\r
1344modules: init build_libraries build_modules\r
1345\r
1346#\r
1347# Build all libraries:\r
1348#\r
1349build_libraries:\r
1350${BEGIN}\t@"$(MAKE)" $(MAKE_FLAGS) -f ${library_makefile_list} pbuild\r
1351${END}\t@cd $(BUILD_DIR)\r
1352\r
1353#\r
1354# Build all modules:\r
1355#\r
1356build_modules:\r
1357${BEGIN}\t@"$(MAKE)" $(MAKE_FLAGS) -f ${module_makefile_list} pbuild\r
1358${END}\t@cd $(BUILD_DIR)\r
1359\r
1360#\r
1361# Clean intermediate files\r
1362#\r
1363clean:\r
1364\t${BEGIN}-@${library_build_command} clean\r
1365\t${END}${BEGIN}-@${module_build_command} clean\r
1366\t${END}@cd $(BUILD_DIR)\r
1367\r
1368#\r
1369# Clean all generated files except to makefile\r
1370#\r
1371cleanall:\r
1372${BEGIN}\t${cleanall_command}\r
1373${END}\r
1374\r
1375#\r
1376# Clean all library files\r
1377#\r
1378cleanlib:\r
1379\t${BEGIN}-@${library_build_command} cleanall\r
1380\t${END}@cd $(BUILD_DIR)\n\r
1381''')\r
1382\r
1383 ## Constructor of PlatformMakefile\r
1384 #\r
1385 # @param ModuleAutoGen Object of PlatformAutoGen class\r
1386 #\r
1387 def __init__(self, PlatformAutoGen):\r
1388 BuildFile.__init__(self, PlatformAutoGen)\r
1389 self.ModuleBuildCommandList = []\r
1390 self.ModuleMakefileList = []\r
1391 self.IntermediateDirectoryList = []\r
1392 self.ModuleBuildDirectoryList = []\r
1393 self.LibraryBuildDirectoryList = []\r
03af2753 1394 self.LibraryMakeCommandList = []\r
f51461c8
LG
1395\r
1396 # Compose a dict object containing information used to do replacement in template\r
4c92c81d
CJ
1397 @property\r
1398 def _TemplateDict(self):\r
f51461c8
LG
1399 Separator = self._SEP_[self._FileType]\r
1400\r
7c12d613
JC
1401 MyAgo = self._AutoGenObject\r
1402 if "MAKE" not in MyAgo.ToolDefinition or "PATH" not in MyAgo.ToolDefinition["MAKE"]:\r
f51461c8 1403 EdkLogger.error("build", OPTION_MISSING, "No MAKE command defined. Please check your tools_def.txt!",\r
7c12d613 1404 ExtraData="[%s]" % str(MyAgo))\r
f51461c8
LG
1405\r
1406 self.IntermediateDirectoryList = ["$(BUILD_DIR)"]\r
1407 self.ModuleBuildDirectoryList = self.GetModuleBuildDirectoryList()\r
1408 self.LibraryBuildDirectoryList = self.GetLibraryBuildDirectoryList()\r
1409\r
1410 MakefileName = self._FILE_NAME_[self._FileType]\r
1411 LibraryMakefileList = []\r
1412 LibraryMakeCommandList = []\r
1413 for D in self.LibraryBuildDirectoryList:\r
7c12d613 1414 D = self.PlaceMacro(D, {"BUILD_DIR":MyAgo.BuildDir})\r
f51461c8
LG
1415 Makefile = os.path.join(D, MakefileName)\r
1416 Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":Makefile}\r
1417 LibraryMakefileList.append(Makefile)\r
1418 LibraryMakeCommandList.append(Command)\r
03af2753 1419 self.LibraryMakeCommandList = LibraryMakeCommandList\r
f51461c8
LG
1420\r
1421 ModuleMakefileList = []\r
1422 ModuleMakeCommandList = []\r
1423 for D in self.ModuleBuildDirectoryList:\r
7c12d613 1424 D = self.PlaceMacro(D, {"BUILD_DIR":MyAgo.BuildDir})\r
f51461c8
LG
1425 Makefile = os.path.join(D, MakefileName)\r
1426 Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":Makefile}\r
1427 ModuleMakefileList.append(Makefile)\r
1428 ModuleMakeCommandList.append(Command)\r
1429\r
1430 MakefileTemplateDict = {\r
1431 "makefile_header" : self._FILE_HEADER_[self._FileType],\r
1432 "makefile_path" : os.path.join("$(BUILD_DIR)", MakefileName),\r
7c12d613 1433 "make_path" : MyAgo.ToolDefinition["MAKE"]["PATH"],\r
f51461c8 1434 "makefile_name" : MakefileName,\r
7c12d613
JC
1435 "platform_name" : MyAgo.Name,\r
1436 "platform_guid" : MyAgo.Guid,\r
1437 "platform_version" : MyAgo.Version,\r
1438 "platform_file" : MyAgo.MetaFile,\r
1439 "platform_relative_directory": MyAgo.SourceDir,\r
1440 "platform_output_directory" : MyAgo.OutputDir,\r
1441 "platform_build_directory" : MyAgo.BuildDir,\r
1442 "platform_dir" : MyAgo.Macros["PLATFORM_DIR"],\r
1443\r
1444 "toolchain_tag" : MyAgo.ToolChain,\r
1445 "build_target" : MyAgo.BuildTarget,\r
1ccc4d89
LG
1446 "shell_command_code" : self._SHELL_CMD_[self._FileType].keys(),\r
1447 "shell_command" : self._SHELL_CMD_[self._FileType].values(),\r
7c12d613
JC
1448 "build_architecture_list" : MyAgo.Arch,\r
1449 "architecture" : MyAgo.Arch,\r
f51461c8
LG
1450 "separator" : Separator,\r
1451 "create_directory_command" : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList),\r
1452 "cleanall_command" : self.GetRemoveDirectoryCommand(self.IntermediateDirectoryList),\r
1453 "library_makefile_list" : LibraryMakefileList,\r
1454 "module_makefile_list" : ModuleMakefileList,\r
1455 "library_build_command" : LibraryMakeCommandList,\r
1456 "module_build_command" : ModuleMakeCommandList,\r
1457 }\r
1458\r
1459 return MakefileTemplateDict\r
1460\r
1461 ## Get the root directory list for intermediate files of all modules build\r
1462 #\r
1463 # @retval list The list of directory\r
1464 #\r
1465 def GetModuleBuildDirectoryList(self):\r
1466 DirList = []\r
1467 for ModuleAutoGen in self._AutoGenObject.ModuleAutoGenList:\r
97fa0ee9
YL
1468 if not ModuleAutoGen.IsBinaryModule:\r
1469 DirList.append(os.path.join(self._AutoGenObject.BuildDir, ModuleAutoGen.BuildDir))\r
f51461c8
LG
1470 return DirList\r
1471\r
1472 ## Get the root directory list for intermediate files of all libraries build\r
1473 #\r
1474 # @retval list The list of directory\r
1475 #\r
1476 def GetLibraryBuildDirectoryList(self):\r
1477 DirList = []\r
1478 for LibraryAutoGen in self._AutoGenObject.LibraryAutoGenList:\r
97fa0ee9
YL
1479 if not LibraryAutoGen.IsBinaryModule:\r
1480 DirList.append(os.path.join(self._AutoGenObject.BuildDir, LibraryAutoGen.BuildDir))\r
f51461c8
LG
1481 return DirList\r
1482\r
f51461c8
LG
1483## TopLevelMakefile class\r
1484#\r
1485# This class encapsules makefie and its generation for entrance makefile. It\r
1486# uses template to generate the content of makefile. The content of makefile\r
1487# will be got from WorkspaceAutoGen object.\r
1488#\r
1489class TopLevelMakefile(BuildFile):\r
1490 ## template used to generate toplevel makefile\r
97fa0ee9 1491 _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
f51461c8
LG
1492\r
1493 ## Constructor of TopLevelMakefile\r
1494 #\r
1495 # @param Workspace Object of WorkspaceAutoGen class\r
1496 #\r
1497 def __init__(self, Workspace):\r
1498 BuildFile.__init__(self, Workspace)\r
1499 self.IntermediateDirectoryList = []\r
1500\r
1501 # Compose a dict object containing information used to do replacement in template\r
4c92c81d
CJ
1502 @property\r
1503 def _TemplateDict(self):\r
f51461c8
LG
1504 Separator = self._SEP_[self._FileType]\r
1505\r
1506 # any platform autogen object is ok because we just need common information\r
7c12d613 1507 MyAgo = self._AutoGenObject\r
f51461c8 1508\r
7c12d613 1509 if "MAKE" not in MyAgo.ToolDefinition or "PATH" not in MyAgo.ToolDefinition["MAKE"]:\r
f51461c8 1510 EdkLogger.error("build", OPTION_MISSING, "No MAKE command defined. Please check your tools_def.txt!",\r
7c12d613 1511 ExtraData="[%s]" % str(MyAgo))\r
f51461c8 1512\r
7c12d613 1513 for Arch in MyAgo.ArchList:\r
f51461c8
LG
1514 self.IntermediateDirectoryList.append(Separator.join(["$(BUILD_DIR)", Arch]))\r
1515 self.IntermediateDirectoryList.append("$(FV_DIR)")\r
1516\r
1517 # TRICK: for not generating GenFds call in makefile if no FDF file\r
1518 MacroList = []\r
7c12d613
JC
1519 if MyAgo.FdfFile is not None and MyAgo.FdfFile != "":\r
1520 FdfFileList = [MyAgo.FdfFile]\r
f51461c8
LG
1521 # macros passed to GenFds\r
1522 MacroList.append('"%s=%s"' % ("EFI_SOURCE", GlobalData.gEfiSource.replace('\\', '\\\\')))\r
1523 MacroList.append('"%s=%s"' % ("EDK_SOURCE", GlobalData.gEdkSource.replace('\\', '\\\\')))\r
1524 MacroDict = {}\r
1525 MacroDict.update(GlobalData.gGlobalDefines)\r
1526 MacroDict.update(GlobalData.gCommandLineDefines)\r
1527 MacroDict.pop("EFI_SOURCE", "dummy")\r
1528 MacroDict.pop("EDK_SOURCE", "dummy")\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
37de70b7
YZ
1549 if GlobalData.gEnableGenfdsMultiThread:\r
1550 ExtraOption += " --genfds-multi-thread"\r
97fa0ee9
YL
1551 if GlobalData.gIgnoreSource:\r
1552 ExtraOption += " --ignore-sources"\r
1553\r
0f228f19
B
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
6b17c11b 1563\r
f51461c8
LG
1564 MakefileName = self._FILE_NAME_[self._FileType]\r
1565 SubBuildCommandList = []\r
7c12d613 1566 for A in MyAgo.ArchList:\r
f51461c8
LG
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
7c12d613
JC
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
97fa0ee9 1578 "conf_directory" : GlobalData.gConfDirectory,\r
f51461c8 1579\r
7c12d613
JC
1580 "toolchain_tag" : MyAgo.ToolChain,\r
1581 "build_target" : MyAgo.BuildTarget,\r
1ccc4d89
LG
1582 "shell_command_code" : self._SHELL_CMD_[self._FileType].keys(),\r
1583 "shell_command" : self._SHELL_CMD_[self._FileType].values(),\r
7c12d613
JC
1584 'arch' : list(MyAgo.ArchList),\r
1585 "build_architecture_list" : ','.join(MyAgo.ArchList),\r
f51461c8
LG
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
7c12d613
JC
1591 "active_platform" : str(MyAgo),\r
1592 "fd" : MyAgo.FdTargetList,\r
1593 "fv" : MyAgo.FvTargetList,\r
1594 "cap" : MyAgo.CapTargetList,\r
f51461c8
LG
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
97fa0ee9
YL
1608 if not ModuleAutoGen.IsBinaryModule:\r
1609 DirList.append(os.path.join(self._AutoGenObject.BuildDir, ModuleAutoGen.BuildDir))\r
f51461c8
LG
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
97fa0ee9
YL
1619 if not LibraryAutoGen.IsBinaryModule:\r
1620 DirList.append(os.path.join(self._AutoGenObject.BuildDir, LibraryAutoGen.BuildDir))\r
f51461c8
LG
1621 return DirList\r
1622\r
f51461c8
LG
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