shrub/include/ent/meson.build

49 lines
1.4 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-31 20:19:28 +03:00
older_oses = get_option('support-older-oses')
2018-12-27 21:27:28 +03:00
2018-12-31 20:19:28 +03:00
if not older_oses
code = '''#include <stddef.h>
#include <inttypes.h> /* OSX sys/random.h needs Availability.h from this */
#include <sys/random.h>
2018-12-28 03:32:30 +03:00
int main() { return getentropy((void*)0, 0); }
'''
2018-12-31 20:19:28 +03:00
sysrandom = compiler.links(code, name : 'getentropy in sys/random.h')
conf_data.set('ENT_GE_SYSRANDOM', sysrandom)
2018-12-27 21:56:10 +03:00
2018-12-31 20:19:28 +03:00
if not 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)
endif
have_getentropy = sysrandom or unistd
conf_data.set('ENT_GETENTROPY', have_getentropy)
else
have_getentropy = false
endif
2018-12-27 21:27:28 +03:00
if not have_getentropy
2018-12-31 20:19:28 +03:00
code = '''#define _GNU_SOURCE
#include <asm/unistd.h>
#include <unistd.h>
#include <sys/syscall.h>
int main() { return !syscall(__NR_getrandom, (void*)0, 0, 0); }
2018-12-27 21:27:28 +03:00
'''
2018-12-31 20:19:28 +03:00
getrandom = compiler.links(code, name : 'getrandom syscall available')
conf_data.set('ENT_GETRANDOM', getrandom)
if not getrandom
code = '''#include <fcntl.h>
int main() { return open("/dev/urandom", O_RDONLY) >= 0 ? 0 : 1; }
'''
urandom = compiler.run(code, name : 'can open /dev/urandom').returncode() == 0
conf_data.set('ENT_URANDOM', urandom)
endif
2018-12-27 21:27:28 +03:00
endif
2018-12-31 20:19:28 +03:00
2018-12-27 21:27:28 +03:00
configure_file(output : 'config.h',
2018-12-28 03:50:27 +03:00
configuration : conf_data)