Merge "Merge remote-tracking branch 'origin/master' into notification-service" into...
[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 def run(cmd):
27     """Run a command and decipher the return code. Exit by default."""
28     res = os.system(cmd)
29     # Assumes that if a process doesn't call exit, it was successful
30     if (os.WIFEXITED(res)):
31         code = os.WEXITSTATUS(res)
32         if code != 0:
33             print "Error: return code: " + str(code)
34             if SCons.Script.keep_going_on_error == 0:
35                 sys.exit(code)
36
37 root_dir = env.get('SRC_DIR')
38
39 tls_dir = os.path.join(root_dir, 'extlibs','mbedtls','mbedtls')
40
41 if not os.path.exists(tls_dir):
42     print '''
43 *********************************** Error: ****************************************
44 * Please download mbedtls using the following command:                            *
45 *     $ git clone https://github.com/ARMmbed/mbedtls.git extlibs/mbedtls/mbedtls  *
46 ***********************************************************************************
47 '''
48     Exit(1)
49
50 start_dir = os.getcwd()
51 os.chdir(tls_dir)
52
53 #Apply patch to enable TLS_ECDH_ANON_WITH_AES_128_CBC_SHA256 ciphersuite and server identity hint
54 cmd = 'git reset --hard ad249f509fd62a3bbea7ccd1fef605dbd482a7bd && git apply ../ocf.patch'
55 run(cmd)
56
57 build_dir = env.get('BUILD_DIR')
58 libs_list = ['libmbedcrypto.so', 'libmbedtls.so', 'libmbedx509.so']
59
60 if env.GetOption('clean'):
61         print 'Clean-up mbedtls...'
62         run('make clean')
63
64         #Delete copied libs from out folder
65         for file_name in libs_list:
66                 run("rm -f " + build_dir + file_name + "*")
67 else:
68         #Pass to make proper debug option
69         if env.get('RELEASE'): debug = ''
70         else: debug = 'DEBUG=1 '
71
72         cmd = 'export SHARED=1 ' + debug + '&& make no_test'
73
74         print 'Making mbedtls libraries...'
75         print cmd
76         run(cmd)
77         
78         #Copy libs to out folder
79         if not os.path.exists(build_dir): os.makedirs(build_dir)
80         for file_name in libs_list:
81                 run("cp -d " + tls_dir + '/library/' + file_name + " " + build_dir)
82                 run("cp " + tls_dir + '/library/' + file_name + ".* " + build_dir)
83
84 os.chdir(start_dir)
85
86
87