2014-02-18 08:33:06 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2014-06-21 11:04:03 +02:00
|
|
|
import os, os.path
|
2015-11-21 00:17:00 +01:00
|
|
|
import sys, subprocess
|
2014-02-18 08:33:06 +01:00
|
|
|
|
|
|
|
if len(sys.argv) < 3:
|
|
|
|
print("Usage: build.py SDK_PATH NDK_PATH [configure_args...]", file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
sdk_path = sys.argv[1]
|
|
|
|
ndk_path = sys.argv[2]
|
|
|
|
configure_args = sys.argv[3:]
|
|
|
|
|
|
|
|
if not os.path.isfile(os.path.join(sdk_path, 'tools', 'android')):
|
|
|
|
print("SDK not found in", ndk_path, file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if not os.path.isdir(ndk_path):
|
|
|
|
print("NDK not found in", ndk_path, file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2014-12-17 16:47:25 +01:00
|
|
|
# select the NDK target
|
2015-11-20 20:30:42 +01:00
|
|
|
arch = 'arm-linux-androideabi'
|
2014-12-17 16:47:25 +01:00
|
|
|
|
2014-02-18 08:33:06 +01:00
|
|
|
# the path to the MPD sources
|
2015-01-22 18:51:53 +01:00
|
|
|
mpd_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]) or '.', '..'))
|
2015-11-20 22:10:22 +01:00
|
|
|
sys.path[0] = os.path.join(mpd_path, 'python')
|
2014-02-18 08:33:06 +01:00
|
|
|
|
|
|
|
# output directories
|
2015-11-23 10:38:48 +01:00
|
|
|
from build.dirs import lib_path, tarball_path, src_path
|
2015-06-03 07:48:38 +02:00
|
|
|
|
2015-11-20 20:30:42 +01:00
|
|
|
arch_path = os.path.join(lib_path, arch)
|
2014-12-17 16:47:25 +01:00
|
|
|
build_path = os.path.join(arch_path, 'build')
|
2014-02-18 08:33:06 +01:00
|
|
|
|
|
|
|
# build host configuration
|
|
|
|
build_arch = 'linux-x86_64'
|
|
|
|
|
|
|
|
# set up the NDK toolchain
|
|
|
|
|
2015-11-20 20:30:42 +01:00
|
|
|
class AndroidNdkToolchain:
|
2015-11-20 23:47:52 +01:00
|
|
|
def __init__(self, tarball_path, src_path, build_path,
|
2016-10-26 11:55:38 +02:00
|
|
|
use_cxx):
|
2015-11-20 23:47:52 +01:00
|
|
|
self.tarball_path = tarball_path
|
|
|
|
self.src_path = src_path
|
|
|
|
self.build_path = build_path
|
|
|
|
|
2015-11-20 20:30:42 +01:00
|
|
|
self.ndk_arch = 'arm'
|
|
|
|
android_abi = 'armeabi-v7a'
|
2017-12-12 09:43:48 +01:00
|
|
|
ndk_platform = 'android-21'
|
2015-11-20 20:30:42 +01:00
|
|
|
|
|
|
|
# select the NDK compiler
|
|
|
|
gcc_version = '4.9'
|
|
|
|
|
|
|
|
ndk_platform_path = os.path.join(ndk_path, 'platforms', ndk_platform)
|
2017-12-12 09:43:48 +01:00
|
|
|
sysroot = os.path.join(ndk_path, 'sysroot')
|
|
|
|
target_root = os.path.join(ndk_platform_path, 'arch-' + self.ndk_arch)
|
2015-11-20 20:30:42 +01:00
|
|
|
|
|
|
|
install_prefix = os.path.join(arch_path, 'root')
|
|
|
|
|
|
|
|
self.arch = arch
|
|
|
|
self.install_prefix = install_prefix
|
|
|
|
self.sysroot = sysroot
|
|
|
|
|
|
|
|
toolchain_path = os.path.join(ndk_path, 'toolchains', arch + '-' + gcc_version, 'prebuilt', build_arch)
|
2016-10-26 11:12:32 +02:00
|
|
|
llvm_path = os.path.join(ndk_path, 'toolchains', 'llvm', 'prebuilt', build_arch)
|
2015-11-20 20:30:42 +01:00
|
|
|
llvm_triple = 'armv7-none-linux-androideabi'
|
|
|
|
|
2018-01-19 11:18:45 +01:00
|
|
|
common_flags = '-Os -g'
|
2018-01-19 12:55:57 +01:00
|
|
|
common_flags += ' -fPIC'
|
2018-01-19 11:18:45 +01:00
|
|
|
common_flags += ' -march=armv7-a -mfloat-abi=softfp'
|
2015-11-20 20:30:42 +01:00
|
|
|
|
|
|
|
toolchain_bin = os.path.join(toolchain_path, 'bin')
|
2016-10-26 11:55:38 +02:00
|
|
|
llvm_bin = os.path.join(llvm_path, 'bin')
|
|
|
|
self.cc = os.path.join(llvm_bin, 'clang')
|
|
|
|
self.cxx = os.path.join(llvm_bin, 'clang++')
|
|
|
|
common_flags += ' -target ' + llvm_triple + ' -integrated-as -gcc-toolchain ' + toolchain_path
|
2015-11-20 20:30:42 +01:00
|
|
|
|
2018-01-04 23:33:07 +01:00
|
|
|
common_flags += ' -fvisibility=hidden -fdata-sections -ffunction-sections'
|
|
|
|
|
2015-11-20 20:30:42 +01:00
|
|
|
self.ar = os.path.join(toolchain_bin, arch + '-ar')
|
2016-10-26 10:40:19 +02:00
|
|
|
self.ranlib = os.path.join(toolchain_bin, arch + '-ranlib')
|
2015-11-20 20:30:42 +01:00
|
|
|
self.nm = os.path.join(toolchain_bin, arch + '-nm')
|
|
|
|
self.strip = os.path.join(toolchain_bin, arch + '-strip')
|
|
|
|
|
2018-01-19 11:18:45 +01:00
|
|
|
self.cflags = common_flags
|
|
|
|
self.cxxflags = common_flags
|
2017-12-12 09:43:48 +01:00
|
|
|
self.cppflags = '--sysroot=' + sysroot + \
|
|
|
|
' -isystem ' + os.path.join(install_prefix, 'include') + \
|
|
|
|
' -isystem ' + os.path.join(sysroot, 'usr', 'include', arch) + \
|
|
|
|
' -D__ANDROID_API__=21'
|
|
|
|
self.ldflags = '--sysroot=' + sysroot + \
|
|
|
|
' -L' + os.path.join(install_prefix, 'lib') + \
|
|
|
|
' -L' + os.path.join(target_root, 'usr', 'lib') + \
|
|
|
|
' -B' + os.path.join(target_root, 'usr', 'lib') + \
|
|
|
|
' ' + common_flags
|
2015-11-20 20:30:42 +01:00
|
|
|
self.libs = ''
|
|
|
|
|
2015-11-21 00:35:52 +01:00
|
|
|
self.is_arm = self.ndk_arch == 'arm'
|
|
|
|
self.is_armv7 = self.is_arm and 'armv7' in self.cflags
|
|
|
|
self.is_windows = False
|
|
|
|
|
2017-03-01 17:17:49 +01:00
|
|
|
libcxx_path = os.path.join(ndk_path, 'sources/cxx-stl/llvm-libc++')
|
|
|
|
libcxx_libs_path = os.path.join(libcxx_path, 'libs', android_abi)
|
|
|
|
|
2018-01-19 22:36:03 +01:00
|
|
|
libstdcxx_flags = '-stdlib=libc++'
|
|
|
|
libstdcxx_cxxflags = libstdcxx_flags + ' -isystem ' + os.path.join(libcxx_path, 'include') + ' -isystem ' + os.path.join(ndk_path, 'sources/android/support/include')
|
|
|
|
libstdcxx_ldflags = libstdcxx_flags + ' -static-libstdc++ -L' + libcxx_libs_path
|
2015-11-20 20:30:42 +01:00
|
|
|
|
|
|
|
if use_cxx:
|
2018-01-19 22:36:03 +01:00
|
|
|
self.cxxflags += ' ' + libstdcxx_cxxflags
|
|
|
|
self.ldflags += ' ' + libstdcxx_ldflags
|
2015-11-20 20:30:42 +01:00
|
|
|
|
|
|
|
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')
|
2014-02-18 08:33:06 +01:00
|
|
|
|
|
|
|
# a list of third-party libraries to be used by MPD on Android
|
2015-11-23 10:43:06 +01:00
|
|
|
from build.libs import *
|
2014-02-18 08:33:06 +01:00
|
|
|
thirdparty_libs = [
|
2015-11-23 10:43:06 +01:00
|
|
|
libogg,
|
|
|
|
libvorbis,
|
|
|
|
opus,
|
|
|
|
flac,
|
|
|
|
libid3tag,
|
|
|
|
libmad,
|
|
|
|
ffmpeg,
|
|
|
|
curl,
|
|
|
|
boost,
|
2014-02-18 08:33:06 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
# build the third-party libraries
|
|
|
|
for x in thirdparty_libs:
|
2015-11-20 23:47:52 +01:00
|
|
|
toolchain = AndroidNdkToolchain(tarball_path, src_path, build_path,
|
2016-10-26 11:55:38 +02:00
|
|
|
use_cxx=x.use_cxx)
|
2015-11-20 20:30:42 +01:00
|
|
|
if not x.is_installed(toolchain):
|
|
|
|
x.build(toolchain)
|
2014-02-18 08:33:06 +01:00
|
|
|
|
|
|
|
# configure and build MPD
|
2015-11-20 23:47:52 +01:00
|
|
|
toolchain = AndroidNdkToolchain(tarball_path, src_path, build_path,
|
2016-10-26 11:55:38 +02:00
|
|
|
use_cxx=True)
|
2014-02-18 08:33:06 +01:00
|
|
|
|
|
|
|
configure = [
|
|
|
|
os.path.join(mpd_path, 'configure'),
|
2015-11-20 20:30:42 +01:00
|
|
|
'CC=' + toolchain.cc,
|
|
|
|
'CXX=' + toolchain.cxx,
|
|
|
|
'CFLAGS=' + toolchain.cflags,
|
|
|
|
'CXXFLAGS=' + toolchain.cxxflags,
|
|
|
|
'CPPFLAGS=' + toolchain.cppflags,
|
|
|
|
'LDFLAGS=' + toolchain.ldflags,
|
|
|
|
'LIBS=' + toolchain.libs,
|
|
|
|
'AR=' + toolchain.ar,
|
2016-10-26 10:40:19 +02:00
|
|
|
'RANLIB=' + toolchain.ranlib,
|
2015-11-20 20:30:42 +01:00
|
|
|
'STRIP=' + toolchain.strip,
|
|
|
|
'--host=' + toolchain.arch,
|
|
|
|
'--prefix=' + toolchain.install_prefix,
|
|
|
|
'--with-sysroot=' + toolchain.sysroot,
|
2014-02-18 08:33:06 +01:00
|
|
|
'--with-android-sdk=' + sdk_path,
|
|
|
|
|
|
|
|
'--enable-silent-rules',
|
|
|
|
|
2014-02-23 19:27:08 +01:00
|
|
|
'--disable-icu',
|
2014-02-18 08:33:06 +01:00
|
|
|
|
|
|
|
] + configure_args
|
|
|
|
|
2017-07-19 20:47:17 +02:00
|
|
|
from build.cmdline import concatenate_cmdline_variables
|
|
|
|
configure = concatenate_cmdline_variables(configure,
|
|
|
|
set(('CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'LIBS')))
|
|
|
|
|
2015-11-20 20:30:42 +01:00
|
|
|
subprocess.check_call(configure, env=toolchain.env)
|
|
|
|
subprocess.check_call(['/usr/bin/make', '--quiet', '-j12'], env=toolchain.env)
|