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', 17*4058b2cbSMatt Johnston 'control.c', 186586fc10SMatt Johnston] 196586fc10SMatt Johnston 206586fc10SMatt Johnstonheaders = [ 216586fc10SMatt Johnston 'libmctp.h', 226586fc10SMatt Johnston] 236586fc10SMatt Johnston 246586fc10SMatt Johnstonserial_sources = [ 256586fc10SMatt Johnston 'serial.c', 266586fc10SMatt Johnston 'crc-16-ccitt.c', 276586fc10SMatt Johnston] 286586fc10SMatt Johnston 296586fc10SMatt Johnstonserial_headers = [ 306586fc10SMatt Johnston 'libmctp-serial.h' 316586fc10SMatt Johnston] 326586fc10SMatt Johnston 336586fc10SMatt Johnstonastlpc_sources = [ 346586fc10SMatt Johnston 'astlpc.c', 356586fc10SMatt Johnston 'crc32.c', 366586fc10SMatt Johnston] 376586fc10SMatt Johnston 386586fc10SMatt Johnstonastlpc_headers = [ 396586fc10SMatt Johnston 'libmctp-astlpc.h', 406586fc10SMatt Johnston] 416586fc10SMatt Johnston 42e5b941d9SMatt Johnstoni2c_sources = [ 43e5b941d9SMatt Johnston 'i2c.c', 44e5b941d9SMatt Johnston] 45e5b941d9SMatt Johnston 46e5b941d9SMatt Johnstoni2c_headers = [ 47e5b941d9SMatt Johnston 'libmctp-i2c.h', 48e5b941d9SMatt Johnston] 49*4058b2cbSMatt Johnstoncontrol_sources = [ 50*4058b2cbSMatt Johnston 'control.c', 51*4058b2cbSMatt Johnston] 52e5b941d9SMatt Johnston 536586fc10SMatt Johnstonlibmctp_sources = sources 546586fc10SMatt Johnstonlibmctp_headers = headers 556586fc10SMatt Johnston 566586fc10SMatt Johnstonif get_option('bindings').contains('serial') 576586fc10SMatt Johnston libmctp_sources += serial_sources 586586fc10SMatt Johnston libmctp_headers += serial_headers 596586fc10SMatt Johnstonendif 606586fc10SMatt Johnstonif get_option('bindings').contains('astlpc') 616586fc10SMatt Johnston libmctp_sources += astlpc_sources 626586fc10SMatt Johnston libmctp_headers += astlpc_headers 636586fc10SMatt Johnstonendif 64e5b941d9SMatt Johnstonif get_option('bindings').contains('i2c') 65e5b941d9SMatt Johnston libmctp_sources += i2c_sources 66e5b941d9SMatt Johnston libmctp_headers += i2c_headers 67e5b941d9SMatt Johnstonendif 68*4058b2cbSMatt Johnstonif get_option('control') 69*4058b2cbSMatt Johnston libmctp_sources += control_sources 70*4058b2cbSMatt Johnstonendif 716586fc10SMatt Johnston 726586fc10SMatt Johnstoncompiler = meson.get_compiler('c') 736586fc10SMatt Johnston 74bbfcc6e1SMatt Johnstonif not get_option('custom_alloc') and get_option('default_alloc').require( 756586fc10SMatt Johnston compiler.links(''' 766586fc10SMatt Johnston #include <stdlib.h> 776586fc10SMatt Johnston void main() 786586fc10SMatt Johnston { 796586fc10SMatt Johnston free(malloc(4096)); 806586fc10SMatt Johnston } 816586fc10SMatt Johnston ''')).allowed() 826586fc10SMatt Johnston add_project_arguments('-DMCTP_DEFAULT_ALLOC', language : 'c') 836586fc10SMatt Johnstonendif 846586fc10SMatt Johnston 85bbfcc6e1SMatt Johnstonif get_option('custom_alloc') 86bbfcc6e1SMatt Johnston add_project_arguments('-DMCTP_CUSTOM_ALLOC', language : 'c') 87bbfcc6e1SMatt Johnstonendif 88bbfcc6e1SMatt Johnston 891250727fSMatt Johnstonif get_option('nolog') 901250727fSMatt Johnston add_project_arguments('-DMCTP_NOLOG', language : 'c') 911250727fSMatt Johnstonelse 921250727fSMatt Johnston libmctp_sources += ['log.c'] 931250727fSMatt Johnstonendif 941250727fSMatt Johnston 9563338a2eSMatt Johnstonfeat_fileio = get_option('fileio').require( 9663338a2eSMatt Johnston compiler.links(''' 9763338a2eSMatt Johnston #include <poll.h> 9863338a2eSMatt Johnston #include <unistd.h> 9963338a2eSMatt Johnston void main() 10063338a2eSMatt Johnston { 10163338a2eSMatt Johnston poll(NULL, 0, -1); 10263338a2eSMatt Johnston } 10363338a2eSMatt Johnston ''')) 10463338a2eSMatt Johnstonif feat_fileio.allowed() 1056586fc10SMatt Johnston add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c') 1066586fc10SMatt Johnstonendif 1076586fc10SMatt Johnston 1086586fc10SMatt Johnstonif get_option('syslog').require( 1096586fc10SMatt Johnston compiler.links(''' 1106586fc10SMatt Johnston #include <stdarg.h> 1116586fc10SMatt Johnston #include <syslog.h> 1126586fc10SMatt Johnston void check_vsyslog(int level, const char *fmt, ...) 1136586fc10SMatt Johnston { 1146586fc10SMatt Johnston va_list ap; 1156586fc10SMatt Johnston va_start(ap, fmt); 1166586fc10SMatt Johnston vsyslog(0, fmt, ap); 1176586fc10SMatt Johnston va_end(ap); 1186586fc10SMatt Johnston } 1196586fc10SMatt Johnston void main() 1206586fc10SMatt Johnston { 1216586fc10SMatt Johnston check_vsyslog(0, "\n"); 1226586fc10SMatt Johnston } 1236586fc10SMatt Johnston ''')).allowed() 1246586fc10SMatt Johnston add_project_arguments('-DMCTP_HAVE_SYSLOG', language : 'c') 1256586fc10SMatt Johnstonendif 1266586fc10SMatt Johnston 1276586fc10SMatt Johnstonif get_option('stdio').require( 1286586fc10SMatt Johnston compiler.links(''' 1296586fc10SMatt Johnston #include <stdarg.h> 1306586fc10SMatt Johnston #include <stdio.h> 1316586fc10SMatt Johnston void check_vsyslog(const char *fmt, ...) 1326586fc10SMatt Johnston { 1336586fc10SMatt Johnston va_list ap; 1346586fc10SMatt Johnston va_start(ap, fmt); 1356586fc10SMatt Johnston vprintf(fmt, ap); 1366586fc10SMatt Johnston va_end(ap); 1376586fc10SMatt Johnston } 1386586fc10SMatt Johnston void main() 1396586fc10SMatt Johnston { 1406586fc10SMatt Johnston check_vsyslog("\n"); 1416586fc10SMatt Johnston } 1426586fc10SMatt Johnston ''')).allowed() 1436586fc10SMatt Johnston add_project_arguments('-DMCTP_HAVE_STDIO', language : 'c') 1446586fc10SMatt Johnstonendif 1456586fc10SMatt Johnston 1466586fc10SMatt Johnston# pcap is necessary for mctp-demux-daemon to be functional 1476586fc10SMatt Johnstonpcap_dep = dependency('libpcap', required: false) 1486586fc10SMatt Johnston 1496586fc10SMatt Johnstonsystemd_dep = dependency('systemd', required: false) 1506586fc10SMatt Johnstonlibsystemd_dep = dependency('libsystemd', required: false) 1516586fc10SMatt Johnston 1526586fc10SMatt Johnstonlibmctp_include_dir = include_directories('.', is_system: true) 1536586fc10SMatt Johnstonlibmctp = library('mctp', 1546586fc10SMatt Johnston libmctp_sources, 1556586fc10SMatt Johnston include_directories: libmctp_include_dir, 1566586fc10SMatt Johnston version: meson.project_version(), 1576586fc10SMatt Johnston install: true, 1586586fc10SMatt Johnston) 1596586fc10SMatt Johnstoninstall_headers(libmctp_headers) 1606586fc10SMatt Johnston 1616586fc10SMatt Johnstonif systemd_dep.found() 1626586fc10SMatt Johnston unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir') 1636586fc10SMatt Johnston install_data('systemd/system/mctp-demux.service', install_dir: unitdir) 1646586fc10SMatt Johnston install_data('systemd/system/mctp-demux.socket', install_dir: unitdir) 1656586fc10SMatt Johnstonendif 1666586fc10SMatt Johnston 1676586fc10SMatt Johnstonimport('pkgconfig').generate(libmctp, 1686586fc10SMatt Johnston name: 'libmctp', 1696586fc10SMatt Johnston description: 'MCTP protocol implementation', 1706586fc10SMatt Johnston version: meson.project_version(), 1716586fc10SMatt Johnston) 1726586fc10SMatt Johnston 1736586fc10SMatt Johnstonlibmctp_dep = declare_dependency( 1746586fc10SMatt Johnston include_directories: libmctp_include_dir, 1756586fc10SMatt Johnston link_with: libmctp, 1766586fc10SMatt Johnston) 1776586fc10SMatt Johnston 178e5b941d9SMatt Johnston# TODO: these should depend on the -internal.h headers so they rebuild 179e5b941d9SMatt Johnston# on changes, unclear how to do that. 180f9b99f1fSMatt Johnstonsizeof_mctp = compiler.sizeof('struct mctp', 181f9b99f1fSMatt Johnston include_directories: libmctp_include_dir, 182f9b99f1fSMatt Johnston prefix: '#include "core-internal.h"') 183e5b941d9SMatt Johnstonsizeof_binding_i2c = compiler.sizeof('struct mctp_binding_i2c', 184e5b941d9SMatt Johnston include_directories: libmctp_include_dir, 185e5b941d9SMatt Johnston prefix: '#include "i2c-internal.h"') 186f9b99f1fSMatt Johnstonsizes_h = configure_file(configuration: { 187f9b99f1fSMatt Johnston 'sizeof_struct_mctp': sizeof_mctp, 188e5b941d9SMatt Johnston 'sizeof_binding_i2c': sizeof_binding_i2c, 189f9b99f1fSMatt Johnston }, 190f9b99f1fSMatt Johnston input: 'libmctp-sizes.h.in', 191f9b99f1fSMatt Johnston output: 'libmctp-sizes.h', 192f9b99f1fSMatt Johnston ) 193f9b99f1fSMatt Johnstoninstall_headers(sizes_h) 194f9b99f1fSMatt Johnston 19563338a2eSMatt Johnstonif feat_fileio.allowed() 1966586fc10SMatt Johnston subdir('utils') 19763338a2eSMatt Johnstonendif 1986586fc10SMatt Johnston 1996586fc10SMatt Johnstonif get_option('tests').allowed() 2006586fc10SMatt Johnston subdir('tests') 2016586fc10SMatt Johnstonendif 202