📄 umake.py
字号:
cvsdir=os.path.join(os.path.dirname(path), "CVS") root = open(os.path.join(cvsdir,"Root"),"r").read() repository = open(os.path.join(cvsdir,"Repository"),"r").read() tag = '' try: tag = open(os.path.join(cvsdir,"Tag"),"r").read() if len(tag) and tag[0] == 'T': tag=tag[1:] else: tag='' except IOError: pass bldreg.set_value("distribute", self.output_path()[1], ( os.path.basename(path), string.strip(root), string.strip(repository), string.strip(tag) )) def mangle(self, filename): filename = string.lower(filename) if sysinfo.host_type == "mac" and filename[0]!=':' and filename[:2]!="./": filaneme = ':' + filename filename = os.path.normpath(filename) return filename ### ### Module dependency handling ### def get_uber_makes(self): class UberMaker: def __init__(self, parent): self.src_root_path = parent.src_root_path self.SubModule = parent.SubModule self.uber_submakes = [] self.done={} self.mangle = parent.mangle self.stats={} self.expcache={} self.addbifdepcache={} def inc(self, stat): self.stats[stat]=self.stats.get(stat,0)+1 def show_stats(self): tmp=self.stats.items() tmp.sort(lambda x, y: x[1] - y[1]) for (stat, num) in tmp: print "%10d %s" % (num, stat) def expand_aliases(self, mf): ## Search for makefile aliases ## Multi-target umakefiles of various ## kinds typically generate aliases if self.expcache.has_key(mf): return self.expcache[mf] tmp = [] done = {} maks = [ mf ] for m in maks: if done.has_key(m): continue done[m]=1 a = bldreg.get("alias", self.mangle(m), None) if a: maks.extend(a) else: tmp.append(m) #print "expand_aliases(%s) => %s" % (repr(mf), repr(tmp)) self.expcache[mf]=tmp return tmp def addbifdep(self, depid): #print "ADDBIFDEP(%s)" % depid if self.addbifdepcache.has_key(depid): return self.addbifdepcache[depid] ret={} type = bldreg.get("bifmodule_type", string.lower(depid), "") if type == "cvs": path=bldreg.get("bifmodule_id_to_path",string.lower(depid),None) if path: path = string.replace(path,"/",os.sep) if sysinfo.host_type == "mac": path = ":" + path abs_mf=os.path.join(path,"Makefile") for x in self.expand_aliases(abs_mf): ret[x]=1 elif type == "name_only": for x in bldreg.get("bifmodule_deplist",string.lower(depid),[]): ret.update(self.addbifdep(x)) self.addbifdepcache[depid]=ret return ret def low_add(self, umf, abs_umf, mf, abs_mf, ignore_errors = 0): lmf=self.mangle(abs_mf) if(self.done.has_key(lmf)): return self.done[lmf] self.done[lmf]=1 if not mf: mf = os.path.join(self.src_root_path, abs_mf) if not abs_umf: abs_umf = bldreg.get("umakefile",lmf,None) if not abs_umf: self.done[lmf]=0 return 0 if not umf: umf = os.path.join(self.src_root_path, abs_umf) #print "low_add(umf=%s,abs_umf=%s,mf=%s,abs_mf=%s,err=%d,lmf=%s)" % (umf, abs_umf, mf, abs_mf, ignore_errors,lmf) deps=bldreg.get("dependencies",lmf,[]) #print "low_add deps = %s" % repr(deps) tmp={} for d in deps: if d == "FROMBIF": modid = umake_lib.module_from_file(abs_umf) if modid: for depid in bldreg.get("bifmodule_deplist",string.lower(modid),[]): tmp.update(self.addbifdep(depid)) else: print "Umake warning: Module does not exist in BIF file." continue dum = bldreg.get("created_by",self.mangle(d), None) #print " DEP %s (%s) => %s" % (d, self.mangle(d), repr(dum)) if dum: tmp[dum]=1 tmp=tmp.keys() tmp2=[] for d in tmp: if self.low_add_mf(d): tmp2.append(d) ## Create the module object mod = self.SubModule() mod.umf = umf mod.mf = mf mod.abs_umf = abs_umf mod.abs_mf = abs_mf mod.deps = tmp2 mod.ignore_errors = ignore_errors self.uber_submakes.append(mod) self.done[lmf]=mod return mod def low_add_mf(self, abs_mf, ignore_errors = 0): return self.low_add(None, None, None, abs_mf, ignore_errors) def add_um(self, um, ignore_errors = 0): lum=self.mangle(abs_um) ## No makefile, no module abs_mf = bldreg.get("makefile",lum,None) if not abs_mf: return mf = os.path.join(self.src_root_path, abs_mf) umf = os.path.join(self.src_root_path, abs_umf) return self.low_add(umf, abs_umf, mf, abs_mf, ignore_errors) def add_mf(self, abs_mf, ignore_errors = 0): for mf in self.expand_aliases(abs_mf): self.low_add_mf(mf, ignore_errors) u = UberMaker(self) u.add_mf(os.path.join(self.module_directory(), self.makefile_name)) u.show_stats() return u.uber_submakes def SetDistLocation(self, release=None, debug=None, any=None): location=None if "release" in self.build_choices: location=release or any else: location=debug or any self.distribute_location=location ## FIXME: Is posix path right here, or do we need to naturalize it? def SetVersionFile(self, file): self.version_file = file#################################################################################def UmakefileVersion(major, minor, micro = 0): if major < 2000: num = major * 10000 + minor * 100 + micro if num < 20000: return project.EnableFeature("submodules") if num < 20100: return project.EnableFeature("versioning_off") if num < 20200: return project.EnableFeature("static_implies_nodll") if num < 20400: return project.EnableFeature("makefile_quotes") else: major = major - 2000 num = major * 10000 + minor * 100 + micro if num < 20000: return project.EnableFeature("submodules")def GetSDKPath(sdk_name, defval=None): """This returns the path to a named SDK""" import sdk path = sdk.GetPath(sdk_name) if not path: path=defval if not path: umake_lib.fatal(" Failed to find path to\n SDK named '%s'. Please read documentation for instructions\n on how to obtain and install this SDK." % sdk_name) path=umake_lib.fix_path(path) return os.path.normpath(os.path.join(os.getcwd(),project.src_root_path, path))def SetSDKPath(sdk_name, path): """Set the path to a named SDK""" import sdk sdk.SetPath(sdk_name, path)def get_module_output(module, *xpath): """Easy way to get something from the output dir of a module. First argument should be the path from the top to the module and the second (if present) should be the file/dir you want from the output dir of that module. All paths should use / to separate dirs.""" parts=[ project.src_root_path ] parts.extend(string.split(module,"/")) parts.append(project.output_dir) for x in xpath: parts.extend(string.split(x,"/")) return apply(os.path.join, parts)def UseCommonObjects(): global USE_COMMON_OBJ USE_COMMON_OBJ = 1def CommonDefines(*args): global common_defines common_defines = string.join(umake_lib.listify(args))def CommonLibraries(*args): global common_libraries common_libraries = string.join(umake_lib.listify(args))def CommonIncludes(*args): global common_includes common_includes = string.join(umake_lib.listify(args))def CommonSources(*args): global common_srcs common_srcs = string.join(umake_lib.listify(args))def __common_target(target): project.AddCommonDefines(common_defines) project.AddCommonLibraries(common_libraries) project.AddCommonIncludes(common_includes) project.AddCommonSources(common_srcs) project.SetTargetName(target) output_path, output_name = project.output_path() project.SetOutputName(output_name) project.AddCopyTargets(output_path) def __with_resource_target(rtarget, rfile, includes): project.with_resource_flag = 1 project.resource_target = rtarget project.resourcefile = rfile project.resourceincludes = [] if type(includes) == types.ListType: for item in includes: project.resourceincludes.append(umake_lib.fix_path(item)) elif type(includes) == types.StringType: project.resourceincludes.append(umake_lib.fix_path(includes)) else: umake_lib.fatal("invalid includes type") def ProgramWithResourceTarget(target, rtarget, rfile, includes): if not stringp(target): umake_lib.fatal("invalid argument") elif not stringp(rtarget): umake_lib.fatal("invalid argument") elif not stringp(rtarget): umake_lib.fatal("invalid argument") elif type(includes) not in [types.StringType, types.ListType]: umake_lib.fatal("invalid argument") project.SetTargetType("exe") __with_resource_target(rtarget, rfile, includes) __common_target(target)def DLLWithResourceTarget(target, rtarget, rfile, includes): if not stringp(target): umake_lib.fatal("invalid argument") elif not stringp(rtarget): umake_lib.fatal("invalid argument") elif not stringp(rtarget): umake_lib.fatal("invalid argument") elif type(includes) not in [types.StringType, types.ListType]: umake_lib.fatal("invalid argument") project.SetTargetType("dll") __with_resource_target(rtarget, rfile, includes) __common_target(target)def ProgramTarget(target): if not stringp(target): umake_lib.fatal("invalid argument") project.SetTargetType("exe") __common_target(target)def LibraryTarget(target): if not stringp(target): umake_lib.fatal("invalid argument") project.SetTargetType("lib") __common_target(target)def DLLTarget(target, libname = None): if not stringp(target): umake_lib.fatal("invalid argument") ## create a static library instead of if project.BuildOption("nodll"): ## set the type of DLL which is being built into a static ## library; this is used for creating a "static" player bldreg.set_value("dll_type", target, project.dll_type) ## to ensure entrypoints are of a well-known form and unique ## in the static version of the DLL, their names are mangled ## using the following define project.AddDefines("_PLUGINNAME=%s" % (target)) LibraryTarget(target) return project.SetTargetType("dll") __common_target(target) project.opt_target_name=libname ## FIXMEdef AllTarget(depends): if not stringp(target): umake_lib.fatal("invalid argument") project.alldepen
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -