configure.ac 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. AC_PREREQ(2.64)
  2. # Process this file with autoconf to produce a configure script.
  3. AC_INIT([json-c], 0.13.1, [json-c@googlegroups.com])
  4. AM_INIT_AUTOMAKE
  5. AC_CONFIG_MACRO_DIRS([autoconf-archive/m4])
  6. AC_PROG_MAKE_SET
  7. AC_CANONICAL_HOST
  8. AC_ARG_ENABLE(threading,
  9. AS_HELP_STRING([--enable-threading],
  10. [Enable code to support partly multi-threaded use]),
  11. [if test x$enableval = xyes; then
  12. enable_threading=yes
  13. AC_DEFINE(ENABLE_THREADING, 1, [Enable partial threading support])
  14. fi])
  15. if test "x$enable_threading" = "xyes"; then
  16. AC_MSG_RESULT([Partial multi-threaded support enabled.])
  17. else
  18. AC_MSG_RESULT([Multi-threaded support disabled. Use --enable-threading to enable.])
  19. fi
  20. AC_ARG_ENABLE(rdrand,
  21. AS_HELP_STRING([--enable-rdrand],
  22. [Enable RDRAND Hardware RNG Hash Seed generation on supported x86/x64 platforms.]),
  23. [if test x$enableval = xyes; then
  24. enable_rdrand=yes
  25. AC_DEFINE(ENABLE_RDRAND, 1, [Enable RDRAND Hardware RNG Hash Seed])
  26. fi])
  27. if test "x$enable_rdrand" = "xyes"; then
  28. AC_MSG_RESULT([RDRAND Hardware RNG Hash Seed enabled on supported x86/x64 platforms])
  29. else
  30. AC_MSG_RESULT([RDRAND Hardware RNG Hash Seed disabled. Use --enable-rdrand to enable])
  31. fi
  32. # enable silent build by default
  33. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
  34. # Checks for programs.
  35. # Checks for libraries.
  36. # Checks for header files.
  37. AM_PROG_CC_C_O
  38. AC_PROG_CC_C99
  39. AC_CONFIG_HEADER(config.h)
  40. AC_CONFIG_HEADER(json_config.h)
  41. AC_HEADER_STDC
  42. AC_CHECK_HEADERS(fcntl.h limits.h strings.h syslog.h unistd.h [sys/cdefs.h] [sys/param.h] stdarg.h locale.h xlocale.h endian.h)
  43. AC_CHECK_HEADER(inttypes.h,[AC_DEFINE([JSON_C_HAVE_INTTYPES_H],[1],[Public define for json_inttypes.h])])
  44. # Checks for typedefs, structures, and compiler characteristics.
  45. AC_C_CONST
  46. AC_TYPE_SIZE_T
  47. AC_CACHE_CHECK([for __thread support], ac_cv___thread, [dnl
  48. AC_LINK_IFELSE([dnl
  49. AC_LANG_PROGRAM([[#undef __thread
  50. static __thread int a; int foo (int b) { return a + b; }]],
  51. [[exit (foo (0));]])],
  52. ac_cv___thread=yes, ac_cv___thread=no)
  53. ])
  54. AS_IF([test "x$ac_cv___thread" != xno],
  55. [AC_DEFINE(HAVE___THREAD, 1, [Have __thread])
  56. AC_DEFINE(SPEC___THREAD, [__thread], [Specifier for __thread])]
  57. )
  58. # Checks for library functions.
  59. AC_FUNC_VPRINTF
  60. AC_FUNC_MEMCMP
  61. AC_CHECK_FUNCS([realloc])
  62. AC_CHECK_FUNCS(strcasecmp strdup strerror snprintf vsnprintf vasprintf open vsyslog strncasecmp setlocale)
  63. AC_CHECK_DECLS([INFINITY], [], [], [[#include <math.h>]])
  64. AC_CHECK_DECLS([nan], [], [], [[#include <math.h>]])
  65. AC_CHECK_DECLS([isnan], [], [], [[#include <math.h>]])
  66. AC_CHECK_DECLS([isinf], [], [], [[#include <math.h>]])
  67. AC_CHECK_DECLS([_isnan], [], [], [[#include <float.h>]])
  68. AC_CHECK_DECLS([_finite], [], [], [[#include <float.h>]])
  69. AC_MSG_CHECKING(for GCC atomic builtins)
  70. AC_LINK_IFELSE(
  71. [
  72. AC_LANG_SOURCE([[
  73. int main() {
  74. volatile unsigned int val = 1;
  75. /* Note: __sync_val_compare_and_swap isn't checked here
  76. * because it's protected by __GCC_HAVE_SYNC_COMPARE_AND_SWAP_<n>,
  77. * which is automatically defined by gcc.
  78. */
  79. __sync_add_and_fetch(&val, 1);
  80. __sync_sub_and_fetch(&val, 1);
  81. return 0;
  82. }
  83. ]])
  84. ],
  85. [
  86. AC_MSG_RESULT([yes])
  87. AC_DEFINE([HAVE_ATOMIC_BUILTINS],[1],[Has atomic builtins])
  88. ],
  89. [
  90. AC_MSG_RESULT([no])
  91. AC_MSG_WARN([json-c will be built without atomic refcounts because atomic builtins are missing])
  92. ])
  93. case "${host_os}" in
  94. linux*)
  95. AC_CHECK_FUNCS([uselocale])
  96. ;;
  97. *) # Nothing
  98. ;;
  99. esac
  100. if test "$ac_cv_have_decl_isnan" = "yes" ; then
  101. AC_TRY_LINK([#include <math.h>], [float f = 0.0; return isnan(f)], [], [LIBS="$LIBS -lm"])
  102. fi
  103. #check if .section.gnu.warning accepts long strings (for __warn_references)
  104. AC_LANG_PUSH([C])
  105. AC_MSG_CHECKING([if .gnu.warning accepts long strings])
  106. AC_LINK_IFELSE([AC_LANG_SOURCE([[
  107. extern void json_object_get();
  108. __asm__(".section .gnu.json_object_get,\n\t.ascii \"Please link against libjson-c instead of libjson\"\n\t.text");
  109. int main(int c,char* v) {return 0;}
  110. ]])], [
  111. AC_DEFINE(HAS_GNU_WARNING_LONG, 1, [Define if .gnu.warning accepts long strings.])
  112. AC_MSG_RESULT(yes)
  113. ], [
  114. AC_MSG_RESULT(no)
  115. ])
  116. AC_LANG_POP([C])
  117. LT_INIT
  118. # Check for the -Bsymbolic-functions linker flag
  119. AC_ARG_ENABLE([Bsymbolic],
  120. [AS_HELP_STRING([--disable-Bsymbolic], [Avoid linking with -Bsymbolic-function])],
  121. [],
  122. [enable_Bsymbolic=check])
  123. AS_IF([test "x$enable_Bsymbolic" = "xcheck"],
  124. [
  125. saved_LDFLAGS="${LDFLAGS}"
  126. AC_MSG_CHECKING([for -Bsymbolic-functions linker flag])
  127. LDFLAGS=-Wl,-Bsymbolic-functions
  128. AC_TRY_LINK([], [int main (void) { return 0; }],
  129. [
  130. AC_MSG_RESULT([yes])
  131. enable_Bsymbolic=yes
  132. ],
  133. [
  134. AC_MSG_RESULT([no])
  135. enable_Bsymbolic=no
  136. ])
  137. LDFLAGS="${saved_LDFLAGS}"
  138. ])
  139. AS_IF([test "x$enable_Bsymbolic" = "xyes"], [JSON_BSYMBOLIC_LDFLAGS=-Wl[,]-Bsymbolic-functions])
  140. AC_SUBST(JSON_BSYMBOLIC_LDFLAGS)
  141. AX_APPEND_COMPILE_FLAGS([-Wall -Werror -Wcast-qual -Wno-error=deprecated-declarations])
  142. AX_APPEND_COMPILE_FLAGS([-Wextra -Wwrite-string -Wno-unused-parameter])
  143. AX_APPEND_COMPILE_FLAGS([-D_GNU_SOURCE])
  144. AC_LANG_PUSH([C])
  145. AC_MSG_CHECKING([for compatibility with _REENTRANT and toolchain headers])
  146. AC_LINK_IFELSE(
  147. [
  148. AC_LANG_SOURCE([[
  149. /* uClibc toolchains without threading barf when _REENTRANT is defined */
  150. #define _REENTRANT 1
  151. #include <sys/types.h>
  152. int main ()
  153. {
  154. return 0;
  155. }
  156. ]])], [
  157. AC_MSG_RESULT(yes)
  158. AX_APPEND_COMPILE_FLAGS([-D_REENTRANT])
  159. ], [
  160. AC_MSG_RESULT(no)
  161. ])
  162. AC_LANG_POP([C])
  163. AX_COMPILE_CHECK_SIZEOF(int)
  164. AX_COMPILE_CHECK_SIZEOF(long)
  165. AX_COMPILE_CHECK_SIZEOF(long long)
  166. AX_COMPILE_CHECK_SIZEOF(size_t, [#include <stdint.h>])
  167. AX_COMPILE_CHECK_SIZEOF(int64_t, [#include <stdint.h>])
  168. AC_CONFIG_FILES([
  169. Makefile
  170. json-c.pc
  171. tests/Makefile
  172. json-c-uninstalled.pc
  173. ])
  174. AC_OUTPUT