d1d2f03cd7dbd76a3482976de259a57834354269
[people/mcb30/basetools.git] / Source / Python / AutoGen / GenMake.py
1 #!/usr/bin/env python\r
2 \r
3 """Create makefile for MS nmake and GNU make"""\r
4 \r
5 import os, sys, string, re\r
6 import os.path as path\r
7 \r
8 from SequentialDict import *\r
9 from EdkIIWorkspaceBuild import *\r
10 from EdkIIWorkspace import *\r
11 from BuildInfo import *\r
12 from BuildToolError import *\r
13 \r
14 gDependencyDatabase = {}    # file path : [dependent files list]\r
15 gIncludePattern = re.compile("^[ \t#]*include[ \t]+[\"<]*([^\"<>]+)[>\" \t\n\r]*", re.MULTILINE | re.UNICODE)\r
16 \r
17 class AutoGenString(object):\r
18     def __init__(self):\r
19         self.String = ''\r
20 \r
21     def __str__(self):\r
22         return self.String\r
23 \r
24     def Append(self, AppendString, Dictionary=None):\r
25         if Dictionary == None:\r
26             self.String += AppendString\r
27         else:\r
28             while AppendString.find('${BEGIN}') >= 0:\r
29                 Start = AppendString.find('${BEGIN}')\r
30                 End   = AppendString.find('${END}')\r
31                 SubString = AppendString[AppendString.find('${BEGIN}'):AppendString.find('${END}')+6]\r
32                 \r
33                 RepeatTime = -1\r
34                 NewDict = {"BEGIN":"", "END":""}\r
35                 for Key in Dictionary:\r
36                     if SubString.find('$' + Key) >= 0 or SubString.find('${' + Key + '}') >= 0:\r
37                         Value = Dictionary[Key]\r
38                         if type(Value) != type([]):\r
39                             NewDict[Key] = Value\r
40                             continue\r
41                         if RepeatTime < 0:\r
42                             RepeatTime = len(Value)\r
43                         elif RepeatTime != len(Value):\r
44                             raise AutoGenError(msg=Key + " has different repeat time from others!")\r
45                         NewDict[Key] = ""\r
46 \r
47                 NewString = ''\r
48                 for Index in range(0, RepeatTime):\r
49                     for Key in NewDict:\r
50                         if Key == "BEGIN" or Key == "END" or type(Dictionary[Key]) != type([]):\r
51                             continue\r
52                         #print "###",Key\r
53                         NewDict[Key] = Dictionary[Key][Index]\r
54                     NewString += string.Template(SubString).safe_substitute(NewDict)\r
55                 AppendString = AppendString[0:Start] + NewString + AppendString[End + 6:]\r
56 \r
57             NewDict = {}\r
58             for Key in Dictionary:\r
59                 if type(Dictionary[Key]) == type([]):\r
60                     continue\r
61                 NewDict[Key] = Dictionary[Key]\r
62             self.String += string.Template(AppendString).safe_substitute(NewDict)\r
63 \r
64 \r
65 MakefileHeader = '''#\r
66 # DO NOT EDIT\r
67 # This file is auto-generated by build utility\r
68 #\r
69 # Module Name:\r
70 #\r
71 #   %s\r
72 #\r
73 # Abstract:\r
74 #\r
75 #   Auto-generated makefile for building module and libraries\r
76 #\r
77 '''\r
78 \r
79 LibraryMakeCommand = '''cd %(makedir)s\r
80 \t$(MAKE) $(MAKE_FLAGS) -f %(makefile)s %(target)s\r
81 \tcd $(MODULE_BUILD_DIR)'''\r
82 \r
83 gMakeType = ""\r
84 if sys.platform == "win32":\r
85     gMakeType = "nmake"\r
86 else:\r
87     gMakeType = "gmake"\r
88 \r
89 gMakefileName = {"nmake" : "Makefile", "gmake" : "GNUmakefile"}\r
90 \r
91 gDirectorySeparator = {"nmake" : "\\", "gmake" : "/"}\r
92 \r
93 gCreateDirectoryCommand = {"nmake" : "mkdir", "gmake" : "mkdir -p"}\r
94 gRemoveDirectoryCommand = {"nmake" : "rmdir /s /q", "gmake" : "rm -r -f"}\r
95 gRemoveFileCommand = {"nmake" : "del /f /q", "gmake" : "rm -f"}\r
96 \r
97 OutputFlag = {\r
98     ("MSFT", "CC", "OUTPUT")      :   "/Fo",\r
99     ("MSFT", "SLINK", "OUTPUT")   :   "/OUT:",\r
100     ("MSFT", "DLINK", "OUTPUT")   :   "/OUT:",\r
101     ("MSFT", "ASMLINK", "OUTPUT") :   "/OUT:",\r
102     ("MSFT", "PCH", "OUTPUT")     :   "/Fp",\r
103     ("MSFT", "ASM", "OUTPUT")     :   "/Fo",\r
104     \r
105     ("INTEL", "CC", "OUTPUT")          :   "/Fo",\r
106     ("INTEL", "SLINK", "OUTPUT")       :   "/OUT:",\r
107     ("INTEL", "DLINK", "OUTPUT")       :   "/OUT:",\r
108     ("INTEL", "ASMLINK", "OUTPUT")     :   "/OUT:",\r
109     ("INTEL", "PCH", "OUTPUT")         :   "/Fp",\r
110     ("INTEL", "ASM", "OUTPUT")         :   "/Fo",\r
111     ("INTEL", "IPF", "ASM", "OUTPUT")  :   "-o ",\r
112 \r
113     ("GCC", "CC", "OUTPUT")        :   "-o ",\r
114     ("GCC", "SLINK", "OUTPUT")     :   "-cr ",\r
115     ("GCC", "DLINK", "OUTPUT")     :   "-o ",\r
116     ("GCC", "ASMLINK", "OUTPUT")   :   "-o ",\r
117     ("GCC", "PCH", "OUTPUT")       :   "-o ",\r
118     ("GCC", "ASM", "OUTPUT")       :   "-o ",\r
119 \r
120     ("OUTPUT")                     : "-o "\r
121 }\r
122 \r
123 IncludeFlag = {"MSFT" : "/I", "GCC" : "-I"}\r
124 \r
125 gCustomMakefileTemplate = '''\r
126 ${makefile_header}\r
127 \r
128 #\r
129 # Platform Macro Definition\r
130 #\r
131 PLATFORM_NAME = ${platform_name}\r
132 PLATFORM_GUID = ${platform_guid}\r
133 PLATFORM_VERSION = ${platform_version}\r
134 PLATFORM_RELATIVE_DIR = ${platform_relative_directory}\r
135 PLATFORM_DIR = $(WORKSPACE)${separator}${platform_relative_directory}\r
136 PLATFORM_OUTPUT_DIR = ${platform_output_directory}\r
137 \r
138 #\r
139 # Package Macro Definition\r
140 #\r
141 PACKAGE_NAME = ${package_name}\r
142 PACKAGE_GUID = ${package_guid}\r
143 PACKAGE_VERSION = ${package_version}\r
144 PACKAGE_RELATIVE_DIR = ${package_relative_directory}\r
145 PACKAGE_DIR = $(WORKSPACE)${separator}${package_relative_directory}\r
146 \r
147 #\r
148 # Module Macro Definition\r
149 #\r
150 MODULE_NAME = ${module_name}\r
151 MODULE_GUID = ${module_guid}\r
152 MODULE_VERSION = ${module_version}\r
153 MODULE_TYPE = ${module_type}\r
154 MODULE_FILE_BASE_NAME = ${module_file_base_name}\r
155 BASE_NAME = $(MODULE_NAME)\r
156 MODULE_RELATIVE_DIR = ${module_relative_directory}\r
157 MODULE_DIR = $(WORKSPACE)${separator}${module_relative_directory}\r
158 \r
159 #\r
160 # Build Configuration Macro Definition\r
161 #\r
162 ARCH = ${architecture}\r
163 TOOLCHAIN_TAG = ${toolchain_tag}\r
164 TARGET = ${build_target}\r
165 \r
166 #\r
167 # Build Directory Macro Definition\r
168 #\r
169 PLATFORM_BUILD_DIR = ${platform_build_directory}\r
170 BUILD_DIR = ${platform_build_directory}${separator}${build_target}_${toolchain_tag}\r
171 BIN_DIR = $(BUILD_DIR)${separator}${architecture}\r
172 LIB_DIR = $(BIN_DIR)\r
173 MODULE_BUILD_DIR = $(BUILD_DIR)${separator}${architecture}${separator}${module_relative_directory}${separator}${module_file_base_name}\r
174 OUTPUT_DIR = $(MODULE_BUILD_DIR)${separator}OUTPUT\r
175 DEBUG_DIR = $(MODULE_BUILD_DIR)${separator}DEBUG\r
176 DEST_DIR_OUTPUT = $(OUTPUT_DIR)\r
177 DEST_DIR_DEBUG = $(DEBUG_DIR)\r
178 \r
179 #\r
180 # Default Tools Flags Macro Definition (from tools_def.txt by default)\r
181 #\r
182 ${BEGIN}DEFAULT_${tool_code}_FLAGS = ${default_tool_flags}\r
183 ${END}\r
184 \r
185 #\r
186 # Platform Tools Flags Macro Definition (from platform description file)\r
187 #\r
188 ${BEGIN}PLATFORM_${tool_code}_FLAGS = ${platform_tool_flags}\r
189 ${END}\r
190 \r
191 #\r
192 # Platform Tools Flags Macro Definition (from platform description file)\r
193 #\r
194 ${BEGIN}MODULE_${tool_code}_FLAGS = ${module_tool_flags}\r
195 ${END}\r
196 \r
197 #\r
198 # ToolsFlagMacro\r
199 #\r
200 ${BEGIN}${tool_code}_FLAGS = $(DEFAULT_${tool_code}_FLAGS) $(PLATFORM_${tool_code}_FLAGS) $(MODULE_${tool_code}_FLAGS)\r
201 ${END}\r
202 MAKE_FLAGS = /nologo\r
203 \r
204 #\r
205 # ToolsPathMacro\r
206 #\r
207 ${BEGIN}${tool_code} = ${tool_path}\r
208 ${END}\r
209 \r
210 ${custom_makefile_content}\r
211 \r
212 #\r
213 # Target used when called from platform makefile, which will bypass the build of dependent libraries\r
214 #\r
215 \r
216 pbuild: init all\r
217 \r
218 \r
219 #\r
220 # Target used for library build, which will bypass the build of dependent libraries\r
221 #\r
222 \r
223 lbuild: init all\r
224 \r
225 \r
226 #\r
227 # ModuleTarget\r
228 #\r
229 \r
230 mbuild: init all\r
231 \r
232 \r
233 #\r
234 # Initialization target: print build information and create necessary directories\r
235 #\r
236 init:\r
237 \t-@echo Building ... $(MODULE_NAME)-$(MODULE_VERSION) [$(ARCH)] in package $(PACKAGE_NAME)-$(PACKAGE_VERSION)\r
238 \t-${create_directory_command} $(DEBUG_DIR) > NUL 2>&1\r
239 \t-${create_directory_command} $(OUTPUT_DIR) > NUL 2>&1\r
240 \t${BEGIN}-${create_directory_command} $(OUTPUT_DIR)${separator}${directory_to_be_created} > NUL 2>&1\r
241 \t${END}\r
242 \r
243 '''\r
244 \r
245 gModuleMakefileTemplate = '''\r
246 ${makefile_header}\r
247 \r
248 #\r
249 # Platform Macro Definition\r
250 #\r
251 PLATFORM_NAME = ${platform_name}\r
252 PLATFORM_GUID = ${platform_guid}\r
253 PLATFORM_VERSION = ${platform_version}\r
254 PLATFORM_RELATIVE_DIR = ${platform_relative_directory}\r
255 PLATFORM_DIR = $(WORKSPACE)${separator}${platform_relative_directory}\r
256 PLATFORM_OUTPUT_DIR = ${platform_output_directory}\r
257 \r
258 #\r
259 # Package Macro Definition\r
260 #\r
261 PACKAGE_NAME = ${package_name}\r
262 PACKAGE_GUID = ${package_guid}\r
263 PACKAGE_VERSION = ${package_version}\r
264 PACKAGE_RELATIVE_DIR = ${package_relative_directory}\r
265 PACKAGE_DIR = $(WORKSPACE)${separator}${package_relative_directory}\r
266 \r
267 #\r
268 # Module Macro Definition\r
269 #\r
270 MODULE_NAME = ${module_name}\r
271 MODULE_GUID = ${module_guid}\r
272 MODULE_VERSION = ${module_version}\r
273 MODULE_TYPE = ${module_type}\r
274 MODULE_FILE_BASE_NAME = ${module_file_base_name}\r
275 BASE_NAME = $(MODULE_NAME)\r
276 MODULE_RELATIVE_DIR = ${module_relative_directory}\r
277 MODULE_DIR = $(WORKSPACE)${separator}${module_relative_directory}\r
278 \r
279 #\r
280 # Build Configuration Macro Definition\r
281 #\r
282 ARCH = ${architecture}\r
283 TOOLCHAIN_TAG = ${toolchain_tag}\r
284 TARGET = ${build_target}\r
285 \r
286 #\r
287 # Build Directory Macro Definition\r
288 #\r
289 PLATFORM_BUILD_DIR = ${platform_build_directory}\r
290 BUILD_DIR = ${platform_build_directory}${separator}${build_target}_${toolchain_tag}\r
291 BIN_DIR = $(BUILD_DIR)${separator}${architecture}\r
292 LIB_DIR = $(BIN_DIR)\r
293 MODULE_BUILD_DIR = $(BUILD_DIR)${separator}${architecture}${separator}${module_relative_directory}${separator}${module_file_base_name}\r
294 OUTPUT_DIR = $(MODULE_BUILD_DIR)${separator}OUTPUT\r
295 DEBUG_DIR = $(MODULE_BUILD_DIR)${separator}DEBUG\r
296 DEST_DIR_OUTPUT = $(OUTPUT_DIR)\r
297 DEST_DIR_DEBUG = $(DEBUG_DIR)\r
298 \r
299 #\r
300 # Default Tools Flags Macro Definition (from tools_def.txt by default)\r
301 #\r
302 ${BEGIN}DEFAULT_${tool_code}_FLAGS = ${default_tool_flags}\r
303 ${END}\r
304 \r
305 #\r
306 # Platform Tools Flags Macro Definition (from platform description file)\r
307 #\r
308 ${BEGIN}PLATFORM_${tool_code}_FLAGS = ${platform_tool_flags}\r
309 ${END}\r
310 \r
311 #\r
312 # Module Tools Flags Macro Definition (from platform/module description file)\r
313 #\r
314 ${BEGIN}MODULE_${tool_code}_FLAGS = ${module_tool_flags}\r
315 ${END}\r
316 \r
317 #\r
318 # Tools Flag Macro\r
319 #\r
320 ${BEGIN}${tool_code}_FLAGS = $(DEFAULT_${tool_code}_FLAGS) $(PLATFORM_${tool_code}_FLAGS) $(MODULE_${tool_code}_FLAGS)\r
321 ${END}\r
322 MAKE_FLAGS = /nologo\r
323 \r
324 #\r
325 # Tools Path Macro\r
326 #\r
327 ${BEGIN}${tool_code} = ${tool_path}\r
328 ${END}\r
329 \r
330 #\r
331 # Build Macro\r
332 #\r
333 SOURCE_FILES = ${BEGIN}$(MODULE_DIR)${separator}${source_file} \\\r
334                ${END}${BEGIN}$(DEBUG_DIR)${separator}${auto_generated_file}\r
335                ${END}\r
336 \r
337 INC = ${BEGIN}${include_path_prefix}$(WORKSPACE)${separator}${include_path} \\\r
338       ${END}\r
339 \r
340 OBJECTS = ${BEGIN}$(OUTPUT_DIR)${separator}${object_file} \\\r
341           ${END}\r
342 \r
343 LIBS = ${BEGIN}$(LIB_DIR)${separator}${library_file} \\\r
344        ${END}\r
345 \r
346 COMMON_DEPS = ${BEGIN}$(WORKSPACE)${separator}${common_dependency_file} \\\r
347               ${END}\r
348 \r
349 ENTRYPOINT = ${module_entry_point}\r
350 \r
351 #\r
352 # Target File Macro Definitions\r
353 #\r
354 PCH_FILE = $(OUTPUT_DIR)\$(MODULE_NAME).pch\r
355 LIB_FILE = $(LIB_DIR)\$(MODULE_NAME).lib\r
356 LLIB_FILE = $(OUTPUT_DIR)\$(MODULE_NAME)Local.lib\r
357 DLL_FILE = $(DEBUG_DIR)\$(MODULE_NAME).dll\r
358 EFI_FILE = $(OUTPUT_DIR)\$(MODULE_NAME).efi\r
359 \r
360 #\r
361 # Overridable Target Macro Definitions\r
362 #\r
363 INIT_TARGET = init\r
364 PCH_TARGET =\r
365 LLIB_TARGET = $(LLIB_FILE)\r
366 \r
367 #\r
368 # Default target, which will build dependent libraries in addition to source files\r
369 #\r
370 \r
371 all: ${build_type}\r
372 \r
373 \r
374 #\r
375 # Target used when called from platform makefile, which will bypass the build of dependent libraries\r
376 #\r
377 \r
378 pbuild: $(INIT_TARGET) $(PCH_TARGET) gen_obj $(LLIB_TARGET) $(EFI_FILE) $(DLL_FILE)\r
379 \r
380 \r
381 #\r
382 # Target used for library build, which will bypass the build of dependent libraries\r
383 #\r
384 \r
385 lbuild: $(INIT_TARGET) $(PCH_TARGET) gen_obj $(LIB_FILE)\r
386 \r
387 \r
388 #\r
389 # ModuleTarget\r
390 #\r
391 \r
392 mbuild: $(INIT_TARGET) gen_libs $(PCH_TARGET) gen_obj $(LLIB_TARGET) $(EFI_FILE) $(DLL_FILE)\r
393 \r
394 \r
395 #\r
396 # Initialization target: print build information and create necessary directories\r
397 #\r
398 init:\r
399 \t-@echo Building ... $(MODULE_NAME)-$(MODULE_VERSION) [$(ARCH)] in package $(PACKAGE_NAME)-$(PACKAGE_VERSION)\r
400 \t-${create_directory_command} $(DEBUG_DIR) > NUL 2>&1\r
401 \t-${create_directory_command} $(OUTPUT_DIR) > NUL 2>&1\r
402 \t${BEGIN}-${create_directory_command} $(OUTPUT_DIR)${separator}${directory_to_be_created} > NUL 2>&1\r
403 \t${END}\r
404 \r
405 #\r
406 # PCH Target\r
407 #\r
408 pch: $(PCH_FILE)\r
409 \r
410 \r
411 #\r
412 # Libs Target\r
413 #\r
414 libs: gen_libs\r
415 \r
416 \r
417 #\r
418 # Vfr Target\r
419 #\r
420 vfr: gen_vfr\r
421 \r
422 \r
423 #\r
424 # Obj Target\r
425 #\r
426 obj: $(PCH_TARGET) gen_obj\r
427 \r
428 \r
429 #\r
430 # LocalLib Target\r
431 #\r
432 locallib: $(PCH_TARGET) gen_obj $(LLIB_FILE)\r
433 \r
434 \r
435 #\r
436 # Dll Target\r
437 #\r
438 dll: gen_libs $(PCH_TARGET) gen_obj $(LLIB_TARGET) $(DLL_FILE)\r
439 \r
440 \r
441 #\r
442 # Efi Target\r
443 #\r
444 efi: gen_libs $(PCH_TARGET) gen_obj $(LLIB_TARGET) $(DLL_FILE) $(EFI_FILE)\r
445 \r
446 \r
447 #\r
448 # GenLibsTarget\r
449 #\r
450 gen_libs:\r
451 \t${BEGIN}cd $(BUILD_DIR)${separator}$(ARCH)${separator}${dependent_library_build_directory}\r
452 \t$(MAKE) $(MAKE_FLAGS)\r
453 \t${END}cd $(MODULE_BUILD_DIR)\r
454 \r
455 #\r
456 # GenVfrTarget\r
457 #\r
458 \r
459 gen_vfr:\r
460 \t@echo placeholder: processing vfr files\r
461 \r
462 #\r
463 # Phony targets for objects\r
464 #\r
465 \r
466 gen_obj: $(PCH_TARGET) $(OBJECTS)\r
467 \r
468 \r
469 #\r
470 # PCH file build target\r
471 #\r
472 \r
473 $(PCH_FILE): $(DEP_FILES)\r
474 \t$(PCH) $(CC_FLAGS) $(PCH_FLAGS) $(DEP_FILES)\r
475 \r
476 #\r
477 # Local Lib file build target\r
478 #\r
479 \r
480 $(LLIB_FILE): $(OBJECTS)\r
481 \t"$(SLINK)" $(SLINK_FLAGS) /OUT:$(LLIB_FILE) $(OBJECTS)\r
482 \r
483 #\r
484 # Library file build target\r
485 #\r
486 \r
487 $(LIB_FILE): $(OBJECTS)\r
488 \t"$(SLINK)" $(SLINK_FLAGS) /OUT:$(LIB_FILE) $(OBJECTS)\r
489 \r
490 #\r
491 # DLL file build target\r
492 #\r
493 \r
494 $(DLL_FILE): $(LIBS) $(LLIB_FILE)\r
495 \t"$(DLINK)" $(DLINK_FLAGS) /OUT:$(DLL_FILE) $(DLINK_SPATH) $(LIBS) $(LLIB_FILE)\r
496 \r
497 #\r
498 # EFI file build target\r
499 #\r
500 \r
501 $(EFI_FILE): $(LIBS) $(LLIB_FILE)\r
502 \t"$(DLINK)" $(DLINK_FLAGS) /OUT:$(EFI_FILE) $(DLINK_SPATH) $(LIBS) $(LLIB_FILE)\r
503 \tGenFw -e ${module_type} -o $(EFI_FILE) $(EFI_FILE)\r
504 \tcopy /y $(EFI_FILE) $(BIN_DIR)\r
505 \r
506 #\r
507 # Individual Object Build Targets\r
508 #\r
509 ${BEGIN}${object_build_target}\r
510 ${END}\r
511 \r
512 \r
513 #\r
514 # clean all intermediate files\r
515 #\r
516 \r
517 clean:\r
518 \t${remove_directory_command} $(OUTPUT_DIR) > NUL 2>&1\r
519 \r
520 #\r
521 # clean all generated files\r
522 #\r
523 \r
524 cleanall:\r
525 \t${remove_directory_command} $(OUTPUT_DIR) $(DEBUG_DIR) > NUL 2>&1\r
526 \t${remove_file_command} *.pdb *.idb > NUL 2>&1\r
527 \r
528 #\r
529 # clean pre-compiled header files\r
530 #\r
531 \r
532 cleanpch:\r
533 \t${remove_file_command} /f /q $(OUTPUT_DIR)\*.pch > NUL 2>&1\r
534 \r
535 #\r
536 # clean all dependent libraries built\r
537 #\r
538 \r
539 cleanlib:\r
540 \t${BEGIN}cd $(BUILD_DIR)${separator}$(ARCH)${separator}${dependent_library_build_directory}\r
541 \t$(MAKE) $(MAKE_FLAGS) cleanall\r
542 \t${END}cd $(MODULE_BUILD_DIR)\r
543 \r
544 '''\r
545 \r
546 gPlatformMakefileTemplate = '''\r
547 ${makefile_header}\r
548 \r
549 #\r
550 # Platform Macro Definition\r
551 #\r
552 PLATFORM_NAME = ${platform_name}\r
553 PLATFORM_GUID = ${platform_guid}\r
554 PLATFORM_VERSION = ${platform_version}\r
555 PLATFORM_DIR = $(WORKSPACE)${separator}${platform_relative_directory}\r
556 PLATFORM_OUTPUT_DIR = ${platform_output_directory}\r
557 \r
558 #\r
559 # Build Configuration Macro Definition\r
560 #\r
561 TOOLCHAIN_TAG = ${toolchain_tag}\r
562 TARGET = ${build_target}\r
563 MAKE_FLAGS = /nologo\r
564 \r
565 #\r
566 # Build Directory Macro Definition\r
567 #\r
568 BUILD_DIR = ${platform_build_directory}${separator}${build_target}_${toolchain_tag}\r
569 FV_DIR = ${platform_build_directory}${separator}${build_target}_${toolchain_tag}${separator}FV\r
570 \r
571 #\r
572 # Default target\r
573 #\r
574 all: init build_libraries build_modules build_fds\r
575 \r
576 #\r
577 # Initialization target: print build information and create necessary directories\r
578 #\r
579 init:\r
580 \t-@echo Building ... $(PLATFORM_NAME)-$(PLATFORM_VERSION) [${build_architecture_list}]\r
581 \t-${create_directory_command} $(FV_DIR) > NUL 2>&1\r
582 \t${BEGIN}-${create_directory_command} $(BUILD_DIR)${separator}${architecture} > NUL 2>&1\r
583 \t${END}\r
584 \t${BEGIN}-${create_directory_command} $(BUILD_DIR)${separator}${directory_to_be_created} > NUL 2>&1\r
585 \t${END}\r
586 #\r
587 # library build target\r
588 #\r
589 libraries: init build_libraries\r
590 \r
591 #\r
592 # module build target\r
593 #\r
594 modules: init build_libraries build_modules\r
595 \r
596 #\r
597 # Flash Device Image Target\r
598 #\r
599 fds: init build_libraries build_modules build_fds\r
600 \r
601 #\r
602 # Build all libraries:\r
603 #\r
604 build_libraries:\r
605 \t${BEGIN}cd $(WORKSPACE)${separator}${library_build_directory}\r
606 \t$(MAKE) $(MAKE_FLAGS) lbuild\r
607 \t${END}cd $(BUILD_DIR)\r
608 \r
609 #\r
610 # Build all modules:\r
611 #\r
612 build_modules:\r
613 \t${BEGIN}cd $(WORKSPACE)${separator}${module_build_directory}\r
614 \t$(MAKE) $(MAKE_FLAGS) pbuild\r
615 \t${END}cd $(BUILD_DIR)\r
616 \r
617 #\r
618 # Build Flash Device Image\r
619 #\r
620 build_fds:\r
621 \t-@echo Generating flash image, if any ...\r
622 ${BEGIN}\tGenFds -f ${fdf_file} -o $(BUILD_DIR) -p ${active_platform}${END}\r
623 \r
624 #\r
625 # run command for emulator platform only\r
626 #\r
627 run:\r
628 \tcd $(BUILD_DIR)${separator}IA32\r
629 \tSecMain\r
630 \tcd $(BUILD_DIR)\r
631 \r
632 #\r
633 # Clean intermediate files\r
634 #\r
635 clean:\r
636 \t${BEGIN}cd $(WORKSPACE)${separator}${library_build_directory}\r
637 \t$(MAKE) $(MAKE_FLAGS) clean\r
638 \t${END}${BEGIN}cd $(WORKSPACE)${separator}${module_build_directory}\r
639 \t$(MAKE) $(MAKE_FLAGS) clean\r
640 \t${END}cd $(BUILD_DIR)\r
641 \r
642 #\r
643 # Clean all generated files except to makefile\r
644 #\r
645 cleanall:\r
646 \t${remove_directory_command} $(FV_DIR) > NUL 2>&1\r
647 \t${BEGIN}${remove_directory_command} $(BUILD_DIR)${separator}${architecture} > NUL 2>&1\r
648 \t${END}\r
649 \r
650 #\r
651 # Clean all library files\r
652 #\r
653 cleanlib:\r
654 \t${BEGIN}cd $(WORKSPACE)${separator}${library_build_directory}\r
655 \t$(MAKE) $(MAKE_FLAGS) cleanall\r
656 \t${END}cd $(BUILD_DIR)\r
657 \r
658 '''\r
659 \r
660 class Makefile(object):\r
661     def __init__(self, info, opt):\r
662         if isinstance(info, ModuleBuildInfo):\r
663             self.ModuleInfo = info\r
664             self.PlatformInfo = info.PlatformInfo\r
665             self.PackageInfo = info.PackageInfo\r
666             self.ModuleBuild = True\r
667             \r
668             self.BuildType = "mbuild"\r
669             if self.ModuleInfo.IsLibrary:\r
670                 self.BuildType = "lbuild"\r
671                 \r
672             self.BuildFileList = []\r
673             self.ObjectFileList = []\r
674             self.ObjectBuildTargetList = []\r
675 \r
676             self.FileDependency = []\r
677             self.LibraryBuildCommandList = []\r
678             self.LibraryFileList = []\r
679             self.LibraryMakefileList = []\r
680             self.LibraryBuildDirectoryList = []\r
681 \r
682         elif type(info) == type({}):    # and isinstance(info, PlatformBuildInfo):\r
683             self.PlatformInfo = info\r
684             self.ModuleBuild = False\r
685             self.ModuleBuildCommandList = []\r
686             self.ModuleMakefileList = []\r
687             self.ModuleBuildDirectoryList = self.GetModuleBuildDirectoryList()\r
688             self.LibraryBuildDirectoryList = self.GetLibraryBuildDirectoryList()\r
689         else:\r
690             raise AutoGenError(msg="Non-buildable item:%s" % str(info))\r
691 \r
692         self.Opt = opt\r
693         self.BuildWithPch = opt["ENABLE_PCH"]\r
694         self.BuildWithLocalLib = opt["ENABLE_LOCAL_LIB"]\r
695         self.IntermediateDirectoryList = []\r
696 \r
697     def PrepareDirectory(self):\r
698         if self.ModuleBuild:\r
699             CreateDirectory(path.join(self.ModuleInfo.WorkspaceDir, self.PlatformInfo.BuildDir))\r
700             CreateDirectory(path.join(self.ModuleInfo.WorkspaceDir, self.ModuleInfo.BuildDir))\r
701             CreateDirectory(path.join(self.ModuleInfo.WorkspaceDir, self.ModuleInfo.DebugDir))\r
702 \r
703     def Generate(self, file=None, makeType=gMakeType):\r
704         if self.ModuleBuild:\r
705             return self.GenerateModuleMakefile(file, makeType)\r
706         else:\r
707             return self.GeneratePlatformMakefile(file, makeType)\r
708     \r
709     def GeneratePlatformMakefile(self, file=None, makeType=gMakeType):\r
710         separator = gDirectorySeparator[makeType]\r
711 \r
712         activePlatform = self.PlatformInfo.values()[0].Platform\r
713         platformInfo = self.PlatformInfo.values()[0]\r
714         \r
715         outputDir = platformInfo.OutputDir\r
716         if os.path.isabs(outputDir):\r
717             self.PlatformBuildDirectory = outputDir\r
718         else:\r
719             self.PlatformBuildDirectory = "$(WORKSPACE)" + separator + outputDir\r
720 \r
721         makefileName = gMakefileName[makeType]\r
722         makefileTemplateDict = {\r
723             "makefile_header"           : MakefileHeader % makefileName,\r
724             "platform_name"             : platformInfo.Name,\r
725             "platform_guid"             : platformInfo.Guid,\r
726             "platform_version"          : platformInfo.Version,\r
727             "platform_relative_directory": platformInfo.SourceDir,\r
728             "platform_output_directory" : platformInfo.OutputDir,\r
729             "platform_build_directory"  : self.PlatformBuildDirectory,\r
730 \r
731             "toolchain_tag"             : platformInfo.ToolChain,\r
732             "build_target"              : platformInfo.BuildTarget,\r
733             "build_architecture_list"   : " ".join(self.PlatformInfo.keys()),\r
734             "architecture"              : self.PlatformInfo.keys(),\r
735             "separator"                 : separator,\r
736             "create_directory_command"  : gCreateDirectoryCommand[makeType],\r
737             "remove_directory_command"  : gRemoveDirectoryCommand[makeType],\r
738             "remove_file_command"       : gRemoveFileCommand[makeType],\r
739             "directory_to_be_created"   : self.IntermediateDirectoryList,\r
740             "library_build_directory"   : self.LibraryBuildDirectoryList,\r
741             "module_build_directory"    : self.ModuleBuildDirectoryList,\r
742             "fdf_file"                  : platformInfo.FdfFileList,\r
743             "active_platform"           : activePlatform.DescFilePath\r
744         }\r
745 \r
746         self.PrepareDirectory()\r
747 \r
748         autoGenMakefile = AutoGenString()\r
749         autoGenMakefile.Append(gPlatformMakefileTemplate, makefileTemplateDict)\r
750         #print autoGenMakefile.String\r
751 \r
752         filePath = ""\r
753         if file == None:\r
754             filePath = path.join(platformInfo.WorkspaceDir, platformInfo.MakefileDir, makefileName)\r
755         else:\r
756             filePath = file\r
757 \r
758         self.SaveFile(filePath, str(autoGenMakefile))\r
759         return filePath\r
760 \r
761     def GenerateModuleMakefile(self, file=None, makeType=gMakeType):\r
762         if makeType in self.ModuleInfo.CustomMakefile and self.ModuleInfo.CustomMakefile[makeType] != "":\r
763             return self.GenerateCustomBuildMakefile(file, makeType)\r
764 \r
765         separator = gDirectorySeparator[makeType]\r
766 \r
767         if os.path.isabs(self.PlatformInfo.OutputDir):\r
768             self.PlatformBuildDirectory = self.PlatformInfo.OutputDir\r
769         else:\r
770             self.PlatformBuildDirectory = "$(WORKSPACE)" + separator + self.PlatformInfo.OutputDir\r
771 \r
772         self.ProcessSourceFileList(makeType)\r
773         self.ProcessDependentLibrary(makeType)\r
774 \r
775         entryPoint = "_ModuleEntryPoint"\r
776         if self.ModuleInfo.Arch == "EBC":\r
777             entryPoint = "EfiStart"\r
778 \r
779         defaultToolFlag = self.PlatformInfo.DefaultToolOption.values()\r
780         if self.ModuleInfo.ModuleType == "USER_DEFINED":\r
781             defaultToolFlag = ["" for p in defaultToolFlag]\r
782             \r
783         makefileName = gMakefileName[makeType]\r
784         makefileTemplateDict = {\r
785             "makefile_header"           : MakefileHeader % makefileName,\r
786             "platform_name"             : self.PlatformInfo.Name,\r
787             "platform_guid"             : self.PlatformInfo.Guid,\r
788             "platform_version"          : self.PlatformInfo.Version,\r
789             "platform_relative_directory": self.PlatformInfo.SourceDir,\r
790             "platform_output_directory" : self.PlatformInfo.OutputDir,\r
791 \r
792             "package_name"              : self.PackageInfo.Name,\r
793             "package_guid"              : self.PackageInfo.Guid,\r
794             "package_version"           : self.PackageInfo.Version,\r
795             "package_relative_directory": self.PackageInfo.SourceDir,\r
796 \r
797             "module_name"               : self.ModuleInfo.Name,\r
798             "module_guid"               : self.ModuleInfo.Guid,\r
799             "module_version"            : self.ModuleInfo.Version,\r
800             "module_type"               : self.ModuleInfo.ModuleType,\r
801             "module_file_base_name"     : self.ModuleInfo.FileBase,\r
802             "module_relative_directory" : self.ModuleInfo.SourceDir,\r
803 \r
804             "architecture"              : self.ModuleInfo.Arch,\r
805             "toolchain_tag"             : self.ModuleInfo.ToolChain,\r
806             "build_target"              : self.ModuleInfo.BuildTarget,\r
807 \r
808             "platform_build_directory"  : self.PlatformBuildDirectory,\r
809 \r
810             "separator"                 : separator,\r
811             "default_tool_flags"        : defaultToolFlag,\r
812             "platform_tool_flags"       : [self.PlatformInfo.BuildOption[tool] for tool in self.PlatformInfo.ToolPath],\r
813             "module_tool_flags"         : [self.ModuleInfo.BuildOption[tool] for tool in self.PlatformInfo.ToolPath],\r
814 \r
815             "tool_code"                 : self.PlatformInfo.ToolPath.keys(),\r
816             "tool_path"                 : self.PlatformInfo.ToolPath.values(),\r
817 \r
818             "module_entry_point"        : entryPoint,\r
819             "source_file"               : self.BuildFileList,\r
820             #"auto_generated_file"       : self.AutoGenBuildFileList,\r
821             "include_path_prefix"       : "-I",\r
822             "include_path"              : self.ModuleInfo.IncludePathList,\r
823             "object_file"               : self.ObjectFileList,\r
824             "library_file"              : self.LibraryFileList,\r
825             "common_dependency_file"    : self.CommonFileDependency,\r
826             "create_directory_command"  : gCreateDirectoryCommand[makeType],\r
827             "remove_directory_command"  : gRemoveDirectoryCommand[makeType],\r
828             "remove_file_command"       : gRemoveFileCommand[makeType],\r
829             "directory_to_be_created"   : self.IntermediateDirectoryList,\r
830             "dependent_library_build_directory" : self.LibraryBuildDirectoryList,\r
831             #"dependent_library_makefile"        : [path.join(bdir, makefileName) for bdir in self.LibraryBuildDirectoryList],\r
832             "object_build_target"               : self.ObjectBuildTargetList,\r
833             "build_type"                        : self.BuildType,\r
834         }\r
835         \r
836         self.PrepareDirectory()\r
837         \r
838         autoGenMakefile = AutoGenString()\r
839         autoGenMakefile.Append(gModuleMakefileTemplate, makefileTemplateDict)\r
840         #print autoGenMakefile.String\r
841         \r
842         filePath = ""\r
843         if file == None:\r
844             filePath = path.join(self.ModuleInfo.WorkspaceDir, self.ModuleInfo.MakefileDir, makefileName)\r
845         else:\r
846             filePath = file\r
847 \r
848         self.SaveFile(filePath, str(autoGenMakefile))\r
849         return filePath\r
850 \r
851     def GenerateCustomBuildMakefile(self, file=None, makeType=gMakeType):\r
852         separator = gDirectorySeparator[makeType]\r
853 \r
854         if os.path.isabs(self.PlatformInfo.OutputDir):\r
855             self.PlatformBuildDirectory = self.PlatformInfo.OutputDir\r
856         else:\r
857             self.PlatformBuildDirectory = "$(WORKSPACE)" + separator + self.PlatformInfo.OutputDir\r
858 \r
859         customMakefile = open(os.path.join(self.ModuleInfo.WorkspaceDir, self .ModuleInfo.CustomMakefile[makeType]), 'r').read()\r
860         \r
861         makefileName = gMakefileName[makeType]\r
862         makefileTemplateDict = {\r
863             "makefile_header"           : MakefileHeader % makefileName,\r
864             "platform_name"             : self.PlatformInfo.Name,\r
865             "platform_guid"             : self.PlatformInfo.Guid,\r
866             "platform_version"          : self.PlatformInfo.Version,\r
867             "platform_relative_directory": self.PlatformInfo.SourceDir,\r
868             "platform_output_directory" : self.PlatformInfo.OutputDir,\r
869 \r
870             "package_name"              : self.PackageInfo.Name,\r
871             "package_guid"              : self.PackageInfo.Guid,\r
872             "package_version"           : self.PackageInfo.Version,\r
873             "package_relative_directory": self.PackageInfo.SourceDir,\r
874 \r
875             "module_name"               : self.ModuleInfo.Name,\r
876             "module_guid"               : self.ModuleInfo.Guid,\r
877             "module_version"            : self.ModuleInfo.Version,\r
878             "module_type"               : self.ModuleInfo.ModuleType,\r
879             "module_file_base_name"     : self.ModuleInfo.FileBase,\r
880             "module_relative_directory" : self.ModuleInfo.SourceDir,\r
881 \r
882             "architecture"              : self.ModuleInfo.Arch,\r
883             "toolchain_tag"             : self.ModuleInfo.ToolChain,\r
884             "build_target"              : self.ModuleInfo.BuildTarget,\r
885 \r
886             "platform_build_directory"  : self.PlatformBuildDirectory,\r
887 \r
888             "separator"                 : separator,\r
889             "default_tool_flags"        : self.PlatformInfo.DefaultToolOption.values(),\r
890             "platform_tool_flags"       : self.PlatformInfo.BuildOption.values(),\r
891             "module_tool_flags"         : self.ModuleInfo.BuildOption.values(),\r
892 \r
893             "tool_code"                 : self.PlatformInfo.ToolPath.keys(),\r
894             "tool_path"                 : self.PlatformInfo.ToolPath.values(),\r
895 \r
896             "create_directory_command"  : "-@mkdir",\r
897             "directory_to_be_created"   : self.IntermediateDirectoryList,\r
898             "dependent_library_build_directory" : self.LibraryBuildDirectoryList,\r
899             "custom_makefile_content"   : customMakefile\r
900         }\r
901 \r
902         self.PrepareDirectory()\r
903 \r
904         autoGenMakefile = AutoGenString()\r
905         autoGenMakefile.Append(gCustomMakefileTemplate, makefileTemplateDict)\r
906         #print autoGenMakefile.String\r
907 \r
908         filePath = ""\r
909         if file == None:\r
910             filePath = path.join(self.ModuleInfo.WorkspaceDir, self.ModuleInfo.MakefileDir, makefileName)\r
911         else:\r
912             filePath = file\r
913 \r
914         self.SaveFile(filePath, str(autoGenMakefile))\r
915         return filePath\r
916 \r
917     def SaveFile(self, file, content):\r
918         # print "######",file,"######"\r
919         f = None\r
920         if os.path.exists(file):\r
921             f = open(file, 'r')\r
922             if content == f.read():\r
923                 f.close()\r
924                 return\r
925             f.close()\r
926         f = open(file, "w")\r
927         f.write(content)\r
928         f.close()\r
929 \r
930     def ProcessSourceFileList(self, makeType=gMakeType):\r
931         rule = self.PlatformInfo.BuildRule\r
932         separator = gDirectorySeparator[makeType]\r
933 \r
934         self.BuildFileList = []\r
935         self.ObjectFileList = []\r
936         self.ObjectBuildTargetList = []\r
937         self.AutoGenBuildFileList = []\r
938         self.IntermediateDirectoryList = []\r
939 \r
940         fileBuildTemplatetList = []\r
941         forceIncludedFile = []\r
942 \r
943         for f in self.ModuleInfo.AutoGenFileList:\r
944             fpath = path.join(self.ModuleInfo.DebugDir, f)\r
945             fdir = path.dirname(f)\r
946             if fdir == "":\r
947                 fdir = "."\r
948             fname = path.basename(f)\r
949             fbase, fext = path.splitext(fname)\r
950 \r
951             ftype = rule.FileTypeMapping[fext]\r
952             if ftype == "C-Header":\r
953                 forceIncludedFile.append(fpath)\r
954             if ftype not in rule.Makefile[makeType]:\r
955                 continue\r
956 \r
957             self.BuildFileList.append(fpath)\r
958             self.ObjectFileList.append(fdir + separator + fbase + ".obj")\r
959 \r
960             fileBuildTemplatetList.append({\r
961                                    "string" : rule.Makefile[makeType][ftype],\r
962                                    "ftype"  : ftype,\r
963                                    "fpath"  : fpath,\r
964                                    "fdir"   : fdir,\r
965                                    "fname"  : fname,\r
966                                    "fbase"  : fbase,\r
967                                    "fext"   : fext,\r
968                                    "fdep"   : "",\r
969                                    "sep"    : separator,\r
970                                    })\r
971 \r
972         fileList = self.ModuleInfo.SourceFileList\r
973         for f in fileList:\r
974             fpath = os.path.join(self.ModuleInfo.SourceDir, f)\r
975             fname = path.basename(f)\r
976             fbase, fext = path.splitext(fname)\r
977             fdir = path.dirname(f)\r
978             \r
979             if fdir == "":\r
980                 fdir = "."\r
981             elif fdir not in self.IntermediateDirectoryList:\r
982                 self.IntermediateDirectoryList.append(fdir)\r
983                 \r
984             ftype = rule.FileTypeMapping[fext]\r
985             if ftype not in rule.Makefile[makeType]:\r
986                 continue\r
987 \r
988             self.BuildFileList.append(fpath)\r
989             self.ObjectFileList.append(fdir + separator + fbase + ".obj")\r
990             \r
991             fileBuildTemplatetList.append({\r
992                                    "string" : rule.Makefile[makeType][ftype],\r
993                                    "ftype"  : ftype,\r
994                                    "fpath"  : fpath,\r
995                                    "fdir"   : fdir,\r
996                                    "fname"  : fname,\r
997                                    "fbase"  : fbase,\r
998                                    "fext"   : fext,\r
999                                    "fdep"   : "",\r
1000                                    "sep"    : separator,\r
1001                                    })\r
1002 \r
1003         #\r
1004         # Search dependency file list for each source file\r
1005         #\r
1006         self.FileDependency = self.GetFileDependency(forceIncludedFile)\r
1007         depSet = set(self.FileDependency.values()[0])\r
1008         for dep in self.FileDependency.values():\r
1009             depSet &= set(dep)\r
1010         #\r
1011         # Extract comman files list in the dependency files\r
1012         #\r
1013         self.CommonFileDependency = forceIncludedFile + list(depSet)\r
1014         for f in self.FileDependency:\r
1015             newDepSet = set(self.FileDependency[f])\r
1016             newDepSet -= depSet\r
1017             self.FileDependency[f] = list(newDepSet)\r
1018 \r
1019         #\r
1020         # Expand "fdep"\r
1021         #\r
1022         for template in fileBuildTemplatetList:\r
1023             makefileString = AutoGenString()\r
1024             template["fdep"] = self.FileDependency[template["fpath"]]\r
1025             makefileString.Append(template["string"], template)\r
1026             self.ObjectBuildTargetList.append(makefileString)\r
1027 \r
1028     def ProcessDependentLibrary(self, makeType=gMakeType):\r
1029         for libm in self.ModuleInfo.DependentLibraryList:\r
1030             libf = str(libm)\r
1031             libp = path.dirname(libf)\r
1032             base = path.basename(libf).split(".")[0]\r
1033             self.LibraryBuildDirectoryList.append(libp + gDirectorySeparator[makeType] + base)\r
1034             self.LibraryFileList.append(libm.BaseName + ".lib")\r
1035 \r
1036     def GetPlatformBuildDirectory(self):\r
1037         if os.path.isabs(self.PlatformInfo.OutputDir):\r
1038             return self.PlatformInfo.OutputDir\r
1039         else:\r
1040             return os.path.join("$(WORKSPACE)", self.PlatformInfo.OutputDir)\r
1041 \r
1042     def GetFileDependency(self, forceList):\r
1043         cwd = os.getcwd()\r
1044         os.chdir(self.ModuleInfo.WorkspaceDir)\r
1045         dependency = {}\r
1046         for f in self.BuildFileList:\r
1047             dependency[f] = self.GetDependencyList(f, forceList, self.ModuleInfo.IncludePathList)\r
1048         os.chdir(cwd)\r
1049         return dependency\r
1050 \r
1051     def GetDependencyList(self, file, forceList, searchPathList):\r
1052         cwd = os.getcwd()\r
1053         os.chdir(self.ModuleInfo.WorkspaceDir)\r
1054 \r
1055         EdkLogger.debug(EdkLogger.DEBUG_3, "Get dependency files for %s" % file)\r
1056         EdkLogger.debug(EdkLogger.DEBUG_2, "Including %s" % " ".join(forceList))\r
1057         fileStack = [file] + forceList\r
1058         dependencyList = []\r
1059         while len(fileStack) > 0:\r
1060             EdkLogger.debug(EdkLogger.DEBUG_2, "Stack %s" % "\n\t".join(fileStack))\r
1061             f = fileStack.pop()\r
1062 \r
1063             currentFileDependencyList = []\r
1064             if f in gDependencyDatabase:\r
1065                 currentFileDependencyList = gDependencyDatabase[f]\r
1066                 for dep in currentFileDependencyList:\r
1067                     if dep not in fileStack and dep not in dependencyList:\r
1068                         fileStack.append(dep)\r
1069             else:\r
1070                 fd = open(f, 'r')\r
1071                 fileContent = fd.read()\r
1072                 fd.close()\r
1073                 if len(fileContent) == 0:\r
1074                     continue\r
1075 \r
1076                 if fileContent[0] == 0xff or fileContent[0] == 0xfe:\r
1077                     fileContent = unicode(fileContent, "utf-16")\r
1078                 includedFileList = gIncludePattern.findall(fileContent)\r
1079 \r
1080                 currentFilePath = os.path.dirname(f)\r
1081                 for inc in includedFileList:\r
1082                     inc = os.path.normpath(inc)\r
1083                     for searchPath in [currentFilePath] + searchPathList:\r
1084                         filePath = os.path.join(searchPath, inc)\r
1085                         if not os.path.exists(filePath) or filePath in currentFileDependencyList:\r
1086                             continue\r
1087                         currentFileDependencyList.append(filePath)\r
1088                         if filePath not in fileStack and filePath not in dependencyList:\r
1089                             fileStack.append(filePath)\r
1090                         break\r
1091                     else:\r
1092                         #raise AutoGenError("%s included by %s was not found in any given path:\n\t%s" % (inc, f, "\n\t".join(searchPathList)))\r
1093                         EdkLogger.verbose("%s included by %s was not found in any given path:\n\t%s" % (inc, f, "\n\t".join(searchPathList)))\r
1094                 gDependencyDatabase[f] = currentFileDependencyList\r
1095             dependencyList.extend(currentFileDependencyList)\r
1096         dependencyList = list(set(dependencyList))  # remove duplicate ones\r
1097 \r
1098         os.chdir(cwd)\r
1099         dependencyList.append(file)\r
1100         return dependencyList\r
1101 \r
1102     def GetModuleBuildDirectoryList(self):\r
1103         dirList = []\r
1104         for arch in self.PlatformInfo:\r
1105             for ma in self.PlatformInfo[arch].ModuleAutoGenList:\r
1106                 dirList.append(ma.BuildInfo.BuildDir)\r
1107         return dirList\r
1108 \r
1109     def GetLibraryBuildDirectoryList(self):\r
1110         dirList = []\r
1111         for arch in self.PlatformInfo:\r
1112             for la in self.PlatformInfo[arch].LibraryAutoGenList:\r
1113                 dirList.append(la.BuildInfo.BuildDir)\r
1114         return dirList\r
1115 \r
1116 # This acts like the main() function for the script, unless it is 'import'ed into another\r
1117 # script.\r
1118 if __name__ == '__main__':\r
1119     print "Running Operating System =", sys.platform\r
1120     ewb = WorkspaceBuild()\r
1121     #print ewb.Build.keys()\r
1122     \r
1123     myArch = ewb.Build["IA32"].Arch\r
1124     #print myArch\r
1125 \r
1126     myBuild = ewb.Build["IA32"]\r
1127     \r
1128     myWorkspace = ewb\r
1129     apf = ewb.TargetTxt.TargetTxtDictionary["ACTIVE_PLATFORM"][0]\r
1130     myPlatform = myBuild.PlatformDatabase[os.path.normpath(apf)]\r
1131 \r
1132     for mf in myBuild.ModuleDatabase:\r
1133         #mf = "MdePkg\\Library\\BaseLib\\BaseLib.inf"\r
1134         #if mf in myPlatform.Modules and mf in myBuild.ModuleDatabase:\r
1135         #print mf\r
1136 \r
1137         myModule = myBuild.ModuleDatabase[mf]\r
1138 \r
1139         myPackage = FindModuleOwner(myModule.DescFilePath, myBuild.PackageDatabase)\r
1140 \r
1141         myToolchain = ewb.TargetTxt.TargetTxtDictionary["TOOL_CHAIN_TAG"][0]\r
1142         #print myToolchain\r
1143 \r
1144         myBuildTarget = ewb.TargetTxt.TargetTxtDictionary["TARGET"][0]\r
1145         #print myBuildTarget\r
1146 \r
1147         myBuildOption = {\r
1148             "ENABLE_PCH"        :   False,\r
1149             "ENABLE_LOCAL_LIB"  :   True,\r
1150         }\r
1151 \r
1152         myMakefile = Makefile(myModule, myPackage, myPlatform, myWorkspace, myToolchain, myBuildTarget,\r
1153                               myArch, myBuildOption, "nmake")\r
1154 \r
1155         myMakefile.NewGenerate()\r