Update mbedTLS
[platform/upstream/iotivity.git] / extlibs / mbedtls / SConscript
1 #******************************************************************
2 #
3 # Copyright 2016 Samsung Electronics All Rights Reserved.
4 #
5 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 Import('env')
22
23 import os
24 import sys
25 import subprocess
26
27 target_os = env.get('TARGET_OS')
28 root_dir = env.get('SRC_DIR')
29 static_lib = env.get('WITH_MBEDTLS_STATIC_LIB');
30 mbedtls_dir = os.path.join(root_dir, 'extlibs','mbedtls','mbedtls/')
31 start_dir = os.getcwd()
32 # Right now this script assumes the revision is a tag, and not a branch or an arbitrary
33 # commit. If this changes, update the check below, or else the script will always conclude
34 # the repo is not up to date because a tag with that name doesn't exist.
35 mbedtls_revision = 'mbedtls-2.16.2'
36
37 if not os.path.exists(mbedtls_dir):
38     print '''
39 *********************************** Error: ****************************************
40 * Please download mbedtls using the following command:                            *
41 *     $ git clone https://github.com/ARMmbed/mbedtls.git extlibs/mbedtls/mbedtls -b %s
42 ***********************************************************************************
43  ''' % mbedtls_revision
44     Exit(1)
45 #cd extlib/mbedtls/mbedtls
46 os.chdir(mbedtls_dir)
47
48 # Tizen uses its own process to prepare the mbedTLS repo in gbsbuild.sh. Make sure
49 # the mbedtls_revision tag selected is the same as in extlibs/mbedtls/prep.sh.
50 # This code also assumes mbedtls_revision is a tag; if it changes to
51 # a branch or an arbitrary commit, disable this check below.
52 # if target_os != 'tizen':
53 #     out = subprocess.check_output('git tag -l ' + mbedtls_revision, shell = True)
54 #     if mbedtls_revision not in out:
55 #         print out
56 #         print '''
57 # *********************************** Error: ****************************************
58 # * Your mbedTLS repo is not up to date with the latest version we require. Please  *
59 # * update with the following commands:                                             *
60 # *     $ cd extlibs/mbedtls/mbedtls                                                *
61 # *     $ git fetch                                                                 *
62 # ***********************************************************************************
63 #  '''
64 #         Exit(1)
65
66 # Apply ocf patch on git revision
67 if os.path.exists('.git/HEAD'):
68     cmd = 'git checkout development && git reset --hard ' + mbedtls_revision + ' && git apply --whitespace=fix ../ocf.patch'
69     os.system(cmd)
70 else:
71     print 'mbedtls: Assume ocf.patch (TLS_ECDH_ANON_WITH_AES_128_CBC_SHA256) was applied in %s' % mbedtls_dir
72 os.chdir(start_dir)
73
74
75 mbedtls_env = env.Clone()
76 mbedtls_env.PrependUnique(CPPPATH = [mbedtls_dir])
77 mbedtls_env.AppendUnique(CPPPATH = [mbedtls_dir+'include/'])
78 mbedtls_env.AppendUnique(CFLAGS = ['-fPIC', '-Wall'])
79
80 asan_build = env.get('WITH_ASAN')
81 print 'Asan build: {}'.format(asan_build)
82 if asan_build:
83     mbedtls_env.AppendUnique(CFLAGS = ['-UMBEDTLS_HAVE_ASM'])
84
85 ######################################################################
86 # Source files and Target(s)
87 ######################################################################
88 mbedtls_src = [
89                 'mbedtls/library/debug.c',
90                 'mbedtls/library/net_sockets.c',
91                 'mbedtls/library/ssl_cache.c',
92                 'mbedtls/library/ssl_ciphersuites.c',
93                 'mbedtls/library/ssl_cli.c',
94                 'mbedtls/library/ssl_cookie.c',
95                 'mbedtls/library/ssl_srv.c',
96                 'mbedtls/library/ssl_ticket.c',
97                 'mbedtls/library/ssl_tls.c'
98         ]
99
100
101 mbedcrypto_src = [
102                     'mbedtls/library/aes.c',
103                     'mbedtls/library/aesni.c',
104                     'mbedtls/library/arc4.c',
105                     'mbedtls/library/asn1parse.c',
106                     'mbedtls/library/asn1write.c',
107                     'mbedtls/library/base64.c',
108                     'mbedtls/library/bignum.c',
109                     'mbedtls/library/blowfish.c',
110                     'mbedtls/library/camellia.c',
111                     'mbedtls/library/ccm.c',
112                     'mbedtls/library/cipher.c',
113                     'mbedtls/library/cipher_wrap.c',
114                     'mbedtls/library/ctr_drbg.c',
115                     'mbedtls/library/des.c',
116                     'mbedtls/library/dhm.c',
117                     'mbedtls/library/ecdh.c',
118                     'mbedtls/library/ecdsa.c',
119                     'mbedtls/library/ecjpake.c',
120                     'mbedtls/library/ecp.c',
121                     'mbedtls/library/ecp_curves.c',
122                     'mbedtls/library/entropy.c',
123                     'mbedtls/library/entropy_poll.c',
124                     'mbedtls/library/error.c',
125                     'mbedtls/library/gcm.c',
126                     'mbedtls/library/havege.c',
127                     'mbedtls/library/hmac_drbg.c',
128                     'mbedtls/library/md.c',
129                     'mbedtls/library/md2.c',
130                     'mbedtls/library/md4.c',
131                     'mbedtls/library/md5.c',
132                     'mbedtls/library/md_wrap.c',
133                     'mbedtls/library/memory_buffer_alloc.c',
134                     'mbedtls/library/oid.c',
135                     'mbedtls/library/padlock.c',
136                     'mbedtls/library/pem.c',
137                     'mbedtls/library/pk.c',
138                     'mbedtls/library/pk_wrap.c',
139                     'mbedtls/library/pkcs12.c',
140                     'mbedtls/library/pkcs5.c',
141                     'mbedtls/library/pkparse.c',
142                     'mbedtls/library/pkwrite.c',
143                     'mbedtls/library/platform.c',
144                     'mbedtls/library/ripemd160.c',
145                     'mbedtls/library/rsa.c',
146                     'mbedtls/library/rsa_internal.c',
147                     'mbedtls/library/sha1.c',
148                     'mbedtls/library/sha256.c',
149                     'mbedtls/library/sha512.c',
150                     'mbedtls/library/threading.c',
151                     'mbedtls/library/timing.c',
152                     'mbedtls/library/version.c',
153                     'mbedtls/library/version_features.c',
154                     'mbedtls/library/xtea.c',
155                     'mbedtls/library/platform_util.c',
156                     'mbedtls/library/chachapoly.c',
157                     'mbedtls/library/poly1305.c',
158                     'mbedtls/library/chacha20.c'
159         ]
160
161 mbeX509_src = [
162                 'mbedtls/library/certs.c',
163                 'mbedtls/library/pkcs11.c',
164                 'mbedtls/library/x509.c',
165                 'mbedtls/library/x509_create.c',
166                 'mbedtls/library/x509_crl.c',
167                 'mbedtls/library/x509_crt.c',
168                 'mbedtls/library/x509_csr.c',
169                 'mbedtls/library/x509write_crt.c',
170                 'mbedtls/library/x509write_csr.c'
171         ]
172
173 mbedcrypto_env = mbedtls_env.Clone()
174 static_libmbedcrypto = mbedcrypto_env.StaticLibrary('mbedcrypto', mbedcrypto_src)
175 mbedcrypto_env.InstallTarget(static_libmbedcrypto, 'mbedcrypto')
176
177 mbex509_env = mbedtls_env.Clone()
178 mbex509_env.AppendUnique(LIBS = ['mbedcrypto'])
179 static_libmbedx509 = mbex509_env.StaticLibrary('mbedx509', mbeX509_src)
180 mbex509_env.InstallTarget(static_libmbedx509, 'mbedx509')
181
182 if static_lib == '1':
183         mbedtls_env.AppendUnique(LIBS = ['mbedx509', 'mbedcrypto'])
184         static_libmbedtls = mbedtls_env.StaticLibrary('mbedtls', mbedtls_src)
185         mbedtls_env.InstallTarget(static_libmbedtls, 'mbedtls')
186 else:
187         if target_os in ['windows', 'msys_nt', 'ios']:
188                 mbedtls_env.AppendUnique(LIBS = ['mbedx509', 'mbedcrypto'])
189                 static_libmbedtls = mbedtls_env.StaticLibrary('mbedtls', mbedtls_src)
190                 mbedtls_env.InstallTarget(static_libmbedtls, 'mbedtls')
191         else:
192                 mbedtls_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
193                 mbedtls_env.AppendUnique(LIBS = ['mbedx509', 'mbedcrypto'])
194                 static_libmbedtls = mbedtls_env.StaticLibrary('mbedtls', mbedtls_src)
195                 shared_libmbedtls = mbedtls_env.SharedLibrary('mbedtls', mbedtls_src)
196                 mbedtls_env.InstallTarget([static_libmbedtls, shared_libmbedtls], 'mbedtls')
197                 mbedtls_env.UserInstallTargetLib([static_libmbedtls, shared_libmbedtls], 'mbedtls')
198         if target_os in ['android']:
199                 mbedtls_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,libmbedtls.so'])