📄 umake_makefile.py
字号:
self.platform, path, self.project.object_dir) if not os.path.isfile(sourcefile.path): continue self.writeln("%s: %s" % ( sourcefile.obj_path, sourcefile.path)) ## make the object target directory (obj_path, obj_basename) = os.path.split(sourcefile.obj_path) for dir in self.mkdir(obj_path, 1): ## the "-" sign allows the command to fail but be okay in ## the Makefile; for parallel builds, the directory creation ## may have already been handled by another process self.writeln("\t-@%s" % (dir)) ## write the command to build the object temp = sourcefile.build_rule.command.execute( sourcefile.obj_path, sourcefile.path) self.writeln("\t%s" % (temp)) def call_submake(self, makefile, rule = None, ignore_errors=None, do_cd = 1): if do_cd: dir = os.path.dirname(makefile) mf = os.path.basename(makefile) else: mf = makefile dir = "" if string.lower(os.path.basename(self.platform.make.cmd)) == 'nmake': ## Win nmake = 1 cmd = "$(MAKE) -nologo -f %s" % mf else: ## Unix nmake = 0 cmd = "$(MAKE) -f %s" % mf if rule: cmd = "%s %s" % (cmd, rule) if len(dir) and dir != ".": if not nmake: cmd="$-$cd %s && %s" % (dir, cmd) else: cmd="cd %s\n\t$-$%s\n\tcd $(MAKEDIR)" % ( dir, cmd ) else: cmd="$-$"+cmd if ignore_errors: dash = "-" else: dash = "" return "\t" + string.replace(cmd,"$-$",dash) def call_all_submake(self, rule = None, ignore_errors=None): for sumake in self.project.submakes: self.writeln(self.call_submake(sumake.makefile(), rule, sumake.ignore_errors or ignore_errors)) def AllTarget(self, targets = ''): if self.created_targets.has_key("all"): return self.created_targets["all"]=1 self.writeln("all: %s %s" % (self.project.object_dir, targets)) self.call_all_submake(None) self.writeln('') if not self.created_targets.has_key(self.project.object_dir): self.created_targets[self.project.object_dir]=1 self.writeln("%s:" % (self.project.object_dir)) for new_dir in self.mkdir(self.project.object_dir, 1): self.writeln("\t-@%s" % (new_dir)) self.writeln('') def MainTarget(self): if self.project.target_type == "": return output_path, output_name = self.project.output_path() self.AllTarget( output_path ) ## linking objects = self.platform.form_var("OBJS") if self.project.target_type != "lib": static_libs = self.platform.form_var("STATIC_LIBS") dynamic_libs = self.platform.form_var("DYNAMIC_LIBS") else: static_libs = '' dynamic_libs = '' self.writeln("%s: %s %s" % (output_path, objects, static_libs)) if len(self.project.output_dir): for new_dir in self.mkdir(self.project.output_dir, 1): self.writeln("\t-@%s" % (new_dir)) if hasattr(self.platform.link, "linker2"): if self.project.target_type == "lib": cmd_list=self.platform.link.LinkLIB(output_path, objects) elif self.project.target_type == "exe": cmd_list=self.platform.link.LinkEXE(output_path, objects, static_libs, dynamic_libs) elif self.project.target_type == "dll": cmd_list=self.platform.link.LinkDLL(output_path, objects, static_libs, dynamic_libs) else: if self.project.target_type == "lib": cmd_list = [ self.platform.make_lib.execute(output_path, objects, "", "") ] if self.platform.make_toc.cmd: cmd_list.append( self.platform.make_toc.execute(output_path) ) else: cmd_list = [ self.platform.link.execute(output_path, objects, static_libs, dynamic_libs) ] for cmd in cmd_list: self.writeln("\t%s" % (cmd)) ## for DRM signing if self.project.target_type == "dll" and \ self.project.BuildOption("drmsign") and \ self.project.CheckDRMSign(): try: temp = os.path.join(os.environ["BUILD_ROOT"], "bin", "drmsign") except KeyError: temp = "drmsign" self.writeln("\t%s %s" % (temp, output_path)) self.writeln('') ## object dependencies if len(self.project.object_dir): self.write_object_depends() self.CleanTarget() self.CopyTarget() self.DependTarget() def CleanTarget(self, targets = ""): """Make clean""" if self.created_targets.has_key("clean"): return self.created_targets["clean"]=1 output_path, output_name = self.project.output_path() if hasattr(self.platform.link, "linker2"): if self.project.target_type == "lib": fun=self.platform.link.CleanLIB elif self.project.target_type == "exe": fun=self.platform.link.CleanEXE elif self.project.target_type == "dll": fun=self.platform.link.CleanDLL elif self.project.target_type == "": fun = lambda p: [] list = fun(output_path) targets = targets + " " + string.join(list) else: if self.project.target_type: output_path, output_name = self.project.output_path() targets = targets + " " + output_path if targets == " ": targets = "" self.writeln("clean:") if targets: cobjects = self.platform.form_var("COMPILED_OBJS") self.writeln("\t%s %s %s" % ( self.platform.form_var("RM"), targets, cobjects)) self.call_all_submake("clean", 1) self.writeln('') def DependTarget(self): if self.created_targets.has_key("depend"): return self.created_targets["depend"]=1 self.writeln("depend:") self.call_all_submake("depend") if len(self.project.sources): temp = self.platform.make_dep.execute( self.platform.form_var("SRCS"), self.project.object_dir) self.writeln("\t%s" % (temp)) self.writeln('') def CopyTarget(self, path_list = []): if self.created_targets.has_key("copy"): return self.created_targets["copy"]=1 deps = [] allcopy = [] path_list = path_list + self.project.copy_target_list for spath in path_list: dpath = os.path.join( self.project.target_dir, os.path.basename(spath)) allcopy.append( ( spath, dpath ) ) ## Create extra copies for debugging for dpath in self.project.debug_copies: spath = self.project.output_path()[0] dest = os.path.join(dpath, os.path.basename(spath)) allcopy.append( ( spath, dest ) ) spacecopy = [] ## Write out all copy targets for (spath, dpath) in allcopy: if " " in dpath: spacecopy.append( (spath,dpath) ) continue dir = os.path.dirname(dpath) self.writeln("%s: %s" % (dpath, spath)) for l in self.mkdir(dir, 1): self.writeln("\t-@%s" % l) if os.path.basename(spath) == os.path.basename(dpath): self.writeln('\t%s "%s"' % (self.platform.rmdir.cmd, dpath)) self.writeln('\t%s "%s" "%s"' % (self.platform.copy.cmd, spath, dpath)) self.writeln("") deps.append(dpath) self.writeln("copy: %s" % string.join(deps," ")) self.call_all_submake("copy") ## Write out copy commands with spaces in them for (spath, dpath) in spacecopy: dir = os.path.dirname(dpath) for l in self.mkdir(dir, 1): self.writeln("\t-@%s" % l) if os.path.basename(spath) == os.path.basename(dpath): self.writeln('\t%s "%s"' % (self.platform.rmdir.cmd, dpath)) self.writeln('\t%s "%s" "%s"' % (self.platform.copy.cmd, spath, dpath)) self.writeln('') def EmptyTarget(self): self.AssertTarget("all") self.writeln("all:") self.AssertTarget("depend") self.writeln("depend:") self.AssertTarget("clean") self.writeln("clean:") self.AssertTarget("dist") self.writeln("dist:") self.AssertTarget("copy") self.writeln("copy:") def __init__(self, platform, project): umake_lib.Targets.__init__(self, platform, project) self.created_targets = {} self.makefile = project.pre_target_buff[:] ## Should this go in MainTarget as well?? self.write_macros() ## Cruft to allow people to create their own makefiles... for targ in project.xtargets: silly=string.upper(targ[:1])+targ[1:]+"Target" makefile_generator.__dict__[silly](self) ## Really make a makefile! self.MainTarget() ## Add extra dependencies for file in project.file_dependencies.keys(): for dep in project.file_dependencies[file]: self.writeln("%s: %s" % (file, dep)) self.makefile.extend(project.post_target_buff) ## Avoid re-parsing the makefile if it was mostly hand-written mfile = string.join(self.makefile,'') if project.target_type: mfile = makefile.ParseMakefile(mfile) self.mfile=mfile ## do some basic checks, print warnings for now... ## this will be extended later to intelligently merge ## duplicate target names -JMP name_list = [] for name in mfile.target_list: if name in name_list: umake_lib.warning( "makefile has duplicate target names=\"%s\"" % (name)) else: name_list.append(name) mfile = str(mfile) ## write out the makefile open(project.makefile_name, "w").write(str(mfile))def make_makefile(platform, project): makefile_generator(platform, project) ## Pretend like everything went well return Nonedef compile(): """This will eventually be the primary function for invoking make""" import shell shell.run("make")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -