📄 umake_win_makefile.py
字号:
return text;class Workspace: """Class representing and generating one MSDEV workspace""" def __init__(self): self.projects = [] self.dependencies = {} def AddProject(self, name, path): self.projects.append( (name, path) ) self.dependencies[name] = [] def AddDependency(self, dependant, supporter): self.dependencies[dependant].append(supporter) def generate(self): text = [] text.append('Microsoft Developer Studio Workspace File, Format Version 6.00') text.append('# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!') text.append('') self.text=text self.done={} self.project_byname={} for (name, path) in self.projects: self.project_byname[name]=path for (name, path) in self.projects: self.generate_project(name) return string.join(self.text,"\n") def generate_project(self, name): if self.done.has_key(name): return self.done[name]=1 if not self.project_byname.has_key(name): return path = self.project_byname[name] for d in self.dependencies.get(name,[]): self.generate_project(d) text=self.text text.append('###############################################################################') text.append('') text.append('Project: "%s"=%s - Package Owner=<4>' % (name, path)) text.append('') text.append('Package=<5>') text.append('{{{') text.append('}}}') text.append('') text.append('Package=<4>') text.append('{{{') for d in self.dependencies.get(name,[]): text.append(' Begin Project Dependency') text.append(' Project_Dep_Name %s' % d) text.append(' End Project Dependency') text.append('}}}') text.append('')def subtract_array(a, b): tmp={} for x in b: tmp[x]=1 ret=[] for x in a: if not tmp.has_key(x): ret.append(x) return retclass project_generator(umake_lib.Targets): """Class which generates a DSP file from the data in in the platform and project classes""" def setup_variables(self): """Read the generated Makefile and grab all the variables from it. This can be optimized a lot since umake_makefile already knows all this stuff.. """ mf=open(self.project.makefile_name,"r").read() mf=makefile.ParseMakefile(mf) self.mf = mf self.variables=mf.get_variables() self.variables["MAKEFILE"]=self.project.makefile_name def do_config(self,type): vars=self.variables.copy() cc=self.platform.cc ## This is modeled after umake.Compiler.execute extra_args = "" if cc.args.has_key(type): extra_args = cc.args[type] #vars["ALL_C_FLAGS"] = umake.form_string( # self.platform.form_var(cc.make_flags), # extra_args, # cc.source_arg) # UGLY! OPTIONS={} for (suffix, rule) in self.platform.build_rules.items(): c=rule.command tmp=c.execute('XyzzY%s' % rule.target_suffix, 'XyzzY%s' % rule.source_suffix) tmp=string.split(tmp,' ') n = [] for x in tmp: if string.count(x,"XyzzY"): continue if x == "$(%s)" % c.make_var: continue n.append(x) tmp=string.join(n) OPTIONS[suffix]=tmp vars["ALL_%s_FLAGS" % c.make_var]=tmp for (suffix, rule) in self.platform.build_rules.items(): c=rule.command f1=makefile.expand_variables(vars["ALL_%s_FLAGS" % c.make_var], vars,1) f2=makefile.expand_variables(OPTIONS[rule.source_suffix],vars,1) f3=string.join(subtract_array(string.split(f1), string.split(f2))) self.variables["EXTRA_%s_FLAGS" % c.make_var]=f3 output_path, output_name = self.project.output_path() vars["OUTFILE"]=output_path static_libs="$(STATIC_LIBS)" # static_libs='' # Added automatically? dynamic_libs="$(DYNAMIC_LIBS)" objects = self.platform.form_var("SOURCE_OBJS") cmd_list=None 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, "", "") ] else: cmd_list = [ self.platform.link.execute(output_path, objects, static_libs, dynamic_libs) ] if cmd_list: linkopts=cmd_list[0] tmp=string.split(linkopts," ") # Kluge!!! p = 0 while tmp[p][0] != "/": p = p + 1 linkopts=string.join(tmp[p:]," ") vars["LINKER_OPTIONS"] = linkopts vars["LD"]=string.join(tmp[:p]," ") vars["OBJDIR"]=self.project.object_dir vars["OUTDIR"]=self.project.output_dir ## Recover 'copy' target from Makefile postbuild = [] for t in self.mf.target_list: if t.name == "copy": for cmd in t.command_list: if not cmd: continue if cmd[0]=='-': cmd=cmd[1:] if cmd[0]=='@': cmd=cmd[1:] postbuild.append(cmd) self.proj.AddConfig(type, vars, postbuild) def add_configurations(self): self.do_config("Release") self.do_config("Debug") def __init__(self, platform, project): umake_lib.Targets.__init__(self, platform, project) self.variables = {} self.setup_variables() # print "VARIABLES = %s" % repr(self.variables) # print "TARGET TYPE = %s" % project.target_type #name = project.target_name #if not name: # name=os.path.split(os.getcwd())[-1] + "_" + self.project.makefile_name name = os.path.join(self.project.module_directory(), self.project.makefile_name) name = umake_lib.declaw_name(name) proj=Project(name, self.project.makefile_name, project.target_type, self.variables) self.proj=proj self.add_configurations() for src in project.sources: sourcefile = umake_lib.SourceFile( platform, src, project.object_dir) proj.AddSourceFile(sourcefile) cache = globals().get("__umake_win_makefile_header_cache__", {"dir":""}) if cache["dir"] != os.getcwd(): cache["dir"]=os.getcwd() headers = [] ## Not very pretty, we add all header files ## found in this directory (or any subdir) ## to the project. potential_headers = [ "." ] for h in potential_headers: if os.path.isdir(h): for f in os.listdir(h): potential_headers.append(os.path.join(h,f)) else: if string.lower(os.path.splitext(h)[1]) == ".h": headers.append(h) cache["headers"] = headers globals()["__umake_win_makefile_header_cache__"] = cache proj.AddHeaderFiles(cache["headers"]) global project_extension global workspace_extension name = os.path.join(self.project.module_directory(), self.project.makefile_name) name = umake_lib.declaw_name(name) data=proj.generate() umake_lib.write_file(name+"."+project_extension,proj.generate())## class workspace_generator(umake_lib.Targets): """Class which generates a DSW file from the data in in the platform and project classes""" def __init__(self, platform, project): global project_extension global workspace_extension umake_lib.Targets.__init__(self, platform, project) dsw=Workspace() projects = [] makefiles = [] for sumake in project.get_uber_makes(): makefiles.append(sumake.abs_makefile()) name = umake_lib.declaw_name(sumake.abs_makefile()) path = os.path.dirname(sumake.makefile()) path = os.path.join(path, umake_lib.declaw_name(sumake.abs_makefile())) dsw.AddProject(name,path+"."+project_extension) for dep in sumake.dependencies(): dep = umake_lib.declaw_name(dep) dsw.AddDependency(name, dep) name = os.path.join(self.project.module_directory(), self.project.makefile_name) name = umake_lib.declaw_name(name) umake_lib.write_file(name+"."+workspace_extension,dsw.generate())def make_makefile(platform, project): ret1 = umake_makefile.make_makefile(platform, project) # Make VC6 project files here ret2 = project_generator(platform, project) ret3 = workspace_generator(platform, project) return ret1 or ret2 or ret3def compile(): return umake_makefile.compile()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -