Ed Tanous | cd9b1c5 | 2025-04-22 08:59:45 -0700 | [diff] [blame^] | 1 | conf = configuration_data() |
| 2 | check_headers = [ |
| 3 | 'dlfcn.h', |
| 4 | 'endian.h', |
| 5 | 'fcntl.h', |
| 6 | 'float.h', |
| 7 | 'inttypes.h', |
| 8 | 'limits.h', |
| 9 | 'memory.h', |
| 10 | 'stdarg.h', |
| 11 | 'stdint.h', |
| 12 | 'stdlib.h', |
| 13 | 'strings.h', |
| 14 | 'string.h', |
| 15 | 'syslog.h', |
| 16 | 'sys/cdefs.h', |
| 17 | 'sys/param.h', |
| 18 | 'sys/stat.h', |
| 19 | 'sys/types.h', |
| 20 | 'unistd.h', |
| 21 | 'xlocale.h', |
| 22 | ] |
| 23 | |
| 24 | foreach header : check_headers |
| 25 | if cc.has_header(header) |
| 26 | conf.set('HAVE_@0@'.format(header.underscorify().to_upper()), 1) |
| 27 | endif |
| 28 | endforeach |
| 29 | |
| 30 | have_stdc = true |
| 31 | foreach header : ['stdlib.h', 'stdarg.h', 'string.h', 'float.h'] |
| 32 | if not conf.has('HAVE_@0@'.format(header.underscorify().to_upper())) |
| 33 | have_stdc = false |
| 34 | endif |
| 35 | endforeach |
| 36 | conf.set10('STDC_HEADERS', have_stdc) |
| 37 | |
| 38 | foreach symbol : ['_isnan', '_finite'] |
| 39 | if cc.has_header_symbol('float.h', symbol) |
| 40 | conf.set('HAVE_DECL_@0@'.format(symbol.to_upper()), 1) |
| 41 | endif |
| 42 | endforeach |
| 43 | |
| 44 | foreach symbol : ['INFINITY', 'isinf', 'isnan', 'nan'] |
| 45 | if cc.has_header_symbol('math.h', symbol) |
| 46 | conf.set('HAVE_DECL_@0@'.format(symbol.to_upper()), 1) |
| 47 | endif |
| 48 | endforeach |
| 49 | |
| 50 | check_function = [ |
| 51 | 'vasprintf', |
| 52 | 'realloc', |
| 53 | 'strcasecmp', |
| 54 | 'strdup', |
| 55 | 'strerror', |
| 56 | 'vsyslog', |
| 57 | 'open', |
| 58 | 'strtoll', |
| 59 | ] |
| 60 | |
| 61 | if conf.has('HAVE_STRINGS_H') |
| 62 | check_function += 'strncasecmp' |
| 63 | endif |
| 64 | |
| 65 | foreach function : check_function |
| 66 | if cc.has_function(function) |
| 67 | conf.set('HAVE_@0@'.format(function.to_upper()), 1) |
| 68 | endif |
| 69 | endforeach |
| 70 | conf.set10('HAVE_DOPRNT', cc.has_function('_doprnt')) |
| 71 | |
| 72 | foreach f : ['snprintf', 'vsnprintf', 'vprintf'] |
| 73 | if cc.has_header_symbol('stdio.h', f) |
| 74 | conf.set('HAVE_@0@'.format(f.to_upper()), 1) |
| 75 | endif |
| 76 | endforeach |
| 77 | |
| 78 | size = cc.sizeof('size_t', prefix: '#include <stddef.h>') |
| 79 | conf.set('SIZEOF_SIZE_T', size) |
| 80 | |
| 81 | if cc.get_argument_syntax() == 'msvc' |
| 82 | size = cc.sizeof('SSIZE_T', prefix: '#include <BaseTsd.h>') |
| 83 | else |
| 84 | size = cc.sizeof('ssize_t', prefix: '#include <sys/types.h>') |
| 85 | endif |
| 86 | conf.set('SIZEOF_SSIZE_T', size) |
| 87 | |
| 88 | foreach type : ['int', 'int64_t', 'long', 'long long'] |
| 89 | size = cc.sizeof(type, prefix: '#include <stdint.h>') |
| 90 | conf.set('SIZEOF_@0@'.format(type.underscorify().to_upper()), size) |
| 91 | endforeach |
| 92 | |
| 93 | if cc.links('int main(){__sync_synchronize();}', name: 'atomic builtins') |
| 94 | conf.set('HAVE_ATOMIC_BUILTINS', 1) |
| 95 | endif |
| 96 | |
| 97 | if cc.compiles('static __thread int x = 0;', name: '__thread') |
| 98 | conf.set('HAVE___THREAD', 1) |
| 99 | endif |
| 100 | |
| 101 | if conf.has('HAVE___THREAD') |
| 102 | conf.set('SPEC___THREAD', '__thread') |
| 103 | elif cc.get_argument_syntax() == 'msvc' |
| 104 | conf.set('SPEC___THREAD', '__declspec(thread)') |
| 105 | endif |
| 106 | |
| 107 | conf.set_quoted('VERSION', meson.project_version()) |
| 108 | |
| 109 | config_h = configure_file(configuration: conf, output: 'config.h') |
| 110 | |