1 # Copyright (C) 2024 Mikulas Patocka
3 # This file is part of Ajla.
5 # Ajla is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 3 of the License, or (at your option) any later
10 # Ajla is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Ajla. If not, see <https://www.gnu.org/licenses/>.
18 # Process this file with autoconf to produce a configure script.
22 AC_CONFIG_SRCDIR(ajla.c)
23 AC_CONFIG_HEADERS(config.h)
24 AM_INIT_AUTOMAKE(-Wall -Werror)
26 if uname 2>/dev/null | grep -i OS/2 >/dev/null || uname 2>/dev/null | grep -i Dos >/dev/null; then
30 ACLOCAL="touch aclocal.m4; echo >/dev/null"
31 AUTOCONF="touch configure; echo >/dev/null"
32 AUTOMAKE="touch Makefile.in; echo >/dev/null"
33 AUTOHEADER="touch config.h.in; echo >/dev/null"
37 # Checks for programs.
40 CPPFLAGS="-D_GNU_SOURCE -D_ALL_SOURCE $CPPFLAGS"
44 CPPFLAGS="$CPPFLAGS -I/usr/local/include"
45 LDFLAGS="$LDFLAGS -L/usr/local/lib"
49 AC_CACHE_CHECK([for EMX], ac_cv_have_emx,
50 AC_TRY_COMPILE(, [#ifndef __EMX__
52 #endif ], ac_cv_have_emx=yes, ac_cv_have_emx=no)
54 AC_CACHE_CHECK([for WIN32], ac_cv_have_win32,
55 AC_TRY_COMPILE(, [#ifndef _WIN32
57 #endif ], ac_cv_have_win32=yes, ac_cv_have_win32=no)
59 AC_CACHE_CHECK([for Minix 3], ac_cv_have_minix3,
60 AC_TRY_COMPILE(, [#ifndef __minix__
62 #endif ], ac_cv_have_minix3=yes, ac_cv_have_minix3=no)
65 AC_ARG_ENABLE(threads, [ --disable-threads disable threads], enable_threads="$enableval", enable_threads=yes)
67 if test "$enable_threads" != no && test "$ac_cv_have_minix3" = no; then
68 if test "$enable_threads" = pthread || test "$ac_cv_have_emx" != yes -a "$ac_cv_have_win32" != yes; then
70 LIBS="$PTHREAD_LIBS $LIBS"
71 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
74 if test "$ax_pthread_ok" != yes -a "$ac_cv_have_emx" = yes; then
77 if test "$ax_pthread_ok" = yes -a "$enable_threads" = pthread; then
78 AC_DEFINE([HAVE_PTHREAD_PREFER], 1, [Prefer pthreads])
82 AC_ARG_ENABLE(computed-goto, [ --disable-computed-goto disable computed goto], enable_computed_goto="$enableval", enable_computed_goto=yes)
84 AC_ARG_ENABLE(bitwise-frame, [ --enable-bitwise-frame use bitwise tags on the frame], enable_bitwise_frame="$enableval", enable_bitwise_frame=no)
85 test "$enable_bitwise_frame" = yes && AC_DEFINE(HAVE_BITWISE_FRAME, 1, Use bitwise frame)
87 AC_ARG_ENABLE(debuglevel, [ --enable-debuglevel set internal checking level
89 1 - checks that don't degrade performane (default)
90 2 - checks that degrade performance
91 3 - checks that degrade performance seriously], enable_debuglevel="$enableval", enable_debuglevel=1)
92 if test "$enable_debuglevel" = no; then enable_debuglevel=0; fi
93 if test "$enable_debuglevel" = yes; then enable_debuglevel=2; fi
94 AC_DEFINE_UNQUOTED(HAVE_DEBUGLEVEL, $enable_debuglevel, Debugging level)
96 # Checks for typedefs, structures, and compiler characteristics.
102 AC_CACHE_CHECK(for __float128, ac_cv_have___float128,
104 volatile __float128 a = 0.1;
105 volatile __float128 b = 0.2;
106 volatile __float128 c, d, e, f;
107 volatile int g, h, i, j;
117 ], ac_cv_have___float128=yes, ac_cv_have___float128=no))
118 test "$ac_cv_have___float128" = yes && AC_DEFINE(HAVE___FLOAT128, 1, Have __float128)
120 AC_CACHE_CHECK(for signbit(__float128), ac_cv_have_signbit__float128,
123 volatile __float128 a = 0.1;
128 ], ac_cv_have_signbit__float128=yes, ac_cv_have_signbit__float128=no, ac_cv_have_signbit__float128=no))
129 test "$ac_cv_have_signbit__float128" = yes && AC_DEFINE(HAVE_SIGNBIT___FLOAT128, 1, Have signbit(__float128))
131 AC_CHECK_TYPES([max_align_t], [], [], [[#include <stddef.h>]])
132 AC_CHECK_TYPES([sig_atomic_t], [], [], [[#include <signal.h>]])
133 AC_CHECK_TYPES([sigset_t], [], [], [[#include <signal.h>]])
134 AC_CHECK_TYPES([socklen_t], [], [], [[
135 #include <sys/types.h>
136 #include <sys/socket.h>]])
137 AC_CHECK_TYPES([_Float16], [], [], [])
143 default_unsigned__int128=0
147 AC_CHECK_SIZEOF(unsigned short,"$default_short")
148 AC_CHECK_SIZEOF(unsigned, "$default_int")
149 AC_CHECK_SIZEOF(unsigned long, "$default_long")
150 AC_CHECK_SIZEOF(unsigned long long, "$default_long_long")
151 AC_CHECK_SIZEOF(unsigned __int128, "$default_unsigned__int128")
152 AC_CHECK_SIZEOF(void *, "$default_void")
153 AC_CHECK_SIZEOF(size_t, "$default_size_t")
155 if test "$ax_pthread_ok" = yes; then
156 AC_CACHE_CHECK([for PTHREAD_MUTEX_ERRORCHECK],
157 ax_cv_PTHREAD_MUTEX_ERRORCHECK, [
159 AC_LANG_PROGRAM([[#include <pthread.h>]], [[int i = PTHREAD_MUTEX_ERRORCHECK;]])],
160 [ax_cv_PTHREAD_MUTEX_ERRORCHECK=yes],
161 [ax_cv_PTHREAD_MUTEX_ERRORCHECK=no])
163 AS_IF([test "x$ax_cv_PTHREAD_MUTEX_ERRORCHECK" = "xyes"],
164 AC_DEFINE([HAVE_PTHREAD_MUTEX_ERRORCHECK], 1, [Have PTHREAD_MUTEX_ERRORCHECK]))
167 AC_CACHE_CHECK([for PTHREAD_MUTEX_ERRORCHECK_NP],
168 ax_cv_PTHREAD_MUTEX_ERRORCHECK_NP, [
170 AC_LANG_PROGRAM([[#include <pthread.h>]], [[int i = PTHREAD_MUTEX_ERRORCHECK_NP;]])],
171 [ax_cv_PTHREAD_MUTEX_ERRORCHECK_NP=yes],
172 [ax_cv_PTHREAD_MUTEX_ERRORCHECK_NP=no])
174 AS_IF([test "x$ax_cv_PTHREAD_MUTEX_ERRORCHECK_NP" = "xyes"],
175 AC_DEFINE([HAVE_PTHREAD_MUTEX_ERRORCHECK_NP], 1, [Have PTHREAD_MUTEX_ERRORCHECK_NP]))
177 AC_CACHE_CHECK([if we can assign to pthread_key_t],
178 ax_cv_pthread_key_t_assign, [
180 AC_LANG_PROGRAM([[#include <pthread.h>]], [[pthread_key_t key = (pthread_key_t)-1;]])],
181 [ax_cv_pthread_key_t_assign=yes],
182 [ax_cv_pthread_key_t_assign=no])
184 AS_IF([test "x$ax_cv_pthread_key_t_assign" = "xyes"],
185 AC_DEFINE([HAVE_PTHREAD_KEY_T_ASSIGN], 1, [Can assign to pthread_key_t]))
189 AC_CACHE_CHECK(for __thread, ac_cv_have___thread,
192 static __thread int j = 0;
195 ], ac_cv_have___thread=yes, ac_cv_have___thread=no))
196 test "$ac_cv_have___thread" = yes && AC_DEFINE(HAVE___THREAD, __thread, Have thread local storage)
198 AC_CACHE_CHECK(for computed goto, ac_cv_have_computed_goto,
201 static const void *dispatch[[4096]] = {
204 goto *(void *)dispatch[[10]];
207 #if defined(__GNUC__) && __GNUC__ <= 2
210 ], ac_cv_have_computed_goto=yes, ac_cv_have_computed_goto=no))
211 test "$ac_cv_have_computed_goto" = yes && test "$enable_computed_goto" != no && AC_DEFINE(HAVE_COMPUTED_GOTO, 1, Have computed goto)
213 if echo "$CC" | grep clang >/dev/null; then
214 AC_CACHE_CHECK(for -no-integrated-as, ac_cv_have_no_integrated_as,
215 save_CFLAGS="$CFLAGS"
216 CFLAGS="-no-integrated-as $CFLAGS"
217 AC_TRY_LINK([ ], [ ], ac_cv_have_no_integrated_as=yes, ac_cv_have_no_integrated_as=no)
218 CFLAGS="$save_CFLAGS"
220 test "$ac_cv_have_no_integrated_as" = yes && CFLAGS="-no-integrated-as $CFLAGS"
223 AC_CACHE_CHECK(for gcc assembler, ac_cv_have_gcc_assembler,
228 __asm__ (""::"i"(63355));
229 __asm__ volatile ("":::"memory");
230 __asm__ (".if 0 \n .endif" : "=r"(dest) : "0"(src));
235 ], ac_cv_have_gcc_assembler=yes, ac_cv_have_gcc_assembler=no))
236 test "$ac_cv_have_gcc_assembler" = yes && AC_DEFINE(HAVE_GCC_ASSEMBLER, 1, Have gcc assembler)
238 if test "$ac_cv_have_gcc_assembler" = yes; then
239 AC_CACHE_CHECK(for asm goto, ac_cv_have_asm_goto,
242 __asm__ goto("" : : : : label);
245 ], ac_cv_have_asm_goto=yes, ac_cv_have_asm_goto=no))
246 test "$ac_cv_have_asm_goto" = yes && AC_DEFINE(HAVE_ASM_GOTO, 1, Have asm goto)
248 if test "$ac_cv_sizeof_unsigned___int128" != 0; then
249 AC_CACHE_CHECK(for assembler __int128, ac_cv_have_assembler___int128,
252 volatile __int128 a, b;
254 #if defined(__aarch64__)
255 __asm__ ("mov %H0, %H1; mov %x0, %x1" : "=&r"(b) : "r"(a));
256 #elif defined(__x86_64__)
257 __asm__ ("" : "=A"(b) : "A"(a));
259 __asm__ ("" : "=r"(b) : "0"(a));
262 ], ac_cv_have_assembler___int128=yes, ac_cv_have_assembler___int128=no))
263 test "$ac_cv_have_assembler___int128" = yes && AC_DEFINE(HAVE_ASSEMBLER___INT128, 1, Have assembler __int128)
266 AC_CACHE_CHECK(for X86 assembler popcnt, ac_cv_have_x86_assembler_popcnt,
269 __asm__ volatile ("popcntw %%ax, %%bx \n popcntl %%eax, %%ebx":::"eax", "ebx", "cc");
270 ], ac_cv_have_x86_assembler_popcnt=yes, ac_cv_have_x86_assembler_popcnt=no))
271 test "$ac_cv_have_x86_assembler_popcnt" = yes && AC_DEFINE(HAVE_X86_ASSEMBLER_POPCNT, 1, Have X86 popcnt)
273 AC_CACHE_CHECK(for X86 assembler lzcnt, ac_cv_have_x86_assembler_lzcnt,
276 __asm__ volatile ("lzcntw %%ax, %%bx \n lzcntl %%eax, %%ebx":::"eax", "ebx", "cc");
277 ], ac_cv_have_x86_assembler_lzcnt=yes, ac_cv_have_x86_assembler_lzcnt=no))
278 test "$ac_cv_have_x86_assembler_lzcnt" = yes && AC_DEFINE(HAVE_X86_ASSEMBLER_LZCNT, 1, Have X86 lzcnt)
280 AC_CACHE_CHECK(for X86 assembler sse, ac_cv_have_x86_assembler_sse,
285 __asm__ volatile ("cvtss2si (%1), %0":"=r"(i):"r"(&a));
286 ], ac_cv_have_x86_assembler_sse=yes, ac_cv_have_x86_assembler_sse=no))
287 test "$ac_cv_have_x86_assembler_sse" = yes && AC_DEFINE(HAVE_X86_ASSEMBLER_SSE, 1, Have X86 sse)
289 AC_CACHE_CHECK(for X86 assembler sse2, ac_cv_have_x86_assembler_sse2,
294 __asm__ volatile ("cvtsd2si (%1), %0":"=r"(i):"r"(&a));
295 ], ac_cv_have_x86_assembler_sse2=yes, ac_cv_have_x86_assembler_sse2=no))
296 test "$ac_cv_have_x86_assembler_sse2" = yes && AC_DEFINE(HAVE_X86_ASSEMBLER_SSE2, 1, Have X86 sse2)
298 AC_CACHE_CHECK(for X86 assembler avx, ac_cv_have_x86_assembler_avx,
303 __asm__ volatile ("vcvtss2si (%1), %0":"=r"(i):"r"(&a));
304 ], ac_cv_have_x86_assembler_avx=yes, ac_cv_have_x86_assembler_avx=no))
305 test "$ac_cv_have_x86_assembler_avx" = yes && AC_DEFINE(HAVE_X86_ASSEMBLER_AVX, 1, Have X86 avx)
307 AC_CACHE_CHECK(for X86 assembler f16c, ac_cv_have_x86_assembler_f16c,
310 __asm__ volatile ("vcvtps2ph \$0, %%xmm0, %%xmm0":::"memory");
311 ], ac_cv_have_x86_assembler_f16c=yes, ac_cv_have_x86_assembler_f16c=no))
312 test "$ac_cv_have_x86_assembler_f16c" = yes && AC_DEFINE(HAVE_X86_ASSEMBLER_F16C, 1, Have X86 f16c)
314 AC_CACHE_CHECK(for ARM assembler, ac_cv_have_arm_assembler,
317 __asm__ volatile (".cpu cortex-a15 \n .fpu neon-vfpv4 \n mov r1, r2":::"r1", "r2");
318 ], ac_cv_have_arm_assembler=yes, ac_cv_have_arm_assembler=no))
319 test "$ac_cv_have_arm_assembler" = yes && AC_DEFINE(HAVE_ARM_ASSEMBLER, 1, Have ARM assembler)
321 if test "$ac_cv_have_arm_assembler" = yes; then
322 AC_CACHE_CHECK(for ARM assembler clz, ac_cv_have_arm_assembler_clz,
325 __asm__ volatile (".cpu cortex-a15 \n .fpu neon-vfpv4 \n clz r1, r2":::"r1", "r2");
326 ], ac_cv_have_arm_assembler_clz=yes, ac_cv_have_arm_assembler_clz=no))
327 test "$ac_cv_have_arm_assembler_clz" = yes && AC_DEFINE(HAVE_ARM_ASSEMBLER_CLZ, 1, Have ARM clz)
329 AC_CACHE_CHECK(for ARM assembler rbit, ac_cv_have_arm_assembler_rbit,
332 __asm__ volatile (".cpu cortex-a15 \n .fpu neon-vfpv4 \n rbit r1, r2":::"r1", "r2");
333 ], ac_cv_have_arm_assembler_rbit=yes, ac_cv_have_arm_assembler_rbit=no))
334 test "$ac_cv_have_arm_assembler_rbit" = yes && AC_DEFINE(HAVE_ARM_ASSEMBLER_RBIT, 1, Have ARM rbit)
336 AC_CACHE_CHECK(for ARM assembler sdiv udiv, ac_cv_have_arm_assembler_sdiv_udiv,
339 __asm__ volatile (".cpu cortex-a15 \n .fpu neon-vfpv4 \n sdiv r1, r2, r3 \n udiv r1, r2, r3":::"r1", "r2", "r3");
340 ], ac_cv_have_arm_assembler_sdiv_udiv=yes, ac_cv_have_arm_assembler_sdiv_udiv=no))
341 test "$ac_cv_have_arm_assembler_sdiv_udiv" = yes && AC_DEFINE(HAVE_ARM_ASSEMBLER_SDIV_UDIV, 1, Have ARM sdiv udiv)
343 AC_CACHE_CHECK(for ARM assembler half-precision, ac_cv_have_arm_assembler_half_precision,
346 __asm__ volatile (".cpu cortex-a15 \n .fpu neon-vfpv4 \n vcvtb.f16.f32 s0, s0 \n vcvtb.f32.f16 s0, s0":::"s0");
347 ], ac_cv_have_arm_assembler_half_precision=yes, ac_cv_have_arm_assembler_half_precision=no))
348 test "$ac_cv_have_arm_assembler_half_precision" = yes && AC_DEFINE(HAVE_ARM_ASSEMBLER_HALF_PRECISION, 1, Have ARM half precision)
350 AC_CACHE_CHECK(for ARM assembler vfp, ac_cv_have_arm_assembler_vfp,
353 __asm__ volatile (".cpu cortex-a15 \n .fpu neon-vfpv4 \n vld1.8 d0[[0]], [[r1]] \n vcnt.8 d0, d0 \n vpaddl.u8 d0, d0 \n vst1.8 d0[[0]], [[r1]]":::"r1", "d0");
354 ], ac_cv_have_arm_assembler_vfp=yes, ac_cv_have_arm_assembler_vfp=no))
355 test "$ac_cv_have_arm_assembler_vfp" = yes && AC_DEFINE(HAVE_ARM_ASSEMBLER_VFP, 1, Have ARM VFP)
359 # Checks for header files.
360 AC_CHECK_HEADERS(asm/prctl.h ffi.h gmp.h gmp/gmp.h linux/falloc.h linux/fs.h malloc.h netdb.h netinet/in.h os2thunk.h quadmath.h signal.h stdalign.h stdatomic.h stdnoreturn.h sys/auxv.h sys/builtin.h sys/epoll.h sys/event.h sys/fmutex.h sys/inotify.h sys/mman.h sys/mount.h sys/netinet.in sys/param.h sys/pstat.h sys/select.h sys/socket.h sys/statvfs.h sys/syscall.h sys/sysctl.h sys/sysmacros.h sys/time.h sys/ucred.h sys/utsname.h sys/vfs.h ucontext.h)
362 # Checks for libraries.
363 AC_CHECK_LIB(m, frexp)
364 if test "$ac_cv_have___float128" = yes && test "$ac_cv_header_quadmath_h" = yes; then
365 AC_CHECK_LIB(quadmath, frexpq)
367 AC_ARG_WITH(gmp, [ --without-gmp use built-in gmp])
368 if test "$with_gmp" != "no"; then
369 if test "$ac_cv_header_gmp_h" = yes || test "$ac_cv_header_gmp_gmp_h" = yes; then
370 AC_CHECK_LIB(gmp, __gmpz_init2)
373 if test "$ac_cv_header_ffi_h" = yes; then
374 AC_CHECK_LIB(ffi, ffi_prep_cif)
375 AC_CHECK_FUNCS(ffi_prep_cif_var)
376 if test "$ac_cv_have_emx" = no -a "$ac_cv_have_win32" = no; then
377 AC_CHECK_FUNCS(dlopen)
378 if test "$ac_cv_have_dlopen" != yes; then
379 AC_CHECK_LIB(dl, dlopen)
386 AC_CHECK_LIB(xnet, getpeername)
388 # Checks for library functions.
389 AC_CHECK_FUNCS(accept4 aligned_alloc cfmakeraw chown clock_gettime epoll_create fallocate fchdir fchmodat fchownat fdatasync ffs ffsl ffsll fls flsl flsll fstat64 fstatat fstatfs fstatvfs fstatvfs64 ftruncate64 getauxval getenv getfsstat gethostname getpagesize getpeername getvfsstat gmtime_r inotify_init isatty kqueue lchown link linkat localtime_r lseek64 lstat lstat64 madvise memalign mempcpy mkdirat mknod mknodat mkostemp mmap mmap64 mprotect mremap open64 openat pipe2 posix_memalign pread pread64 pstat_getdynamic pthread_condattr_setclock pthread_sigmask pthread_spin_init pwrite pwrite64 raise readlink readlinkat renameat setitimer setvbuf sigaction sigblock sigfillset sigprocmask sigsetmask socket stat64 statfs statvfs statvfs64 strerror strerror_r strnlen strverscmp symlink symlinkat syncfs syscall sysconf sysctl timegm timer_create truncate64 uname unlinkat utime utimensat utimes vsnprintf _beginthreadex _fmutex_create _threadstore)
393 nextafter nextafterf nextafterl \
395 finite finitef finitel finiteq \
396 isnan isnanf isnanl isnanq \
412 asinh asinhf asinhl \
413 acosh acoshf acoshl \
414 atanh atanhf atanhl \
416 exp2 exp2f exp2l exp2q \
418 exp10 exp10f exp10l exp10q \
426 trunc truncf truncl \
428 frexpf frexpl frexpq \
432 ldexpf ldexpl ldexpq \
437 if test "$ac_cv_func_socket" != yes; then
438 AC_CHECK_LIB(socket, socket)
439 if test "$ac_cv_lib_socket_socket" != yes; then
440 AC_CHECK_LIB(watt, socket)
441 if test "$ac_cv_lib_watt_socket" != yes; then
442 AC_CHECK_LIB(wsock32, socket)
443 if test "$ac_cv_lib_wsock32_socket" != yes; then
444 if echo "$CC" | grep -i mingw >/dev/null; then
445 LIBS="-lwsock32 $LIBS"
453 AC_CHECK_FUNCS(gethostbyname)
454 if test "$ac_cv_func_gethostbyname" != yes; then
455 AC_CHECK_LIB(socket, gethostbyname)
456 if test "$ac_cv_lib_socket_gethostbyname" != yes; then
457 AC_CHECK_LIB(nsl, gethostbyname)
458 if test "$ac_cv_lib_nsl_gethostbyname" != yes; then
463 if test "$cf_have_socket" = yes && test "$ac_cv_header_sys_socket_h" = yes && test "$ac_cv_header_netinet_in_h" = yes && test "$ac_cv_header_netdb_h" = yes; then
464 AC_DEFINE(HAVE_NETWORK, 1, Have networking)
466 AC_CHECK_FUNCS(gethostbyaddr getaddrinfo getnameinfo hstrerror h_errno)
468 AC_CACHE_CHECK(for struct timespec, ac_cv_have_struct_timespec,
477 ], ac_cv_have_struct_timespec=yes, ac_cv_have_struct_timespec=no))
478 test "$ac_cv_have_struct_timespec" = yes && AC_DEFINE(HAVE_STRUCT_TIMESPEC, 1, Have struct timespec)
480 AC_CACHE_CHECK(if struct stat has st_atim, ac_cv_have_struct_stat_st_atim,
482 #include <sys/stat.h>
484 volatile struct stat st;
485 volatile struct timespec a = st.st_atim;
487 ], ac_cv_have_struct_stat_st_atim=yes, ac_cv_have_struct_stat_st_atim=no))
488 test "$ac_cv_have_struct_stat_st_atim" = yes && AC_DEFINE(HAVE_STRUCT_STAT_ST_ATIM, 1, Struct stat has st_atim)
490 AC_CACHE_CHECK(if struct stat has st_atimespec, ac_cv_have_struct_stat_st_atimespec,
492 #include <sys/stat.h>
494 volatile struct stat st;
495 volatile struct timespec a = st.st_atimespec;
497 ], ac_cv_have_struct_stat_st_atimespec=yes, ac_cv_have_struct_stat_st_atimespec=no))
498 test "$ac_cv_have_struct_stat_st_atimespec" = yes && AC_DEFINE(HAVE_STRUCT_STAT_ST_ATIMESPEC, 1, Struct stat has st_atimespec)
501 if test "$ac_cv_func_clock_gettime" = no -a "$ax_pthread_ok" = yes -a "$ac_cv_func_pthread_condattr_setclock" = yes; then
502 AC_CHECK_LIB(rt, clock_gettime)
503 if test "$ac_cv_lib_rt_clock_gettime" = yes; then
504 AC_DEFINE(HAVE_CLOCK_GETTIME)
508 AC_CACHE_CHECK(for struct sigevent, ac_cv_have_struct_sigevent,
515 timer_create(CLOCK_MONOTONIC, &sev, &timer_id);
517 ], ac_cv_have_struct_sigevent=yes, ac_cv_have_struct_sigevent=no))
518 test "$ac_cv_have_struct_sigevent" = yes && AC_DEFINE(HAVE_STRUCT_SIGEVENT, 1, Have struct sigevent)
520 if test "$ac_cv_have_struct_sigevent" = yes -a "$ac_cv_func_timer_create" = no; then
521 AC_CHECK_LIB(rt, timer_create)
522 if test "$ac_cv_lib_rt_timer_create" = yes; then
523 AC_DEFINE(HAVE_TIMER_CREATE)
528 AC_CACHE_CHECK(for CLOCK_MONOTONIC, ac_cv_have_clock_monotonic,
532 clockid_t id = CLOCK_MONOTONIC;
534 ], ac_cv_have_clock_monotonic=yes, ac_cv_have_clock_monotonic=no))
535 test "$ac_cv_have_clock_monotonic" = yes && AC_DEFINE(HAVE_CLOCK_MONOTONIC, 1, Have CLOCK_MONOTONIC)
537 AC_CACHE_CHECK(for CLOCK_MONOTONIC_RAW, ac_cv_have_clock_monotonic_raw,
541 clockid_t id = CLOCK_MONOTONIC_RAW;
543 ], ac_cv_have_clock_monotonic_raw=yes, ac_cv_have_clock_monotonic_raw=no))
544 test "$ac_cv_have_clock_monotonic_raw" = yes && AC_DEFINE(HAVE_CLOCK_MONOTONIC_RAW, 1, Have CLOCK_MONOTONIC_RAW)
547 AC_CACHE_CHECK(for intX_t and u_intX_t, ac_cv_have_intx_t_u_intx_t,
549 #include <sys/types.h>
557 return (int)(a + b + c + d + e + f);
558 ], ac_cv_have_intx_t_u_intx_t=yes, ac_cv_have_intx_t_u_intx_t=no))
559 test "$ac_cv_have_intx_t_u_intx_t" = yes && AC_DEFINE(HAVE_INT_T_U_INT_T, 1, Have intX_t and u_intX_t)
561 AC_CACHE_CHECK(for int64_t and u_int64_t, ac_cv_have_int64_t_u_int64_t,
563 #include <sys/types.h>
565 int64_t a = 0x12345678;
566 u_int64_t b = 0x9abcdef0;
568 ], ac_cv_have_int64_t_u_int64_t=yes, ac_cv_have_int64_t_u_int64_t=no))
569 test "$ac_cv_have_int64_t_u_int64_t" = yes && AC_DEFINE(HAVE_INT64_T_U_INT64_T, 1, Have int64_t and u_int64_t)
571 AC_CACHE_CHECK(for int64_t and uint64_t, ac_cv_have_int64_t_uint64_t,
575 int64_t a = 0x12345678;
576 uint64_t b = 0x9abcdef0;
578 ], ac_cv_have_int64_t_uint64_t=yes, ac_cv_have_int64_t_uint64_t=no))
579 test "$ac_cv_have_int64_t_uint64_t" = yes && AC_DEFINE(HAVE_INT64_T_UINT64_T, 1, Have int64_t and uint64_t)
581 AC_CACHE_CHECK([for big endian], ac_cv_big_endian,
584 char *c = (char *)&l;
588 return !(c[[sizeof(long) - 1]] == 0x78 && c[[sizeof(long) - 2]] == 0x56 && c[[sizeof(long) - 3]] == 0x34 && c[[sizeof(long) - 4]] == 0x12);
590 ], ac_cv_big_endian=yes, ac_cv_big_endian=no, ac_cv_big_endian=unknown)
592 AC_CACHE_CHECK([for little endian], ac_cv_little_endian,
595 char *c = (char *)&l;
599 return !(c[[0]] == 0x78 && c[[1]] == 0x56 && c[[2]] == 0x34 && c[[3]] == 0x12);
601 ], ac_cv_little_endian=yes, ac_cv_little_endian=no, ac_cv_little_endian=unknown)
604 if test "$ac_cv_big_endian" = yes -a "$ac_cv_little_endian" = yes; then
605 AC_ERROR([The endianity test is broken])
606 elif test "$ac_cv_big_endian" = yes; then
607 AC_DEFINE(CONFIG_BIG_ENDIAN, 1, Define if the system is big endian)
608 elif test "$ac_cv_little_endian" = yes; then
609 AC_DEFINE(CONFIG_LITTLE_ENDIAN, 1, Define if the system is little endian)
612 AC_CACHE_CHECK([if rwx mappings work], ac_cv_rwx_mmap,
615 #include <sys/mman.h>
618 return mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0) == MAP_FAILED;
620 ], ac_cv_rwx_mmap=yes, ac_cv_rwx_mmap=no, ac_cv_rwx_mmap=no))
621 test "$ac_cv_func_mmap" = yes && test "$ac_cv_rwx_mmap" = no && AC_DEFINE(DISABLE_RWX_MAPPINGS, 1, Disable rwx mappings)
623 AC_CACHE_CHECK([for pointer tags], ac_cv_pointer_tags,
627 volatile unsigned val = 0x12345678U;
628 volatile unsigned * volatile ptr, * volatile tagged_ptr;
629 unsigned long want_tag = 0;
630 #if defined(__aarch64__) && !defined(__ILP32__)
631 want_tag = 0xFF00000000000000UL;
633 #if defined(__s390__) && !defined(__LP64__)
634 want_tag = 0x80000000UL;
639 if ((unsigned long)ptr & want_tag)
641 tagged_ptr = (unsigned *)((unsigned long)ptr | want_tag);
642 return *tagged_ptr == 0x12345678U ? 0 : 1;
644 ], ac_cv_pointer_tags=yes, ac_cv_pointer_tags=no, ac_cv_pointer_tags=unknown)
646 test "$ac_cv_pointer_tags" = yes && AC_DEFINE(HAVE_POINTER_TAGS, 1, Have pointer tags)
648 AC_CACHE_CHECK(for __sync_add_and_fetch __sync_sub_and_fetch __sync_bool_compare_and_swap __sync_synchronize, ac_cv_have_sync_and_fetch,
650 unsigned long val = 0;
651 __sync_synchronize();
652 __sync_add_and_fetch(&val, 1);
653 __sync_bool_compare_and_swap(&val, 1, 2);
654 return __sync_sub_and_fetch(&val, 1);
655 ], ac_cv_have_sync_and_fetch=yes, ac_cv_have_sync_and_fetch=no))
656 test "$ac_cv_have_sync_and_fetch" = yes && AC_DEFINE(HAVE_SYNC_AND_FETCH, 1, Have __sync_add_and_fetch __sync_sub_and_fetch)
658 if test "$ac_cv_header_stdatomic_h" = yes; then
659 AC_CACHE_CHECK(for C11 atomics, ac_cv_have_c11_atomics,
662 #include <stdatomic.h>
663 atomic_uintptr_t val;
664 _Atomic uintptr_t val2;
666 uintptr_t ld = atomic_load_explicit(&val, memory_order_relaxed);
667 uintptr_t fld = atomic_fetch_add_explicit(&val, 4, memory_order_acq_rel);
668 uintptr_t fld2 = atomic_fetch_sub_explicit(&val2, 8, memory_order_release);
669 uintptr_t xch = atomic_exchange_explicit(&val2, 12, memory_order_acquire);
670 atomic_thread_fence(memory_order_seq_cst);
671 return (int)(ld + fld + fld2 + xch);
672 ], ac_cv_have_c11_atomics=yes, ac_cv_have_c11_atomics=no))
673 if test "$ac_cv_have_c11_atomics" = yes; then
674 AC_DEFINE(HAVE_C11_ATOMICS, 1, Have C11 atomics)
677 LIBS="-latomic $LIBS"
678 AC_CACHE_CHECK(for C11 atomics with -latomic, ac_cv_have_c11_atomics_latomic,
681 #include <stdatomic.h>
682 atomic_uintptr_t val;
684 uintptr_t ld = atomic_load_explicit(&val, memory_order_relaxed);
685 uintptr_t fld = atomic_fetch_add_explicit(&val, 4, memory_order_acq_rel);
686 uintptr_t fld2 = atomic_fetch_sub_explicit(&val, 8, memory_order_release);
687 uintptr_t xch = atomic_exchange_explicit(&val, 12, memory_order_acquire);
688 atomic_thread_fence(memory_order_seq_cst);
689 return (int)(ld + fld + fld2 + xch);
690 ], ac_cv_have_c11_atomics_latomic=yes, ac_cv_have_c11_atomics_latomic=no))
691 if test "$ac_cv_have_c11_atomics_latomic" = yes; then
692 AC_DEFINE(HAVE_C11_ATOMICS, 1, Have C11 atomics)
699 AX_GCC_BUILTIN(__builtin_unreachable)
700 AX_GCC_BUILTIN(__builtin_bswap32)
701 AX_GCC_BUILTIN(__builtin_bswap64)
702 AX_GCC_BUILTIN(__builtin_assume_aligned)
703 AX_GCC_BUILTIN(__builtin___clear_cache)
705 AC_CACHE_CHECK(for __builtin_clz __builtin_clzl __builtin_clzll, ac_cv_have_builtin_clz,
707 volatile unsigned a = 0x12345678;
708 volatile unsigned long b = 0x567890ab;
709 volatile unsigned long long c = 0x9abcdef0;
711 return __builtin_clz(a) + __builtin_clzl(b) + __builtin_clzll(c);
712 ], ac_cv_have_builtin_clz=yes, ac_cv_have_builtin_clz=no))
713 test "$ac_cv_have_builtin_clz" = yes && AC_DEFINE(HAVE_BUILTIN_CLZ, 1, Have __builtin_clz __builtin_clzl __builtin_clzll)
715 AC_CACHE_CHECK(for __builtin_ctz __builtin_ctzl __builtin_ctzll, ac_cv_have_builtin_ctz,
717 volatile unsigned a = 0x12345678;
718 volatile unsigned long b = 0x567890ab;
719 volatile unsigned long long c = 0x9abcdef0;
721 return __builtin_ctz(a) + __builtin_ctzl(b) + __builtin_ctzll(c);
722 ], ac_cv_have_builtin_ctz=yes, ac_cv_have_builtin_ctz=no))
723 test "$ac_cv_have_builtin_ctz" = yes && AC_DEFINE(HAVE_BUILTIN_CTZ, 1, Have __builtin_ctz __builtin_ctzl __builtin_ctzll)
725 AC_CACHE_CHECK(for __builtin_popcount __builtin_popcountll, ac_cv_have_builtin_popcount,
727 volatile unsigned a = 0x12345678;
728 volatile unsigned long long b = 0x9abcdef0;
730 return __builtin_popcount(a) + __builtin_popcountll(b);
731 ], ac_cv_have_builtin_popcount=yes, ac_cv_have_builtin_popcount=no))
732 test "$ac_cv_have_builtin_popcount" = yes && AC_DEFINE(HAVE_BUILTIN_POPCOUNT, 1, Have __builtin_popcount __builtin_popcountll)
735 if test "$ac_cv_sizeof_unsigned___int128" != 0; then
737 elif test "$ac_cv_c_long_long" = yes; then
743 AC_CACHE_CHECK(for __builtin_mul_overflow, ac_cv_have_builtin_mul_overflow,
745 volatile $max_type a = 0x12345678;
746 volatile $max_type b = 0x9abcdef;
747 volatile $max_type c;
749 int o1 = __builtin_mul_overflow(a, b, &c);
751 ], ac_cv_have_builtin_mul_overflow=yes, ac_cv_have_builtin_mul_overflow=no))
753 if test "$ac_cv_have_builtin_mul_overflow" = yes; then
754 AC_DEFINE(HAVE_BUILTIN_MUL_OVERFLOW, 1, Have __builtin_mul_overflow)
756 AC_CACHE_CHECK(for __builtin_mul_overflow with -rtlib=compiler-rt, ac_cv_have_builtin_mul_overflow_rtlib_compiler_rt,
757 save_LDFLAGS="$LDFLAGS"
758 LDFLAGS="-rtlib=compiler-rt $LDFLAGS"
760 volatile $max_type a = 0x12345678;
761 volatile $max_type b = 0x9abcdef;
762 volatile $max_type c;
764 int o1 = __builtin_mul_overflow(a, b, &c);
766 ], ac_cv_have_builtin_mul_overflow_rtlib_compiler_rt=yes, ac_cv_have_builtin_mul_overflow_rtlib_compiler_rt=no)
767 LDFLAGS="$save_LDFLAGS"
770 if test "$ac_cv_have_builtin_mul_overflow_rtlib_compiler_rt" = yes; then
772 if test "$ac_cv_have___float128" = yes; then
773 AC_CHECK_LIB(gcc, __addtf3)
774 if test "$ac_cv_lib_gcc___addtf3" != yes; then
775 use_compiler_rt=false
778 if $use_compiler_rt; then
779 LDFLAGS="-rtlib=compiler-rt $LDFLAGS"
780 AC_DEFINE(HAVE_BUILTIN_MUL_OVERFLOW, 1, Have __builtin_mul_overflow)
785 AC_CACHE_CHECK(for __builtin_add_overflow __builtin_sub_overflow, ac_cv_have_builtin_add_sub_overflow,
787 volatile $max_type a = 0x12345678;
788 volatile $max_type b = 0x9abcdef;
789 volatile $max_type c;
791 int o1 = __builtin_add_overflow(a, b, &c);
792 int o2 = __builtin_sub_overflow(a, b, &c);
794 ], ac_cv_have_builtin_add_sub_overflow=yes, ac_cv_have_builtin_add_sub_overflow=no))
795 test "$ac_cv_have_builtin_add_sub_overflow" = yes && AC_DEFINE(HAVE_BUILTIN_ADD_SUB_OVERFLOW, 1, Have __builtin_add_overflow __builtin_sub_overflow)
799 AC_CACHE_CHECK(for -mieee, ac_cv_have_mieee,
800 save_CFLAGS="$CFLAGS"
801 CFLAGS="-mieee $CFLAGS"
802 AC_TRY_LINK([ ], [ ], ac_cv_have_mieee=yes, ac_cv_have_mieee=no)
803 CFLAGS="$save_CFLAGS"
805 test "$ac_cv_have_mieee" = yes && CFLAGS="-mieee $CFLAGS"
809 AC_CACHE_CHECK(if we can use union of float and uint32_t, ac_cv_union_float_uint32_t,
821 return !(u.i == 0xBE280000UL);
823 ], ac_cv_union_float_uint32_t=yes, ac_cv_union_float_uint32_t=no, ac_cv_union_float_uint32_t=unknown))
824 test "$ac_cv_union_float_uint32_t" = yes && AC_DEFINE(HAVE_UNION_FLOAT_UINT32_T, 1, Can use union of float and uint32_t)
826 dnl gcc-4.* on ARM has buggy infinity float to __fp16 conversion (it incorrectly returns NaN)
827 dnl clang-6 on ARM64 generates invalid instruction when storing fp16 zero
828 AC_CACHE_CHECK(for __fp16, ac_cv_have___fp16,
832 volatile float a = HUGE_VAL;
835 static __fp16 store0(__fp16 *fp, __fp16 arg)
841 __fp16 (*volatile ptr_store0)(__fp16 *, __fp16) = store0;
848 return !(f == 0 && b == HUGE_VAL);
850 ], ac_cv_have___fp16=yes, ac_cv_have___fp16=no, ac_cv_have___fp16=unknown))
851 cf_have_fp16="$ac_cv_have___fp16"
853 if test "$ac_cv_have___fp16" = no; then
854 save_CFLAGS="$CFLAGS"
855 CFLAGS="-mfp16-format=ieee $CFLAGS"
856 AC_CACHE_CHECK(for __fp16 with -mfp16-format=ieee, ac_cv_have___fp16_2,
860 volatile float a = HUGE_VAL;
863 static __fp16 store0(__fp16 *fp, __fp16 arg)
869 __fp16 (*volatile ptr_store0)(__fp16 *, __fp16) = store0;
876 return !(f == 0 && b == HUGE_VAL);
878 ], ac_cv_have___fp16_2=yes, ac_cv_have___fp16_2=no, ac_cv_have___fp16_2=unknown))
879 if test "$ac_cv_have___fp16_2" = yes; then
882 CFLAGS="$save_CFLAGS"
886 if test "$cf_have_fp16" = yes; then
887 dnl libgcc-6 on ARM64 lacks the functions __extendhftf2 and __trunctfhf2
888 dnl clang-6 on X86 lacks the function __truncxfhf2
889 AC_CACHE_CHECK(if conversion between __fp16 and long double works, ac_cv_conversion___fp16_long_double,
891 volatile __fp16 a = 1.2;
892 volatile long double b;
898 ], ac_cv_conversion___fp16_long_double=yes, ac_cv_conversion___fp16_long_double=no))
899 test "$ac_cv_conversion___fp16_long_double" = no && cf_have_fp16=no
901 dnl libgcc-6 on ARM64 lacks the function __floatundihf
902 AC_CACHE_CHECK(if conversion from unsigned long to __fp16 works, ac_cv_conversion_unsigned_long___fp16,
904 volatile unsigned long a = 10;
905 volatile __fp16 b = 1.2;
909 ], ac_cv_conversion_unsigned_long___fp16=yes, ac_cv_conversion_unsigned_long___fp16=no))
910 test "$ac_cv_conversion_unsigned_long___fp16" = no && cf_have_fp16=no
912 if test "$ac_cv_sizeof_unsigned___int128" != 0; then
913 dnl libgcc-6 on ARM64 lacks the functions __fixhfti and __fixunshfti
914 AC_CACHE_CHECK(if conversion from __fp16 to __int128 works, ac_cv_conversion___fp16___int128,
916 volatile __fp16 a = 1.2;
918 volatile unsigned __int128 c;
921 c = (unsigned __int128)a;
923 ], ac_cv_conversion___fp16___int128=yes, ac_cv_conversion___fp16___int128=no))
924 test "$ac_cv_conversion___fp16___int128" = no && cf_have_fp16=no
926 dnl libgcc-6 on ARM64 lacks the functions __floattihf and __floattihf
927 AC_CACHE_CHECK(if conversion from __int128 to __fp16 works, ac_cv_conversion___int128___fp16,
929 volatile __int128 a = 12;
930 volatile unsigned __int128 b = 34;
936 ], ac_cv_conversion___int128___fp16=yes, ac_cv_conversion___int128___fp16=no))
937 test "$ac_cv_conversion___int128___fp16" = no && cf_have_fp16=no
940 test "$cf_have_fp16" = yes && AC_DEFINE(HAVE___FP16, 1, Have __fp16)
942 AC_CACHE_CHECK(if sqrt sets errno, ac_cv_have_sqrt_errno,
947 volatile double a = -1;
955 ], ac_cv_have_sqrt_errno=yes, ac_cv_have_sqrt_errno=no, ac_cv_have_sqrt_errno=unknown))
957 if test "$ac_cv_have_sqrt_errno" = yes; then
958 save_CFLAGS="$CFLAGS"
959 CFLAGS="-fno-math-errno $CFLAGS"
960 AC_CACHE_CHECK(for -fno-math-errno, ac_cv_have__fno_math_errno,
965 volatile double a = -1;
973 ], ac_cv_have__fno_math_errno=yes, ac_cv_have__fno_math_errno=no, ac_cv_have__fno_math_errno=unknown))
974 if test "$ac_cv_have__fno_math_errno" != yes; then
975 CFLAGS="$save_CFLAGS"
979 AC_CACHE_CHECK(if fmod is buggy, ac_cv_have_buggy_fmod,
982 volatile double a = 0.;
983 volatile double b = 0.;
986 return fmod(a, b) == 0;
988 ], ac_cv_have_buggy_fmod=no, ac_cv_have_buggy_fmod=yes, ac_cv_have_buggy_fmod=yes))
989 test "$ac_cv_have_buggy_fmod" = yes && AC_DEFINE(HAVE_BUGGY_FMOD, 1, Have buggy fmod)
991 AC_CACHE_CHECK(if modf is buggy, ac_cv_have_buggy_modf,
994 volatile double a = 1.;
995 volatile double b = 0.;
999 return !(modf(a / b, &d) == 0);
1001 ], ac_cv_have_buggy_modf=no, ac_cv_have_buggy_modf=yes, ac_cv_have_buggy_modf=yes))
1002 test "$ac_cv_have_buggy_modf" = yes && AC_DEFINE(HAVE_BUGGY_MODF, 1, Have buggy modf)
1005 AC_CONFIG_FILES(Makefile)
1008 if test "$ac_cv_lib_ffi_ffi_prep_cif" != yes; then
1009 AC_MSG_WARN([libffi is not present, ffi functionality will be disabled])
1011 if test "$ac_cv_lib_gmp___gmpz_init2" != yes; then
1012 AC_MSG_WARN([libgmp is not present, slow built-in emulation will be used])