2 # Create makefile for MS nmake and GNU make
4 # Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 import Common
.LongFilePathOs
as os
20 import os
.path
as path
21 from Common
.LongFilePathSupport
import OpenLongFilePath
as open
22 from Common
.MultipleWorkspace
import MultipleWorkspace
as mws
23 from Common
.BuildToolError
import *
24 from Common
.Misc
import *
25 from Common
.String
import *
26 from BuildEngine
import *
27 import Common
.GlobalData
as GlobalData
29 ## Regular expression for finding header file inclusions
30 gIncludePattern
= re
.compile(r
"^[ \t]*#?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?
[ \t]*)([-\w
.\\/() \t]+)(?
:[ \t]*[\">]?\
)?
)", re.MULTILINE | re.UNICODE | re.IGNORECASE)
32 ## Regular expression for matching macro used in header file inclusion
33 gMacroPattern = re.compile("([_A
-Z
][_A
-Z0
-9]*)[ \t]*\
((.+)\
)", re.UNICODE)
37 ## pattern for include style in Edk.x code
38 gProtocolDefinition = "Protocol
/%(HeaderKey)s/%(HeaderKey)s.h
"
39 gGuidDefinition = "Guid
/%(HeaderKey)s/%(HeaderKey)s.h
"
40 gArchProtocolDefinition = "ArchProtocol
/%(HeaderKey)s/%(HeaderKey)s.h
"
41 gPpiDefinition = "Ppi
/%(HeaderKey)s/%(HeaderKey)s.h
"
42 gIncludeMacroConversion = {
43 "EFI_PROTOCOL_DEFINITION
" : gProtocolDefinition,
44 "EFI_GUID_DEFINITION
" : gGuidDefinition,
45 "EFI_ARCH_PROTOCOL_DEFINITION
" : gArchProtocolDefinition,
46 "EFI_PROTOCOL_PRODUCER
" : gProtocolDefinition,
47 "EFI_PROTOCOL_CONSUMER
" : gProtocolDefinition,
48 "EFI_PROTOCOL_DEPENDENCY
" : gProtocolDefinition,
49 "EFI_ARCH_PROTOCOL_PRODUCER
" : gArchProtocolDefinition,
50 "EFI_ARCH_PROTOCOL_CONSUMER
" : gArchProtocolDefinition,
51 "EFI_ARCH_PROTOCOL_DEPENDENCY
" : gArchProtocolDefinition,
52 "EFI_PPI_DEFINITION
" : gPpiDefinition,
53 "EFI_PPI_PRODUCER
" : gPpiDefinition,
54 "EFI_PPI_CONSUMER
" : gPpiDefinition,
55 "EFI_PPI_DEPENDENCY
" : gPpiDefinition,
58 ## default makefile type
60 if sys.platform == "win32
":
68 # This base class encapsules build file and its generation. It uses template to generate
69 # the content of build file. The content of build file will be got from AutoGen objects.
71 class BuildFile(object):
72 ## template used to generate the build file (i.e. makefile if using make)
73 _TEMPLATE_ = TemplateString('')
75 _DEFAULT_FILE_NAME_ = "Makefile
"
77 ## default file name for each type of build file
80 "gmake
" : "GNUmakefile
"
83 ## Fixed header string for makefile
84 _MAKEFILE_HEADER = '''#
86 # This file is auto-generated by build utility
94 # Auto-generated makefile for building modules, libraries or platform
98 ## Header string for each type of build file
100 "nmake
" : _MAKEFILE_HEADER % _FILE_NAME_["nmake
"],
101 "gmake
" : _MAKEFILE_HEADER % _FILE_NAME_["gmake
"]
104 ## shell commands which can be used in build file in the form of macro
105 # $(CP) copy file command
106 # $(MV) move file command
107 # $(RM) remove file command
108 # $(MD) create dir command
109 # $(RD) remove dir command
117 "RD
" : "rmdir
/s
/q
",
129 ## directory separator
135 ## directory creation template
137 "nmake
" : 'if not exist %(dir)s $(MD) %(dir)s',
138 "gmake
" : "$
(MD
) %(dir)s"
141 ## directory removal template
143 "nmake
" : 'if exist %(dir)s $(RD) %(dir)s',
144 "gmake
" : "$
(RD
) %(dir)s"
148 "nmake
" : 'if exist %(dir)s cd %(dir)s',
149 "gmake
" : "test
-e
%(dir)s && cd
%(dir)s"
153 "nmake
" : 'if exist %(file)s "$
(MAKE
)" $(MAKE_FLAGS) -f %(file)s',
154 "gmake
" : 'test -e %(file)s && "$
(MAKE
)" $(MAKE_FLAGS) -f %(file)s'
158 "nmake
" : '!INCLUDE',
162 _INC_FLAG_ = {"MSFT
" : "/I
", "GCC
" : "-I
", "INTEL
" : "-I
", "RVCT
" : "-I
"}
164 ## Constructor of BuildFile
166 # @param AutoGenObject Object of AutoGen class
168 def __init__(self, AutoGenObject):
169 self._AutoGenObject = AutoGenObject
170 self._FileType = gMakeType
174 # @param FileType Type of build file. Only nmake and gmake are supported now.
176 # @retval TRUE The build file is created or re-created successfully
177 # @retval FALSE The build file exists and is the same as the one to be generated
179 def Generate(self, FileType=gMakeType):
180 if FileType not in self._FILE_NAME_:
181 EdkLogger.error("build
", PARAMETER_INVALID, "Invalid build
type [%s]" % FileType,
182 ExtraData="[%s]" % str(self._AutoGenObject))
183 self._FileType = FileType
184 FileContent = self._TEMPLATE_.Replace(self._TemplateDict)
185 FileName = self._FILE_NAME_[FileType]
186 return SaveFileOnChange(os.path.join(self._AutoGenObject.MakeFileDir, FileName), FileContent, False)
188 ## Return a list of directory creation command string
190 # @param DirList The list of directory to be created
192 # @retval list The directory creation command list
194 def GetCreateDirectoryCommand(self, DirList):
195 return [self._MD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]
197 ## Return a list of directory removal command string
199 # @param DirList The list of directory to be removed
201 # @retval list The directory removal command list
203 def GetRemoveDirectoryCommand(self, DirList):
204 return [self._RD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]
206 def PlaceMacro(self, Path, MacroDefinitions={}):
207 if Path.startswith("$
("):
210 PathLength = len(Path)
211 for MacroName in MacroDefinitions:
212 MacroValue = MacroDefinitions[MacroName]
213 MacroValueLength = len(MacroValue)
214 if MacroValueLength <= PathLength and Path.startswith(MacroValue):
215 Path = "$
(%s)%s" % (MacroName, Path[MacroValueLength:])
219 ## ModuleMakefile class
221 # This class encapsules makefie and its generation for module. It uses template to generate
222 # the content of makefile. The content of makefile will be got from ModuleAutoGen object.
224 class ModuleMakefile(BuildFile):
225 ## template used to generate the makefile for module
226 _TEMPLATE_ = TemplateString('''\
230 # Platform Macro Definition
232 PLATFORM_NAME = ${platform_name}
233 PLATFORM_GUID = ${platform_guid}
234 PLATFORM_VERSION = ${platform_version}
235 PLATFORM_RELATIVE_DIR = ${platform_relative_directory}
236 PLATFORM_DIR = ${platform_dir}
237 PLATFORM_OUTPUT_DIR = ${platform_output_directory}
240 # Module Macro Definition
242 MODULE_NAME = ${module_name}
243 MODULE_GUID = ${module_guid}
244 MODULE_NAME_GUID = ${module_name_guid}
245 MODULE_VERSION = ${module_version}
246 MODULE_TYPE = ${module_type}
247 MODULE_FILE = ${module_file}
248 MODULE_FILE_BASE_NAME = ${module_file_base_name}
249 BASE_NAME = $(MODULE_NAME)
250 MODULE_RELATIVE_DIR = ${module_relative_directory}
251 PACKAGE_RELATIVE_DIR = ${package_relative_directory}
252 MODULE_DIR = ${module_dir}
254 MODULE_ENTRY_POINT = ${module_entry_point}
255 ARCH_ENTRY_POINT = ${arch_entry_point}
256 IMAGE_ENTRY_POINT = ${image_entry_point}
258 ${BEGIN}${module_extra_defines}
261 # Build Configuration Macro Definition
263 ARCH = ${architecture}
264 TOOLCHAIN = ${toolchain_tag}
265 TOOLCHAIN_TAG = ${toolchain_tag}
266 TARGET = ${build_target}
269 # Build Directory Macro Definition
271 # PLATFORM_BUILD_DIR = ${platform_build_directory}
272 BUILD_DIR = ${platform_build_directory}
273 BIN_DIR = $(BUILD_DIR)${separator}${architecture}
275 MODULE_BUILD_DIR = ${module_build_directory}
276 OUTPUT_DIR = ${module_output_directory}
277 DEBUG_DIR = ${module_debug_directory}
278 DEST_DIR_OUTPUT = $(OUTPUT_DIR)
279 DEST_DIR_DEBUG = $(DEBUG_DIR)
282 # Shell Command Macro
284 ${BEGIN}${shell_command_code} = ${shell_command}
288 # Tools definitions specific to this module
290 ${BEGIN}${module_tool_definitions}
292 MAKE_FILE = ${makefile_path}
297 ${BEGIN}${file_macro}
300 COMMON_DEPS = ${BEGIN}${common_dependency_file} \\
304 # Overridable Target Macro Definitions
306 FORCE_REBUILD = force_build
309 BC_TARGET = ${BEGIN}${backward_compatible_target} ${END}
310 CODA_TARGET = ${BEGIN}${remaining_build_target} \\
314 # Default target, which will build dependent libraries in addition to source files
321 # Target used when called from platform makefile, which will bypass the build of dependent libraries
324 pbuild: $(INIT_TARGET) $(BC_TARGET) $(PCH_TARGET) $(CODA_TARGET)
330 mbuild: $(INIT_TARGET) $(BC_TARGET) gen_libs $(PCH_TARGET) $(CODA_TARGET)
333 # Build Target used in multi-thread build mode, which will bypass the init and gen_libs targets
336 tbuild: $(BC_TARGET) $(PCH_TARGET) $(CODA_TARGET)
339 # Phony target which is used to force executing commands for a target
345 # Target to update the FD
351 # Initialization target: print build information and create necessary directories
356 \t-@echo Building ... $(MODULE_DIR)${separator}$(MODULE_FILE) [$(ARCH)]
359 ${BEGIN}\t-@${create_directory_command}\n${END}
362 \t-@$(CP) $(DEBUG_DIR)${separator}AutoGen.h $(DEBUG_DIR)${separator}$(MODULE_NAME)StrDefs.h
368 \t${BEGIN}@"$
(MAKE
)" $(MAKE_FLAGS) -f ${dependent_library_build_directory}${separator}${makefile_name}
369 \t${END}@cd $(MODULE_BUILD_DIR)
372 # Build Flash Device Image
375 \t@"$
(MAKE
)" $(MAKE_FLAGS) -f $(BUILD_DIR)${separator}${makefile_name} fds
376 \t@cd $(MODULE_BUILD_DIR)
379 # Individual Object Build Targets
381 ${BEGIN}${file_build_target}
385 # clean all intermediate files
388 \t${BEGIN}${clean_command}
392 # clean all generated files
395 ${BEGIN}\t${cleanall_command}
396 ${END}\t$(RM) *.pdb *.idb > NUL 2>&1
397 \t$(RM) $(BIN_DIR)${separator}$(MODULE_NAME).efi
400 # clean all dependent libraries built
403 \t${BEGIN}-@${library_build_command} cleanall
404 \t${END}@cd $(MODULE_BUILD_DIR)\n\n''')
406 _FILE_MACRO_TEMPLATE = TemplateString("${macro_name}
= ${BEGIN}
\\\n ${source_file}${END}
\n")
407 _BUILD_TARGET_TEMPLATE = TemplateString("${BEGIN}${target}
: ${deps}
\n${END}
\t${cmd}
\n")
409 ## Constructor of ModuleMakefile
411 # @param ModuleAutoGen Object of ModuleAutoGen class
413 def __init__(self, ModuleAutoGen):
414 BuildFile.__init__(self, ModuleAutoGen)
415 self.PlatformInfo = self._AutoGenObject.PlatformInfo
417 self.ResultFileList = []
418 self.IntermediateDirectoryList = ["$
(DEBUG_DIR
)", "$
(OUTPUT_DIR
)"]
420 self.SourceFileDatabase = {} # {file type : file path}
421 self.DestFileDatabase = {} # {file type : file path}
422 self.FileBuildTargetList = [] # [(src, target string)]
423 self.BuildTargetList = [] # [target string]
424 self.PendingBuildTargetList = [] # [FileBuildRule objects]
425 self.CommonFileDependency = []
426 self.FileListMacros = {}
427 self.ListFileMacros = {}
430 self.FileDependency = []
431 self.LibraryBuildCommandList = []
432 self.LibraryFileList = []
433 self.LibraryMakefileList = []
434 self.LibraryBuildDirectoryList = []
435 self.SystemLibraryList = []
436 self.Macros = sdict()
437 self.Macros["OUTPUT_DIR
" ] = self._AutoGenObject.Macros["OUTPUT_DIR
"]
438 self.Macros["DEBUG_DIR
" ] = self._AutoGenObject.Macros["DEBUG_DIR
"]
439 self.Macros["MODULE_BUILD_DIR
"] = self._AutoGenObject.Macros["MODULE_BUILD_DIR
"]
440 self.Macros["BIN_DIR
" ] = self._AutoGenObject.Macros["BIN_DIR
"]
441 self.Macros["BUILD_DIR
" ] = self._AutoGenObject.Macros["BUILD_DIR
"]
442 self.Macros["WORKSPACE
" ] = self._AutoGenObject.Macros["WORKSPACE
"]
444 # Compose a dict object containing information used to do replacement in template
445 def _CreateTemplateDict(self):
446 if self._FileType not in self._SEP_:
447 EdkLogger.error("build
", PARAMETER_INVALID, "Invalid Makefile
type [%s]" % self._FileType,
448 ExtraData="[%s]" % str(self._AutoGenObject))
449 Separator = self._SEP_[self._FileType]
451 # break build if no source files and binary files are found
452 if len(self._AutoGenObject.SourceFileList) == 0 and len(self._AutoGenObject.BinaryFileList) == 0:
453 EdkLogger.error("build
", AUTOGEN_ERROR, "No files to be built
in module
[%s, %s, %s]"
454 % (self._AutoGenObject.BuildTarget, self._AutoGenObject.ToolChain, self._AutoGenObject.Arch),
455 ExtraData="[%s]" % str(self._AutoGenObject))
457 # convert dependent libraries to build command
458 self.ProcessDependentLibrary()
459 if len(self._AutoGenObject.Module.ModuleEntryPointList) > 0:
460 ModuleEntryPoint = self._AutoGenObject.Module.ModuleEntryPointList[0]
462 ModuleEntryPoint = "_ModuleEntryPoint
"
464 # Intel EBC compiler enforces EfiMain
465 if self._AutoGenObject.AutoGenVersion < 0x00010005 and self._AutoGenObject.Arch == "EBC
":
466 ArchEntryPoint = "EfiMain
"
468 ArchEntryPoint = ModuleEntryPoint
470 if self._AutoGenObject.Arch == "EBC
":
471 # EBC compiler always use "EfiStart
" as entry point. Only applies to EdkII modules
472 ImageEntryPoint = "EfiStart
"
473 elif self._AutoGenObject.AutoGenVersion < 0x00010005:
474 # Edk modules use entry point specified in INF file
475 ImageEntryPoint = ModuleEntryPoint
477 # EdkII modules always use "_ModuleEntryPoint
" as entry point
478 ImageEntryPoint = "_ModuleEntryPoint
"
480 for k, v in self._AutoGenObject.Module.Defines.iteritems():
481 if k not in self._AutoGenObject.Macros.keys():
482 self._AutoGenObject.Macros[k] = v
484 if 'MODULE_ENTRY_POINT' not in self._AutoGenObject.Macros.keys():
485 self._AutoGenObject.Macros['MODULE_ENTRY_POINT'] = ModuleEntryPoint
486 if 'ARCH_ENTRY_POINT' not in self._AutoGenObject.Macros.keys():
487 self._AutoGenObject.Macros['ARCH_ENTRY_POINT'] = ArchEntryPoint
488 if 'IMAGE_ENTRY_POINT' not in self._AutoGenObject.Macros.keys():
489 self._AutoGenObject.Macros['IMAGE_ENTRY_POINT'] = ImageEntryPoint
493 IncPrefix = self._INC_FLAG_[self._AutoGenObject.ToolChainFamily]
494 for Tool in self._AutoGenObject.BuildOption:
495 for Attr in self._AutoGenObject.BuildOption[Tool]:
496 Value = self._AutoGenObject.BuildOption[Tool][Attr]
500 ToolsDef.append("%s = %s" % (Tool, Value))
502 # Don't generate MAKE_FLAGS in makefile. It's put in environment variable.
505 # Remove duplicated include path, if any
507 Value = RemoveDupOption(Value, IncPrefix, self._AutoGenObject.IncludePathList)
508 ToolsDef.append("%s_%s = %s" % (Tool, Attr, Value))
511 # generate the Response file and Response flag
512 RespDict = self.CommandExceedLimit()
513 RespFileList = os.path.join(self._AutoGenObject.OutputDir, 'respfilelist.txt')
515 RespFileListContent = ''
516 for Resp in RespDict.keys():
517 RespFile = os.path.join(self._AutoGenObject.OutputDir, str(Resp).lower() + '.txt')
518 StrList = RespDict[Resp].split(' ')
523 UnexpandMacro.append(Str)
526 UnexpandMacroStr = ' '.join(UnexpandMacro)
527 NewRespStr = ' '.join(NewStr)
528 SaveFileOnChange(RespFile, NewRespStr, False)
529 ToolsDef.append("%s = %s" % (Resp, UnexpandMacroStr + ' @' + RespFile))
530 RespFileListContent += '@' + RespFile + os.linesep
531 RespFileListContent += NewRespStr + os.linesep
532 SaveFileOnChange(RespFileList, RespFileListContent, False)
534 if os.path.exists(RespFileList):
535 os.remove(RespFileList)
537 # convert source files and binary files to build targets
538 self.ResultFileList = [str(T.Target) for T in self._AutoGenObject.CodaTargetList]
539 if len(self.ResultFileList) == 0 and len(self._AutoGenObject.SourceFileList) <> 0:
540 EdkLogger.error("build
", AUTOGEN_ERROR, "Nothing to build
",
541 ExtraData="[%s]" % str(self._AutoGenObject))
543 self.ProcessBuildTargetList()
545 # Generate macros used to represent input files
546 FileMacroList = [] # macro name = file list
547 for FileListMacro in self.FileListMacros:
548 FileMacro = self._FILE_MACRO_TEMPLATE.Replace(
550 "macro_name
" : FileListMacro,
551 "source_file
" : self.FileListMacros[FileListMacro]
554 FileMacroList.append(FileMacro)
556 # INC_LIST is special
559 for P in self._AutoGenObject.IncludePathList:
560 IncludePathList.append(IncPrefix + self.PlaceMacro(P, self.Macros))
561 if FileBuildRule.INC_LIST_MACRO in self.ListFileMacros:
562 self.ListFileMacros[FileBuildRule.INC_LIST_MACRO].append(IncPrefix + P)
563 FileMacro += self._FILE_MACRO_TEMPLATE.Replace(
565 "macro_name
" : "INC
",
566 "source_file
" : IncludePathList
569 FileMacroList.append(FileMacro)
571 # Generate macros used to represent files containing list of input files
572 for ListFileMacro in self.ListFileMacros:
573 ListFileName = os.path.join(self._AutoGenObject.OutputDir, "%s.lst
" % ListFileMacro.lower()[:len(ListFileMacro) - 5])
574 FileMacroList.append("%s = %s" % (ListFileMacro, ListFileName))
577 "\n".join(self.ListFileMacros[ListFileMacro]),
581 # Edk modules need <BaseName>StrDefs.h for string ID
582 #if self._AutoGenObject.AutoGenVersion < 0x00010005 and len(self._AutoGenObject.UnicodeFileList) > 0:
583 # BcTargetList = ['strdefs']
588 MakefileName = self._FILE_NAME_[self._FileType]
589 LibraryMakeCommandList = []
590 for D in self.LibraryBuildDirectoryList:
591 Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":os.path.join(D, MakefileName)}
592 LibraryMakeCommandList.append(Command)
594 package_rel_dir = self._AutoGenObject.SourceDir
595 current_dir = self.Macros["WORKSPACE
"]
597 while not found and os.sep in package_rel_dir:
598 index = package_rel_dir.index(os.sep)
599 current_dir = mws.join(current_dir, package_rel_dir[:index])
600 for fl in os.listdir(current_dir):
601 if fl.endswith('.dec'):
604 package_rel_dir = package_rel_dir[index + 1:]
606 MakefileTemplateDict = {
607 "makefile_header
" : self._FILE_HEADER_[self._FileType],
608 "makefile_path
" : os.path.join("$
(MODULE_BUILD_DIR
)", MakefileName),
609 "makefile_name
" : MakefileName,
610 "platform_name
" : self.PlatformInfo.Name,
611 "platform_guid
" : self.PlatformInfo.Guid,
612 "platform_version
" : self.PlatformInfo.Version,
613 "platform_relative_directory
": self.PlatformInfo.SourceDir,
614 "platform_output_directory
" : self.PlatformInfo.OutputDir,
615 "platform_dir
" : self._AutoGenObject.Macros["PLATFORM_DIR
"],
617 "module_name
" : self._AutoGenObject.Name,
618 "module_guid
" : self._AutoGenObject.Guid,
619 "module_name_guid
" : self._AutoGenObject._GetUniqueBaseName(),
620 "module_version
" : self._AutoGenObject.Version,
621 "module_type
" : self._AutoGenObject.ModuleType,
622 "module_file
" : self._AutoGenObject.MetaFile.Name,
623 "module_file_base_name
" : self._AutoGenObject.MetaFile.BaseName,
624 "module_relative_directory
" : self._AutoGenObject.SourceDir,
625 "module_dir
" : mws.join (self.Macros["WORKSPACE
"], self._AutoGenObject.SourceDir),
626 "package_relative_directory
": package_rel_dir,
627 "module_extra_defines
" : ["%s = %s" % (k, v) for k, v in self._AutoGenObject.Module.Defines.iteritems()],
629 "architecture
" : self._AutoGenObject.Arch,
630 "toolchain_tag
" : self._AutoGenObject.ToolChain,
631 "build_target
" : self._AutoGenObject.BuildTarget,
633 "platform_build_directory
" : self.PlatformInfo.BuildDir,
634 "module_build_directory
" : self._AutoGenObject.BuildDir,
635 "module_output_directory
" : self._AutoGenObject.OutputDir,
636 "module_debug_directory
" : self._AutoGenObject.DebugDir,
638 "separator
" : Separator,
639 "module_tool_definitions
" : ToolsDef,
641 "shell_command_code
" : self._SHELL_CMD_[self._FileType].keys(),
642 "shell_command
" : self._SHELL_CMD_[self._FileType].values(),
644 "module_entry_point
" : ModuleEntryPoint,
645 "image_entry_point
" : ImageEntryPoint,
646 "arch_entry_point
" : ArchEntryPoint,
647 "remaining_build_target
" : self.ResultFileList,
648 "common_dependency_file
" : self.CommonFileDependency,
649 "create_directory_command
" : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList),
650 "clean_command
" : self.GetRemoveDirectoryCommand(["$
(OUTPUT_DIR
)"]),
651 "cleanall_command
" : self.GetRemoveDirectoryCommand(["$
(DEBUG_DIR
)", "$
(OUTPUT_DIR
)"]),
652 "dependent_library_build_directory
" : self.LibraryBuildDirectoryList,
653 "library_build_command
" : LibraryMakeCommandList,
654 "file_macro
" : FileMacroList,
655 "file_build_target
" : self.BuildTargetList,
656 "backward_compatible_target
": BcTargetList,
659 return MakefileTemplateDict
661 def CommandExceedLimit(self):
663 'CC' : { 'Macro' : '$(CC_FLAGS)', 'Value' : False},
664 'PP' : { 'Macro' : '$(PP_FLAGS)', 'Value' : False},
665 'APP' : { 'Macro' : '$(APP_FLAGS)', 'Value' : False},
666 'ASLPP' : { 'Macro' : '$(ASLPP_FLAGS)', 'Value' : False},
667 'VFRPP' : { 'Macro' : '$(VFRPP_FLAGS)', 'Value' : False},
668 'ASM' : { 'Macro' : '$(ASM_FLAGS)', 'Value' : False},
669 'ASLCC' : { 'Macro' : '$(ASLCC_FLAGS)', 'Value' : False},
674 IncPrefix = self._INC_FLAG_[self._AutoGenObject.ToolChainFamily]
676 # base on the source files to decide the file type
677 for File in self._AutoGenObject.SourceFileList:
678 for type in self._AutoGenObject.FileTypes:
679 if File in self._AutoGenObject.FileTypes[type]:
680 if type not in FileTypeList:
681 FileTypeList.append(type)
683 # calculate the command-line length
685 for type in FileTypeList:
686 BuildTargets = self._AutoGenObject.BuildRules[type].BuildTargets
687 for Target in BuildTargets:
688 CommandList = BuildTargets[Target].Commands
689 for SingleCommand in CommandList:
691 SingleCommandLength = len(SingleCommand)
692 SingleCommandList = SingleCommand.split()
693 if len(SingleCommandList) > 0:
694 for Flag in FlagDict.keys():
695 if '$('+ Flag +')' in SingleCommandList[0]:
699 SingleCommandLength += len(self._AutoGenObject._BuildOption[Tool]['PATH'])
700 for item in SingleCommandList[1:]:
701 if FlagDict[Tool]['Macro'] in item:
702 Str = self._AutoGenObject._BuildOption[Tool]['FLAGS']
703 for Option in self._AutoGenObject.BuildOption.keys():
704 for Attr in self._AutoGenObject.BuildOption[Option]:
705 if Str.find(Option + '_' + Attr) != -1:
706 Str = Str.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr])
707 while(Str.find('$(') != -1):
708 for macro in self._AutoGenObject.Macros.keys():
709 MacroName = '$('+ macro + ')'
710 if (Str.find(MacroName) != -1):
711 Str = Str.replace(MacroName, self._AutoGenObject.Macros[macro])
715 SingleCommandLength += len(Str)
716 elif '$(INC)' in item:
717 SingleCommandLength += self._AutoGenObject.IncludePathLength + len(IncPrefix) * len(self._AutoGenObject._IncludePathList)
718 elif item.find('$(') != -1:
720 for Option in self._AutoGenObject.BuildOption.keys():
721 for Attr in self._AutoGenObject.BuildOption[Option]:
722 if Str.find(Option + '_' + Attr) != -1:
723 Str = Str.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr])
724 while(Str.find('$(') != -1):
725 for macro in self._AutoGenObject.Macros.keys():
726 MacroName = '$('+ macro + ')'
727 if (Str.find(MacroName) != -1):
728 Str = Str.replace(MacroName, self._AutoGenObject.Macros[macro])
732 SingleCommandLength += len(Str)
734 if SingleCommandLength > GlobalData.gCommandMaxLength:
735 FlagDict[Tool]['Value'] = True
737 # generate the response file content by combine the FLAGS and INC
738 for Flag in FlagDict.keys():
739 if FlagDict[Flag]['Value']:
741 RespMacro = FlagDict[Flag]['Macro'].replace('FLAGS', 'RESP')
742 Value = self._AutoGenObject.BuildOption[Flag]['FLAGS']
743 for inc in self._AutoGenObject._IncludePathList:
744 Value += ' ' + IncPrefix + inc
745 for Option in self._AutoGenObject.BuildOption.keys():
746 for Attr in self._AutoGenObject.BuildOption[Option]:
747 if Value.find(Option + '_' + Attr) != -1:
748 Value = Value.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr])
749 while (Value.find('$(') != -1):
750 for macro in self._AutoGenObject.Macros.keys():
751 MacroName = '$('+ macro + ')'
752 if (Value.find(MacroName) != -1):
753 Value = Value.replace(MacroName, self._AutoGenObject.Macros[macro])
757 RespDict[Key] = Value
758 for Target in BuildTargets:
759 for i, SingleCommand in enumerate(BuildTargets[Target].Commands):
760 if FlagDict[Flag]['Macro'] in SingleCommand:
761 BuildTargets[Target].Commands[i] = SingleCommand.replace('$(INC)','').replace(FlagDict[Flag]['Macro'], RespMacro)
764 def ProcessBuildTargetList(self):
766 # Search dependency file list for each source file
768 ForceIncludedFile = []
769 for File in self._AutoGenObject.AutoGenFileList:
771 ForceIncludedFile.append(File)
773 for Target in self._AutoGenObject.IntroTargetList:
774 SourceFileList.extend(Target.Inputs)
776 self.FileDependency = self.GetFileDependency(
779 self._AutoGenObject.IncludePathList + self._AutoGenObject.BuildOptionIncPathList
782 for File in self.FileDependency:
783 if not self.FileDependency[File]:
784 self.FileDependency[File] = ['$(FORCE_REBUILD)']
787 if File.Ext not in [".c
", ".C
"] or File.Name == "AutoGen
.c
":
790 DepSet = set(self.FileDependency[File])
792 DepSet &= set(self.FileDependency[File])
793 # in case nothing in SourceFileList
797 # Extract common files list in the dependency files
800 self.CommonFileDependency.append(self.PlaceMacro(File.Path, self.Macros))
802 for File in self.FileDependency:
804 if File.Ext not in [".c
", ".C
"] or File.Name == "AutoGen
.c
":
806 NewDepSet = set(self.FileDependency[File])
808 self.FileDependency[File] = ["$
(COMMON_DEPS
)"] + list(NewDepSet)
810 # Convert target description object to target string in makefile
811 for Type in self._AutoGenObject.Targets:
812 for T in self._AutoGenObject.Targets[Type]:
813 # Generate related macros if needed
814 if T.GenFileListMacro and T.FileListMacro not in self.FileListMacros:
815 self.FileListMacros[T.FileListMacro] = []
816 if T.GenListFile and T.ListFileMacro not in self.ListFileMacros:
817 self.ListFileMacros[T.ListFileMacro] = []
818 if T.GenIncListFile and T.IncListFileMacro not in self.ListFileMacros:
819 self.ListFileMacros[T.IncListFileMacro] = []
822 # Add force-dependencies
823 for Dep in T.Dependencies:
824 Deps.append(self.PlaceMacro(str(Dep), self.Macros))
825 # Add inclusion-dependencies
826 if len(T.Inputs) == 1 and T.Inputs[0] in self.FileDependency:
827 for F in self.FileDependency[T.Inputs[0]]:
828 Deps.append(self.PlaceMacro(str(F), self.Macros))
829 # Add source-dependencies
831 NewFile = self.PlaceMacro(str(F), self.Macros)
832 # In order to use file list macro as dependency
834 # gnu tools need forward slash path separater, even on Windows
835 self.ListFileMacros[T.ListFileMacro].append(str(F).replace ('\\', '/'))
836 self.FileListMacros[T.FileListMacro].append(NewFile)
837 elif T.GenFileListMacro:
838 self.FileListMacros[T.FileListMacro].append(NewFile)
842 # Use file list macro as dependency
843 if T.GenFileListMacro:
844 Deps.append("$
(%s)" % T.FileListMacro)
847 "target
" : self.PlaceMacro(T.Target.Path, self.Macros),
848 "cmd
" : "\n\t".join(T.Commands),
851 self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(TargetDict))
853 ## For creating makefile targets for dependent libraries
854 def ProcessDependentLibrary(self):
855 for LibraryAutoGen in self._AutoGenObject.LibraryAutoGenList:
856 self.LibraryBuildDirectoryList.append(self.PlaceMacro(LibraryAutoGen.BuildDir, self.Macros))
858 ## Return a list containing source file's dependencies
860 # @param FileList The list of source files
861 # @param ForceInculeList The list of files which will be included forcely
862 # @param SearchPathList The list of search path
864 # @retval dict The mapping between source file path and its dependencies
866 def GetFileDependency(self, FileList, ForceInculeList, SearchPathList):
869 Dependency[F] = self.GetDependencyList(F, ForceInculeList, SearchPathList)
872 ## Find dependencies for one source file
874 # By searching recursively "#include" directive in file, find out all the
875 # files needed by given source file. The dependecies will be only searched
876 # in given search path list.
878 # @param File The source file
879 # @param ForceInculeList The list of files which will be included forcely
880 # @param SearchPathList The list of search path
882 # @retval list The list of files the given source file depends on
884 def GetDependencyList(self
, File
, ForceList
, SearchPathList
):
885 EdkLogger
.debug(EdkLogger
.DEBUG_1
, "Try to get dependency files for %s" % File
)
886 FileStack
= [File
] + ForceList
887 DependencySet
= set()
889 if self
._AutoGenObject
.Arch
not in gDependencyDatabase
:
890 gDependencyDatabase
[self
._AutoGenObject
.Arch
] = {}
891 DepDb
= gDependencyDatabase
[self
._AutoGenObject
.Arch
]
893 while len(FileStack
) > 0:
896 FullPathDependList
= []
897 if F
in self
.FileCache
:
898 for CacheFile
in self
.FileCache
[F
]:
899 FullPathDependList
.append(CacheFile
)
900 if CacheFile
not in DependencySet
:
901 FileStack
.append(CacheFile
)
902 DependencySet
.update(FullPathDependList
)
905 CurrentFileDependencyList
= []
907 CurrentFileDependencyList
= DepDb
[F
]
910 Fd
= open(F
.Path
, 'r')
911 except BaseException
, X
:
912 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=F
.Path
+ "\n\t" + str(X
))
914 FileContent
= Fd
.read()
916 if len(FileContent
) == 0:
919 if FileContent
[0] == 0xff or FileContent
[0] == 0xfe:
920 FileContent
= unicode(FileContent
, "utf-16")
921 IncludedFileList
= gIncludePattern
.findall(FileContent
)
923 for Inc
in IncludedFileList
:
925 # if there's macro used to reference header file, expand it
926 HeaderList
= gMacroPattern
.findall(Inc
)
927 if len(HeaderList
) == 1 and len(HeaderList
[0]) == 2:
928 HeaderType
= HeaderList
[0][0]
929 HeaderKey
= HeaderList
[0][1]
930 if HeaderType
in gIncludeMacroConversion
:
931 Inc
= gIncludeMacroConversion
[HeaderType
] % {"HeaderKey" : HeaderKey
}
933 # not known macro used in #include, always build the file by
934 # returning a empty dependency
935 self
.FileCache
[File
] = []
937 Inc
= os
.path
.normpath(Inc
)
938 CurrentFileDependencyList
.append(Inc
)
939 DepDb
[F
] = CurrentFileDependencyList
941 CurrentFilePath
= F
.Dir
942 PathList
= [CurrentFilePath
] + SearchPathList
943 for Inc
in CurrentFileDependencyList
:
944 for SearchPath
in PathList
:
945 FilePath
= os
.path
.join(SearchPath
, Inc
)
946 if FilePath
in gIsFileMap
:
947 if not gIsFileMap
[FilePath
]:
949 # If isfile is called too many times, the performance is slow down.
950 elif not os
.path
.isfile(FilePath
):
951 gIsFileMap
[FilePath
] = False
954 gIsFileMap
[FilePath
] = True
955 FilePath
= PathClass(FilePath
)
956 FullPathDependList
.append(FilePath
)
957 if FilePath
not in DependencySet
:
958 FileStack
.append(FilePath
)
961 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "%s included by %s was not found "\
962 "in any given path:\n\t%s" % (Inc
, F
, "\n\t".join(SearchPathList
)))
964 self
.FileCache
[F
] = FullPathDependList
965 DependencySet
.update(FullPathDependList
)
967 DependencySet
.update(ForceList
)
968 if File
in DependencySet
:
969 DependencySet
.remove(File
)
970 DependencyList
= list(DependencySet
) # remove duplicate ones
972 return DependencyList
974 _TemplateDict
= property(_CreateTemplateDict
)
976 ## CustomMakefile class
978 # This class encapsules makefie and its generation for module. It uses template to generate
979 # the content of makefile. The content of makefile will be got from ModuleAutoGen object.
981 class CustomMakefile(BuildFile
):
982 ## template used to generate the makefile for module with custom makefile
983 _TEMPLATE_
= TemplateString('''\
987 # Platform Macro Definition
989 PLATFORM_NAME = ${platform_name}
990 PLATFORM_GUID = ${platform_guid}
991 PLATFORM_VERSION = ${platform_version}
992 PLATFORM_RELATIVE_DIR = ${platform_relative_directory}
993 PLATFORM_DIR = $(platform_dir)
994 PLATFORM_OUTPUT_DIR = ${platform_output_directory}
997 # Module Macro Definition
999 MODULE_NAME = ${module_name}
1000 MODULE_GUID = ${module_guid}
1001 MODULE_NAME_GUID = ${module_name_guid}
1002 MODULE_VERSION = ${module_version}
1003 MODULE_TYPE = ${module_type}
1004 MODULE_FILE = ${module_file}
1005 MODULE_FILE_BASE_NAME = ${module_file_base_name}
1006 BASE_NAME = $(MODULE_NAME)
1007 MODULE_RELATIVE_DIR = ${module_relative_directory}
1008 MODULE_DIR = ${module_dir}
1011 # Build Configuration Macro Definition
1013 ARCH = ${architecture}
1014 TOOLCHAIN = ${toolchain_tag}
1015 TOOLCHAIN_TAG = ${toolchain_tag}
1016 TARGET = ${build_target}
1019 # Build Directory Macro Definition
1021 # PLATFORM_BUILD_DIR = ${platform_build_directory}
1022 BUILD_DIR = ${platform_build_directory}
1023 BIN_DIR = $(BUILD_DIR)${separator}${architecture}
1024 LIB_DIR = $(BIN_DIR)
1025 MODULE_BUILD_DIR = ${module_build_directory}
1026 OUTPUT_DIR = ${module_output_directory}
1027 DEBUG_DIR = ${module_debug_directory}
1028 DEST_DIR_OUTPUT = $(OUTPUT_DIR)
1029 DEST_DIR_DEBUG = $(DEBUG_DIR)
1032 # Tools definitions specific to this module
1034 ${BEGIN}${module_tool_definitions}
1036 MAKE_FILE = ${makefile_path}
1039 # Shell Command Macro
1041 ${BEGIN}${shell_command_code} = ${shell_command}
1044 ${custom_makefile_content}
1047 # Target used when called from platform makefile, which will bypass the build of dependent libraries
1060 # Build Target used in multi-thread build mode, which no init target is needed
1066 # Initialization target: print build information and create necessary directories
1069 \t-@echo Building ... $(MODULE_DIR)${separator}$(MODULE_FILE) [$(ARCH)]
1070 ${BEGIN}\t-@${create_directory_command}\n${END}\
1074 ## Constructor of CustomMakefile
1076 # @param ModuleAutoGen Object of ModuleAutoGen class
1078 def __init__(self
, ModuleAutoGen
):
1079 BuildFile
.__init
__(self
, ModuleAutoGen
)
1080 self
.PlatformInfo
= self
._AutoGenObject
.PlatformInfo
1081 self
.IntermediateDirectoryList
= ["$(DEBUG_DIR)", "$(OUTPUT_DIR)"]
1083 # Compose a dict object containing information used to do replacement in template
1084 def _CreateTemplateDict(self
):
1085 Separator
= self
._SEP
_[self
._FileType
]
1086 if self
._FileType
not in self
._AutoGenObject
.CustomMakefile
:
1087 EdkLogger
.error('build', OPTION_NOT_SUPPORTED
, "No custom makefile for %s" % self
._FileType
,
1088 ExtraData
="[%s]" % str(self
._AutoGenObject
))
1089 MakefilePath
= mws
.join(
1090 self
._AutoGenObject
.WorkspaceDir
,
1091 self
._AutoGenObject
.CustomMakefile
[self
._FileType
]
1094 CustomMakefile
= open(MakefilePath
, 'r').read()
1096 EdkLogger
.error('build', FILE_OPEN_FAILURE
, File
=str(self
._AutoGenObject
),
1097 ExtraData
=self
._AutoGenObject
.CustomMakefile
[self
._FileType
])
1101 for Tool
in self
._AutoGenObject
.BuildOption
:
1102 # Don't generate MAKE_FLAGS in makefile. It's put in environment variable.
1105 for Attr
in self
._AutoGenObject
.BuildOption
[Tool
]:
1106 if Attr
== "FAMILY":
1108 elif Attr
== "PATH":
1109 ToolsDef
.append("%s = %s" % (Tool
, self
._AutoGenObject
.BuildOption
[Tool
][Attr
]))
1111 ToolsDef
.append("%s_%s = %s" % (Tool
, Attr
, self
._AutoGenObject
.BuildOption
[Tool
][Attr
]))
1114 MakefileName
= self
._FILE
_NAME
_[self
._FileType
]
1115 MakefileTemplateDict
= {
1116 "makefile_header" : self
._FILE
_HEADER
_[self
._FileType
],
1117 "makefile_path" : os
.path
.join("$(MODULE_BUILD_DIR)", MakefileName
),
1118 "platform_name" : self
.PlatformInfo
.Name
,
1119 "platform_guid" : self
.PlatformInfo
.Guid
,
1120 "platform_version" : self
.PlatformInfo
.Version
,
1121 "platform_relative_directory": self
.PlatformInfo
.SourceDir
,
1122 "platform_output_directory" : self
.PlatformInfo
.OutputDir
,
1123 "platform_dir" : self
._AutoGenObject
.Macros
["PLATFORM_DIR"],
1125 "module_name" : self
._AutoGenObject
.Name
,
1126 "module_guid" : self
._AutoGenObject
.Guid
,
1127 "module_name_guid" : self
._AutoGenObject
._GetUniqueBaseName
(),
1128 "module_version" : self
._AutoGenObject
.Version
,
1129 "module_type" : self
._AutoGenObject
.ModuleType
,
1130 "module_file" : self
._AutoGenObject
.MetaFile
,
1131 "module_file_base_name" : self
._AutoGenObject
.MetaFile
.BaseName
,
1132 "module_relative_directory" : self
._AutoGenObject
.SourceDir
,
1133 "module_dir" : mws
.join (self
._AutoGenObject
.WorkspaceDir
, self
._AutoGenObject
.SourceDir
),
1135 "architecture" : self
._AutoGenObject
.Arch
,
1136 "toolchain_tag" : self
._AutoGenObject
.ToolChain
,
1137 "build_target" : self
._AutoGenObject
.BuildTarget
,
1139 "platform_build_directory" : self
.PlatformInfo
.BuildDir
,
1140 "module_build_directory" : self
._AutoGenObject
.BuildDir
,
1141 "module_output_directory" : self
._AutoGenObject
.OutputDir
,
1142 "module_debug_directory" : self
._AutoGenObject
.DebugDir
,
1144 "separator" : Separator
,
1145 "module_tool_definitions" : ToolsDef
,
1147 "shell_command_code" : self
._SHELL
_CMD
_[self
._FileType
].keys(),
1148 "shell_command" : self
._SHELL
_CMD
_[self
._FileType
].values(),
1150 "create_directory_command" : self
.GetCreateDirectoryCommand(self
.IntermediateDirectoryList
),
1151 "custom_makefile_content" : CustomMakefile
1154 return MakefileTemplateDict
1156 _TemplateDict
= property(_CreateTemplateDict
)
1158 ## PlatformMakefile class
1160 # This class encapsules makefie and its generation for platform. It uses
1161 # template to generate the content of makefile. The content of makefile will be
1162 # got from PlatformAutoGen object.
1164 class PlatformMakefile(BuildFile
):
1165 ## template used to generate the makefile for platform
1166 _TEMPLATE_
= TemplateString('''\
1170 # Platform Macro Definition
1172 PLATFORM_NAME = ${platform_name}
1173 PLATFORM_GUID = ${platform_guid}
1174 PLATFORM_VERSION = ${platform_version}
1175 PLATFORM_FILE = ${platform_file}
1176 PLATFORM_DIR = $(platform_dir)
1177 PLATFORM_OUTPUT_DIR = ${platform_output_directory}
1180 # Build Configuration Macro Definition
1182 TOOLCHAIN = ${toolchain_tag}
1183 TOOLCHAIN_TAG = ${toolchain_tag}
1184 TARGET = ${build_target}
1187 # Build Directory Macro Definition
1189 BUILD_DIR = ${platform_build_directory}
1190 FV_DIR = ${platform_build_directory}${separator}FV
1193 # Shell Command Macro
1195 ${BEGIN}${shell_command_code} = ${shell_command}
1199 MAKE_FILE = ${makefile_path}
1204 all: init build_libraries build_modules
1207 # Initialization target: print build information and create necessary directories
1210 \t-@echo Building ... $(PLATFORM_FILE) [${build_architecture_list}]
1211 \t${BEGIN}-@${create_directory_command}
1214 # library build target
1216 libraries: init build_libraries
1219 # module build target
1221 modules: init build_libraries build_modules
1224 # Build all libraries:
1227 ${BEGIN}\t@"$(MAKE)" $(MAKE_FLAGS) -f ${library_makefile_list} pbuild
1228 ${END}\t@cd $(BUILD_DIR)
1231 # Build all modules:
1234 ${BEGIN}\t@"$(MAKE)" $(MAKE_FLAGS) -f ${module_makefile_list} pbuild
1235 ${END}\t@cd $(BUILD_DIR)
1238 # Clean intermediate files
1241 \t${BEGIN}-@${library_build_command} clean
1242 \t${END}${BEGIN}-@${module_build_command} clean
1243 \t${END}@cd $(BUILD_DIR)
1246 # Clean all generated files except to makefile
1249 ${BEGIN}\t${cleanall_command}
1253 # Clean all library files
1256 \t${BEGIN}-@${library_build_command} cleanall
1257 \t${END}@cd $(BUILD_DIR)\n
1260 ## Constructor of PlatformMakefile
1262 # @param ModuleAutoGen Object of PlatformAutoGen class
1264 def __init__(self
, PlatformAutoGen
):
1265 BuildFile
.__init
__(self
, PlatformAutoGen
)
1266 self
.ModuleBuildCommandList
= []
1267 self
.ModuleMakefileList
= []
1268 self
.IntermediateDirectoryList
= []
1269 self
.ModuleBuildDirectoryList
= []
1270 self
.LibraryBuildDirectoryList
= []
1271 self
.LibraryMakeCommandList
= []
1273 # Compose a dict object containing information used to do replacement in template
1274 def _CreateTemplateDict(self
):
1275 Separator
= self
._SEP
_[self
._FileType
]
1277 PlatformInfo
= self
._AutoGenObject
1278 if "MAKE" not in PlatformInfo
.ToolDefinition
or "PATH" not in PlatformInfo
.ToolDefinition
["MAKE"]:
1279 EdkLogger
.error("build", OPTION_MISSING
, "No MAKE command defined. Please check your tools_def.txt!",
1280 ExtraData
="[%s]" % str(self
._AutoGenObject
))
1282 self
.IntermediateDirectoryList
= ["$(BUILD_DIR)"]
1283 self
.ModuleBuildDirectoryList
= self
.GetModuleBuildDirectoryList()
1284 self
.LibraryBuildDirectoryList
= self
.GetLibraryBuildDirectoryList()
1286 MakefileName
= self
._FILE
_NAME
_[self
._FileType
]
1287 LibraryMakefileList
= []
1288 LibraryMakeCommandList
= []
1289 for D
in self
.LibraryBuildDirectoryList
:
1290 D
= self
.PlaceMacro(D
, {"BUILD_DIR":PlatformInfo
.BuildDir
})
1291 Makefile
= os
.path
.join(D
, MakefileName
)
1292 Command
= self
._MAKE
_TEMPLATE
_[self
._FileType
] % {"file":Makefile
}
1293 LibraryMakefileList
.append(Makefile
)
1294 LibraryMakeCommandList
.append(Command
)
1295 self
.LibraryMakeCommandList
= LibraryMakeCommandList
1297 ModuleMakefileList
= []
1298 ModuleMakeCommandList
= []
1299 for D
in self
.ModuleBuildDirectoryList
:
1300 D
= self
.PlaceMacro(D
, {"BUILD_DIR":PlatformInfo
.BuildDir
})
1301 Makefile
= os
.path
.join(D
, MakefileName
)
1302 Command
= self
._MAKE
_TEMPLATE
_[self
._FileType
] % {"file":Makefile
}
1303 ModuleMakefileList
.append(Makefile
)
1304 ModuleMakeCommandList
.append(Command
)
1306 MakefileTemplateDict
= {
1307 "makefile_header" : self
._FILE
_HEADER
_[self
._FileType
],
1308 "makefile_path" : os
.path
.join("$(BUILD_DIR)", MakefileName
),
1309 "make_path" : PlatformInfo
.ToolDefinition
["MAKE"]["PATH"],
1310 "makefile_name" : MakefileName
,
1311 "platform_name" : PlatformInfo
.Name
,
1312 "platform_guid" : PlatformInfo
.Guid
,
1313 "platform_version" : PlatformInfo
.Version
,
1314 "platform_file" : self
._AutoGenObject
.MetaFile
,
1315 "platform_relative_directory": PlatformInfo
.SourceDir
,
1316 "platform_output_directory" : PlatformInfo
.OutputDir
,
1317 "platform_build_directory" : PlatformInfo
.BuildDir
,
1318 "platform_dir" : self
._AutoGenObject
.Macros
["PLATFORM_DIR"],
1320 "toolchain_tag" : PlatformInfo
.ToolChain
,
1321 "build_target" : PlatformInfo
.BuildTarget
,
1322 "shell_command_code" : self
._SHELL
_CMD
_[self
._FileType
].keys(),
1323 "shell_command" : self
._SHELL
_CMD
_[self
._FileType
].values(),
1324 "build_architecture_list" : self
._AutoGenObject
.Arch
,
1325 "architecture" : self
._AutoGenObject
.Arch
,
1326 "separator" : Separator
,
1327 "create_directory_command" : self
.GetCreateDirectoryCommand(self
.IntermediateDirectoryList
),
1328 "cleanall_command" : self
.GetRemoveDirectoryCommand(self
.IntermediateDirectoryList
),
1329 "library_makefile_list" : LibraryMakefileList
,
1330 "module_makefile_list" : ModuleMakefileList
,
1331 "library_build_command" : LibraryMakeCommandList
,
1332 "module_build_command" : ModuleMakeCommandList
,
1335 return MakefileTemplateDict
1337 ## Get the root directory list for intermediate files of all modules build
1339 # @retval list The list of directory
1341 def GetModuleBuildDirectoryList(self
):
1343 for ModuleAutoGen
in self
._AutoGenObject
.ModuleAutoGenList
:
1344 if not ModuleAutoGen
.IsBinaryModule
:
1345 DirList
.append(os
.path
.join(self
._AutoGenObject
.BuildDir
, ModuleAutoGen
.BuildDir
))
1348 ## Get the root directory list for intermediate files of all libraries build
1350 # @retval list The list of directory
1352 def GetLibraryBuildDirectoryList(self
):
1354 for LibraryAutoGen
in self
._AutoGenObject
.LibraryAutoGenList
:
1355 if not LibraryAutoGen
.IsBinaryModule
:
1356 DirList
.append(os
.path
.join(self
._AutoGenObject
.BuildDir
, LibraryAutoGen
.BuildDir
))
1359 _TemplateDict
= property(_CreateTemplateDict
)
1361 ## TopLevelMakefile class
1363 # This class encapsules makefie and its generation for entrance makefile. It
1364 # uses template to generate the content of makefile. The content of makefile
1365 # will be got from WorkspaceAutoGen object.
1367 class TopLevelMakefile(BuildFile
):
1368 ## template used to generate toplevel makefile
1369 _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}''')
1371 ## Constructor of TopLevelMakefile
1373 # @param Workspace Object of WorkspaceAutoGen class
1375 def __init__(self
, Workspace
):
1376 BuildFile
.__init
__(self
, Workspace
)
1377 self
.IntermediateDirectoryList
= []
1379 # Compose a dict object containing information used to do replacement in template
1380 def _CreateTemplateDict(self
):
1381 Separator
= self
._SEP
_[self
._FileType
]
1383 # any platform autogen object is ok because we just need common information
1384 PlatformInfo
= self
._AutoGenObject
1386 if "MAKE" not in PlatformInfo
.ToolDefinition
or "PATH" not in PlatformInfo
.ToolDefinition
["MAKE"]:
1387 EdkLogger
.error("build", OPTION_MISSING
, "No MAKE command defined. Please check your tools_def.txt!",
1388 ExtraData
="[%s]" % str(self
._AutoGenObject
))
1390 for Arch
in PlatformInfo
.ArchList
:
1391 self
.IntermediateDirectoryList
.append(Separator
.join(["$(BUILD_DIR)", Arch
]))
1392 self
.IntermediateDirectoryList
.append("$(FV_DIR)")
1394 # TRICK: for not generating GenFds call in makefile if no FDF file
1396 if PlatformInfo
.FdfFile
!= None and PlatformInfo
.FdfFile
!= "":
1397 FdfFileList
= [PlatformInfo
.FdfFile
]
1398 # macros passed to GenFds
1399 MacroList
.append('"%s=%s"' % ("EFI_SOURCE", GlobalData
.gEfiSource
.replace('\\', '\\\\')))
1400 MacroList
.append('"%s=%s"' % ("EDK_SOURCE", GlobalData
.gEdkSource
.replace('\\', '\\\\')))
1402 MacroDict
.update(GlobalData
.gGlobalDefines
)
1403 MacroDict
.update(GlobalData
.gCommandLineDefines
)
1404 MacroDict
.pop("EFI_SOURCE", "dummy")
1405 MacroDict
.pop("EDK_SOURCE", "dummy")
1406 for MacroName
in MacroDict
:
1407 if MacroDict
[MacroName
] != "":
1408 MacroList
.append('"%s=%s"' % (MacroName
, MacroDict
[MacroName
].replace('\\', '\\\\')))
1410 MacroList
.append('"%s"' % MacroName
)
1414 # pass extra common options to external program called in makefile, currently GenFds.exe
1416 LogLevel
= EdkLogger
.GetLevel()
1417 if LogLevel
== EdkLogger
.VERBOSE
:
1418 ExtraOption
+= " -v"
1419 elif LogLevel
<= EdkLogger
.DEBUG_9
:
1420 ExtraOption
+= " -d %d" % (LogLevel
- 1)
1421 elif LogLevel
== EdkLogger
.QUIET
:
1422 ExtraOption
+= " -q"
1424 if GlobalData
.gCaseInsensitive
:
1425 ExtraOption
+= " -c"
1427 if GlobalData
.gIgnoreSource
:
1428 ExtraOption
+= " --ignore-sources"
1430 MakefileName
= self
._FILE
_NAME
_[self
._FileType
]
1431 SubBuildCommandList
= []
1432 for A
in PlatformInfo
.ArchList
:
1433 Command
= self
._MAKE
_TEMPLATE
_[self
._FileType
] % {"file":os
.path
.join("$(BUILD_DIR)", A
, MakefileName
)}
1434 SubBuildCommandList
.append(Command
)
1436 MakefileTemplateDict
= {
1437 "makefile_header" : self
._FILE
_HEADER
_[self
._FileType
],
1438 "makefile_path" : os
.path
.join("$(BUILD_DIR)", MakefileName
),
1439 "make_path" : PlatformInfo
.ToolDefinition
["MAKE"]["PATH"],
1440 "platform_name" : PlatformInfo
.Name
,
1441 "platform_guid" : PlatformInfo
.Guid
,
1442 "platform_version" : PlatformInfo
.Version
,
1443 "platform_build_directory" : PlatformInfo
.BuildDir
,
1444 "conf_directory" : GlobalData
.gConfDirectory
,
1446 "toolchain_tag" : PlatformInfo
.ToolChain
,
1447 "build_target" : PlatformInfo
.BuildTarget
,
1448 "shell_command_code" : self
._SHELL
_CMD
_[self
._FileType
].keys(),
1449 "shell_command" : self
._SHELL
_CMD
_[self
._FileType
].values(),
1450 'arch' : list(PlatformInfo
.ArchList
),
1451 "build_architecture_list" : ','.join(PlatformInfo
.ArchList
),
1452 "separator" : Separator
,
1453 "create_directory_command" : self
.GetCreateDirectoryCommand(self
.IntermediateDirectoryList
),
1454 "cleanall_command" : self
.GetRemoveDirectoryCommand(self
.IntermediateDirectoryList
),
1455 "sub_build_command" : SubBuildCommandList
,
1456 "fdf_file" : FdfFileList
,
1457 "active_platform" : str(PlatformInfo
),
1458 "fd" : PlatformInfo
.FdTargetList
,
1459 "fv" : PlatformInfo
.FvTargetList
,
1460 "cap" : PlatformInfo
.CapTargetList
,
1461 "extra_options" : ExtraOption
,
1462 "macro" : MacroList
,
1465 return MakefileTemplateDict
1467 ## Get the root directory list for intermediate files of all modules build
1469 # @retval list The list of directory
1471 def GetModuleBuildDirectoryList(self
):
1473 for ModuleAutoGen
in self
._AutoGenObject
.ModuleAutoGenList
:
1474 if not ModuleAutoGen
.IsBinaryModule
:
1475 DirList
.append(os
.path
.join(self
._AutoGenObject
.BuildDir
, ModuleAutoGen
.BuildDir
))
1478 ## Get the root directory list for intermediate files of all libraries build
1480 # @retval list The list of directory
1482 def GetLibraryBuildDirectoryList(self
):
1484 for LibraryAutoGen
in self
._AutoGenObject
.LibraryAutoGenList
:
1485 if not LibraryAutoGen
.IsBinaryModule
:
1486 DirList
.append(os
.path
.join(self
._AutoGenObject
.BuildDir
, LibraryAutoGen
.BuildDir
))
1489 _TemplateDict
= property(_CreateTemplateDict
)
1491 # This acts like the main() function for the script, unless it is 'import'ed into another script.
1492 if __name__
== '__main__':