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
|
|
|
|
2018-03-04 20:43:59 +01:00
|
|
|
if len(sys.argv) < 4:
|
|
|
|
print("Usage: build.py SDK_PATH NDK_PATH ABI [configure_args...]", file=sys.stderr)
|
2014-02-18 08:33:06 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
sdk_path = sys.argv[1]
|
|
|
|
ndk_path = sys.argv[2]
|
2018-03-04 20:43:59 +01:00
|
|
|
android_abi = sys.argv[3]
|
|
|
|
configure_args = sys.argv[4:]
|
2014-02-18 08:33:06 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2018-03-04 20:43:59 +01:00
|
|
|
android_abis = {
|
|
|
|
'armeabi-v7a': {
|
|
|
|
'arch': 'arm-linux-androideabi',
|
|
|
|
'ndk_arch': 'arm',
|
2018-03-04 20:46:46 +01:00
|
|
|
'toolchain_arch': 'arm-linux-androideabi',
|
2020-01-12 11:51:20 +01:00
|
|
|
'llvm_triple': 'armv7-linux-androideabi',
|
2020-05-07 13:57:34 +02:00
|
|
|
'cflags': '-fpic -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp',
|
2018-03-04 20:43:59 +01:00
|
|
|
},
|
2018-03-04 20:46:46 +01:00
|
|
|
|
2018-08-17 17:53:46 +02:00
|
|
|
'arm64-v8a': {
|
|
|
|
'arch': 'aarch64-linux-android',
|
|
|
|
'ndk_arch': 'arm64',
|
|
|
|
'toolchain_arch': 'aarch64-linux-android',
|
2020-01-12 11:51:20 +01:00
|
|
|
'llvm_triple': 'aarch64-linux-android',
|
2020-05-07 13:57:34 +02:00
|
|
|
'cflags': '-fpic',
|
2018-08-17 17:53:46 +02:00
|
|
|
},
|
|
|
|
|
2018-03-04 20:46:46 +01:00
|
|
|
'x86': {
|
|
|
|
'arch': 'i686-linux-android',
|
|
|
|
'ndk_arch': 'x86',
|
|
|
|
'toolchain_arch': 'x86',
|
2020-01-12 11:51:20 +01:00
|
|
|
'llvm_triple': 'i686-linux-android',
|
2020-05-07 13:57:34 +02:00
|
|
|
'cflags': '-fPIC -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32',
|
2018-03-04 20:46:46 +01:00
|
|
|
},
|
2020-01-12 13:02:07 +01:00
|
|
|
|
|
|
|
'x86_64': {
|
|
|
|
'arch': 'x86_64-linux-android',
|
|
|
|
'ndk_arch': 'x86_64',
|
|
|
|
'toolchain_arch': 'x86_64',
|
|
|
|
'llvm_triple': 'x86_64-linux-android',
|
2020-05-07 13:57:34 +02:00
|
|
|
'cflags': '-fPIC -m64',
|
2020-01-12 13:02:07 +01:00
|
|
|
},
|
2018-03-04 20:43:59 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 16:47:25 +01:00
|
|
|
# select the NDK target
|
2018-03-04 20:43:59 +01:00
|
|
|
abi_info = android_abis[android_abi]
|
|
|
|
arch = abi_info['arch']
|
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
|
2017-12-29 17:12:55 +01:00
|
|
|
from build.meson import configure as run_meson
|
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
|
|
|
|
|
2018-03-04 20:43:59 +01:00
|
|
|
ndk_arch = abi_info['ndk_arch']
|
2018-08-17 18:44:05 +02:00
|
|
|
android_api_level = '21'
|
2015-11-20 20:30:42 +01:00
|
|
|
|
|
|
|
# select the NDK compiler
|
|
|
|
gcc_version = '4.9'
|
|
|
|
|
|
|
|
install_prefix = os.path.join(arch_path, 'root')
|
|
|
|
|
|
|
|
self.arch = arch
|
|
|
|
self.install_prefix = install_prefix
|
2021-08-06 17:30:45 +02:00
|
|
|
self.toolchain_arch = abi_info['toolchain_arch']
|
2015-11-20 20:30:42 +01:00
|
|
|
|
2021-08-06 17:30:45 +02:00
|
|
|
toolchain_path = os.path.join(ndk_path, 'toolchains', self.toolchain_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)
|
2020-01-12 12:02:12 +01:00
|
|
|
llvm_triple = abi_info['llvm_triple'] + android_api_level
|
2015-11-20 20:30:42 +01:00
|
|
|
|
2018-01-19 11:18:45 +01:00
|
|
|
common_flags = '-Os -g'
|
2018-03-04 20:43:59 +01:00
|
|
|
common_flags += ' ' + abi_info['cflags']
|
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++')
|
2021-01-19 20:11:41 +01:00
|
|
|
common_flags += ' -target ' + llvm_triple + ' -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'
|
|
|
|
|
2020-01-12 12:41:37 +01:00
|
|
|
# required flags from https://android.googlesource.com/platform/ndk/+/ndk-release-r20/docs/BuildSystemMaintainers.md#additional-required-arguments
|
|
|
|
common_flags += ' -fno-addrsig'
|
|
|
|
|
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
|
2020-01-12 12:07:55 +01:00
|
|
|
self.cppflags = ' -isystem ' + os.path.join(install_prefix, 'include')
|
|
|
|
self.ldflags = ' -L' + os.path.join(install_prefix, 'lib') + \
|
2020-01-12 12:47:31 +01:00
|
|
|
' -Wl,--exclude-libs=ALL' + \
|
2017-12-12 09:43:48 +01:00
|
|
|
' ' + common_flags
|
2020-01-12 12:07:55 +01:00
|
|
|
self.ldflags = common_flags
|
2015-11-20 20:30:42 +01:00
|
|
|
self.libs = ''
|
|
|
|
|
2018-03-04 20:32:50 +01:00
|
|
|
self.is_arm = ndk_arch == 'arm'
|
2015-11-21 00:35:52 +01:00
|
|
|
self.is_armv7 = self.is_arm and 'armv7' in self.cflags
|
2018-08-17 17:53:46 +02:00
|
|
|
self.is_aarch64 = ndk_arch == 'arm64'
|
2015-11-21 00:35:52 +01:00
|
|
|
self.is_windows = False
|
|
|
|
|
2018-10-23 19:32:25 +02:00
|
|
|
libstdcxx_flags = ''
|
2020-01-12 12:07:55 +01:00
|
|
|
libstdcxx_cxxflags = ''
|
|
|
|
libstdcxx_ldflags = ''
|
|
|
|
libstdcxx_libs = '-static-libstdc++'
|
2015-11-20 20:30:42 +01:00
|
|
|
|
2019-05-03 20:15:30 +02:00
|
|
|
if self.is_armv7:
|
|
|
|
# On 32 bit ARM, clang generates no ".eh_frame" section;
|
|
|
|
# instead, the LLVM unwinder library is used for unwinding
|
|
|
|
# the stack after a C++ exception was thrown
|
|
|
|
libstdcxx_libs += ' -lunwind'
|
|
|
|
|
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
|
2018-10-23 19:32:25 +02:00
|
|
|
self.libs += ' ' + libstdcxx_libs
|
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
|
2017-12-29 17:12:55 +01:00
|
|
|
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
|
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 = [
|
2018-02-24 22:59:33 +01:00
|
|
|
libmpdclient,
|
2015-11-23 10:43:06 +01:00
|
|
|
libogg,
|
|
|
|
libvorbis,
|
|
|
|
opus,
|
|
|
|
flac,
|
|
|
|
libid3tag,
|
2020-05-26 21:08:29 +02:00
|
|
|
libmodplug,
|
|
|
|
wildmidi,
|
2020-06-10 20:58:31 +02:00
|
|
|
gme,
|
2015-11-23 10:43:06 +01:00
|
|
|
ffmpeg,
|
2021-01-21 14:13:59 +01:00
|
|
|
openssl,
|
2015-11-23 10:43:06 +01:00
|
|
|
curl,
|
2018-08-17 17:15:05 +02:00
|
|
|
libexpat,
|
2018-02-20 22:45:15 +01:00
|
|
|
libnfs,
|
2015-11-23 10:43:06 +01:00
|
|
|
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
|
|
|
|
2017-12-29 17:12:55 +01:00
|
|
|
configure_args += [
|
|
|
|
'-Dandroid_sdk=' + sdk_path,
|
|
|
|
'-Dandroid_ndk=' + ndk_path,
|
|
|
|
'-Dandroid_abi=' + android_abi,
|
|
|
|
'-Dandroid_strip=' + toolchain.strip,
|
|
|
|
]
|
|
|
|
|
|
|
|
from build.meson import configure as run_meson
|
|
|
|
run_meson(toolchain, mpd_path, '.', configure_args)
|
|
|
|
subprocess.check_call(['/usr/bin/ninja'], env=toolchain.env)
|