1AC_PREREQ([2.60])
2AC_INIT([jansson], [2.13.1], [https://github.com/akheron/jansson/issues])
3
4AC_CONFIG_AUX_DIR([.])
5AM_INIT_AUTOMAKE([1.10 foreign])
6
7AC_CONFIG_SRCDIR([src/value.c])
8AC_CONFIG_HEADERS([jansson_private_config.h])
9
10# Checks for programs.
11AC_PROG_CC
12AC_PROG_CXX
13AC_PROG_LIBTOOL
14AM_CONDITIONAL([GCC], [test x$GCC = xyes])
15
16# Checks for libraries.
17
18# Checks for header files.
19AC_CHECK_HEADERS([endian.h fcntl.h locale.h sched.h unistd.h sys/param.h sys/stat.h sys/time.h sys/types.h])
20
21# Checks for typedefs, structures, and compiler characteristics.
22AC_TYPE_INT32_T
23AC_TYPE_UINT32_T
24AC_TYPE_UINT16_T
25AC_TYPE_UINT8_T
26AC_TYPE_LONG_LONG_INT
27
28AC_C_INLINE
29case $ac_cv_c_inline in
30    yes) json_inline=inline;;
31    no) json_inline=;;
32    *) json_inline=$ac_cv_c_inline;;
33esac
34AC_SUBST([json_inline])
35
36# Checks for library functions.
37AC_CHECK_FUNCS([close getpid gettimeofday localeconv open read sched_yield strtoll])
38
39AC_MSG_CHECKING([for gcc __sync builtins])
40have_sync_builtins=no
41AC_TRY_LINK(
42  [], [unsigned long val; __sync_bool_compare_and_swap(&val, 0, 1); __sync_add_and_fetch(&val, 1); __sync_sub_and_fetch(&val, 1);],
43  [have_sync_builtins=yes],
44)
45if test "x$have_sync_builtins" = "xyes"; then
46  AC_DEFINE([HAVE_SYNC_BUILTINS], [1],
47    [Define to 1 if gcc's __sync builtins are available])
48  json_have_sync_builtins=1
49else
50  json_have_sync_builtins=0
51fi
52AC_SUBST([json_have_sync_builtins])
53AC_MSG_RESULT([$have_sync_builtins])
54
55AC_MSG_CHECKING([for gcc __atomic builtins])
56have_atomic_builtins=no
57AC_TRY_LINK(
58  [], [char l; unsigned long v; __atomic_test_and_set(&l, __ATOMIC_RELAXED); __atomic_store_n(&v, 1, __ATOMIC_RELEASE); __atomic_load_n(&v, __ATOMIC_ACQUIRE); __atomic_add_fetch(&v, 1, __ATOMIC_ACQUIRE); __atomic_sub_fetch(&v, 1, __ATOMIC_RELEASE);],
59  [have_atomic_builtins=yes],
60)
61if test "x$have_atomic_builtins" = "xyes"; then
62  AC_DEFINE([HAVE_ATOMIC_BUILTINS], [1],
63    [Define to 1 if gcc's __atomic builtins are available])
64  json_have_atomic_builtins=1
65else
66  json_have_atomic_builtins=0
67fi
68AC_SUBST([json_have_atomic_builtins])
69AC_MSG_RESULT([$have_atomic_builtins])
70
71case "$ac_cv_type_long_long_int$ac_cv_func_strtoll" in
72     yesyes) json_have_long_long=1;;
73     *) json_have_long_long=0;;
74esac
75AC_SUBST([json_have_long_long])
76
77case "$ac_cv_header_locale_h$ac_cv_func_localeconv" in
78     yesyes) json_have_localeconv=1;;
79     *) json_have_localeconv=0;;
80esac
81AC_SUBST([json_have_localeconv])
82
83# Features
84AC_ARG_ENABLE([urandom],
85  [AS_HELP_STRING([--disable-urandom],
86    [Don't use /dev/urandom to seed the hash function])],
87  [use_urandom=$enableval], [use_urandom=yes])
88
89if test "x$use_urandom" = xyes; then
90AC_DEFINE([USE_URANDOM], [1],
91  [Define to 1 if /dev/urandom should be used for seeding the hash function])
92fi
93
94AC_ARG_ENABLE([windows-cryptoapi],
95  [AS_HELP_STRING([--disable-windows-cryptoapi],
96    [Don't use CryptGenRandom to seed the hash function])],
97  [use_windows_cryptoapi=$enableval], [use_windows_cryptoapi=yes])
98
99if test "x$use_windows_cryptoapi" = xyes; then
100AC_DEFINE([USE_WINDOWS_CRYPTOAPI], [1],
101  [Define to 1 if CryptGenRandom should be used for seeding the hash function])
102fi
103
104AC_ARG_ENABLE([initial-hashtable-order],
105  [AS_HELP_STRING([--enable-initial-hashtable-order=VAL],
106    [Number of buckets new object hashtables contain is 2 raised to this power. The default is 3, so empty hashtables contain 2^3 = 8 buckets.])],
107  [initial_hashtable_order=$enableval], [initial_hashtable_order=3])
108AC_DEFINE_UNQUOTED([INITIAL_HASHTABLE_ORDER], [$initial_hashtable_order],
109  [Number of buckets new object hashtables contain is 2 raised to this power. E.g. 3 -> 2^3 = 8.])
110
111AC_ARG_ENABLE([Bsymbolic],
112  [AS_HELP_STRING([--disable-Bsymbolic],
113    [Avoid linking with -Bsymbolic-function])],
114  [], [with_Bsymbolic=check])
115
116if test "x$with_Bsymbolic" != "xno" ; then
117    AC_MSG_CHECKING([for -Bsymbolic-functions linker flag])
118    saved_LDFLAGS="${LDFLAGS}"
119    LDFLAGS=-Wl,-Bsymbolic-functions
120    AC_TRY_LINK(
121      [], [int main (void) { return 0; }],
122      [AC_MSG_RESULT([yes])
123       have_Bsymbolic=yes],
124      [AC_MSG_RESULT([no])
125       have_Bsymbolic=no]
126    )
127    LDFLAGS="${saved_LDFLAGS}"
128
129    if test "x$with_Bsymbolic" = "xcheck" ; then
130        with_Bsymbolic=$have_Bsymbolic;
131    fi
132    if test "x$with_Bsymbolic:x$have_Bsymbolic" = "xyes:xno" ; then
133        AC_MSG_ERROR([linker support is required for -Bsymbolic])
134    fi
135fi
136
137AS_IF([test "x$with_Bsymbolic" = "xyes"], [JSON_BSYMBOLIC_LDFLAGS=-Wl[,]-Bsymbolic-functions])
138AC_SUBST(JSON_BSYMBOLIC_LDFLAGS)
139
140
141AC_ARG_ENABLE([ossfuzzers],
142  [AS_HELP_STRING([--enable-ossfuzzers],
143    [Whether to generate the fuzzers for OSS-Fuzz])],
144  [have_ossfuzzers=yes], [have_ossfuzzers=no])
145AM_CONDITIONAL([USE_OSSFUZZERS], [test "x$have_ossfuzzers" = "xyes"])
146
147
148AC_SUBST([LIB_FUZZING_ENGINE])
149AM_CONDITIONAL([USE_OSSFUZZ_FLAG], [test "x$LIB_FUZZING_ENGINE" = "x-fsanitize=fuzzer"])
150AM_CONDITIONAL([USE_OSSFUZZ_STATIC], [test -f "$LIB_FUZZING_ENGINE"])
151
152
153if test x$GCC = xyes; then
154    AC_MSG_CHECKING(for -Wno-format-truncation)
155    wnoformat_truncation="-Wno-format-truncation"
156    AS_IF([${CC} -Wno-format-truncation -Werror -S -o /dev/null -xc /dev/null > /dev/null 2>&1],
157      [AC_MSG_RESULT(yes)],
158      [AC_MSG_RESULT(no)
159      wnoformat_truncation=""])
160
161    AM_CFLAGS="-Wall -Wextra -Wdeclaration-after-statement -Wshadow ${wnoformat_truncation}"
162fi
163AC_SUBST([AM_CFLAGS])
164
165AC_CONFIG_FILES([
166        jansson.pc
167        Makefile
168        doc/Makefile
169        src/Makefile
170        src/jansson_config.h
171        test/Makefile
172        test/bin/Makefile
173        test/ossfuzz/Makefile
174        test/suites/Makefile
175        test/suites/api/Makefile
176])
177AC_OUTPUT
178