]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Python/GenMake.py
Add a python script that can generate gnu makefiles for the mde package.
[mirror_edk2.git] / Tools / Python / GenMake.py
1 #!/usr/bin/env python
2
3 """Create Makefiles for the MdePkg."""
4
5 import os, sys, getopt, string, xml.dom.minidom, shutil
6 from XmlRoutines import *
7 from WorkspaceRoutines import *
8
9 ARCH = "X64"
10
11 Makefile = """MAKEROOT ?= ..
12
13 LIBNAME = %s
14
15 OBJECTS = %s
16
17 include $(MAKEROOT)/lib.makefile
18 """
19
20 def openMdeSpd():
21
22 """Open the MdePkg.spd and process the msa files."""
23
24 db = xml.dom.minidom.parse(inWorkspace("MdePkg/MdePkg.spd"))
25
26 for msaFile in XmlList(db, "/PackageSurfaceArea/MsaFiles/Filename"):
27 msaFileName = XmlElementData(msaFile)
28 DoLib(msaFileName)
29
30 return db
31
32 def inMde(f):
33 """Make a path relative to the Mde Pkg root dir."""
34 return inWorkspace(os.path.join("MdePkg", f))
35
36 def DoLib(msafile):
37
38 """Create a directory with the sources, AutoGen.h and a makefile."""
39
40 sources = []
41
42 msa = xml.dom.minidom.parse(inMde(msafile))
43 libName = str(XmlElement(msa, "/ModuleSurfaceArea/MsaHeader/ModuleName"))
44 base, _ = os.path.splitext(msafile)
45 msabase = os.path.basename(base)
46
47 suppArch = str(XmlElement(msa, "/ModuleSurfaceArea/ModuleDefinitions/SupportedArchitectures"))
48 if not ARCH in string.split(suppArch, " "):
49 return
50
51 try:
52 os.path.isdir(libName) or os.mkdir(libName);
53 except:
54 print "Error: file %s exists" % libName
55 sys.exit()
56
57
58 for msaFile in XmlList(msa, "/ModuleSurfaceArea/SourceFiles/Filename"):
59
60 msaFileName = str(XmlElementData(msaFile))
61 arch = msaFile.getAttribute("SupArchList")
62 toolchain = msaFile.getAttribute("ToolChainFamily")
63 base, ext = os.path.splitext(msaFileName)
64
65 if arch in ["", ARCH] and (ext in [".c", ".h"] or toolchain in ["GCC"]):
66 if ext in [".c", ".S"]:
67 sources.append(str(base+".o"))
68 targetDir = os.path.join(libName, os.path.dirname(msaFileName))
69 try:
70 os.makedirs(targetDir)
71 except:
72 pass
73 shutil.copy(inMde(os.path.join(os.path.dirname(msafile), msaFileName)),
74 targetDir)
75
76 # Write a Makefile for this module
77 f = open(os.path.join(libName, "Makefile"), "w")
78 f.write(Makefile % (libName, string.join(sources, " ")))
79 f.close()
80
81 # Right now we are getting the AutoGen.h file from a previous build. We
82 # could create it from scratch also.
83 shutil.copy(inWorkspace("Build/Mde/DEBUG_UNIXGCC/%s/MdePkg/Library/%s/%s/DEBUG/AutoGen.h") % (ARCH, libName, msabase), libName)
84
85 # This acts like the main() function for the script, unless it is 'import'ed
86 # into another script.
87 if __name__ == '__main__':
88
89 openMdeSpd();