16586fc10SMatt Johnstonproject( 26586fc10SMatt Johnston 'libmctp', 'c', 36586fc10SMatt Johnston meson_version: '>= 1.1', 46586fc10SMatt Johnston version: '0.11', 56586fc10SMatt Johnston default_options: [ 66586fc10SMatt Johnston 'debug=true', 76586fc10SMatt Johnston 'optimization=g', 86586fc10SMatt Johnston 'warning_level=2', 96586fc10SMatt Johnston 'werror=true', 106586fc10SMatt Johnston 'tests=' + (meson.is_subproject() ? 'disabled' : 'enabled'), 116586fc10SMatt Johnston ], 126586fc10SMatt Johnston) 136586fc10SMatt Johnston 146586fc10SMatt Johnstonsources = [ 156586fc10SMatt Johnston 'core.c', 166586fc10SMatt Johnston 'alloc.c', 176586fc10SMatt Johnston] 186586fc10SMatt Johnston 196586fc10SMatt Johnstonheaders = [ 206586fc10SMatt Johnston 'libmctp.h', 216586fc10SMatt Johnston] 226586fc10SMatt Johnston 236586fc10SMatt Johnstonserial_sources = [ 246586fc10SMatt Johnston 'serial.c', 256586fc10SMatt Johnston 'crc-16-ccitt.c', 266586fc10SMatt Johnston] 276586fc10SMatt Johnston 286586fc10SMatt Johnstonserial_headers = [ 296586fc10SMatt Johnston 'libmctp-serial.h' 306586fc10SMatt Johnston] 316586fc10SMatt Johnston 326586fc10SMatt Johnstonastlpc_sources = [ 336586fc10SMatt Johnston 'astlpc.c', 346586fc10SMatt Johnston 'crc32.c', 356586fc10SMatt Johnston] 366586fc10SMatt Johnston 376586fc10SMatt Johnstonastlpc_headers = [ 386586fc10SMatt Johnston 'libmctp-astlpc.h', 396586fc10SMatt Johnston] 406586fc10SMatt Johnston 416586fc10SMatt Johnstonlibmctp_sources = sources 426586fc10SMatt Johnstonlibmctp_headers = headers 436586fc10SMatt Johnston 446586fc10SMatt Johnstonif get_option('bindings').contains('serial') 456586fc10SMatt Johnston libmctp_sources += serial_sources 466586fc10SMatt Johnston libmctp_headers += serial_headers 476586fc10SMatt Johnstonendif 486586fc10SMatt Johnstonif get_option('bindings').contains('astlpc') 496586fc10SMatt Johnston libmctp_sources += astlpc_sources 506586fc10SMatt Johnston libmctp_headers += astlpc_headers 516586fc10SMatt Johnstonendif 526586fc10SMatt Johnston 536586fc10SMatt Johnstoncompiler = meson.get_compiler('c') 546586fc10SMatt Johnston 55bbfcc6e1SMatt Johnstonif not get_option('custom_alloc') and get_option('default_alloc').require( 566586fc10SMatt Johnston compiler.links(''' 576586fc10SMatt Johnston #include <stdlib.h> 586586fc10SMatt Johnston void main() 596586fc10SMatt Johnston { 606586fc10SMatt Johnston free(malloc(4096)); 616586fc10SMatt Johnston } 626586fc10SMatt Johnston ''')).allowed() 636586fc10SMatt Johnston add_project_arguments('-DMCTP_DEFAULT_ALLOC', language : 'c') 646586fc10SMatt Johnstonendif 656586fc10SMatt Johnston 66bbfcc6e1SMatt Johnstonif get_option('custom_alloc') 67bbfcc6e1SMatt Johnston add_project_arguments('-DMCTP_CUSTOM_ALLOC', language : 'c') 68bbfcc6e1SMatt Johnstonendif 69bbfcc6e1SMatt Johnston 70*1250727fSMatt Johnstonif get_option('nolog') 71*1250727fSMatt Johnston add_project_arguments('-DMCTP_NOLOG', language : 'c') 72*1250727fSMatt Johnstonelse 73*1250727fSMatt Johnston libmctp_sources += ['log.c'] 74*1250727fSMatt Johnstonendif 75*1250727fSMatt Johnston 7663338a2eSMatt Johnstonfeat_fileio = get_option('fileio').require( 7763338a2eSMatt Johnston compiler.links(''' 7863338a2eSMatt Johnston #include <poll.h> 7963338a2eSMatt Johnston #include <unistd.h> 8063338a2eSMatt Johnston void main() 8163338a2eSMatt Johnston { 8263338a2eSMatt Johnston poll(NULL, 0, -1); 8363338a2eSMatt Johnston } 8463338a2eSMatt Johnston ''')) 8563338a2eSMatt Johnstonif feat_fileio.allowed() 866586fc10SMatt Johnston add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c') 876586fc10SMatt Johnstonendif 886586fc10SMatt Johnston 896586fc10SMatt Johnstonif get_option('syslog').require( 906586fc10SMatt Johnston compiler.links(''' 916586fc10SMatt Johnston #include <stdarg.h> 926586fc10SMatt Johnston #include <syslog.h> 936586fc10SMatt Johnston void check_vsyslog(int level, const char *fmt, ...) 946586fc10SMatt Johnston { 956586fc10SMatt Johnston va_list ap; 966586fc10SMatt Johnston va_start(ap, fmt); 976586fc10SMatt Johnston vsyslog(0, fmt, ap); 986586fc10SMatt Johnston va_end(ap); 996586fc10SMatt Johnston } 1006586fc10SMatt Johnston void main() 1016586fc10SMatt Johnston { 1026586fc10SMatt Johnston check_vsyslog(0, "\n"); 1036586fc10SMatt Johnston } 1046586fc10SMatt Johnston ''')).allowed() 1056586fc10SMatt Johnston add_project_arguments('-DMCTP_HAVE_SYSLOG', language : 'c') 1066586fc10SMatt Johnstonendif 1076586fc10SMatt Johnston 1086586fc10SMatt Johnstonif get_option('stdio').require( 1096586fc10SMatt Johnston compiler.links(''' 1106586fc10SMatt Johnston #include <stdarg.h> 1116586fc10SMatt Johnston #include <stdio.h> 1126586fc10SMatt Johnston void check_vsyslog(const char *fmt, ...) 1136586fc10SMatt Johnston { 1146586fc10SMatt Johnston va_list ap; 1156586fc10SMatt Johnston va_start(ap, fmt); 1166586fc10SMatt Johnston vprintf(fmt, ap); 1176586fc10SMatt Johnston va_end(ap); 1186586fc10SMatt Johnston } 1196586fc10SMatt Johnston void main() 1206586fc10SMatt Johnston { 1216586fc10SMatt Johnston check_vsyslog("\n"); 1226586fc10SMatt Johnston } 1236586fc10SMatt Johnston ''')).allowed() 1246586fc10SMatt Johnston add_project_arguments('-DMCTP_HAVE_STDIO', language : 'c') 1256586fc10SMatt Johnstonendif 1266586fc10SMatt Johnston 1276586fc10SMatt Johnston# pcap is necessary for mctp-demux-daemon to be functional 1286586fc10SMatt Johnstonpcap_dep = dependency('libpcap', required: false) 1296586fc10SMatt Johnston 1306586fc10SMatt Johnstonsystemd_dep = dependency('systemd', required: false) 1316586fc10SMatt Johnstonlibsystemd_dep = dependency('libsystemd', required: false) 1326586fc10SMatt Johnston 1336586fc10SMatt Johnstonlibmctp_include_dir = include_directories('.', is_system: true) 1346586fc10SMatt Johnstonlibmctp = library('mctp', 1356586fc10SMatt Johnston libmctp_sources, 1366586fc10SMatt Johnston include_directories: libmctp_include_dir, 1376586fc10SMatt Johnston version: meson.project_version(), 1386586fc10SMatt Johnston install: true, 1396586fc10SMatt Johnston) 1406586fc10SMatt Johnstoninstall_headers(libmctp_headers) 1416586fc10SMatt Johnston 1426586fc10SMatt Johnstonif systemd_dep.found() 1436586fc10SMatt Johnston unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir') 1446586fc10SMatt Johnston install_data('systemd/system/mctp-demux.service', install_dir: unitdir) 1456586fc10SMatt Johnston install_data('systemd/system/mctp-demux.socket', install_dir: unitdir) 1466586fc10SMatt Johnstonendif 1476586fc10SMatt Johnston 1486586fc10SMatt Johnstonimport('pkgconfig').generate(libmctp, 1496586fc10SMatt Johnston name: 'libmctp', 1506586fc10SMatt Johnston description: 'MCTP protocol implementation', 1516586fc10SMatt Johnston version: meson.project_version(), 1526586fc10SMatt Johnston) 1536586fc10SMatt Johnston 1546586fc10SMatt Johnstonlibmctp_dep = declare_dependency( 1556586fc10SMatt Johnston include_directories: libmctp_include_dir, 1566586fc10SMatt Johnston link_with: libmctp, 1576586fc10SMatt Johnston) 1586586fc10SMatt Johnston 15963338a2eSMatt Johnstonif feat_fileio.allowed() 1606586fc10SMatt Johnston subdir('utils') 16163338a2eSMatt Johnstonendif 1626586fc10SMatt Johnston 1636586fc10SMatt Johnstonif get_option('tests').allowed() 1646586fc10SMatt Johnston subdir('tests') 1656586fc10SMatt Johnstonendif 166