1 ################################################################################
3 # Copyright 2016 Intel Corporation
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 ################################################################################
22 # 'libcoap' script to check if LibCoAP library is installed. If not,
23 # get it and install it
32 libcoap_env = env.Clone()
33 target_os = libcoap_env.get('TARGET_OS')
34 src_dir = libcoap_env.get('SRC_DIR')
35 ca_transport = libcoap_env.get('TARGET_TRANSPORT')
36 with_tcp = libcoap_env.get('WITH_TCP')
37 with_upstream_libcoap = libcoap_env.get('WITH_UPSTREAM_LIBCOAP')
39 # Temporary LibCoAP URL is a fork of the original.
40 # Once a pull request is merged, change this back to the obgm original below.
41 libcoap_repo_url = 'https://github.com/dthaler/libcoap'
42 #libcoap_repo_url = 'https://github.com/obgm/libcoap'
44 ######################################################################
46 ######################################################################
47 libcoap_branch = 'develop'
48 libcoap_dir = os.path.join(src_dir, 'extlibs', 'libcoap', 'libcoap')
49 libcoap_zip_file = os.path.join(src_dir, 'extlibs', 'libcoap', libcoap_branch + '.zip')
50 libcoap_url = libcoap_repo_url + '/archive/' + libcoap_branch + '.zip'
51 libcoap_checkout_command = 'git clone ' + libcoap_repo_url + '.git extlibs/libcoap/libcoap --branch ' + libcoap_branch
53 if with_upstream_libcoap == '1':
54 print '*** Checking for installation of libCoAP ***'
55 if not os.path.exists(libcoap_dir):
56 # If the libcoap zip file is not already present, download it
57 if not os.path.exists(libcoap_zip_file):
58 libcoap_zip = libcoap_env.Download(libcoap_zip_file, libcoap_url)
60 libcoap_zip = libcoap_zip_file
62 if libcoap_zip and not os.path.exists(os.path.join(libcoap_dir, 'configure')):
63 print 'Unzipping libCoAP'
64 env.UnpackAll(libcoap_dir, libcoap_zip)
66 libcoap_unzip_dir = os.path.join(src_dir, 'extlibs', 'libcoap', 'libcoap-' + libcoap_branch)
67 if os.path.exists(os.path.join(libcoap_unzip_dir)):
68 os.rename(libcoap_unzip_dir, libcoap_dir)
69 if not os.path.exists(os.path.join(libcoap_dir, 'README')):
71 *********************************** Error: ****************************************
72 * Unable to download and unpack libcoap! *
73 * Please download libcoap using the following command: *
75 ''' + libcoap_checkout_command + '''
77 ***********************************************************************************'''
81 *********************************** Info: *****************************************
82 * Using FORKED copy of libCoap located in: *
83 * resource/csdk/connectivity/lib/libcoap-4.1.1 *
84 ***********************************************************************************'''
86 ######################################################################
88 ######################################################################
89 # As in the source code(C) includes arduino Time library head file(C++)
90 # It requires compile the .c with g++
91 if target_os == 'arduino':
92 libcoap_env.Replace(CFLAGS = libcoap_env.get('CXXFLAGS'))
93 libcoap_env.PrependUnique(CPPPATH = [
95 env.get('ARDUINO_HOME') + '/',
96 env.get('ARDUINO_HOME') + '/hardware/arduino/avr/cores/arduino',
97 env.get('ARDUINO_HOME') + '/hardware/tools/avr/avr/include/',
98 env.get('ARDUINO_HOME') + '/hardware/arduino/avr/variants/mega',
99 env.get('ARDUINO_HOME') + '/libraries/Time/Time',
100 env.get('ARDUINO_HOME') + '/libraries/TimedAction',
101 env.get('ARDUINO_HOME') + '/hardware/arduino/avr/libraries/SPI',
102 env.get('ARDUINO_HOME') + '/libraries/Ethernet/src/utility',
106 if target_os not in ['arduino', 'windows', 'winrt', 'msys_nt']:
107 libcoap_env.AppendUnique(CPPDEFINES = ['WITH_POSIX', '_DEFAULT_SOURCE'])
108 libcoap_env.AppendUnique(CFLAGS = ['-std=gnu99','-fPIC'])
110 if target_os not in ['windows', 'winrt']:
111 libcoap_env.AppendUnique(CFLAGS = ['-Wall', '-ffunction-sections',
112 '-fdata-sections', '-fno-exceptions'])
114 if target_os == 'msys_nt':
115 libcoap_env.AppendUnique(CPPDEFINES = ['_DEFAULT_SOURCE'])
116 libcoap_env.AppendUnique(CFLAGS = ['-std=c99'])
118 if target_os in ['linux', 'tizen', 'android', 'ios', 'arduino']:
120 libcoap_env.AppendUnique(CPPDEFINES = ['WITH_TCP'])
122 if target_os in ['linux', 'tizen', 'android', 'arduino']:
123 libcoap_env.AppendUnique(LIBS = ['log'])
124 if (('BLE' in ca_transport) or ('BT' in ca_transport) or ('ALL' in ca_transport)):
125 libcoap_env.AppendUnique(CPPDEFINES = ['WITH_TCP'])
127 if target_os == 'arduino':
128 libcoap_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
130 if target_os in ['darwin', 'ios']:
131 libcoap_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
133 if env.get('LOGGING') == '1':
134 libcoap_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
136 ######################################################################
137 # Source files and Target(s)
138 ######################################################################
139 with_upstream_libcoap = libcoap_env.get('WITH_UPSTREAM_LIBCOAP')
140 if with_upstream_libcoap == '1':
141 libcoap_env.PrependUnique(CPPPATH = ['libcoap/include/coap'])
142 libcoap_env.AppendUnique(CPPDEFINES = ['WITH_UPSTREAM_LIBCOAP'])
143 libcoap_src_root = os.path.join(libcoap_dir, 'src')
145 # We need to generate coap.h from coap.h.in
146 coap_h_pc_file = os.path.join(libcoap_dir, 'include', 'coap', 'coap.h.in')
147 coap_h_output = os.path.join(libcoap_dir, 'include', 'coap', 'coap.h')
149 libcoap_version = libcoap_branch
150 lib_prefix = '' + str(libcoap_env.get('PREFIX'))
152 '\@LIBCOAP_PACKAGE_NAME\@' : lib_prefix + 'coap',
153 '\@LIBCOAP_PACKAGE_STRING\@' : lib_prefix + 'coap-' + libcoap_version,
154 '\@LIBCOAP_PACKAGE_URL\@' : libcoap_repo_url,
155 '\@LIBCOAP_PACKAGE_BUGREPORT\@' : libcoap_repo_url + '/issues',
156 '\@LIBCOAP_PACKAGE_VERSION\@' : libcoap_version
158 libcoap_env.Substfile(coap_h_pc_file, SUBST_DICT = pc_vars)
160 libcoap_src = glob.glob(os.path.join(libcoap_src_root, '*.c'))
161 libcoap_src.remove(os.path.join(libcoap_src_root, 'coap_io_lwip.c'))
163 # For bring up purposes only, the forked version will live here.
164 libcoap_src_root = src_dir + '/resource/csdk/connectivity/lib/libcoap-4.1.1'
165 libcoap_src = glob.glob(os.path.join(libcoap_src_root, '*.c'))
167 libcoap = libcoap_env.StaticLibrary('coap', libcoap_src, OBJPREFIX='libcoap_')
169 libcoap_env.InstallTarget([libcoap], 'coap')