build.py 3.65 KB
Newer Older
1 2 3
#!/usr/bin/env python3

import os, os.path
4
import sys, subprocess
5 6 7

configure_args = sys.argv[1:]

8
x64 = True
9

10 11 12 13
while len(configure_args) > 0:
    arg = configure_args[0]
    if arg == '--64':
        x64 = True
14 15
    elif arg == '--32':
        x64 = False
16 17 18
    else:
        break
    configure_args.pop(0)
19 20

if x64:
21
    host_arch = 'x86_64-w64-mingw32'
22 23
else:
    host_arch = 'i686-w64-mingw32'
24

25
# the path to the MPD sources
26
mpd_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]) or '.', '..'))
27
sys.path[0] = os.path.join(mpd_path, 'python')
28 29

# output directories
30
from build.dirs import lib_path, tarball_path, src_path
31

32 33 34
arch_path = os.path.join(lib_path, host_arch)
build_path = os.path.join(arch_path, 'build')
root_path = os.path.join(arch_path, 'root')
35

36
class CrossGccToolchain:
37 38
    def __init__(self, toolchain_path, arch,
                 tarball_path, src_path, build_path, install_prefix):
39
        self.arch = arch
40 41 42
        self.tarball_path = tarball_path
        self.src_path = src_path
        self.build_path = build_path
43 44 45 46 47 48
        self.install_prefix = install_prefix

        toolchain_bin = os.path.join(toolchain_path, 'bin')
        self.cc = os.path.join(toolchain_bin, arch + '-gcc')
        self.cxx = os.path.join(toolchain_bin, arch + '-g++')
        self.ar = os.path.join(toolchain_bin, arch + '-ar')
49
        self.ranlib = os.path.join(toolchain_bin, arch + '-ranlib')
50 51 52
        self.nm = os.path.join(toolchain_bin, arch + '-nm')
        self.strip = os.path.join(toolchain_bin, arch + '-strip')

53
        common_flags = '-O2 -g'
54 55 56 57 58

        if not x64:
            # enable SSE support which is required for LAME
            common_flags += ' -march=pentium3'

59 60
        self.cflags = common_flags
        self.cxxflags = common_flags
61 62
        self.cppflags = '-isystem ' + os.path.join(install_prefix, 'include') + \
                        ' -DWINVER=0x0600 -D_WIN32_WINNT=0x0600'
63
        self.ldflags = '-L' + os.path.join(install_prefix, 'lib')
64 65
        self.libs = ''

66 67 68 69
        self.is_arm = arch.startswith('arm')
        self.is_armv7 = self.is_arm and 'armv7' in self.cflags
        self.is_windows = 'mingw32' in arch

70 71 72 73 74
        self.env = dict(os.environ)

        # redirect pkg-config to use our root directory instead of the
        # default one on the build host
        self.env['PKG_CONFIG_LIBDIR'] = os.path.join(install_prefix, 'lib/pkgconfig')
75 76

# a list of third-party libraries to be used by MPD on Android
77
from build.libs import *
78
thirdparty_libs = [
79 80 81 82 83 84
    libogg,
    libvorbis,
    opus,
    flac,
    zlib,
    libid3tag,
85
    liblame,
86 87 88
    ffmpeg,
    curl,
    boost,
89 90 91
]

# build the third-party libraries
92 93
toolchain = CrossGccToolchain('/usr', host_arch,
                              tarball_path, src_path, build_path, root_path)
94

95
for x in thirdparty_libs:
96 97
    if not x.is_installed(toolchain):
        x.build(toolchain)
98 99 100 101 102

# configure and build MPD

configure = [
    os.path.join(mpd_path, 'configure'),
103 104 105 106 107 108 109 110
    'CC=' + toolchain.cc,
    'CXX=' + toolchain.cxx,
    'CFLAGS=' + toolchain.cflags,
    'CXXFLAGS=' + toolchain.cxxflags,
    'CPPFLAGS=' + toolchain.cppflags,
    'LDFLAGS=' + toolchain.ldflags + ' -static',
    'LIBS=' + toolchain.libs,
    'AR=' + toolchain.ar,
111
    'RANLIB=' + toolchain.ranlib,
112 113 114
    'STRIP=' + toolchain.strip,
    '--host=' + toolchain.arch,
    '--prefix=' + toolchain.install_prefix,
115 116 117 118 119 120 121

    '--enable-silent-rules',

    '--disable-icu',

] + configure_args

122 123 124 125
from build.cmdline import concatenate_cmdline_variables
configure = concatenate_cmdline_variables(configure,
    set(('CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'LIBS')))

126 127
subprocess.check_call(configure, env=toolchain.env)
subprocess.check_call(['/usr/bin/make', '--quiet', '-j12'], env=toolchain.env)