2017-08-13 03:24:00 +02:00
|
|
|
import sh
|
|
|
|
import os
|
2022-12-02 21:15:34 +01:00
|
|
|
import platform
|
|
|
|
from os.path import join, isdir, exists
|
|
|
|
from multiprocessing import cpu_count
|
|
|
|
from pythonforandroid.recipe import Recipe
|
2019-03-30 21:58:45 +01:00
|
|
|
from pythonforandroid.toolchain import shprint
|
2017-08-13 03:24:00 +02:00
|
|
|
from pythonforandroid.util import current_directory, ensure_dir
|
|
|
|
|
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
class ICURecipe(Recipe):
|
2017-08-13 03:24:00 +02:00
|
|
|
name = 'icu4c'
|
|
|
|
version = '57.1'
|
2022-12-02 21:15:34 +01:00
|
|
|
major_version = version.split('.')[0]
|
|
|
|
url = (
|
|
|
|
"https://github.com/unicode-org/icu/releases/download/"
|
|
|
|
"release-{version_hyphen}/icu4c-{version_underscore}-src.tgz"
|
|
|
|
)
|
|
|
|
|
|
|
|
depends = ['hostpython3'] # installs in python
|
|
|
|
patches = ['disable-libs-version.patch']
|
|
|
|
|
|
|
|
built_libraries = {
|
|
|
|
'libicui18n{}.so'.format(major_version): 'build_icu_android/lib',
|
|
|
|
'libicuuc{}.so'.format(major_version): 'build_icu_android/lib',
|
|
|
|
'libicudata{}.so'.format(major_version): 'build_icu_android/lib',
|
|
|
|
'libicule{}.so'.format(major_version): 'build_icu_android/lib',
|
|
|
|
'libicuio{}.so'.format(major_version): 'build_icu_android/lib',
|
|
|
|
'libicutu{}.so'.format(major_version): 'build_icu_android/lib',
|
|
|
|
'libiculx{}.so'.format(major_version): 'build_icu_android/lib',
|
|
|
|
}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def versioned_url(self):
|
|
|
|
if self.url is None:
|
|
|
|
return None
|
|
|
|
return self.url.format(
|
|
|
|
version=self.version,
|
|
|
|
version_underscore=self.version.replace('.', '_'),
|
|
|
|
version_hyphen=self.version.replace('.', '-'))
|
|
|
|
|
|
|
|
def get_recipe_dir(self):
|
|
|
|
"""
|
|
|
|
.. note:: We need to overwrite `Recipe.get_recipe_dir` due to the
|
|
|
|
mismatch name between the recipe's folder (icu) and the value
|
|
|
|
of `ICURecipe.name` (icu4c).
|
|
|
|
"""
|
|
|
|
if self.ctx.local_recipes is not None:
|
|
|
|
local_recipe_dir = join(self.ctx.local_recipes, 'icu')
|
|
|
|
if exists(local_recipe_dir):
|
|
|
|
return local_recipe_dir
|
|
|
|
return join(self.ctx.root_dir, 'recipes', 'icu')
|
|
|
|
|
|
|
|
def build_arch(self, arch):
|
2017-08-13 03:24:00 +02:00
|
|
|
env = self.get_recipe_env(arch).copy()
|
|
|
|
build_root = self.get_build_dir(arch.arch)
|
|
|
|
|
|
|
|
def make_build_dest(dest):
|
|
|
|
build_dest = join(build_root, dest)
|
|
|
|
if not isdir(build_dest):
|
|
|
|
ensure_dir(build_dest)
|
|
|
|
return build_dest, False
|
|
|
|
|
|
|
|
return build_dest, True
|
|
|
|
|
|
|
|
icu_build = join(build_root, "icu_build")
|
2022-12-02 21:15:34 +01:00
|
|
|
build_host, exists = make_build_dest("build_icu_host")
|
2017-08-13 03:24:00 +02:00
|
|
|
|
|
|
|
host_env = os.environ.copy()
|
|
|
|
# reduce the function set
|
|
|
|
host_env["CPPFLAGS"] = (
|
|
|
|
"-O3 -fno-short-wchar -DU_USING_ICU_NAMESPACE=1 -fno-short-enums "
|
|
|
|
"-DU_HAVE_NL_LANGINFO_CODESET=0 -D__STDC_INT64__ -DU_TIMEZONE=0 "
|
|
|
|
"-DUCONFIG_NO_LEGACY_CONVERSION=1 "
|
|
|
|
"-DUCONFIG_NO_TRANSLITERATION=0 ")
|
|
|
|
|
|
|
|
if not exists:
|
2022-12-02 21:15:34 +01:00
|
|
|
icu4c_host_platform = platform.system()
|
|
|
|
if icu4c_host_platform == "Darwin":
|
|
|
|
icu4c_host_platform = "MacOSX"
|
2017-08-13 03:24:00 +02:00
|
|
|
configure = sh.Command(
|
|
|
|
join(build_root, "source", "runConfigureICU"))
|
2022-12-02 21:15:34 +01:00
|
|
|
with current_directory(build_host):
|
2017-08-13 03:24:00 +02:00
|
|
|
shprint(
|
|
|
|
configure,
|
2022-12-02 21:15:34 +01:00
|
|
|
icu4c_host_platform,
|
2017-08-13 03:24:00 +02:00
|
|
|
"--prefix="+icu_build,
|
|
|
|
"--enable-extras=no",
|
|
|
|
"--enable-strict=no",
|
2022-12-02 21:15:34 +01:00
|
|
|
"--enable-static=no",
|
2017-08-13 03:24:00 +02:00
|
|
|
"--enable-tests=no",
|
|
|
|
"--enable-samples=no",
|
|
|
|
_env=host_env)
|
2022-12-02 21:15:34 +01:00
|
|
|
shprint(sh.make, "-j", str(cpu_count()), _env=host_env)
|
2017-08-13 03:24:00 +02:00
|
|
|
shprint(sh.make, "install", _env=host_env)
|
|
|
|
build_android, exists = make_build_dest("build_icu_android")
|
|
|
|
if not exists:
|
|
|
|
configure = sh.Command(join(build_root, "source", "configure"))
|
|
|
|
|
|
|
|
with current_directory(build_android):
|
|
|
|
shprint(
|
|
|
|
configure,
|
2022-12-02 21:15:34 +01:00
|
|
|
"--with-cross-build="+build_host,
|
2017-08-13 03:24:00 +02:00
|
|
|
"--enable-extras=no",
|
|
|
|
"--enable-strict=no",
|
2022-12-02 21:15:34 +01:00
|
|
|
"--enable-static=no",
|
2017-08-13 03:24:00 +02:00
|
|
|
"--enable-tests=no",
|
|
|
|
"--enable-samples=no",
|
2022-12-02 21:15:34 +01:00
|
|
|
"--host="+arch.command_prefix,
|
2017-08-13 03:24:00 +02:00
|
|
|
"--prefix="+icu_build,
|
|
|
|
_env=env)
|
2022-12-02 21:15:34 +01:00
|
|
|
shprint(sh.make, "-j", str(cpu_count()), _env=env)
|
2017-08-13 03:24:00 +02:00
|
|
|
shprint(sh.make, "install", _env=env)
|
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
def install_libraries(self, arch):
|
|
|
|
super().install_libraries(arch)
|
2017-08-13 03:24:00 +02:00
|
|
|
|
|
|
|
src_include = join(
|
|
|
|
self.get_build_dir(arch.arch), "icu_build", "include")
|
|
|
|
dst_include = join(
|
2022-12-02 21:15:34 +01:00
|
|
|
self.ctx.get_python_install_dir(arch.arch), "include", "icu")
|
2017-08-13 03:24:00 +02:00
|
|
|
ensure_dir(dst_include)
|
|
|
|
shprint(sh.cp, "-r", join(src_include, "layout"), dst_include)
|
|
|
|
shprint(sh.cp, "-r", join(src_include, "unicode"), dst_include)
|
|
|
|
|
|
|
|
|
|
|
|
recipe = ICURecipe()
|