b25f6d43dba5d4186541456c7b0043a8fcba6a9c
[efi/basetools/.git] / Source / Python / MigrationMsa2Inf / MigrationMsa2Inf.py
1 #!/usr/bin/env python
2 #
3 #
4 # Copyright (c) 2007, Intel Corporation
5 # All rights reserved. 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
9
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.
12
13
14 """ This program converts EDK II MSA files into EDK II Extended INF format files """
15
16 import os, re, sys, fnmatch, xml.dom.minidom
17 from optparse import OptionParser
18 from AutoGenExterns import *
19 from Common.XmlRoutines import  *             # XmlParseFile, XmlElement, XmlAttribute, XmlList, XmlElementData, XmlNode
20 from Common.EdkIIWorkspace import *
21
22 versionNumber = "0.9"
23 __version__ = "%prog Version " + versionNumber
24 __copyright__ = "Copyright (c) 2007, Intel Corporation  All rights reserved."
25
26 commonHeaderFilename = "CommonHeader.h"
27 entryPointFilename   = "EntryPoint.c"
28
29 AutoGenLibraryMapping = {
30     "HiiLib":"HiiLibFramework",
31     "EdkIfrSupportLib":"IfrSupportLibFramework",
32     "EdkScsiLib":"ScsiLib",
33     "EdkUsbLib":"UsbLib",
34     "EdkFvbServiceLib":"FvbServiceLib",
35     "EdkGraphicsLib":"GraphicsLib"
36     }
37     
38 def myOptionParser():
39     """ Argument Parser """
40     usage = "%prog [options] -f input_filename"
41     parser = OptionParser(usage=usage,description=__copyright__,version="%prog " + str(versionNumber))
42     parser.add_option("-f", "--file", dest="filename", help="Name of MSA file to convert")
43     parser.add_option("-o", "--output", dest="outfile", help="Specific Name of the INF file to create, otherwise it is the MSA filename with the extension repalced.")
44     parser.add_option("-a", "--auto", action="store_true", dest="autowrite", default=False, help="Automatically create output files and write the INF file")
45     parser.add_option("-i", "--interactive", action="store_true", dest="interactive", default=False, help="Set Interactive mode, user must approve each change.")
46     parser.add_option("-q", "--quiet", action="store_const", const=0, dest="verbose", help="Do not print any messages, just return either 0 for succes or 1 for failure")
47     parser.add_option("-v", "--verbose", action="count", dest="verbose", help="Do not print any messages, just return either 0 for succes or 1 for failure")
48     parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="Enable printing of debug messages.")
49     parser.add_option("-c", "--convert", action="store_true", dest="convert", default=False, help="Convert package: OldMdePkg->MdePkg EdkModulePkg->MdeModulePkg.")
50     parser.add_option("-e", "--event", action="store_true", dest="event", default=False, help="Enable handling of Exit Boot Services & Virtual Address Changed Event")
51     parser.add_option("-m", "--manual", action="store_true", dest="manual", default=False, help="Generate CommonHeader.txt, user picks up & copy it to a module common header")
52     parser.add_option("-w", "--workspace", dest="workspace", default=str(os.environ.get('WORKSPACE')), help="Specify workspace directory.")
53     (options, args) = parser.parse_args(sys.argv[1:])
54
55     return options,args
56
57
58 def openDatabase(f):
59     """ Parse XML in the FrameworkDatabase.db file pointed to by f """
60     if (options.debug and options.verbose > 1):
61         print "Opening the database file:", f
62     if os.path.exists(f):
63         fdb = XmlParseFile(f)
64     else:
65         return "None"
66     return fdb
67
68 def openSpd(s):
69     """ Parse XML in the SPD file pointed to by s """
70     if (options.debug and options.verbose > 1):
71         print "Opening the SPD file:", s
72     if os.path.exists(s):
73         spd = XmlParseFile(s)
74     else:
75         return "None"
76     return spd
77
78 def openMsa(m):
79     """ Parse XML in the MSA file pointed to by m """
80     if (options.debug and options.verbose > 1):
81         print "Opening the MSA file:", m
82     if os.path.exists(m):
83         msa = XmlParseFile(m)
84     else:
85         return "None"
86     return msa
87
88 def AddGuid(ArchList, CName, Usage):
89     """ Add a GUID to the Architecture array that the GUID is valid for. """
90     if "IA32" in ArchList:
91         GuidCNameIa32.insert(0, str("  %-45s # %s" % (CName, Usage)))
92     if "X64" in ArchList:
93         GuidCNameX64.insert(0, str("  %-45s # %s" % (CName, Usage)))
94     if "IPF" in ArchList:
95         GuidCNameIPF.insert(0, str("  %-45s # %s" % (CName, Usage)))
96     if "EBC" in ArchList:
97         GuidCNameEBC.insert(0, str("  %-45s # %s" % (CName, Usage)))
98     if "ALL" in ArchList:
99         GuidCName.insert(0, str("  %-45s # %s" % (CName, Usage)))
100
101
102 def removeDups(CN, ListName):
103     """ Remove Duplicate Entries from the Guid List passed in """
104     for Entry in ListName[:]:
105         if " " + CN + " " in Entry:
106             if (options.verbose > 1):
107                 print "Removing C Name %s Entry from Guids List." % (CN)
108             ListName.remove(Entry)
109
110 def chkArch(Archs):
111     """ Process the supported architectures passed in to combine if possible """
112     Archs = Archs.upper()
113     if (("IA32" in Archs) & ("X64" in Archs) & ("IPF" in Archs) & ("EBC" in Archs)):
114         Archs = "ALL"
115     if (len(Archs) == 0):
116         Archs = "ALL"
117     return Archs
118
119 def saveSourceFile(moduleDir, sourceFilename, sourceFileContents):
120     newFilename = os.path.join(moduleDir, sourceFilename)
121     
122     try:
123         f = open(newFilename, "w+")
124         f.write(sourceFileContents)
125         f.close()
126     except:
127         print "IO error in saving %s" % sourceFilename
128         
129     return sourceFilename
130
131 def openSourceFile(moduleDir, sourceFilename):
132     newFilename = os.path.join(moduleDir, sourceFilename)
133     sourceFileContents = ""
134     try:
135         f = open(newFilename, "r")
136         sourceFileContents = f.read()
137         f.close()
138     except:
139         print "IO error in opening %s" % sourceFilename
140         
141     return sourceFileContents
142
143 def MatchOption(eline, ToolChainFamily, Targets, Archs, ToolCode, Value):
144     IDs = eline.split("_")
145     
146     if len(IDs) < 5:
147         return []
148     
149     MatchedTargets = []
150     if (Targets[0] == "*") or IDs[0] in Targets:
151         MatchedTargets.append(IDs[0])
152     elif IDs[0] == "*":
153         MatchedTargets = Targets
154
155     MatchedArchs = []
156     if Archs[0] == "*" or IDs[2] in Archs:
157         MatchedArchs.append(IDs[2])
158     elif IDs[2] == "*":
159         MatchedArchs = Archs
160
161     if IDs[3] != ToolCode and IDs[3] != "*":
162         return []
163     
164     result = []
165     for arch in MatchedArchs:
166         for target in MatchedTargets:
167             line = "%s:%s_%s_%s_%s_FLAGS = %s" % (ToolChainFamily, target, IDs[1], arch, ToolCode, Value)
168             result.append(line)
169
170     return result
171         
172 def main():
173
174     AutoGenSource = ""
175     AutoGenHeader = ""
176     AutoGenDeclaration = ""
177     AutoGenModuleFolder = None
178
179     workspace = ""
180
181     if (options.workspace == None):
182         print "ERROR: E0000: WORKSPACE not defined.\n  Please set the WORKSPACE environment variable to the location of the EDK II install directory."
183         sys.exit(1)
184     else:
185         workspace = options.workspace
186         if (options.debug):
187             print "Using Workspace:", workspace
188
189     try:
190         options.verbose +=1
191     except:
192         options.verbose = 1
193         pass
194
195
196     FdbFile = ""
197     FdbPath = os.path.join(workspace, "Tools")
198     FdbPath = os.path.join(FdbPath, "Conf")
199     FdbPath = os.path.join(FdbPath, "FrameworkDatabase.db")
200     if os.path.exists(FdbPath):
201         FdbFile = FdbPath
202     else:
203         FdbPath = os.path.join(workspace, "Conf")
204         FdbPath = os.path.join(FdbPath, "FrameworkDatabase.db")
205         if os.path.exists(FdbPath):
206             FdbFile = FdbPath
207         else:
208             print "ERROR: E0001: WORKSPACE does not contain the FrameworkDatabase File.\n  Please run EdkSetup from the EDK II install directory.\n"
209             sys.exit(1)
210
211     Fdb = openDatabase(FdbFile)
212     if (Fdb == 'None'):
213         print "ERROR: E0002 Could not open the Framework Database file:", FdbFile
214         sys.exit(1)
215
216     if (options.debug):
217         print "FrameworkDataBase.db file:", FdbFile
218
219     #
220     InitializeAutoGen(workspace, Fdb)
221
222     if (options.filename):
223         filename = options.filename
224         if ((options.verbose > 1) | (options.autowrite)):
225             print "Filename:", filename
226     else:
227         print "ERROR: E0001 - You must specify an input filename"
228         sys.exit(1)
229
230     if (options.outfile):
231         outputFile = options.outfile
232     else:
233        outputFile = filename.replace('.msa', '.inf')
234
235     if ((options.verbose > 2) or (options.debug)):
236         print "Output Filename:", outputFile
237
238     Msa = openMsa(filename)
239     if (Msa == 'None'):
240         ## Maybe developer think WORKSPACE macro is the root directory of file name
241         ## So we will try to add WORKSPACE path into filename
242         MsaFileName = ""
243         MsaFileName = os.path.join(workspace, filename)
244         Msa = openMsa(MsaFileName)
245         if (Msa == 'None'):
246             print "ERROR: E0002: Could not open the file:", filename
247             sys.exit(1)
248
249     AutoGenModuleFolder = os.path.dirname(filename)
250         
251     MsaHeader = "/ModuleSurfaceArea/MsaHeader/"
252     MsaDefs = "/ModuleSurfaceArea/ModuleDefinitions/"
253     BaseName = str(XmlElement(Msa, MsaDefs + "OutputFileBasename")).strip()
254
255     if (len(BaseName) < 1):
256       BaseName = str(XmlElement(Msa, MsaHeader + "BaseName")).strip()
257       BaseName = re.sub(' ', '_', BaseName)
258
259     GuidValue = str(XmlElement(Msa, MsaHeader + "GuidValue")).strip()
260     VerString = str(XmlElement(Msa, MsaHeader + "Version")).strip()
261     ModType = str(XmlElement(Msa, MsaHeader + "ModuleType")).strip()
262     CopyRight = str(XmlElement(Msa, MsaHeader + "Copyright")).strip()
263     Abstract = str(XmlElement(Msa, MsaHeader + "Abstract")).strip()
264     Description = str(XmlElement(Msa, MsaHeader + "Description")).strip().replace("  ", " ").replace("  ", " ").replace("  ", " ")
265     if not CopyRight.find("2007"):
266         CopyRight = CopyRight.replace("2006", "2007")
267     License = str(XmlElement(Msa, MsaHeader + "License")).strip().replace("  ", " ")
268     MsaDefs = "/ModuleSurfaceArea/ModuleDefinitions/"
269     BinModule = ""
270     try:
271         BinModule = str(XmlElement(Msa, MsaDefs + "BinaryModule")).strip()
272     except:
273         pass
274
275     SupportedArchitectures = ""
276     try:
277         SupportedArchitectures = str(XmlElement(Msa, MsaDefs + "SupportedArchitectures")).strip()
278     except:
279         pass
280
281     DefinesComments = []
282     if (len(SupportedArchitectures) > 0):
283         DefinesComments.insert(0, "\n#\n# The following information is for reference only and not required by the build tools.\n#\n")
284         DefinesComments.append("#  VALID_ARCHITECTURES           = " + SupportedArchitectures + "\n")
285         DefinesComments.append("#\n")
286
287     MsaExtern = "/ModuleSurfaceArea/Externs/"
288     PcdIsDriver = ""
289     try:
290         PcdIsDriver = str(XmlElement(Msa, MsaExtern + "PcdIsDriver")).strip()
291     except:
292         pass
293
294     SpecList = []
295     List = []
296     try:
297         List = XmlList(Msa, MsaExtern + "Specification")
298     except:
299         pass
300
301     if (len(List) > 0):
302         for spec in List[:]:
303             SpecList.insert(0, str(XmlElementData(spec)).strip())
304
305     DriverModules = []
306     LibraryModules = []
307     Externlist = []
308     Flag = (DefinesComments == [])
309
310     # Data structure to insert autogen code
311     AutoGenDriverModel = []
312     AutoGenExitBootServices = []
313     AutoGenVirtualAddressChanged = []
314     AutoGenEntryPoint = ""
315     AutoGenUnload = ""
316     AutoGenGuid = []
317     AutoGenLibClass = []
318     AutoGenPackage = []
319     AutoGenSourceFiles = []
320     OldEntryPoint = ""
321     OldUnload = ""
322     
323     try:
324         Externlist = XmlList(Msa, MsaExtern + "Extern")
325     except:
326         pass
327
328     if (len(Externlist) > 0):
329         if (options.debug and options.verbose > 2):
330             print "In Extern Parsing Routine"
331         for extern in Externlist:
332             EntryPoint = ""
333             Unload = ""
334             DBinding = ""
335             CompName = ""
336             Diag = ""
337             Config = ""
338             Constr = ""
339             Destr = ""
340             CallBack = ""
341             lFlag = False
342             AutoGenDriverModelItem = []
343             try:
344                 EntryPoint = str(XmlElementData(extern.getElementsByTagName("ModuleEntryPoint")[0])).strip()
345                 AutoGenEntryPoint = EntryPoint
346                 #DriverModules.append("  %-30s = %s\n" % ("ENTRY_POINT" , EntryPoint))
347             except:
348                 pass
349
350             try:
351                 Unload = str(XmlElementData(extern.getElementsByTagName("ModuleUnloadImage")[0])).strip()
352                 AutoGenUnload = Unload
353                 DriverModules.append("  %-30s = %s\n" % ("UNLOAD_IMAGE", Unload))
354             except:
355                 pass
356
357             try:
358                 DBinding = str(XmlElementData(extern.getElementsByTagName("DriverBinding")[0])).strip()
359                 AutoGenDriverModelItem.append("&" + DBinding)
360                 DefinesComments.append("#  %-29s =  %-45s\n" % ("DRIVER_BINDING", DBinding))
361                 lFlag = True
362             except:
363                 pass
364
365             try:
366                 CompName = str(XmlElementData(extern.getElementsByTagName("ComponentName")[0])).strip()
367                 AutoGenDriverModelItem.append("&" + CompName)
368                 DefinesComments.append("#  %-29s =  %-45s\n" % ("COMPONENT_NAME", CompName))
369                 lFlag = True
370             except:
371                 if lFlag:
372                     AutoGenDriverModelItem.append("NULL")
373                 pass
374
375             try:
376                 Config = str(XmlElementData(extern.getElementsByTagName("DriverConfig")[0])).strip()
377                 AutoGenDriverModelItem.append("&" + Config)
378                 DefinesComments.append("#  %-29s =  %-45s\n" % ("DRIVER_CONFIG", Config))
379                 lFlag = True
380             except:
381                 if lFlag:
382                     AutoGenDriverModelItem.append("NULL")
383                 pass
384
385             try:
386                 Diag = str(XmlElementData(extern.getElementsByTagName("DriverDiag")[0])).strip()
387                 AutoGenDriverModelItem.append("&" + Diag)
388                 DefinesComments.append("#  %-29s =  %-45s\n" % ("DRIVER_DIAG", Diag))
389                 lFlag = True
390             except:
391                 if lFlag:
392                     AutoGenDriverModelItem.append("NULL")
393                 pass
394
395             if len(AutoGenDriverModelItem) > 0:
396                 AutoGenDriverModel.append(AutoGenDriverModelItem)
397                 
398             try:
399                 Constr = str(XmlElementData(extern.getElementsByTagName("Constructor")[0])).strip()
400                 LibraryModules.append("  %-30s = %s\n" % ("CONSTRUCTOR", Constr))
401             except:
402                 pass
403
404             try:
405                 Destr = str(XmlElementData(extern.getElementsByTagName("Destructor")[0])).strip()
406                 LibraryModules.append("  %-30s = %s\n" % ("DESTRUCTOR", Destr))
407             except:
408                 pass
409     
410             try:
411                 CallBack = str(XmlElement(extern, "Extern/SetVirtualAddressMapCallBack")).strip()
412                 if CallBack != "":
413                     AutoGenVirtualAddressChanged.append(CallBack)
414                     DefinesComments.append("#  %-29s =  %-45s\n" % ("VIRTUAL_ADDRESS_MAP_CALLBACK", CallBack))
415                     lFlag = True
416             except:
417
418                 pass
419
420             try:
421                 CallBack = str(XmlElement(extern, "Extern/ExitBootServicesCallBack")).strip()
422                 if CallBack != "":
423                     AutoGenExitBootServices.append(CallBack)
424                     DefinesComments.append("#  %-29s =  %-45s\n" % ("EXIT_BOOT_SERVICES_CALLBACK", CallBack))
425                     lFlag = True
426             except:
427                 pass
428
429        
430     Flag = False
431
432     """ Get the Module's custom build options """
433     MBOlines = []
434     MBO = "/ModuleSurfaceArea/ModuleBuildOptions/Options/Option"
435     mboList = []
436     try:
437         mboList = XmlList(Msa, MBO)
438     except:
439         pass
440
441     if (len(mboList) > 0):
442         for Option in mboList:
443             Targets = []
444             Archs = []
445
446             bt = ""
447             try:
448                 bt = str(Option.getAttribute("BuildTargets"))
449             except:
450                 pass
451
452             if (len(bt) > 0):
453                 if (re.findall(" ", bt) > 0):
454                     Targets = bt.split()
455                 else:
456                     Targets.insert(0, bt)
457             else:
458                 Targets.insert(0, "*")
459
460             if (options.debug and options.verbose > 2):
461                 print "Targets", len(Targets), Targets
462
463             pro = ""
464             try:
465                 pro = Option.getAttribute("SupArchList")
466                 if (re.findall(" ", pro) > 0):
467                     Archs = pro.split()
468                 elif (re.findall(",", pro) > 0):
469                     Archs = pro.split(",")
470             except:
471                 pass
472
473             if (len(pro) == 0):
474                 Archs.insert(0, "*")
475
476             if (options.debug and options.verbose > 2):
477                 print "Archs", len(Archs), Archs
478
479             ToolCode = ""
480             try:
481                 ToolCode = str(Option.getAttribute("ToolCode"))
482             except:
483                 pass
484
485             if (len(ToolCode) == 0):
486                 ToolCode="*"
487
488             value = ""
489             try:
490                 value = str(XmlElementData(Option))
491             except:
492                 pass
493             Tags = []
494             TagName = ""
495             try:
496                 TagName = str(Option.getAttribute("TagName"))
497             except:
498                 pass
499
500             if (len(TagName) > 0) :
501                 if (options.debug and options.verbose > 2):
502                     print "TagName was defined:", TagName
503                 Tags.insert(0, TagName)
504             else:
505                 if (options.debug and options.verbose > 2):
506                     print "TagName was NOT defined!"
507                 TagName = "*"
508                 Tags.insert(0, "*")
509
510             Family = ""
511             try:
512                 Family = str(Option.getAttribute("ToolChainFamily")).strip()
513             except:
514                 pass
515
516             if (len(Family) > 0):
517                 if (options.debug):
518                     print "Searching tools_def.txt for Tool Tags that belong to:", Family, "family"
519                 TCF = []
520                 tdFile = ""
521                 tdPath = os.path.join(workspace, "Tools")
522                 tdPath = os.path.join(tdPath, "Conf")
523                 tdPath = os.path.join(tdPath, "tools_def.txt")
524                 tdPath = tdPath.replace("\\", "/")
525                 if os.path.exists(tdPath):
526                     tdFile = tdPath
527                 else:
528                     tdPath = os.path.join(workspace, "Conf")
529                     tdPath = os.path.join(tdPath, "tools_def.txt")
530                     if os.path.exists(tdPath):
531                         tdFile = tdPath
532                     else:
533                         print "ERROR: E0001: WORKSPACE does not contain the tools_def.txt File.\n  Please run EdkSetup from the EDK II install directory.\n"
534                         sys.exit(1)
535
536                 if (options.debug and options.verbose > 2):
537                     print "Opening:", tdFile
538
539                 TagNameList = []
540                 tools_def = open(tdFile, "r")
541                 for tdline in tools_def:
542                     if "# " in tdline:
543                         continue
544                     if "FAMILY" in tdline:
545                         if (options.debug and options.verbose > 2):
546                             print "Testing for FAMILY:", Family, "in the line:", tdline.strip()
547                         if Family in tdline:
548                             enter = tdline.split("=")[0]
549                             if (options.debug and options.verbose > 2):
550                                 print "Adding TNL:", tdline
551                             TagNameList.insert(0, enter)
552                 tools_def.close()
553
554                 if (options.debug and options.verbose > 2):
555                     print "TagNameList:", TagNameList
556
557                 olinesSet = {}
558                 for eline in TagNameList:
559                     if "# " in eline:
560                         continue
561                     if (options.debug and options.verbose > 2):
562                         print "ToolsDef entry:", eline
563                         
564                     olines = MatchOption(eline, Family, Targets, Archs, ToolCode, value)
565                     for oline in olines:
566                         olinesSet[oline] = 1
567                         
568                 for oline in olinesSet:
569                     if (options.debug and options.verbose > 2):
570                         print "Adding:", str(oline)
571                     MBOlines.insert(0, oline)
572             else:
573                 for targ in Targets:
574                     for arch in Archs:
575                         oline = "  %s_%s_%s_%s_FLAGS = %s" % (targ, Tags[0], arch, str(ToolCode), str(Value))
576                         if (options.debug and options.verbose > 2):
577                             print "Adding:", str(oline)
578                         MBOlines.insert(0, oline)
579            
580
581
582
583             for tag in Tags:
584                 for targ in Targets:
585                     for arch in Archs:
586                         oline = "  " + str(targ) + "_" + str(tag) + "_" + str(arch) + "_" + str(ToolCode) + "_FLAGS  = " + str(value)
587                         if (options.debug and options.verbose > 2):
588                             print "Adding:", str(oline)
589                         #MBOlines.insert(0, oline)
590   
591
592     """ Get the Library Class information """
593     MsaLcDefs = "/ModuleSurfaceArea/LibraryClassDefinitions/LibraryClass"
594     LcDefList = []
595     try:
596         LcDefList = XmlList(Msa, MsaLcDefs)
597     except:
598         pass
599
600     IamLibrary = []
601     LibClassList = []
602     LibClassListIa32 = []
603     LibClassListX64 = []
604     LibClassListIpf = []
605     LibClassListEbc = []
606
607     
608     if (len(LcDefList) > 0):
609         for Lc in LcDefList:
610             lcKeyword = ""
611             try:
612                 lcKeyword = str(XmlElementData(Lc.getElementsByTagName("Keyword")[0]))
613             except:
614                 raise SyntaxError, "The MSA is not correctly formed, a Library Class Keyword Element is required"
615
616             lcUsage = ""
617             try:
618                 lcUsage = str(XmlAttribute(Lc, "Usage"))
619             except:
620                 raise SyntaxError, "The MSA is not correctly formed, a Usage Attribute is required for all Library Class Elements"
621
622             Archs = ""
623             try:
624                 Archs = str(XmlAttribute(Lc, "SupArchList"))
625             except:
626                 pass
627
628             Archs = chkArch(Archs)
629
630             if (options.debug and options.verbose > 2):
631                 print "Attr: ",  lcUsage, lcKeyword, Archs
632
633             if (options.convert):
634                 lcKeyword = AutoGenLibraryMapping.get(lcKeyword, lcKeyword)
635                 
636             if re.findall("PRODUCED", lcUsage, re.IGNORECASE):
637                 try:
638                     lcSupModList = ""
639
640                     try:
641                         lcSupModList = str(XmlAttribute(Lc, "SupModuleList"))
642                     except:
643                         lcSupModList = ""
644                     pass
645
646                     lcLine = lcKeyword
647                     AutoGenLibClass.append(lcKeyword)
648                     if len(lcSupModList) > 0:
649                         lcLine = lcLine + "|" + lcSupModList
650                     IamLibrary.insert(0, lcLine)
651                 except:
652                     pass
653             elif lcKeyword != "UefiDriverModelLib":
654                 AutoGenLibClass.append(lcKeyword)
655                 # This section handles the library classes that are CONSUMED
656                 if "IA32" in Archs:
657                     LibClassListIa32.insert(0, lcKeyword)
658                 if "X64" in Archs:
659                     LibClassListX64.insert(0, lcKeyword)
660                 if "IPF" in Archs:
661                     LibClassListIpf.insert(0, lcKeyword)
662                 if "EBC" in Archs:
663                     LibClassListEbc.insert(0, lcKeyword)
664                 if "ALL" in Archs:
665                     LibClassList.insert(0, lcKeyword)
666         if len(AutoGenDriverModel) > 0 and "UefiLib" not in LibClassList:
667             AutoGenLibClass.append("UefiLib")
668             LibClassList.insert(0, "UefiLib")
669     
670     AutoGenDxsFiles = []
671     """ Get the Source File list """
672     SrcFilenames = []
673     SrcFilenamesIa32 = []
674     SrcFilenamesX64 = []
675     SrcFilenamesIpf = []
676     SrcFilenamesEbc = []
677     SrcFiles = "/ModuleSurfaceArea/SourceFiles/Filename"
678     SrcList = []
679     try:
680         SrcList = XmlList(Msa, SrcFiles)
681     except:
682         pass
683
684     if (len(SrcList) > 0):
685         for fn in SrcList:
686             file = ""
687             Archs = ""
688
689             try:
690                 Archs = fn.getAttribute("SupArchList")
691             except:
692                 pass
693
694             Archs = chkArch(Archs)
695
696             try:
697                 file = str(XmlElementData(fn))
698             except:
699                 pass
700
701             if file.endswith(".dxs"):
702                 AutoGenDxsFiles.append((file, Archs))
703             else:
704                 AutoGenSourceFiles.append(file)
705                 if "IA32" in Archs:
706                     SrcFilenamesIa32.insert(0, file)
707                 if "X64" in Archs:
708                     SrcFilenamesX64.insert(0, file)
709                 if "IPF" in Archs:
710                     SrcFilenamesIpf.insert(0, file)
711                 if "EBC" in Archs:
712                     SrcFilenamesEbc.insert(0, file)
713                 if "ALL" in Archs:
714                     SrcFilenames.insert(0, file)
715
716     """ Package Dependency section """
717     DbPkgList = "/FrameworkDatabase/PackageList/Filename"
718     WorkspacePkgs = []
719     try:
720         WorkspacePkgs = XmlList(Fdb, DbPkgList)
721     except:
722         print "Could not tet the package data from the database"
723         sys.exit(1)
724
725     PkgDb = []
726     HeaderLocations = []
727
728     if (options.debug and options.verbose > 1):
729         print "Found %s packages in the WORKSPACE" % (len(WorkspacePkgs))
730
731     Dirs = []
732     GuidDecls = []
733     if (len(WorkspacePkgs) > 0):
734         SpdHeader = "/PackageSurfaceArea/SpdHeader/"
735         for Pkg in WorkspacePkgs[:]:
736             PackageGuid = ""
737             PackageVersion = ""
738             file = ""
739             try:
740                 file = str(XmlElementData(Pkg))
741             except:
742                 pass
743
744             if (options.debug and options.verbose > 2):
745                 print "PKG:", file
746
747             if fnmatch.fnmatch(file, "*.dec"):
748                 print "parsing " + os.path.join(workspace, file)
749                 PackageGuid = ""
750                 PackageVersion = ""
751                 try:
752                     Lines = open(os.path.join(workspace, file)).readlines()
753                 except:
754                     print "Could not parse the Package file:", file
755                     sys.exit(1)
756                     
757                 for Line in Lines:
758                     Line = Line.split("#")[0]
759                     Items = Line.split("=")
760                     if len(Items) != 2:
761                         continue
762
763                     Key = Items[0].strip().upper()
764                     if Key == "PACKAGE_GUID":
765                         PackageGuid = Items[1].strip()
766                     if Key == "PACKAGE_VERSION":
767                         PackageVersion = Items[1].strip()
768
769             else:
770                 Spd = openSpd(os.path.join(workspace, file))
771                 if (Spd == 'None'):
772                     print "Could not parse the Package file:", file
773                     sys.exit(1)
774
775                 path = os.path.split(file)[0]
776                 file = file.replace(".nspd", ".dec")
777                 file = file.replace(".spd", ".dec")
778
779                 try:
780                     PackageGuid = str(XmlElement(Spd, SpdHeader + "GuidValue"))
781                 except:
782                     pass
783
784                 try:
785                     PackageVersion = str(XmlElement(Spd, SpdHeader + "Version"))
786                 except:
787                     pass
788
789             file = file + "|" + PackageGuid + "|" + PackageVersion
790             PkgDb.insert(0, file)
791
792             GuidEntries = []
793             try:
794                 GuidEntries = XmlList(Spd, "/PackageSurfaceArea/GuidDeclarations/Entry")
795             except:
796                 pass
797
798             if (len(GuidEntries) > 0):
799                 for Entry in GuidEntries[:]:
800                     try:
801                         GuidDecls.append(str(XmlElementData(Entry.getElementsByTagName("C_Name")[0])).strip())
802                     except:
803                         pass
804
805        
806             pHdrs = []
807             try:
808                 pHdrs = XmlList(Spd, "/PackageSurfaceArea/PackageHeaders/IncludePkgHeader")
809             except:
810                 pass
811
812             if (len(pHdrs) > 0):
813                 for Hdr in pHdrs[:]:
814                     try:
815                         ModTypeList = str(Hdr.getAttribute("ModuleType"))
816                         if (ModType in ModTypeList):
817                             HeaderName= str(XmlElementData(Hdr))[0]
818                             Dirs.insert(0, os.path.join(packagepath,str(os.path.split(HeaderName))))
819                     except:
820                         pass
821
822             # Get the Guid:Header from the Packages
823             SpdLcDec = "/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass"
824             lcList = []
825             try:
826                 lcList = XmlList(Spd, SpdLcDec)
827             except:
828                 pass
829
830             if (len(lcList) > 0):
831                 for Lc in lcList[:]:
832                     Name = ""
833                     try:
834                         Name = Lc.getAttribute("Name")
835                     except:
836                         pass
837
838                     Header = ""
839                     try:
840                         Header = XmlElementData(Lc.getElementsByTagName("IncludeHeader")[0])
841                     except:
842                         pass
843
844                     if ((len(Name) > 0) and (len(Header) > 0)):
845                         line = Name + "|" + os.path.join(path, Header)
846                         if (options.debug and options.verbose > 2):
847                             print "Adding:", line
848                         HeaderLocations.insert(0, line)
849
850             ishList = []
851             try:
852                 IndStdHeaders = "/PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader"
853                 ishList = XmlList(Spd, IndStdHeaders)
854             except:
855                 pass
856
857             if (len(ishList) > 0):
858                 for Lc in ishList[:]:
859                     Name = ""
860                     try:
861                         Name = str(Lc.getAttribute("Name")).strip()
862                     except:
863                         pass
864
865                     Header = ""
866                     try:
867                         Header = str(XmlElementData(Lc.getElementsByTagName("IncludeHeader")[0])).strip()
868                     except:
869                         pass
870
871                     if ((len(Name) > 0) and (len(Header) > 0)):
872                         line = Name + "|" + os.path.join(path, Header)
873                         HeaderLocations.insert(0, str(line))
874
875     PkgList = []
876     PkgListIa32 = []
877     PkgListX64 = []
878     PkgListIpf = []
879     PkgListEbc = []
880     Pkgs = "/ModuleSurfaceArea/PackageDependencies/Package"
881     pkgL = []
882     try:
883        pkgL = XmlList(Msa, Pkgs)
884     except:
885        pass
886    
887
888     gUnknownPkgGuid = {}
889     if (len(pkgL) > 0):
890         if (options.debug and options.verbose > 1):
891             print "Found %s packages in the module" % (len(pkgL))
892         for pkg in pkgL[:]:
893             Archs = ""
894             pkgGuid = ""
895             pkgVer = ""
896             
897             FindPkgGuid = False
898             try:
899                 Archs = pkg.getAttribute("SupArchList")
900             except:
901                 pass
902
903             Archs = chkArch(Archs)
904
905             try:
906                 pkgGuid = pkg.getAttribute("PackageGuid")
907             except:
908                 pass
909
910             if options.convert:
911                 if pkgGuid.lower() == "5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec":
912                     pkgGuid = "1E73767F-8F52-4603-AEB4-F29B510B6766"
913                 if pkgGuid.lower() == "68169ab0-d41b-4009-9060-292c253ac43d":
914                     pkgGuid = "BA0D78D6-2CAF-414b-BD4D-B6762A894288"
915             AutoGenPackage.append(pkgGuid)
916             try:
917                 pkgVer = pkg.getAttribute("PackageVersion")
918             except:
919                 pass
920
921             for PkgEntry in PkgDb[:]:
922                 if pkgGuid in PkgEntry:
923                     if len(pkgVer) > 0:
924                         if pkgVer in PkgEntry:
925                             FindPkgGuid = True
926                             if "IA32" in Archs:
927                                 PkgListIa32.insert(0, PkgEntry.split("|")[0])
928                             if "X64" in Archs:
929                                 PkgListX64.insert(0, PkgEntry.split("|")[0])
930                             if "IPF" in Archs:
931                                 PkgListIpf.insert(0, PkgEntry.split("|")[0])
932                             if "EBC" in Archs:
933                                 PkgListEbc.insert(0, PkgEntry.split("|")[0])
934                             if "ALL" in Archs:
935                                 PkgList.insert(0, PkgEntry.split("|")[0])
936                     else:
937                         FindPkgGuid = True
938                         if "IA32" in Archs:
939                             PkgListIa32.insert(0, PkgEntry.split("|")[0])
940                         if "X64" in Archs:
941                             PkgListX64.insert(0, PkgEntry.split("|")[0])
942                         if "IPF" in Archs:
943                             PkgListIpf.insert(0, PkgEntry.split("|")[0])
944                         if "EBC" in Archs:
945                             PkgListEbc.insert(0, PkgEntry.split("|")[0])
946                         if "ALL" in Archs:
947                             PkgList.insert(0, PkgEntry.split("|")[0])
948
949             if not FindPkgGuid:
950                 gUnknownPkgGuid[str(pkgGuid)] = 1
951
952     for UnknownPkgGuid in gUnknownPkgGuid:
953         print "Cannot resolve package dependency Guid:", UnknownPkgGuid
954
955     PkgList.reverse()
956     PkgListIa32.reverse()
957     PkgListX64.reverse()
958     PkgListIpf.reverse()
959     PkgListEbc.reverse()
960     if (options.debug):
961         print "Package List:", PkgList
962
963
964     
965     """ Setup the Global GuidCName arrays that will hold data from various MSA locations """
966     global GuidCName
967     global GuidCNameIa32
968     global GuidCNameX64
969     global GuidCNameIPF
970     global GuidCNameEBC
971     GuidCName = []
972     GuidCNameIa32 = []
973     GuidCNameX64 = []
974     GuidCNameIPF = []
975     GuidCNameEBC = []
976
977     """ Check for the GUIDs Element """
978     Guids = "/ModuleSurfaceArea/Guids/GuidCNames"
979     GuidList = []
980     try:
981         GuidList = XmlList(Msa, Guids)
982     except:
983         pass
984
985     if (len(GuidList) > 0):
986         for Guid in GuidList:
987             Archs = ""
988             Usage = ""
989             CName = ""
990
991             try:
992                 Archs = Guid.getAttribute("SupArchList")
993             except:
994                 pass
995
996             Archs = chkArch(Archs)
997
998             try:
999                 Usage = Guid.getAttribute("Usage")
1000             except:
1001                 pass
1002
1003             try:
1004                 CName = str(XmlElementData(Guid.getElementsByTagName("GuidCName")[0]))
1005                 if CName in GuidDecls:
1006                     if (options.debug and options.verbose > 1):
1007                         print "Guids Adding Guid CName: %-45s # %s Archs: %s" % (CName, Usage, Archs)
1008                     AddGuid(Archs, CName, Usage)
1009                     AutoGenGuid.append(CName)
1010                 else:
1011                     raise AssertionError, "Guid %s defined in %s is not declared in any package (.dec) file!" % (CName, filename)
1012             except:
1013                 pass
1014
1015     if (options.debug and options.verbose > 2):
1016         print "Guid C Name List:", GuidCName
1017
1018     """ Check for Events """
1019     Guids = "/ModuleSurfaceArea/Events/CreateEvents/EventTypes"
1020     GuidList = []
1021     try:
1022         GuidList = XmlList(Msa, Guids)
1023     except:
1024         pass
1025
1026     if (len(GuidList) > 0):
1027         for Guid in GuidList:
1028             Archs = ""
1029             Usage = ""
1030             CName = ""
1031
1032             try:
1033                 Archs = Guid.getAttribute("SupArchList")
1034             except:
1035                 pass
1036
1037             Archs = chkArch(Archs)
1038
1039             try:
1040                 Usage = Guid.getAttribute("Usage")
1041                 Type = str(XmlElementData(Guid.getElementsByTagName("EventType")[0]))
1042                 Usage += "  Create Event: " + Type
1043             except:
1044                 pass
1045
1046             try:
1047                 CName = str(Guid.getAttribute("EventGuidCName"))
1048                 if CName in GuidDecls:
1049                     if (options.debug and options.verbose > 1):
1050                         print "CreateEvent Adding Guid CName: %-45s # %s Archs: %s" % (CName, Usage, Archs)
1051                     AddGuid(Archs, CName, Usage)
1052                     AutoGenGuid.append(CName)
1053                 else:
1054                     if (len(DefinesComments) == 0):
1055                         DefinesComments.insert(0, "\n#\n# The following information is for reference only and not required by the build tools.\n#\n")
1056                     DefinesComments.append("#  Create Event Guid C Name: " + CName + " Event Type: " + Type + "\n")
1057                     Flag = True
1058             except:
1059                 pass
1060
1061     if (Flag):
1062         DefinesComments.append("#\n")
1063         Flag = False
1064
1065     Guids = "/ModuleSurfaceArea/Events/SignalEvents/EventTypes"
1066     GuidList = []
1067     try:
1068         GuidList = XmlList(Msa, Guids)
1069     except:
1070         pass
1071
1072     if (len(GuidList) > 0):
1073         for Guid in GuidList:
1074             Archs = ""
1075             Usage = ""
1076             CName = ""
1077
1078             try:
1079                 Archs = Guid.getAttribute("SupArchList")
1080             except:
1081                 pass
1082
1083             Archs = chkArch(Archs)
1084
1085             try:
1086                 Usage = Guid.getAttribute("Usage")
1087                 Type = str(XmlElementData(Guid.getElementsByTagName("EventType")[0]))
1088                 Usage += "  Signal Event: " + Type
1089             except:
1090                 pass
1091
1092             try:
1093                 CName = str(Guid.getAttribute("EventGuidCName"))
1094                 if CName in GuidDecls:
1095                     if (options.debug and options.verbose > 1):
1096                         print "SignalEvent Adding Guid CName: %-45s # %s Archs: %s" % (CName, Usage, Archs)
1097                     AddGuid(Archs, CName, Usage)
1098                     AutoGenGuid.append(CName)
1099                 else:
1100                     if (len(DefinesComments) == 0):
1101                         DefinesComments.insert(0, "\n#\n# The following information is for reference only and not required by the build tools.\n#\n")
1102                     DefinesComments.append("#  Signal Event Guid C Name: " + CName + " Event Type: " + Type + "\n")
1103                     Flag = True
1104             except:
1105                 pass
1106
1107     if (Flag):
1108         DefinesComments.append("#\n")
1109         Flag = False
1110
1111     """ Check the HOB guids """
1112     Guids = "/ModuleSurfaceArea/Hobs/HobTypes"
1113     GuidList = []
1114     try:
1115         GuidList = XmlList(Msa, Guids)
1116     except:
1117         pass
1118
1119     if (len(GuidList) > 0):
1120         for Guid in GuidList:
1121             Archs = ""
1122             Usage = ""
1123             CName = ""
1124
1125             try:
1126                 Archs = Guid.getAttribute("SupArchList")
1127             except:
1128                 pass
1129
1130             Archs = chkArch(Archs)
1131
1132             try:
1133                 Usage = Guid.getAttribute("Usage")
1134                 Type = str(XmlElementData(Guid.getElementsByTagName("HobType")[0]))
1135                 Usage += "  Hob: " + Type
1136             except:
1137                 pass
1138
1139             try:
1140                 CName = str(Guid.getAttribute("HobGuidCName"))
1141                 if CName in GuidDecls:
1142                     if (options.debug and options.verbose > 1):
1143                         print "Hob Adding Guid CName: %-45s # %s Archs: %s" % (CName, Usage, Archs)
1144                     AddGuid(Archs, CName, Usage)
1145                     AutoGenGuid.append(CName)
1146                 else:
1147                     if (len(DefinesComments) == 0):
1148                         DefinesComments.insert(0, "\n#\n# The following information is for reference only and not required by the build tools.\n#\n")
1149                     DefinesComments.append("#  HOB Guid C Name: " + CName + " Hob Type: " + Type + "\n")
1150                     Flag = True
1151             except:
1152                 if (len(DefinesComments) == 0):
1153                     DefinesComments.insert(0, "\n#\n# The following information is for reference only and not required by the build tools.\n#\n")
1154                 DefinesComments.append("#  HOB: " + Type + "\n")
1155                 Flag = True
1156                 pass
1157       
1158     if (Flag):
1159         DefinesComments.append("#\n")
1160         Flag = False
1161
1162     """ Check for the SystemTables Element """
1163     Guids = "/ModuleSurfaceArea/SystemTables/SystemTableCNames"
1164     GuidList = []
1165     try:
1166         GuidList = XmlList(Msa, Guids)
1167     except:
1168         pass
1169
1170     if (len(GuidList) > 0):
1171         for Guid in GuidList:
1172             Archs = ""
1173             Usage = ""
1174             CName = ""
1175
1176             try:
1177                 Archs = Guid.getAttribute("SupArchList")
1178             except:
1179                 pass
1180
1181             Archs = chkArch(Archs)
1182
1183             try:
1184                 Usage = Guid.getAttribute("Usage")
1185                 Usage += "  System Table"
1186             except:
1187                 pass
1188
1189             try:
1190                 CName = str(XmlElementData(Guid.getElementsByTagName("SystemTableCName")[0]))
1191                 if (options.debug and options.verbose > 1):
1192                     print "System Table Adding Guid CName: %-45s # %s Archs: %s" % (CName, Usage, Archs)
1193                 AddGuid(Archs, CName, Usage)
1194                 AutoGenGuid.append(CName)
1195             except:
1196                 pass
1197
1198     """ Check for the DataHubs Element """
1199     Guids = "/ModuleSurfaceArea/DataHubs/DataHubRecord"
1200     GuidList = []
1201     try:
1202         GuidList = XmlList(Msa, Guids)
1203     except:
1204         pass
1205
1206     if (len(GuidList) > 0):
1207         for Guid in GuidList:
1208             Archs = ""
1209             Usage = ""
1210             CName = ""
1211
1212             try:
1213                 Archs = Guid.getAttribute("SupArchList")
1214             except:
1215                 pass
1216
1217             Archs = chkArch(Archs)
1218
1219             try:
1220                 Usage = Guid.getAttribute("Usage")
1221                 Usage += "  Data Hub"
1222             except:
1223                 pass
1224
1225             try:
1226                 CName = str(XmlElementData(Guid.getElementsByTagName("DataHubCName")[0]))
1227                 if (options.debug and options.verbose > 1):
1228                     print "Data Hub Adding Guid CName: %-45s # %s Archs: %s" % (CName, Usage, Archs)
1229                 AddGuid(Archs, CName, Usage)
1230                 AutoGenGuid.append(CName)
1231             except:
1232                 pass
1233
1234     """ Check for the HiiPackages Element """
1235     Guids = "/ModuleSurfaceArea/HiiPackages/HiiPackage"
1236     GuidList = []
1237     try:
1238         GuidList = XmlList(Msa, Guids)
1239     except:
1240         pass
1241
1242     if (len(GuidList) > 0):
1243         for Guid in GuidList:
1244             Archs = ""
1245             Usage = ""
1246             CName = ""
1247
1248             try:
1249                 Archs = Guid.getAttribute("SupArchList")
1250             except:
1251                 pass
1252
1253             Archs = chkArch(Archs)
1254
1255             try:
1256                 Usage = Guid.getAttribute("Usage")
1257                 Usage += "  HII Formset"
1258             except:
1259                 pass
1260
1261             try:
1262                 CName = str(XmlElementData(Guid.getElementsByTagName("HiiCName")[0]))
1263                 if (options.debug and options.verbose > 1):
1264                     print "Hii Formset Adding Guid CName: %-45s # %s Archs: %s" % (CName, Usage, Archs)
1265                 AddGuid(Archs, CName, Usage)
1266                 AutoGenGuid.append(CName)
1267             except:
1268                 pass
1269  
1270     """ Check for the Variables Element """
1271     Guids = "/ModuleSurfaceArea/Variables/Variable"
1272     GuidList = []
1273     try:
1274         GuidList = XmlList(Msa, Guids)
1275     except:
1276         pass
1277
1278     if (len(GuidList) > 0):
1279         for Guid in GuidList:
1280             Archs = ""
1281             Usage = ""
1282             CName = ""
1283             VariableName = ""
1284
1285             try:
1286                 Archs = Guid.getAttribute("SupArchList")
1287             except:
1288                 pass
1289
1290             Archs = chkArch(Archs)
1291
1292             try:
1293                 Usage = Guid.getAttribute("Usage")
1294             except:
1295                 pass
1296
1297             try:
1298                 VariableName = str(XmlElementData(Guid.getElementsByTagName("VariableName")[0]))
1299                 CName = str(XmlElementData(Guid.getElementsByTagName("GuidC_Name")[0]))
1300
1301                 HexData = VariableName.strip().split()
1302                 UniString = " L\""
1303                 for dig in HexData[:]:
1304                     UniString += str(unichr(eval(dig)))
1305                 UniString += "\""
1306
1307                 Usage += UniString
1308       
1309                 if CName in set(GuidDecls):
1310                     removeDups(CName, GuidCName)
1311                     removeDups(CName, GuidCNameIa32)
1312                     removeDups(CName, GuidCNameX64)
1313                     removeDups(CName, GuidCNameIPF)
1314                     removeDups(CName, GuidCNameEBC)
1315
1316                     if (options.debug):
1317                         print "Variable Adding Guid CName: %-45s # %s Archs: %s" % (CName, Usage, Archs)
1318                     AddGuid(Archs, CName, Usage)
1319                     AutoGenGuid.append(CName)
1320                 else:
1321                     if (len(DefinesComments) == 0):
1322                         DefinesComments.insert(0, "\n#\n# The following information is for reference only and not required by the build tools.\n#\n")
1323                     DefinesComments.append("#  Variable Guid C Name: " + CName + " Variable Name:" + UniString + "\n")
1324                     Flag = True
1325             except:
1326                 pass
1327
1328     if (Flag):
1329         DefinesComments.append("#\n")
1330         Flag = False
1331
1332     """ Check for the Protocol Element """
1333     Protocols = "/ModuleSurfaceArea/Protocols/Protocol"
1334     ProtocolList = []
1335     ProtocolCName = []
1336     ProtocolCNameIa32 = []
1337     ProtocolCNameX64 = []
1338     ProtocolCNameIPF = []
1339     ProtocolCNameEBC = []
1340
1341     try:
1342         ProtocolList = XmlList(Msa, Protocols)
1343     except:
1344         pass
1345
1346     if (len(ProtocolList) > 0):
1347         for Protocol in ProtocolList:
1348             Archs = ""
1349             Usage = ""
1350             CName = ""
1351
1352             try:
1353                 Archs = Protocol.getAttribute("SupArchList")
1354             except:
1355                 pass
1356
1357             Archs = chkArch(Archs)
1358
1359             try:
1360                 Usage = Protocol.getAttribute("Usage")
1361             except:
1362                 pass
1363
1364             try:
1365                 CName = str(XmlElementData(Protocol.getElementsByTagName("ProtocolCName")[0]))
1366                 AutoGenGuid.append(CName)
1367                 removeDups(CName, GuidCName)
1368                 removeDups(CName, GuidCNameIa32)
1369                 removeDups(CName, GuidCNameX64)
1370                 removeDups(CName, GuidCNameIPF)
1371                 removeDups(CName, GuidCNameEBC)
1372       
1373                 if (options.debug and options.verbose > 1):
1374                     print "Found %s - %s - %s " % (CName, Usage, str(len(Archs)))
1375
1376                 if "IA32" in Archs:
1377                     ProtocolCNameIa32.insert(0, str("  %-45s # PROTOCOL %s" % (CName, Usage)))
1378                 if "X64" in Archs:
1379                     ProtocolCNameX64.insert(0, str("  %-45s # PROTOCOL %s" % (CName, Usage)))
1380                 if "IPF" in Archs:
1381                     ProtocolCNameIPF.insert(0, str("  %-45s # PROTOCOL %s" % (CName, Usage)))
1382                 if "EBC" in Archs:
1383                     ProtocolCNameEBC.insert(0, str("  %-45s # PROTOCOL %s" % (CName, Usage)))
1384                 if "ALL" in Archs:
1385                     ProtocolCName.insert(0, str("  %-45s # PROTOCOL %s" % (CName, Usage)))
1386             except:
1387                 pass
1388
1389
1390     Protocols = "/ModuleSurfaceArea/Protocols/ProtocolNotify"
1391     try:
1392         ProtocolList = XmlList(Msa, Protocols)
1393     except:
1394         pass
1395
1396     if (len(ProtocolList) > 0):
1397         for Protocol in ProtocolList:
1398             Archs = ""
1399             Usage = ""
1400             CName = ""
1401
1402             try:
1403                 Archs = Protocol.getAttribute("SupArchList")
1404             except:
1405                 pass
1406
1407             Archs = chkArch(Archs)
1408
1409             try:
1410                 Usage = Protocol.getAttribute("Usage")
1411             except:
1412                 pass
1413
1414             try:
1415                 CName = str(XmlElementData(Protocol.getElementsByTagName("ProtocolNotifyCName")[0]))
1416                 AutoGenGuid.append(CName)
1417                 removeDups(CName, GuidCName)
1418                 removeDups(CName, GuidCNameIa32)
1419                 removeDups(CName, GuidCNameX64)
1420                 removeDups(CName, GuidCNameIPF)
1421                 removeDups(CName, GuidCNameEBC)
1422       
1423                 if "IA32" in Archs:
1424                     ProtocolCNameIa32.insert(0, "  %-45s # PROTOCOL_NOTIFY %s" % (CName, Usage))
1425                 if "X64" in Archs:
1426                     ProtocolCNameX64.insert(0, "  %-45s # PROTOCOL_NOTIFY %s" % (CName, Usage))
1427                 if "IPF" in Archs:
1428                     ProtocolCNameIPF.insert(0, "  %-45s # PROTOCOL_NOTIFY %s" % (CName, Usage))
1429                 if "EBC" in Archs:
1430                     ProtocolCNameEBC.insert(0, "  %-45s # PROTOCOL_NOTIFY %s" % (CName, Usage))
1431                 if "ALL" in Archs:
1432                     ProtocolCName.insert(0, "  %-45s # PROTOCOL_NOTIFY %s" % (CName, Usage))
1433             except:
1434                 pass
1435
1436     """ Check for the PPIs Element """
1437     PPIs = "/ModuleSurfaceArea/PPIs/Ppi"
1438     PPIsList = []
1439     PpiCName = []
1440     PpiCNameIa32 = []
1441     PpiCNameX64 = []
1442     PpiCNameIPF = []
1443     PpiCNameEBC = []
1444
1445     try:
1446         PPIsList = XmlList(Msa, PPIs)
1447     except:
1448         pass
1449
1450     if (len(PPIsList) > 0):
1451         for Ppi in PPIsList:
1452             Archs = ""
1453             Usage = ""
1454             CName = ""
1455
1456             try:
1457                 Archs = str(Ppi.getAttribute("SupArchList"))
1458             except:
1459                 pass
1460
1461             Archs = chkArch(Archs)
1462
1463             try:
1464                 Usage = str(Ppi.getAttribute("Usage"))
1465             except:
1466                 pass
1467
1468             try:
1469                 CName = str(XmlElementData(Ppi.getElementsByTagName("PpiCName")[0])).strip()
1470                 AutoGenGuid.append(CName)
1471                 removeDups(CName, GuidCName)
1472                 removeDups(CName, GuidCNameIa32)
1473                 removeDups(CName, GuidCNameX64)
1474                 removeDups(CName, GuidCNameIPF)
1475                 removeDups(CName, GuidCNameEBC)
1476       
1477                 if "IA32" in Archs:
1478                     PpiCNameIa32.insert(0, "  %-45s # PPI %s" % (CName, Usage))
1479                 if "X64" in Archs:
1480                     PpiCNameX64.insert(0, "  %-45s # PPI %s" % (CName, Usage))
1481                 if "IPF" in Archs:
1482                     PpiCNameIPF.insert(0, "  %-45s # PPI %s" % (CName, Usage))
1483                 if "EBC" in Archs:
1484                     PpiCNameEBC.insert(0, "  %-45s # PPI %s" % (CName, Usage))
1485                 if "ALL" in Archs:
1486                     PpiCName.insert(0, "  %-45s # PPI %s" % (CName, Usage))
1487             except:
1488                 pass
1489
1490
1491     PPIs = "/ModuleSurfaceArea/PPIs/PpiNotify"
1492     try:
1493         PPIsList = XmlList(Msa, PPIs)
1494     except:
1495         pass 
1496
1497     if (len(PPIsList) > 0):
1498         for Ppi in PPIsList:
1499             Archs = ""
1500             Usage = ""
1501             CName = ""
1502
1503             try:
1504                 Archs = Ppi.getAttribute("SupArchList")
1505             except:
1506                 pass
1507
1508             Archs = chkArch(Archs)
1509
1510             try:
1511                 Usage = Ppi.getAttribute("Usage")
1512             except:
1513                 pass
1514
1515             try:
1516                 CName = str(XmlElementData(Ppi.getElementsByTagName("PpiNotifyCName")[0]))
1517                 AutoGenGuid.append(CName)
1518                 removeDups(CName, GuidCName)
1519                 removeDups(CName, GuidCNameIa32)
1520                 removeDups(CName, GuidCNameX64)
1521                 removeDups(CName, GuidCNameIPF)
1522                 removeDups(CName, GuidCNameEBC)
1523       
1524                 if "IA32" in Archs:
1525                     PpiCNameIa32.insert(0, "  %-45s # PPI_NOTIFY %s" % (CName, Usage))
1526                 if "X64" in Archs:
1527                     PpiCNameX64.insert(0,  "  %-45s # PPI_NOTIFY %s" % (CName, Usage))
1528                 if "IPF" in Archs:
1529                     PpiCNameIPF.insert(0,  "  %-45s # PPI_NOTIFY %s" % (CName, Usage))
1530                 if "EBC" in Archs:
1531                     PpiCNameEBC.insert(0,  "  %-45s # PPI_NOTIFY %s" % (CName, Usage))
1532                 if "ALL" in Archs:
1533                     PpiCName.insert(0,     "  %-45s # PPI_NOTIFY %s" % (CName, Usage))
1534             except:
1535                 pass
1536
1537
1538     """ Get the PCD entries now """
1539     PcdCoded = "/ModuleSurfaceArea/PcdCoded/PcdEntry"
1540     PcdList = []
1541     try:
1542         PcdList = XmlList(Msa, PcdCoded)
1543     except:
1544         pass
1545
1546     (PcdFF, PcdFFIa32, PcdFFX64, PcdFFIpf, PcdFFEbc) = ([],[],[],[],[])
1547     (PcdFAB, PcdFABIa32, PcdFABX64, PcdFABIpf, PcdFABEbc) = ([],[],[],[],[])
1548     (PcdPIM, PcdPIMIa32, PcdPIMX64, PcdPIMIpf, PcdPIMEbc) = ([],[],[],[],[])
1549     (PcdDY, PcdDYIa32, PcdDYX64, PcdDYIpf, PcdDYEbc) = ([],[],[],[],[])
1550     (PcdDYE, PcdDYEIa32, PcdDYEX64, PcdDYEIpf, PcdDYEEbc) = ([],[],[],[],[])
1551
1552     if (len(PcdList) > 0):
1553         for Pcd in PcdList:
1554             Archs = ""
1555             Usage = ""
1556             CName = ""
1557             DefVal = ""
1558
1559             try:
1560                 Archs = Pcd.getAttribute("SupArchList")
1561             except:
1562                 pass
1563
1564             Archs = chkArch(Archs)
1565
1566             try:
1567                 ItemType = Pcd.getAttribute("PcdItemType")
1568             except:
1569                 pass
1570
1571             try:
1572                 CName = str(XmlElementData(Pcd.getElementsByTagName("C_Name")[0]))
1573             except:
1574                 raise SyntaxError, "ERROR: MSA has a PCD with no Pcd C_Name defined"
1575
1576             try:
1577                 TSGC = str(XmlElementData(Pcd.getElementsByTagName("TokenSpaceGuidCName")[0]))
1578             except:
1579                 pass
1580
1581             try:
1582                 DefVal = str(XmlElementData(Pcd.getElementsByTagName("DefaultValue")))
1583             except:
1584                 pass
1585
1586             if (len(DefVal) > 0):
1587                 line = TSGC + "." + CName + "|" + DefVal
1588             else:
1589                 line = TSGC + "." + CName
1590
1591             if (ItemType == "FEATURE_FLAG"):
1592                 if ("IA32" in Archs):
1593                     PcdFFIa32.insert(0, line)
1594                 if ("IPF" in Archs):
1595                     PcdFFIpf.insert(0, line)
1596                 if ("X64" in Archs):
1597                     PcdFFX64.insert(0, line)
1598                 if ("EBC" in Archs):
1599                     PcdFFEbc.insert(0, line)
1600                 if ("ALL" in Archs):
1601                     PcdFF.insert(0, line)
1602             elif (ItemType == "FIXED_AT_BUILD"):
1603                 if ("IA32" in Archs):
1604                     PcdFABIa32.insert(0, line)
1605                 if ("IPF" in Archs):
1606                     PcdFABIpf.insert(0, line)
1607                 if ("X64" in Archs):
1608                     PcdFABX64.insert(0, line)
1609                 if ("EBC" in Archs):
1610                     PcdFABEbc.insert(0, line)
1611                 if ("ALL" in Archs):
1612                     PcdFAB.insert(0, line)
1613             elif (ItemType == "PATCHABLE_IN_MODULE"):
1614                 if ("IA32" in Archs):
1615                     PcdPIMIa32.insert(0, line)
1616                 if ("IPF" in Archs):
1617                     PcdPIMIpf.insert(0, line)
1618                 if ("X64" in Archs):
1619                     PcdPIMX64.insert(0, line)
1620                 if ("EBC" in Archs):
1621                     PcdPIMEbc.insert(0, line)
1622                 if ("ALL" in Archs):
1623                     PcdFAB.insert(0, line)
1624             elif (ItemType == "DYNAMIC_EX"):
1625                 if ("IA32" in Archs):
1626                     PcdDYEIa32.insert(0, line)
1627                 if ("IPF" in Archs):
1628                     PcdDYEIpf.insert(0, line)
1629                 if ("X64" in Archs):
1630                     PcdDYEX64.insert(0, line)
1631                 if ("EBC" in Archs):
1632                     PcdDYEEbc.insert(0, line)
1633                 if ("ALL" in Archs):
1634                     PcdDYE.insert(0, line)
1635             else:
1636                 if ("IA32" in Archs):
1637                     PcdDYIa32.insert(0, line)
1638                 if ("IPF" in Archs):
1639                     PcdDYIpf.insert(0, line)
1640                 if ("X64" in Archs):
1641                     PcdDYX64.insert(0, line)
1642                 if ("EBC" in Archs):
1643                     PcdDYEbc.insert(0, line)
1644                 if ("ALL" in Archs):
1645                     PcdDY.insert(0, line)
1646
1647     """ User Extensions Section """
1648     UEList = []
1649     UESectionList = []
1650     try:
1651         UESectionList = XmlList(Msa, "/ModuleSurfaceArea/UserExtensions")
1652     except:
1653         pass
1654
1655     if (len(UESectionList) > 0):
1656         for UE in UESectionList[:]:
1657             UserId = ""
1658             Identifier = ""
1659             Value = ""
1660
1661             try:
1662                 UserId = str(UE.getAttribute("UserID"))
1663             except:
1664                 raise SyntaxError, "ERROR: Malformed MSA, No UserID Specified in UserExtensions element"
1665
1666             try:
1667                 Identifier = str(UE.getAttribute("Identifier"))
1668             except:
1669                 raise SyntaxError, "ERROR: Malformed MSA, No Identifier Specified in UserExtensions element"
1670
1671             if (options.debug):
1672                 print "FOUND A UE Element", UserId, Identifier
1673
1674             try:
1675                 Value = str(XmlElementData(UE))
1676             except:
1677                 pass
1678       
1679             Entry = [UserId, Identifier, Value]
1680             UEList.insert(0, Entry)
1681
1682
1683
1684     if (len(Externlist) > 0):
1685         AutoGenSource = ""
1686         AutoGenDefinitionSource = ""
1687         AutoGenEntryPointSource = ""
1688         AutoGenUnloadSource = ""
1689         if (len(AutoGenDriverModel) > 0):
1690             AutoGenCode = AddDriverBindingProtocolStatement(AutoGenDriverModel)
1691             AutoGenEntryPointSource += AutoGenCode[0]
1692             AutoGenUnloadSource += AutoGenCode[1]
1693             AutoGenDeclaration += AutoGenCode[3]
1694             
1695
1696         if (len(AutoGenExitBootServices) > 0):
1697             print "[Warning] Please manually add Create Event statement for Exit Boot Service Event!"
1698             if options.event:
1699                 AutoGenCode = AddBootServiceEventStatement(AutoGenExitBootServices)
1700                 AutoGenEntryPointSource += AutoGenCode[0]
1701                 AutoGenUnloadSource += AutoGenCode[1]
1702                 AutoGenDefinitionSource += AutoGenCode[2]
1703                 AutoGenDeclaration += AutoGenCode[3]
1704
1705         if (len(AutoGenVirtualAddressChanged) > 0):
1706             print "[Warning] Please manually add Create Event statement for Virtual Address Change Event!"
1707             if options.event:
1708                 AutoGenCode = AddVirtualAddressEventStatement(AutoGenVirtualAddressChanged)
1709                 AutoGenEntryPointSource += AutoGenCode[0]
1710                 AutoGenUnloadSource += AutoGenCode[1]
1711                 AutoGenDefinitionSource += AutoGenCode[2]
1712                 AutoGenDeclaration += AutoGenCode[3]
1713             
1714         if AutoGenEntryPointSource != "":
1715             OldEntryPoint = AutoGenEntryPoint
1716             AutoGenCode   = AddNewEntryPointContentsStatement(BaseName, AutoGenEntryPoint, AutoGenEntryPointSource)
1717             AutoGenEntryPoint = AutoGenCode[0]
1718             AutoGenEntryPointSource = AutoGenCode[1]
1719             AutoGenDeclaration += AutoGenCode[2]
1720                 
1721             
1722         if AutoGenEntryPoint != "":    
1723             DriverModules.insert(0, "  %-30s = %s\n" % ("ENTRY_POINT" , AutoGenEntryPoint))
1724          
1725         AutoGenSource = AutoGenDefinitionSource + AutoGenEntryPointSource + AutoGenUnloadSource     
1726         
1727         if (lFlag):
1728             DefinesComments.append("#\n")
1729
1730         if (Flag and len(DefinesComments) > 0):
1731             DefinesComments.insert(0, "\n#\n# The following information is for reference only and not required by the build tools.\n#\n")
1732
1733         if (options.debug and options.verbose > 2):
1734             if (len(DriverModules) > 0):
1735                 print DriverModules
1736             if (len(LibraryModules) > 0):
1737                 print LibraryModules
1738             if (len(DefinesComments) > 0):
1739                 print DefinesComments
1740
1741     Depex = []
1742     DepexIa32 = []
1743     DepexX64 = []
1744     DepexIpf = []
1745     DepexEbc = []
1746     
1747     for DxsFile, Archs in AutoGenDxsFiles:
1748         fileContents = openSourceFile(AutoGenModuleFolder, DxsFile)
1749         Contents, Unresolved = TranslateDpxSection(fileContents)
1750         if Contents == "":
1751             print "[warning] Cannot read dxs expression"
1752         else:
1753             if (len(Unresolved) > 0):
1754                 print "[warning] Guid Macro(s): %s cannot find corresponding cNames. Please resolve it in [depex] section in extened inf" % ",".join(Unresolved)
1755                 
1756             if ("IA32" in Archs):
1757                 DepexIa32.insert(0, Contents)
1758             if ("IPF" in Archs):
1759                 DepexIpf.insert(0, Contents)
1760             if ("X64" in Archs):
1761                 DepexX64.insert(0, Contents)
1762             if ("EBC" in Archs):
1763                 DepexEbc.insert(0, Contents)
1764             if ("ALL" in Archs):
1765                 Depex.insert(0, Contents)
1766
1767     AutoGenSourceHeaderFormat = "/**@file\n  %s\n\n  %s\n  %s\n  %s\n**/\n\n%s"
1768     includeCommonHeaderFileStatement = "#include \"%s\"" % commonHeaderFilename
1769
1770     AutoGenHeader += AddSystemIncludeStatement(ModType, AutoGenPackage)
1771     AutoGenHeader += AddGuidStatement(AutoGenGuid)
1772     AutoGenHeader += AddLibraryClassStatement(AutoGenLibClass)
1773
1774     if options.manual:
1775         saveSourceFile(AutoGenModuleFolder, "CommonHeader.txt", AutoGenHeader)
1776     else:
1777  
1778         commonHeaderFilename2 = re.sub("(?=[^a-z])", "_", commonHeaderFilename)
1779         commonHeaderFilename2 = "_" + commonHeaderFilename2.replace(".", "").upper() + "_"
1780         briefDiscription = "Common header file shared by all source files."
1781         detailedDiscription = "This file includes package header files, library classes and protocol, PPI & GUID definitions.\n"
1782         AutoGenHeader += AutoGenDeclaration
1783         AutoGenHeader = "#ifndef %s\n#define %s\n\n\n%s\n#endif\n" % (commonHeaderFilename2, commonHeaderFilename2, AutoGenHeader)
1784         AutoGenHeader = AutoGenSourceHeaderFormat % (briefDiscription, detailedDiscription, CopyRight, License, AutoGenHeader)
1785         saveSourceFile(AutoGenModuleFolder, commonHeaderFilename, AutoGenHeader)
1786         SrcFilenames.append(commonHeaderFilename)
1787
1788         for source in AutoGenSourceFiles:
1789             extension = os.path.splitext(source)[1]
1790             if extension == ".c":
1791                 sourceContents = openSourceFile(AutoGenModuleFolder, source)
1792                 sourceContents = AddCommonInclusionStatement(sourceContents, includeCommonHeaderFileStatement)
1793                 saveSourceFile(AutoGenModuleFolder, source, sourceContents)
1794     
1795
1796     if AutoGenSource != "":
1797         briefDiscription = "Entry Point Source file."
1798         detailedDiscription = "This file contains the user entry point \n"
1799         AutoGenSource = AutoGenSourceHeaderFormat % (briefDiscription, detailedDiscription, CopyRight, License, AutoGenSource)
1800         AutoGenSource = AddCommonInclusionStatement(AutoGenSource, includeCommonHeaderFileStatement)
1801
1802         saveSourceFile(AutoGenModuleFolder, entryPointFilename, AutoGenSource)
1803         SrcFilenames.append(entryPointFilename)
1804     
1805     
1806
1807       
1808     # DONE Getting data, now output it in INF format.
1809     Msa.unlink()
1810     Fdb.unlink()
1811     Output = []
1812
1813     """ Print the converted data format """
1814     head =  "#/** @file\n"
1815     head += "# " + str(Abstract) + "\n#\n"
1816     head += "# " + str(Description).strip().replace("\n", "\n# ") + "\n"
1817     head += "# " + str(CopyRight) + "\n#\n"
1818     head += "#  " + str(License).replace("\n", "\n# ").replace("  ", " ").strip() + "\n#\n"
1819     head += "#\n#**/\n"
1820   
1821     Output.append(head)
1822     if (options.debug):
1823         print head
1824
1825 ##    Defines = "\n" + "#"*80+ "\n#\n"
1826 ##    if (BinModule != "false"):
1827 ##        Defines += "# Defines Section - statements that will be processed to generate a binary image.\n"
1828 ##    else:
1829 ##        Defines += "# Defines Section - statements that will be processed to create a Makefile.\n"
1830 ##    Defines += "#\n" + "#"*80 + "\n"
1831
1832     Defines  = "\n"
1833     Defines += "[Defines]\n"
1834     Defines += "  %-30s = %s\n" % ("INF_VERSION", "0x00010005")
1835     Defines += "  %-30s = %s\n" % ("BASE_NAME", BaseName)
1836     Defines += "  %-30s = %s\n" % ("FILE_GUID", GuidValue)
1837     Defines += "  %-30s = %s\n" % ("MODULE_TYPE", ModType)
1838     Defines += "  %-30s = %s\n" % ("VERSION_STRING", VerString)
1839   
1840     if (len(PcdIsDriver) > 0):
1841         Defines += "  %-30s = %s\n" %  ("PCD_DRIVER", PcdIsDriver)
1842   
1843     if (len(IamLibrary) > 0):
1844         lcstr = ""
1845         for lc in IamLibrary[:]:
1846             lcstr += lc + " "
1847             Defines += "  %-30s = %s" %  ("LIBRARY_CLASS", lcstr)
1848         Defines += "\n"
1849   
1850     if (len(SpecList) > 0):
1851         for spec in SpecList[:]:
1852             (specname, specval) = spec.split()
1853             Defines += "  %-30s = %s\n" %  (specname, specval)
1854         Defines += "\n"
1855   
1856     if (len(DriverModules) > 0):
1857         for line in DriverModules[:]:
1858             Defines += line
1859
1860     if (len(LibraryModules) > 0):
1861         for line in LibraryModules[:]:
1862             Defines += line
1863      
1864     if (len(DefinesComments) > 0):
1865         for line in DefinesComments[:]:
1866             Defines += line
1867   
1868     Output.append(Defines)
1869   
1870     if (options.debug):
1871         print Defines
1872   
1873     if (BinModule != "false"):
1874         """ Binary Module, so sources are really binaries. """
1875 ##        Sources = "\n" + "#"*80 + "\n#\n"
1876 ##        Sources += "# Binaries Section - list of binary files that are required for the build\n# to succeed.\n"
1877 ##        Sources += "#\n" + "#"*80 + "\n\n"
1878         Sources = "\n"
1879         if ModType == "UEFI_APPLICATION":
1880             FileType = "UEFI_APP"
1881             if options.verbose > 0:
1882                 print "WARNING: Binary Module: %s is assuming UEFI_APPLICATION file type." % (options.filename)
1883         else:
1884             FileType = "FV"
1885             if options.verbose > 0:
1886                 print "WARNING: Binary Module: %s is assuming FV file type." % (options.filename)
1887   
1888         if (len(SrcFilenames) > 0):
1889             Sources += "[Binaries.common]\n"
1890             for file in SrcFilenames[:]:
1891                 file = file.replace("\\", "/")
1892                 Sources += "  " + FileType + "|" + file + "\n"
1893             Sources += "\n"
1894   
1895         if (len(SrcFilenamesIa32) > 0):
1896             Sources += "[Binaries.Ia32]\n"
1897             for file in SrcFilenamesIa32[:]:
1898                 file = file.replace("\\", "/")
1899                 Sources += "  " + FileType + "|" + file + "\n"
1900             Sources += "\n"
1901   
1902         if (len(SrcFilenamesX64) > 0):
1903             Sources += "[Binaries.X64]\n"
1904             for file in SrcFilenamesX64[:]:
1905                 file = file.replace("\\", "/")
1906                 Sources += "  " + FileType + "|" + file + "\n"
1907             Sources += "\n"
1908   
1909         if (len(SrcFilenamesIpf) > 0):
1910             Sources += "[Binaries.IPF]\n"
1911             for file in SrcFilenamesIpf[:]:
1912                 file = file.replace("\\", "/")
1913                 Sources += "  " + FileType + "|" + file + "\n"
1914             Sources += "\n"
1915   
1916         if (len(SrcFilenamesEbc) > 0):
1917             Sources += "[Binaries.EBC]\n"
1918             for file in SrcFilenamesEbc[:]:
1919                 file = file.replace("\\", "/")
1920                 Sources += "  " + FileType + "|" + file + "\n"
1921             Sources += "\n"
1922   
1923         Output.append(Sources)
1924         if (options.debug):
1925             print Sources
1926     else: 
1927 ##        Sources = "\n" + "#"*80 + "\n#\n"
1928 ##        Sources += "# Sources Section - list of files that are required for the build to succeed.\n"
1929 ##        Sources += "#\n" + "#"*80 + "\n\n"
1930         Sources = "\n"
1931         if (len(SrcFilenames) > 0):
1932             Sources += "[Sources.common]\n"
1933             for file in SrcFilenames[:]:
1934                 Sources += "  " + file + "\n"
1935             Sources += "\n"
1936   
1937         if (len(SrcFilenamesIa32) > 0):
1938             Sources += "[Sources.Ia32]\n"
1939             for file in SrcFilenamesIa32[:]:
1940                 Sources += "  " + file + "\n"
1941             Sources += "\n"
1942   
1943         if (len(SrcFilenamesX64) > 0):
1944             Sources += "[Sources.X64]\n"
1945             for file in SrcFilenamesX64[:]:
1946                 Sources += "  " + file + "\n"
1947             Sources += "\n"
1948   
1949         if (len(SrcFilenamesIpf) > 0):
1950             Sources += "[Sources.IPF]\n"
1951             for file in SrcFilenamesIpf[:]:
1952                 Sources += "  " + file + "\n"
1953             Sources += "\n"
1954   
1955         if (len(SrcFilenamesEbc) > 0):
1956             Sources += "[Sources.EBC]\n"
1957             for file in SrcFilenamesEbc[:]:
1958                 Sources += "  " + file + "\n"
1959             Sources += "\n"
1960   
1961         Output.append(Sources)
1962         if (options.debug):
1963             print Sources
1964   
1965
1966     includeLine = ""
1967     if ((len(HeaderLocations) > 0) or (len(Dirs) > 0)):
1968         allLcs = set(LibClassList + LibClassListIa32 + LibClassListX64 + LibClassListIpf + LibClassListEbc + Dirs)
1969         Lines = []
1970         for line in HeaderLocations[:]:
1971             for Lc in allLcs:
1972                 (keyword, header) = line.split("|")
1973                 if Lc in keyword:
1974                     if (options.debug):
1975                         print "FOUND", Lc, "in", keyword, "header", header
1976                     path = "$(WORKSPACE)/" + os.path.split(header)[0]
1977                     Lines.insert(0, path.strip())
1978         Includes = ""
1979 ##        Includes = "\n" + "#"*80 + "\n#\n"
1980 ##        Includes += "# Includes Section - list of Include locations that are required for\n"
1981 ##        Includes += "#                    this module.\n"
1982 ##        Includes += "#\n" + "#"*80 + "\n\n"
1983 ##        Includes += "[Includes]\n"
1984 ##        includeLines = []
1985 ##        includeLines = set(Lines)
1986 ##        if (options.debug):
1987 ##            print "There are", len(includeLines), "entries"
1988 ##        for Line in includeLines:
1989 ##            Includes += "  " + str(Line).strip().replace("\\", "/") + "\n"
1990   
1991         Output.append(Includes)
1992         if (options.debug):
1993             print Includes
1994   
1995          
1996   
1997     if ((len(PkgList) + len(PkgListIa32) + len(PkgListX64) + len(PkgListIpf) + len(PkgListEbc)) > 0):
1998         """ We do this if and only if we have Package Dependencies """
1999 ##        PackageDepends = "\n" + "#"*80 + "\n#\n"
2000 ##        PackageDepends += "# Package Dependency Section - list of Package files that are required for\n"
2001 ##        PackageDepends += "#                              this module.\n"
2002 ##        PackageDepends += "#\n" + "#"*80 + "\n\n"
2003         PackageDepends = "\n"
2004         if (len(PkgList) > 0):
2005             PackageDepends += "[Packages]\n"
2006             for lc in PkgList[:]:
2007                 lc = lc.replace("\\", "/")
2008                 PackageDepends += "  " + lc + "\n"
2009             PackageDepends += "\n"
2010   
2011         if (len(PkgListIa32) > 0):
2012             PackageDepends += "[Packages.IA32]\n"
2013             for lc in PkgListIa32[:]:
2014                 lc = lc.replace("\\", "/")
2015                 PackageDepends += "  " + lc + "\n"
2016             PackageDepends += "\n"
2017   
2018         if (len(PkgListX64) > 0):
2019             PackageDepends += "[Packages.X64]\n"
2020             for lc in PkgListX64[:]:
2021                 lc = lc.replace("\\", "/")
2022                 PackageDepends += "  " + lc + "\n"
2023             PackageDepends += "\n"
2024   
2025         if (len(PkgListIpf) > 0):
2026             PackageDepends += "[Packages.IPF]\n"
2027             for lc in PkgListIpf[:]:
2028                 lc = lc.replace("\\", "/")
2029                 PackageDepends += "  " + lc + "\n"
2030             PackageDepends += "\n"
2031   
2032         if (len(PkgListEbc) > 0):
2033             PackageDepends += "[Packages.EBC]\n"
2034             for lc in PkgListEbc[:]:
2035                 lc = lc.replace("\\", "/")
2036                 PackageDepends += "  " + lc + "\n"
2037             PackageDepends += "\n"
2038   
2039         Output.append(PackageDepends)
2040         if (options.debug):
2041             print PackageDepends
2042   
2043     if ((len(LibClassList) + len(LibClassListIa32) + len(LibClassListX64) + len(LibClassListIpf) + len(LibClassListEbc)) > 0):
2044 ##        LibraryClasses = "\n" + "#"*80 + "\n#\n"
2045 ##        LibraryClasses += "# Library Class Section - list of Library Classes that are required for\n"
2046 ##        LibraryClasses += "#                         this module.\n"
2047 ##        LibraryClasses += "#\n" + "#"*80 + "\n\n"
2048   
2049         LibraryClasses = "\n"
2050         if (len(LibClassList) > 0):
2051             LibraryClasses += "[LibraryClasses]\n"
2052             for lc in LibClassList[:]:
2053               LibraryClasses += "  " + lc + "\n"
2054             LibraryClasses += "\n"
2055   
2056         if (len(LibClassListIa32) > 0):
2057             LibraryClasses += "[LibraryClasses.IA32]\n"
2058             for lc in LibClassListIa32[:]:
2059                 LibraryClasses += "  " + lc + "\n"
2060             LibraryClasses += "\n"
2061   
2062         if (len(LibClassListX64) > 0):
2063             LibraryClasses += "[LibraryClasses.X64]\n"
2064             for lc in LibClassListX64[:]:
2065                 LibraryClasses += "  " + lc + "\n"
2066             LibraryClasses += "\n"
2067   
2068         if (len(LibClassListIpf) > 0):
2069             LibraryClasses += "[LibraryClasses.IPF]\n"
2070             for lc in LibClassListIpf[:]:
2071                 LibraryClasses += "  " + lc + "\n"
2072             LibraryClasses += "\n"
2073   
2074         if (len(LibClassListEbc) > 0):
2075             LibraryClasses += "[LibraryClasses.EBC]\n"
2076             for lc in LibClassListEbc[:]:
2077                 LibraryClasses += "  " + lc + "\n"
2078             LibraryClasses += "\n"
2079   
2080         Output.append(LibraryClasses)
2081         if (options.debug):
2082             print LibraryClasses
2083   
2084     # Print the Guids sections
2085     if (len(GuidCName) + len(GuidCNameIa32) + len(GuidCNameIPF) + len(GuidCNameX64) + len(GuidCNameEBC)) > 0:
2086 ##        GuidSection = "\n" + "#"*80 + "\n#\n"
2087 ##        GuidSection += "# Guid C Name Section - list of Guids that this module uses or produces.\n"
2088 ##        GuidSection += "#\n" + "#"*80 + "\n\n"
2089         GuidSection = "\n"
2090         if (len(GuidCName) > 0):
2091             GuidSection += "[Guids]\n"
2092             for Guid in GuidCName[:]:
2093                 GuidSection += Guid + "\n"
2094             GuidSection += "\n"
2095   
2096         if (len(GuidCNameIa32) > 0):
2097             GuidSection += "[Guids.IA32]\n"
2098             for Guid in GuidCNameIa32[:]:
2099                 GuidSection += Guid + "\n"
2100             GuidSection += "\n"
2101   
2102         if (len(GuidCNameX64) > 0):
2103             GuidSection += "[Guids.X64]\n"
2104             for Guid in GuidCNameX64[:]:
2105                 GuidSection += Guid + "\n"
2106             GuidSection += "\n"
2107   
2108         if (len(GuidCNameIPF) > 0):
2109             GuidSection += "[Guids.IPF]\n"
2110             for Guid in GuidCNameIPF[:]:
2111                 GuidSection += Guid + "\n"
2112             GuidSection += "\n"
2113   
2114         if (len(GuidCNameEBC) > 0):
2115             GuidSection += "[Guids.EBC]\n"
2116             for Guid in GuidCNameEBC[:]:
2117                 GuidSection += Guid + "\n"
2118             GuidSection += "\n"
2119   
2120         Output.append(GuidSection)
2121         if (options.debug and options.verbose > 1):
2122             print GuidSection
2123   
2124     # Print the Protocol sections
2125     if (len(ProtocolCName) + len(ProtocolCNameIa32) + len(ProtocolCNameIPF) + len(ProtocolCNameX64) + len(ProtocolCNameEBC)) > 0:
2126 ##        ProtocolsSection = "\n" + "#"*80 + "\n#\n"
2127 ##        ProtocolsSection += "# Protocol C Name Section - list of Protocol and Protocol Notify C Names\n"
2128 ##        ProtocolsSection += "#                           that this module uses or produces.\n"
2129 ##        ProtocolsSection += "#\n" + "#"*80 + "\n\n"
2130   
2131         ProtocolsSection = "\n"
2132         if (len(ProtocolCName) > 0):
2133             ProtocolsSection += "[Protocols]\n"
2134             for Guid in ProtocolCName[:]:
2135                 ProtocolsSection += Guid + "\n"
2136             ProtocolsSection += "\n"
2137   
2138         if (len(ProtocolCNameIa32) > 0):
2139             ProtocolsSection += "[Protocols.IA32]\n"
2140             for Guid in ProtocolCNameIa32[:]:
2141                 ProtocolsSection += Guid + "\n"
2142             ProtocolsSection += "\n"
2143   
2144         if (len(ProtocolCNameX64) > 0):
2145             ProtocolsSection += "[Protocols.X64]\n"
2146             for Guid in ProtocolCNameX64[:]:
2147                 ProtocolsSection += Guid + "\n"
2148             ProtocolsSection += "\n"
2149   
2150         if (len(ProtocolCNameIPF) > 0):
2151             ProtocolsSection += "[Protocols.IPF]\n"
2152             for Guid in ProtocolCNameIPF[:]:
2153                 ProtocolsSection += Guid + "\n"
2154             ProtocolsSection += "\n"
2155   
2156         if (len(ProtocolCNameEBC) > 0):
2157             ProtocolsSection += "[Protocols.EBC]\n"
2158             for Guid in ProtocolCNameEBC[:]:
2159                 ProtocolsSection += Guid + "\n"
2160             ProtocolsSection += "\n"
2161   
2162         Output.append(ProtocolsSection)
2163         if (options.debug):
2164           print ProtocolsSection
2165   
2166     # Print the PPI sections
2167     if (len(PpiCName) + len(PpiCNameIa32) + len(PpiCNameIPF) + len(PpiCNameX64) + len(PpiCNameEBC)) > 0:
2168 ##        PpiSection = "\n" + "#"*80 + "\n#\n"
2169 ##        PpiSection += "# PPI C Name Section - list of PPI and PPI Notify C Names that this module\n"
2170 ##        PpiSection += "#                      uses or produces.\n"
2171 ##        PpiSection += "#\n" + "#"*80 + "\n\n"
2172   
2173         PpiSection = "\n"
2174         if (len(PpiCName) > 0):
2175             PpiSection += "[Ppis]\n"
2176             for Guid in PpiCName[:]:
2177                 PpiSection += Guid + "\n"
2178             PpiSection += "\n"
2179   
2180         if (len(PpiCNameIa32) > 0):
2181             PpiSection += "[Ppis.IA32]\n"
2182             for Guid in PpiCNameIa32[:]:
2183                 PpiSection += Guid + "\n"
2184             PpiSection += "\n"
2185   
2186         if (len(PpiCNameX64) > 0):
2187             PpiSection += "[Ppis.X64]\n"
2188             for Guid in PpiCNameX64[:]:
2189                 PpiSection += Guid + "\n"
2190             PpiSection += "\n"
2191   
2192         if (len(PpiCNameIPF) > 0):
2193             PpiSection += "[Ppis.IPF]\n"
2194             for Guid in PpiCNameIPF[:]:
2195                 PpiSection += Guid + "\n"
2196             PpiSection += "\n"
2197   
2198         if (len(PpiCNameEBC) > 0):
2199             PpiSection += "[Ppis.EBC]\n"
2200             for Guid in PpiCNameEBC[:]:
2201                 PpiSection += Guid + "\n"
2202             PpiSection += "\n"
2203   
2204         Output.append(PpiSection)
2205         if (options.debug):
2206             print PpiSection
2207   
2208     # Print the PCD sections
2209     if ((len(PcdFF)+len(PcdFFIa32)+len(PcdFFX64)+len(PcdFFIpf)+len(PcdFFEbc)) > 0):
2210 ##        FeatureFlagSection = "\n" + "#"*80 + "\n#\n"
2211 ##        FeatureFlagSection += "# Pcd FEATURE_FLAG - list of PCDs that this module is coded for.\n"
2212 ##        FeatureFlagSection += "#\n" + "#"*80 + "\n\n"
2213   
2214         FeatureFlagSection = "\n"
2215         if (len(PcdFF) > 0):
2216             FeatureFlagSection += "[FeaturePcd.common]\n"
2217             for Entry in PcdFF[:]:
2218                 FeatureFlagSection += "  " + Entry + "\n"
2219             FeatureFlagSection += "\n"
2220         if (len(PcdFFIa32) > 0):
2221             FeatureFlagSection += "[FeaturePcd.IA32]\n"
2222             for Entry in PcdFFIa32[:]:
2223                 FeatureFlagSection += "  " + Entry + "\n"
2224             FeatureFlagSection += "\n"
2225         if (len(PcdFFX64) > 0):
2226             FeatureFlagSection += "[FeaturePcd.X64]\n"
2227             for Entry in PcdFFX64[:]:
2228                 FeatureFlagSection += "  " + Entry + "\n"
2229             FeatureFlagSection += "\n"
2230         if (len(PcdFFIpf) > 0):
2231             FeatureFlagSection += "[PcdsFeatureFlag.IPF]\n"
2232             for Entry in PcdFFIpf[:]:
2233                 FeatureFlagSection += "  " + Entry + "\n"
2234             FeatureFlagSection += "\n"
2235         if (len(PcdFFEbc) > 0):
2236             FeatureFlagSection += "[FeaturePcd.EBC]\n"
2237             for Entry in PcdFFEbc[:]:
2238                 FeatureFlagSection += "  " + Entry + "\n"
2239             FeatureFlagSection += "\n"
2240   
2241         Output.append(FeatureFlagSection)
2242         if (options.debug):
2243           print FeatureFlagSection
2244   
2245     if ((len(PcdFAB)+len(PcdFABIa32)+len(PcdFABX64)+len(PcdFABIpf)+len(PcdFABEbc)) > 0):
2246 ##        FixedAtBuildSection = "\n" + "#"*80 + "\n#\n"
2247 ##        FixedAtBuildSection += "# Pcd FIXED_AT_BUILD - list of PCDs that this module is coded for.\n"
2248 ##        FixedAtBuildSection += "#\n" + "#"*80 + "\n\n"
2249   
2250         FixedAtBuildSection = "\n"
2251         if (len(PcdFAB) > 0):
2252             FixedAtBuildSection += "[FixedPcd.common]\n"
2253             for Entry in PcdFAB[:]:
2254                 FixedAtBuildSection += "  " + Entry + "\n"
2255             FixedAtBuildSection += "\n"
2256         if (len(PcdFABIa32) > 0):
2257             FixedAtBuildSection += "[FixedPcd.IA32]\n"
2258             for Entry in PcdFABIa32[:]:
2259                 FixedAtBuildSection += "  " + Entry + "\n"
2260             FixedAtBuildSection += "\n"
2261         if (len(PcdFABX64) > 0):
2262             FixedAtBuildSection += "[FixedPcd.X64]\n"
2263             for Entry in PcdFABX64[:]:
2264                 FixedAtBuildSection += "  " + Entry + "\n"
2265             FixedAtBuildSection += "\n"
2266         if (len(PcdFABIpf) > 0):
2267             FixedAtBuildSection += "[FixedPcd.IPF]\n"
2268             for Entry in PcdFABIpf[:]:
2269                 FixedAtBuildSection += "  " + Entry + "\n"
2270             FixedAtBuildSection += "\n"
2271         if (len(PcdFABEbc) > 0):
2272             FixedAtBuildSection += "[FixedPcd.EBC]\n"
2273             for Entry in PcdFABEbc[:]:
2274                 FixedAtBuildSection += "  " + Entry + "\n"
2275             FixedAtBuildSection += "\n"
2276   
2277         Output.append(FixedAtBuildSection)
2278         if (options.debug):
2279             print FixedAtBuildSection
2280   
2281     if ((len(PcdPIM)+len(PcdPIMIa32)+len(PcdPIMX64)+len(PcdPIMIpf)+len(PcdPIMEbc)) > 0):
2282 ##        PatchableInModuleSection = "\n" + "#"*80 + "\n#\n"
2283 ##        PatchableInModuleSection += "# Pcd PATCHABLE_IN_MODULE - list of PCDs that this module is coded for.\n"
2284 ##        PatchableInModuleSection += "#\n" + "#"*80 + "\n\n"
2285     
2286         PatchableInModuleSection = "\n"
2287         if (len(PcdPIM) > 0):
2288             PatchableInModuleSection += "[PatchPcd.common]\n"
2289             for Entry in PcdPIM[:]:
2290                 PatchableInModuleSection += "  " + Entry + "\n"
2291             PatchableInModuleSection += "\n"
2292         if (len(PcdPIMIa32) > 0):
2293             PatchableInModuleSection += "[PatchPcd.IA32]\n"
2294             for Entry in PcdPIMIa32[:]:
2295                 PatchableInModuleSection += "  " + Entry + "\n"
2296             PatchableInModuleSection += "\n"
2297         if (len(PcdPIMX64) > 0):
2298             PatchableInModuleSection += "[PatchPcd.X64]\n"
2299             for Entry in PcdPIMX64[:]:
2300                 PatchableInModuleSection += "  " + Entry + "\n"
2301             PatchableInModuleSection += "\n"
2302         if (len(PcdPIMIpf) > 0):
2303             PatchableInModuleSection += "[PatchPcd.IPF]\n"
2304             for Entry in PcdPIMIpf[:]:
2305                 PatchableInModuleSection += "  " + Entry + "\n"
2306             PatchableInModuleSection += "\n"
2307         if (len(PcdPIMEbc) > 0):
2308             PatchableInModuleSection += "[PatchPcd.EBC]\n"
2309             for Entry in PcdPIMEbc[:]:
2310                 PatchableInModuleSection += "  " + Entry + "\n"
2311             PatchableInModuleSection += "\n"
2312   
2313         Output.append(PatchableInModuleSection)
2314         if (options.debug):
2315             print PatchableInModuleSection
2316   
2317     if ((len(PcdDYE)+len(PcdDYEIa32)+len(PcdDYEX64)+len(PcdDYEIpf)+len(PcdDYEEbc)) > 0):
2318 ##        DynamicExSection = "\n" + "#"*80 + "\n#\n"
2319 ##        DynamicExSection += "# Pcd DYNAMIC_EX - list of PCDs that this module is coded for.\n"
2320 ##        DynamicExSection += "#\n" + "#"*80 + "\n\n"
2321   
2322         DynamicExSection = "\n"
2323         if (len(PcdDYE) > 0):
2324             DynamicExSection += "[PcdEx.common]\n"
2325             for Entry in PcdDYE[:]:
2326                 DynamicExSection += "  " + Entry + "\n"
2327             DynamicExSection += "\n"
2328         if (len(PcdDYEIa32) > 0):
2329             DynamicExSection += "[PcdEx.IA32]\n"
2330             for Entry in PcdDYEIa32[:]:
2331                 DynamicExSection += "  " + Entry + "\n"
2332             DynamicExSection += "\n"
2333         if (len(PcdDYEX64) > 0):
2334             DynamicExSection += "[PcdEx.X64]\n"
2335             for Entry in PcdDYEX64[:]:
2336                 DynamicExSection += "  " + Entry + "\n"
2337             DynamicExSection += "\n"
2338         if (len(PcdDYEIpf) > 0):
2339             DynamicExSection += "[PcdEx.IPF]\n"
2340             for Entry in PcdDYEIpf[:]:
2341                 DynamicExSection += "  " + Entry + "\n"
2342             DynamicExSection += "\n"
2343         if (len(PcdDYEEbc) > 0):
2344             DynamicExSection += "[PcdEx.EBC]\n"
2345             for Entry in PcdDYEEbc[:]:
2346                 DynamicExSection += "  " + Entry + "\n"
2347             DynamicExSection += "\n"
2348     
2349         Output.append(DynamicExSection)
2350         if (options.debug):
2351             print DynamicExSection
2352   
2353     if ((len(PcdDY)+len(PcdDYIa32)+len(PcdDYX64)+len(PcdDYIpf)+len(PcdDYEbc)) > 0):
2354 ##        DynamicSection = "\n" + "#"*80 + "\n#\n"
2355 ##        DynamicSection += "# Pcd DYNAMIC - list of PCDs that this module is coded for.\n"
2356 ##        DynamicSection += "#\n" + "#"*80 + "\n\n"
2357       
2358         DynamicSection = "\n"
2359         if (len(PcdDY) > 0):
2360             DynamicSection += "[Pcd.common]\n"
2361             for Entry in PcdDY[:]:
2362                 DynamicSection += "  " + Entry + "\n"
2363             DynamicSection += "\n"
2364         if (len(PcdDYIa32) > 0):
2365             DynamicSection += "[Pcd.IA32]\n"
2366             for Entry in PcdDYIa32[:]:
2367                 DynamicSection += "  " + Entry + "\n"
2368             DynamicSection += "\n"
2369         if (len(PcdDYX64) > 0):
2370             DynamicSection += "[Pcd.X64]\n"
2371             for Entry in PcdDYX64[:]:
2372                 DynamicSection += "  " + Entry + "\n"
2373             DynamicSection += "\n"
2374         if (len(PcdDYIpf) > 0):
2375             DynamicSection += "[Pcd.IPF]\n"
2376             for Entry in PcdDYIpf[:]:
2377                 DynamicSection += "  " + Entry + "\n"
2378             DynamicSection += "\n"
2379         if (len(PcdDYEbc) > 0):
2380             DynamicSection += "[Pcd.EBC]\n"
2381             for Entry in PcdDYEbc[:]:
2382                 DynamicSection += "  " + Entry + "\n"
2383             DynamicSection += "\n"
2384     
2385         Output.append(DynamicSection)
2386         if (options.debug):
2387             print DynamicSection
2388   
2389     if ((len(Depex) + len(DepexIa32) + len(DepexX64) + len(DepexIpf) + len(DepexEbc)) > 0):
2390         """ We do this if and only if we have Package Dependencies """
2391 ##        Dpx = "\n" + "#"*80 + "\n#\n"
2392 ##        Dpx += "# Dependency Expression Section - list of Dependency expressions that are required for\n"
2393 ##        Dpx += "#                              this module.\n"
2394 ##        Dpx += "#\n" + "#"*80 + "\n\n"
2395         Dpx = "\n"
2396         if (len(Depex) > 0):
2397             Dpx += "[Depex]\n"
2398             for lc in Depex[:]:
2399                 Dpx += "  " + lc + "\n"
2400             Dpx += "\n"
2401
2402         if (len(DepexIa32) > 0):
2403             Dpx += "[Depex.IA32]\n"
2404             for lc in DepexIa32[:]:
2405                 Dpx += "  " + lc + "\n"
2406             Dpx += "\n"
2407
2408         if (len(DepexX64) > 0):
2409             Dpx += "[Depex.X64]\n"
2410             for lc in DepexX64[:]:
2411                 Dpx += "  " + lc + "\n"
2412             Dpx += "\n"
2413
2414         if (len(DepexIpf) > 0):
2415             Dpx += "[Depex.IPF]\n"
2416             for lc in DepexIpf[:]:
2417                 Dpx += "  " + lc + "\n"
2418             Dpx += "\n"
2419
2420         if (len(DepexEbc) > 0):
2421             Dpx += "[Depex.EBC]\n"
2422             for lc in DepexEbc[:]:
2423                 Dpx += "  " + lc + "\n"
2424             Dpx += "\n"
2425
2426         Output.append(Dpx)
2427         if (options.debug):
2428             print Dpx
2429             
2430     if (len(MBOlines) > 0):
2431         BuildSection = ""
2432 ##        BuildSection = "\n" + "#"*80 + "\n#\n"
2433 ##        BuildSection += "# Build Options - list of custom build options for this module.\n"
2434 ##        BuildSection += "#\n" + "#"*80 + "\n\n"
2435         BuildSection += "\n[BuildOptions]\n"
2436         for mbo in MBOlines:
2437             tool, targs = mbo.split("=",2)
2438             BuildSection += "  %-40s = %s\n" %  (tool.strip(), targs.strip())
2439
2440         Output.append(BuildSection)
2441         if (options.debug):
2442             print BuildSection
2443   
2444
2445     if (len(UEList) > 0):
2446         UserExtensionSection = ""
2447         for UE in UEList[:]:
2448             UserExtensionSection += "[UserExtensions." + UE[0] + '."' + UE[1] + '"]\n'
2449             if (len(UE[2]) > 0):
2450                 UserExtensionSection += '"' + UE[2] + '"\n'
2451             else:
2452                 UserExtensionSection += "\n"
2453   
2454         Output.append(UserExtensionSection)
2455         if (options.debug):
2456             print UserExtensionSection
2457
2458     print "write file", outputFile
2459     if (options.autowrite):
2460         fo = open(outputFile, "w")
2461         for Section in Output[:]:
2462             fo.writelines(Section)
2463             if (options.verbose > 1):
2464                 print Section
2465         fo.close()
2466     elif (options.outfile):
2467         fo = open(outputFile, "w")
2468         for Section in Output[:]:
2469             fo.writelines(Section)
2470         fo.close()
2471     else:
2472         for Section in Output[:]:
2473             print Section
2474
2475   
2476 if __name__ == '__main__':
2477
2478     global options
2479     global args
2480     options,args = myOptionParser()
2481     
2482     main()
2483     sys.exit(0)
2484