Example #1
0
    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(
                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))
Example #2
0
    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
Example #3
0
    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(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))
Example #4
0
    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
Example #5
0
def remove_line_continuations(um_buff, name):
    """Takes a string of Python code as input, runs it through pylex() to
    remove line continuations, then it removes all the blank lines.  It
    returns a list of strings with one Python statment per line."""

    umake_lib.debug("calling pylex..")
    _line_list = pylex(um_buff, name)
    umake_lib.debug("pylex done")

    line_list = []
    for line in _line_list:
        line = string.rstrip(line)
        if len(line) == 0:
            continue
        line_list.append(line)

    return line_list
Example #6
0
def remove_line_continuations(um_buff, name):
    """Takes a string of Python code as input, runs it through pylex() to
    remove line continuations, then it removes all the blank lines.  It
    returns a list of strings with one Python statment per line."""

    umake_lib.debug("calling pylex..")
    _line_list = pylex(um_buff, name)
    umake_lib.debug("pylex done")

    line_list = []
    for line in _line_list:
        line = string.rstrip(line)
        if len(line) == 0:
            continue
        line_list.append(line)

    return line_list
Example #7
0
    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("")
Example #8
0
    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("")
Example #9
0
def generate_uberxml(platform, project, mprj):
    global UberTemplate

    target_tag = '#TARGET#'
    targetorder_tag = '#TARGETORDER#'
    group_tag = '#GROUP#'
    make_all_subtargets_tag = '#MAKE_ALL_SUBTARGETS#'

    dependencies_section_empty = '<SUBTARGETLIST></SUBTARGETLIST>'

    uber_template = UberTemplate

    # scoop up the uber text from each directory, add the depend
    all_module_targetnames_list = []

    for mod in project.get_uber_makes():
        uber_file_name = mod.makefile() + "_uber.xmldata"
        umake_lib.debug("Reading uber-data %r" % repr(uber_file_name))
        # Read the generated UBER-file
        try:
            uber_text = open(uber_file_name, 'r').read()
        except:
            print "==> Cannot read from %s " % (uber_file_name )
            continue

        uber_text = string.replace(uber_text,"#SRC_ROOT_PATH#", project.src_root_path)

        try:
            (uber_target_name,
             uber_text_1,
             uber_text_2,
             uber_text_3,
             uber_output_path) = string.split(uber_text, "<<>>")

        except:
            print "==> Cannot parse %s from module %s for <<>> sections" % (uber_file_name, module.name)
            continue

        uber_target_name = string.strip(uber_target_name)

        # also add this as a subtarget for the Make All target
        all_module_targetnames_list.append(uber_target_name)

        # now we look for the <SUBTARGETLIST></SUBTARGETLIST> in the target section of the
        # module's XML, and replace it with a list of all actual dependencies

        # make a subtarget list containing our dependencies list, and replace the empty one
        # in the template with ours

        deps = mod.dependencies()[:]
        deps.reverse()
        dependencies_section_xml = MakeDependenciesSubtargetListXML(deps)
        uber_text_1 = string.replace(uber_text_1,
                                     dependencies_section_empty,
                                     dependencies_section_xml,
                                     1)
        
        # if an empty subtarget list is left in the template, remove it
        uber_text_1 = string.replace(uber_text_1,
                                     dependencies_section_empty,
                                     "",
                                     1)

        # finally, follow the target, targetorder, and group placeholders in the top level
        # template with the data for this module

        template1 = string.replace(uber_template, target_tag, target_tag + '\n' + uber_text_1, 1)
        template2 = string.replace(template1, targetorder_tag, targetorder_tag + '\n' + uber_text_2, 1)
        uber_template = string.replace(template2, group_tag, group_tag + '\n' + uber_text_3, 1)

    # if we found any uber.xml files, generate the master uber.xml file

    # print "Extracted uber-project XML from %s" % (string.join(success_list, ", "))

    # insert the Make All subtarget list
    make_all_dependencies_section_xml = MakeDependenciesSubtargetListXML(all_module_targetnames_list)
    uber_template = string.replace(uber_template,
                                   make_all_subtargets_tag,
                                   make_all_dependencies_section_xml, 1)

    # remove the placeholder tags from the template
    uber_template = string.replace(uber_template, target_tag, "", 1)
    uber_template = string.replace(uber_template, targetorder_tag, "", 1)
    uber_template = string.replace(uber_template, group_tag, "", 1)

    # write out the file into an uber directory in the source directory
    uberxml_output_name = project.makefile_name + "_uber.xml"
    print "Writing %s" % (uberxml_output_name)
    try:
        # delete any old xml file with the same name as our uber
        if os.path.isfile(uberxml_output_name):
            os.remove(uberxml_output_name)

        open(uberxml_output_name, 'w').write(uber_template)
    except IOError:
        print "*** Failed to write file %s" % (uberxml_output_name) 
Example #10
0
def WriteProjectSettingsXML(mprj, templateName):
    """ Writes out the Applescript which writes the <SETTINGS> section of
    the CodeWarrior XML. This includes all the CW project preferences,
    source file list and link order.  This function is used to write
    out the settings for 'project.xml' and 'project_uber.xml' """

    template_filename = os.path.join(os.environ['BUILD_ROOT'],"bin","mac", templateName)
    template_text = open(template_filename,"r").read()
                 
    ## set access paths
    user_list = []
    if templateName == "project_uber.xml":  
        # uber can't have local paths eg. ':', ':pub:'
        # they must be like '::pndebug:', '::pndebug:pub:'
        module_path = os.getcwd()
        src_root_path = macpath.normpath(os.path.join(module_path,mprj.project.src_root_path))+":"

        
        for (path, recursive, origin) in mprj.user_paths:
            umake_lib.debug("USER_PATH: %s => (%s)" %
                            (repr(path),
                             repr(mprj.project.src_root_path)))

            path = macpath.normpath(macpath.join(module_path, path))
            if path[:len(src_root_path)] == src_root_path:
                path = "#SRC_ROOT_PATH#" + path[len(src_root_path):]

            umake_lib.debug("USER_PATH: => %s (%s)" %
                            (repr(path),
                             repr(src_root_path)))

            user_list.append(path)
    else:
        for (path, recursive, origin) in mprj.user_paths:
            path = macpath.normpath(path)
            user_list.append(path)

    ## Set CodeWarrior prefs
    empty_list = []
    template_text = SetAccessPathBlock(template_text,
                                       user_list,
                                       empty_list,
                                       empty_list,
                                       "#USER_SEARCH_PATHS#")

    system_list = []
    recursive_list = []
    origin_list = []
    for (path, recursive, origin) in mprj.system_paths:
        system_list.append(path)
        recursive_list.append(recursive)
        origin_list.append(origin)

    template_text = SetAccessPathBlock(template_text,
                                       system_list,
                                       recursive_list,
                                       origin_list,
                                       "#SYSTEM_SEARCH_PATHS#")

    ## add files
    file_list = string.join(mprj.source_list, ',')
    source_dir,output_dir = macpath.split(mprj.output_dir_path)
    
    target_type = ''
    if output_dir == "debug":
        target_type = "debug"

    template_text = SetFileListBlock(template_text,
                                     file_list,
                                     "#TEXT_FILE_LIST#",
                                     "Text",
                                     target_type)

    source_list = []
    for file_name in mprj.source_list:
        source_list.append(file_name)

    if len(mprj.library_list):
        library_list = string.join(mprj.library_list, ',')
        template_text = SetFileListBlock(template_text,
                                         library_list,
                                         "#LIB_FILE_LIST#",
                                         "Library",
                                         "")

        # add libs to source list since they need to be
        # included with groups, link order iterms
        for library in mprj.library_list:
            lib_path, lib_name = os.path.split(library)
            if lib_name not in mprj.source_list:
                source_list.append(lib_name)
    else:
        template_text=string.replace(template_text, "#LIB_FILE_LIST#", "")
        
    # link order
    file_list = string.join(source_list, ',')

    gLinkOrderBlockString="""
                <FILEREF>
                    <PATHTYPE>Name</PATHTYPE>
                    <PATH>#THE_VALUE#</PATH>
                    <PATHFORMAT>MacOS</PATHFORMAT>
                </FILEREF>
"""

    template_text = SetPreferenceBlock(template_text,
                                       file_list,
                                       gLinkOrderBlockString,
                                       "#LINK_ORDER_ITEMS#")
    
    ## add frameworks
    if len(mprj.project.sys_frameworks):
        framework_string_list = string.join(mprj.project.sys_frameworks, ',')
        template_text=SetFrameworkBlock(template_text,
                                        framework_string_list,
                                        "#FRAMEWORK_LIST#")
    else:
        template_text=string.replace(template_text, "#FRAMEWORK_LIST#", "")

    ## group order
    template_text=SetGroupBlock(template_text,
                                file_list,
                                "#GROUP_LIST_ITEMS#",
                                mprj.cwtarget_name)
    template_text = string.replace(template_text,
                                   "#GROUP_NAME#",
                                   mprj.cwtarget_name)

    ## CW project preferences
    template_text=SetPreferenceValue(template_text, "MWFrontEnd_C_prefixname", mprj.prefix_file)
    template_text=SetPreferenceValue(template_text, "MWRez_Language_prefixname", mprj.rprefix_file)
                
    ## set remaining preferences - theses are defined in macos-carbon-powerpc-cw6.cf
    for (panel, pref) in mprj.preferences.items():
        for (pref_key, pref_value) in pref.items():
            template_text = SetPreferenceValue(template_text,
                                               pref_key,
                                               pref_value)


    # set target dir to debug/release
    if templateName == "project_uber.xml":  
        module_path = mprj.project_file_path[:-1]
        module_path, module_name = os.path.split(module_path)
        module_path, module_name = os.path.split(module_path)
        template_text = string.replace(template_text,
                                       "#TARGET_DIR#",
                                       "#SRC_ROOT_PATH#%s:%s:" % (module_name,output_dir))
                                       
        template_text = string.replace(template_text,
                                       "#OUTPUT_FILE_NAME#",
                                       "%s:%s" % (output_dir,mprj.output_name))
    else:
        template_text = string.replace(template_text,
                                       "#TARGET_DIR#",
                                       ":%s:" % (output_dir))

    template_text = string.replace(template_text,
                                   "#TARGET_NAME#",
                                   mprj.cwtarget_name)

    return template_text