Fixes for scons builds
[platform/upstream/iotivity.git] / resource / csdk / libcoap-4.1.1 / SConscript
1 ##
2 # libcoap (share library) build script
3 ##
4
5 Import('env')
6
7 libcoap_env = env.Clone()
8
9 target_os = env.get('TARGET_OS')
10 # As in the source code(C) includes arduino Time library head file(C++)
11 # It requires compile the .c with g++
12 if target_os == 'arduino':
13         libcoap_env.Replace(CC = env.get('CXX'))
14         libcoap_env.Replace(CFLAGS = env.get('CXXFLAGS'))
15
16 ######################################################################
17 # Build flags
18 ######################################################################
19 libcoap_env.PrependUnique(CPPPATH = [
20                 '../ocsocket/include',
21                 '../ocmalloc/include',
22                 '../logger/include',
23                 '../ocrandom/include',
24                 '../stack',
25                 '../../oc_logger/include'
26                 ])
27
28 if target_os not in ['arduino', 'windows', 'winrt']:
29         libcoap_env.AppendUnique(CPPDEFINES = ['WITH_POSIX'])
30         libcoap_env.AppendUnique(CFLAGS = ['-std=gnu99', '-fPIC'])
31
32 if target_os not in ['windows', 'winrt']:
33         libcoap_env.AppendUnique(CFLAGS = ['-Wall', '-ffunction-sections',
34                         '-fdata-sections', '-fno-exceptions'])
35
36 if target_os == 'android':
37         libcoap_env.AppendUnique(LIBS = ['log'])
38
39 if target_os == 'arduino':
40         libcoap_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
41
42 if target_os in ['darwin', 'ios']:
43         libcoap_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
44
45 if not env.get('RELEASE'):
46         libcoap_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
47
48 ######################################################################
49 # Source files and Target(s)
50 ######################################################################
51 libcoap_src = [
52         'pdu.c',
53         'net.c',
54         'debug.c',
55         'encode.c',
56         'uri.c',
57         'coap_list.c',
58 #       'resource.c',
59         'hashkey.c',
60     'str.c',
61         'option.c',
62         'async.c',
63         'subscribe.c',
64         'block.c',
65         '../logger/src/logger.c',
66         '../ocrandom/src/ocrandom.c',
67         '../ocmalloc/src/ocmalloc.c',
68         '../../oc_logger/c/oc_logger.c',
69         '../../oc_logger/c/oc_console_logger.c'
70         ]
71
72 if target_os == 'arduino':
73         if env.get('NET') == 'Wifi':
74                 libcoap_src.append(['../ocsocket/src/ocsocket_arduino_wifi.cpp'])
75         else:
76                 libcoap_src.append(['../ocsocket/src/ocsocket_arduino.cpp'])
77 else:
78         libcoap_src.append(['../ocsocket/src/ocsocket.c'])
79
80 if target_os == 'arduino':
81         libcoap = libcoap_env.StaticLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
82 else:
83         libcoap = libcoap_env.SharedLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
84
85 libcoap_env.InstallTarget(libcoap, 'libcoap')