2019-03-30 21:58:45 +01:00
|
|
|
from os.path import join
|
2017-08-13 03:24:00 +02:00
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
from pythonforandroid.recipe import Recipe
|
|
|
|
from pythonforandroid.util import current_directory
|
|
|
|
from pythonforandroid.logger import shprint
|
2017-08-13 03:24:00 +02:00
|
|
|
import sh
|
|
|
|
|
|
|
|
|
|
|
|
class OpenSSLRecipe(Recipe):
|
2019-03-30 21:58:45 +01:00
|
|
|
'''
|
|
|
|
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`, :meth:`link_dirs_flags` and
|
|
|
|
:meth:`link_libs_flags`.
|
|
|
|
|
|
|
|
.. warning:: This recipe is very sensitive because is used for our core
|
|
|
|
recipes, the python recipes. The used API should match with the one
|
|
|
|
used in our python build, otherwise we will be unable to build the
|
|
|
|
_ssl.so python module.
|
|
|
|
|
|
|
|
.. 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+
|
|
|
|
- Add ability to build a legacy version of the openssl libs when using
|
|
|
|
python2legacy or python3crystax.
|
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
.. versionchanged:: 2019.06.06.1.dev0
|
|
|
|
|
|
|
|
- Removed legacy version of openssl libraries
|
|
|
|
|
2019-03-30 21:58:45 +01:00
|
|
|
'''
|
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
version = '1.1'
|
2019-03-30 21:58:45 +01:00
|
|
|
'''the major minor version used to link our recipes'''
|
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
url_version = '1.1.1m'
|
2019-03-30 21:58:45 +01:00
|
|
|
'''the version used to download our libraries'''
|
|
|
|
|
|
|
|
url = 'https://www.openssl.org/source/openssl-{url_version}.tar.gz'
|
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
built_libraries = {
|
|
|
|
'libcrypto{version}.so'.format(version=version): '.',
|
|
|
|
'libssl{version}.so'.format(version=version): '.',
|
|
|
|
}
|
2019-03-30 21:58:45 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def versioned_url(self):
|
|
|
|
if self.url is None:
|
|
|
|
return None
|
|
|
|
return self.url.format(url_version=self.url_version)
|
|
|
|
|
|
|
|
def get_build_dir(self, arch):
|
2022-12-02 21:15:34 +01:00
|
|
|
return join(
|
|
|
|
self.get_build_container_dir(arch), self.name + self.version
|
|
|
|
)
|
2019-03-30 21:58:45 +01:00
|
|
|
|
|
|
|
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_dirs_flags(self, arch):
|
|
|
|
'''Returns a string with the appropriate `-L<lib directory>` to link
|
|
|
|
with the openssl libs. This string is usually added to the environment
|
|
|
|
variable `LDFLAGS`'''
|
|
|
|
return ' -L' + self.get_build_dir(arch.arch)
|
|
|
|
|
|
|
|
def link_libs_flags(self):
|
|
|
|
'''Returns a string with the appropriate `-l<lib>` flags to link with
|
|
|
|
the openssl libs. This string is usually added to the environment
|
|
|
|
variable `LIBS`'''
|
|
|
|
return ' -lcrypto{version} -lssl{version}'.format(version=self.version)
|
|
|
|
|
|
|
|
def link_flags(self, arch):
|
|
|
|
'''Returns a string with the flags to link with the openssl libraries
|
|
|
|
in the format: `-L<lib directory> -l<lib>`'''
|
|
|
|
return self.link_dirs_flags(arch) + self.link_libs_flags()
|
2017-08-13 03:24:00 +02:00
|
|
|
|
|
|
|
def get_recipe_env(self, arch=None):
|
2022-12-02 21:15:34 +01:00
|
|
|
env = super().get_recipe_env(arch)
|
2017-08-13 03:24:00 +02:00
|
|
|
env['OPENSSL_VERSION'] = self.version
|
2019-03-30 21:58:45 +01:00
|
|
|
env['MAKE'] = 'make' # This removes the '-j5', which isn't safe
|
2022-12-02 21:15:34 +01:00
|
|
|
env['CC'] = 'clang'
|
|
|
|
env['ANDROID_NDK_HOME'] = self.ctx.ndk_dir
|
2017-08-13 03:24:00 +02:00
|
|
|
return env
|
|
|
|
|
|
|
|
def select_build_arch(self, arch):
|
|
|
|
aname = arch.arch
|
|
|
|
if 'arm64' in aname:
|
2022-12-02 21:15:34 +01:00
|
|
|
return 'android-arm64'
|
2017-08-13 03:24:00 +02:00
|
|
|
if 'v7a' in aname:
|
2022-12-02 21:15:34 +01:00
|
|
|
return 'android-arm'
|
2017-08-13 03:24:00 +02:00
|
|
|
if 'arm' in aname:
|
|
|
|
return 'android'
|
2019-03-30 21:58:45 +01:00
|
|
|
if 'x86_64' in aname:
|
|
|
|
return 'android-x86_64'
|
|
|
|
if 'x86' in aname:
|
|
|
|
return 'android-x86'
|
2017-08-13 03:24:00 +02:00
|
|
|
return 'linux-armv4'
|
|
|
|
|
|
|
|
def build_arch(self, arch):
|
|
|
|
env = self.get_recipe_env(arch)
|
|
|
|
with current_directory(self.get_build_dir(arch.arch)):
|
|
|
|
# sh fails with code 255 trying to execute ./Configure
|
|
|
|
# so instead we manually run perl passing in Configure
|
|
|
|
perl = sh.Command('perl')
|
|
|
|
buildarch = self.select_build_arch(arch)
|
2022-12-02 21:15:34 +01:00
|
|
|
config_args = [
|
|
|
|
'shared',
|
|
|
|
'no-dso',
|
|
|
|
'no-asm',
|
|
|
|
buildarch,
|
|
|
|
'-D__ANDROID_API__={}'.format(self.ctx.ndk_api),
|
|
|
|
]
|
2019-03-30 21:58:45 +01:00
|
|
|
shprint(perl, 'Configure', *config_args, _env=env)
|
2022-12-02 21:15:34 +01:00
|
|
|
self.apply_patch('disable-sover.patch', arch.arch)
|
2019-03-30 21:58:45 +01:00
|
|
|
|
|
|
|
shprint(sh.make, 'build_libs', _env=env)
|
2017-08-13 03:24:00 +02:00
|
|
|
|
2019-03-30 21:58:45 +01:00
|
|
|
|
2017-08-13 03:24:00 +02:00
|
|
|
recipe = OpenSSLRecipe()
|