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