82aafeb1f78e4b60006c056f47a9e6178e9dd1f6
[platform/upstream/iotivity.git] / extlibs / tinydtls / SConscript
1 # *****************************************************************
2 #
3 #  Copyright 2015 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 # Tinydtls build script
22 ##
23
24 Import('env')
25
26 print "Reading Tinydtls folder script"
27
28 target_os = env.get('TARGET_OS')
29
30 if(target_os) == 'arduino':
31         env.Replace(CFLAGS = env.get('CXXFLAGS'))
32
33 root_dir = './'
34 tinydtls_src_path = root_dir
35
36 dtls_env = env.Clone()
37
38 dtls_env.PrependUnique(CPPPATH = [root_dir])
39 dtls_env.AppendUnique(CPPPATH = [root_dir+'aes/'])
40 dtls_env.AppendUnique(CPPPATH = [root_dir+'ecc/'])
41 dtls_env.AppendUnique(CPPPATH = [root_dir+'sha2/'])
42
43 ######################################################################
44 # Source files and Target(s)
45 ######################################################################
46 tinydtls_src = [
47                 'dtls.c',
48                 'crypto.c',
49                 'ccm.c',
50                 'hmac.c',
51                 'netq.c',
52                 'peer.c',
53                 'dtls_time.c',
54                 'session.c',
55                 'aes/rijndael.c',
56                 'ecc/ecc.c',
57                 'sha2/sha2.c',
58         ]
59
60 if not dtls_env.get('RELEASE'):
61         if(target_os) not in ['arduino']:
62                 tinydtls_src += ['debug.c']
63         else:
64                 dtls_env.AppendUnique(CPPDEFINES = ['NDEBUG'])
65 else:
66         dtls_env.AppendUnique(CPPDEFINES = ['NDEBUG'])
67
68 dtls_env.AppendUnique(CPPDEFINES = ['DTLSV12',  'WITH_SHA256', 'DTLS_CHECK_CONTENTTYPE', 'SHA2_USE_INTTYPES_H'])
69 env.AppendUnique(CPPDEFINES = ['SHA2_USE_INTTYPES_H'])
70
71 libtinydtls = dtls_env.StaticLibrary('tinydtls', tinydtls_src, OBJPREFIX='libtinydtls_')
72
73 ######################################################################
74 # Generate tinydtls samples
75 #
76 # Note:
77 # Currently there is a bug in debug.h/debug.c which fails compilation
78 # of tinydtls samples in release mode. This bug is being tracked in
79 # IOT-395
80 ######################################################################
81 if not env.get('RELEASE'):
82         samples_env = dtls_env.Clone()
83
84         if target_os not in ['arduino', 'windows']:
85                 samples_env.AppendUnique(CPPDEFINES = ['_GNU_SOURCE'])
86
87         dtlsserver = samples_env.Program('dtls-server', ['tests/dtls-server.c'])
88         dtlsclient = samples_env.Program('dtls-client', ['tests/dtls-client.c'])
89
90         samples_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
91         samples_env.PrependUnique(LIBS = ['tinydtls'])
92
93         if target_os in ['windows', 'msys_nt']:
94                 samples_env.AppendUnique(LIBS = ['ws2_32', 'iphlpapi', 'advapi32', 'bcrypt'])
95
96         Alias("samples", [dtlsserver, dtlsclient])
97
98         samples_env.AppendTarget('samples')
99
100 dtls_env.InstallTarget(libtinydtls, 'tinydtls');
101