configure.ac 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. # -*- Autoconf -*-
  2. # Process this file with autoconf to produce a configure script.
  3. AC_PREREQ(2.68)
  4. AC_INIT([libplist], [m4_esyscmd(./git-version-gen $RELEASE_VERSION)], [https://github.com/libimobiledevice/libplist/issues], [], [https://libimobiledevice.org])
  5. AM_INIT_AUTOMAKE([dist-bzip2 no-dist-gzip check-news])
  6. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES])
  7. AC_CONFIG_SRCDIR([src/])
  8. AC_CONFIG_HEADERS([config.h])
  9. AC_CONFIG_MACRO_DIR([m4])
  10. dnl libtool versioning
  11. # +1 : 0 : +1 == adds new functions to the interface
  12. # +1 : 0 : 0 == changes or removes functions (changes include both
  13. # changes to the signature and the semantic)
  14. # ? :+1 : ? == just internal changes
  15. # CURRENT : REVISION : AGE
  16. LIBPLIST_SO_VERSION=10:0:6
  17. AC_SUBST(LIBPLIST_SO_VERSION)
  18. # Check if we have a version defined
  19. if test -z $PACKAGE_VERSION; then
  20. AC_MSG_ERROR([PACKAGE_VERSION is not defined. Make sure to configure a source tree checked out from git or that .tarball-version is present.])
  21. fi
  22. # Checks for programs.
  23. AC_PROG_CC
  24. AC_PROG_CXX
  25. # AC_PROG_CXX will return "g++" even if no c++ compiler is installed
  26. AC_LANG_PUSH([C++])
  27. AC_MSG_CHECKING([whether $CXX is available and compiles a program])
  28. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
  29. [AC_MSG_RESULT([yes])],
  30. [AC_MSG_RESULT([no])
  31. AC_MSG_ERROR([C++ compiler not available or unable to compile])])
  32. AC_LANG_POP
  33. AM_PROG_CC_C_O
  34. LT_INIT
  35. # Checks for header files.
  36. AC_CHECK_HEADERS([stdint.h stdlib.h string.h])
  37. # Checks for typedefs, structures, and compiler characteristics.
  38. AC_C_CONST
  39. AC_TYPE_SIZE_T
  40. AC_TYPE_SSIZE_T
  41. AC_TYPE_UINT16_T
  42. AC_TYPE_UINT32_T
  43. AC_TYPE_UINT8_T
  44. # Checks for library functions.
  45. AC_CHECK_FUNCS([strdup strndup strerror gmtime_r localtime_r timegm strptime memmem])
  46. # Checking endianness
  47. AC_C_BIGENDIAN([AC_DEFINE([__BIG_ENDIAN__], [1], [big endian])],
  48. [AC_DEFINE([__LITTLE_ENDIAN__], [1], [little endian])])
  49. # Check for operating system
  50. AC_MSG_CHECKING([for platform-specific build settings])
  51. case ${host_os} in
  52. *mingw32*|*cygwin*)
  53. AC_MSG_RESULT([${host_os}])
  54. win32=true
  55. ;;
  56. darwin*|*android*)
  57. AC_MSG_RESULT([${host_os}])
  58. ;;
  59. *)
  60. AC_MSG_RESULT([${host_os}])
  61. AX_PTHREAD([], [AC_MSG_ERROR([pthread is required to build libplist])])
  62. AC_CHECK_LIB(pthread, [pthread_once], [], [AC_MSG_ERROR([pthread with pthread_once required to build libplist])])
  63. ;;
  64. esac
  65. AM_CONDITIONAL(WIN32, test x$win32 = xtrue)
  66. AC_SEARCH_LIBS([fmin],[m])
  67. # Check if struct tm has a tm_gmtoff member
  68. AC_CACHE_CHECK(for tm_gmtoff in struct tm, ac_cv_struct_tm_gmtoff,
  69. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
  70. #include <time.h>
  71. ], [
  72. struct tm tm;
  73. tm.tm_gmtoff = 1;
  74. ])],
  75. [ac_cv_struct_tm_gmtoff=yes],
  76. [ac_cv_struct_tm_gmtoff=no]
  77. )
  78. )
  79. if (test "$ac_cv_struct_tm_gmtoff" = "yes"); then
  80. AC_DEFINE(HAVE_TM_TM_GMTOFF, 1, [Define if struct tm has a tm_gmtoff member])
  81. fi
  82. # Check if struct tm has a tm_zone member
  83. AC_CACHE_CHECK(for tm_zone in struct tm, ac_cv_struct_tm_zone,
  84. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
  85. #include <time.h>
  86. ], [
  87. struct tm tm;
  88. tm.tm_zone = (char*)"UTC";
  89. ])],
  90. [ac_cv_struct_tm_zone=yes],
  91. [ac_cv_struct_tm_zone=no]
  92. )
  93. )
  94. if (test "$ac_cv_struct_tm_zone" = "yes"); then
  95. AC_DEFINE(HAVE_TM_TM_ZONE, 1, [Define if struct tm has a tm_zone member])
  96. fi
  97. # Cython Python Bindings
  98. AC_ARG_WITH([cython],
  99. [AS_HELP_STRING([--without-cython],
  100. [build Python bindings using Cython (default is yes)])],
  101. [build_cython=false],
  102. [build_cython=true])
  103. if test "$build_cython" = "true"; then
  104. AC_PROG_CYTHON([3.0.0])
  105. if [test "x$CYTHON" != "xfalse"]; then
  106. AM_PATH_PYTHON([3.0], [CYTHON_PYTHON])
  107. fi
  108. else
  109. CYTHON=false
  110. fi
  111. if [test "x$CYTHON" != "xfalse"]; then
  112. PKG_PROG_PKG_CONFIG
  113. AC_MSG_CHECKING([for libplist Cython bindings])
  114. if test -x "$PKG_CONFIG"; then
  115. CYTHON_PLIST_INCLUDE_DIR=$($PKG_CONFIG --variable=includedir libplist-2.0)/plist/cython
  116. fi
  117. if [test ! -d "$CYTHON_PLIST_INCLUDE_DIR"]; then
  118. CYTHON_PLIST_INCLUDE_DIR=.
  119. cython_python_bindings=yes
  120. AC_MSG_RESULT([Using built-in libplist Cython bindings (assuming this is a first build)])
  121. else
  122. AC_SUBST([CYTHON_PLIST_INCLUDE_DIR])
  123. AC_MSG_RESULT([$CYTHON_PLIST_INCLUDE_DIR])
  124. cython_python_bindings=yes
  125. fi
  126. else
  127. cython_python_bindings=no
  128. fi
  129. AM_CONDITIONAL([HAVE_CYTHON],[test "x$cython_python_bindings" = "xyes"])
  130. AC_ARG_WITH([tools],
  131. [AS_HELP_STRING([--with-tools], [Build libplist tools. [default=yes]])],
  132. [build_tools=${withval}],
  133. [build_tools=yes]
  134. )
  135. AS_IF([test "x$build_tools" = "xyes"], [AC_DEFINE(BUILD_TOOLS, 1, [Define if we are building plist tools])])
  136. AM_CONDITIONAL(BUILD_TOOLS, test "x$build_tools" = "xyes")
  137. AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter -Wno-strict-aliasing $PTHREAD_CFLAGS")
  138. GLOBAL_LDFLAGS="$PTHREAD_LIBS"
  139. AC_ARG_ENABLE(debug,
  140. AS_HELP_STRING([--enable-debug],
  141. [build debug message output code (default is no)]),
  142. [case "${enableval}" in
  143. yes) debug=yes ;;
  144. no) debug=no ;;
  145. *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
  146. esac],
  147. [debug=no])
  148. if (test "x$debug" = "xyes"); then
  149. AC_DEFINE(DEBUG, 1, [Define if debug message output code should be built.])
  150. GLOBAL_CFLAGS+=" -g"
  151. fi
  152. if test "x$enable_static" = "xyes" -a "x$enable_shared" = "xno"; then
  153. GLOBAL_CFLAGS+=" -DLIBPLIST_STATIC"
  154. fi
  155. GLOBAL_CXXFLAGS=$GLOBAL_CFLAGS
  156. AS_COMPILER_FLAG([-fvisibility=hidden], [
  157. GLOBAL_CFLAGS+=" -fvisibility=hidden"
  158. ], [])
  159. AC_SUBST(GLOBAL_CFLAGS)
  160. AC_SUBST(GLOBAL_CXXFLAGS)
  161. AC_SUBST(GLOBAL_LDFLAGS)
  162. case "$GLOBAL_CFLAGS" in
  163. *-fvisibility=hidden*)
  164. AC_DEFINE([HAVE_FVISIBILITY], [1], [Define if compiled with -fvisibility=hidden])
  165. esac
  166. AC_ARG_WITH([sanitizers],
  167. [AS_HELP_STRING([--with-sanitizers],
  168. [build libplist with sanitizers (default is no)])],
  169. [build_sanitizers=${withval}],
  170. [])
  171. AC_ARG_WITH([fuzzers],
  172. [AS_HELP_STRING([--with-fuzzers],
  173. [build fuzzers (implies --with-sanitizers, default is no)])],
  174. [build_fuzzers=${withval}],
  175. [build_fuzzers=no])
  176. AC_ARG_WITH([tests],
  177. [AS_HELP_STRING([--without-tests],
  178. [Do not build libplist test suite (default is yes)])],
  179. [build_tests=${withval}],
  180. [build_tests=${build_tools}])
  181. if test "x$build_tests" = "xyes" -a "x$build_tools" != "xyes"; then
  182. AC_MSG_ERROR([Building the test suite requires plistutil. Reconfigure with --with-tools=yes to enable.])
  183. fi
  184. if test "x$build_fuzzers" = "xyes"; then
  185. if test "x$build_sanitizers" = "xno"; then
  186. AC_MSG_ERROR([--with-fuzzers implies --with-sanitizers, but --without-sanitizers was given. This does not work.])
  187. fi
  188. build_sanitizers=yes
  189. fi
  190. if test "x$build_sanitizers" = "xyes"; then
  191. AS_COMPILER_FLAG([-fsanitize=address], [
  192. SANITIZER_FLAGS+=" -fsanitize=address"
  193. ASAN_AVAILABLE=yes
  194. ], [])
  195. if test "$ASAN_AVAILABLE" = "yes"; then
  196. AS_COMPILER_FLAG([-fsanitize=address -fsanitize-address-use-after-scope], [
  197. SANITIZER_FLAGS+=" -fsanitize-address-use-after-scope"
  198. ], [])
  199. SANITIZERS+="ASAN "
  200. fi
  201. AS_COMPILER_FLAG([-fsanitize=undefined], [
  202. SANITIZER_FLAGS+=" -fsanitize=undefined"
  203. UBSAN_AVAILABLE=yes
  204. ], [])
  205. if test "$UBSAN_AVAILABLE" = "yes"; then
  206. SANITIZERS+="UBSAN "
  207. fi
  208. if test -z "$SANITIZER_FLAGS"; then
  209. AC_MSG_ERROR([compiler doesn't support -fsanitize=address nor -fsanitize=undefined])
  210. fi
  211. COVERAGE_CHECKS="trace-pc-guard trace-cmp edge"
  212. for COV_CHECK in $COVERAGE_CHECKS; do
  213. AS_COMPILER_FLAG([-fsanitize-coverage=$COV_CHECK], [
  214. if test -z "$SAN_COV_FLAGS"; then
  215. SAN_COV_FLAGS="$COV_CHECK"
  216. else
  217. SAN_COV_FLAGS+=",$COV_CHECK"
  218. fi
  219. ], [])
  220. done
  221. if test -n "$SAN_COV_FLAGS"; then
  222. SANITIZER_FLAGS+=" -fsanitize-coverage=$SAN_COV_FLAGS"
  223. SANITIZERS+="+coverage "
  224. else
  225. AC_MSG_WARN([No sanitizer coverage supported by compiler])
  226. fi
  227. CFLAGS="-O1"
  228. AS_COMPILER_FLAG([-fno-omit-frame-pointer], [
  229. CFLAGS+=" -fno-omit-frame-pointer"
  230. ], [])
  231. AS_COMPILER_FLAG([-gline-tables-only], [
  232. CFLAGS+=" -gline-tables-only"
  233. ],
  234. [
  235. CFLAGS+=" -g"
  236. ])
  237. EXTRA_CONF+=" Enabled sanitizers ......: $SANITIZERS
  238. "
  239. CFLAGS+=" $SANITIZER_FLAGS"
  240. CXXFLAGS="$CFLAGS -std=c++11"
  241. fi
  242. if test "x$build_fuzzers" = "xyes"; then
  243. IS_CLANG=`$CXX --version 2>/dev/null |grep clang`
  244. case "$IS_CLANG" in
  245. *clang*)
  246. ;;
  247. *)
  248. AC_MSG_WARN([building fuzzers requires clang/clang++ (continuing anyway)])
  249. ;;
  250. esac
  251. CFLAGS+=" -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION"
  252. EXTRA_CONF+=" Build fuzzers ...........: yes
  253. "
  254. fi
  255. AM_CONDITIONAL([BUILD_FUZZERS],[test "x$build_fuzzers" = "xyes"])
  256. AM_CONDITIONAL([BUILD_TESTS],[test "x$build_tests" != "xno"])
  257. if test "x$build_fuzzers" = "xyes" || test "x$build_sanitizers" = "xyes"; then
  258. AS_COMPILER_FLAGS(TEST_CFLAGS, [$CFLAGS])
  259. fi
  260. m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
  261. AC_CONFIG_FILES([
  262. Makefile
  263. libcnary/Makefile
  264. src/Makefile
  265. src/libplist-2.0.pc
  266. src/libplist++-2.0.pc
  267. include/Makefile
  268. tools/Makefile
  269. docs/Makefile
  270. cython/Makefile
  271. test/Makefile
  272. fuzz/Makefile
  273. doxygen.cfg
  274. ])
  275. AC_OUTPUT
  276. echo "
  277. Configuration for $PACKAGE $VERSION:
  278. -------------------------------------------
  279. Install prefix ..........: $prefix
  280. Debug code ..............: $debug
  281. Python bindings .........: $cython_python_bindings
  282. Build tools .............: $build_tools
  283. Build test suite ........: $build_tests
  284. $EXTRA_CONF
  285. Now type 'make' to build $PACKAGE $VERSION,
  286. and then 'make install' for installation.
  287. "