]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Python/GenMake.py
Mark some .c files as MSFT only.
[mirror_edk2.git] / Tools / Python / GenMake.py
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 openMdeSpd(arch):
33
34 """Open the MdePkg.spd and process the msa files."""
35
36 db = xml.dom.minidom.parse(inWorkspace("MdePkg/MdePkg.spd"))
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 sources = []
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 (ext in [".c", ".h", ".S"] or toolchain in ["GCC"]):
76 if ext in [".c", ".S"]:
77 sources.append(str(base+".o"))
78 sourceDir = os.path.join(libName, os.path.dirname(sourceFileName))
79 mkdir(sourceDir)
80 mkdir(os.path.join(buildDir, os.path.dirname(sourceFileName)))
81 if copyingSources :
82 shutil.copy(inMde(os.path.join(os.path.dirname(msafile), sourceFileName)),
83 sourceDir)
84
85 # Write a Makefile for this module
86 f = open(os.path.join(buildDir, "Makefile"), "w")
87 f.write(Makefile.substitute(ARCH=arch, LIBNAME=libName, OBJECTS=string.join(sources, " ")))
88 f.close()
89
90 # Right now we are getting the AutoGen.h file from a previous build. We
91 # could create it from scratch also.
92 shutil.copy(inWorkspace("Build/Mde/DEBUG_UNIXGCC/%s/MdePkg/Library/%s/%s/DEBUG/AutoGen.h") % (arch, libName, msabase), buildDir)
93
94 # This acts like the main() function for the script, unless it is 'import'ed
95 # into another script.
96 if __name__ == '__main__':
97
98 for arch in ["IA32", "X64"]:
99 openMdeSpd(arch);