diff --git a/pythonforandroid/recipes/openssl/__init__.py b/pythonforandroid/recipes/openssl/__init__.py index b8256e8662..0da5c69f6c 100644 --- a/pythonforandroid/recipes/openssl/__init__.py +++ b/pythonforandroid/recipes/openssl/__init__.py @@ -1,3 +1,5 @@ +import time +from os.path import join from functools import partial from pythonforandroid.toolchain import Recipe, shprint, current_directory @@ -5,8 +7,58 @@ class OpenSSLRecipe(Recipe): - version = '1.0.2h' - url = 'https://www.openssl.org/source/openssl-{version}.tar.gz' + ''' + The OpenSSL libraries for python-for-android. This recipe will generate the + following libraries as shared libraries (*.so): + + - crypto + - ssl + + The generated openssl libraries are versioned, where the version is the + recipe attribute :attr:`version` e.g.: ``libcrypto1.1.so``, + ``libssl1.1.so``...so...to link your recipe with the openssl libs, + remember to add the version at the end, e.g.: + ``-lcrypto1.1 -lssl1.1``. Or better, you could do it dynamically + using the methods: :meth:`include_flags` and :meth:`link_flags`. + + .. versionchanged:: 0.6.0 + + - The gcc compiler has been deprecated in favour of clang and libraries + updated to version 1.1.1 (LTS - supported until 11th September 2023) + - Added two new methods to make easier to link with openssl: + :meth:`include_flags` and :meth:`link_flags` + - subclassed versioned_url + - Adapted method :meth:`select_build_arch` to API 21+ + + ''' + + version = '1.1' + '''the major minor version used to link our recipes''' + + url_version = '1.1.1' + '''the version used to download our libraries''' + + url = 'https://www.openssl.org/source/openssl-{url_version}.tar.gz' + + @property + def versioned_url(self): + if self.url is None: + return None + return self.url.format(url_version=self.url_version) + + def include_flags(self, arch): + '''Returns a string with the include folders''' + openssl_includes = join(self.get_build_dir(arch.arch), 'include') + return ' -I' + openssl_includes + \ + ' -I' + join(openssl_includes, 'internal') + \ + ' -I' + join(openssl_includes, 'openssl') + + def link_flags(self, arch): + '''Returns a string with the right link flags to compile against the + openssl libraries''' + build_dir = self.get_build_dir(arch.arch) + return ' -L' + build_dir + \ + ' -lcrypto{version} -lssl{version}'.format(version=self.version) def should_build(self, arch): return not self.has_libs(arch, 'libssl' + self.version + '.so', @@ -21,12 +73,12 @@ def check_symbol(self, env, sofile, symbol): print('{} missing symbol {}; rebuilding'.format(sofile, symbol)) return False - def get_recipe_env(self, arch=None): - env = super(OpenSSLRecipe, self).get_recipe_env(arch) + def get_recipe_env(self, arch=None, with_flags_in_cc=True, clang=True): + env = super(OpenSSLRecipe, self).get_recipe_env( + arch, with_flags_in_cc=True, clang=True) env['OPENSSL_VERSION'] = self.version - env['CFLAGS'] += ' ' + env['LDFLAGS'] - env['CC'] += ' ' + env['LDFLAGS'] env['MAKE'] = 'make' # This removes the '-j5', which isn't safe + env['ANDROID_NDK'] = self.ctx.ndk_dir return env def select_build_arch(self, arch): @@ -34,7 +86,7 @@ def select_build_arch(self, arch): if 'arm64' in aname: return 'linux-aarch64' if 'v7a' in aname: - return 'android-armv7' + return 'android-arm' if 'arm' in aname: return 'android' if 'x86' in aname: @@ -48,16 +100,17 @@ def build_arch(self, arch): # so instead we manually run perl passing in Configure perl = sh.Command('perl') buildarch = self.select_build_arch(arch) - shprint(perl, 'Configure', 'shared', 'no-dso', 'no-krb5', buildarch, _env=env) + shprint(perl, 'Configure', 'shared', 'no-dso', 'no-asm', buildarch, + '-D__ANDROID_API__={}'.format(self.ctx.ndk_api), + _env=env) self.apply_patch('disable-sover.patch', arch.arch) - self.apply_patch('rename-shared-lib.patch', arch.arch) - # check_ssl = partial(self.check_symbol, env, 'libssl' + self.version + '.so') check_crypto = partial(self.check_symbol, env, 'libcrypto' + self.version + '.so') while True: shprint(sh.make, 'build_libs', _env=env) - if all(map(check_crypto, ('SSLeay', 'MD5_Transform', 'MD4_Init'))): + if all(map(check_crypto, ('MD5_Transform', 'MD4_Init'))): break + time.sleep(3) shprint(sh.make, 'clean', _env=env) self.install_libs(arch, 'libssl' + self.version + '.so', diff --git a/pythonforandroid/recipes/openssl/disable-sover.patch b/pythonforandroid/recipes/openssl/disable-sover.patch index 6099fadcef..83a93ceea0 100644 --- a/pythonforandroid/recipes/openssl/disable-sover.patch +++ b/pythonforandroid/recipes/openssl/disable-sover.patch @@ -1,20 +1,11 @@ ---- openssl/Makefile 2016-01-28 17:26:49.159522273 +0100 -+++ b/Makefile 2016-01-28 17:26:54.358438402 +0100 -@@ -342,7 +342,7 @@ - link-shared: - @ set -e; for i in $(SHLIBDIRS); do \ - $(MAKE) -f $(HERE)/Makefile.shared -e $(BUILDENV) \ -- LIBNAME=$$i LIBVERSION=$(SHLIB_MAJOR).$(SHLIB_MINOR) \ -+ LIBNAME=$$i LIBVERSION= \ - LIBCOMPATVERSIONS=";$(SHLIB_VERSION_HISTORY)" \ - symlink.$(SHLIB_TARGET); \ - libs="$$libs -l$$i"; \ -@@ -356,7 +356,7 @@ - libs="$(LIBKRB5) $$libs"; \ - fi; \ - $(CLEARENV) && $(MAKE) -f Makefile.shared -e $(BUILDENV) \ -- LIBNAME=$$i LIBVERSION=$(SHLIB_MAJOR).$(SHLIB_MINOR) \ -+ LIBNAME=$$i LIBVERSION= \ - LIBCOMPATVERSIONS=";$(SHLIB_VERSION_HISTORY)" \ - LIBDEPS="$$libs $(EX_LIBS)" \ - link_a.$(SHLIB_TARGET); \ +--- openssl/Makefile.orig 2018-10-20 22:49:40.418310423 +0200 ++++ openssl/Makefile 2018-10-20 22:50:23.347322403 +0200 +@@ -19,7 +19,7 @@ + SHLIB_MAJOR=1 + SHLIB_MINOR=1 + SHLIB_TARGET=linux-shared +-SHLIB_EXT=.so.$(SHLIB_VERSION_NUMBER) ++SHLIB_EXT=$(SHLIB_VERSION_NUMBER).so + SHLIB_EXT_SIMPLE=.so + SHLIB_EXT_IMPORT= +