Esempio n. 1
0
def prog(target, objs, env=None, build_dir=None, **kwargs):
    """ Convert the list of objects into a program given the cflags """
    nobjs = util.flatten(objs)
    BuildDir = util.get_build_dir(env, build_dir)
    ntarget = os.path.join(BuildDir, target)
    t_prog(ntarget, nobjs, env=env, **kwargs)
    return nodes.File(ntarget)
Esempio n. 2
0
    def _find_deps_pxd(self, s):
        temp = util.flatten([m.findall(s) for m in self._DEP_REGS_PXD])
        all_matches = util.flatten(
            [ [ s.strip() for s in m.split(',') ] for m in temp] )

        for dep in all_matches:
            dep = self._normalize_module_name(dep)
            dep += '.pxd'
            if dep not in self.deps:
                # Recurse, if file exists. If not, the file might be global
                # (which we currently do not track) or the file
                # might not exist, which is not our problem, but cythons
                for path in self.include_paths + ['']:
                    filename = os.path.relpath(os.path.join(path, dep))
                    if os.path.exists(filename):
                        self._find_deps(open(filename,"r").read())
                    self.deps.add(filename)
Esempio n. 3
0
def shared_obj(target, objs, env=None, build_dir=None, **kwargs):
    """ Convert the list of objects into a program given the cflags """
    nobjs = util.flatten(objs)
    BuildDir = util.get_build_dir(env, build_dir)
    ntarget = os.path.join(BuildDir, target)

    if "CFLAGS" in kwargs:
        merged_CFLAGS = kwargs["CFLAGS"][:]
        del kwargs["CFLAGS"]
    else:
        merged_CFLAGS = env.CFLAGS[:]

    merged_CFLAGS.insert(0, "-shared")

    t_prog(ntarget, nobjs, env=env, CFLAGS=merged_CFLAGS, **kwargs)

    return nodes.File(ntarget)
Esempio n. 4
0
def obj(source_list, target=None, env=None, build_dir=None, **kwargs):
    """ Take a list of sources and convert them to a correct object file """

    BuildDir = util.get_build_dir(env, build_dir)
    threads = []

    if not type(source_list) == list:
        source_list = [source_list]

    nslist = util.flatten(source_list)

    # If a target is specified, build all the sources in the list into
    # a single target
    if target:
        buildext = None
        new_source_list = []
        for source in nslist:
            source = os.path.join(os.getcwd(), source)
            (name, ext) = os.path.splitext(str(source))
            if buildext == None:
                buildext = ext
            elif buildext != ext:
                Mem.instance().fail("Mixed extensions in a single build object")
            new_source_list.append(source)

        t = os.path.join(BuildDir, str(target))
        thread = build_obj(t, new_source_list, buildext, env, **kwargs)
        thread.join()
        return [thread.result]

    # No target specified.  Build each object individually
    for source in nslist:
        (name, ext) = os.path.splitext(str(source))
        target = os.path.join(BuildDir, name + ".o")

        source = os.path.join(os.getcwd(), str(source))
        if not ext == ".h":
            threads.append(build_obj(target, [source], ext, env, **kwargs))

    for t in threads:
        if t:
            t.join()

    return [t.result for t in threads if t]
Esempio n. 5
0
def python_ext(target, sources, env={}, build_dir = "", inplace = False,
               **kwargs):
    """Turn the sources list into a python extension"""

    if not isinstance(sources, list):
        sources = [ sources ]

    mem = Mem.instance()

    build_dir = util.get_build_dir(env, build_dir)


    # Set our function specific config
    newenv = util.Env(env)
    newenv.update(kwargs)

    # Fill in the holes with sensible defaults
    # Is this C or C++?
    if 'CC' not in newenv:
        if 'CXXFLAGS' in newenv and 'CFLAGS' not in newenv:
            newenv.CC = 'g++'
        else:
            newenv.CC = 'gcc'


    all_objs = []
    for source in util.flatten(sources):
        ext = os.path.splitext(source)[1].lower()
        if ext not in _EXTENSION_DISPATCH:
            raise ValueError("Don't know how to build extension from source %s"
                    % source)

        objs = _EXTENSION_DISPATCH[ext](source, newenv or {}, build_dir, **kwargs)

        all_objs.extend(objs)

    target += '.so'

    if not inplace:
        ntarget = os.path.join(build_dir, target)
    else:
        ntarget = target

    return _link_python_ext(ntarget, all_objs, env=newenv)