--- /dev/null
+#!/usr/bin/env python\r
+\r
+# Copyright (c) 2007, Intel Corporation\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+"""Generate build file for given platform"""\r
+\r
+import os, sys, copy\r
+import xml.dom.minidom, pprint\r
+import FrameworkElement\r
+\r
+from SurfaceAreaElement import *\r
+from XmlRoutines import *\r
+from AntTasks import *\r
+from sets import Set\r
+\r
+class BuildFile:\r
+ def __init__(self, workspace, platform, toolchain, target):\r
+ if workspace == None or workspace == "":\r
+ raise Exception("No workspace, no build")\r
+ if platform == None or platform == "":\r
+ raise Exception("No platform, no build")\r
+ if toolchain == None or toolchain == "":\r
+ raise Exception("No toolchain, no build")\r
+ if target == None or target == "":\r
+ raise Exception("No target, no build")\r
+ \r
+ self.Workspace = workspace\r
+ self.Platform = platform\r
+ self.Toolchain = toolchain\r
+ self.Target = target\r
+ self.Path = ""\r
+\r
+ def Generate(self):\r
+ """Generate the build file"""\r
+ pass\r
+\r
+# generating build.xml for platform\r
+class AntPlatformBuildFile(BuildFile):\r
+ def __init__(self, workspace, platform, toolchain, target):\r
+ BuildFile.__init__(self, workspace, platform, toolchain, target)\r
+ # Form the build file path, hard-coded at present. It should be specified by a configuration file\r
+ self.Path = os.path.join(self.Workspace.Path, self.Platform.OutputPath, target + "_" + toolchain, "build.xml")\r
+ print ""\r
+ # Generate a common build option property file in the format of Java's property file\r
+ self.DefaultBuildOptions()\r
+ \r
+ # new a build file object\r
+ self.BuildXml = AntBuildFile(name="platform", basedir=".", default="all")\r
+ \r
+ # generate the top level properties, tasks, etc.\r
+ self.Header()\r
+ \r
+ # generate "prebuild" target\r
+ self.PreBuild()\r
+ \r
+ # generate "libraries" target for building library modules\r
+ self.Libraries()\r
+ \r
+ # generate "modules" target for building non-library modules\r
+ self.Modules()\r
+ \r
+ # generate "fvs" target for building firmware volume. (not supported yet)\r
+ \r
+ # generate "fds" target for building FlashDevice. (not supported yet)\r
+ \r
+ # generate "postbuild" target\r
+ self.PostBuild()\r
+\r
+ def Generate(self):\r
+ print "Generating platform build file ...", self.Path\r
+ self.BuildXml.Create(self.Path)\r
+\r
+ def Header(self):\r
+ _topLevel = self.BuildXml\r
+ # import external tasks\r
+ _topLevel.SubTask("taskdef", resource="GenBuild.tasks")\r
+ _topLevel.SubTask("taskdef", resource="frameworktasks.tasks")\r
+ _topLevel.SubTask("taskdef", resource="net/sf/antcontrib/antlib.xml")\r
+\r
+ # platform wide properties\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment("WORKSPACE wide attributes")\r
+ _topLevel.SubTask("property", environment="env")\r
+ _topLevel.SubTask("property", name="WORKSPACE_DIR", value="${env.WORKSPACE}")\r
+ _topLevel.SubTask("property", name="CONFIG_DIR", value="${WORKSPACE_DIR}/Tools/Conf")\r
+\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment("Common build attributes")\r
+ _topLevel.SubTask("property", name="THREAD_COUNT", value=self.Workspace.ThreadCount)\r
+ _topLevel.SubTask("property", name="SINGLE_MODULE_BUILD", value="no")\r
+ _topLevel.SubTask("property", name="MODULE_BUILD_TARGET", value="platform_module_build")\r
+\r
+ _topLevel.Blankline()\r
+ _topLevel.SubTask("property", name="TOOLCHAIN", value=self.Toolchain)\r
+ _topLevel.SubTask("property", name="TARGET", value=self.Target)\r
+ \r
+ _topLevel.Blankline()\r
+ _topLevel.Comment("Platform attributes")\r
+ _topLevel.SubTask("property", name="PLATFORM", value=self.Platform.Name)\r
+ _topLevel.SubTask("property", name="PLATFORM_GUID", value=self.Platform.GuidValue)\r
+ _topLevel.SubTask("property", name="PLATFORM_VERSION", value=self.Platform.Version)\r
+ _topLevel.SubTask("property", name="PLATFORM_RELATIVE_DIR", value=self.Platform.Dir)\r
+ _topLevel.SubTask("property", name="PLATFORM_DIR", value="${WORKSPACE_DIR}/${PLATFORM_RELATIVE_DIR}")\r
+ _topLevel.SubTask("property", name="PLATFORM_OUTPUT_DIR", value=self.Platform.OutputPath)\r
+\r
+ # user configurable build path for platform\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment("Common path definition for platform build")\r
+ _topLevel.SubTask("property", file="${WORKSPACE_DIR}/Tools/Python/buildgen/platform_build_path.txt")\r
+ \r
+ # common build tasks in the form of Ant macro\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment("Task Macros for Compiling, Assembling, Linking, etc.")\r
+ _topLevel.SubTask("import", file="${CONFIG_DIR}/BuildMacro.xml")\r
+ _topLevel.Blankline()\r
+ _topLevel.SubTask("echo", message="${PLATFORM}-${PLATFORM_VERSION} (${PLATFORM_RELATIVE_DIR})", level="info")\r
+ \r
+ # define the targets execution sequence\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment("Default target")\r
+ _topLevel.SubTask("target", name="all", depends="prebuild, libraries, modules, postbuild")\r
+\r
+ def PreBuild(self):\r
+ _topLevel = self.BuildXml\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment(" TARGET: prebuild ")\r
+ \r
+ # prebuild is defined by user in the fpd file through <UserExtionsion> element,\r
+ # which has attribute "identifier=0" or "identifier=prebuild"\r
+ prebuildTasks = []\r
+ if self.Platform.UserExtensions.has_key("0"):\r
+ prebuildTasks = self.Platform.UserExtensions["0"]\r
+ elif self.Platform.UserExtensions.has_key("postbuild"):\r
+ prebuildTasks = self.Platform.UserExtensions["prebuild"]\r
+\r
+ _topLevel.SubTask("target", prebuildTasks, name="prebuild")\r
+\r
+ def Libraries(self):\r
+ _topLevel = self.BuildXml\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment(" TARGET: libraries ")\r
+ \r
+ librariesTarget = _topLevel.SubTask("target", name="libraries")\r
+ parallelBuild = librariesTarget.SubTask("parallel", threadCount="${THREAD_COUNT}")\r
+ \r
+ libraryNumber = 0\r
+ for arch in self.Platform.Libraries:\r
+ libraryNumber += len(self.Platform.Libraries[arch])\r
+ libraryIndex = 0\r
+ for arch in self.Platform.Libraries:\r
+ for lib in self.Platform.Libraries[arch]:\r
+ libraryIndex += 1\r
+ print "Generating library build files ... %d%%\r" % int((float(libraryIndex) / float(libraryNumber)) * 100),\r
+ buildFile = AntModuleBuildFile(self.Workspace, self.Platform, lib, self.Toolchain, self.Target, arch)\r
+ buildFile.Generate()\r
+ buildDir = os.path.join("${TARGET_DIR}", arch, lib.Module.Package.SubPath(lib.Module.Dir),\r
+ lib.Module.FileBaseName)\r
+ parallelBuild.SubTask("ant", dir=buildDir,\r
+ #antfile="build.xml",\r
+ inheritAll="true",\r
+ target="${MODULE_BUILD_TARGET}")\r
+ print ""\r
+\r
+ def Modules(self):\r
+ _topLevel = self.BuildXml\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment(" TARGET: modules ")\r
+\r
+ modulesTarget = _topLevel.SubTask("target", name="modules")\r
+ parallelBuild = modulesTarget.SubTask("parallel", threadCount="${THREAD_COUNT}")\r
+\r
+ moduleNumber = 0\r
+ for arch in self.Platform.Modules:\r
+ moduleNumber += len(self.Platform.Modules[arch])\r
+ \r
+ moduleIndex = 0\r
+ for arch in self.Platform.Modules:\r
+ for module in self.Platform.Modules[arch]:\r
+ moduleIndex += 1\r
+ print "Generating module build files ... %d%%\r" % int((float(moduleIndex) / float(moduleNumber)) * 100),\r
+ \r
+ buildDir = os.path.join("${TARGET_DIR}", arch, module.Module.Package.SubPath(module.Module.Dir),\r
+ module.Module.FileBaseName)\r
+ parallelBuild.SubTask("ant", dir=buildDir,\r
+ #antfile="build.xml",\r
+ inheritAll="true",\r
+ target="${MODULE_BUILD_TARGET}")\r
+ buildFile = AntModuleBuildFile(self.Workspace, self.Platform, module, self.Toolchain, self.Target, arch)\r
+ buildFile.Generate()\r
+ print ""\r
+\r
+ def Fvs(self):\r
+ pass\r
+\r
+ def Fds(self):\r
+ pass\r
+\r
+ def PostBuild(self):\r
+ _topLevel = self.BuildXml\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment(" TARGET: postbuild ")\r
+ \r
+ # postbuild is defined by user in the fpd file through <UserExtionsion> element,\r
+ # which has attribute "identifier=1" or "identifier=postbuild"\r
+ postbuildTasks = []\r
+ if self.Platform.UserExtensions.has_key("1"):\r
+ postbuildTasks = self.Platform.UserExtensions["1"]\r
+ elif self.Platform.UserExtensions.has_key("postbuild"):\r
+ postbuildTasks = self.Platform.UserExtensions["postbuild"]\r
+ \r
+ _topLevel.SubTask("target", postbuildTasks, name="postbuild")\r
+\r
+ def Clean(self):\r
+ pass\r
+\r
+ def CleanAll(self):\r
+ pass\r
+\r
+ def UserExtensions(self):\r
+ pass\r
+\r
+ def DefaultBuildOptions(self):\r
+ """Generate ${ARCH}_build.opt which contains the default build&tool definitions"""\r
+ tools = self.Workspace.ToolConfig.ToolCodes\r
+ for arch in self.Workspace.ActiveArchs:\r
+ optFileDir = os.path.join(self.Workspace.Path, self.Platform.OutputPath,\r
+ self.Target + "_" + self.Toolchain)\r
+ optFileName = arch + "_build.opt"\r
+ if not os.path.exists(optFileDir): os.makedirs(optFileDir)\r
+ f = open(os.path.join(optFileDir, optFileName), "w")\r
+ for tool in tools:\r
+ key = (self.Toolchain, self.Target, arch, tool, "FLAGS")\r
+ flag = self.Workspace.ToolConfig[key]\r
+ f.write("DEFAULT_%s_FLAGS=%s\n" % (tool, flag))\r
+\r
+ f.write("\n")\r
+ for tool in tools:\r
+ key = (self.Toolchain, self.Target, arch, tool, "FLAGS")\r
+ if key in self.Platform.BuildOptions:\r
+ flag = self.Platform.BuildOptions[key]\r
+ else:\r
+ key = (self.Toolchain, self.Target, arch, tool, "FAMILY")\r
+ family = self.Workspace.ToolConfig[key]\r
+ key = (family, self.Target, arch, tool, "FLAGS")\r
+ if key in self.Platform.BuildOptions:\r
+ flag = self.Platform.BuildOptions[key]\r
+ else:\r
+ flag = ""\r
+ f.write("PLATFORM_%s_FLAGS=%s\n" % (tool, flag))\r
+\r
+ f.write("\n")\r
+ for tool in tools:\r
+ for attr in self.Workspace.ToolConfig.Attributes:\r
+ if attr == "FLAGS": continue\r
+ key = (self.Toolchain, self.Target, arch, tool, attr)\r
+ value = self.Workspace.ToolConfig[key]\r
+ if attr == "NAME":\r
+ f.write("%s=%s\n" % (tool, value))\r
+ else:\r
+ f.write("%s_%s=%s\n" % (tool, attr, value))\r
+ f.write("%s_FLAGS=${DEFAULT_%s_FLAGS} ${DEFAULT_MODULE_%s_FLAGS} ${PLATFORM_%s_FLAGS} ${MODULE_%s_FLAGS}\n" %\r
+ (tool, tool, tool, tool, tool))\r
+ f.write("\n")\r
+\r
+ f.close()\r
+\r
+class AntModuleBuildFile(BuildFile):\r
+ def __init__(self, workspace, platform, module, toolchain, target, arch):\r
+ BuildFile.__init__(self, workspace, platform, toolchain, target)\r
+ self.Module = module\r
+ self.Arch = arch\r
+ self.Path = os.path.join(self.Workspace.Path, self.Platform.OutputPath,\r
+ target + "_" + toolchain, arch, self.Module.Module.Package.Dir,\r
+ self.Module.Module.Dir, self.Module.Module.FileBaseName, "build.xml")\r
+ self.BuildXml = AntBuildFile(self.Module.Module.Name)\r
+\r
+ self.SourceFiles = self.GetSourceFiles()\r
+ \r
+ self.Header()\r
+ self.PreBuild()\r
+ self.Libraries()\r
+ self.Sourcefiles()\r
+ self.Sections()\r
+ self.Ffs()\r
+ self.PostBuild()\r
+\r
+ def Generate(self):\r
+ # print self.Path,"\r",\r
+ self.BuildXml.Create(self.Path)\r
+\r
+ def Header(self):\r
+ _topLevel = self.BuildXml\r
+ _topLevel.SubTask("taskdef", resource="frameworktasks.tasks")\r
+ _topLevel.SubTask("taskdef", resource="cpptasks.tasks")\r
+ _topLevel.SubTask("taskdef", resource="cpptasks.types")\r
+ _topLevel.SubTask("taskdef", resource="net/sf/antcontrib/antlib.xml")\r
+\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment(" TODO ")\r
+ _topLevel.SubTask("property", environment="env")\r
+ _topLevel.SubTask("property", name="WORKSPACE_DIR", value="${env.WORKSPACE}")\r
+\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment("Common build attributes")\r
+ _topLevel.SubTask("property", name="SINGLE_MODULE_BUILD", value="yes")\r
+ _topLevel.SubTask("property", name="MODULE_BUILD_TARGET", value="single_module_build")\r
+ _topLevel.SubTask("property", name="PLATFORM_PREBUILD", value="yes")\r
+ _topLevel.SubTask("property", name="PLATFORM_POSTBUILD", value="no")\r
+ \r
+ _topLevel.Blankline()\r
+ _topLevel.Comment(" TODO ")\r
+ ifTask = _topLevel.SubTask("if")\r
+ ifTask.SubTask("istrue", value="${SINGLE_MODULE_BUILD}")\r
+ thenTask = ifTask.SubTask("then")\r
+ platformBuildFile = os.path.join("${WORKSPACE_DIR}", self.Platform.OutputPath,\r
+ self.Target + "_" + self.Toolchain, "build.xml")\r
+ thenTask.SubTask("import", file=platformBuildFile)\r
+ \r
+ _topLevel.Blankline()\r
+ _topLevel.SubTask("property", name="ARCH", value=self.Arch)\r
+ \r
+ module = self.Module.Module\r
+ package = module.Package\r
+ _topLevel.Blankline()\r
+ _topLevel.SubTask("property", name="PACKAGE", value=package.Name)\r
+ _topLevel.SubTask("property", name="PACKAGE_GUID", value=package.GuidValue)\r
+ _topLevel.SubTask("property", name="PACKAGE_VERSION", value=package.Version)\r
+ _topLevel.SubTask("property", name="PACKAGE_RELATIVE_DIR", value=package.Dir)\r
+ _topLevel.SubTask("property", name="PACKAGE_DIR", value=os.path.join("${WORKSPACE_DIR}","${PACKAGE_RELATIVE_DIR}"))\r
+ \r
+ _topLevel.Blankline()\r
+ _topLevel.SubTask("property", name="MODULE", value=module.Name)\r
+ _topLevel.SubTask("property", name="MODULE_GUID", value=module.GuidValue)\r
+ _topLevel.SubTask("property", name="MODULE_VERSION", value=module.Version)\r
+ _topLevel.SubTask("property", name="MODULE_TYPE", value=module.Type)\r
+ _topLevel.SubTask("property", name="MODULE_FILE_BASE_NAME", value=module.FileBaseName)\r
+ _topLevel.SubTask("property", name="MODULE_RELATIVE_DIR", value=module.Dir)\r
+ _topLevel.SubTask("property", name="MODULE_DIR", value=os.path.join("${PACKAGE_DIR}", "${MODULE_RELATIVE_DIR}"))\r
+ _topLevel.SubTask("property", name="BASE_NAME", value=module.BaseName)\r
+\r
+ _topLevel.Blankline()\r
+ _topLevel.SubTask("property", file="${WORKSPACE_DIR}/Tools/Python/buildgen/module_build_path.txt")\r
+ \r
+ self._BuildOption()\r
+ \r
+ _topLevel.Blankline()\r
+ _topLevel.SubTask("property", name="ENTRYPOINT", value="_ModuleEntryPoint")\r
+ \r
+ _topLevel.SubTask("property", name="SOURCE_FILES", value="\n ".join(self._GetSourceFileList()))\r
+ _topLevel.SubTask("property", name="LIBS", value="\n ".join(self._GetLibList()))\r
+ \r
+ _topLevel.Blankline()\r
+ _topLevel.SubTask("property", file="${PLATFORM_BUILD_DIR}/%s_build.opt" % self.Arch)\r
+ _topLevel.Blankline()\r
+ _topLevel.SubTask("echo", message="${MODULE}-${MODULE_VERSION} [${ARCH}] from package ${PACKAGE}-${PACKAGE_VERSION} (${MODULE_RELATIVE_DIR})", level="info")\r
+\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment("Default target")\r
+ _topLevel.SubTask("target", name="all", depends="single_module_build")\r
+ _topLevel.SubTask("target", name="platform_module_build", depends="prebuild, sourcefiles, sections, output, postbuild")\r
+ _topLevel.SubTask("target", name="single_module_build", depends="prebuild, libraries, sourcefiles, sections, output, postbuild")\r
+\r
+ def _BuildOption(self):\r
+ _topLevel = self.BuildXml\r
+ _topLevel.Blankline()\r
+ baseModule = self.Module.Module\r
+ tools = self.Workspace.ToolConfig.ToolCodes\r
+\r
+ for tool in tools:\r
+ key = (self.Toolchain, self.Target, self.Arch, tool, "FLAGS")\r
+ flag = ""\r
+ if key in baseModule.BuildOptions:\r
+ flag = baseModule.BuildOptions[key]\r
+ _topLevel.SubTask("property", name="DEFAULT_MODULE_%s_FLAGS" % tool, value=flag)\r
+\r
+ _topLevel.Blankline()\r
+ for tool in tools:\r
+ key = (self.Toolchain, self.Target, self.Arch, tool, "FLAGS")\r
+ flag = ""\r
+ if key in self.Module.BuildOptions:\r
+ flag = self.Module.BuildOptions[key]\r
+ _topLevel.SubTask("property", name="MODULE_%s_FLAGS" % tool, value=flag)\r
+\r
+ def PreBuild(self):\r
+ _topLevel = self.BuildXml\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment(" TARGET: prebuild ")\r
+\r
+ prebuildTasks = []\r
+ module = self.Module.Module\r
+ if module.UserExtensions.has_key("0"):\r
+ prebuildTasks = module.UserExtensions["0"]\r
+ elif module.UserExtensions.has_key("postbuild"):\r
+ prebuildTasks = module.UserExtensions["prebuild"]\r
+\r
+ _topLevel.SubTask("target", prebuildTasks, name="prebuild")\r
+\r
+\r
+ def Libraries(self):\r
+ _topLevel = self.BuildXml\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment(" TARGET: libraries ")\r
+ \r
+ librariesTarget = _topLevel.SubTask("target", name="libraries")\r
+ parallelBuild = librariesTarget.SubTask("parallel", threadCount="${THREAD_COUNT}")\r
+ for lib in self.Module.Libraries:\r
+ module = lib.Module\r
+ buildDir = os.path.join("${BIN_DIR}", module.Package.SubPath(module.Dir), module.FileBaseName)\r
+ libTask = parallelBuild.SubTask("ant", dir=buildDir,\r
+ inheritAll="false",\r
+ target="${MODULE_BUILD_TARGET}")\r
+ libTask.SubTask("property", name="PLATFORM_PREBUILD", value="false")\r
+ libTask.SubTask("property", name="PLATFORM_POSTBUILD", value="false")\r
+\r
+ def Sourcefiles(self):\r
+ _topLevel = self.BuildXml\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment(" TARGET: sourcefiles ")\r
+ _sourcefilesTarget = _topLevel.SubTask("target", name="sourcefiles")\r
+ \r
+ _incTask = AntTask(self.BuildXml.Document, "EXTRA.INC")\r
+ _incTask.SubTask("includepath", path="${WORKSPACE_DIR}")\r
+ _incTask.SubTask("includepath", path="${MODULE_DIR}")\r
+ _incTask.SubTask("includepath", path=os.path.join("${MODULE_DIR}", self.Arch.capitalize()))\r
+ _incTask.SubTask("includepath", path="${DEST_DIR_DEBUG}")\r
+ if self.Arch in self.Module.Module.IncludePaths:\r
+ for inc in self.Module.Module.IncludePaths[self.Arch]:\r
+ _incTask.SubTask("includepath", path=os.path.join("${WORKSPACE_DIR}", inc))\r
+ \r
+ # init\r
+ if not self.Module.Module.IsBinary:\r
+ _buildTask = _sourcefilesTarget.SubTask("Build_Init")\r
+ _buildTask.AddSubTask(_incTask)\r
+ \r
+ # AutoGen firt\r
+ _buildTask = _sourcefilesTarget.SubTask("Build_AUTOGEN", FILEEXT="c", FILENAME="AutoGen", FILEPATH=".")\r
+ _buildTask.AddSubTask(_incTask)\r
+\r
+ # uni file follows\r
+ type = "UNI"\r
+ if type in self.SourceFiles:\r
+ for srcpath in self.SourceFiles[type]:\r
+ taskName = "Build_" + type\r
+ fileDir = os.path.dirname(srcpath)\r
+ if fileDir == "": fileDir = "."\r
+ fileBaseName,fileExt = os.path.basename(srcpath).rsplit(".", 1)\r
+ _buildTask = _sourcefilesTarget.SubTask(taskName, FILENAME=fileBaseName, FILEEXT=fileExt, FILEPATH=fileDir)\r
+ _buildTask.AddSubTask(_incTask)\r
+\r
+ # others: c, vfr, ...\r
+ for type in self.SourceFiles:\r
+ if type == "Unicode": continue\r
+ for srcpath in self.SourceFiles[type]:\r
+ taskName = "Build_" + type\r
+ fileDir = os.path.dirname(srcpath)\r
+ if fileDir == "": fileDir = "."\r
+ fileBaseName,fileExt = os.path.basename(srcpath).rsplit(".", 1)\r
+ _buildTask = _sourcefilesTarget.SubTask(taskName, FILENAME=fileBaseName, FILEEXT=fileExt, FILEPATH=fileDir)\r
+ _buildTask.AddSubTask(_incTask)\r
+\r
+ def Sections(self):\r
+ _topLevel = self.BuildXml\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment(" TARGET: sections ")\r
+ _sectionsTarget = _topLevel.SubTask("target", name="sections")\r
+\r
+ def Ffs(self):\r
+ _topLevel = self.BuildXml\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment(" TARGET: output ")\r
+ _sectionsTarget = _topLevel.SubTask("target", name="output")\r
+\r
+ def PostBuild(self):\r
+ _topLevel = self.BuildXml\r
+ _topLevel.Blankline()\r
+ _topLevel.Comment(" TARGET: postbuild ")\r
+\r
+ postbuildTasks = []\r
+ module = self.Module.Module\r
+ if module.UserExtensions.has_key("1"):\r
+ postbuildTasks = module.UserExtensions["1"]\r
+ elif module.UserExtensions.has_key("postbuild"):\r
+ postbuildTasks = module.UserExtensions["postbuild"]\r
+\r
+ _topLevel.SubTask("target", postbuildTasks, name="postbuild")\r
+\r
+ def Clean(self):\r
+ pass\r
+\r
+ def CleanAll(self):\r
+ pass\r
+\r
+ def UserExtensions(self):\r
+ pass\r
+ \r
+ def GetSourceFiles(self):\r
+ ## check arch, toolchain, family, toolcode, ext\r
+ ## if the arch of source file supports active arch\r
+ ## if the toolchain of source file supports active toolchain\r
+ ## if the toolchain family of source file supports active toolchain family\r
+ ## if the ext of the source file is supported by the toolcode\r
+ module = self.Module.Module\r
+ files = {} # file type -> src\r
+ for type in module.SourceFiles[self.Arch]:\r
+ if not module.IsBuildable(type):\r
+ # print type,"is not buildable"\r
+ continue\r
+ \r
+ if type not in files:\r
+ files[type] = []\r
+ for src in module.SourceFiles[self.Arch][type]:\r
+ if self.Toolchain not in src.Toolchains:\r
+ # print self.Toolchain,"not in ",src.Toolchains\r
+ continue\r
+ if not self.IsCompatible(src.Families, self.Workspace.ActiveFamilies):\r
+ # print src.Families,"not compatible with",self.Workspace.ActiveFamilies\r
+ continue\r
+ toolcode = src.GetToolCode(src.Type)\r
+ if toolcode != "":\r
+ ext = self.Workspace.GetToolDef(self.Toolchain, self.Target, self.Arch, toolcode, "EXT")\r
+ if ext != "" and ext != src.Ext:\r
+ # print ext,"in tools_def.txt is not the same as",src.Ext\r
+ continue\r
+ ## fileFullPath = os.path.join("${MODULE_DIR}", )\r
+ ## print fileFullPath\r
+ files[type].append(src.Path)\r
+\r
+ return files\r
+\r
+ def Intersection(self, list1, list2):\r
+ return list(Set(list1) & Set(list2))\r
+\r
+ def IsCompatible(self, list1, list2):\r
+ return len(self.Intersection(list1, list2)) > 0\r
+\r
+ def _GetLibList(self):\r
+ libList = []\r
+ for lib in self.Module.Libraries:\r
+ module = lib.Module\r
+ libList.append(os.path.join("${BIN_DIR}", module.Name + ".lib"))\r
+ return libList\r
+ \r
+ def _GetSourceFileList(self):\r
+ srcList = []\r
+ for type in self.SourceFiles:\r
+ srcList.extend(self.SourceFiles[type])\r
+ return srcList\r
+\r
+class NmakeFile(BuildFile):\r
+ pass\r
+\r
+class GmakeFile(BuildFile):\r
+ pass\r
+\r
+# for test\r
+if __name__ == "__main__":\r
+ workspacePath = os.getenv("WORKSPACE", os.getcwd())\r
+ startTime = time.clock()\r
+ ws = Workspace(workspacePath, [], [])\r
+ \r
+ # generate build.xml\r
+ ap = ws.ActivePlatform\r
+ for target in ws.ActiveTargets:\r
+ ant = AntPlatformBuildFile(ws, ap, ws.ActiveToolchain, target)\r
+ ant.Generate()\r
+ \r
+ print "\n[Finished in %fs]" % (time.clock() - startTime)\r