]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python | |
2 | ||
3 | """Create GNU Makefiles for the Libraries of the MdePkg.""" | |
4 | ||
5 | import os, sys, getopt, string, xml.dom.minidom, shutil | |
6 | from XmlRoutines import * | |
7 | from WorkspaceRoutines import * | |
8 | ||
9 | copyingSources = 1 | |
10 | ||
11 | Makefile = string.Template("""ARCH = $ARCH | |
12 | ||
13 | MAKEROOT ?= ../.. | |
14 | ||
15 | VPATH = .. | |
16 | ||
17 | LIBNAME = $LIBNAME | |
18 | ||
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 openSpd(spdFile, arch): | |
33 | ||
34 | """Open the spdFile and process the msa files it contains.""" | |
35 | ||
36 | db = xml.dom.minidom.parse(inWorkspace(spdFile)) | |
37 | ||
38 | for msaFile in XmlList(db, "/PackageSurfaceArea/MsaFiles/Filename"): | |
39 | msaFileName = XmlElementData(msaFile) | |
40 | doLib(msaFileName, arch) | |
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 | ||
48 | def doLib(msafile, arch): | |
49 | ||
50 | """Create a directory with the sources, AutoGen.h and a makefile.""" | |
51 | ||
52 | objects = [] | |
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")) | |
60 | if not arch in string.split(suppArch, " "): | |
61 | return | |
62 | ||
63 | mkdir(libName); | |
64 | ||
65 | buildDir = os.path.join(libName, "build-%s" % arch ) | |
66 | mkdir(buildDir) | |
67 | ||
68 | for sourceFile in XmlList(msa, "/ModuleSurfaceArea/SourceFiles/Filename"): | |
69 | ||
70 | sourceFileName = str(XmlElementData(sourceFile)) | |
71 | suppArchs = sourceFile.getAttribute("SupArchList").split(" ") | |
72 | toolchain = sourceFile.getAttribute("ToolChainFamily") | |
73 | base, ext = os.path.splitext(sourceFileName) | |
74 | ||
75 | if ( suppArchs == [""] or arch in suppArchs) and toolchain in ["", "GCC"] and ext in [".c", ".h", ".S"]: | |
76 | if ext in [".c", ".S"]: | |
77 | obj = str(base+".o") | |
78 | if obj in objects: | |
79 | print "Error: The msa file %s is ambiguous. There are mutliple sources that can produce the object file %s. Please fix it." % (msafile, obj) | |
80 | sys.exit() | |
81 | else: | |
82 | objects.append(obj) | |
83 | sourceDir = os.path.join(libName, os.path.dirname(sourceFileName)) | |
84 | mkdir(sourceDir) | |
85 | mkdir(os.path.join(buildDir, os.path.dirname(sourceFileName))) | |
86 | if copyingSources : | |
87 | shutil.copy(inMde(os.path.join(os.path.dirname(msafile), sourceFileName)), | |
88 | sourceDir) | |
89 | ||
90 | # Write a Makefile for this module | |
91 | f = open(os.path.join(buildDir, "Makefile"), "w") | |
92 | f.write(Makefile.substitute(ARCH=arch, LIBNAME=libName, OBJECTS=string.join(objects, " "))) | |
93 | f.close() | |
94 | ||
95 | # Right now we are getting the AutoGen.h file from a previous build. We | |
96 | # could create it from scratch also. | |
97 | shutil.copy(inWorkspace("Build/Mde/DEBUG_UNIXGCC/%s/MdePkg/Library/%s/%s/DEBUG/AutoGen.h") % (arch, libName, msabase), buildDir) | |
98 | ||
99 | # This acts like the main() function for the script, unless it is 'import'ed | |
100 | # into another script. | |
101 | if __name__ == '__main__': | |
102 | ||
103 | for arch in ["IA32", "X64"]: | |
104 | openSpd("MdePkg/MdePkg.spd", arch); |