1 dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
3 define(_CLIENT_VERSION_MAJOR, 2)
4 define(_CLIENT_VERSION_MINOR, 0)
5 define(_CLIENT_VERSION_REVISION, 0)
6 define(_CLIENT_VERSION_BUILD, 50)
7 define(_ZC_BUILD_VAL, m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, m4_incr(_CLIENT_VERSION_BUILD), m4_eval(_CLIENT_VERSION_BUILD < 50), 1, m4_eval(_CLIENT_VERSION_BUILD - 24), m4_eval(_CLIENT_VERSION_BUILD == 50), 1, , m4_eval(_CLIENT_VERSION_BUILD - 50)))
8 define(_CLIENT_VERSION_SUFFIX, m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, _CLIENT_VERSION_REVISION-beta$1, m4_eval(_CLIENT_VERSION_BUILD < 50), 1, _CLIENT_VERSION_REVISION-rc$1, m4_eval(_CLIENT_VERSION_BUILD == 50), 1, _CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION-$1)))
9 define(_CLIENT_VERSION_IS_RELEASE, true)
10 define(_COPYRIGHT_YEAR, 2017)
11 AC_INIT([Zcash],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_SUFFIX(_ZC_BUILD_VAL)],[https://github.com/zcash/zcash/issues],[zcash])
12 AC_CONFIG_SRCDIR([src/main.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=zcashd
18 BITCOIN_CLI_NAME=zcash-cli
19 BITCOIN_TX_NAME=zcash-tx
21 dnl Unless the user specified ARFLAGS, force it to be cr
22 AC_ARG_VAR(ARFLAGS, [Flags for the archiver, defaults to <cr> if not set])
23 if test "x${ARFLAGS+set}" != "xset"; then
29 AH_TOP([#ifndef BITCOIN_CONFIG_H])
30 AH_TOP([#define BITCOIN_CONFIG_H])
31 AH_BOTTOM([#endif //BITCOIN_CONFIG_H])
33 dnl faketime breaks configure and is only needed for make. Disable it here.
36 dnl Automake init set-up and checks
37 AM_INIT_AUTOMAKE([no-define subdir-objects foreign tar-pax])
39 dnl faketime messes with timestamps and causes configure to be re-run.
40 dnl --disable-maintainer-mode can be used to bypass this.
41 AM_MAINTAINER_MODE([enable])
43 dnl make the compilation flags quiet unless V=1 is used
44 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
46 dnl Compiler checks (here before libtool).
47 if test "x${CXXFLAGS+set}" = "xset"; then
48 CXXFLAGS_overridden=yes
50 CXXFLAGS_overridden=no
54 m4_ifdef([AC_PROG_OBJCXX],[AC_PROG_OBJCXX])
56 dnl By default, libtool for mingw refuses to link static libs into a dll for
57 dnl fear of mixing pic/non-pic objects, and import/export complications. Since
58 dnl we have those under control, re-enable that functionality.
61 lt_cv_deplibs_check_method="pass_all"
64 dnl Require C++11 compiler (no GNU extensions)
65 AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory], [nodefault])
66 dnl Check if -latomic is required for <std::atomic>
69 dnl Libtool init checks.
72 dnl Check/return PATH for base programs.
74 AC_PATH_TOOL(RANLIB, ranlib)
75 AC_PATH_TOOL(STRIP, strip)
76 AC_PATH_TOOL(GCOV, gcov)
77 AC_PATH_PROG(LCOV, lcov)
78 AC_PATH_PROG(GENHTML, genhtml)
79 AC_PATH_PROG([GIT], [git])
80 AC_PATH_PROG(CCACHE,ccache)
81 AC_PATH_PROG(XGETTEXT,xgettext)
82 AC_PATH_PROG(HEXDUMP,hexdump)
83 AC_PATH_TOOL(READELF,readelf)
84 AC_PATH_TOOL(CPPFILT,c++filt)
87 AC_ARG_ENABLE([wallet],
88 [AS_HELP_STRING([--enable-wallet],
89 [enable wallet (default is yes)])],
90 [enable_wallet=$enableval],
93 AC_ARG_ENABLE([mining],
94 [AS_HELP_STRING([--enable-mining],
95 [enable mining (default is yes)])],
96 [enable_mining=$enableval],
99 AC_ARG_ENABLE([proton],
100 [AS_HELP_STRING([--disable-proton],
101 [disable Proton (AMQP messaging)])],
102 [use_proton=$enableval],
106 AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
107 [use_tests=$enableval],
110 AC_ARG_ENABLE([asan],
111 [AS_HELP_STRING([--enable-asan],
112 [instrument the executables with asan (default is no)])],
113 [use_asan=$enableval],
116 AC_ARG_ENABLE([tsan],
117 [AS_HELP_STRING([--enable-tsan],
118 [instrument the executables with tsan (default is no)])],
119 [use_tsan=$enableval],
122 AC_ARG_ENABLE([hardening],
123 [AS_HELP_STRING([--enable-hardening],
124 [attempt to harden the resulting executables (default is yes)])],
125 [use_hardening=$enableval],
128 AC_ARG_ENABLE([reduce-exports],
129 [AS_HELP_STRING([--enable-reduce-exports],
130 [attempt to reduce exported symbols in the resulting executables (default is no)])],
131 [use_reduce_exports=$enableval],
132 [use_reduce_exports=no])
134 AC_ARG_ENABLE([ccache],
135 [AS_HELP_STRING([--enable-ccache],
136 [use ccache for building (default is yes if ccache is found)])],
137 [use_ccache=$enableval],
140 AC_ARG_ENABLE([lcov],
141 [AS_HELP_STRING([--enable-lcov],
142 [enable lcov testing (default is no)])],
146 AC_ARG_ENABLE([glibc-back-compat],
147 [AS_HELP_STRING([--enable-glibc-back-compat],
148 [enable backwards compatibility with glibc])],
149 [use_glibc_compat=$enableval],
150 [use_glibc_compat=no])
153 [AS_HELP_STRING([--disable-zmq],
154 [disable ZMQ notifications])],
155 [use_zmq=$enableval],
158 AC_ARG_WITH([protoc-bindir],[AS_HELP_STRING([--with-protoc-bindir=BIN_DIR],[specify protoc bin path])], [protoc_bin_path=$withval], [])
161 [AS_HELP_STRING([--disable-man],
162 [do not install man pages (default is to install)])],,
164 AM_CONDITIONAL(ENABLE_MAN, test "$enable_man" != no)
167 AC_ARG_ENABLE([debug],
168 [AS_HELP_STRING([--enable-debug],
169 [use debug compiler flags and macros (default is no)])],
170 [enable_debug=$enableval],
173 # Turn warnings into errors
174 AC_ARG_ENABLE([werror],
175 [AS_HELP_STRING([--enable-werror],
176 [Treat all compiler warnings as errors (default is no)])],
177 [enable_werror=$enableval],
181 AX_CHECK_COMPILE_FLAG([-Werror],[CXXFLAG_WERROR="-Werror"],[CXXFLAG_WERROR=""])
183 if test "x$enable_debug" = xyes; then
184 CPPFLAGS="$CPPFLAGS -DDEBUG -DDEBUG_LOCKORDER"
185 if test "x$GCC" = xyes; then
186 CFLAGS="$CFLAGS -g3 -O0"
189 if test "x$GXX" = xyes; then
190 CXXFLAGS="$CXXFLAGS -g3 -O0"
195 if test "x$enable_werror" = "xyes"; then
196 if test "x$CXXFLAG_WERROR" = "x"; then
197 AC_MSG_ERROR("enable-werror set but -Werror is not usable")
199 ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror"
202 if test "x$CXXFLAGS_overridden" = "xno"; then
203 AX_CHECK_COMPILE_FLAG([-Wall],[CXXFLAGS="$CXXFLAGS -Wall"],,[[$CXXFLAG_WERROR]])
204 AX_CHECK_COMPILE_FLAG([-Wextra],[CXXFLAGS="$CXXFLAGS -Wextra"],,[[$CXXFLAG_WERROR]])
205 AX_CHECK_COMPILE_FLAG([-Wformat],[CXXFLAGS="$CXXFLAGS -Wformat"],,[[$CXXFLAG_WERROR]])
206 AX_CHECK_COMPILE_FLAG([-Wvla],[CXXFLAGS="$CXXFLAGS -Wvla"],,[[$CXXFLAG_WERROR]])
207 AX_CHECK_COMPILE_FLAG([-Wformat-security],[CXXFLAGS="$CXXFLAGS -Wformat-security"],,[[$CXXFLAG_WERROR]])
209 ## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
210 ## unknown options if any other warning is produced. Test the -Wfoo case, and
211 ## set the -Wno-foo case if it works.
212 AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[CXXFLAGS="$CXXFLAGS -Wno-unused-parameter"],,[[$CXXFLAG_WERROR]])
213 AX_CHECK_COMPILE_FLAG([-Wself-assign],[CXXFLAGS="$CXXFLAGS -Wno-self-assign"],,[[$CXXFLAG_WERROR]])
214 AX_CHECK_COMPILE_FLAG([-Wunused-local-typedef],[CXXFLAGS="$CXXFLAGS -Wno-unused-local-typedef"],,[[$CXXFLAG_WERROR]])
215 AX_CHECK_COMPILE_FLAG([-Wdeprecated-register],[CXXFLAGS="$CXXFLAGS -Wno-deprecated-register"],,[[$CXXFLAG_WERROR]])
217 CPPFLAGS="$CPPFLAGS -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS"
220 [AS_HELP_STRING([--with-utils],
221 [build zcash-cli zcash-tx (default=yes)])],
222 [build_bitcoin_utils=$withval],
223 [build_bitcoin_utils=yes])
226 [AS_HELP_STRING([--with-libs],
227 [build libraries (default=no)])],
228 [build_bitcoin_libs=$withval],
229 [build_bitcoin_libs=no])
231 AC_ARG_WITH([daemon],
232 [AS_HELP_STRING([--with-daemon],
233 [build bitcoind daemon (default=yes)])],
234 [build_bitcoind=$withval],
235 [build_bitcoind=yes])
241 #pkgconfig does more harm than good with MinGW
245 AC_CHECK_LIB([mingwthrd], [main],, AC_MSG_ERROR(lib missing))
246 AC_CHECK_LIB([kernel32], [main],, AC_MSG_ERROR(lib missing))
247 AC_CHECK_LIB([user32], [main],, AC_MSG_ERROR(lib missing))
248 AC_CHECK_LIB([gdi32], [main],, AC_MSG_ERROR(lib missing))
249 AC_CHECK_LIB([comdlg32], [main],, AC_MSG_ERROR(lib missing))
250 AC_CHECK_LIB([winspool], [main],, AC_MSG_ERROR(lib missing))
251 AC_CHECK_LIB([winmm], [main],, AC_MSG_ERROR(lib missing))
252 AC_CHECK_LIB([shell32], [main],, AC_MSG_ERROR(lib missing))
253 AC_CHECK_LIB([comctl32], [main],, AC_MSG_ERROR(lib missing))
254 AC_CHECK_LIB([ole32], [main],, AC_MSG_ERROR(lib missing))
255 AC_CHECK_LIB([oleaut32], [main],, AC_MSG_ERROR(lib missing))
256 AC_CHECK_LIB([uuid], [main],, AC_MSG_ERROR(lib missing))
257 AC_CHECK_LIB([rpcrt4], [main],, AC_MSG_ERROR(lib missing))
258 AC_CHECK_LIB([advapi32], [main],, AC_MSG_ERROR(lib missing))
259 AC_CHECK_LIB([ws2_32], [main],, AC_MSG_ERROR(lib missing))
260 AC_CHECK_LIB([mswsock], [main],, AC_MSG_ERROR(lib missing))
261 AC_CHECK_LIB([shlwapi], [main],, AC_MSG_ERROR(lib missing))
262 AC_CHECK_LIB([iphlpapi], [main],, AC_MSG_ERROR(lib missing))
263 AC_CHECK_LIB([crypt32], [main],, AC_MSG_ERROR(lib missing))
265 # -static is interpreted by libtool, where it has a different meaning.
266 # In libtool-speak, it's -all-static.
267 AX_CHECK_LINK_FLAG([[-static]],[LIBTOOL_APP_LDFLAGS="$LIBTOOL_APP_LDFLAGS -all-static"])
269 AC_PATH_PROG([MAKENSIS], [makensis], none)
270 if test x$MAKENSIS = xnone; then
271 AC_MSG_WARN("makensis not found. Cannot create installer.")
274 AC_PATH_TOOL(WINDRES, windres, none)
275 if test x$WINDRES = xnone; then
276 AC_MSG_ERROR("windres not found")
279 CPPFLAGS="$CPPFLAGS -D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB"
280 LEVELDB_TARGET_FLAGS="TARGET_OS=OS_WINDOWS_CROSSCOMPILE"
281 if test "x$CXXFLAGS_overridden" = "xno"; then
282 CXXFLAGS="$CXXFLAGS -w"
285 i?86-*) WINDOWS_BITS=32 ;;
286 x86_64-*) WINDOWS_BITS=64 ;;
287 *) AC_MSG_ERROR("Could not determine win32/win64 for installer") ;;
289 AC_SUBST(WINDOWS_BITS)
291 dnl libtool insists upon adding -nostdlib and a list of objects/libs to link against.
292 dnl That breaks our ability to build dll's with static libgcc/libstdc++/libssp. Override
293 dnl its command here, with the predeps/postdeps removed, and -static inserted. Postdeps are
294 dnl also overridden to prevent their insertion later.
295 dnl This should only affect dll's.
296 archive_cmds_CXX="\$CC -shared \$libobjs \$deplibs \$compiler_flags -static -o \$output_objdir/\$soname \${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker \$lib"
302 LEVELDB_TARGET_FLAGS="TARGET_OS=Darwin"
303 if test x$cross_compiling != xyes; then
305 AC_CHECK_PROG([PORT],port, port)
306 if test x$PORT = xport; then
307 dnl add default macports paths
308 CPPFLAGS="$CPPFLAGS -isystem /opt/local/include"
309 LIBS="$LIBS -L/opt/local/lib"
310 if test -d /opt/local/include/db62; then
311 CPPFLAGS="$CPPFLAGS -I/opt/local/include/db62"
312 LIBS="$LIBS -L/opt/local/lib/db62"
316 AC_CHECK_PROG([BREW],brew, brew)
317 if test x$BREW = xbrew; then
318 dnl These Homebrew packages may be keg-only, meaning that they won't be found
319 dnl in expected paths because they may conflict with system files. Ask
320 dnl Homebrew where each one is located, then adjust paths accordingly.
321 dnl It's safe to add these paths even if the functionality is disabled by
322 dnl the user (--without-wallet for example).
324 openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
325 bdb_prefix=`$BREW --prefix berkeley-db4 2>/dev/null`
326 if test x$openssl_prefix != x; then
327 PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
328 export PKG_CONFIG_PATH
330 if test x$bdb_prefix != x; then
331 CPPFLAGS="$CPPFLAGS -I$bdb_prefix/include"
332 LIBS="$LIBS -L$bdb_prefix/lib"
341 AC_PATH_TOOL([INSTALLNAMETOOL], [install_name_tool], install_name_tool)
342 AC_PATH_TOOL([OTOOL], [otool], otool)
343 AC_PATH_PROGS([GENISOIMAGE], [genisoimage mkisofs],genisoimage)
345 dnl libtool will try to strip the static lib, which is a problem for
346 dnl cross-builds because strip attempts to call a hard-coded ld,
347 dnl which may not exist in the path. Stripping the .a is not
348 dnl necessary, so just disable it.
354 AX_CHECK_LINK_FLAG([[-Wl,-headerpad_max_install_names]], [LDFLAGS="$LDFLAGS -Wl,-headerpad_max_install_names"])
355 CPPFLAGS="$CPPFLAGS -DMAC_OSX"
356 OBJCXXFLAGS="$CXXFLAGS"
365 if test x$use_pkgconfig = xyes; then
366 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.)])
367 m4_ifdef([PKG_PROG_PKG_CONFIG], [
369 if test x"$PKG_CONFIG" = "x"; then
370 AC_MSG_ERROR(pkg-config not found.)
375 if test x$use_lcov = xyes; then
376 if test x$LCOV = x; then
377 AC_MSG_ERROR("lcov testing requested but lcov not found")
379 if test x$GCOV = x; then
380 AC_MSG_ERROR("lcov testing requested but gcov not found")
382 if test x$GENHTML = x; then
383 AC_MSG_ERROR("lcov testing requested but genhtml not found")
385 LCOV="$LCOV --gcov-tool=$GCOV --rc lcov_branch_coverage=1"
386 GENHTML="$GENHTML --branch-coverage"
387 AX_CHECK_COMPILE_FLAG([--coverage],[CXXFLAGS="$CXXFLAGS --coverage"],
388 [AC_MSG_ERROR("lcov testing requested but --coverage flag does not work")])
391 dnl Check for endianness
394 dnl Check for pthread compile/link requirements
397 # The following macro will add the necessary defines to bitcoin-config.h, but
398 # they also need to be passed down to any subprojects. Pull the results out of
399 # the cache and add them to CPPFLAGS.
401 # detect POSIX or GNU variant of strerror_r
404 if test x$ac_cv_sys_file_offset_bits != x &&
405 test x$ac_cv_sys_file_offset_bits != xno &&
406 test x$ac_cv_sys_file_offset_bits != xunknown; then
407 CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=$ac_cv_sys_file_offset_bits"
410 if test x$ac_cv_sys_large_files != x &&
411 test x$ac_cv_sys_large_files != xno &&
412 test x$ac_cv_sys_large_files != xunknown; then
413 CPPFLAGS="$CPPFLAGS -D_LARGE_FILES=$ac_cv_sys_large_files"
416 AX_CHECK_LINK_FLAG([[-Wl,--large-address-aware]], [LDFLAGS="$LDFLAGS -Wl,--large-address-aware"])
418 AX_GCC_FUNC_ATTRIBUTE([visibility])
419 AX_GCC_FUNC_ATTRIBUTE([dllexport])
420 AX_GCC_FUNC_ATTRIBUTE([dllimport])
422 if test x$use_glibc_compat != xno; then
424 #glibc absorbed clock_gettime in 2.17. librt (its previous location) is safe to link
425 #in anyway for back-compat.
426 AC_CHECK_LIB([rt],[clock_gettime],, AC_MSG_ERROR(lib missing))
428 #__fdelt_chk's params and return type have changed from long unsigned int to long int.
429 # See which one is present here.
430 AC_MSG_CHECKING(__fdelt_chk type)
431 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifdef _FORTIFY_SOURCE
432 #undef _FORTIFY_SOURCE
434 #define _FORTIFY_SOURCE 2
435 #include <sys/select.h>
436 extern "C" long unsigned int __fdelt_warn(long unsigned int);]],[[]])],
437 [ fdelt_type="long unsigned int"],
438 [ fdelt_type="long int"])
439 AC_MSG_RESULT($fdelt_type)
440 AC_DEFINE_UNQUOTED(FDELT_TYPE, $fdelt_type,[parameter and return value type for __fdelt_chk])
442 AC_SEARCH_LIBS([clock_gettime],[rt])
445 if test x$TARGET_OS != xwindows; then
446 # All windows code is PIC, forcing it on just adds useless compile warnings
447 AX_CHECK_COMPILE_FLAG([-fPIC],[PIC_FLAGS="-fPIC"])
450 #asan and tsan cannot be used together
451 if test x$use_asan$use_tsan == xyesyes; then
452 AC_MSG_ERROR(asan and tsan cannot be simultaneously enabled)
455 # using asan flag to enable address sanitizer and undefined behavior sanitizer
456 if test x$use_asan == xyes; then
457 AX_CHECK_LINK_FLAG([-static-libstdc++],[SAN_LDFLAGS="$SAN_LDFLAGS -static-libstdc++"],[AC_MSG_ERROR(Cannot statically link -static-libstdc++)])
458 AX_CHECK_LINK_FLAG([-static-libasan],[SAN_LDFLAGS="$SAN_LDFLAGS -static-libasan"],[AC_MSG_ERROR(Cannot statically link -static-libasan)])
459 AX_CHECK_COMPILE_FLAG([-fsanitize=address],[SAN_CXXFLAGS="$SAN_CXXFLAGS -fsanitize=address"],[AC_MSG_ERROR(Cannot enable -fsanitize=address)])
460 AX_CHECK_COMPILE_FLAG([-fsanitize=undefined],[SAN_CXXFLAGS="$SAN_CXXFLAGS -fsanitize=undefined"],[AC_MSG_ERROR(Cannot enable -fsanitize=undefined)])
461 AX_CHECK_COMPILE_FLAG([-fno-omit-frame-pointer],[SAN_CXXFLAGS="$SAN_CXXFLAGS -fno-omit-frame-pointer"],[AC_MSG_ERROR(Cannot enable -fno-omit-frame-pointer)])
464 # using tsan flag to enable address thread sanitizer
465 # TSAN is supported on Linux x84_64 and tested on Ubuntu 12.04
466 # Non-position-independent executables are not supported. Use with -fPIE and -pie flags
467 # libc/libstdc++ static linking is not supported
468 if test x$use_tsan == xyes; then
469 AX_CHECK_COMPILE_FLAG([-fsanitize=thread],[SAN_CXXFLAGS="$SAN_CXXFLAGS -fsanitize=thread"],[AC_MSG_ERROR(Cannot enable -fsanitize=thread)])
470 AX_CHECK_COMPILE_FLAG([-fno-omit-frame-pointer],[SAN_CXXFLAGS="$SAN_CXXFLAGS -fno-omit-frame-pointer"],[AC_MSG_ERROR(Cannot enable -fno-omit-frame-pointer)])
473 if test x$use_hardening != xno; then
474 AX_CHECK_COMPILE_FLAG([-Wformat],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wformat"],[AC_MSG_ERROR(Cannot enable -Wformat)])
475 AX_CHECK_COMPILE_FLAG([-Wformat-security],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wformat-security"],[AC_MSG_ERROR(Cannot enable -Wformat-security)],[-Wformat])
476 AX_CHECK_COMPILE_FLAG([-Wstack-protector],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"],[AC_MSG_ERROR(Cannot enable -Wstack-protector)])
477 AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"],[AC_MSG_ERROR(Cannot enable -fstack-protector-all)])
479 AX_CHECK_PREPROC_FLAG([-D_FORTIFY_SOURCE=2],[
480 AX_CHECK_PREPROC_FLAG([-U_FORTIFY_SOURCE],[
481 HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -U_FORTIFY_SOURCE"
482 ],[AC_MSG_ERROR(Cannot enable -U_FORTIFY_SOURCE)])
483 HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -D_FORTIFY_SOURCE=2"
484 ],[AC_MSG_ERROR(Cannot enable -D_FORTIFY_SOURCE=2)])
486 if test x$BUILD_OS = xdarwin; then
487 # Xcode's ld (at least ld64-302.3) doesn't support -z
488 AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_WARN(Cannot enable RELRO)])
489 AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_WARN(Cannot enable BIND_NOW)])
491 AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_ERROR(Cannot enable RELRO)])
492 AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_ERROR(Cannot enable BIND_NOW)])
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([-fPIE],[PIE_FLAGS="-fPIE"],[AC_MSG_ERROR(Cannot enable -fPIE)])
498 if test x$BUILD_OS = xdarwin; then
499 AX_CHECK_LINK_FLAG([[-Wl,-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-pie"],[AC_MSG_ERROR(Cannot enable -Wl,-pie)])
501 AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"],[AC_MSG_ERROR(Cannot enable -pie)])
504 # These are only available on Windows.
505 AX_CHECK_LINK_FLAG([[-Wl,--dynamicbase]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--dynamicbase"],[AC_MSG_ERROR(Cannot enable --dynamicbase)])
506 AX_CHECK_LINK_FLAG([[-Wl,--nxcompat]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--nxcompat"],[AC_MSG_ERROR(Cannot enable --nxcompat)])
507 AX_CHECK_LINK_FLAG([[-Wl,--high-entropy-va]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--high-entropy-va"],[AC_MSG_ERROR(Cannot enable ASLR)])
512 AC_CHECK_LIB([ssp], [main],, AC_MSG_ERROR(lib missing))
517 dnl this flag screws up non-darwin gcc even when the check fails. special-case it.
518 if test x$TARGET_OS = xdarwin; then
519 AX_CHECK_LINK_FLAG([[-Wl,-dead_strip]], [LDFLAGS="$LDFLAGS -Wl,-dead_strip"])
522 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])
523 AC_SEARCH_LIBS([getaddrinfo_a], [anl], [AC_DEFINE(HAVE_GETADDRINFO_A, 1, [Define this symbol if you have getaddrinfo_a])])
524 AC_SEARCH_LIBS([inet_pton], [nsl resolv], [AC_DEFINE(HAVE_INET_PTON, 1, [Define this symbol if you have inet_pton])])
526 AC_CHECK_DECLS([strnlen])
528 AC_CHECK_DECLS([le16toh, le32toh, le64toh, htole16, htole32, htole64, be16toh, be32toh, be64toh, htobe16, htobe32, htobe64],,,
531 #elif HAVE_SYS_ENDIAN_H
532 #include <sys/endian.h>
535 AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64],,,
537 #include <byteswap.h>
540 dnl Check for MSG_NOSIGNAL
541 AC_MSG_CHECKING(for MSG_NOSIGNAL)
542 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]],
543 [[ int f = MSG_NOSIGNAL; ]])],
544 [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_MSG_NOSIGNAL, 1,[Define this symbol if you have MSG_NOSIGNAL]) ],
548 AC_MSG_CHECKING([for visibility attribute])
549 AC_LINK_IFELSE([AC_LANG_SOURCE([
550 int foo_def( void ) __attribute__((visibility("default")));
554 AC_DEFINE(HAVE_VISIBILITY_ATTRIBUTE,1,[Define if the visibility attribute is supported.])
559 if test x$use_reduce_exports = xyes; then
560 AC_MSG_ERROR([Cannot find a working visibility attribute. Use --disable-reduce-exports.])
565 if test x$use_reduce_exports = xyes; then
566 AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[RE_CXXFLAGS="-fvisibility=hidden"],
567 [AC_MSG_ERROR([Cannot set default symbol visibility. Use --disable-reduce-exports.])])
573 AM_CONDITIONAL([EMBEDDED_LEVELDB],[true])
574 AC_SUBST(LEVELDB_CPPFLAGS)
578 if test x$enable_wallet != xno; then
579 dnl Check for libdb_cxx only if wallet enabled
583 dnl Check Qpid Proton headers and library exist
584 if test x$use_proton = xyes; then
585 AC_CHECK_HEADERS([proton/connection.hpp],
587 [AC_MSG_WARN([Proton headers not found, disabling Proton support])
589 AC_CHECK_LIB([qpid-proton-cpp], [main],
590 [PROTON_LIBS="-lqpid-proton-cpp -lqpid-proton"],
591 [AC_MSG_WARN([Proton libraries not found, disabling Proton support])
594 if test x$use_proton = xyes; then
595 AC_DEFINE(ENABLE_PROTON, 1, [Define to 1 to enable Proton functions])
597 AC_DEFINE(ENABLE_PROTON, 0, [Define to 1 to enable Proton functions])
600 if test x$build_bitcoin_utils$build_bitcoind$use_tests = xnonono; then
606 if test x$use_boost = xyes; then
608 dnl Check for boost libs
609 dnl We need Boost >= 1.62 to fix a potential security bug (https://github.com/zcash/zcash/issues/1241)
610 AX_BOOST_BASE([1.62])
613 AX_BOOST_PROGRAM_OPTIONS
619 if test x$use_reduce_exports = xyes; then
620 CXXFLAGS="$CXXFLAGS $RE_CXXFLAGS"
621 AX_CHECK_LINK_FLAG([[-Wl,--exclude-libs,ALL]], [RELDFLAGS="-Wl,--exclude-libs,ALL"])
624 if test x$use_tests = xyes; then
626 if test x$HEXDUMP = x; then
627 AC_MSG_ERROR(hexdump is required for tests)
631 if test x$use_boost = xyes; then
633 AX_BOOST_UNIT_TEST_FRAMEWORK
635 dnl Determine if -DBOOST_TEST_DYN_LINK is needed
636 AC_MSG_CHECKING([for dynamic linked boost test])
638 LIBS="$LIBS $BOOST_LDFLAGS $BOOST_UNIT_TEST_FRAMEWORK_LIB"
639 TEMP_CPPFLAGS="$CPPFLAGS"
640 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
641 AC_LINK_IFELSE([AC_LANG_SOURCE([
642 #define BOOST_TEST_DYN_LINK
643 #define BOOST_TEST_MAIN
644 #include <boost/test/unit_test.hpp>
648 [TESTDEFS="$TESTDEFS -DBOOST_TEST_DYN_LINK"],
651 CPPFLAGS="$TEMP_CPPFLAGS"
656 if test x$use_boost = xyes; then
657 BOOST_LIBS="$BOOST_LDFLAGS $BOOST_SYSTEM_LIB $BOOST_FILESYSTEM_LIB $BOOST_PROGRAM_OPTIONS_LIB $BOOST_THREAD_LIB $BOOST_CHRONO_LIB"
660 if test x$use_pkgconfig = xyes; then
665 PKG_CHECK_MODULES([SSL], [libssl],, [AC_MSG_ERROR(openssl not found.)])
666 PKG_CHECK_MODULES([CRYPTO], [libcrypto],,[AC_MSG_ERROR(libcrypto not found.)])
667 if test x$build_bitcoin_utils$build_bitcoind$bitcoin_enable_qt$use_tests != xnononono; then
668 PKG_CHECK_MODULES([EVENT], [libevent],, [AC_MSG_ERROR(libevent not found.)])
669 if test x$TARGET_OS != xwindows; then
670 PKG_CHECK_MODULES([EVENT_PTHREADS], [libevent_pthreads],, [AC_MSG_ERROR(libevent_pthreads not found.)])
674 if test "x$use_zmq" = "xyes"; then
675 PKG_CHECK_MODULES([ZMQ],[libzmq >= 4],
676 [AC_DEFINE([ENABLE_ZMQ],[1],[Define to 1 to enable ZMQ functions])],
677 [AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])
678 AC_MSG_WARN([libzmq version 4.x or greater not found, disabling])
681 AC_DEFINE_UNQUOTED([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])
687 echo 'BUG: configure does not yet check for the following dependencies if pkg-config is not on the system: libcrypto++, libgmp'
689 AC_CHECK_HEADER([openssl/crypto.h],,AC_MSG_ERROR(libcrypto headers missing))
690 AC_CHECK_LIB([crypto], [main],CRYPTO_LIBS=-lcrypto, AC_MSG_ERROR(libcrypto missing))
692 AC_CHECK_HEADER([openssl/ssl.h],, AC_MSG_ERROR(libssl headers missing),)
693 AC_CHECK_LIB([ssl], [main],SSL_LIBS=-lssl, AC_MSG_ERROR(libssl missing))
695 if test x$build_bitcoin_utils$build_bitcoind$bitcoin_enable_qt$use_tests != xnononono; then
696 AC_CHECK_HEADER([event2/event.h],, AC_MSG_ERROR(libevent headers missing),)
697 AC_CHECK_LIB([event],[main],EVENT_LIBS=-levent,AC_MSG_ERROR(libevent missing))
698 if test x$TARGET_OS != xwindows; then
699 AC_CHECK_LIB([event_pthreads],[main],EVENT_PTHREADS_LIBS=-levent_pthreads,AC_MSG_ERROR(libevent_pthreads missing))
703 if test "x$use_zmq" = "xyes"; then
704 AC_CHECK_HEADER([zmq.h],
705 [AC_DEFINE([ENABLE_ZMQ],[1],[Define to 1 to enable ZMQ functions])],
706 [AC_MSG_WARN([zmq.h not found, disabling zmq support])
708 AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])])
709 AC_CHECK_LIB([zmq],[zmq_ctx_shutdown],ZMQ_LIBS=-lzmq,
710 [AC_MSG_WARN([libzmq >= 4.0 not found, disabling zmq support])
712 AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])])
714 AC_DEFINE_UNQUOTED([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])
717 if test "x$use_zmq" = "xyes"; then
718 dnl Assume libzmq was built for static linking
721 ZMQ_CFLAGS="$ZMQ_CFLAGS -DZMQ_STATIC"
727 # These packages don't provide pkgconfig config files across all
728 # platforms, so we use older autoconf detection mechanisms:
729 AC_CHECK_HEADER([gmp.h],,AC_MSG_ERROR(libgmp headers missing))
730 AC_CHECK_LIB([gmp],[[__gmpn_sub_n]],GMP_LIBS=-lgmp, [AC_MSG_ERROR(libgmp missing)])
732 AC_CHECK_HEADER([gmpxx.h],,AC_MSG_ERROR(libgmpxx headers missing))
733 AC_CHECK_LIB([gmpxx],[main],GMPXX_LIBS=-lgmpxx, [AC_MSG_ERROR(libgmpxx missing)])
735 RUST_LIBS="-lrustzcash -ldl"
737 dnl Check for OpenMP support
739 [AC_DEFINE(HAVE_OPENMP, 1, [Define if OpenMP is enabled])
740 AM_CONDITIONAL([HAVE_OPENMP], [true])
741 CPPFLAGS="$CPPFLAGS -DMULTICORE"
742 CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"],
743 [AC_MSG_WARN([OpenMP not supported, disabling multithreading])
744 AC_DEFINE(HAVE_OPENMP, 0, [Define if OpenMP is enabled])
745 AM_CONDITIONAL([HAVE_OPENMP], [false])])
747 # Gitian uses a config.site that sets depends_prefix, and then sets --prefix=/
748 # build.sh just uses --prefix
749 if test x$depends_prefix != x; then
750 LIBSNARK_DEPINST="$depends_prefix"
752 LIBSNARK_DEPINST="$prefix"
755 # Additional Zcash flags
756 AX_CHECK_COMPILE_FLAG([-fwrapv],[CXXFLAGS="$CXXFLAGS -fwrapv"])
757 AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing],[CXXFLAGS="$CXXFLAGS -fno-strict-aliasing"])
758 AX_CHECK_COMPILE_FLAG([-Wno-builtin-declaration-mismatch],[CXXFLAGS="$CXXFLAGS -Wno-builtin-declaration-mismatch"],,[[$CXXFLAG_WERROR]])
760 LIBZCASH_LIBS="-lgmp -lgmpxx $BOOST_SYSTEM_LIB -lcrypto -lsodium $RUST_LIBS"
762 AC_MSG_CHECKING([whether to build bitcoind])
763 AM_CONDITIONAL([BUILD_BITCOIND], [test x$build_bitcoind = xyes])
764 AC_MSG_RESULT($build_bitcoind)
766 AC_MSG_CHECKING([whether to build utils (zcash-cli zcash-tx)])
767 AM_CONDITIONAL([BUILD_BITCOIN_UTILS], [test x$build_bitcoin_utils = xyes])
768 AC_MSG_RESULT($build_bitcoin_utils)
770 AC_MSG_CHECKING([whether to build libraries])
771 AM_CONDITIONAL([BUILD_BITCOIN_LIBS], [test x$build_bitcoin_libs = xyes])
772 if test x$build_bitcoin_libs = xyes; then
773 AC_DEFINE(HAVE_CONSENSUS_LIB, 1, [Define this symbol if the consensus lib has been built])
774 AC_CONFIG_FILES([libzcashconsensus.pc:libzcashconsensus.pc.in])
777 AC_MSG_RESULT($build_bitcoin_libs)
781 if test "x$use_ccache" != "xno"; then
782 AC_MSG_CHECKING(if ccache should be used)
783 if test x$CCACHE = x; then
784 if test "x$use_ccache" = "xyes"; then
785 AC_MSG_ERROR([ccache not found.]);
791 CC="$ac_cv_path_CCACHE $CC"
792 CXX="$ac_cv_path_CCACHE $CXX"
794 AC_MSG_RESULT($use_ccache)
796 if test "x$use_ccache" = "xyes"; then
797 AX_CHECK_PREPROC_FLAG([-Qunused-arguments],[CPPFLAGS="-Qunused-arguments $CPPFLAGS"])
801 AC_MSG_CHECKING([if wallet should be enabled])
802 if test x$enable_wallet != xno; then
804 AC_DEFINE_UNQUOTED([ENABLE_WALLET],[1],[Define to 1 to enable wallet functions])
811 AC_MSG_CHECKING([if mining should be enabled])
812 if test x$enable_mining != xno; then
814 AC_DEFINE(ENABLE_MINING, 1, [Define to 1 to enable mining functions])
820 AM_CONDITIONAL([ENABLE_ZMQ], [test "x$use_zmq" = "xyes"])
822 AM_CONDITIONAL([ENABLE_PROTON], [test "x$use_proton" = "xyes"])
824 AC_MSG_CHECKING([whether to build test_bitcoin])
825 if test x$use_tests = xyes; then
833 AC_MSG_CHECKING([whether to reduce exports])
834 if test x$use_reduce_exports = xyes; then
840 if test x$build_bitcoin_utils$build_bitcoin_libs$build_bitcoind$use_tests = xnononono; then
841 AC_MSG_ERROR([No targets! Please specify at least one of: --with-utils --with-libs --with-daemon or --enable-tests])
844 AM_CONDITIONAL([TARGET_DARWIN], [test x$TARGET_OS = xdarwin])
845 AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
846 AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
847 AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
848 AM_CONDITIONAL([ENABLE_MINING],[test x$enable_mining = xyes])
849 AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
850 AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
851 AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes])
852 AM_CONDITIONAL([HARDEN],[test x$use_hardening = xyes])
853 AM_CONDITIONAL([ASAN],[test x$use_asan = xyes])
854 AM_CONDITIONAL([TSAN],[test x$use_tsan = xyes])
856 AC_DEFINE(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR, [Major version])
857 AC_DEFINE(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR, [Minor version])
858 AC_DEFINE(CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION, [Build revision])
859 AC_DEFINE(CLIENT_VERSION_BUILD, _CLIENT_VERSION_BUILD, [Version Build])
860 AC_DEFINE(CLIENT_VERSION_IS_RELEASE, _CLIENT_VERSION_IS_RELEASE, [Version is release])
861 AC_DEFINE(COPYRIGHT_YEAR, _COPYRIGHT_YEAR, [Version is release])
862 AC_SUBST(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR)
863 AC_SUBST(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR)
864 AC_SUBST(CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION)
865 AC_SUBST(CLIENT_VERSION_BUILD, _CLIENT_VERSION_BUILD)
866 AC_SUBST(CLIENT_VERSION_IS_RELEASE, _CLIENT_VERSION_IS_RELEASE)
867 AC_SUBST(COPYRIGHT_YEAR, _COPYRIGHT_YEAR)
868 AC_SUBST(BITCOIN_DAEMON_NAME)
869 AC_SUBST(BITCOIN_CLI_NAME)
870 AC_SUBST(BITCOIN_TX_NAME)
873 AC_SUBST(ERROR_CXXFLAGS)
874 AC_SUBST(SAN_CXXFLAGS)
875 AC_SUBST(SAN_LDFLAGS)
876 AC_SUBST(HARDENED_CXXFLAGS)
877 AC_SUBST(HARDENED_CPPFLAGS)
878 AC_SUBST(HARDENED_LDFLAGS)
881 AC_SUBST(LIBTOOL_APP_LDFLAGS)
884 AC_SUBST(LEVELDB_TARGET_FLAGS)
885 AC_SUBST(CRYPTO_LIBS)
888 AC_SUBST(EVENT_PTHREADS_LIBS)
892 AC_SUBST(LIBSNARK_DEPINST)
893 AC_SUBST(LIBZCASH_LIBS)
894 AC_SUBST(PROTON_LIBS)
895 AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile src/test/buildenv.py])
896 AC_CONFIG_FILES([qa/pull-tester/run-bitcoind-for-test.sh],[chmod +x qa/pull-tester/run-bitcoind-for-test.sh])
897 AC_CONFIG_FILES([qa/pull-tester/tests-config.sh],[chmod +x qa/pull-tester/tests-config.sh])
899 dnl boost's m4 checks do something really nasty: they export these vars. As a
900 dnl result, they leak into secp256k1's configure and crazy things happen.
901 dnl Until this is fixed upstream and we've synced, we'll just un-export them.
902 CPPFLAGS_TEMP="$CPPFLAGS"
904 CPPFLAGS="$CPPFLAGS_TEMP"
906 LDFLAGS_TEMP="$LDFLAGS"
908 LDFLAGS="$LDFLAGS_TEMP"
914 PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH"
915 unset PKG_CONFIG_PATH
916 PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"
918 PKGCONFIG_LIBDIR_TEMP="$PKG_CONFIG_LIBDIR"
919 unset PKG_CONFIG_LIBDIR
920 PKG_CONFIG_LIBDIR="$PKGCONFIG_LIBDIR_TEMP"
922 ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no --enable-module-recovery"
923 AC_CONFIG_SUBDIRS([src/secp256k1 src/snark src/univalue])
927 dnl Taken from https://wiki.debian.org/RpathIssue
930 AC_MSG_RESULT([Fixing libtool for -rpath problems.])
931 sed < libtool > libtool-2 \
932 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_IS_A_FOOL__ "/'
939 echo "Options used to compile and link:"
940 echo " with wallet = $enable_wallet"
941 echo " with proton = $use_proton"
942 echo " with zmq = $use_zmq"
943 echo " with test = $use_tests"
944 echo " debug enabled = $enable_debug"
945 echo " werror = $enable_werror"
947 echo " target os = $TARGET_OS"
948 echo " build os = $BUILD_OS"
951 echo " CFLAGS = $CFLAGS"
952 echo " CPPFLAGS = $CPPFLAGS"
954 echo " CXXFLAGS = $CXXFLAGS"
955 echo " LDFLAGS = $LDFLAGS"
956 echo " ARFLAGS = $ARFLAGS"