configure.ac 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. ;;
  62. esac
  63. AM_CONDITIONAL(WIN32, test x$win32 = xtrue)
  64. AC_SEARCH_LIBS([fmin],[m])
  65. # Check if struct tm has a tm_gmtoff member
  66. AC_CACHE_CHECK(for tm_gmtoff in struct tm, ac_cv_struct_tm_gmtoff,
  67. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
  68. #include <time.h>
  69. ], [
  70. struct tm tm;
  71. tm.tm_gmtoff = 1;
  72. ])],
  73. [ac_cv_struct_tm_gmtoff=yes],
  74. [ac_cv_struct_tm_gmtoff=no]
  75. )
  76. )
  77. if (test "$ac_cv_struct_tm_gmtoff" = "yes"); then
  78. AC_DEFINE(HAVE_TM_TM_GMTOFF, 1, [Define if struct tm has a tm_gmtoff member])
  79. fi
  80. # Check if struct tm has a tm_zone member
  81. AC_CACHE_CHECK(for tm_zone in struct tm, ac_cv_struct_tm_zone,
  82. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
  83. #include <time.h>
  84. ], [
  85. struct tm tm;
  86. tm.tm_zone = (char*)"UTC";
  87. ])],
  88. [ac_cv_struct_tm_zone=yes],
  89. [ac_cv_struct_tm_zone=no]
  90. )
  91. )
  92. if (test "$ac_cv_struct_tm_zone" = "yes"); then
  93. AC_DEFINE(HAVE_TM_TM_ZONE, 1, [Define if struct tm has a tm_zone member])
  94. fi
  95. # Cython Python Bindings
  96. AC_ARG_WITH([cython],
  97. [AS_HELP_STRING([--without-cython],
  98. [build Python bindings using Cython (default is yes)])],
  99. [build_cython=false],
  100. [build_cython=true])
  101. if test "$build_cython" = "true"; then
  102. AC_PROG_CYTHON([3.0.0])
  103. if [test "x$CYTHON" != "xfalse"]; then
  104. AM_PATH_PYTHON([3.0], [CYTHON_PYTHON])
  105. fi
  106. else
  107. CYTHON=false
  108. fi
  109. if [test "x$CYTHON" != "xfalse"]; then
  110. PKG_PROG_PKG_CONFIG
  111. AC_MSG_CHECKING([for libplist Cython bindings])
  112. if test -x "$PKG_CONFIG"; then
  113. CYTHON_PLIST_INCLUDE_DIR=$($PKG_CONFIG --variable=includedir libplist-2.0)/plist/cython
  114. fi
  115. if [test ! -d "$CYTHON_PLIST_INCLUDE_DIR"]; then
  116. CYTHON_PLIST_INCLUDE_DIR=.
  117. cython_python_bindings=yes
  118. AC_MSG_RESULT([Using built-in libplist Cython bindings (assuming this is a first build)])
  119. else
  120. AC_SUBST([CYTHON_PLIST_INCLUDE_DIR])
  121. AC_MSG_RESULT([$CYTHON_PLIST_INCLUDE_DIR])
  122. cython_python_bindings=yes
  123. fi
  124. else
  125. cython_python_bindings=no
  126. fi
  127. AM_CONDITIONAL([HAVE_CYTHON],[test "x$cython_python_bindings" = "xyes"])
  128. AC_ARG_WITH([tools],
  129. [AS_HELP_STRING([--with-tools], [Build libplist tools. [default=yes]])],
  130. [build_tools=${withval}],
  131. [build_tools=yes]
  132. )
  133. AS_IF([test "x$build_tools" = "xyes"], [AC_DEFINE(BUILD_TOOLS, 1, [Define if we are building plist tools])])
  134. AM_CONDITIONAL(BUILD_TOOLS, test "x$build_tools" = "xyes")
  135. AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter -Wno-strict-aliasing")
  136. GLOBAL_LDFLAGS=""
  137. AC_ARG_ENABLE(debug,
  138. AS_HELP_STRING([--enable-debug],
  139. [build debug message output code (default is no)]),
  140. [case "${enableval}" in
  141. yes) debug=yes ;;
  142. no) debug=no ;;
  143. *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
  144. esac],
  145. [debug=no])
  146. if (test "x$debug" = "xyes"); then
  147. AC_DEFINE(DEBUG, 1, [Define if debug message output code should be built.])
  148. GLOBAL_CFLAGS+=" -g"
  149. fi
  150. if test "x$enable_static" = "xyes" -a "x$enable_shared" = "xno"; then
  151. GLOBAL_CFLAGS+=" -DLIBPLIST_STATIC"
  152. fi
  153. GLOBAL_CXXFLAGS=$GLOBAL_CFLAGS
  154. AS_COMPILER_FLAG([-fvisibility=hidden], [
  155. GLOBAL_CFLAGS+=" -fvisibility=hidden"
  156. ], [])
  157. AC_SUBST(GLOBAL_CFLAGS)
  158. AC_SUBST(GLOBAL_CXXFLAGS)
  159. AC_SUBST(GLOBAL_LDFLAGS)
  160. case "$GLOBAL_CFLAGS" in
  161. *-fvisibility=hidden*)
  162. AC_DEFINE([HAVE_FVISIBILITY], [1], [Define if compiled with -fvisibility=hidden])
  163. esac
  164. AC_ARG_WITH([sanitizers],
  165. [AS_HELP_STRING([--with-sanitizers],
  166. [build libplist with sanitizers (default is no)])],
  167. [build_sanitizers=${withval}],
  168. [])
  169. AC_ARG_WITH([fuzzers],
  170. [AS_HELP_STRING([--with-fuzzers],
  171. [build fuzzers (implies --with-sanitizers, default is no)])],
  172. [build_fuzzers=${withval}],
  173. [build_fuzzers=no])
  174. AC_ARG_WITH([tests],
  175. [AS_HELP_STRING([--without-tests],
  176. [Do not build libplist test suite (default is yes)])],
  177. [build_tests=${withval}],
  178. [build_tests=${build_tools}])
  179. if test "x$build_tests" = "xyes" -a "x$build_tools" != "xyes"; then
  180. AC_MSG_ERROR([Building the test suite requires plistutil. Reconfigure with --with-tools=yes to enable.])
  181. fi
  182. if test "x$build_fuzzers" = "xyes"; then
  183. if test "x$build_sanitizers" = "xno"; then
  184. AC_MSG_ERROR([--with-fuzzers implies --with-sanitizers, but --without-sanitizers was given. This does not work.])
  185. fi
  186. build_sanitizers=yes
  187. fi
  188. if test "x$build_sanitizers" = "xyes"; then
  189. AS_COMPILER_FLAG([-fsanitize=address], [
  190. SANITIZER_FLAGS+=" -fsanitize=address"
  191. ASAN_AVAILABLE=yes
  192. ], [])
  193. if test "$ASAN_AVAILABLE" = "yes"; then
  194. AS_COMPILER_FLAG([-fsanitize=address -fsanitize-address-use-after-scope], [
  195. SANITIZER_FLAGS+=" -fsanitize-address-use-after-scope"
  196. ], [])
  197. SANITIZERS+="ASAN "
  198. fi
  199. AS_COMPILER_FLAG([-fsanitize=undefined], [
  200. SANITIZER_FLAGS+=" -fsanitize=undefined"
  201. UBSAN_AVAILABLE=yes
  202. ], [])
  203. if test "$UBSAN_AVAILABLE" = "yes"; then
  204. SANITIZERS+="UBSAN "
  205. fi
  206. if test -z "$SANITIZER_FLAGS"; then
  207. AC_MSG_ERROR([compiler doesn't support -fsanitize=address nor -fsanitize=undefined])
  208. fi
  209. COVERAGE_CHECKS="trace-pc-guard trace-cmp edge"
  210. for COV_CHECK in $COVERAGE_CHECKS; do
  211. AS_COMPILER_FLAG([-fsanitize-coverage=$COV_CHECK], [
  212. if test -z "$SAN_COV_FLAGS"; then
  213. SAN_COV_FLAGS="$COV_CHECK"
  214. else
  215. SAN_COV_FLAGS+=",$COV_CHECK"
  216. fi
  217. ], [])
  218. done
  219. if test -n "$SAN_COV_FLAGS"; then
  220. SANITIZER_FLAGS+=" -fsanitize-coverage=$SAN_COV_FLAGS"
  221. SANITIZERS+="+coverage "
  222. else
  223. AC_MSG_WARN([No sanitizer coverage supported by compiler])
  224. fi
  225. CFLAGS="-O1"
  226. AS_COMPILER_FLAG([-fno-omit-frame-pointer], [
  227. CFLAGS+=" -fno-omit-frame-pointer"
  228. ], [])
  229. AS_COMPILER_FLAG([-gline-tables-only], [
  230. CFLAGS+=" -gline-tables-only"
  231. ],
  232. [
  233. CFLAGS+=" -g"
  234. ])
  235. EXTRA_CONF+=" Enabled sanitizers ......: $SANITIZERS
  236. "
  237. CFLAGS+=" $SANITIZER_FLAGS"
  238. CXXFLAGS="$CFLAGS -std=c++11"
  239. fi
  240. if test "x$build_fuzzers" = "xyes"; then
  241. IS_CLANG=`$CXX --version 2>/dev/null |grep clang`
  242. case "$IS_CLANG" in
  243. *clang*)
  244. ;;
  245. *)
  246. AC_MSG_WARN([building fuzzers requires clang/clang++ (continuing anyway)])
  247. ;;
  248. esac
  249. CFLAGS+=" -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION"
  250. EXTRA_CONF+=" Build fuzzers ...........: yes
  251. "
  252. fi
  253. AM_CONDITIONAL([BUILD_FUZZERS],[test "x$build_fuzzers" = "xyes"])
  254. AM_CONDITIONAL([BUILD_TESTS],[test "x$build_tests" != "xno"])
  255. if test "x$build_fuzzers" = "xyes" || test "x$build_sanitizers" = "xyes"; then
  256. AS_COMPILER_FLAGS(TEST_CFLAGS, [$CFLAGS])
  257. fi
  258. m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
  259. AC_CONFIG_FILES([
  260. Makefile
  261. libcnary/Makefile
  262. src/Makefile
  263. src/libplist-2.0.pc
  264. src/libplist++-2.0.pc
  265. include/Makefile
  266. tools/Makefile
  267. docs/Makefile
  268. cython/Makefile
  269. test/Makefile
  270. fuzz/Makefile
  271. doxygen.cfg
  272. ])
  273. AC_OUTPUT
  274. echo "
  275. Configuration for $PACKAGE $VERSION:
  276. -------------------------------------------
  277. Install prefix ..........: $prefix
  278. Debug code ..............: $debug
  279. Python bindings .........: $cython_python_bindings
  280. Build tools .............: $build_tools
  281. Build test suite ........: $build_tests
  282. $EXTRA_CONF
  283. Now type 'make' to build $PACKAGE $VERSION,
  284. and then 'make install' for installation.
  285. "