📄 umake_makefile.py
字号:
# # ***** BEGIN LICENSE BLOCK *****# Source last modified: $Id: umake_makefile.py,v 1.22 2004/11/30 20:50:34 hubbe Exp $# # Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.# # The contents of this file, and the files included with this file,# are subject to the current version of the RealNetworks Public# Source License (the "RPSL") available at# http://www.helixcommunity.org/content/rpsl unless you have licensed# the file under the current version of the RealNetworks Community# Source License (the "RCSL") available at# http://www.helixcommunity.org/content/rcsl, in which case the RCSL# will apply. You may also obtain the license terms directly from# RealNetworks. You may not use this file except in compliance with# the RPSL or, if you have a valid RCSL with RealNetworks applicable# to this file, the RCSL. Please see the applicable RPSL or RCSL for# the rights, obligations and limitations governing use of the# contents of the file.# # Alternatively, the contents of this file may be used under the# terms of the GNU General Public License Version 2 or later (the# "GPL") in which case the provisions of the GPL are applicable# instead of those above. If you wish to allow use of your version of# this file only under the terms of the GPL, and not to allow others# to use your version of this file under the terms of either the RPSL# or RCSL, indicate your decision by deleting the provisions above# and replace them with the notice and other provisions required by# the GPL. If you do not delete the provisions above, a recipient may# use your version of this file under the terms of any one of the# RPSL, the RCSL or the GPL.# # This file is part of the Helix DNA Technology. RealNetworks is the# developer of the Original Code and owns the copyrights in the# portions it created.# # This file, and the files included with this file, is distributed# and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY# KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS# ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET# ENJOYMENT OR NON-INFRINGEMENT.# # Technology Compatibility Kit Test Suite(s) Location:# http://www.helixcommunity.org/content/tck# # Contributor(s):# # ***** END LICENSE BLOCK *****# """Implement the Makefile back end for Umake. This is used by both UNIX andWindows targets to generate Makefiles to build targets."""import osimport stringimport typesimport umake_libimport makefileimport shellimport redef prepend_str_list(prepend_str, list): """Given a string and a list of strings, returns a new list with the string pre-pended to each item in the list.""" new_list = [] for current_str in list: new_list.append(prepend_str + current_str) return new_listclass makefile_generator(umake_lib.Targets): def writeln(self, text): self.makefile.append(text+"\n") def write(self, text): self.makefile.append(text) def AssertTarget(self, targ): if self.created_targets.has_key(targ): print "umake: warning: Duplicate target %s" % targ else: self.created_targets[targ]=1 def mkdir(self, dir, recursive = 0): """Returns a string that should make a directory on the current platform, if recursive = 1, then it returns a list of makedir strings that when executed in order creates a deep subdirectory.""" umake_lib.debug("Project.mkdir") if not recursive: return self.platform.mkdir.execute(dir) ## Special Recursive mode for Makefiles cmds = [] done = { None:1, "":1, os.sep:1, os.curdir:1, os.pardir:1 } while 1: if done.has_key(dir): break (head, tail) = os.path.split(dir) if not done.has_key(tail): cmds.append(self.platform.mkdir.execute(dir)) done[dir]=1 dir = head cmds.reverse() return cmds def build_quoted_arg_list(self, args, prefix=""): if len(args) == 0: return "" tmp=[] if len(prefix) and prefix[-1] == ' ': l=string.strip(prefix) for n in args: tmp.append(l) tmp.append(n) else: for n in args: tmp.append(prefix+n) if string.lower(os.path.basename(self.platform.make.cmd)) == 'nmake': ## NMAKE/cmd.exe quoting def do_quote(str): if re.match('^[^ "]*$', str): return str str = re.sub(r'(\\*)"', r'\1\1\"', str + '"') return '"%s"' % str[:-2] else: ## POSIX quoting def do_quote(str): if re.match('^[-a-zA-Z0-9_+=.,/@]*$', str): return str str = re.sub(r'([^- a-zA-Z0-9_+=.,/@])', r'\\\1', str) return '"' + str + '"' return string.join(map(do_quote, tmp)," ") def compat_quote(self, args, prefix=""): if self.project.FeatureIsEnabled("makefile_quotes"): return self.build_quoted_arg_list(args, prefix) else: if prefix: args=prepend_str_list(prefix, args) return string.join(args) def write_macros(self): """Writes all the macros (variables) to the Makefile.""" umake_lib.debug("Project.write_macros") def str_list(list): return string.join(list) self.writeln("## Generated from %s, do not edit, do not commit to cvs!" % (self.project.umakefile_name )) self.writeln("") ## print out all command and command flag variables ## in the platform command list, taking care not to ## print blank lines for commands/command flas which ## do not exist for current_command in self.platform.command_list: command_var = current_command.setup_command_var() flags_var = current_command.setup_flags_var() if len(command_var): self.writeln(command_var) if len(flags_var): self.writeln(flags_var) ## write out env variables for compilers for build_rule in self.platform.build_rules.values(): current_command = build_rule.command command_var = current_command.setup_command_var() flags_var = current_command.setup_flags_var() if len(command_var): self.writeln(command_var) if len(flags_var): self.writeln(flags_var) ## LINKER if not hasattr(self.platform.link, "linker2"): self.writeln(self.platform.link.setup_command_var()) self.writeln(self.platform.link.setup_flags_var()) ## SRCS self.writeln("SRCS=%s" % (self.compat_quote(self.project.sources))) ## COMPILED_OBJS, SOURCE_OBJS, OBJS self.writeln("OBJS=%s %s" % ( self.platform.form_var("COMPILED_OBJS"), self.platform.form_var("SOURCE_OBJS"))) self.writeln("COMPILED_OBJS=%s" % ( self.compat_quote(self.project.objects))) self.writeln('SOURCE_OBJS=%s' % ( self.compat_quote(self.project.objsrcs))) ## INCLUDES self.writeln("INCLUDES=%s" % self.build_quoted_arg_list( self.project.includes, self.platform.include_arg)) ## DEFINES if self.platform.cc.prefix_include_arg: defdir = self.project.output_dir shell.mkdir(defdir) name = os.path.join(self.project.module_directory(), self.project.makefile_name) prefix_file_name = umake_lib.declaw_name(name)+"_ribodefs.h" prefix_file_name=os.path.join(defdir, prefix_file_name) lines=[] defs=self.project.defines defs.sort() for d in defs: ind = string.find(d,"=") if ind == -1: lines.append("#ifndef %s" % (d)) lines.append("#define %s 1" % (d)) else: lines.append("#ifndef %s" % (d[:ind])) lines.append("#define %s %s" % (d[:ind],d[ind+1:])) lines.append("#endif") for include in self.project.prefix_file_include_list: ## Ugly magic stuff if type(include) == types.StringType: if include[0] == '"' or include[0] == '<': lines.append("#include %s" % (include)) elif include[0] == '#': lines.append("%s" % (include)) else: lines.append("#include <%s>" % (include)) elif type(include) == types.ListType: lines.extend(include) data = string.join(lines,"\n")+"\n" umake_lib.write_file(prefix_file_name, data) self.writeln("DEFINES=%s%s %s%s" % ( self.platform.include_arg, os.curdir, self.platform.cc.prefix_include_arg, prefix_file_name)) else: self.writeln("DEFINES=%s" % self.build_quoted_arg_list( self.project.defines, self.platform.define_arg)) ## STATIC_LIBS static_libs = self.project.libraries + self.project.libraries2 + \ self.project.local_libs + self.project.module_libs self.writeln("STATIC_LIBS=%s" % (self.compat_quote(static_libs))) ## DYNAMIC_LIBS self.writeln("DYNAMIC_LIBS=%s %s" % ( self.compat_quote(self.project.dynamic_libraries), self.compat_quote(self.project.sys_libraries, self.platform.sys_lib_arg))) self.writeln("") ## suffixes if len(self.platform.suffix_list): self.writeln(".SUFFIXES: %s" % ( string.join(self.platform.suffix_list))) self.writeln("") ## default/misc build rules for rule in self.platform.build_rules.values(): ## Add custom INCLUDE/DEFINE variables for each compiler ## (Except CC/CXX, which uses INCLUDE/DEFINES) if rule.command.make_var not in [ "CC", "CXX" ]: if rule.command.define_arg and rule.command.make_var: try: defs = None try: defs = rule.command.defines except AttributeError: pass if defs == None: defs = self.project.defines self.writeln("%sDEFINES=%s" % ( rule.command.make_var, self.build_quoted_arg_list(defs, rule.command.define_arg))) self.writeln("") except: pass if rule.command.include_arg and rule.command.make_var: try: includes = None try: includes = rule.command.includes except AttributeError: pass if includes == None: includes = self.project.includes self.writeln("%sINCLUDES=%s" % ( rule.command.make_var, self.build_quoted_arg_list(includes, rule.command.include_arg))) self.writeln("") except: pass if self.platform.build_rules.get(rule.source_suffix,None) == rule: rule_str = "%s%s%s" % ( rule.source_suffix, rule.target_suffix, self.platform.make_depend) self.writeln(rule_str) cmd_str = rule.command.execute( self.platform.make_target, self.platform.make_source) self.writeln("\t%s" % (cmd_str)) self.writeln("") def write_object_depends(self): """Write out a dependancy rule for each source file so its object file can be written to a alternative target directory.""" umake_lib.debug("Project.write_object_depends") for path in self.project.sources: sourcefile = umake_lib.SourceFile(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -