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