]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Python/GenMake.py
3 """Create GNU Makefiles for the Libraries of the MdePkg."""
5 import os
, sys
, getopt
, string
, xml
.dom
.minidom
, shutil
6 from XmlRoutines
import *
7 from WorkspaceRoutines
import *
11 Makefile
= string
.Template("""ARCH = $ARCH
21 include $$(MAKEROOT)/lib.makefile
25 """Make a directory if it is not there already."""
32 def openSpd(spdFile
, arch
):
34 """Open the spdFile and process the msa files it contains."""
36 db
= xml
.dom
.minidom
.parse(inWorkspace(spdFile
))
38 for msaFile
in XmlList(db
, "/PackageSurfaceArea/MsaFiles/Filename"):
39 msaFileName
= XmlElementData(msaFile
)
40 doLib(msaFileName
, arch
)
45 """Make a path relative to the Mde Pkg root dir."""
46 return inWorkspace(os
.path
.join("MdePkg", f
))
48 def doLib(msafile
, arch
):
50 """Create a directory with the sources, AutoGen.h and a makefile."""
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
)
59 suppArch
= str(XmlElement(msa
, "/ModuleSurfaceArea/ModuleDefinitions/SupportedArchitectures"))
60 if not arch
in string
.split(suppArch
, " "):
65 buildDir
= os
.path
.join(libName
, "build-%s" % arch
)
68 for sourceFile
in XmlList(msa
, "/ModuleSurfaceArea/SourceFiles/Filename"):
70 sourceFileName
= str(XmlElementData(sourceFile
))
71 suppArchs
= sourceFile
.getAttribute("SupArchList").split(" ")
72 toolchain
= sourceFile
.getAttribute("ToolChainFamily")
73 base
, ext
= os
.path
.splitext(sourceFileName
)
75 if ( suppArchs
== [""] or arch
in suppArchs
) and toolchain
in ["", "GCC"] and ext
in [".c", ".h", ".S"]:
76 if ext
in [".c", ".S"]:
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
)
83 sourceDir
= os
.path
.join(libName
, os
.path
.dirname(sourceFileName
))
85 mkdir(os
.path
.join(buildDir
, os
.path
.dirname(sourceFileName
)))
87 shutil
.copy(inMde(os
.path
.join(os
.path
.dirname(msafile
), sourceFileName
)),
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
, " ")))
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
)
99 # This acts like the main() function for the script, unless it is 'import'ed
100 # into another script.
101 if __name__
== '__main__':
103 for arch
in ["IA32", "X64"]:
104 openSpd("MdePkg/MdePkg.spd", arch
);