1 #******************************************************************
3 # Copyright 2016 Samsung Electronics All Rights Reserved.
5 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
26 from shutil import copyfile
28 target_os = env.get('TARGET_OS')
29 root_dir = env.get('SRC_DIR')
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.4.0'
37 if not os.path.exists(mbedtls_dir):
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
45 #cd extlib/mbedtls/mbedtls
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:
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 *
62 ***********************************************************************************
67 # Apply ocf patch on git revision
68 if os.path.exists('.git/HEAD'):
69 cmd = 'git checkout development && git reset --hard ' + mbedtls_revision + ' && git clean -f && git apply --whitespace=fix ../ocf.patch'
72 print 'mbedtls: Assume ocf.patch (TLS_ECDH_ANON_WITH_AES_128_CBC_SHA256) was applied in %s' % mbedtls_dir
75 # Copy IoTivity's version of the mbedtls build configuration file
76 # from extlibs/mbedtls/iotivity-config.h
77 # to extlibs/mbedtls/mbedtls/include/mbedtls/config.h
78 iotivity_config = os.path.join(root_dir, 'extlibs', 'mbedtls', 'config-iotivity.h')
79 mbedtls_config = os.path.join(root_dir, 'extlibs', 'mbedtls', 'mbedtls', 'include', 'mbedtls', 'config.h')
82 copyfile(iotivity_config, mbedtls_config)
84 print 'mbedtls SConscript: cannot copy ' + iotivity_config + ' to ' + mbedtls_config
87 print 'Copied IoTivity version of config.h to ' + mbedtls_config
89 mbedtls_env = env.Clone()
90 mbedtls_env.PrependUnique(CPPPATH = [mbedtls_dir])
91 mbedtls_env.AppendUnique(CPPPATH = [mbedtls_dir+'include/'])
92 if 'g++' in mbedtls_env.get('CXX'):
93 mbedtls_env.AppendUnique(CFLAGS = ['-Wall'])
95 if mbedtls_env['CC'] != 'cl':
96 mbedtls_env.AppendUnique(CFLAGS = ['-fPIC'])
98 ######################################################################
99 # Source files and Target(s)
100 ######################################################################
102 'mbedtls/library/debug.c',
103 'mbedtls/library/net_sockets.c',
104 'mbedtls/library/ssl_cache.c',
105 'mbedtls/library/ssl_ciphersuites.c',
106 'mbedtls/library/ssl_cli.c',
107 'mbedtls/library/ssl_cookie.c',
108 'mbedtls/library/ssl_srv.c',
109 'mbedtls/library/ssl_ticket.c',
110 'mbedtls/library/ssl_tls.c'
115 'mbedtls/library/aes.c',
116 'mbedtls/library/aesni.c',
117 'mbedtls/library/arc4.c',
118 'mbedtls/library/asn1parse.c',
119 'mbedtls/library/asn1write.c',
120 'mbedtls/library/base64.c',
121 'mbedtls/library/bignum.c',
122 'mbedtls/library/blowfish.c',
123 'mbedtls/library/camellia.c',
124 'mbedtls/library/ccm.c',
125 'mbedtls/library/cipher.c',
126 'mbedtls/library/cipher_wrap.c',
127 'mbedtls/library/ctr_drbg.c',
128 'mbedtls/library/des.c',
129 'mbedtls/library/dhm.c',
130 'mbedtls/library/ecdh.c',
131 'mbedtls/library/ecdsa.c',
132 'mbedtls/library/ecjpake.c',
133 'mbedtls/library/ecp.c',
134 'mbedtls/library/ecp_curves.c',
135 'mbedtls/library/entropy.c',
136 'mbedtls/library/entropy_poll.c',
137 'mbedtls/library/error.c',
138 'mbedtls/library/gcm.c',
139 'mbedtls/library/havege.c',
140 'mbedtls/library/hmac_drbg.c',
141 'mbedtls/library/md.c',
142 'mbedtls/library/md2.c',
143 'mbedtls/library/md4.c',
144 'mbedtls/library/md5.c',
145 'mbedtls/library/md_wrap.c',
146 'mbedtls/library/memory_buffer_alloc.c',
147 'mbedtls/library/oid.c',
148 'mbedtls/library/padlock.c',
149 'mbedtls/library/pem.c',
150 'mbedtls/library/pk.c',
151 'mbedtls/library/pk_wrap.c',
152 'mbedtls/library/pkcs12.c',
153 'mbedtls/library/pkcs5.c',
154 'mbedtls/library/pkparse.c',
155 'mbedtls/library/pkwrite.c',
156 'mbedtls/library/platform.c',
157 'mbedtls/library/ripemd160.c',
158 'mbedtls/library/rsa.c',
159 'mbedtls/library/sha1.c',
160 'mbedtls/library/sha256.c',
161 'mbedtls/library/sha512.c',
162 'mbedtls/library/threading.c',
163 'mbedtls/library/timing.c',
164 'mbedtls/library/version.c',
165 'mbedtls/library/version_features.c',
166 'mbedtls/library/xtea.c'
170 'mbedtls/library/certs.c',
171 'mbedtls/library/pkcs11.c',
172 'mbedtls/library/x509.c',
173 'mbedtls/library/x509_create.c',
174 'mbedtls/library/x509_crl.c',
175 'mbedtls/library/x509_crt.c',
176 'mbedtls/library/x509_csr.c',
177 'mbedtls/library/x509write_crt.c',
178 'mbedtls/library/x509write_csr.c'
181 mbedcrypto_env = mbedtls_env.Clone()
182 static_libmbedcrypto = mbedcrypto_env.StaticLibrary('mbedcrypto', mbedcrypto_src)
183 mbedcrypto_env.InstallTarget(static_libmbedcrypto, 'mbedcrypto')
185 mbex509_env = mbedtls_env.Clone()
186 mbex509_env.AppendUnique(LIBS = ['mbedcrypto'])
187 static_libmbedx509 = mbex509_env.StaticLibrary('mbedx509', mbeX509_src)
188 mbex509_env.InstallTarget(static_libmbedx509, 'mbedx509')
191 mbedtls_env.AppendUnique(LIBS = ['mbedx509', 'mbedcrypto'])
192 static_libmbedtls = mbedtls_env.StaticLibrary('mbedtls', mbedtls_src)
193 mbedtls_env.InstallTarget(static_libmbedtls, 'mbedtls')