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