Commit 2daa3eb6 authored by Max Kellermann's avatar Max Kellermann

{android,win32}/build.py: add toolchain classes

parent 3079aa1f
...@@ -30,27 +30,30 @@ arch_path = os.path.join(lib_path, host_arch) ...@@ -30,27 +30,30 @@ arch_path = os.path.join(lib_path, host_arch)
build_path = os.path.join(arch_path, 'build') build_path = os.path.join(arch_path, 'build')
root_path = os.path.join(arch_path, 'root') root_path = os.path.join(arch_path, 'root')
# redirect pkg-config to use our root directory instead of the default class CrossGccToolchain:
# one on the build host def __init__(self, toolchain_path, arch, install_prefix):
os.environ['PKG_CONFIG_LIBDIR'] = os.path.join(root_path, 'lib/pkgconfig') self.arch = arch
self.install_prefix = install_prefix
gcc_toolchain = '/usr'
toolchain_bin = os.path.join(toolchain_path, 'bin')
def select_toolchain(): self.cc = os.path.join(toolchain_bin, arch + '-gcc')
global cc, cxx, ar, nm, strip, cflags, cxxflags, cppflags, ldflags, libs self.cxx = os.path.join(toolchain_bin, arch + '-g++')
self.ar = os.path.join(toolchain_bin, arch + '-ar')
target_arch = '' self.nm = os.path.join(toolchain_bin, arch + '-nm')
cc = os.path.join(gcc_toolchain, 'bin', host_arch + '-gcc') self.strip = os.path.join(toolchain_bin, arch + '-strip')
cxx = os.path.join(gcc_toolchain, 'bin', host_arch + '-g++')
ar = os.path.join(gcc_toolchain, 'bin', host_arch + '-ar') common_flags = ''
nm = os.path.join(gcc_toolchain, 'bin', host_arch + '-nm') self.cflags = '-O2 -g ' + common_flags
strip = os.path.join(gcc_toolchain, 'bin', host_arch + '-strip') self.cxxflags = '-O2 -g ' + common_flags
self.cppflags = '-isystem ' + os.path.join(install_prefix, 'include')
cflags = '-O2 -g ' + target_arch self.ldflags = '-L' + os.path.join(root_path, 'lib')
cxxflags = '-O2 -g ' + target_arch self.libs = ''
cppflags = '-I' + root_path + '/include'
ldflags = '-L' + root_path + '/lib' self.env = dict(os.environ)
libs = ''
# 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')
def file_md5(path): def file_md5(path):
"""Calculate the MD5 checksum of a file and return it in hexadecimal notation.""" """Calculate the MD5 checksum of a file and return it in hexadecimal notation."""
...@@ -116,10 +119,9 @@ class Project: ...@@ -116,10 +119,9 @@ class Project:
def download(self): def download(self):
return download_tarball(self.url, self.md5) return download_tarball(self.url, self.md5)
def is_installed(self): def is_installed(self, toolchain):
global root_path
tarball = self.download() tarball = self.download()
installed = os.path.join(root_path, self.installed) installed = os.path.join(toolchain.install_prefix, self.installed)
tarball_mtime = os.path.getmtime(tarball) tarball_mtime = os.path.getmtime(tarball)
try: try:
return os.path.getmtime(installed) >= tarball_mtime return os.path.getmtime(installed) >= tarball_mtime
...@@ -161,7 +163,7 @@ class AutotoolsProject(Project): ...@@ -161,7 +163,7 @@ class AutotoolsProject(Project):
self.autogen = autogen self.autogen = autogen
self.cppflags = cppflags self.cppflags = cppflags
def build(self): def build(self, toolchain):
src = self.unpack() src = self.unpack()
if self.autogen: if self.autogen:
subprocess.check_call(['/usr/bin/aclocal'], cwd=src) subprocess.check_call(['/usr/bin/aclocal'], cwd=src)
...@@ -171,46 +173,46 @@ class AutotoolsProject(Project): ...@@ -171,46 +173,46 @@ class AutotoolsProject(Project):
build = self.make_build_path() build = self.make_build_path()
select_toolchain()
configure = [ configure = [
os.path.join(src, 'configure'), os.path.join(src, 'configure'),
'CC=' + cc, 'CC=' + toolchain.cc,
'CXX=' + cxx, 'CXX=' + toolchain.cxx,
'CFLAGS=' + cflags, 'CFLAGS=' + toolchain.cflags,
'CXXFLAGS=' + cxxflags, 'CXXFLAGS=' + toolchain.cxxflags,
'CPPFLAGS=' + cppflags + ' ' + self.cppflags, 'CPPFLAGS=' + toolchain.cppflags + ' ' + self.cppflags,
'LDFLAGS=' + ldflags, 'LDFLAGS=' + toolchain.ldflags,
'LIBS=' + libs, 'LIBS=' + toolchain.libs,
'AR=' + ar, 'AR=' + toolchain.ar,
'STRIP=' + strip, 'STRIP=' + toolchain.strip,
'--host=' + host_arch, '--host=' + toolchain.arch,
'--prefix=' + root_path, '--prefix=' + toolchain.install_prefix,
'--enable-silent-rules', '--enable-silent-rules',
] + self.configure_args ] + self.configure_args
subprocess.check_call(configure, cwd=build) subprocess.check_call(configure, cwd=build, env=toolchain.env)
subprocess.check_call(['/usr/bin/make', '--quiet', '-j12'], cwd=build) subprocess.check_call(['/usr/bin/make', '--quiet', '-j12'],
subprocess.check_call(['/usr/bin/make', '--quiet', 'install'], cwd=build) cwd=build, env=toolchain.env)
subprocess.check_call(['/usr/bin/make', '--quiet', 'install'],
cwd=build, env=toolchain.env)
class ZlibProject(Project): class ZlibProject(Project):
def __init__(self, url, md5, installed, def __init__(self, url, md5, installed,
**kwargs): **kwargs):
Project.__init__(self, url, md5, installed, **kwargs) Project.__init__(self, url, md5, installed, **kwargs)
def build(self): def build(self, toolchain):
src = self.unpack(out_of_tree=False) src = self.unpack(out_of_tree=False)
select_toolchain()
subprocess.check_call(['/usr/bin/make', '--quiet', subprocess.check_call(['/usr/bin/make', '--quiet',
'-f', 'win32/Makefile.gcc', '-f', 'win32/Makefile.gcc',
'PREFIX=' + host_arch + '-', 'PREFIX=' + toolchain.arch + '-',
'-j12', '-j12',
'install', 'install',
'DESTDIR=' + root_path + '/', 'DESTDIR=' + toolchain.install_prefix + '/',
'INCLUDE_PATH=include', 'INCLUDE_PATH=include',
'LIBRARY_PATH=lib', 'LIBRARY_PATH=lib',
'BINARY_PATH=bin', 'SHARED_MODE=1'], 'BINARY_PATH=bin', 'SHARED_MODE=1'],
cwd=src) cwd=src, env=toolchain.env)
class FfmpegProject(Project): class FfmpegProject(Project):
def __init__(self, url, md5, installed, configure_args=[], def __init__(self, url, md5, installed, configure_args=[],
...@@ -220,31 +222,32 @@ class FfmpegProject(Project): ...@@ -220,31 +222,32 @@ class FfmpegProject(Project):
self.configure_args = configure_args self.configure_args = configure_args
self.cppflags = cppflags self.cppflags = cppflags
def build(self): def build(self, toolchain):
src = self.unpack() src = self.unpack()
build = self.make_build_path() build = self.make_build_path()
select_toolchain()
configure = [ configure = [
os.path.join(src, 'configure'), os.path.join(src, 'configure'),
'--cc=' + cc, '--cc=' + toolchain.cc,
'--cxx=' + cxx, '--cxx=' + toolchain.cxx,
'--nm=' + nm, '--nm=' + toolchain.nm,
'--extra-cflags=' + cflags + ' ' + cppflags + ' ' + self.cppflags, '--extra-cflags=' + toolchain.cflags + ' ' + toolchain.cppflags + ' ' + self.cppflags,
'--extra-cxxflags=' + cxxflags + ' ' + cppflags + ' ' + self.cppflags, '--extra-cxxflags=' + toolchain.cxxflags + ' ' + toolchain.cppflags + ' ' + self.cppflags,
'--extra-ldflags=' + ldflags, '--extra-ldflags=' + toolchain.ldflags,
'--extra-libs=' + libs, '--extra-libs=' + toolchain.libs,
'--ar=' + ar, '--ar=' + toolchain.ar,
'--enable-cross-compile', '--enable-cross-compile',
'--arch=x86', '--arch=x86',
'--target-os=mingw32', '--target-os=mingw32',
'--cross-prefix=' + host_arch + '-', '--cross-prefix=' + toolchain.arch + '-',
'--prefix=' + root_path, '--prefix=' + toolchain.install_prefix,
] + self.configure_args ] + self.configure_args
subprocess.check_call(configure, cwd=build) subprocess.check_call(configure, cwd=build, env=toolchain.env)
subprocess.check_call(['/usr/bin/make', '--quiet', '-j12'], cwd=build) subprocess.check_call(['/usr/bin/make', '--quiet', '-j12'],
subprocess.check_call(['/usr/bin/make', '--quiet', 'install'], cwd=build) cwd=build, env=toolchain.env)
subprocess.check_call(['/usr/bin/make', '--quiet', 'install'],
cwd=build, env=toolchain.env)
class BoostProject(Project): class BoostProject(Project):
def __init__(self, url, md5, installed, def __init__(self, url, md5, installed,
...@@ -255,12 +258,12 @@ class BoostProject(Project): ...@@ -255,12 +258,12 @@ class BoostProject(Project):
name='boost', version=version, name='boost', version=version,
**kwargs) **kwargs)
def build(self): def build(self, toolchain):
src = self.unpack() src = self.unpack()
# install the headers manually; don't build any library # install the headers manually; don't build any library
# (because right now, we only use header-only libraries) # (because right now, we only use header-only libraries)
includedir = os.path.join(root_path, 'include') includedir = os.path.join(toolchain.install_prefix, 'include')
for dirpath, dirnames, filenames in os.walk(os.path.join(src, 'boost')): for dirpath, dirnames, filenames in os.walk(os.path.join(src, 'boost')):
relpath = dirpath[len(src)+1:] relpath = dirpath[len(src)+1:]
destdir = os.path.join(includedir, relpath) destdir = os.path.join(includedir, relpath)
...@@ -373,26 +376,27 @@ thirdparty_libs = [ ...@@ -373,26 +376,27 @@ thirdparty_libs = [
] ]
# build the third-party libraries # build the third-party libraries
toolchain = CrossGccToolchain('/usr', host_arch, root_path)
for x in thirdparty_libs: for x in thirdparty_libs:
if not x.is_installed(): if not x.is_installed(toolchain):
x.build() x.build(toolchain)
# configure and build MPD # configure and build MPD
select_toolchain()
configure = [ configure = [
os.path.join(mpd_path, 'configure'), os.path.join(mpd_path, 'configure'),
'CC=' + cc, 'CC=' + toolchain.cc,
'CXX=' + cxx, 'CXX=' + toolchain.cxx,
'CFLAGS=' + cflags, 'CFLAGS=' + toolchain.cflags,
'CXXFLAGS=' + cxxflags, 'CXXFLAGS=' + toolchain.cxxflags,
'CPPFLAGS=' + cppflags, 'CPPFLAGS=' + toolchain.cppflags,
'LDFLAGS=' + ldflags + ' -static', 'LDFLAGS=' + toolchain.ldflags + ' -static',
'LIBS=' + libs, 'LIBS=' + toolchain.libs,
'AR=' + ar, 'AR=' + toolchain.ar,
'STRIP=' + strip, 'STRIP=' + toolchain.strip,
'--host=' + host_arch, '--host=' + toolchain.arch,
'--prefix=' + root_path, '--prefix=' + toolchain.install_prefix,
'--enable-silent-rules', '--enable-silent-rules',
...@@ -400,5 +404,5 @@ configure = [ ...@@ -400,5 +404,5 @@ configure = [
] + configure_args ] + configure_args
subprocess.check_call(configure) subprocess.check_call(configure, env=toolchain.env)
subprocess.check_call(['/usr/bin/make', '--quiet', '-j12']) subprocess.check_call(['/usr/bin/make', '--quiet', '-j12'], env=toolchain.env)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment