X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FPython%2FGenMake.py;h=171a6d79bd7744f1122c573a2fce3410464caece;hp=56401fbbc0854c766169924c93e6ed39c02a183c;hb=dd51a993419cb90cc954aa4d9ae53fb012991d21;hpb=0026dbe0acd9f19489129dc050158e999e0bb795 diff --git a/Tools/Python/GenMake.py b/Tools/Python/GenMake.py index 56401fbbc0..171a6d79bd 100755 --- a/Tools/Python/GenMake.py +++ b/Tools/Python/GenMake.py @@ -1,89 +1,114 @@ #!/usr/bin/env python -"""Create Makefiles for the MdePkg.""" +"""Create GNU Makefiles for the Libraries of the MdePkg.""" import os, sys, getopt, string, xml.dom.minidom, shutil from XmlRoutines import * from WorkspaceRoutines import * -ARCH = "X64" +Makefile = string.Template("""ARCH = $ARCH -Makefile = """MAKEROOT ?= .. +MAKEROOT ?= ../.. -LIBNAME = %s +VPATH = .. -OBJECTS = %s +$IDENTIFIER -include $(MAKEROOT)/lib.makefile -""" +OBJECTS = $OBJECTS -def openMdeSpd(): +include $$(MAKEROOT)/lib.makefile +""") - """Open the MdePkg.spd and process the msa files.""" +def openSpd(spdFile): - db = xml.dom.minidom.parse(inWorkspace("MdePkg/MdePkg.spd")) + """Open the spdFile and process the msa files it contains.""" - for msaFile in XmlList(db, "/PackageSurfaceArea/MsaFiles/Filename"): - msaFileName = XmlElementData(msaFile) - DoLib(msaFileName) + db = xml.dom.minidom.parse(inWorkspace(spdFile)) - return db + 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() def inMde(f): """Make a path relative to the Mde Pkg root dir.""" return inWorkspace(os.path.join("MdePkg", f)) -def DoLib(msafile): +def doLib(msafile, arch): """Create a directory with the sources, AutoGen.h and a makefile.""" - sources = [] + objects = [] msa = xml.dom.minidom.parse(inMde(msafile)) - libName = str(XmlElement(msa, "/ModuleSurfaceArea/MsaHeader/ModuleName")) + modName = str(XmlElement(msa, "/ModuleSurfaceArea/MsaHeader/ModuleName")) base, _ = os.path.splitext(msafile) msabase = os.path.basename(base) suppArch = str(XmlElement(msa, "/ModuleSurfaceArea/ModuleDefinitions/SupportedArchitectures")) - if not ARCH in string.split(suppArch, " "): + if not arch in string.split(suppArch, " "): return - try: - os.path.isdir(libName) or os.mkdir(libName); - except: - print "Error: file %s exists" % libName - sys.exit() - + # What kind of module is this? + + # 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 ) + mkdir(buildDir) - for msaFile in XmlList(msa, "/ModuleSurfaceArea/SourceFiles/Filename"): + for sourceFile in XmlList(msa, "/ModuleSurfaceArea/SourceFiles/Filename"): - msaFileName = str(XmlElementData(msaFile)) - arch = msaFile.getAttribute("SupArchList") - toolchain = msaFile.getAttribute("ToolChainFamily") - base, ext = os.path.splitext(msaFileName) + sourceFileName = str(XmlElementData(sourceFile)) + suppArchs = sourceFile.getAttribute("SupArchList").split(" ") + toolchain = sourceFile.getAttribute("ToolChainFamily") + base, ext = os.path.splitext(sourceFileName) - if arch in ["", ARCH] and (ext in [".c", ".h"] or toolchain in ["GCC"]): + if (suppArchs == [""] or arch in suppArchs) and toolchain in ["", "GCC"] and ext in [".c", ".h", ".S"]: if ext in [".c", ".S"]: - sources.append(str(base+".o")) - targetDir = os.path.join(libName, os.path.dirname(msaFileName)) - try: - os.makedirs(targetDir) - except: - pass - shutil.copy(inMde(os.path.join(os.path.dirname(msafile), msaFileName)), - targetDir) + obj = str(base+".o") + if obj in objects: + print "Error: The msa file %s is ambiguous. There are mutliple sources that can produce the object file %s. Please fix it." % (msafile, obj) + sys.exit() + else: + objects.append(obj) + sourceDir = os.path.join(modName, os.path.dirname(sourceFileName)) + mkdir(sourceDir) + mkdir(os.path.join(buildDir, os.path.dirname(sourceFileName))) + shutil.copy(inMde(os.path.join(os.path.dirname(msafile), sourceFileName)), + sourceDir) # Write a Makefile for this module - f = open(os.path.join(libName, "Makefile"), "w") - f.write(Makefile % (libName, string.join(sources, " "))) + f = open(os.path.join(buildDir, "Makefile"), "w") + f.write(Makefile.substitute(ARCH=arch, IDENTIFIER=identifier, OBJECTS=string.join(objects, " "))) f.close() # Right now we are getting the AutoGen.h file from a previous build. We # could create it from scratch also. - shutil.copy(inWorkspace("Build/Mde/DEBUG_UNIXGCC/%s/MdePkg/Library/%s/%s/DEBUG/AutoGen.h") % (ARCH, libName, msabase), libName) + shutil.copy(inWorkspace("Build/Mde/DEBUG_UNIXGCC/%s/MdePkg/Library/%s/%s/DEBUG/AutoGen.h") % (arch, modName, msabase), buildDir) # This acts like the main() function for the script, unless it is 'import'ed # into another script. if __name__ == '__main__': - openMdeSpd(); + openSpd("MdePkg/MdePkg.spd")