1
+ import time
2
+ from os .path import join
1
3
from functools import partial
2
4
3
5
from pythonforandroid .toolchain import Recipe , shprint , current_directory
4
6
import sh
5
7
6
8
7
9
class OpenSSLRecipe (Recipe ):
8
- version = '1.1.1'
9
- lib_version = '1.1'
10
- url = 'https://www.openssl.org/source/openssl-{version}.tar.gz'
10
+ '''
11
+ The OpenSSL libraries for python-for-android. This recipe will generate the
12
+ following libraries as shared libraries (*.so):
13
+
14
+ - crypto
15
+ - ssl
16
+
17
+ The generated openssl libraries are versioned, where the version is the
18
+ recipe attribute :attr:`version` e.g.: ``libcrypto1.1.so``,
19
+ ``libssl1.1.so``...so...to link your recipe with the openssl libs,
20
+ remember to add the version at the end, e.g.:
21
+ ``-lcrypto1.1 -lssl1.1``. Or better, you could do it dynamically
22
+ using the methods: :meth:`include_flags` and :meth:`link_flags`.
23
+
24
+ .. warning:: This recipe is very sensitive because is used for our core
25
+ recipes, the python recipes. The used API should match with the one
26
+ used in our python build, otherwise we will be unable to build the
27
+ _ssl.so python module.
28
+
29
+ .. versionchanged:: 0.6.0
30
+
31
+ - The gcc compiler has been deprecated in favour of clang and libraries
32
+ updated to version 1.1.1 (LTS - supported until 11th September 2023)
33
+ - Added two new methods to make easier to link with openssl:
34
+ :meth:`include_flags` and :meth:`link_flags`
35
+ - subclassed versioned_url
36
+ - Adapted method :meth:`select_build_arch` to API 21+
37
+
38
+ '''
39
+
40
+ version = '1.1'
41
+ '''the major minor version used to link our recipes'''
42
+
43
+ url_version = '1.1.1'
44
+ '''the version used to download our libraries'''
45
+
46
+ url = 'https://www.openssl.org/source/openssl-{url_version}.tar.gz'
47
+
48
+ @property
49
+ def versioned_url (self ):
50
+ if self .url is None :
51
+ return None
52
+ return self .url .format (url_version = self .url_version )
53
+
54
+ def include_flags (self , arch ):
55
+ '''Returns a string with the include folders'''
56
+ openssl_includes = join (self .get_build_dir (arch .arch ), 'include' )
57
+ return ' -I' + openssl_includes + \
58
+ ' -I' + join (openssl_includes , 'internal' ) + \
59
+ ' -I' + join (openssl_includes , 'openssl' )
60
+
61
+ def link_flags (self , arch ):
62
+ '''Returns a string with the right link flags to compile against the
63
+ openssl libraries'''
64
+ build_dir = self .get_build_dir (arch .arch )
65
+ return ' -L' + build_dir + \
66
+ ' -lcrypto{version} -lssl{version}' .format (version = self .version )
11
67
12
68
def should_build (self , arch ):
13
- return not self .has_libs (arch , 'libssl' + self .lib_version + '.so' ,
14
- 'libcrypto' + self .lib_version + '.so' )
69
+ return not self .has_libs (arch , 'libssl' + self .version + '.so' ,
70
+ 'libcrypto' + self .version + '.so' )
15
71
16
72
def check_symbol (self , env , sofile , symbol ):
17
73
nm = env .get ('NM' , 'nm' )
@@ -24,7 +80,7 @@ def check_symbol(self, env, sofile, symbol):
24
80
25
81
def get_recipe_env (self , arch = None ):
26
82
env = super (OpenSSLRecipe , self ).get_recipe_env (arch , clang = True )
27
- env ['OPENSSL_VERSION' ] = self .lib_version
83
+ env ['OPENSSL_VERSION' ] = self .version
28
84
env ['MAKE' ] = 'make' # This removes the '-j5', which isn't safe
29
85
env ['ANDROID_NDK' ] = self .ctx .ndk_dir
30
86
return env
@@ -54,21 +110,22 @@ def build_arch(self, arch):
54
110
# ^
55
111
# crypto/aes/bsaes-armv7.S:1434:14: error: immediate operand must be in the range [0,4095]
56
112
# sub r6, r8, #.LREVM0SR-.LSR @ pass constants
57
- shprint (perl , 'Configure' , 'shared' , 'no-dso' , 'no-asm' , buildarch , _env = env )
113
+ shprint (perl , 'Configure' , 'shared' , 'no-dso' , 'no-asm' , buildarch ,
114
+ '-D__ANDROID_API__={}' .format (self .ctx .ndk_api ),
115
+ _env = env )
58
116
self .apply_patch ('disable-sover.patch' , arch .arch )
59
117
60
118
# check_ssl = partial(self.check_symbol, env, 'libssl' + self.version + '.so')
61
- check_crypto = partial (self .check_symbol , env , 'libcrypto' + self .lib_version + '.so' )
119
+ check_crypto = partial (self .check_symbol , env , 'libcrypto' + self .version + '.so' )
62
120
while True :
63
121
shprint (sh .make , 'build_libs' , _env = env )
64
122
if all (map (check_crypto , ('MD5_Transform' , 'MD4_Init' ))):
65
123
break
66
- import time
67
124
time .sleep (3 )
68
125
shprint (sh .make , 'clean' , _env = env )
69
126
70
- self .install_libs (arch , 'libssl' + self .lib_version + '.so' ,
71
- 'libcrypto' + self .lib_version + '.so' )
127
+ self .install_libs (arch , 'libssl' + self .version + '.so' ,
128
+ 'libcrypto' + self .version + '.so' )
72
129
73
130
74
131
recipe = OpenSSLRecipe ()
0 commit comments