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 | Makefile = string.Template("""ARCH = $ARCH |
0026dbe0 |
10 | |
07253e8e |
11 | MAKEROOT ?= ../.. |
0026dbe0 |
12 | |
07253e8e |
13 | VPATH = .. |
0026dbe0 |
14 | |
26e72077 |
15 | $IDENTIFIER |
0026dbe0 |
16 | |
07253e8e |
17 | OBJECTS = $OBJECTS |
18 | |
19 | include $$(MAKEROOT)/lib.makefile |
20 | """) |
21 | |
26e72077 |
22 | def openSpd(spdFile): |
0026dbe0 |
23 | |
b12dbde3 |
24 | """Open the spdFile and process the msa files it contains.""" |
0026dbe0 |
25 | |
b12dbde3 |
26 | db = xml.dom.minidom.parse(inWorkspace(spdFile)) |
0026dbe0 |
27 | |
26e72077 |
28 | for arch in ["IA32", "X64"]: |
29 | for msaFile in XmlList(db, "/PackageSurfaceArea/MsaFiles/Filename"): |
30 | msaFileName = XmlElementData(msaFile) |
31 | doLib(msaFileName, arch) |
32 | |
33 | # Copy the Include tree for the Package |
34 | packageDir = os.path.dirname(spdFile) |
35 | mkdir(packageDir) |
36 | if not os.path.exists(os.path.join(packageDir, "Include")): |
37 | print "Exporting the include dir..." |
38 | os.system("svn export %s %s" % |
39 | (inWorkspace(os.path.join(packageDir, "Include")), |
40 | os.path.join(packageDir, "Include"))) |
41 | else: |
42 | print "Error: The directory '%s' is in the way. Please move it." % os.path.join(packageDir, "Include") |
43 | sys.exit() |
0026dbe0 |
44 | |
45 | def inMde(f): |
46 | """Make a path relative to the Mde Pkg root dir.""" |
47 | return inWorkspace(os.path.join("MdePkg", f)) |
48 | |
07253e8e |
49 | def doLib(msafile, arch): |
0026dbe0 |
50 | |
51 | """Create a directory with the sources, AutoGen.h and a makefile.""" |
52 | |
b23e12fa |
53 | objects = [] |
0026dbe0 |
54 | |
55 | msa = xml.dom.minidom.parse(inMde(msafile)) |
26e72077 |
56 | modName = str(XmlElement(msa, "/ModuleSurfaceArea/MsaHeader/ModuleName")) |
0026dbe0 |
57 | base, _ = os.path.splitext(msafile) |
58 | msabase = os.path.basename(base) |
59 | |
60 | suppArch = str(XmlElement(msa, "/ModuleSurfaceArea/ModuleDefinitions/SupportedArchitectures")) |
07253e8e |
61 | if not arch in string.split(suppArch, " "): |
0026dbe0 |
62 | return |
63 | |
26e72077 |
64 | # What kind of module is this? |
07253e8e |
65 | |
26e72077 |
66 | # Assume it is a driver. |
67 | identifier = "DRIVERNAME = %s" % modName |
68 | |
69 | # Let's see if it claims to produce a library class. |
70 | for libClass in XmlList(msa, "/ModuleSurfaceArea/LibraryClassDefinitions/LibraryClass"): |
71 | if libClass.getAttribute("Usage") == "ALWAYS_PRODUCED": |
72 | # It's a library. |
73 | identifier = "LIBNAME = %s" % modName |
74 | |
75 | mkdir(modName) |
76 | |
77 | buildDir = os.path.join(modName, "build-%s" % arch ) |
07253e8e |
78 | mkdir(buildDir) |
0026dbe0 |
79 | |
07253e8e |
80 | for sourceFile in XmlList(msa, "/ModuleSurfaceArea/SourceFiles/Filename"): |
0026dbe0 |
81 | |
07253e8e |
82 | sourceFileName = str(XmlElementData(sourceFile)) |
83 | suppArchs = sourceFile.getAttribute("SupArchList").split(" ") |
84 | toolchain = sourceFile.getAttribute("ToolChainFamily") |
85 | base, ext = os.path.splitext(sourceFileName) |
0026dbe0 |
86 | |
26e72077 |
87 | if (suppArchs == [""] or arch in suppArchs) and toolchain in ["", "GCC"] and ext in [".c", ".h", ".S"]: |
0026dbe0 |
88 | if ext in [".c", ".S"]: |
b23e12fa |
89 | obj = str(base+".o") |
90 | if obj in objects: |
b12dbde3 |
91 | print "Error: The msa file %s is ambiguous. There are mutliple sources that can produce the object file %s. Please fix it." % (msafile, obj) |
b23e12fa |
92 | sys.exit() |
93 | else: |
94 | objects.append(obj) |
26e72077 |
95 | sourceDir = os.path.join(modName, os.path.dirname(sourceFileName)) |
07253e8e |
96 | mkdir(sourceDir) |
97 | mkdir(os.path.join(buildDir, os.path.dirname(sourceFileName))) |
26e72077 |
98 | shutil.copy(inMde(os.path.join(os.path.dirname(msafile), sourceFileName)), |
99 | sourceDir) |
0026dbe0 |
100 | |
101 | # Write a Makefile for this module |
07253e8e |
102 | f = open(os.path.join(buildDir, "Makefile"), "w") |
26e72077 |
103 | f.write(Makefile.substitute(ARCH=arch, IDENTIFIER=identifier, OBJECTS=string.join(objects, " "))) |
0026dbe0 |
104 | f.close() |
105 | |
106 | # Right now we are getting the AutoGen.h file from a previous build. We |
107 | # could create it from scratch also. |
26e72077 |
108 | shutil.copy(inWorkspace("Build/Mde/DEBUG_UNIXGCC/%s/MdePkg/Library/%s/%s/DEBUG/AutoGen.h") % (arch, modName, msabase), buildDir) |
0026dbe0 |
109 | |
110 | # This acts like the main() function for the script, unless it is 'import'ed |
111 | # into another script. |
112 | if __name__ == '__main__': |
113 | |
26e72077 |
114 | openSpd("MdePkg/MdePkg.spd") |