autotools.py 2.38 KB
Newer Older
1
import os.path, subprocess, sys
2

3
from build.makeproject import MakeProject
4

5
class AutotoolsProject(MakeProject):
6 7
    def __init__(self, url, md5, installed, configure_args=[],
                 autogen=False,
8
                 autoreconf=False,
9
                 cppflags='',
10 11
                 ldflags='',
                 libs='',
12
                 subdirs=None,
13
                 **kwargs):
14
        MakeProject.__init__(self, url, md5, installed, **kwargs)
15 16
        self.configure_args = configure_args
        self.autogen = autogen
17
        self.autoreconf = autoreconf
18
        self.cppflags = cppflags
19 20
        self.ldflags = ldflags
        self.libs = libs
21
        self.subdirs = subdirs
22

23
    def configure(self, toolchain):
24 25
        src = self.unpack(toolchain)
        if self.autogen:
26 27 28 29
            if sys.platform == 'darwin':
                subprocess.check_call(['glibtoolize', '--force'], cwd=src)
            else:
                subprocess.check_call(['libtoolize', '--force'], cwd=src)
30 31 32
            subprocess.check_call(['aclocal'], cwd=src)
            subprocess.check_call(['automake', '--add-missing', '--force-missing', '--foreign'], cwd=src)
            subprocess.check_call(['autoconf'], cwd=src)
33 34
        if self.autoreconf:
            subprocess.check_call(['autoreconf', '-vif'], cwd=src)
35 36 37 38 39 40 41 42 43 44

        build = self.make_build_path(toolchain)

        configure = [
            os.path.join(src, 'configure'),
            'CC=' + toolchain.cc,
            'CXX=' + toolchain.cxx,
            'CFLAGS=' + toolchain.cflags,
            'CXXFLAGS=' + toolchain.cxxflags,
            'CPPFLAGS=' + toolchain.cppflags + ' ' + self.cppflags,
45 46
            'LDFLAGS=' + toolchain.ldflags + ' ' + self.ldflags,
            'LIBS=' + toolchain.libs + ' ' + self.libs,
47
            'AR=' + toolchain.ar,
48
            'RANLIB=' + toolchain.ranlib,
49 50 51 52 53 54 55
            'STRIP=' + toolchain.strip,
            '--host=' + toolchain.arch,
            '--prefix=' + toolchain.install_prefix,
            '--enable-silent-rules',
        ] + self.configure_args

        subprocess.check_call(configure, cwd=build, env=toolchain.env)
56 57 58 59
        return build

    def build(self, toolchain):
        build = self.configure(toolchain)
60 61 62 63 64
        if self.subdirs is not None:
            for subdir in self.subdirs:
                MakeProject.build(self, toolchain, os.path.join(build, subdir))
        else:
            MakeProject.build(self, toolchain, build)