[IOT-1511] Update mbedTLS to use 2.4.0 release tagged version
[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
26 target_os = env.get('TARGET_OS')
27 root_dir = env.get('SRC_DIR')
28 mbedtls_dir = os.path.join(root_dir, 'extlibs','mbedtls','mbedtls/')
29 # Right now this script assumes the revision is a tag, and not a branch or an arbitrary
30 # commit. If this changes, update the check below, or else the script will always conclude
31 # the repo is not up to date because a tag with that name doesn't exist.
32 mbedtls_revision = 'mbedtls-2.4.0'
33
34 if not os.path.exists(mbedtls_dir):
35     print '''
36 *********************************** Error: ****************************************
37 * Please download mbedtls using the following command:                            *
38 *     $ git clone https://github.com/ARMmbed/mbedtls.git extlibs/mbedtls/mbedtls  *
39 ***********************************************************************************
40  '''
41     Exit(1)
42
43 # Tizen uses its own process to prepare the mbedTLS repo in gbsbuild.sh. Make sure
44 # the mbedtls_revision tag selected is the same as in extlibs/mbedtls/prep.sh.
45 # This code also assumes mbedtls_revision is a tag; if it changes to
46 # a branch or an arbitrary commit, disable this check below.
47 if target_os != 'tizen':
48     if not os.path.exists(os.path.join(mbedtls_dir, '.git', 'refs', 'tags', mbedtls_revision)):
49         print '''
50 *********************************** Error: ****************************************
51 * Your mbedTLS repo is not up to date with the latest version we require. Please  *
52 * update with the following commands:                                             *
53 *     $ cd extlibs/mbedtls/mbedtls                                                *
54 *     $ git fetch                                                                 *
55 ***********************************************************************************
56  '''
57         Exit(1)
58
59 start_dir = os.getcwd()
60 os.chdir(mbedtls_dir)
61 # Apply ocf patch on git revision
62 if os.path.exists('.git/HEAD'):
63     cmd = 'git checkout development && git reset --hard ' + mbedtls_revision + ' && git apply --whitespace=fix ../ocf.patch'
64     os.system(cmd)
65 else:
66     print 'mbedtls: Assume ocf.patch (TLS_ECDH_ANON_WITH_AES_128_CBC_SHA256) was applied in %s' % mbedtls_dir
67 os.chdir(start_dir)
68
69
70 mbedtls_env = env.Clone()
71 mbedtls_env.PrependUnique(CPPPATH = [mbedtls_dir])
72 mbedtls_env.AppendUnique(CPPPATH = [mbedtls_dir+'include/'])
73 mbedtls_env.AppendUnique(CFLAGS = ['-fPIC', '-Wall'])
74
75 ######################################################################
76 # Source files and Target(s)
77 ######################################################################
78 mbedtls_src = [
79                 'mbedtls/library/debug.c',
80                 'mbedtls/library/net_sockets.c',
81                 'mbedtls/library/ssl_cache.c',
82                 'mbedtls/library/ssl_ciphersuites.c',
83                 'mbedtls/library/ssl_cli.c',
84                 'mbedtls/library/ssl_cookie.c',
85                 'mbedtls/library/ssl_srv.c',
86                 'mbedtls/library/ssl_ticket.c',
87                 'mbedtls/library/ssl_tls.c'
88         ]
89
90
91 mbedcrypto_src = [
92                     'mbedtls/library/aes.c',
93                     'mbedtls/library/aesni.c',
94                     'mbedtls/library/arc4.c',
95                     'mbedtls/library/asn1parse.c',
96                     'mbedtls/library/asn1write.c',
97                     'mbedtls/library/base64.c',
98                     'mbedtls/library/bignum.c',
99                     'mbedtls/library/blowfish.c',
100                     'mbedtls/library/camellia.c',
101                     'mbedtls/library/ccm.c',
102                     'mbedtls/library/cipher.c',
103                     'mbedtls/library/cipher_wrap.c',
104                     'mbedtls/library/ctr_drbg.c',
105                     'mbedtls/library/des.c',
106                     'mbedtls/library/dhm.c',
107                     'mbedtls/library/ecdh.c',
108                     'mbedtls/library/ecdsa.c',
109                     'mbedtls/library/ecjpake.c',
110                     'mbedtls/library/ecp.c',
111                     'mbedtls/library/ecp_curves.c',
112                     'mbedtls/library/entropy.c',
113                     'mbedtls/library/entropy_poll.c',
114                     'mbedtls/library/error.c',
115                     'mbedtls/library/gcm.c',
116                     'mbedtls/library/havege.c',
117                     'mbedtls/library/hmac_drbg.c',
118                     'mbedtls/library/md.c',
119                     'mbedtls/library/md2.c',
120                     'mbedtls/library/md4.c',
121                     'mbedtls/library/md5.c',
122                     'mbedtls/library/md_wrap.c',
123                     'mbedtls/library/memory_buffer_alloc.c',
124                     'mbedtls/library/oid.c',
125                     'mbedtls/library/padlock.c',
126                     'mbedtls/library/pem.c',
127                     'mbedtls/library/pk.c',
128                     'mbedtls/library/pk_wrap.c',
129                     'mbedtls/library/pkcs12.c',
130                     'mbedtls/library/pkcs5.c',
131                     'mbedtls/library/pkparse.c',
132                     'mbedtls/library/pkwrite.c',
133                     'mbedtls/library/platform.c',
134                     'mbedtls/library/ripemd160.c',
135                     'mbedtls/library/rsa.c',
136                     'mbedtls/library/sha1.c',
137                     'mbedtls/library/sha256.c',
138                     'mbedtls/library/sha512.c',
139                     'mbedtls/library/threading.c',
140                     'mbedtls/library/timing.c',
141                     'mbedtls/library/version.c',
142                     'mbedtls/library/version_features.c',
143                     'mbedtls/library/xtea.c'
144         ]
145
146 mbeX509_src = [
147                 'mbedtls/library/certs.c',
148                 'mbedtls/library/pkcs11.c',
149                 'mbedtls/library/x509.c',
150                 'mbedtls/library/x509_create.c',
151                 'mbedtls/library/x509_crl.c',
152                 'mbedtls/library/x509_crt.c',
153                 'mbedtls/library/x509_csr.c',
154                 'mbedtls/library/x509write_crt.c',
155                 'mbedtls/library/x509write_csr.c'
156         ]
157
158 mbedcrypto_env = mbedtls_env.Clone()
159 static_libmbedcrypto = mbedcrypto_env.StaticLibrary('mbedcrypto', mbedcrypto_src)
160 mbedcrypto_env.InstallTarget(static_libmbedcrypto, 'mbedcrypto')
161
162 mbex509_env = mbedtls_env.Clone()
163 mbex509_env.AppendUnique(LIBS = ['mbedcrypto'])
164 static_libmbedx509 = mbex509_env.StaticLibrary('mbedx509', mbeX509_src)
165 mbex509_env.InstallTarget(static_libmbedx509, 'mbedx509')
166
167
168 mbedtls_env.AppendUnique(LIBS = ['mbedx509', 'mbedcrypto'])
169 static_libmbedtls = mbedtls_env.StaticLibrary('mbedtls', mbedtls_src)
170 mbedtls_env.InstallTarget(static_libmbedtls, 'mbedtls')