urbit/include/ent/meson.build

34 lines
1.0 KiB
Meson
Raw Normal View History

2018-12-27 21:27:28 +03:00
conf_data = configuration_data()
compiler = meson.get_compiler('c')
2018-12-27 21:56:10 +03:00
code = '''#include <stddef.h>
#include <inttypes.h> /* OSX sys/random.h needs Availability.h from this */
2018-12-27 21:27:28 +03:00
#include <sys/random.h>
int main() { return getentropy((void*)0, 0); }
'''
2018-12-27 21:56:10 +03:00
sysrandom = compiler.links(code, name : 'getentropy in sys/random.h')
conf_data.set('ENT_GE_SYSRANDOM', sysrandom)
code = '''#include <unistd.h>
int main() { return getentropy((void*)0, 0); }
'''
unistd = compiler.links(code, name : 'getentropy is in unistd.h')
conf_data.set('ENT_GE_UNISTD', unistd)
have_getentropy = sysrandom or unistd
conf_data.set('ENT_GETENTROPY', have_getentropy)
2018-12-27 21:27:28 +03:00
if not have_getentropy
code = '''#include <fcntl.h>
int main() { return -1 != open("/dev/urandom", O_RDONLY) ? 0 : 1; }
'''
2018-12-27 21:56:10 +03:00
use_urandom = compiler.run(code, name : 'can open /dev/urandom')
conf_data.set('ENT_URANDOM', use_urandom.returncode() == 0)
2018-12-27 21:27:28 +03:00
endif
configure_file(output : 'config.h',
configuration : conf_data,
install_dir : 'include/ent')
install_headers('ent.h', subdir : 'ent')