@@ -18,7 +18,7 @@ def options(ctx):
18
18
# Set libcsp options
19
19
gr = ctx .add_option_group ('libcsp options' )
20
20
gr .add_option ('--includes' , default = '' , help = 'Add additional include paths, separate with comma' )
21
- gr .add_option ('--abi' , default = 'hard ' , help = 'Add additional CFLAG for floating point abi. Must be one of: ' + str (valid_float_abi ))
21
+ gr .add_option ('--abi' , default = '' , help = 'Add additional CFLAG for floating point abi. Must be one of: ' + str (valid_float_abi ))
22
22
gr .add_option ('--enable-reproducible-builds' , action = 'store_true' , help = 'Enable reproducible builds' )
23
23
24
24
gr .add_option ('--disable-output' , action = 'store_true' , help = 'Disable CSP output' )
@@ -95,283 +95,9 @@ def configure(ctx):
95
95
ctx .define_cond ('CSP_POSIX' , ctx .options .with_os == 'posix' )
96
96
97
97
# Floating point
98
- if ctx .options .abi == 'hard' :
99
- ctx .env .prepend_value ('CFLAGS' , ["-mfloat-abi=hard" ,
100
- "-mcpu=cortex-m4" , "-mthumb" ,
101
- "-mfpu=fpv4-sp-d16" ,"-mcpu=cortex-m4" ,
102
- "-ffunction-sections" , "-fdata-sections" ,
103
- "-fPIC" , "-fstack-usage" ])
104
-
105
- # Add files
106
- ctx .env .append_unique ('FILES_CSP' , ['src/crypto/csp_hmac.c' ,
107
- 'src/crypto/csp_sha1.c' ,
108
- 'src/csp_buffer.c' ,
109
- 'src/csp_bridge.c' ,
110
- 'src/csp_conn.c' ,
111
- 'src/csp_crc32.c' ,
112
- 'src/csp_debug.c' ,
113
- 'src/csp_dedup.c' ,
114
- 'src/csp_iflist.c' ,
115
- 'src/csp_init.c' ,
116
- 'src/csp_io.c' ,
117
- 'src/csp_port.c' ,
118
- 'src/csp_qfifo.c' ,
119
- 'src/csp_route.c' ,
120
- 'src/csp_service_handler.c' ,
121
- 'src/csp_services.c' ,
122
- 'src/csp_id.c' ,
123
- 'src/csp_sfp.c' ,
124
- 'src/interfaces/csp_if_lo.c' ,
125
- 'src/interfaces/csp_if_can.c' ,
126
- 'src/interfaces/csp_if_can_pbuf.c' ,
127
- 'src/interfaces/csp_if_kiss.c' ,
128
- 'src/interfaces/csp_if_i2c.c' ,
129
- 'src/arch/{0}/**/*.c' .format (ctx .options .with_os ),
130
- ])
131
-
132
- # Add if rtable
133
- if ctx .options .enable_rtable :
134
- ctx .env .append_unique ('FILES_CSP' , ['src/csp_rtable_cidr.c' ])
135
- # Add if stdio
136
- if ctx .check (header_name = "stdio.h" , mandatory = False ):
137
- ctx .define ('CSP_HAVE_STDIO' , True )
138
- ctx .env .append_unique ('FILES_CSP' , ['src/csp_rtable_stdio.c' ])
139
-
140
- # Add if UDP
141
- if ctx .check (header_name = "sys/socket.h" , mandatory = False ) and ctx .check (header_name = "arpa/inet.h" , mandatory = False ):
142
- ctx .env .append_unique ('FILES_CSP' , ['src/interfaces/csp_if_udp.c' ])
143
-
144
- if not ctx .options .disable_output :
145
- ctx .env .append_unique ('FILES_CSP' , ['src/csp_hex_dump.c' ])
146
-
147
- if ctx .options .enable_promisc :
148
- ctx .env .append_unique ('FILES_CSP' , ['src/csp_promisc.c' ])
149
-
150
- if ctx .options .enable_rdp :
151
- ctx .env .append_unique ('FILES_CSP' , ['src/csp_rdp.c' ,
152
- 'src/csp_rdp_queue.c' ])
153
-
154
- # Add YAML
155
- if ctx .options .enable_yaml :
156
- ctx .check_cfg (package = 'yaml-0.1' , args = '--cflags --libs' , define_name = 'CSP_HAVE_LIBYAML' )
157
- ctx .env .append_unique ('LIBS' , ctx .env .LIB_LIBYAML )
158
- ctx .env .append_unique ('FILES_CSP' , 'src/csp_yaml.c' )
159
-
160
- # Add socketcan
161
- if ctx .options .enable_can_socketcan :
162
- ctx .env .append_unique ('FILES_CSP' , 'src/drivers/can/can_socketcan.c' )
163
- ctx .check_cfg (package = 'libsocketcan' , args = '--cflags --libs' , define_name = 'CSP_HAVE_LIBSOCKETCAN' )
164
- ctx .env .append_unique ('LIBS' , ctx .env .LIB_LIBSOCKETCAN )
165
-
166
- # Add USART driver
167
- if ctx .options .with_driver_usart :
168
- ctx .env .append_unique ('FILES_CSP' , ['src/drivers/usart/usart_kiss.c' ,
169
- 'src/drivers/usart/usart_{0}.c' .format (ctx .options .with_driver_usart )])
170
-
171
- # Add ZMQ
172
- if ctx .options .enable_if_zmqhub :
173
- ctx .check_cfg (package = 'libzmq' , args = '--cflags --libs' , define_name = 'CSP_HAVE_LIBZMQ' )
174
- ctx .env .append_unique ('LIBS' , ctx .env .LIB_LIBZMQ )
175
- ctx .env .append_unique ('FILES_CSP' , 'src/interfaces/csp_if_zmqhub.c' )
176
-
177
- # Store configuration options
178
- ctx .env .ENABLE_EXAMPLES = ctx .options .enable_examples
179
-
180
- # Add Python bindings
181
- if ctx .options .enable_python3_bindings :
182
- ctx .check_python_version ((3 ,5 ))
183
- ctx .check_python_headers (features = 'pyext' )
184
-
185
- # Set defines for customizable parameters
186
- ctx .define ('CSP_QFIFO_LEN' , ctx .options .with_router_queue_length )
187
- ctx .define ('CSP_PORT_MAX_BIND' , ctx .options .with_max_bind_port )
188
- ctx .define ('CSP_CONN_RXQUEUE_LEN' , ctx .options .with_conn_queue_length )
189
- ctx .define ('CSP_CONN_MAX' , ctx .options .with_max_connections )
190
- ctx .define ('CSP_BUFFER_SIZE' , ctx .options .with_buffer_size )
191
- ctx .define ('CSP_BUFFER_COUNT' , ctx .options .with_buffer_count )
192
- ctx .define ('CSP_RDP_MAX_WINDOW' , ctx .options .with_rdp_max_window )
193
- ctx .define ('CSP_RTABLE_SIZE' , ctx .options .with_rtable_size )
194
-
195
- # Set defines for enabling features
196
- ctx .define ('CSP_REPRODUCIBLE_BUILDS' , ctx .options .enable_reproducible_builds )
197
- ctx .define ('CSP_ENABLE_CSP_PRINT' , not ctx .options .disable_output )
198
- ctx .define ('CSP_PRINT_STDIO' , not ctx .options .disable_print_stdio )
199
- ctx .define ('CSP_USE_RDP' , ctx .options .enable_rdp )
200
- ctx .define ('CSP_USE_HMAC' , ctx .options .enable_hmac )
201
- ctx .define ('CSP_USE_PROMISC' , ctx .options .enable_promisc )
202
- ctx .define ('CSP_USE_RTABLE' , ctx .options .enable_rtable )
203
-
204
-
205
- ctx .write_config_header ('include/csp/autoconfig.h' )
206
-
207
- def build (ctx ):
208
-
209
- # Set install path for header files
210
- install_path = None
211
- if ctx .is_install :
212
- install_path = '${PREFIX}/lib'
213
- ctx .install_files ('${PREFIX}/include/csp' ,
214
- ctx .path .ant_glob ('include/csp/**/*.h' ),
215
- cwd = ctx .path .find_dir ('include/csp' ),
216
- relative_trick = True )
217
- ctx .install_files ('${PREFIX}/include/csp' , 'include/csp/autoconfig.h' , cwd = ctx .bldnode )
218
-
219
- ctx (export_includes = ctx .env .INCLUDES_CSP , name = 'csp_h' )
220
-
221
- ctx (features = ctx .env .FEATURES ,
222
- source = ctx .path .ant_glob (ctx .env .FILES_CSP ),
223
- target = 'csp' ,
224
- use = ['csp_h' , 'freertos_h' , 'util' ],
225
- install_path = install_path )
226
-
227
- # Build shared library
228
- if ctx .env .LIBCSP_SHLIB or ctx .env .HAVE_PYEXT :
229
- ctx .shlib (source = ctx .path .ant_glob (ctx .env .FILES_CSP ),
230
- name = 'csp_shlib' ,
231
- target = 'csp' ,
232
- use = ['csp_h' , 'util_shlib' ],
233
- lib = ctx .env .LIBS )
234
-
235
- # Build Python bindings
236
- if ctx .env .HAVE_PYEXT :
237
- ctx .shlib (source = ctx .path .ant_glob ('src/bindings/python/**/*.c' ),
238
- target = 'libcsp_py3' ,
239
- features = 'pyext' ,
240
- use = ['csp_shlib' ],
241
- pytest_path = [ctx .path .get_bld ()])
242
-
243
- if ctx .env .ENABLE_EXAMPLES :
244
- ctx .program (source = ['examples/csp_server_client.c' ,
245
- 'examples/csp_server_client_{0}.c' .format (ctx .env .OS )],
246
- target = 'examples/csp_server_client' ,
247
- lib = ctx .env .LIBS ,
248
- use = 'csp' )
249
-
250
- ctx .program (source = ['examples/csp_server.c' ,
251
- 'examples/csp_server_{0}.c' .format (ctx .env .OS )],
252
- target = 'examples/csp_server' ,
253
- lib = ctx .env .LIBS ,
254
- use = 'csp' )
255
-
256
- ctx .program (source = ['examples/csp_client.c' ,
257
- 'examples/csp_client_{0}.c' .format (ctx .env .OS )],
258
- target = 'examples/csp_client' ,
259
- lib = ctx .env .LIBS ,
260
- use = 'csp' )
261
-
262
- ctx .program (source = 'examples/csp_arch.c' ,
263
- target = 'examples/csp_arch' ,
264
- lib = ctx .env .LIBS ,
265
- use = 'csp' )
266
-
267
- if ctx .env .CSP_HAVE_LIBZMQ :
268
- ctx .program (source = 'examples/zmqproxy.c' ,
269
- target = 'examples/zmqproxy' ,
270
- lib = ctx .env .LIBS ,
271
- use = 'csp' )
272
-
273
-
274
- def dist (ctx ):
275
- ctx .excl = 'build/* **/.* **/*.pyc **/*.o **/*~ *.tar.gz'
276
- #!/usr/bin/env python
277
- # encoding: utf-8
278
-
279
- import os
280
-
281
- APPNAME = 'libcsp'
282
- VERSION = '2.1'
283
-
284
- valid_os = ['posix' , 'freertos' ]
285
- valid_float_abi = ['hard' , 'soft' , 'softfp' ]
286
-
287
- def options (ctx ):
288
- # Load compiler
289
- ctx .load ('compiler_c' )
290
-
291
- ctx .add_option ('--toolchain' , default = None , help = 'Set toolchain prefix' )
292
-
293
- # Set libcsp options
294
- gr = ctx .add_option_group ('libcsp options' )
295
- gr .add_option ('--includes' , default = '' , help = 'Add additional include paths, separate with comma' )
296
- gr .add_option ('--abi' , default = 'hard' , help = 'Add additional CFLAG for floating point abi. Must be one of: ' + str (valid_float_abi ))
297
- gr .add_option ('--enable-reproducible-builds' , action = 'store_true' , help = 'Enable reproducible builds' )
298
-
299
- gr .add_option ('--disable-output' , action = 'store_true' , help = 'Disable CSP output' )
300
- gr .add_option ('--disable-print-stdio' , action = 'store_true' , help = 'Disable vprintf for csp_print_func' )
301
- gr .add_option ('--disable-stlib' , action = 'store_true' , help = 'Build objects only' )
302
- gr .add_option ('--enable-shlib' , action = 'store_true' , help = 'Build shared library' )
303
- gr .add_option ('--enable-rdp' , action = 'store_true' , help = 'Enable RDP support' )
304
- gr .add_option ('--enable-promisc' , action = 'store_true' , help = 'Enable promiscuous support' )
305
- gr .add_option ('--enable-crc32' , action = 'store_true' , help = 'Enable CRC32 support' )
306
- gr .add_option ('--enable-hmac' , action = 'store_true' , help = 'Enable HMAC-SHA1 support' )
307
- gr .add_option ('--enable-rtable' , action = 'store_true' , help = 'Allows to setup a list of static routes' )
308
- gr .add_option ('--enable-python3-bindings' , action = 'store_true' , help = 'Enable Python3 bindings' )
309
- gr .add_option ('--enable-examples' , action = 'store_true' , help = 'Enable examples' )
310
- gr .add_option ('--enable-dedup' , action = 'store_true' , help = 'Enable packet deduplicator' )
311
- gr .add_option ('--enable-yaml' , action = 'store_true' , help = 'Enable YAML configurator' )
312
- gr .add_option ('--with-rdp-max-window' , type = int , default = 5 , help = 'Set maximum window size for RDP' )
313
- gr .add_option ('--with-max-bind-port' , type = int , default = 16 , help = 'Set maximum bindable port' )
314
- gr .add_option ('--with-max-connections' , type = int , default = 8 , help = 'Set maximum number of connections' )
315
- gr .add_option ('--with-conn-queue-length' , type = int , default = 15 , help = 'Set max connection queue length' )
316
- gr .add_option ('--with-router-queue-length' , type = int , default = 15 , help = 'Set max router queue length' )
317
- gr .add_option ('--with-buffer-size' , type = int , default = 256 , help = 'Set size of csp buffers' )
318
- gr .add_option ('--with-buffer-count' , type = int , default = 15 , help = 'Set number of csp buffers' )
319
- gr .add_option ('--with-rtable-size' , type = int , default = 10 , help = 'Set max number of entries in route table' )
320
-
321
- # Drivers and interfaces (requires external dependencies)
322
- gr .add_option ('--enable-if-zmqhub' , action = 'store_true' , help = 'Enable ZMQ interface' )
323
- gr .add_option ('--enable-can-socketcan' , action = 'store_true' , help = 'Enable Linux socketcan driver' )
324
- gr .add_option ('--with-driver-usart' , default = None , metavar = 'DRIVER' , help = 'Build USART driver. [linux, None]' )
325
-
326
- # OS
327
- gr .add_option ('--with-os' , metavar = 'OS' , default = 'posix' , help = 'Set operating system. Must be one of: ' + str (valid_os ))
328
-
329
-
330
- def configure (ctx ):
331
- # Validate options
332
- if ctx .options .with_os not in valid_os :
333
- ctx .fatal ('--with-os must be either: ' + str (valid_os ))
334
-
335
- # Setup and validate toolchain
336
- if (len (ctx .stack_path ) <= 1 ) and ctx .options .toolchain :
337
- ctx .env .CC = ctx .options .toolchain + 'gcc'
338
- ctx .env .AR = ctx .options .toolchain + 'ar'
339
-
340
- ctx .load ('compiler_c python' )
341
-
342
- # Set git revision define
343
- git_rev = os .popen ('git describe --long --always 2> /dev/null || echo unknown' ).read ().strip ()
344
- ctx .define ('GIT_REV' , git_rev )
345
-
346
- # Set build output format
347
- ctx .env .FEATURES = ['c' ]
348
- if not ctx .options .disable_stlib :
349
- ctx .env .FEATURES += ['cstlib' ]
350
-
351
- ctx .env .LIBCSP_SHLIB = ctx .options .enable_shlib
352
-
353
- # Setup CFLAGS
354
- if (len (ctx .stack_path ) <= 1 ) and (len (ctx .env .CFLAGS ) == 0 ):
355
- ctx .env .prepend_value ('CFLAGS' , ["-std=gnu11" , "-g" , "-Os" , "-Wall" , "-Wextra" , "-Wshadow" , "-Wcast-align" ,
356
- "-Wpointer-arith" ,
357
- "-Wwrite-strings" , "-Wno-unused-parameter" , "-Werror" ])
358
-
359
- # Setup default include path and any extra defined
360
- ctx .env .append_unique ('INCLUDES_CSP' , ['include' , 'src' ] + ctx .options .includes .split (',' ))
361
-
362
- # Store OS as env variable
363
- ctx .env .OS = ctx .options .with_os
364
-
365
- # Platform/OS specifics
366
- if ctx .options .with_os == 'posix' :
367
- ctx .env .append_unique ('LIBS' , ['rt' , 'pthread' , 'util' ])
368
-
369
- ctx .define_cond ('CSP_FREERTOS' , ctx .options .with_os == 'freertos' )
370
- ctx .define_cond ('CSP_POSIX' , ctx .options .with_os == 'posix' )
371
-
372
- # Floating point
373
- if ctx .options .abi == 'hard' :
374
- ctx .env .prepend_value ('CFLAGS' , ["-mfloat-abi=hard" ,
98
+ if (ctx .options .abi ) :
99
+ if (ctx .options .abi == 'hard' ) :
100
+ ctx .env .prepend_value ('CFLAGS' , ["-mfloat-abi=hard" ,
375
101
"-mcpu=cortex-m4" , "-mthumb" ,
376
102
"-mfpu=fpv4-sp-d16" ,"-mcpu=cortex-m4" ,
377
103
"-ffunction-sections" , "-fdata-sections" ,
0 commit comments