1AC_PREREQ([2.69])
2define(_CLIENT_VERSION_MAJOR, 0)
3define(_CLIENT_VERSION_MINOR, 20)
4define(_CLIENT_VERSION_REVISION, 3)
5define(_CLIENT_VERSION_BUILD, 0)
6define(_CLIENT_VERSION_RC, 0)
7define(_CLIENT_VERSION_IS_RELEASE, true)
8define(_COPYRIGHT_YEAR, 2021)
9define(_COPYRIGHT_HOLDERS,[The %s Developers])
10define(_COPYRIGHT_HOLDERS_SUBSTITUTION,[[Qtum Core]])
11AC_INIT([Qtum Core],m4_join([.], _CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MINOR, _CLIENT_VERSION_REVISION, m4_if(_CLIENT_VERSION_BUILD, [0], [], _CLIENT_VERSION_BUILD))m4_if(_CLIENT_VERSION_RC, [0], [], [rc]_CLIENT_VERSION_RC),[https://github.com/qtumproject/qtum/issues],[qtum],[https://qtum.org/])
12AC_CONFIG_SRCDIR([src/validation.cpp])
13AC_CONFIG_HEADERS([src/config/bitcoin-config.h])
14AC_CONFIG_AUX_DIR([build-aux])
15AC_CONFIG_MACRO_DIR([build-aux/m4])
16
17BITCOIN_DAEMON_NAME=qtumd
18BITCOIN_GUI_NAME=qtum-qt
19BITCOIN_CLI_NAME=qtum-cli
20BITCOIN_TX_NAME=qtum-tx
21BITCOIN_WALLET_TOOL_NAME=qtum-wallet
22
23dnl Unless the user specified ARFLAGS, force it to be cr
24AC_ARG_VAR(ARFLAGS, [Flags for the archiver, defaults to <cr> if not set])
25if test "x${ARFLAGS+set}" != "xset"; then
26  ARFLAGS="cr"
27fi
28
29AC_CANONICAL_HOST
30
31AH_TOP([#ifndef BITCOIN_CONFIG_H])
32AH_TOP([#define BITCOIN_CONFIG_H])
33AH_BOTTOM([#endif //BITCOIN_CONFIG_H])
34
35dnl faketime breaks configure and is only needed for make. Disable it here.
36unset FAKETIME
37
38dnl Automake init set-up and checks
39AM_INIT_AUTOMAKE([1.13 no-define subdir-objects foreign])
40
41dnl faketime messes with timestamps and causes configure to be re-run.
42dnl --disable-maintainer-mode can be used to bypass this.
43AM_MAINTAINER_MODE([enable])
44
45dnl make the compilation flags quiet unless V=1 is used
46AM_SILENT_RULES([yes])
47
48dnl Compiler checks (here before libtool).
49if test "x${CXXFLAGS+set}" = "xset"; then
50  CXXFLAGS_overridden=yes
51else
52  CXXFLAGS_overridden=no
53fi
54AC_PROG_CXX
55
56dnl By default, libtool for mingw refuses to link static libs into a dll for
57dnl fear of mixing pic/non-pic objects, and import/export complications. Since
58dnl we have those under control, re-enable that functionality.
59dnl Compiler with posix support is needed for cross compile some of c++ 14 features for mingw like threads and mutexes.
60case $host in
61  *mingw*)
62     lt_cv_deplibs_check_method="pass_all"
63     CC="$CC-posix"
64     CXX="$CXX-posix"
65  ;;
66esac
67dnl Require C++14 compiler (no GNU extensions)
68AX_CXX_COMPILE_STDCXX([14], [noext], [mandatory], [nodefault])
69dnl Check if -latomic is required for <std::atomic>
70CHECK_ATOMIC
71
72dnl Unless the user specified OBJCXX, force it to be the same as CXX. This ensures
73dnl that we get the same -std flags for both.
74m4_ifdef([AC_PROG_OBJCXX],[
75if test "x${OBJCXX+set}" = "x"; then
76  OBJCXX="${CXX}"
77fi
78AC_PROG_OBJCXX
79])
80
81dnl Since libtool 1.5.2 (released 2004-01-25), on Linux libtool no longer
82dnl sets RPATH for any directories in the dynamic linker search path.
83dnl See more: https://wiki.debian.org/RpathIssue
84LT_PREREQ([1.5.2])
85dnl Libtool init checks.
86LT_INIT([pic-only])
87
88dnl Check/return PATH for base programs.
89AC_PATH_TOOL(AR, ar)
90AC_PATH_TOOL(RANLIB, ranlib)
91AC_PATH_TOOL(STRIP, strip)
92AC_PATH_TOOL(GCOV, gcov)
93AC_PATH_PROG(LCOV, lcov)
94dnl Python 3.5 is specified in .python-version and should be used if available, see doc/dependencies.md
95AC_PATH_PROGS([PYTHON], [python3.5 python3.6 python3.7 python3.8 python3 python])
96AC_PATH_PROG(GENHTML, genhtml)
97AC_PATH_PROG([GIT], [git])
98AC_PATH_PROG(CCACHE,ccache)
99AC_PATH_PROG(XGETTEXT,xgettext)
100AC_PATH_PROG(HEXDUMP,hexdump)
101AC_PATH_TOOL(READELF, readelf)
102AC_PATH_TOOL(CPPFILT, c++filt)
103AC_PATH_TOOL(OBJCOPY, objcopy)
104AC_PATH_PROG(DOXYGEN, doxygen)
105if test -z "$DOXYGEN"; then
106   AC_MSG_WARN([Doxygen not found])
107fi
108AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])
109
110AC_ARG_VAR(PYTHONPATH, Augments the default search path for python module files)
111
112AC_ARG_ENABLE([wallet],
113  [AS_HELP_STRING([--disable-wallet],
114  [disable wallet (enabled by default)])],
115  [enable_wallet=$enableval],
116  [enable_wallet=yes])
117
118AC_ARG_WITH([miniupnpc],
119  [AS_HELP_STRING([--with-miniupnpc],
120  [enable UPNP (default is yes if libminiupnpc is found)])],
121  [use_upnp=$withval],
122  [use_upnp=auto])
123
124AC_ARG_ENABLE([upnp-default],
125  [AS_HELP_STRING([--enable-upnp-default],
126  [if UPNP is enabled, turn it on at startup (default is no)])],
127  [use_upnp_default=$enableval],
128  [use_upnp_default=no])
129
130AC_ARG_ENABLE(tests,
131    AS_HELP_STRING([--disable-tests],[do not compile tests (default is to compile)]),
132    [use_tests=$enableval],
133    [use_tests=yes])
134
135AC_ARG_ENABLE(gui-tests,
136    AS_HELP_STRING([--disable-gui-tests],[do not compile GUI tests (default is to compile if GUI and tests enabled)]),
137    [use_gui_tests=$enableval],
138    [use_gui_tests=$use_tests])
139
140AC_ARG_ENABLE(bench,
141    AS_HELP_STRING([--disable-bench],[do not compile benchmarks (default is to compile)]),
142    [use_bench=$enableval],
143    [use_bench=yes])
144
145AC_ARG_ENABLE([extended-functional-tests],
146    AS_HELP_STRING([--enable-extended-functional-tests],[enable expensive functional tests when using lcov (default no)]),
147    [use_extended_functional_tests=$enableval],
148    [use_extended_functional_tests=no])
149
150AC_ARG_ENABLE([fuzz],
151    AS_HELP_STRING([--enable-fuzz],
152    [enable building of fuzz targets (default no). enabling this will disable all other targets]),
153    [enable_fuzz=$enableval],
154    [enable_fuzz=no])
155
156AC_ARG_WITH([qrencode],
157  [AS_HELP_STRING([--with-qrencode],
158  [enable QR code support (default is yes if qt is enabled and libqrencode is found)])],
159  [use_qr=$withval],
160  [use_qr=auto])
161
162AC_ARG_ENABLE([hardening],
163  [AS_HELP_STRING([--disable-hardening],
164  [do not attempt to harden the resulting executables (default is to harden when possible)])],
165  [use_hardening=$enableval],
166  [use_hardening=auto])
167
168AC_ARG_ENABLE([reduce-exports],
169  [AS_HELP_STRING([--enable-reduce-exports],
170  [attempt to reduce exported symbols in the resulting executables (default is no)])],
171  [use_reduce_exports=$enableval],
172  [use_reduce_exports=no])
173
174AC_ARG_ENABLE([ccache],
175  [AS_HELP_STRING([--disable-ccache],
176  [do not use ccache for building (default is to use if found)])],
177  [use_ccache=$enableval],
178  [use_ccache=auto])
179
180AC_ARG_ENABLE([lcov],
181  [AS_HELP_STRING([--enable-lcov],
182  [enable lcov testing (default is no)])],
183  [use_lcov=$enableval],
184  [use_lcov=no])
185
186AC_ARG_ENABLE([lcov-branch-coverage],
187  [AS_HELP_STRING([--enable-lcov-branch-coverage],
188  [enable lcov testing branch coverage (default is no)])],
189  [use_lcov_branch=yes],
190  [use_lcov_branch=no])
191
192AC_ARG_ENABLE([glibc-back-compat],
193  [AS_HELP_STRING([--enable-glibc-back-compat],
194  [enable backwards compatibility with glibc])],
195  [use_glibc_compat=$enableval],
196  [use_glibc_compat=no])
197
198AC_ARG_ENABLE([threadlocal],
199  [AS_HELP_STRING([--enable-threadlocal],
200  [enable features that depend on the c++ thread_local keyword (currently just thread names in debug logs). (default is to enabled if there is platform support and glibc-back-compat is not enabled)])],
201  [use_thread_local=$enableval],
202  [use_thread_local=auto])
203
204AC_ARG_ENABLE([asm],
205  [AS_HELP_STRING([--disable-asm],
206  [disable assembly routines (enabled by default)])],
207  [use_asm=$enableval],
208  [use_asm=yes])
209
210if test "x$use_asm" = xyes; then
211  AC_DEFINE(USE_ASM, 1, [Define this symbol to build in assembly routines])
212fi
213
214AC_ARG_WITH([system-univalue],
215  [AS_HELP_STRING([--with-system-univalue],
216  [Build with system UniValue (default is no)])],
217  [system_univalue=$withval],
218  [system_univalue=no]
219)
220AC_ARG_ENABLE([zmq],
221  [AS_HELP_STRING([--disable-zmq],
222  [disable ZMQ notifications])],
223  [use_zmq=$enableval],
224  [use_zmq=yes])
225
226AC_ARG_ENABLE([bip70],
227  [AS_HELP_STRING([--enable-bip70],
228  [BIP70 (payment protocol) support in the GUI (no longer supported)])],
229  [enable_bip70=$enableval],
230  [enable_bip70=no])
231
232if test x$enable_bip70 != xno; then
233  AC_MSG_ERROR([BIP70 is no longer supported!])
234fi
235
236AC_ARG_ENABLE(man,
237    [AS_HELP_STRING([--disable-man],
238                    [do not install man pages (default is to install)])],,
239    enable_man=yes)
240AM_CONDITIONAL(ENABLE_MAN, test "$enable_man" != no)
241
242dnl Enable debug
243AC_ARG_ENABLE([debug],
244    [AS_HELP_STRING([--enable-debug],
245                    [use compiler flags and macros suited for debugging (default is no)])],
246    [enable_debug=$enableval],
247    [enable_debug=no])
248
249dnl Enable different -fsanitize options
250AC_ARG_WITH([sanitizers],
251    [AS_HELP_STRING([--with-sanitizers],
252                    [comma separated list of extra sanitizers to build with (default is none enabled)])],
253    [use_sanitizers=$withval])
254
255dnl Enable gprof profiling
256AC_ARG_ENABLE([gprof],
257    [AS_HELP_STRING([--enable-gprof],
258                    [use gprof profiling compiler flags (default is no)])],
259    [enable_gprof=$enableval],
260    [enable_gprof=no])
261
262dnl Pass compiler & liner flags that make builds deterministic
263AC_ARG_ENABLE([determinism],
264    [AS_HELP_STRING([--enable-determinism],
265                    [Enable compilation flags that make builds deterministic (default is no)])],
266    [enable_determinism=$enableval],
267    [enable_determinism=no])
268
269dnl Turn warnings into errors
270AC_ARG_ENABLE([werror],
271    [AS_HELP_STRING([--enable-werror],
272                    [Treat certain compiler warnings as errors (default is no)])],
273    [enable_werror=$enableval],
274    [enable_werror=no])
275
276AC_LANG_PUSH([C++])
277AX_CHECK_COMPILE_FLAG([-Werror],[CXXFLAG_WERROR="-Werror"],[CXXFLAG_WERROR=""])
278
279if test "x$enable_debug" = xyes; then
280  dnl Clear default -g -O2 flags
281  if test "x$CXXFLAGS_overridden" = xno; then
282	CXXFLAGS=""
283  fi
284
285  dnl Disable all optimizations
286  AX_CHECK_COMPILE_FLAG([-O0], [[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"]],,[[$CXXFLAG_WERROR]])
287
288  dnl Prefer -g3, fall back to -g if that is unavailable.
289  AX_CHECK_COMPILE_FLAG(
290    [-g3],
291    [[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -g3"]],
292    [AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -g"]],,[[$CXXFLAG_WERROR]])],
293    [[$CXXFLAG_WERROR]])
294
295  AX_CHECK_PREPROC_FLAG([-DDEBUG],[[DEBUG_CPPFLAGS="$DEBUG_CPPFLAGS -DDEBUG"]],,[[$CXXFLAG_WERROR]])
296  AX_CHECK_PREPROC_FLAG([-DDEBUG_LOCKORDER],[[DEBUG_CPPFLAGS="$DEBUG_CPPFLAGS -DDEBUG_LOCKORDER"]],,[[$CXXFLAG_WERROR]])
297  AX_CHECK_COMPILE_FLAG([-ftrapv],[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -ftrapv"],,[[$CXXFLAG_WERROR]])
298fi
299
300if test x$use_sanitizers != x; then
301  dnl First check if the compiler accepts flags. If an incompatible pair like
302  dnl -fsanitize=address,thread is used here, this check will fail. This will also
303  dnl fail if a bad argument is passed, e.g. -fsanitize=undfeined
304  AX_CHECK_COMPILE_FLAG(
305    [[-fsanitize=$use_sanitizers]],
306    [[SANITIZER_CXXFLAGS=-fsanitize=$use_sanitizers]],
307    [AC_MSG_ERROR([compiler did not accept requested flags])])
308
309  dnl Some compilers (e.g. GCC) require additional libraries like libasan,
310  dnl libtsan, libubsan, etc. Make sure linking still works with the sanitize
311  dnl flag. This is a separate check so we can give a better error message when
312  dnl the sanitize flags are supported by the compiler but the actual sanitizer
313  dnl libs are missing.
314  AX_CHECK_LINK_FLAG(
315    [[-fsanitize=$use_sanitizers]],
316    [[SANITIZER_LDFLAGS=-fsanitize=$use_sanitizers]],
317    [AC_MSG_ERROR([linker did not accept requested flags, you are missing required libraries])],
318    [],
319    [AC_LANG_PROGRAM([[
320    #include <cstdint>
321    #include <cstddef>
322    extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { return 0; }
323    __attribute__((weak)) // allow for libFuzzer linking
324    ]],[[]])])
325fi
326
327CPPFLAGS="$CPPFLAGS -DQTUM_BUILD"
328
329ERROR_CXXFLAGS=
330if test "x$enable_werror" = "xyes"; then
331  if test "x$CXXFLAG_WERROR" = "x"; then
332    AC_MSG_ERROR("enable-werror set but -Werror is not usable")
333  fi
334  AX_CHECK_COMPILE_FLAG([-Werror=vla],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=vla"],,[[$CXXFLAG_WERROR]])
335  AX_CHECK_COMPILE_FLAG([-Werror=switch],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=switch"],,[[$CXXFLAG_WERROR]])
336  AX_CHECK_COMPILE_FLAG([-Werror=thread-safety-analysis],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=thread-safety-analysis"],,[[$CXXFLAG_WERROR]])
337  AX_CHECK_COMPILE_FLAG([-Werror=unused-variable],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=unused-variable"],,[[$CXXFLAG_WERROR]])
338  AX_CHECK_COMPILE_FLAG([-Werror=date-time],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=date-time"],,[[$CXXFLAG_WERROR]])
339  AX_CHECK_COMPILE_FLAG([-Werror=return-type],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=return-type"],,[[$CXXFLAG_WERROR]])
340fi
341
342if test "x$CXXFLAGS_overridden" = "xno"; then
343  AX_CHECK_COMPILE_FLAG([-Wall],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wall"],,[[$CXXFLAG_WERROR]])
344  AX_CHECK_COMPILE_FLAG([-Wextra],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wextra"],,[[$CXXFLAG_WERROR]])
345  AX_CHECK_COMPILE_FLAG([-Wformat],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wformat"],,[[$CXXFLAG_WERROR]])
346  AX_CHECK_COMPILE_FLAG([-Wvla],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wvla"],,[[$CXXFLAG_WERROR]])
347  AX_CHECK_COMPILE_FLAG([-Wswitch],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wswitch"],,[[$CXXFLAG_WERROR]])
348  AX_CHECK_COMPILE_FLAG([-Wformat-security],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wformat-security"],,[[$CXXFLAG_WERROR]])
349  AX_CHECK_COMPILE_FLAG([-Wthread-safety-analysis],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wthread-safety-analysis"],,[[$CXXFLAG_WERROR]])
350  AX_CHECK_COMPILE_FLAG([-Wrange-loop-analysis],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wrange-loop-analysis"],,[[$CXXFLAG_WERROR]])
351  AX_CHECK_COMPILE_FLAG([-Wredundant-decls],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wredundant-decls"],,[[$CXXFLAG_WERROR]])
352  AX_CHECK_COMPILE_FLAG([-Wunused-variable],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wunused-variable"],,[[$CXXFLAG_WERROR]])
353  AX_CHECK_COMPILE_FLAG([-Wdate-time],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wdate-time"],,[[$CXXFLAG_WERROR]])
354
355  dnl Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
356  dnl unknown options if any other warning is produced. Test the -Wfoo case, and
357  dnl set the -Wno-foo case if it works.
358  AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-parameter"],,[[$CXXFLAG_WERROR]])
359  AX_CHECK_COMPILE_FLAG([-Wself-assign],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-self-assign"],,[[$CXXFLAG_WERROR]])
360  AX_CHECK_COMPILE_FLAG([-Wunused-local-typedef],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-local-typedef"],,[[$CXXFLAG_WERROR]])
361  AX_CHECK_COMPILE_FLAG([-Wdeprecated-register],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-deprecated-register"],,[[$CXXFLAG_WERROR]])
362  AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-implicit-fallthrough"],,[[$CXXFLAG_WERROR]])
363  AX_CHECK_COMPILE_FLAG([-Wno-unknown-pragmas],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unknown-pragmas"],,[[$CXXFLAG_WERROR]])
364  AX_CHECK_COMPILE_FLAG([-Wno-strict-aliasing],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-strict-aliasing"],,[[$CXXFLAG_WERROR]])
365fi
366
367enable_sse42=no
368enable_sse41=no
369enable_avx2=no
370enable_shani=no
371
372if test "x$use_asm" = "xyes"; then
373
374dnl Check for optional instruction set support. Enabling these does _not_ imply that all code will
375dnl be compiled with them, rather that specific objects/libs may use them after checking for runtime
376dnl compatibility.
377
378dnl x86
379AX_CHECK_COMPILE_FLAG([-msse4.2],[[SSE42_CXXFLAGS="-msse4.2"]],,[[$CXXFLAG_WERROR]])
380AX_CHECK_COMPILE_FLAG([-msse4.1],[[SSE41_CXXFLAGS="-msse4.1"]],,[[$CXXFLAG_WERROR]])
381AX_CHECK_COMPILE_FLAG([-mavx -mavx2],[[AVX2_CXXFLAGS="-mavx -mavx2"]],,[[$CXXFLAG_WERROR]])
382AX_CHECK_COMPILE_FLAG([-msse4 -msha],[[SHANI_CXXFLAGS="-msse4 -msha"]],,[[$CXXFLAG_WERROR]])
383
384TEMP_CXXFLAGS="$CXXFLAGS"
385CXXFLAGS="$CXXFLAGS $SSE42_CXXFLAGS"
386AC_MSG_CHECKING(for SSE4.2 intrinsics)
387AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
388    #include <stdint.h>
389    #if defined(_MSC_VER)
390    #include <intrin.h>
391    #elif defined(__GNUC__) && defined(__SSE4_2__)
392    #include <nmmintrin.h>
393    #endif
394  ]],[[
395    uint64_t l = 0;
396    l = _mm_crc32_u8(l, 0);
397    l = _mm_crc32_u32(l, 0);
398    l = _mm_crc32_u64(l, 0);
399    return l;
400  ]])],
401 [ AC_MSG_RESULT(yes); enable_sse42=yes],
402 [ AC_MSG_RESULT(no)]
403)
404CXXFLAGS="$TEMP_CXXFLAGS"
405
406TEMP_CXXFLAGS="$CXXFLAGS"
407CXXFLAGS="$CXXFLAGS $SSE41_CXXFLAGS"
408AC_MSG_CHECKING(for SSE4.1 intrinsics)
409AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
410    #include <stdint.h>
411    #include <immintrin.h>
412  ]],[[
413    __m128i l = _mm_set1_epi32(0);
414    return _mm_extract_epi32(l, 3);
415  ]])],
416 [ AC_MSG_RESULT(yes); enable_sse41=yes; AC_DEFINE(ENABLE_SSE41, 1, [Define this symbol to build code that uses SSE4.1 intrinsics]) ],
417 [ AC_MSG_RESULT(no)]
418)
419CXXFLAGS="$TEMP_CXXFLAGS"
420
421TEMP_CXXFLAGS="$CXXFLAGS"
422CXXFLAGS="$CXXFLAGS $AVX2_CXXFLAGS"
423AC_MSG_CHECKING(for AVX2 intrinsics)
424AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
425    #include <stdint.h>
426    #include <immintrin.h>
427  ]],[[
428    __m256i l = _mm256_set1_epi32(0);
429    return _mm256_extract_epi32(l, 7);
430  ]])],
431 [ AC_MSG_RESULT(yes); enable_avx2=yes; AC_DEFINE(ENABLE_AVX2, 1, [Define this symbol to build code that uses AVX2 intrinsics]) ],
432 [ AC_MSG_RESULT(no)]
433)
434CXXFLAGS="$TEMP_CXXFLAGS"
435
436TEMP_CXXFLAGS="$CXXFLAGS"
437CXXFLAGS="$CXXFLAGS $SHANI_CXXFLAGS"
438AC_MSG_CHECKING(for SHA-NI intrinsics)
439AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
440    #include <stdint.h>
441    #include <immintrin.h>
442  ]],[[
443    __m128i i = _mm_set1_epi32(0);
444    __m128i j = _mm_set1_epi32(1);
445    __m128i k = _mm_set1_epi32(2);
446    return _mm_extract_epi32(_mm_sha256rnds2_epu32(i, i, k), 0);
447  ]])],
448 [ AC_MSG_RESULT(yes); enable_shani=yes; AC_DEFINE(ENABLE_SHANI, 1, [Define this symbol to build code that uses SHA-NI intrinsics]) ],
449 [ AC_MSG_RESULT(no)]
450)
451CXXFLAGS="$TEMP_CXXFLAGS"
452
453# ARM
454AX_CHECK_COMPILE_FLAG([-march=armv8-a+crc+crypto],[[ARM_CRC_CXXFLAGS="-march=armv8-a+crc+crypto"]],,[[$CXXFLAG_WERROR]])
455
456TEMP_CXXFLAGS="$CXXFLAGS"
457CXXFLAGS="$CXXFLAGS $ARM_CRC_CXXFLAGS"
458AC_MSG_CHECKING(for ARM CRC32 intrinsics)
459AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
460    #include <arm_acle.h>
461    #include <arm_neon.h>
462  ]],[[
463    __crc32cb(0, 0); __crc32ch(0, 0); __crc32cw(0, 0); __crc32cd(0, 0);
464    vmull_p64(0, 0);
465  ]])],
466 [ AC_MSG_RESULT(yes); enable_arm_crc=yes; ],
467 [ AC_MSG_RESULT(no)]
468)
469CXXFLAGS="$TEMP_CXXFLAGS"
470
471fi
472
473CPPFLAGS="$CPPFLAGS -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS"
474
475AC_ARG_WITH([utils],
476  [AS_HELP_STRING([--with-utils],
477  [build bitcoin-cli bitcoin-tx bitcoin-wallet (default=yes)])],
478  [build_bitcoin_utils=$withval],
479  [build_bitcoin_utils=yes])
480
481AC_ARG_ENABLE([util-cli],
482  [AS_HELP_STRING([--enable-util-cli],
483  [build bitcoin-cli])],
484  [build_bitcoin_cli=$enableval],
485  [build_bitcoin_cli=$build_bitcoin_utils])
486
487AC_ARG_ENABLE([util-tx],
488  [AS_HELP_STRING([--enable-util-tx],
489  [build bitcoin-tx])],
490  [build_bitcoin_tx=$enableval],
491  [build_bitcoin_tx=$build_bitcoin_utils])
492
493AC_ARG_ENABLE([util-wallet],
494  [AS_HELP_STRING([--enable-util-wallet],
495  [build bitcoin-wallet])],
496  [build_bitcoin_wallet=$enableval],
497  [build_bitcoin_wallet=$build_bitcoin_utils])
498
499AC_ARG_WITH([libs],
500  [AS_HELP_STRING([--with-libs],
501  [build libraries (default=yes)])],
502  [build_bitcoin_libs=$withval],
503  [build_bitcoin_libs=yes])
504
505AC_ARG_WITH([daemon],
506  [AS_HELP_STRING([--with-daemon],
507  [build bitcoind daemon (default=yes)])],
508  [build_bitcoind=$withval],
509  [build_bitcoind=yes])
510
511use_pkgconfig=yes
512case $host in
513  *mingw*)
514
515     dnl pkgconfig does more harm than good with MinGW
516     use_pkgconfig=no
517
518     TARGET_OS=windows
519     AC_CHECK_LIB([kernel32], [GetModuleFileNameA],, AC_MSG_ERROR(libkernel32 missing))
520     AC_CHECK_LIB([user32],   [main],, AC_MSG_ERROR(libuser32 missing))
521     AC_CHECK_LIB([gdi32],    [main],, AC_MSG_ERROR(libgdi32 missing))
522     AC_CHECK_LIB([comdlg32], [main],, AC_MSG_ERROR(libcomdlg32 missing))
523     AC_CHECK_LIB([winmm],    [main],, AC_MSG_ERROR(libwinmm missing))
524     AC_CHECK_LIB([shell32],  [SHGetSpecialFolderPathW],, AC_MSG_ERROR(libshell32 missing))
525     AC_CHECK_LIB([comctl32], [main],, AC_MSG_ERROR(libcomctl32 missing))
526     AC_CHECK_LIB([ole32],    [CoCreateInstance],, AC_MSG_ERROR(libole32 missing))
527     AC_CHECK_LIB([oleaut32], [main],, AC_MSG_ERROR(liboleaut32 missing))
528     AC_CHECK_LIB([uuid],     [main],, AC_MSG_ERROR(libuuid missing))
529     AC_CHECK_LIB([advapi32], [CryptAcquireContextW],, AC_MSG_ERROR(libadvapi32 missing))
530     AC_CHECK_LIB([ws2_32],   [WSAStartup],, AC_MSG_ERROR(libws2_32 missing))
531     AC_CHECK_LIB([shlwapi],  [PathRemoveFileSpecW],, AC_MSG_ERROR(libshlwapi missing))
532     AC_CHECK_LIB([iphlpapi], [GetAdaptersAddresses],, AC_MSG_ERROR(libiphlpapi missing))
533
534     dnl -static is interpreted by libtool, where it has a different meaning.
535     dnl In libtool-speak, it's -all-static.
536     AX_CHECK_LINK_FLAG([[-static]],[LIBTOOL_APP_LDFLAGS="$LIBTOOL_APP_LDFLAGS -all-static"])
537
538     AC_PATH_PROG([MAKENSIS], [makensis], none)
539     if test x$MAKENSIS = xnone; then
540       AC_MSG_WARN("makensis not found. Cannot create installer.")
541     fi
542
543     AC_PATH_TOOL(WINDRES, windres, none)
544     if test x$WINDRES = xnone; then
545       AC_MSG_ERROR("windres not found")
546     fi
547
548     CPPFLAGS="$CPPFLAGS -D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -D_WIN32_WINNT=0x0601"
549     if test "x$CXXFLAGS_overridden" = "xno"; then
550       CXXFLAGS="$CXXFLAGS -w"
551     fi
552
553     dnl libtool insists upon adding -nostdlib and a list of objects/libs to link against.
554     dnl That breaks our ability to build dll's with static libgcc/libstdc++/libssp. Override
555     dnl its command here, with the predeps/postdeps removed, and -static inserted. Postdeps are
556     dnl also overridden to prevent their insertion later.
557     dnl This should only affect dll's.
558     archive_cmds_CXX="\$CC -shared \$libobjs \$deplibs \$compiler_flags -static -o \$output_objdir/\$soname \${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker \$lib"
559     postdeps_CXX=
560
561     ;;
562  *darwin*)
563     TARGET_OS=darwin
564     if  test x$cross_compiling != xyes; then
565       BUILD_OS=darwin
566       AC_PATH_PROGS([RSVG_CONVERT], [rsvg-convert rsvg],rsvg-convert)
567       AC_CHECK_PROG([BREW],brew, brew)
568       if test x$BREW = xbrew; then
569         dnl These Homebrew packages may be keg-only, meaning that they won't be found
570         dnl in expected paths because they may conflict with system files. Ask
571         dnl Homebrew where each one is located, then adjust paths accordingly.
572         dnl It's safe to add these paths even if the functionality is disabled by
573         dnl the user (--without-wallet or --without-gui for example).
574
575         openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
576         bdb_prefix=$($BREW --prefix berkeley-db4 2>/dev/null)
577         qt5_prefix=$($BREW --prefix qt5 2>/dev/null)
578         if test x$openssl_prefix != x; then
579           PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
580           export PKG_CONFIG_PATH
581         fi
582         if test x$bdb_prefix != x; then
583           CPPFLAGS="$CPPFLAGS -I$bdb_prefix/include"
584           LIBS="$LIBS -L$bdb_prefix/lib"
585         fi
586         if test x$qt5_prefix != x; then
587           PKG_CONFIG_PATH="$qt5_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
588           export PKG_CONFIG_PATH
589         fi
590       fi
591     else
592       case $build_os in
593         *darwin*)
594           BUILD_OS=darwin
595           ;;
596         *)
597           AC_PATH_TOOL([INSTALLNAMETOOL], [install_name_tool], install_name_tool)
598           AC_PATH_TOOL([OTOOL], [otool], otool)
599           AC_PATH_PROGS([GENISOIMAGE], [genisoimage mkisofs],genisoimage)
600           AC_PATH_PROGS([RSVG_CONVERT], [rsvg-convert rsvg],rsvg-convert)
601           AC_PATH_PROGS([IMAGEMAGICK_CONVERT], [convert],convert)
602           AC_PATH_PROGS([TIFFCP], [tiffcp],tiffcp)
603
604           dnl libtool will try to strip the static lib, which is a problem for
605           dnl cross-builds because strip attempts to call a hard-coded ld,
606           dnl which may not exist in the path. Stripping the .a is not
607           dnl necessary, so just disable it.
608           old_striplib=
609           ;;
610       esac
611     fi
612
613     AX_CHECK_LINK_FLAG([[-Wl,-headerpad_max_install_names]], [LDFLAGS="$LDFLAGS -Wl,-headerpad_max_install_names"])
614     CPPFLAGS="$CPPFLAGS -DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0"
615     OBJCXXFLAGS="$CXXFLAGS"
616     ;;
617   *android*)
618     dnl make sure android stays above linux for hosts like *linux-android*
619     TARGET_OS=android
620     ;;
621   *linux*)
622     TARGET_OS=linux
623     ;;
624esac
625
626LIBFF_TARGET_FLAGS=""
627
628if test x$use_pkgconfig = xyes; then
629  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.)])
630  m4_ifdef([PKG_PROG_PKG_CONFIG], [
631  PKG_PROG_PKG_CONFIG
632  if test x"$PKG_CONFIG" = "x"; then
633    AC_MSG_ERROR(pkg-config not found.)
634  fi
635  ])
636fi
637
638if test x$use_extended_functional_tests != xno; then
639  AC_SUBST(EXTENDED_FUNCTIONAL_TESTS, --extended)
640fi
641
642if test x$use_lcov = xyes; then
643  if test x$LCOV = x; then
644    AC_MSG_ERROR("lcov testing requested but lcov not found")
645  fi
646  if test x$GCOV = x; then
647    AC_MSG_ERROR("lcov testing requested but gcov not found")
648  fi
649  if test x$PYTHON = x; then
650    AC_MSG_ERROR("lcov testing requested but python not found")
651  fi
652  if test x$GENHTML = x; then
653    AC_MSG_ERROR("lcov testing requested but genhtml not found")
654  fi
655  LCOV="$LCOV --gcov-tool=$GCOV"
656  AX_CHECK_LINK_FLAG([[--coverage]], [LDFLAGS="$LDFLAGS --coverage"],
657    [AC_MSG_ERROR("lcov testing requested but --coverage linker flag does not work")])
658  AX_CHECK_COMPILE_FLAG([--coverage],[CXXFLAGS="$CXXFLAGS --coverage"],
659    [AC_MSG_ERROR("lcov testing requested but --coverage flag does not work")])
660  CXXFLAGS="$CXXFLAGS -Og"
661fi
662
663if test x$use_lcov_branch != xno; then
664  AC_SUBST(LCOV_OPTS, "$LCOV_OPTS --rc lcov_branch_coverage=1")
665fi
666
667dnl Check for endianness
668AC_C_BIGENDIAN
669
670dnl Check for pthread compile/link requirements
671AX_PTHREAD
672
673dnl The following macro will add the necessary defines to bitcoin-config.h, but
674dnl they also need to be passed down to any subprojects. Pull the results out of
675dnl the cache and add them to CPPFLAGS.
676AC_SYS_LARGEFILE
677dnl detect POSIX or GNU variant of strerror_r
678AC_FUNC_STRERROR_R
679
680if test x$ac_cv_sys_file_offset_bits != x &&
681   test x$ac_cv_sys_file_offset_bits != xno &&
682   test x$ac_cv_sys_file_offset_bits != xunknown; then
683  CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=$ac_cv_sys_file_offset_bits"
684fi
685
686if test x$ac_cv_sys_large_files != x &&
687   test x$ac_cv_sys_large_files != xno &&
688   test x$ac_cv_sys_large_files != xunknown; then
689  CPPFLAGS="$CPPFLAGS -D_LARGE_FILES=$ac_cv_sys_large_files"
690fi
691
692AX_GCC_FUNC_ATTRIBUTE([visibility])
693AX_GCC_FUNC_ATTRIBUTE([dllexport])
694AX_GCC_FUNC_ATTRIBUTE([dllimport])
695
696if test x$use_glibc_compat != xno; then
697
698  dnl __fdelt_chk's params and return type have changed from long unsigned int to long int.
699  dnl See which one is present here.
700  AC_MSG_CHECKING(__fdelt_chk type)
701  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifdef _FORTIFY_SOURCE
702                    #undef _FORTIFY_SOURCE
703                  #endif
704                  #define _FORTIFY_SOURCE 2
705                  #include <sys/select.h>
706     extern "C" long unsigned int __fdelt_warn(long unsigned int);]],[[]])],
707    [ fdelt_type="long unsigned int"],
708    [ fdelt_type="long int"])
709  AC_MSG_RESULT($fdelt_type)
710  AC_DEFINE_UNQUOTED(FDELT_TYPE, $fdelt_type,[parameter and return value type for __fdelt_chk])
711  AX_CHECK_LINK_FLAG([[-Wl,--wrap=__divmoddi4]], [COMPAT_LDFLAGS="$COMPAT_LDFLAGS -Wl,--wrap=__divmoddi4"])
712  AX_CHECK_LINK_FLAG([[-Wl,--wrap=log2f]], [COMPAT_LDFLAGS="$COMPAT_LDFLAGS -Wl,--wrap=log2f"])
713else
714  AC_SEARCH_LIBS([clock_gettime],[rt])
715fi
716
717if test "x$enable_gprof" = xyes; then
718    dnl -pg is incompatible with -pie. Since hardening and profiling together doesn't make sense,
719    dnl we simply make them mutually exclusive here. Additionally, hardened toolchains may force
720    dnl -pie by default, in which case it needs to be turned off with -no-pie.
721
722    if test x$use_hardening = xyes; then
723        AC_MSG_ERROR(gprof profiling is not compatible with hardening. Reconfigure with --disable-hardening or --disable-gprof)
724    fi
725    use_hardening=no
726    AX_CHECK_COMPILE_FLAG([-pg],[GPROF_CXXFLAGS="-pg"],
727        [AC_MSG_ERROR(gprof profiling requested but not available)], [[$CXXFLAG_WERROR]])
728
729    AX_CHECK_LINK_FLAG([[-no-pie]], [GPROF_LDFLAGS="-no-pie"])
730    AX_CHECK_LINK_FLAG([[-pg]],[GPROF_LDFLAGS="$GPROF_LDFLAGS -pg"],
731        [AC_MSG_ERROR(gprof profiling requested but not available)], [[$GPROF_LDFLAGS]])
732fi
733
734if test x$TARGET_OS != xwindows; then
735  dnl All windows code is PIC, forcing it on just adds useless compile warnings
736  AX_CHECK_COMPILE_FLAG([-fPIC],[PIC_FLAGS="-fPIC"])
737fi
738
739dnl All versions of gcc that we commonly use for building are subject to bug
740dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348. To work around that, set
741dnl -fstack-reuse=none for all gcc builds. (Only gcc understands this flag)
742AX_CHECK_COMPILE_FLAG([-fstack-reuse=none],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-reuse=none"])
743if test x$use_hardening != xno; then
744  use_hardening=yes
745  AX_CHECK_COMPILE_FLAG([-Wstack-protector],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"])
746  AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"])
747
748  dnl When enable_debug is yes, all optimizations are disabled.
749  dnl However, FORTIFY_SOURCE requires that there is some level of optimization, otherwise it does nothing and just creates a compiler warning.
750  dnl Since FORTIFY_SOURCE is a no-op without optimizations, do not enable it when enable_debug is yes.
751  if test x$enable_debug != xyes; then
752    AX_CHECK_PREPROC_FLAG([-D_FORTIFY_SOURCE=2],[
753      AX_CHECK_PREPROC_FLAG([-U_FORTIFY_SOURCE],[
754        HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -U_FORTIFY_SOURCE"
755      ])
756      HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -D_FORTIFY_SOURCE=2"
757    ])
758  fi
759
760  AX_CHECK_LINK_FLAG([[-Wl,--dynamicbase]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--dynamicbase"])
761  AX_CHECK_LINK_FLAG([[-Wl,--nxcompat]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--nxcompat"])
762  AX_CHECK_LINK_FLAG([[-Wl,--high-entropy-va]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--high-entropy-va"])
763  AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"])
764  AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"])
765  AX_CHECK_LINK_FLAG([[-fPIE -pie]], [PIE_FLAGS="-fPIE"; HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"],, [[$CXXFLAG_WERROR]])
766
767  case $host in
768    *mingw*)
769       AC_CHECK_LIB([ssp],      [main],, AC_MSG_ERROR(libssp missing))
770    ;;
771  esac
772fi
773
774dnl this flag screws up non-darwin gcc even when the check fails. special-case it.
775if test x$TARGET_OS = xdarwin; then
776  AX_CHECK_LINK_FLAG([[-Wl,-dead_strip]], [LDFLAGS="$LDFLAGS -Wl,-dead_strip"])
777  AX_CHECK_LINK_FLAG([[-Wl,-dead_strip_dylibs]], [LDFLAGS="$LDFLAGS -Wl,-dead_strip_dylibs"])
778  AX_CHECK_LINK_FLAG([[-Wl,-bind_at_load]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-bind_at_load"])
779fi
780
781if test x$enable_determinism = xyes; then
782  if test x$TARGET_OS = xwindows; then
783    AX_CHECK_LINK_FLAG([[-Wl,--no-insert-timestamp]], [LDFLAGS="$LDFLAGS -Wl,--no-insert-timestamp"])
784  fi
785fi
786
787AC_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 sys/sysctl.h vm/vm_param.h sys/vmmeter.h sys/resources.h])
788
789dnl FD_ZERO may be dependent on a declaration of memcpy, e.g. in SmartOS
790dnl check that it fails to build without memcpy, then that it builds with
791AC_MSG_CHECKING(FD_ZERO memcpy dependence)
792AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
793    #include <cstddef>
794    #if HAVE_SYS_SELECT_H
795    #include <sys/select.h>
796    #endif
797  ]],[[
798    #if HAVE_SYS_SELECT_H
799    fd_set fds;
800    FD_ZERO(&fds);
801    #endif
802  ]])],
803  [ AC_MSG_RESULT(no) ],
804  [
805      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
806          #include <cstring>
807          #if HAVE_SYS_SELECT_H
808          #include <sys/select.h>
809          #endif
810        ]], [[
811          #if HAVE_SYS_SELECT_H
812          fd_set fds;
813          FD_ZERO(&fds);
814          #endif
815        ]])],
816        [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_CSTRING_DEPENDENT_FD_ZERO, 1, [Define this symbol if FD_ZERO is dependent of a memcpy declaration being available]) ],
817        [ AC_MSG_ERROR(failed with cstring include) ]
818      )
819  ]
820)
821
822AC_CHECK_DECLS([getifaddrs, freeifaddrs],,,
823    [#include <sys/types.h>
824    #include <ifaddrs.h>]
825)
826AC_CHECK_DECLS([strnlen])
827
828dnl Check for daemon(3), unrelated to --with-daemon (although used by it)
829AC_CHECK_DECLS([daemon])
830
831AC_CHECK_DECLS([le16toh, le32toh, le64toh, htole16, htole32, htole64, be16toh, be32toh, be64toh, htobe16, htobe32, htobe64],,,
832		[#if HAVE_ENDIAN_H
833                 #include <endian.h>
834                 #elif HAVE_SYS_ENDIAN_H
835                 #include <sys/endian.h>
836                 #endif])
837
838AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64],,,
839		[#if HAVE_BYTESWAP_H
840                 #include <byteswap.h>
841                 #endif])
842
843AC_CHECK_DECLS([__builtin_clz, __builtin_clzl, __builtin_clzll])
844
845dnl Check for malloc_info (for memory statistics information in getmemoryinfo)
846AC_MSG_CHECKING(for getmemoryinfo)
847AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <malloc.h>]],
848 [[ int f = malloc_info(0, NULL); ]])],
849 [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_MALLOC_INFO, 1,[Define this symbol if you have malloc_info]) ],
850 [ AC_MSG_RESULT(no)]
851)
852
853dnl Check for mallopt(M_ARENA_MAX) (to set glibc arenas)
854AC_MSG_CHECKING(for mallopt M_ARENA_MAX)
855AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <malloc.h>]],
856 [[ mallopt(M_ARENA_MAX, 1); ]])],
857 [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_MALLOPT_ARENA_MAX, 1,[Define this symbol if you have mallopt with M_ARENA_MAX]) ],
858 [ AC_MSG_RESULT(no)]
859)
860
861AC_MSG_CHECKING([for visibility attribute])
862AC_LINK_IFELSE([AC_LANG_SOURCE([
863  int foo_def( void ) __attribute__((visibility("default")));
864  int main(){}
865  ])],
866  [
867    AC_DEFINE(HAVE_VISIBILITY_ATTRIBUTE,1,[Define if the visibility attribute is supported.])
868    AC_MSG_RESULT(yes)
869  ],
870  [
871    AC_MSG_RESULT(no)
872    if test x$use_reduce_exports = xyes; then
873      AC_MSG_ERROR([Cannot find a working visibility attribute. Use --disable-reduce-exports.])
874    fi
875  ]
876)
877
878if test "x$use_thread_local" = xyes || { test "x$use_thread_local" = xauto && test "x$use_glibc_compat" = xno; }; then
879  TEMP_LDFLAGS="$LDFLAGS"
880  LDFLAGS="$TEMP_LDFLAGS $PTHREAD_CFLAGS"
881  AC_MSG_CHECKING([for thread_local support])
882  AC_LINK_IFELSE([AC_LANG_SOURCE([
883    #include <thread>
884    static thread_local int foo = 0;
885    static void run_thread() { foo++;}
886    int main(){
887    for(int i = 0; i < 10; i++) { std::thread(run_thread).detach();}
888    return foo;
889    }
890    ])],
891    [
892     case $host in
893       *mingw*)
894          dnl mingw32's implementation of thread_local has also been shown to behave
895          dnl erroneously under concurrent usage; see:
896          dnl https://gist.github.com/jamesob/fe9a872051a88b2025b1aa37bfa98605
897          AC_MSG_RESULT(no)
898          ;;
899        *freebsd*)
900          dnl FreeBSD's implementation of thread_local is also buggy (per
901          dnl https://groups.google.com/d/msg/bsdmailinglist/22ncTZAbDp4/Dii_pII5AwAJ)
902          AC_MSG_RESULT(no)
903          ;;
904        *)
905          AC_DEFINE(HAVE_THREAD_LOCAL,1,[Define if thread_local is supported.])
906          AC_MSG_RESULT(yes)
907          ;;
908      esac
909    ],
910    [
911      AC_MSG_RESULT(no)
912    ]
913  )
914  LDFLAGS="$TEMP_LDFLAGS"
915fi
916
917dnl check for gmtime_r(), fallback to gmtime_s() if that is unavailable
918dnl fail if neither are available.
919AC_MSG_CHECKING(for gmtime_r)
920AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ctime>]],
921  [[ gmtime_r((const time_t *) nullptr, (struct tm *) nullptr); ]])],
922  [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_GMTIME_R, 1, [Define this symbol if gmtime_r is available]) ],
923  [ AC_MSG_RESULT(no);
924    AC_MSG_CHECKING(for gmtime_s);
925    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ctime>]],
926       [[ gmtime_s((struct tm *) nullptr, (const time_t *) nullptr); ]])],
927       [ AC_MSG_RESULT(yes)],
928       [ AC_MSG_RESULT(no); AC_MSG_ERROR(Both gmtime_r and gmtime_s are unavailable) ]
929    )
930  ]
931)
932
933dnl Check for different ways of gathering OS randomness
934AC_MSG_CHECKING(for Linux getrandom syscall)
935AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>
936  #include <sys/syscall.h>
937  #include <linux/random.h>]],
938 [[ syscall(SYS_getrandom, nullptr, 32, 0); ]])],
939 [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYS_GETRANDOM, 1,[Define this symbol if the Linux getrandom system call is available]) ],
940 [ AC_MSG_RESULT(no)]
941)
942
943AC_MSG_CHECKING(for getentropy)
944AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>]],
945 [[ getentropy(nullptr, 32) ]])],
946 [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_GETENTROPY, 1,[Define this symbol if the BSD getentropy system call is available]) ],
947 [ AC_MSG_RESULT(no)]
948)
949
950AC_MSG_CHECKING(for getentropy via random.h)
951AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>
952 #include <sys/random.h>]],
953 [[ getentropy(nullptr, 32) ]])],
954 [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_GETENTROPY_RAND, 1,[Define this symbol if the BSD getentropy system call is available with sys/random.h]) ],
955 [ AC_MSG_RESULT(no)]
956)
957
958AC_MSG_CHECKING(for sysctl)
959AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
960  #include <sys/sysctl.h>]],
961 [[ #ifdef __linux__
962    #error "Don't use sysctl on Linux, it's deprecated even when it works"
963    #endif
964    sysctl(nullptr, 2, nullptr, nullptr, nullptr, 0); ]])],
965 [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCTL, 1,[Define this symbol if the BSD sysctl() is available]) ],
966 [ AC_MSG_RESULT(no)]
967)
968
969AC_MSG_CHECKING(for sysctl KERN_ARND)
970AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
971  #include <sys/sysctl.h>]],
972 [[ #ifdef __linux__
973    #error "Don't use sysctl on Linux, it's deprecated even when it works"
974    #endif
975    static int name[2] = {CTL_KERN, KERN_ARND};
976    sysctl(name, 2, nullptr, nullptr, nullptr, 0); ]])],
977 [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCTL_ARND, 1,[Define this symbol if the BSD sysctl(KERN_ARND) is available]) ],
978 [ AC_MSG_RESULT(no)]
979)
980
981AC_MSG_CHECKING(for if type char equals int8_t)
982AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdint.h>
983  #include <type_traits>]],
984 [[ static_assert(std::is_same<int8_t, char>::value, ""); ]])],
985 [ AC_MSG_RESULT(yes); AC_DEFINE(CHAR_EQUALS_INT8, 1,[Define this symbol if type char equals int8_t]) ],
986 [ AC_MSG_RESULT(no)]
987)
988
989dnl LevelDB platform checks
990AC_MSG_CHECKING(for fdatasync)
991AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>]],
992 [[ fdatasync(0); ]])],
993 [ AC_MSG_RESULT(yes); HAVE_FDATASYNC=1 ],
994 [ AC_MSG_RESULT(no); HAVE_FDATASYNC=0 ]
995)
996
997AC_MSG_CHECKING(for F_FULLFSYNC)
998AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <fcntl.h>]],
999 [[ fcntl(0, F_FULLFSYNC, 0); ]])],
1000 [ AC_MSG_RESULT(yes); HAVE_FULLFSYNC=1 ],
1001 [ AC_MSG_RESULT(no); HAVE_FULLFSYNC=0 ]
1002)
1003
1004AC_MSG_CHECKING(for O_CLOEXEC)
1005AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <fcntl.h>]],
1006 [[ open("", O_CLOEXEC); ]])],
1007 [ AC_MSG_RESULT(yes); HAVE_O_CLOEXEC=1 ],
1008 [ AC_MSG_RESULT(no); HAVE_O_CLOEXEC=0 ]
1009)
1010
1011dnl crc32c platform checks
1012AC_MSG_CHECKING(for __builtin_prefetch)
1013AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
1014  char data = 0;
1015  const char* address = &data;
1016  __builtin_prefetch(address, 0, 0);
1017  ]])],
1018 [ AC_MSG_RESULT(yes); HAVE_BUILTIN_PREFETCH=1 ],
1019 [ AC_MSG_RESULT(no); HAVE_BUILTIN_PREFETCH=0 ]
1020)
1021
1022AC_MSG_CHECKING(for _mm_prefetch)
1023AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <xmmintrin.h>]], [[
1024  char data = 0;
1025  const char* address = &data;
1026  _mm_prefetch(address, _MM_HINT_NTA);
1027  ]])],
1028 [ AC_MSG_RESULT(yes); HAVE_MM_PREFETCH=1 ],
1029 [ AC_MSG_RESULT(no); HAVE_MM_PREFETCH=0 ]
1030)
1031
1032AC_MSG_CHECKING(for strong getauxval support in the system headers)
1033AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1034    #include <arm_acle.h>
1035    #include <arm_neon.h>
1036    #include <sys/auxv.h>
1037  ]], [[
1038    getauxval(AT_HWCAP);
1039  ]])],
1040 [ AC_MSG_RESULT(yes); HAVE_STRONG_GETAUXVAL=1 ],
1041 [ AC_MSG_RESULT(no); HAVE_STRONG_GETAUXVAL=0 ]
1042)
1043
1044AC_MSG_CHECKING(for weak getauxval support in the compiler)
1045AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1046    unsigned long getauxval(unsigned long type) __attribute__((weak));
1047    #define AT_HWCAP 16
1048  ]], [[
1049    getauxval(AT_HWCAP);
1050  ]])],
1051 [ AC_MSG_RESULT(yes); HAVE_WEAK_GETAUXVAL=1 ],
1052 [ AC_MSG_RESULT(no); HAVE_WEAK_GETAUXVAL=0 ]
1053)
1054
1055dnl Check for reduced exports
1056if test x$use_reduce_exports = xyes; then
1057  AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[RE_CXXFLAGS="-fvisibility=hidden"],
1058  [AC_MSG_ERROR([Cannot set default symbol visibility. Use --disable-reduce-exports.])])
1059fi
1060
1061AC_MSG_CHECKING([for std::system])
1062AC_LINK_IFELSE(
1063    [ AC_LANG_PROGRAM(
1064        [[ #include <cstdlib> ]],
1065        [[ int nErr = std::system(""); ]]
1066    )],
1067    [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_STD__SYSTEM, 1, Define to 1 if std::system is available.)],
1068    [ AC_MSG_RESULT(no) ]
1069)
1070
1071AC_MSG_CHECKING([for ::_wsystem])
1072AC_LINK_IFELSE(
1073    [ AC_LANG_PROGRAM(
1074        [[ ]],
1075        [[ int nErr = ::_wsystem(""); ]]
1076    )],
1077    [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_WSYSTEM, 1, Define to 1 if ::wsystem is available.)],
1078    [ AC_MSG_RESULT(no) ]
1079)
1080
1081AC_DEFINE([HAVE_SYSTEM], [HAVE_STD__SYSTEM || HAVE_WSYSTEM], [std::system or ::wsystem])
1082
1083LEVELDB_CPPFLAGS=
1084LIBLEVELDB=
1085LIBMEMENV=
1086AM_CONDITIONAL([EMBEDDED_LEVELDB],[true])
1087AC_SUBST(LEVELDB_CPPFLAGS)
1088AC_SUBST(LIBLEVELDB)
1089AC_SUBST(LIBMEMENV)
1090
1091CRYPTOPP_CPPFLAGS=
1092LIBCRYPTOPP=
1093AM_CONDITIONAL([EMBEDDED_CRYPTOPP],[true])
1094AC_SUBST(CRYPTOPP_CPPFLAGS)
1095AC_SUBST(LIBCRYPTOPP)
1096
1097LIBFF_CPPFLAGS=
1098LIBFF=
1099AM_CONDITIONAL([EMBEDDED_LIBFF],[true])
1100AC_SUBST(LIBFF_CPPFLAGS)
1101AC_SUBST(LIBFF)
1102
1103dnl enable-fuzz should disable all other targets
1104if test "x$enable_fuzz" = "xyes"; then
1105  AC_MSG_WARN(enable-fuzz will disable all other targets)
1106  build_bitcoin_utils=no
1107  build_bitcoin_cli=no
1108  build_bitcoin_tx=no
1109  build_bitcoin_wallet=no
1110  build_bitcoind=no
1111  build_bitcoin_libs=no
1112  bitcoin_enable_qt=no
1113  bitcoin_enable_qt_test=no
1114  bitcoin_enable_qt_dbus=no
1115  enable_wallet=no
1116  use_bench=no
1117  use_upnp=no
1118  use_zmq=no
1119else
1120  BITCOIN_QT_INIT
1121
1122  dnl sets $bitcoin_enable_qt, $bitcoin_enable_qt_test, $bitcoin_enable_qt_dbus
1123  BITCOIN_QT_CONFIGURE([$use_pkgconfig])
1124fi
1125
1126if test x$enable_wallet != xno; then
1127    dnl Check for libdb_cxx only if wallet enabled
1128    BITCOIN_FIND_BDB48
1129fi
1130
1131dnl Check for libminiupnpc (optional)
1132if test x$use_upnp != xno; then
1133  AC_CHECK_HEADERS(
1134    [miniupnpc/miniwget.h miniupnpc/miniupnpc.h miniupnpc/upnpcommands.h miniupnpc/upnperrors.h],
1135    [AC_CHECK_LIB([miniupnpc], [upnpDiscover], [MINIUPNPC_LIBS=-lminiupnpc], [have_miniupnpc=no])],
1136    [have_miniupnpc=no]
1137  )
1138dnl The minimum supported miniUPnPc API version is set to 10. This keeps compatibility
1139dnl with Ubuntu 16.04 LTS and Debian 8 libminiupnpc-dev packages.
1140if test x$have_miniupnpc != xno; then
1141  AC_MSG_CHECKING([whether miniUPnPc API version is supported])
1142  AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
1143      @%:@include <miniupnpc/miniupnpc.h>
1144    ]], [[
1145      #if MINIUPNPC_API_VERSION >= 10
1146      // Everything is okay
1147      #else
1148      #  error miniUPnPc API version is too old
1149      #endif
1150    ]])],[
1151      AC_MSG_RESULT(yes)
1152    ],[
1153    AC_MSG_RESULT(no)
1154    AC_MSG_WARN([miniUPnPc API version < 10 is unsupported, disabling UPnP support.])
1155    have_miniupnpc=no
1156  ])
1157fi
1158fi
1159
1160if test x$build_bitcoin_wallet$build_bitcoin_cli$build_bitcoin_tx$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench = xnonononononono; then
1161    use_boost=no
1162else
1163    use_boost=yes
1164fi
1165
1166if test x$use_boost = xyes; then
1167
1168dnl Minimum required Boost version
1169define(MINIMUM_REQUIRED_BOOST, 1.64.0)
1170
1171dnl Check for boost libs
1172AX_BOOST_BASE([MINIMUM_REQUIRED_BOOST])
1173if test x$want_boost = xno; then
1174    AC_MSG_ERROR([[only libbitcoinconsensus can be built without boost]])
1175fi
1176AX_BOOST_SYSTEM
1177AX_BOOST_FILESYSTEM
1178AX_BOOST_PROGRAM_OPTIONS
1179AX_BOOST_THREAD
1180AX_BOOST_RANDOM
1181AX_BOOST_CHRONO
1182
1183dnl Boost 1.56 through 1.62 allow using std::atomic instead of its own atomic
1184dnl counter implementations. In 1.63 and later the std::atomic approach is default.
1185m4_pattern_allow(DBOOST_AC_USE_STD_ATOMIC) dnl otherwise it's treated like a macro
1186BOOST_CPPFLAGS="-DBOOST_SP_USE_STD_ATOMIC -DBOOST_AC_USE_STD_ATOMIC $BOOST_CPPFLAGS"
1187
1188if test x$use_reduce_exports = xyes; then
1189  AC_MSG_CHECKING([for working boost reduced exports])
1190  TEMP_CPPFLAGS="$CPPFLAGS"
1191  CPPFLAGS="$BOOST_CPPFLAGS $CPPFLAGS"
1192  AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
1193      @%:@include <boost/version.hpp>
1194    ]], [[
1195      #if BOOST_VERSION >= 104900
1196      // Everything is okay
1197      #else
1198      #  error Boost version is too old
1199      #endif
1200    ]])],[
1201      AC_MSG_RESULT(yes)
1202    ],[
1203    AC_MSG_ERROR([boost versions < 1.49 are known to be broken with reduced exports. Use --disable-reduce-exports.])
1204  ])
1205  CPPFLAGS="$TEMP_CPPFLAGS"
1206fi
1207fi
1208
1209if test x$use_reduce_exports = xyes; then
1210    CXXFLAGS="$CXXFLAGS $RE_CXXFLAGS"
1211    AX_CHECK_LINK_FLAG([[-Wl,--exclude-libs,ALL]], [RELDFLAGS="-Wl,--exclude-libs,ALL"])
1212fi
1213
1214if test x$use_tests = xyes; then
1215
1216  if test x$HEXDUMP = x; then
1217    AC_MSG_ERROR(hexdump is required for tests)
1218  fi
1219
1220
1221  if test x$use_boost = xyes; then
1222
1223  AX_BOOST_UNIT_TEST_FRAMEWORK
1224
1225  dnl Determine if -DBOOST_TEST_DYN_LINK is needed
1226  AC_MSG_CHECKING([for dynamic linked boost test])
1227  TEMP_LIBS="$LIBS"
1228  LIBS="$LIBS $BOOST_LDFLAGS $BOOST_UNIT_TEST_FRAMEWORK_LIB"
1229  TEMP_CPPFLAGS="$CPPFLAGS"
1230  CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
1231  AC_LINK_IFELSE([AC_LANG_SOURCE([
1232       #define BOOST_TEST_DYN_LINK
1233       #define BOOST_TEST_MAIN
1234        #include <boost/test/unit_test.hpp>
1235
1236       ])],
1237    [AC_MSG_RESULT(yes)]
1238    [TESTDEFS="$TESTDEFS -DBOOST_TEST_DYN_LINK"],
1239    [AC_MSG_RESULT(no)])
1240  LIBS="$TEMP_LIBS"
1241  CPPFLAGS="$TEMP_CPPFLAGS"
1242
1243  fi
1244fi
1245
1246if test x$use_boost = xyes; then
1247
1248BOOST_LIBS="$BOOST_LDFLAGS $BOOST_SYSTEM_LIB $BOOST_FILESYSTEM_LIB $BOOST_PROGRAM_OPTIONS_LIB $BOOST_THREAD_LIB $BOOST_CHRONO_LIB $BOOST_RANDOM_LIB"
1249
1250
1251dnl If boost (prior to 1.57) was built without c++11, it emulated scoped enums
1252dnl using c++98 constructs. Unfortunately, this implementation detail leaked into
1253dnl the abi. This was fixed in 1.57.
1254
1255dnl When building against that installed version using c++11, the headers pick up
1256dnl on the native c++11 scoped enum support and enable it, however it will fail to
1257dnl link. This can be worked around by disabling c++11 scoped enums if linking will
1258dnl fail.
1259dnl BOOST_NO_SCOPED_ENUMS was changed to BOOST_NO_CXX11_SCOPED_ENUMS in 1.51.
1260
1261TEMP_LIBS="$LIBS"
1262LIBS="$BOOST_LIBS $LIBS"
1263TEMP_CPPFLAGS="$CPPFLAGS"
1264CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
1265AC_MSG_CHECKING([for mismatched boost c++11 scoped enums])
1266AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1267  #include <boost/config.hpp>
1268  #include <boost/version.hpp>
1269  #if !defined(BOOST_NO_SCOPED_ENUMS) && !defined(BOOST_NO_CXX11_SCOPED_ENUMS) && BOOST_VERSION < 105700
1270  #define BOOST_NO_SCOPED_ENUMS
1271  #define BOOST_NO_CXX11_SCOPED_ENUMS
1272  #define CHECK
1273  #endif
1274  #include <boost/filesystem.hpp>
1275  ]],[[
1276  #if defined(CHECK)
1277    boost::filesystem::copy_file("foo", "bar");
1278  #else
1279    choke;
1280  #endif
1281  ]])],
1282  [AC_MSG_RESULT(mismatched); BOOST_CPPFLAGS="$BOOST_CPPFLAGS -DBOOST_NO_SCOPED_ENUMS -DBOOST_NO_CXX11_SCOPED_ENUMS"], [AC_MSG_RESULT(ok)])
1283LIBS="$TEMP_LIBS"
1284CPPFLAGS="$TEMP_CPPFLAGS"
1285
1286fi
1287
1288if test x$use_pkgconfig = xyes; then
1289  : dnl
1290  m4_ifdef(
1291    [PKG_CHECK_MODULES],
1292    [
1293      PKG_CHECK_MODULES([SSL], [libssl],, [AC_MSG_ERROR(openssl not found.)])
1294      PKG_CHECK_MODULES([CRYPTO], [libcrypto],,[AC_MSG_ERROR(libcrypto not found.)])
1295      if test x$use_qr != xno; then
1296        BITCOIN_QT_CHECK([PKG_CHECK_MODULES([QR], [libqrencode], [have_qrencode=yes], [have_qrencode=no])])
1297      fi
1298      if test x$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench != xnonononono; then
1299        PKG_CHECK_MODULES([EVENT], [libevent >= 2.0.21],, [AC_MSG_ERROR(libevent version 2.0.21 or greater not found.)])
1300        if test x$TARGET_OS != xwindows; then
1301          PKG_CHECK_MODULES([EVENT_PTHREADS], [libevent_pthreads >= 2.0.21],, [AC_MSG_ERROR(libevent_pthreads version 2.0.21 or greater not found.)])
1302        fi
1303      fi
1304
1305      if test "x$use_zmq" = "xyes"; then
1306        PKG_CHECK_MODULES([ZMQ],[libzmq >= 4],
1307          [AC_DEFINE([ENABLE_ZMQ],[1],[Define to 1 to enable ZMQ functions])],
1308          [AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])
1309           AC_MSG_WARN([libzmq version 4.x or greater not found, disabling])
1310           use_zmq=no])
1311      else
1312          AC_DEFINE_UNQUOTED([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])
1313      fi
1314    ]
1315  )
1316else
1317  AC_CHECK_HEADER([openssl/crypto.h],,AC_MSG_ERROR(libcrypto headers missing))
1318  AC_CHECK_LIB([crypto],      [main],CRYPTO_LIBS=-lcrypto, AC_MSG_ERROR(libcrypto missing))
1319
1320  AC_CHECK_HEADER([openssl/ssl.h],, AC_MSG_ERROR(libssl headers missing),)
1321  AC_CHECK_LIB([ssl],         [main],SSL_LIBS=-lssl, AC_MSG_ERROR(libssl missing))
1322
1323  if test x$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench != xnonononono; then
1324    AC_CHECK_HEADER([event2/event.h],, AC_MSG_ERROR(libevent headers missing),)
1325    AC_CHECK_LIB([event],[main],EVENT_LIBS=-levent,AC_MSG_ERROR(libevent missing))
1326    if test x$TARGET_OS != xwindows; then
1327      AC_CHECK_LIB([event_pthreads],[main],EVENT_PTHREADS_LIBS=-levent_pthreads,AC_MSG_ERROR(libevent_pthreads missing))
1328    fi
1329  fi
1330
1331  if test "x$use_zmq" = "xyes"; then
1332     AC_CHECK_HEADER([zmq.h],
1333       [AC_DEFINE([ENABLE_ZMQ],[1],[Define to 1 to enable ZMQ functions])],
1334       [AC_MSG_WARN([zmq.h not found, disabling zmq support])
1335        use_zmq=no
1336        AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])])
1337     AC_CHECK_LIB([zmq],[zmq_ctx_shutdown],ZMQ_LIBS=-lzmq,
1338       [AC_MSG_WARN([libzmq >= 4.0 not found, disabling zmq support])
1339        use_zmq=no
1340        AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])])
1341  else
1342    AC_DEFINE_UNQUOTED([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])
1343  fi
1344
1345  if test "x$use_zmq" = "xyes"; then
1346    dnl Assume libzmq was built for static linking
1347    case $host in
1348      *mingw*)
1349        ZMQ_CFLAGS="$ZMQ_CFLAGS -DZMQ_STATIC"
1350      ;;
1351    esac
1352  fi
1353
1354  if test x$use_qr != xno; then
1355    BITCOIN_QT_CHECK([AC_CHECK_LIB([qrencode], [main],[QR_LIBS=-lqrencode], [have_qrencode=no])])
1356    BITCOIN_QT_CHECK([AC_CHECK_HEADER([qrencode.h],, have_qrencode=no)])
1357  fi
1358fi
1359
1360# These packages don't provide pkgconfig config files across all
1361# platforms, so we use older autoconf detection mechanisms:
1362AC_CHECK_HEADER([gmp.h],,AC_MSG_ERROR(libgmp headers missing))
1363AC_CHECK_LIB([gmp],[[__gmpn_sub_n]],GMP_LIBS=-lgmp, [AC_MSG_ERROR(libgmp missing)])
1364
1365AC_CHECK_HEADER([gmpxx.h],,AC_MSG_ERROR(libgmpxx headers missing))
1366AC_CHECK_LIB([gmpxx],[main],GMPXX_LIBS=-lgmpxx, [AC_MSG_ERROR(libgmpxx missing)])
1367
1368save_CXXFLAGS="${CXXFLAGS}"
1369CXXFLAGS="${CXXFLAGS} ${CRYPTO_CFLAGS} ${SSL_CFLAGS}"
1370AC_CHECK_DECLS([EVP_MD_CTX_new],,,[AC_INCLUDES_DEFAULT
1371#include <openssl/x509_vfy.h>
1372])
1373CXXFLAGS="${save_CXXFLAGS}"
1374
1375dnl univalue check
1376
1377need_bundled_univalue=yes
1378
1379if test x$build_bitcoin_wallet$build_bitcoin_cli$build_bitcoin_tx$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench = xnonononononono; then
1380  need_bundled_univalue=no
1381else
1382
1383if test x$system_univalue != xno ; then
1384  found_univalue=no
1385  if test x$use_pkgconfig = xyes; then
1386    : #NOP
1387    m4_ifdef(
1388      [PKG_CHECK_MODULES],
1389      [
1390        PKG_CHECK_MODULES([UNIVALUE],[libunivalue >= 1.0.4],[found_univalue=yes],[true])
1391      ]
1392    )
1393  else
1394    AC_CHECK_HEADER([univalue.h],[
1395      AC_CHECK_LIB([univalue],  [main],[
1396        UNIVALUE_LIBS=-lunivalue
1397        found_univalue=yes
1398      ],[true])
1399    ],[true])
1400  fi
1401
1402  if test x$found_univalue = xyes ; then
1403    system_univalue=yes
1404    need_bundled_univalue=no
1405  elif test x$system_univalue = xyes ; then
1406    AC_MSG_ERROR([univalue not found])
1407  else
1408    system_univalue=no
1409  fi
1410fi
1411
1412if test x$need_bundled_univalue = xyes ; then
1413  UNIVALUE_CFLAGS='-I$(srcdir)/univalue/include'
1414  UNIVALUE_LIBS='univalue/libunivalue.la'
1415fi
1416
1417fi
1418
1419AM_CONDITIONAL([EMBEDDED_UNIVALUE],[test x$need_bundled_univalue = xyes])
1420AC_SUBST(UNIVALUE_CFLAGS)
1421AC_SUBST(UNIVALUE_LIBS)
1422
1423AC_MSG_CHECKING([whether to build bitcoind])
1424AM_CONDITIONAL([BUILD_BITCOIND], [test x$build_bitcoind = xyes])
1425AC_MSG_RESULT($build_bitcoind)
1426
1427AC_MSG_CHECKING([whether to build bitcoin-cli])
1428AM_CONDITIONAL([BUILD_BITCOIN_CLI], [test x$build_bitcoin_cli = xyes])
1429AC_MSG_RESULT($build_bitcoin_cli)
1430
1431AC_MSG_CHECKING([whether to build bitcoin-tx])
1432AM_CONDITIONAL([BUILD_BITCOIN_TX], [test x$build_bitcoin_tx = xyes])
1433AC_MSG_RESULT($build_bitcoin_tx)
1434
1435AC_MSG_CHECKING([whether to build bitcoin-wallet])
1436AM_CONDITIONAL([BUILD_BITCOIN_WALLET], [test x$build_bitcoin_wallet = xyes])
1437AC_MSG_RESULT($build_bitcoin_wallet)
1438
1439AC_MSG_CHECKING([whether to build libraries])
1440AM_CONDITIONAL([BUILD_BITCOIN_LIBS], [test x$build_bitcoin_libs = xyes])
1441if test x$build_bitcoin_libs = xyes; then
1442  AC_DEFINE(HAVE_CONSENSUS_LIB, 1, [Define this symbol if the consensus lib has been built])
1443  AC_CONFIG_FILES([libbitcoinconsensus.pc:libbitcoinconsensus.pc.in])
1444fi
1445AC_MSG_RESULT($build_bitcoin_libs)
1446
1447AC_LANG_POP
1448
1449if test "x$use_ccache" != "xno"; then
1450  AC_MSG_CHECKING(if ccache should be used)
1451  if test x$CCACHE = x; then
1452    if test "x$use_ccache" = "xyes"; then
1453      AC_MSG_ERROR([ccache not found.]);
1454    else
1455      use_ccache=no
1456    fi
1457  else
1458    use_ccache=yes
1459    CC="$ac_cv_path_CCACHE $CC"
1460    CXX="$ac_cv_path_CCACHE $CXX"
1461  fi
1462  AC_MSG_RESULT($use_ccache)
1463fi
1464if test "x$use_ccache" = "xyes"; then
1465    AX_CHECK_PREPROC_FLAG([-Qunused-arguments],[CPPFLAGS="-Qunused-arguments $CPPFLAGS"])
1466fi
1467
1468dnl enable wallet
1469AC_MSG_CHECKING([if wallet should be enabled])
1470if test x$enable_wallet != xno; then
1471  AC_MSG_RESULT(yes)
1472  AC_DEFINE_UNQUOTED([ENABLE_WALLET],[1],[Define to 1 to enable wallet functions])
1473
1474else
1475  AC_MSG_RESULT(no)
1476fi
1477
1478dnl enable upnp support
1479AC_MSG_CHECKING([whether to build with support for UPnP])
1480if test x$have_miniupnpc = xno; then
1481  if test x$use_upnp = xyes; then
1482     AC_MSG_ERROR("UPnP requested but cannot be built. Use --without-miniupnpc.")
1483  fi
1484  AC_MSG_RESULT(no)
1485  use_upnp=no
1486else
1487  if test x$use_upnp != xno; then
1488    AC_MSG_RESULT(yes)
1489    AC_MSG_CHECKING([whether to build with UPnP enabled by default])
1490    use_upnp=yes
1491    upnp_setting=0
1492    if test x$use_upnp_default != xno; then
1493      use_upnp_default=yes
1494      upnp_setting=1
1495    fi
1496    AC_MSG_RESULT($use_upnp_default)
1497    AC_DEFINE_UNQUOTED([USE_UPNP],[$upnp_setting],[UPnP support not compiled if undefined, otherwise value (0 or 1) determines default state])
1498    if test x$TARGET_OS = xwindows; then
1499      MINIUPNPC_CPPFLAGS="-DSTATICLIB -DMINIUPNP_STATICLIB"
1500    fi
1501  else
1502    AC_MSG_RESULT(no)
1503  fi
1504fi
1505
1506dnl these are only used when qt is enabled
1507BUILD_TEST_QT=""
1508if test x$bitcoin_enable_qt != xno; then
1509  dnl enable dbus support
1510  AC_MSG_CHECKING([whether to build GUI with support for D-Bus])
1511  if test x$bitcoin_enable_qt_dbus != xno; then
1512    AC_DEFINE([USE_DBUS],[1],[Define if dbus support should be compiled in])
1513  fi
1514  AC_MSG_RESULT($bitcoin_enable_qt_dbus)
1515
1516  dnl enable qr support
1517  AC_MSG_CHECKING([whether to build GUI with support for QR codes])
1518  if test x$have_qrencode = xno; then
1519    if test x$use_qr = xyes; then
1520      AC_MSG_ERROR([QR support requested but cannot be built. Use --without-qrencode])
1521    fi
1522    use_qr=no
1523  else
1524    if test x$use_qr != xno; then
1525      AC_DEFINE([USE_QRCODE],[1],[Define if QR support should be compiled in])
1526      use_qr=yes
1527    fi
1528  fi
1529  AC_MSG_RESULT([$use_qr])
1530
1531  if test x$XGETTEXT = x; then
1532    AC_MSG_WARN("xgettext is required to update qt translations")
1533  fi
1534
1535  AC_MSG_CHECKING([whether to build test_bitcoin-qt])
1536  if test x$use_gui_tests$bitcoin_enable_qt_test = xyesyes; then
1537    AC_MSG_RESULT([yes])
1538    BUILD_TEST_QT="yes"
1539  else
1540    AC_MSG_RESULT([no])
1541  fi
1542fi
1543
1544AM_CONDITIONAL([ENABLE_ZMQ], [test "x$use_zmq" = "xyes"])
1545
1546AC_MSG_CHECKING([whether to build test_bitcoin])
1547if test x$use_tests = xyes; then
1548  AC_MSG_RESULT([yes])
1549  BUILD_TEST="yes"
1550else
1551  AC_MSG_RESULT([no])
1552  BUILD_TEST=""
1553fi
1554
1555AC_MSG_CHECKING([whether to reduce exports])
1556if test x$use_reduce_exports = xyes; then
1557  AC_MSG_RESULT([yes])
1558else
1559  AC_MSG_RESULT([no])
1560fi
1561
1562if test x$build_bitcoin_wallet$build_bitcoin_cli$build_bitcoin_tx$build_bitcoin_libs$build_bitcoind$bitcoin_enable_qt$use_bench$use_tests = xnononononononono; then
1563  AC_MSG_ERROR([No targets! Please specify at least one of: --with-utils --with-libs --with-daemon --with-gui --enable-bench or --enable-tests])
1564fi
1565
1566AM_CONDITIONAL([TARGET_DARWIN], [test x$TARGET_OS = xdarwin])
1567AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
1568AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
1569AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
1570AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
1571AM_CONDITIONAL([ENABLE_FUZZ],[test x$enable_fuzz = xyes])
1572AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])
1573AM_CONDITIONAL([ENABLE_QT_TESTS],[test x$BUILD_TEST_QT = xyes])
1574AM_CONDITIONAL([ENABLE_BENCH],[test x$use_bench = xyes])
1575AM_CONDITIONAL([USE_QRCODE], [test x$use_qr = xyes])
1576AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
1577AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes])
1578AM_CONDITIONAL([HARDEN],[test x$use_hardening = xyes])
1579AM_CONDITIONAL([ENABLE_SSE42],[test x$enable_sse42 = xyes])
1580AM_CONDITIONAL([ENABLE_SSE41],[test x$enable_sse41 = xyes])
1581AM_CONDITIONAL([ENABLE_AVX2],[test x$enable_avx2 = xyes])
1582AM_CONDITIONAL([ENABLE_SHANI],[test x$enable_shani = xyes])
1583AM_CONDITIONAL([ENABLE_ARM_CRC],[test x$enable_arm_crc = xyes])
1584AM_CONDITIONAL([USE_ASM],[test x$use_asm = xyes])
1585AM_CONDITIONAL([WORDS_BIGENDIAN],[test x$ac_cv_c_bigendian = xyes])
1586
1587AC_DEFINE(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR, [Major version])
1588AC_DEFINE(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR, [Minor version])
1589AC_DEFINE(CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION, [Build revision])
1590AC_DEFINE(CLIENT_VERSION_BUILD, _CLIENT_VERSION_BUILD, [Version Build])
1591AC_DEFINE(CLIENT_VERSION_IS_RELEASE, _CLIENT_VERSION_IS_RELEASE, [Version is release])
1592AC_DEFINE(COPYRIGHT_YEAR, _COPYRIGHT_YEAR, [Copyright year])
1593AC_DEFINE(COPYRIGHT_HOLDERS, "_COPYRIGHT_HOLDERS", [Copyright holder(s) before %s replacement])
1594AC_DEFINE(COPYRIGHT_HOLDERS_SUBSTITUTION, "_COPYRIGHT_HOLDERS_SUBSTITUTION", [Replacement for %s in copyright holders string])
1595define(_COPYRIGHT_HOLDERS_FINAL, [patsubst(_COPYRIGHT_HOLDERS, [%s], [_COPYRIGHT_HOLDERS_SUBSTITUTION])])
1596AC_DEFINE(COPYRIGHT_HOLDERS_FINAL, "_COPYRIGHT_HOLDERS_FINAL", [Copyright holder(s)])
1597AC_SUBST(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR)
1598AC_SUBST(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR)
1599AC_SUBST(CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION)
1600AC_SUBST(CLIENT_VERSION_BUILD, _CLIENT_VERSION_BUILD)
1601AC_SUBST(CLIENT_VERSION_IS_RELEASE, _CLIENT_VERSION_IS_RELEASE)
1602AC_SUBST(COPYRIGHT_YEAR, _COPYRIGHT_YEAR)
1603AC_SUBST(COPYRIGHT_HOLDERS, "_COPYRIGHT_HOLDERS")
1604AC_SUBST(COPYRIGHT_HOLDERS_SUBSTITUTION, "_COPYRIGHT_HOLDERS_SUBSTITUTION")
1605AC_SUBST(COPYRIGHT_HOLDERS_FINAL, "_COPYRIGHT_HOLDERS_FINAL")
1606AC_SUBST(BITCOIN_DAEMON_NAME)
1607AC_SUBST(BITCOIN_GUI_NAME)
1608AC_SUBST(BITCOIN_CLI_NAME)
1609AC_SUBST(BITCOIN_TX_NAME)
1610AC_SUBST(BITCOIN_WALLET_TOOL_NAME)
1611
1612AC_SUBST(RELDFLAGS)
1613AC_SUBST(DEBUG_CPPFLAGS)
1614AC_SUBST(WARN_CXXFLAGS)
1615AC_SUBST(NOWARN_CXXFLAGS)
1616AC_SUBST(DEBUG_CXXFLAGS)
1617AC_SUBST(COMPAT_LDFLAGS)
1618AC_SUBST(ERROR_CXXFLAGS)
1619AC_SUBST(GPROF_CXXFLAGS)
1620AC_SUBST(GPROF_LDFLAGS)
1621AC_SUBST(HARDENED_CXXFLAGS)
1622AC_SUBST(HARDENED_CPPFLAGS)
1623AC_SUBST(HARDENED_LDFLAGS)
1624AC_SUBST(PIC_FLAGS)
1625AC_SUBST(PIE_FLAGS)
1626AC_SUBST(SANITIZER_CXXFLAGS)
1627AC_SUBST(SANITIZER_LDFLAGS)
1628AC_SUBST(SSE42_CXXFLAGS)
1629AC_SUBST(SSE41_CXXFLAGS)
1630AC_SUBST(AVX2_CXXFLAGS)
1631AC_SUBST(SHANI_CXXFLAGS)
1632AC_SUBST(ARM_CRC_CXXFLAGS)
1633AC_SUBST(LIBTOOL_APP_LDFLAGS)
1634AC_SUBST(USE_UPNP)
1635AC_SUBST(USE_QRCODE)
1636AC_SUBST(BOOST_LIBS)
1637AC_SUBST(TESTDEFS)
1638AC_SUBST(CRYPTOPP_TARGET_FLAGS)
1639AC_SUBST(MINIUPNPC_CPPFLAGS)
1640AC_SUBST(MINIUPNPC_LIBS)
1641AC_SUBST(CRYPTO_LIBS)
1642AC_SUBST(SSL_LIBS)
1643AC_SUBST(EVENT_LIBS)
1644AC_SUBST(EVENT_PTHREADS_LIBS)
1645AC_SUBST(ZMQ_LIBS)
1646AC_SUBST(QR_LIBS)
1647AC_SUBST(GMP_LIBS)
1648AC_SUBST(GMPXX_LIBS)
1649AC_SUBST(HAVE_GMTIME_R)
1650AC_SUBST(HAVE_FDATASYNC)
1651AC_SUBST(HAVE_FULLFSYNC)
1652AC_SUBST(HAVE_O_CLOEXEC)
1653AC_SUBST(HAVE_BUILTIN_PREFETCH)
1654AC_SUBST(HAVE_MM_PREFETCH)
1655AC_SUBST(HAVE_STRONG_GETAUXVAL)
1656AC_SUBST(HAVE_WEAK_GETAUXVAL)
1657AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist test/config.ini])
1658AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh])
1659AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])
1660AC_CONFIG_LINKS([contrib/filter-lcov.py:contrib/filter-lcov.py])
1661AC_CONFIG_LINKS([test/functional/test_runner.py:test/functional/test_runner.py])
1662AC_CONFIG_LINKS([test/fuzz/test_runner.py:test/fuzz/test_runner.py])
1663AC_CONFIG_LINKS([test/util/bitcoin-util-test.py:test/util/bitcoin-util-test.py])
1664AC_CONFIG_LINKS([test/util/rpcauth-test.py:test/util/rpcauth-test.py])
1665
1666dnl boost's m4 checks do something really nasty: they export these vars. As a
1667dnl result, they leak into secp256k1's configure and crazy things happen.
1668dnl Until this is fixed upstream and we've synced, we'll just un-export them.
1669CPPFLAGS_TEMP="$CPPFLAGS"
1670unset CPPFLAGS
1671CPPFLAGS="$CPPFLAGS_TEMP"
1672
1673LDFLAGS_TEMP="$LDFLAGS"
1674unset LDFLAGS
1675LDFLAGS="$LDFLAGS_TEMP"
1676
1677LIBS_TEMP="$LIBS"
1678unset LIBS
1679LIBS="$LIBS_TEMP"
1680
1681PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH"
1682unset PKG_CONFIG_PATH
1683PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"
1684
1685PKGCONFIG_LIBDIR_TEMP="$PKG_CONFIG_LIBDIR"
1686unset PKG_CONFIG_LIBDIR
1687PKG_CONFIG_LIBDIR="$PKGCONFIG_LIBDIR_TEMP"
1688
1689if test x$need_bundled_univalue = xyes; then
1690  AC_CONFIG_SUBDIRS([src/univalue])
1691fi
1692
1693ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-benchmark=no --with-bignum=no --enable-module-recovery --enable-module-ecdh --enable-experimental --disable-jni"
1694AC_CONFIG_SUBDIRS([src/secp256k1])
1695
1696AC_OUTPUT
1697
1698dnl Replace the BUILDDIR path with the correct Windows path if compiling on Native Windows
1699case ${OS} in
1700   *Windows*)
1701     sed  's/BUILDDIR="\/\([[a-z]]\)/BUILDDIR="\1:/'  test/config.ini > test/config-2.ini
1702     mv test/config-2.ini test/config.ini
1703   ;;
1704esac
1705
1706echo
1707echo "Options used to compile and link:"
1708echo "  with wallet   = $enable_wallet"
1709echo "  with gui / qt = $bitcoin_enable_qt"
1710if test x$bitcoin_enable_qt != xno; then
1711    echo "    with qr     = $use_qr"
1712fi
1713echo "  with zmq      = $use_zmq"
1714echo "  with test     = $use_tests"
1715if test x$use_tests != xno; then
1716    echo "    with fuzz   = $enable_fuzz"
1717fi
1718echo "  with bench    = $use_bench"
1719echo "  with upnp     = $use_upnp"
1720echo "  use asm       = $use_asm"
1721echo "  sanitizers    = $use_sanitizers"
1722echo "  debug enabled = $enable_debug"
1723echo "  gprof enabled = $enable_gprof"
1724echo "  werror        = $enable_werror"
1725echo
1726echo "  target os     = $TARGET_OS"
1727echo "  build os      = $build_os"
1728echo
1729echo "  CC            = $CC"
1730echo "  CFLAGS        = $CFLAGS"
1731echo "  CPPFLAGS      = $DEBUG_CPPFLAGS $HARDENED_CPPFLAGS $CPPFLAGS"
1732echo "  CXX           = $CXX"
1733echo "  CXXFLAGS      = $DEBUG_CXXFLAGS $HARDENED_CXXFLAGS $WARN_CXXFLAGS $NOWARN_CXXFLAGS $ERROR_CXXFLAGS $GPROF_CXXFLAGS $CXXFLAGS"
1734echo "  LDFLAGS       = $PTHREAD_CFLAGS $HARDENED_LDFLAGS $GPROF_LDFLAGS $LDFLAGS"
1735echo "  ARFLAGS       = $ARFLAGS"
1736echo
1737