]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Python/buildgen/BuildFile.py
Move the entrypoint function declarations to AutoGen.h for sake of Intel compiler
[mirror_edk2.git] / Tools / Python / buildgen / BuildFile.py
CommitLineData
28972318 1#!/usr/bin/env python\r
2\r
3# Copyright (c) 2007, Intel Corporation\r
4# All rights reserved. This program and the accompanying materials\r
5# are licensed and made available under the terms and conditions of the BSD License\r
6# which accompanies this distribution. The full text of the license may be found at\r
7# http://opensource.org/licenses/bsd-license.php\r
8#\r
9# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12"""Generate build file for given platform"""\r
13\r
14import os, sys, copy\r
15import xml.dom.minidom, pprint\r
16import FrameworkElement\r
17\r
18from SurfaceAreaElement import *\r
19from XmlRoutines import *\r
20from AntTasks import *\r
21from sets import Set\r
22\r
23class BuildFile:\r
24 def __init__(self, workspace, platform, toolchain, target):\r
25 if workspace == None or workspace == "":\r
26 raise Exception("No workspace, no build")\r
27 if platform == None or platform == "":\r
28 raise Exception("No platform, no build")\r
29 if toolchain == None or toolchain == "":\r
30 raise Exception("No toolchain, no build")\r
31 if target == None or target == "":\r
32 raise Exception("No target, no build")\r
33 \r
34 self.Workspace = workspace\r
35 self.Platform = platform\r
36 self.Toolchain = toolchain\r
37 self.Target = target\r
38 self.Path = ""\r
39\r
40 def Generate(self):\r
41 """Generate the build file"""\r
42 pass\r
43\r
44# generating build.xml for platform\r
45class AntPlatformBuildFile(BuildFile):\r
46 def __init__(self, workspace, platform, toolchain, target):\r
47 BuildFile.__init__(self, workspace, platform, toolchain, target)\r
48 # Form the build file path, hard-coded at present. It should be specified by a configuration file\r
49 self.Path = os.path.join(self.Workspace.Path, self.Platform.OutputPath, target + "_" + toolchain, "build.xml")\r
50 print ""\r
51 # Generate a common build option property file in the format of Java's property file\r
52 self.DefaultBuildOptions()\r
53 \r
54 # new a build file object\r
55 self.BuildXml = AntBuildFile(name="platform", basedir=".", default="all")\r
56 \r
57 # generate the top level properties, tasks, etc.\r
58 self.Header()\r
59 \r
60 # generate "prebuild" target\r
61 self.PreBuild()\r
62 \r
63 # generate "libraries" target for building library modules\r
64 self.Libraries()\r
65 \r
66 # generate "modules" target for building non-library modules\r
67 self.Modules()\r
68 \r
69 # generate "fvs" target for building firmware volume. (not supported yet)\r
70 \r
71 # generate "fds" target for building FlashDevice. (not supported yet)\r
72 \r
73 # generate "postbuild" target\r
74 self.PostBuild()\r
75\r
76 def Generate(self):\r
77 print "Generating platform build file ...", self.Path\r
78 self.BuildXml.Create(self.Path)\r
79\r
80 def Header(self):\r
81 _topLevel = self.BuildXml\r
82 # import external tasks\r
83 _topLevel.SubTask("taskdef", resource="GenBuild.tasks")\r
84 _topLevel.SubTask("taskdef", resource="frameworktasks.tasks")\r
85 _topLevel.SubTask("taskdef", resource="net/sf/antcontrib/antlib.xml")\r
86\r
87 # platform wide properties\r
88 _topLevel.Blankline()\r
89 _topLevel.Comment("WORKSPACE wide attributes")\r
90 _topLevel.SubTask("property", environment="env")\r
91 _topLevel.SubTask("property", name="WORKSPACE_DIR", value="${env.WORKSPACE}")\r
92 _topLevel.SubTask("property", name="CONFIG_DIR", value="${WORKSPACE_DIR}/Tools/Conf")\r
93\r
94 _topLevel.Blankline()\r
95 _topLevel.Comment("Common build attributes")\r
96 _topLevel.SubTask("property", name="THREAD_COUNT", value=self.Workspace.ThreadCount)\r
97 _topLevel.SubTask("property", name="SINGLE_MODULE_BUILD", value="no")\r
98 _topLevel.SubTask("property", name="MODULE_BUILD_TARGET", value="platform_module_build")\r
99\r
100 _topLevel.Blankline()\r
101 _topLevel.SubTask("property", name="TOOLCHAIN", value=self.Toolchain)\r
102 _topLevel.SubTask("property", name="TARGET", value=self.Target)\r
103 \r
104 _topLevel.Blankline()\r
105 _topLevel.Comment("Platform attributes")\r
106 _topLevel.SubTask("property", name="PLATFORM", value=self.Platform.Name)\r
107 _topLevel.SubTask("property", name="PLATFORM_GUID", value=self.Platform.GuidValue)\r
108 _topLevel.SubTask("property", name="PLATFORM_VERSION", value=self.Platform.Version)\r
109 _topLevel.SubTask("property", name="PLATFORM_RELATIVE_DIR", value=self.Platform.Dir)\r
110 _topLevel.SubTask("property", name="PLATFORM_DIR", value="${WORKSPACE_DIR}/${PLATFORM_RELATIVE_DIR}")\r
111 _topLevel.SubTask("property", name="PLATFORM_OUTPUT_DIR", value=self.Platform.OutputPath)\r
112\r
113 # user configurable build path for platform\r
114 _topLevel.Blankline()\r
115 _topLevel.Comment("Common path definition for platform build")\r
116 _topLevel.SubTask("property", file="${WORKSPACE_DIR}/Tools/Python/buildgen/platform_build_path.txt")\r
117 \r
118 # common build tasks in the form of Ant macro\r
119 _topLevel.Blankline()\r
120 _topLevel.Comment("Task Macros for Compiling, Assembling, Linking, etc.")\r
121 _topLevel.SubTask("import", file="${CONFIG_DIR}/BuildMacro.xml")\r
122 _topLevel.Blankline()\r
123 _topLevel.SubTask("echo", message="${PLATFORM}-${PLATFORM_VERSION} (${PLATFORM_RELATIVE_DIR})", level="info")\r
124 \r
125 # define the targets execution sequence\r
126 _topLevel.Blankline()\r
127 _topLevel.Comment("Default target")\r
128 _topLevel.SubTask("target", name="all", depends="prebuild, libraries, modules, postbuild")\r
129\r
130 def PreBuild(self):\r
131 _topLevel = self.BuildXml\r
132 _topLevel.Blankline()\r
133 _topLevel.Comment(" TARGET: prebuild ")\r
134 \r
135 # prebuild is defined by user in the fpd file through <UserExtionsion> element,\r
136 # which has attribute "identifier=0" or "identifier=prebuild"\r
137 prebuildTasks = []\r
138 if self.Platform.UserExtensions.has_key("0"):\r
139 prebuildTasks = self.Platform.UserExtensions["0"]\r
140 elif self.Platform.UserExtensions.has_key("postbuild"):\r
141 prebuildTasks = self.Platform.UserExtensions["prebuild"]\r
142\r
143 _topLevel.SubTask("target", prebuildTasks, name="prebuild")\r
144\r
145 def Libraries(self):\r
146 _topLevel = self.BuildXml\r
147 _topLevel.Blankline()\r
148 _topLevel.Comment(" TARGET: libraries ")\r
149 \r
150 librariesTarget = _topLevel.SubTask("target", name="libraries")\r
151 parallelBuild = librariesTarget.SubTask("parallel", threadCount="${THREAD_COUNT}")\r
152 \r
153 libraryNumber = 0\r
154 for arch in self.Platform.Libraries:\r
155 libraryNumber += len(self.Platform.Libraries[arch])\r
156 libraryIndex = 0\r
157 for arch in self.Platform.Libraries:\r
158 for lib in self.Platform.Libraries[arch]:\r
159 libraryIndex += 1\r
160 print "Generating library build files ... %d%%\r" % int((float(libraryIndex) / float(libraryNumber)) * 100),\r
161 buildFile = AntModuleBuildFile(self.Workspace, self.Platform, lib, self.Toolchain, self.Target, arch)\r
162 buildFile.Generate()\r
163 buildDir = os.path.join("${TARGET_DIR}", arch, lib.Module.Package.SubPath(lib.Module.Dir),\r
164 lib.Module.FileBaseName)\r
165 parallelBuild.SubTask("ant", dir=buildDir,\r
166 #antfile="build.xml",\r
167 inheritAll="true",\r
168 target="${MODULE_BUILD_TARGET}")\r
169 print ""\r
170\r
171 def Modules(self):\r
172 _topLevel = self.BuildXml\r
173 _topLevel.Blankline()\r
174 _topLevel.Comment(" TARGET: modules ")\r
175\r
176 modulesTarget = _topLevel.SubTask("target", name="modules")\r
177 parallelBuild = modulesTarget.SubTask("parallel", threadCount="${THREAD_COUNT}")\r
178\r
179 moduleNumber = 0\r
180 for arch in self.Platform.Modules:\r
181 moduleNumber += len(self.Platform.Modules[arch])\r
182 \r
183 moduleIndex = 0\r
184 for arch in self.Platform.Modules:\r
185 for module in self.Platform.Modules[arch]:\r
186 moduleIndex += 1\r
187 print "Generating module build files ... %d%%\r" % int((float(moduleIndex) / float(moduleNumber)) * 100),\r
188 \r
189 buildDir = os.path.join("${TARGET_DIR}", arch, module.Module.Package.SubPath(module.Module.Dir),\r
190 module.Module.FileBaseName)\r
191 parallelBuild.SubTask("ant", dir=buildDir,\r
192 #antfile="build.xml",\r
193 inheritAll="true",\r
194 target="${MODULE_BUILD_TARGET}")\r
195 buildFile = AntModuleBuildFile(self.Workspace, self.Platform, module, self.Toolchain, self.Target, arch)\r
196 buildFile.Generate()\r
197 print ""\r
198\r
199 def Fvs(self):\r
200 pass\r
201\r
202 def Fds(self):\r
203 pass\r
204\r
205 def PostBuild(self):\r
206 _topLevel = self.BuildXml\r
207 _topLevel.Blankline()\r
208 _topLevel.Comment(" TARGET: postbuild ")\r
209 \r
210 # postbuild is defined by user in the fpd file through <UserExtionsion> element,\r
211 # which has attribute "identifier=1" or "identifier=postbuild"\r
212 postbuildTasks = []\r
213 if self.Platform.UserExtensions.has_key("1"):\r
214 postbuildTasks = self.Platform.UserExtensions["1"]\r
215 elif self.Platform.UserExtensions.has_key("postbuild"):\r
216 postbuildTasks = self.Platform.UserExtensions["postbuild"]\r
217 \r
218 _topLevel.SubTask("target", postbuildTasks, name="postbuild")\r
219\r
220 def Clean(self):\r
221 pass\r
222\r
223 def CleanAll(self):\r
224 pass\r
225\r
226 def UserExtensions(self):\r
227 pass\r
228\r
229 def DefaultBuildOptions(self):\r
230 """Generate ${ARCH}_build.opt which contains the default build&tool definitions"""\r
231 tools = self.Workspace.ToolConfig.ToolCodes\r
232 for arch in self.Workspace.ActiveArchs:\r
233 optFileDir = os.path.join(self.Workspace.Path, self.Platform.OutputPath,\r
234 self.Target + "_" + self.Toolchain)\r
235 optFileName = arch + "_build.opt"\r
236 if not os.path.exists(optFileDir): os.makedirs(optFileDir)\r
237 f = open(os.path.join(optFileDir, optFileName), "w")\r
238 for tool in tools:\r
239 key = (self.Toolchain, self.Target, arch, tool, "FLAGS")\r
240 flag = self.Workspace.ToolConfig[key]\r
241 f.write("DEFAULT_%s_FLAGS=%s\n" % (tool, flag))\r
242\r
243 f.write("\n")\r
244 for tool in tools:\r
245 key = (self.Toolchain, self.Target, arch, tool, "FLAGS")\r
246 if key in self.Platform.BuildOptions:\r
247 flag = self.Platform.BuildOptions[key]\r
248 else:\r
249 key = (self.Toolchain, self.Target, arch, tool, "FAMILY")\r
250 family = self.Workspace.ToolConfig[key]\r
251 key = (family, self.Target, arch, tool, "FLAGS")\r
252 if key in self.Platform.BuildOptions:\r
253 flag = self.Platform.BuildOptions[key]\r
254 else:\r
255 flag = ""\r
256 f.write("PLATFORM_%s_FLAGS=%s\n" % (tool, flag))\r
257\r
258 f.write("\n")\r
259 for tool in tools:\r
260 for attr in self.Workspace.ToolConfig.Attributes:\r
261 if attr == "FLAGS": continue\r
262 key = (self.Toolchain, self.Target, arch, tool, attr)\r
263 value = self.Workspace.ToolConfig[key]\r
264 if attr == "NAME":\r
265 f.write("%s=%s\n" % (tool, value))\r
266 else:\r
267 f.write("%s_%s=%s\n" % (tool, attr, value))\r
268 f.write("%s_FLAGS=${DEFAULT_%s_FLAGS} ${DEFAULT_MODULE_%s_FLAGS} ${PLATFORM_%s_FLAGS} ${MODULE_%s_FLAGS}\n" %\r
269 (tool, tool, tool, tool, tool))\r
270 f.write("\n")\r
271\r
272 f.close()\r
273\r
274class AntModuleBuildFile(BuildFile):\r
275 def __init__(self, workspace, platform, module, toolchain, target, arch):\r
276 BuildFile.__init__(self, workspace, platform, toolchain, target)\r
277 self.Module = module\r
278 self.Arch = arch\r
279 self.Path = os.path.join(self.Workspace.Path, self.Platform.OutputPath,\r
280 target + "_" + toolchain, arch, self.Module.Module.Package.Dir,\r
281 self.Module.Module.Dir, self.Module.Module.FileBaseName, "build.xml")\r
282 self.BuildXml = AntBuildFile(self.Module.Module.Name)\r
283\r
284 self.SourceFiles = self.GetSourceFiles()\r
285 \r
286 self.Header()\r
287 self.PreBuild()\r
288 self.Libraries()\r
289 self.Sourcefiles()\r
290 self.Sections()\r
291 self.Ffs()\r
292 self.PostBuild()\r
293\r
294 def Generate(self):\r
295 # print self.Path,"\r",\r
296 self.BuildXml.Create(self.Path)\r
297\r
298 def Header(self):\r
299 _topLevel = self.BuildXml\r
300 _topLevel.SubTask("taskdef", resource="frameworktasks.tasks")\r
301 _topLevel.SubTask("taskdef", resource="cpptasks.tasks")\r
302 _topLevel.SubTask("taskdef", resource="cpptasks.types")\r
303 _topLevel.SubTask("taskdef", resource="net/sf/antcontrib/antlib.xml")\r
304\r
305 _topLevel.Blankline()\r
306 _topLevel.Comment(" TODO ")\r
307 _topLevel.SubTask("property", environment="env")\r
308 _topLevel.SubTask("property", name="WORKSPACE_DIR", value="${env.WORKSPACE}")\r
309\r
310 _topLevel.Blankline()\r
311 _topLevel.Comment("Common build attributes")\r
312 _topLevel.SubTask("property", name="SINGLE_MODULE_BUILD", value="yes")\r
313 _topLevel.SubTask("property", name="MODULE_BUILD_TARGET", value="single_module_build")\r
314 _topLevel.SubTask("property", name="PLATFORM_PREBUILD", value="yes")\r
315 _topLevel.SubTask("property", name="PLATFORM_POSTBUILD", value="no")\r
316 \r
317 _topLevel.Blankline()\r
318 _topLevel.Comment(" TODO ")\r
319 ifTask = _topLevel.SubTask("if")\r
320 ifTask.SubTask("istrue", value="${SINGLE_MODULE_BUILD}")\r
321 thenTask = ifTask.SubTask("then")\r
322 platformBuildFile = os.path.join("${WORKSPACE_DIR}", self.Platform.OutputPath,\r
323 self.Target + "_" + self.Toolchain, "build.xml")\r
324 thenTask.SubTask("import", file=platformBuildFile)\r
325 \r
326 _topLevel.Blankline()\r
327 _topLevel.SubTask("property", name="ARCH", value=self.Arch)\r
328 \r
329 module = self.Module.Module\r
330 package = module.Package\r
331 _topLevel.Blankline()\r
332 _topLevel.SubTask("property", name="PACKAGE", value=package.Name)\r
333 _topLevel.SubTask("property", name="PACKAGE_GUID", value=package.GuidValue)\r
334 _topLevel.SubTask("property", name="PACKAGE_VERSION", value=package.Version)\r
335 _topLevel.SubTask("property", name="PACKAGE_RELATIVE_DIR", value=package.Dir)\r
336 _topLevel.SubTask("property", name="PACKAGE_DIR", value=os.path.join("${WORKSPACE_DIR}","${PACKAGE_RELATIVE_DIR}"))\r
337 \r
338 _topLevel.Blankline()\r
339 _topLevel.SubTask("property", name="MODULE", value=module.Name)\r
340 _topLevel.SubTask("property", name="MODULE_GUID", value=module.GuidValue)\r
341 _topLevel.SubTask("property", name="MODULE_VERSION", value=module.Version)\r
342 _topLevel.SubTask("property", name="MODULE_TYPE", value=module.Type)\r
343 _topLevel.SubTask("property", name="MODULE_FILE_BASE_NAME", value=module.FileBaseName)\r
344 _topLevel.SubTask("property", name="MODULE_RELATIVE_DIR", value=module.Dir)\r
345 _topLevel.SubTask("property", name="MODULE_DIR", value=os.path.join("${PACKAGE_DIR}", "${MODULE_RELATIVE_DIR}"))\r
346 _topLevel.SubTask("property", name="BASE_NAME", value=module.BaseName)\r
347\r
348 _topLevel.Blankline()\r
349 _topLevel.SubTask("property", file="${WORKSPACE_DIR}/Tools/Python/buildgen/module_build_path.txt")\r
350 \r
351 self._BuildOption()\r
352 \r
353 _topLevel.Blankline()\r
354 _topLevel.SubTask("property", name="ENTRYPOINT", value="_ModuleEntryPoint")\r
355 \r
356 _topLevel.SubTask("property", name="SOURCE_FILES", value="\n ".join(self._GetSourceFileList()))\r
357 _topLevel.SubTask("property", name="LIBS", value="\n ".join(self._GetLibList()))\r
358 \r
359 _topLevel.Blankline()\r
360 _topLevel.SubTask("property", file="${PLATFORM_BUILD_DIR}/%s_build.opt" % self.Arch)\r
361 _topLevel.Blankline()\r
362 _topLevel.SubTask("echo", message="${MODULE}-${MODULE_VERSION} [${ARCH}] from package ${PACKAGE}-${PACKAGE_VERSION} (${MODULE_RELATIVE_DIR})", level="info")\r
363\r
364 _topLevel.Blankline()\r
365 _topLevel.Comment("Default target")\r
366 _topLevel.SubTask("target", name="all", depends="single_module_build")\r
367 _topLevel.SubTask("target", name="platform_module_build", depends="prebuild, sourcefiles, sections, output, postbuild")\r
368 _topLevel.SubTask("target", name="single_module_build", depends="prebuild, libraries, sourcefiles, sections, output, postbuild")\r
369\r
370 def _BuildOption(self):\r
371 _topLevel = self.BuildXml\r
372 _topLevel.Blankline()\r
373 baseModule = self.Module.Module\r
374 tools = self.Workspace.ToolConfig.ToolCodes\r
375\r
376 for tool in tools:\r
377 key = (self.Toolchain, self.Target, self.Arch, tool, "FLAGS")\r
378 flag = ""\r
379 if key in baseModule.BuildOptions:\r
380 flag = baseModule.BuildOptions[key]\r
381 _topLevel.SubTask("property", name="DEFAULT_MODULE_%s_FLAGS" % tool, value=flag)\r
382\r
383 _topLevel.Blankline()\r
384 for tool in tools:\r
385 key = (self.Toolchain, self.Target, self.Arch, tool, "FLAGS")\r
386 flag = ""\r
387 if key in self.Module.BuildOptions:\r
388 flag = self.Module.BuildOptions[key]\r
389 _topLevel.SubTask("property", name="MODULE_%s_FLAGS" % tool, value=flag)\r
390\r
391 def PreBuild(self):\r
392 _topLevel = self.BuildXml\r
393 _topLevel.Blankline()\r
394 _topLevel.Comment(" TARGET: prebuild ")\r
395\r
396 prebuildTasks = []\r
397 module = self.Module.Module\r
398 if module.UserExtensions.has_key("0"):\r
399 prebuildTasks = module.UserExtensions["0"]\r
400 elif module.UserExtensions.has_key("postbuild"):\r
401 prebuildTasks = module.UserExtensions["prebuild"]\r
402\r
403 _topLevel.SubTask("target", prebuildTasks, name="prebuild")\r
404\r
405\r
406 def Libraries(self):\r
407 _topLevel = self.BuildXml\r
408 _topLevel.Blankline()\r
409 _topLevel.Comment(" TARGET: libraries ")\r
410 \r
411 librariesTarget = _topLevel.SubTask("target", name="libraries")\r
412 parallelBuild = librariesTarget.SubTask("parallel", threadCount="${THREAD_COUNT}")\r
413 for lib in self.Module.Libraries:\r
414 module = lib.Module\r
415 buildDir = os.path.join("${BIN_DIR}", module.Package.SubPath(module.Dir), module.FileBaseName)\r
416 libTask = parallelBuild.SubTask("ant", dir=buildDir,\r
417 inheritAll="false",\r
418 target="${MODULE_BUILD_TARGET}")\r
419 libTask.SubTask("property", name="PLATFORM_PREBUILD", value="false")\r
420 libTask.SubTask("property", name="PLATFORM_POSTBUILD", value="false")\r
421\r
422 def Sourcefiles(self):\r
423 _topLevel = self.BuildXml\r
424 _topLevel.Blankline()\r
425 _topLevel.Comment(" TARGET: sourcefiles ")\r
426 _sourcefilesTarget = _topLevel.SubTask("target", name="sourcefiles")\r
427 \r
428 _incTask = AntTask(self.BuildXml.Document, "EXTRA.INC")\r
429 _incTask.SubTask("includepath", path="${WORKSPACE_DIR}")\r
430 _incTask.SubTask("includepath", path="${MODULE_DIR}")\r
431 _incTask.SubTask("includepath", path=os.path.join("${MODULE_DIR}", self.Arch.capitalize()))\r
432 _incTask.SubTask("includepath", path="${DEST_DIR_DEBUG}")\r
433 if self.Arch in self.Module.Module.IncludePaths:\r
434 for inc in self.Module.Module.IncludePaths[self.Arch]:\r
435 _incTask.SubTask("includepath", path=os.path.join("${WORKSPACE_DIR}", inc))\r
436 \r
437 # init\r
438 if not self.Module.Module.IsBinary:\r
439 _buildTask = _sourcefilesTarget.SubTask("Build_Init")\r
440 _buildTask.AddSubTask(_incTask)\r
441 \r
442 # AutoGen firt\r
443 _buildTask = _sourcefilesTarget.SubTask("Build_AUTOGEN", FILEEXT="c", FILENAME="AutoGen", FILEPATH=".")\r
444 _buildTask.AddSubTask(_incTask)\r
445\r
446 # uni file follows\r
447 type = "UNI"\r
448 if type in self.SourceFiles:\r
449 for srcpath in self.SourceFiles[type]:\r
450 taskName = "Build_" + type\r
451 fileDir = os.path.dirname(srcpath)\r
452 if fileDir == "": fileDir = "."\r
453 fileBaseName,fileExt = os.path.basename(srcpath).rsplit(".", 1)\r
454 _buildTask = _sourcefilesTarget.SubTask(taskName, FILENAME=fileBaseName, FILEEXT=fileExt, FILEPATH=fileDir)\r
455 _buildTask.AddSubTask(_incTask)\r
456\r
457 # others: c, vfr, ...\r
458 for type in self.SourceFiles:\r
459 if type == "Unicode": continue\r
460 for srcpath in self.SourceFiles[type]:\r
461 taskName = "Build_" + type\r
462 fileDir = os.path.dirname(srcpath)\r
463 if fileDir == "": fileDir = "."\r
464 fileBaseName,fileExt = os.path.basename(srcpath).rsplit(".", 1)\r
465 _buildTask = _sourcefilesTarget.SubTask(taskName, FILENAME=fileBaseName, FILEEXT=fileExt, FILEPATH=fileDir)\r
466 _buildTask.AddSubTask(_incTask)\r
467\r
468 def Sections(self):\r
469 _topLevel = self.BuildXml\r
470 _topLevel.Blankline()\r
471 _topLevel.Comment(" TARGET: sections ")\r
472 _sectionsTarget = _topLevel.SubTask("target", name="sections")\r
473\r
474 def Ffs(self):\r
475 _topLevel = self.BuildXml\r
476 _topLevel.Blankline()\r
477 _topLevel.Comment(" TARGET: output ")\r
478 _sectionsTarget = _topLevel.SubTask("target", name="output")\r
479\r
480 def PostBuild(self):\r
481 _topLevel = self.BuildXml\r
482 _topLevel.Blankline()\r
483 _topLevel.Comment(" TARGET: postbuild ")\r
484\r
485 postbuildTasks = []\r
486 module = self.Module.Module\r
487 if module.UserExtensions.has_key("1"):\r
488 postbuildTasks = module.UserExtensions["1"]\r
489 elif module.UserExtensions.has_key("postbuild"):\r
490 postbuildTasks = module.UserExtensions["postbuild"]\r
491\r
492 _topLevel.SubTask("target", postbuildTasks, name="postbuild")\r
493\r
494 def Clean(self):\r
495 pass\r
496\r
497 def CleanAll(self):\r
498 pass\r
499\r
500 def UserExtensions(self):\r
501 pass\r
502 \r
503 def GetSourceFiles(self):\r
504 ## check arch, toolchain, family, toolcode, ext\r
505 ## if the arch of source file supports active arch\r
506 ## if the toolchain of source file supports active toolchain\r
507 ## if the toolchain family of source file supports active toolchain family\r
508 ## if the ext of the source file is supported by the toolcode\r
509 module = self.Module.Module\r
510 files = {} # file type -> src\r
511 for type in module.SourceFiles[self.Arch]:\r
512 if not module.IsBuildable(type):\r
513 # print type,"is not buildable"\r
514 continue\r
515 \r
516 if type not in files:\r
517 files[type] = []\r
518 for src in module.SourceFiles[self.Arch][type]:\r
519 if self.Toolchain not in src.Toolchains:\r
520 # print self.Toolchain,"not in ",src.Toolchains\r
521 continue\r
522 if not self.IsCompatible(src.Families, self.Workspace.ActiveFamilies):\r
523 # print src.Families,"not compatible with",self.Workspace.ActiveFamilies\r
524 continue\r
525 toolcode = src.GetToolCode(src.Type)\r
526 if toolcode != "":\r
527 ext = self.Workspace.GetToolDef(self.Toolchain, self.Target, self.Arch, toolcode, "EXT")\r
528 if ext != "" and ext != src.Ext:\r
529 # print ext,"in tools_def.txt is not the same as",src.Ext\r
530 continue\r
531 ## fileFullPath = os.path.join("${MODULE_DIR}", )\r
532 ## print fileFullPath\r
533 files[type].append(src.Path)\r
534\r
535 return files\r
536\r
537 def Intersection(self, list1, list2):\r
538 return list(Set(list1) & Set(list2))\r
539\r
540 def IsCompatible(self, list1, list2):\r
541 return len(self.Intersection(list1, list2)) > 0\r
542\r
543 def _GetLibList(self):\r
544 libList = []\r
545 for lib in self.Module.Libraries:\r
546 module = lib.Module\r
547 libList.append(os.path.join("${BIN_DIR}", module.Name + ".lib"))\r
548 return libList\r
549 \r
550 def _GetSourceFileList(self):\r
551 srcList = []\r
552 for type in self.SourceFiles:\r
553 srcList.extend(self.SourceFiles[type])\r
554 return srcList\r
555\r
556class NmakeFile(BuildFile):\r
557 pass\r
558\r
559class GmakeFile(BuildFile):\r
560 pass\r
561\r
562# for test\r
563if __name__ == "__main__":\r
564 workspacePath = os.getenv("WORKSPACE", os.getcwd())\r
565 startTime = time.clock()\r
566 ws = Workspace(workspacePath, [], [])\r
567 \r
568 # generate build.xml\r
569 ap = ws.ActivePlatform\r
570 for target in ws.ActiveTargets:\r
571 ant = AntPlatformBuildFile(ws, ap, ws.ActiveToolchain, target)\r
572 ant.Generate()\r
573 \r
574 print "\n[Finished in %fs]" % (time.clock() - startTime)\r