2007-01-10 03:23:35 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2007-01-10 23:36:15 +01:00
|
|
|
"""Create GNU Makefiles for the Libraries of the MdePkg."""
|
2007-01-10 03:23:35 +01:00
|
|
|
|
|
|
|
import os, sys, getopt, string, xml.dom.minidom, shutil
|
|
|
|
from XmlRoutines import *
|
|
|
|
from WorkspaceRoutines import *
|
|
|
|
|
2007-01-10 23:36:15 +01:00
|
|
|
Makefile = string.Template("""ARCH = $ARCH
|
2007-01-10 03:23:35 +01:00
|
|
|
|
2007-01-10 23:36:15 +01:00
|
|
|
MAKEROOT ?= ../..
|
2007-01-10 03:23:35 +01:00
|
|
|
|
2007-01-10 23:36:15 +01:00
|
|
|
VPATH = ..
|
2007-01-10 03:23:35 +01:00
|
|
|
|
2007-01-17 01:16:32 +01:00
|
|
|
$IDENTIFIER
|
2007-01-10 03:23:35 +01:00
|
|
|
|
2007-01-10 23:36:15 +01:00
|
|
|
OBJECTS = $OBJECTS
|
|
|
|
|
|
|
|
include $$(MAKEROOT)/lib.makefile
|
|
|
|
""")
|
|
|
|
|
2007-01-17 01:16:32 +01:00
|
|
|
def openSpd(spdFile):
|
2007-01-10 03:23:35 +01:00
|
|
|
|
2007-01-11 08:11:34 +01:00
|
|
|
"""Open the spdFile and process the msa files it contains."""
|
2007-01-10 03:23:35 +01:00
|
|
|
|
2007-01-11 08:11:34 +01:00
|
|
|
db = xml.dom.minidom.parse(inWorkspace(spdFile))
|
2007-01-10 03:23:35 +01:00
|
|
|
|
2007-01-17 01:16:32 +01:00
|
|
|
for arch in ["IA32", "X64"]:
|
|
|
|
for msaFile in XmlList(db, "/PackageSurfaceArea/MsaFiles/Filename"):
|
|
|
|
msaFileName = XmlElementData(msaFile)
|
|
|
|
doLib(msaFileName, arch)
|
|
|
|
|
|
|
|
# Copy the Include tree for the Package
|
|
|
|
packageDir = os.path.dirname(spdFile)
|
|
|
|
mkdir(packageDir)
|
|
|
|
if not os.path.exists(os.path.join(packageDir, "Include")):
|
|
|
|
print "Exporting the include dir..."
|
|
|
|
os.system("svn export %s %s" %
|
|
|
|
(inWorkspace(os.path.join(packageDir, "Include")),
|
|
|
|
os.path.join(packageDir, "Include")))
|
|
|
|
else:
|
|
|
|
print "Error: The directory '%s' is in the way. Please move it." % os.path.join(packageDir, "Include")
|
|
|
|
sys.exit()
|
2007-01-10 03:23:35 +01:00
|
|
|
|
|
|
|
def inMde(f):
|
|
|
|
"""Make a path relative to the Mde Pkg root dir."""
|
|
|
|
return inWorkspace(os.path.join("MdePkg", f))
|
|
|
|
|
2007-01-10 23:36:15 +01:00
|
|
|
def doLib(msafile, arch):
|
2007-01-10 03:23:35 +01:00
|
|
|
|
|
|
|
"""Create a directory with the sources, AutoGen.h and a makefile."""
|
|
|
|
|
2007-01-11 01:14:05 +01:00
|
|
|
objects = []
|
2007-01-10 03:23:35 +01:00
|
|
|
|
|
|
|
msa = xml.dom.minidom.parse(inMde(msafile))
|
2007-01-17 01:16:32 +01:00
|
|
|
modName = str(XmlElement(msa, "/ModuleSurfaceArea/MsaHeader/ModuleName"))
|
2007-01-10 03:23:35 +01:00
|
|
|
base, _ = os.path.splitext(msafile)
|
|
|
|
msabase = os.path.basename(base)
|
|
|
|
|
|
|
|
suppArch = str(XmlElement(msa, "/ModuleSurfaceArea/ModuleDefinitions/SupportedArchitectures"))
|
2007-01-10 23:36:15 +01:00
|
|
|
if not arch in string.split(suppArch, " "):
|
2007-01-10 03:23:35 +01:00
|
|
|
return
|
|
|
|
|
2007-01-17 01:16:32 +01:00
|
|
|
# What kind of module is this?
|
2007-01-10 23:36:15 +01:00
|
|
|
|
2007-01-17 01:16:32 +01:00
|
|
|
# Assume it is a driver.
|
|
|
|
identifier = "DRIVERNAME = %s" % modName
|
|
|
|
|
|
|
|
# Let's see if it claims to produce a library class.
|
|
|
|
for libClass in XmlList(msa, "/ModuleSurfaceArea/LibraryClassDefinitions/LibraryClass"):
|
|
|
|
if libClass.getAttribute("Usage") == "ALWAYS_PRODUCED":
|
|
|
|
# It's a library.
|
|
|
|
identifier = "LIBNAME = %s" % modName
|
|
|
|
|
|
|
|
mkdir(modName)
|
|
|
|
|
|
|
|
buildDir = os.path.join(modName, "build-%s" % arch )
|
2007-01-10 23:36:15 +01:00
|
|
|
mkdir(buildDir)
|
2007-01-10 03:23:35 +01:00
|
|
|
|
2007-01-10 23:36:15 +01:00
|
|
|
for sourceFile in XmlList(msa, "/ModuleSurfaceArea/SourceFiles/Filename"):
|
2007-01-10 03:23:35 +01:00
|
|
|
|
2007-01-10 23:36:15 +01:00
|
|
|
sourceFileName = str(XmlElementData(sourceFile))
|
|
|
|
suppArchs = sourceFile.getAttribute("SupArchList").split(" ")
|
|
|
|
toolchain = sourceFile.getAttribute("ToolChainFamily")
|
|
|
|
base, ext = os.path.splitext(sourceFileName)
|
2007-01-10 03:23:35 +01:00
|
|
|
|
2007-01-17 01:16:32 +01:00
|
|
|
if (suppArchs == [""] or arch in suppArchs) and toolchain in ["", "GCC"] and ext in [".c", ".h", ".S"]:
|
2007-01-10 03:23:35 +01:00
|
|
|
if ext in [".c", ".S"]:
|
2007-01-11 01:14:05 +01:00
|
|
|
obj = str(base+".o")
|
|
|
|
if obj in objects:
|
2007-01-11 08:11:34 +01:00
|
|
|
print "Error: The msa file %s is ambiguous. There are mutliple sources that can produce the object file %s. Please fix it." % (msafile, obj)
|
2007-01-11 01:14:05 +01:00
|
|
|
sys.exit()
|
|
|
|
else:
|
|
|
|
objects.append(obj)
|
2007-01-17 01:16:32 +01:00
|
|
|
sourceDir = os.path.join(modName, os.path.dirname(sourceFileName))
|
2007-01-10 23:36:15 +01:00
|
|
|
mkdir(sourceDir)
|
|
|
|
mkdir(os.path.join(buildDir, os.path.dirname(sourceFileName)))
|
2007-01-17 01:16:32 +01:00
|
|
|
shutil.copy(inMde(os.path.join(os.path.dirname(msafile), sourceFileName)),
|
|
|
|
sourceDir)
|
2007-01-10 03:23:35 +01:00
|
|
|
|
|
|
|
# Write a Makefile for this module
|
2007-01-10 23:36:15 +01:00
|
|
|
f = open(os.path.join(buildDir, "Makefile"), "w")
|
2007-01-17 01:16:32 +01:00
|
|
|
f.write(Makefile.substitute(ARCH=arch, IDENTIFIER=identifier, OBJECTS=string.join(objects, " ")))
|
2007-01-10 03:23:35 +01:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
# Right now we are getting the AutoGen.h file from a previous build. We
|
|
|
|
# could create it from scratch also.
|
2007-01-17 01:16:32 +01:00
|
|
|
shutil.copy(inWorkspace("Build/Mde/DEBUG_UNIXGCC/%s/MdePkg/Library/%s/%s/DEBUG/AutoGen.h") % (arch, modName, msabase), buildDir)
|
2007-01-10 03:23:35 +01:00
|
|
|
|
|
|
|
# This acts like the main() function for the script, unless it is 'import'ed
|
|
|
|
# into another script.
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
2007-01-17 01:16:32 +01:00
|
|
|
openSpd("MdePkg/MdePkg.spd")
|