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