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