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

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

configure_args = sys.argv[1:]

9
x64 = True
10

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

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

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

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

33 34 35
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')
36

37
class CrossGccToolchain:
38 39
    def __init__(self, toolchain_path, arch,
                 tarball_path, src_path, build_path, install_prefix):
40
        self.arch = arch
41 42 43
        self.tarball_path = tarball_path
        self.src_path = src_path
        self.build_path = build_path
44 45 46 47 48 49
        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')
50
        self.ranlib = os.path.join(toolchain_bin, arch + '-ranlib')
51 52
        self.nm = os.path.join(toolchain_bin, arch + '-nm')
        self.strip = os.path.join(toolchain_bin, arch + '-strip')
53
        self.windres = os.path.join(toolchain_bin, arch + '-windres')
54

55
        common_flags = '-O2 -g'
56 57 58 59 60

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

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

69 70
        self.is_arm = arch.startswith('arm')
        self.is_armv7 = self.is_arm and 'armv7' in self.cflags
71
        self.is_aarch64 = arch == 'aarch64'
72 73
        self.is_windows = 'mingw32' in arch

74 75 76 77
        self.env = dict(os.environ)

        # redirect pkg-config to use our root directory instead of the
        # default one on the build host
78 79 80 81 82 83 84 85 86
        import shutil
        bin_dir = os.path.join(install_prefix, 'bin')
        try:
            os.makedirs(bin_dir)
        except:
            pass
        self.pkg_config = shutil.copy(os.path.join(mpd_path, 'build', 'pkg-config.sh'),
                                      os.path.join(bin_dir, 'pkg-config'))
        self.env['PKG_CONFIG'] = self.pkg_config
87 88

# a list of third-party libraries to be used by MPD on Android
89
from build.libs import *
90
thirdparty_libs = [
91
    libmpdclient,
92 93 94 95 96 97
    libogg,
    libvorbis,
    opus,
    flac,
    zlib,
    libid3tag,
98
    liblame,
99 100
    ffmpeg,
    curl,
101
    libexpat,
102
    libnfs,
103
    boost,
104 105 106
]

# build the third-party libraries
107 108
toolchain = CrossGccToolchain('/usr', host_arch,
                              tarball_path, src_path, build_path, root_path)
109

110
for x in thirdparty_libs:
111 112
    if not x.is_installed(toolchain):
        x.build(toolchain)
113 114 115

# configure and build MPD

116 117 118
from build.meson import configure as run_meson
run_meson(toolchain, mpd_path, '.', configure_args)
subprocess.check_call(['/usr/bin/ninja'], env=toolchain.env)