Remove unreachable or otherwise redundant code
[bitcoinplatinum.git] / configure.ac
blob160be397ba5fab0b435baffc4df678c08cfb785c
1 dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
2 AC_PREREQ([2.60])
3 define(_CLIENT_VERSION_MAJOR, 0)
4 define(_CLIENT_VERSION_MINOR, 14)
5 define(_CLIENT_VERSION_REVISION, 99)
6 define(_CLIENT_VERSION_BUILD, 0)
7 define(_CLIENT_VERSION_IS_RELEASE, false)
8 define(_COPYRIGHT_YEAR, 2017)
9 define(_COPYRIGHT_HOLDERS,[The %s developers])
10 define(_COPYRIGHT_HOLDERS_SUBSTITUTION,[[Bitcoin Core]])
11 AC_INIT([Bitcoin Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[https://github.com/bitcoin/bitcoin/issues],[bitcoin],[https://bitcoincore.org/])
12 AC_CONFIG_SRCDIR([src/validation.cpp])
13 AC_CONFIG_HEADERS([src/config/bitcoin-config.h])
14 AC_CONFIG_AUX_DIR([build-aux])
15 AC_CONFIG_MACRO_DIR([build-aux/m4])
17 BITCOIN_DAEMON_NAME=bitcoind
18 BITCOIN_GUI_NAME=bitcoin-qt
19 BITCOIN_CLI_NAME=bitcoin-cli
20 BITCOIN_TX_NAME=bitcoin-tx
22 AC_CANONICAL_HOST
24 AH_TOP([#ifndef BITCOIN_CONFIG_H])
25 AH_TOP([#define BITCOIN_CONFIG_H])
26 AH_BOTTOM([#endif //BITCOIN_CONFIG_H])
28 dnl faketime breaks configure and is only needed for make. Disable it here.
29 unset FAKETIME
31 dnl Automake init set-up and checks
32 AM_INIT_AUTOMAKE([no-define subdir-objects foreign])
34 dnl faketime messes with timestamps and causes configure to be re-run.
35 dnl --disable-maintainer-mode can be used to bypass this.
36 AM_MAINTAINER_MODE([enable])
38 dnl make the compilation flags quiet unless V=1 is used
39 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
41 dnl Compiler checks (here before libtool).
42 if test "x${CXXFLAGS+set}" = "xset"; then
43   CXXFLAGS_overridden=yes
44 else
45   CXXFLAGS_overridden=no
47 AC_PROG_CXX
49 dnl By default, libtool for mingw refuses to link static libs into a dll for
50 dnl fear of mixing pic/non-pic objects, and import/export complications. Since
51 dnl we have those under control, re-enable that functionality.
52 case $host in
53   *mingw*)
54      lt_cv_deplibs_check_method="pass_all"
55   ;;
56 esac
57 dnl Require C++11 compiler (no GNU extensions)
58 AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory], [nodefault])
59 dnl Check if -latomic is required for <std::atomic>
60 CHECK_ATOMIC
62 dnl Unless the user specified OBJCXX, force it to be the same as CXX. This ensures
63 dnl that we get the same -std flags for both.
64 m4_ifdef([AC_PROG_OBJCXX],[
65 if test "x${OBJCXX+set}" = "x"; then
66   OBJCXX="${CXX}"
68 AC_PROG_OBJCXX
71 dnl Libtool init checks.
72 LT_INIT([pic-only])
74 dnl Check/return PATH for base programs.
75 AC_PATH_TOOL(AR, ar)
76 AC_PATH_TOOL(RANLIB, ranlib)
77 AC_PATH_TOOL(STRIP, strip)
78 AC_PATH_TOOL(GCOV, gcov)
79 AC_PATH_PROG(LCOV, lcov)
80 dnl Python 3.x is supported from 3.4 on (see https://github.com/bitcoin/bitcoin/issues/7893)
81 AC_PATH_PROGS([PYTHON], [python3.6 python3.5 python3.4 python3 python2.7 python2 python])
82 AC_PATH_PROG(GENHTML, genhtml)
83 AC_PATH_PROG([GIT], [git])
84 AC_PATH_PROG(CCACHE,ccache)
85 AC_PATH_PROG(XGETTEXT,xgettext)
86 AC_PATH_PROG(HEXDUMP,hexdump)
87 AC_PATH_TOOL(READELF, readelf)
88 AC_PATH_TOOL(CPPFILT, c++filt)
89 AC_PATH_TOOL(OBJCOPY, objcopy)
91 AC_ARG_VAR(PYTHONPATH, Augments the default search path for python module files)
93 # Enable wallet
94 AC_ARG_ENABLE([wallet],
95   [AS_HELP_STRING([--disable-wallet],
96   [disable wallet (enabled by default)])],
97   [enable_wallet=$enableval],
98   [enable_wallet=yes])
100 AC_ARG_WITH([miniupnpc],
101   [AS_HELP_STRING([--with-miniupnpc],
102   [enable UPNP (default is yes if libminiupnpc is found)])],
103   [use_upnp=$withval],
104   [use_upnp=auto])
106 AC_ARG_ENABLE([upnp-default],
107   [AS_HELP_STRING([--enable-upnp-default],
108   [if UPNP is enabled, turn it on at startup (default is no)])],
109   [use_upnp_default=$enableval],
110   [use_upnp_default=no])
112 AC_ARG_ENABLE(tests,
113     AS_HELP_STRING([--disable-tests],[do not compile tests (default is to compile)]),
114     [use_tests=$enableval],
115     [use_tests=yes])
117 AC_ARG_ENABLE(gui-tests,
118     AS_HELP_STRING([--disable-gui-tests],[do not compile GUI tests (default is to compile if GUI and tests enabled)]),
119     [use_gui_tests=$enableval],
120     [use_gui_tests=$use_tests])
122 AC_ARG_ENABLE(bench,
123     AS_HELP_STRING([--disable-bench],[do not compile benchmarks (default is to compile)]),
124     [use_bench=$enableval],
125     [use_bench=yes])
127 AC_ARG_ENABLE([extended-functional-tests],
128     AS_HELP_STRING([--enable-extended-functional-tests],[enable expensive functional tests when using lcov (default no)]),
129     [use_extended_functional_tests=$enableval],
130     [use_extended_functional_tests=no])
132 AC_ARG_WITH([qrencode],
133   [AS_HELP_STRING([--with-qrencode],
134   [enable QR code support (default is yes if qt is enabled and libqrencode is found)])],
135   [use_qr=$withval],
136   [use_qr=auto])
138 AC_ARG_ENABLE([hardening],
139   [AS_HELP_STRING([--disable-hardening],
140   [do not attempt to harden the resulting executables (default is to harden)])],
141   [use_hardening=$enableval],
142   [use_hardening=yes])
144 AC_ARG_ENABLE([reduce-exports],
145   [AS_HELP_STRING([--enable-reduce-exports],
146   [attempt to reduce exported symbols in the resulting executables (default is no)])],
147   [use_reduce_exports=$enableval],
148   [use_reduce_exports=no])
150 AC_ARG_ENABLE([ccache],
151   [AS_HELP_STRING([--disable-ccache],
152   [do not use ccache for building (default is to use if found)])],
153   [use_ccache=$enableval],
154   [use_ccache=auto])
156 AC_ARG_ENABLE([lcov],
157   [AS_HELP_STRING([--enable-lcov],
158   [enable lcov testing (default is no)])],
159   [use_lcov=yes],
160   [use_lcov=no])
162 AC_ARG_ENABLE([glibc-back-compat],
163   [AS_HELP_STRING([--enable-glibc-back-compat],
164   [enable backwards compatibility with glibc])],
165   [use_glibc_compat=$enableval],
166   [use_glibc_compat=no])
168 AC_ARG_WITH([system-univalue],
169   [AS_HELP_STRING([--with-system-univalue],
170   [Build with system UniValue (default is no)])],
171   [system_univalue=$withval],
172   [system_univalue=no]
174 AC_ARG_ENABLE([zmq],
175   [AS_HELP_STRING([--disable-zmq],
176   [disable ZMQ notifications])],
177   [use_zmq=$enableval],
178   [use_zmq=yes])
180 AC_ARG_WITH([protoc-bindir],[AS_HELP_STRING([--with-protoc-bindir=BIN_DIR],[specify protoc bin path])], [protoc_bin_path=$withval], [])
182 AC_ARG_ENABLE(man,
183     [AS_HELP_STRING([--disable-man],
184                     [do not install man pages (default is to install)])],,
185     enable_man=yes)
186 AM_CONDITIONAL(ENABLE_MAN, test "$enable_man" != no)
188 # Enable debug
189 AC_ARG_ENABLE([debug],
190     [AS_HELP_STRING([--enable-debug],
191                     [use debug compiler flags and macros (default is no)])],
192     [enable_debug=$enableval],
193     [enable_debug=no])
195 # Turn warnings into errors
196 AC_ARG_ENABLE([werror],
197     [AS_HELP_STRING([--enable-werror],
198                     [Treat certain compiler warnings as errors (default is no)])],
199     [enable_werror=$enableval],
200     [enable_werror=no])
202 AC_LANG_PUSH([C++])
203 AX_CHECK_COMPILE_FLAG([-Werror],[CXXFLAG_WERROR="-Werror"],[CXXFLAG_WERROR=""])
205 if test "x$enable_debug" = xyes; then
206     CPPFLAGS="$CPPFLAGS -DDEBUG -DDEBUG_LOCKORDER"
207     if test "x$GCC" = xyes; then
208         CFLAGS="$CFLAGS -g3 -O0"
209     fi
211     if test "x$GXX" = xyes; then
212         CXXFLAGS="$CXXFLAGS -g3 -O0"
213     fi
216 ERROR_CXXFLAGS=
217 if test "x$enable_werror" = "xyes"; then
218   if test "x$CXXFLAG_WERROR" = "x"; then
219     AC_MSG_ERROR("enable-werror set but -Werror is not usable")
220   fi
221   AX_CHECK_COMPILE_FLAG([-Werror=vla],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=vla"],,[[$CXXFLAG_WERROR]])
224 if test "x$CXXFLAGS_overridden" = "xno"; then
225   AX_CHECK_COMPILE_FLAG([-Wall],[CXXFLAGS="$CXXFLAGS -Wall"],,[[$CXXFLAG_WERROR]])
226   AX_CHECK_COMPILE_FLAG([-Wextra],[CXXFLAGS="$CXXFLAGS -Wextra"],,[[$CXXFLAG_WERROR]])
227   AX_CHECK_COMPILE_FLAG([-Wformat],[CXXFLAGS="$CXXFLAGS -Wformat"],,[[$CXXFLAG_WERROR]])
228   AX_CHECK_COMPILE_FLAG([-Wvla],[CXXFLAGS="$CXXFLAGS -Wvla"],,[[$CXXFLAG_WERROR]])
229   AX_CHECK_COMPILE_FLAG([-Wformat-security],[CXXFLAGS="$CXXFLAGS -Wformat-security"],,[[$CXXFLAG_WERROR]])
231   ## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
232   ## unknown options if any other warning is produced. Test the -Wfoo case, and
233   ## set the -Wno-foo case if it works.
234   AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[CXXFLAGS="$CXXFLAGS -Wno-unused-parameter"],,[[$CXXFLAG_WERROR]])
235   AX_CHECK_COMPILE_FLAG([-Wself-assign],[CXXFLAGS="$CXXFLAGS -Wno-self-assign"],,[[$CXXFLAG_WERROR]])
236   AX_CHECK_COMPILE_FLAG([-Wunused-local-typedef],[CXXFLAGS="$CXXFLAGS -Wno-unused-local-typedef"],,[[$CXXFLAG_WERROR]])
237   AX_CHECK_COMPILE_FLAG([-Wdeprecated-register],[CXXFLAGS="$CXXFLAGS -Wno-deprecated-register"],,[[$CXXFLAG_WERROR]])
238   AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough],[CXXFLAGS="$CXXFLAGS -Wno-implicit-fallthrough"],,[[$CXXFLAG_WERROR]])
240 CPPFLAGS="$CPPFLAGS -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS"
242 AC_ARG_WITH([utils],
243   [AS_HELP_STRING([--with-utils],
244   [build bitcoin-cli bitcoin-tx (default=yes)])],
245   [build_bitcoin_utils=$withval],
246   [build_bitcoin_utils=yes])
248 AC_ARG_WITH([libs],
249   [AS_HELP_STRING([--with-libs],
250   [build libraries (default=yes)])],
251   [build_bitcoin_libs=$withval],
252   [build_bitcoin_libs=yes])
254 AC_ARG_WITH([daemon],
255   [AS_HELP_STRING([--with-daemon],
256   [build bitcoind daemon (default=yes)])],
257   [build_bitcoind=$withval],
258   [build_bitcoind=yes])
260 use_pkgconfig=yes
261 case $host in
262   *mingw*)
264      #pkgconfig does more harm than good with MinGW
265      use_pkgconfig=no
267      TARGET_OS=windows
268      AC_CHECK_LIB([mingwthrd],      [main],, AC_MSG_ERROR(lib missing))
269      AC_CHECK_LIB([kernel32],      [main],, AC_MSG_ERROR(lib missing))
270      AC_CHECK_LIB([user32],      [main],, AC_MSG_ERROR(lib missing))
271      AC_CHECK_LIB([gdi32],      [main],, AC_MSG_ERROR(lib missing))
272      AC_CHECK_LIB([comdlg32],      [main],, AC_MSG_ERROR(lib missing))
273      AC_CHECK_LIB([winspool],      [main],, AC_MSG_ERROR(lib missing))
274      AC_CHECK_LIB([winmm],      [main],, AC_MSG_ERROR(lib missing))
275      AC_CHECK_LIB([shell32],      [main],, AC_MSG_ERROR(lib missing))
276      AC_CHECK_LIB([comctl32],      [main],, AC_MSG_ERROR(lib missing))
277      AC_CHECK_LIB([ole32],      [main],, AC_MSG_ERROR(lib missing))
278      AC_CHECK_LIB([oleaut32],      [main],, AC_MSG_ERROR(lib missing))
279      AC_CHECK_LIB([uuid],      [main],, AC_MSG_ERROR(lib missing))
280      AC_CHECK_LIB([rpcrt4],      [main],, AC_MSG_ERROR(lib missing))
281      AC_CHECK_LIB([advapi32],      [main],, AC_MSG_ERROR(lib missing))
282      AC_CHECK_LIB([ws2_32],      [main],, AC_MSG_ERROR(lib missing))
283      AC_CHECK_LIB([mswsock],      [main],, AC_MSG_ERROR(lib missing))
284      AC_CHECK_LIB([shlwapi],      [main],, AC_MSG_ERROR(lib missing))
285      AC_CHECK_LIB([iphlpapi],      [main],, AC_MSG_ERROR(lib missing))
286      AC_CHECK_LIB([crypt32],      [main],, AC_MSG_ERROR(lib missing))
288      # -static is interpreted by libtool, where it has a different meaning.
289      # In libtool-speak, it's -all-static.
290      AX_CHECK_LINK_FLAG([[-static]],[LIBTOOL_APP_LDFLAGS="$LIBTOOL_APP_LDFLAGS -all-static"])
292      AC_PATH_PROG([MAKENSIS], [makensis], none)
293      if test x$MAKENSIS = xnone; then
294        AC_MSG_WARN("makensis not found. Cannot create installer.")
295      fi
297      AC_PATH_TOOL(WINDRES, windres, none)
298      if test x$WINDRES = xnone; then
299        AC_MSG_ERROR("windres not found")
300      fi
302      CPPFLAGS="$CPPFLAGS -D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB"
303      LEVELDB_TARGET_FLAGS="-DOS_WINDOWS"
304      if test "x$CXXFLAGS_overridden" = "xno"; then
305        CXXFLAGS="$CXXFLAGS -w"
306      fi
307      case $host in
308        i?86-*) WINDOWS_BITS=32 ;;
309        x86_64-*) WINDOWS_BITS=64 ;;
310        *) AC_MSG_ERROR("Could not determine win32/win64 for installer") ;;
311      esac
312      AC_SUBST(WINDOWS_BITS)
314      dnl libtool insists upon adding -nostdlib and a list of objects/libs to link against.
315      dnl That breaks our ability to build dll's with static libgcc/libstdc++/libssp. Override
316      dnl its command here, with the predeps/postdeps removed, and -static inserted. Postdeps are
317      dnl also overridden to prevent their insertion later.
318      dnl This should only affect dll's.
319      archive_cmds_CXX="\$CC -shared \$libobjs \$deplibs \$compiler_flags -static -o \$output_objdir/\$soname \${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker \$lib"
320      postdeps_CXX=
322      ;;
323   *darwin*)
324      TARGET_OS=darwin
325      LEVELDB_TARGET_FLAGS="-DOS_MACOSX"
326      if  test x$cross_compiling != xyes; then
327        BUILD_OS=darwin
328        AC_CHECK_PROG([PORT],port, port)
329        if test x$PORT = xport; then
330          dnl add default macports paths
331          CPPFLAGS="$CPPFLAGS -isystem /opt/local/include"
332          LIBS="$LIBS -L/opt/local/lib"
333          if test -d /opt/local/include/db48; then
334            CPPFLAGS="$CPPFLAGS -I/opt/local/include/db48"
335            LIBS="$LIBS -L/opt/local/lib/db48"
336          fi
337        fi
339        AC_PATH_PROGS([RSVG_CONVERT], [rsvg-convert rsvg],rsvg-convert)
340        AC_CHECK_PROG([BREW],brew, brew)
341        if test x$BREW = xbrew; then
342          dnl These Homebrew packages may be keg-only, meaning that they won't be found
343          dnl in expected paths because they may conflict with system files. Ask
344          dnl Homebrew where each one is located, then adjust paths accordingly.
345          dnl It's safe to add these paths even if the functionality is disabled by
346          dnl the user (--without-wallet or --without-gui for example).
348          openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
349          bdb_prefix=`$BREW --prefix berkeley-db4 2>/dev/null`
350          qt5_prefix=`$BREW --prefix qt5 2>/dev/null`
351          if test x$openssl_prefix != x; then
352            PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
353            export PKG_CONFIG_PATH
354          fi
355          if test x$bdb_prefix != x; then
356            CPPFLAGS="$CPPFLAGS -I$bdb_prefix/include"
357            LIBS="$LIBS -L$bdb_prefix/lib"
358          fi
359          if test x$qt5_prefix != x; then
360            PKG_CONFIG_PATH="$qt5_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
361            export PKG_CONFIG_PATH
362          fi
363        fi
364      else
365        case $build_os in
366          *darwin*)
367            BUILD_OS=darwin
368            ;;
369          *)
370            AC_PATH_TOOL([INSTALLNAMETOOL], [install_name_tool], install_name_tool)
371            AC_PATH_TOOL([OTOOL], [otool], otool)
372            AC_PATH_PROGS([GENISOIMAGE], [genisoimage mkisofs],genisoimage)
373            AC_PATH_PROGS([RSVG_CONVERT], [rsvg-convert rsvg],rsvg-convert)
374            AC_PATH_PROGS([IMAGEMAGICK_CONVERT], [convert],convert)
375            AC_PATH_PROGS([TIFFCP], [tiffcp],tiffcp)
377            dnl libtool will try to strip the static lib, which is a problem for
378            dnl cross-builds because strip attempts to call a hard-coded ld,
379            dnl which may not exist in the path. Stripping the .a is not
380            dnl necessary, so just disable it.
381            old_striplib=
382            ;;
383        esac
384      fi
386      AX_CHECK_LINK_FLAG([[-Wl,-headerpad_max_install_names]], [LDFLAGS="$LDFLAGS -Wl,-headerpad_max_install_names"])
387      CPPFLAGS="$CPPFLAGS -DMAC_OSX"
388      OBJCXXFLAGS="$CXXFLAGS"
389      ;;
390    *linux*)
391      TARGET_OS=linux
392      LEVELDB_TARGET_FLAGS="-DOS_LINUX"
393      ;;
394    *freebsd*)
395      LEVELDB_TARGET_FLAGS="-DOS_FREEBSD"
396      ;;
397    *openbsd*)
398      LEVELDB_TARGET_FLAGS="-DOS_OPENBSD"
399      ;;
400    *)
401      OTHER_OS=`echo ${host_os} | awk '{print toupper($0)}'`
402      AC_MSG_WARN([Guessing LevelDB OS as OS_${OTHER_OS}, please check whether this is correct, if not add an entry to configure.ac.])
403      LEVELDB_TARGET_FLAGS="-DOS_${OTHER_OS}"
404      ;;
405 esac
407 if test x$use_pkgconfig = xyes; then
408   m4_ifndef([PKG_PROG_PKG_CONFIG], [AC_MSG_ERROR(PKG_PROG_PKG_CONFIG macro not found. Please install pkg-config and re-run autogen.sh.)])
409   m4_ifdef([PKG_PROG_PKG_CONFIG], [
410   PKG_PROG_PKG_CONFIG
411   if test x"$PKG_CONFIG" = "x"; then
412     AC_MSG_ERROR(pkg-config not found.)
413   fi
414   ])
417 if test x$use_extended_functional_tests != xno; then
418   AC_SUBST(EXTENDED_FUNCTIONAL_TESTS, --extended)
421 if test x$use_lcov = xyes; then
422   if test x$LCOV = x; then
423     AC_MSG_ERROR("lcov testing requested but lcov not found")
424   fi
425   if test x$GCOV = x; then
426     AC_MSG_ERROR("lcov testing requested but gcov not found")
427   fi
428   if test x$PYTHON = x; then
429     AC_MSG_ERROR("lcov testing requested but python not found")
430   fi
431   if test x$GENHTML = x; then
432     AC_MSG_ERROR("lcov testing requested but genhtml not found")
433   fi
434   LCOV="$LCOV --gcov-tool=$GCOV"
435   AX_CHECK_LINK_FLAG([[--coverage]], [LDFLAGS="$LDFLAGS --coverage"],
436     [AC_MSG_ERROR("lcov testing requested but --coverage linker flag does not work")])
437   AX_CHECK_COMPILE_FLAG([--coverage],[CXXFLAGS="$CXXFLAGS --coverage"],
438     [AC_MSG_ERROR("lcov testing requested but --coverage flag does not work")])
441 dnl Check for endianness
442 AC_C_BIGENDIAN
444 dnl Check for pthread compile/link requirements
445 AX_PTHREAD
447 # The following macro will add the necessary defines to bitcoin-config.h, but
448 # they also need to be passed down to any subprojects. Pull the results out of
449 # the cache and add them to CPPFLAGS.
450 AC_SYS_LARGEFILE
451 # detect POSIX or GNU variant of strerror_r
452 AC_FUNC_STRERROR_R
454 if test x$ac_cv_sys_file_offset_bits != x &&
455    test x$ac_cv_sys_file_offset_bits != xno &&
456    test x$ac_cv_sys_file_offset_bits != xunknown; then
457   CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=$ac_cv_sys_file_offset_bits"
460 if test x$ac_cv_sys_large_files != x &&
461    test x$ac_cv_sys_large_files != xno &&
462    test x$ac_cv_sys_large_files != xunknown; then
463   CPPFLAGS="$CPPFLAGS -D_LARGE_FILES=$ac_cv_sys_large_files"
466 AX_CHECK_LINK_FLAG([[-Wl,--large-address-aware]], [LDFLAGS="$LDFLAGS -Wl,--large-address-aware"])
468 AX_GCC_FUNC_ATTRIBUTE([visibility])
469 AX_GCC_FUNC_ATTRIBUTE([dllexport])
470 AX_GCC_FUNC_ATTRIBUTE([dllimport])
472 if test x$use_glibc_compat != xno; then
474   #glibc absorbed clock_gettime in 2.17. librt (its previous location) is safe to link
475   #in anyway for back-compat.
476   AC_CHECK_LIB([rt],[clock_gettime],, AC_MSG_ERROR(lib missing))
478   #__fdelt_chk's params and return type have changed from long unsigned int to long int.
479   # See which one is present here.
480   AC_MSG_CHECKING(__fdelt_chk type)
481   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifdef _FORTIFY_SOURCE
482                     #undef _FORTIFY_SOURCE
483                   #endif
484                   #define _FORTIFY_SOURCE 2
485                   #include <sys/select.h>
486      extern "C" long unsigned int __fdelt_warn(long unsigned int);]],[[]])],
487     [ fdelt_type="long unsigned int"],
488     [ fdelt_type="long int"])
489   AC_MSG_RESULT($fdelt_type)
490   AC_DEFINE_UNQUOTED(FDELT_TYPE, $fdelt_type,[parameter and return value type for __fdelt_chk])
491 else
492   AC_SEARCH_LIBS([clock_gettime],[rt])
495 if test x$TARGET_OS != xwindows; then
496   # All windows code is PIC, forcing it on just adds useless compile warnings
497   AX_CHECK_COMPILE_FLAG([-fPIC],[PIC_FLAGS="-fPIC"])
500 if test x$use_hardening != xno; then
501   AX_CHECK_COMPILE_FLAG([-Wstack-protector],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"])
502   AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"])
504   AX_CHECK_PREPROC_FLAG([-D_FORTIFY_SOURCE=2],[
505     AX_CHECK_PREPROC_FLAG([-U_FORTIFY_SOURCE],[
506       HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -U_FORTIFY_SOURCE"
507     ])
508     HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -D_FORTIFY_SOURCE=2"
509   ])
511   AX_CHECK_LINK_FLAG([[-Wl,--dynamicbase]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--dynamicbase"])
512   AX_CHECK_LINK_FLAG([[-Wl,--nxcompat]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--nxcompat"])
513   AX_CHECK_LINK_FLAG([[-Wl,--high-entropy-va]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--high-entropy-va"])
514   AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"])
515   AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"])
517   if test x$TARGET_OS != xwindows; then
518     AX_CHECK_COMPILE_FLAG([-fPIE],[PIE_FLAGS="-fPIE"])
519     AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"])
520   fi
522   case $host in
523     *mingw*)
524        AC_CHECK_LIB([ssp],      [main],, AC_MSG_ERROR(lib missing))
525     ;;
526   esac
529 dnl this flag screws up non-darwin gcc even when the check fails. special-case it.
530 if test x$TARGET_OS = xdarwin; then
531   AX_CHECK_LINK_FLAG([[-Wl,-dead_strip]], [LDFLAGS="$LDFLAGS -Wl,-dead_strip"])
534 AC_CHECK_HEADERS([endian.h sys/endian.h byteswap.h stdio.h stdlib.h unistd.h strings.h sys/types.h sys/stat.h sys/select.h sys/prctl.h])
536 AC_CHECK_DECLS([strnlen])
538 # Check for daemon(3), unrelated to --with-daemon (although used by it)
539 AC_CHECK_DECLS([daemon])
541 AC_CHECK_DECLS([le16toh, le32toh, le64toh, htole16, htole32, htole64, be16toh, be32toh, be64toh, htobe16, htobe32, htobe64],,,
542                 [#if HAVE_ENDIAN_H
543                  #include <endian.h>
544                  #elif HAVE_SYS_ENDIAN_H
545                  #include <sys/endian.h>
546                  #endif])
548 AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64],,,
549                 [#if HAVE_BYTESWAP_H
550                  #include <byteswap.h>
551                  #endif])
553 AC_CHECK_DECLS([__builtin_clz, __builtin_clzl, __builtin_clzll])
555 dnl Check for MSG_NOSIGNAL
556 AC_MSG_CHECKING(for MSG_NOSIGNAL)
557 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]],
558  [[ int f = MSG_NOSIGNAL; ]])],
559  [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_MSG_NOSIGNAL, 1,[Define this symbol if you have MSG_NOSIGNAL]) ],
560  [ AC_MSG_RESULT(no)]
563 dnl Check for MSG_DONTWAIT
564 AC_MSG_CHECKING(for MSG_DONTWAIT)
565 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]],
566  [[ int f = MSG_DONTWAIT; ]])],
567  [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_MSG_DONTWAIT, 1,[Define this symbol if you have MSG_DONTWAIT]) ],
568  [ AC_MSG_RESULT(no)]
571 dnl Check for malloc_info (for memory statistics information in getmemoryinfo)
572 AC_MSG_CHECKING(for getmemoryinfo)
573 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <malloc.h>]],
574  [[ int f = malloc_info(0, NULL); ]])],
575  [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_MALLOC_INFO, 1,[Define this symbol if you have malloc_info]) ],
576  [ AC_MSG_RESULT(no)]
579 dnl Check for mallopt(M_ARENA_MAX) (to set glibc arenas)
580 AC_MSG_CHECKING(for mallopt M_ARENA_MAX)
581 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <malloc.h>]],
582  [[ mallopt(M_ARENA_MAX, 1); ]])],
583  [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_MALLOPT_ARENA_MAX, 1,[Define this symbol if you have mallopt with M_ARENA_MAX]) ],
584  [ AC_MSG_RESULT(no)]
587 AC_MSG_CHECKING([for visibility attribute])
588 AC_LINK_IFELSE([AC_LANG_SOURCE([
589   int foo_def( void ) __attribute__((visibility("default")));
590   int main(){}
591   ])],
592   [
593     AC_DEFINE(HAVE_VISIBILITY_ATTRIBUTE,1,[Define if the visibility attribute is supported.])
594     AC_MSG_RESULT(yes)
595   ],
596   [
597     AC_MSG_RESULT(no)
598     if test x$use_reduce_exports = xyes; then
599       AC_MSG_ERROR([Cannot find a working visibility attribute. Use --disable-reduce-exports.])
600     fi
601   ]
604 # Check for different ways of gathering OS randomness
605 AC_MSG_CHECKING(for Linux getrandom syscall)
606 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>
607   #include <sys/syscall.h>
608   #include <linux/random.h>]],
609  [[ syscall(SYS_getrandom, nullptr, 32, 0); ]])],
610  [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYS_GETRANDOM, 1,[Define this symbol if the Linux getrandom system call is available]) ],
611  [ AC_MSG_RESULT(no)]
614 AC_MSG_CHECKING(for getentropy)
615 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>]],
616  [[ getentropy(nullptr, 32) ]])],
617  [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_GETENTROPY, 1,[Define this symbol if the BSD getentropy system call is available]) ],
618  [ AC_MSG_RESULT(no)]
621 AC_MSG_CHECKING(for sysctl KERN_ARND)
622 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
623   #include <sys/sysctl.h>]],
624  [[ static const int name[2] = {CTL_KERN, KERN_ARND};
625     sysctl(name, 2, nullptr, nullptr, nullptr, 0); ]])],
626  [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCTL_ARND, 1,[Define this symbol if the BSD sysctl(KERN_ARND) is available]) ],
627  [ AC_MSG_RESULT(no)]
630 # Check for reduced exports
631 if test x$use_reduce_exports = xyes; then
632   AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[RE_CXXFLAGS="-fvisibility=hidden"],
633   [AC_MSG_ERROR([Cannot set default symbol visibility. Use --disable-reduce-exports.])])
636 LEVELDB_CPPFLAGS=
637 LIBLEVELDB=
638 LIBMEMENV=
639 AM_CONDITIONAL([EMBEDDED_LEVELDB],[true])
640 AC_SUBST(LEVELDB_CPPFLAGS)
641 AC_SUBST(LIBLEVELDB)
642 AC_SUBST(LIBMEMENV)
644 if test x$enable_wallet != xno; then
645     dnl Check for libdb_cxx only if wallet enabled
646     BITCOIN_FIND_BDB48
649 dnl Check for libminiupnpc (optional)
650 if test x$use_upnp != xno; then
651   AC_CHECK_HEADERS(
652     [miniupnpc/miniwget.h miniupnpc/miniupnpc.h miniupnpc/upnpcommands.h miniupnpc/upnperrors.h],
653     [AC_CHECK_LIB([miniupnpc], [main],[MINIUPNPC_LIBS=-lminiupnpc], [have_miniupnpc=no])],
654     [have_miniupnpc=no]
655   )
658 BITCOIN_QT_INIT
660 dnl sets $bitcoin_enable_qt, $bitcoin_enable_qt_test, $bitcoin_enable_qt_dbus
661 BITCOIN_QT_CONFIGURE([$use_pkgconfig], [qt5])
663 if test x$build_bitcoin_utils$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench = xnonononono; then
664     use_boost=no
665 else
666     use_boost=yes
669 if test x$use_boost = xyes; then
671 dnl Minimum required Boost version
672 define(MINIMUM_REQUIRED_BOOST, 1.47.0)
674 dnl Check for boost libs
675 AX_BOOST_BASE([MINIMUM_REQUIRED_BOOST])
676 AX_BOOST_SYSTEM
677 AX_BOOST_FILESYSTEM
678 AX_BOOST_PROGRAM_OPTIONS
679 AX_BOOST_THREAD
680 AX_BOOST_CHRONO
682 dnl Boost 1.56 through 1.62 allow using std::atomic instead of its own atomic
683 dnl counter implementations. In 1.63 and later the std::atomic approach is default.
684 m4_pattern_allow(DBOOST_AC_USE_STD_ATOMIC) dnl otherwise it's treated like a macro
685 BOOST_CPPFLAGS="-DBOOST_SP_USE_STD_ATOMIC -DBOOST_AC_USE_STD_ATOMIC $BOOST_CPPFLAGS"
687 if test x$use_reduce_exports = xyes; then
688   AC_MSG_CHECKING([for working boost reduced exports])
689   TEMP_CPPFLAGS="$CPPFLAGS"
690   CPPFLAGS="$BOOST_CPPFLAGS $CPPFLAGS"
691   AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
692       @%:@include <boost/version.hpp>
693     ]], [[
694       #if BOOST_VERSION >= 104900
695       // Everything is okay
696       #else
697       #  error Boost version is too old
698       #endif
699     ]])],[
700       AC_MSG_RESULT(yes)
701     ],[
702     AC_MSG_ERROR([boost versions < 1.49 are known to be broken with reduced exports. Use --disable-reduce-exports.])
703   ])
704   CPPFLAGS="$TEMP_CPPFLAGS"
708 if test x$use_reduce_exports = xyes; then
709     CXXFLAGS="$CXXFLAGS $RE_CXXFLAGS"
710     AX_CHECK_LINK_FLAG([[-Wl,--exclude-libs,ALL]], [RELDFLAGS="-Wl,--exclude-libs,ALL"])
713 if test x$use_tests = xyes; then
715   if test x$HEXDUMP = x; then
716     AC_MSG_ERROR(hexdump is required for tests)
717   fi
720   if test x$use_boost = xyes; then
722   AX_BOOST_UNIT_TEST_FRAMEWORK
724   dnl Determine if -DBOOST_TEST_DYN_LINK is needed
725   AC_MSG_CHECKING([for dynamic linked boost test])
726   TEMP_LIBS="$LIBS"
727   LIBS="$LIBS $BOOST_LDFLAGS $BOOST_UNIT_TEST_FRAMEWORK_LIB"
728   TEMP_CPPFLAGS="$CPPFLAGS"
729   CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
730   AC_LINK_IFELSE([AC_LANG_SOURCE([
731        #define BOOST_TEST_DYN_LINK
732        #define BOOST_TEST_MAIN
733         #include <boost/test/unit_test.hpp>
735        ])],
736     [AC_MSG_RESULT(yes)]
737     [TESTDEFS="$TESTDEFS -DBOOST_TEST_DYN_LINK"],
738     [AC_MSG_RESULT(no)])
739   LIBS="$TEMP_LIBS"
740   CPPFLAGS="$TEMP_CPPFLAGS"
742   fi
745 if test x$use_boost = xyes; then
747 BOOST_LIBS="$BOOST_LDFLAGS $BOOST_SYSTEM_LIB $BOOST_FILESYSTEM_LIB $BOOST_PROGRAM_OPTIONS_LIB $BOOST_THREAD_LIB $BOOST_CHRONO_LIB"
750 dnl If boost (prior to 1.57) was built without c++11, it emulated scoped enums
751 dnl using c++98 constructs. Unfortunately, this implementation detail leaked into
752 dnl the abi. This was fixed in 1.57.
754 dnl When building against that installed version using c++11, the headers pick up
755 dnl on the native c++11 scoped enum support and enable it, however it will fail to
756 dnl link. This can be worked around by disabling c++11 scoped enums if linking will
757 dnl fail.
758 dnl BOOST_NO_SCOPED_ENUMS was changed to BOOST_NO_CXX11_SCOPED_ENUMS in 1.51.
760 TEMP_LIBS="$LIBS"
761 LIBS="$BOOST_LIBS $LIBS"
762 TEMP_CPPFLAGS="$CPPFLAGS"
763 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
764 AC_MSG_CHECKING([for mismatched boost c++11 scoped enums])
765 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
766   #include "boost/config.hpp"
767   #include "boost/version.hpp"
768   #if !defined(BOOST_NO_SCOPED_ENUMS) && !defined(BOOST_NO_CXX11_SCOPED_ENUMS) && BOOST_VERSION < 105700
769   #define BOOST_NO_SCOPED_ENUMS
770   #define BOOST_NO_CXX11_SCOPED_ENUMS
771   #define CHECK
772   #endif
773   #include "boost/filesystem.hpp"
774   ]],[[
775   #if defined(CHECK)
776     boost::filesystem::copy_file("foo", "bar");
777   #else
778     choke;
779   #endif
780   ]])],
781   [AC_MSG_RESULT(mismatched); BOOST_CPPFLAGS="$BOOST_CPPFLAGS -DBOOST_NO_SCOPED_ENUMS -DBOOST_NO_CXX11_SCOPED_ENUMS"], [AC_MSG_RESULT(ok)])
782 LIBS="$TEMP_LIBS"
783 CPPFLAGS="$TEMP_CPPFLAGS"
785 dnl Boost >= 1.50 uses sleep_for rather than the now-deprecated sleep, however
786 dnl it was broken from 1.50 to 1.52 when backed by nanosleep. Use sleep_for if
787 dnl a working version is available, else fall back to sleep. sleep was removed
788 dnl after 1.56.
789 dnl If neither is available, abort.
790 TEMP_LIBS="$LIBS"
791 LIBS="$BOOST_LIBS $LIBS"
792 TEMP_CPPFLAGS="$CPPFLAGS"
793 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
794 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
795   #include <boost/thread/thread.hpp>
796   #include <boost/version.hpp>
797   ]],[[
798   #if BOOST_VERSION >= 105000 && (!defined(BOOST_HAS_NANOSLEEP) || BOOST_VERSION >= 105200)
799       boost::this_thread::sleep_for(boost::chrono::milliseconds(0));
800   #else
801    choke me
802   #endif
803   ]])],
804   [boost_sleep=yes;
805      AC_DEFINE(HAVE_WORKING_BOOST_SLEEP_FOR, 1, [Define this symbol if boost sleep_for works])],
806   [boost_sleep=no])
807 LIBS="$TEMP_LIBS"
808 CPPFLAGS="$TEMP_CPPFLAGS"
810 if test x$boost_sleep != xyes; then
811 TEMP_LIBS="$LIBS"
812 LIBS="$BOOST_LIBS $LIBS"
813 TEMP_CPPFLAGS="$CPPFLAGS"
814 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
815 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
816   #include <boost/version.hpp>
817   #include <boost/thread.hpp>
818   #include <boost/date_time/posix_time/posix_time_types.hpp>
819   ]],[[
820   #if BOOST_VERSION <= 105600
821       boost::this_thread::sleep(boost::posix_time::milliseconds(0));
822   #else
823    choke me
824   #endif
825   ]])],
826   [boost_sleep=yes; AC_DEFINE(HAVE_WORKING_BOOST_SLEEP, 1, [Define this symbol if boost sleep works])],
827   [boost_sleep=no])
828 LIBS="$TEMP_LIBS"
829 CPPFLAGS="$TEMP_CPPFLAGS"
832 if test x$boost_sleep != xyes; then
833   AC_MSG_ERROR(No working boost sleep implementation found.)
838 if test x$use_pkgconfig = xyes; then
839   : dnl
840   m4_ifdef(
841     [PKG_CHECK_MODULES],
842     [
843       PKG_CHECK_MODULES([SSL], [libssl],, [AC_MSG_ERROR(openssl  not found.)])
844       PKG_CHECK_MODULES([CRYPTO], [libcrypto],,[AC_MSG_ERROR(libcrypto  not found.)])
845       BITCOIN_QT_CHECK([PKG_CHECK_MODULES([PROTOBUF], [protobuf], [have_protobuf=yes], [BITCOIN_QT_FAIL(libprotobuf not found)])])
846       if test x$use_qr != xno; then
847         BITCOIN_QT_CHECK([PKG_CHECK_MODULES([QR], [libqrencode], [have_qrencode=yes], [have_qrencode=no])])
848       fi
849       if test x$build_bitcoin_utils$build_bitcoind$bitcoin_enable_qt$use_tests != xnononono; then
850         PKG_CHECK_MODULES([EVENT], [libevent],, [AC_MSG_ERROR(libevent not found.)])
851         if test x$TARGET_OS != xwindows; then
852           PKG_CHECK_MODULES([EVENT_PTHREADS], [libevent_pthreads],, [AC_MSG_ERROR(libevent_pthreads not found.)])
853         fi
854       fi
856       if test "x$use_zmq" = "xyes"; then
857         PKG_CHECK_MODULES([ZMQ],[libzmq >= 4],
858           [AC_DEFINE([ENABLE_ZMQ],[1],[Define to 1 to enable ZMQ functions])],
859           [AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])
860            AC_MSG_WARN([libzmq version 4.x or greater not found, disabling])
861            use_zmq=no])
862       else
863           AC_DEFINE_UNQUOTED([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])
864       fi
865     ]
866   )
867 else
868   AC_CHECK_HEADER([openssl/crypto.h],,AC_MSG_ERROR(libcrypto headers missing))
869   AC_CHECK_LIB([crypto],      [main],CRYPTO_LIBS=-lcrypto, AC_MSG_ERROR(libcrypto missing))
871   AC_CHECK_HEADER([openssl/ssl.h],, AC_MSG_ERROR(libssl headers missing),)
872   AC_CHECK_LIB([ssl],         [main],SSL_LIBS=-lssl, AC_MSG_ERROR(libssl missing))
874   if test x$build_bitcoin_utils$build_bitcoind$bitcoin_enable_qt$use_tests != xnononono; then
875     AC_CHECK_HEADER([event2/event.h],, AC_MSG_ERROR(libevent headers missing),)
876     AC_CHECK_LIB([event],[main],EVENT_LIBS=-levent,AC_MSG_ERROR(libevent missing))
877     if test x$TARGET_OS != xwindows; then
878       AC_CHECK_LIB([event_pthreads],[main],EVENT_PTHREADS_LIBS=-levent_pthreads,AC_MSG_ERROR(libevent_pthreads missing))
879     fi
880   fi
882   if test "x$use_zmq" = "xyes"; then
883      AC_CHECK_HEADER([zmq.h],
884        [AC_DEFINE([ENABLE_ZMQ],[1],[Define to 1 to enable ZMQ functions])],
885        [AC_MSG_WARN([zmq.h not found, disabling zmq support])
886         use_zmq=no
887         AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])])
888      AC_CHECK_LIB([zmq],[zmq_ctx_shutdown],ZMQ_LIBS=-lzmq,
889        [AC_MSG_WARN([libzmq >= 4.0 not found, disabling zmq support])
890         use_zmq=no
891         AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])])
892   else
893     AC_DEFINE_UNQUOTED([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])
894   fi
896   if test "x$use_zmq" = "xyes"; then
897     dnl Assume libzmq was built for static linking
898     case $host in
899       *mingw*)
900         ZMQ_CFLAGS="$ZMQ_CFLAGS -DZMQ_STATIC"
901       ;;
902     esac
903   fi
905   BITCOIN_QT_CHECK(AC_CHECK_LIB([protobuf] ,[main],[PROTOBUF_LIBS=-lprotobuf], BITCOIN_QT_FAIL(libprotobuf not found)))
906   if test x$use_qr != xno; then
907     BITCOIN_QT_CHECK([AC_CHECK_LIB([qrencode], [main],[QR_LIBS=-lqrencode], [have_qrencode=no])])
908     BITCOIN_QT_CHECK([AC_CHECK_HEADER([qrencode.h],, have_qrencode=no)])
909   fi
912 save_CXXFLAGS="${CXXFLAGS}"
913 CXXFLAGS="${CXXFLAGS} ${CRYPTO_CFLAGS} ${SSL_CFLAGS}"
914 AC_CHECK_DECLS([EVP_MD_CTX_new],,,[AC_INCLUDES_DEFAULT
915 #include <openssl/x509_vfy.h>
917 CXXFLAGS="${save_CXXFLAGS}"
919 dnl univalue check
921 need_bundled_univalue=yes
923 if test x$build_bitcoin_utils$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench = xnonononono; then
924   need_bundled_univalue=no
925 else
927 if test x$system_univalue != xno ; then
928   found_univalue=no
929   if test x$use_pkgconfig = xyes; then
930     : #NOP
931     m4_ifdef(
932       [PKG_CHECK_MODULES],
933       [
934         PKG_CHECK_MODULES([UNIVALUE],[libunivalue],[found_univalue=yes],[true])
935       ]
936     )
937   else
938     AC_CHECK_HEADER([univalue.h],[
939       AC_CHECK_LIB([univalue],  [main],[
940         UNIVALUE_LIBS=-lunivalue
941         found_univalue=yes
942       ],[true])
943     ],[true])
944   fi
946   if test x$found_univalue = xyes ; then
947     system_univalue=yes
948     need_bundled_univalue=no
949   elif test x$system_univalue = xyes ; then
950     AC_MSG_ERROR([univalue not found])
951   else
952     system_univalue=no
953   fi
956 if test x$need_bundled_univalue = xyes ; then
957   UNIVALUE_CFLAGS='-I$(srcdir)/univalue/include'
958   UNIVALUE_LIBS='univalue/libunivalue.la'
963 AM_CONDITIONAL([EMBEDDED_UNIVALUE],[test x$need_bundled_univalue = xyes])
964 AC_SUBST(UNIVALUE_CFLAGS)
965 AC_SUBST(UNIVALUE_LIBS)
967 BITCOIN_QT_PATH_PROGS([PROTOC], [protoc],$protoc_bin_path)
969 AC_MSG_CHECKING([whether to build bitcoind])
970 AM_CONDITIONAL([BUILD_BITCOIND], [test x$build_bitcoind = xyes])
971 AC_MSG_RESULT($build_bitcoind)
973 AC_MSG_CHECKING([whether to build utils (bitcoin-cli bitcoin-tx)])
974 AM_CONDITIONAL([BUILD_BITCOIN_UTILS], [test x$build_bitcoin_utils = xyes])
975 AC_MSG_RESULT($build_bitcoin_utils)
977 AC_MSG_CHECKING([whether to build libraries])
978 AM_CONDITIONAL([BUILD_BITCOIN_LIBS], [test x$build_bitcoin_libs = xyes])
979 if test x$build_bitcoin_libs = xyes; then
980   AC_DEFINE(HAVE_CONSENSUS_LIB, 1, [Define this symbol if the consensus lib has been built])
981   AC_CONFIG_FILES([libbitcoinconsensus.pc:libbitcoinconsensus.pc.in])
983 AC_MSG_RESULT($build_bitcoin_libs)
985 AC_LANG_POP
987 if test "x$use_ccache" != "xno"; then
988   AC_MSG_CHECKING(if ccache should be used)
989   if test x$CCACHE = x; then
990     if test "x$use_ccache" = "xyes"; then
991       AC_MSG_ERROR([ccache not found.]);
992     else
993       use_ccache=no
994     fi
995   else
996     use_ccache=yes
997     CC="$ac_cv_path_CCACHE $CC"
998     CXX="$ac_cv_path_CCACHE $CXX"
999   fi
1000   AC_MSG_RESULT($use_ccache)
1002 if test "x$use_ccache" = "xyes"; then
1003     AX_CHECK_PREPROC_FLAG([-Qunused-arguments],[CPPFLAGS="-Qunused-arguments $CPPFLAGS"])
1006 dnl enable wallet
1007 AC_MSG_CHECKING([if wallet should be enabled])
1008 if test x$enable_wallet != xno; then
1009   AC_MSG_RESULT(yes)
1010   AC_DEFINE_UNQUOTED([ENABLE_WALLET],[1],[Define to 1 to enable wallet functions])
1012 else
1013   AC_MSG_RESULT(no)
1016 dnl enable upnp support
1017 AC_MSG_CHECKING([whether to build with support for UPnP])
1018 if test x$have_miniupnpc = xno; then
1019   if test x$use_upnp = xyes; then
1020      AC_MSG_ERROR("UPnP requested but cannot be built. use --without-miniupnpc")
1021   fi
1022   AC_MSG_RESULT(no)
1023 else
1024   if test x$use_upnp != xno; then
1025     AC_MSG_RESULT(yes)
1026     AC_MSG_CHECKING([whether to build with UPnP enabled by default])
1027     use_upnp=yes
1028     upnp_setting=0
1029     if test x$use_upnp_default != xno; then
1030       use_upnp_default=yes
1031       upnp_setting=1
1032     fi
1033     AC_MSG_RESULT($use_upnp_default)
1034     AC_DEFINE_UNQUOTED([USE_UPNP],[$upnp_setting],[UPnP support not compiled if undefined, otherwise value (0 or 1) determines default state])
1035     if test x$TARGET_OS = xwindows; then
1036       MINIUPNPC_CPPFLAGS="-DSTATICLIB -DMINIUPNP_STATICLIB"
1037     fi
1038   else
1039     AC_MSG_RESULT(no)
1040   fi
1043 dnl these are only used when qt is enabled
1044 BUILD_TEST_QT=""
1045 if test x$bitcoin_enable_qt != xno; then
1046   dnl enable dbus support
1047   AC_MSG_CHECKING([whether to build GUI with support for D-Bus])
1048   if test x$bitcoin_enable_qt_dbus != xno; then
1049     AC_DEFINE([USE_DBUS],[1],[Define if dbus support should be compiled in])
1050   fi
1051   AC_MSG_RESULT($bitcoin_enable_qt_dbus)
1053   dnl enable qr support
1054   AC_MSG_CHECKING([whether to build GUI with support for QR codes])
1055   if test x$have_qrencode = xno; then
1056     if test x$use_qr = xyes; then
1057      AC_MSG_ERROR("QR support requested but cannot be built. use --without-qrencode")
1058     fi
1059     AC_MSG_RESULT(no)
1060   else
1061     if test x$use_qr != xno; then
1062       AC_MSG_RESULT(yes)
1063       AC_DEFINE([USE_QRCODE],[1],[Define if QR support should be compiled in])
1064       use_qr=yes
1065     else
1066       AC_MSG_RESULT(no)
1067     fi
1068   fi
1070   if test x$XGETTEXT = x; then
1071     AC_MSG_WARN("xgettext is required to update qt translations")
1072   fi
1074   AC_MSG_CHECKING([whether to build test_bitcoin-qt])
1075   if test x$use_gui_tests$bitcoin_enable_qt_test = xyesyes; then
1076     AC_MSG_RESULT([yes])
1077     BUILD_TEST_QT="yes"
1078   else
1079     AC_MSG_RESULT([no])
1080   fi
1083 AM_CONDITIONAL([ENABLE_ZMQ], [test "x$use_zmq" = "xyes"])
1085 AC_MSG_CHECKING([whether to build test_bitcoin])
1086 if test x$use_tests = xyes; then
1087   AC_MSG_RESULT([yes])
1088   BUILD_TEST="yes"
1089 else
1090   AC_MSG_RESULT([no])
1091   BUILD_TEST=""
1094 AC_MSG_CHECKING([whether to reduce exports])
1095 if test x$use_reduce_exports = xyes; then
1096   AC_MSG_RESULT([yes])
1097 else
1098   AC_MSG_RESULT([no])
1101 if test x$build_bitcoin_utils$build_bitcoin_libs$build_bitcoind$bitcoin_enable_qt$use_bench$use_tests = xnononononono; then
1102   AC_MSG_ERROR([No targets! Please specify at least one of: --with-utils --with-libs --with-daemon --with-gui --enable-bench or --enable-tests])
1105 AM_CONDITIONAL([TARGET_DARWIN], [test x$TARGET_OS = xdarwin])
1106 AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
1107 AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
1108 AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
1109 AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
1110 AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])
1111 AM_CONDITIONAL([ENABLE_QT_TESTS],[test x$BUILD_TEST_QT = xyes])
1112 AM_CONDITIONAL([ENABLE_BENCH],[test x$use_bench = xyes])
1113 AM_CONDITIONAL([USE_QRCODE], [test x$use_qr = xyes])
1114 AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
1115 AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes])
1116 AM_CONDITIONAL([HARDEN],[test x$use_hardening = xyes])
1118 AC_DEFINE(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR, [Major version])
1119 AC_DEFINE(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR, [Minor version])
1120 AC_DEFINE(CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION, [Build revision])
1121 AC_DEFINE(CLIENT_VERSION_BUILD, _CLIENT_VERSION_BUILD, [Version Build])
1122 AC_DEFINE(CLIENT_VERSION_IS_RELEASE, _CLIENT_VERSION_IS_RELEASE, [Version is release])
1123 AC_DEFINE(COPYRIGHT_YEAR, _COPYRIGHT_YEAR, [Copyright year])
1124 AC_DEFINE(COPYRIGHT_HOLDERS, "_COPYRIGHT_HOLDERS", [Copyright holder(s) before %s replacement])
1125 AC_DEFINE(COPYRIGHT_HOLDERS_SUBSTITUTION, "_COPYRIGHT_HOLDERS_SUBSTITUTION", [Replacement for %s in copyright holders string])
1126 define(_COPYRIGHT_HOLDERS_FINAL, [patsubst(_COPYRIGHT_HOLDERS, [%s], [_COPYRIGHT_HOLDERS_SUBSTITUTION])])
1127 AC_DEFINE(COPYRIGHT_HOLDERS_FINAL, "_COPYRIGHT_HOLDERS_FINAL", [Copyright holder(s)])
1128 AC_SUBST(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR)
1129 AC_SUBST(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR)
1130 AC_SUBST(CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION)
1131 AC_SUBST(CLIENT_VERSION_BUILD, _CLIENT_VERSION_BUILD)
1132 AC_SUBST(CLIENT_VERSION_IS_RELEASE, _CLIENT_VERSION_IS_RELEASE)
1133 AC_SUBST(COPYRIGHT_YEAR, _COPYRIGHT_YEAR)
1134 AC_SUBST(COPYRIGHT_HOLDERS, "_COPYRIGHT_HOLDERS")
1135 AC_SUBST(COPYRIGHT_HOLDERS_SUBSTITUTION, "_COPYRIGHT_HOLDERS_SUBSTITUTION")
1136 AC_SUBST(COPYRIGHT_HOLDERS_FINAL, "_COPYRIGHT_HOLDERS_FINAL")
1137 AC_SUBST(BITCOIN_DAEMON_NAME)
1138 AC_SUBST(BITCOIN_GUI_NAME)
1139 AC_SUBST(BITCOIN_CLI_NAME)
1140 AC_SUBST(BITCOIN_TX_NAME)
1142 AC_SUBST(RELDFLAGS)
1143 AC_SUBST(ERROR_CXXFLAGS)
1144 AC_SUBST(HARDENED_CXXFLAGS)
1145 AC_SUBST(HARDENED_CPPFLAGS)
1146 AC_SUBST(HARDENED_LDFLAGS)
1147 AC_SUBST(PIC_FLAGS)
1148 AC_SUBST(PIE_FLAGS)
1149 AC_SUBST(LIBTOOL_APP_LDFLAGS)
1150 AC_SUBST(USE_UPNP)
1151 AC_SUBST(USE_QRCODE)
1152 AC_SUBST(BOOST_LIBS)
1153 AC_SUBST(TESTDEFS)
1154 AC_SUBST(LEVELDB_TARGET_FLAGS)
1155 AC_SUBST(MINIUPNPC_CPPFLAGS)
1156 AC_SUBST(MINIUPNPC_LIBS)
1157 AC_SUBST(CRYPTO_LIBS)
1158 AC_SUBST(SSL_LIBS)
1159 AC_SUBST(EVENT_LIBS)
1160 AC_SUBST(EVENT_PTHREADS_LIBS)
1161 AC_SUBST(ZMQ_LIBS)
1162 AC_SUBST(PROTOBUF_LIBS)
1163 AC_SUBST(QR_LIBS)
1164 AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist test/config.ini])
1165 AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh])
1166 AC_CONFIG_FILES([doc/Doxyfile])
1167 AC_CONFIG_LINKS([test/functional/test_runner.py:test/functional/test_runner.py])
1168 AC_CONFIG_LINKS([test/util/bitcoin-util-test.py:test/util/bitcoin-util-test.py])
1170 dnl boost's m4 checks do something really nasty: they export these vars. As a
1171 dnl result, they leak into secp256k1's configure and crazy things happen.
1172 dnl Until this is fixed upstream and we've synced, we'll just un-export them.
1173 CPPFLAGS_TEMP="$CPPFLAGS"
1174 unset CPPFLAGS
1175 CPPFLAGS="$CPPFLAGS_TEMP"
1177 LDFLAGS_TEMP="$LDFLAGS"
1178 unset LDFLAGS
1179 LDFLAGS="$LDFLAGS_TEMP"
1181 LIBS_TEMP="$LIBS"
1182 unset LIBS
1183 LIBS="$LIBS_TEMP"
1185 PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH"
1186 unset PKG_CONFIG_PATH
1187 PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"
1189 PKGCONFIG_LIBDIR_TEMP="$PKG_CONFIG_LIBDIR"
1190 unset PKG_CONFIG_LIBDIR
1191 PKG_CONFIG_LIBDIR="$PKGCONFIG_LIBDIR_TEMP"
1193 if test x$need_bundled_univalue = xyes; then
1194   AC_CONFIG_SUBDIRS([src/univalue])
1197 ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no --enable-module-recovery"
1198 AC_CONFIG_SUBDIRS([src/secp256k1])
1200 AC_OUTPUT
1202 dnl Taken from https://wiki.debian.org/RpathIssue
1203 case $host in
1204    *-*-linux-gnu)
1205      AC_MSG_RESULT([Fixing libtool for -rpath problems.])
1206      sed < libtool > libtool-2 \
1207      's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_IS_A_FOOL__ "/'
1208      mv libtool-2 libtool
1209      chmod 755 libtool
1210    ;;
1211 esac
1213 dnl Replace the BUILDDIR path with the correct Windows path if compiling on Native Windows
1214 case ${OS} in
1215    *Windows*)
1216      sed  's/BUILDDIR="\/\([[a-z]]\)/BUILDDIR="\1:/'  test/config.ini > test/config-2.ini
1217      mv test/config-2.ini test/config.ini
1218    ;;
1219 esac
1221 echo 
1222 echo "Options used to compile and link:"
1223 echo "  with wallet   = $enable_wallet"
1224 echo "  with gui / qt = $bitcoin_enable_qt"
1225 if test x$bitcoin_enable_qt != xno; then
1226     echo "    qt version  = $bitcoin_qt_got_major_vers"
1227     echo "    with qr     = $use_qr"
1229 echo "  with zmq      = $use_zmq"
1230 echo "  with test     = $use_tests"
1231 echo "  with bench    = $use_bench"
1232 echo "  with upnp     = $use_upnp"
1233 echo "  debug enabled = $enable_debug"
1234 echo "  werror        = $enable_werror"
1235 echo 
1236 echo "  target os     = $TARGET_OS"
1237 echo "  build os      = $BUILD_OS"
1238 echo
1239 echo "  CC            = $CC"
1240 echo "  CFLAGS        = $CFLAGS"
1241 echo "  CPPFLAGS      = $CPPFLAGS"
1242 echo "  CXX           = $CXX"
1243 echo "  CXXFLAGS      = $CXXFLAGS"
1244 echo "  LDFLAGS       = $LDFLAGS"
1245 echo