import os
import sys
+import subprocess
target_os = env.get('TARGET_OS')
root_dir = env.get('SRC_DIR')
+static_lib = env.get('WITH_MBEDTLS_STATIC_LIB');
mbedtls_dir = os.path.join(root_dir, 'extlibs','mbedtls','mbedtls/')
+start_dir = os.getcwd()
+# Right now this script assumes the revision is a tag, and not a branch or an arbitrary
+# commit. If this changes, update the check below, or else the script will always conclude
+# the repo is not up to date because a tag with that name doesn't exist.
+mbedtls_revision = 'mbedtls-2.16.2'
if not os.path.exists(mbedtls_dir):
print '''
*********************************** Error: ****************************************
* Please download mbedtls using the following command: *
-* $ git clone https://github.com/ARMmbed/mbedtls.git extlibs/mbedtls/mbedtls *
+* $ git clone https://github.com/ARMmbed/mbedtls.git extlibs/mbedtls/mbedtls -b %s
***********************************************************************************
- '''
+ ''' % mbedtls_revision
Exit(1)
-#Apply patch to enable TLS_ECDH_ANON_WITH_AES_128_CBC_SHA256 ciphersuite and server identity hint
-#For tizen platform patch is applied by gbsbuild script
-if target_os != 'tizen':
- start_dir = os.getcwd()
- os.chdir(mbedtls_dir)
- cmd = 'git checkout development && git reset --hard ad249f509fd62a3bbea7ccd1fef605dbd482a7bd && git apply --whitespace=fix ../ocf.patch'
+#cd extlib/mbedtls/mbedtls
+os.chdir(mbedtls_dir)
+
+# Tizen uses its own process to prepare the mbedTLS repo in gbsbuild.sh. Make sure
+# the mbedtls_revision tag selected is the same as in extlibs/mbedtls/prep.sh.
+# This code also assumes mbedtls_revision is a tag; if it changes to
+# a branch or an arbitrary commit, disable this check below.
+# if target_os != 'tizen':
+# out = subprocess.check_output('git tag -l ' + mbedtls_revision, shell = True)
+# if mbedtls_revision not in out:
+# print out
+# print '''
+# *********************************** Error: ****************************************
+# * Your mbedTLS repo is not up to date with the latest version we require. Please *
+# * update with the following commands: *
+# * $ cd extlibs/mbedtls/mbedtls *
+# * $ git fetch *
+# ***********************************************************************************
+# '''
+# Exit(1)
+
+# Apply ocf patch on git revision
+if os.path.exists('.git/HEAD'):
+ cmd = 'git checkout development && git reset --hard ' + mbedtls_revision + ' && git apply --whitespace=fix ../ocf.patch'
os.system(cmd)
- os.chdir(start_dir)
+else:
+ print 'mbedtls: Assume ocf.patch (TLS_ECDH_ANON_WITH_AES_128_CBC_SHA256) was applied in %s' % mbedtls_dir
+os.chdir(start_dir)
mbedtls_env = env.Clone()
mbedtls_env.AppendUnique(CPPPATH = [mbedtls_dir+'include/'])
mbedtls_env.AppendUnique(CFLAGS = ['-fPIC', '-Wall'])
+asan_build = env.get('WITH_ASAN')
+print 'Asan build: {}'.format(asan_build)
+if asan_build:
+ mbedtls_env.AppendUnique(CFLAGS = ['-UMBEDTLS_HAVE_ASM'])
+
######################################################################
# Source files and Target(s)
######################################################################
mbedtls_src = [
'mbedtls/library/debug.c',
- 'mbedtls/library/net.c',
+ 'mbedtls/library/net_sockets.c',
'mbedtls/library/ssl_cache.c',
'mbedtls/library/ssl_ciphersuites.c',
'mbedtls/library/ssl_cli.c',
'mbedtls/library/platform.c',
'mbedtls/library/ripemd160.c',
'mbedtls/library/rsa.c',
+ 'mbedtls/library/rsa_internal.c',
'mbedtls/library/sha1.c',
'mbedtls/library/sha256.c',
'mbedtls/library/sha512.c',
'mbedtls/library/timing.c',
'mbedtls/library/version.c',
'mbedtls/library/version_features.c',
- 'mbedtls/library/xtea.c'
+ 'mbedtls/library/xtea.c',
+ 'mbedtls/library/platform_util.c',
+ 'mbedtls/library/chachapoly.c',
+ 'mbedtls/library/poly1305.c',
+ 'mbedtls/library/chacha20.c'
]
mbeX509_src = [
static_libmbedx509 = mbex509_env.StaticLibrary('mbedx509', mbeX509_src)
mbex509_env.InstallTarget(static_libmbedx509, 'mbedx509')
-
-mbedtls_env.AppendUnique(LIBS = ['mbedx509', 'mbedcrypto'])
-static_libmbedtls = mbedtls_env.StaticLibrary('mbedtls', mbedtls_src)
-mbedtls_env.InstallTarget(static_libmbedtls, 'mbedtls')
+if static_lib == '1':
+ mbedtls_env.AppendUnique(LIBS = ['mbedx509', 'mbedcrypto'])
+ static_libmbedtls = mbedtls_env.StaticLibrary('mbedtls', mbedtls_src)
+ mbedtls_env.InstallTarget(static_libmbedtls, 'mbedtls')
+else:
+ if target_os in ['windows', 'msys_nt', 'ios']:
+ mbedtls_env.AppendUnique(LIBS = ['mbedx509', 'mbedcrypto'])
+ static_libmbedtls = mbedtls_env.StaticLibrary('mbedtls', mbedtls_src)
+ mbedtls_env.InstallTarget(static_libmbedtls, 'mbedtls')
+ else:
+ mbedtls_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+ mbedtls_env.AppendUnique(LIBS = ['mbedx509', 'mbedcrypto'])
+ static_libmbedtls = mbedtls_env.StaticLibrary('mbedtls', mbedtls_src)
+ shared_libmbedtls = mbedtls_env.SharedLibrary('mbedtls', mbedtls_src)
+ mbedtls_env.InstallTarget([static_libmbedtls, shared_libmbedtls], 'mbedtls')
+ mbedtls_env.UserInstallTargetLib([static_libmbedtls, shared_libmbedtls], 'mbedtls')
+ if target_os in ['android']:
+ mbedtls_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,libmbedtls.so'])