build_tools.py 4.76 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# cerbero - a multi-platform build system for Open Source software
# Copyright (C) 2012 Andoni Morales Alastruey <ylatuya@gmail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

import os

21
from cerbero.config import Config, Platform, DistroVersion
22
from cerbero.bootstrap import BootstrapperBase
23
24
from cerbero.build.oven import Oven
from cerbero.build.cookbook import CookBook
25
from cerbero.commands.fetch import Fetch
26
27
from cerbero.utils import _
from cerbero.errors import FatalError, ConfigurationError
28
29


30
class BuildTools (BootstrapperBase, Fetch):
31

32
33
    BUILD_TOOLS = ['automake', 'autoconf', 'm4', 'gettext-tools', 'libtool',
                   'pkg-config', 'orc-tool', 'gettext-m4', 'meson']
34
    PLAT_BUILD_TOOLS = {
35
        Platform.DARWIN: ['intltool', 'yasm', 'bison', 'flex'],
36
        Platform.WINDOWS: ['intltool', 'yasm'],
37
        Platform.LINUX: ['intltool-m4'],
38
    }
39

40
41
    def __init__(self, config, offline):
        BootstrapperBase.__init__(self, config, offline)
42
43
44

        # if cross-compiling or not on linux, make sure we have gtk-doc
        if self.config.target_platform != Platform.LINUX or\
45
           self.config.cross_compiling():
46
47
            self.BUILD_TOOLS.append('gtk-doc-lite')

48
49
50
51
52
        if self.config.platform == Platform.WINDOWS:
            self.BUILD_TOOLS.remove('m4')
            self.BUILD_TOOLS.append('gperf')
        if self.config.platform == Platform.DARWIN:
            self.BUILD_TOOLS.append('gperf')
53
            self.BUILD_TOOLS.append('cmake')
54
            self.BUILD_TOOLS.insert(0, 'xz')
55
        if self.config.platform == Platform.LINUX:
56
            if self.config.distro_version == DistroVersion.UBUNTU_LUCID or \
57
58
59
                self.config.distro_version == DistroVersion.DEBIAN_SQUEEZE or \
                self.config.distro_version == DistroVersion.DEBIAN_WHEEZY:
                # x264 requires yasm >= 1.2
60
                self.BUILD_TOOLS.append('yasm')
61
62
            if self.config.distro_version in [DistroVersion.REDHAT_6,
                                              DistroVersion.AMAZON_LINUX]:
63
                self.BUILD_TOOLS.append('cmake')
64
65
        if self.config.target_platform == Platform.IOS:
            self.BUILD_TOOLS.append('gas-preprocessor')
66
67
68
        if self.config.distro_version in [DistroVersion.UBUNTU_LUCID,
                                          DistroVersion.UBUNTU_NATTY]:
            self.BUILD_TOOLS.append('glib-tools')
69
        if self.config.target_platform != Platform.LINUX and not \
70
           self.config.prefix_is_executable():
71
72
            # For glib-mkenums and glib-genmarshal
            self.BUILD_TOOLS.append('glib-tools')
73
        self.BUILD_TOOLS += self.config.extra_build_tools
74

75
76
77
        # Use a common prefix for the build tools for all the configurations
        # so that it can be reused
        config = Config()
78
79
        os.environ.clear()
        os.environ.update(self.config._pre_environ)
80
        config.prefix = self.config.build_tools_prefix
81
        config.home_dir = self.config.home_dir
82
        config.load()
83

84
        config.prefix = self.config.build_tools_prefix
85
        config.build_tools_prefix = self.config.build_tools_prefix
86
        config.sources = self.config.build_tools_sources
87
        config.build_tools_sources = self.config.build_tools_sources
88
        config.cache_file = self.config.build_tools_cache
89
        config.build_tools_cache = self.config.build_tools_cache
90
        config.external_recipes = self.config.external_recipes
91

92
93
        if not os.path.exists(config.toolchain_prefix):
            os.makedirs(config.toolchain_prefix)
94
95
96
97
98
99
        if not os.path.exists(config.prefix):
            os.makedirs(config.prefix)
        if not os.path.exists(config.sources):
            os.makedirs(config.sources)

        config.do_setup_env()
100
101
102
103
104
105
        self.cookbook = CookBook(config, offline=self.offline)
        self.recipes = self.BUILD_TOOLS
        self.recipes += self.PLAT_BUILD_TOOLS.get(self.config.platform, [])

    def start(self):
        oven = Oven(self.recipes, self.cookbook)
106
107
        oven.start_cooking()
        self.config.do_setup_env()
108
109
110

    def fetch_recipes(self):
        Fetch.fetch(self.cookbook, self.recipes, False, False, False, False)