diff --git a/.appveyor.yml b/.appveyor.yml
new file mode 100644
index 0000000000..8c27d9d5ef
--- /dev/null
+++ b/.appveyor.yml
@@ -0,0 +1,46 @@
+version: '{branch}.{build}'
+skip_tags: true
+image: Visual Studio 2017
+configuration: Release
+platform: x64
+clone_depth: 5
+environment:
+ APPVEYOR_SAVE_CACHE_ON_ERROR: true
+ CLCACHE_SERVER: 1
+ PACKAGES: berkeleydb boost-filesystem boost-signals2 boost-test libevent openssl rapidcheck zeromq
+ PATH: 'C:\Python37-x64;C:\Python37-x64\Scripts;%PATH%'
+ PYTHONUTF8: 1
+cache:
+- C:\tools\vcpkg\installed -> .appveyor.yml
+- C:\Users\appveyor\clcache -> .appveyor.yml, build_msvc\**, **\Makefile.am, **\*.vcxproj.in
+install:
+- cmd: pip install --quiet git+https://github.com/frerich/clcache.git@v4.2.0
+# Disable zmq test for now since python zmq library on Windows would cause Access violation sometimes.
+# - cmd: pip install zmq
+- cmd: echo set(VCPKG_BUILD_TYPE release) >> C:\tools\vcpkg\triplets\%PLATFORM%-windows-static.cmake
+- cmd: vcpkg remove --outdated --recurse
+- cmd: vcpkg install --triplet %PLATFORM%-windows-static %PACKAGES% > NUL
+before_build:
+- ps: clcache -M 536870912
+- cmd: python build_msvc\msvc-autogen.py
+- ps: $files = (Get-ChildItem -Recurse | where {$_.extension -eq ".vcxproj"}).FullName
+- ps: for (${i} = 0; ${i} -lt ${files}.length; ${i}++) {
+ ${content} = (Get-Content ${files}[${i}]);
+ ${content} = ${content}.Replace("", "None");
+ ${content} = ${content}.Replace("true", "false");
+ Set-Content ${files}[${i}] ${content};
+ }
+- ps: Start-Process clcache-server
+- ps: fsutil behavior set disablelastaccess 0 # Enable Access time feature on Windows (for clcache)
+build_script:
+- cmd: msbuild /p:TrackFileAccess=false /p:CLToolExe=clcache.exe build_msvc\defi.sln /m /v:n /nologo
+after_build:
+- ps: fsutil behavior set disablelastaccess 1 # Disable Access time feature on Windows (better performance)
+- ps: clcache -z
+test_script:
+- cmd: src\test_bitcoin.exe -k stdout -e stdout 2> NUL
+- cmd: src\bench_bitcoin.exe -evals=1 -scaling=0 > NUL
+- ps: python test\util\bitcoin-util-test.py
+- cmd: python test\util\rpcauth-test.py
+- cmd: python test\functional\test_runner.py --ci --quiet --combinedlogslen=4000 --failfast
+deploy: off
diff --git a/.cirrus.yml b/.cirrus.yml
new file mode 100644
index 0000000000..1e6e6937da
--- /dev/null
+++ b/.cirrus.yml
@@ -0,0 +1,53 @@
+task:
+ name: "FreeBsd 12.0 amd64 [GOAL: install] [no depends, only system libs]"
+ freebsd_instance:
+ image: freebsd-12-0-release-amd64
+ cpu: 8
+ memory: 8G
+ timeout_in: 60m
+ env:
+ MAKEJOBS: "-j9"
+ CONFIGURE_OPTS: "--disable-dependency-tracking"
+ GOAL: "install"
+ CCACHE_SIZE: "200M"
+ CCACHE_COMPRESS: 1
+ CCACHE_DIR: "/tmp/ccache_dir"
+ ccache_cache:
+ folder: "/tmp/ccache_dir"
+ install_script:
+ - pkg install -y autoconf automake boost-libs git gmake libevent libtool openssl pkgconf python3 ccache
+ - ./contrib/install_db4.sh $(pwd)
+ - ccache --max-size=${CCACHE_SIZE}
+ configure_script:
+ - ./autogen.sh
+ - ./configure ${CONFIGURE_OPTS} BDB_LIBS="-L$(pwd)/db4/lib -ldb_cxx-4.8" BDB_CFLAGS="-I$(pwd)/db4/include" || ( cat config.log && false)
+ make_script:
+ - gmake ${MAKEJOBS} ${GOAL} || ( echo "Build failure. Verbose build follows." && gmake ${GOAL} V=1 ; false )
+ check_script:
+ - gmake check ${MAKEJOBS} VERBOSE=1
+ functional_test_script:
+ - ./test/functional/test_runner.py --jobs 9 --ci --extended --exclude feature_dbcrash --combinedlogslen=1000 --quiet --failfast
+task:
+ name: "x86_64 Linux [GOAL: install] [bionic] [Using ./ci/ system]"
+ container:
+ image: ubuntu:18.04
+ cpu: 8
+ memory: 8G
+ timeout_in: 60m
+ env:
+ MAKEJOBS: "-j9"
+ RUN_CI_ON_HOST: "1"
+ CCACHE_SIZE: "200M"
+ CCACHE_DIR: "/tmp/ccache_dir"
+ ccache_cache:
+ folder: "/tmp/ccache_dir"
+ depends_built_cache:
+ folder: "/tmp/cirrus-ci-build/depends/built"
+ depends_sdk_cache:
+ folder: "/tmp/cirrus-ci-build/depends/sdk-sources"
+ install_script:
+ - apt-get update
+ - apt-get -y install git bash ccache
+ - ccache --max-size=${CCACHE_SIZE}
+ ci_script:
+ - ./ci/test_run_all.sh
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000000..ee34820dd4
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,164 @@
+.github
+contrib/dockerfiles
+
+# depends
+
+depends/built
+depends/work
+depends/sources
+depends/x86_64*
+depends/i686*
+depends/mips*
+depends/arm*
+depends/aarch64*
+depends/riscv32*
+depends/riscv64*
+
+## Copy of .gitignore
+
+.code
+.idea
+build
+
+*.tar.gz
+
+*.exe
+*.pdb
+src/defi
+src/defid
+src/defi-cli
+src/defi-tx
+src/defi-wallet
+src/test/test_defi
+src/test/test_defi_fuzzy
+src/qt/test/test_defi-qt
+
+# autoreconf
+Makefile.in
+aclocal.m4
+autom4te.cache/
+build-aux/config.guess
+build-aux/config.sub
+build-aux/depcomp
+build-aux/install-sh
+build-aux/ltmain.sh
+build-aux/m4/libtool.m4
+build-aux/m4/lt~obsolete.m4
+build-aux/m4/ltoptions.m4
+build-aux/m4/ltsugar.m4
+build-aux/m4/ltversion.m4
+build-aux/missing
+build-aux/compile
+build-aux/test-driver
+config.log
+config.status
+configure
+libtool
+src/config/defi-config.h
+src/config/defi-config.h.in
+src/config/stamp-h1
+src/obj
+share/setup.nsi
+share/qt/Info.plist
+
+src/univalue/gen
+
+src/qt/*.moc
+src/qt/moc_*.cpp
+src/qt/forms/ui_*.h
+
+src/qt/test/moc*.cpp
+
+src/qt/defi-qt.config
+src/qt/defi-qt.creator
+src/qt/defi-qt.creator.user
+src/qt/defi-qt.files
+src/qt/defi-qt.includes
+
+.deps
+.dirstamp
+.libs
+.*.swp
+*.*~*
+*.bak
+*.rej
+*.orig
+*.pyc
+*.o
+*.o-*
+*.a
+*.pb.cc
+*.pb.h
+*.dat
+
+*.log
+*.trs
+*.dmg
+
+*.json.h
+*.raw.h
+
+# Only ignore unexpected patches
+*.patch
+!depends/patches/**/*.patch
+
+#libtool object files
+*.lo
+*.la
+
+# Compilation and Qt preprocessor part
+*.qm
+Makefile
+!depends/Makefile
+defi-qt
+Defi-Qt.app
+background.tiff*
+
+# Qt Creator
+Makefile.am.user
+
+# Unit-tests
+Makefile.test
+defi-qt_test
+
+# Resources cpp
+qrc_*.cpp
+
+# Mac specific
+.DS_Store
+build
+
+#lcov
+*.gcno
+*.gcda
+/*.info
+test_defi.coverage/
+total.coverage/
+coverage_percent.txt
+
+#build tests
+linux-coverage-build
+linux-build
+win32-build
+test/config.ini
+test/cache/*
+
+!src/leveldb*/Makefile
+
+/doc/doxygen/
+
+libdeficonsensus.pc
+contrib/devtools/split-debug.sh
+
+# Output from running db4 installation
+db4/
+
+# clang-check
+*.plist
+
+osx_volname
+dist/
+*.background.tiff
+
+# spv
+!src/spv/Makefile
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000000..c9cf4a7d9c
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+src/clientversion.cpp export-subst
diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md
new file mode 100644
index 0000000000..958dff7b94
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE.md
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 0000000000..bf94531cd8
--- /dev/null
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,31 @@
+Pull requests without a rationale and clear improvement may be closed
+immediately.
+
+Please provide clear motivation for your patch and explain how it improves
+DeFi Blockchain user experience or the DeFi Blockchain developer experience
+significantly.
+
+* Any test improvements or new tests that improve coverage are always welcome.
+* All other changes should have accompanying unit tests (see `src/test/`) or
+ functional tests (see `test/`). Contributors should note which tests cover
+ modified code. If no tests exist for a region of modified code, new tests
+ should accompany the change.
+* Bug fixes are most welcome when they come with steps to reproduce or an
+ explanation of the potential issue as well as reasoning for the way the bug
+ was fixed.
+* Features are welcome, but might be rejected due to design or scope issues.
+ If a feature is based on a lot of dependencies, contributors should first
+ consider building the system outside of DeFi Blockchain, if possible.
+* Refactoring changes are only accepted if they are required for a feature or
+ bug fix or otherwise improve developer experience significantly. For example,
+ most "code style" refactoring changes require a thorough explanation why they
+ are useful, what downsides they have and why they *significantly* improve
+ developer experience or avoid serious programming bugs. Note that code style
+ is often a subjective matter. Unless they are explicitly mentioned to be
+ preferred in the [developer notes](/doc/developer-notes.md), stylistic code
+ changes are usually rejected.
+
+DeFi Blockchain has a thorough review process and even the most trivial change
+needs to pass a lot of eyes and requires non-zero or even substantial time
+effort to review. There is a huge lack of active reviewers on the project, so
+patches often sit for a long time.
diff --git a/.github/workflows/dev-builds.yaml b/.github/workflows/dev-builds.yaml
new file mode 100644
index 0000000000..337b649868
--- /dev/null
+++ b/.github/workflows/dev-builds.yaml
@@ -0,0 +1,72 @@
+on:
+ push:
+ tags:
+ - "!v*"
+ branches:
+ - master
+ - staging
+ - develop
+ - ci/*
+ pull_request:
+ branches:
+ - master
+ - develop
+ - staging
+ - ci/*
+jobs:
+
+ linux:
+ # We use a matrix since it's easier to migrate upwards, add new
+ # test on multiple, then remove old without creating friction.
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-18.04]
+ env:
+ BUILD_VERSION: latest # Computed
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Build and package
+ run: TARGETS="x86_64-pc-linux-gnu" ./make.sh docker-release-git
+ - name: Publish artifact - x86_64-pc-linux-gnu
+ uses: actions/upload-artifact@v2-preview
+ with:
+ name: defichain-${{ env.BUILD_VERSION }}-x86_64-pc-linux-gnu
+ path: ./build/defichain-${{ env.BUILD_VERSION }}-x86_64-pc-linux-gnu.tar.gz
+
+ windows:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-18.04]
+ env:
+ BUILD_VERSION: latest # Computed
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Build and package
+ run: TARGETS="x86_64-w64-mingw32" ./make.sh docker-release-git
+ - name: Publish artifact - x86_64-w64-mingw32
+ uses: actions/upload-artifact@v2-preview
+ with:
+ name: defichain-${{ env.BUILD_VERSION }}-x86_64-w64-mingw32
+ path: ./build/defichain-${{ env.BUILD_VERSION }}-x86_64-w64-mingw32.tar.gz
+
+ macos:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-18.04]
+ env:
+ BUILD_VERSION: latest # Computed
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Build and package
+ run: TARGETS="x86_64-apple-darwin11" ./make.sh docker-release-git
+ - name: Publish artifact - x86_64-apple-darwin11
+ uses: actions/upload-artifact@v2-preview
+ with:
+ name: defichain-${{ env.BUILD_VERSION }}-x86_64-apple-darwin11
+ path: ./build/defichain-${{ env.BUILD_VERSION }}-x86_64-apple-darwin11.tar.gz
diff --git a/.github/workflows/prune-artifacts.yaml b/.github/workflows/prune-artifacts.yaml
new file mode 100644
index 0000000000..b6c70c5ad8
--- /dev/null
+++ b/.github/workflows/prune-artifacts.yaml
@@ -0,0 +1,21 @@
+# This is a script to remove all artifacts every month. By default it's 3 months, I think.
+# This may be removed in the future when we don't have so many builds which could end up
+# filling up the storage space
+
+on:
+ schedule:
+ # Every day at 1am
+ - cron: '0 1 * * *'
+
+jobs:
+ cleanup:
+ runs-on: ubuntu-18.04
+ timeout-minutes: 10
+
+ steps:
+ - name: Prune artifacts
+ uses: c-hive/gha-remove-artifacts@v1
+ with:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ age: '4 weeks'
+ skip-tags: true
diff --git a/.github/workflows/release-builds.yaml b/.github/workflows/release-builds.yaml
new file mode 100644
index 0000000000..758f293b70
--- /dev/null
+++ b/.github/workflows/release-builds.yaml
@@ -0,0 +1,149 @@
+on:
+ push:
+ tags:
+ - "v*"
+jobs:
+
+ linux:
+ runs-on: ubuntu-18.04
+ env:
+ BUILD_VERSION: latest # Computed
+ if: startsWith(github.ref, 'refs/tags/')
+
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: Build and package
+ run: ./make.sh docker-release-git
+
+ - name: Publish artifacts
+ uses: actions/upload-artifact@v2-preview
+ with:
+ name: defichain-${{ env.BUILD_VERSION }}-x86_64-pc-linux-gnu
+ path: ./build/defichain-${{ env.BUILD_VERSION }}-x86_64-pc-linux-gnu.tar.gz
+
+ # Linux build additionally pushes the docker images to docker hub on successful build
+ - name: Tag dockerhub build
+ if: ${{ github.repository == 'DeFiCh/ain' }}
+ run: >
+ docker tag defichain-x86_64-pc-linux-gnu:${{ env.BUILD_VERSION }}
+ defichain-x86_64-pc-linux-gnu:dockerhub-latest
+
+ - uses: docker/build-push-action@v1
+ # Make sure to only build on ain repo. Also add in additional restrictions here if needed to
+ # make sure we don't push unnecessary images to docker
+ if: ${{ github.repository == 'DeFiCh/ain' }}
+ with:
+ username: ${{ secrets.DOCKER_HUB_USER }}
+ password: ${{ secrets.DOCKER_HUB_TOKEN }}
+ path: ./contrib/dockerfiles/dockerhub
+ dockerfile: ./contrib/dockerfiles/dockerhub/x86_64-pc-linux-gnu.dockerfile
+ repository: defi/defichain
+ tags: latest,${{ env.BUILD_VERSION }}
+
+ windows:
+ runs-on: ubuntu-18.04
+ env:
+ BUILD_VERSION: latest # Computed
+ if: startsWith(github.ref, 'refs/tags/')
+
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: Build and package
+ run: TARGETS="x86_64-w64-mingw32" ./make.sh docker-release-git
+
+ - name: Publish artifact - x86_64-w64-mingw32
+ uses: actions/upload-artifact@v2-preview
+ with:
+ name: defichain-${{ env.BUILD_VERSION }}-x86_64-w64-mingw32
+ path: ./build/defichain-${{ env.BUILD_VERSION }}-x86_64-w64-mingw32.tar.gz
+
+ macos:
+ runs-on: ubuntu-18.04
+ env:
+ BUILD_VERSION: latest # Computed
+ if: startsWith(github.ref, 'refs/tags/')
+
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: Build and package
+ run: TARGETS="x86_64-apple-darwin11" ./make.sh docker-release-git
+
+ - name: Publish artifact - x86_64-apple-darwin11
+ uses: actions/upload-artifact@v2-preview
+ with:
+ name: defichain-${{ env.BUILD_VERSION }}-x86_64-apple-darwin11
+ path: ./build/defichain-${{ env.BUILD_VERSION }}-x86_64-apple-darwin11.tar.gz
+
+ create-release:
+ needs:
+ - linux
+ - windows
+ - macos
+ runs-on: ubuntu-18.04
+ env:
+ BUILD_VERSION: latest # Computed
+ if: startsWith(github.ref, 'refs/tags/')
+
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: compute build version
+ run: ./make.sh git-version
+
+ - name: cleanup work dir
+ run: rm -rf *
+
+ - name: get all build artifacts
+ uses: actions/download-artifact@v2
+
+ - name: zip package for windows
+ run: |
+ set -e
+ cd defichain-${{ env.BUILD_VERSION }}-x86_64-w64-mingw32
+ tar xzf defichain-${{ env.BUILD_VERSION }}-x86_64-w64-mingw32.tar.gz
+ zip -r "defichain-${{ env.BUILD_VERSION }}-x86_64-w64-mingw32.zip" \
+ defichain-${{ env.BUILD_VERSION }}/
+
+ - name: Create release
+ id: create_release
+ uses: actions/create-release@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ tag_name: ${{ github.ref }}
+ release_name: ${{ github.ref }}
+ draft: false
+ prerelease: false
+
+ - name: Upload release asset - linux
+ uses: actions/upload-release-asset@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ upload_url: ${{ steps.create_release.outputs.upload_url }}
+ asset_path: ./defichain-${{ env.BUILD_VERSION }}-x86_64-pc-linux-gnu/defichain-${{ env.BUILD_VERSION }}-x86_64-pc-linux-gnu.tar.gz
+ asset_name: defichain-${{ env.BUILD_VERSION }}-x86_64-pc-linux-gnu.tar.gz
+ asset_content_type: application/gzip
+
+ - name: Upload release asset - windows
+ uses: actions/upload-release-asset@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ upload_url: ${{ steps.create_release.outputs.upload_url }}
+ asset_path: ./defichain-${{ env.BUILD_VERSION }}-x86_64-w64-mingw32/defichain-${{ env.BUILD_VERSION }}-x86_64-w64-mingw32.zip
+ asset_name: defichain-${{ env.BUILD_VERSION }}-x86_64-w64-mingw32.zip
+ asset_content_type: application/zip
+
+ - name: Upload release asset - macos
+ uses: actions/upload-release-asset@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ upload_url: ${{ steps.create_release.outputs.upload_url }}
+ asset_path: ./defichain-${{ env.BUILD_VERSION }}-x86_64-apple-darwin11/defichain-${{ env.BUILD_VERSION }}-x86_64-apple-darwin11.tar.gz
+ asset_name: defichain-${{ env.BUILD_VERSION }}-x86_64-apple-darwin11.tar.gz
+ asset_content_type: application/gzip
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 55d325aeef..a81dfb7026 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,38 +1,24 @@
-bench_inv
-bench_ecdh
-bench_ecmult
-bench_sign
-bench_verify
-bench_schnorr_verify
-bench_recover
-bench_internal
-tests
-exhaustive_tests
-gen_context
+.code
+.idea
+build
+
+*.tar.gz
+
*.exe
-*.so
-*.a
-!.gitignore
+*.pdb
+src/defi
+src/defid
+src/defi-cli
+src/defi-tx
+src/defi-wallet
+src/test/test_defi
+src/test/test_defi_fuzzy
+src/qt/test/test_defi-qt
-Makefile
-configure
-.libs/
+# autoreconf
Makefile.in
aclocal.m4
autom4te.cache/
-config.log
-config.status
-*.tar.gz
-*.la
-libtool
-.deps/
-.dirstamp
-*.lo
-*.o
-*~
-src/libsecp256k1-config.h
-src/libsecp256k1-config.h.in
-src/ecmult_static_context.h
build-aux/config.guess
build-aux/config.sub
build-aux/depcomp
@@ -46,5 +32,115 @@ build-aux/m4/ltversion.m4
build-aux/missing
build-aux/compile
build-aux/test-driver
-src/stamp-h1
-libsecp256k1.pc
+config.log
+config.status
+configure
+libtool
+src/config/defi-config.h
+src/config/defi-config.h.in
+src/config/stamp-h1
+src/obj
+share/setup.nsi
+share/qt/Info.plist
+
+src/univalue/gen
+
+src/qt/*.moc
+src/qt/moc_*.cpp
+src/qt/forms/ui_*.h
+
+src/qt/test/moc*.cpp
+
+src/qt/defi-qt.config
+src/qt/defi-qt.creator
+src/qt/defi-qt.creator.user
+src/qt/defi-qt.files
+src/qt/defi-qt.includes
+
+.deps
+.dirstamp
+.libs
+.*.swp
+*.*~*
+*.bak
+*.rej
+*.orig
+*.pyc
+*.o
+*.o-*
+*.a
+*.pb.cc
+*.pb.h
+*.dat
+
+*.log
+*.trs
+*.dmg
+
+*.json.h
+*.raw.h
+
+# Only ignore unexpected patches
+*.patch
+!depends/patches/**/*.patch
+
+#libtool object files
+*.lo
+*.la
+
+# Compilation and Qt preprocessor part
+*.qm
+Makefile
+!depends/Makefile
+defi-qt
+Defi-Qt.app
+background.tiff*
+
+# Qt Creator
+Makefile.am.user
+
+# Unit-tests
+Makefile.test
+defi-qt_test
+
+# Resources cpp
+qrc_*.cpp
+
+# Mac specific
+.DS_Store
+build
+
+#lcov
+*.gcno
+*.gcda
+/*.info
+test_defi.coverage/
+total.coverage/
+coverage_percent.txt
+
+#build tests
+linux-coverage-build
+linux-build
+win32-build
+test/config.ini
+test/cache/*
+
+!src/leveldb*/Makefile
+
+/doc/doxygen/
+
+libdeficonsensus.pc
+contrib/devtools/split-debug.sh
+
+# Output from running db4 installation
+db4/
+
+# clang-check
+*.plist
+
+osx_volname
+dist/
+*.background.tiff
+
+# spv
+!src/spv/Makefile
\ No newline at end of file
diff --git a/.python-version b/.python-version
new file mode 100644
index 0000000000..c49282585a
--- /dev/null
+++ b/.python-version
@@ -0,0 +1 @@
+3.5.6
diff --git a/.style.yapf b/.style.yapf
new file mode 100644
index 0000000000..69d8c6aee4
--- /dev/null
+++ b/.style.yapf
@@ -0,0 +1,261 @@
+[style]
+# Align closing bracket with visual indentation.
+align_closing_bracket_with_visual_indent=True
+
+# Allow dictionary keys to exist on multiple lines. For example:
+#
+# x = {
+# ('this is the first element of a tuple',
+# 'this is the second element of a tuple'):
+# value,
+# }
+allow_multiline_dictionary_keys=False
+
+# Allow lambdas to be formatted on more than one line.
+allow_multiline_lambdas=False
+
+# Allow splits before the dictionary value.
+allow_split_before_dict_value=True
+
+# Number of blank lines surrounding top-level function and class
+# definitions.
+blank_lines_around_top_level_definition=2
+
+# Insert a blank line before a class-level docstring.
+blank_line_before_class_docstring=False
+
+# Insert a blank line before a module docstring.
+blank_line_before_module_docstring=False
+
+# Insert a blank line before a 'def' or 'class' immediately nested
+# within another 'def' or 'class'. For example:
+#
+# class Foo:
+# # <------ this blank line
+# def method():
+# ...
+blank_line_before_nested_class_or_def=False
+
+# Do not split consecutive brackets. Only relevant when
+# dedent_closing_brackets is set. For example:
+#
+# call_func_that_takes_a_dict(
+# {
+# 'key1': 'value1',
+# 'key2': 'value2',
+# }
+# )
+#
+# would reformat to:
+#
+# call_func_that_takes_a_dict({
+# 'key1': 'value1',
+# 'key2': 'value2',
+# })
+coalesce_brackets=False
+
+# The column limit.
+column_limit=160
+
+# The style for continuation alignment. Possible values are:
+#
+# - SPACE: Use spaces for continuation alignment. This is default behavior.
+# - FIXED: Use fixed number (CONTINUATION_INDENT_WIDTH) of columns
+# (ie: CONTINUATION_INDENT_WIDTH/INDENT_WIDTH tabs) for continuation
+# alignment.
+# - LESS: Slightly left if cannot vertically align continuation lines with
+# indent characters.
+# - VALIGN-RIGHT: Vertically align continuation lines with indent
+# characters. Slightly right (one more indent character) if cannot
+# vertically align continuation lines with indent characters.
+#
+# For options FIXED, and VALIGN-RIGHT are only available when USE_TABS is
+# enabled.
+continuation_align_style=SPACE
+
+# Indent width used for line continuations.
+continuation_indent_width=4
+
+# Put closing brackets on a separate line, dedented, if the bracketed
+# expression can't fit in a single line. Applies to all kinds of brackets,
+# including function definitions and calls. For example:
+#
+# config = {
+# 'key1': 'value1',
+# 'key2': 'value2',
+# } # <--- this bracket is dedented and on a separate line
+#
+# time_series = self.remote_client.query_entity_counters(
+# entity='dev3246.region1',
+# key='dns.query_latency_tcp',
+# transform=Transformation.AVERAGE(window=timedelta(seconds=60)),
+# start_ts=now()-timedelta(days=3),
+# end_ts=now(),
+# ) # <--- this bracket is dedented and on a separate line
+dedent_closing_brackets=False
+
+# Disable the heuristic which places each list element on a separate line
+# if the list is comma-terminated.
+disable_ending_comma_heuristic=False
+
+# Place each dictionary entry onto its own line.
+each_dict_entry_on_separate_line=True
+
+# The regex for an i18n comment. The presence of this comment stops
+# reformatting of that line, because the comments are required to be
+# next to the string they translate.
+i18n_comment=
+
+# The i18n function call names. The presence of this function stops
+# reformattting on that line, because the string it has cannot be moved
+# away from the i18n comment.
+i18n_function_call=
+
+# Indent the dictionary value if it cannot fit on the same line as the
+# dictionary key. For example:
+#
+# config = {
+# 'key1':
+# 'value1',
+# 'key2': value1 +
+# value2,
+# }
+indent_dictionary_value=False
+
+# The number of columns to use for indentation.
+indent_width=4
+
+# Join short lines into one line. E.g., single line 'if' statements.
+join_multiple_lines=True
+
+# Do not include spaces around selected binary operators. For example:
+#
+# 1 + 2 * 3 - 4 / 5
+#
+# will be formatted as follows when configured with "*,/":
+#
+# 1 + 2*3 - 4/5
+#
+no_spaces_around_selected_binary_operators=
+
+# Use spaces around default or named assigns.
+spaces_around_default_or_named_assign=False
+
+# Use spaces around the power operator.
+spaces_around_power_operator=False
+
+# The number of spaces required before a trailing comment.
+spaces_before_comment=2
+
+# Insert a space between the ending comma and closing bracket of a list,
+# etc.
+space_between_ending_comma_and_closing_bracket=True
+
+# Split before arguments
+split_all_comma_separated_values=False
+
+# Split before arguments if the argument list is terminated by a
+# comma.
+split_arguments_when_comma_terminated=False
+
+# Set to True to prefer splitting before '&', '|' or '^' rather than
+# after.
+split_before_bitwise_operator=True
+
+# Split before the closing bracket if a list or dict literal doesn't fit on
+# a single line.
+split_before_closing_bracket=True
+
+# Split before a dictionary or set generator (comp_for). For example, note
+# the split before the 'for':
+#
+# foo = {
+# variable: 'Hello world, have a nice day!'
+# for variable in bar if variable != 42
+# }
+split_before_dict_set_generator=True
+
+# Split before the '.' if we need to split a longer expression:
+#
+# foo = ('This is a really long string: {}, {}, {}, {}'.format(a, b, c, d))
+#
+# would reformat to something like:
+#
+# foo = ('This is a really long string: {}, {}, {}, {}'
+# .format(a, b, c, d))
+split_before_dot=False
+
+# Split after the opening paren which surrounds an expression if it doesn't
+# fit on a single line.
+split_before_expression_after_opening_paren=False
+
+# If an argument / parameter list is going to be split, then split before
+# the first argument.
+split_before_first_argument=False
+
+# Set to True to prefer splitting before 'and' or 'or' rather than
+# after.
+split_before_logical_operator=True
+
+# Split named assignments onto individual lines.
+split_before_named_assigns=True
+
+# Set to True to split list comprehensions and generators that have
+# non-trivial expressions and multiple clauses before each of these
+# clauses. For example:
+#
+# result = [
+# a_long_var + 100 for a_long_var in xrange(1000)
+# if a_long_var % 10]
+#
+# would reformat to something like:
+#
+# result = [
+# a_long_var + 100
+# for a_long_var in xrange(1000)
+# if a_long_var % 10]
+split_complex_comprehension=False
+
+# The penalty for splitting right after the opening bracket.
+split_penalty_after_opening_bracket=30
+
+# The penalty for splitting the line after a unary operator.
+split_penalty_after_unary_operator=10000
+
+# The penalty for splitting right before an if expression.
+split_penalty_before_if_expr=0
+
+# The penalty of splitting the line around the '&', '|', and '^'
+# operators.
+split_penalty_bitwise_operator=300
+
+# The penalty for splitting a list comprehension or generator
+# expression.
+split_penalty_comprehension=80
+
+# The penalty for characters over the column limit.
+split_penalty_excess_character=7000
+
+# The penalty incurred by adding a line split to the unwrapped line. The
+# more line splits added the higher the penalty.
+split_penalty_for_added_line_split=30
+
+# The penalty of splitting a list of "import as" names. For example:
+#
+# from a_very_long_or_indented_module_name_yada_yad import (long_argument_1,
+# long_argument_2,
+# long_argument_3)
+#
+# would reformat to something like:
+#
+# from a_very_long_or_indented_module_name_yada_yad import (
+# long_argument_1, long_argument_2, long_argument_3)
+split_penalty_import_names=0
+
+# The penalty of splitting the line around the 'and' and 'or'
+# operators.
+split_penalty_logical_operator=300
+
+# Use the Tab character for indentation.
+use_tabs=False
+
diff --git a/.travis.yml b/.travis.yml
index 74f658f4d1..d37cdd4a94 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,68 +1,137 @@
-language: c
+# The test build matrix (stage: test) is constructed to test a wide range of
+# configurations, rather than a single pass/fail. This helps to catch build
+# failures and logic errors that present on platforms other than the ones the
+# author has tested.
+#
+# Some builders use the dependency-generator in `./depends`, rather than using
+# apt-get to install build dependencies. This guarantees that the tester is
+# using the same versions as Gitian, so the build results are nearly identical
+# to what would be found in a final release.
+#
+# In order to avoid rebuilding all dependencies for each build, the binaries
+# are cached and re-used when possible. Changes in the dependency-generator
+# will trigger cache-invalidation and rebuilds as necessary.
+#
+# These caches can be manually removed if necessary. This is one of the very
+# few manual operations that is possible with Travis, and it can be done by a
+# DeFi Foundation GitHub member via the Travis web interface [0].
+#
+# Travis CI uploads the cache after the script phase of the build [1].
+# However, the build is terminated without saving the cache if it takes over
+# 50 minutes [2]. Thus, if we spent too much time in early build stages, fail
+# with an error and save the cache.
+#
+# [0] https://travis-ci.org/defich/ain/caches
+# [1] https://docs.travis-ci.com/user/caching/#build-phases
+# [2] https://docs.travis-ci.com/user/customizing-the-build#build-timeouts
+
+dist: xenial
os: linux
-addons:
- apt:
- packages: libgmp-dev
-compiler:
- - clang
- - gcc
+language: minimal
cache:
+ ccache: true
directories:
- - src/java/guava/
+ - $TRAVIS_BUILD_DIR/depends/built
+ - $TRAVIS_BUILD_DIR/depends/sdk-sources
+ - $TRAVIS_BUILD_DIR/ci/scratch/.ccache
+stages:
+ - lint
+ - test
+ - extended-lint
env:
global:
- - FIELD=auto BIGNUM=auto SCALAR=auto ENDOMORPHISM=no STATICPRECOMPUTATION=yes ASM=no BUILD=check EXTRAFLAGS= HOST= ECDH=no RECOVERY=no EXPERIMENTAL=no JNI=no
- - GUAVA_URL=https://search.maven.org/remotecontent?filepath=com/google/guava/guava/18.0/guava-18.0.jar GUAVA_JAR=src/java/guava/guava-18.0.jar
- matrix:
- - SCALAR=32bit RECOVERY=yes
- - SCALAR=32bit FIELD=32bit ECDH=yes EXPERIMENTAL=yes
- - SCALAR=64bit
- - FIELD=64bit RECOVERY=yes
- - FIELD=64bit ENDOMORPHISM=yes
- - FIELD=64bit ENDOMORPHISM=yes ECDH=yes EXPERIMENTAL=yes
- - FIELD=64bit ASM=x86_64
- - FIELD=64bit ENDOMORPHISM=yes ASM=x86_64
- - FIELD=32bit ENDOMORPHISM=yes
- - BIGNUM=no
- - BIGNUM=no ENDOMORPHISM=yes RECOVERY=yes EXPERIMENTAL=yes
- - BIGNUM=no STATICPRECOMPUTATION=no
- - BUILD=distcheck
- - EXTRAFLAGS=CPPFLAGS=-DDETERMINISTIC
- - EXTRAFLAGS=CFLAGS=-O0
- - BUILD=check-java JNI=yes ECDH=yes EXPERIMENTAL=yes
-matrix:
- fast_finish: true
- include:
- - compiler: clang
- env: HOST=i686-linux-gnu ENDOMORPHISM=yes
- addons:
- apt:
- packages:
- - gcc-multilib
- - libgmp-dev:i386
- - compiler: clang
- env: HOST=i686-linux-gnu
- addons:
- apt:
- packages:
- - gcc-multilib
- - compiler: gcc
- env: HOST=i686-linux-gnu ENDOMORPHISM=yes
- addons:
- apt:
- packages:
- - gcc-multilib
- - compiler: gcc
- env: HOST=i686-linux-gnu
- addons:
- apt:
- packages:
- - gcc-multilib
- - libgmp-dev:i386
-before_install: mkdir -p `dirname $GUAVA_JAR`
-install: if [ ! -f $GUAVA_JAR ]; then wget $GUAVA_URL -O $GUAVA_JAR; fi
-before_script: ./autogen.sh
+ - CI_RETRY_EXE="travis_retry"
+ - CACHE_ERR_MSG="Error! Initial build successful, but not enough time remains to run later build stages and tests. Please manually re-run this job by using the travis restart button or asking a DeFi Blockchain maintainer to restart. The next run should not time out because the build cache has been saved."
+before_install:
+ - set -o errexit; source ./ci/test/00_setup_env.sh
+ - set -o errexit; source ./ci/test/03_before_install.sh
+install:
+ - set -o errexit; source ./ci/test/04_install.sh
+before_script:
+ - set -o errexit; source ./ci/test/05_before_script.sh
script:
- - if [ -n "$HOST" ]; then export USE_HOST="--host=$HOST"; fi
- - if [ "x$HOST" = "xi686-linux-gnu" ]; then export CC="$CC -m32"; fi
- - ./configure --enable-experimental=$EXPERIMENTAL --enable-endomorphism=$ENDOMORPHISM --with-field=$FIELD --with-bignum=$BIGNUM --with-scalar=$SCALAR --enable-ecmult-static-precomputation=$STATICPRECOMPUTATION --enable-module-ecdh=$ECDH --enable-module-recovery=$RECOVERY --enable-jni=$JNI $EXTRAFLAGS $USE_HOST && make -j2 $BUILD
+ - export CONTINUE=1
+ - if [ $SECONDS -gt 1200 ]; then export CONTINUE=0; fi # Likely the depends build took very long
+ - if [ $TRAVIS_REPO_SLUG = "defich/ain" ] || [ $TRAVIS_REPO_SLUG = "cakedefi/defichain" ]; then export CONTINUE=1; fi # Whitelisted repo (90 minutes build time)
+ - if [ $CONTINUE = "1" ]; then set -o errexit; source ./ci/test/06_script_a.sh; else set +o errexit; echo "$CACHE_ERR_MSG"; false; fi
+ - if [ $SECONDS -gt 2000 ]; then export CONTINUE=0; fi # Likely the build took very long; The tests take about 1000s, so we should abort if we have less than 50*60-1000=2000s left
+ - if [ $TRAVIS_REPO_SLUG = "defich/ain" ] || [ $TRAVIS_REPO_SLUG = "cakedefi/defichain" ]; then export CONTINUE=1; fi # Whitelisted repo (90 minutes build time)
+ - if [ $CONTINUE = "1" ]; then set -o errexit; source ./ci/test/06_script_b.sh; else set +o errexit; echo "$CACHE_ERR_MSG"; false; fi
+after_script:
+ - echo $TRAVIS_COMMIT_RANGE
+jobs:
+ include:
+
+ - stage: lint
+ name: 'lint'
+ cache: false
+ language: python
+ python: '3.5' # Oldest supported version according to doc/dependencies.md
+ install:
+ - set -o errexit; source ./ci/lint/04_install.sh
+ before_script:
+ - set -o errexit; source ./ci/lint/05_before_script.sh
+ script:
+ - set -o errexit; source ./ci/lint/06_script.sh
+
+ - stage: extended-lint
+ name: 'extended lint [runtime >= 60 seconds]'
+ cache: false
+ language: python
+ python: '3.5'
+ install:
+ - set -o errexit; source ./ci/extended_lint/04_install.sh
+ before_script:
+ - set -o errexit; source ./ci/lint/05_before_script.sh
+ script:
+ - set -o errexit; source ./ci/extended_lint/06_script.sh
+
+ # - stage: test
+ # name: 'ARM [GOAL: install] [no unit or functional tests]'
+ # env: >-
+ # FILE_ENV="./ci/test/00_setup_env_arm.sh"
+
+ # - stage: test
+ # name: 'Win64 [GOAL: deploy] [no gui or functional tests]'
+ # env: >-
+ # FILE_ENV="./ci/test/00_setup_env_win64.sh"
+
+ # - stage: test
+ # name: '32-bit + dash [GOAL: install] [GUI: no BIP70]'
+ # env: >-
+ # FILE_ENV="./ci/test/00_setup_env_i686.sh"
+
+ # - stage: test
+ # name: 'x86_64 Linux [GOAL: install] [bionic] [uses qt5 dev package instead of depends Qt to speed up build and avoid timeout] [unsigned char]'
+ # env: >-
+ # FILE_ENV="./ci/test/00_setup_env_amd64_qt5.sh"
+
+ # - stage: test
+ # name: 'x86_64 Linux [GOAL: install] [trusty] [no functional tests, no depends, only system libs]'
+ # env: >-
+ # FILE_ENV="./ci/test/00_setup_env_amd64_trusty.sh"
+
+ # - stage: test
+ # name: 'x86_64 Linux [GOAL: install] [xenial] [no depends, only system libs, sanitizers: thread (TSan), no wallet]'
+ # env: >-
+ # FILE_ENV="./ci/test/00_setup_env_amd64_tsan.sh"
+
+ - stage: test
+ name: 'x86_64 Linux [GOAL: install] [bionic] [no depends, only system libs, sanitizers: address/leak (ASan + LSan) + undefined (UBSan) + integer]'
+ env: >-
+ FILE_ENV="./ci/test/00_setup_env_amd64_asan.sh"
+
+ # - stage: test
+ # name: 'x86_64 Linux [GOAL: install] [bionic] [no depends, only system libs, sanitizers: fuzzer,address]'
+ # env: >-
+ # FILE_ENV="./ci/test/00_setup_env_amd64_fuzz.sh"
+
+ # - stage: test
+ # name: 'x86_64 Linux [GOAL: install] [bionic] [no wallet]'
+ # env: >-
+ # FILE_ENV="./ci/test/00_setup_env_amd64_nowallet.sh"
+
+ # - stage: test
+ # name: 'macOS 10.10 [GOAL: deploy] [no functional tests]'
+ # env: >-
+ # FILE_ENV="./ci/test/00_setup_env_mac.sh"
diff --git a/.tx/config b/.tx/config
new file mode 100644
index 0000000000..2ac26fef82
--- /dev/null
+++ b/.tx/config
@@ -0,0 +1,7 @@
+[main]
+host = https://www.transifex.com
+
+[defi.qt-translation-018x]
+file_filter = src/qt/locale/defi_.ts
+source_file = src/qt/locale/defi_en.ts
+source_lang = en
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000000..f99dfa7f83
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,305 @@
+Contributing to DeFi Blockchain
+============================
+
+The DeFi Blockchain project operates an open contributor model where anyone is
+welcome to contribute towards development in the form of peer review, testing
+and patches. This document explains the practical process and guidelines for
+contributing.
+
+Firstly in terms of structure, there is no particular concept of "Core
+developers" in the sense of privileged people. Open source often naturally
+revolves around meritocracy where longer term contributors gain more trust from
+the developer community. However, some hierarchy is necessary for practical
+purposes. As such there are repository "maintainers" who are responsible for
+merging pull requests as well as a "lead maintainer" who is responsible for the
+release cycle, overall merging, moderation and appointment of maintainers.
+
+If you're looking for somewhere to start contributing, check out the
+[good first issue](https://github.com/defich/ain/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22)
+list.
+
+
+Contributor Workflow
+--------------------
+
+The codebase is maintained using the "contributor workflow" where everyone
+without exception contributes patch proposals using "pull requests". This
+facilitates social contribution, easy testing and peer review.
+
+To contribute a patch, the workflow is as follows:
+
+ 1. Fork repository
+ 1. Create topic branch
+ 1. Commit patches
+
+The project coding conventions in the [developer notes](doc/developer-notes.md)
+must be adhered to.
+
+In general [commits should be atomic](https://en.wikipedia.org/wiki/Atomic_commit#Atomic_commit_convention)
+and diffs should be easy to read. For this reason do not mix any formatting
+fixes or code moves with actual code changes.
+
+Commit messages should be verbose by default consisting of a short subject line
+(50 chars max), a blank line and detailed explanatory text as separate
+paragraph(s), unless the title alone is self-explanatory (like "Corrected typo
+in init.cpp") in which case a single title line is sufficient. Commit messages should be
+helpful to people reading your code in the future, so explain the reasoning for
+your decisions. Further explanation [here](https://chris.beams.io/posts/git-commit/).
+
+If a particular commit references another issue, please add the reference. For
+example: `refs #1234` or `fixes #4321`. Using the `fixes` or `closes` keywords
+will cause the corresponding issue to be closed when the pull request is merged.
+
+Commit messages should never contain any `@` mentions.
+
+Please refer to the [Git manual](https://git-scm.com/doc) for more information
+about Git.
+
+ - Push changes to your fork
+ - Create pull request
+
+The title of the pull request should be prefixed by the component or area that
+the pull request affects. Valid areas as:
+
+ - `consensus` for changes to consensus critical code
+ - `doc` for changes to the documentation
+ - `qt` or `gui` for changes to defi-qt
+ - `log` for changes to log messages
+ - `mining` for changes to the mining code
+ - `net` or `p2p` for changes to the peer-to-peer network code
+ - `refactor` for structural changes that do not change behavior
+ - `rpc`, `rest` or `zmq` for changes to the RPC, REST or ZMQ APIs
+ - `script` for changes to the scripts and tools
+ - `test` for changes to DeFi Blockchain unit tests or QA tests
+ - `util` or `lib` for changes to the utils or libraries
+ - `wallet` for changes to the wallet code
+ - `build` for changes to the GNU Autotools, reproducible builds or CI code
+
+Examples:
+
+ consensus: Add new opcode for BIP-XXXX OP_CHECKAWESOMESIG
+ net: Automatically create hidden service, listen on Tor
+ qt: Add feed bump button
+ log: Fix typo in log message
+
+Note that translations should not be submitted as pull requests, please see
+[Translation Process](https://github.com/defich/ain/blob/master/doc/translation_process.md)
+for more information on helping with translations.
+
+If a pull request is not to be considered for merging (yet), please
+prefix the title with [WIP] or use [Tasks Lists](https://help.github.com/articles/basic-writing-and-formatting-syntax/#task-lists)
+in the body of the pull request to indicate tasks are pending.
+
+The body of the pull request should contain enough description about what the
+patch does together with any justification/reasoning. You should include
+references to any discussions (for example other tickets or mailing list
+discussions).
+
+At this stage one should expect comments and review from other contributors. You
+can add more commits to your pull request by committing them locally and pushing
+to your fork until you have satisfied all feedback.
+
+Note: Code review is a burdensome but important part of the development process, and as such, certain types of pull requests are rejected. In general, if the **improvements** do not warrant the **review effort** required, the PR has a high chance of being rejected. It is up to the PR author to convince the reviewers that the changes warrant the review effort, and if reviewers are "Concept NAK'ing" the PR, the author may need to present arguments and/or do research backing their suggested changes.
+
+Squashing Commits
+---------------------------
+If your pull request is accepted for merging, you may be asked by a maintainer
+to squash and or [rebase](https://git-scm.com/docs/git-rebase) your commits
+before it will be merged. The basic squashing workflow is shown below.
+
+ git checkout your_branch_name
+ git rebase -i HEAD~n
+ # n is normally the number of commits in the pull request.
+ # Set commits (except the one in the first line) from 'pick' to 'squash', save and quit.
+ # On the next screen, edit/refine commit messages.
+ # Save and quit.
+ git push -f # (force push to GitHub)
+
+Please update the resulting commit message if needed, it should read as a
+coherent message. In most cases this means that you should not just list the
+interim commits.
+
+If you have problems with squashing (or other workflows with `git`), you can
+alternatively enable "Allow edits from maintainers" in the right GitHub
+sidebar and ask for help in the pull request.
+
+Please refrain from creating several pull requests for the same change.
+Use the pull request that is already open (or was created earlier) to amend
+changes. This preserves the discussion and review that happened earlier for
+the respective change set.
+
+The length of time required for peer review is unpredictable and will vary from
+pull request to pull request.
+
+
+Pull Request Philosophy
+-----------------------
+
+Patchsets should always be focused. For example, a pull request could add a
+feature, fix a bug, or refactor code; but not a mixture. Please also avoid super
+pull requests which attempt to do too much, are overly large, or overly complex
+as this makes review difficult.
+
+
+### Features
+
+When adding a new feature, thought must be given to the long term technical debt
+and maintenance that feature may require after inclusion. Before proposing a new
+feature that will require maintenance, please consider if you are willing to
+maintain it (including bug fixing). If features get orphaned with no maintainer
+in the future, they may be removed by the Repository Maintainer.
+
+
+### Refactoring
+
+Refactoring is a necessary part of any software project's evolution. The
+following guidelines cover refactoring pull requests for the project.
+
+There are three categories of refactoring, code only moves, code style fixes,
+code refactoring. In general refactoring pull requests should not mix these
+three kinds of activity in order to make refactoring pull requests easy to
+review and uncontroversial. In all cases, refactoring PRs must not change the
+behaviour of code within the pull request (bugs must be preserved as is).
+
+Project maintainers aim for a quick turnaround on refactoring pull requests, so
+where possible keep them short, uncomplex and easy to verify.
+
+Pull requests that refactor the code should not be made by new contributors. It
+requires a certain level of experience to know where the code belongs to and to
+understand the full ramification (including rebase effort of open pull requests).
+
+Trivial pull requests or pull requests that refactor the code with no clear
+benefits may be immediately closed by the maintainers to reduce unnecessary
+workload on reviewing.
+
+
+"Decision Making" Process
+-------------------------
+
+The following applies to code changes to the DeFi Blockchain project (and related
+projects such as libsecp256k1), and is not to be confused with overall DeFi
+Network Protocol consensus changes.
+
+Whether a pull request is merged into DeFi Blockchain rests with the project merge
+maintainers and ultimately the project lead.
+
+Maintainers will take into consideration if a patch is in line with the general
+principles of the project; meets the minimum standards for inclusion; and will
+judge the general consensus of contributors.
+
+In general, all pull requests must:
+
+ - Have a clear use case, fix a demonstrable bug or serve the greater good of
+ the project (for example refactoring for modularisation);
+ - Be well peer reviewed;
+ - Have unit tests and functional tests where appropriate;
+ - Follow code style guidelines ([C++](doc/developer-notes.md), [functional tests](test/functional/README.md));
+ - Not break the existing test suite;
+ - Where bugs are fixed, where possible, there should be unit tests
+ demonstrating the bug and also proving the fix. This helps prevent regression.
+ - Change relevant comments and documentation when behaviour of code changes.
+
+Patches that change DeFi Blockchain consensus rules are considerably more involved than
+normal because they affect the entire ecosystem and so must be preceded by
+extensive mailing list discussions and have a numbered BIP. While each case will
+be different, one should be prepared to expend more time and effort than for
+other kinds of patches because of increased peer review and consensus building
+requirements.
+
+
+### Peer Review
+
+Anyone may participate in peer review which is expressed by comments in the pull
+request. Typically reviewers will review the code for obvious errors, as well as
+test out the patch set and opine on the technical merits of the patch. Project
+maintainers take into account the peer review when determining if there is
+consensus to merge a pull request (remember that discussions may have been
+spread out over GitHub, mailing list and IRC discussions).
+
+#### Conceptual Review
+
+A review can be a conceptual review, where the reviewer leaves a comment
+ * `Concept (N)ACK`, meaning "I do (not) agree in the general goal of this pull
+ request",
+ * `Approach (N)ACK`, meaning `Concept ACK`, but "I do (not) agree with the
+ approach of this change".
+
+A `NACK` needs to include a rationale why the change is not worthwhile.
+NACKs without accompanying reasoning may be disregarded.
+
+#### Code Review
+
+After conceptual agreement on the change, code review can be provided. It is
+starting with `ACK BRANCH_COMMIT`, where `BRANCH_COMMIT` is the top of the
+topic branch. The review is followed by a description of how the reviewer did
+the review. The following
+language is used within pull-request comments:
+
+ - "I have tested the code", involving
+ change-specific manual testing in addition to running the unit and functional
+ tests, and in case it is not obvious how the manual testing was done, it should
+ be described;
+ - "I have not tested the code, but I have reviewed it and it looks
+ OK, I agree it can be merged";
+ - Nit refers to trivial, often non-blocking issues.
+
+Project maintainers reserve the right to weigh the opinions of peer reviewers
+using common sense judgement and also may weight based on meritocracy: Those
+that have demonstrated a deeper commitment and understanding towards the project
+(over time) or have clear domain expertise may naturally have more weight, as
+one would expect in all walks of life.
+
+Where a patch set affects consensus critical code, the bar will be set much
+higher in terms of discussion and peer review requirements, keeping in mind that
+mistakes could be very costly to the wider community. This includes refactoring
+of consensus critical code.
+
+Where a patch set proposes to change the DeFi Blockchain consensus, it must have been
+discussed extensively on the mailing list and IRC, be accompanied by a widely
+discussed BIP and have a generally widely perceived technical consensus of being
+a worthwhile change based on the judgement of the maintainers.
+
+### Finding Reviewers
+
+As most reviewers are themselves developers with their own projects, the review
+process can be quite lengthy, and some amount of patience is required. If you find
+that you've been waiting for a pull request to be given attention for several
+months, there may be a number of reasons for this, some of which you can do something
+about:
+
+ - It may be because of a feature freeze due to an upcoming release. During this time,
+ only bug fixes are taken into consideration. If your pull request is a new feature,
+ it will not be prioritized until the release is over. Wait for release.
+ - It may be because the changes you are suggesting do not appeal to people. Rather than
+ nits and critique, which require effort and means they care enough to spend time on your
+ contribution, thundering silence is a good sign of widespread (mild) dislike of a given change
+ (because people don't assume *others* won't actually like the proposal). Don't take
+ that personally, though! Instead, take another critical look at what you are suggesting
+ and see if it: changes too much, is too broad, doesn't adhere to the
+ [developer notes](doc/developer-notes.md), is dangerous or insecure, is messily written, etc.
+ Identify and address any of the issues you find. Then ask e.g. on IRC if someone could give
+ their opinion on the concept itself.
+ - It may be because your code is too complex for all but a few people. And those people
+ may not have realized your pull request even exists. A great way to find people who
+ are qualified and care about the code you are touching is the
+ [Git Blame feature](https://help.github.com/articles/tracing-changes-in-a-file/). Simply
+ find the person touching the code you are touching before you and see if you can find
+ them and give them a nudge. Don't be incessant about the nudging though.
+ - Finally, if all else fails, ask on IRC or elsewhere for someone to give your pull request
+ a look. If you think you've been waiting an unreasonably long amount of time (month+) for
+ no particular reason (few lines changed, etc), this is totally fine. Try to return the favor
+ when someone else is asking for feedback on their code, and universe balances out.
+
+
+Release Policy
+--------------
+
+The project leader is the release manager for each DeFi Blockchain release.
+
+Copyright
+---------
+
+By contributing to this repository, you agree to license your work under the
+MIT license unless specified otherwise in `contrib/debian/copyright` or at
+the top of the file itself. Any work contributed where you are not the original
+author must contain its license header with the original author(s) and source.
diff --git a/COPYING b/COPYING
index 4522a5990e..cc8f90bc92 100644
--- a/COPYING
+++ b/COPYING
@@ -1,4 +1,8 @@
-Copyright (c) 2013 Pieter Wuille
+The MIT License (MIT)
+
+Copyright (c) 2009-2019 The Bitcoin Core developers
+Copyright (c) 2009-2019 Bitcoin Developers
+Copyright (c) 2020 DeFi Blockchain Developers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/INSTALL.md b/INSTALL.md
new file mode 100644
index 0000000000..657acf05ed
--- /dev/null
+++ b/INSTALL.md
@@ -0,0 +1,5 @@
+Building the DeFi Blockchain
+================
+
+See doc/build-*.md for instructions on building the various
+elements of DeFi Blockchain.
diff --git a/Makefile.am b/Makefile.am
index 9e5b7dcce0..8357a24ec4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,182 +1,334 @@
+# Copyright (c) 2013-2016 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
ACLOCAL_AMFLAGS = -I build-aux/m4
+SUBDIRS = src
+if ENABLE_MAN
+SUBDIRS += doc/man
+endif
+.PHONY: deploy FORCE
-lib_LTLIBRARIES = libsecp256k1.la
-if USE_JNI
-JNI_LIB = libsecp256k1_jni.la
-noinst_LTLIBRARIES = $(JNI_LIB)
-else
-JNI_LIB =
+export PYTHONPATH
+
+if BUILD_DEFI_LIBS
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libdeficonsensus.pc
endif
-include_HEADERS = include/secp256k1.h
-noinst_HEADERS =
-noinst_HEADERS += src/scalar.h
-noinst_HEADERS += src/scalar_4x64.h
-noinst_HEADERS += src/scalar_8x32.h
-noinst_HEADERS += src/scalar_low.h
-noinst_HEADERS += src/scalar_impl.h
-noinst_HEADERS += src/scalar_4x64_impl.h
-noinst_HEADERS += src/scalar_8x32_impl.h
-noinst_HEADERS += src/scalar_low_impl.h
-noinst_HEADERS += src/group.h
-noinst_HEADERS += src/group_impl.h
-noinst_HEADERS += src/num_gmp.h
-noinst_HEADERS += src/num_gmp_impl.h
-noinst_HEADERS += src/ecdsa.h
-noinst_HEADERS += src/ecdsa_impl.h
-noinst_HEADERS += src/eckey.h
-noinst_HEADERS += src/eckey_impl.h
-noinst_HEADERS += src/ecmult.h
-noinst_HEADERS += src/ecmult_impl.h
-noinst_HEADERS += src/ecmult_const.h
-noinst_HEADERS += src/ecmult_const_impl.h
-noinst_HEADERS += src/ecmult_gen.h
-noinst_HEADERS += src/ecmult_gen_impl.h
-noinst_HEADERS += src/num.h
-noinst_HEADERS += src/num_impl.h
-noinst_HEADERS += src/field_10x26.h
-noinst_HEADERS += src/field_10x26_impl.h
-noinst_HEADERS += src/field_5x52.h
-noinst_HEADERS += src/field_5x52_impl.h
-noinst_HEADERS += src/field_5x52_int128_impl.h
-noinst_HEADERS += src/field_5x52_asm_impl.h
-noinst_HEADERS += src/java/org_bitcoin_NativeSecp256k1.h
-noinst_HEADERS += src/java/org_bitcoin_Secp256k1Context.h
-noinst_HEADERS += src/util.h
-noinst_HEADERS += src/scratch.h
-noinst_HEADERS += src/scratch_impl.h
-noinst_HEADERS += src/testrand.h
-noinst_HEADERS += src/testrand_impl.h
-noinst_HEADERS += src/hash.h
-noinst_HEADERS += src/hash_impl.h
-noinst_HEADERS += src/field.h
-noinst_HEADERS += src/field_impl.h
-noinst_HEADERS += src/bench.h
-noinst_HEADERS += contrib/lax_der_parsing.h
-noinst_HEADERS += contrib/lax_der_parsing.c
-noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
-noinst_HEADERS += contrib/lax_der_privatekey_parsing.c
-
-if USE_EXTERNAL_ASM
-COMMON_LIB = libsecp256k1_common.la
-noinst_LTLIBRARIES = $(COMMON_LIB)
+
+DEFID_BIN=$(top_builddir)/src/$(DEFI_DAEMON_NAME)$(EXEEXT)
+DEFI_QT_BIN=$(top_builddir)/src/qt/$(DEFI_GUI_NAME)$(EXEEXT)
+DEFI_CLI_BIN=$(top_builddir)/src/$(DEFI_CLI_NAME)$(EXEEXT)
+DEFI_TX_BIN=$(top_builddir)/src/$(DEFI_TX_NAME)$(EXEEXT)
+DEFI_WALLET_BIN=$(top_builddir)/src/$(DEFI_WALLET_TOOL_NAME)$(EXEEXT)
+DEFI_WIN_INSTALLER=$(PACKAGE)-$(PACKAGE_VERSION)-win$(WINDOWS_BITS)-setup$(EXEEXT)
+
+support_examples_dir = $(pkgdatadir)/examples
+support_examples__DATA = $(top_srcdir)/share/examples/default.conf \
+ $(top_srcdir)/share/examples/pruned.conf
+
+support_rpcauth_dir = $(pkgdatadir)/rpcauth
+support_rpcauth__DATA = $(top_srcdir)/share/rpcauth/rpcauth.py \
+ $(top_srcdir)/share/rpcauth/README.md
+
+support_service_dir = $(pkgdatadir)/service
+support_service__DATA = $(top_srcdir)/contrib/init/defid.conf \
+ $(top_srcdir)/contrib/init/defid.init \
+ $(top_srcdir)/contrib/init/defid.openrc \
+ $(top_srcdir)/contrib/init/defid.openrcconf \
+ $(top_srcdir)/contrib/init/defid.service
+
+support_bash_dir = $(datadir)/bash-completion/completions
+support_bash__DATA = $(top_srcdir)/contrib/defi-cli.bash-completion \
+ $(top_srcdir)/contrib/defi-tx.bash-completion \
+ $(top_srcdir)/contrib/defid.bash-completion
+
+empty :=
+space := $(empty) $(empty)
+
+OSX_APP=Defi-Qt.app
+OSX_VOLNAME = $(subst $(space),-,$(PACKAGE_NAME))
+OSX_DMG = $(OSX_VOLNAME).dmg
+OSX_BACKGROUND_SVG=background.svg
+OSX_BACKGROUND_IMAGE=background.tiff
+OSX_BACKGROUND_IMAGE_DPIS=36 72
+OSX_DSSTORE_GEN=$(top_srcdir)/contrib/macdeploy/custom_dsstore.py
+OSX_DEPLOY_SCRIPT=$(top_srcdir)/contrib/macdeploy/macdeployqtplus
+OSX_FANCY_PLIST=$(top_srcdir)/contrib/macdeploy/fancy.plist
+OSX_INSTALLER_ICONS=$(top_srcdir)/src/qt/res/icons/defi.icns
+OSX_PLIST=$(top_builddir)/share/qt/Info.plist #not installed
+OSX_QT_TRANSLATIONS = da,de,es,hu,ru,uk,zh_CN,zh_TW
+
+DIST_DOCS = $(wildcard doc/*.md) $(wildcard doc/release-notes/*.md)
+DIST_CONTRIB = $(top_srcdir)/contrib/defi-cli.bash-completion \
+ $(top_srcdir)/contrib/defi-tx.bash-completion \
+ $(top_srcdir)/contrib/defid.bash-completion \
+ $(top_srcdir)/contrib/debian/copyright \
+ $(top_srcdir)/contrib/init \
+ $(top_srcdir)/contrib/install_db4.sh
+DIST_SHARE = \
+ $(top_srcdir)/share/genbuild.sh \
+ $(top_srcdir)/share/rpcauth
+
+BIN_CHECKS=$(top_srcdir)/contrib/devtools/symbol-check.py \
+ $(top_srcdir)/contrib/devtools/security-check.py
+
+WINDOWS_PACKAGING = $(top_srcdir)/share/pixmaps/defi.ico \
+ $(top_srcdir)/share/pixmaps/nsis-header.bmp \
+ $(top_srcdir)/share/pixmaps/nsis-wizard.bmp \
+ $(top_srcdir)/doc/README_windows.txt
+
+OSX_PACKAGING = $(OSX_DEPLOY_SCRIPT) $(OSX_FANCY_PLIST) $(OSX_INSTALLER_ICONS) \
+ $(top_srcdir)/contrib/macdeploy/$(OSX_BACKGROUND_SVG) \
+ $(OSX_DSSTORE_GEN) \
+ $(top_srcdir)/contrib/macdeploy/detached-sig-apply.sh \
+ $(top_srcdir)/contrib/macdeploy/detached-sig-create.sh
+
+COVERAGE_INFO = baseline.info \
+ test_defi_filtered.info total_coverage.info \
+ baseline_filtered.info functional_test.info functional_test_filtered.info \
+ test_defi_coverage.info test_defi.info
+
+dist-hook:
+ -$(GIT) archive --format=tar HEAD -- src/clientversion.cpp | $(AMTAR) -C $(top_distdir) -xf -
+
+$(DEFI_WIN_INSTALLER): all-recursive
+ $(MKDIR_P) $(top_builddir)/release
+ STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(DEFID_BIN) $(top_builddir)/release
+ STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(DEFI_QT_BIN) $(top_builddir)/release
+ STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(DEFI_CLI_BIN) $(top_builddir)/release
+ STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(DEFI_TX_BIN) $(top_builddir)/release
+ STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(DEFI_WALLET_BIN) $(top_builddir)/release
+ @test -f $(MAKENSIS) && $(MAKENSIS) -V2 $(top_builddir)/share/setup.nsi || \
+ echo error: could not build $@
+ @echo built $@
+
+$(OSX_APP)/Contents/PkgInfo:
+ $(MKDIR_P) $(@D)
+ @echo "APPL????" > $@
+
+$(OSX_APP)/Contents/Resources/empty.lproj:
+ $(MKDIR_P) $(@D)
+ @touch $@
+
+$(OSX_APP)/Contents/Info.plist: $(OSX_PLIST)
+ $(MKDIR_P) $(@D)
+ $(INSTALL_DATA) $< $@
+
+$(OSX_APP)/Contents/Resources/defi.icns: $(OSX_INSTALLER_ICONS)
+ $(MKDIR_P) $(@D)
+ $(INSTALL_DATA) $< $@
+
+$(OSX_APP)/Contents/MacOS/Defi-Qt: all-recursive
+ $(MKDIR_P) $(@D)
+ STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(DEFI_QT_BIN) $@
+
+$(OSX_APP)/Contents/Resources/Base.lproj/InfoPlist.strings:
+ $(MKDIR_P) $(@D)
+ echo '{ CFBundleDisplayName = "$(PACKAGE_NAME)"; CFBundleName = "$(PACKAGE_NAME)"; }' > $@
+
+OSX_APP_BUILT=$(OSX_APP)/Contents/PkgInfo $(OSX_APP)/Contents/Resources/empty.lproj \
+ $(OSX_APP)/Contents/Resources/defi.icns $(OSX_APP)/Contents/Info.plist \
+ $(OSX_APP)/Contents/MacOS/Defi-Qt $(OSX_APP)/Contents/Resources/Base.lproj/InfoPlist.strings
+
+osx_volname:
+ echo $(OSX_VOLNAME) >$@
+
+if BUILD_DARWIN
+$(OSX_DMG): $(OSX_APP_BUILT) $(OSX_PACKAGING) $(OSX_BACKGROUND_IMAGE)
+ $(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) -add-qt-tr $(OSX_QT_TRANSLATIONS) -translations-dir=$(QT_TRANSLATION_DIR) -dmg -fancy $(OSX_FANCY_PLIST) -verbose 2 -volname $(OSX_VOLNAME)
+
+$(OSX_BACKGROUND_IMAGE).png: contrib/macdeploy/$(OSX_BACKGROUND_SVG)
+ sed 's/PACKAGE_NAME/$(PACKAGE_NAME)/' < "$<" | $(RSVG_CONVERT) -f png -d 36 -p 36 -o $@
+$(OSX_BACKGROUND_IMAGE)@2x.png: contrib/macdeploy/$(OSX_BACKGROUND_SVG)
+ sed 's/PACKAGE_NAME/$(PACKAGE_NAME)/' < "$<" | $(RSVG_CONVERT) -f png -d 72 -p 72 -o $@
+$(OSX_BACKGROUND_IMAGE): $(OSX_BACKGROUND_IMAGE).png $(OSX_BACKGROUND_IMAGE)@2x.png
+ tiffutil -cathidpicheck $^ -out $@
+
+deploydir: $(OSX_DMG)
else
-COMMON_LIB =
-endif
+APP_DIST_DIR=$(top_builddir)/dist
+APP_DIST_EXTRAS=$(APP_DIST_DIR)/.background/$(OSX_BACKGROUND_IMAGE) $(APP_DIST_DIR)/.DS_Store $(APP_DIST_DIR)/Applications
-pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = libsecp256k1.pc
+$(APP_DIST_DIR)/Applications:
+ @rm -f $@
+ @cd $(@D); $(LN_S) /Applications $(@F)
-if USE_EXTERNAL_ASM
-if USE_ASM_ARM
-libsecp256k1_common_la_SOURCES = src/asm/field_10x26_arm.s
-endif
-endif
+$(APP_DIST_EXTRAS): $(APP_DIST_DIR)/$(OSX_APP)/Contents/MacOS/Defi-Qt
-libsecp256k1_la_SOURCES = src/secp256k1.c
-libsecp256k1_la_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
-libsecp256k1_la_LIBADD = $(JNI_LIB) $(SECP_LIBS) $(COMMON_LIB)
-
-libsecp256k1_jni_la_SOURCES = src/java/org_bitcoin_NativeSecp256k1.c src/java/org_bitcoin_Secp256k1Context.c
-libsecp256k1_jni_la_CPPFLAGS = -DSECP256K1_BUILD $(JNI_INCLUDES)
-
-noinst_PROGRAMS =
-if USE_BENCHMARK
-noinst_PROGRAMS += bench_verify bench_sign bench_internal bench_ecmult
-bench_verify_SOURCES = src/bench_verify.c
-bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
-bench_sign_SOURCES = src/bench_sign.c
-bench_sign_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
-bench_internal_SOURCES = src/bench_internal.c
-bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB)
-bench_internal_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
-bench_ecmult_SOURCES = src/bench_ecmult.c
-bench_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB)
-bench_ecmult_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
-endif
+$(OSX_DMG): $(APP_DIST_EXTRAS)
+ $(GENISOIMAGE) -no-cache-inodes -D -l -probe -V "$(OSX_VOLNAME)" -no-pad -r -dir-mode 0755 -apple -o $@ dist
-TESTS =
-if USE_TESTS
-noinst_PROGRAMS += tests
-tests_SOURCES = src/tests.c
-tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
-if !ENABLE_COVERAGE
-tests_CPPFLAGS += -DVERIFY
-endif
-tests_LDADD = $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
-tests_LDFLAGS = -static
-TESTS += tests
+dpi%.$(OSX_BACKGROUND_IMAGE): contrib/macdeploy/$(OSX_BACKGROUND_SVG)
+ sed 's/PACKAGE_NAME/$(PACKAGE_NAME)/' < "$<" | $(RSVG_CONVERT) -f png -d $* -p $* | $(IMAGEMAGICK_CONVERT) - $@
+OSX_BACKGROUND_IMAGE_DPIFILES := $(foreach dpi,$(OSX_BACKGROUND_IMAGE_DPIS),dpi$(dpi).$(OSX_BACKGROUND_IMAGE))
+$(APP_DIST_DIR)/.background/$(OSX_BACKGROUND_IMAGE): $(OSX_BACKGROUND_IMAGE_DPIFILES)
+ $(MKDIR_P) $(@D)
+ $(TIFFCP) -c none $(OSX_BACKGROUND_IMAGE_DPIFILES) $@
+
+$(APP_DIST_DIR)/.DS_Store: $(OSX_DSSTORE_GEN)
+ $(PYTHON) $< "$@" "$(OSX_VOLNAME)"
+
+$(APP_DIST_DIR)/$(OSX_APP)/Contents/MacOS/Defi-Qt: $(OSX_APP_BUILT) $(OSX_PACKAGING)
+ INSTALLNAMETOOL=$(INSTALLNAMETOOL) OTOOL=$(OTOOL) STRIP=$(STRIP) $(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) -translations-dir=$(QT_TRANSLATION_DIR) -add-qt-tr $(OSX_QT_TRANSLATIONS) -verbose 2
+
+deploydir: $(APP_DIST_EXTRAS)
endif
-if USE_EXHAUSTIVE_TESTS
-noinst_PROGRAMS += exhaustive_tests
-exhaustive_tests_SOURCES = src/tests_exhaustive.c
-exhaustive_tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src $(SECP_INCLUDES)
-if !ENABLE_COVERAGE
-exhaustive_tests_CPPFLAGS += -DVERIFY
+if TARGET_DARWIN
+appbundle: $(OSX_APP_BUILT)
+deploy: $(OSX_DMG)
endif
-exhaustive_tests_LDADD = $(SECP_LIBS) $(COMMON_LIB)
-exhaustive_tests_LDFLAGS = -static
-TESTS += exhaustive_tests
+if TARGET_WINDOWS
+deploy: $(DEFI_WIN_INSTALLER)
endif
-JAVAROOT=src/java
-JAVAORG=org/bitcoin
-JAVA_GUAVA=$(srcdir)/$(JAVAROOT)/guava/guava-18.0.jar
-CLASSPATH_ENV=CLASSPATH=$(JAVA_GUAVA)
-JAVA_FILES= \
- $(JAVAROOT)/$(JAVAORG)/NativeSecp256k1.java \
- $(JAVAROOT)/$(JAVAORG)/NativeSecp256k1Test.java \
- $(JAVAROOT)/$(JAVAORG)/NativeSecp256k1Util.java \
- $(JAVAROOT)/$(JAVAORG)/Secp256k1Context.java
-
-if USE_JNI
-
-$(JAVA_GUAVA):
- @echo Guava is missing. Fetch it via: \
- wget https://search.maven.org/remotecontent?filepath=com/google/guava/guava/18.0/guava-18.0.jar -O $(@)
- @false
-
-.stamp-java: $(JAVA_FILES)
- @echo Compiling $^
- $(AM_V_at)$(CLASSPATH_ENV) javac $^
+$(DEFI_QT_BIN): FORCE
+ $(MAKE) -C src qt/$(@F)
+
+$(DEFID_BIN): FORCE
+ $(MAKE) -C src $(@F)
+
+$(DEFI_CLI_BIN): FORCE
+ $(MAKE) -C src $(@F)
+
+$(DEFI_TX_BIN): FORCE
+ $(MAKE) -C src $(@F)
+
+$(DEFI_WALLET_BIN): FORCE
+ $(MAKE) -C src $(@F)
+
+if USE_LCOV
+LCOV_FILTER_PATTERN=-p "/usr/include/" -p "/usr/lib/" -p "src/leveldb/" -p "src/bench/" -p "src/univalue" -p "src/crypto/ctaes" -p "src/secp256k1"
+
+baseline.info:
+ $(LCOV) -c -i -d $(abs_builddir)/src -o $@
+
+baseline_filtered.info: baseline.info
+ $(abs_builddir)/contrib/filter-lcov.py $(LCOV_FILTER_PATTERN) $< $@
+ $(LCOV) -a $@ $(LCOV_OPTS) -o $@
+
+test_defi.info: baseline_filtered.info
+ $(MAKE) -C src/ check
+ $(LCOV) -c $(LCOV_OPTS) -d $(abs_builddir)/src -t test_defi -o $@
+ $(LCOV) -z $(LCOV_OPTS) -d $(abs_builddir)/src
+
+test_defi_filtered.info: test_defi.info
+ $(abs_builddir)/contrib/filter-lcov.py $(LCOV_FILTER_PATTERN) $< $@
+ $(LCOV) -a $@ $(LCOV_OPTS) -o $@
+
+functional_test.info: test_defi_filtered.info
+ @TIMEOUT=15 test/functional/test_runner.py $(EXTENDED_FUNCTIONAL_TESTS)
+ $(LCOV) -c $(LCOV_OPTS) -d $(abs_builddir)/src --t functional-tests -o $@
+ $(LCOV) -z $(LCOV_OPTS) -d $(abs_builddir)/src
+
+functional_test_filtered.info: functional_test.info
+ $(abs_builddir)/contrib/filter-lcov.py $(LCOV_FILTER_PATTERN) $< $@
+ $(LCOV) -a $@ $(LCOV_OPTS) -o $@
+
+test_defi_coverage.info: baseline_filtered.info test_defi_filtered.info
+ $(LCOV) -a $(LCOV_OPTS) baseline_filtered.info -a test_defi_filtered.info -o $@
+
+total_coverage.info: test_defi_filtered.info functional_test_filtered.info
+ $(LCOV) -a $(LCOV_OPTS) baseline_filtered.info -a test_defi_filtered.info -a functional_test_filtered.info -o $@ | $(GREP) "\%" | $(AWK) '{ print substr($$3,2,50) "/" $$5 }' > coverage_percent.txt
+
+test_defi.coverage/.dirstamp: test_defi_coverage.info
+ $(GENHTML) -s $(LCOV_OPTS) $< -o $(@D)
@touch $@
-if USE_TESTS
+total.coverage/.dirstamp: total_coverage.info
+ $(GENHTML) -s $(LCOV_OPTS) $< -o $(@D)
+ @touch $@
-check-java: libsecp256k1.la $(JAVA_GUAVA) .stamp-java
- $(AM_V_at)java -Djava.library.path="./:./src:./src/.libs:.libs/" -cp "$(JAVA_GUAVA):$(JAVAROOT)" $(JAVAORG)/NativeSecp256k1Test
+cov: test_defi.coverage/.dirstamp total.coverage/.dirstamp
endif
-endif
-if USE_ECMULT_STATIC_PRECOMPUTATION
-CPPFLAGS_FOR_BUILD +=-I$(top_srcdir)
+dist_noinst_SCRIPTS = autogen.sh
-gen_context_OBJECTS = gen_context.o
-gen_context_BIN = gen_context$(BUILD_EXEEXT)
-gen_%.o: src/gen_%.c
- $(CC_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
+EXTRA_DIST = $(DIST_SHARE) $(DIST_CONTRIB) $(DIST_DOCS) $(WINDOWS_PACKAGING) $(OSX_PACKAGING) $(BIN_CHECKS)
-$(gen_context_BIN): $(gen_context_OBJECTS)
- $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
+EXTRA_DIST += \
+ test/functional \
+ test/fuzz
-$(libsecp256k1_la_OBJECTS): src/ecmult_static_context.h
-$(tests_OBJECTS): src/ecmult_static_context.h
-$(bench_internal_OBJECTS): src/ecmult_static_context.h
-$(bench_ecmult_OBJECTS): src/ecmult_static_context.h
+EXTRA_DIST += \
+ test/util/defi-util-test.py \
+ test/util/data/defi-util-test.json \
+ test/util/data/blanktxv1.hex \
+ test/util/data/blanktxv1.json \
+ test/util/data/blanktxv2.hex \
+ test/util/data/blanktxv2.json \
+ test/util/data/tt-delin1-out.hex \
+ test/util/data/tt-delin1-out.json \
+ test/util/data/tt-delout1-out.hex \
+ test/util/data/tt-delout1-out.json \
+ test/util/data/tt-locktime317000-out.hex \
+ test/util/data/tt-locktime317000-out.json \
+ test/util/data/tx394b54bb.hex \
+ test/util/data/txcreate1.hex \
+ test/util/data/txcreate1.json \
+ test/util/data/txcreate2.hex \
+ test/util/data/txcreate2.json \
+ test/util/data/txcreatedata1.hex \
+ test/util/data/txcreatedata1.json \
+ test/util/data/txcreatedata2.hex \
+ test/util/data/txcreatedata2.json \
+ test/util/data/txcreatedata_seq0.hex \
+ test/util/data/txcreatedata_seq0.json \
+ test/util/data/txcreatedata_seq1.hex \
+ test/util/data/txcreatedata_seq1.json \
+ test/util/data/txcreatemultisig1.hex \
+ test/util/data/txcreatemultisig1.json \
+ test/util/data/txcreatemultisig2.hex \
+ test/util/data/txcreatemultisig2.json \
+ test/util/data/txcreatemultisig3.hex \
+ test/util/data/txcreatemultisig3.json \
+ test/util/data/txcreatemultisig4.hex \
+ test/util/data/txcreatemultisig4.json \
+ test/util/data/txcreatemultisig5.json \
+ test/util/data/txcreateoutpubkey1.hex \
+ test/util/data/txcreateoutpubkey1.json \
+ test/util/data/txcreateoutpubkey2.hex \
+ test/util/data/txcreateoutpubkey2.json \
+ test/util/data/txcreateoutpubkey3.hex \
+ test/util/data/txcreateoutpubkey3.json \
+ test/util/data/txcreatescript1.hex \
+ test/util/data/txcreatescript1.json \
+ test/util/data/txcreatescript2.hex \
+ test/util/data/txcreatescript2.json \
+ test/util/data/txcreatescript3.hex \
+ test/util/data/txcreatescript3.json \
+ test/util/data/txcreatescript4.hex \
+ test/util/data/txcreatescript4.json \
+ test/util/data/txcreatesignv1.hex \
+ test/util/data/txcreatesignv1.json \
+ test/util/data/txcreatesignv2.hex \
+ test/util/rpcauth-test.py
-src/ecmult_static_context.h: $(gen_context_BIN)
- ./$(gen_context_BIN)
+CLEANFILES = $(OSX_DMG) $(DEFI_WIN_INSTALLER)
-CLEANFILES = $(gen_context_BIN) src/ecmult_static_context.h $(JAVAROOT)/$(JAVAORG)/*.class .stamp-java
-endif
+.INTERMEDIATE: $(COVERAGE_INFO)
-EXTRA_DIST = autogen.sh src/gen_context.c src/basic-config.h $(JAVA_FILES)
+DISTCHECK_CONFIGURE_FLAGS = --enable-man
-if ENABLE_MODULE_ECDH
-include src/modules/ecdh/Makefile.am.include
-endif
+doc/doxygen/.stamp: doc/Doxyfile FORCE
+ $(MKDIR_P) $(@D)
+ $(DOXYGEN) $^
+ $(AM_V_at) touch $@
-if ENABLE_MODULE_RECOVERY
-include src/modules/recovery/Makefile.am.include
+if HAVE_DOXYGEN
+docs: doc/doxygen/.stamp
+else
+docs:
+ @echo "error: doxygen not found"
endif
+
+clean-docs:
+ rm -rf doc/doxygen
+
+clean-local: clean-docs
+ rm -rf coverage_percent.txt test_defi.coverage/ total.coverage/ test/tmp/ cache/ $(OSX_APP)
+ rm -rf test/functional/__pycache__ test/functional/test_framework/__pycache__ test/cache share/rpcauth/__pycache__
+ rm -rf osx_volname dist/ dpi36.background.tiff dpi72.background.tiff
+
diff --git a/README.md b/README.md
index 8cd344ea81..8710887f0a 100644
--- a/README.md
+++ b/README.md
@@ -1,61 +1,59 @@
-libsecp256k1
-============
-
-[![Build Status](https://travis-ci.org/bitcoin-core/secp256k1.svg?branch=master)](https://travis-ci.org/bitcoin-core/secp256k1)
-
-Optimized C library for EC operations on curve secp256k1.
-
-This library is a work in progress and is being used to research best practices. Use at your own risk.
-
-Features:
-* secp256k1 ECDSA signing/verification and key generation.
-* Adding/multiplying private/public keys.
-* Serialization/parsing of private keys, public keys, signatures.
-* Constant time, constant memory access signing and pubkey generation.
-* Derandomized DSA (via RFC6979 or with a caller provided function.)
-* Very efficient implementation.
-
-Implementation details
-----------------------
-
-* General
- * No runtime heap allocation.
- * Extensive testing infrastructure.
- * Structured to facilitate review and analysis.
- * Intended to be portable to any system with a C89 compiler and uint64_t support.
- * Expose only higher level interfaces to minimize the API surface and improve application security. ("Be difficult to use insecurely.")
-* Field operations
- * Optimized implementation of arithmetic modulo the curve's field size (2^256 - 0x1000003D1).
- * Using 5 52-bit limbs (including hand-optimized assembly for x86_64, by Diederik Huys).
- * Using 10 26-bit limbs.
- * Field inverses and square roots using a sliding window over blocks of 1s (by Peter Dettman).
-* Scalar operations
- * Optimized implementation without data-dependent branches of arithmetic modulo the curve's order.
- * Using 4 64-bit limbs (relying on __int128 support in the compiler).
- * Using 8 32-bit limbs.
-* Group operations
- * Point addition formula specifically simplified for the curve equation (y^2 = x^3 + 7).
- * Use addition between points in Jacobian and affine coordinates where possible.
- * Use a unified addition/doubling formula where necessary to avoid data-dependent branches.
- * Point/x comparison without a field inversion by comparison in the Jacobian coordinate space.
-* Point multiplication for verification (a*P + b*G).
- * Use wNAF notation for point multiplicands.
- * Use a much larger window for multiples of G, using precomputed multiples.
- * Use Shamir's trick to do the multiplication with the public key and the generator simultaneously.
- * Optionally (off by default) use secp256k1's efficiently-computable endomorphism to split the P multiplicand into 2 half-sized ones.
-* Point multiplication for signing
- * Use a precomputed table of multiples of powers of 16 multiplied with the generator, so general multiplication becomes a series of additions.
- * Access the table with branch-free conditional moves so memory access is uniform.
- * No data-dependent branches
- * The precomputed tables add and eventually subtract points for which no known scalar (private key) is known, preventing even an attacker with control over the private key used to control the data internally.
-
-Build steps
------------
-
-libsecp256k1 is built using autotools:
-
- $ ./autogen.sh
- $ ./configure
- $ make
- $ ./tests
- $ sudo make install # optional
+![DeFi Blockchain Logo](doc/img/defichain-logo.svg)
+
+# DeFi Blockchain
+
+[![Build Status](https://travis-ci.com/DeFiCh/ain.svg?branch=master)](https://travis-ci.com/DeFiCh/ain)
+
+https://defichain.io
+
+## What is DeFi Blockchain?
+
+DeFi Blockchain’s primary vision is to enable decentralized finance with Bitcoin-grade security, strength and immutability. It's a blockchain dedicated to fast, intelligent and transparent financial services, accessible by everyone.
+
+For more information:
+
+- Visit the [DeFi Blockchain website](https://defichain.io)
+- Read our [white paper](https://defichain.io/white-paper/)
+
+Downloadable binaries are available from the [GitHub Releases](https://github.com/DeFiCh/ain/releases) page.
+
+### Bitcoin Core
+
+DeFi Blockchain is a fork on [Bitcoin Core](https://github.com/bitcoin/bitcoin) from commit [7d6f63c](https://github.com/bitcoin/bitcoin/commit/7d6f63cc2c2b9c4f07a43619eef0b7314474fffd) – which is slightly after v0.18.1 of Bitcoin Core.
+
+DeFi Blockchain has done significant modifications from Bitcoin Core, for instance:
+
+- Moving from Proof-of-Work to Proof-of-Stake
+- Masternode model
+- Community fund support
+- Bitcoin blockchain block anchoring
+- Increased decentralized financial transaction and opcode support, etc.
+- Configuration defaults (mainnet ports: `8555/4`, testnet ports: `18555/4`, regnet ports: `19555/4`, etc)
+
+Merges from upstream (Bitcoin Core) will be done selectively if it applies to the improved functionality and security of DeFi Blockchain.
+
+## Quick Start
+
+- [Running a node](./doc/setup-nodes.md)
+- [Running a node with docker](./doc/setup-nodes-docker.md)
+- [Running a masternode](./doc/setup-masternodes.md)
+- [Building from scratch](./doc/build-quick.md)
+
+## License
+
+DeFi Blockchain is released under the terms of the MIT license. See [COPYING](COPYING) for more
+information or see https://opensource.org/licenses/MIT.
+
+## Development Process
+
+The `master` branch is regularly built and tested, but is not guaranteed to be
+completely stable. [Tags](https://github.com/DeFiCh/ain/tags) are created
+regularly to indicate new official, stable release versions of DeFi Blockchain.
+
+The contribution workflow is described in [CONTRIBUTING.md](CONTRIBUTING.md).
+
+## Questions?
+
+Pull requests are warmly welcomed.
+
+Reach us at [engineering@defichain.io](mailto:engineering@defichain.io) for any questions or collaborations.
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 0000000000..7e311c8a98
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,22 @@
+# Security Policy
+
+> NOTE: This section is a work in progress for DeFi Blockchain, and may not be applicable at it's current state.
+
+## Supported Versions
+
+See our website for versions of DeFi Blockchain that are currently supported with
+security updates: https://bitcoincore.org/en/lifecycle/#schedule
+
+## Reporting a Vulnerability
+
+To report security issues send an email to security@bitcoincore.org (not for support).
+
+The following keys may be used to communicate sensitive information to developers:
+
+| Name | Fingerprint |
+|------|-------------|
+| Wladimir van der Laan | 71A3 B167 3540 5025 D447 E8F2 7481 0B01 2346 C9A6 |
+| Jonas Schnelli | 32EE 5C4C 3FA1 5CCA DB46 ABE5 29D4 BCB6 416F 53EC |
+| Pieter Wuille | 133E AC17 9436 F14A 5CF1 B794 860F EB80 4E66 9320 |
+
+You can import a key by running the following command with that individual’s fingerprint: `gpg --recv-keys ""` Ensure that you put quotes around fingerprints containing spaces.
diff --git a/autogen.sh b/autogen.sh
index 65286b9353..2c434e9ef0 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,3 +1,16 @@
#!/bin/sh
+# Copyright (c) 2013-2016 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
set -e
-autoreconf -if --warnings=all
+srcdir="$(dirname $0)"
+cd "$srcdir"
+if [ -z ${LIBTOOLIZE} ] && GLIBTOOLIZE="$(command -v glibtoolize)"; then
+ LIBTOOLIZE="${GLIBTOOLIZE}"
+ export LIBTOOLIZE
+fi
+command -v autoreconf >/dev/null || \
+ (echo "configuration failed, please install autoconf first" && exit 1)
+autoreconf --install --force --warnings=all
diff --git a/build-aux/m4/ax_boost_base.m4 b/build-aux/m4/ax_boost_base.m4
new file mode 100644
index 0000000000..d540395763
--- /dev/null
+++ b/build-aux/m4/ax_boost_base.m4
@@ -0,0 +1,301 @@
+# ===========================================================================
+# https://www.gnu.org/software/autoconf-archive/ax_boost_base.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_BOOST_BASE([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+#
+# DESCRIPTION
+#
+# Test for the Boost C++ libraries of a particular version (or newer)
+#
+# If no path to the installed boost library is given the macro searchs
+# under /usr, /usr/local, /opt and /opt/local and evaluates the
+# $BOOST_ROOT environment variable. Further documentation is available at
+# .
+#
+# This macro calls:
+#
+# AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
+#
+# And sets:
+#
+# HAVE_BOOST
+#
+# LICENSE
+#
+# Copyright (c) 2008 Thomas Porschberg
+# Copyright (c) 2009 Peter Adolphs
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 45
+
+# example boost program (need to pass version)
+m4_define([_AX_BOOST_BASE_PROGRAM],
+ [AC_LANG_PROGRAM([[
+#include
+]],[[
+(void) ((void)sizeof(char[1 - 2*!!((BOOST_VERSION) < ($1))]));
+]])])
+
+AC_DEFUN([AX_BOOST_BASE],
+[
+AC_ARG_WITH([boost],
+ [AS_HELP_STRING([--with-boost@<:@=ARG@:>@],
+ [use Boost library from a standard location (ARG=yes),
+ from the specified location (ARG=),
+ or disable it (ARG=no)
+ @<:@ARG=yes@:>@ ])],
+ [
+ AS_CASE([$withval],
+ [no],[want_boost="no";_AX_BOOST_BASE_boost_path=""],
+ [yes],[want_boost="yes";_AX_BOOST_BASE_boost_path=""],
+ [want_boost="yes";_AX_BOOST_BASE_boost_path="$withval"])
+ ],
+ [want_boost="yes"])
+
+
+AC_ARG_WITH([boost-libdir],
+ [AS_HELP_STRING([--with-boost-libdir=LIB_DIR],
+ [Force given directory for boost libraries.
+ Note that this will override library path detection,
+ so use this parameter only if default library detection fails
+ and you know exactly where your boost libraries are located.])],
+ [
+ AS_IF([test -d "$withval"],
+ [_AX_BOOST_BASE_boost_lib_path="$withval"],
+ [AC_MSG_ERROR([--with-boost-libdir expected directory name])])
+ ],
+ [_AX_BOOST_BASE_boost_lib_path=""])
+
+BOOST_LDFLAGS=""
+BOOST_CPPFLAGS=""
+AS_IF([test "x$want_boost" = "xyes"],
+ [_AX_BOOST_BASE_RUNDETECT([$1],[$2],[$3])])
+AC_SUBST(BOOST_CPPFLAGS)
+AC_SUBST(BOOST_LDFLAGS)
+])
+
+
+# convert a version string in $2 to numeric and affect to polymorphic var $1
+AC_DEFUN([_AX_BOOST_BASE_TONUMERICVERSION],[
+ AS_IF([test "x$2" = "x"],[_AX_BOOST_BASE_TONUMERICVERSION_req="1.20.0"],[_AX_BOOST_BASE_TONUMERICVERSION_req="$2"])
+ _AX_BOOST_BASE_TONUMERICVERSION_req_shorten=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '\([[0-9]]*\.[[0-9]]*\)'`
+ _AX_BOOST_BASE_TONUMERICVERSION_req_major=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '\([[0-9]]*\)'`
+ AS_IF([test "x$_AX_BOOST_BASE_TONUMERICVERSION_req_major" = "x"],
+ [AC_MSG_ERROR([You should at least specify libboost major version])])
+ _AX_BOOST_BASE_TONUMERICVERSION_req_minor=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '[[0-9]]*\.\([[0-9]]*\)'`
+ AS_IF([test "x$_AX_BOOST_BASE_TONUMERICVERSION_req_minor" = "x"],
+ [_AX_BOOST_BASE_TONUMERICVERSION_req_minor="0"])
+ _AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+ AS_IF([test "X$_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor" = "X"],
+ [_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor="0"])
+ _AX_BOOST_BASE_TONUMERICVERSION_RET=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req_major \* 100000 \+ $_AX_BOOST_BASE_TONUMERICVERSION_req_minor \* 100 \+ $_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor`
+ AS_VAR_SET($1,$_AX_BOOST_BASE_TONUMERICVERSION_RET)
+])
+
+dnl Run the detection of boost should be run only if $want_boost
+AC_DEFUN([_AX_BOOST_BASE_RUNDETECT],[
+ _AX_BOOST_BASE_TONUMERICVERSION(WANT_BOOST_VERSION,[$1])
+ succeeded=no
+
+
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ dnl On 64-bit systems check for system libraries in both lib64 and lib.
+ dnl The former is specified by FHS, but e.g. Debian does not adhere to
+ dnl this (as it rises problems for generic multi-arch support).
+ dnl The last entry in the list is chosen by default when no libraries
+ dnl are found, e.g. when only header-only libraries are installed!
+ AS_CASE([${host_cpu}],
+ [x86_64],[libsubdirs="lib64 libx32 lib lib64"],
+ [ppc64|powerpc64|s390x|sparc64|aarch64|ppc64le|powerpc64le|riscv64],[libsubdirs="lib64 lib lib64"],
+ [libsubdirs="lib"]
+ )
+
+ dnl allow for real multi-arch paths e.g. /usr/lib/x86_64-linux-gnu. Give
+ dnl them priority over the other paths since, if libs are found there, they
+ dnl are almost assuredly the ones desired.
+ AS_CASE([${host_cpu}],
+ [i?86],[multiarch_libsubdir="lib/i386-${host_os}"],
+ [multiarch_libsubdir="lib/${host_cpu}-${host_os}"]
+ )
+
+ dnl first we check the system location for boost libraries
+ dnl this location ist chosen if boost libraries are installed with the --layout=system option
+ dnl or if you install boost with RPM
+ AS_IF([test "x$_AX_BOOST_BASE_boost_path" != "x"],[
+ AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION) includes in "$_AX_BOOST_BASE_boost_path/include"])
+ AS_IF([test -d "$_AX_BOOST_BASE_boost_path/include" && test -r "$_AX_BOOST_BASE_boost_path/include"],[
+ AC_MSG_RESULT([yes])
+ BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path/include"
+ for _AX_BOOST_BASE_boost_path_tmp in $multiarch_libsubdir $libsubdirs; do
+ AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION) lib path in "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp"])
+ AS_IF([test -d "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp" && test -r "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp" ],[
+ AC_MSG_RESULT([yes])
+ BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp";
+ break;
+ ],
+ [AC_MSG_RESULT([no])])
+ done],[
+ AC_MSG_RESULT([no])])
+ ],[
+ if test X"$cross_compiling" = Xyes; then
+ search_libsubdirs=$multiarch_libsubdir
+ else
+ search_libsubdirs="$multiarch_libsubdir $libsubdirs"
+ fi
+ for _AX_BOOST_BASE_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
+ if test -d "$_AX_BOOST_BASE_boost_path_tmp/include/boost" && test -r "$_AX_BOOST_BASE_boost_path_tmp/include/boost" ; then
+ for libsubdir in $search_libsubdirs ; do
+ if ls "$_AX_BOOST_BASE_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
+ done
+ BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path_tmp/$libsubdir"
+ BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path_tmp/include"
+ break;
+ fi
+ done
+ ])
+
+ dnl overwrite ld flags if we have required special directory with
+ dnl --with-boost-libdir parameter
+ AS_IF([test "x$_AX_BOOST_BASE_boost_lib_path" != "x"],
+ [BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_lib_path"])
+
+ AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION)])
+ CPPFLAGS_SAVED="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+ export CPPFLAGS
+
+ LDFLAGS_SAVED="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
+ export LDFLAGS
+
+ AC_REQUIRE([AC_PROG_CXX])
+ AC_LANG_PUSH(C++)
+ AC_COMPILE_IFELSE([_AX_BOOST_BASE_PROGRAM($WANT_BOOST_VERSION)],[
+ AC_MSG_RESULT(yes)
+ succeeded=yes
+ found_system=yes
+ ],[
+ ])
+ AC_LANG_POP([C++])
+
+
+
+ dnl if we found no boost with system layout we search for boost libraries
+ dnl built and installed without the --layout=system option or for a staged(not installed) version
+ if test "x$succeeded" != "xyes" ; then
+ CPPFLAGS="$CPPFLAGS_SAVED"
+ LDFLAGS="$LDFLAGS_SAVED"
+ BOOST_CPPFLAGS=
+ if test -z "$_AX_BOOST_BASE_boost_lib_path" ; then
+ BOOST_LDFLAGS=
+ fi
+ _version=0
+ if test -n "$_AX_BOOST_BASE_boost_path" ; then
+ if test -d "$_AX_BOOST_BASE_boost_path" && test -r "$_AX_BOOST_BASE_boost_path"; then
+ for i in `ls -d $_AX_BOOST_BASE_boost_path/include/boost-* 2>/dev/null`; do
+ _version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
+ V_CHECK=`expr $_version_tmp \> $_version`
+ if test "x$V_CHECK" = "x1" ; then
+ _version=$_version_tmp
+ fi
+ VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
+ BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path/include/boost-$VERSION_UNDERSCORE"
+ done
+ dnl if nothing found search for layout used in Windows distributions
+ if test -z "$BOOST_CPPFLAGS"; then
+ if test -d "$_AX_BOOST_BASE_boost_path/boost" && test -r "$_AX_BOOST_BASE_boost_path/boost"; then
+ BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path"
+ fi
+ fi
+ dnl if we found something and BOOST_LDFLAGS was unset before
+ dnl (because "$_AX_BOOST_BASE_boost_lib_path" = ""), set it here.
+ if test -n "$BOOST_CPPFLAGS" && test -z "$BOOST_LDFLAGS"; then
+ for libsubdir in $libsubdirs ; do
+ if ls "$_AX_BOOST_BASE_boost_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
+ done
+ BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path/$libsubdir"
+ fi
+ fi
+ else
+ if test "x$cross_compiling" != "xyes" ; then
+ for _AX_BOOST_BASE_boost_path in /usr /usr/local /opt /opt/local ; do
+ if test -d "$_AX_BOOST_BASE_boost_path" && test -r "$_AX_BOOST_BASE_boost_path" ; then
+ for i in `ls -d $_AX_BOOST_BASE_boost_path/include/boost-* 2>/dev/null`; do
+ _version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
+ V_CHECK=`expr $_version_tmp \> $_version`
+ if test "x$V_CHECK" = "x1" ; then
+ _version=$_version_tmp
+ best_path=$_AX_BOOST_BASE_boost_path
+ fi
+ done
+ fi
+ done
+
+ VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
+ BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
+ if test -z "$_AX_BOOST_BASE_boost_lib_path" ; then
+ for libsubdir in $libsubdirs ; do
+ if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
+ done
+ BOOST_LDFLAGS="-L$best_path/$libsubdir"
+ fi
+ fi
+
+ if test -n "$BOOST_ROOT" ; then
+ for libsubdir in $libsubdirs ; do
+ if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
+ done
+ if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/$libsubdir" && test -r "$BOOST_ROOT/stage/$libsubdir"; then
+ version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
+ stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
+ stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
+ V_CHECK=`expr $stage_version_shorten \>\= $_version`
+ if test "x$V_CHECK" = "x1" && test -z "$_AX_BOOST_BASE_boost_lib_path" ; then
+ AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
+ BOOST_CPPFLAGS="-I$BOOST_ROOT"
+ BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir"
+ fi
+ fi
+ fi
+ fi
+
+ CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+ export CPPFLAGS
+ LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
+ export LDFLAGS
+
+ AC_LANG_PUSH(C++)
+ AC_COMPILE_IFELSE([_AX_BOOST_BASE_PROGRAM($WANT_BOOST_VERSION)],[
+ AC_MSG_RESULT(yes)
+ succeeded=yes
+ found_system=yes
+ ],[
+ ])
+ AC_LANG_POP([C++])
+ fi
+
+ if test "x$succeeded" != "xyes" ; then
+ if test "x$_version" = "x0" ; then
+ AC_MSG_NOTICE([[We could not detect the boost libraries (version $1 or higher). If you have a staged boost library (still not installed) please specify \$BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in . See http://randspringer.de/boost for more documentation.]])
+ else
+ AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
+ fi
+ # execute ACTION-IF-NOT-FOUND (if present):
+ ifelse([$3], , :, [$3])
+ else
+ AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
+ # execute ACTION-IF-FOUND (if present):
+ ifelse([$2], , :, [$2])
+ fi
+
+ CPPFLAGS="$CPPFLAGS_SAVED"
+ LDFLAGS="$LDFLAGS_SAVED"
+
+])
diff --git a/build-aux/m4/ax_boost_chrono.m4 b/build-aux/m4/ax_boost_chrono.m4
new file mode 100644
index 0000000000..6ea77b9b3e
--- /dev/null
+++ b/build-aux/m4/ax_boost_chrono.m4
@@ -0,0 +1,118 @@
+# ===========================================================================
+# https://www.gnu.org/software/autoconf-archive/ax_boost_chrono.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_BOOST_CHRONO
+#
+# DESCRIPTION
+#
+# Test for Chrono library from the Boost C++ libraries. The macro requires
+# a preceding call to AX_BOOST_BASE. Further documentation is available at
+# .
+#
+# This macro calls:
+#
+# AC_SUBST(BOOST_CHRONO_LIB)
+#
+# And sets:
+#
+# HAVE_BOOST_CHRONO
+#
+# LICENSE
+#
+# Copyright (c) 2012 Xiyue Deng
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 4
+
+AC_DEFUN([AX_BOOST_CHRONO],
+[
+ AC_ARG_WITH([boost-chrono],
+ AS_HELP_STRING([--with-boost-chrono@<:@=special-lib@:>@],
+ [use the Chrono library from boost - it is possible to specify a certain library for the linker
+ e.g. --with-boost-chrono=boost_chrono-gcc-mt ]),
+ [
+ if test "$withval" = "no"; then
+ want_boost="no"
+ elif test "$withval" = "yes"; then
+ want_boost="yes"
+ ax_boost_user_chrono_lib=""
+ else
+ want_boost="yes"
+ ax_boost_user_chrono_lib="$withval"
+ fi
+ ],
+ [want_boost="yes"]
+ )
+
+ if test "x$want_boost" = "xyes"; then
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([AC_CANONICAL_BUILD])
+ CPPFLAGS_SAVED="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+ export CPPFLAGS
+
+ LDFLAGS_SAVED="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
+ export LDFLAGS
+
+ AC_CACHE_CHECK(whether the Boost::Chrono library is available,
+ ax_cv_boost_chrono,
+ [AC_LANG_PUSH([C++])
+ CXXFLAGS_SAVE=$CXXFLAGS
+
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]],
+ [[boost::chrono::system_clock::time_point* time = new boost::chrono::system_clock::time_point; delete time;]])],
+ ax_cv_boost_chrono=yes, ax_cv_boost_chrono=no)
+ CXXFLAGS=$CXXFLAGS_SAVE
+ AC_LANG_POP([C++])
+ ])
+ if test "x$ax_cv_boost_chrono" = "xyes"; then
+ AC_SUBST(BOOST_CPPFLAGS)
+
+ AC_DEFINE(HAVE_BOOST_CHRONO,,[define if the Boost::Chrono library is available])
+ BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
+
+ LDFLAGS_SAVE=$LDFLAGS
+ if test "x$ax_boost_user_chrono_lib" = "x"; then
+ for libextension in `ls $BOOSTLIBDIR/libboost_chrono*.so* $BOOSTLIBDIR/libboost_chrono*.dylib* $BOOSTLIBDIR/libboost_chrono*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_chrono.*\)\.so.*$;\1;' -e 's;^lib\(boost_chrono.*\)\.dylib.*$;\1;' -e 's;^lib\(boost_chrono.*\)\.a.*$;\1;'` ; do
+ ax_lib=${libextension}
+ AC_CHECK_LIB($ax_lib, exit,
+ [BOOST_CHRONO_LIB="-l$ax_lib"; AC_SUBST(BOOST_CHRONO_LIB) link_chrono="yes"; break],
+ [link_chrono="no"])
+ done
+ if test "x$link_chrono" != "xyes"; then
+ for libextension in `ls $BOOSTLIBDIR/boost_chrono*.dll* $BOOSTLIBDIR/boost_chrono*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_chrono.*\)\.dll.*$;\1;' -e 's;^\(boost_chrono.*\)\.a.*$;\1;'` ; do
+ ax_lib=${libextension}
+ AC_CHECK_LIB($ax_lib, exit,
+ [BOOST_CHRONO_LIB="-l$ax_lib"; AC_SUBST(BOOST_CHRONO_LIB) link_chrono="yes"; break],
+ [link_chrono="no"])
+ done
+ fi
+
+ else
+ for ax_lib in $ax_boost_user_chrono_lib boost_chrono-$ax_boost_user_chrono_lib; do
+ AC_CHECK_LIB($ax_lib, exit,
+ [BOOST_CHRONO_LIB="-l$ax_lib"; AC_SUBST(BOOST_CHRONO_LIB) link_chrono="yes"; break],
+ [link_chrono="no"])
+ done
+
+ fi
+ if test "x$ax_lib" = "x"; then
+ AC_MSG_ERROR(Could not find a version of the library!)
+ fi
+ if test "x$link_chrono" = "xno"; then
+ AC_MSG_ERROR(Could not link against $ax_lib !)
+ fi
+ fi
+
+ CPPFLAGS="$CPPFLAGS_SAVED"
+ LDFLAGS="$LDFLAGS_SAVED"
+ fi
+])
diff --git a/build-aux/m4/ax_boost_filesystem.m4 b/build-aux/m4/ax_boost_filesystem.m4
new file mode 100644
index 0000000000..f5c9d56470
--- /dev/null
+++ b/build-aux/m4/ax_boost_filesystem.m4
@@ -0,0 +1,119 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_boost_filesystem.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_BOOST_FILESYSTEM
+#
+# DESCRIPTION
+#
+# Test for Filesystem library from the Boost C++ libraries. The macro
+# requires a preceding call to AX_BOOST_BASE. Further documentation is
+# available at .
+#
+# This macro calls:
+#
+# AC_SUBST(BOOST_FILESYSTEM_LIB)
+#
+# And sets:
+#
+# HAVE_BOOST_FILESYSTEM
+#
+# LICENSE
+#
+# Copyright (c) 2009 Thomas Porschberg
+# Copyright (c) 2009 Michael Tindal
+# Copyright (c) 2009 Roman Rybalko
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 26
+
+AC_DEFUN([AX_BOOST_FILESYSTEM],
+[
+ AC_ARG_WITH([boost-filesystem],
+ AS_HELP_STRING([--with-boost-filesystem@<:@=special-lib@:>@],
+ [use the Filesystem library from boost - it is possible to specify a certain library for the linker
+ e.g. --with-boost-filesystem=boost_filesystem-gcc-mt ]),
+ [
+ if test "$withval" = "no"; then
+ want_boost="no"
+ elif test "$withval" = "yes"; then
+ want_boost="yes"
+ ax_boost_user_filesystem_lib=""
+ else
+ want_boost="yes"
+ ax_boost_user_filesystem_lib="$withval"
+ fi
+ ],
+ [want_boost="yes"]
+ )
+
+ if test "x$want_boost" = "xyes"; then
+ AC_REQUIRE([AC_PROG_CC])
+ CPPFLAGS_SAVED="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+ export CPPFLAGS
+
+ LDFLAGS_SAVED="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
+ export LDFLAGS
+
+ LIBS_SAVED=$LIBS
+ LIBS="$LIBS $BOOST_SYSTEM_LIB"
+ export LIBS
+
+ AC_CACHE_CHECK(whether the Boost::Filesystem library is available,
+ ax_cv_boost_filesystem,
+ [AC_LANG_PUSH([C++])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]],
+ [[using namespace boost::filesystem;
+ path my_path( "foo/bar/data.txt" );
+ return 0;]])],
+ ax_cv_boost_filesystem=yes, ax_cv_boost_filesystem=no)
+ AC_LANG_POP([C++])
+ ])
+ if test "x$ax_cv_boost_filesystem" = "xyes"; then
+ AC_DEFINE(HAVE_BOOST_FILESYSTEM,,[define if the Boost::Filesystem library is available])
+ BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
+ ax_lib=
+ if test "x$ax_boost_user_filesystem_lib" = "x"; then
+ for libextension in `ls -r $BOOSTLIBDIR/libboost_filesystem* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'` ; do
+ ax_lib=${libextension}
+ AC_CHECK_LIB($ax_lib, exit,
+ [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break],
+ [link_filesystem="no"])
+ done
+ if test "x$link_filesystem" != "xyes"; then
+ for libextension in `ls -r $BOOSTLIBDIR/boost_filesystem* 2>/dev/null | sed 's,.*/,,' | sed -e 's,\..*,,'` ; do
+ ax_lib=${libextension}
+ AC_CHECK_LIB($ax_lib, exit,
+ [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break],
+ [link_filesystem="no"])
+ done
+ fi
+ else
+ for ax_lib in $ax_boost_user_filesystem_lib boost_filesystem-$ax_boost_user_filesystem_lib; do
+ AC_CHECK_LIB($ax_lib, exit,
+ [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break],
+ [link_filesystem="no"])
+ done
+
+ fi
+ if test "x$ax_lib" = "x"; then
+ AC_MSG_ERROR(Could not find a version of the boost_filesystem library!)
+ fi
+ if test "x$link_filesystem" != "xyes"; then
+ AC_MSG_ERROR(Could not link against $ax_lib !)
+ fi
+ fi
+
+ CPPFLAGS="$CPPFLAGS_SAVED"
+ LDFLAGS="$LDFLAGS_SAVED"
+ LIBS="$LIBS_SAVED"
+ fi
+])
diff --git a/build-aux/m4/ax_boost_system.m4 b/build-aux/m4/ax_boost_system.m4
new file mode 100644
index 0000000000..207d7be8de
--- /dev/null
+++ b/build-aux/m4/ax_boost_system.m4
@@ -0,0 +1,121 @@
+# ===========================================================================
+# https://www.gnu.org/software/autoconf-archive/ax_boost_system.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_BOOST_SYSTEM
+#
+# DESCRIPTION
+#
+# Test for System library from the Boost C++ libraries. The macro requires
+# a preceding call to AX_BOOST_BASE. Further documentation is available at
+# .
+#
+# This macro calls:
+#
+# AC_SUBST(BOOST_SYSTEM_LIB)
+#
+# And sets:
+#
+# HAVE_BOOST_SYSTEM
+#
+# LICENSE
+#
+# Copyright (c) 2008 Thomas Porschberg
+# Copyright (c) 2008 Michael Tindal
+# Copyright (c) 2008 Daniel Casimiro
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 19
+
+AC_DEFUN([AX_BOOST_SYSTEM],
+[
+ AC_ARG_WITH([boost-system],
+ AS_HELP_STRING([--with-boost-system@<:@=special-lib@:>@],
+ [use the System library from boost - it is possible to specify a certain library for the linker
+ e.g. --with-boost-system=boost_system-gcc-mt ]),
+ [
+ if test "$withval" = "no"; then
+ want_boost="no"
+ elif test "$withval" = "yes"; then
+ want_boost="yes"
+ ax_boost_user_system_lib=""
+ else
+ want_boost="yes"
+ ax_boost_user_system_lib="$withval"
+ fi
+ ],
+ [want_boost="yes"]
+ )
+
+ if test "x$want_boost" = "xyes"; then
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([AC_CANONICAL_BUILD])
+ CPPFLAGS_SAVED="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+ export CPPFLAGS
+
+ LDFLAGS_SAVED="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
+ export LDFLAGS
+
+ AC_CACHE_CHECK(whether the Boost::System library is available,
+ ax_cv_boost_system,
+ [AC_LANG_PUSH([C++])
+ CXXFLAGS_SAVE=$CXXFLAGS
+ CXXFLAGS=
+
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]],
+ [[boost::system::error_category *a = 0;]])],
+ ax_cv_boost_system=yes, ax_cv_boost_system=no)
+ CXXFLAGS=$CXXFLAGS_SAVE
+ AC_LANG_POP([C++])
+ ])
+ if test "x$ax_cv_boost_system" = "xyes"; then
+ AC_SUBST(BOOST_CPPFLAGS)
+
+ AC_DEFINE(HAVE_BOOST_SYSTEM,,[define if the Boost::System library is available])
+ BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
+
+ LDFLAGS_SAVE=$LDFLAGS
+ if test "x$ax_boost_user_system_lib" = "x"; then
+ for libextension in `ls -r $BOOSTLIBDIR/libboost_system* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'` ; do
+ ax_lib=${libextension}
+ AC_CHECK_LIB($ax_lib, exit,
+ [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break],
+ [link_system="no"])
+ done
+ if test "x$link_system" != "xyes"; then
+ for libextension in `ls -r $BOOSTLIBDIR/boost_system* 2>/dev/null | sed 's,.*/,,' | sed -e 's,\..*,,'` ; do
+ ax_lib=${libextension}
+ AC_CHECK_LIB($ax_lib, exit,
+ [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break],
+ [link_system="no"])
+ done
+ fi
+
+ else
+ for ax_lib in $ax_boost_user_system_lib boost_system-$ax_boost_user_system_lib; do
+ AC_CHECK_LIB($ax_lib, exit,
+ [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break],
+ [link_system="no"])
+ done
+
+ fi
+ if test "x$ax_lib" = "x"; then
+ AC_MSG_ERROR(Could not find a version of the library!)
+ fi
+ if test "x$link_system" = "xno"; then
+ AC_MSG_ERROR(Could not link against $ax_lib !)
+ fi
+ fi
+
+ CPPFLAGS="$CPPFLAGS_SAVED"
+ LDFLAGS="$LDFLAGS_SAVED"
+ fi
+])
diff --git a/build-aux/m4/ax_boost_thread.m4 b/build-aux/m4/ax_boost_thread.m4
new file mode 100644
index 0000000000..9f0bd0b23c
--- /dev/null
+++ b/build-aux/m4/ax_boost_thread.m4
@@ -0,0 +1,150 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_boost_thread.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_BOOST_THREAD
+#
+# DESCRIPTION
+#
+# Test for Thread library from the Boost C++ libraries. The macro requires
+# a preceding call to AX_BOOST_BASE. Further documentation is available at
+# .
+#
+# This macro calls:
+#
+# AC_SUBST(BOOST_THREAD_LIB)
+#
+# And sets:
+#
+# HAVE_BOOST_THREAD
+#
+# LICENSE
+#
+# Copyright (c) 2009 Thomas Porschberg
+# Copyright (c) 2009 Michael Tindal
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 27
+
+AC_DEFUN([AX_BOOST_THREAD],
+[
+ AC_ARG_WITH([boost-thread],
+ AS_HELP_STRING([--with-boost-thread@<:@=special-lib@:>@],
+ [use the Thread library from boost - it is possible to specify a certain library for the linker
+ e.g. --with-boost-thread=boost_thread-gcc-mt ]),
+ [
+ if test "$withval" = "no"; then
+ want_boost="no"
+ elif test "$withval" = "yes"; then
+ want_boost="yes"
+ ax_boost_user_thread_lib=""
+ else
+ want_boost="yes"
+ ax_boost_user_thread_lib="$withval"
+ fi
+ ],
+ [want_boost="yes"]
+ )
+
+ if test "x$want_boost" = "xyes"; then
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([AC_CANONICAL_BUILD])
+ CPPFLAGS_SAVED="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+ export CPPFLAGS
+
+ LDFLAGS_SAVED="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
+ export LDFLAGS
+
+ AC_CACHE_CHECK(whether the Boost::Thread library is available,
+ ax_cv_boost_thread,
+ [AC_LANG_PUSH([C++])
+ CXXFLAGS_SAVE=$CXXFLAGS
+
+ if test "x$host_os" = "xsolaris" ; then
+ CXXFLAGS="-pthreads $CXXFLAGS"
+ elif test "x$host_os" = "xmingw32" ; then
+ CXXFLAGS="-mthreads $CXXFLAGS"
+ else
+ CXXFLAGS="-pthread $CXXFLAGS"
+ fi
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]],
+ [[boost::thread_group thrds;
+ return 0;]])],
+ ax_cv_boost_thread=yes, ax_cv_boost_thread=no)
+ CXXFLAGS=$CXXFLAGS_SAVE
+ AC_LANG_POP([C++])
+ ])
+ if test "x$ax_cv_boost_thread" = "xyes"; then
+ if test "x$host_os" = "xsolaris" ; then
+ BOOST_CPPFLAGS="-pthreads $BOOST_CPPFLAGS"
+ elif test "x$host_os" = "xmingw32" ; then
+ BOOST_CPPFLAGS="-mthreads $BOOST_CPPFLAGS"
+ else
+ BOOST_CPPFLAGS="-pthread $BOOST_CPPFLAGS"
+ fi
+
+ AC_SUBST(BOOST_CPPFLAGS)
+
+ AC_DEFINE(HAVE_BOOST_THREAD,,[define if the Boost::Thread library is available])
+ BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
+
+ LDFLAGS_SAVE=$LDFLAGS
+ case "x$host_os" in
+ *bsd* )
+ LDFLAGS="-pthread $LDFLAGS"
+ break;
+ ;;
+ esac
+ if test "x$ax_boost_user_thread_lib" = "x"; then
+ ax_lib=
+ for libextension in `ls -r $BOOSTLIBDIR/libboost_thread* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'`; do
+ ax_lib=${libextension}
+ AC_CHECK_LIB($ax_lib, exit,
+ [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break],
+ [link_thread="no"])
+ done
+ if test "x$link_thread" != "xyes"; then
+ for libextension in `ls -r $BOOSTLIBDIR/boost_thread* 2>/dev/null | sed 's,.*/,,' | sed 's,\..*,,'`; do
+ ax_lib=${libextension}
+ AC_CHECK_LIB($ax_lib, exit,
+ [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break],
+ [link_thread="no"])
+ done
+ fi
+
+ else
+ for ax_lib in $ax_boost_user_thread_lib boost_thread-$ax_boost_user_thread_lib; do
+ AC_CHECK_LIB($ax_lib, exit,
+ [BOOST_THREAD_LIB="-l$ax_lib"; AC_SUBST(BOOST_THREAD_LIB) link_thread="yes"; break],
+ [link_thread="no"])
+ done
+
+ fi
+ if test "x$ax_lib" = "x"; then
+ AC_MSG_ERROR(Could not find a version of the boost_thread library!)
+ fi
+ if test "x$link_thread" = "xno"; then
+ AC_MSG_ERROR(Could not link against $ax_lib !)
+ else
+ case "x$host_os" in
+ *bsd* )
+ BOOST_LDFLAGS="-pthread $BOOST_LDFLAGS"
+ break;
+ ;;
+ esac
+
+ fi
+ fi
+
+ CPPFLAGS="$CPPFLAGS_SAVED"
+ LDFLAGS="$LDFLAGS_SAVED"
+ fi
+])
diff --git a/build-aux/m4/ax_boost_unit_test_framework.m4 b/build-aux/m4/ax_boost_unit_test_framework.m4
new file mode 100644
index 0000000000..3d8e93e964
--- /dev/null
+++ b/build-aux/m4/ax_boost_unit_test_framework.m4
@@ -0,0 +1,137 @@
+# =================================================================================
+# https://www.gnu.org/software/autoconf-archive/ax_boost_unit_test_framework.html
+# =================================================================================
+#
+# SYNOPSIS
+#
+# AX_BOOST_UNIT_TEST_FRAMEWORK
+#
+# DESCRIPTION
+#
+# Test for Unit_Test_Framework library from the Boost C++ libraries. The
+# macro requires a preceding call to AX_BOOST_BASE. Further documentation
+# is available at .
+#
+# This macro calls:
+#
+# AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
+#
+# And sets:
+#
+# HAVE_BOOST_UNIT_TEST_FRAMEWORK
+#
+# LICENSE
+#
+# Copyright (c) 2008 Thomas Porschberg
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 21
+
+AC_DEFUN([AX_BOOST_UNIT_TEST_FRAMEWORK],
+[
+ AC_ARG_WITH([boost-unit-test-framework],
+ AS_HELP_STRING([--with-boost-unit-test-framework@<:@=special-lib@:>@],
+ [use the Unit_Test_Framework library from boost - it is possible to specify a certain library for the linker
+ e.g. --with-boost-unit-test-framework=boost_unit_test_framework-gcc ]),
+ [
+ if test "$withval" = "no"; then
+ want_boost="no"
+ elif test "$withval" = "yes"; then
+ want_boost="yes"
+ ax_boost_user_unit_test_framework_lib=""
+ else
+ want_boost="yes"
+ ax_boost_user_unit_test_framework_lib="$withval"
+ fi
+ ],
+ [want_boost="yes"]
+ )
+
+ if test "x$want_boost" = "xyes"; then
+ AC_REQUIRE([AC_PROG_CC])
+ CPPFLAGS_SAVED="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+ export CPPFLAGS
+
+ LDFLAGS_SAVED="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
+ export LDFLAGS
+
+ AC_CACHE_CHECK(whether the Boost::Unit_Test_Framework library is available,
+ ax_cv_boost_unit_test_framework,
+ [AC_LANG_PUSH([C++])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]],
+ [[using boost::unit_test::test_suite;
+ test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" ); if (test == NULL) { return 1; } else { return 0; }]])],
+ ax_cv_boost_unit_test_framework=yes, ax_cv_boost_unit_test_framework=no)
+ AC_LANG_POP([C++])
+ ])
+ if test "x$ax_cv_boost_unit_test_framework" = "xyes"; then
+ AC_DEFINE(HAVE_BOOST_UNIT_TEST_FRAMEWORK,,[define if the Boost::Unit_Test_Framework library is available])
+ BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
+
+ if test "x$ax_boost_user_unit_test_framework_lib" = "x"; then
+ saved_ldflags="${LDFLAGS}"
+ for monitor_library in `ls $BOOSTLIBDIR/libboost_unit_test_framework*.so* $BOOSTLIBDIR/libboost_unit_test_framework*.dylib* $BOOSTLIBDIR/libboost_unit_test_framework*.a* 2>/dev/null` ; do
+ if test -r $monitor_library ; then
+ libextension=`echo $monitor_library | sed 's,.*/,,' | sed -e 's;^lib\(boost_unit_test_framework.*\)\.so.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.dylib.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.a.*$;\1;'`
+ ax_lib=${libextension}
+ link_unit_test_framework="yes"
+ else
+ link_unit_test_framework="no"
+ fi
+
+ if test "x$link_unit_test_framework" = "xyes"; then
+ BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"
+ AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
+ break
+ fi
+ done
+ if test "x$link_unit_test_framework" != "xyes"; then
+ for libextension in `ls $BOOSTLIBDIR/boost_unit_test_framework*.dll* $BOOSTLIBDIR/boost_unit_test_framework*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_unit_test_framework.*\)\.dll.*$;\1;' -e 's;^\(boost_unit_test_framework.*\)\.a.*$;\1;'` ; do
+ ax_lib=${libextension}
+ AC_CHECK_LIB($ax_lib, exit,
+ [BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"; AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) link_unit_test_framework="yes"; break],
+ [link_unit_test_framework="no"])
+ done
+ fi
+ else
+ link_unit_test_framework="no"
+ saved_ldflags="${LDFLAGS}"
+ for ax_lib in boost_unit_test_framework-$ax_boost_user_unit_test_framework_lib $ax_boost_user_unit_test_framework_lib ; do
+ if test "x$link_unit_test_framework" = "xyes"; then
+ break;
+ fi
+ for unittest_library in `ls $BOOSTLIBDIR/lib${ax_lib}.so* $BOOSTLIBDIR/lib${ax_lib}.a* 2>/dev/null` ; do
+ if test -r $unittest_library ; then
+ libextension=`echo $unittest_library | sed 's,.*/,,' | sed -e 's;^lib\(boost_unit_test_framework.*\)\.so.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.a*$;\1;'`
+ ax_lib=${libextension}
+ link_unit_test_framework="yes"
+ else
+ link_unit_test_framework="no"
+ fi
+
+ if test "x$link_unit_test_framework" = "xyes"; then
+ BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"
+ AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB)
+ break
+ fi
+ done
+ done
+ fi
+ if test "x$ax_lib" = "x"; then
+ AC_MSG_ERROR(Could not find a version of the library!)
+ fi
+ if test "x$link_unit_test_framework" != "xyes"; then
+ AC_MSG_ERROR(Could not link against $ax_lib !)
+ fi
+ fi
+
+ CPPFLAGS="$CPPFLAGS_SAVED"
+ LDFLAGS="$LDFLAGS_SAVED"
+ fi
+])
diff --git a/build-aux/m4/ax_check_compile_flag.m4 b/build-aux/m4/ax_check_compile_flag.m4
new file mode 100644
index 0000000000..ca3639715e
--- /dev/null
+++ b/build-aux/m4/ax_check_compile_flag.m4
@@ -0,0 +1,74 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
+#
+# DESCRIPTION
+#
+# Check whether the given FLAG works with the current language's compiler
+# or gives an error. (Warnings, however, are ignored)
+#
+# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
+# success/failure.
+#
+# If EXTRA-FLAGS is defined, it is added to the current language's default
+# flags (e.g. CFLAGS) when the check is done. The check is thus made with
+# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
+# force the compiler to issue an error when a bad flag is given.
+#
+# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
+#
+# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
+# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Guido U. Draheim
+# Copyright (c) 2011 Maarten Bosmans
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 4
+
+AC_DEFUN([AX_CHECK_COMPILE_FLAG],
+[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
+AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
+AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
+ ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
+ _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
+ AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
+ [AS_VAR_SET(CACHEVAR,[yes])],
+ [AS_VAR_SET(CACHEVAR,[no])])
+ _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
+AS_VAR_IF(CACHEVAR,yes,
+ [m4_default([$2], :)],
+ [m4_default([$3], :)])
+AS_VAR_POPDEF([CACHEVAR])dnl
+])dnl AX_CHECK_COMPILE_FLAGS
diff --git a/build-aux/m4/ax_check_link_flag.m4 b/build-aux/m4/ax_check_link_flag.m4
new file mode 100644
index 0000000000..eb01a6ce13
--- /dev/null
+++ b/build-aux/m4/ax_check_link_flag.m4
@@ -0,0 +1,74 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_CHECK_LINK_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
+#
+# DESCRIPTION
+#
+# Check whether the given FLAG works with the linker or gives an error.
+# (Warnings, however, are ignored)
+#
+# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
+# success/failure.
+#
+# If EXTRA-FLAGS is defined, it is added to the linker's default flags
+# when the check is done. The check is thus made with the flags: "LDFLAGS
+# EXTRA-FLAGS FLAG". This can for example be used to force the linker to
+# issue an error when a bad flag is given.
+#
+# INPUT gives an alternative input source to AC_LINK_IFELSE.
+#
+# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
+# macro in sync with AX_CHECK_{PREPROC,COMPILE}_FLAG.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Guido U. Draheim
+# Copyright (c) 2011 Maarten Bosmans
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 4
+
+AC_DEFUN([AX_CHECK_LINK_FLAG],
+[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
+AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_ldflags_$4_$1])dnl
+AC_CACHE_CHECK([whether the linker accepts $1], CACHEVAR, [
+ ax_check_save_flags=$LDFLAGS
+ LDFLAGS="$LDFLAGS $4 $1"
+ AC_LINK_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
+ [AS_VAR_SET(CACHEVAR,[yes])],
+ [AS_VAR_SET(CACHEVAR,[no])])
+ LDFLAGS=$ax_check_save_flags])
+AS_VAR_IF(CACHEVAR,yes,
+ [m4_default([$2], :)],
+ [m4_default([$3], :)])
+AS_VAR_POPDEF([CACHEVAR])dnl
+])dnl AX_CHECK_LINK_FLAGS
diff --git a/build-aux/m4/ax_check_preproc_flag.m4 b/build-aux/m4/ax_check_preproc_flag.m4
new file mode 100644
index 0000000000..ca1d5ee2b6
--- /dev/null
+++ b/build-aux/m4/ax_check_preproc_flag.m4
@@ -0,0 +1,74 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_check_preproc_flag.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_CHECK_PREPROC_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
+#
+# DESCRIPTION
+#
+# Check whether the given FLAG works with the current language's
+# preprocessor or gives an error. (Warnings, however, are ignored)
+#
+# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
+# success/failure.
+#
+# If EXTRA-FLAGS is defined, it is added to the preprocessor's default
+# flags when the check is done. The check is thus made with the flags:
+# "CPPFLAGS EXTRA-FLAGS FLAG". This can for example be used to force the
+# preprocessor to issue an error when a bad flag is given.
+#
+# INPUT gives an alternative input source to AC_PREPROC_IFELSE.
+#
+# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
+# macro in sync with AX_CHECK_{COMPILE,LINK}_FLAG.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Guido U. Draheim
+# Copyright (c) 2011 Maarten Bosmans
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 4
+
+AC_DEFUN([AX_CHECK_PREPROC_FLAG],
+[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
+AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]cppflags_$4_$1])dnl
+AC_CACHE_CHECK([whether _AC_LANG preprocessor accepts $1], CACHEVAR, [
+ ax_check_save_flags=$CPPFLAGS
+ CPPFLAGS="$CPPFLAGS $4 $1"
+ AC_PREPROC_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
+ [AS_VAR_SET(CACHEVAR,[yes])],
+ [AS_VAR_SET(CACHEVAR,[no])])
+ CPPFLAGS=$ax_check_save_flags])
+AS_VAR_IF(CACHEVAR,yes,
+ [m4_default([$2], :)],
+ [m4_default([$3], :)])
+AS_VAR_POPDEF([CACHEVAR])dnl
+])dnl AX_CHECK_PREPROC_FLAGS
diff --git a/build-aux/m4/ax_cxx_compile_stdcxx.m4 b/build-aux/m4/ax_cxx_compile_stdcxx.m4
new file mode 100644
index 0000000000..f147cee3b1
--- /dev/null
+++ b/build-aux/m4/ax_cxx_compile_stdcxx.m4
@@ -0,0 +1,568 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional])
+#
+# DESCRIPTION
+#
+# Check for baseline language coverage in the compiler for the specified
+# version of the C++ standard. If necessary, add switches to CXX and
+# CXXCPP to enable support. VERSION may be '11' (for the C++11 standard)
+# or '14' (for the C++14 standard).
+#
+# The second argument, if specified, indicates whether you insist on an
+# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
+# -std=c++11). If neither is specified, you get whatever works, with
+# preference for an extended mode.
+#
+# The third argument, if specified 'mandatory' or if left unspecified,
+# indicates that baseline support for the specified C++ standard is
+# required and that the macro should error out if no mode with that
+# support is found. If specified 'optional', then configuration proceeds
+# regardless, after defining HAVE_CXX${VERSION} if and only if a
+# supporting mode is found.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Benjamin Kosnik
+# Copyright (c) 2012 Zack Weinberg
+# Copyright (c) 2013 Roy Stogner
+# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov
+# Copyright (c) 2015 Paul Norman
+# Copyright (c) 2015 Moritz Klammler
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 4
+
+dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
+dnl (serial version number 13).
+
+AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
+ m4_if([$1], [11], [],
+ [$1], [14], [],
+ [$1], [17], [m4_fatal([support for C++17 not yet implemented in AX_CXX_COMPILE_STDCXX])],
+ [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
+ m4_if([$2], [], [],
+ [$2], [ext], [],
+ [$2], [noext], [],
+ [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl
+ m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true],
+ [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true],
+ [$3], [optional], [ax_cxx_compile_cxx$1_required=false],
+ [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])])
+ m4_if([$4], [], [ax_cxx_compile_cxx$1_try_default=true],
+ [$4], [default], [ax_cxx_compile_cxx$1_try_default=true],
+ [$4], [nodefault], [ax_cxx_compile_cxx$1_try_default=false],
+ [m4_fatal([invalid fourth argument `$4' to AX_CXX_COMPILE_STDCXX])])
+ AC_LANG_PUSH([C++])dnl
+ ac_success=no
+
+ m4_if([$4], [nodefault], [], [dnl
+ AC_CACHE_CHECK(whether $CXX supports C++$1 features by default,
+ ax_cv_cxx_compile_cxx$1,
+ [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
+ [ax_cv_cxx_compile_cxx$1=yes],
+ [ax_cv_cxx_compile_cxx$1=no])])
+ if test x$ax_cv_cxx_compile_cxx$1 = xyes; then
+ ac_success=yes
+ fi])
+
+ m4_if([$2], [noext], [], [dnl
+ if test x$ac_success = xno; then
+ for switch in -std=gnu++$1 -std=gnu++0x; do
+ cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
+ AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
+ $cachevar,
+ [ac_save_CXX="$CXX"
+ CXX="$CXX $switch"
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
+ [eval $cachevar=yes],
+ [eval $cachevar=no])
+ CXX="$ac_save_CXX"])
+ if eval test x\$$cachevar = xyes; then
+ CXX="$CXX $switch"
+ if test -n "$CXXCPP" ; then
+ CXXCPP="$CXXCPP $switch"
+ fi
+ ac_success=yes
+ break
+ fi
+ done
+ fi])
+
+ m4_if([$2], [ext], [], [dnl
+ if test x$ac_success = xno; then
+ dnl HP's aCC needs +std=c++11 according to:
+ dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
+ dnl Cray's crayCC needs "-h std=c++11"
+ for switch in -std=c++$1 -std=c++0x +std=c++$1 "-h std=c++$1"; do
+ cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
+ AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
+ $cachevar,
+ [ac_save_CXX="$CXX"
+ CXX="$CXX $switch"
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
+ [eval $cachevar=yes],
+ [eval $cachevar=no])
+ CXX="$ac_save_CXX"])
+ if eval test x\$$cachevar = xyes; then
+ CXX="$CXX $switch"
+ if test -n "$CXXCPP" ; then
+ CXXCPP="$CXXCPP $switch"
+ fi
+ ac_success=yes
+ break
+ fi
+ done
+ fi])
+ AC_LANG_POP([C++])
+ if test x$ax_cxx_compile_cxx$1_required = xtrue; then
+ if test x$ac_success = xno; then
+ AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.])
+ fi
+ fi
+ if test x$ac_success = xno; then
+ HAVE_CXX$1=0
+ AC_MSG_NOTICE([No compiler with C++$1 support was found])
+ else
+ HAVE_CXX$1=1
+ AC_DEFINE(HAVE_CXX$1,1,
+ [define if the compiler supports basic C++$1 syntax])
+ fi
+ AC_SUBST(HAVE_CXX$1)
+])
+
+
+dnl Test body for checking C++11 support
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
+)
+
+
+dnl Test body for checking C++14 support
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
+)
+
+
+dnl Tests for new features in C++11
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
+
+// If the compiler admits that it is not ready for C++11, why torture it?
+// Hopefully, this will speed up the test.
+
+#ifndef __cplusplus
+
+#error "This is not a C++ compiler"
+
+#elif __cplusplus < 201103L
+
+#error "This is not a C++11 compiler"
+
+#else
+
+namespace cxx11
+{
+
+ namespace test_static_assert
+ {
+
+ template
+ struct check
+ {
+ static_assert(sizeof(int) <= sizeof(T), "not big enough");
+ };
+
+ }
+
+ namespace test_final_override
+ {
+
+ struct Base
+ {
+ virtual void f() {}
+ };
+
+ struct Derived : public Base
+ {
+ virtual void f() override {}
+ };
+
+ }
+
+ namespace test_double_right_angle_brackets
+ {
+
+ template < typename T >
+ struct check {};
+
+ typedef check single_type;
+ typedef check> double_type;
+ typedef check>> triple_type;
+ typedef check>>> quadruple_type;
+
+ }
+
+ namespace test_decltype
+ {
+
+ int
+ f()
+ {
+ int a = 1;
+ decltype(a) b = 2;
+ return a + b;
+ }
+
+ }
+
+ namespace test_type_deduction
+ {
+
+ template < typename T1, typename T2 >
+ struct is_same
+ {
+ static const bool value = false;
+ };
+
+ template < typename T >
+ struct is_same
+ {
+ static const bool value = true;
+ };
+
+ template < typename T1, typename T2 >
+ auto
+ add(T1 a1, T2 a2) -> decltype(a1 + a2)
+ {
+ return a1 + a2;
+ }
+
+ int
+ test(const int c, volatile int v)
+ {
+ static_assert(is_same::value == true, "");
+ static_assert(is_same::value == false, "");
+ static_assert(is_same::value == false, "");
+ auto ac = c;
+ auto av = v;
+ auto sumi = ac + av + 'x';
+ auto sumf = ac + av + 1.0;
+ static_assert(is_same::value == true, "");
+ static_assert(is_same::value == true, "");
+ static_assert(is_same::value == true, "");
+ static_assert(is_same::value == false, "");
+ static_assert(is_same::value == true, "");
+ return (sumf > 0.0) ? sumi : add(c, v);
+ }
+
+ }
+
+ namespace test_noexcept
+ {
+
+ int f() { return 0; }
+ int g() noexcept { return 0; }
+
+ static_assert(noexcept(f()) == false, "");
+ static_assert(noexcept(g()) == true, "");
+
+ }
+
+ namespace test_constexpr
+ {
+
+ template < typename CharT >
+ unsigned long constexpr
+ strlen_c_r(const CharT *const s, const unsigned long acc) noexcept
+ {
+ return *s ? strlen_c_r(s + 1, acc + 1) : acc;
+ }
+
+ template < typename CharT >
+ unsigned long constexpr
+ strlen_c(const CharT *const s) noexcept
+ {
+ return strlen_c_r(s, 0UL);
+ }
+
+ static_assert(strlen_c("") == 0UL, "");
+ static_assert(strlen_c("1") == 1UL, "");
+ static_assert(strlen_c("example") == 7UL, "");
+ static_assert(strlen_c("another\0example") == 7UL, "");
+
+ }
+
+ namespace test_rvalue_references
+ {
+
+ template < int N >
+ struct answer
+ {
+ static constexpr int value = N;
+ };
+
+ answer<1> f(int&) { return answer<1>(); }
+ answer<2> f(const int&) { return answer<2>(); }
+ answer<3> f(int&&) { return answer<3>(); }
+
+ void
+ test()
+ {
+ int i = 0;
+ const int c = 0;
+ static_assert(decltype(f(i))::value == 1, "");
+ static_assert(decltype(f(c))::value == 2, "");
+ static_assert(decltype(f(0))::value == 3, "");
+ }
+
+ }
+
+ namespace test_uniform_initialization
+ {
+
+ struct test
+ {
+ static const int zero {};
+ static const int one {1};
+ };
+
+ static_assert(test::zero == 0, "");
+ static_assert(test::one == 1, "");
+
+ }
+
+ namespace test_lambdas
+ {
+
+ void
+ test1()
+ {
+ auto lambda1 = [](){};
+ auto lambda2 = lambda1;
+ lambda1();
+ lambda2();
+ }
+
+ int
+ test2()
+ {
+ auto a = [](int i, int j){ return i + j; }(1, 2);
+ auto b = []() -> int { return '0'; }();
+ auto c = [=](){ return a + b; }();
+ auto d = [&](){ return c; }();
+ auto e = [a, &b](int x) mutable {
+ const auto identity = [](int y){ return y; };
+ for (auto i = 0; i < a; ++i)
+ a += b--;
+ return x + identity(a + b);
+ }(0);
+ return a + b + c + d + e;
+ }
+
+ int
+ test3()
+ {
+ const auto nullary = [](){ return 0; };
+ const auto unary = [](int x){ return x; };
+ using nullary_t = decltype(nullary);
+ using unary_t = decltype(unary);
+ const auto higher1st = [](nullary_t f){ return f(); };
+ const auto higher2nd = [unary](nullary_t f1){
+ return [unary, f1](unary_t f2){ return f2(unary(f1())); };
+ };
+ return higher1st(nullary) + higher2nd(nullary)(unary);
+ }
+
+ }
+
+ namespace test_variadic_templates
+ {
+
+ template
+ struct sum;
+
+ template
+ struct sum
+ {
+ static constexpr auto value = N0 + sum::value;
+ };
+
+ template <>
+ struct sum<>
+ {
+ static constexpr auto value = 0;
+ };
+
+ static_assert(sum<>::value == 0, "");
+ static_assert(sum<1>::value == 1, "");
+ static_assert(sum<23>::value == 23, "");
+ static_assert(sum<1, 2>::value == 3, "");
+ static_assert(sum<5, 5, 11>::value == 21, "");
+ static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, "");
+
+ }
+
+ // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae
+ // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function
+ // because of this.
+ namespace test_template_alias_sfinae
+ {
+
+ struct foo {};
+
+ template
+ using member = typename T::member_type;
+
+ template
+ void func(...) {}
+
+ template
+ void func(member*) {}
+
+ void test();
+
+ void test() { func(0); }
+
+ }
+
+} // namespace cxx11
+
+#endif // __cplusplus >= 201103L
+
+]])
+
+
+dnl Tests for new features in C++14
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
+
+// If the compiler admits that it is not ready for C++14, why torture it?
+// Hopefully, this will speed up the test.
+
+#ifndef __cplusplus
+
+#error "This is not a C++ compiler"
+
+#elif __cplusplus < 201402L
+
+#error "This is not a C++14 compiler"
+
+#else
+
+namespace cxx14
+{
+
+ namespace test_polymorphic_lambdas
+ {
+
+ int
+ test()
+ {
+ const auto lambda = [](auto&&... args){
+ const auto istiny = [](auto x){
+ return (sizeof(x) == 1UL) ? 1 : 0;
+ };
+ const int aretiny[] = { istiny(args)... };
+ return aretiny[0];
+ };
+ return lambda(1, 1L, 1.0f, '1');
+ }
+
+ }
+
+ namespace test_binary_literals
+ {
+
+ constexpr auto ivii = 0b0000000000101010;
+ static_assert(ivii == 42, "wrong value");
+
+ }
+
+ namespace test_generalized_constexpr
+ {
+
+ template < typename CharT >
+ constexpr unsigned long
+ strlen_c(const CharT *const s) noexcept
+ {
+ auto length = 0UL;
+ for (auto p = s; *p; ++p)
+ ++length;
+ return length;
+ }
+
+ static_assert(strlen_c("") == 0UL, "");
+ static_assert(strlen_c("x") == 1UL, "");
+ static_assert(strlen_c("test") == 4UL, "");
+ static_assert(strlen_c("another\0test") == 7UL, "");
+
+ }
+
+ namespace test_lambda_init_capture
+ {
+
+ int
+ test()
+ {
+ auto x = 0;
+ const auto lambda1 = [a = x](int b){ return a + b; };
+ const auto lambda2 = [a = lambda1(x)](){ return a; };
+ return lambda2();
+ }
+
+ }
+
+ namespace test_digit_seperators
+ {
+
+ constexpr auto ten_million = 100'000'000;
+ static_assert(ten_million == 100000000, "");
+
+ }
+
+ namespace test_return_type_deduction
+ {
+
+ auto f(int& x) { return x; }
+ decltype(auto) g(int& x) { return x; }
+
+ template < typename T1, typename T2 >
+ struct is_same
+ {
+ static constexpr auto value = false;
+ };
+
+ template < typename T >
+ struct is_same
+ {
+ static constexpr auto value = true;
+ };
+
+ int
+ test()
+ {
+ auto x = 0;
+ static_assert(is_same::value, "");
+ static_assert(is_same::value, "");
+ return x;
+ }
+
+ }
+
+} // namespace cxx14
+
+#endif // __cplusplus >= 201402L
+
+]])
diff --git a/build-aux/m4/ax_gcc_func_attribute.m4 b/build-aux/m4/ax_gcc_func_attribute.m4
new file mode 100644
index 0000000000..c788ca9bd4
--- /dev/null
+++ b/build-aux/m4/ax_gcc_func_attribute.m4
@@ -0,0 +1,223 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE)
+#
+# DESCRIPTION
+#
+# This macro checks if the compiler supports one of GCC's function
+# attributes; many other compilers also provide function attributes with
+# the same syntax. Compiler warnings are used to detect supported
+# attributes as unsupported ones are ignored by default so quieting
+# warnings when using this macro will yield false positives.
+#
+# The ATTRIBUTE parameter holds the name of the attribute to be checked.
+#
+# If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_.
+#
+# The macro caches its result in the ax_cv_have_func_attribute_
+# variable.
+#
+# The macro currently supports the following function attributes:
+#
+# alias
+# aligned
+# alloc_size
+# always_inline
+# artificial
+# cold
+# const
+# constructor
+# constructor_priority for constructor attribute with priority
+# deprecated
+# destructor
+# dllexport
+# dllimport
+# error
+# externally_visible
+# flatten
+# format
+# format_arg
+# gnu_inline
+# hot
+# ifunc
+# leaf
+# malloc
+# noclone
+# noinline
+# nonnull
+# noreturn
+# nothrow
+# optimize
+# pure
+# unused
+# used
+# visibility
+# warning
+# warn_unused_result
+# weak
+# weakref
+#
+# Unsuppored function attributes will be tested with a prototype returning
+# an int and not accepting any arguments and the result of the check might
+# be wrong or meaningless so use with care.
+#
+# LICENSE
+#
+# Copyright (c) 2013 Gabriele Svelto
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 3
+
+AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [
+ AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1])
+
+ AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([
+ m4_case([$1],
+ [alias], [
+ int foo( void ) { return 0; }
+ int bar( void ) __attribute__(($1("foo")));
+ ],
+ [aligned], [
+ int foo( void ) __attribute__(($1(32)));
+ ],
+ [alloc_size], [
+ void *foo(int a) __attribute__(($1(1)));
+ ],
+ [always_inline], [
+ inline __attribute__(($1)) int foo( void ) { return 0; }
+ ],
+ [artificial], [
+ inline __attribute__(($1)) int foo( void ) { return 0; }
+ ],
+ [cold], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [const], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [constructor_priority], [
+ int foo( void ) __attribute__((__constructor__(65535/2)));
+ ],
+ [constructor], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [deprecated], [
+ int foo( void ) __attribute__(($1("")));
+ ],
+ [destructor], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [dllexport], [
+ __attribute__(($1)) int foo( void ) { return 0; }
+ ],
+ [dllimport], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [error], [
+ int foo( void ) __attribute__(($1("")));
+ ],
+ [externally_visible], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [flatten], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [format], [
+ int foo(const char *p, ...) __attribute__(($1(printf, 1, 2)));
+ ],
+ [format_arg], [
+ char *foo(const char *p) __attribute__(($1(1)));
+ ],
+ [gnu_inline], [
+ inline __attribute__(($1)) int foo( void ) { return 0; }
+ ],
+ [hot], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [ifunc], [
+ int my_foo( void ) { return 0; }
+ static int (*resolve_foo(void))(void) { return my_foo; }
+ int foo( void ) __attribute__(($1("resolve_foo")));
+ ],
+ [leaf], [
+ __attribute__(($1)) int foo( void ) { return 0; }
+ ],
+ [malloc], [
+ void *foo( void ) __attribute__(($1));
+ ],
+ [noclone], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [noinline], [
+ __attribute__(($1)) int foo( void ) { return 0; }
+ ],
+ [nonnull], [
+ int foo(char *p) __attribute__(($1(1)));
+ ],
+ [noreturn], [
+ void foo( void ) __attribute__(($1));
+ ],
+ [nothrow], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [optimize], [
+ __attribute__(($1(3))) int foo( void ) { return 0; }
+ ],
+ [pure], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [unused], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [used], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [visibility], [
+ int foo_def( void ) __attribute__(($1("default")));
+ int foo_hid( void ) __attribute__(($1("hidden")));
+ int foo_int( void ) __attribute__(($1("internal")));
+ int foo_pro( void ) __attribute__(($1("protected")));
+ ],
+ [warning], [
+ int foo( void ) __attribute__(($1("")));
+ ],
+ [warn_unused_result], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [weak], [
+ int foo( void ) __attribute__(($1));
+ ],
+ [weakref], [
+ static int foo( void ) { return 0; }
+ static int bar( void ) __attribute__(($1("foo")));
+ ],
+ [
+ m4_warn([syntax], [Unsupported attribute $1, the test may fail])
+ int foo( void ) __attribute__(($1));
+ ]
+ )], [])
+ ],
+ dnl GCC doesn't exit with an error if an unknown attribute is
+ dnl provided but only outputs a warning, so accept the attribute
+ dnl only if no warning were issued.
+ [AS_IF([test -s conftest.err],
+ [AS_VAR_SET([ac_var], [no])],
+ [AS_VAR_SET([ac_var], [yes])])],
+ [AS_VAR_SET([ac_var], [no])])
+ ])
+
+ AS_IF([test yes = AS_VAR_GET([ac_var])],
+ [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1,
+ [Define to 1 if the system has the `$1' function attribute])], [])
+
+ AS_VAR_POPDEF([ac_var])
+])
diff --git a/build-aux/m4/ax_pthread.m4 b/build-aux/m4/ax_pthread.m4
new file mode 100644
index 0000000000..4c4051ea37
--- /dev/null
+++ b/build-aux/m4/ax_pthread.m4
@@ -0,0 +1,485 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_pthread.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+#
+# DESCRIPTION
+#
+# This macro figures out how to build C programs using POSIX threads. It
+# sets the PTHREAD_LIBS output variable to the threads library and linker
+# flags, and the PTHREAD_CFLAGS output variable to any special C compiler
+# flags that are needed. (The user can also force certain compiler
+# flags/libs to be tested by setting these environment variables.)
+#
+# Also sets PTHREAD_CC to any special C compiler that is needed for
+# multi-threaded programs (defaults to the value of CC otherwise). (This
+# is necessary on AIX to use the special cc_r compiler alias.)
+#
+# NOTE: You are assumed to not only compile your program with these flags,
+# but also to link with them as well. For example, you might link with
+# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
+#
+# If you are only building threaded programs, you may wish to use these
+# variables in your default LIBS, CFLAGS, and CC:
+#
+# LIBS="$PTHREAD_LIBS $LIBS"
+# CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+# CC="$PTHREAD_CC"
+#
+# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
+# has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to
+# that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
+#
+# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the
+# PTHREAD_PRIO_INHERIT symbol is defined when compiling with
+# PTHREAD_CFLAGS.
+#
+# ACTION-IF-FOUND is a list of shell commands to run if a threads library
+# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
+# is not found. If ACTION-IF-FOUND is not specified, the default action
+# will define HAVE_PTHREAD.
+#
+# Please let the authors know if this macro fails on any platform, or if
+# you have any other suggestions or comments. This macro was based on work
+# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
+# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
+# Alejandro Forero Cuervo to the autoconf macro repository. We are also
+# grateful for the helpful feedback of numerous users.
+#
+# Updated for Autoconf 2.68 by Daniel Richard G.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Steven G. Johnson
+# Copyright (c) 2011 Daniel Richard G.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 23
+
+AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
+AC_DEFUN([AX_PTHREAD], [
+AC_REQUIRE([AC_CANONICAL_HOST])
+AC_REQUIRE([AC_PROG_CC])
+AC_REQUIRE([AC_PROG_SED])
+AC_LANG_PUSH([C])
+ax_pthread_ok=no
+
+# We used to check for pthread.h first, but this fails if pthread.h
+# requires special compiler flags (e.g. on Tru64 or Sequent).
+# It gets checked for in the link test anyway.
+
+# First of all, check if the user has set any of the PTHREAD_LIBS,
+# etcetera environment variables, and if threads linking works using
+# them:
+if test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then
+ ax_pthread_save_CC="$CC"
+ ax_pthread_save_CFLAGS="$CFLAGS"
+ ax_pthread_save_LIBS="$LIBS"
+ AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"])
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS])
+ AC_LINK_IFELSE([AC_LANG_CALL([], [pthread_join])], [ax_pthread_ok=yes])
+ AC_MSG_RESULT([$ax_pthread_ok])
+ if test "x$ax_pthread_ok" = "xno"; then
+ PTHREAD_LIBS=""
+ PTHREAD_CFLAGS=""
+ fi
+ CC="$ax_pthread_save_CC"
+ CFLAGS="$ax_pthread_save_CFLAGS"
+ LIBS="$ax_pthread_save_LIBS"
+fi
+
+# We must check for the threads library under a number of different
+# names; the ordering is very important because some systems
+# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
+# libraries is broken (non-POSIX).
+
+# Create a list of thread flags to try. Items starting with a "-" are
+# C compiler flags, and other items are library names, except for "none"
+# which indicates that we try without any flags at all, and "pthread-config"
+# which is a program returning the flags for the Pth emulation library.
+
+ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
+
+# The ordering *is* (sometimes) important. Some notes on the
+# individual items follow:
+
+# pthreads: AIX (must check this before -lpthread)
+# none: in case threads are in libc; should be tried before -Kthread and
+# other compiler flags to prevent continual compiler warnings
+# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
+# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64
+# (Note: HP C rejects this with "bad form for `-t' option")
+# -pthreads: Solaris/gcc (Note: HP C also rejects)
+# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
+# doesn't hurt to check since this sometimes defines pthreads and
+# -D_REENTRANT too), HP C (must be checked before -lpthread, which
+# is present but should not be used directly; and before -mthreads,
+# because the compiler interprets this as "-mt" + "-hreads")
+# -mthreads: Mingw32/gcc, Lynx/gcc
+# pthread: Linux, etcetera
+# --thread-safe: KAI C++
+# pthread-config: use pthread-config program (for GNU Pth library)
+
+case $host_os in
+
+ freebsd*)
+
+ # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
+ # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
+
+ ax_pthread_flags="-kthread lthread $ax_pthread_flags"
+ ;;
+
+ hpux*)
+
+ # From the cc(1) man page: "[-mt] Sets various -D flags to enable
+ # multi-threading and also sets -lpthread."
+
+ ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags"
+ ;;
+
+ openedition*)
+
+ # IBM z/OS requires a feature-test macro to be defined in order to
+ # enable POSIX threads at all, so give the user a hint if this is
+ # not set. (We don't define these ourselves, as they can affect
+ # other portions of the system API in unpredictable ways.)
+
+ AC_EGREP_CPP([AX_PTHREAD_ZOS_MISSING],
+ [
+# if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS)
+ AX_PTHREAD_ZOS_MISSING
+# endif
+ ],
+ [AC_MSG_WARN([IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support.])])
+ ;;
+
+ solaris*)
+
+ # On Solaris (at least, for some versions), libc contains stubbed
+ # (non-functional) versions of the pthreads routines, so link-based
+ # tests will erroneously succeed. (N.B.: The stubs are missing
+ # pthread_cleanup_push, or rather a function called by this macro,
+ # so we could check for that, but who knows whether they'll stub
+ # that too in a future libc.) So we'll check first for the
+ # standard Solaris way of linking pthreads (-mt -lpthread).
+
+ ax_pthread_flags="-mt,pthread pthread $ax_pthread_flags"
+ ;;
+esac
+
+# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC)
+
+AS_IF([test "x$GCC" = "xyes"],
+ [ax_pthread_flags="-pthread -pthreads $ax_pthread_flags"])
+
+# The presence of a feature test macro requesting re-entrant function
+# definitions is, on some systems, a strong hint that pthreads support is
+# correctly enabled
+
+case $host_os in
+ darwin* | hpux* | linux* | osf* | solaris*)
+ ax_pthread_check_macro="_REENTRANT"
+ ;;
+
+ aix*)
+ ax_pthread_check_macro="_THREAD_SAFE"
+ ;;
+
+ *)
+ ax_pthread_check_macro="--"
+ ;;
+esac
+AS_IF([test "x$ax_pthread_check_macro" = "x--"],
+ [ax_pthread_check_cond=0],
+ [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"])
+
+# Are we compiling with Clang?
+
+AC_CACHE_CHECK([whether $CC is Clang],
+ [ax_cv_PTHREAD_CLANG],
+ [ax_cv_PTHREAD_CLANG=no
+ # Note that Autoconf sets GCC=yes for Clang as well as GCC
+ if test "x$GCC" = "xyes"; then
+ AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG],
+ [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */
+# if defined(__clang__) && defined(__llvm__)
+ AX_PTHREAD_CC_IS_CLANG
+# endif
+ ],
+ [ax_cv_PTHREAD_CLANG=yes])
+ fi
+ ])
+ax_pthread_clang="$ax_cv_PTHREAD_CLANG"
+
+ax_pthread_clang_warning=no
+
+# Clang needs special handling, because older versions handle the -pthread
+# option in a rather... idiosyncratic way
+
+if test "x$ax_pthread_clang" = "xyes"; then
+
+ # Clang takes -pthread; it has never supported any other flag
+
+ # (Note 1: This will need to be revisited if a system that Clang
+ # supports has POSIX threads in a separate library. This tends not
+ # to be the way of modern systems, but it's conceivable.)
+
+ # (Note 2: On some systems, notably Darwin, -pthread is not needed
+ # to get POSIX threads support; the API is always present and
+ # active. We could reasonably leave PTHREAD_CFLAGS empty. But
+ # -pthread does define _REENTRANT, and while the Darwin headers
+ # ignore this macro, third-party headers might not.)
+
+ PTHREAD_CFLAGS="-pthread"
+ PTHREAD_LIBS=
+
+ ax_pthread_ok=yes
+
+ # However, older versions of Clang make a point of warning the user
+ # that, in an invocation where only linking and no compilation is
+ # taking place, the -pthread option has no effect ("argument unused
+ # during compilation"). They expect -pthread to be passed in only
+ # when source code is being compiled.
+ #
+ # Problem is, this is at odds with the way Automake and most other
+ # C build frameworks function, which is that the same flags used in
+ # compilation (CFLAGS) are also used in linking. Many systems
+ # supported by AX_PTHREAD require exactly this for POSIX threads
+ # support, and in fact it is often not straightforward to specify a
+ # flag that is used only in the compilation phase and not in
+ # linking. Such a scenario is extremely rare in practice.
+ #
+ # Even though use of the -pthread flag in linking would only print
+ # a warning, this can be a nuisance for well-run software projects
+ # that build with -Werror. So if the active version of Clang has
+ # this misfeature, we search for an option to squash it.
+
+ AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread],
+ [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG],
+ [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown
+ # Create an alternate version of $ac_link that compiles and
+ # links in two steps (.c -> .o, .o -> exe) instead of one
+ # (.c -> exe), because the warning occurs only in the second
+ # step
+ ax_pthread_save_ac_link="$ac_link"
+ ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g'
+ ax_pthread_link_step=`$as_echo "$ac_link" | sed "$ax_pthread_sed"`
+ ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)"
+ ax_pthread_save_CFLAGS="$CFLAGS"
+ for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do
+ AS_IF([test "x$ax_pthread_try" = "xunknown"], [break])
+ CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS"
+ ac_link="$ax_pthread_save_ac_link"
+ AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])],
+ [ac_link="$ax_pthread_2step_ac_link"
+ AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])],
+ [break])
+ ])
+ done
+ ac_link="$ax_pthread_save_ac_link"
+ CFLAGS="$ax_pthread_save_CFLAGS"
+ AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no])
+ ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try"
+ ])
+
+ case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in
+ no | unknown) ;;
+ *) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;;
+ esac
+
+fi # $ax_pthread_clang = yes
+
+if test "x$ax_pthread_ok" = "xno"; then
+for ax_pthread_try_flag in $ax_pthread_flags; do
+
+ case $ax_pthread_try_flag in
+ none)
+ AC_MSG_CHECKING([whether pthreads work without any flags])
+ ;;
+
+ -mt,pthread)
+ AC_MSG_CHECKING([whether pthreads work with -mt -lpthread])
+ PTHREAD_CFLAGS="-mt"
+ PTHREAD_LIBS="-lpthread"
+ ;;
+
+ -*)
+ AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag])
+ PTHREAD_CFLAGS="$ax_pthread_try_flag"
+ ;;
+
+ pthread-config)
+ AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no])
+ AS_IF([test "x$ax_pthread_config" = "xno"], [continue])
+ PTHREAD_CFLAGS="`pthread-config --cflags`"
+ PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
+ ;;
+
+ *)
+ AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag])
+ PTHREAD_LIBS="-l$ax_pthread_try_flag"
+ ;;
+ esac
+
+ ax_pthread_save_CFLAGS="$CFLAGS"
+ ax_pthread_save_LIBS="$LIBS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+
+ # Check for various functions. We must include pthread.h,
+ # since some functions may be macros. (On the Sequent, we
+ # need a special flag -Kthread to make this header compile.)
+ # We check for pthread_join because it is in -lpthread on IRIX
+ # while pthread_create is in libc. We check for pthread_attr_init
+ # due to DEC craziness with -lpthreads. We check for
+ # pthread_cleanup_push because it is one of the few pthread
+ # functions on Solaris that doesn't have a non-functional libc stub.
+ # We try pthread_create on general principles.
+
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([#include
+# if $ax_pthread_check_cond
+# error "$ax_pthread_check_macro must be defined"
+# endif
+ static void routine(void *a) { a = 0; }
+ static void *start_routine(void *a) { return a; }],
+ [pthread_t th; pthread_attr_t attr;
+ pthread_create(&th, 0, start_routine, 0);
+ pthread_join(th, 0);
+ pthread_attr_init(&attr);
+ pthread_cleanup_push(routine, 0);
+ pthread_cleanup_pop(0) /* ; */])],
+ [ax_pthread_ok=yes],
+ [])
+
+ CFLAGS="$ax_pthread_save_CFLAGS"
+ LIBS="$ax_pthread_save_LIBS"
+
+ AC_MSG_RESULT([$ax_pthread_ok])
+ AS_IF([test "x$ax_pthread_ok" = "xyes"], [break])
+
+ PTHREAD_LIBS=""
+ PTHREAD_CFLAGS=""
+done
+fi
+
+# Various other checks:
+if test "x$ax_pthread_ok" = "xyes"; then
+ ax_pthread_save_CFLAGS="$CFLAGS"
+ ax_pthread_save_LIBS="$LIBS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+
+ # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
+ AC_CACHE_CHECK([for joinable pthread attribute],
+ [ax_cv_PTHREAD_JOINABLE_ATTR],
+ [ax_cv_PTHREAD_JOINABLE_ATTR=unknown
+ for ax_pthread_attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ],
+ [int attr = $ax_pthread_attr; return attr /* ; */])],
+ [ax_cv_PTHREAD_JOINABLE_ATTR=$ax_pthread_attr; break],
+ [])
+ done
+ ])
+ AS_IF([test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xunknown" && \
+ test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xPTHREAD_CREATE_JOINABLE" && \
+ test "x$ax_pthread_joinable_attr_defined" != "xyes"],
+ [AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE],
+ [$ax_cv_PTHREAD_JOINABLE_ATTR],
+ [Define to necessary symbol if this constant
+ uses a non-standard name on your system.])
+ ax_pthread_joinable_attr_defined=yes
+ ])
+
+ AC_CACHE_CHECK([whether more special flags are required for pthreads],
+ [ax_cv_PTHREAD_SPECIAL_FLAGS],
+ [ax_cv_PTHREAD_SPECIAL_FLAGS=no
+ case $host_os in
+ solaris*)
+ ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS"
+ ;;
+ esac
+ ])
+ AS_IF([test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \
+ test "x$ax_pthread_special_flags_added" != "xyes"],
+ [PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS"
+ ax_pthread_special_flags_added=yes])
+
+ AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT],
+ [ax_cv_PTHREAD_PRIO_INHERIT],
+ [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]],
+ [[int i = PTHREAD_PRIO_INHERIT;]])],
+ [ax_cv_PTHREAD_PRIO_INHERIT=yes],
+ [ax_cv_PTHREAD_PRIO_INHERIT=no])
+ ])
+ AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" && \
+ test "x$ax_pthread_prio_inherit_defined" != "xyes"],
+ [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.])
+ ax_pthread_prio_inherit_defined=yes
+ ])
+
+ CFLAGS="$ax_pthread_save_CFLAGS"
+ LIBS="$ax_pthread_save_LIBS"
+
+ # More AIX lossage: compile with *_r variant
+ if test "x$GCC" != "xyes"; then
+ case $host_os in
+ aix*)
+ AS_CASE(["x/$CC"],
+ [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6],
+ [#handle absolute path differently from PATH based program lookup
+ AS_CASE(["x$CC"],
+ [x/*],
+ [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])],
+ [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])])
+ ;;
+ esac
+ fi
+fi
+
+test -n "$PTHREAD_CC" || PTHREAD_CC="$CC"
+
+AC_SUBST([PTHREAD_LIBS])
+AC_SUBST([PTHREAD_CFLAGS])
+AC_SUBST([PTHREAD_CC])
+
+# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
+if test "x$ax_pthread_ok" = "xyes"; then
+ ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1])
+ :
+else
+ ax_pthread_ok=no
+ $2
+fi
+AC_LANG_POP
+])dnl AX_PTHREAD
diff --git a/build-aux/m4/defi_find_bdb48.m4 b/build-aux/m4/defi_find_bdb48.m4
new file mode 100644
index 0000000000..c45c68cd51
--- /dev/null
+++ b/build-aux/m4/defi_find_bdb48.m4
@@ -0,0 +1,78 @@
+dnl Copyright (c) 2013-2015 The Bitcoin Core developers
+dnl Distributed under the MIT software license, see the accompanying
+dnl file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+AC_DEFUN([DEFI_FIND_BDB48],[
+ AC_ARG_VAR(BDB_CFLAGS, [C compiler flags for BerkeleyDB, bypasses autodetection])
+ AC_ARG_VAR(BDB_LIBS, [Linker flags for BerkeleyDB, bypasses autodetection])
+
+ if test "x$BDB_CFLAGS" = "x"; then
+ AC_MSG_CHECKING([for Berkeley DB C++ headers])
+ BDB_CPPFLAGS=
+ bdbpath=X
+ bdb48path=X
+ bdbdirlist=
+ for _vn in 4.8 48 4 5 5.3 ''; do
+ for _pfx in b lib ''; do
+ bdbdirlist="$bdbdirlist ${_pfx}db${_vn}"
+ done
+ done
+ for searchpath in $bdbdirlist ''; do
+ test -n "${searchpath}" && searchpath="${searchpath}/"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include <${searchpath}db_cxx.h>
+ ]],[[
+ #if !((DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 8) || DB_VERSION_MAJOR > 4)
+ #error "failed to find bdb 4.8+"
+ #endif
+ ]])],[
+ if test "x$bdbpath" = "xX"; then
+ bdbpath="${searchpath}"
+ fi
+ ],[
+ continue
+ ])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include <${searchpath}db_cxx.h>
+ ]],[[
+ #if !(DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 8)
+ #error "failed to find bdb 4.8"
+ #endif
+ ]])],[
+ bdb48path="${searchpath}"
+ break
+ ],[])
+ done
+ if test "x$bdbpath" = "xX"; then
+ AC_MSG_RESULT([no])
+ AC_MSG_ERROR([libdb_cxx headers missing, ]AC_PACKAGE_NAME[ requires this library for wallet functionality (--disable-wallet to disable wallet functionality)])
+ elif test "x$bdb48path" = "xX"; then
+ DEFI_SUBDIR_TO_INCLUDE(BDB_CPPFLAGS,[${bdbpath}],db_cxx)
+ AC_ARG_WITH([incompatible-bdb],[AS_HELP_STRING([--with-incompatible-bdb], [allow using a bdb version other than 4.8])],[
+ AC_MSG_WARN([Found Berkeley DB other than 4.8; wallets opened by this build will not be portable!])
+ ],[
+ AC_MSG_ERROR([Found Berkeley DB other than 4.8, required for portable wallets (--with-incompatible-bdb to ignore or --disable-wallet to disable wallet functionality)])
+ ])
+ else
+ DEFI_SUBDIR_TO_INCLUDE(BDB_CPPFLAGS,[${bdb48path}],db_cxx)
+ bdbpath="${bdb48path}"
+ fi
+ else
+ BDB_CPPFLAGS=${BDB_CFLAGS}
+ fi
+ AC_SUBST(BDB_CPPFLAGS)
+
+ if test "x$BDB_LIBS" = "x"; then
+ # TODO: Ideally this could find the library version and make sure it matches the headers being used
+ for searchlib in db_cxx-4.8 db_cxx db4_cxx; do
+ AC_CHECK_LIB([$searchlib],[main],[
+ BDB_LIBS="-l${searchlib}"
+ break
+ ])
+ done
+ if test "x$BDB_LIBS" = "x"; then
+ AC_MSG_ERROR([libdb_cxx missing, ]AC_PACKAGE_NAME[ requires this library for wallet functionality (--disable-wallet to disable wallet functionality)])
+ fi
+ fi
+ AC_SUBST(BDB_LIBS)
+])
diff --git a/build-aux/m4/defi_qt.m4 b/build-aux/m4/defi_qt.m4
new file mode 100644
index 0000000000..148aeccfbc
--- /dev/null
+++ b/build-aux/m4/defi_qt.m4
@@ -0,0 +1,507 @@
+dnl Copyright (c) 2013-2016 The Bitcoin Core developers
+dnl Distributed under the MIT software license, see the accompanying
+dnl file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+dnl Helper for cases where a qt dependency is not met.
+dnl Output: If qt version is auto, set defi_enable_qt to false. Else, exit.
+AC_DEFUN([DEFI_QT_FAIL],[
+ if test "x$defi_qt_want_version" = xauto && test "x$defi_qt_force" != xyes; then
+ if test "x$defi_enable_qt" != xno; then
+ AC_MSG_WARN([$1; defi-qt frontend will not be built])
+ fi
+ defi_enable_qt=no
+ defi_enable_qt_test=no
+ else
+ AC_MSG_ERROR([$1])
+ fi
+])
+
+AC_DEFUN([DEFI_QT_CHECK],[
+ if test "x$defi_enable_qt" != xno && test "x$defi_qt_want_version" != xno; then
+ true
+ $1
+ else
+ true
+ $2
+ fi
+])
+
+dnl DEFI_QT_PATH_PROGS([FOO], [foo foo2], [/path/to/search/first], [continue if missing])
+dnl Helper for finding the path of programs needed for Qt.
+dnl Inputs: $1: Variable to be set
+dnl Inputs: $2: List of programs to search for
+dnl Inputs: $3: Look for $2 here before $PATH
+dnl Inputs: $4: If "yes", don't fail if $2 is not found.
+dnl Output: $1 is set to the path of $2 if found. $2 are searched in order.
+AC_DEFUN([DEFI_QT_PATH_PROGS],[
+ DEFI_QT_CHECK([
+ if test "x$3" != x; then
+ AC_PATH_PROGS($1,$2,,$3)
+ else
+ AC_PATH_PROGS($1,$2)
+ fi
+ if test "x$$1" = x && test "x$4" != xyes; then
+ DEFI_QT_FAIL([$1 not found])
+ fi
+ ])
+])
+
+dnl Initialize qt input.
+dnl This must be called before any other DEFI_QT* macros to ensure that
+dnl input variables are set correctly.
+dnl CAUTION: Do not use this inside of a conditional.
+AC_DEFUN([DEFI_QT_INIT],[
+ dnl enable qt support
+ AC_ARG_WITH([gui],
+ [AS_HELP_STRING([--with-gui@<:@=no|qt5|auto@:>@],
+ [build defi-qt GUI (default=auto)])],
+ [
+ defi_qt_want_version=$withval
+ if test "x$defi_qt_want_version" = xyes; then
+ defi_qt_force=yes
+ defi_qt_want_version=auto
+ fi
+ ],
+ [defi_qt_want_version=auto])
+
+ AC_ARG_WITH([qt-incdir],[AS_HELP_STRING([--with-qt-incdir=INC_DIR],[specify qt include path (overridden by pkgconfig)])], [qt_include_path=$withval], [])
+ AC_ARG_WITH([qt-libdir],[AS_HELP_STRING([--with-qt-libdir=LIB_DIR],[specify qt lib path (overridden by pkgconfig)])], [qt_lib_path=$withval], [])
+ AC_ARG_WITH([qt-plugindir],[AS_HELP_STRING([--with-qt-plugindir=PLUGIN_DIR],[specify qt plugin path (overridden by pkgconfig)])], [qt_plugin_path=$withval], [])
+ AC_ARG_WITH([qt-translationdir],[AS_HELP_STRING([--with-qt-translationdir=PLUGIN_DIR],[specify qt translation path (overridden by pkgconfig)])], [qt_translation_path=$withval], [])
+ AC_ARG_WITH([qt-bindir],[AS_HELP_STRING([--with-qt-bindir=BIN_DIR],[specify qt bin path])], [qt_bin_path=$withval], [])
+
+ AC_ARG_WITH([qtdbus],
+ [AS_HELP_STRING([--with-qtdbus],
+ [enable DBus support (default is yes if qt is enabled and QtDBus is found)])],
+ [use_dbus=$withval],
+ [use_dbus=auto])
+
+ AC_SUBST(QT_TRANSLATION_DIR,$qt_translation_path)
+])
+
+dnl Find the appropriate version of Qt libraries and includes.
+dnl Inputs: $1: Whether or not pkg-config should be used. yes|no. Default: yes.
+dnl Inputs: $2: If $1 is "yes" and --with-gui=auto, which qt version should be
+dnl tried first.
+dnl Outputs: See _DEFI_QT_FIND_LIBS_*
+dnl Outputs: Sets variables for all qt-related tools.
+dnl Outputs: defi_enable_qt, defi_enable_qt_dbus, defi_enable_qt_test
+AC_DEFUN([DEFI_QT_CONFIGURE],[
+ use_pkgconfig=$1
+
+ if test "x$use_pkgconfig" = x; then
+ use_pkgconfig=yes
+ fi
+
+ if test "x$use_pkgconfig" = xyes; then
+ DEFI_QT_CHECK([_DEFI_QT_FIND_LIBS_WITH_PKGCONFIG])
+ else
+ DEFI_QT_CHECK([_DEFI_QT_FIND_LIBS_WITHOUT_PKGCONFIG])
+ fi
+
+ dnl This is ugly and complicated. Yuck. Works as follows:
+ dnl For Qt5, we can check a header to find out whether Qt is build
+ dnl statically. When Qt is built statically, some plugins must be linked into
+ dnl the final binary as well.
+ dnl With Qt5, languages moved into core and the WindowsIntegration plugin was
+ dnl added.
+ dnl _DEFI_QT_CHECK_STATIC_PLUGINS does a quick link-check and appends the
+ dnl results to QT_LIBS.
+ DEFI_QT_CHECK([
+ TEMP_CPPFLAGS=$CPPFLAGS
+ TEMP_CXXFLAGS=$CXXFLAGS
+ CPPFLAGS="$QT_INCLUDES $CPPFLAGS"
+ CXXFLAGS="$PIC_FLAGS $CXXFLAGS"
+ _DEFI_QT_IS_STATIC
+ if test "x$defi_cv_static_qt" = xyes; then
+ _DEFI_QT_FIND_STATIC_PLUGINS
+ AC_DEFINE(QT_STATICPLUGIN, 1, [Define this symbol if qt plugins are static])
+ _DEFI_QT_CHECK_STATIC_PLUGINS([Q_IMPORT_PLUGIN(QMinimalIntegrationPlugin)],[-lqminimal])
+ AC_DEFINE(QT_QPA_PLATFORM_MINIMAL, 1, [Define this symbol if the minimal qt platform exists])
+ if test "x$TARGET_OS" = xwindows; then
+ _DEFI_QT_CHECK_STATIC_PLUGINS([Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)],[-lqwindows])
+ AC_DEFINE(QT_QPA_PLATFORM_WINDOWS, 1, [Define this symbol if the qt platform is windows])
+ elif test "x$TARGET_OS" = xlinux; then
+ _DEFI_QT_CHECK_STATIC_PLUGINS([Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)],[-lqxcb -lxcb-static])
+ AC_DEFINE(QT_QPA_PLATFORM_XCB, 1, [Define this symbol if the qt platform is xcb])
+ elif test "x$TARGET_OS" = xdarwin; then
+ AX_CHECK_LINK_FLAG([[-framework IOKit]],[QT_LIBS="$QT_LIBS -framework IOKit"],[AC_MSG_ERROR(could not iokit framework)])
+ _DEFI_QT_CHECK_STATIC_PLUGINS([Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)],[-lqcocoa])
+ AC_DEFINE(QT_QPA_PLATFORM_COCOA, 1, [Define this symbol if the qt platform is cocoa])
+ fi
+ fi
+ CPPFLAGS=$TEMP_CPPFLAGS
+ CXXFLAGS=$TEMP_CXXFLAGS
+ ])
+
+ if test "x$use_pkgconfig$qt_bin_path" = xyes; then
+ qt_bin_path="`$PKG_CONFIG --variable=host_bins Qt5Core 2>/dev/null`"
+ fi
+
+ if test "x$use_hardening" != xno; then
+ DEFI_QT_CHECK([
+ AC_MSG_CHECKING(whether -fPIE can be used with this Qt config)
+ TEMP_CPPFLAGS=$CPPFLAGS
+ TEMP_CXXFLAGS=$CXXFLAGS
+ CPPFLAGS="$QT_INCLUDES $CPPFLAGS"
+ CXXFLAGS="$PIE_FLAGS $CXXFLAGS"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include
+ #ifndef QT_VERSION
+ # include
+ #endif
+ ]],
+ [[
+ #if defined(QT_REDUCE_RELOCATIONS)
+ choke
+ #endif
+ ]])],
+ [ AC_MSG_RESULT(yes); QT_PIE_FLAGS=$PIE_FLAGS ],
+ [ AC_MSG_RESULT(no); QT_PIE_FLAGS=$PIC_FLAGS]
+ )
+ CPPFLAGS=$TEMP_CPPFLAGS
+ CXXFLAGS=$TEMP_CXXFLAGS
+ ])
+ else
+ DEFI_QT_CHECK([
+ AC_MSG_CHECKING(whether -fPIC is needed with this Qt config)
+ TEMP_CPPFLAGS=$CPPFLAGS
+ CPPFLAGS="$QT_INCLUDES $CPPFLAGS"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include
+ #ifndef QT_VERSION
+ # include
+ #endif
+ ]],
+ [[
+ #if defined(QT_REDUCE_RELOCATIONS)
+ choke
+ #endif
+ ]])],
+ [ AC_MSG_RESULT(no)],
+ [ AC_MSG_RESULT(yes); QT_PIE_FLAGS=$PIC_FLAGS]
+ )
+ CPPFLAGS=$TEMP_CPPFLAGS
+ ])
+ fi
+
+ DEFI_QT_PATH_PROGS([MOC], [moc-qt5 moc5 moc], $qt_bin_path)
+ DEFI_QT_PATH_PROGS([UIC], [uic-qt5 uic5 uic], $qt_bin_path)
+ DEFI_QT_PATH_PROGS([RCC], [rcc-qt5 rcc5 rcc], $qt_bin_path)
+ DEFI_QT_PATH_PROGS([LRELEASE], [lrelease-qt5 lrelease5 lrelease], $qt_bin_path)
+ DEFI_QT_PATH_PROGS([LUPDATE], [lupdate-qt5 lupdate5 lupdate],$qt_bin_path, yes)
+
+ MOC_DEFS='-DHAVE_CONFIG_H -I$(srcdir)'
+ case $host in
+ *darwin*)
+ DEFI_QT_CHECK([
+ MOC_DEFS="${MOC_DEFS} -DQ_OS_MAC"
+ base_frameworks="-framework Foundation -framework ApplicationServices -framework AppKit"
+ AX_CHECK_LINK_FLAG([[$base_frameworks]],[QT_LIBS="$QT_LIBS $base_frameworks"],[AC_MSG_ERROR(could not find base frameworks)])
+ ])
+ ;;
+ *mingw*)
+ DEFI_QT_CHECK([
+ AX_CHECK_LINK_FLAG([[-mwindows]],[QT_LDFLAGS="$QT_LDFLAGS -mwindows"],[AC_MSG_WARN(-mwindows linker support not detected)])
+ ])
+ esac
+
+
+ dnl enable qt support
+ AC_MSG_CHECKING(whether to build ]AC_PACKAGE_NAME[ GUI)
+ DEFI_QT_CHECK([
+ defi_enable_qt=yes
+ defi_enable_qt_test=yes
+ if test "x$have_qt_test" = xno; then
+ defi_enable_qt_test=no
+ fi
+ defi_enable_qt_dbus=no
+ if test "x$use_dbus" != xno && test "x$have_qt_dbus" = xyes; then
+ defi_enable_qt_dbus=yes
+ fi
+ if test "x$use_dbus" = xyes && test "x$have_qt_dbus" = xno; then
+ AC_MSG_ERROR([libQtDBus not found. Install libQtDBus or remove --with-qtdbus.])
+ fi
+ if test "x$LUPDATE" = x; then
+ AC_MSG_WARN([lupdate is required to update qt translations])
+ fi
+ ],[
+ defi_enable_qt=no
+ ])
+ AC_MSG_RESULT([$defi_enable_qt (Qt5)])
+
+ AC_SUBST(QT_PIE_FLAGS)
+ AC_SUBST(QT_INCLUDES)
+ AC_SUBST(QT_LIBS)
+ AC_SUBST(QT_LDFLAGS)
+ AC_SUBST(QT_DBUS_INCLUDES)
+ AC_SUBST(QT_DBUS_LIBS)
+ AC_SUBST(QT_TEST_INCLUDES)
+ AC_SUBST(QT_TEST_LIBS)
+ AC_SUBST(QT_SELECT, qt5)
+ AC_SUBST(MOC_DEFS)
+])
+
+dnl All macros below are internal and should _not_ be used from the main
+dnl configure.ac.
+dnl ----
+
+dnl Internal. Check included version of Qt against minimum specified in doc/dependencies.md
+dnl Requires: INCLUDES must be populated as necessary.
+dnl Output: defi_cv_qt5=yes|no
+AC_DEFUN([_DEFI_QT_CHECK_QT5],[
+ AC_CACHE_CHECK(for Qt 5, defi_cv_qt5,[
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include
+ #ifndef QT_VERSION
+ # include
+ #endif
+ ]],
+ [[
+ #if QT_VERSION < 0x050501
+ choke
+ #endif
+ ]])],
+ [defi_cv_qt5=yes],
+ [defi_cv_qt5=no])
+])])
+
+dnl Internal. Check if the included version of Qt is greater than Qt58.
+dnl Requires: INCLUDES must be populated as necessary.
+dnl Output: defi_cv_qt58=yes|no
+AC_DEFUN([_DEFI_QT_CHECK_QT58],[
+ AC_CACHE_CHECK(for > Qt 5.7, defi_cv_qt58,[
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include
+ #ifndef QT_VERSION
+ # include
+ #endif
+ ]],
+ [[
+ #if QT_VERSION_MINOR < 8
+ choke
+ #endif
+ ]])],
+ [defi_cv_qt58=yes],
+ [defi_cv_qt58=no])
+])])
+
+
+dnl Internal. Check if the linked version of Qt was built as static libs.
+dnl Requires: Qt5.
+dnl Requires: INCLUDES and LIBS must be populated as necessary.
+dnl Output: defi_cv_static_qt=yes|no
+dnl Output: Defines QT_STATICPLUGIN if plugins are static.
+AC_DEFUN([_DEFI_QT_IS_STATIC],[
+ AC_CACHE_CHECK(for static Qt, defi_cv_static_qt,[
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include
+ #ifndef QT_VERSION OR QT_VERSION_STR
+ # include
+ #endif
+ ]],
+ [[
+ #if !defined(QT_STATIC)
+ choke
+ #endif
+ ]])],
+ [defi_cv_static_qt=yes],
+ [defi_cv_static_qt=no])
+ ])
+ if test "x$defi_cv_static_qt" = xyes; then
+ AC_DEFINE(QT_STATICPLUGIN, 1, [Define this symbol for static Qt plugins])
+ fi
+])
+
+dnl Internal. Check if the link-requirements for static plugins are met.
+dnl Requires: INCLUDES and LIBS must be populated as necessary.
+dnl Inputs: $1: A series of Q_IMPORT_PLUGIN().
+dnl Inputs: $2: The libraries that resolve $1.
+dnl Output: QT_LIBS is prepended or configure exits.
+AC_DEFUN([_DEFI_QT_CHECK_STATIC_PLUGINS],[
+ AC_MSG_CHECKING(for static Qt plugins: $2)
+ CHECK_STATIC_PLUGINS_TEMP_LIBS="$LIBS"
+ LIBS="$2 $QT_LIBS $LIBS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+ #define QT_STATICPLUGIN
+ #include
+ $1]],
+ [[return 0;]])],
+ [AC_MSG_RESULT(yes); QT_LIBS="$2 $QT_LIBS"],
+ [AC_MSG_RESULT(no); DEFI_QT_FAIL(Could not resolve: $2)])
+ LIBS="$CHECK_STATIC_PLUGINS_TEMP_LIBS"
+])
+
+dnl Internal. Find paths necessary for linking qt static plugins
+dnl Inputs: qt_plugin_path. optional.
+dnl Outputs: QT_LIBS is appended
+AC_DEFUN([_DEFI_QT_FIND_STATIC_PLUGINS],[
+ if test "x$qt_plugin_path" != x; then
+ QT_LIBS="$QT_LIBS -L$qt_plugin_path/platforms"
+ if test -d "$qt_plugin_path/accessible"; then
+ QT_LIBS="$QT_LIBS -L$qt_plugin_path/accessible"
+ fi
+ if test "x$use_pkgconfig" = xyes; then
+ : dnl
+ m4_ifdef([PKG_CHECK_MODULES],[
+ if test x$defi_cv_qt58 = xno; then
+ PKG_CHECK_MODULES([QTPLATFORM], [Qt5PlatformSupport], [QT_LIBS="$QTPLATFORM_LIBS $QT_LIBS"])
+ else
+ PKG_CHECK_MODULES([QTFONTDATABASE], [Qt5FontDatabaseSupport], [QT_LIBS="-lQt5FontDatabaseSupport $QT_LIBS"])
+ PKG_CHECK_MODULES([QTEVENTDISPATCHER], [Qt5EventDispatcherSupport], [QT_LIBS="-lQt5EventDispatcherSupport $QT_LIBS"])
+ PKG_CHECK_MODULES([QTTHEME], [Qt5ThemeSupport], [QT_LIBS="-lQt5ThemeSupport $QT_LIBS"])
+ PKG_CHECK_MODULES([QTDEVICEDISCOVERY], [Qt5DeviceDiscoverySupport], [QT_LIBS="-lQt5DeviceDiscoverySupport $QT_LIBS"])
+ PKG_CHECK_MODULES([QTACCESSIBILITY], [Qt5AccessibilitySupport], [QT_LIBS="-lQt5AccessibilitySupport $QT_LIBS"])
+ PKG_CHECK_MODULES([QTFB], [Qt5FbSupport], [QT_LIBS="-lQt5FbSupport $QT_LIBS"])
+ fi
+ if test "x$TARGET_OS" = xlinux; then
+ PKG_CHECK_MODULES([QTXCBQPA], [Qt5XcbQpa], [QT_LIBS="$QTXCBQPA_LIBS $QT_LIBS"])
+ elif test "x$TARGET_OS" = xdarwin; then
+ PKG_CHECK_MODULES([QTCLIPBOARD], [Qt5ClipboardSupport], [QT_LIBS="-lQt5ClipboardSupport $QT_LIBS"])
+ PKG_CHECK_MODULES([QTGRAPHICS], [Qt5GraphicsSupport], [QT_LIBS="-lQt5GraphicsSupport $QT_LIBS"])
+ PKG_CHECK_MODULES([QTCGL], [Qt5CglSupport], [QT_LIBS="-lQt5CglSupport $QT_LIBS"])
+ fi
+ ])
+ else
+ if test "x$TARGET_OS" = xwindows; then
+ AC_CACHE_CHECK(for Qt >= 5.6, defi_cv_need_platformsupport,[
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include
+ #ifndef QT_VERSION
+ # include
+ #endif
+ ]],
+ [[
+ #if QT_VERSION < 0x050600 || QT_VERSION_MINOR < 6
+ choke
+ #endif
+ ]])],
+ [defi_cv_need_platformsupport=yes],
+ [defi_cv_need_platformsupport=no])
+ ])
+ if test "x$defi_cv_need_platformsupport" = xyes; then
+ if test x$defi_cv_qt58 = xno; then
+ DEFI_QT_CHECK(AC_CHECK_LIB([${QT_LIB_PREFIX}PlatformSupport],[main],,DEFI_QT_FAIL(lib$QT_LIB_PREFIXPlatformSupport not found)))
+ else
+ DEFI_QT_CHECK(AC_CHECK_LIB([${QT_LIB_PREFIX}FontDatabaseSupport],[main],,DEFI_QT_FAIL(lib$QT_LIB_PREFIXFontDatabaseSupport not found)))
+ DEFI_QT_CHECK(AC_CHECK_LIB([${QT_LIB_PREFIX}EventDispatcherSupport],[main],,DEFI_QT_FAIL(lib$QT_LIB_PREFIXEventDispatcherSupport not found)))
+ DEFI_QT_CHECK(AC_CHECK_LIB([${QT_LIB_PREFIX}ThemeSupport],[main],,DEFI_QT_FAIL(lib$QT_LIB_PREFIXThemeSupport not found)))
+ DEFI_QT_CHECK(AC_CHECK_LIB([${QT_LIB_PREFIX}FbSupport],[main],,DEFI_QT_FAIL(lib$QT_LIB_PREFIXFbSupport not found)))
+ DEFI_QT_CHECK(AC_CHECK_LIB([${QT_LIB_PREFIX}DeviceDiscoverySupport],[main],,DEFI_QT_FAIL(lib$QT_LIB_PREFIXDeviceDiscoverySupport not found)))
+ DEFI_QT_CHECK(AC_CHECK_LIB([${QT_LIB_PREFIX}AccessibilitySupport],[main],,DEFI_QT_FAIL(lib$QT_LIB_PREFIXAccessibilitySupport not found)))
+ QT_LIBS="$QT_LIBS -lversion -ldwmapi -luxtheme"
+ fi
+ fi
+ fi
+ fi
+ fi
+])
+
+dnl Internal. Find Qt libraries using pkg-config.
+dnl Inputs: defi_qt_want_version (from --with-gui=). The version to check
+dnl first.
+dnl Inputs: $1: If defi_qt_want_version is "auto", check for this version
+dnl first.
+dnl Outputs: All necessary QT_* variables are set.
+dnl Outputs: have_qt_test and have_qt_dbus are set (if applicable) to yes|no.
+AC_DEFUN([_DEFI_QT_FIND_LIBS_WITH_PKGCONFIG],[
+ m4_ifdef([PKG_CHECK_MODULES],[
+ QT_LIB_PREFIX=Qt5
+ qt5_modules="Qt5Core Qt5Gui Qt5Network Qt5Widgets"
+ DEFI_QT_CHECK([
+ PKG_CHECK_MODULES([QT5], [$qt5_modules], [QT_INCLUDES="$QT5_CFLAGS"; QT_LIBS="$QT5_LIBS" have_qt=yes],[have_qt=no])
+
+ if test "x$have_qt" != xyes; then
+ have_qt=no
+ DEFI_QT_FAIL([Qt dependencies not found])
+ fi
+ ])
+ DEFI_QT_CHECK([
+ PKG_CHECK_MODULES([QT_TEST], [${QT_LIB_PREFIX}Test], [QT_TEST_INCLUDES="$QT_TEST_CFLAGS"; have_qt_test=yes], [have_qt_test=no])
+ if test "x$use_dbus" != xno; then
+ PKG_CHECK_MODULES([QT_DBUS], [${QT_LIB_PREFIX}DBus], [QT_DBUS_INCLUDES="$QT_DBUS_CFLAGS"; have_qt_dbus=yes], [have_qt_dbus=no])
+ fi
+ ])
+ ])
+ true; dnl
+])
+
+dnl Internal. Find Qt libraries without using pkg-config. Version is deduced
+dnl from the discovered headers.
+dnl Inputs: defi_qt_want_version (from --with-gui=). The version to use.
+dnl If "auto", the version will be discovered by _DEFI_QT_CHECK_QT5.
+dnl Outputs: All necessary QT_* variables are set.
+dnl Outputs: have_qt_test and have_qt_dbus are set (if applicable) to yes|no.
+AC_DEFUN([_DEFI_QT_FIND_LIBS_WITHOUT_PKGCONFIG],[
+ TEMP_CPPFLAGS="$CPPFLAGS"
+ TEMP_CXXFLAGS="$CXXFLAGS"
+ CXXFLAGS="$PIC_FLAGS $CXXFLAGS"
+ TEMP_LIBS="$LIBS"
+ DEFI_QT_CHECK([
+ if test "x$qt_include_path" != x; then
+ QT_INCLUDES="-I$qt_include_path -I$qt_include_path/QtCore -I$qt_include_path/QtGui -I$qt_include_path/QtWidgets -I$qt_include_path/QtNetwork -I$qt_include_path/QtTest -I$qt_include_path/QtDBus"
+ CPPFLAGS="$QT_INCLUDES $CPPFLAGS"
+ fi
+ ])
+
+ DEFI_QT_CHECK([AC_CHECK_HEADER([QtPlugin],,DEFI_QT_FAIL(QtCore headers missing))])
+ DEFI_QT_CHECK([AC_CHECK_HEADER([QApplication],, DEFI_QT_FAIL(QtGui headers missing))])
+ DEFI_QT_CHECK([AC_CHECK_HEADER([QLocalSocket],, DEFI_QT_FAIL(QtNetwork headers missing))])
+
+ DEFI_QT_CHECK([
+ if test "x$defi_qt_want_version" = xauto; then
+ _DEFI_QT_CHECK_QT5
+ _DEFI_QT_CHECK_QT58
+ fi
+ QT_LIB_PREFIX=Qt5
+ ])
+
+ DEFI_QT_CHECK([
+ LIBS=
+ if test "x$qt_lib_path" != x; then
+ LIBS="$LIBS -L$qt_lib_path"
+ fi
+
+ if test "x$TARGET_OS" = xwindows; then
+ AC_CHECK_LIB([imm32], [main],, DEFI_QT_FAIL(libimm32 not found))
+ fi
+ ])
+
+ DEFI_QT_CHECK(AC_CHECK_LIB([z] ,[main],,AC_MSG_WARN([zlib not found. Assuming qt has it built-in])))
+ if test x$defi_cv_qt58 = xno; then
+ DEFI_QT_CHECK(AC_SEARCH_LIBS([png_error] ,[qtpng png],,AC_MSG_WARN([libpng not found. Assuming qt has it built-in])))
+ DEFI_QT_CHECK(AC_SEARCH_LIBS([pcre16_exec], [qtpcre pcre16],,AC_MSG_WARN([libpcre16 not found. Assuming qt has it built-in])))
+ else
+ DEFI_QT_CHECK(AC_SEARCH_LIBS([png_error] ,[qtlibpng png],,AC_MSG_WARN([libpng not found. Assuming qt has it built-in])))
+ DEFI_QT_CHECK(AC_SEARCH_LIBS([pcre2_match_16], [qtpcre2 libqtpcre2],,AC_MSG_WARN([libqtpcre2 not found. Assuming qt has it built-in])))
+ fi
+ DEFI_QT_CHECK(AC_SEARCH_LIBS([hb_ot_tags_from_script] ,[qtharfbuzzng qtharfbuzz harfbuzz],,AC_MSG_WARN([libharfbuzz not found. Assuming qt has it built-in or support is disabled])))
+ DEFI_QT_CHECK(AC_CHECK_LIB([${QT_LIB_PREFIX}Core] ,[main],,DEFI_QT_FAIL(lib${QT_LIB_PREFIX}Core not found)))
+ DEFI_QT_CHECK(AC_CHECK_LIB([${QT_LIB_PREFIX}Gui] ,[main],,DEFI_QT_FAIL(lib${QT_LIB_PREFIX}Gui not found)))
+ DEFI_QT_CHECK(AC_CHECK_LIB([${QT_LIB_PREFIX}Network],[main],,DEFI_QT_FAIL(lib${QT_LIB_PREFIX}Network not found)))
+ DEFI_QT_CHECK(AC_CHECK_LIB([${QT_LIB_PREFIX}Widgets],[main],,DEFI_QT_FAIL(lib${QT_LIB_PREFIX}Widgets not found)))
+ QT_LIBS="$LIBS"
+ LIBS="$TEMP_LIBS"
+
+ DEFI_QT_CHECK([
+ LIBS=
+ if test "x$qt_lib_path" != x; then
+ LIBS="-L$qt_lib_path"
+ fi
+ AC_CHECK_LIB([${QT_LIB_PREFIX}Test], [main],, have_qt_test=no)
+ AC_CHECK_HEADER([QTest],, have_qt_test=no)
+ QT_TEST_LIBS="$LIBS"
+ if test "x$use_dbus" != xno; then
+ LIBS=
+ if test "x$qt_lib_path" != x; then
+ LIBS="-L$qt_lib_path"
+ fi
+ AC_CHECK_LIB([${QT_LIB_PREFIX}DBus], [main],, have_qt_dbus=no)
+ AC_CHECK_HEADER([QtDBus],, have_qt_dbus=no)
+ QT_DBUS_LIBS="$LIBS"
+ fi
+ ])
+ CPPFLAGS="$TEMP_CPPFLAGS"
+ CXXFLAGS="$TEMP_CXXFLAGS"
+ LIBS="$TEMP_LIBS"
+])
diff --git a/build-aux/m4/defi_subdir_to_include.m4 b/build-aux/m4/defi_subdir_to_include.m4
new file mode 100644
index 0000000000..69155d9665
--- /dev/null
+++ b/build-aux/m4/defi_subdir_to_include.m4
@@ -0,0 +1,18 @@
+dnl Copyright (c) 2013-2014 The Bitcoin Core developers
+dnl Distributed under the MIT software license, see the accompanying
+dnl file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+dnl DEFI_SUBDIR_TO_INCLUDE([CPPFLAGS-VARIABLE-NAME],[SUBDIRECTORY-NAME],[HEADER-FILE])
+dnl SUBDIRECTORY-NAME must end with a path separator
+AC_DEFUN([DEFI_SUBDIR_TO_INCLUDE],[
+ if test "x$2" = "x"; then
+ AC_MSG_RESULT([default])
+ else
+ echo "#include <$2$3.h>" >conftest.cpp
+ newinclpath=`${CXXCPP} ${CPPFLAGS} -M conftest.cpp 2>/dev/null | [ tr -d '\\n\\r\\\\' | sed -e 's/^.*[[:space:]:]\(\/[^[:space:]]*\)]$3[\.h[[:space:]].*$/\1/' -e t -e d`]
+ AC_MSG_RESULT([${newinclpath}])
+ if test "x${newinclpath}" != "x"; then
+ eval "$1=\"\$$1\"' -I${newinclpath}'"
+ fi
+ fi
+])
diff --git a/build-aux/m4/l_atomic.m4 b/build-aux/m4/l_atomic.m4
new file mode 100644
index 0000000000..75c43f9a92
--- /dev/null
+++ b/build-aux/m4/l_atomic.m4
@@ -0,0 +1,46 @@
+dnl Copyright (c) 2015 Tim Kosse
+dnl Copying and distribution of this file, with or without modification, are
+dnl permitted in any medium without royalty provided the copyright notice
+dnl and this notice are preserved. This file is offered as-is, without any
+dnl warranty.
+
+# Some versions of gcc/libstdc++ require linking with -latomic if
+# using the C++ atomic library.
+#
+# Sourced from http://bugs.debian.org/797228
+
+m4_define([_CHECK_ATOMIC_testbody], [[
+ #include
+ #include
+
+ int main() {
+ std::atomic a{};
+
+ int64_t v = 5;
+ int64_t r = a.fetch_add(v);
+ return static_cast(r);
+ }
+]])
+
+AC_DEFUN([CHECK_ATOMIC], [
+
+ AC_LANG_PUSH(C++)
+
+ AC_MSG_CHECKING([whether std::atomic can be used without link library])
+
+ AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_ATOMIC_testbody])],[
+ AC_MSG_RESULT([yes])
+ ],[
+ AC_MSG_RESULT([no])
+ LIBS="$LIBS -latomic"
+ AC_MSG_CHECKING([whether std::atomic needs -latomic])
+ AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_ATOMIC_testbody])],[
+ AC_MSG_RESULT([yes])
+ ],[
+ AC_MSG_RESULT([no])
+ AC_MSG_FAILURE([cannot figure out how to use std::atomic])
+ ])
+ ])
+
+ AC_LANG_POP
+])
diff --git a/build_msvc/.gitignore b/build_msvc/.gitignore
new file mode 100644
index 0000000000..8ba65dda8f
--- /dev/null
+++ b/build_msvc/.gitignore
@@ -0,0 +1,12 @@
+# Build directories
+Debug/*
+Release/*
+.vs
+packages/*
+*/Obj
+*/Debug
+*/Release
+*/x64
+*.vcxproj.user
+*.vcxproj
+*/Win32
diff --git a/build_msvc/README.md b/build_msvc/README.md
new file mode 100644
index 0000000000..99da76b983
--- /dev/null
+++ b/build_msvc/README.md
@@ -0,0 +1,50 @@
+Building DeFi Blockchain with Visual Studio
+========================================
+
+Introduction
+---------------------
+Solution and project files to build DeFi Blockchain applications (except Qt dependent ones) with Visual Studio 2017 can be found in the build_msvc directory.
+
+Building with Visual Studio is an alternative to the Linux based [cross-compiler build](../doc/build-windows.md).
+
+Dependencies
+---------------------
+A number of [open source libraries](../doc/dependencies.md) are required in order to be able to build the DeFi Blockchain.
+
+Options for installing the dependencies in a Visual Studio compatible manner are:
+
+- Use Microsoft's [vcpkg](https://docs.microsoft.com/en-us/cpp/vcpkg) to download the source packages and build locally. This is the recommended approach.
+- Download the source code, build each dependency, add the required include paths, link libraries and binary tools to the Visual Studio project files.
+- Use [nuget](https://www.nuget.org/) packages with the understanding that any binary files have been compiled by an untrusted third party.
+
+The external dependencies required for the Visual Studio build are (see [dependencies.md](../doc/dependencies.md) for more info):
+
+- Berkeley DB
+- OpenSSL
+- Boost
+- libevent
+- ZeroMQ
+- RapidCheck
+
+Additional dependencies required from the [DeFi Blockchain](https://github.com/defich/ain) GitHub repository are:
+- libsecp256k1
+- LevelDB
+
+Building
+---------------------
+The instructions below use `vcpkg` to install the dependencies.
+
+- Clone `vcpkg` from the [github repository](https://github.com/Microsoft/vcpkg) and install as per the instructions in the main README.md.
+- Install the required packages (replace x64 with x86 as required):
+
+```
+ PS >.\vcpkg install --triplet x64-windows-static boost-filesystem boost-signals2 boost-test libevent openssl zeromq berkeleydb secp256k1 leveldb rapidcheck
+```
+
+- Use Python to generate *.vcxproj from Makefile
+
+```
+ PS >py -3 msvc-autogen.py
+```
+
+- Build in Visual Studio.
diff --git a/build_msvc/bench_defi/bench_defi.vcxproj.in b/build_msvc/bench_defi/bench_defi.vcxproj.in
new file mode 100644
index 0000000000..8d248a8ef6
--- /dev/null
+++ b/build_msvc/bench_defi/bench_defi.vcxproj.in
@@ -0,0 +1,59 @@
+
+
+
+
+ {1125654E-E1B2-4431-8B5C-62EA9A2FEECB}
+
+
+ Application
+ $(SolutionDir)$(Platform)\$(Configuration)\
+
+
+@SOURCE_FILES@
+
+
+
+ {2b384fa8-9ee1-4544-93cb-0d733c25e8ce}
+
+
+ {7c87e378-df58-482e-aa2f-1bc129bc19ce}
+
+
+ {6190199c-6cf4-4dad-bfbd-93fa72a760c1}
+
+
+ {460fee33-1fe1-483f-b3bf-931ff8e969a5}
+
+
+ {b53a5535-ee9d-4c6f-9a26-f79ee3bc3754}
+
+
+ {93b86837-b543-48a5-a89b-7c87abb77df2}
+
+
+ {792d487f-f14c-49fc-a9de-3fc150f31c3f}
+
+
+ {5724ba7d-a09a-4ba8-800b-c4c1561b3d69}
+
+
+ {bb493552-3b8c-4a8c-bf69-a6e7a51d2ea6}
+
+
+ {18430fef-6b61-4c53-b396-718e02850f1b}
+
+
+
+
+ There was an error executing the raw bench header generation task.
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build_msvc/common.init.vcxproj b/build_msvc/common.init.vcxproj
new file mode 100644
index 0000000000..e9f4e23862
--- /dev/null
+++ b/build_msvc/common.init.vcxproj
@@ -0,0 +1,121 @@
+
+
+
+
+
+ 16.0
+ x86-windows-static
+ x64-windows-static
+
+
+ $(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion)
+ $(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion)
+
+ $(WindowsTargetPlatformVersion_10).0
+ $(WindowsTargetPlatformVersion_10)
+
+
+
+
+ Release
+ x64
+
+
+ Debug
+ x64
+
+
+ Release
+ Win32
+
+
+ Debug
+ Win32
+
+
+
+
+ true
+ false
+ true
+ v141
+ Unicode
+ $(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\
+ $(Platform)\$(Configuration)\$(ProjectName)\
+
+
+ false
+ true
+ false
+ v141
+ Unicode
+ $(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\
+ $(Platform)\$(Configuration)\$(ProjectName)\
+
+
+
+
+ MaxSpeed
+ true
+ true
+ true
+ MultiThreaded
+
+
+ true
+ true
+
+
+
+
+ Disabled
+ _DEBUG;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDebug
+ /bigobj %(AdditionalOptions)
+
+
+
+
+ MaxSpeed
+ true
+ true
+ true
+ MultiThreaded
+
+
+ true
+ true
+
+
+
+
+ Disabled
+ _DEBUG;%(PreprocessorDefinitions)
+ true
+ MultiThreadedDebug
+ /bigobj %(AdditionalOptions)
+
+
+
+
+
+ Level3
+ NotUsing
+ /utf-8 %(AdditionalOptions)
+ 4018;4221;4244;4267;4715;4805;
+ true
+ ZMQ_STATIC;NOMINMAX;WIN32;HAVE_CONFIG_H;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_CONSOLE;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions)
+ ..\..\src;..\..\src\univalue\include;..\..\src\secp256k1\include;..\..\src\leveldb\include;..\..\src\leveldb\helpers\memenv;%(AdditionalIncludeDirectories)
+
+
+ Console
+ true
+ crypt32.lib;Iphlpapi.lib;ws2_32.lib;Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
+
+
+ /ignore:4221
+
+
+
+
diff --git a/build_msvc/common.vcxproj b/build_msvc/common.vcxproj
new file mode 100644
index 0000000000..4bbcc3767f
--- /dev/null
+++ b/build_msvc/common.vcxproj
@@ -0,0 +1,12 @@
+
+
+$(BuildDependsOn);CopyBuildArtifacts
+
+
+
+
+
+
+
+
+
diff --git a/build_msvc/defi.sln b/build_msvc/defi.sln
new file mode 100644
index 0000000000..8977079555
--- /dev/null
+++ b/build_msvc/defi.sln
@@ -0,0 +1,210 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.28803.452
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdeficonsensus", "libdeficonsensus\libdeficonsensus.vcxproj", "{2B384FA8-9EE1-4544-93CB-0D733C25E8CE}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testconsensus", "testconsensus\testconsensus.vcxproj", "{E78473E9-B850-456C-9120-276301E04C06}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "defid", "defid\defid.vcxproj", "{D4513DDF-6013-44DC-ADCC-12EAF6D1F038}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdefi_util", "libdefi_util\libdefi_util.vcxproj", "{B53A5535-EE9D-4C6F-9A26-F79EE3BC3754}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdefi_common", "libdefi_common\libdefi_common.vcxproj", "{7C87E378-DF58-482E-AA2F-1BC129BC19CE}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdefi_crypto", "libdefi_crypto\libdefi_crypto.vcxproj", "{6190199C-6CF4-4DAD-BFBD-93FA72A760C1}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdefi_server", "libdefi_server\libdefi_server.vcxproj", "{460FEE33-1FE1-483F-B3BF-931FF8E969A5}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libunivalue", "libunivalue\libunivalue.vcxproj", "{5724BA7D-A09A-4BA8-800B-C4C1561B3D69}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdefi_wallet", "libdefi_wallet\libdefi_wallet.vcxproj", "{93B86837-B543-48A5-A89B-7C87ABB77DF2}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdefi_zmq", "libdefi_zmq\libdefi_zmq.vcxproj", "{792D487F-F14C-49FC-A9DE-3FC150F31C3F}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_defi", "test_defi\test_defi.vcxproj", "{A56B73DB-D46D-4882-8374-1FE3FFA08F07}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdefi_cli", "libdefi_cli\libdefi_cli.vcxproj", "{0667528C-D734-4009-ADF9-C0D6C4A5A5A6}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "defi-cli", "defi-cli\defi-cli.vcxproj", "{0B2D7431-F876-4A58-87BF-F748338CD3BF}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bench_defi", "bench_defi\bench_defi.vcxproj", "{1125654E-E1B2-4431-8B5C-62EA9A2FEECB}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "defi-tx", "defi-tx\defi-tx.vcxproj", "{D3022AF6-AD33-4CE3-B358-87CB6A1B29CF}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "defi-wallet", "defi-wallet\defi-wallet.vcxproj", "{84DE8790-EDE3-4483-81AC-C32F15E861F4}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdefi_wallet_tool", "libdefi_wallet_tool\libdefi_wallet_tool.vcxproj", "{F91AC55E-6F5E-4C58-9AC5-B40DB7DEEF93}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libsecp256k1", "libsecp256k1\libsecp256k1.vcxproj", "{BB493552-3B8C-4A8C-BF69-A6E7A51D2EA6}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libleveldb", "libleveldb\libleveldb.vcxproj", "{18430FEF-6B61-4C53-B396-718E02850F1B}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {2B384FA8-9EE1-4544-93CB-0D733C25E8CE}.Debug|x64.ActiveCfg = Debug|x64
+ {2B384FA8-9EE1-4544-93CB-0D733C25E8CE}.Debug|x64.Build.0 = Debug|x64
+ {2B384FA8-9EE1-4544-93CB-0D733C25E8CE}.Debug|x86.ActiveCfg = Debug|Win32
+ {2B384FA8-9EE1-4544-93CB-0D733C25E8CE}.Debug|x86.Build.0 = Debug|Win32
+ {2B384FA8-9EE1-4544-93CB-0D733C25E8CE}.Release|x64.ActiveCfg = Release|x64
+ {2B384FA8-9EE1-4544-93CB-0D733C25E8CE}.Release|x64.Build.0 = Release|x64
+ {2B384FA8-9EE1-4544-93CB-0D733C25E8CE}.Release|x86.ActiveCfg = Release|Win32
+ {2B384FA8-9EE1-4544-93CB-0D733C25E8CE}.Release|x86.Build.0 = Release|Win32
+ {E78473E9-B850-456C-9120-276301E04C06}.Debug|x64.ActiveCfg = Debug|x64
+ {E78473E9-B850-456C-9120-276301E04C06}.Debug|x64.Build.0 = Debug|x64
+ {E78473E9-B850-456C-9120-276301E04C06}.Debug|x86.ActiveCfg = Debug|Win32
+ {E78473E9-B850-456C-9120-276301E04C06}.Debug|x86.Build.0 = Debug|Win32
+ {E78473E9-B850-456C-9120-276301E04C06}.Release|x64.ActiveCfg = Release|x64
+ {E78473E9-B850-456C-9120-276301E04C06}.Release|x64.Build.0 = Release|x64
+ {E78473E9-B850-456C-9120-276301E04C06}.Release|x86.ActiveCfg = Release|Win32
+ {E78473E9-B850-456C-9120-276301E04C06}.Release|x86.Build.0 = Release|Win32
+ {D4513DDF-6013-44DC-ADCC-12EAF6D1F038}.Debug|x64.ActiveCfg = Debug|x64
+ {D4513DDF-6013-44DC-ADCC-12EAF6D1F038}.Debug|x64.Build.0 = Debug|x64
+ {D4513DDF-6013-44DC-ADCC-12EAF6D1F038}.Debug|x86.ActiveCfg = Debug|Win32
+ {D4513DDF-6013-44DC-ADCC-12EAF6D1F038}.Debug|x86.Build.0 = Debug|Win32
+ {D4513DDF-6013-44DC-ADCC-12EAF6D1F038}.Release|x64.ActiveCfg = Release|x64
+ {D4513DDF-6013-44DC-ADCC-12EAF6D1F038}.Release|x64.Build.0 = Release|x64
+ {D4513DDF-6013-44DC-ADCC-12EAF6D1F038}.Release|x86.ActiveCfg = Release|Win32
+ {D4513DDF-6013-44DC-ADCC-12EAF6D1F038}.Release|x86.Build.0 = Release|Win32
+ {B53A5535-EE9D-4C6F-9A26-F79EE3BC3754}.Debug|x64.ActiveCfg = Debug|x64
+ {B53A5535-EE9D-4C6F-9A26-F79EE3BC3754}.Debug|x64.Build.0 = Debug|x64
+ {B53A5535-EE9D-4C6F-9A26-F79EE3BC3754}.Debug|x86.ActiveCfg = Debug|Win32
+ {B53A5535-EE9D-4C6F-9A26-F79EE3BC3754}.Debug|x86.Build.0 = Debug|Win32
+ {B53A5535-EE9D-4C6F-9A26-F79EE3BC3754}.Release|x64.ActiveCfg = Release|x64
+ {B53A5535-EE9D-4C6F-9A26-F79EE3BC3754}.Release|x64.Build.0 = Release|x64
+ {B53A5535-EE9D-4C6F-9A26-F79EE3BC3754}.Release|x86.ActiveCfg = Release|Win32
+ {B53A5535-EE9D-4C6F-9A26-F79EE3BC3754}.Release|x86.Build.0 = Release|Win32
+ {7C87E378-DF58-482E-AA2F-1BC129BC19CE}.Debug|x64.ActiveCfg = Debug|x64
+ {7C87E378-DF58-482E-AA2F-1BC129BC19CE}.Debug|x64.Build.0 = Debug|x64
+ {7C87E378-DF58-482E-AA2F-1BC129BC19CE}.Debug|x86.ActiveCfg = Debug|Win32
+ {7C87E378-DF58-482E-AA2F-1BC129BC19CE}.Debug|x86.Build.0 = Debug|Win32
+ {7C87E378-DF58-482E-AA2F-1BC129BC19CE}.Release|x64.ActiveCfg = Release|x64
+ {7C87E378-DF58-482E-AA2F-1BC129BC19CE}.Release|x64.Build.0 = Release|x64
+ {7C87E378-DF58-482E-AA2F-1BC129BC19CE}.Release|x86.ActiveCfg = Release|Win32
+ {7C87E378-DF58-482E-AA2F-1BC129BC19CE}.Release|x86.Build.0 = Release|Win32
+ {6190199C-6CF4-4DAD-BFBD-93FA72A760C1}.Debug|x64.ActiveCfg = Debug|x64
+ {6190199C-6CF4-4DAD-BFBD-93FA72A760C1}.Debug|x64.Build.0 = Debug|x64
+ {6190199C-6CF4-4DAD-BFBD-93FA72A760C1}.Debug|x86.ActiveCfg = Debug|Win32
+ {6190199C-6CF4-4DAD-BFBD-93FA72A760C1}.Debug|x86.Build.0 = Debug|Win32
+ {6190199C-6CF4-4DAD-BFBD-93FA72A760C1}.Release|x64.ActiveCfg = Release|x64
+ {6190199C-6CF4-4DAD-BFBD-93FA72A760C1}.Release|x64.Build.0 = Release|x64
+ {6190199C-6CF4-4DAD-BFBD-93FA72A760C1}.Release|x86.ActiveCfg = Release|Win32
+ {6190199C-6CF4-4DAD-BFBD-93FA72A760C1}.Release|x86.Build.0 = Release|Win32
+ {460FEE33-1FE1-483F-B3BF-931FF8E969A5}.Debug|x64.ActiveCfg = Debug|x64
+ {460FEE33-1FE1-483F-B3BF-931FF8E969A5}.Debug|x64.Build.0 = Debug|x64
+ {460FEE33-1FE1-483F-B3BF-931FF8E969A5}.Debug|x86.ActiveCfg = Debug|Win32
+ {460FEE33-1FE1-483F-B3BF-931FF8E969A5}.Debug|x86.Build.0 = Debug|Win32
+ {460FEE33-1FE1-483F-B3BF-931FF8E969A5}.Release|x64.ActiveCfg = Release|x64
+ {460FEE33-1FE1-483F-B3BF-931FF8E969A5}.Release|x64.Build.0 = Release|x64
+ {460FEE33-1FE1-483F-B3BF-931FF8E969A5}.Release|x86.ActiveCfg = Release|Win32
+ {460FEE33-1FE1-483F-B3BF-931FF8E969A5}.Release|x86.Build.0 = Release|Win32
+ {5724BA7D-A09A-4BA8-800B-C4C1561B3D69}.Debug|x64.ActiveCfg = Debug|x64
+ {5724BA7D-A09A-4BA8-800B-C4C1561B3D69}.Debug|x64.Build.0 = Debug|x64
+ {5724BA7D-A09A-4BA8-800B-C4C1561B3D69}.Debug|x86.ActiveCfg = Debug|Win32
+ {5724BA7D-A09A-4BA8-800B-C4C1561B3D69}.Debug|x86.Build.0 = Debug|Win32
+ {5724BA7D-A09A-4BA8-800B-C4C1561B3D69}.Release|x64.ActiveCfg = Release|x64
+ {5724BA7D-A09A-4BA8-800B-C4C1561B3D69}.Release|x64.Build.0 = Release|x64
+ {5724BA7D-A09A-4BA8-800B-C4C1561B3D69}.Release|x86.ActiveCfg = Release|Win32
+ {5724BA7D-A09A-4BA8-800B-C4C1561B3D69}.Release|x86.Build.0 = Release|Win32
+ {93B86837-B543-48A5-A89B-7C87ABB77DF2}.Debug|x64.ActiveCfg = Debug|x64
+ {93B86837-B543-48A5-A89B-7C87ABB77DF2}.Debug|x64.Build.0 = Debug|x64
+ {93B86837-B543-48A5-A89B-7C87ABB77DF2}.Debug|x86.ActiveCfg = Debug|Win32
+ {93B86837-B543-48A5-A89B-7C87ABB77DF2}.Debug|x86.Build.0 = Debug|Win32
+ {93B86837-B543-48A5-A89B-7C87ABB77DF2}.Release|x64.ActiveCfg = Release|x64
+ {93B86837-B543-48A5-A89B-7C87ABB77DF2}.Release|x64.Build.0 = Release|x64
+ {93B86837-B543-48A5-A89B-7C87ABB77DF2}.Release|x86.ActiveCfg = Release|Win32
+ {93B86837-B543-48A5-A89B-7C87ABB77DF2}.Release|x86.Build.0 = Release|Win32
+ {792D487F-F14C-49FC-A9DE-3FC150F31C3F}.Debug|x64.ActiveCfg = Debug|x64
+ {792D487F-F14C-49FC-A9DE-3FC150F31C3F}.Debug|x64.Build.0 = Debug|x64
+ {792D487F-F14C-49FC-A9DE-3FC150F31C3F}.Debug|x86.ActiveCfg = Debug|Win32
+ {792D487F-F14C-49FC-A9DE-3FC150F31C3F}.Debug|x86.Build.0 = Debug|Win32
+ {792D487F-F14C-49FC-A9DE-3FC150F31C3F}.Release|x64.ActiveCfg = Release|x64
+ {792D487F-F14C-49FC-A9DE-3FC150F31C3F}.Release|x64.Build.0 = Release|x64
+ {792D487F-F14C-49FC-A9DE-3FC150F31C3F}.Release|x86.ActiveCfg = Release|Win32
+ {792D487F-F14C-49FC-A9DE-3FC150F31C3F}.Release|x86.Build.0 = Release|Win32
+ {A56B73DB-D46D-4882-8374-1FE3FFA08F07}.Debug|x64.ActiveCfg = Debug|x64
+ {A56B73DB-D46D-4882-8374-1FE3FFA08F07}.Debug|x64.Build.0 = Debug|x64
+ {A56B73DB-D46D-4882-8374-1FE3FFA08F07}.Debug|x86.ActiveCfg = Debug|Win32
+ {A56B73DB-D46D-4882-8374-1FE3FFA08F07}.Debug|x86.Build.0 = Debug|Win32
+ {A56B73DB-D46D-4882-8374-1FE3FFA08F07}.Release|x64.ActiveCfg = Release|x64
+ {A56B73DB-D46D-4882-8374-1FE3FFA08F07}.Release|x64.Build.0 = Release|x64
+ {A56B73DB-D46D-4882-8374-1FE3FFA08F07}.Release|x86.ActiveCfg = Release|Win32
+ {A56B73DB-D46D-4882-8374-1FE3FFA08F07}.Release|x86.Build.0 = Release|Win32
+ {0667528C-D734-4009-ADF9-C0D6C4A5A5A6}.Debug|x64.ActiveCfg = Debug|x64
+ {0667528C-D734-4009-ADF9-C0D6C4A5A5A6}.Debug|x64.Build.0 = Debug|x64
+ {0667528C-D734-4009-ADF9-C0D6C4A5A5A6}.Debug|x86.ActiveCfg = Debug|Win32
+ {0667528C-D734-4009-ADF9-C0D6C4A5A5A6}.Debug|x86.Build.0 = Debug|Win32
+ {0667528C-D734-4009-ADF9-C0D6C4A5A5A6}.Release|x64.ActiveCfg = Release|x64
+ {0667528C-D734-4009-ADF9-C0D6C4A5A5A6}.Release|x64.Build.0 = Release|x64
+ {0667528C-D734-4009-ADF9-C0D6C4A5A5A6}.Release|x86.ActiveCfg = Release|Win32
+ {0667528C-D734-4009-ADF9-C0D6C4A5A5A6}.Release|x86.Build.0 = Release|Win32
+ {0B2D7431-F876-4A58-87BF-F748338CD3BF}.Debug|x64.ActiveCfg = Debug|x64
+ {0B2D7431-F876-4A58-87BF-F748338CD3BF}.Debug|x64.Build.0 = Debug|x64
+ {0B2D7431-F876-4A58-87BF-F748338CD3BF}.Debug|x86.ActiveCfg = Debug|Win32
+ {0B2D7431-F876-4A58-87BF-F748338CD3BF}.Debug|x86.Build.0 = Debug|Win32
+ {0B2D7431-F876-4A58-87BF-F748338CD3BF}.Release|x64.ActiveCfg = Release|x64
+ {0B2D7431-F876-4A58-87BF-F748338CD3BF}.Release|x64.Build.0 = Release|x64
+ {0B2D7431-F876-4A58-87BF-F748338CD3BF}.Release|x86.ActiveCfg = Release|Win32
+ {0B2D7431-F876-4A58-87BF-F748338CD3BF}.Release|x86.Build.0 = Release|Win32
+ {1125654E-E1B2-4431-8B5C-62EA9A2FEECB}.Debug|x64.ActiveCfg = Debug|x64
+ {1125654E-E1B2-4431-8B5C-62EA9A2FEECB}.Debug|x64.Build.0 = Debug|x64
+ {1125654E-E1B2-4431-8B5C-62EA9A2FEECB}.Debug|x86.ActiveCfg = Debug|Win32
+ {1125654E-E1B2-4431-8B5C-62EA9A2FEECB}.Debug|x86.Build.0 = Debug|Win32
+ {1125654E-E1B2-4431-8B5C-62EA9A2FEECB}.Release|x64.ActiveCfg = Release|x64
+ {1125654E-E1B2-4431-8B5C-62EA9A2FEECB}.Release|x64.Build.0 = Release|x64
+ {1125654E-E1B2-4431-8B5C-62EA9A2FEECB}.Release|x86.ActiveCfg = Release|Win32
+ {1125654E-E1B2-4431-8B5C-62EA9A2FEECB}.Release|x86.Build.0 = Release|Win32
+ {D3022AF6-AD33-4CE3-B358-87CB6A1B29CF}.Debug|x64.ActiveCfg = Debug|x64
+ {D3022AF6-AD33-4CE3-B358-87CB6A1B29CF}.Debug|x64.Build.0 = Debug|x64
+ {D3022AF6-AD33-4CE3-B358-87CB6A1B29CF}.Debug|x86.ActiveCfg = Debug|Win32
+ {D3022AF6-AD33-4CE3-B358-87CB6A1B29CF}.Debug|x86.Build.0 = Debug|Win32
+ {D3022AF6-AD33-4CE3-B358-87CB6A1B29CF}.Release|x64.ActiveCfg = Release|x64
+ {D3022AF6-AD33-4CE3-B358-87CB6A1B29CF}.Release|x64.Build.0 = Release|x64
+ {D3022AF6-AD33-4CE3-B358-87CB6A1B29CF}.Release|x86.ActiveCfg = Release|Win32
+ {D3022AF6-AD33-4CE3-B358-87CB6A1B29CF}.Release|x86.Build.0 = Release|Win32
+ {84DE8790-EDE3-4483-81AC-C32F15E861F4}.Debug|x64.ActiveCfg = Debug|x64
+ {84DE8790-EDE3-4483-81AC-C32F15E861F4}.Debug|x64.Build.0 = Debug|x64
+ {84DE8790-EDE3-4483-81AC-C32F15E861F4}.Debug|x86.ActiveCfg = Debug|Win32
+ {84DE8790-EDE3-4483-81AC-C32F15E861F4}.Debug|x86.Build.0 = Debug|Win32
+ {84DE8790-EDE3-4483-81AC-C32F15E861F4}.Release|x64.ActiveCfg = Release|x64
+ {84DE8790-EDE3-4483-81AC-C32F15E861F4}.Release|x64.Build.0 = Release|x64
+ {84DE8790-EDE3-4483-81AC-C32F15E861F4}.Release|x86.ActiveCfg = Release|Win32
+ {84DE8790-EDE3-4483-81AC-C32F15E861F4}.Release|x86.Build.0 = Release|Win32
+ {F91AC55E-6F5E-4C58-9AC5-B40DB7DEEF93}.Debug|x64.ActiveCfg = Debug|x64
+ {F91AC55E-6F5E-4C58-9AC5-B40DB7DEEF93}.Debug|x64.Build.0 = Debug|x64
+ {F91AC55E-6F5E-4C58-9AC5-B40DB7DEEF93}.Debug|x86.ActiveCfg = Debug|Win32
+ {F91AC55E-6F5E-4C58-9AC5-B40DB7DEEF93}.Debug|x86.Build.0 = Debug|Win32
+ {F91AC55E-6F5E-4C58-9AC5-B40DB7DEEF93}.Release|x64.ActiveCfg = Release|x64
+ {F91AC55E-6F5E-4C58-9AC5-B40DB7DEEF93}.Release|x64.Build.0 = Release|x64
+ {F91AC55E-6F5E-4C58-9AC5-B40DB7DEEF93}.Release|x86.ActiveCfg = Release|Win32
+ {F91AC55E-6F5E-4C58-9AC5-B40DB7DEEF93}.Release|x86.Build.0 = Release|Win32
+ {BB493552-3B8C-4A8C-BF69-A6E7A51D2EA6}.Debug|x64.ActiveCfg = Debug|x64
+ {BB493552-3B8C-4A8C-BF69-A6E7A51D2EA6}.Debug|x64.Build.0 = Debug|x64
+ {BB493552-3B8C-4A8C-BF69-A6E7A51D2EA6}.Debug|x86.ActiveCfg = Debug|Win32
+ {BB493552-3B8C-4A8C-BF69-A6E7A51D2EA6}.Debug|x86.Build.0 = Debug|Win32
+ {BB493552-3B8C-4A8C-BF69-A6E7A51D2EA6}.Release|x64.ActiveCfg = Release|x64
+ {BB493552-3B8C-4A8C-BF69-A6E7A51D2EA6}.Release|x64.Build.0 = Release|x64
+ {BB493552-3B8C-4A8C-BF69-A6E7A51D2EA6}.Release|x86.ActiveCfg = Release|Win32
+ {BB493552-3B8C-4A8C-BF69-A6E7A51D2EA6}.Release|x86.Build.0 = Release|Win32
+ {18430FEF-6B61-4C53-B396-718E02850F1B}.Debug|x64.ActiveCfg = Debug|x64
+ {18430FEF-6B61-4C53-B396-718E02850F1B}.Debug|x64.Build.0 = Debug|x64
+ {18430FEF-6B61-4C53-B396-718E02850F1B}.Debug|x86.ActiveCfg = Debug|Win32
+ {18430FEF-6B61-4C53-B396-718E02850F1B}.Debug|x86.Build.0 = Debug|Win32
+ {18430FEF-6B61-4C53-B396-718E02850F1B}.Release|x64.ActiveCfg = Release|x64
+ {18430FEF-6B61-4C53-B396-718E02850F1B}.Release|x64.Build.0 = Release|x64
+ {18430FEF-6B61-4C53-B396-718E02850F1B}.Release|x86.ActiveCfg = Release|Win32
+ {18430FEF-6B61-4C53-B396-718E02850F1B}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {DA7D16A6-E5F0-45B3-B194-C3FE64F1BFCD}
+ EndGlobalSection
+EndGlobal
diff --git a/build_msvc/defi_config.h b/build_msvc/defi_config.h
new file mode 100644
index 0000000000..a0bffa27cc
--- /dev/null
+++ b/build_msvc/defi_config.h
@@ -0,0 +1,434 @@
+#ifndef DEFI_DEFI_CONFIG_H
+#define DEFI_DEFI_CONFIG_H
+
+/* Define if building universal (internal helper macro) */
+/* #undef AC_APPLE_UNIVERSAL_BUILD */
+
+/* Version Build */
+#define CLIENT_VERSION_BUILD 0
+
+/* Version is release */
+#define CLIENT_VERSION_IS_RELEASE false
+
+/* Major version */
+#define CLIENT_VERSION_MAJOR 1
+
+/* Minor version */
+#define CLIENT_VERSION_MINOR 0
+
+/* Build revision */
+#define CLIENT_VERSION_REVISION 0
+
+/* Copyright holder(s) before %s replacement */
+#define COPYRIGHT_HOLDERS "The %s Developers"
+
+/* Copyright holder(s) */
+#define COPYRIGHT_HOLDERS_FINAL "The DeFi Blockchain Developers"
+
+/* Replacement for %s in copyright holders string */
+#define COPYRIGHT_HOLDERS_SUBSTITUTION "DeFi Blockchain"
+
+/* Copyright year */
+#define COPYRIGHT_YEAR 2020
+
+/* Define to 1 to enable wallet functions */
+#define ENABLE_WALLET 1
+
+/* Define to 1 to enable ZMQ functions */
+#define ENABLE_ZMQ 1
+
+/* parameter and return value type for __fdelt_chk */
+/* #undef FDELT_TYPE */
+
+/* define if the Boost library is available */
+#define HAVE_BOOST /**/
+
+/* define if the Boost::Chrono library is available */
+#define HAVE_BOOST_CHRONO /**/
+
+/* define if the Boost::Filesystem library is available */
+#define HAVE_BOOST_FILESYSTEM /**/
+
+/* define if the Boost::PROGRAM_OPTIONS library is available */
+#define HAVE_BOOST_PROGRAM_OPTIONS /**/
+
+/* define if the Boost::System library is available */
+#define HAVE_BOOST_SYSTEM /**/
+
+/* define if the Boost::Thread library is available */
+#define HAVE_BOOST_THREAD /**/
+
+/* define if the Boost::Unit_Test_Framework library is available */
+#define HAVE_BOOST_UNIT_TEST_FRAMEWORK /**/
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_BYTESWAP_H */
+
+/* Define this symbol if the consensus lib has been built */
+#define HAVE_CONSENSUS_LIB 1
+
+/* define if the compiler supports basic C++11 syntax */
+#define HAVE_CXX11 1
+
+/* Define to 1 if you have the declaration of `be16toh', and to 0 if you
+ don't. */
+#define HAVE_DECL_BE16TOH 0
+
+/* Define to 1 if you have the declaration of `be32toh', and to 0 if you
+ don't. */
+#define HAVE_DECL_BE32TOH 0
+
+/* Define to 1 if you have the declaration of `be64toh', and to 0 if you
+ don't. */
+#define HAVE_DECL_BE64TOH 0
+
+/* Define to 1 if you have the declaration of `bswap_16', and to 0 if you
+ don't. */
+#define HAVE_DECL_BSWAP_16 0
+
+/* Define to 1 if you have the declaration of `bswap_32', and to 0 if you
+ don't. */
+#define HAVE_DECL_BSWAP_32 0
+
+/* Define to 1 if you have the declaration of `bswap_64', and to 0 if you
+ don't. */
+#define HAVE_DECL_BSWAP_64 0
+
+/* Define to 1 if you have the declaration of `daemon', and to 0 if you don't.
+ */
+#define HAVE_DECL_DAEMON 0
+
+/* Define to 1 if you have the declaration of `EVP_MD_CTX_new', and to 0 if
+ you don't. */
+//#define HAVE_DECL_EVP_MD_CTX_NEW 1
+
+/* Define to 1 if you have the declaration of `htobe16', and to 0 if you
+ don't. */
+#define HAVE_DECL_HTOBE16 0
+
+/* Define to 1 if you have the declaration of `htobe32', and to 0 if you
+ don't. */
+#define HAVE_DECL_HTOBE32 0
+
+/* Define to 1 if you have the declaration of `htobe64', and to 0 if you
+ don't. */
+#define HAVE_DECL_HTOBE64 0
+
+/* Define to 1 if you have the declaration of `htole16', and to 0 if you
+ don't. */
+#define HAVE_DECL_HTOLE16 0
+
+/* Define to 1 if you have the declaration of `htole32', and to 0 if you
+ don't. */
+#define HAVE_DECL_HTOLE32 0
+
+/* Define to 1 if you have the declaration of `htole64', and to 0 if you
+ don't. */
+#define HAVE_DECL_HTOLE64 0
+
+/* Define to 1 if you have the declaration of `le16toh', and to 0 if you
+ don't. */
+#define HAVE_DECL_LE16TOH 0
+
+/* Define to 1 if you have the declaration of `le32toh', and to 0 if you
+ don't. */
+#define HAVE_DECL_LE32TOH 0
+
+/* Define to 1 if you have the declaration of `le64toh', and to 0 if you
+ don't. */
+#define HAVE_DECL_LE64TOH 0
+
+/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRERROR_R 0
+
+/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRNLEN 1
+
+/* Define to 1 if you have the declaration of `__builtin_clz', and to 0 if you
+ don't. */
+//#define HAVE_DECL___BUILTIN_CLZ 1
+
+/* Define to 1 if you have the declaration of `__builtin_clzl', and to 0 if
+ you don't. */
+//#define HAVE_DECL___BUILTIN_CLZL 1
+
+/* Define to 1 if you have the declaration of `__builtin_clzll', and to 0 if
+ you don't. */
+//#define HAVE_DECL___BUILTIN_CLZLL 1
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_DLFCN_H */
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_ENDIAN_H */
+
+/* Define to 1 if the system has the `dllexport' function attribute */
+#define HAVE_FUNC_ATTRIBUTE_DLLEXPORT 1
+
+/* Define to 1 if the system has the `dllimport' function attribute */
+#define HAVE_FUNC_ATTRIBUTE_DLLIMPORT 1
+
+/* Define to 1 if the system has the `visibility' function attribute */
+#define HAVE_FUNC_ATTRIBUTE_VISIBILITY 1
+
+/* Define this symbol if the BSD getentropy system call is available */
+/* #undef HAVE_GETENTROPY */
+
+/* Define this symbol if the BSD getentropy system call is available with
+ sys/random.h */
+/* #undef HAVE_GETENTROPY_RAND */
+
+/* Define to 1 if you have the header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the `advapi32' library (-ladvapi32). */
+#define HAVE_LIBADVAPI32 1
+
+/* Define to 1 if you have the `comctl32' library (-lcomctl32). */
+#define HAVE_LIBCOMCTL32 1
+
+/* Define to 1 if you have the `comdlg32' library (-lcomdlg32). */
+#define HAVE_LIBCOMDLG32 1
+
+/* Define to 1 if you have the `crypt32' library (-lcrypt32). */
+#define HAVE_LIBCRYPT32 1
+
+/* Define to 1 if you have the `gdi32' library (-lgdi32). */
+#define HAVE_LIBGDI32 1
+
+/* Define to 1 if you have the `imm32' library (-limm32). */
+#define HAVE_LIBIMM32 1
+
+/* Define to 1 if you have the `iphlpapi' library (-liphlpapi). */
+#define HAVE_LIBIPHLPAPI 1
+
+/* Define to 1 if you have the `kernel32' library (-lkernel32). */
+#define HAVE_LIBKERNEL32 1
+
+/* Define to 1 if you have the `mingwthrd' library (-lmingwthrd). */
+#define HAVE_LIBMINGWTHRD 1
+
+/* Define to 1 if you have the `mswsock' library (-lmswsock). */
+#define HAVE_LIBMSWSOCK 1
+
+/* Define to 1 if you have the `ole32' library (-lole32). */
+#define HAVE_LIBOLE32 1
+
+/* Define to 1 if you have the `oleaut32' library (-loleaut32). */
+#define HAVE_LIBOLEAUT32 1
+
+/* Define to 1 if you have the `rpcrt4' library (-lrpcrt4). */
+#define HAVE_LIBRPCRT4 1
+
+/* Define to 1 if you have the `rt' library (-lrt). */
+/* #undef HAVE_LIBRT */
+
+/* Define to 1 if you have the `shell32' library (-lshell32). */
+#define HAVE_LIBSHELL32 1
+
+/* Define to 1 if you have the `shlwapi' library (-lshlwapi). */
+#define HAVE_LIBSHLWAPI 1
+
+/* Define to 1 if you have the `ssp' library (-lssp). */
+#define HAVE_LIBSSP 1
+
+/* Define to 1 if you have the `user32' library (-luser32). */
+#define HAVE_LIBUSER32 1
+
+/* Define to 1 if you have the `uuid' library (-luuid). */
+#define HAVE_LIBUUID 1
+
+/* Define to 1 if you have the `winmm' library (-lwinmm). */
+#define HAVE_LIBWINMM 1
+
+/* Define to 1 if you have the `winspool' library (-lwinspool). */
+#define HAVE_LIBWINSPOOL 1
+
+/* Define to 1 if you have the `ws2_32' library (-lws2_32). */
+#define HAVE_LIBWS2_32 1
+
+/* Define to 1 if you have the `z ' library (-lz ). */
+#define HAVE_LIBZ_ 1
+
+/* Define this symbol if you have malloc_info */
+/* #undef HAVE_MALLOC_INFO */
+
+/* Define this symbol if you have mallopt with M_ARENA_MAX */
+/* #undef HAVE_MALLOPT_ARENA_MAX */
+
+/* Define to 1 if you have the header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_MINIUPNPC_MINIUPNPC_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_MINIUPNPC_MINIWGET_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_MINIUPNPC_UPNPCOMMANDS_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_MINIUPNPC_UPNPERRORS_H 1
+
+/* Define this symbol if you have MSG_DONTWAIT */
+/* #undef HAVE_MSG_DONTWAIT */
+
+/* Define this symbol if you have MSG_NOSIGNAL */
+/* #undef HAVE_MSG_NOSIGNAL */
+
+/* Define if you have POSIX threads libraries and header files. */
+//#define HAVE_PTHREAD 1
+
+/* Have PTHREAD_PRIO_INHERIT. */
+//#define HAVE_PTHREAD_PRIO_INHERIT 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strerror_r' function. */
+/* #undef HAVE_STRERROR_R */
+
+/* Define to 1 if you have the header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_STRING_H 1
+
+/* Define this symbol if the BSD sysctl(KERN_ARND) is available */
+/* #undef HAVE_SYSCTL_ARND */
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_SYS_ENDIAN_H */
+
+/* Define this symbol if the Linux getrandom system call is available */
+/* #undef HAVE_SYS_GETRANDOM */
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_SYS_PRCTL_H */
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_SYS_SELECT_H */
+
+/* Define to 1 if you have the header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the header file. */
+//#define HAVE_UNISTD_H 1
+
+/* Define if the visibility attribute is supported. */
+#define HAVE_VISIBILITY_ATTRIBUTE 1
+
+/* Define this symbol if boost sleep works */
+/* #undef HAVE_WORKING_BOOST_SLEEP */
+
+/* Define this symbol if boost sleep_for works */
+#define HAVE_WORKING_BOOST_SLEEP_FOR 1
+
+/* Define to the sub-directory where libtool stores uninstalled libraries. */
+#define LT_OBJDIR ".libs/"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "https://github.com/defich/ain/issues"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "DeFi Blockchain"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "DeFi Blockchain 1.0.0"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "defi"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL "https://defichain.io/"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "1.0.0"
+
+/* Define to necessary symbol if this constant uses a non-standard name on
+ your system. */
+/* #undef PTHREAD_CREATE_JOINABLE */
+
+/* Define this symbol if the qt platform is cocoa */
+/* #undef QT_QPA_PLATFORM_COCOA */
+
+/* Define this symbol if the minimal qt platform exists */
+#define QT_QPA_PLATFORM_MINIMAL 1
+
+/* Define this symbol if the qt platform is windows */
+#define QT_QPA_PLATFORM_WINDOWS 1
+
+/* Define this symbol if the qt platform is xcb */
+/* #undef QT_QPA_PLATFORM_XCB */
+
+/* Define this symbol if qt plugins are static */
+#define QT_STATICPLUGIN 1
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if strerror_r returns char *. */
+/* #undef STRERROR_R_CHAR_P */
+
+/* Define this symbol to build in assembly routines */
+//#define USE_ASM 1
+
+/* Define this symbol if coverage is enabled */
+/* #undef USE_COVERAGE */
+
+/* Define if dbus support should be compiled in */
+/* #undef USE_DBUS */
+
+/* Define if QR support should be compiled in */
+//#define USE_QRCODE 1
+
+/* UPnP support not compiled if undefined, otherwise value (0 or 1) determines
+ default state */
+//#define USE_UPNP 0
+
+/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+ significant byte first (like Motorola and SPARC, unlike Intel). */
+#if defined AC_APPLE_UNIVERSAL_BUILD
+# if defined __BIG_ENDIAN__
+# define WORDS_BIGENDIAN 1
+# endif
+#else
+# ifndef WORDS_BIGENDIAN
+/* # undef WORDS_BIGENDIAN */
+# endif
+#endif
+
+/* Enable large inode numbers on Mac OS X 10.5. */
+#ifndef _DARWIN_USE_64_BIT_INODE
+# define _DARWIN_USE_64_BIT_INODE 1
+#endif
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+#define _FILE_OFFSET_BITS 64
+
+/* Define for large files, on AIX-style hosts. */
+/* #undef _LARGE_FILES */
+
+/* Windows Universal Platform constraints */
+#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
+/* Either a desktop application without API restrictions, or and older system
+ before these macros were defined. */
+
+/* ::wsystem is available */
+#define HAVE_SYSTEM 1
+
+#endif // !WINAPI_FAMILY || WINAPI_FAMILY_DESKTOP_APP
+
+#endif //DEFI_DEFI_CONFIG_H
diff --git a/build_msvc/libdefi_cli/libdefi_cli.vcxproj.in b/build_msvc/libdefi_cli/libdefi_cli.vcxproj.in
new file mode 100644
index 0000000000..620df72a2f
--- /dev/null
+++ b/build_msvc/libdefi_cli/libdefi_cli.vcxproj.in
@@ -0,0 +1,16 @@
+
+
+
+
+ {0667528C-D734-4009-ADF9-C0D6C4A5A5A6}
+
+
+ StaticLibrary
+
+
+@SOURCE_FILES@
+
+
+
+
+
diff --git a/build_msvc/libdefi_common/libdefi_common.vcxproj.in b/build_msvc/libdefi_common/libdefi_common.vcxproj.in
new file mode 100644
index 0000000000..b47d62b295
--- /dev/null
+++ b/build_msvc/libdefi_common/libdefi_common.vcxproj.in
@@ -0,0 +1,16 @@
+
+
+
+
+ {7C87E378-DF58-482E-AA2F-1BC129BC19CE}
+
+
+ StaticLibrary
+
+
+@SOURCE_FILES@
+
+
+
+
+
diff --git a/build_msvc/libdefi_crypto/libdefi_crypto.vcxproj.in b/build_msvc/libdefi_crypto/libdefi_crypto.vcxproj.in
new file mode 100644
index 0000000000..32cb75bf87
--- /dev/null
+++ b/build_msvc/libdefi_crypto/libdefi_crypto.vcxproj.in
@@ -0,0 +1,16 @@
+
+
+
+
+ {6190199C-6CF4-4DAD-BFBD-93FA72A760C1}
+
+
+ StaticLibrary
+
+
+@SOURCE_FILES@
+
+
+
+
+
diff --git a/build_msvc/libdefi_server/libdefi_server.vcxproj.in b/build_msvc/libdefi_server/libdefi_server.vcxproj.in
new file mode 100644
index 0000000000..58e90dbaeb
--- /dev/null
+++ b/build_msvc/libdefi_server/libdefi_server.vcxproj.in
@@ -0,0 +1,19 @@
+
+
+
+
+ {460FEE33-1FE1-483F-B3BF-931FF8E969A5}
+
+
+ StaticLibrary
+
+
+@SOURCE_FILES@
+
+ $(IntDir)wallet_init.obj
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build_msvc/libdefi_util/libdefi_util.vcxproj.in b/build_msvc/libdefi_util/libdefi_util.vcxproj.in
new file mode 100644
index 0000000000..adf4fa0354
--- /dev/null
+++ b/build_msvc/libdefi_util/libdefi_util.vcxproj.in
@@ -0,0 +1,16 @@
+
+
+
+
+ {B53A5535-EE9D-4C6F-9A26-F79EE3BC3754}
+
+
+ StaticLibrary
+
+
+@SOURCE_FILES@
+
+
+
+
+
diff --git a/build_msvc/libdefi_wallet/libdefi_wallet.vcxproj.in b/build_msvc/libdefi_wallet/libdefi_wallet.vcxproj.in
new file mode 100644
index 0000000000..9c8279c72a
--- /dev/null
+++ b/build_msvc/libdefi_wallet/libdefi_wallet.vcxproj.in
@@ -0,0 +1,16 @@
+
+
+
+
+ {93B86837-B543-48A5-A89B-7C87ABB77DF2}
+
+
+ StaticLibrary
+
+
+@SOURCE_FILES@
+
+
+
+
+
diff --git a/build_msvc/libdefi_wallet_tool/libdefi_wallet_tool.vcxproj.in b/build_msvc/libdefi_wallet_tool/libdefi_wallet_tool.vcxproj.in
new file mode 100644
index 0000000000..1a6b7b6b92
--- /dev/null
+++ b/build_msvc/libdefi_wallet_tool/libdefi_wallet_tool.vcxproj.in
@@ -0,0 +1,16 @@
+
+
+
+
+ {F91AC55E-6F5E-4C58-9AC5-B40DB7DEEF93}
+
+
+ StaticLibrary
+
+
+@SOURCE_FILES@
+
+
+
+
+
diff --git a/build_msvc/libdefi_zmq/libdefi_zmq.vcxproj.in b/build_msvc/libdefi_zmq/libdefi_zmq.vcxproj.in
new file mode 100644
index 0000000000..e86eea81e6
--- /dev/null
+++ b/build_msvc/libdefi_zmq/libdefi_zmq.vcxproj.in
@@ -0,0 +1,16 @@
+
+
+
+
+ {792D487F-F14C-49FC-A9DE-3FC150F31C3F}
+
+
+ StaticLibrary
+
+
+@SOURCE_FILES@
+
+
+
+
+
diff --git a/build_msvc/libleveldb/libleveldb.vcxproj b/build_msvc/libleveldb/libleveldb.vcxproj
new file mode 100644
index 0000000000..f855923c62
--- /dev/null
+++ b/build_msvc/libleveldb/libleveldb.vcxproj
@@ -0,0 +1,63 @@
+
+
+
+
+ {18430FEF-6B61-4C53-B396-718E02850F1B}
+
+
+ StaticLibrary
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ _CRT_NONSTDC_NO_DEPRECATE;LEVELDB_PLATFORM_WINDOWS;LEVELDB_ATOMIC_PRESENT;%(PreprocessorDefinitions)
+ 4244;4267;4312;
+ ..\..\src\leveldb;..\..\src\leveldb\include;%(AdditionalIncludeDirectories)
+
+
+
+
+
+
diff --git a/build_msvc/libsecp256k1/libsecp256k1.vcxproj b/build_msvc/libsecp256k1/libsecp256k1.vcxproj
new file mode 100644
index 0000000000..99fb63fb02
--- /dev/null
+++ b/build_msvc/libsecp256k1/libsecp256k1.vcxproj
@@ -0,0 +1,22 @@
+
+
+
+
+ {BB493552-3B8C-4A8C-BF69-A6E7A51D2EA6}
+
+
+ StaticLibrary
+
+
+
+
+
+
+ ENABLE_MODULE_ECDH;ENABLE_MODULE_RECOVERY;%(PreprocessorDefinitions)
+ ..\..\src\secp256k1;%(AdditionalIncludeDirectories)
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build_msvc/libsecp256k1_config.h b/build_msvc/libsecp256k1_config.h
new file mode 100644
index 0000000000..a48f17538c
--- /dev/null
+++ b/build_msvc/libsecp256k1_config.h
@@ -0,0 +1,29 @@
+/**********************************************************************
+ * Copyright (c) 2013, 2014 Pieter Wuille *
+ * Distributed under the MIT software license, see the accompanying *
+ * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ **********************************************************************/
+
+#ifndef DEFI_LIBSECP256K1_CONFIG_H
+#define DEFI_LIBSECP256K1_CONFIG_H
+
+#undef USE_ASM_X86_64
+#undef USE_ENDOMORPHISM
+#undef USE_FIELD_10X26
+#undef USE_FIELD_5X52
+#undef USE_FIELD_INV_BUILTIN
+#undef USE_FIELD_INV_NUM
+#undef USE_NUM_GMP
+#undef USE_NUM_NONE
+#undef USE_SCALAR_4X64
+#undef USE_SCALAR_8X32
+#undef USE_SCALAR_INV_BUILTIN
+#undef USE_SCALAR_INV_NUM
+
+#define USE_NUM_NONE 1
+#define USE_FIELD_INV_BUILTIN 1
+#define USE_SCALAR_INV_BUILTIN 1
+#define USE_FIELD_10X26 1
+#define USE_SCALAR_8X32 1
+
+#endif /* DEFI_LIBSECP256K1_CONFIG_H */
diff --git a/build_msvc/libunivalue/libunivalue.vcxproj b/build_msvc/libunivalue/libunivalue.vcxproj
new file mode 100644
index 0000000000..0f13a57241
--- /dev/null
+++ b/build_msvc/libunivalue/libunivalue.vcxproj
@@ -0,0 +1,19 @@
+
+
+
+
+ {5724BA7D-A09A-4BA8-800B-C4C1561B3D69}
+
+
+ StaticLibrary
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build_msvc/msbuild/tasks/hexdump.targets b/build_msvc/msbuild/tasks/hexdump.targets
new file mode 100644
index 0000000000..12868a9874
--- /dev/null
+++ b/build_msvc/msbuild/tasks/hexdump.targets
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ outFileInfo.LastWriteTime)
+ {
+ using (Stream inStm = File.OpenRead(RawFilePath))
+ {
+ using (StreamWriter sw = new StreamWriter(HeaderFilePath))
+ {
+ sw.WriteLine(SourceHeader);
+ int count = 0;
+ int rawChar = inStm.ReadByte();
+ while(rawChar != -1)
+ {
+ sw.Write("0x{0:x2}, ", rawChar);
+ count++;
+ if(count % 8 == 0)
+ {
+ sw.WriteLine();
+ }
+ rawChar = inStm.ReadByte();
+ }
+ sw.WriteLine(SourceFooter);
+ }
+ }
+ }
+}
+]]>
+
+
+
+
\ No newline at end of file
diff --git a/build_msvc/msbuild/tasks/replaceinfile.targets b/build_msvc/msbuild/tasks/replaceinfile.targets
new file mode 100644
index 0000000000..2ccb8b30e0
--- /dev/null
+++ b/build_msvc/msbuild/tasks/replaceinfile.targets
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build_msvc/msvc-autogen.py b/build_msvc/msvc-autogen.py
new file mode 100644
index 0000000000..08eefa712b
--- /dev/null
+++ b/build_msvc/msvc-autogen.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python3
+
+import os
+import re
+import argparse
+from shutil import copyfile
+
+SOURCE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src'))
+DEFAULT_PLATFORM_TOOLSET = R'v141'
+
+libs = [
+ 'libdefi_cli',
+ 'libdefi_common',
+ 'libdefi_crypto',
+ 'libdefi_server',
+ 'libdefi_util',
+ 'libdefi_wallet_tool',
+ 'libdefi_wallet',
+ 'libdefi_zmq',
+ 'bench_defi',
+]
+
+ignore_list = [
+]
+
+lib_sources = {}
+
+
+def parse_makefile(makefile):
+ with open(makefile, 'r', encoding='utf-8') as file:
+ current_lib = ''
+ for line in file.read().splitlines():
+ if current_lib:
+ source = line.split()[0]
+ if source.endswith('.cpp') and not source.startswith('$') and source not in ignore_list:
+ source_filename = source.replace('/', '\\')
+ object_filename = source.replace('/', '_')[:-4] + ".obj"
+ lib_sources[current_lib].append((source_filename, object_filename))
+ if not line.endswith('\\'):
+ current_lib = ''
+ continue
+ for lib in libs:
+ _lib = lib.replace('-', '_')
+ if re.search(_lib + '.*_SOURCES \\= \\\\', line):
+ current_lib = lib
+ lib_sources[current_lib] = []
+ break
+
+def set_common_properties(toolset):
+ with open(os.path.join(SOURCE_DIR, '../build_msvc/common.init.vcxproj'), 'r', encoding='utf-8') as rfile:
+ s = rfile.read()
+ s = re.sub('.*?', ''+toolset+'', s)
+ with open(os.path.join(SOURCE_DIR, '../build_msvc/common.init.vcxproj'), 'w', encoding='utf-8',newline='\n') as wfile:
+ wfile.write(s)
+
+def main():
+ parser = argparse.ArgumentParser(description='Defi-core msbuild configuration initialiser.')
+ parser.add_argument('-toolset', nargs='?',help='Optionally sets the msbuild platform toolset, e.g. v142 for Visual Studio 2019.'
+ ' default is %s.'%DEFAULT_PLATFORM_TOOLSET)
+ args = parser.parse_args()
+ if args.toolset:
+ set_common_properties(args.toolset)
+
+ for makefile_name in os.listdir(SOURCE_DIR):
+ if 'Makefile' in makefile_name:
+ parse_makefile(os.path.join(SOURCE_DIR, makefile_name))
+ for key, value in lib_sources.items():
+ vcxproj_filename = os.path.abspath(os.path.join(os.path.dirname(__file__), key, key + '.vcxproj'))
+ content = ''
+ for source_filename, object_filename in value:
+ content += ' \n'
+ content += ' $(IntDir)' + object_filename + '\n'
+ content += ' \n'
+ with open(vcxproj_filename + '.in', 'r', encoding='utf-8') as vcxproj_in_file:
+ with open(vcxproj_filename, 'w', encoding='utf-8') as vcxproj_file:
+ vcxproj_file.write(vcxproj_in_file.read().replace(
+ '@SOURCE_FILES@\n', content))
+ copyfile(os.path.join(SOURCE_DIR,'../build_msvc/defi_config.h'), os.path.join(SOURCE_DIR, 'config/defi-config.h'))
+ copyfile(os.path.join(SOURCE_DIR,'../build_msvc/libsecp256k1_config.h'), os.path.join(SOURCE_DIR, 'secp256k1/src/libsecp256k1-config.h'))
+
+if __name__ == '__main__':
+ main()
diff --git a/build_msvc/testconsensus/testconsensus.cpp b/build_msvc/testconsensus/testconsensus.cpp
new file mode 100644
index 0000000000..9b25686d42
--- /dev/null
+++ b/build_msvc/testconsensus/testconsensus.cpp
@@ -0,0 +1,50 @@
+#include
+
+// defi includes.
+#include <..\src\script\deficonsensus.h>
+#include <..\src\primitives\transaction.h>
+#include <..\src\script\script.h>
+#include <..\src\streams.h>
+#include <..\src\version.h>
+
+CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CScriptWitness& scriptWitness, int nValue = 0)
+{
+ CMutableTransaction txSpend;
+ txSpend.nVersion = 1;
+ txSpend.nLockTime = 0;
+ txSpend.vin.resize(1);
+ txSpend.vout.resize(1);
+ txSpend.vin[0].scriptWitness = scriptWitness;
+ txSpend.vin[0].prevout.hash = uint256();
+ txSpend.vin[0].prevout.n = 0;
+ txSpend.vin[0].scriptSig = scriptSig;
+ txSpend.vin[0].nSequence = CTxIn::SEQUENCE_FINAL;
+ txSpend.vout[0].scriptPubKey = CScript();
+ txSpend.vout[0].nValue = nValue;
+
+ return txSpend;
+}
+
+int main()
+{
+ std::cout << "deficonsensus version: " << deficonsensus_version() << std::endl;
+
+ CScript pubKeyScript;
+ pubKeyScript << OP_1 << OP_0 << OP_1;
+
+ int amount = 0; // 600000000;
+
+ CScript scriptSig;
+ CScriptWitness scriptWitness;
+ CTransaction vanillaSpendTx = BuildSpendingTransaction(scriptSig, scriptWitness, amount);
+ CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
+ stream << vanillaSpendTx;
+
+ deficonsensus_error err;
+ auto op0Result = deficonsensus_verify_script_with_amount(pubKeyScript.data(), pubKeyScript.size(), amount, (const unsigned char*)&stream[0], stream.size(), 0, deficonsensus_SCRIPT_FLAGS_VERIFY_ALL, &err);
+ std::cout << "Op0 result: " << op0Result << ", error code " << err << std::endl;
+
+ getchar();
+
+ return 0;
+}
diff --git a/build_msvc/testconsensus/testconsensus.vcxproj b/build_msvc/testconsensus/testconsensus.vcxproj
new file mode 100644
index 0000000000..dd20dcbbf1
--- /dev/null
+++ b/build_msvc/testconsensus/testconsensus.vcxproj
@@ -0,0 +1,28 @@
+
+
+
+
+ {E78473E9-B850-456C-9120-276301E04C06}
+
+
+ Application
+ $(SolutionDir)$(Platform)\$(Configuration)\
+
+
+
+
+
+
+ {2B384FA8-9EE1-4544-93CB-0D733C25E8CE}
+
+
+ {B53A5535-EE9D-4C6F-9A26-F79EE3BC3754}
+
+
+ {BB493552-3B8C-4A8C-BF69-A6E7A51D2EA6}
+
+
+
+
+
+
diff --git a/ci/README.md b/ci/README.md
new file mode 100644
index 0000000000..16c481158f
--- /dev/null
+++ b/ci/README.md
@@ -0,0 +1,31 @@
+## ci scripts
+
+This directory contains scripts for each build step in each build stage.
+
+Currently three stages `lint`, `extended_lint` and `test` are defined. Each stage has its own lifecycle, similar to the
+[Travis CI lifecycle](https://docs.travis-ci.com/user/job-lifecycle#the-job-lifecycle). Every script in here is named
+and numbered according to which stage and lifecycle step it belongs to.
+
+### Running a stage locally
+
+To allow for a wide range of tested environments, but also ensure reproducibility to some extent, the test stage
+requires `docker` to be installed. To install all requirements on Ubuntu, run
+
+```
+sudo apt install docker.io ccache bash git
+```
+
+To run the default test stage,
+
+```
+./ci/test_run_all.sh
+```
+
+To run the test stage with a specific configuration,
+
+```
+FILE_ENV="./ci/test/00_setup_env_arm.sh" ./ci/test_run_all.sh
+```
+
+Be aware that the tests will be build and run in-place, so please run at your own risk.
+If the repository is not a fresh git clone, you might have to clean files from previous builds or test runs first.
diff --git a/ci/extended_lint/04_install.sh b/ci/extended_lint/04_install.sh
new file mode 100755
index 0000000000..123d874a84
--- /dev/null
+++ b/ci/extended_lint/04_install.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+
+CPPCHECK_VERSION=1.86
+curl -s https://codeload.github.com/danmar/cppcheck/tar.gz/${CPPCHECK_VERSION} | tar -zxf - --directory /tmp/
+(cd /tmp/cppcheck-${CPPCHECK_VERSION}/ && make CFGDIR=/tmp/cppcheck-${CPPCHECK_VERSION}/cfg/ > /dev/null)
+export PATH="$PATH:/tmp/cppcheck-${CPPCHECK_VERSION}/"
diff --git a/ci/extended_lint/06_script.sh b/ci/extended_lint/06_script.sh
new file mode 100755
index 0000000000..e8228c9c4d
--- /dev/null
+++ b/ci/extended_lint/06_script.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+
+test/lint/extended-lint-all.sh
diff --git a/ci/lint/04_install.sh b/ci/lint/04_install.sh
new file mode 100755
index 0000000000..20bff368a5
--- /dev/null
+++ b/ci/lint/04_install.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+
+travis_retry pip3 install codespell==1.15.0
+travis_retry pip3 install flake8==3.5.0
+travis_retry pip3 install vulture==0.29
+
+SHELLCHECK_VERSION=v0.6.0
+curl -s "https://storage.googleapis.com/shellcheck/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar --xz -xf - --directory /tmp/
+export PATH="/tmp/shellcheck-${SHELLCHECK_VERSION}:${PATH}"
diff --git a/ci/lint/05_before_script.sh b/ci/lint/05_before_script.sh
new file mode 100755
index 0000000000..28bcbb47f7
--- /dev/null
+++ b/ci/lint/05_before_script.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+
+git fetch --unshallow
diff --git a/ci/lint/06_script.sh b/ci/lint/06_script.sh
new file mode 100755
index 0000000000..18084a57f5
--- /dev/null
+++ b/ci/lint/06_script.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+
+if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
+ test/lint/commit-script-check.sh $TRAVIS_COMMIT_RANGE
+fi
+
+test/lint/git-subtree-check.sh src/crypto/ctaes
+test/lint/git-subtree-check.sh src/secp256k1
+test/lint/git-subtree-check.sh src/univalue
+test/lint/git-subtree-check.sh src/leveldb
+test/lint/check-doc.py
+test/lint/check-rpc-mappings.py .
+test/lint/lint-all.sh
+
+if [ "$TRAVIS_REPO_SLUG" = "defich/ain" ] && [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then
+ git log --merges --before="2 days ago" -1 --format='%H' > ./contrib/verify-commits/trusted-sha512-root-commit
+ travis_retry gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys $( $max_sleep ? $max_sleep : t)}"`
+ fi
+}
+
+__log_out() {
+ echo "$1" 1>&2
+}
+
+# Paramters: max_tries min_sleep max_sleep constant_sleep fail_script EXECUTION_COMMAND
+retry()
+{
+ local max_tries="$1"; shift
+ local min_sleep="$1"; shift
+ local max_sleep="$1"; shift
+ local constant_sleep="$1"; shift
+ local fail_script="$1"; shift
+ if [ -n "$VERBOSE" ]; then
+ __log_out "Retry Parameters: max_tries=$max_tries min_sleep=$min_sleep max_sleep=$max_sleep constant_sleep=$constant_sleep"
+ if [ -n "$fail_script" ]; then __log_out "Fail script: $fail_script"; fi
+ __log_out ""
+ __log_out "Execution Command: $*"
+ __log_out ""
+ fi
+
+ local attempts=0
+ local return_code=1
+
+
+ while [[ $return_code -ne 0 && $attempts -le $max_tries ]]; do
+ if [ $attempts -gt 0 ]; then
+ __sleep_amount
+ __log_out "Before retry #$attempts: sleeping $sleep_time seconds"
+ sleep $sleep_time
+ fi
+
+ P="$1"
+ for param in "${@:2}"; do P="$P '$param'"; done
+ #TODO: replace single quotes in each arg with '"'"' ?
+ export RETRY_ATTEMPT=$attempts
+ bash -c "$P"
+ return_code=$?
+ #__log_out "Process returned $return_code on attempt $attempts"
+ if [ $return_code -eq 127 ]; then
+ # command not found
+ exit $return_code
+ elif [ $return_code -ne 0 ]; then
+ attempts=$[$attempts +1]
+ fi
+ done
+
+ if [ $attempts -gt $max_tries ]; then
+ if [ -n "$fail_script" ]; then
+ __log_out "Retries exhausted, running fail script"
+ eval $fail_script
+ else
+ __log_out "Retries exhausted"
+ fi
+ fi
+
+ exit $return_code
+}
+
+# If we're being sourced, don't worry about such things
+if [ "$BASH_SOURCE" == "$0" ]; then
+ # Prints the help text
+ help()
+ {
+ local retry=$(basename $0)
+ cat < /dev/null
+ if [[ $? -ne 4 ]]; then
+ echo "I’m sorry, 'getopt --test' failed in this environment. Please load GNU getopt."
+ exit 1
+ fi
+
+ OPTIONS=vt:s:m:x:f:
+ LONGOPTIONS=verbose,tries:,sleep:,min:,max:,fail:
+
+ PARSED=$($GETOPT_BIN --options="$OPTIONS" --longoptions="$LONGOPTIONS" --name "$0" -- "$@")
+ if [[ $? -ne 0 ]]; then
+ # e.g. $? == 1
+ # then getopt has complained about wrong arguments to stdout
+ exit 2
+ fi
+ # read getopt’s output this way to handle the quoting right:
+ eval set -- "$PARSED"
+
+ max_tries=10
+ min_sleep=0.3
+ max_sleep=60.0
+ constant_sleep=
+ fail_script=
+
+ # now enjoy the options in order and nicely split until we see --
+ while true; do
+ case "$1" in
+ -v|--verbose)
+ VERBOSE=true
+ shift
+ ;;
+ -t|--tries)
+ max_tries="$2"
+ shift 2
+ ;;
+ -s|--sleep)
+ constant_sleep="$2"
+ shift 2
+ ;;
+ -m|--min)
+ min_sleep="$2"
+ shift 2
+ ;;
+ -x|--max)
+ max_sleep="$2"
+ shift 2
+ ;;
+ -f|--fail)
+ fail_script="$2"
+ shift 2
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ echo "Programming error"
+ exit 3
+ ;;
+ esac
+ done
+
+ retry "$max_tries" "$min_sleep" "$max_sleep" "$constant_sleep" "$fail_script" "$@"
+
+fi
diff --git a/ci/test/00_setup_env.sh b/ci/test/00_setup_env.sh
new file mode 100755
index 0000000000..51b5cfdd3f
--- /dev/null
+++ b/ci/test/00_setup_env.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+echo "Setting default values in env"
+
+BASE_ROOT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../../ >/dev/null 2>&1 && pwd )
+export BASE_ROOT_DIR
+
+# The number of parallel jobs to pass down to make and test_runner.py
+export MAKEJOBS=${MAKEJOBS:--j4}
+# A folder for the ci system to put temporary files (ccache, datadirs for tests, ...)
+export BASE_SCRATCH_DIR=${BASE_SCRATCH_DIR:-$BASE_ROOT_DIR/ci/scratch/}
+export HOST=${HOST:-x86_64-unknown-linux-gnu}
+export RUN_UNIT_TESTS=${RUN_UNIT_TESTS:-true}
+export RUN_FUNCTIONAL_TESTS=${RUN_FUNCTIONAL_TESTS:-true}
+export RUN_FUZZ_TESTS=${RUN_FUZZ_TESTS:-false}
+export DOCKER_NAME_TAG=${DOCKER_NAME_TAG:-ubuntu:18.04}
+export BOOST_TEST_RANDOM=${BOOST_TEST_RANDOM:-1$TRAVIS_BUILD_ID}
+export CCACHE_SIZE=${CCACHE_SIZE:-100M}
+export CCACHE_TEMPDIR=${CCACHE_TEMPDIR:-/tmp/.ccache-temp}
+export CCACHE_COMPRESS=${CCACHE_COMPRESS:-1}
+export CCACHE_DIR=${CCACHE_DIR:-$BASE_SCRATCH_DIR/.ccache}
+export BASE_BUILD_DIR=${BASE_BUILD_DIR:-${TRAVIS_BUILD_DIR:-$BASE_ROOT_DIR}}
+export BASE_OUTDIR=${BASE_OUTDIR:-$BASE_BUILD_DIR/out/$HOST}
+export SDK_URL=${SDK_URL:-https://bitcoincore.org/depends-sources/sdks}
+export WINEDEBUG=${WINEDEBUG:-fixme-all}
+export DOCKER_PACKAGES=${DOCKER_PACKAGES:-build-essential libtool autotools-dev automake pkg-config bsdmainutils curl ca-certificates ccache python3}
+export GOAL=${GOAL:-install}
+export DIR_QA_ASSETS=${DIR_QA_ASSETS:-${BASE_BUILD_DIR}/qa-assets}
+export PATH=${BASE_ROOT_DIR}/ci/retry:$PATH
+export CI_RETRY_EXE=${CI_RETRY_EXE:retry}
+
+echo "Setting specific values in env"
+if [ -n "${FILE_ENV}" ]; then
+ set -o errexit;
+ # shellcheck disable=SC1090
+ source "${FILE_ENV}"
+fi
diff --git a/ci/test/00_setup_env_amd64_asan.sh b/ci/test/00_setup_env_amd64_asan.sh
new file mode 100644
index 0000000000..3c1e4ca0df
--- /dev/null
+++ b/ci/test/00_setup_env_amd64_asan.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+export HOST=x86_64-unknown-linux-gnu
+export PACKAGES="clang llvm python3-zmq qtbase5-dev qttools5-dev-tools libssl1.0-dev libevent-dev bsdmainutils libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev libdb5.3++-dev libminiupnpc-dev libzmq3-dev libprotobuf-dev protobuf-compiler libqrencode-dev"
+export NO_DEPENDS=1
+export GOAL="install"
+export DEFI_CONFIG="--enable-zmq --without-gui --with-incompatible-bdb CPPFLAGS=-DDEBUG_LOCKORDER --with-sanitizers=address,integer,undefined CC=clang CXX=clang++"
diff --git a/ci/test/00_setup_env_amd64_fuzz.sh b/ci/test/00_setup_env_amd64_fuzz.sh
new file mode 100644
index 0000000000..f7bfb6f027
--- /dev/null
+++ b/ci/test/00_setup_env_amd64_fuzz.sh
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+export HOST=x86_64-unknown-linux-gnu
+export PACKAGES="clang llvm python3 libssl1.0-dev libevent-dev bsdmainutils libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev"
+export NO_DEPENDS=1
+export RUN_UNIT_TESTS=false
+export RUN_FUNCTIONAL_TESTS=false
+export RUN_FUZZ_TESTS=true
+export GOAL="install"
+export DEFI_CONFIG="--enable-fuzz --without-gui --with-sanitizers=fuzzer,address CC=clang CXX=clang++"
diff --git a/ci/test/00_setup_env_amd64_nowallet.sh b/ci/test/00_setup_env_amd64_nowallet.sh
new file mode 100644
index 0000000000..3d7236ccfa
--- /dev/null
+++ b/ci/test/00_setup_env_amd64_nowallet.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+export HOST=x86_64-unknown-linux-gnu
+export PACKAGES="python3-zmq"
+export DEP_OPTS="NO_WALLET=1"
+export GOAL="install"
+export DEFI_CONFIG="--enable-glibc-back-compat --enable-reduce-exports --without-gui"
diff --git a/ci/test/00_setup_env_amd64_trusty.sh b/ci/test/00_setup_env_amd64_trusty.sh
new file mode 100644
index 0000000000..6222f97937
--- /dev/null
+++ b/ci/test/00_setup_env_amd64_trusty.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+export HOST=x86_64-unknown-linux-gnu
+export DOCKER_NAME_TAG=ubuntu:14.04
+export PACKAGES="python3-zmq qtbase5-dev qttools5-dev-tools libicu-dev libpng-dev libssl-dev libevent-dev bsdmainutils libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev libdb5.1++-dev libzmq3-dev libprotobuf-dev protobuf-compiler libqrencode-dev"
+export NO_DEPENDS=1
+export RUN_FUNCTIONAL_TESTS=false
+export GOAL="install"
+export DEFI_CONFIG="--enable-zmq --with-incompatible-bdb --with-gui=no"
diff --git a/ci/test/00_setup_env_amd64_tsan.sh b/ci/test/00_setup_env_amd64_tsan.sh
new file mode 100644
index 0000000000..6c3cd2017f
--- /dev/null
+++ b/ci/test/00_setup_env_amd64_tsan.sh
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+export HOST=x86_64-unknown-linux-gnu
+export DOCKER_NAME_TAG=ubuntu:16.04
+export PACKAGES="clang llvm python3-zmq qtbase5-dev qttools5-dev-tools libssl-dev libevent-dev bsdmainutils libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev libdb5.3++-dev libminiupnpc-dev libzmq3-dev libprotobuf-dev protobuf-compiler libqrencode-dev"
+export NO_DEPENDS=1
+export GOAL="install"
+export DEFI_CONFIG="--enable-zmq --disable-wallet --without-gui CPPFLAGS=-DDEBUG_LOCKORDER --with-sanitizers=thread --disable-hardening --disable-asm CC=clang CXX=clang++"
diff --git a/ci/test/00_setup_env_arm.sh b/ci/test/00_setup_env_arm.sh
new file mode 100644
index 0000000000..2053c388ac
--- /dev/null
+++ b/ci/test/00_setup_env_arm.sh
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+export HOST=arm-linux-gnueabihf
+export PACKAGES="python3 g++-arm-linux-gnueabihf"
+export RUN_UNIT_TESTS=false
+export RUN_FUNCTIONAL_TESTS=false
+export GOAL="install"
+# -Wno-psabi is to disable ABI warnings: "note: parameter passing for argument of type ... changed in GCC 7.1"
+# This could be removed once the ABI change warning does not show up by default
+export DEFI_CONFIG="--enable-glibc-back-compat --without-gui --enable-reduce-exports CXXFLAGS=-Wno-psabi"
diff --git a/ci/test/00_setup_env_i686.sh b/ci/test/00_setup_env_i686.sh
new file mode 100644
index 0000000000..2ffe070c3a
--- /dev/null
+++ b/ci/test/00_setup_env_i686.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+export HOST=i686-pc-linux-gnu
+export PACKAGES="g++-multilib python3-zmq"
+export GOAL="install"
+export DEFI_CONFIG="--enable-zmq --without-gui --disable-bip70 --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++"
+export CONFIG_SHELL="/bin/dash"
diff --git a/ci/test/00_setup_env_mac.sh b/ci/test/00_setup_env_mac.sh
new file mode 100644
index 0000000000..53677218a3
--- /dev/null
+++ b/ci/test/00_setup_env_mac.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+export HOST=x86_64-apple-darwin14
+export PACKAGES="cmake imagemagick libcap-dev librsvg2-bin libz-dev libbz2-dev libtiff-tools python3-dev python3-setuptools"
+export OSX_SDK=10.11
+export RUN_UNIT_TESTS=false
+export RUN_FUNCTIONAL_TESTS=false
+export GOAL="deploy"
+export DEFI_CONFIG="--without-gui --enable-reduce-exports --enable-werror"
diff --git a/ci/test/00_setup_env_win64.sh b/ci/test/00_setup_env_win64.sh
new file mode 100644
index 0000000000..e68e551bdb
--- /dev/null
+++ b/ci/test/00_setup_env_win64.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+export HOST=x86_64-w64-mingw32
+export PACKAGES="python3 nsis g++-mingw-w64-x86-64 wine-binfmt wine64"
+export RUN_FUNCTIONAL_TESTS=false
+export GOAL="deploy"
+export DEFI_CONFIG="--enable-reduce-exports --without-gui"
diff --git a/ci/test/03_before_install.sh b/ci/test/03_before_install.sh
new file mode 100755
index 0000000000..5086114ba1
--- /dev/null
+++ b/ci/test/03_before_install.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+# Add llvm-symbolizer directory to PATH. Needed to get symbolized stack traces from the sanitizers.
+PATH=$PATH:/usr/lib/llvm-6.0/bin/
+export PATH
+
+BEGIN_FOLD () {
+ echo ""
+ CURRENT_FOLD_NAME=$1
+ echo "travis_fold:start:${CURRENT_FOLD_NAME}"
+}
+
+END_FOLD () {
+ RET=$?
+ echo "travis_fold:end:${CURRENT_FOLD_NAME}"
+ if [ $RET != 0 ]; then
+ echo "${CURRENT_FOLD_NAME} failed with status code ${RET}"
+ fi
+}
+
diff --git a/ci/test/04_install.sh b/ci/test/04_install.sh
new file mode 100755
index 0000000000..4e5ddb238d
--- /dev/null
+++ b/ci/test/04_install.sh
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+mkdir -p "${BASE_SCRATCH_DIR}"
+ccache echo "Creating ccache dir if it didn't already exist"
+
+if [ ! -d ${DIR_QA_ASSETS} ]; then
+ git clone https://github.com/bitcoin-core/qa-assets ${DIR_QA_ASSETS}
+fi
+export DIR_FUZZ_IN=${DIR_QA_ASSETS}/fuzz_seed_corpus/
+
+mkdir -p "${BASE_BUILD_DIR}/sanitizer-output/"
+export ASAN_OPTIONS=""
+export LSAN_OPTIONS="suppressions=${BASE_BUILD_DIR}/test/sanitizer_suppressions/lsan"
+export TSAN_OPTIONS="suppressions=${BASE_BUILD_DIR}/test/sanitizer_suppressions/tsan:log_path=${BASE_BUILD_DIR}/sanitizer-output/tsan"
+export UBSAN_OPTIONS="suppressions=${BASE_BUILD_DIR}/test/sanitizer_suppressions/ubsan:print_stacktrace=1:halt_on_error=1"
+env | grep -E '^(DEFI_CONFIG|CCACHE_|WINEDEBUG|LC_ALL|BOOST_TEST_RANDOM|CONFIG_SHELL|(ASAN|LSAN|TSAN|UBSAN)_OPTIONS)' | tee /tmp/env
+if [[ $HOST = *-mingw32 ]]; then
+ DOCKER_ADMIN="--cap-add SYS_ADMIN"
+elif [[ $DEFI_CONFIG = *--with-sanitizers=*address* ]]; then # If ran with (ASan + LSan), Docker needs access to ptrace (https://github.com/google/sanitizers/issues/764)
+ DOCKER_ADMIN="--cap-add SYS_PTRACE"
+fi
+
+if [ -z "$RUN_CI_ON_HOST" ]; then
+ echo "Creating $DOCKER_NAME_TAG container to run in"
+ ${CI_RETRY_EXE} docker pull "$DOCKER_NAME_TAG"
+
+ DOCKER_ID=$(docker run $DOCKER_ADMIN -idt --mount type=bind,src=$BASE_BUILD_DIR,dst=$BASE_BUILD_DIR --mount type=bind,src=$CCACHE_DIR,dst=$CCACHE_DIR -w $BASE_BUILD_DIR --env-file /tmp/env $DOCKER_NAME_TAG)
+
+ DOCKER_EXEC () {
+ docker exec $DOCKER_ID bash -c "cd $PWD && $*"
+ }
+else
+ echo "Running on host system without docker wrapper"
+ DOCKER_EXEC () {
+ bash -c "cd $PWD && $*"
+ }
+fi
+
+DOCKER_EXEC free -m -h
+DOCKER_EXEC echo "Number of CPUs \(nproc\): $(nproc)"
+
+${CI_RETRY_EXE} DOCKER_EXEC apt-get update
+${CI_RETRY_EXE} DOCKER_EXEC apt-get install --no-install-recommends --no-upgrade -qq $PACKAGES $DOCKER_PACKAGES
+
diff --git a/ci/test/05_before_script.sh b/ci/test/05_before_script.sh
new file mode 100755
index 0000000000..a29bf564f5
--- /dev/null
+++ b/ci/test/05_before_script.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+DOCKER_EXEC echo \> \$HOME/.defi # Make sure default datadir does not exist and is never read by creating a dummy file
+
+mkdir -p depends/SDKs depends/sdk-sources
+
+if [ -n "$OSX_SDK" ] && [ ! -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then
+ curl --location --fail $SDK_URL/MacOSX${OSX_SDK}.sdk.tar.gz -o depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz
+fi
+if [ -n "$OSX_SDK" ] && [ -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then
+ tar -C depends/SDKs -xf depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz
+fi
+if [[ $HOST = *-mingw32 ]]; then
+ DOCKER_EXEC update-alternatives --set $HOST-g++ \$\(which $HOST-g++-posix\)
+fi
+if [ -z "$NO_DEPENDS" ]; then
+ DOCKER_EXEC CONFIG_SHELL= make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS
+fi
diff --git a/ci/test/06_script_a.sh b/ci/test/06_script_a.sh
new file mode 100755
index 0000000000..d9ffc257e8
--- /dev/null
+++ b/ci/test/06_script_a.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+DEFI_CONFIG_ALL="--disable-dependency-tracking --prefix=$BASE_BUILD_DIR/depends/$HOST --bindir=$BASE_OUTDIR/bin --libdir=$BASE_OUTDIR/lib"
+if [ -z "$NO_DEPENDS" ]; then
+ DOCKER_EXEC ccache --max-size=$CCACHE_SIZE
+fi
+
+BEGIN_FOLD autogen
+if [ -n "$CONFIG_SHELL" ]; then
+ DOCKER_EXEC "$CONFIG_SHELL" -c "./autogen.sh"
+else
+ DOCKER_EXEC ./autogen.sh
+fi
+END_FOLD
+
+mkdir -p build
+cd build || (echo "could not enter build directory"; exit 1)
+
+BEGIN_FOLD configure
+DOCKER_EXEC ../configure --cache-file=config.cache $DEFI_CONFIG_ALL $DEFI_CONFIG || ( cat config.log && false)
+END_FOLD
+
+BEGIN_FOLD distdir
+DOCKER_EXEC make distdir VERSION=$HOST
+DOCKER_EXEC cp -r ../share "defi-$HOST/"
+DOCKER_EXEC cp -r ../contrib "defi-$HOST/"
+END_FOLD
+
+cd "defi-$HOST" || (echo "could not enter distdir defi-$HOST"; exit 1)
+
+BEGIN_FOLD configure
+DOCKER_EXEC ./configure --cache-file=../config.cache $DEFI_CONFIG_ALL $DEFI_CONFIG || ( cat config.log && false)
+END_FOLD
+
+set -o errtrace
+trap 'DOCKER_EXEC "cat ${BASE_BUILD_DIR}/sanitizer-output/* 2> /dev/null"' ERR
+
+BEGIN_FOLD build
+DOCKER_EXEC make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && DOCKER_EXEC make $GOAL V=1 ; false )
+END_FOLD
+
+cd ${BASE_BUILD_DIR} || (echo "could not enter travis build dir $BASE_BUILD_DIR"; exit 1)
diff --git a/ci/test/06_script_b.sh b/ci/test/06_script_b.sh
new file mode 100755
index 0000000000..cc5fe5bba9
--- /dev/null
+++ b/ci/test/06_script_b.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+cd "build/defi-$HOST" || (echo "could not enter distdir build/defi-$HOST"; exit 1)
+
+if [ "$RUN_UNIT_TESTS" = "true" ]; then
+ BEGIN_FOLD unit-tests
+ DOCKER_EXEC LD_LIBRARY_PATH=$BASE_BUILD_DIR/depends/$HOST/lib make $MAKEJOBS check VERBOSE=1
+ END_FOLD
+fi
+
+if [ "$RUN_FUNCTIONAL_TESTS" = "true" ]; then
+ BEGIN_FOLD functional-tests
+ DOCKER_EXEC test/functional/test_runner.py --ci $MAKEJOBS --tmpdirprefix "${BASE_SCRATCH_DIR}/test_runner/" --ansi --combinedlogslen=4000 ${TEST_RUNNER_EXTRA} --quiet --failfast
+ END_FOLD
+fi
+
+if [ "$RUN_FUZZ_TESTS" = "true" ]; then
+ BEGIN_FOLD fuzz-tests
+ DOCKER_EXEC test/fuzz/test_runner.py -l DEBUG ${DIR_FUZZ_IN}
+ END_FOLD
+fi
+
+cd ${BASE_BUILD_DIR} || (echo "could not enter travis build dir $BASE_BUILD_DIR"; exit 1)
diff --git a/ci/test_run_all.sh b/ci/test_run_all.sh
new file mode 100755
index 0000000000..a1d4bd1952
--- /dev/null
+++ b/ci/test_run_all.sh
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C.UTF-8
+
+set -o errexit; source ./ci/test/00_setup_env.sh
+set -o errexit; source ./ci/test/03_before_install.sh
+set -o errexit; source ./ci/test/04_install.sh
+set -o errexit; source ./ci/test/05_before_script.sh
+set -o errexit; source ./ci/test/06_script_a.sh
+set -o errexit; source ./ci/test/06_script_b.sh
diff --git a/configure.ac b/configure.ac
index 3b7a328c8a..4434142f79 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,524 +1,1681 @@
+dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
-AC_INIT([libsecp256k1],[0.1])
+define(_CLIENT_VERSION_MAJOR, 1)
+define(_CLIENT_VERSION_MINOR, 0)
+define(_CLIENT_VERSION_REVISION, 0)
+define(_CLIENT_VERSION_BUILD, 0)
+define(_CLIENT_VERSION_RC, 0)
+define(_CLIENT_VERSION_IS_RELEASE, true)
+define(_COPYRIGHT_YEAR, 2020)
+define(_COPYRIGHT_HOLDERS,[The %s developers])
+define(_COPYRIGHT_HOLDERS_SUBSTITUTION,[[DeFi Blockchain]])
+AC_INIT([DeFi Blockchain],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/defich/ain/issues],[defi],[https://defichain.io/])
+AC_CONFIG_SRCDIR([src/validation.cpp])
+AC_CONFIG_HEADERS([src/config/defi-config.h])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([build-aux/m4])
+
+DEFI_DAEMON_NAME=defid
+DEFI_GUI_NAME=defi-qt
+DEFI_CLI_NAME=defi-cli
+DEFI_TX_NAME=defi-tx
+DEFI_WALLET_TOOL_NAME=defi-wallet
+
+dnl Unless the user specified ARFLAGS, force it to be cr
+AC_ARG_VAR(ARFLAGS, [Flags for the archiver, defaults to if not set])
+if test "x${ARFLAGS+set}" != "xset"; then
+ ARFLAGS="cr"
+fi
+
AC_CANONICAL_HOST
-AH_TOP([#ifndef LIBSECP256K1_CONFIG_H])
-AH_TOP([#define LIBSECP256K1_CONFIG_H])
-AH_BOTTOM([#endif /*LIBSECP256K1_CONFIG_H*/])
-AM_INIT_AUTOMAKE([foreign subdir-objects])
-LT_INIT
+
+AH_TOP([#ifndef DEFI_CONFIG_H])
+AH_TOP([#define DEFI_CONFIG_H])
+AH_BOTTOM([#endif //DEFI_CONFIG_H])
+
+dnl faketime breaks configure and is only needed for make. Disable it here.
+unset FAKETIME
+
+dnl Automake init set-up and checks
+AM_INIT_AUTOMAKE([no-define subdir-objects foreign])
+
+dnl faketime messes with timestamps and causes configure to be re-run.
+dnl --disable-maintainer-mode can be used to bypass this.
+AM_MAINTAINER_MODE([enable])
dnl make the compilation flags quiet unless V=1 is used
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
-PKG_PROG_PKG_CONFIG
+dnl Compiler checks (here before libtool).
+if test "x${CXXFLAGS+set}" = "xset"; then
+ CXXFLAGS_overridden=yes
+else
+ CXXFLAGS_overridden=no
+fi
+AC_PROG_CXX
+
+dnl By default, libtool for mingw refuses to link static libs into a dll for
+dnl fear of mixing pic/non-pic objects, and import/export complications. Since
+dnl we have those under control, re-enable that functionality.
+case $host in
+ *mingw*)
+ lt_cv_deplibs_check_method="pass_all"
+ ;;
+esac
+dnl Require C++11 compiler (no GNU extensions)
+AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory], [nodefault])
+dnl Check if -latomic is required for
+CHECK_ATOMIC
+
+dnl Unless the user specified OBJCXX, force it to be the same as CXX. This ensures
+dnl that we get the same -std flags for both.
+m4_ifdef([AC_PROG_OBJCXX],[
+if test "x${OBJCXX+set}" = "x"; then
+ OBJCXX="${CXX}"
+fi
+AC_PROG_OBJCXX
+])
+
+dnl Libtool init checks.
+LT_INIT([pic-only])
+dnl Check/return PATH for base programs.
AC_PATH_TOOL(AR, ar)
AC_PATH_TOOL(RANLIB, ranlib)
AC_PATH_TOOL(STRIP, strip)
-AX_PROG_CC_FOR_BUILD
+AC_PATH_TOOL(GCOV, gcov)
+AC_PATH_PROG(LCOV, lcov)
+dnl Python 3.5 is specified in .python-version and should be used if available, see doc/dependencies.md
+AC_PATH_PROGS([PYTHON], [python3.5 python3.6 python3.7 python3.8 python3 python])
+AC_PATH_PROG(GENHTML, genhtml)
+AC_PATH_PROG([GIT], [git])
+AC_PATH_PROG(CCACHE,ccache)
+AC_PATH_PROG(XGETTEXT,xgettext)
+AC_PATH_PROG(HEXDUMP,hexdump)
+AC_PATH_TOOL(READELF, readelf)
+AC_PATH_TOOL(CPPFILT, c++filt)
+AC_PATH_TOOL(OBJCOPY, objcopy)
+AC_PATH_PROG(DOXYGEN, doxygen)
+if test -z "$DOXYGEN"; then
+ AC_MSG_WARN([Doxygen not found])
+fi
+AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])
+
+AC_ARG_VAR(PYTHONPATH, Augments the default search path for python module files)
+
+AC_ARG_ENABLE([wallet],
+ [AS_HELP_STRING([--disable-wallet],
+ [disable wallet (enabled by default)])],
+ [enable_wallet=$enableval],
+ [enable_wallet=yes])
+
+AC_ARG_WITH([miniupnpc],
+ [AS_HELP_STRING([--with-miniupnpc],
+ [enable UPNP (default is yes if libminiupnpc is found)])],
+ [use_upnp=$withval],
+ [use_upnp=auto])
+
+AC_ARG_ENABLE([upnp-default],
+ [AS_HELP_STRING([--enable-upnp-default],
+ [if UPNP is enabled, turn it on at startup (default is no)])],
+ [use_upnp_default=$enableval],
+ [use_upnp_default=no])
+
+AC_ARG_ENABLE(tests,
+ AS_HELP_STRING([--disable-tests],[do not compile tests (default is to compile)]),
+ [use_tests=$enableval],
+ [use_tests=yes])
+
+AC_ARG_ENABLE(gui-tests,
+ AS_HELP_STRING([--disable-gui-tests],[do not compile GUI tests (default is to compile if GUI and tests enabled)]),
+ [use_gui_tests=$enableval],
+ [use_gui_tests=$use_tests])
+
+AC_ARG_WITH([rapidcheck],
+ [AS_HELP_STRING([--with-rapidcheck],
+ [enable RapidCheck property-based tests (default is yes if librapidcheck is found)])],
+ [use_rapidcheck=$withval],
+ [use_rapidcheck=auto])
+
+AC_ARG_ENABLE(bench,
+ AS_HELP_STRING([--disable-bench],[do not compile benchmarks (default is to compile)]),
+ [use_bench=$enableval],
+ [use_bench=yes])
+
+AC_ARG_ENABLE([extended-functional-tests],
+ AS_HELP_STRING([--enable-extended-functional-tests],[enable expensive functional tests when using lcov (default no)]),
+ [use_extended_functional_tests=$enableval],
+ [use_extended_functional_tests=no])
+
+AC_ARG_ENABLE([fuzz],
+ AS_HELP_STRING([--enable-fuzz],
+ [enable building of fuzz targets (default no). enabling this will disable all other targets]),
+ [enable_fuzz=$enableval],
+ [enable_fuzz=no])
+
+AC_ARG_WITH([qrencode],
+ [AS_HELP_STRING([--with-qrencode],
+ [enable QR code support (default is yes if qt is enabled and libqrencode is found)])],
+ [use_qr=$withval],
+ [use_qr=auto])
+
+AC_ARG_ENABLE([hardening],
+ [AS_HELP_STRING([--disable-hardening],
+ [do not attempt to harden the resulting executables (default is to harden when possible)])],
+ [use_hardening=$enableval],
+ [use_hardening=auto])
+
+AC_ARG_ENABLE([reduce-exports],
+ [AS_HELP_STRING([--enable-reduce-exports],
+ [attempt to reduce exported symbols in the resulting executables (default is no)])],
+ [use_reduce_exports=$enableval],
+ [use_reduce_exports=no])
+
+AC_ARG_ENABLE([ccache],
+ [AS_HELP_STRING([--disable-ccache],
+ [do not use ccache for building (default is to use if found)])],
+ [use_ccache=$enableval],
+ [use_ccache=auto])
+
+AC_ARG_ENABLE([lcov],
+ [AS_HELP_STRING([--enable-lcov],
+ [enable lcov testing (default is no)])],
+ [use_lcov=$enableval],
+ [use_lcov=no])
+
+AC_ARG_ENABLE([lcov-branch-coverage],
+ [AS_HELP_STRING([--enable-lcov-branch-coverage],
+ [enable lcov testing branch coverage (default is no)])],
+ [use_lcov_branch=yes],
+ [use_lcov_branch=no])
+
+AC_ARG_ENABLE([glibc-back-compat],
+ [AS_HELP_STRING([--enable-glibc-back-compat],
+ [enable backwards compatibility with glibc])],
+ [use_glibc_compat=$enableval],
+ [use_glibc_compat=no])
+
+AC_ARG_ENABLE([threadlocal],
+ [AS_HELP_STRING([--enable-threadlocal],
+ [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)])],
+ [use_thread_local=$enableval],
+ [use_thread_local=auto])
+
+AC_ARG_ENABLE([asm],
+ [AS_HELP_STRING([--disable-asm],
+ [disable assembly routines (enabled by default)])],
+ [use_asm=$enableval],
+ [use_asm=yes])
+
+if test "x$use_asm" = xyes; then
+ AC_DEFINE(USE_ASM, 1, [Define this symbol to build in assembly routines])
+fi
+
+AC_ARG_WITH([system-univalue],
+ [AS_HELP_STRING([--with-system-univalue],
+ [Build with system UniValue (default is no)])],
+ [system_univalue=$withval],
+ [system_univalue=no]
+)
+AC_ARG_ENABLE([zmq],
+ [AS_HELP_STRING([--disable-zmq],
+ [disable ZMQ notifications])],
+ [use_zmq=$enableval],
+ [use_zmq=yes])
+AC_ARG_ENABLE([bip70],
+ [AS_HELP_STRING([--disable-bip70],
+ [disable BIP70 (payment protocol) support in GUI (enabled by default)])],
+ [enable_bip70=$enableval],
+ [enable_bip70=auto])
+
+AC_ARG_WITH([protoc-bindir],[AS_HELP_STRING([--with-protoc-bindir=BIN_DIR],[specify protoc bin path])], [protoc_bin_path=$withval], [])
+
+AC_ARG_ENABLE(man,
+ [AS_HELP_STRING([--disable-man],
+ [do not install man pages (default is to install)])],,
+ enable_man=yes)
+AM_CONDITIONAL(ENABLE_MAN, test "$enable_man" != no)
+
+# Enable debug
+AC_ARG_ENABLE([debug],
+ [AS_HELP_STRING([--enable-debug],
+ [use compiler flags and macros suited for debugging (default is no)])],
+ [enable_debug=$enableval],
+ [enable_debug=no])
+
+# Enable different -fsanitize options
+AC_ARG_WITH([sanitizers],
+ [AS_HELP_STRING([--with-sanitizers],
+ [comma separated list of extra sanitizers to build with (default is none enabled)])],
+ [use_sanitizers=$withval])
+
+# Enable gprof profiling
+AC_ARG_ENABLE([gprof],
+ [AS_HELP_STRING([--enable-gprof],
+ [use gprof profiling compiler flags (default is no)])],
+ [enable_gprof=$enableval],
+ [enable_gprof=no])
+
+# Turn warnings into errors
+AC_ARG_ENABLE([werror],
+ [AS_HELP_STRING([--enable-werror],
+ [Treat certain compiler warnings as errors (default is no)])],
+ [enable_werror=$enableval],
+ [enable_werror=no])
+
+AC_LANG_PUSH([C++])
+AX_CHECK_COMPILE_FLAG([-Werror],[CXXFLAG_WERROR="-Werror"],[CXXFLAG_WERROR=""])
+
+if test "x$enable_debug" = xyes; then
+ # Clear default -g -O2 flags
+ if test "x$CXXFLAGS_overridden" = xno; then
+ CXXFLAGS=""
+ fi
+
+ # Disable all optimizations
+ AX_CHECK_COMPILE_FLAG([-O0], [[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"]],,[[$CXXFLAG_WERROR]])
+
+ # Prefer -g3, fall back to -g if that is unavailable.
+ AX_CHECK_COMPILE_FLAG(
+ [-g3],
+ [[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -g3"]],
+ [AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -g"]],,[[$CXXFLAG_WERROR]])],
+ [[$CXXFLAG_WERROR]])
+
+ AX_CHECK_PREPROC_FLAG([-DDEBUG],[[DEBUG_CPPFLAGS="$DEBUG_CPPFLAGS -DDEBUG"]],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_PREPROC_FLAG([-DDEBUG_LOCKORDER],[[DEBUG_CPPFLAGS="$DEBUG_CPPFLAGS -DDEBUG_LOCKORDER"]],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-ftrapv],[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -ftrapv"],,[[$CXXFLAG_WERROR]])
+fi
+
+if test x$use_sanitizers != x; then
+ # First check if the compiler accepts flags. If an incompatible pair like
+ # -fsanitize=address,thread is used here, this check will fail. This will also
+ # fail if a bad argument is passed, e.g. -fsanitize=undfeined
+ AX_CHECK_COMPILE_FLAG(
+ [[-fsanitize=$use_sanitizers]],
+ [[SANITIZER_CXXFLAGS=-fsanitize=$use_sanitizers]],
+ [AC_MSG_ERROR([compiler did not accept requested flags])])
+
+ # Some compilers (e.g. GCC) require additional libraries like libasan,
+ # libtsan, libubsan, etc. Make sure linking still works with the sanitize
+ # flag. This is a separate check so we can give a better error message when
+ # the sanitize flags are supported by the compiler but the actual sanitizer
+ # libs are missing.
+ AX_CHECK_LINK_FLAG(
+ [[-fsanitize=$use_sanitizers]],
+ [[SANITIZER_LDFLAGS=-fsanitize=$use_sanitizers]],
+ [AC_MSG_ERROR([linker did not accept requested flags, you are missing required libraries])],
+ [],
+ [AC_LANG_PROGRAM([[
+ #include
+ #include
+ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { return 0; }
+ __attribute__((weak)) // allow for libFuzzer linking
+ ]],[[]])])
+fi
+
+ERROR_CXXFLAGS=
+if test "x$enable_werror" = "xyes"; then
+ if test "x$CXXFLAG_WERROR" = "x"; then
+ AC_MSG_ERROR("enable-werror set but -Werror is not usable")
+ fi
+ AX_CHECK_COMPILE_FLAG([-Werror=vla],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=vla"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Werror=switch],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=switch"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Werror=thread-safety-analysis],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=thread-safety-analysis"],,[[$CXXFLAG_WERROR]])
+fi
+
+if test "x$CXXFLAGS_overridden" = "xno"; then
+ AX_CHECK_COMPILE_FLAG([-Wall],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wall"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Wextra],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wextra"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Wformat],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wformat"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Wvla],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wvla"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Wswitch],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wswitch"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Wformat-security],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wformat-security"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Wthread-safety-analysis],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wthread-safety-analysis"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Wrange-loop-analysis],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wrange-loop-analysis"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Wredundant-decls],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wredundant-decls"],,[[$CXXFLAG_WERROR]])
-if test "x$CFLAGS" = "x"; then
- CFLAGS="-g"
+ ## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
+ ## unknown options if any other warning is produced. Test the -Wfoo case, and
+ ## set the -Wno-foo case if it works.
+ AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-parameter"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Wself-assign],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-self-assign"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Wunused-local-typedef],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-local-typedef"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Wdeprecated-register],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-deprecated-register"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-implicit-fallthrough"],,[[$CXXFLAG_WERROR]])
fi
-AM_PROG_CC_C_O
+enable_hwcrc32=no
+enable_sse41=no
+enable_avx2=no
+enable_shani=no
+
+if test "x$use_asm" = "xyes"; then
+
+# Check for optional instruction set support. Enabling these does _not_ imply that all code will
+# be compiled with them, rather that specific objects/libs may use them after checking for runtime
+# compatibility.
+AX_CHECK_COMPILE_FLAG([-msse4.2],[[SSE42_CXXFLAGS="-msse4.2"]],,[[$CXXFLAG_WERROR]])
+AX_CHECK_COMPILE_FLAG([-msse4.1],[[SSE41_CXXFLAGS="-msse4.1"]],,[[$CXXFLAG_WERROR]])
+AX_CHECK_COMPILE_FLAG([-mavx -mavx2],[[AVX2_CXXFLAGS="-mavx -mavx2"]],,[[$CXXFLAG_WERROR]])
+AX_CHECK_COMPILE_FLAG([-msse4 -msha],[[SHANI_CXXFLAGS="-msse4 -msha"]],,[[$CXXFLAG_WERROR]])
+
+TEMP_CXXFLAGS="$CXXFLAGS"
+CXXFLAGS="$CXXFLAGS $SSE42_CXXFLAGS"
+AC_MSG_CHECKING(for assembler crc32 support)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include
+ #if defined(_MSC_VER)
+ #include
+ #elif defined(__GNUC__) && defined(__SSE4_2__)
+ #include
+ #endif
+ ]],[[
+ uint64_t l = 0;
+ l = _mm_crc32_u8(l, 0);
+ l = _mm_crc32_u32(l, 0);
+ l = _mm_crc32_u64(l, 0);
+ return l;
+ ]])],
+ [ AC_MSG_RESULT(yes); enable_hwcrc32=yes],
+ [ AC_MSG_RESULT(no)]
+)
+CXXFLAGS="$TEMP_CXXFLAGS"
+
+TEMP_CXXFLAGS="$CXXFLAGS"
+CXXFLAGS="$CXXFLAGS $SSE41_CXXFLAGS"
+AC_MSG_CHECKING(for SSE4.1 intrinsics)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include
+ #include
+ ]],[[
+ __m128i l = _mm_set1_epi32(0);
+ return _mm_extract_epi32(l, 3);
+ ]])],
+ [ AC_MSG_RESULT(yes); enable_sse41=yes; AC_DEFINE(ENABLE_SSE41, 1, [Define this symbol to build code that uses SSE4.1 intrinsics]) ],
+ [ AC_MSG_RESULT(no)]
+)
+CXXFLAGS="$TEMP_CXXFLAGS"
+
+TEMP_CXXFLAGS="$CXXFLAGS"
+CXXFLAGS="$CXXFLAGS $AVX2_CXXFLAGS"
+AC_MSG_CHECKING(for AVX2 intrinsics)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include
+ #include
+ ]],[[
+ __m256i l = _mm256_set1_epi32(0);
+ return _mm256_extract_epi32(l, 7);
+ ]])],
+ [ AC_MSG_RESULT(yes); enable_avx2=yes; AC_DEFINE(ENABLE_AVX2, 1, [Define this symbol to build code that uses AVX2 intrinsics]) ],
+ [ AC_MSG_RESULT(no)]
+)
+CXXFLAGS="$TEMP_CXXFLAGS"
+
+TEMP_CXXFLAGS="$CXXFLAGS"
+CXXFLAGS="$CXXFLAGS $SHANI_CXXFLAGS"
+AC_MSG_CHECKING(for SHA-NI intrinsics)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include
+ #include
+ ]],[[
+ __m128i i = _mm_set1_epi32(0);
+ __m128i j = _mm_set1_epi32(1);
+ __m128i k = _mm_set1_epi32(2);
+ return _mm_extract_epi32(_mm_sha256rnds2_epu32(i, i, k), 0);
+ ]])],
+ [ AC_MSG_RESULT(yes); enable_shani=yes; AC_DEFINE(ENABLE_SHANI, 1, [Define this symbol to build code that uses SHA-NI intrinsics]) ],
+ [ AC_MSG_RESULT(no)]
+)
+CXXFLAGS="$TEMP_CXXFLAGS"
-AC_PROG_CC_C89
-if test x"$ac_cv_prog_cc_c89" = x"no"; then
- AC_MSG_ERROR([c89 compiler support required])
fi
-AM_PROG_AS
-case $host_os in
+CPPFLAGS="$CPPFLAGS -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS"
+
+AC_ARG_WITH([utils],
+ [AS_HELP_STRING([--with-utils],
+ [build defi-cli defi-tx defi-wallet (default=yes)])],
+ [build_defi_utils=$withval],
+ [build_defi_utils=yes])
+
+AC_ARG_ENABLE([util-cli],
+ [AS_HELP_STRING([--enable-util-cli],
+ [build defi-cli])],
+ [build_defi_cli=$enableval],
+ [build_defi_cli=$build_defi_utils])
+
+AC_ARG_ENABLE([util-tx],
+ [AS_HELP_STRING([--enable-util-tx],
+ [build defi-tx])],
+ [build_defi_tx=$enableval],
+ [build_defi_tx=$build_defi_utils])
+
+AC_ARG_ENABLE([util-wallet],
+ [AS_HELP_STRING([--enable-util-wallet],
+ [build defi-wallet])],
+ [build_defi_wallet=$enableval],
+ [build_defi_wallet=$build_defi_utils])
+
+AC_ARG_WITH([libs],
+ [AS_HELP_STRING([--with-libs],
+ [build libraries (default=yes)])],
+ [build_defi_libs=$withval],
+ [build_defi_libs=yes])
+
+AC_ARG_WITH([daemon],
+ [AS_HELP_STRING([--with-daemon],
+ [build defid daemon (default=yes)])],
+ [build_defid=$withval],
+ [build_defid=yes])
+
+use_pkgconfig=yes
+case $host in
+ *mingw*)
+
+ #pkgconfig does more harm than good with MinGW
+ use_pkgconfig=no
+
+ TARGET_OS=windows
+ AC_CHECK_LIB([mingwthrd], [main],, AC_MSG_ERROR(libmingwthrd missing))
+ AC_CHECK_LIB([kernel32], [main],, AC_MSG_ERROR(libkernel32 missing))
+ AC_CHECK_LIB([user32], [main],, AC_MSG_ERROR(libuser32 missing))
+ AC_CHECK_LIB([gdi32], [main],, AC_MSG_ERROR(libgdi32 missing))
+ AC_CHECK_LIB([comdlg32], [main],, AC_MSG_ERROR(libcomdlg32 missing))
+ AC_CHECK_LIB([winspool], [main],, AC_MSG_ERROR(libwinspool missing))
+ AC_CHECK_LIB([winmm], [main],, AC_MSG_ERROR(libwinmm missing))
+ AC_CHECK_LIB([shell32], [main],, AC_MSG_ERROR(libshell32 missing))
+ AC_CHECK_LIB([comctl32], [main],, AC_MSG_ERROR(libcomctl32 missing))
+ AC_CHECK_LIB([ole32], [main],, AC_MSG_ERROR(libole32 missing))
+ AC_CHECK_LIB([oleaut32], [main],, AC_MSG_ERROR(liboleaut32 missing))
+ AC_CHECK_LIB([uuid], [main],, AC_MSG_ERROR(libuuid missing))
+ AC_CHECK_LIB([rpcrt4], [main],, AC_MSG_ERROR(librpcrt4 missing))
+ AC_CHECK_LIB([advapi32], [main],, AC_MSG_ERROR(libadvapi32 missing))
+ AC_CHECK_LIB([ws2_32], [main],, AC_MSG_ERROR(libws2_32 missing))
+ AC_CHECK_LIB([mswsock], [main],, AC_MSG_ERROR(libmswsock missing))
+ AC_CHECK_LIB([shlwapi], [main],, AC_MSG_ERROR(libshlwapi missing))
+ AC_CHECK_LIB([iphlpapi], [main],, AC_MSG_ERROR(libiphlpapi missing))
+ AC_CHECK_LIB([crypt32], [main],, AC_MSG_ERROR(libcrypt32 missing))
+
+ # -static is interpreted by libtool, where it has a different meaning.
+ # In libtool-speak, it's -all-static.
+ AX_CHECK_LINK_FLAG([[-static]],[LIBTOOL_APP_LDFLAGS="$LIBTOOL_APP_LDFLAGS -all-static"])
+
+ AC_PATH_PROG([MAKENSIS], [makensis], none)
+ if test x$MAKENSIS = xnone; then
+ AC_MSG_WARN("makensis not found. Cannot create installer.")
+ fi
+
+ AC_PATH_TOOL(WINDRES, windres, none)
+ if test x$WINDRES = xnone; then
+ AC_MSG_ERROR("windres not found")
+ fi
+
+ CPPFLAGS="$CPPFLAGS -D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -D_WIN32_WINNT=0x0601"
+ LEVELDB_TARGET_FLAGS="-DOS_WINDOWS"
+ if test "x$CXXFLAGS_overridden" = "xno"; then
+ CXXFLAGS="$CXXFLAGS -w"
+ fi
+ case $host in
+ i?86-*) WINDOWS_BITS=32 ;;
+ x86_64-*) WINDOWS_BITS=64 ;;
+ *) AC_MSG_ERROR("Could not determine win32/win64 for installer") ;;
+ esac
+ AC_SUBST(WINDOWS_BITS)
+
+ dnl libtool insists upon adding -nostdlib and a list of objects/libs to link against.
+ dnl That breaks our ability to build dll's with static libgcc/libstdc++/libssp. Override
+ dnl its command here, with the predeps/postdeps removed, and -static inserted. Postdeps are
+ dnl also overridden to prevent their insertion later.
+ dnl This should only affect dll's.
+ archive_cmds_CXX="\$CC -shared \$libobjs \$deplibs \$compiler_flags -static -o \$output_objdir/\$soname \${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker \$lib"
+ postdeps_CXX=
+
+ ;;
*darwin*)
+ TARGET_OS=darwin
+ LEVELDB_TARGET_FLAGS="-DOS_MACOSX"
if test x$cross_compiling != xyes; then
- AC_PATH_PROG([BREW],brew,)
- if test x$BREW != x; then
+ BUILD_OS=darwin
+ AC_PATH_PROGS([RSVG_CONVERT], [rsvg-convert rsvg],rsvg-convert)
+ AC_CHECK_PROG([BREW],brew, brew)
+ if test x$BREW = xbrew; then
dnl These Homebrew packages may be keg-only, meaning that they won't be found
dnl in expected paths because they may conflict with system files. Ask
dnl Homebrew where each one is located, then adjust paths accordingly.
+ dnl It's safe to add these paths even if the functionality is disabled by
+ dnl the user (--without-wallet or --without-gui for example).
openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
- gmp_prefix=`$BREW --prefix gmp 2>/dev/null`
+ bdb_prefix=`$BREW --prefix berkeley-db4 2>/dev/null`
+ qt5_prefix=`$BREW --prefix qt5 2>/dev/null`
if test x$openssl_prefix != x; then
PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
export PKG_CONFIG_PATH
fi
- if test x$gmp_prefix != x; then
- GMP_CPPFLAGS="-I$gmp_prefix/include"
- GMP_LIBS="-L$gmp_prefix/lib"
+ if test x$bdb_prefix != x; then
+ CPPFLAGS="$CPPFLAGS -I$bdb_prefix/include"
+ LIBS="$LIBS -L$bdb_prefix/lib"
fi
- else
- AC_PATH_PROG([PORT],port,)
- dnl if homebrew isn't installed and macports is, add the macports default paths
- dnl as a last resort.
- if test x$PORT != x; then
- CPPFLAGS="$CPPFLAGS -isystem /opt/local/include"
- LDFLAGS="$LDFLAGS -L/opt/local/lib"
+ if test x$qt5_prefix != x; then
+ PKG_CONFIG_PATH="$qt5_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
+ export PKG_CONFIG_PATH
fi
fi
+ else
+ case $build_os in
+ *darwin*)
+ BUILD_OS=darwin
+ ;;
+ *)
+ AC_PATH_TOOL([INSTALLNAMETOOL], [install_name_tool], install_name_tool)
+ AC_PATH_TOOL([OTOOL], [otool], otool)
+ AC_PATH_PROGS([GENISOIMAGE], [genisoimage mkisofs],genisoimage)
+ AC_PATH_PROGS([RSVG_CONVERT], [rsvg-convert rsvg],rsvg-convert)
+ AC_PATH_PROGS([IMAGEMAGICK_CONVERT], [convert],convert)
+ AC_PATH_PROGS([TIFFCP], [tiffcp],tiffcp)
+
+ dnl libtool will try to strip the static lib, which is a problem for
+ dnl cross-builds because strip attempts to call a hard-coded ld,
+ dnl which may not exist in the path. Stripping the .a is not
+ dnl necessary, so just disable it.
+ old_striplib=
+ ;;
+ esac
fi
- ;;
+
+ AX_CHECK_LINK_FLAG([[-Wl,-headerpad_max_install_names]], [LDFLAGS="$LDFLAGS -Wl,-headerpad_max_install_names"])
+ CPPFLAGS="$CPPFLAGS -DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0"
+ OBJCXXFLAGS="$CXXFLAGS"
+ ;;
+ *android*)
+ dnl make sure android stays above linux for hosts like *linux-android*
+ LEVELDB_TARGET_FLAGS="-DOS_ANDROID"
+ ;;
+ *linux*)
+ TARGET_OS=linux
+ LEVELDB_TARGET_FLAGS="-DOS_LINUX"
+ ;;
+ *kfreebsd*)
+ LEVELDB_TARGET_FLAGS="-DOS_KFREEBSD"
+ ;;
+ *freebsd*)
+ LEVELDB_TARGET_FLAGS="-DOS_FREEBSD"
+ ;;
+ *openbsd*)
+ LEVELDB_TARGET_FLAGS="-DOS_OPENBSD"
+ ;;
+ *netbsd*)
+ LEVELDB_TARGET_FLAGS="-DOS_NETBSD"
+ ;;
+ *dragonfly*)
+ LEVELDB_TARGET_FLAGS="-DOS_DRAGONFLYBSD"
+ ;;
+ *solaris*)
+ LEVELDB_TARGET_FLAGS="-DOS_SOLARIS"
+ ;;
+ *hpux*)
+ LEVELDB_TARGET_FLAGS="-DOS_HPUX"
+ ;;
+ *)
+ AC_MSG_ERROR(Cannot build leveldb for $host. Please file a bug report.)
+ ;;
esac
-CFLAGS="$CFLAGS -W"
+if test x$use_pkgconfig = xyes; then
+ 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.)])
+ m4_ifdef([PKG_PROG_PKG_CONFIG], [
+ PKG_PROG_PKG_CONFIG
+ if test x"$PKG_CONFIG" = "x"; then
+ AC_MSG_ERROR(pkg-config not found.)
+ fi
+ ])
+fi
-warn_CFLAGS="-std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings"
-saved_CFLAGS="$CFLAGS"
-CFLAGS="$CFLAGS $warn_CFLAGS"
-AC_MSG_CHECKING([if ${CC} supports ${warn_CFLAGS}])
-AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
- [ AC_MSG_RESULT([yes]) ],
- [ AC_MSG_RESULT([no])
- CFLAGS="$saved_CFLAGS"
- ])
+if test x$use_extended_functional_tests != xno; then
+ AC_SUBST(EXTENDED_FUNCTIONAL_TESTS, --extended)
+fi
+
+if test x$use_lcov = xyes; then
+ if test x$LCOV = x; then
+ AC_MSG_ERROR("lcov testing requested but lcov not found")
+ fi
+ if test x$GCOV = x; then
+ AC_MSG_ERROR("lcov testing requested but gcov not found")
+ fi
+ if test x$PYTHON = x; then
+ AC_MSG_ERROR("lcov testing requested but python not found")
+ fi
+ if test x$GENHTML = x; then
+ AC_MSG_ERROR("lcov testing requested but genhtml not found")
+ fi
+ LCOV="$LCOV --gcov-tool=$GCOV"
+ AX_CHECK_LINK_FLAG([[--coverage]], [LDFLAGS="$LDFLAGS --coverage"],
+ [AC_MSG_ERROR("lcov testing requested but --coverage linker flag does not work")])
+ AX_CHECK_COMPILE_FLAG([--coverage],[CXXFLAGS="$CXXFLAGS --coverage"],
+ [AC_MSG_ERROR("lcov testing requested but --coverage flag does not work")])
+ AC_DEFINE(USE_COVERAGE, 1, [Define this symbol if coverage is enabled])
+ CXXFLAGS="$CXXFLAGS -Og"
+fi
-saved_CFLAGS="$CFLAGS"
-CFLAGS="$CFLAGS -fvisibility=hidden"
-AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden])
-AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
- [ AC_MSG_RESULT([yes]) ],
- [ AC_MSG_RESULT([no])
- CFLAGS="$saved_CFLAGS"
+if test x$use_lcov_branch != xno; then
+ AC_SUBST(LCOV_OPTS, "$LCOV_OPTS --rc lcov_branch_coverage=1")
+fi
+
+dnl Check for endianness
+AC_C_BIGENDIAN
+
+dnl Check for pthread compile/link requirements
+AX_PTHREAD
+
+# The following macro will add the necessary defines to defi-config.h, but
+# they also need to be passed down to any subprojects. Pull the results out of
+# the cache and add them to CPPFLAGS.
+AC_SYS_LARGEFILE
+# detect POSIX or GNU variant of strerror_r
+AC_FUNC_STRERROR_R
+
+if test x$ac_cv_sys_file_offset_bits != x &&
+ test x$ac_cv_sys_file_offset_bits != xno &&
+ test x$ac_cv_sys_file_offset_bits != xunknown; then
+ CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=$ac_cv_sys_file_offset_bits"
+fi
+
+if test x$ac_cv_sys_large_files != x &&
+ test x$ac_cv_sys_large_files != xno &&
+ test x$ac_cv_sys_large_files != xunknown; then
+ CPPFLAGS="$CPPFLAGS -D_LARGE_FILES=$ac_cv_sys_large_files"
+fi
+
+AX_CHECK_LINK_FLAG([[-Wl,--large-address-aware]], [LDFLAGS="$LDFLAGS -Wl,--large-address-aware"])
+
+AX_GCC_FUNC_ATTRIBUTE([visibility])
+AX_GCC_FUNC_ATTRIBUTE([dllexport])
+AX_GCC_FUNC_ATTRIBUTE([dllimport])
+
+if test x$use_glibc_compat != xno; then
+
+ #glibc absorbed clock_gettime in 2.17. librt (its previous location) is safe to link
+ #in anyway for back-compat.
+ AC_CHECK_LIB([rt],[clock_gettime],, AC_MSG_ERROR(librt missing))
+
+ #__fdelt_chk's params and return type have changed from long unsigned int to long int.
+ # See which one is present here.
+ AC_MSG_CHECKING(__fdelt_chk type)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifdef _FORTIFY_SOURCE
+ #undef _FORTIFY_SOURCE
+ #endif
+ #define _FORTIFY_SOURCE 2
+ #include
+ extern "C" long unsigned int __fdelt_warn(long unsigned int);]],[[]])],
+ [ fdelt_type="long unsigned int"],
+ [ fdelt_type="long int"])
+ AC_MSG_RESULT($fdelt_type)
+ AC_DEFINE_UNQUOTED(FDELT_TYPE, $fdelt_type,[parameter and return value type for __fdelt_chk])
+ AX_CHECK_LINK_FLAG([[-Wl,--wrap=__divmoddi4]], [COMPAT_LDFLAGS="$COMPAT_LDFLAGS -Wl,--wrap=__divmoddi4"])
+ AX_CHECK_LINK_FLAG([[-Wl,--wrap=log2f]], [COMPAT_LDFLAGS="$COMPAT_LDFLAGS -Wl,--wrap=log2f"])
+else
+ AC_SEARCH_LIBS([clock_gettime],[rt])
+fi
+
+if test "x$enable_gprof" = xyes; then
+ dnl -pg is incompatible with -pie. Since hardening and profiling together doesn't make sense,
+ dnl we simply make them mutually exclusive here. Additionally, hardened toolchains may force
+ dnl -pie by default, in which case it needs to be turned off with -no-pie.
+
+ if test x$use_hardening = xyes; then
+ AC_MSG_ERROR(gprof profiling is not compatible with hardening. Reconfigure with --disable-hardening or --disable-gprof)
+ fi
+ use_hardening=no
+ AX_CHECK_COMPILE_FLAG([-pg],[GPROF_CXXFLAGS="-pg"],
+ [AC_MSG_ERROR(gprof profiling requested but not available)], [[$CXXFLAG_WERROR]])
+
+ AX_CHECK_LINK_FLAG([[-no-pie]], [GPROF_LDFLAGS="-no-pie"])
+ AX_CHECK_LINK_FLAG([[-pg]],[GPROF_LDFLAGS="$GPROF_LDFLAGS -pg"],
+ [AC_MSG_ERROR(gprof profiling requested but not available)], [[$GPROF_LDFLAGS]])
+fi
+
+if test x$TARGET_OS != xwindows; then
+ # All windows code is PIC, forcing it on just adds useless compile warnings
+ AX_CHECK_COMPILE_FLAG([-fPIC],[PIC_FLAGS="-fPIC"])
+fi
+
+# All versions of gcc that we commonly use for building are subject to bug
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348. To work around that, set
+# -fstack-reuse=none for all gcc builds. (Only gcc understands this flag)
+AX_CHECK_COMPILE_FLAG([-fstack-reuse=none],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-reuse=none"])
+if test x$use_hardening != xno; then
+ use_hardening=yes
+ AX_CHECK_COMPILE_FLAG([-Wstack-protector],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"])
+ AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"])
+
+ AX_CHECK_PREPROC_FLAG([-D_FORTIFY_SOURCE=2],[
+ AX_CHECK_PREPROC_FLAG([-U_FORTIFY_SOURCE],[
+ HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -U_FORTIFY_SOURCE"
])
+ HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -D_FORTIFY_SOURCE=2"
+ ])
-AC_ARG_ENABLE(benchmark,
- AS_HELP_STRING([--enable-benchmark],[compile benchmark (default is yes)]),
- [use_benchmark=$enableval],
- [use_benchmark=yes])
+ AX_CHECK_LINK_FLAG([[-Wl,--dynamicbase]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--dynamicbase"])
+ AX_CHECK_LINK_FLAG([[-Wl,--nxcompat]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--nxcompat"])
+ AX_CHECK_LINK_FLAG([[-Wl,--high-entropy-va]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--high-entropy-va"])
+ AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"])
+ AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"])
+ AX_CHECK_LINK_FLAG([[-fPIE -pie]], [PIE_FLAGS="-fPIE"; HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"],, [[$CXXFLAG_WERROR]])
-AC_ARG_ENABLE(coverage,
- AS_HELP_STRING([--enable-coverage],[enable compiler flags to support kcov coverage analysis]),
- [enable_coverage=$enableval],
- [enable_coverage=no])
+ case $host in
+ *mingw*)
+ AC_CHECK_LIB([ssp], [main],, AC_MSG_ERROR(libssp missing))
+ ;;
+ esac
+fi
-AC_ARG_ENABLE(tests,
- AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
- [use_tests=$enableval],
- [use_tests=yes])
+dnl this flag screws up non-darwin gcc even when the check fails. special-case it.
+if test x$TARGET_OS = xdarwin; then
+ AX_CHECK_LINK_FLAG([[-Wl,-dead_strip]], [LDFLAGS="$LDFLAGS -Wl,-dead_strip"])
+fi
+
+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])
+
+AC_CHECK_DECLS([getifaddrs, freeifaddrs],,,
+ [#include
+ #include ]
+)
+AC_CHECK_DECLS([strnlen])
+
+# Check for daemon(3), unrelated to --with-daemon (although used by it)
+AC_CHECK_DECLS([daemon])
+
+AC_CHECK_DECLS([le16toh, le32toh, le64toh, htole16, htole32, htole64, be16toh, be32toh, be64toh, htobe16, htobe32, htobe64],,,
+ [#if HAVE_ENDIAN_H
+ #include
+ #elif HAVE_SYS_ENDIAN_H
+ #include
+ #endif])
-AC_ARG_ENABLE(openssl_tests,
- AS_HELP_STRING([--enable-openssl-tests],[enable OpenSSL tests, if OpenSSL is available (default is auto)]),
- [enable_openssl_tests=$enableval],
- [enable_openssl_tests=auto])
+AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64],,,
+ [#if HAVE_BYTESWAP_H
+ #include
+ #endif])
-AC_ARG_ENABLE(experimental,
- AS_HELP_STRING([--enable-experimental],[allow experimental configure options (default is no)]),
- [use_experimental=$enableval],
- [use_experimental=no])
+AC_CHECK_DECLS([__builtin_clz, __builtin_clzl, __builtin_clzll])
-AC_ARG_ENABLE(exhaustive_tests,
- AS_HELP_STRING([--enable-exhaustive-tests],[compile exhaustive tests (default is yes)]),
- [use_exhaustive_tests=$enableval],
- [use_exhaustive_tests=yes])
+dnl Check for malloc_info (for memory statistics information in getmemoryinfo)
+AC_MSG_CHECKING(for getmemoryinfo)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]],
+ [[ int f = malloc_info(0, NULL); ]])],
+ [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_MALLOC_INFO, 1,[Define this symbol if you have malloc_info]) ],
+ [ AC_MSG_RESULT(no)]
+)
-AC_ARG_ENABLE(endomorphism,
- AS_HELP_STRING([--enable-endomorphism],[enable endomorphism (default is no)]),
- [use_endomorphism=$enableval],
- [use_endomorphism=no])
+dnl Check for mallopt(M_ARENA_MAX) (to set glibc arenas)
+AC_MSG_CHECKING(for mallopt M_ARENA_MAX)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]],
+ [[ mallopt(M_ARENA_MAX, 1); ]])],
+ [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_MALLOPT_ARENA_MAX, 1,[Define this symbol if you have mallopt with M_ARENA_MAX]) ],
+ [ AC_MSG_RESULT(no)]
+)
-AC_ARG_ENABLE(ecmult_static_precomputation,
- AS_HELP_STRING([--enable-ecmult-static-precomputation],[enable precomputed ecmult table for signing (default is yes)]),
- [use_ecmult_static_precomputation=$enableval],
- [use_ecmult_static_precomputation=auto])
+AC_MSG_CHECKING([for visibility attribute])
+AC_LINK_IFELSE([AC_LANG_SOURCE([
+ int foo_def( void ) __attribute__((visibility("default")));
+ int main(){}
+ ])],
+ [
+ AC_DEFINE(HAVE_VISIBILITY_ATTRIBUTE,1,[Define if the visibility attribute is supported.])
+ AC_MSG_RESULT(yes)
+ ],
+ [
+ AC_MSG_RESULT(no)
+ if test x$use_reduce_exports = xyes; then
+ AC_MSG_ERROR([Cannot find a working visibility attribute. Use --disable-reduce-exports.])
+ fi
+ ]
+)
-AC_ARG_ENABLE(module_ecdh,
- AS_HELP_STRING([--enable-module-ecdh],[enable ECDH shared secret computation (experimental)]),
- [enable_module_ecdh=$enableval],
- [enable_module_ecdh=no])
+if test "x$use_thread_local" = xyes || { test "x$use_thread_local" = xauto && test "x$use_glibc_compat" = xno; }; then
+ TEMP_LDFLAGS="$LDFLAGS"
+ LDFLAGS="$TEMP_LDFLAGS $PTHREAD_CFLAGS"
+ AC_MSG_CHECKING([for thread_local support])
+ AC_LINK_IFELSE([AC_LANG_SOURCE([
+ #include
+ static thread_local int foo = 0;
+ static void run_thread() { foo++;}
+ int main(){
+ for(int i = 0; i < 10; i++) { std::thread(run_thread).detach();}
+ return foo;
+ }
+ ])],
+ [
+ case $host in
+ *mingw*)
+ # mingw32's implementation of thread_local has also been shown to behave
+ # erroneously under concurrent usage; see:
+ # https://gist.github.com/jamesob/fe9a872051a88b2025b1aa37bfa98605
+ AC_MSG_RESULT(no)
+ ;;
+ *darwin*)
+ # TODO enable thread_local on later versions of Darwin where it is
+ # supported (per https://stackoverflow.com/a/29929949)
+ AC_MSG_RESULT(no)
+ ;;
+ *freebsd*)
+ # FreeBSD's implementation of thread_local is also buggy (per
+ # https://groups.google.com/d/msg/bsdmailinglist/22ncTZAbDp4/Dii_pII5AwAJ)
+ AC_MSG_RESULT(no)
+ ;;
+ *)
+ AC_DEFINE(HAVE_THREAD_LOCAL,1,[Define if thread_local is supported.])
+ AC_MSG_RESULT(yes)
+ ;;
+ esac
+ ],
+ [
+ AC_MSG_RESULT(no)
+ ]
+ )
+ LDFLAGS="$TEMP_LDFLAGS"
+fi
-AC_ARG_ENABLE(module_recovery,
- AS_HELP_STRING([--enable-module-recovery],[enable ECDSA pubkey recovery module (default is no)]),
- [enable_module_recovery=$enableval],
- [enable_module_recovery=no])
+# Check for different ways of gathering OS randomness
+AC_MSG_CHECKING(for Linux getrandom syscall)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include
+ #include
+ #include ]],
+ [[ syscall(SYS_getrandom, nullptr, 32, 0); ]])],
+ [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYS_GETRANDOM, 1,[Define this symbol if the Linux getrandom system call is available]) ],
+ [ AC_MSG_RESULT(no)]
+)
-AC_ARG_ENABLE(jni,
- AS_HELP_STRING([--enable-jni],[enable libsecp256k1_jni (default is no)]),
- [use_jni=$enableval],
- [use_jni=no])
+AC_MSG_CHECKING(for getentropy)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]],
+ [[ getentropy(nullptr, 32) ]])],
+ [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_GETENTROPY, 1,[Define this symbol if the BSD getentropy system call is available]) ],
+ [ AC_MSG_RESULT(no)]
+)
-AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=64bit|32bit|auto],
-[Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto])
+AC_MSG_CHECKING(for getentropy via random.h)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include
+ #include ]],
+ [[ getentropy(nullptr, 32) ]])],
+ [ 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]) ],
+ [ AC_MSG_RESULT(no)]
+)
-AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|no|auto],
-[Specify Bignum Implementation. Default is auto])],[req_bignum=$withval], [req_bignum=auto])
+AC_MSG_CHECKING(for sysctl KERN_ARND)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include
+ #include ]],
+ [[ static const int name[2] = {CTL_KERN, KERN_ARND};
+ sysctl(name, 2, nullptr, nullptr, nullptr, 0); ]])],
+ [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCTL_ARND, 1,[Define this symbol if the BSD sysctl(KERN_ARND) is available]) ],
+ [ AC_MSG_RESULT(no)]
+)
-AC_ARG_WITH([scalar], [AS_HELP_STRING([--with-scalar=64bit|32bit|auto],
-[Specify scalar implementation. Default is auto])],[req_scalar=$withval], [req_scalar=auto])
+AC_MSG_CHECKING(for if type char equals int8_t)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include
+ #include ]],
+ [[ static_assert(std::is_same::value, ""); ]])],
+ [ AC_MSG_RESULT(yes); AC_DEFINE(CHAR_EQUALS_INT8, 1,[Define this symbol if type char equals int8_t]) ],
+ [ AC_MSG_RESULT(no)]
+)
+
+# Check for reduced exports
+if test x$use_reduce_exports = xyes; then
+ AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[RE_CXXFLAGS="-fvisibility=hidden"],
+ [AC_MSG_ERROR([Cannot set default symbol visibility. Use --disable-reduce-exports.])])
+fi
-AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto]
-[Specify assembly optimizations to use. Default is auto (experimental: arm)])],[req_asm=$withval], [req_asm=auto])
+AC_MSG_CHECKING([for std::system])
+AC_LINK_IFELSE(
+ [ AC_LANG_PROGRAM(
+ [[ #include ]],
+ [[ int nErr = std::system(""); ]]
+ )],
+ [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_STD__SYSTEM, 1, Define to 1 if you have the `std::system' function.)],
+ [ AC_MSG_RESULT(no) ]
+)
-AC_CHECK_TYPES([__int128])
+AC_MSG_CHECKING([for ::_wsystem])
+AC_LINK_IFELSE(
+ [ AC_LANG_PROGRAM(
+ [[ ]],
+ [[ int nErr = ::_wsystem(""); ]]
+ )],
+ [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_WSYSTEM, 1, Define to 1 if you have the `::wsystem' function.)],
+ [ AC_MSG_RESULT(no) ]
+)
-if test x"$enable_coverage" = x"yes"; then
- AC_DEFINE(COVERAGE, 1, [Define this symbol to compile out all VERIFY code])
- CFLAGS="$CFLAGS -O0 --coverage"
- LDFLAGS="--coverage"
+# Define to 1 if std::system or ::wsystem (Windows) is available
+AC_DEFINE([HAVE_SYSTEM], [HAVE_STD__SYSTEM || HAVE_WSYSTEM], [std::system or ::wsystem])
+
+LEVELDB_CPPFLAGS=
+LIBLEVELDB=
+LIBMEMENV=
+AM_CONDITIONAL([EMBEDDED_LEVELDB],[true])
+AC_SUBST(LEVELDB_CPPFLAGS)
+AC_SUBST(LIBLEVELDB)
+AC_SUBST(LIBMEMENV)
+
+dnl enable-fuzz should disable all other targets
+if test "x$enable_fuzz" = "xyes"; then
+ AC_MSG_WARN(enable-fuzz will disable all other targets)
+ build_defi_utils=no
+ build_defi_cli=no
+ build_defi_tx=no
+ build_defi_wallet=no
+ build_defid=no
+ build_defi_libs=no
+ defi_enable_qt=no
+ defi_enable_qt_test=no
+ defi_enable_qt_dbus=no
+ enable_wallet=no
+ use_bench=no
+ use_upnp=no
+ use_zmq=no
else
- CFLAGS="$CFLAGS -O3"
-fi
-
-if test x"$use_ecmult_static_precomputation" != x"no"; then
- # Temporarily switch to an environment for the native compiler
- save_cross_compiling=$cross_compiling
- cross_compiling=no
- SAVE_CC="$CC"
- CC="$CC_FOR_BUILD"
- SAVE_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS_FOR_BUILD"
- SAVE_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$CPPFLAGS_FOR_BUILD"
- SAVE_LDFLAGS="$LDFLAGS"
- LDFLAGS="$LDFLAGS_FOR_BUILD"
-
- warn_CFLAGS_FOR_BUILD="-Wall -Wextra -Wno-unused-function"
- saved_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS $warn_CFLAGS_FOR_BUILD"
- AC_MSG_CHECKING([if native ${CC_FOR_BUILD} supports ${warn_CFLAGS_FOR_BUILD}])
- AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
- [ AC_MSG_RESULT([yes]) ],
- [ AC_MSG_RESULT([no])
- CFLAGS="$saved_CFLAGS"
- ])
-
- AC_MSG_CHECKING([for working native compiler: ${CC_FOR_BUILD}])
- AC_RUN_IFELSE(
- [AC_LANG_PROGRAM([], [])],
- [working_native_cc=yes],
- [working_native_cc=no],[dnl])
-
- CFLAGS_FOR_BUILD="$CFLAGS"
-
- # Restore the environment
- cross_compiling=$save_cross_compiling
- CC="$SAVE_CC"
- CFLAGS="$SAVE_CFLAGS"
- CPPFLAGS="$SAVE_CPPFLAGS"
- LDFLAGS="$SAVE_LDFLAGS"
-
- if test x"$working_native_cc" = x"no"; then
- AC_MSG_RESULT([no])
- set_precomp=no
- m4_define([please_set_for_build], [Please set CC_FOR_BUILD, CFLAGS_FOR_BUILD, CPPFLAGS_FOR_BUILD, and/or LDFLAGS_FOR_BUILD.])
- if test x"$use_ecmult_static_precomputation" = x"yes"; then
- AC_MSG_ERROR([native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build])
- else
- AC_MSG_WARN([Disabling statically generated ecmult table because the native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build])
- fi
- else
- AC_MSG_RESULT([yes])
- set_precomp=yes
- fi
+ DEFI_QT_INIT
+
+ dnl sets $defi_enable_qt, $defi_enable_qt_test, $defi_enable_qt_dbus
+ DEFI_QT_CONFIGURE([$use_pkgconfig])
+fi
+
+if test x$enable_wallet != xno; then
+ dnl Check for libdb_cxx only if wallet enabled
+ DEFI_FIND_BDB48
+fi
+
+dnl Check for libminiupnpc (optional)
+if test x$use_upnp != xno; then
+ AC_CHECK_HEADERS(
+ [miniupnpc/miniwget.h miniupnpc/miniupnpc.h miniupnpc/upnpcommands.h miniupnpc/upnperrors.h],
+ [AC_CHECK_LIB([miniupnpc], [upnpDiscover], [MINIUPNPC_LIBS=-lminiupnpc], [have_miniupnpc=no])],
+ [have_miniupnpc=no]
+ )
+dnl The minimum supported miniUPnPc API version is set to 10. This keeps compatibility
+dnl with Ubuntu 16.04 LTS and Debian 8 libminiupnpc-dev packages.
+if test x$have_miniupnpc != xno; then
+ AC_MSG_CHECKING([whether miniUPnPc API version is supported])
+ AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
+ @%:@include
+ ]], [[
+ #if MINIUPNPC_API_VERSION >= 10
+ // Everything is okay
+ #else
+ # error miniUPnPc API version is too old
+ #endif
+ ]])],[
+ AC_MSG_RESULT(yes)
+ ],[
+ AC_MSG_RESULT(no)
+ AC_MSG_WARN([miniUPnPc API version < 10 is unsupported, disabling UPnP support.])
+ have_miniupnpc=no
+ ])
+fi
+fi
+
+if test x$build_defi_wallet$build_defi_cli$build_defi_tx$build_defid$defi_enable_qt$use_tests$use_bench = xnonononononono; then
+ use_boost=no
else
- set_precomp=no
+ use_boost=yes
+fi
+
+if test x$use_boost = xyes; then
+
+dnl Minimum required Boost version
+define(MINIMUM_REQUIRED_BOOST, 1.47.0)
+
+dnl Check for boost libs
+AX_BOOST_BASE([MINIMUM_REQUIRED_BOOST])
+if test x$want_boost = xno; then
+ AC_MSG_ERROR([[only libdeficonsensus can be built without boost]])
+fi
+AX_BOOST_SYSTEM
+AX_BOOST_FILESYSTEM
+AX_BOOST_THREAD
+AX_BOOST_CHRONO
+
+dnl Boost 1.56 through 1.62 allow using std::atomic instead of its own atomic
+dnl counter implementations. In 1.63 and later the std::atomic approach is default.
+m4_pattern_allow(DBOOST_AC_USE_STD_ATOMIC) dnl otherwise it's treated like a macro
+BOOST_CPPFLAGS="-DBOOST_SP_USE_STD_ATOMIC -DBOOST_AC_USE_STD_ATOMIC $BOOST_CPPFLAGS"
+
+if test x$use_reduce_exports = xyes; then
+ AC_MSG_CHECKING([for working boost reduced exports])
+ TEMP_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$BOOST_CPPFLAGS $CPPFLAGS"
+ AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
+ @%:@include
+ ]], [[
+ #if BOOST_VERSION >= 104900
+ // Everything is okay
+ #else
+ # error Boost version is too old
+ #endif
+ ]])],[
+ AC_MSG_RESULT(yes)
+ ],[
+ AC_MSG_ERROR([boost versions < 1.49 are known to be broken with reduced exports. Use --disable-reduce-exports.])
+ ])
+ CPPFLAGS="$TEMP_CPPFLAGS"
+fi
fi
-if test x"$req_asm" = x"auto"; then
- SECP_64BIT_ASM_CHECK
- if test x"$has_64bit_asm" = x"yes"; then
- set_asm=x86_64
+if test x$use_reduce_exports = xyes; then
+ CXXFLAGS="$CXXFLAGS $RE_CXXFLAGS"
+ AX_CHECK_LINK_FLAG([[-Wl,--exclude-libs,ALL]], [RELDFLAGS="-Wl,--exclude-libs,ALL"])
+fi
+
+if test x$use_tests = xyes; then
+
+ if test x$HEXDUMP = x; then
+ AC_MSG_ERROR(hexdump is required for tests)
fi
- if test x"$set_asm" = x; then
- set_asm=no
+
+
+ if test x$use_boost = xyes; then
+
+ AX_BOOST_UNIT_TEST_FRAMEWORK
+
+ dnl Determine if -DBOOST_TEST_DYN_LINK is needed
+ AC_MSG_CHECKING([for dynamic linked boost test])
+ TEMP_LIBS="$LIBS"
+ LIBS="$LIBS $BOOST_LDFLAGS $BOOST_UNIT_TEST_FRAMEWORK_LIB"
+ TEMP_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+ AC_LINK_IFELSE([AC_LANG_SOURCE([
+ #define BOOST_TEST_DYN_LINK
+ #define BOOST_TEST_MAIN
+ #include
+
+ ])],
+ [AC_MSG_RESULT(yes)]
+ [TESTDEFS="$TESTDEFS -DBOOST_TEST_DYN_LINK"],
+ [AC_MSG_RESULT(no)])
+ LIBS="$TEMP_LIBS"
+ CPPFLAGS="$TEMP_CPPFLAGS"
+
fi
-else
- set_asm=$req_asm
- case $set_asm in
- x86_64)
- SECP_64BIT_ASM_CHECK
- if test x"$has_64bit_asm" != x"yes"; then
- AC_MSG_ERROR([x86_64 assembly optimization requested but not available])
- fi
- ;;
- arm)
- ;;
- no)
- ;;
- *)
- AC_MSG_ERROR([invalid assembly optimization selection])
- ;;
- esac
fi
-if test x"$req_field" = x"auto"; then
- if test x"set_asm" = x"x86_64"; then
- set_field=64bit
- fi
- if test x"$set_field" = x; then
- SECP_INT128_CHECK
- if test x"$has_int128" = x"yes"; then
- set_field=64bit
+if test x$use_boost = xyes; then
+
+BOOST_LIBS="$BOOST_LDFLAGS $BOOST_SYSTEM_LIB $BOOST_FILESYSTEM_LIB $BOOST_THREAD_LIB $BOOST_CHRONO_LIB"
+
+
+dnl If boost (prior to 1.57) was built without c++11, it emulated scoped enums
+dnl using c++98 constructs. Unfortunately, this implementation detail leaked into
+dnl the abi. This was fixed in 1.57.
+
+dnl When building against that installed version using c++11, the headers pick up
+dnl on the native c++11 scoped enum support and enable it, however it will fail to
+dnl link. This can be worked around by disabling c++11 scoped enums if linking will
+dnl fail.
+dnl BOOST_NO_SCOPED_ENUMS was changed to BOOST_NO_CXX11_SCOPED_ENUMS in 1.51.
+
+TEMP_LIBS="$LIBS"
+LIBS="$BOOST_LIBS $LIBS"
+TEMP_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+AC_MSG_CHECKING([for mismatched boost c++11 scoped enums])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+ #include
+ #include
+ #if !defined(BOOST_NO_SCOPED_ENUMS) && !defined(BOOST_NO_CXX11_SCOPED_ENUMS) && BOOST_VERSION < 105700
+ #define BOOST_NO_SCOPED_ENUMS
+ #define BOOST_NO_CXX11_SCOPED_ENUMS
+ #define CHECK
+ #endif
+ #include
+ ]],[[
+ #if defined(CHECK)
+ boost::filesystem::copy_file("foo", "bar");
+ #else
+ choke;
+ #endif
+ ]])],
+ [AC_MSG_RESULT(mismatched); BOOST_CPPFLAGS="$BOOST_CPPFLAGS -DBOOST_NO_SCOPED_ENUMS -DBOOST_NO_CXX11_SCOPED_ENUMS"], [AC_MSG_RESULT(ok)])
+LIBS="$TEMP_LIBS"
+CPPFLAGS="$TEMP_CPPFLAGS"
+
+dnl Boost >= 1.50 uses sleep_for rather than the now-deprecated sleep, however
+dnl it was broken from 1.50 to 1.52 when backed by nanosleep. Use sleep_for if
+dnl a working version is available, else fall back to sleep. sleep was removed
+dnl after 1.56.
+dnl If neither is available, abort.
+TEMP_LIBS="$LIBS"
+LIBS="$BOOST_LIBS $LIBS"
+TEMP_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+ #include
+ #include
+ ]],[[
+ #if BOOST_VERSION >= 105000 && (!defined(BOOST_HAS_NANOSLEEP) || BOOST_VERSION >= 105200)
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(0));
+ #else
+ choke me
+ #endif
+ ]])],
+ [boost_sleep=yes;
+ AC_DEFINE(HAVE_WORKING_BOOST_SLEEP_FOR, 1, [Define this symbol if boost sleep_for works])],
+ [boost_sleep=no])
+LIBS="$TEMP_LIBS"
+CPPFLAGS="$TEMP_CPPFLAGS"
+
+if test x$boost_sleep != xyes; then
+TEMP_LIBS="$LIBS"
+LIBS="$BOOST_LIBS $LIBS"
+TEMP_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+ #include
+ #include
+ #include
+ ]],[[
+ #if BOOST_VERSION <= 105600
+ boost::this_thread::sleep(boost::posix_time::milliseconds(0));
+ #else
+ choke me
+ #endif
+ ]])],
+ [boost_sleep=yes; AC_DEFINE(HAVE_WORKING_BOOST_SLEEP, 1, [Define this symbol if boost sleep works])],
+ [boost_sleep=no])
+LIBS="$TEMP_LIBS"
+CPPFLAGS="$TEMP_CPPFLAGS"
+fi
+
+if test x$boost_sleep != xyes; then
+ AC_MSG_ERROR(No working boost sleep implementation found.)
+fi
+
+fi
+
+if test x$use_pkgconfig = xyes; then
+ : dnl
+ m4_ifdef(
+ [PKG_CHECK_MODULES],
+ [
+ PKG_CHECK_MODULES([SSL], [libssl],, [AC_MSG_ERROR(openssl not found.)])
+ PKG_CHECK_MODULES([CRYPTO], [libcrypto],,[AC_MSG_ERROR(libcrypto not found.)])
+ if test x$enable_bip70 != xno; then
+ DEFI_QT_CHECK([PKG_CHECK_MODULES([PROTOBUF], [protobuf], [have_protobuf=yes], [have_protobuf=no])])
+ fi
+ if test x$use_qr != xno; then
+ DEFI_QT_CHECK([PKG_CHECK_MODULES([QR], [libqrencode], [have_qrencode=yes], [have_qrencode=no])])
+ fi
+ if test x$build_defi_cli$build_defid$defi_enable_qt$use_tests != xnononono; then
+ PKG_CHECK_MODULES([EVENT], [libevent],, [AC_MSG_ERROR(libevent not found.)])
+ if test x$TARGET_OS != xwindows; then
+ PKG_CHECK_MODULES([EVENT_PTHREADS], [libevent_pthreads],, [AC_MSG_ERROR(libevent_pthreads not found.)])
+ fi
+ fi
+
+ if test "x$use_zmq" = "xyes"; then
+ PKG_CHECK_MODULES([ZMQ],[libzmq >= 4],
+ [AC_DEFINE([ENABLE_ZMQ],[1],[Define to 1 to enable ZMQ functions])],
+ [AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])
+ AC_MSG_WARN([libzmq version 4.x or greater not found, disabling])
+ use_zmq=no])
+ else
+ AC_DEFINE_UNQUOTED([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])
+ fi
+ ]
+ )
+else
+ AC_CHECK_HEADER([openssl/crypto.h],,AC_MSG_ERROR(libcrypto headers missing))
+ AC_CHECK_LIB([crypto], [main],CRYPTO_LIBS=-lcrypto, AC_MSG_ERROR(libcrypto missing))
+
+ AC_CHECK_HEADER([openssl/ssl.h],, AC_MSG_ERROR(libssl headers missing),)
+ AC_CHECK_LIB([ssl], [main],SSL_LIBS=-lssl, AC_MSG_ERROR(libssl missing))
+
+ if test x$build_defi_cli$build_defid$defi_enable_qt$use_tests != xnononono; then
+ AC_CHECK_HEADER([event2/event.h],, AC_MSG_ERROR(libevent headers missing),)
+ AC_CHECK_LIB([event],[main],EVENT_LIBS=-levent,AC_MSG_ERROR(libevent missing))
+ if test x$TARGET_OS != xwindows; then
+ AC_CHECK_LIB([event_pthreads],[main],EVENT_PTHREADS_LIBS=-levent_pthreads,AC_MSG_ERROR(libevent_pthreads missing))
fi
fi
- if test x"$set_field" = x; then
- set_field=32bit
+
+ if test "x$use_zmq" = "xyes"; then
+ AC_CHECK_HEADER([zmq.h],
+ [AC_DEFINE([ENABLE_ZMQ],[1],[Define to 1 to enable ZMQ functions])],
+ [AC_MSG_WARN([zmq.h not found, disabling zmq support])
+ use_zmq=no
+ AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])])
+ AC_CHECK_LIB([zmq],[zmq_ctx_shutdown],ZMQ_LIBS=-lzmq,
+ [AC_MSG_WARN([libzmq >= 4.0 not found, disabling zmq support])
+ use_zmq=no
+ AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])])
+ else
+ AC_DEFINE_UNQUOTED([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])
fi
-else
- set_field=$req_field
- case $set_field in
- 64bit)
- if test x"$set_asm" != x"x86_64"; then
- SECP_INT128_CHECK
- if test x"$has_int128" != x"yes"; then
- AC_MSG_ERROR([64bit field explicitly requested but neither __int128 support or x86_64 assembly available])
- fi
- fi
- ;;
- 32bit)
- ;;
- *)
- AC_MSG_ERROR([invalid field implementation selection])
- ;;
- esac
-fi
-if test x"$req_scalar" = x"auto"; then
- SECP_INT128_CHECK
- if test x"$has_int128" = x"yes"; then
- set_scalar=64bit
+ if test "x$use_zmq" = "xyes"; then
+ dnl Assume libzmq was built for static linking
+ case $host in
+ *mingw*)
+ ZMQ_CFLAGS="$ZMQ_CFLAGS -DZMQ_STATIC"
+ ;;
+ esac
fi
- if test x"$set_scalar" = x; then
- set_scalar=32bit
+
+ if test x$enable_bip70 != xno; then
+ DEFI_QT_CHECK(AC_CHECK_LIB([protobuf] ,[main],[PROTOBUF_LIBS=-lprotobuf], [have_protobuf=no]))
fi
-else
- set_scalar=$req_scalar
- case $set_scalar in
- 64bit)
- SECP_INT128_CHECK
- if test x"$has_int128" != x"yes"; then
- AC_MSG_ERROR([64bit scalar explicitly requested but __int128 support not available])
- fi
- ;;
- 32bit)
- ;;
- *)
- AC_MSG_ERROR([invalid scalar implementation selected])
- ;;
- esac
+ if test x$use_qr != xno; then
+ DEFI_QT_CHECK([AC_CHECK_LIB([qrencode], [main],[QR_LIBS=-lqrencode], [have_qrencode=no])])
+ DEFI_QT_CHECK([AC_CHECK_HEADER([qrencode.h],, have_qrencode=no)])
+ fi
+fi
+
+save_CXXFLAGS="${CXXFLAGS}"
+CXXFLAGS="${CXXFLAGS} ${CRYPTO_CFLAGS} ${SSL_CFLAGS}"
+AC_CHECK_DECLS([EVP_MD_CTX_new],,,[AC_INCLUDES_DEFAULT
+#include
+])
+CXXFLAGS="${save_CXXFLAGS}"
+
+dnl RapidCheck property-based testing
+
+enable_property_tests=no
+if test "x$use_rapidcheck" = xauto; then
+ AC_CHECK_HEADERS([rapidcheck.h], [enable_property_tests=yes])
+elif test "x$use_rapidcheck" != xno; then
+ enable_property_tests=yes
+fi
+
+RAPIDCHECK_LIBS=
+if test "x$enable_property_tests" = xyes; then
+ RAPIDCHECK_LIBS=-lrapidcheck
fi
+AC_SUBST(RAPIDCHECK_LIBS)
+AM_CONDITIONAL([ENABLE_PROPERTY_TESTS], [test x$enable_property_tests = xyes])
+
+dnl univalue check
+
+need_bundled_univalue=yes
-if test x"$req_bignum" = x"auto"; then
- SECP_GMP_CHECK
- if test x"$has_gmp" = x"yes"; then
- set_bignum=gmp
+if test x$build_defi_wallet$build_defi_cli$build_defi_tx$build_defid$defi_enable_qt$use_tests$use_bench = xnonononononono; then
+ need_bundled_univalue=no
+else
+
+if test x$system_univalue != xno ; then
+ found_univalue=no
+ if test x$use_pkgconfig = xyes; then
+ : #NOP
+ m4_ifdef(
+ [PKG_CHECK_MODULES],
+ [
+ PKG_CHECK_MODULES([UNIVALUE],[libunivalue >= 1.0.4],[found_univalue=yes],[true])
+ ]
+ )
+ else
+ AC_CHECK_HEADER([univalue.h],[
+ AC_CHECK_LIB([univalue], [main],[
+ UNIVALUE_LIBS=-lunivalue
+ found_univalue=yes
+ ],[true])
+ ],[true])
fi
- if test x"$set_bignum" = x; then
- set_bignum=no
+ if test x$found_univalue = xyes ; then
+ system_univalue=yes
+ need_bundled_univalue=no
+ elif test x$system_univalue = xyes ; then
+ AC_MSG_ERROR([univalue not found])
+ else
+ system_univalue=no
fi
-else
- set_bignum=$req_bignum
- case $set_bignum in
- gmp)
- SECP_GMP_CHECK
- if test x"$has_gmp" != x"yes"; then
- AC_MSG_ERROR([gmp bignum explicitly requested but libgmp not available])
- fi
- ;;
- no)
- ;;
- *)
- AC_MSG_ERROR([invalid bignum implementation selection])
- ;;
- esac
fi
-# select assembly optimization
-use_external_asm=no
+if test x$need_bundled_univalue = xyes ; then
+ UNIVALUE_CFLAGS='-I$(srcdir)/univalue/include'
+ UNIVALUE_LIBS='univalue/libunivalue.la'
+fi
-case $set_asm in
-x86_64)
- AC_DEFINE(USE_ASM_X86_64, 1, [Define this symbol to enable x86_64 assembly optimizations])
- ;;
-arm)
- use_external_asm=yes
- ;;
-no)
- ;;
-*)
- AC_MSG_ERROR([invalid assembly optimizations])
- ;;
-esac
+fi
-# select field implementation
-case $set_field in
-64bit)
- AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation])
- ;;
-32bit)
- AC_DEFINE(USE_FIELD_10X26, 1, [Define this symbol to use the FIELD_10X26 implementation])
- ;;
-*)
- AC_MSG_ERROR([invalid field implementation])
- ;;
-esac
+AM_CONDITIONAL([EMBEDDED_UNIVALUE],[test x$need_bundled_univalue = xyes])
+AC_SUBST(UNIVALUE_CFLAGS)
+AC_SUBST(UNIVALUE_LIBS)
-# select bignum implementation
-case $set_bignum in
-gmp)
- AC_DEFINE(HAVE_LIBGMP, 1, [Define this symbol if libgmp is installed])
- AC_DEFINE(USE_NUM_GMP, 1, [Define this symbol to use the gmp implementation for num])
- AC_DEFINE(USE_FIELD_INV_NUM, 1, [Define this symbol to use the num-based field inverse implementation])
- AC_DEFINE(USE_SCALAR_INV_NUM, 1, [Define this symbol to use the num-based scalar inverse implementation])
- ;;
-no)
- AC_DEFINE(USE_NUM_NONE, 1, [Define this symbol to use no num implementation])
- AC_DEFINE(USE_FIELD_INV_BUILTIN, 1, [Define this symbol to use the native field inverse implementation])
- AC_DEFINE(USE_SCALAR_INV_BUILTIN, 1, [Define this symbol to use the native scalar inverse implementation])
- ;;
-*)
- AC_MSG_ERROR([invalid bignum implementation])
- ;;
-esac
-#select scalar implementation
-case $set_scalar in
-64bit)
- AC_DEFINE(USE_SCALAR_4X64, 1, [Define this symbol to use the 4x64 scalar implementation])
- ;;
-32bit)
- AC_DEFINE(USE_SCALAR_8X32, 1, [Define this symbol to use the 8x32 scalar implementation])
- ;;
-*)
- AC_MSG_ERROR([invalid scalar implementation])
- ;;
-esac
+if test x$have_protobuf != xno &&
+ test x$enable_bip70 != xno; then
+ DEFI_QT_PATH_PROGS([PROTOC], [protoc],$protoc_bin_path)
+fi
-if test x"$use_tests" = x"yes"; then
- SECP_OPENSSL_CHECK
- if test x"$has_openssl_ec" = x"yes"; then
- if test x"$enable_openssl_tests" != x"no"; then
- AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available])
- SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS"
- SECP_TEST_LIBS="$CRYPTO_LIBS"
+AC_MSG_CHECKING([whether to build defid])
+AM_CONDITIONAL([BUILD_DEFID], [test x$build_defid = xyes])
+AC_MSG_RESULT($build_defid)
- case $host in
- *mingw*)
- SECP_TEST_LIBS="$SECP_TEST_LIBS -lgdi32"
- ;;
- esac
+AC_MSG_CHECKING([whether to build defi-cli])
+AM_CONDITIONAL([BUILD_DEFI_CLI], [test x$build_defi_cli = xyes])
+AC_MSG_RESULT($build_defi_cli)
+
+AC_MSG_CHECKING([whether to build defi-tx])
+AM_CONDITIONAL([BUILD_DEFI_TX], [test x$build_defi_tx = xyes])
+AC_MSG_RESULT($build_defi_tx)
+
+AC_MSG_CHECKING([whether to build defi-wallet])
+AM_CONDITIONAL([BUILD_DEFI_WALLET], [test x$build_defi_wallet = xyes])
+AC_MSG_RESULT($build_defi_wallet)
+
+AC_MSG_CHECKING([whether to build libraries])
+AM_CONDITIONAL([BUILD_DEFI_LIBS], [test x$build_defi_libs = xyes])
+if test x$build_defi_libs = xyes; then
+ AC_DEFINE(HAVE_CONSENSUS_LIB, 1, [Define this symbol if the consensus lib has been built])
+ AC_CONFIG_FILES([libdeficonsensus.pc:libdeficonsensus.pc.in])
+fi
+AC_MSG_RESULT($build_defi_libs)
+
+AC_LANG_POP
+
+if test "x$use_ccache" != "xno"; then
+ AC_MSG_CHECKING(if ccache should be used)
+ if test x$CCACHE = x; then
+ if test "x$use_ccache" = "xyes"; then
+ AC_MSG_ERROR([ccache not found.]);
+ else
+ use_ccache=no
fi
else
- if test x"$enable_openssl_tests" = x"yes"; then
- AC_MSG_ERROR([OpenSSL tests requested but OpenSSL with EC support is not available])
- fi
+ use_ccache=yes
+ CC="$ac_cv_path_CCACHE $CC"
+ CXX="$ac_cv_path_CCACHE $CXX"
fi
+ AC_MSG_RESULT($use_ccache)
+fi
+if test "x$use_ccache" = "xyes"; then
+ AX_CHECK_PREPROC_FLAG([-Qunused-arguments],[CPPFLAGS="-Qunused-arguments $CPPFLAGS"])
+fi
+
+dnl enable wallet
+AC_MSG_CHECKING([if wallet should be enabled])
+if test x$enable_wallet != xno; then
+ AC_MSG_RESULT(yes)
+ AC_DEFINE_UNQUOTED([ENABLE_WALLET],[1],[Define to 1 to enable wallet functions])
+
else
- if test x"$enable_openssl_tests" = x"yes"; then
- AC_MSG_ERROR([OpenSSL tests requested but tests are not enabled])
+ AC_MSG_RESULT(no)
+fi
+
+dnl enable upnp support
+AC_MSG_CHECKING([whether to build with support for UPnP])
+if test x$have_miniupnpc = xno; then
+ if test x$use_upnp = xyes; then
+ AC_MSG_ERROR("UPnP requested but cannot be built. Use --without-miniupnpc.")
+ fi
+ AC_MSG_RESULT(no)
+ use_upnp=no
+else
+ if test x$use_upnp != xno; then
+ AC_MSG_RESULT(yes)
+ AC_MSG_CHECKING([whether to build with UPnP enabled by default])
+ use_upnp=yes
+ upnp_setting=0
+ if test x$use_upnp_default != xno; then
+ use_upnp_default=yes
+ upnp_setting=1
+ fi
+ AC_MSG_RESULT($use_upnp_default)
+ AC_DEFINE_UNQUOTED([USE_UPNP],[$upnp_setting],[UPnP support not compiled if undefined, otherwise value (0 or 1) determines default state])
+ if test x$TARGET_OS = xwindows; then
+ MINIUPNPC_CPPFLAGS="-DSTATICLIB -DMINIUPNP_STATICLIB"
+ fi
+ else
+ AC_MSG_RESULT(no)
fi
fi
-if test x"$use_jni" != x"no"; then
- AX_JNI_INCLUDE_DIR
- have_jni_dependencies=yes
- if test x"$enable_module_ecdh" = x"no"; then
- have_jni_dependencies=no
+dnl these are only used when qt is enabled
+BUILD_TEST_QT=""
+if test x$defi_enable_qt != xno; then
+ dnl enable dbus support
+ AC_MSG_CHECKING([whether to build GUI with support for D-Bus])
+ if test x$defi_enable_qt_dbus != xno; then
+ AC_DEFINE([USE_DBUS],[1],[Define if dbus support should be compiled in])
+ fi
+ AC_MSG_RESULT($defi_enable_qt_dbus)
+
+ dnl enable qr support
+ AC_MSG_CHECKING([whether to build GUI with support for QR codes])
+ if test x$have_qrencode = xno; then
+ if test x$use_qr = xyes; then
+ AC_MSG_ERROR("QR support requested but cannot be built. use --without-qrencode")
+ fi
+ AC_MSG_RESULT(no)
+ else
+ if test x$use_qr != xno; then
+ AC_MSG_RESULT(yes)
+ AC_DEFINE([USE_QRCODE],[1],[Define if QR support should be compiled in])
+ use_qr=yes
+ else
+ AC_MSG_RESULT(no)
+ fi
+ fi
+
+ if test x$XGETTEXT = x; then
+ AC_MSG_WARN("xgettext is required to update qt translations")
fi
- if test "x$JNI_INCLUDE_DIRS" = "x"; then
- have_jni_dependencies=no
+
+ AC_MSG_CHECKING([whether to build test_defi-qt])
+ if test x$use_gui_tests$defi_enable_qt_test = xyesyes; then
+ AC_MSG_RESULT([yes])
+ BUILD_TEST_QT="yes"
+ else
+ AC_MSG_RESULT([no])
fi
- if test "x$have_jni_dependencies" = "xno"; then
- if test x"$use_jni" = x"yes"; then
- AC_MSG_ERROR([jni support explicitly requested but headers/dependencies were not found. Enable ECDH and try again.])
+
+ AC_MSG_CHECKING([whether to build BIP70 support])
+ if test x$have_protobuf = xno; then
+ if test x$enable_bip70 = xyes; then
+ AC_MSG_ERROR(protobuf missing)
fi
- AC_MSG_WARN([jni headers/dependencies not found. jni support disabled])
- use_jni=no
+ enable_bip70=no
+ AC_MSG_RESULT(no)
else
- use_jni=yes
- for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS; do
- JNI_INCLUDES="$JNI_INCLUDES -I$JNI_INCLUDE_DIR"
- done
+ if test x$enable_bip70 != xno; then
+ AC_DEFINE([ENABLE_BIP70],[1],[Define if BIP70 support should be compiled in])
+ enable_bip70=yes
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ fi
fi
fi
-if test x"$set_bignum" = x"gmp"; then
- SECP_LIBS="$SECP_LIBS $GMP_LIBS"
- SECP_INCLUDES="$SECP_INCLUDES $GMP_CPPFLAGS"
-fi
+AM_CONDITIONAL([ENABLE_ZMQ], [test "x$use_zmq" = "xyes"])
-if test x"$use_endomorphism" = x"yes"; then
- AC_DEFINE(USE_ENDOMORPHISM, 1, [Define this symbol to use endomorphism optimization])
+AC_MSG_CHECKING([whether to build test_defi])
+if test x$use_tests = xyes; then
+ AC_MSG_RESULT([yes])
+ BUILD_TEST="yes"
+else
+ AC_MSG_RESULT([no])
+ BUILD_TEST=""
fi
-if test x"$set_precomp" = x"yes"; then
- AC_DEFINE(USE_ECMULT_STATIC_PRECOMPUTATION, 1, [Define this symbol to use a statically generated ecmult table])
+AC_MSG_CHECKING([whether to reduce exports])
+if test x$use_reduce_exports = xyes; then
+ AC_MSG_RESULT([yes])
+else
+ AC_MSG_RESULT([no])
fi
-if test x"$enable_module_ecdh" = x"yes"; then
- AC_DEFINE(ENABLE_MODULE_ECDH, 1, [Define this symbol to enable the ECDH module])
+if test x$build_defi_wallet$build_defi_cli$build_defi_tx$build_defi_libs$build_defid$defi_enable_qt$use_bench$use_tests = xnononononononono; then
+ AC_MSG_ERROR([No targets! Please specify at least one of: --with-utils --with-libs --with-daemon --with-gui --enable-bench or --enable-tests])
fi
-if test x"$enable_module_recovery" = x"yes"; then
- AC_DEFINE(ENABLE_MODULE_RECOVERY, 1, [Define this symbol to enable the ECDSA pubkey recovery module])
-fi
+AM_CONDITIONAL([TARGET_DARWIN], [test x$TARGET_OS = xdarwin])
+AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
+AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
+AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
+AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
+AM_CONDITIONAL([ENABLE_FUZZ],[test x$enable_fuzz = xyes])
+AM_CONDITIONAL([ENABLE_QT],[test x$defi_enable_qt = xyes])
+AM_CONDITIONAL([ENABLE_QT_TESTS],[test x$BUILD_TEST_QT = xyes])
+AM_CONDITIONAL([ENABLE_BIP70],[test x$enable_bip70 = xyes])
+AM_CONDITIONAL([ENABLE_BENCH],[test x$use_bench = xyes])
+AM_CONDITIONAL([USE_QRCODE], [test x$use_qr = xyes])
+AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
+AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes])
+AM_CONDITIONAL([HARDEN],[test x$use_hardening = xyes])
+AM_CONDITIONAL([ENABLE_HWCRC32],[test x$enable_hwcrc32 = xyes])
+AM_CONDITIONAL([ENABLE_SSE41],[test x$enable_sse41 = xyes])
+AM_CONDITIONAL([ENABLE_AVX2],[test x$enable_avx2 = xyes])
+AM_CONDITIONAL([ENABLE_SHANI],[test x$enable_shani = xyes])
+AM_CONDITIONAL([USE_ASM],[test x$use_asm = xyes])
-AC_C_BIGENDIAN()
+AC_DEFINE(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR, [Major version])
+AC_DEFINE(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR, [Minor version])
+AC_DEFINE(CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION, [Build revision])
+AC_DEFINE(CLIENT_VERSION_BUILD, _CLIENT_VERSION_BUILD, [Version Build])
+AC_DEFINE(CLIENT_VERSION_IS_RELEASE, _CLIENT_VERSION_IS_RELEASE, [Version is release])
+AC_DEFINE(COPYRIGHT_YEAR, _COPYRIGHT_YEAR, [Copyright year])
+AC_DEFINE(COPYRIGHT_HOLDERS, "_COPYRIGHT_HOLDERS", [Copyright holder(s) before %s replacement])
+AC_DEFINE(COPYRIGHT_HOLDERS_SUBSTITUTION, "_COPYRIGHT_HOLDERS_SUBSTITUTION", [Replacement for %s in copyright holders string])
+define(_COPYRIGHT_HOLDERS_FINAL, [patsubst(_COPYRIGHT_HOLDERS, [%s], [_COPYRIGHT_HOLDERS_SUBSTITUTION])])
+AC_DEFINE(COPYRIGHT_HOLDERS_FINAL, "_COPYRIGHT_HOLDERS_FINAL", [Copyright holder(s)])
+AC_SUBST(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR)
+AC_SUBST(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR)
+AC_SUBST(CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION)
+AC_SUBST(CLIENT_VERSION_BUILD, _CLIENT_VERSION_BUILD)
+AC_SUBST(CLIENT_VERSION_IS_RELEASE, _CLIENT_VERSION_IS_RELEASE)
+AC_SUBST(COPYRIGHT_YEAR, _COPYRIGHT_YEAR)
+AC_SUBST(COPYRIGHT_HOLDERS, "_COPYRIGHT_HOLDERS")
+AC_SUBST(COPYRIGHT_HOLDERS_SUBSTITUTION, "_COPYRIGHT_HOLDERS_SUBSTITUTION")
+AC_SUBST(COPYRIGHT_HOLDERS_FINAL, "_COPYRIGHT_HOLDERS_FINAL")
+AC_SUBST(DEFI_DAEMON_NAME)
+AC_SUBST(DEFI_GUI_NAME)
+AC_SUBST(DEFI_CLI_NAME)
+AC_SUBST(DEFI_TX_NAME)
+AC_SUBST(DEFI_WALLET_TOOL_NAME)
-if test x"$use_external_asm" = x"yes"; then
- AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used])
-fi
+AC_SUBST(RELDFLAGS)
+AC_SUBST(DEBUG_CPPFLAGS)
+AC_SUBST(WARN_CXXFLAGS)
+AC_SUBST(NOWARN_CXXFLAGS)
+AC_SUBST(DEBUG_CXXFLAGS)
+AC_SUBST(COMPAT_LDFLAGS)
+AC_SUBST(ERROR_CXXFLAGS)
+AC_SUBST(GPROF_CXXFLAGS)
+AC_SUBST(GPROF_LDFLAGS)
+AC_SUBST(HARDENED_CXXFLAGS)
+AC_SUBST(HARDENED_CPPFLAGS)
+AC_SUBST(HARDENED_LDFLAGS)
+AC_SUBST(PIC_FLAGS)
+AC_SUBST(PIE_FLAGS)
+AC_SUBST(SANITIZER_CXXFLAGS)
+AC_SUBST(SANITIZER_LDFLAGS)
+AC_SUBST(SSE42_CXXFLAGS)
+AC_SUBST(SSE41_CXXFLAGS)
+AC_SUBST(AVX2_CXXFLAGS)
+AC_SUBST(SHANI_CXXFLAGS)
+AC_SUBST(LIBTOOL_APP_LDFLAGS)
+AC_SUBST(USE_UPNP)
+AC_SUBST(USE_QRCODE)
+AC_SUBST(BOOST_LIBS)
+AC_SUBST(TESTDEFS)
+AC_SUBST(LEVELDB_TARGET_FLAGS)
+AC_SUBST(MINIUPNPC_CPPFLAGS)
+AC_SUBST(MINIUPNPC_LIBS)
+AC_SUBST(CRYPTO_LIBS)
+AC_SUBST(SSL_LIBS)
+AC_SUBST(EVENT_LIBS)
+AC_SUBST(EVENT_PTHREADS_LIBS)
+AC_SUBST(ZMQ_LIBS)
+AC_SUBST(PROTOBUF_LIBS)
+AC_SUBST(QR_LIBS)
+AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist test/config.ini])
+AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh])
+AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])
+AC_CONFIG_LINKS([contrib/filter-lcov.py:contrib/filter-lcov.py])
+AC_CONFIG_LINKS([test/functional/test_runner.py:test/functional/test_runner.py])
+AC_CONFIG_LINKS([test/util/defi-util-test.py:test/util/defi-util-test.py])
+AC_CONFIG_LINKS([test/util/rpcauth-test.py:test/util/rpcauth-test.py])
-if test x"$enable_experimental" = x"yes"; then
- AC_MSG_NOTICE([******])
- AC_MSG_NOTICE([WARNING: experimental build])
- AC_MSG_NOTICE([Experimental features do not have stable APIs or properties, and may not be safe for production use.])
- AC_MSG_NOTICE([Building ECDH module: $enable_module_ecdh])
- AC_MSG_NOTICE([******])
-else
- if test x"$enable_module_ecdh" = x"yes"; then
- AC_MSG_ERROR([ECDH module is experimental. Use --enable-experimental to allow.])
- fi
- if test x"$set_asm" = x"arm"; then
- AC_MSG_ERROR([ARM assembly optimization is experimental. Use --enable-experimental to allow.])
- fi
-fi
+dnl boost's m4 checks do something really nasty: they export these vars. As a
+dnl result, they leak into secp256k1's configure and crazy things happen.
+dnl Until this is fixed upstream and we've synced, we'll just un-export them.
+CPPFLAGS_TEMP="$CPPFLAGS"
+unset CPPFLAGS
+CPPFLAGS="$CPPFLAGS_TEMP"
+
+LDFLAGS_TEMP="$LDFLAGS"
+unset LDFLAGS
+LDFLAGS="$LDFLAGS_TEMP"
+
+LIBS_TEMP="$LIBS"
+unset LIBS
+LIBS="$LIBS_TEMP"
-AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
-AC_CONFIG_FILES([Makefile libsecp256k1.pc])
-AC_SUBST(JNI_INCLUDES)
-AC_SUBST(SECP_INCLUDES)
-AC_SUBST(SECP_LIBS)
-AC_SUBST(SECP_TEST_LIBS)
-AC_SUBST(SECP_TEST_INCLUDES)
-AM_CONDITIONAL([ENABLE_COVERAGE], [test x"$enable_coverage" = x"yes"])
-AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"])
-AM_CONDITIONAL([USE_EXHAUSTIVE_TESTS], [test x"$use_exhaustive_tests" != x"no"])
-AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"])
-AM_CONDITIONAL([USE_ECMULT_STATIC_PRECOMPUTATION], [test x"$set_precomp" = x"yes"])
-AM_CONDITIONAL([ENABLE_MODULE_ECDH], [test x"$enable_module_ecdh" = x"yes"])
-AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"yes"])
-AM_CONDITIONAL([USE_JNI], [test x"$use_jni" = x"yes"])
-AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$use_external_asm" = x"yes"])
-AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm"])
-
-dnl make sure nothing new is exported so that we don't break the cache
PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH"
unset PKG_CONFIG_PATH
PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"
+PKGCONFIG_LIBDIR_TEMP="$PKG_CONFIG_LIBDIR"
+unset PKG_CONFIG_LIBDIR
+PKG_CONFIG_LIBDIR="$PKGCONFIG_LIBDIR_TEMP"
+
+if test x$need_bundled_univalue = xyes; then
+ AC_CONFIG_SUBDIRS([src/univalue])
+fi
+
+ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-benchmark=no --with-bignum=no --enable-module-recovery --disable-jni"
+AC_CONFIG_SUBDIRS([src/secp256k1])
+
AC_OUTPUT
+dnl Taken from https://wiki.debian.org/RpathIssue
+case $host in
+ *-*-linux-gnu)
+ AC_MSG_RESULT([Fixing libtool for -rpath problems.])
+ sed < libtool > libtool-2 \
+ 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_IS_A_FOOL__ "/'
+ mv libtool-2 libtool
+ chmod 755 libtool
+ ;;
+esac
+
+dnl Replace the BUILDDIR path with the correct Windows path if compiling on Native Windows
+case ${OS} in
+ *Windows*)
+ sed 's/BUILDDIR="\/\([[a-z]]\)/BUILDDIR="\1:/' test/config.ini > test/config-2.ini
+ mv test/config-2.ini test/config.ini
+ ;;
+esac
+
echo
-echo "Build Options:"
-echo " with endomorphism = $use_endomorphism"
-echo " with ecmult precomp = $set_precomp"
-echo " with jni = $use_jni"
-echo " with benchmarks = $use_benchmark"
-echo " with coverage = $enable_coverage"
-echo " module ecdh = $enable_module_ecdh"
-echo " module recovery = $enable_module_recovery"
+echo "Options used to compile and link:"
+echo " with wallet = $enable_wallet"
+echo " with gui / qt = $defi_enable_qt"
+if test x$defi_enable_qt != xno; then
+ echo " with bip70 = $enable_bip70"
+ echo " with qr = $use_qr"
+fi
+echo " with zmq = $use_zmq"
+echo " with test = $use_tests"
+if test x$use_tests != xno; then
+ echo " with prop = $enable_property_tests"
+ echo " with fuzz = $enable_fuzz"
+fi
+echo " with bench = $use_bench"
+echo " with upnp = $use_upnp"
+echo " use asm = $use_asm"
+echo " sanitizers = $use_sanitizers"
+echo " debug enabled = $enable_debug"
+echo " gprof enabled = $enable_gprof"
+echo " werror = $enable_werror"
echo
-echo " asm = $set_asm"
-echo " bignum = $set_bignum"
-echo " field = $set_field"
-echo " scalar = $set_scalar"
+echo " target os = $TARGET_OS"
+echo " build os = $BUILD_OS"
echo
-echo " CC = $CC"
-echo " CFLAGS = $CFLAGS"
-echo " CPPFLAGS = $CPPFLAGS"
-echo " LDFLAGS = $LDFLAGS"
+echo " CC = $CC"
+echo " CFLAGS = $CFLAGS"
+echo " CPPFLAGS = $DEBUG_CPPFLAGS $HARDENED_CPPFLAGS $CPPFLAGS"
+echo " CXX = $CXX"
+echo " CXXFLAGS = $DEBUG_CXXFLAGS $HARDENED_CXXFLAGS $WARN_CXXFLAGS $NOWARN_CXXFLAGS $ERROR_CXXFLAGS $GPROF_CXXFLAGS $CXXFLAGS"
+echo " LDFLAGS = $PTHREAD_CFLAGS $HARDENED_LDFLAGS $GPROF_LDFLAGS $LDFLAGS"
+echo " ARFLAGS = $ARFLAGS"
echo
diff --git a/contrib/README.md b/contrib/README.md
new file mode 100644
index 0000000000..e9e72f6686
--- /dev/null
+++ b/contrib/README.md
@@ -0,0 +1,48 @@
+Repository Tools
+---------------------
+
+### [Developer tools](/contrib/devtools) ###
+Specific tools for developers working on this repository.
+Additional tools, including the `github-merge.py` script, are available in the [maintainer-tools](https://github.com/bitcoin-core/bitcoin-maintainer-tools) repository.
+
+### [Verify-Commits](/contrib/verify-commits) ###
+Tool to verify that every merge commit was signed by a developer using the `github-merge.py` script.
+
+### [Linearize](/contrib/linearize) ###
+Construct a linear, no-fork, best version of the blockchain.
+
+### [Qos](/contrib/qos) ###
+
+A Linux bash script that will set up traffic control (tc) to limit the outgoing bandwidth for connections to the Bitcoin network. This means one can have an always-on bitcoind instance running, and another local bitcoind/bitcoin-qt instance which connects to this node and receives blocks from it.
+
+### [Seeds](/contrib/seeds) ###
+Utility to generate the pnSeed[] array that is compiled into the client.
+
+Build Tools and Keys
+---------------------
+
+### Packaging ###
+The [Debian](/contrib/debian) subfolder contains the copyright file.
+
+All other packaging related files can be found in the [bitcoin-core/packaging](https://github.com/bitcoin-core/packaging) repository.
+
+### [Gitian-descriptors](/contrib/gitian-descriptors) ###
+Files used during the gitian build process. For more information about gitian, see the [the Bitcoin Core documentation repository](https://github.com/bitcoin-core/docs).
+
+### [Gitian-keys](/contrib/gitian-keys)
+PGP keys used for signing Bitcoin Core [Gitian release](/doc/release-process.md) results.
+
+### [MacDeploy](/contrib/macdeploy) ###
+Scripts and notes for Mac builds.
+
+### [Gitian-build](/contrib/gitian-build.py) ###
+Script for running full Gitian builds.
+
+Test and Verify Tools
+---------------------
+
+### [TestGen](/contrib/testgen) ###
+Utilities to generate test vectors for the data-driven Bitcoin tests.
+
+### [Verify Binaries](/contrib/verifybinaries) ###
+This script attempts to download and verify the signature file SHA256SUMS.asc from bitcoin.org.
diff --git a/contrib/debian/copyright b/contrib/debian/copyright
new file mode 100644
index 0000000000..ee71dce87b
--- /dev/null
+++ b/contrib/debian/copyright
@@ -0,0 +1,146 @@
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: Bitcoin
+Upstream-Contact: Satoshi Nakamoto
+ irc://#bitcoin@freenode.net
+Source: https://github.com/bitcoin/bitcoin
+
+Files: *
+Copyright: 2009-2019, Bitcoin Core Developers
+License: Expat
+Comment: The Bitcoin Core Developers encompasses the current developers listed on bitcoin.org,
+ as well as the numerous contributors to the project.
+
+Files: debian/*
+Copyright: 2010-2011, Jonas Smedegaard
+ 2011, Matt Corallo
+License: GPL-2+
+
+Files: src/secp256k1/build-aux/m4/ax_jni_include_dir.m4
+Copyright: 2008 Don Anderson
+License: GNU-All-permissive-License
+
+Files: src/secp256k1/build-aux/m4/ax_prog_cc_for_build.m4
+Copyright: 2008 Paolo Bonzini
+License: GNU-All-permissive-License
+
+Files: src/qt/res/icons/add.png
+ src/qt/res/icons/address-book.png
+ src/qt/res/icons/chevron.png
+ src/qt/res/icons/edit.png
+ src/qt/res/icons/editcopy.png
+ src/qt/res/icons/editpaste.png
+ src/qt/res/icons/export.png
+ src/qt/res/icons/eye.png
+ src/qt/res/icons/history.png
+ src/qt/res/icons/lock_*.png
+ src/qt/res/icons/overview.png
+ src/qt/res/icons/receive.png
+ src/qt/res/icons/remove.png
+ src/qt/res/icons/send.png
+ src/qt/res/icons/synced.png
+ src/qt/res/icons/transaction*.png
+ src/qt/res/icons/tx_output.png
+ src/qt/res/icons/warning.png
+Copyright: Stephen Hutchings (and more)
+ http://typicons.com
+License: Expat
+Comment: Site: https://github.com/stephenhutchings/typicons.font
+
+Files: src/qt/res/icons/connect*.png
+ src/qt/res/src/connect-*.svg
+ src/qt/res/icons/network_disabled.png
+ src/qt/res/src/network_disabled.svg
+Copyright: Marco Falke
+ Luke Dashjr
+License: Expat
+Comment: Inspired by Stephen Hutchings' Typicons
+
+Files: src/qt/res/icons/tx_mined.png
+ src/qt/res/src/mine.svg
+ src/qt/res/icons/fontbigger.png
+ src/qt/res/icons/fontsmaller.png
+ src/qt/res/icons/hd_disabled.png
+ src/qt/res/src/hd_disabled.svg
+ src/qt/res/icons/hd_enabled.png
+ src/qt/res/src/hd_enabled.svg
+Copyright: Jonas Schnelli
+License: Expat
+
+Files: src/qt/res/icons/clock*.png
+ src/qt/res/icons/eye_*.png
+ src/qt/res/icons/tx_in*.png
+ src/qt/res/src/clock_*.svg
+ src/qt/res/src/tx_*.svg
+Copyright: Stephen Hutchings, Jonas Schnelli
+License: Expat
+Comment: Modifications of Stephen Hutchings' Typicons
+
+Files: src/qt/res/icons/defi.*
+ share/pixmaps/defi*
+ src/qt/res/src/defi.svg
+Copyright: Bitboy, Jonas Schnelli
+License: public-domain
+Comment: Site: https://bitcointalk.org/?topic=1756.0
+
+Files: src/qt/res/icons/proxy.png
+ src/qt/res/src/proxy.svg
+Copyright: Cristian Mircea Messel
+License: public-domain
+
+
+License: Expat
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+ .
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+ .
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+License: GNU-All-permissive-License
+ Copying and distribution of this file, with or without modification, are
+ permitted in any medium without royalty provided the copyright notice
+ and this notice are preserved. This file is offered as-is, without any
+ warranty.
+
+License: GPL-2+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+ .
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+Comment:
+ On Debian systems the GNU General Public License (GPL) version 2 is
+ located in '/usr/share/common-licenses/GPL-2'.
+ .
+ You should have received a copy of the GNU General Public License along
+ with this program. If not, see .
+
+License: GPL-3+
+ Permission is granted to copy, distribute and/or modify this document
+ under the terms of the GNU General Public License, Version 3 or any
+ later version published by the Free Software Foundation.
+Comment:
+ On Debian systems the GNU General Public License (GPL) version 3 is
+ located in '/usr/share/common-licenses/GPL-3'.
+ .
+ You should have received a copy of the GNU General Public License along
+ with this program. If not, see .
+
+License: public-domain
+ This work is in the public domain.
diff --git a/contrib/defi-cli.bash-completion b/contrib/defi-cli.bash-completion
new file mode 100644
index 0000000000..ddfc520316
--- /dev/null
+++ b/contrib/defi-cli.bash-completion
@@ -0,0 +1,154 @@
+# bash programmable completion for defi-cli(1)
+# Copyright (c) 2012-2016 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+# call $defi-cli for RPC
+_defi_rpc() {
+ # determine already specified args necessary for RPC
+ local rpcargs=()
+ for i in ${COMP_LINE}; do
+ case "$i" in
+ -conf=*|-datadir=*|-regtest|-rpc*|-testnet)
+ rpcargs=( "${rpcargs[@]}" "$i" )
+ ;;
+ esac
+ done
+ $defi_cli "${rpcargs[@]}" "$@"
+}
+
+# Add wallet accounts to COMPREPLY
+_defi_accounts() {
+ local accounts
+ accounts=$(_defi_rpc listaccounts | awk -F '"' '{ print $2 }')
+ COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$accounts" -- "$cur" ) )
+}
+
+_defi_cli() {
+ local cur prev words=() cword
+ local defi_cli
+
+ # save and use original argument to invoke defi-cli for -help, help and RPC
+ # as defi-cli might not be in $PATH
+ defi_cli="$1"
+
+ COMPREPLY=()
+ _get_comp_words_by_ref -n = cur prev words cword
+
+ if ((cword > 5)); then
+ case ${words[cword-5]} in
+ sendtoaddress)
+ COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
+ return 0
+ ;;
+ esac
+ fi
+
+ if ((cword > 4)); then
+ case ${words[cword-4]} in
+ importaddress|listtransactions|setban)
+ COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
+ return 0
+ ;;
+ signrawtransactionwithkey|signrawtransactionwithwallet)
+ COMPREPLY=( $( compgen -W "ALL NONE SINGLE ALL|ANYONECANPAY NONE|ANYONECANPAY SINGLE|ANYONECANPAY" -- "$cur" ) )
+ return 0
+ ;;
+ esac
+ fi
+
+ if ((cword > 3)); then
+ case ${words[cword-3]} in
+ addmultisigaddress)
+ _defi_accounts
+ return 0
+ ;;
+ getbalance|gettxout|importaddress|importpubkey|importprivkey|listreceivedbyaccount|listreceivedbyaddress|listsinceblock)
+ COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
+ return 0
+ ;;
+ esac
+ fi
+
+ if ((cword > 2)); then
+ case ${words[cword-2]} in
+ addnode)
+ COMPREPLY=( $( compgen -W "add remove onetry" -- "$cur" ) )
+ return 0
+ ;;
+ setban)
+ COMPREPLY=( $( compgen -W "add remove" -- "$cur" ) )
+ return 0
+ ;;
+ fundrawtransaction|getblock|getblockheader|getmempoolancestors|getmempooldescendants|getrawtransaction|gettransaction|listaccounts|listreceivedbyaccount|listreceivedbyaddress|sendrawtransaction)
+ COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
+ return 0
+ ;;
+ move|setaccount)
+ _defi_accounts
+ return 0
+ ;;
+ esac
+ fi
+
+ case "$prev" in
+ backupwallet|dumpwallet|importwallet)
+ _filedir
+ return 0
+ ;;
+ getaddednodeinfo|getrawmempool|lockunspent|setgenerate)
+ COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
+ return 0
+ ;;
+ getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
+ _defi_accounts
+ return 0
+ ;;
+ esac
+
+ case "$cur" in
+ -conf=*)
+ cur="${cur#*=}"
+ _filedir
+ return 0
+ ;;
+ -datadir=*)
+ cur="${cur#*=}"
+ _filedir -d
+ return 0
+ ;;
+ -*=*) # prevent nonsense completions
+ return 0
+ ;;
+ *)
+ local helpopts commands
+
+ # only parse -help if senseful
+ if [[ -z "$cur" || "$cur" =~ ^- ]]; then
+ helpopts=$($defi_cli -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
+ fi
+
+ # only parse help if senseful
+ if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then
+ commands=$(_defi_rpc help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }')
+ fi
+
+ COMPREPLY=( $( compgen -W "$helpopts $commands" -- "$cur" ) )
+
+ # Prevent space if an argument is desired
+ if [[ $COMPREPLY == *= ]]; then
+ compopt -o nospace
+ fi
+ return 0
+ ;;
+ esac
+} &&
+complete -F _defi_cli defi-cli
+
+# Local variables:
+# mode: shell-script
+# sh-basic-offset: 4
+# sh-indent-comment: t
+# indent-tabs-mode: nil
+# End:
+# ex: ts=4 sw=4 et filetype=sh
diff --git a/contrib/defi-qt.pro b/contrib/defi-qt.pro
new file mode 100644
index 0000000000..ace6148378
--- /dev/null
+++ b/contrib/defi-qt.pro
@@ -0,0 +1,21 @@
+FORMS += \
+ ../src/qt/forms/aboutdialog.ui \
+ ../src/qt/forms/addressbookpage.ui \
+ ../src/qt/forms/askpassphrasedialog.ui \
+ ../src/qt/forms/coincontroldialog.ui \
+ ../src/qt/forms/editaddressdialog.ui \
+ ../src/qt/forms/helpmessagedialog.ui \
+ ../src/qt/forms/intro.ui \
+ ../src/qt/forms/openuridialog.ui \
+ ../src/qt/forms/optionsdialog.ui \
+ ../src/qt/forms/overviewpage.ui \
+ ../src/qt/forms/receivecoinsdialog.ui \
+ ../src/qt/forms/receiverequestdialog.ui \
+ ../src/qt/forms/debugwindow.ui \
+ ../src/qt/forms/sendcoinsdialog.ui \
+ ../src/qt/forms/sendcoinsentry.ui \
+ ../src/qt/forms/signverifymessagedialog.ui \
+ ../src/qt/forms/transactiondescdialog.ui \
+
+RESOURCES += \
+ ../src/qt/defi.qrc
diff --git a/contrib/defi-tx.bash-completion b/contrib/defi-tx.bash-completion
new file mode 100644
index 0000000000..4b6f03d511
--- /dev/null
+++ b/contrib/defi-tx.bash-completion
@@ -0,0 +1,57 @@
+# bash programmable completion for defi-tx(1)
+# Copyright (c) 2016 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+_defi_tx() {
+ local cur prev words=() cword
+ local defi_tx
+
+ # save and use original argument to invoke defi-tx for -help
+ # it might not be in $PATH
+ defi_tx="$1"
+
+ COMPREPLY=()
+ _get_comp_words_by_ref -n =: cur prev words cword
+
+ case "$cur" in
+ load=*:*)
+ cur="${cur#load=*:}"
+ _filedir
+ return 0
+ ;;
+ *=*) # prevent attempts to complete other arguments
+ return 0
+ ;;
+ esac
+
+ if [[ "$cword" == 1 || ( "$prev" != "-create" && "$prev" == -* ) ]]; then
+ # only options (or an uncompletable hex-string) allowed
+ # parse defi-tx -help for options
+ local helpopts
+ helpopts=$($defi_tx -help | sed -e '/^ -/ p' -e d )
+ COMPREPLY=( $( compgen -W "$helpopts" -- "$cur" ) )
+ else
+ # only commands are allowed
+ # parse -help for commands
+ local helpcmds
+ helpcmds=$($defi_tx -help | sed -e '1,/Commands:/d' -e 's/=.*/=/' -e '/^ [a-z]/ p' -e d )
+ COMPREPLY=( $( compgen -W "$helpcmds" -- "$cur" ) )
+ fi
+
+ # Prevent space if an argument is desired
+ if [[ $COMPREPLY == *= ]]; then
+ compopt -o nospace
+ fi
+
+ return 0
+} &&
+complete -F _defi_tx defi-tx
+
+# Local variables:
+# mode: shell-script
+# sh-basic-offset: 4
+# sh-indent-comment: t
+# indent-tabs-mode: nil
+# End:
+# ex: ts=4 sw=4 et filetype=sh
diff --git a/contrib/defid.bash-completion b/contrib/defid.bash-completion
new file mode 100644
index 0000000000..fa8fba8f47
--- /dev/null
+++ b/contrib/defid.bash-completion
@@ -0,0 +1,56 @@
+# bash programmable completion for defid(1) and defi-qt(1)
+# Copyright (c) 2012-2016 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+_defid() {
+ local cur prev words=() cword
+ local defid
+
+ # save and use original argument to invoke defid for -help
+ # it might not be in $PATH
+ defid="$1"
+
+ COMPREPLY=()
+ _get_comp_words_by_ref -n = cur prev words cword
+
+ case "$cur" in
+ -conf=*|-pid=*|-loadblock=*|-rootcertificates=*|-rpccookiefile=*|-wallet=*)
+ cur="${cur#*=}"
+ _filedir
+ return 0
+ ;;
+ -datadir=*)
+ cur="${cur#*=}"
+ _filedir -d
+ return 0
+ ;;
+ -*=*) # prevent nonsense completions
+ return 0
+ ;;
+ *)
+
+ # only parse -help if sensible
+ if [[ -z "$cur" || "$cur" =~ ^- ]]; then
+ local helpopts
+ helpopts=$($defid -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' )
+ COMPREPLY=( $( compgen -W "$helpopts" -- "$cur" ) )
+ fi
+
+ # Prevent space if an argument is desired
+ if [[ $COMPREPLY == *= ]]; then
+ compopt -o nospace
+ fi
+ return 0
+ ;;
+ esac
+} &&
+complete -F _defid defid defi-qt
+
+# Local variables:
+# mode: shell-script
+# sh-basic-offset: 4
+# sh-indent-comment: t
+# indent-tabs-mode: nil
+# End:
+# ex: ts=4 sw=4 et filetype=sh
diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md
new file mode 100644
index 0000000000..3136585ecc
--- /dev/null
+++ b/contrib/devtools/README.md
@@ -0,0 +1,132 @@
+Contents
+========
+This directory contains tools for developers working on this repository.
+
+clang-format-diff.py
+===================
+
+A script to format unified git diffs according to [.clang-format](../../src/.clang-format).
+
+Requires `clang-format`, installed e.g. via `brew install clang-format` on macOS.
+
+For instance, to format the last commit with 0 lines of context,
+the script should be called from the git root folder as follows.
+
+```
+git diff -U0 HEAD~1.. | ./contrib/devtools/clang-format-diff.py -p1 -i -v
+```
+
+copyright\_header.py
+====================
+
+Provides utilities for managing copyright headers of `The Bitcoin Core
+developers` in repository source files. It has three subcommands:
+
+```
+$ ./copyright_header.py report [verbose]
+$ ./copyright_header.py update
+$ ./copyright_header.py insert
+```
+Running these subcommands without arguments displays a usage string.
+
+copyright\_header.py report \ [verbose]
+---------------------------------------------------------
+
+Produces a report of all copyright header notices found inside the source files
+of a repository. Useful to quickly visualize the state of the headers.
+Specifying `verbose` will list the full filenames of files of each category.
+
+copyright\_header.py update \ [verbose]
+---------------------------------------------------------
+Updates all the copyright headers of `The Bitcoin Core developers` which were
+changed in a year more recent than is listed. For example:
+```
+// Copyright (c) - The Bitcoin Core developers
+```
+will be updated to:
+```
+// Copyright (c) - The Bitcoin Core developers
+```
+where `` is obtained from the `git log` history.
+
+This subcommand also handles copyright headers that have only a single year. In
+those cases:
+```
+// Copyright (c) The Bitcoin Core developers
+```
+will be updated to:
+```
+// Copyright (c) - The Bitcoin Core developers
+```
+where the update is appropriate.
+
+copyright\_header.py insert \
+------------------------------------
+Inserts a copyright header for `The Bitcoin Core developers` at the top of the
+file in either Python or C++ style as determined by the file extension. If the
+file is a Python file and it has `#!` starting the first line, the header is
+inserted in the line below it.
+
+The copyright dates will be set to be `-` where
+`` is according to the `git log` history. If
+`` is equal to ``, it will be set as a single
+year rather than two hyphenated years.
+
+If the file already has a copyright for `The Bitcoin Core developers`, the
+script will exit.
+
+gen-manpages.sh
+===============
+
+A small script to automatically create manpages in ../../doc/man by running the release binaries with the -help option.
+This requires help2man which can be found at: https://www.gnu.org/software/help2man/
+
+With in-tree builds this tool can be run from any directory within the
+repostitory. To use this tool with out-of-tree builds set `BUILDDIR`. For
+example:
+
+```bash
+BUILDDIR=$PWD/build contrib/devtools/gen-manpages.sh
+```
+
+optimize-pngs.py
+================
+
+A script to optimize png files in the defi
+repository (requires pngcrush).
+
+security-check.py and test-security-check.py
+============================================
+
+Perform basic ELF security checks on a series of executables.
+
+symbol-check.py
+===============
+
+A script to check that the (Linux) executables produced by gitian only contain
+allowed gcc, glibc and libstdc++ version symbols. This makes sure they are
+still compatible with the minimum supported Linux distribution versions.
+
+Example usage after a gitian build:
+
+ find ../gitian-builder/build -type f -executable | xargs python3 contrib/devtools/symbol-check.py
+
+If only supported symbols are used the return value will be 0 and the output will be empty.
+
+If there are 'unsupported' symbols, the return value will be 1 a list like this will be printed:
+
+ .../64/test_defi: symbol memcpy from unsupported version GLIBC_2.14
+ .../64/test_defi: symbol __fdelt_chk from unsupported version GLIBC_2.15
+ .../64/test_defi: symbol std::out_of_range::~out_of_range() from unsupported version GLIBCXX_3.4.15
+ .../64/test_defi: symbol _ZNSt8__detail15_List_nod from unsupported version GLIBCXX_3.4.15
+
+circular-dependencies.py
+========================
+
+Run this script from the root of the source tree (`src/`) to find circular dependencies in the source code.
+This looks only at which files include other files, treating the `.cpp` and `.h` file as one unit.
+
+Example usage:
+
+ cd .../src
+ ../contrib/devtools/circular-dependencies.py {*,*/*,*/*/*}.{h,cpp}
diff --git a/contrib/devtools/circular-dependencies.py b/contrib/devtools/circular-dependencies.py
new file mode 100755
index 0000000000..2e4657f1dd
--- /dev/null
+++ b/contrib/devtools/circular-dependencies.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python3
+
+import sys
+import re
+
+MAPPING = {
+ 'core_read.cpp': 'core_io.cpp',
+ 'core_write.cpp': 'core_io.cpp',
+}
+
+# Directories with header-based modules, where the assumption that .cpp files
+# define functions and variables declared in corresponding .h files is
+# incorrect.
+HEADER_MODULE_PATHS = [
+ 'interfaces/'
+]
+
+def module_name(path):
+ if path in MAPPING:
+ path = MAPPING[path]
+ if any(path.startswith(dirpath) for dirpath in HEADER_MODULE_PATHS):
+ return path
+ if path.endswith(".h"):
+ return path[:-2]
+ if path.endswith(".c"):
+ return path[:-2]
+ if path.endswith(".cpp"):
+ return path[:-4]
+ return None
+
+files = dict()
+deps = dict()
+
+RE = re.compile("^#include <(.*)>")
+
+# Iterate over files, and create list of modules
+for arg in sys.argv[1:]:
+ module = module_name(arg)
+ if module is None:
+ print("Ignoring file %s (does not constitute module)\n" % arg)
+ else:
+ files[arg] = module
+ deps[module] = set()
+
+# Iterate again, and build list of direct dependencies for each module
+# TODO: implement support for multiple include directories
+for arg in sorted(files.keys()):
+ module = files[arg]
+ with open(arg, 'r', encoding="utf8") as f:
+ for line in f:
+ match = RE.match(line)
+ if match:
+ include = match.group(1)
+ included_module = module_name(include)
+ if included_module is not None and included_module in deps and included_module != module:
+ deps[module].add(included_module)
+
+# Loop to find the shortest (remaining) circular dependency
+have_cycle = False
+while True:
+ shortest_cycle = None
+ for module in sorted(deps.keys()):
+ # Build the transitive closure of dependencies of module
+ closure = dict()
+ for dep in deps[module]:
+ closure[dep] = []
+ while True:
+ old_size = len(closure)
+ old_closure_keys = sorted(closure.keys())
+ for src in old_closure_keys:
+ for dep in deps[src]:
+ if dep not in closure:
+ closure[dep] = closure[src] + [src]
+ if len(closure) == old_size:
+ break
+ # If module is in its own transitive closure, it's a circular dependency; check if it is the shortest
+ if module in closure and (shortest_cycle is None or len(closure[module]) + 1 < len(shortest_cycle)):
+ shortest_cycle = [module] + closure[module]
+ if shortest_cycle is None:
+ break
+ # We have the shortest circular dependency; report it
+ module = shortest_cycle[0]
+ print("Circular dependency: %s" % (" -> ".join(shortest_cycle + [module])))
+ # And then break the dependency to avoid repeating in other cycles
+ deps[shortest_cycle[-1]] = deps[shortest_cycle[-1]] - set([module])
+ have_cycle = True
+
+sys.exit(1 if have_cycle else 0)
diff --git a/contrib/devtools/clang-format-diff.py b/contrib/devtools/clang-format-diff.py
new file mode 100755
index 0000000000..f322b3a880
--- /dev/null
+++ b/contrib/devtools/clang-format-diff.py
@@ -0,0 +1,166 @@
+#!/usr/bin/env python3
+#
+#===- clang-format-diff.py - ClangFormat Diff Reformatter ----*- python -*--===#
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License.
+#
+# ============================================================
+#
+# University of Illinois/NCSA
+# Open Source License
+#
+# Copyright (c) 2007-2015 University of Illinois at Urbana-Champaign.
+# All rights reserved.
+#
+# Developed by:
+#
+# LLVM Team
+#
+# University of Illinois at Urbana-Champaign
+#
+# http://llvm.org
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of
+# this software and associated documentation files (the "Software"), to deal with
+# the Software without restriction, including without limitation the rights to
+# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+# of the Software, and to permit persons to whom the Software is furnished to do
+# so, subject to the following conditions:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimers.
+#
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimers in the
+# documentation and/or other materials provided with the distribution.
+#
+# * Neither the names of the LLVM Team, University of Illinois at
+# Urbana-Champaign, nor the names of its contributors may be used to
+# endorse or promote products derived from this Software without specific
+# prior written permission.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
+# SOFTWARE.
+#
+# ============================================================
+#
+#===------------------------------------------------------------------------===#
+
+r"""
+ClangFormat Diff Reformatter
+============================
+
+This script reads input from a unified diff and reformats all the changed
+lines. This is useful to reformat all the lines touched by a specific patch.
+Example usage for git/svn users:
+
+ git diff -U0 HEAD^ | clang-format-diff.py -p1 -i
+ svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i
+
+"""
+
+import argparse
+import difflib
+import io
+import re
+import subprocess
+import sys
+
+
+# Change this to the full path if clang-format is not on the path.
+binary = 'clang-format'
+
+
+def main():
+ parser = argparse.ArgumentParser(description=
+ 'Reformat changed lines in diff. Without -i '
+ 'option just output the diff that would be '
+ 'introduced.')
+ parser.add_argument('-i', action='store_true', default=False,
+ help='apply edits to files instead of displaying a diff')
+ parser.add_argument('-p', metavar='NUM', default=0,
+ help='strip the smallest prefix containing P slashes')
+ parser.add_argument('-regex', metavar='PATTERN', default=None,
+ help='custom pattern selecting file paths to reformat '
+ '(case sensitive, overrides -iregex)')
+ parser.add_argument('-iregex', metavar='PATTERN', default=
+ r'.*\.(cpp|cc|c\+\+|cxx|c|cl|h|hpp|m|mm|inc|js|ts|proto'
+ r'|protodevel|java)',
+ help='custom pattern selecting file paths to reformat '
+ '(case insensitive, overridden by -regex)')
+ parser.add_argument('-sort-includes', action='store_true', default=False,
+ help='let clang-format sort include blocks')
+ parser.add_argument('-v', '--verbose', action='store_true',
+ help='be more verbose, ineffective without -i')
+ args = parser.parse_args()
+
+ # Extract changed lines for each file.
+ filename = None
+ lines_by_file = {}
+ for line in sys.stdin:
+ match = re.search('^\+\+\+\ (.*?/){%s}(\S*)' % args.p, line)
+ if match:
+ filename = match.group(2)
+ if filename is None:
+ continue
+
+ if args.regex is not None:
+ if not re.match('^%s$' % args.regex, filename):
+ continue
+ else:
+ if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE):
+ continue
+
+ match = re.search('^@@.*\+(\d+)(,(\d+))?', line)
+ if match:
+ start_line = int(match.group(1))
+ line_count = 1
+ if match.group(3):
+ line_count = int(match.group(3))
+ if line_count == 0:
+ continue
+ end_line = start_line + line_count - 1
+ lines_by_file.setdefault(filename, []).extend(
+ ['-lines', str(start_line) + ':' + str(end_line)])
+
+ # Reformat files containing changes in place.
+ for filename, lines in lines_by_file.items():
+ if args.i and args.verbose:
+ print('Formatting {}'.format(filename))
+ command = [binary, filename]
+ if args.i:
+ command.append('-i')
+ if args.sort_includes:
+ command.append('-sort-includes')
+ command.extend(lines)
+ command.extend(['-style=file', '-fallback-style=none'])
+ p = subprocess.Popen(command,
+ stdout=subprocess.PIPE,
+ stderr=None,
+ stdin=subprocess.PIPE,
+ universal_newlines=True)
+ stdout, stderr = p.communicate()
+ if p.returncode != 0:
+ sys.exit(p.returncode)
+
+ if not args.i:
+ with open(filename, encoding="utf8") as f:
+ code = f.readlines()
+ formatted_code = io.StringIO(stdout).readlines()
+ diff = difflib.unified_diff(code, formatted_code,
+ filename, filename,
+ '(before formatting)', '(after formatting)')
+ diff_string = ''.join(diff)
+ if len(diff_string) > 0:
+ sys.stdout.write(diff_string)
+
+if __name__ == '__main__':
+ main()
diff --git a/contrib/devtools/copyright_header.py b/contrib/devtools/copyright_header.py
new file mode 100755
index 0000000000..f3066e5516
--- /dev/null
+++ b/contrib/devtools/copyright_header.py
@@ -0,0 +1,600 @@
+#!/usr/bin/env python3
+# Copyright (c) 2016-2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+import re
+import fnmatch
+import sys
+import subprocess
+import datetime
+import os
+
+################################################################################
+# file filtering
+################################################################################
+
+EXCLUDE = [
+ # auto generated:
+ 'src/qt/defistrings.cpp',
+ 'src/chainparamsseeds.h',
+ # other external copyrights:
+ 'src/tinyformat.h',
+ 'test/functional/test_framework/bignum.py',
+ # python init:
+ '*__init__.py',
+]
+EXCLUDE_COMPILED = re.compile('|'.join([fnmatch.translate(m) for m in EXCLUDE]))
+
+EXCLUDE_DIRS = [
+ # git subtrees
+ "src/crypto/ctaes/",
+ "src/leveldb/",
+ "src/secp256k1/",
+ "src/univalue/",
+]
+
+INCLUDE = ['*.h', '*.cpp', '*.cc', '*.c', '*.mm', '*.py']
+INCLUDE_COMPILED = re.compile('|'.join([fnmatch.translate(m) for m in INCLUDE]))
+
+def applies_to_file(filename):
+ for excluded_dir in EXCLUDE_DIRS:
+ if filename.startswith(excluded_dir):
+ return False
+ return ((EXCLUDE_COMPILED.match(filename) is None) and
+ (INCLUDE_COMPILED.match(filename) is not None))
+
+################################################################################
+# obtain list of files in repo according to INCLUDE and EXCLUDE
+################################################################################
+
+GIT_LS_CMD = 'git ls-files --full-name'.split(' ')
+GIT_TOPLEVEL_CMD = 'git rev-parse --show-toplevel'.split(' ')
+
+def call_git_ls(base_directory):
+ out = subprocess.check_output([*GIT_LS_CMD, base_directory])
+ return [f for f in out.decode("utf-8").split('\n') if f != '']
+
+def call_git_toplevel():
+ "Returns the absolute path to the project root"
+ return subprocess.check_output(GIT_TOPLEVEL_CMD).strip().decode("utf-8")
+
+def get_filenames_to_examine(base_directory):
+ "Returns an array of absolute paths to any project files in the base_directory that pass the include/exclude filters"
+ root = call_git_toplevel()
+ filenames = call_git_ls(base_directory)
+ return sorted([os.path.join(root, filename) for filename in filenames if
+ applies_to_file(filename)])
+
+################################################################################
+# define and compile regexes for the patterns we are looking for
+################################################################################
+
+
+COPYRIGHT_WITH_C = 'Copyright \(c\)'
+COPYRIGHT_WITHOUT_C = 'Copyright'
+ANY_COPYRIGHT_STYLE = '(%s|%s)' % (COPYRIGHT_WITH_C, COPYRIGHT_WITHOUT_C)
+
+YEAR = "20[0-9][0-9]"
+YEAR_RANGE = '(%s)(-%s)?' % (YEAR, YEAR)
+YEAR_LIST = '(%s)(, %s)+' % (YEAR, YEAR)
+ANY_YEAR_STYLE = '(%s|%s)' % (YEAR_RANGE, YEAR_LIST)
+ANY_COPYRIGHT_STYLE_OR_YEAR_STYLE = ("%s %s" % (ANY_COPYRIGHT_STYLE,
+ ANY_YEAR_STYLE))
+
+ANY_COPYRIGHT_COMPILED = re.compile(ANY_COPYRIGHT_STYLE_OR_YEAR_STYLE)
+
+def compile_copyright_regex(copyright_style, year_style, name):
+ return re.compile('%s %s,? %s' % (copyright_style, year_style, name))
+
+EXPECTED_HOLDER_NAMES = [
+ "Satoshi Nakamoto\n",
+ "The Bitcoin Core developers\n",
+ "BitPay Inc\.\n",
+ "University of Illinois at Urbana-Champaign\.\n",
+ "Pieter Wuille\n",
+ "Wladimir J. van der Laan\n",
+ "Jeff Garzik\n",
+ "Jan-Klaas Kollhof\n",
+ "ArtForz -- public domain half-a-node\n",
+ "Intel Corporation",
+ "The Zcash developers",
+ "Jeremy Rubin",
+ "DeFi Blockchain Developers",
+]
+
+DOMINANT_STYLE_COMPILED = {}
+YEAR_LIST_STYLE_COMPILED = {}
+WITHOUT_C_STYLE_COMPILED = {}
+
+for holder_name in EXPECTED_HOLDER_NAMES:
+ DOMINANT_STYLE_COMPILED[holder_name] = (
+ compile_copyright_regex(COPYRIGHT_WITH_C, YEAR_RANGE, holder_name))
+ YEAR_LIST_STYLE_COMPILED[holder_name] = (
+ compile_copyright_regex(COPYRIGHT_WITH_C, YEAR_LIST, holder_name))
+ WITHOUT_C_STYLE_COMPILED[holder_name] = (
+ compile_copyright_regex(COPYRIGHT_WITHOUT_C, ANY_YEAR_STYLE,
+ holder_name))
+
+################################################################################
+# search file contents for copyright message of particular category
+################################################################################
+
+def get_count_of_copyrights_of_any_style_any_holder(contents):
+ return len(ANY_COPYRIGHT_COMPILED.findall(contents))
+
+def file_has_dominant_style_copyright_for_holder(contents, holder_name):
+ match = DOMINANT_STYLE_COMPILED[holder_name].search(contents)
+ return match is not None
+
+def file_has_year_list_style_copyright_for_holder(contents, holder_name):
+ match = YEAR_LIST_STYLE_COMPILED[holder_name].search(contents)
+ return match is not None
+
+def file_has_without_c_style_copyright_for_holder(contents, holder_name):
+ match = WITHOUT_C_STYLE_COMPILED[holder_name].search(contents)
+ return match is not None
+
+################################################################################
+# get file info
+################################################################################
+
+def read_file(filename):
+ return open(filename, 'r', encoding="utf8").read()
+
+def gather_file_info(filename):
+ info = {}
+ info['filename'] = filename
+ c = read_file(filename)
+ info['contents'] = c
+
+ info['all_copyrights'] = get_count_of_copyrights_of_any_style_any_holder(c)
+
+ info['classified_copyrights'] = 0
+ info['dominant_style'] = {}
+ info['year_list_style'] = {}
+ info['without_c_style'] = {}
+ for holder_name in EXPECTED_HOLDER_NAMES:
+ has_dominant_style = (
+ file_has_dominant_style_copyright_for_holder(c, holder_name))
+ has_year_list_style = (
+ file_has_year_list_style_copyright_for_holder(c, holder_name))
+ has_without_c_style = (
+ file_has_without_c_style_copyright_for_holder(c, holder_name))
+ info['dominant_style'][holder_name] = has_dominant_style
+ info['year_list_style'][holder_name] = has_year_list_style
+ info['without_c_style'][holder_name] = has_without_c_style
+ if has_dominant_style or has_year_list_style or has_without_c_style:
+ info['classified_copyrights'] = info['classified_copyrights'] + 1
+ return info
+
+################################################################################
+# report execution
+################################################################################
+
+SEPARATOR = '-'.join(['' for _ in range(80)])
+
+def print_filenames(filenames, verbose):
+ if not verbose:
+ return
+ for filename in filenames:
+ print("\t%s" % filename)
+
+def print_report(file_infos, verbose):
+ print(SEPARATOR)
+ examined = [i['filename'] for i in file_infos]
+ print("%d files examined according to INCLUDE and EXCLUDE fnmatch rules" %
+ len(examined))
+ print_filenames(examined, verbose)
+
+ print(SEPARATOR)
+ print('')
+ zero_copyrights = [i['filename'] for i in file_infos if
+ i['all_copyrights'] == 0]
+ print("%4d with zero copyrights" % len(zero_copyrights))
+ print_filenames(zero_copyrights, verbose)
+ one_copyright = [i['filename'] for i in file_infos if
+ i['all_copyrights'] == 1]
+ print("%4d with one copyright" % len(one_copyright))
+ print_filenames(one_copyright, verbose)
+ two_copyrights = [i['filename'] for i in file_infos if
+ i['all_copyrights'] == 2]
+ print("%4d with two copyrights" % len(two_copyrights))
+ print_filenames(two_copyrights, verbose)
+ three_copyrights = [i['filename'] for i in file_infos if
+ i['all_copyrights'] == 3]
+ print("%4d with three copyrights" % len(three_copyrights))
+ print_filenames(three_copyrights, verbose)
+ four_or_more_copyrights = [i['filename'] for i in file_infos if
+ i['all_copyrights'] >= 4]
+ print("%4d with four or more copyrights" % len(four_or_more_copyrights))
+ print_filenames(four_or_more_copyrights, verbose)
+ print('')
+ print(SEPARATOR)
+ print('Copyrights with dominant style:\ne.g. "Copyright (c)" and '
+ '"" or "-":\n')
+ for holder_name in EXPECTED_HOLDER_NAMES:
+ dominant_style = [i['filename'] for i in file_infos if
+ i['dominant_style'][holder_name]]
+ if len(dominant_style) > 0:
+ print("%4d with '%s'" % (len(dominant_style),
+ holder_name.replace('\n', '\\n')))
+ print_filenames(dominant_style, verbose)
+ print('')
+ print(SEPARATOR)
+ print('Copyrights with year list style:\ne.g. "Copyright (c)" and '
+ '", , ...":\n')
+ for holder_name in EXPECTED_HOLDER_NAMES:
+ year_list_style = [i['filename'] for i in file_infos if
+ i['year_list_style'][holder_name]]
+ if len(year_list_style) > 0:
+ print("%4d with '%s'" % (len(year_list_style),
+ holder_name.replace('\n', '\\n')))
+ print_filenames(year_list_style, verbose)
+ print('')
+ print(SEPARATOR)
+ print('Copyrights with no "(c)" style:\ne.g. "Copyright" and "" or '
+ '"-":\n')
+ for holder_name in EXPECTED_HOLDER_NAMES:
+ without_c_style = [i['filename'] for i in file_infos if
+ i['without_c_style'][holder_name]]
+ if len(without_c_style) > 0:
+ print("%4d with '%s'" % (len(without_c_style),
+ holder_name.replace('\n', '\\n')))
+ print_filenames(without_c_style, verbose)
+
+ print('')
+ print(SEPARATOR)
+
+ unclassified_copyrights = [i['filename'] for i in file_infos if
+ i['classified_copyrights'] < i['all_copyrights']]
+ print("%d with unexpected copyright holder names" %
+ len(unclassified_copyrights))
+ print_filenames(unclassified_copyrights, verbose)
+ print(SEPARATOR)
+
+def exec_report(base_directory, verbose):
+ filenames = get_filenames_to_examine(base_directory)
+ file_infos = [gather_file_info(f) for f in filenames]
+ print_report(file_infos, verbose)
+
+################################################################################
+# report cmd
+################################################################################
+
+REPORT_USAGE = """
+Produces a report of all copyright header notices found inside the source files
+of a repository.
+
+Usage:
+ $ ./copyright_header.py report [verbose]
+
+Arguments:
+ - The base directory of a defi source code repository.
+ [verbose] - Includes a list of every file of each subcategory in the report.
+"""
+
+def report_cmd(argv):
+ if len(argv) == 2:
+ sys.exit(REPORT_USAGE)
+
+ base_directory = argv[2]
+ if not os.path.exists(base_directory):
+ sys.exit("*** bad : %s" % base_directory)
+
+ if len(argv) == 3:
+ verbose = False
+ elif argv[3] == 'verbose':
+ verbose = True
+ else:
+ sys.exit("*** unknown argument: %s" % argv[2])
+
+ exec_report(base_directory, verbose)
+
+################################################################################
+# query git for year of last change
+################################################################################
+
+GIT_LOG_CMD = "git log --pretty=format:%%ai %s"
+
+def call_git_log(filename):
+ out = subprocess.check_output((GIT_LOG_CMD % filename).split(' '))
+ return out.decode("utf-8").split('\n')
+
+def get_git_change_years(filename):
+ git_log_lines = call_git_log(filename)
+ if len(git_log_lines) == 0:
+ return [datetime.date.today().year]
+ # timestamp is in ISO 8601 format. e.g. "2016-09-05 14:25:32 -0600"
+ return [line.split(' ')[0].split('-')[0] for line in git_log_lines]
+
+def get_most_recent_git_change_year(filename):
+ return max(get_git_change_years(filename))
+
+################################################################################
+# read and write to file
+################################################################################
+
+def read_file_lines(filename):
+ f = open(filename, 'r', encoding="utf8")
+ file_lines = f.readlines()
+ f.close()
+ return file_lines
+
+def write_file_lines(filename, file_lines):
+ f = open(filename, 'w', encoding="utf8")
+ f.write(''.join(file_lines))
+ f.close()
+
+################################################################################
+# update header years execution
+################################################################################
+
+COPYRIGHT = 'Copyright \(c\)'
+YEAR = "20[0-9][0-9]"
+YEAR_RANGE = '(%s)(-%s)?' % (YEAR, YEAR)
+HOLDER = 'The Bitcoin Core developers'
+UPDATEABLE_LINE_COMPILED = re.compile(' '.join([COPYRIGHT, YEAR_RANGE, HOLDER]))
+
+def get_updatable_copyright_line(file_lines):
+ index = 0
+ for line in file_lines:
+ if UPDATEABLE_LINE_COMPILED.search(line) is not None:
+ return index, line
+ index = index + 1
+ return None, None
+
+def parse_year_range(year_range):
+ year_split = year_range.split('-')
+ start_year = year_split[0]
+ if len(year_split) == 1:
+ return start_year, start_year
+ return start_year, year_split[1]
+
+def year_range_to_str(start_year, end_year):
+ if start_year == end_year:
+ return start_year
+ return "%s-%s" % (start_year, end_year)
+
+def create_updated_copyright_line(line, last_git_change_year):
+ copyright_splitter = 'Copyright (c) '
+ copyright_split = line.split(copyright_splitter)
+ # Preserve characters on line that are ahead of the start of the copyright
+ # notice - they are part of the comment block and vary from file-to-file.
+ before_copyright = copyright_split[0]
+ after_copyright = copyright_split[1]
+
+ space_split = after_copyright.split(' ')
+ year_range = space_split[0]
+ start_year, end_year = parse_year_range(year_range)
+ if end_year == last_git_change_year:
+ return line
+ return (before_copyright + copyright_splitter +
+ year_range_to_str(start_year, last_git_change_year) + ' ' +
+ ' '.join(space_split[1:]))
+
+def update_updatable_copyright(filename):
+ file_lines = read_file_lines(filename)
+ index, line = get_updatable_copyright_line(file_lines)
+ if not line:
+ print_file_action_message(filename, "No updatable copyright.")
+ return
+ last_git_change_year = get_most_recent_git_change_year(filename)
+ new_line = create_updated_copyright_line(line, last_git_change_year)
+ if line == new_line:
+ print_file_action_message(filename, "Copyright up-to-date.")
+ return
+ file_lines[index] = new_line
+ write_file_lines(filename, file_lines)
+ print_file_action_message(filename,
+ "Copyright updated! -> %s" % last_git_change_year)
+
+def exec_update_header_year(base_directory):
+ for filename in get_filenames_to_examine(base_directory):
+ update_updatable_copyright(filename)
+
+################################################################################
+# update cmd
+################################################################################
+
+UPDATE_USAGE = """
+Updates all the copyright headers of "The Bitcoin Core developers" which were
+changed in a year more recent than is listed. For example:
+
+// Copyright (c) - The Bitcoin Core developers
+
+will be updated to:
+
+// Copyright (c) - The Bitcoin Core developers
+
+where is obtained from the 'git log' history.
+
+This subcommand also handles copyright headers that have only a single year. In those cases:
+
+// Copyright (c) The Bitcoin Core developers
+
+will be updated to:
+
+// Copyright (c) - The Bitcoin Core developers
+
+where the update is appropriate.
+
+Usage:
+ $ ./copyright_header.py update
+
+Arguments:
+ - The base directory of a defi source code repository.
+"""
+
+def print_file_action_message(filename, action):
+ print("%-52s %s" % (filename, action))
+
+def update_cmd(argv):
+ if len(argv) != 3:
+ sys.exit(UPDATE_USAGE)
+
+ base_directory = argv[2]
+ if not os.path.exists(base_directory):
+ sys.exit("*** bad base_directory: %s" % base_directory)
+ exec_update_header_year(base_directory)
+
+################################################################################
+# inserted copyright header format
+################################################################################
+
+def get_header_lines(header, start_year, end_year):
+ lines = header.split('\n')[1:-1]
+ lines[0] = lines[0] % year_range_to_str(start_year, end_year)
+ return [line + '\n' for line in lines]
+
+CPP_HEADER = '''
+// Copyright (c) %s The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+'''
+
+def get_cpp_header_lines_to_insert(start_year, end_year):
+ return reversed(get_header_lines(CPP_HEADER, start_year, end_year))
+
+PYTHON_HEADER = '''
+# Copyright (c) %s The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+'''
+
+def get_python_header_lines_to_insert(start_year, end_year):
+ return reversed(get_header_lines(PYTHON_HEADER, start_year, end_year))
+
+################################################################################
+# query git for year of last change
+################################################################################
+
+def get_git_change_year_range(filename):
+ years = get_git_change_years(filename)
+ return min(years), max(years)
+
+################################################################################
+# check for existing core copyright
+################################################################################
+
+def file_already_has_core_copyright(file_lines):
+ index, _ = get_updatable_copyright_line(file_lines)
+ return index is not None
+
+################################################################################
+# insert header execution
+################################################################################
+
+def file_has_hashbang(file_lines):
+ if len(file_lines) < 1:
+ return False
+ if len(file_lines[0]) <= 2:
+ return False
+ return file_lines[0][:2] == '#!'
+
+def insert_python_header(filename, file_lines, start_year, end_year):
+ if file_has_hashbang(file_lines):
+ insert_idx = 1
+ else:
+ insert_idx = 0
+ header_lines = get_python_header_lines_to_insert(start_year, end_year)
+ for line in header_lines:
+ file_lines.insert(insert_idx, line)
+ write_file_lines(filename, file_lines)
+
+def insert_cpp_header(filename, file_lines, start_year, end_year):
+ header_lines = get_cpp_header_lines_to_insert(start_year, end_year)
+ for line in header_lines:
+ file_lines.insert(0, line)
+ write_file_lines(filename, file_lines)
+
+def exec_insert_header(filename, style):
+ file_lines = read_file_lines(filename)
+ if file_already_has_core_copyright(file_lines):
+ sys.exit('*** %s already has a copyright by The Bitcoin Core developers'
+ % (filename))
+ start_year, end_year = get_git_change_year_range(filename)
+ if style == 'python':
+ insert_python_header(filename, file_lines, start_year, end_year)
+ else:
+ insert_cpp_header(filename, file_lines, start_year, end_year)
+
+################################################################################
+# insert cmd
+################################################################################
+
+INSERT_USAGE = """
+Inserts a copyright header for "The Bitcoin Core developers" at the top of the
+file in either Python or C++ style as determined by the file extension. If the
+file is a Python file and it has a '#!' starting the first line, the header is
+inserted in the line below it.
+
+The copyright dates will be set to be:
+
+"-"
+
+where is according to the 'git log' history. If
+ is equal to , the date will be set to be:
+
+""
+
+If the file already has a copyright for "The Bitcoin Core developers", the
+script will exit.
+
+Usage:
+ $ ./copyright_header.py insert
+
+Arguments:
+ - A source file in the DeFi Blockchain repository.
+"""
+
+def insert_cmd(argv):
+ if len(argv) != 3:
+ sys.exit(INSERT_USAGE)
+
+ filename = argv[2]
+ if not os.path.isfile(filename):
+ sys.exit("*** bad filename: %s" % filename)
+ _, extension = os.path.splitext(filename)
+ if extension not in ['.h', '.cpp', '.cc', '.c', '.py']:
+ sys.exit("*** cannot insert for file extension %s" % extension)
+
+ if extension == '.py':
+ style = 'python'
+ else:
+ style = 'cpp'
+ exec_insert_header(filename, style)
+
+################################################################################
+# UI
+################################################################################
+
+USAGE = """
+copyright_header.py - utilities for managing copyright headers of 'The Bitcoin
+Core developers' in repository source files.
+
+Usage:
+ $ ./copyright_header
+
+Subcommands:
+ report
+ update
+ insert
+
+To see subcommand usage, run them without arguments.
+"""
+
+SUBCOMMANDS = ['report', 'update', 'insert']
+
+if __name__ == "__main__":
+ if len(sys.argv) == 1:
+ sys.exit(USAGE)
+ subcommand = sys.argv[1]
+ if subcommand not in SUBCOMMANDS:
+ sys.exit(USAGE)
+ if subcommand == 'report':
+ report_cmd(sys.argv)
+ elif subcommand == 'update':
+ update_cmd(sys.argv)
+ elif subcommand == 'insert':
+ insert_cmd(sys.argv)
diff --git a/contrib/devtools/gen-manpages.sh b/contrib/devtools/gen-manpages.sh
new file mode 100755
index 0000000000..79a9ebbbb4
--- /dev/null
+++ b/contrib/devtools/gen-manpages.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+export LC_ALL=C
+TOPDIR=${TOPDIR:-$(git rev-parse --show-toplevel)}
+BUILDDIR=${BUILDDIR:-$TOPDIR}
+
+BINDIR=${BINDIR:-$BUILDDIR/src}
+MANDIR=${MANDIR:-$TOPDIR/doc/man}
+
+DEFID=${DEFID:-$BINDIR/defid}
+DEFICLI=${DEFICLI:-$BINDIR/defi-cli}
+DEFITX=${DEFITX:-$BINDIR/defi-tx}
+WALLET_TOOL=${WALLET_TOOL:-$BINDIR/defi-wallet}
+DEFIQT=${DEFIQT:-$BINDIR/qt/defi-qt}
+
+[ ! -x $DEFID ] && echo "$DEFID not found or not executable." && exit 1
+
+# The autodetected version git tag can screw up manpage output a little bit
+read -r -a BTCVER <<< "$($DEFICLI --version | head -n1 | awk -F'[ -]' '{ print $6, $7 }')"
+
+# Create a footer file with copyright content.
+# This gets autodetected fine for defid if --version-string is not set,
+# but has different outcomes for defi-qt and defi-cli.
+echo "[COPYRIGHT]" > footer.h2m
+$DEFID --version | sed -n '1!p' >> footer.h2m
+
+for cmd in $DEFID $DEFICLI $DEFITX $WALLET_TOOL $DEFIQT; do
+ cmdname="${cmd##*/}"
+ help2man -N --version-string=${BTCVER[0]} --include=footer.h2m -o ${MANDIR}/${cmdname}.1 ${cmd}
+ sed -i "s/\\\-${BTCVER[1]}//g" ${MANDIR}/${cmdname}.1
+done
+
+rm -f footer.h2m
diff --git a/contrib/devtools/optimize-pngs.py b/contrib/devtools/optimize-pngs.py
new file mode 100755
index 0000000000..e9481dbbcf
--- /dev/null
+++ b/contrib/devtools/optimize-pngs.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python3
+# Copyright (c) 2014-2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+'''
+Run this script every time you change one of the png files. Using pngcrush, it will optimize the png files, remove various color profiles, remove ancillary chunks (alla) and text chunks (text).
+#pngcrush -brute -ow -rem gAMA -rem cHRM -rem iCCP -rem sRGB -rem alla -rem text
+'''
+import os
+import sys
+import subprocess
+import hashlib
+from PIL import Image # pip3 install Pillow
+
+def file_hash(filename):
+ '''Return hash of raw file contents'''
+ with open(filename, 'rb') as f:
+ return hashlib.sha256(f.read()).hexdigest()
+
+def content_hash(filename):
+ '''Return hash of RGBA contents of image'''
+ i = Image.open(filename)
+ i = i.convert('RGBA')
+ data = i.tobytes()
+ return hashlib.sha256(data).hexdigest()
+
+pngcrush = 'pngcrush'
+git = 'git'
+folders = ["src/qt/res/movies", "src/qt/res/icons", "share/pixmaps"]
+basePath = subprocess.check_output([git, 'rev-parse', '--show-toplevel'], universal_newlines=True, encoding='utf8').rstrip('\n')
+totalSaveBytes = 0
+noHashChange = True
+
+outputArray = []
+for folder in folders:
+ absFolder=os.path.join(basePath, folder)
+ for file in os.listdir(absFolder):
+ extension = os.path.splitext(file)[1]
+ if extension.lower() == '.png':
+ print("optimizing {}...".format(file), end =' ')
+ file_path = os.path.join(absFolder, file)
+ fileMetaMap = {'file' : file, 'osize': os.path.getsize(file_path), 'sha256Old' : file_hash(file_path)}
+ fileMetaMap['contentHashPre'] = content_hash(file_path)
+
+ try:
+ subprocess.call([pngcrush, "-brute", "-ow", "-rem", "gAMA", "-rem", "cHRM", "-rem", "iCCP", "-rem", "sRGB", "-rem", "alla", "-rem", "text", file_path],
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+ except:
+ print("pngcrush is not installed, aborting...")
+ sys.exit(0)
+
+ #verify
+ if "Not a PNG file" in subprocess.check_output([pngcrush, "-n", "-v", file_path], stderr=subprocess.STDOUT, universal_newlines=True, encoding='utf8'):
+ print("PNG file "+file+" is corrupted after crushing, check out pngcursh version")
+ sys.exit(1)
+
+ fileMetaMap['sha256New'] = file_hash(file_path)
+ fileMetaMap['contentHashPost'] = content_hash(file_path)
+
+ if fileMetaMap['contentHashPre'] != fileMetaMap['contentHashPost']:
+ print("Image contents of PNG file {} before and after crushing don't match".format(file))
+ sys.exit(1)
+
+ fileMetaMap['psize'] = os.path.getsize(file_path)
+ outputArray.append(fileMetaMap)
+ print("done")
+
+print("summary:\n+++++++++++++++++")
+for fileDict in outputArray:
+ oldHash = fileDict['sha256Old']
+ newHash = fileDict['sha256New']
+ totalSaveBytes += fileDict['osize'] - fileDict['psize']
+ noHashChange = noHashChange and (oldHash == newHash)
+ print(fileDict['file']+"\n size diff from: "+str(fileDict['osize'])+" to: "+str(fileDict['psize'])+"\n old sha256: "+oldHash+"\n new sha256: "+newHash+"\n")
+
+print("completed. Checksum stable: "+str(noHashChange)+". Total reduction: "+str(totalSaveBytes)+" bytes")
diff --git a/contrib/devtools/security-check.py b/contrib/devtools/security-check.py
new file mode 100755
index 0000000000..44b7f6c7cc
--- /dev/null
+++ b/contrib/devtools/security-check.py
@@ -0,0 +1,215 @@
+#!/usr/bin/env python3
+# Copyright (c) 2015-2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+'''
+Perform basic ELF security checks on a series of executables.
+Exit status will be 0 if successful, and the program will be silent.
+Otherwise the exit status will be 1 and it will log which executables failed which checks.
+Needs `readelf` (for ELF) and `objdump` (for PE).
+'''
+import subprocess
+import sys
+import os
+
+READELF_CMD = os.getenv('READELF', '/usr/bin/readelf')
+OBJDUMP_CMD = os.getenv('OBJDUMP', '/usr/bin/objdump')
+NONFATAL = {} # checks which are non-fatal for now but only generate a warning
+
+def check_ELF_PIE(executable):
+ '''
+ Check for position independent executable (PIE), allowing for address space randomization.
+ '''
+ p = subprocess.Popen([READELF_CMD, '-h', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
+ (stdout, stderr) = p.communicate()
+ if p.returncode:
+ raise IOError('Error opening file')
+
+ ok = False
+ for line in stdout.splitlines():
+ line = line.split()
+ if len(line)>=2 and line[0] == 'Type:' and line[1] == 'DYN':
+ ok = True
+ return ok
+
+def get_ELF_program_headers(executable):
+ '''Return type and flags for ELF program headers'''
+ p = subprocess.Popen([READELF_CMD, '-l', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
+ (stdout, stderr) = p.communicate()
+ if p.returncode:
+ raise IOError('Error opening file')
+ in_headers = False
+ count = 0
+ headers = []
+ for line in stdout.splitlines():
+ if line.startswith('Program Headers:'):
+ in_headers = True
+ if line == '':
+ in_headers = False
+ if in_headers:
+ if count == 1: # header line
+ ofs_typ = line.find('Type')
+ ofs_offset = line.find('Offset')
+ ofs_flags = line.find('Flg')
+ ofs_align = line.find('Align')
+ if ofs_typ == -1 or ofs_offset == -1 or ofs_flags == -1 or ofs_align == -1:
+ raise ValueError('Cannot parse elfread -lW output')
+ elif count > 1:
+ typ = line[ofs_typ:ofs_offset].rstrip()
+ flags = line[ofs_flags:ofs_align].rstrip()
+ headers.append((typ, flags))
+ count += 1
+ return headers
+
+def check_ELF_NX(executable):
+ '''
+ Check that no sections are writable and executable (including the stack)
+ '''
+ have_wx = False
+ have_gnu_stack = False
+ for (typ, flags) in get_ELF_program_headers(executable):
+ if typ == 'GNU_STACK':
+ have_gnu_stack = True
+ if 'W' in flags and 'E' in flags: # section is both writable and executable
+ have_wx = True
+ return have_gnu_stack and not have_wx
+
+def check_ELF_RELRO(executable):
+ '''
+ Check for read-only relocations.
+ GNU_RELRO program header must exist
+ Dynamic section must have BIND_NOW flag
+ '''
+ have_gnu_relro = False
+ for (typ, flags) in get_ELF_program_headers(executable):
+ # Note: not checking flags == 'R': here as linkers set the permission differently
+ # This does not affect security: the permission flags of the GNU_RELRO program header are ignored, the PT_LOAD header determines the effective permissions.
+ # However, the dynamic linker need to write to this area so these are RW.
+ # Glibc itself takes care of mprotecting this area R after relocations are finished.
+ # See also https://marc.info/?l=binutils&m=1498883354122353
+ if typ == 'GNU_RELRO':
+ have_gnu_relro = True
+
+ have_bindnow = False
+ p = subprocess.Popen([READELF_CMD, '-d', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
+ (stdout, stderr) = p.communicate()
+ if p.returncode:
+ raise IOError('Error opening file')
+ for line in stdout.splitlines():
+ tokens = line.split()
+ if len(tokens)>1 and tokens[1] == '(BIND_NOW)' or (len(tokens)>2 and tokens[1] == '(FLAGS)' and 'BIND_NOW' in tokens[2:]):
+ have_bindnow = True
+ return have_gnu_relro and have_bindnow
+
+def check_ELF_Canary(executable):
+ '''
+ Check for use of stack canary
+ '''
+ p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
+ (stdout, stderr) = p.communicate()
+ if p.returncode:
+ raise IOError('Error opening file')
+ ok = False
+ for line in stdout.splitlines():
+ if '__stack_chk_fail' in line:
+ ok = True
+ return ok
+
+def get_PE_dll_characteristics(executable):
+ '''
+ Get PE DllCharacteristics bits.
+ Returns a tuple (arch,bits) where arch is 'i386:x86-64' or 'i386'
+ and bits is the DllCharacteristics value.
+ '''
+ p = subprocess.Popen([OBJDUMP_CMD, '-x', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
+ (stdout, stderr) = p.communicate()
+ if p.returncode:
+ raise IOError('Error opening file')
+ arch = ''
+ bits = 0
+ for line in stdout.splitlines():
+ tokens = line.split()
+ if len(tokens)>=2 and tokens[0] == 'architecture:':
+ arch = tokens[1].rstrip(',')
+ if len(tokens)>=2 and tokens[0] == 'DllCharacteristics':
+ bits = int(tokens[1],16)
+ return (arch,bits)
+
+IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA = 0x0020
+IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE = 0x0040
+IMAGE_DLL_CHARACTERISTICS_NX_COMPAT = 0x0100
+
+def check_PE_DYNAMIC_BASE(executable):
+ '''PIE: DllCharacteristics bit 0x40 signifies dynamicbase (ASLR)'''
+ (arch,bits) = get_PE_dll_characteristics(executable)
+ reqbits = IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE
+ return (bits & reqbits) == reqbits
+
+# On 64 bit, must support high-entropy 64-bit address space layout randomization in addition to DYNAMIC_BASE
+# to have secure ASLR.
+def check_PE_HIGH_ENTROPY_VA(executable):
+ '''PIE: DllCharacteristics bit 0x20 signifies high-entropy ASLR'''
+ (arch,bits) = get_PE_dll_characteristics(executable)
+ if arch == 'i386:x86-64':
+ reqbits = IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA
+ else: # Unnecessary on 32-bit
+ assert(arch == 'i386')
+ reqbits = 0
+ return (bits & reqbits) == reqbits
+
+def check_PE_NX(executable):
+ '''NX: DllCharacteristics bit 0x100 signifies nxcompat (DEP)'''
+ (arch,bits) = get_PE_dll_characteristics(executable)
+ return (bits & IMAGE_DLL_CHARACTERISTICS_NX_COMPAT) == IMAGE_DLL_CHARACTERISTICS_NX_COMPAT
+
+CHECKS = {
+'ELF': [
+ ('PIE', check_ELF_PIE),
+ ('NX', check_ELF_NX),
+ ('RELRO', check_ELF_RELRO),
+ ('Canary', check_ELF_Canary)
+],
+'PE': [
+ ('DYNAMIC_BASE', check_PE_DYNAMIC_BASE),
+ ('HIGH_ENTROPY_VA', check_PE_HIGH_ENTROPY_VA),
+ ('NX', check_PE_NX)
+]
+}
+
+def identify_executable(executable):
+ with open(filename, 'rb') as f:
+ magic = f.read(4)
+ if magic.startswith(b'MZ'):
+ return 'PE'
+ elif magic.startswith(b'\x7fELF'):
+ return 'ELF'
+ return None
+
+if __name__ == '__main__':
+ retval = 0
+ for filename in sys.argv[1:]:
+ try:
+ etype = identify_executable(filename)
+ if etype is None:
+ print('%s: unknown format' % filename)
+ retval = 1
+ continue
+
+ failed = []
+ warning = []
+ for (name, func) in CHECKS[etype]:
+ if not func(filename):
+ if name in NONFATAL:
+ warning.append(name)
+ else:
+ failed.append(name)
+ if failed:
+ print('%s: failed %s' % (filename, ' '.join(failed)))
+ retval = 1
+ if warning:
+ print('%s: warning %s' % (filename, ' '.join(warning)))
+ except IOError:
+ print('%s: cannot open' % filename)
+ retval = 1
+ sys.exit(retval)
+
diff --git a/contrib/devtools/split-debug.sh.in b/contrib/devtools/split-debug.sh.in
new file mode 100644
index 0000000000..92b72b1446
--- /dev/null
+++ b/contrib/devtools/split-debug.sh.in
@@ -0,0 +1,10 @@
+#!/bin/sh
+set -e
+if [ $# -ne 3 ];
+ then echo "usage: $0 "
+fi
+
+@OBJCOPY@ --enable-deterministic-archives -p --only-keep-debug $1 $3
+@OBJCOPY@ --enable-deterministic-archives -p --strip-debug $1 $2
+@STRIP@ --enable-deterministic-archives -p -s $2
+@OBJCOPY@ --enable-deterministic-archives -p --add-gnu-debuglink=$3 $2
diff --git a/contrib/devtools/symbol-check.py b/contrib/devtools/symbol-check.py
new file mode 100755
index 0000000000..76b47b7f4c
--- /dev/null
+++ b/contrib/devtools/symbol-check.py
@@ -0,0 +1,175 @@
+#!/usr/bin/env python3
+# Copyright (c) 2014 Wladimir J. van der Laan
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+'''
+A script to check that the (Linux) executables produced by gitian only contain
+allowed gcc, glibc and libstdc++ version symbols. This makes sure they are
+still compatible with the minimum supported Linux distribution versions.
+
+Example usage:
+
+ find ../gitian-builder/build -type f -executable | xargs python3 contrib/devtools/symbol-check.py
+'''
+import subprocess
+import re
+import sys
+import os
+
+# Debian 6.0.9 (Squeeze) has:
+#
+# - g++ version 4.4.5 (https://packages.debian.org/search?suite=default§ion=all&arch=any&searchon=names&keywords=g%2B%2B)
+# - libc version 2.11.3 (https://packages.debian.org/search?suite=default§ion=all&arch=any&searchon=names&keywords=libc6)
+# - libstdc++ version 4.4.5 (https://packages.debian.org/search?suite=default§ion=all&arch=any&searchon=names&keywords=libstdc%2B%2B6)
+#
+# Ubuntu 10.04.4 (Lucid Lynx) has:
+#
+# - g++ version 4.4.3 (http://packages.ubuntu.com/search?keywords=g%2B%2B&searchon=names&suite=lucid§ion=all)
+# - libc version 2.11.1 (http://packages.ubuntu.com/search?keywords=libc6&searchon=names&suite=lucid§ion=all)
+# - libstdc++ version 4.4.3 (http://packages.ubuntu.com/search?suite=lucid§ion=all&arch=any&keywords=libstdc%2B%2B&searchon=names)
+#
+# Taking the minimum of these as our target.
+#
+# According to GNU ABI document (http://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html) this corresponds to:
+# GCC 4.4.0: GCC_4.4.0
+# GCC 4.4.2: GLIBCXX_3.4.13, CXXABI_1.3.3
+# (glibc) GLIBC_2_11
+#
+MAX_VERSIONS = {
+'GCC': (4,4,0),
+'CXXABI': (1,3,3),
+'GLIBCXX': (3,4,13),
+'GLIBC': (2,11),
+'LIBATOMIC': (1,0)
+}
+# See here for a description of _IO_stdin_used:
+# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=634261#109
+
+# Ignore symbols that are exported as part of every executable
+IGNORE_EXPORTS = {
+'_edata', '_end', '__end__', '_init', '__bss_start', '__bss_start__', '_bss_end__', '__bss_end__', '_fini', '_IO_stdin_used', 'stdin', 'stdout', 'stderr'
+}
+READELF_CMD = os.getenv('READELF', '/usr/bin/readelf')
+CPPFILT_CMD = os.getenv('CPPFILT', '/usr/bin/c++filt')
+# Allowed NEEDED libraries
+ALLOWED_LIBRARIES = {
+# defid and defi-qt
+'libgcc_s.so.1', # GCC base support
+'libc.so.6', # C library
+'libpthread.so.0', # threading
+'libanl.so.1', # DNS resolve
+'libm.so.6', # math library
+'librt.so.1', # real-time (clock)
+'libatomic.so.1',
+'ld-linux-x86-64.so.2', # 64-bit dynamic linker
+'ld-linux.so.2', # 32-bit dynamic linker
+'ld-linux-aarch64.so.1', # 64-bit ARM dynamic linker
+'ld-linux-armhf.so.3', # 32-bit ARM dynamic linker
+'ld-linux-riscv64-lp64d.so.1', # 64-bit RISC-V dynamic linker
+# defi-qt only
+'libxcb.so.1', # part of X11
+'libfontconfig.so.1', # font support
+'libfreetype.so.6', # font parsing
+'libdl.so.2' # programming interface to dynamic linker
+}
+ARCH_MIN_GLIBC_VER = {
+'80386': (2,1),
+'X86-64': (2,2,5),
+'ARM': (2,4),
+'AArch64':(2,17),
+'RISC-V': (2,27)
+}
+class CPPFilt(object):
+ '''
+ Demangle C++ symbol names.
+
+ Use a pipe to the 'c++filt' command.
+ '''
+ def __init__(self):
+ self.proc = subprocess.Popen(CPPFILT_CMD, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True)
+
+ def __call__(self, mangled):
+ self.proc.stdin.write(mangled + '\n')
+ self.proc.stdin.flush()
+ return self.proc.stdout.readline().rstrip()
+
+ def close(self):
+ self.proc.stdin.close()
+ self.proc.stdout.close()
+ self.proc.wait()
+
+def read_symbols(executable, imports=True):
+ '''
+ Parse an ELF executable and return a list of (symbol,version) tuples
+ for dynamic, imported symbols.
+ '''
+ p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', '-h', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
+ (stdout, stderr) = p.communicate()
+ if p.returncode:
+ raise IOError('Could not read symbols for %s: %s' % (executable, stderr.strip()))
+ syms = []
+ for line in stdout.splitlines():
+ line = line.split()
+ if 'Machine:' in line:
+ arch = line[-1]
+ if len(line)>7 and re.match('[0-9]+:$', line[0]):
+ (sym, _, version) = line[7].partition('@')
+ is_import = line[6] == 'UND'
+ if version.startswith('@'):
+ version = version[1:]
+ if is_import == imports:
+ syms.append((sym, version, arch))
+ return syms
+
+def check_version(max_versions, version, arch):
+ if '_' in version:
+ (lib, _, ver) = version.rpartition('_')
+ else:
+ lib = version
+ ver = '0'
+ ver = tuple([int(x) for x in ver.split('.')])
+ if not lib in max_versions:
+ return False
+ return ver <= max_versions[lib] or lib == 'GLIBC' and ver <= ARCH_MIN_GLIBC_VER[arch]
+
+def read_libraries(filename):
+ p = subprocess.Popen([READELF_CMD, '-d', '-W', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
+ (stdout, stderr) = p.communicate()
+ if p.returncode:
+ raise IOError('Error opening file')
+ libraries = []
+ for line in stdout.splitlines():
+ tokens = line.split()
+ if len(tokens)>2 and tokens[1] == '(NEEDED)':
+ match = re.match('^Shared library: \[(.*)\]$', ' '.join(tokens[2:]))
+ if match:
+ libraries.append(match.group(1))
+ else:
+ raise ValueError('Unparseable (NEEDED) specification')
+ return libraries
+
+if __name__ == '__main__':
+ cppfilt = CPPFilt()
+ retval = 0
+ for filename in sys.argv[1:]:
+ # Check imported symbols
+ for sym,version,arch in read_symbols(filename, True):
+ if version and not check_version(MAX_VERSIONS, version, arch):
+ print('%s: symbol %s from unsupported version %s' % (filename, cppfilt(sym), version))
+ retval = 1
+ # Check exported symbols
+ if arch != 'RISC-V':
+ for sym,version,arch in read_symbols(filename, False):
+ if sym in IGNORE_EXPORTS:
+ continue
+ print('%s: export of symbol %s not allowed' % (filename, cppfilt(sym)))
+ retval = 1
+ # Check dependency libraries
+ for library_name in read_libraries(filename):
+ if library_name not in ALLOWED_LIBRARIES:
+ print('%s: NEEDED library %s is not allowed' % (filename, library_name))
+ retval = 1
+
+ sys.exit(retval)
+
+
diff --git a/contrib/devtools/test-security-check.py b/contrib/devtools/test-security-check.py
new file mode 100755
index 0000000000..bb864bfc0c
--- /dev/null
+++ b/contrib/devtools/test-security-check.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+# Copyright (c) 2015-2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+'''
+Test script for security-check.py
+'''
+import subprocess
+import unittest
+
+def write_testcode(filename):
+ with open(filename, 'w', encoding="utf8") as f:
+ f.write('''
+ #include
+ int main()
+ {
+ printf("the quick brown fox jumps over the lazy god\\n");
+ return 0;
+ }
+ ''')
+
+def call_security_check(cc, source, executable, options):
+ subprocess.check_call([cc,source,'-o',executable] + options)
+ p = subprocess.Popen(['./security-check.py',executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
+ (stdout, stderr) = p.communicate()
+ return (p.returncode, stdout.rstrip())
+
+class TestSecurityChecks(unittest.TestCase):
+ def test_ELF(self):
+ source = 'test1.c'
+ executable = 'test1'
+ cc = 'gcc'
+ write_testcode(source)
+
+ self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-zexecstack','-fno-stack-protector','-Wl,-znorelro','-no-pie','-fno-PIE']),
+ (1, executable+': failed PIE NX RELRO Canary'))
+ self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-znoexecstack','-fno-stack-protector','-Wl,-znorelro','-no-pie','-fno-PIE']),
+ (1, executable+': failed PIE RELRO Canary'))
+ self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-znoexecstack','-fstack-protector-all','-Wl,-znorelro','-no-pie','-fno-PIE']),
+ (1, executable+': failed PIE RELRO'))
+ self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-znoexecstack','-fstack-protector-all','-Wl,-znorelro','-pie','-fPIE']),
+ (1, executable+': failed RELRO'))
+ self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-znoexecstack','-fstack-protector-all','-Wl,-zrelro','-Wl,-z,now','-pie','-fPIE']),
+ (0, ''))
+
+ def test_64bit_PE(self):
+ source = 'test1.c'
+ executable = 'test1.exe'
+ cc = 'x86_64-w64-mingw32-gcc'
+ write_testcode(source)
+
+ self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--no-nxcompat','-Wl,--no-dynamicbase','-Wl,--no-high-entropy-va']), (1, executable+': failed DYNAMIC_BASE HIGH_ENTROPY_VA NX'))
+ self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--no-dynamicbase','-Wl,--no-high-entropy-va']), (1, executable+': failed DYNAMIC_BASE HIGH_ENTROPY_VA'))
+ self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--dynamicbase','-Wl,--no-high-entropy-va']), (1, executable+': failed HIGH_ENTROPY_VA'))
+ self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--dynamicbase','-Wl,--high-entropy-va']), (0, ''))
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/contrib/devtools/test_deterministic_coverage.sh b/contrib/devtools/test_deterministic_coverage.sh
new file mode 100755
index 0000000000..9e03111eb4
--- /dev/null
+++ b/contrib/devtools/test_deterministic_coverage.sh
@@ -0,0 +1,152 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#
+# Test for deterministic coverage across unit test runs.
+
+export LC_ALL=C
+
+# Use GCOV_EXECUTABLE="gcov" if compiling with gcc.
+# Use GCOV_EXECUTABLE="llvm-cov gcov" if compiling with clang.
+GCOV_EXECUTABLE="gcov"
+
+# Disable tests known to cause non-deterministic behaviour and document the source or point of non-determinism.
+NON_DETERMINISTIC_TESTS=(
+ "blockfilter_index_tests/blockfilter_index_initial_sync" # src/checkqueue.h: In CCheckQueue::Loop(): while (queue.empty()) { ... }
+ "coinselector_tests/knapsack_solver_test" # coinselector_tests.cpp: if (equal_sets(setCoinsRet, setCoinsRet2))
+ "denialofservice_tests/DoS_mapOrphans" # denialofservice_tests.cpp: it = mapOrphanTransactions.lower_bound(InsecureRand256());
+ "fs_tests/fsbridge_fstream" # deterministic test failure?
+ "miner_tests/CreateNewBlock_validity" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
+ "scheduler_tests/manythreads" # scheduler.cpp: CScheduler::serviceQueue()
+ "scheduler_tests/singlethreadedscheduler_ordered" # scheduler.cpp: CScheduler::serviceQueue()
+ "tx_validationcache_tests/checkinputs_test" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
+ "tx_validationcache_tests/tx_mempool_block_doublespend" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
+ "txindex_tests/txindex_initial_sync" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
+ "txvalidation_tests/tx_mempool_reject_coinbase" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
+ "validation_block_tests/processnewblock_signals_ordering" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
+ "wallet_tests/coin_mark_dirty_immature_credit" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
+ "wallet_tests/dummy_input_size_test" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
+ "wallet_tests/importmulti_rescan" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
+ "wallet_tests/importwallet_rescan" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
+ "wallet_tests/ListCoins" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
+ "wallet_tests/scan_for_wallet_transactions" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
+ "wallet_tests/wallet_disableprivkeys" # validation.cpp: if (GetMainSignals().CallbacksPending() > 10)
+)
+
+TEST_DEFI_BINARY="src/test/test_defi"
+
+print_usage() {
+ echo "Usage: $0 [custom test filter (default: all but known non-deterministic tests)] [number of test runs (default: 2)]"
+}
+
+N_TEST_RUNS=2
+BOOST_TEST_RUN_FILTERS=""
+if [[ $# != 0 ]]; then
+ if [[ $1 == "--help" ]]; then
+ print_usage
+ exit
+ fi
+ PARSED_ARGUMENTS=0
+ if [[ $1 =~ [a-z] ]]; then
+ BOOST_TEST_RUN_FILTERS=$1
+ PARSED_ARGUMENTS=$((PARSED_ARGUMENTS + 1))
+ shift
+ fi
+ if [[ $1 =~ ^[0-9]+$ ]]; then
+ N_TEST_RUNS=$1
+ PARSED_ARGUMENTS=$((PARSED_ARGUMENTS + 1))
+ shift
+ fi
+ if [[ ${PARSED_ARGUMENTS} == 0 || $# -gt 2 || ${N_TEST_RUNS} -lt 2 ]]; then
+ print_usage
+ exit
+ fi
+fi
+if [[ ${BOOST_TEST_RUN_FILTERS} == "" ]]; then
+ BOOST_TEST_RUN_FILTERS="$(IFS=":"; echo "!${NON_DETERMINISTIC_TESTS[*]}" | sed 's/:/:!/g')"
+else
+ echo "Using Boost test filter: ${BOOST_TEST_RUN_FILTERS}"
+ echo
+fi
+
+if ! command -v gcov > /dev/null; then
+ echo "Error: gcov not installed. Exiting."
+ exit 1
+fi
+
+if ! command -v gcovr > /dev/null; then
+ echo "Error: gcovr not installed. Exiting."
+ exit 1
+fi
+
+if [[ ! -e ${TEST_DEFI_BINARY} ]]; then
+ echo "Error: Executable ${TEST_DEFI_BINARY} not found. Run \"./configure --enable-lcov\" and compile."
+ exit 1
+fi
+
+get_file_suffix_count() {
+ find src/ -type f -name "*.$1" | wc -l
+}
+
+if [[ $(get_file_suffix_count gcno) == 0 ]]; then
+ echo "Error: Could not find any *.gcno files. The *.gcno files are generated by the compiler. Run \"./configure --enable-lcov\" and re-compile."
+ exit 1
+fi
+
+get_covr_filename() {
+ echo "gcovr.run-$1.txt"
+}
+
+TEST_RUN_ID=0
+while [[ ${TEST_RUN_ID} -lt ${N_TEST_RUNS} ]]; do
+ TEST_RUN_ID=$((TEST_RUN_ID + 1))
+ echo "[$(date +"%Y-%m-%d %H:%M:%S")] Measuring coverage, run #${TEST_RUN_ID} of ${N_TEST_RUNS}"
+ find src/ -type f -name "*.gcda" -exec rm {} \;
+ if [[ $(get_file_suffix_count gcda) != 0 ]]; then
+ echo "Error: Stale *.gcda files found. Exiting."
+ exit 1
+ fi
+ TEST_OUTPUT_TEMPFILE=$(mktemp)
+ if ! BOOST_TEST_RUN_FILTERS="${BOOST_TEST_RUN_FILTERS}" ${TEST_DEFI_BINARY} > "${TEST_OUTPUT_TEMPFILE}" 2>&1; then
+ cat "${TEST_OUTPUT_TEMPFILE}"
+ rm "${TEST_OUTPUT_TEMPFILE}"
+ exit 1
+ fi
+ rm "${TEST_OUTPUT_TEMPFILE}"
+ if [[ $(get_file_suffix_count gcda) == 0 ]]; then
+ echo "Error: Running the test suite did not create any *.gcda files. The gcda files are generated when the instrumented test programs are executed. Run \"./configure --enable-lcov\" and re-compile."
+ exit 1
+ fi
+ GCOVR_TEMPFILE=$(mktemp)
+ if ! gcovr --gcov-executable "${GCOV_EXECUTABLE}" -r src/ > "${GCOVR_TEMPFILE}"; then
+ echo "Error: gcovr failed. Output written to ${GCOVR_TEMPFILE}. Exiting."
+ exit 1
+ fi
+ GCOVR_FILENAME=$(get_covr_filename ${TEST_RUN_ID})
+ mv "${GCOVR_TEMPFILE}" "${GCOVR_FILENAME}"
+ if grep -E "^TOTAL *0 *0 " "${GCOVR_FILENAME}"; then
+ echo "Error: Spurious gcovr output. Make sure the correct GCOV_EXECUTABLE variable is set in $0 (\"gcov\" for gcc, \"llvm-cov gcov\" for clang)."
+ exit 1
+ fi
+ if [[ ${TEST_RUN_ID} != 1 ]]; then
+ COVERAGE_DIFF=$(diff -u "$(get_covr_filename 1)" "${GCOVR_FILENAME}")
+ if [[ ${COVERAGE_DIFF} != "" ]]; then
+ echo
+ echo "The line coverage is non-deterministic between runs. Exiting."
+ echo
+ echo "The test suite must be deterministic in the sense that the set of lines executed at least"
+ echo "once must be identical between runs. This is a necessary condition for meaningful"
+ echo "coverage measuring."
+ echo
+ echo "${COVERAGE_DIFF}"
+ exit 1
+ fi
+ rm "${GCOVR_FILENAME}"
+ fi
+done
+
+echo
+echo "Coverage test passed: Deterministic coverage across ${N_TEST_RUNS} runs."
+exit
diff --git a/contrib/dockerfiles/arm-linux-gnueabihf.dockerfile b/contrib/dockerfiles/arm-linux-gnueabihf.dockerfile
new file mode 100644
index 0000000000..2661e91b69
--- /dev/null
+++ b/contrib/dockerfiles/arm-linux-gnueabihf.dockerfile
@@ -0,0 +1,68 @@
+ARG TARGET=arm-linux-gnueabihf
+
+# -----------
+FROM ubuntu:18.04 as builder-base
+ARG TARGET
+LABEL org.defichain.name="defichain-builder-base"
+LABEL org.defichain.arch=${TARGET}
+
+RUN apt update && apt dist-upgrade -y
+
+# Setup Defichain build dependencies. Refer to depends/README.md and doc/build-unix.md
+# from the source root for info on the builder setup
+
+RUN apt install -y software-properties-common build-essential libtool autotools-dev automake \
+pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev \
+libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev \
+libminiupnpc-dev libzmq3-dev libqrencode-dev \
+curl cmake \
+g++-arm-linux-gnueabihf binutils-arm-linux-gnueabihf
+
+# For Berkeley DB - but we don't need as we do a depends build.
+# RUN apt install -y libdb-dev
+
+# -----------
+FROM builder-base as depends-builder
+ARG TARGET
+LABEL org.defichain.name="defichain-depends-builder"
+LABEL org.defichain.arch=${TARGET}
+
+WORKDIR /work/depends
+COPY ./depends .
+# XREF: #depends-make
+RUN make HOST=${TARGET} NO_QT=1
+
+# -----------
+FROM builder-base as builder
+ARG TARGET
+LABEL org.defichain.name="defichain-builder"
+LABEL org.defichain.arch=${TARGET}
+
+WORKDIR /work
+
+COPY --from=depends-builder /work/depends ./depends
+COPY . .
+
+RUN ./autogen.sh
+
+# XREF: #make-configure
+RUN ./configure --prefix=`pwd`/depends/${TARGET} \
+ --enable-glibc-back-compat \
+ --enable-reduce-exports \
+ --without-gui \
+ LDFLAGS="-static-libstdc++"
+
+RUN make
+RUN mkdir /app && make prefix=/ DESTDIR=/app install && cp /work/README.md /app/.
+
+# -----------
+### Actual image that contains defi binaries
+FROM arm32v7/ubuntu:18.04
+ARG TARGET
+LABEL org.defichain.name="defichain"
+LABEL org.defichain.arch=${TARGET}
+
+WORKDIR /app
+
+COPY --from=builder /app/. ./
+
diff --git a/contrib/dockerfiles/dockerhub/x86_64-pc-linux-gnu.dockerfile b/contrib/dockerfiles/dockerhub/x86_64-pc-linux-gnu.dockerfile
new file mode 100644
index 0000000000..7b7c27743c
--- /dev/null
+++ b/contrib/dockerfiles/dockerhub/x86_64-pc-linux-gnu.dockerfile
@@ -0,0 +1,19 @@
+FROM defichain-x86_64-pc-linux-gnu:dockerhub-latest as dh-build
+
+FROM debian:10-slim
+ENV PATH=/app/bin:$PATH
+WORKDIR /app
+
+COPY --from=dh-build /app/. ./
+
+RUN useradd --create-home defi && \
+ mkdir -p /data && \
+ chown defi:defi /data && \
+ ln -s /data /home/defi/.defi
+
+VOLUME ["/data"]
+
+USER defi:defi
+CMD [ "/app/bin/defid" ]
+
+EXPOSE 8555 8554 18555 18554 19555 19554
diff --git a/contrib/dockerfiles/x86_64-apple-darwin11.dockerfile b/contrib/dockerfiles/x86_64-apple-darwin11.dockerfile
new file mode 100644
index 0000000000..277cad83da
--- /dev/null
+++ b/contrib/dockerfiles/x86_64-apple-darwin11.dockerfile
@@ -0,0 +1,63 @@
+ARG TARGET=x86_64-apple-darwin11
+
+# -----------
+FROM ubuntu:18.04 as builder-base
+ARG TARGET
+LABEL org.defichain.name="defichain-builder-base"
+LABEL org.defichain.arch=${TARGET}
+
+RUN apt update && apt dist-upgrade -y
+
+# Setup Defichain build dependencies. Refer to depends/README.md and doc/build-unix.md
+# from the source root for info on the builder setup
+
+RUN apt install -y software-properties-common build-essential libtool autotools-dev automake \
+pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev \
+libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev \
+libminiupnpc-dev libzmq3-dev libqrencode-dev \
+curl cmake \
+python3-dev python3-pip libcap-dev libbz2-dev libz-dev fonts-tuffy librsvg2-bin libtiff-tools imagemagick
+
+# For Berkeley DB - but we don't need as we do a depends build.
+# RUN apt install -y libdb-dev
+
+# -----------
+FROM builder-base as depends-builder
+ARG TARGET
+LABEL org.defichain.name="defichain-depends-builder"
+LABEL org.defichain.arch=${TARGET}
+
+WORKDIR /work/depends
+COPY ./depends .
+# XREF: #depends-make
+RUN make HOST=${TARGET} NO_QT=1
+
+# -----------
+FROM builder-base as builder
+ARG TARGET
+LABEL org.defichain.name="defichain-builder"
+LABEL org.defichain.arch=${TARGET}
+
+WORKDIR /work
+
+COPY --from=depends-builder /work/depends ./depends
+COPY . .
+
+RUN ./autogen.sh
+
+# XREF: #make-configure
+RUN ./configure --prefix=`pwd`/depends/${TARGET} --without-gui
+
+RUN make
+RUN mkdir /app && make prefix=/ DESTDIR=/app install && cp /work/README.md /app/.
+
+# -----------
+### Actual image that contains defi binaries
+FROM ubuntu:18.04
+ARG TARGET
+LABEL org.defichain.name="defichain"
+LABEL org.defichain.arch=${TARGET}
+
+WORKDIR /app
+
+COPY --from=builder /app/. ./
diff --git a/contrib/dockerfiles/x86_64-pc-linux-gnu-dev.dockerfile b/contrib/dockerfiles/x86_64-pc-linux-gnu-dev.dockerfile
new file mode 100644
index 0000000000..96c47db783
--- /dev/null
+++ b/contrib/dockerfiles/x86_64-pc-linux-gnu-dev.dockerfile
@@ -0,0 +1,12 @@
+ARG TARGET=x86_64-pc-linux-gnu
+
+FROM defichain-builder-base-${TARGET}
+ARG TARGET
+LABEL org.defichain.name="defichain-dev"
+LABEL org.defichain.arch=${TARGET}
+
+WORKDIR /data
+COPY . .
+
+VOLUME [ "/data" ]
+CMD [ "bash", "-c", "./make.sh release" ]
\ No newline at end of file
diff --git a/contrib/dockerfiles/x86_64-pc-linux-gnu.dockerfile b/contrib/dockerfiles/x86_64-pc-linux-gnu.dockerfile
new file mode 100644
index 0000000000..73693c0c99
--- /dev/null
+++ b/contrib/dockerfiles/x86_64-pc-linux-gnu.dockerfile
@@ -0,0 +1,62 @@
+ARG TARGET=x86_64-pc-linux-gnu
+
+# -----------
+FROM ubuntu:18.04 as builder-base
+ARG TARGET
+LABEL org.defichain.name="defichain-builder-base"
+LABEL org.defichain.arch=${TARGET}
+
+RUN apt update && apt dist-upgrade -y
+
+# Setup Defichain build dependencies. Refer to depends/README.md and doc/build-unix.md
+# from the source root for info on the builder setup
+
+RUN apt install -y software-properties-common build-essential libtool autotools-dev automake \
+pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev \
+libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev \
+libminiupnpc-dev libzmq3-dev libqrencode-dev \
+curl cmake
+
+# For Berkeley DB - but we don't need as we do a depends build.
+# RUN apt install -y libdb-dev
+
+# -----------
+FROM builder-base as depends-builder
+ARG TARGET
+LABEL org.defichain.name="defichain-depends-builder"
+LABEL org.defichain.arch=${TARGET}
+
+WORKDIR /work/depends
+COPY ./depends .
+# XREF: #depends-make
+RUN make HOST=${TARGET} NO_QT=1
+
+# -----------
+FROM builder-base as builder
+ARG TARGET
+LABEL org.defichain.name="defichain-builder"
+LABEL org.defichain.arch=${TARGET}
+
+WORKDIR /work
+
+COPY --from=depends-builder /work/depends ./depends
+COPY . .
+
+RUN ./autogen.sh
+
+# XREF: #make-configure
+RUN ./configure --prefix=`pwd`/depends/${TARGET} --without-gui
+
+RUN make
+RUN mkdir /app && make prefix=/ DESTDIR=/app install && cp /work/README.md /app/.
+
+# -----------
+### Actual image that contains defi binaries
+FROM ubuntu:18.04
+ARG TARGET
+LABEL org.defichain.name="defichain"
+LABEL org.defichain.arch=${TARGET}
+
+WORKDIR /app
+
+COPY --from=builder /app/. ./
diff --git a/contrib/dockerfiles/x86_64-w64-mingw32.dockerfile b/contrib/dockerfiles/x86_64-w64-mingw32.dockerfile
new file mode 100644
index 0000000000..a5c9d6b0d5
--- /dev/null
+++ b/contrib/dockerfiles/x86_64-w64-mingw32.dockerfile
@@ -0,0 +1,66 @@
+ARG TARGET=x86_64-w64-mingw32
+
+# -----------
+FROM ubuntu:18.04 as builder-base
+ARG TARGET
+LABEL org.defichain.name="defichain-builder-base"
+LABEL org.defichain.arch=${TARGET}
+
+RUN apt update && apt dist-upgrade -y
+
+# Setup Defichain build dependencies. Refer to depends/README.md and doc/build-unix.md
+# from the source root for info on the builder setup
+
+RUN apt install -y software-properties-common build-essential libtool autotools-dev automake \
+pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev \
+libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev \
+libminiupnpc-dev libzmq3-dev libqrencode-dev \
+curl cmake \
+g++-mingw-w64-x86-64 mingw-w64-x86-64-dev nsis
+
+# Set the default mingw32 g++ compiler option to posix.
+RUN update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
+
+# For Berkeley DB - but we don't need as we do a depends build.
+# RUN apt install -y libdb-dev
+
+# -----------
+FROM builder-base as depends-builder
+ARG TARGET
+LABEL org.defichain.name="defichain-depends-builder"
+LABEL org.defichain.arch=${TARGET}
+
+WORKDIR /work/depends
+COPY ./depends .
+# XREF: #depends-make
+RUN make HOST=${TARGET} NO_QT=1
+
+# -----------
+FROM builder-base as builder
+ARG TARGET
+LABEL org.defichain.name="defichain-builder"
+LABEL org.defichain.arch=${TARGET}
+
+WORKDIR /work
+
+COPY --from=depends-builder /work/depends ./depends
+COPY . .
+
+RUN ./autogen.sh
+
+# XREF: #make-configure
+RUN CONFIG_SITE=`pwd`/depends/x86_64-w64-mingw32/share/config.site ./configure --prefix=/ --without-gui
+
+RUN make
+RUN mkdir /app && make prefix=/ DESTDIR=/app install && cp /work/README.md /app/.
+
+# -----------
+### Actual image that contains defi binaries
+FROM ubuntu:18.04
+ARG TARGET
+LABEL org.defichain.name="defichain"
+LABEL org.defichain.arch=${TARGET}
+
+WORKDIR /app
+
+COPY --from=builder /app/. ./
diff --git a/contrib/filter-lcov.py b/contrib/filter-lcov.py
new file mode 100755
index 0000000000..df1db76e92
--- /dev/null
+++ b/contrib/filter-lcov.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+
+import argparse
+
+parser = argparse.ArgumentParser(description='Remove the coverage data from a tracefile for all files matching the pattern.')
+parser.add_argument('--pattern', '-p', action='append', help='the pattern of files to remove', required=True)
+parser.add_argument('tracefile', help='the tracefile to remove the coverage data from')
+parser.add_argument('outfile', help='filename for the output to be written to')
+
+args = parser.parse_args()
+tracefile = args.tracefile
+pattern = args.pattern
+outfile = args.outfile
+
+in_remove = False
+with open(tracefile, 'r', encoding="utf8") as f:
+ with open(outfile, 'w', encoding="utf8") as wf:
+ for line in f:
+ for p in pattern:
+ if line.startswith("SF:") and p in line:
+ in_remove = True
+ if not in_remove:
+ wf.write(line)
+ if line == 'end_of_record\n':
+ in_remove = False
diff --git a/contrib/gitian-build.py b/contrib/gitian-build.py
new file mode 100755
index 0000000000..53f3d0aa4d
--- /dev/null
+++ b/contrib/gitian-build.py
@@ -0,0 +1,261 @@
+#!/usr/bin/env python3
+
+import argparse
+import os
+import subprocess
+import sys
+
+def setup():
+ global args, workdir
+ programs = ['ruby', 'git', 'make', 'wget', 'curl']
+ if args.kvm:
+ programs += ['apt-cacher-ng', 'python-vm-builder', 'qemu-kvm', 'qemu-utils']
+ elif args.docker and not os.path.isfile('/lib/systemd/system/docker.service'):
+ dockers = ['docker.io', 'docker-ce']
+ for i in dockers:
+ return_code = subprocess.call(['sudo', 'apt-get', 'install', '-qq', i])
+ if return_code == 0:
+ break
+ if return_code != 0:
+ print('Cannot find any way to install Docker.', file=sys.stderr)
+ sys.exit(1)
+ else:
+ programs += ['apt-cacher-ng', 'lxc', 'debootstrap']
+ subprocess.check_call(['sudo', 'apt-get', 'install', '-qq'] + programs)
+ if not os.path.isdir('gitian.sigs'):
+ subprocess.check_call(['git', 'clone', 'https://github.com/bitcoin-core/gitian.sigs.git'])
+ if not os.path.isdir('defi-detached-sigs'):
+ subprocess.check_call(['git', 'clone', 'https://github.com/bitcoin-core/bitcoin-detached-sigs.git'])
+ if not os.path.isdir('gitian-builder'):
+ subprocess.check_call(['git', 'clone', 'https://github.com/devrandom/gitian-builder.git'])
+ if not os.path.isdir('defi'):
+ subprocess.check_call(['git', 'clone', 'https://github.com/bitcoin/bitcoin.git'])
+ os.chdir('gitian-builder')
+ make_image_prog = ['bin/make-base-vm', '--suite', 'bionic', '--arch', 'amd64']
+ if args.docker:
+ make_image_prog += ['--docker']
+ elif not args.kvm:
+ make_image_prog += ['--lxc']
+ subprocess.check_call(make_image_prog)
+ os.chdir(workdir)
+ if args.is_bionic and not args.kvm and not args.docker:
+ subprocess.check_call(['sudo', 'sed', '-i', 's/lxcbr0/br0/', '/etc/default/lxc-net'])
+ print('Reboot is required')
+ sys.exit(0)
+
+def build():
+ global args, workdir
+
+ os.makedirs('defi-binaries/' + args.version, exist_ok=True)
+ print('\nBuilding Dependencies\n')
+ os.chdir('gitian-builder')
+ os.makedirs('inputs', exist_ok=True)
+
+ subprocess.check_call(['wget', '-N', '-P', 'inputs', 'https://downloads.sourceforge.net/project/osslsigncode/osslsigncode/osslsigncode-1.7.1.tar.gz'])
+ subprocess.check_call(['wget', '-N', '-P', 'inputs', 'https://bitcoincore.org/cfields/osslsigncode-Backports-to-1.7.1.patch'])
+ subprocess.check_call(["echo 'a8c4e9cafba922f89de0df1f2152e7be286aba73f78505169bc351a7938dd911 inputs/osslsigncode-Backports-to-1.7.1.patch' | sha256sum -c"], shell=True)
+ subprocess.check_call(["echo 'f9a8cdb38b9c309326764ebc937cba1523a3a751a7ab05df3ecc99d18ae466c9 inputs/osslsigncode-1.7.1.tar.gz' | sha256sum -c"], shell=True)
+ subprocess.check_call(['make', '-C', '../defi/depends', 'download', 'SOURCES_PATH=' + os.getcwd() + '/cache/common'])
+
+ if args.linux:
+ print('\nCompiling ' + args.version + ' Linux')
+ subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'defi='+args.commit, '--url', 'defi='+args.url, '../defi/contrib/gitian-descriptors/gitian-linux.yml'])
+ subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version+'-linux', '--destination', '../gitian.sigs/', '../defi/contrib/gitian-descriptors/gitian-linux.yml'])
+ subprocess.check_call('mv build/out/defi-*.tar.gz build/out/src/defi-*.tar.gz ../defi-binaries/'+args.version, shell=True)
+
+ if args.windows:
+ print('\nCompiling ' + args.version + ' Windows')
+ subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'defi='+args.commit, '--url', 'defi='+args.url, '../defi/contrib/gitian-descriptors/gitian-win.yml'])
+ subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version+'-win-unsigned', '--destination', '../gitian.sigs/', '../defi/contrib/gitian-descriptors/gitian-win.yml'])
+ subprocess.check_call('mv build/out/defi-*-win-unsigned.tar.gz inputs/', shell=True)
+ subprocess.check_call('mv build/out/defi-*.zip build/out/defi-*.exe build/out/src/defi-*.tar.gz ../defi-binaries/'+args.version, shell=True)
+
+ if args.macos:
+ print('\nCompiling ' + args.version + ' MacOS')
+ subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'defi='+args.commit, '--url', 'defi='+args.url, '../defi/contrib/gitian-descriptors/gitian-osx.yml'])
+ subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version+'-osx-unsigned', '--destination', '../gitian.sigs/', '../defi/contrib/gitian-descriptors/gitian-osx.yml'])
+ subprocess.check_call('mv build/out/defi-*-osx-unsigned.tar.gz inputs/', shell=True)
+ subprocess.check_call('mv build/out/defi-*.tar.gz build/out/defi-*.dmg build/out/src/defi-*.tar.gz ../defi-binaries/'+args.version, shell=True)
+
+ os.chdir(workdir)
+
+ if args.commit_files:
+ print('\nCommitting '+args.version+' Unsigned Sigs\n')
+ os.chdir('gitian.sigs')
+ subprocess.check_call(['git', 'add', args.version+'-linux/'+args.signer])
+ subprocess.check_call(['git', 'add', args.version+'-win-unsigned/'+args.signer])
+ subprocess.check_call(['git', 'add', args.version+'-osx-unsigned/'+args.signer])
+ subprocess.check_call(['git', 'commit', '-m', 'Add '+args.version+' unsigned sigs for '+args.signer])
+ os.chdir(workdir)
+
+def sign():
+ global args, workdir
+ os.chdir('gitian-builder')
+
+ if args.windows:
+ print('\nSigning ' + args.version + ' Windows')
+ subprocess.check_call('cp inputs/defi-' + args.version + '-win-unsigned.tar.gz inputs/defi-win-unsigned.tar.gz', shell=True)
+ subprocess.check_call(['bin/gbuild', '--skip-image', '--upgrade', '--commit', 'signature='+args.commit, '../defi/contrib/gitian-descriptors/gitian-win-signer.yml'])
+ subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version+'-win-signed', '--destination', '../gitian.sigs/', '../defi/contrib/gitian-descriptors/gitian-win-signer.yml'])
+ subprocess.check_call('mv build/out/defi-*win64-setup.exe ../defi-binaries/'+args.version, shell=True)
+
+ if args.macos:
+ print('\nSigning ' + args.version + ' MacOS')
+ subprocess.check_call('cp inputs/defi-' + args.version + '-osx-unsigned.tar.gz inputs/defi-osx-unsigned.tar.gz', shell=True)
+ subprocess.check_call(['bin/gbuild', '--skip-image', '--upgrade', '--commit', 'signature='+args.commit, '../defi/contrib/gitian-descriptors/gitian-osx-signer.yml'])
+ subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version+'-osx-signed', '--destination', '../gitian.sigs/', '../defi/contrib/gitian-descriptors/gitian-osx-signer.yml'])
+ subprocess.check_call('mv build/out/defi-osx-signed.dmg ../defi-binaries/'+args.version+'/defi-'+args.version+'-osx.dmg', shell=True)
+
+ os.chdir(workdir)
+
+ if args.commit_files:
+ print('\nCommitting '+args.version+' Signed Sigs\n')
+ os.chdir('gitian.sigs')
+ subprocess.check_call(['git', 'add', args.version+'-win-signed/'+args.signer])
+ subprocess.check_call(['git', 'add', args.version+'-osx-signed/'+args.signer])
+ subprocess.check_call(['git', 'commit', '-a', '-m', 'Add '+args.version+' signed binary sigs for '+args.signer])
+ os.chdir(workdir)
+
+def verify():
+ global args, workdir
+ rc = 0
+ os.chdir('gitian-builder')
+
+ print('\nVerifying v'+args.version+' Linux\n')
+ if subprocess.call(['bin/gverify', '-v', '-d', '../gitian.sigs/', '-r', args.version+'-linux', '../defi/contrib/gitian-descriptors/gitian-linux.yml']):
+ print('Verifying v'+args.version+' Linux FAILED\n')
+ rc = 1
+
+ print('\nVerifying v'+args.version+' Windows\n')
+ if subprocess.call(['bin/gverify', '-v', '-d', '../gitian.sigs/', '-r', args.version+'-win-unsigned', '../defi/contrib/gitian-descriptors/gitian-win.yml']):
+ print('Verifying v'+args.version+' Windows FAILED\n')
+ rc = 1
+
+ print('\nVerifying v'+args.version+' MacOS\n')
+ if subprocess.call(['bin/gverify', '-v', '-d', '../gitian.sigs/', '-r', args.version+'-osx-unsigned', '../defi/contrib/gitian-descriptors/gitian-osx.yml']):
+ print('Verifying v'+args.version+' MacOS FAILED\n')
+ rc = 1
+
+ print('\nVerifying v'+args.version+' Signed Windows\n')
+ if subprocess.call(['bin/gverify', '-v', '-d', '../gitian.sigs/', '-r', args.version+'-win-signed', '../defi/contrib/gitian-descriptors/gitian-win-signer.yml']):
+ print('Verifying v'+args.version+' Signed Windows FAILED\n')
+ rc = 1
+
+ print('\nVerifying v'+args.version+' Signed MacOS\n')
+ if subprocess.call(['bin/gverify', '-v', '-d', '../gitian.sigs/', '-r', args.version+'-osx-signed', '../defi/contrib/gitian-descriptors/gitian-osx-signer.yml']):
+ print('Verifying v'+args.version+' Signed MacOS FAILED\n')
+ rc = 1
+
+ os.chdir(workdir)
+ return rc
+
+def main():
+ global args, workdir
+
+ parser = argparse.ArgumentParser(description='Script for running full Gitian builds.')
+ parser.add_argument('-c', '--commit', action='store_true', dest='commit', help='Indicate that the version argument is for a commit or branch')
+ parser.add_argument('-p', '--pull', action='store_true', dest='pull', help='Indicate that the version argument is the number of a github repository pull request')
+ parser.add_argument('-u', '--url', dest='url', default='https://github.com/bitcoin/bitcoin', help='Specify the URL of the repository. Default is %(default)s')
+ parser.add_argument('-v', '--verify', action='store_true', dest='verify', help='Verify the Gitian build')
+ parser.add_argument('-b', '--build', action='store_true', dest='build', help='Do a Gitian build')
+ parser.add_argument('-s', '--sign', action='store_true', dest='sign', help='Make signed binaries for Windows and MacOS')
+ parser.add_argument('-B', '--buildsign', action='store_true', dest='buildsign', help='Build both signed and unsigned binaries')
+ parser.add_argument('-o', '--os', dest='os', default='lwm', help='Specify which Operating Systems the build is for. Default is %(default)s. l for Linux, w for Windows, m for MacOS')
+ parser.add_argument('-j', '--jobs', dest='jobs', default='2', help='Number of processes to use. Default %(default)s')
+ parser.add_argument('-m', '--memory', dest='memory', default='2000', help='Memory to allocate in MiB. Default %(default)s')
+ parser.add_argument('-k', '--kvm', action='store_true', dest='kvm', help='Use KVM instead of LXC')
+ parser.add_argument('-d', '--docker', action='store_true', dest='docker', help='Use Docker instead of LXC')
+ parser.add_argument('-S', '--setup', action='store_true', dest='setup', help='Set up the Gitian building environment. Only works on Debian-based systems (Ubuntu, Debian)')
+ parser.add_argument('-D', '--detach-sign', action='store_true', dest='detach_sign', help='Create the assert file for detached signing. Will not commit anything.')
+ parser.add_argument('-n', '--no-commit', action='store_false', dest='commit_files', help='Do not commit anything to git')
+ parser.add_argument('signer', nargs='?', help='GPG signer to sign each build assert file')
+ parser.add_argument('version', nargs='?', help='Version number, commit, or branch to build. If building a commit or branch, the -c option must be specified')
+
+ args = parser.parse_args()
+ workdir = os.getcwd()
+
+ args.is_bionic = b'bionic' in subprocess.check_output(['lsb_release', '-cs'])
+
+ if args.kvm and args.docker:
+ raise Exception('Error: cannot have both kvm and docker')
+
+ # Ensure no more than one environment variable for gitian-builder (USE_LXC, USE_VBOX, USE_DOCKER) is set as they
+ # can interfere (e.g., USE_LXC being set shadows USE_DOCKER; for details see gitian-builder/libexec/make-clean-vm).
+ os.environ['USE_LXC'] = ''
+ os.environ['USE_VBOX'] = ''
+ os.environ['USE_DOCKER'] = ''
+ if args.docker:
+ os.environ['USE_DOCKER'] = '1'
+ elif not args.kvm:
+ os.environ['USE_LXC'] = '1'
+ if 'GITIAN_HOST_IP' not in os.environ.keys():
+ os.environ['GITIAN_HOST_IP'] = '10.0.3.1'
+ if 'LXC_GUEST_IP' not in os.environ.keys():
+ os.environ['LXC_GUEST_IP'] = '10.0.3.5'
+
+ if args.setup:
+ setup()
+
+ if args.buildsign:
+ args.build = True
+ args.sign = True
+
+ if not args.build and not args.sign and not args.verify:
+ sys.exit(0)
+
+ args.linux = 'l' in args.os
+ args.windows = 'w' in args.os
+ args.macos = 'm' in args.os
+
+ # Disable for MacOS if no SDK found
+ if args.macos and not os.path.isfile('gitian-builder/inputs/MacOSX10.11.sdk.tar.gz'):
+ print('Cannot build for MacOS, SDK does not exist. Will build for other OSes')
+ args.macos = False
+
+ args.sign_prog = 'true' if args.detach_sign else 'gpg --detach-sign'
+
+ script_name = os.path.basename(sys.argv[0])
+ if not args.signer:
+ print(script_name+': Missing signer')
+ print('Try '+script_name+' --help for more information')
+ sys.exit(1)
+ if not args.version:
+ print(script_name+': Missing version')
+ print('Try '+script_name+' --help for more information')
+ sys.exit(1)
+
+ # Add leading 'v' for tags
+ if args.commit and args.pull:
+ raise Exception('Cannot have both commit and pull')
+ args.commit = ('' if args.commit else 'v') + args.version
+
+ os.chdir('defi')
+ if args.pull:
+ subprocess.check_call(['git', 'fetch', args.url, 'refs/pull/'+args.version+'/merge'])
+ os.chdir('../gitian-builder/inputs/defi')
+ subprocess.check_call(['git', 'fetch', args.url, 'refs/pull/'+args.version+'/merge'])
+ args.commit = subprocess.check_output(['git', 'show', '-s', '--format=%H', 'FETCH_HEAD'], universal_newlines=True, encoding='utf8').strip()
+ args.version = 'pull-' + args.version
+ print(args.commit)
+ subprocess.check_call(['git', 'fetch'])
+ subprocess.check_call(['git', 'checkout', args.commit])
+ os.chdir(workdir)
+
+ os.chdir('gitian-builder')
+ subprocess.check_call(['git', 'pull'])
+ os.chdir(workdir)
+
+ if args.build:
+ build()
+
+ if args.sign:
+ sign()
+
+ if args.verify:
+ os.chdir('gitian.sigs')
+ subprocess.check_call(['git', 'pull'])
+ os.chdir(workdir)
+ sys.exit(verify())
+
+if __name__ == '__main__':
+ main()
diff --git a/contrib/gitian-descriptors/gitian-linux.yml b/contrib/gitian-descriptors/gitian-linux.yml
new file mode 100644
index 0000000000..3a37bb1908
--- /dev/null
+++ b/contrib/gitian-descriptors/gitian-linux.yml
@@ -0,0 +1,191 @@
+---
+name: "defi-core-linux-0.19"
+enable_cache: true
+distro: "ubuntu"
+suites:
+- "bionic"
+architectures:
+- "amd64"
+packages:
+- "curl"
+- "g++-aarch64-linux-gnu"
+- "g++-8-aarch64-linux-gnu"
+- "gcc-8-aarch64-linux-gnu"
+- "binutils-aarch64-linux-gnu"
+- "g++-arm-linux-gnueabihf"
+- "g++-8-arm-linux-gnueabihf"
+- "gcc-8-arm-linux-gnueabihf"
+- "binutils-arm-linux-gnueabihf"
+- "g++-riscv64-linux-gnu"
+- "g++-8-riscv64-linux-gnu"
+- "gcc-8-riscv64-linux-gnu"
+- "binutils-riscv64-linux-gnu"
+- "g++-8-multilib"
+- "gcc-8-multilib"
+- "binutils-gold"
+- "git"
+- "pkg-config"
+- "autoconf"
+- "libtool"
+- "automake"
+- "faketime"
+- "bsdmainutils"
+- "ca-certificates"
+- "python3"
+remotes:
+- "url": "https://github.com/bitcoin/bitcoin.git"
+ "dir": "defi"
+files: []
+script: |
+ set -e -o pipefail
+
+ WRAP_DIR=$HOME/wrapped
+ HOSTS="i686-pc-linux-gnu x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu"
+ CONFIGFLAGS="--enable-glibc-back-compat --enable-reduce-exports --disable-bench --disable-gui-tests"
+ FAKETIME_HOST_PROGS="gcc g++"
+ FAKETIME_PROGS="date ar ranlib nm"
+ HOST_CFLAGS="-O2 -g"
+ HOST_CXXFLAGS="-O2 -g"
+ HOST_LDFLAGS=-static-libstdc++
+
+ export QT_RCC_TEST=1
+ export QT_RCC_SOURCE_DATE_OVERRIDE=1
+ export TZ="UTC"
+ export BUILD_DIR=`pwd`
+ mkdir -p ${WRAP_DIR}
+ if test -n "$GBUILD_CACHE_ENABLED"; then
+ export SOURCES_PATH=${GBUILD_COMMON_CACHE}
+ export BASE_CACHE=${GBUILD_PACKAGE_CACHE}
+ mkdir -p ${BASE_CACHE} ${SOURCES_PATH}
+ fi
+
+ function create_global_faketime_wrappers {
+ for prog in ${FAKETIME_PROGS}; do
+ echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${prog}
+ echo "REAL=\`which -a ${prog} | grep -v ${WRAP_DIR}/${prog} | head -1\`" >> ${WRAP_DIR}/${prog}
+ echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${prog}
+ echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${prog}
+ echo "\$REAL \$@" >> $WRAP_DIR/${prog}
+ chmod +x ${WRAP_DIR}/${prog}
+ done
+ }
+
+ function create_per-host_faketime_wrappers {
+ for i in $HOSTS; do
+ for prog in ${FAKETIME_HOST_PROGS}; do
+ if which ${i}-${prog}-8
+ then
+ echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}-${prog}
+ echo "REAL=\`which -a ${i}-${prog}-8 | grep -v ${WRAP_DIR}/${i}-${prog} | head -1\`" >> ${WRAP_DIR}/${i}-${prog}
+ echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${i}-${prog}
+ echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${i}-${prog}
+ echo "\$REAL \$@" >> $WRAP_DIR/${i}-${prog}
+ chmod +x ${WRAP_DIR}/${i}-${prog}
+ fi
+ done
+ done
+ }
+
+ # Faketime for depends so intermediate results are comparable
+ export PATH_orig=${PATH}
+ create_global_faketime_wrappers "2000-01-01 12:00:00"
+ create_per-host_faketime_wrappers "2000-01-01 12:00:00"
+ export PATH=${WRAP_DIR}:${PATH}
+
+ EXTRA_INCLUDES_BASE=$WRAP_DIR/extra_includes
+ mkdir -p $EXTRA_INCLUDES_BASE
+
+ # x86 needs /usr/include/i386-linux-gnu/asm pointed to /usr/include/x86_64-linux-gnu/asm,
+ # but we can't write there. Instead, create a link here and force it to be included in the
+ # search paths by wrapping gcc/g++.
+
+ mkdir -p $EXTRA_INCLUDES_BASE/i686-pc-linux-gnu
+ rm -f $WRAP_DIR/extra_includes/i686-pc-linux-gnu/asm
+ ln -s /usr/include/x86_64-linux-gnu/asm $EXTRA_INCLUDES_BASE/i686-pc-linux-gnu/asm
+
+ for prog in gcc g++; do
+ rm -f ${WRAP_DIR}/${prog}
+ cat << EOF > ${WRAP_DIR}/${prog}
+ #!/usr/bin/env bash
+ REAL="`which -a ${prog}-8 | grep -v ${WRAP_DIR}/${prog} | head -1`"
+ for var in "\$@"
+ do
+ if [ "\$var" = "-m32" ]; then
+ export C_INCLUDE_PATH="$EXTRA_INCLUDES_BASE/i686-pc-linux-gnu"
+ export CPLUS_INCLUDE_PATH="$EXTRA_INCLUDES_BASE/i686-pc-linux-gnu"
+ break
+ fi
+ done
+ \$REAL \$@
+ EOF
+ chmod +x ${WRAP_DIR}/${prog}
+ done
+
+ cd defi
+ BASEPREFIX=`pwd`/depends
+ # Build dependencies for each host
+ for i in $HOSTS; do
+ EXTRA_INCLUDES="$EXTRA_INCLUDES_BASE/$i"
+ if [ -d "$EXTRA_INCLUDES" ]; then
+ export HOST_ID_SALT="$EXTRA_INCLUDES"
+ fi
+ make ${MAKEOPTS} -C ${BASEPREFIX} HOST="${i}"
+ unset HOST_ID_SALT
+ done
+
+ # Faketime for binaries
+ export PATH=${PATH_orig}
+ create_global_faketime_wrappers "${REFERENCE_DATETIME}"
+ create_per-host_faketime_wrappers "${REFERENCE_DATETIME}"
+ export PATH=${WRAP_DIR}:${PATH}
+
+ # Create the release tarball using (arbitrarily) the first host
+ ./autogen.sh
+ CONFIG_SITE=${BASEPREFIX}/`echo "${HOSTS}" | awk '{print $1;}'`/share/config.site ./configure --prefix=/
+ make dist
+ SOURCEDIST=`echo defi-*.tar.gz`
+ DISTNAME=`echo ${SOURCEDIST} | sed 's/.tar.*//'`
+ # Correct tar file order
+ mkdir -p temp
+ pushd temp
+ tar -xf ../$SOURCEDIST
+ find defi-* | sort | tar --mtime="$REFERENCE_DATETIME" --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ../$SOURCEDIST
+ popd
+
+ # Workaround for tarball not building with the bare tag version (prep)
+ make -C src obj/build.h
+
+ ORIGPATH="$PATH"
+ # Extract the release tarball into a dir for each host and build
+ for i in ${HOSTS}; do
+ export PATH=${BASEPREFIX}/${i}/native/bin:${ORIGPATH}
+ mkdir -p distsrc-${i}
+ cd distsrc-${i}
+ INSTALLPATH=`pwd`/installed/${DISTNAME}
+ mkdir -p ${INSTALLPATH}
+ tar --strip-components=1 -xf ../$SOURCEDIST
+
+ # Workaround for tarball not building with the bare tag version
+ echo '#!/bin/true' >share/genbuild.sh
+ mkdir src/obj
+ cp ../src/obj/build.h src/obj/
+
+ CONFIG_SITE=${BASEPREFIX}/${i}/share/config.site ./configure --prefix=/ --disable-ccache --disable-maintainer-mode --disable-dependency-tracking ${CONFIGFLAGS} CFLAGS="${HOST_CFLAGS}" CXXFLAGS="${HOST_CXXFLAGS}" LDFLAGS="${HOST_LDFLAGS}"
+ make ${MAKEOPTS}
+ make ${MAKEOPTS} -C src check-security
+ make ${MAKEOPTS} -C src check-symbols
+ make install DESTDIR=${INSTALLPATH}
+ cd installed
+ find . -name "lib*.la" -delete
+ find . -name "lib*.a" -delete
+ rm -rf ${DISTNAME}/lib/pkgconfig
+ find ${DISTNAME}/bin -type f -executable -print0 | xargs -0 -n1 -I{} ../contrib/devtools/split-debug.sh {} {} {}.dbg
+ find ${DISTNAME}/lib -type f -print0 | xargs -0 -n1 -I{} ../contrib/devtools/split-debug.sh {} {} {}.dbg
+ cp ../doc/README.md ${DISTNAME}/
+ find ${DISTNAME} -not -name "*.dbg" | sort | tar --mtime="$REFERENCE_DATETIME" --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-${i}.tar.gz
+ find ${DISTNAME} -name "*.dbg" | sort | tar --mtime="$REFERENCE_DATETIME" --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-${i}-debug.tar.gz
+ cd ../../
+ rm -rf distsrc-${i}
+ done
+ mkdir -p $OUTDIR/src
+ mv $SOURCEDIST $OUTDIR/src
diff --git a/contrib/gitian-descriptors/gitian-osx-signer.yml b/contrib/gitian-descriptors/gitian-osx-signer.yml
new file mode 100644
index 0000000000..9d54374684
--- /dev/null
+++ b/contrib/gitian-descriptors/gitian-osx-signer.yml
@@ -0,0 +1,40 @@
+---
+name: "defi-dmg-signer"
+distro: "ubuntu"
+suites:
+- "bionic"
+architectures:
+- "amd64"
+packages:
+- "faketime"
+remotes:
+- "url": "https://github.com/bitcoin-core/bitcoin-detached-sigs.git"
+ "dir": "signature"
+files:
+- "defi-osx-unsigned.tar.gz"
+script: |
+ set -e -o pipefail
+
+ WRAP_DIR=$HOME/wrapped
+ mkdir -p ${WRAP_DIR}
+ export PATH=`pwd`:$PATH
+ FAKETIME_PROGS="dmg genisoimage"
+
+ # Create global faketime wrappers
+ for prog in ${FAKETIME_PROGS}; do
+ echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${prog}
+ echo "REAL=\`which -a ${prog} | grep -v ${WRAP_DIR}/${prog} | head -1\`" >> ${WRAP_DIR}/${prog}
+ echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${prog}
+ echo "export FAKETIME=\"${REFERENCE_DATETIME}\"" >> ${WRAP_DIR}/${prog}
+ echo "\$REAL \$@" >> $WRAP_DIR/${prog}
+ chmod +x ${WRAP_DIR}/${prog}
+ done
+
+ UNSIGNED=defi-osx-unsigned.tar.gz
+ SIGNED=defi-osx-signed.dmg
+
+ tar -xf ${UNSIGNED}
+ OSX_VOLNAME="$(cat osx_volname)"
+ ./detached-sig-apply.sh ${UNSIGNED} signature/osx
+ ${WRAP_DIR}/genisoimage -no-cache-inodes -D -l -probe -V "${OSX_VOLNAME}" -no-pad -r -dir-mode 0755 -apple -o uncompressed.dmg signed-app
+ ${WRAP_DIR}/dmg dmg uncompressed.dmg ${OUTDIR}/${SIGNED}
diff --git a/contrib/gitian-descriptors/gitian-osx.yml b/contrib/gitian-descriptors/gitian-osx.yml
new file mode 100644
index 0000000000..372d387474
--- /dev/null
+++ b/contrib/gitian-descriptors/gitian-osx.yml
@@ -0,0 +1,168 @@
+---
+name: "defi-core-osx-0.19"
+enable_cache: true
+distro: "ubuntu"
+suites:
+- "bionic"
+architectures:
+- "amd64"
+packages:
+- "ca-certificates"
+- "curl"
+- "g++"
+- "git"
+- "pkg-config"
+- "autoconf"
+- "librsvg2-bin"
+- "libtiff-tools"
+- "libtool"
+- "automake"
+- "faketime"
+- "bsdmainutils"
+- "cmake"
+- "imagemagick"
+- "libcap-dev"
+- "libz-dev"
+- "libbz2-dev"
+- "python3"
+- "python3-dev"
+- "python3-setuptools"
+- "fonts-tuffy"
+remotes:
+- "url": "https://github.com/bitcoin/bitcoin.git"
+ "dir": "defi"
+files:
+- "MacOSX10.11.sdk.tar.gz"
+script: |
+ set -e -o pipefail
+
+ WRAP_DIR=$HOME/wrapped
+ HOSTS="x86_64-apple-darwin14"
+ CONFIGFLAGS="--enable-reduce-exports --disable-bench --disable-gui-tests GENISOIMAGE=$WRAP_DIR/genisoimage"
+ FAKETIME_HOST_PROGS=""
+ FAKETIME_PROGS="ar ranlib date dmg genisoimage"
+
+ export QT_RCC_TEST=1
+ export QT_RCC_SOURCE_DATE_OVERRIDE=1
+ export TZ="UTC"
+ export BUILD_DIR=`pwd`
+ mkdir -p ${WRAP_DIR}
+ if test -n "$GBUILD_CACHE_ENABLED"; then
+ export SOURCES_PATH=${GBUILD_COMMON_CACHE}
+ export BASE_CACHE=${GBUILD_PACKAGE_CACHE}
+ mkdir -p ${BASE_CACHE} ${SOURCES_PATH}
+ fi
+
+ export ZERO_AR_DATE=1
+
+ function create_global_faketime_wrappers {
+ for prog in ${FAKETIME_PROGS}; do
+ echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${prog}
+ echo "REAL=\`which -a ${prog} | grep -v ${WRAP_DIR}/${prog} | head -1\`" >> ${WRAP_DIR}/${prog}
+ echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${prog}
+ echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${prog}
+ echo "\$REAL \$@" >> $WRAP_DIR/${prog}
+ chmod +x ${WRAP_DIR}/${prog}
+ done
+ }
+
+ function create_per-host_faketime_wrappers {
+ for i in $HOSTS; do
+ for prog in ${FAKETIME_HOST_PROGS}; do
+ echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}-${prog}
+ echo "REAL=\`which -a ${i}-${prog} | grep -v ${WRAP_DIR}/${i}-${prog} | head -1\`" >> ${WRAP_DIR}/${i}-${prog}
+ echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${i}-${prog}
+ echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${i}-${prog}
+ echo "\$REAL \$@" >> $WRAP_DIR/${i}-${prog}
+ chmod +x ${WRAP_DIR}/${i}-${prog}
+ done
+ done
+ }
+
+ # Faketime for depends so intermediate results are comparable
+ export PATH_orig=${PATH}
+ create_global_faketime_wrappers "2000-01-01 12:00:00"
+ create_per-host_faketime_wrappers "2000-01-01 12:00:00"
+ export PATH=${WRAP_DIR}:${PATH}
+
+ cd defi
+ BASEPREFIX=`pwd`/depends
+
+ mkdir -p ${BASEPREFIX}/SDKs
+ tar -C ${BASEPREFIX}/SDKs -xf ${BUILD_DIR}/MacOSX10.11.sdk.tar.gz
+
+ # Build dependencies for each host
+ for i in $HOSTS; do
+ make ${MAKEOPTS} -C ${BASEPREFIX} HOST="${i}"
+ done
+
+ # Faketime for binaries
+ export PATH=${PATH_orig}
+ create_global_faketime_wrappers "${REFERENCE_DATETIME}"
+ create_per-host_faketime_wrappers "${REFERENCE_DATETIME}"
+ export PATH=${WRAP_DIR}:${PATH}
+
+ # Create the release tarball using (arbitrarily) the first host
+ ./autogen.sh
+ CONFIG_SITE=${BASEPREFIX}/`echo "${HOSTS}" | awk '{print $1;}'`/share/config.site ./configure --prefix=/
+ make dist
+ SOURCEDIST=`echo defi-*.tar.gz`
+ DISTNAME=`echo ${SOURCEDIST} | sed 's/.tar.*//'`
+
+ # Correct tar file order
+ mkdir -p temp
+ pushd temp
+ tar -xf ../$SOURCEDIST
+ find defi-* | sort | tar --mtime="$REFERENCE_DATETIME" --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ../$SOURCEDIST
+ popd
+
+ # Workaround for tarball not building with the bare tag version (prep)
+ make -C src obj/build.h
+
+ ORIGPATH="$PATH"
+ # Extract the release tarball into a dir for each host and build
+ for i in ${HOSTS}; do
+ export PATH=${BASEPREFIX}/${i}/native/bin:${ORIGPATH}
+ mkdir -p distsrc-${i}
+ cd distsrc-${i}
+ INSTALLPATH=`pwd`/installed/${DISTNAME}
+ mkdir -p ${INSTALLPATH}
+ tar --strip-components=1 -xf ../$SOURCEDIST
+
+ # Workaround for tarball not building with the bare tag version
+ echo '#!/bin/true' >share/genbuild.sh
+ mkdir src/obj
+ cp ../src/obj/build.h src/obj/
+
+ CONFIG_SITE=${BASEPREFIX}/${i}/share/config.site ./configure --prefix=/ --disable-ccache --disable-maintainer-mode --disable-dependency-tracking ${CONFIGFLAGS}
+ make ${MAKEOPTS}
+ make install-strip DESTDIR=${INSTALLPATH}
+
+ make osx_volname
+ make deploydir
+ OSX_VOLNAME="$(cat osx_volname)"
+ mkdir -p unsigned-app-${i}
+ cp osx_volname unsigned-app-${i}/
+ cp contrib/macdeploy/detached-sig-apply.sh unsigned-app-${i}
+ cp contrib/macdeploy/detached-sig-create.sh unsigned-app-${i}
+ cp ${BASEPREFIX}/${i}/native/bin/dmg ${BASEPREFIX}/${i}/native/bin/genisoimage unsigned-app-${i}
+ cp ${BASEPREFIX}/${i}/native/bin/${i}-codesign_allocate unsigned-app-${i}/codesign_allocate
+ cp ${BASEPREFIX}/${i}/native/bin/${i}-pagestuff unsigned-app-${i}/pagestuff
+ mv dist unsigned-app-${i}
+ pushd unsigned-app-${i}
+ find . | sort | tar --mtime="$REFERENCE_DATETIME" --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-osx-unsigned.tar.gz
+ popd
+
+ make deploy
+ ${WRAP_DIR}/dmg dmg "${OSX_VOLNAME}.dmg" ${OUTDIR}/${DISTNAME}-osx-unsigned.dmg
+
+ cd installed
+ find . -name "lib*.la" -delete
+ find . -name "lib*.a" -delete
+ rm -rf ${DISTNAME}/lib/pkgconfig
+ find ${DISTNAME} | sort | tar --mtime="$REFERENCE_DATETIME" --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-${i}.tar.gz
+ cd ../../
+ done
+ mkdir -p $OUTDIR/src
+ mv $SOURCEDIST $OUTDIR/src
+ mv ${OUTDIR}/${DISTNAME}-x86_64-*.tar.gz ${OUTDIR}/${DISTNAME}-osx64.tar.gz
diff --git a/contrib/gitian-descriptors/gitian-win-signer.yml b/contrib/gitian-descriptors/gitian-win-signer.yml
new file mode 100644
index 0000000000..5e6fdd08f5
--- /dev/null
+++ b/contrib/gitian-descriptors/gitian-win-signer.yml
@@ -0,0 +1,42 @@
+---
+name: "defi-win-signer"
+distro: "ubuntu"
+suites:
+- "bionic"
+architectures:
+- "amd64"
+packages:
+# Once osslsigncode supports openssl 1.1, we can change this back to libssl-dev
+- "libssl1.0-dev"
+- "autoconf"
+remotes:
+- "url": "https://github.com/bitcoin-core/bitcoin-detached-sigs.git"
+ "dir": "signature"
+files:
+- "osslsigncode-1.7.1.tar.gz"
+- "osslsigncode-Backports-to-1.7.1.patch"
+- "defi-win-unsigned.tar.gz"
+script: |
+ set -e -o pipefail
+
+ BUILD_DIR=`pwd`
+ SIGDIR=${BUILD_DIR}/signature/win
+ UNSIGNED_DIR=${BUILD_DIR}/unsigned
+
+ echo "f9a8cdb38b9c309326764ebc937cba1523a3a751a7ab05df3ecc99d18ae466c9 osslsigncode-1.7.1.tar.gz" | sha256sum -c
+ echo "a8c4e9cafba922f89de0df1f2152e7be286aba73f78505169bc351a7938dd911 osslsigncode-Backports-to-1.7.1.patch" | sha256sum -c
+
+ mkdir -p ${UNSIGNED_DIR}
+ tar -C ${UNSIGNED_DIR} -xf defi-win-unsigned.tar.gz
+
+ tar xf osslsigncode-1.7.1.tar.gz
+ cd osslsigncode-1.7.1
+ patch -p1 < ${BUILD_DIR}/osslsigncode-Backports-to-1.7.1.patch
+
+ ./configure --without-gsf --without-curl --disable-dependency-tracking
+ make
+ find ${UNSIGNED_DIR} -name "*-unsigned.exe" | while read i; do
+ INFILE="`basename "${i}"`"
+ OUTFILE="`echo "${INFILE}" | sed s/-unsigned//`"
+ ./osslsigncode attach-signature -in "${i}" -out "${OUTDIR}/${OUTFILE}" -sigin "${SIGDIR}/${INFILE}.pem"
+ done
diff --git a/contrib/gitian-descriptors/gitian-win.yml b/contrib/gitian-descriptors/gitian-win.yml
new file mode 100644
index 0000000000..41b86d9aa8
--- /dev/null
+++ b/contrib/gitian-descriptors/gitian-win.yml
@@ -0,0 +1,180 @@
+---
+name: "defi-core-win-0.19"
+enable_cache: true
+distro: "ubuntu"
+suites:
+- "bionic"
+architectures:
+- "amd64"
+packages:
+- "curl"
+- "g++"
+- "git"
+- "pkg-config"
+- "autoconf"
+- "libtool"
+- "automake"
+- "faketime"
+- "bsdmainutils"
+- "mingw-w64"
+- "g++-mingw-w64"
+- "nsis"
+- "zip"
+- "ca-certificates"
+- "python3"
+- "rename"
+remotes:
+- "url": "https://github.com/bitcoin/bitcoin.git"
+ "dir": "defi"
+files: []
+script: |
+ set -e -o pipefail
+
+ WRAP_DIR=$HOME/wrapped
+ HOSTS="x86_64-w64-mingw32"
+ CONFIGFLAGS="--enable-reduce-exports --disable-bench --disable-gui-tests"
+ FAKETIME_HOST_PROGS="ar ranlib nm windres strip objcopy"
+ FAKETIME_PROGS="date makensis zip"
+ HOST_CFLAGS="-O2 -g"
+ HOST_CXXFLAGS="-O2 -g"
+
+ export QT_RCC_TEST=1
+ export QT_RCC_SOURCE_DATE_OVERRIDE=1
+ export TZ="UTC"
+ export BUILD_DIR=`pwd`
+ mkdir -p ${WRAP_DIR}
+ if test -n "$GBUILD_CACHE_ENABLED"; then
+ export SOURCES_PATH=${GBUILD_COMMON_CACHE}
+ export BASE_CACHE=${GBUILD_PACKAGE_CACHE}
+ mkdir -p ${BASE_CACHE} ${SOURCES_PATH}
+ fi
+
+ function create_global_faketime_wrappers {
+ for prog in ${FAKETIME_PROGS}; do
+ echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${prog}
+ echo "REAL=\`which -a ${prog} | grep -v ${WRAP_DIR}/${prog} | head -1\`" >> ${WRAP_DIR}/${prog}
+ echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${prog}
+ echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${prog}
+ echo "\$REAL \$@" >> $WRAP_DIR/${prog}
+ chmod +x ${WRAP_DIR}/${prog}
+ done
+ }
+
+ function create_per-host_faketime_wrappers {
+ for i in $HOSTS; do
+ for prog in ${FAKETIME_HOST_PROGS}; do
+ echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}-${prog}
+ echo "REAL=\`which -a ${i}-${prog} | grep -v ${WRAP_DIR}/${i}-${prog} | head -1\`" >> ${WRAP_DIR}/${i}-${prog}
+ echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${i}-${prog}
+ echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${i}-${prog}
+ echo "\$REAL \$@" >> $WRAP_DIR/${i}-${prog}
+ chmod +x ${WRAP_DIR}/${i}-${prog}
+ done
+ done
+ }
+
+ function create_per-host_linker_wrapper {
+ # This is only needed for trusty, as the mingw linker leaks a few bytes of
+ # heap, causing non-determinism. See discussion in https://github.com/bitcoin/bitcoin/pull/6900
+ for i in $HOSTS; do
+ mkdir -p ${WRAP_DIR}/${i}
+ for prog in collect2; do
+ echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}/${prog}
+ REAL=$(${i}-gcc -print-prog-name=${prog})
+ echo "export MALLOC_PERTURB_=255" >> ${WRAP_DIR}/${i}/${prog}
+ echo "${REAL} \$@" >> $WRAP_DIR/${i}/${prog}
+ chmod +x ${WRAP_DIR}/${i}/${prog}
+ done
+ for prog in gcc g++; do
+ echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}-${prog}
+ echo "REAL=\`which -a ${i}-${prog}-posix | grep -v ${WRAP_DIR}/${i}-${prog} | head -1\`" >> ${WRAP_DIR}/${i}-${prog}
+ echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${i}-${prog}
+ echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${i}-${prog}
+ echo "export COMPILER_PATH=${WRAP_DIR}/${i}" >> ${WRAP_DIR}/${i}-${prog}
+ echo "\$REAL \$@" >> $WRAP_DIR/${i}-${prog}
+ chmod +x ${WRAP_DIR}/${i}-${prog}
+ done
+ done
+ }
+
+ # Faketime for depends so intermediate results are comparable
+ export PATH_orig=${PATH}
+ create_global_faketime_wrappers "2000-01-01 12:00:00"
+ create_per-host_faketime_wrappers "2000-01-01 12:00:00"
+ create_per-host_linker_wrapper "2000-01-01 12:00:00"
+ export PATH=${WRAP_DIR}:${PATH}
+
+ cd defi
+ BASEPREFIX=`pwd`/depends
+ # Build dependencies for each host
+ for i in $HOSTS; do
+ make ${MAKEOPTS} -C ${BASEPREFIX} HOST="${i}"
+ done
+
+ # Faketime for binaries
+ export PATH=${PATH_orig}
+ create_global_faketime_wrappers "${REFERENCE_DATETIME}"
+ create_per-host_faketime_wrappers "${REFERENCE_DATETIME}"
+ create_per-host_linker_wrapper "${REFERENCE_DATETIME}"
+ export PATH=${WRAP_DIR}:${PATH}
+
+ # Create the release tarball using (arbitrarily) the first host
+ ./autogen.sh
+ CONFIG_SITE=${BASEPREFIX}/`echo "${HOSTS}" | awk '{print $1;}'`/share/config.site ./configure --prefix=/
+ make dist
+ SOURCEDIST=`echo defi-*.tar.gz`
+ DISTNAME=`echo ${SOURCEDIST} | sed 's/.tar.*//'`
+
+ # Correct tar file order
+ mkdir -p temp
+ pushd temp
+ tar -xf ../$SOURCEDIST
+ find defi-* | sort | tar --mtime="$REFERENCE_DATETIME" --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ../$SOURCEDIST
+ mkdir -p $OUTDIR/src
+ cp ../$SOURCEDIST $OUTDIR/src
+ popd
+
+ # Workaround for tarball not building with the bare tag version (prep)
+ make -C src obj/build.h
+
+ ORIGPATH="$PATH"
+ # Extract the release tarball into a dir for each host and build
+ for i in ${HOSTS}; do
+ export PATH=${BASEPREFIX}/${i}/native/bin:${ORIGPATH}
+ mkdir -p distsrc-${i}
+ cd distsrc-${i}
+ INSTALLPATH=`pwd`/installed/${DISTNAME}
+ mkdir -p ${INSTALLPATH}
+ tar --strip-components=1 -xf ../$SOURCEDIST
+
+ # Workaround for tarball not building with the bare tag version
+ echo '#!/bin/true' >share/genbuild.sh
+ mkdir src/obj
+ cp ../src/obj/build.h src/obj/
+
+ CONFIG_SITE=${BASEPREFIX}/${i}/share/config.site ./configure --prefix=/ --disable-ccache --disable-maintainer-mode --disable-dependency-tracking ${CONFIGFLAGS} CFLAGS="${HOST_CFLAGS}" CXXFLAGS="${HOST_CXXFLAGS}"
+ make ${MAKEOPTS}
+ make ${MAKEOPTS} -C src check-security
+ make deploy
+ make install DESTDIR=${INSTALLPATH}
+ rename 's/-setup\.exe$/-setup-unsigned.exe/' *-setup.exe
+ cp -f defi-*setup*.exe $OUTDIR/
+ cd installed
+ mv ${DISTNAME}/bin/*.dll ${DISTNAME}/lib/
+ find . -name "lib*.la" -delete
+ find . -name "lib*.a" -delete
+ rm -rf ${DISTNAME}/lib/pkgconfig
+ find ${DISTNAME}/bin -type f -executable -exec ${i}-objcopy --only-keep-debug {} {}.dbg \; -exec ${i}-strip -s {} \; -exec ${i}-objcopy --add-gnu-debuglink={}.dbg {} \;
+ find ${DISTNAME}/lib -type f -exec ${i}-objcopy --only-keep-debug {} {}.dbg \; -exec ${i}-strip -s {} \; -exec ${i}-objcopy --add-gnu-debuglink={}.dbg {} \;
+ find ${DISTNAME} -not -name "*.dbg" -type f | sort | zip -X@ ${OUTDIR}/${DISTNAME}-${i}.zip
+ find ${DISTNAME} -name "*.dbg" -type f | sort | zip -X@ ${OUTDIR}/${DISTNAME}-${i}-debug.zip
+ cd ../../
+ rm -rf distsrc-${i}
+ done
+ cp -rf contrib/windeploy $BUILD_DIR
+ cd $BUILD_DIR/windeploy
+ mkdir unsigned
+ cp $OUTDIR/defi-*setup-unsigned.exe unsigned/
+ find . | sort | tar --mtime="$REFERENCE_DATETIME" --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-win-unsigned.tar.gz
+ mv ${OUTDIR}/${DISTNAME}-x86_64-*-debug.zip ${OUTDIR}/${DISTNAME}-win64-debug.zip
+ mv ${OUTDIR}/${DISTNAME}-x86_64-*.zip ${OUTDIR}/${DISTNAME}-win64.zip
diff --git a/contrib/gitian-keys/README.md b/contrib/gitian-keys/README.md
new file mode 100644
index 0000000000..08212870c1
--- /dev/null
+++ b/contrib/gitian-keys/README.md
@@ -0,0 +1,29 @@
+## PGP keys of Gitian builders and Developers
+
+> NOTE: This section is a work in progress for DeFi Blockchain, and may not be applicable at it's current state.
+
+The file `keys.txt` contains fingerprints of the public keys of Gitian builders
+and active developers.
+
+The associated keys are mainly used to sign git commits or the build results
+of Gitian builds.
+
+The most recent version of each pgp key can be found on most pgp key servers.
+
+Fetch the latest version from the key server to see if any key was revoked in
+the meantime.
+To fetch the latest version of all pgp keys in your gpg homedir,
+
+```sh
+gpg --refresh-keys
+```
+
+To fetch keys of Gitian builders and active developers, feed the list of
+fingerprints of the primary keys into gpg:
+
+```sh
+while read fingerprint keyholder_name; do gpg --keyserver hkp://subset.pool.sks-keyservers.net --recv-keys ${fingerprint}; done < ./keys.txt
+```
+
+Add your key to the list if you provided Gitian signatures for two major or
+minor releases of Bitcoin Core.
diff --git a/contrib/gitian-keys/keys.txt b/contrib/gitian-keys/keys.txt
new file mode 100644
index 0000000000..9222a40b17
--- /dev/null
+++ b/contrib/gitian-keys/keys.txt
@@ -0,0 +1,33 @@
+9D3CC86A72F8494342EA5FD10A41BDC3F4FAFF1C Aaron Clauson (sipsorcery)
+617C90010B3BD370B0AC7D424BB42E31C79111B8 Akira Takizawa
+E944AE667CF960B1004BC32FCA662BE18B877A60 Andreas Schildbach
+152812300785C96444D3334D17565732E08E5E41 Andrew Chow
+912FD3228387123DC97E0E57D5566241A0295FA9 BtcDrak
+C519EBCF3B926298946783EFF6430754120EC2F4 Christian Decker (cdecker)
+F20F56EF6A067F70E8A5C99FFF95FAA971697405 centaur
+C060A6635913D98A3587D7DB1C2491FFEB0EF770 Cory Fields
+BF6273FAEF7CC0BA1F562E50989F6B3048A116B5 Dev Random
+6D3170C1DC2C6FD0AEEBCA6743811D1A26623924 Douglas Roark
+9A1689B60D1B3CCE9262307A2F40A9BF167FBA47 Erik Mossberg (erkmos)
+D35176BE9264832E4ACA8986BF0792FBE95DC863 fivepiece
+01CDF4627A3B88AAE4A571C87588242FBE38D3A8 Gavin Andresen
+D1DBF2C4B96F2DEBF4C16654410108112E7EA81F Hennadii Stepanov (hebasto)
+D3CC177286005BB8FF673294C5242A1AB3936517 jl2012
+32EE5C4C3FA15CCADB46ABE529D4BCB6416F53EC Jonas Schnelli
+4B4E840451149DD7FB0D633477DFAB5C3108B9A8 Jorge Timon
+C42AFF7C61B3E44A1454CD3557AF762DB3353322 Karl-Johan Alm (kallewoof)
+E463A93F5F3117EEDE6C7316BD02942421F4889F Luke Dashjr
+B8B3F1C0E58C15DB6A81D30C3648A882F4316B9B Marco Falke
+07DF3E57A548CCFB7530709189BBB8663E2E65CE Matt Corallo (BlueMatt)
+CA03882CB1FC067B5D3ACFE4D300116E1C875A3D MeshCollider
+E777299FC265DD04793070EB944D35F9AC3DB76A Michael Ford
+9692B91BBF0E8D34DFD33B1882C5C009628ECF0C Michagogo
+77E72E69DA7EE0A148C06B21B34821D4944DE5F7 Nils Schneider
+D62A803E27E7F43486035ADBBCD04D8E9CCCAC2A Paul Rabahy
+37EC7D7B0A217CDB4B4E007E7FAB114267E4FA04 Peter Todd
+D762373D24904A3E42F33B08B9A408E71DAAC974 Pieter Wuille (Location: Leuven, Belgium)
+133EAC179436F14A5CF1B794860FEB804E669320 Pieter Wuille
+ED9BDF7AD6A55E232E84524257FF9BDBCC301009 Sjors Provoost
+AEC1884398647C47413C1C3FB1179EB7347DC10D Warren Togami
+79D00BAC68B56D422F945A8F8E3A8F3247DBCBBF Willy Ko
+71A3B16735405025D447E8F274810B012346C9A6 Wladimir J. van der Laan
diff --git a/contrib/guix/README.md b/contrib/guix/README.md
new file mode 100644
index 0000000000..4dfa1729a5
--- /dev/null
+++ b/contrib/guix/README.md
@@ -0,0 +1,229 @@
+# Bootstrappable Bitcoin Core Builds
+
+This directory contains the files necessary to perform bootstrappable Bitcoin
+Core builds.
+
+[Bootstrappability][b17e] furthers our binary security guarantees by allowing us
+to _audit and reproduce_ our toolchain instead of blindly _trusting_ binary
+downloads.
+
+We achieve bootstrappability by using Guix as a functional package manager.
+
+## Requirements
+
+Conservatively, a x86_64 machine with:
+
+- 2 or more logical cores
+- 4GB of free disk space on the partition that /gnu/store will reside in
+- 24GB of free disk space on the partition that the Bitcoin Core git repository
+ resides in
+
+> Note: these requirements are slightly less onerous than those of Gitian builds
+
+## Setup
+
+### Installing Guix
+
+If you're just testing this out, you can use the
+[Dockerfile][fanquake/guix-docker] for convenience. It automatically speeds up
+your builds by [using substitutes](#speeding-up-builds-with-substitute-servers).
+If you don't want this behaviour, refer to the [next
+section](#choosing-your-security-model).
+
+Otherwise, follow the [Guix installation guide][guix/bin-install].
+
+> Note: For those who like to keep their filesystems clean, Guix is designed to
+> be very standalone and _will not_ conflict with your system's package
+> manager/existing setup. It _only_ touches `/var/guix`, `/gnu`, and
+> `~/.config/guix`.
+
+### Choosing your security model
+
+Guix allows us to achieve better binary security by using our CPU time to build
+everything from scratch. However, it doesn't sacrifice user choice in pursuit of
+this: users can decide whether or not to bootstrap and to use substitutes.
+
+After installation, you may want to consider [adding substitute
+servers](#speeding-up-builds-with-substitute-servers) to speed up your build if
+that fits your security model (say, if you're just testing that this works).
+This is skippable if you're using the [Dockerfile][fanquake/guix-docker].
+
+If you prefer not to use any substitutes, make sure to set
+`ADDITIONAL_GUIX_ENVIRONMENT_FLAGS` like the following snippet. The first build
+will take a while, but the resulting packages will be cached for future builds.
+
+```sh
+export ADDITIONAL_GUIX_ENVIRONMENT_FLAGS='--no-substitutes'
+```
+
+Likewise, to perform a bootstrapped build (takes even longer):
+
+```sh
+export ADDITIONAL_GUIX_ENVIRONMENT_FLAGS='--bootstrap --no-substitutes'
+```
+
+### Using the right Guix
+
+Once Guix is installed, deploy our patched version into your current Guix
+profile. The changes there are slowly being upstreamed.
+
+```sh
+guix pull --url=https://github.com/dongcarl/guix.git \
+ --commit=82c77e52b8b46e0a3aad2cb12307c2e30547deec \
+ --max-jobs=4 # change accordingly
+```
+
+Make sure that you are using your current profile. (You are prompted to do this
+at the end of the `guix pull`)
+
+```bash
+export PATH="${HOME}/.config/guix/current/bin${PATH:+:}$PATH"
+```
+
+> Note: There is ongoing work to eliminate this entire section using Guix
+> [inferiors][guix/inferiors] and [channels][guix/channels].
+
+## Usage
+
+### As a Development Environment
+
+For a Bitcoin Core depends development environment, simply invoke
+
+```sh
+guix environment --manifest=contrib/guix/manifest.scm
+```
+
+And you'll land back in your shell with all the build dependencies required for
+a `depends` build injected into your environment.
+
+### As a Tool for Deterministic Builds
+
+From the top of a clean Bitcoin Core repository:
+
+```sh
+./contrib/guix/guix-build.sh
+```
+
+After the build finishes successfully (check the status code please), compare
+hashes:
+
+```sh
+find output/ -type f -print0 | sort -z | xargs -r0 sha256sum
+```
+
+#### Recognized environment variables
+
+* _**HOSTS**_
+
+ Override the space-separated list of platform triples for which to perform a
+ bootstrappable build. _(defaults to "i686-linux-gnu x86\_64-linux-gnu
+ arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu")_
+
+ > Windows and OS X platform triplet support are WIP.
+
+* _**SOURCES_PATH**_
+
+ Set the depends tree download cache for sources. This is passed through to the
+ depends tree. Setting this to the same directory across multiple builds of the
+ depends tree can eliminate unnecessary redownloading of package sources.
+
+* _**MAX_JOBS**_
+
+ Override the maximum number of jobs to run simultaneously, you might want to
+ do so on a memory-limited machine. This may be passed to `make` as in `make
+ --jobs="$MAX_JOBS"` or `xargs` as in `xargs -P"$MAX_JOBS"`. _(defaults to the
+ value of `nproc` outside the container)_
+
+* _**SOURCE_DATE_EPOCH**_
+
+ Override the reference UNIX timestamp used for bit-for-bit reproducibility,
+ the variable name conforms to [standard][r12e/source-date-epoch]. _(defaults
+ to the output of `$(git log --format=%at -1)`)_
+
+* _**V**_
+
+ If non-empty, will pass `V=1` to all `make` invocations, making `make` output
+ verbose.
+
+* _**ADDITIONAL_GUIX_ENVIRONMENT_FLAGS**_
+
+ Additional flags to be passed to `guix environment`. For a fully-bootstrapped
+ build, set this to `--bootstrap --no-substitutes` (refer to the [security
+ model section](#choosing-your-security-model) for more details). Note that a
+ fully-bootstrapped build will take quite a long time on the first run.
+
+## Tips and Tricks
+
+### Speeding up builds with substitute servers
+
+_This whole section is automatically done in the convenience
+[Dockerfiles][fanquake/guix-docker]_
+
+For those who are used to life in the fast _(and trustful)_ lane, you can use
+[substitute servers][guix/substitutes] to enable binary downloads of packages.
+
+> For those who only want to use substitutes from the official Guix build farm
+> and have authorized the build farm's signing key during Guix's installation,
+> you don't need to do anything.
+
+#### Authorize the signing keys
+
+For the official Guix build farm at https://ci.guix.gnu.org, run as root:
+
+```
+guix archive --authorize < ~root/.config/guix/current/share/guix/ci.guix.gnu.org.pub
+```
+
+For dongcarl's substitute server at https://guix.carldong.io, run as root:
+
+```sh
+wget -qO- 'https://guix.carldong.io/signing-key.pub' | guix archive --authorize
+```
+
+#### Use the substitute servers
+
+The official Guix build farm at https://ci.guix.gnu.org is automatically used
+unless the `--no-substitutes` flag is supplied.
+
+This can be overridden for all `guix` invocations by passing the
+`--substitute-urls` option to your invocation of `guix-daemon`. This can also be
+overridden on a call-by-call basis by passing the same `--substitute-urls`
+option to client tools such at `guix environment`.
+
+To use dongcarl's substitute server for Bitcoin Core builds after having
+[authorized his signing key](#authorize-the-signing-keys):
+
+```
+export ADDITIONAL_GUIX_ENVIRONMENT_FLAGS='--substitute-urls="https://guix.carldong.io https://ci.guix.gnu.org"'
+```
+
+## FAQ
+
+### How can I trust the binary installation?
+
+As mentioned at the bottom of [this manual page][guix/bin-install]:
+
+> The binary installation tarballs can be (re)produced and verified simply by
+> running the following command in the Guix source tree:
+>
+> make guix-binary.x86_64-linux.tar.xz
+
+### When will Guix be packaged in debian?
+
+Vagrant Cascadian has been making good progress on this
+[here][debian/guix-package]. We have all the pieces needed to put up an APT
+repository and will likely put one up soon.
+
+[b17e]: http://bootstrappable.org/
+[r12e/source-date-epoch]: https://reproducible-builds.org/docs/source-date-epoch/
+
+[guix/install.sh]: https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh
+[guix/bin-install]: https://www.gnu.org/software/guix/manual/en/html_node/Binary-Installation.html
+[guix/env-setup]: https://www.gnu.org/software/guix/manual/en/html_node/Build-Environment-Setup.html
+[guix/substitutes]: https://www.gnu.org/software/guix/manual/en/html_node/Substitutes.html
+[guix/substitute-server-auth]: https://www.gnu.org/software/guix/manual/en/html_node/Substitute-Server-Authorization.html
+[guix/inferiors]: https://www.gnu.org/software/guix/manual/en/html_node/Inferiors.html
+[guix/channels]: https://www.gnu.org/software/guix/manual/en/html_node/Channels.html
+
+[debian/guix-package]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=850644
+[fanquake/guix-docker]: https://github.com/fanquake/core-review/tree/master/guix
diff --git a/contrib/guix/guix-build.sh b/contrib/guix/guix-build.sh
new file mode 100755
index 0000000000..26ddd0c982
--- /dev/null
+++ b/contrib/guix/guix-build.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+export LC_ALL=C
+set -e -o pipefail
+
+# Determine the maximum number of jobs to run simultaneously (overridable by
+# environment)
+MAX_JOBS="${MAX_JOBS:-$(nproc)}"
+
+# Download the depends sources now as we won't have internet access in the build
+# container
+make -C "${PWD}/depends" -j"$MAX_JOBS" download ${V:+V=1} ${SOURCES_PATH:+SOURCES_PATH="$SOURCES_PATH"}
+
+# Determine the reference time used for determinism (overridable by environment)
+SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(git log --format=%at -1)}"
+
+# Deterministically build Bitcoin Core for HOSTs (overriable by environment)
+for host in ${HOSTS=i686-linux-gnu x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu}; do
+
+ # Display proper warning when the user interrupts the build
+ trap 'echo "** INT received while building ${host}, you may want to clean up the relevant output and distsrc-* directories before rebuilding"' INT
+
+ # Run the build script 'contrib/guix/libexec/build.sh' in the build
+ # container specified by 'contrib/guix/manifest.scm'
+ # shellcheck disable=SC2086
+ guix environment --manifest="${PWD}/contrib/guix/manifest.scm" \
+ --container \
+ --pure \
+ --no-cwd \
+ --share="$PWD"=/defi \
+ ${SOURCES_PATH:+--share="$SOURCES_PATH"} \
+ ${ADDITIONAL_GUIX_ENVIRONMENT_FLAGS} \
+ -- env HOST="$host" \
+ MAX_JOBS="$MAX_JOBS" \
+ SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:?unable to determine value}" \
+ ${V:+V=1} \
+ ${SOURCES_PATH:+SOURCES_PATH="$SOURCES_PATH"} \
+ bash -c "cd /defi && bash contrib/guix/libexec/build.sh"
+
+done
diff --git a/contrib/guix/libexec/build.sh b/contrib/guix/libexec/build.sh
new file mode 100644
index 0000000000..55ed731518
--- /dev/null
+++ b/contrib/guix/libexec/build.sh
@@ -0,0 +1,206 @@
+#!/usr/bin/env bash
+export LC_ALL=C
+set -e -o pipefail
+
+# Check that environment variables assumed to be set by the environment are set
+echo "Building for platform triple ${HOST:?not set} with reference timestamp ${SOURCE_DATE_EPOCH:?not set}..."
+echo "At most ${MAX_JOBS:?not set} jobs will run at once..."
+
+#####################
+# Environment Setup #
+#####################
+
+# The depends folder also serves as a base-prefix for depends packages for
+# $HOSTs after successfully building.
+BASEPREFIX="${PWD}/depends"
+
+# Setup an output directory for our build
+OUTDIR="${OUTDIR:-${PWD}/output}"
+[ -e "$OUTDIR" ] || mkdir -p "$OUTDIR"
+
+# Setup the directory where our DeFi Blockchain build for HOST will occur
+DISTSRC="${DISTSRC:-${PWD}/distsrc-${HOST}}"
+if [ -e "$DISTSRC" ]; then
+ echo "DISTSRC directory '${DISTSRC}' exists, probably because of previous builds... Aborting..."
+ exit 1
+else
+ mkdir -p "$DISTSRC"
+fi
+
+# Given a package name and an output name, return the path of that output in our
+# current guix environment
+store_path() {
+ grep --extended-regexp "/[^-]{32}-${1}-cross-${HOST}-[^-]+${2:+-${2}}" "${GUIX_ENVIRONMENT}/manifest" \
+ | head --lines=1 \
+ | sed --expression='s|^[[:space:]]*"||' \
+ --expression='s|"[[:space:]]*$||'
+}
+
+# Determine output paths to use in CROSS_* environment variables
+CROSS_GLIBC="$(store_path glibc)"
+CROSS_GLIBC_STATIC="$(store_path glibc static)"
+CROSS_KERNEL="$(store_path linux-libre-headers)"
+CROSS_GCC="$(store_path gcc)"
+
+# Set environment variables to point Guix's cross-toolchain to the right
+# includes/libs for $HOST
+export CROSS_C_INCLUDE_PATH="${CROSS_GCC}/include:${CROSS_GLIBC}/include:${CROSS_KERNEL}/include"
+export CROSS_CPLUS_INCLUDE_PATH="${CROSS_GCC}/include/c++:${CROSS_GLIBC}/include:${CROSS_KERNEL}/include"
+export CROSS_LIBRARY_PATH="${CROSS_GLIBC}/lib:${CROSS_GLIBC_STATIC}/lib:${CROSS_GCC}/lib:${CROSS_GCC}/${HOST}/lib:${CROSS_KERNEL}/lib"
+
+# Disable Guix ld auto-rpath behavior
+export GUIX_LD_WRAPPER_DISABLE_RPATH=yes
+
+# Make /usr/bin if it doesn't exist
+[ -e /usr/bin ] || mkdir -p /usr/bin
+
+# Symlink file and env to a conventional path
+[ -e /usr/bin/file ] || ln -s --no-dereference "$(command -v file)" /usr/bin/file
+[ -e /usr/bin/env ] || ln -s --no-dereference "$(command -v env)" /usr/bin/env
+
+# Determine the correct value for -Wl,--dynamic-linker for the current $HOST
+glibc_dynamic_linker=$(
+ case "$HOST" in
+ i686-linux-gnu) echo /lib/ld-linux.so.2 ;;
+ x86_64-linux-gnu) echo /lib64/ld-linux-x86-64.so.2 ;;
+ arm-linux-gnueabihf) echo /lib/ld-linux-armhf.so.3 ;;
+ aarch64-linux-gnu) echo /lib/ld-linux-aarch64.so.1 ;;
+ riscv64-linux-gnu) echo /lib/ld-linux-riscv64-lp64d.so.1 ;;
+ *) exit 1 ;;
+ esac
+)
+
+# Environment variables for determinism
+export QT_RCC_TEST=1
+export QT_RCC_SOURCE_DATE_OVERRIDE=1
+export TAR_OPTIONS="--owner=0 --group=0 --numeric-owner --mtime='@${SOURCE_DATE_EPOCH}' --sort=name"
+export TZ="UTC"
+
+####################
+# Depends Building #
+####################
+
+# Build the depends tree, overriding variables that assume multilib gcc
+make -C depends --jobs="$MAX_JOBS" HOST="$HOST" \
+ ${V:+V=1} \
+ ${SOURCES_PATH+SOURCES_PATH="$SOURCES_PATH"} \
+ i686_linux_CC=i686-linux-gnu-gcc \
+ i686_linux_CXX=i686-linux-gnu-g++ \
+ i686_linux_AR=i686-linux-gnu-ar \
+ i686_linux_RANLIB=i686-linux-gnu-ranlib \
+ i686_linux_NM=i686-linux-gnu-nm \
+ i686_linux_STRIP=i686-linux-gnu-strip \
+ x86_64_linux_CC=x86_64-linux-gnu-gcc \
+ x86_64_linux_CXX=x86_64-linux-gnu-g++ \
+ x86_64_linux_AR=x86_64-linux-gnu-ar \
+ x86_64_linux_RANLIB=x86_64-linux-gnu-ranlib \
+ x86_64_linux_NM=x86_64-linux-gnu-nm \
+ x86_64_linux_STRIP=x86_64-linux-gnu-strip \
+ qt_config_opts_i686_linux='-platform linux-g++ -xplatform defi-linux-g++'
+
+
+###########################
+# Source Tarball Building #
+###########################
+
+# Create the source tarball and move it to "${OUTDIR}/src" if not already there
+if [ -z "$(find "${OUTDIR}/src" -name 'defi-*.tar.gz')" ]; then
+ ./autogen.sh
+ env CONFIG_SITE="${BASEPREFIX}/${HOST}/share/config.site" ./configure --prefix=/
+ make dist GZIP_ENV='-9n' ${V:+V=1}
+ mkdir -p "${OUTDIR}/src"
+ mv "$(find "${PWD}" -name 'defi-*.tar.gz')" "${OUTDIR}/src/"
+fi
+
+# Determine the full path to our source tarball
+SOURCEDIST="$(find "${OUTDIR}/src" -name 'defi-*.tar.gz')"
+# Determine our distribution name (e.g. defi-0.18.0)
+DISTNAME="$(basename "$SOURCEDIST" '.tar.gz')"
+
+###########################
+# Binary Tarball Building #
+###########################
+
+# Create a spec file to normalize ssp linking behaviour
+spec_file="$(mktemp)"
+cat << EOF > "$spec_file"
+*link_ssp:
+%{fstack-protector|fstack-protector-all|fstack-protector-strong|fstack-protector-explicit:}
+EOF
+
+# Similar flags to Gitian
+CONFIGFLAGS="--enable-glibc-back-compat --enable-reduce-exports --disable-bench --disable-gui-tests"
+HOST_CFLAGS="-O2 -g -specs=${spec_file} -ffile-prefix-map=${PWD}=."
+HOST_CXXFLAGS="-O2 -g -specs=${spec_file} -ffile-prefix-map=${PWD}=."
+HOST_LDFLAGS="-Wl,--as-needed -Wl,--dynamic-linker=$glibc_dynamic_linker -static-libstdc++"
+
+# Make $HOST-specific native binaries from depends available in $PATH
+export PATH="${BASEPREFIX}/${HOST}/native/bin:${PATH}"
+(
+ cd "$DISTSRC"
+
+ # Extract the source tarball
+ tar --strip-components=1 -xf "${SOURCEDIST}"
+
+ # Configure this DISTSRC for $HOST
+ # shellcheck disable=SC2086
+ env CONFIG_SITE="${BASEPREFIX}/${HOST}/share/config.site" \
+ ./configure --prefix=/ \
+ --disable-ccache \
+ --disable-maintainer-mode \
+ --disable-dependency-tracking \
+ ${CONFIGFLAGS} \
+ CFLAGS="${HOST_CFLAGS}" \
+ CXXFLAGS="${HOST_CXXFLAGS}" \
+ LDFLAGS="${HOST_LDFLAGS}"
+
+ sed -i.old 's/-lstdc++ //g' config.status libtool src/univalue/config.status src/univalue/libtool
+
+ # Build DeFi Blockchain
+ make --jobs="$MAX_JOBS" ${V:+V=1}
+
+ # Perform basic ELF security checks on a series of executables.
+ make -C src --jobs=1 check-security ${V:+V=1}
+ # Check that executables only contain allowed gcc, glibc and libstdc++
+ # version symbols for Linux distro back-compatibility.
+ make -C src --jobs=1 check-symbols ${V:+V=1}
+
+ # Setup the directory where our DeFi Blockchain build for HOST will be
+ # installed. This directory will also later serve as the input for our
+ # binary tarballs.
+ INSTALLPATH="${PWD}/installed/${DISTNAME}"
+ mkdir -p "${INSTALLPATH}"
+ # Install built DeFi Blockchain to $INSTALLPATH
+ make install DESTDIR="${INSTALLPATH}" ${V:+V=1}
+ (
+ cd installed
+
+ # Prune libtool and object archives
+ find . -name "lib*.la" -delete
+ find . -name "lib*.a" -delete
+
+ # Prune pkg-config files
+ rm -r "${DISTNAME}/lib/pkgconfig"
+
+ # Split binaries and libraries from their debug symbols
+ {
+ find "${DISTNAME}/bin" -type f -executable -print0
+ find "${DISTNAME}/lib" -type f -print0
+ } | xargs -0 -n1 -P"$MAX_JOBS" -I{} "${DISTSRC}/contrib/devtools/split-debug.sh" {} {} {}.dbg
+
+ cp "${DISTSRC}/doc/README.md" "${DISTNAME}/"
+
+ # Finally, deterministically produce {non-,}debug binary tarballs ready
+ # for release
+ find "${DISTNAME}" -not -name "*.dbg" -print0 \
+ | sort --zero-terminated \
+ | tar --create --no-recursion --mode='u+rw,go+r-w,a+X' --null --files-from=- \
+ | gzip -9n > "${OUTDIR}/${DISTNAME}-${HOST}.tar.gz" \
+ || ( rm -f "${OUTDIR}/${DISTNAME}-${HOST}.tar.gz" && exit 1 )
+ find "${DISTNAME}" -name "*.dbg" -print0 \
+ | sort --zero-terminated \
+ | tar --create --no-recursion --mode='u+rw,go+r-w,a+X' --null --files-from=- \
+ | gzip -9n > "${OUTDIR}/${DISTNAME}-${HOST}-debug.tar.gz" \
+ || ( rm -f "${OUTDIR}/${DISTNAME}-${HOST}-debug.tar.gz" && exit 1 )
+ )
+)
diff --git a/contrib/guix/manifest.scm b/contrib/guix/manifest.scm
new file mode 100644
index 0000000000..aaba37f1e9
--- /dev/null
+++ b/contrib/guix/manifest.scm
@@ -0,0 +1,158 @@
+(use-modules (gnu)
+ (gnu packages)
+ (gnu packages autotools)
+ (gnu packages base)
+ (gnu packages bash)
+ (gnu packages check)
+ (gnu packages commencement)
+ (gnu packages compression)
+ (gnu packages cross-base)
+ (gnu packages file)
+ (gnu packages gawk)
+ (gnu packages gcc)
+ (gnu packages linux)
+ (gnu packages perl)
+ (gnu packages pkg-config)
+ (gnu packages python)
+ (gnu packages shells)
+ (guix build-system trivial)
+ (guix gexp)
+ (guix packages)
+ (guix profiles)
+ (guix utils))
+
+(define (make-ssp-fixed-gcc xgcc)
+ "Given a XGCC package, return a modified package that uses the SSP function
+from glibc instead of from libssp.so. Taken from:
+http://www.linuxfromscratch.org/hlfs/view/development/chapter05/gcc-pass1.html"
+ (package
+ (inherit xgcc)
+ (arguments
+ (substitute-keyword-arguments (package-arguments xgcc)
+ ((#:make-flags flags)
+ `(cons "gcc_cv_libc_provides_ssp=yes" ,flags))))))
+
+(define (make-gcc-rpath-link xgcc)
+ "Given a XGCC package, return a modified package that replace each instance of
+-rpath in the default system spec that's inserted by Guix with -rpath-link"
+ (package
+ (inherit xgcc)
+ (arguments
+ (substitute-keyword-arguments (package-arguments xgcc)
+ ((#:phases phases)
+ `(modify-phases ,phases
+ (add-after 'pre-configure 'replace-rpath-with-rpath-link
+ (lambda _
+ (substitute* (cons "gcc/config/rs6000/sysv4.h"
+ (find-files "gcc/config"
+ "^gnu-user.*\\.h$"))
+ (("-rpath=") "-rpath-link="))
+ #t))))))))
+
+(define (make-cross-toolchain target
+ base-gcc-for-libc
+ base-kernel-headers
+ base-libc
+ base-gcc)
+ "Create a cross-compilation toolchain package for TARGET"
+ (let* ((xbinutils (cross-binutils target))
+ ;; 1. Build a cross-compiling gcc without targeting any libc, derived
+ ;; from BASE-GCC-FOR-LIBC
+ (xgcc-sans-libc (cross-gcc target
+ #:xgcc base-gcc-for-libc
+ #:xbinutils xbinutils))
+ ;; 2. Build cross-compiled kernel headers with XGCC-SANS-LIBC, derived
+ ;; from BASE-KERNEL-HEADERS
+ (xkernel (cross-kernel-headers target
+ base-kernel-headers
+ xgcc-sans-libc
+ xbinutils))
+ ;; 3. Build a cross-compiled libc with XGCC-SANS-LIBC and XKERNEL,
+ ;; derived from BASE-LIBC
+ (xlibc (cross-libc target
+ base-libc
+ xgcc-sans-libc
+ xbinutils
+ xkernel))
+ ;; 4. Build a cross-compiling gcc targeting XLIBC, derived from
+ ;; BASE-GCC
+ (xgcc (cross-gcc target
+ #:xgcc base-gcc
+ #:xbinutils xbinutils
+ #:libc xlibc)))
+ ;; Define a meta-package that propagates the resulting XBINUTILS, XLIBC, and
+ ;; XGCC
+ (package
+ (name (string-append target "-toolchain"))
+ (version (package-version xgcc))
+ (source #f)
+ (build-system trivial-build-system)
+ (arguments '(#:builder (begin (mkdir %output) #t)))
+ (propagated-inputs
+ `(("binutils" ,xbinutils)
+ ("libc" ,xlibc)
+ ("libc:static" ,xlibc "static")
+ ("gcc" ,xgcc)))
+ (synopsis (string-append "Complete GCC tool chain for " target))
+ (description (string-append "This package provides a complete GCC tool
+chain for " target " development."))
+ (home-page (package-home-page xgcc))
+ (license (package-license xgcc)))))
+
+(define* (make-defi-cross-toolchain target
+ #:key
+ (base-gcc-for-libc gcc-5)
+ (base-kernel-headers linux-libre-headers-4.19)
+ (base-libc glibc-2.27)
+ (base-gcc (make-gcc-rpath-link
+ (make-ssp-fixed-gcc gcc-9))))
+ "Convienience wrapper around MAKE-CROSS-TOOLCHAIN with default values
+desirable for building DeFi Blockchain release binaries."
+ (make-cross-toolchain target
+ base-gcc-for-libc
+ base-kernel-headers
+ base-libc
+ base-gcc))
+
+(packages->manifest
+ (list ;; The Basics
+ bash-minimal
+ which
+ coreutils
+ util-linux
+ ;; File(system) inspection
+ file
+ grep
+ diffutils
+ findutils
+ ;; File transformation
+ patch
+ gawk
+ sed
+ ;; Compression and archiving
+ tar
+ bzip2
+ gzip
+ xz
+ zlib
+ ;; Build tools
+ gnu-make
+ libtool
+ autoconf
+ automake
+ pkg-config
+ ;; Scripting
+ perl
+ python-3.7
+ ;; Native gcc 9 toolchain targeting glibc 2.27
+ (make-gcc-toolchain gcc-9 glibc-2.27)
+ ;; Cross gcc 9 toolchains targeting glibc 2.27
+ (make-defi-cross-toolchain "i686-linux-gnu")
+ (make-defi-cross-toolchain "x86_64-linux-gnu")
+ (make-defi-cross-toolchain "aarch64-linux-gnu")
+ (make-defi-cross-toolchain "arm-linux-gnueabihf")
+ ;; The glibc 2.27 for riscv64 needs gcc 7 to successfully build (see:
+ ;; https://www.gnu.org/software/gcc/gcc-7/changes.html#riscv). The final
+ ;; toolchain is still a gcc 9 toolchain targeting glibc 2.27.
+ (make-defi-cross-toolchain "riscv64-linux-gnu"
+ #:base-gcc-for-libc gcc-7)))
diff --git a/contrib/init/README.md b/contrib/init/README.md
new file mode 100644
index 0000000000..268834fea0
--- /dev/null
+++ b/contrib/init/README.md
@@ -0,0 +1,12 @@
+Sample configuration files for:
+```
+SystemD: defid.service
+Upstart: defid.conf
+OpenRC: defid.openrc
+ defid.openrcconf
+CentOS: defid.init
+macOS: org.defi.defid.plist
+```
+have been made available to assist packagers in creating node packages here.
+
+See doc/init.md for more information.
diff --git a/contrib/init/defid.conf b/contrib/init/defid.conf
new file mode 100644
index 0000000000..c6ea8003ca
--- /dev/null
+++ b/contrib/init/defid.conf
@@ -0,0 +1,65 @@
+description "DeFi Blockchain Daemon"
+
+start on runlevel [2345]
+stop on starting rc RUNLEVEL=[016]
+
+env DEFID_BIN="/usr/bin/defid"
+env DEFID_USER="defi"
+env DEFID_GROUP="defi"
+env DEFID_PIDDIR="/var/run/defid"
+# upstart can't handle variables constructed with other variables
+env DEFID_PIDFILE="/var/run/defid/defid.pid"
+env DEFID_CONFIGFILE="/etc/defi/defi.conf"
+env DEFID_DATADIR="/var/lib/defi"
+
+expect fork
+
+respawn
+respawn limit 5 120
+kill timeout 60
+
+pre-start script
+ # this will catch non-existent config files
+ # defid will check and exit with this very warning, but it can do so
+ # long after forking, leaving upstart to think everything started fine.
+ # since this is a commonly encountered case on install, just check and
+ # warn here.
+ if ! grep -qs '^rpcpassword=' "$DEFID_CONFIGFILE" ; then
+ echo "ERROR: You must set a secure rpcpassword to run defid."
+ echo "The setting must appear in $DEFID_CONFIGFILE"
+ echo
+ echo "This password is security critical to securing wallets "
+ echo "and must not be the same as the rpcuser setting."
+ echo "You can generate a suitable random password using the following "
+ echo "command from the shell:"
+ echo
+ echo "bash -c 'tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo'"
+ echo
+ echo "It is recommended that you also set alertnotify so you are "
+ echo "notified of problems:"
+ echo
+ echo "ie: alertnotify=echo %%s | mail -s \"DeFi Blockchain Alert\"" \
+ "admin@foo.com"
+ echo
+ exit 1
+ fi
+
+ mkdir -p "$DEFID_PIDDIR"
+ chmod 0755 "$DEFID_PIDDIR"
+ chown $DEFID_USER:$DEFID_GROUP "$DEFID_PIDDIR"
+ chown $DEFID_USER:$DEFID_GROUP "$DEFID_CONFIGFILE"
+ chmod 0660 "$DEFID_CONFIGFILE"
+end script
+
+exec start-stop-daemon \
+ --start \
+ --pidfile "$DEFID_PIDFILE" \
+ --chuid $DEFID_USER:$DEFID_GROUP \
+ --exec "$DEFID_BIN" \
+ -- \
+ -pid="$DEFID_PIDFILE" \
+ -conf="$DEFID_CONFIGFILE" \
+ -datadir="$DEFID_DATADIR" \
+ -disablewallet \
+ -daemon
+
diff --git a/contrib/init/defid.init b/contrib/init/defid.init
new file mode 100644
index 0000000000..8547ae7970
--- /dev/null
+++ b/contrib/init/defid.init
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+#
+# defid The DeFi Blockchain server.
+#
+#
+# chkconfig: 345 80 20
+# description: defid
+# processname: defid
+#
+
+# Source function library.
+. /etc/init.d/functions
+
+# you can override defaults in /etc/sysconfig/defid, see below
+if [ -f /etc/sysconfig/defid ]; then
+ . /etc/sysconfig/defid
+fi
+
+RETVAL=0
+
+prog=defid
+# you can override the lockfile via DEFID_LOCKFILE in /etc/sysconfig/defid
+lockfile=${DEFID_LOCKFILE-/var/lock/subsys/defid}
+
+# defid defaults to /usr/bin/defid, override with DEFID_BIN
+defid=${DEFID_BIN-/usr/bin/defid}
+
+# defid opts default to -disablewallet, override with DEFID_OPTS
+defid_opts=${DEFID_OPTS--disablewallet}
+
+start() {
+ echo -n $"Starting $prog: "
+ daemon $DAEMONOPTS $defid $defid_opts
+ RETVAL=$?
+ echo
+ [ $RETVAL -eq 0 ] && touch $lockfile
+ return $RETVAL
+}
+
+stop() {
+ echo -n $"Stopping $prog: "
+ killproc $prog
+ RETVAL=$?
+ echo
+ [ $RETVAL -eq 0 ] && rm -f $lockfile
+ return $RETVAL
+}
+
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ status)
+ status $prog
+ ;;
+ restart)
+ stop
+ start
+ ;;
+ *)
+ echo "Usage: service $prog {start|stop|status|restart}"
+ exit 1
+ ;;
+esac
diff --git a/contrib/init/defid.openrc b/contrib/init/defid.openrc
new file mode 100644
index 0000000000..7fa8665b5c
--- /dev/null
+++ b/contrib/init/defid.openrc
@@ -0,0 +1,92 @@
+#!/sbin/openrc-run
+
+# backward compatibility for existing gentoo layout
+#
+if [ -d "/var/lib/defi/.defi" ]; then
+ DEFID_DEFAULT_DATADIR="/var/lib/defi/.defi"
+else
+ DEFID_DEFAULT_DATADIR="/var/lib/defi"
+fi
+
+DEFID_CONFIGFILE=${DEFID_CONFIGFILE:-/etc/defi/defi.conf}
+DEFID_PIDDIR=${DEFID_PIDDIR:-/var/run/defid}
+DEFID_PIDFILE=${DEFID_PIDFILE:-${DEFID_PIDDIR}/defid.pid}
+DEFID_DATADIR=${DEFID_DATADIR:-${DEFID_DEFAULT_DATADIR}}
+DEFID_USER=${DEFID_USER:-${DEFI_USER:-defi}}
+DEFID_GROUP=${DEFID_GROUP:-defi}
+DEFID_BIN=${DEFID_BIN:-/usr/bin/defid}
+DEFID_NICE=${DEFID_NICE:-${NICELEVEL:-0}}
+DEFID_OPTS="${DEFID_OPTS:-${DEFI_OPTS}}"
+
+name="DeFi Blockchain Daemon"
+description="DeFi Blockchain P2P network daemon"
+
+command="/usr/bin/defid"
+command_args="-pid=\"${DEFID_PIDFILE}\" \
+ -conf=\"${DEFID_CONFIGFILE}\" \
+ -datadir=\"${DEFID_DATADIR}\" \
+ -daemon \
+ ${DEFID_OPTS}"
+
+required_files="${DEFID_CONFIGFILE}"
+start_stop_daemon_args="-u ${DEFID_USER} \
+ -N ${DEFID_NICE} -w 2000"
+pidfile="${DEFID_PIDFILE}"
+
+# The retry schedule to use when stopping the daemon. Could be either
+# a timeout in seconds or multiple signal/timeout pairs (like
+# "SIGKILL/180 SIGTERM/300")
+retry="${DEFID_SIGTERM_TIMEOUT}"
+
+depend() {
+ need localmount net
+}
+
+# verify
+# 1) that the datadir exists and is writable (or create it)
+# 2) that a directory for the pid exists and is writable
+# 3) ownership and permissions on the config file
+start_pre() {
+ checkpath \
+ -d \
+ --mode 0750 \
+ --owner "${DEFID_USER}:${DEFID_GROUP}" \
+ "${DEFID_DATADIR}"
+
+ checkpath \
+ -d \
+ --mode 0755 \
+ --owner "${DEFID_USER}:${DEFID_GROUP}" \
+ "${DEFID_PIDDIR}"
+
+ checkpath -f \
+ -o ${DEFID_USER}:${DEFID_GROUP} \
+ -m 0660 \
+ ${DEFID_CONFIGFILE}
+
+ checkconfig || return 1
+}
+
+checkconfig()
+{
+ if ! grep -qs '^rpcpassword=' "${DEFID_CONFIGFILE}" ; then
+ eerror ""
+ eerror "ERROR: You must set a secure rpcpassword to run defid."
+ eerror "The setting must appear in ${DEFID_CONFIGFILE}"
+ eerror ""
+ eerror "This password is security critical to securing wallets "
+ eerror "and must not be the same as the rpcuser setting."
+ eerror "You can generate a suitable random password using the following "
+ eerror "command from the shell:"
+ eerror ""
+ eerror "bash -c 'tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo'"
+ eerror ""
+ eerror "It is recommended that you also set alertnotify so you are "
+ eerror "notified of problems:"
+ eerror ""
+ eerror "ie: alertnotify=echo %%s | mail -s \"Defi Alert\"" \
+ "admin@foo.com"
+ eerror ""
+ return 1
+ fi
+}
diff --git a/contrib/init/defid.openrcconf b/contrib/init/defid.openrcconf
new file mode 100644
index 0000000000..32e2b6891a
--- /dev/null
+++ b/contrib/init/defid.openrcconf
@@ -0,0 +1,33 @@
+# /etc/conf.d/defid: config file for /etc/init.d/defid
+
+# Config file location
+#DEFID_CONFIGFILE="/etc/defi/defi.conf"
+
+# What directory to write pidfile to? (created and owned by $DEFID_USER)
+#DEFID_PIDDIR="/var/run/defid"
+
+# What filename to give the pidfile
+#DEFID_PIDFILE="${DEFID_PIDDIR}/defid.pid"
+
+# Where to write defid data (be mindful that the blockchain is large)
+#DEFID_DATADIR="/var/lib/defi"
+
+# User and group to own defid process
+#DEFID_USER="defi"
+#DEFID_GROUP="defi"
+
+# Path to defid executable
+#DEFID_BIN="/usr/bin/defid"
+
+# Nice value to run defid under
+#DEFID_NICE=0
+
+# Additional options (avoid -conf and -datadir, use flags above)
+#DEFID_OPTS=""
+
+# The timeout in seconds OpenRC will wait for defid to terminate
+# after a SIGTERM has been raised.
+# Note that this will be mapped as argument to start-stop-daemon's
+# '--retry' option, which means you can specify a retry schedule
+# here. For more information see man 8 start-stop-daemon.
+DEFID_SIGTERM_TIMEOUT=60
diff --git a/contrib/init/defid.service b/contrib/init/defid.service
new file mode 100644
index 0000000000..2da57409ae
--- /dev/null
+++ b/contrib/init/defid.service
@@ -0,0 +1,76 @@
+# It is not recommended to modify this file in-place, because it will
+# be overwritten during package upgrades. If you want to add further
+# options or overwrite existing ones then use
+# $ systemctl edit defid.service
+# See "man systemd.service" for details.
+
+# Note that almost all daemon options could be specified in
+# /etc/defi/defi.conf, but keep in mind those explicitly
+# specified as arguments in ExecStart= will override those in the
+# config file.
+
+[Unit]
+Description=DeFi Blockchain Daemon
+After=network.target
+
+[Service]
+ExecStart=/usr/bin/defid -daemon \
+ -pid=/run/defid/defid.pid \
+ -conf=/etc/defi/defi.conf \
+ -datadir=/var/lib/defi
+
+# Make sure the config directory is readable by the service user
+PermissionsStartOnly=true
+ExecStartPre=/bin/chgrp defi /etc/defi
+
+# Process management
+####################
+
+Type=forking
+PIDFile=/run/defid/defid.pid
+Restart=on-failure
+
+# Directory creation and permissions
+####################################
+
+# Run as defi:defi
+User=defi
+Group=defi
+
+# /run/defid
+RuntimeDirectory=defid
+RuntimeDirectoryMode=0710
+
+# /etc/defi
+ConfigurationDirectory=defi
+ConfigurationDirectoryMode=0710
+
+# /var/lib/defi
+StateDirectory=defi
+StateDirectoryMode=0710
+
+# Hardening measures
+####################
+
+# Provide a private /tmp and /var/tmp.
+PrivateTmp=true
+
+# Mount /usr, /boot/ and /etc read-only for the process.
+ProtectSystem=full
+
+# Deny access to /home, /root and /run/user
+ProtectHome=true
+
+# Disallow the process and all of its children to gain
+# new privileges through execve().
+NoNewPrivileges=true
+
+# Use a new /dev namespace only populated with API pseudo devices
+# such as /dev/null, /dev/zero and /dev/random.
+PrivateDevices=true
+
+# Deny the creation of writable and executable memory mappings.
+MemoryDenyWriteExecute=true
+
+[Install]
+WantedBy=multi-user.target
diff --git a/contrib/install_db4.sh b/contrib/install_db4.sh
new file mode 100755
index 0000000000..c6749e0160
--- /dev/null
+++ b/contrib/install_db4.sh
@@ -0,0 +1,103 @@
+#!/bin/sh
+
+# Install libdb4.8 (Berkeley DB).
+
+export LC_ALL=C
+set -e
+
+if [ -z "${1}" ]; then
+ echo "Usage: $0 [ ...]"
+ echo
+ echo "Must specify a single argument: the directory in which db4 will be built."
+ echo "This is probably \`pwd\` if you're at the root of the defi repository."
+ exit 1
+fi
+
+expand_path() {
+ cd "${1}" && pwd -P
+}
+
+BDB_PREFIX="$(expand_path ${1})/db4"; shift;
+BDB_VERSION='db-4.8.30.NC'
+BDB_HASH='12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef'
+BDB_URL="https://download.oracle.com/berkeley-db/${BDB_VERSION}.tar.gz"
+
+check_exists() {
+ command -v "$1" >/dev/null
+}
+
+sha256_check() {
+ # Args:
+ #
+ if check_exists sha256sum; then
+ echo "${1} ${2}" | sha256sum -c
+ elif check_exists sha256; then
+ if [ "$(uname)" = "FreeBSD" ]; then
+ sha256 -c "${1}" "${2}"
+ else
+ echo "${1} ${2}" | sha256 -c
+ fi
+ else
+ echo "${1} ${2}" | shasum -a 256 -c
+ fi
+}
+
+http_get() {
+ # Args:
+ #
+ # It's acceptable that we don't require SSL here because we manually verify
+ # content hashes below.
+ #
+ if [ -f "${2}" ]; then
+ echo "File ${2} already exists; not downloading again"
+ elif check_exists curl; then
+ curl --insecure --retry 5 "${1}" -o "${2}"
+ else
+ wget --no-check-certificate "${1}" -O "${2}"
+ fi
+
+ sha256_check "${3}" "${2}"
+}
+
+mkdir -p "${BDB_PREFIX}"
+http_get "${BDB_URL}" "${BDB_VERSION}.tar.gz" "${BDB_HASH}"
+tar -xzvf ${BDB_VERSION}.tar.gz -C "$BDB_PREFIX"
+cd "${BDB_PREFIX}/${BDB_VERSION}/"
+
+# Apply a patch necessary when building with clang and c++11 (see https://community.oracle.com/thread/3952592)
+CLANG_CXX11_PATCH_URL='https://gist.githubusercontent.com/LnL7/5153b251fd525fe15de69b67e63a6075/raw/7778e9364679093a32dec2908656738e16b6bdcb/clang.patch'
+CLANG_CXX11_PATCH_HASH='7a9a47b03fd5fb93a16ef42235fa9512db9b0829cfc3bdf90edd3ec1f44d637c'
+http_get "${CLANG_CXX11_PATCH_URL}" clang.patch "${CLANG_CXX11_PATCH_HASH}"
+patch -p2 < clang.patch
+
+# The packaged config.guess and config.sub are ancient (2009) and can cause build issues.
+# Replace them with modern versions.
+# See https://github.com/bitcoin/bitcoin/issues/16064
+CONFIG_GUESS_URL='https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=55eaf3e779455c4e5cc9f82efb5278be8f8f900b'
+CONFIG_GUESS_HASH='2d1ff7bca773d2ec3c6217118129220fa72d8adda67c7d2bf79994b3129232c1'
+CONFIG_SUB_URL='https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=55eaf3e779455c4e5cc9f82efb5278be8f8f900b'
+CONFIG_SUB_HASH='3a4befde9bcdf0fdb2763fc1bfa74e8696df94e1ad7aac8042d133c8ff1d2e32'
+
+rm -f "dist/config.guess"
+rm -f "dist/config.sub"
+
+http_get "${CONFIG_GUESS_URL}" dist/config.guess "${CONFIG_GUESS_HASH}"
+http_get "${CONFIG_SUB_URL}" dist/config.sub "${CONFIG_SUB_HASH}"
+
+cd build_unix/
+
+"${BDB_PREFIX}/${BDB_VERSION}/dist/configure" \
+ --enable-cxx --disable-shared --disable-replication --with-pic --prefix="${BDB_PREFIX}" \
+ "${@}"
+
+make install
+
+echo
+echo "db4 build complete."
+echo
+# shellcheck disable=SC2016
+echo 'When compiling defid, run `./configure` in the following way:'
+echo
+echo " export BDB_PREFIX='${BDB_PREFIX}'"
+# shellcheck disable=SC2016
+echo ' ./configure BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS="-I${BDB_PREFIX}/include" ...'
diff --git a/contrib/linearize/README.md b/contrib/linearize/README.md
new file mode 100644
index 0000000000..726ee0ce1f
--- /dev/null
+++ b/contrib/linearize/README.md
@@ -0,0 +1,54 @@
+# Linearize
+Construct a linear, no-fork, best version of the DeFi Blockchain.
+
+## Step 1: Download hash list
+
+ $ ./linearize-hashes.py linearize.cfg > hashlist.txt
+
+Required configuration file settings for linearize-hashes:
+* RPC: `datadir` (Required if `rpcuser` and `rpcpassword` are not specified)
+* RPC: `rpcuser`, `rpcpassword` (Required if `datadir` is not specified)
+
+Optional config file setting for linearize-hashes:
+* RPC: `host` (Default: `127.0.0.1`)
+* RPC: `port` (Default: `8554`)
+* Blockchain: `min_height`, `max_height`
+* `rev_hash_bytes`: If true, the written block hash list will be
+byte-reversed. (In other words, the hash returned by getblockhash will have its
+bytes reversed.) False by default. Intended for generation of
+standalone hash lists but safe to use with linearize-data.py, which will output
+the same data no matter which byte format is chosen.
+
+The `linearize-hashes` script requires a connection, local or remote, to a
+JSON-RPC server. Running `defid` or `defi-qt -server` will be sufficient.
+
+## Step 2: Copy local block data
+
+ $ ./linearize-data.py linearize.cfg
+
+Required configuration file settings:
+* `output_file`: The file that will contain the final blockchain.
+ or
+* `output`: Output directory for linearized `blocks/blkNNNNN.dat` output.
+
+Optional config file setting for linearize-data:
+* `debug_output`: Some printouts may not always be desired. If true, such output
+will be printed.
+* `file_timestamp`: Set each file's last-accessed and last-modified times,
+respectively, to the current time and to the timestamp of the most recent block
+written to the script's blockchain.
+* `genesis`: The hash of the genesis block in the blockchain.
+* `input`: defid blocks/ directory containing blkNNNNN.dat
+* `hashlist`: text file containing list of block hashes created by
+linearize-hashes.py.
+* `max_out_sz`: Maximum size for files created by the `output_file` option.
+(Default: `1000*1000*1000 bytes`)
+* `netmagic`: Network magic number.
+* `out_of_order_cache_sz`: If out-of-order blocks are being read, the block can
+be written to a cache so that the blockchain doesn't have to be sought again.
+This option specifies the cache size. (Default: `100*1000*1000 bytes`)
+* `rev_hash_bytes`: If true, the block hash list written by linearize-hashes.py
+will be byte-reversed when read by linearize-data.py. See the linearize-hashes
+entry for more information.
+* `split_timestamp`: Split blockchain files when a new month is first seen, in
+addition to reaching a maximum file size (`max_out_sz`).
diff --git a/contrib/linearize/example-linearize.cfg b/contrib/linearize/example-linearize.cfg
new file mode 100644
index 0000000000..d7fe438817
--- /dev/null
+++ b/contrib/linearize/example-linearize.cfg
@@ -0,0 +1,50 @@
+# defid RPC settings (linearize-hashes)
+rpcuser=someuser
+rpcpassword=somepassword
+#datadir=~/.defi
+host=127.0.0.1
+
+#mainnet default
+port=8554
+
+#testnet default
+#port=18554
+
+#regtest default
+#port=19554
+
+# bootstrap.dat hashlist settings (linearize-hashes)
+max_height=313000
+
+# bootstrap.dat input/output settings (linearize-data)
+
+# mainnet
+netmagic=f9beb4d9
+genesis=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
+input=/home/example/.defi/blocks
+
+# testnet
+#netmagic=0b110907
+#genesis=000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943
+#input=/home/example/.defi/testnet3/blocks
+
+# "output" option causes blockchain files to be written to the given location,
+# with "output_file" ignored. If not used, "output_file" is used instead.
+# output=/home/example/blockchain_directory
+output_file=/home/example/Downloads/bootstrap.dat
+hashlist=hashlist.txt
+
+# Maximum size in bytes of out-of-order blocks cache in memory
+out_of_order_cache_sz = 100000000
+
+# Do we want the reverse the hash bytes coming from getblockhash?
+rev_hash_bytes = False
+
+# On a new month, do we want to set the access and modify times of the new
+# blockchain file?
+file_timestamp = 0
+# Do we want to split the blockchain files given a new month or specific height?
+split_timestamp = 0
+
+# Do we want debug printouts?
+debug_output = False
diff --git a/contrib/linearize/linearize-data.py b/contrib/linearize/linearize-data.py
new file mode 100755
index 0000000000..468aec04b5
--- /dev/null
+++ b/contrib/linearize/linearize-data.py
@@ -0,0 +1,320 @@
+#!/usr/bin/env python3
+#
+# linearize-data.py: Construct a linear, no-fork version of the chain.
+#
+# Copyright (c) 2013-2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#
+
+import struct
+import re
+import os
+import os.path
+import sys
+import hashlib
+import datetime
+import time
+from collections import namedtuple
+from binascii import unhexlify
+
+settings = {}
+
+def hex_switchEndian(s):
+ """ Switches the endianness of a hex string (in pairs of hex chars) """
+ pairList = [s[i:i+2].encode() for i in range(0, len(s), 2)]
+ return b''.join(pairList[::-1]).decode()
+
+def uint32(x):
+ return x & 0xffffffff
+
+def bytereverse(x):
+ return uint32(( ((x) << 24) | (((x) << 8) & 0x00ff0000) |
+ (((x) >> 8) & 0x0000ff00) | ((x) >> 24) ))
+
+def bufreverse(in_buf):
+ out_words = []
+ for i in range(0, len(in_buf), 4):
+ word = struct.unpack('@I', in_buf[i:i+4])[0]
+ out_words.append(struct.pack('@I', bytereverse(word)))
+ return b''.join(out_words)
+
+def wordreverse(in_buf):
+ out_words = []
+ for i in range(0, len(in_buf), 4):
+ out_words.append(in_buf[i:i+4])
+ out_words.reverse()
+ return b''.join(out_words)
+
+def calc_hdr_hash(blk_hdr):
+ hash1 = hashlib.sha256()
+ hash1.update(blk_hdr)
+ hash1_o = hash1.digest()
+
+ hash2 = hashlib.sha256()
+ hash2.update(hash1_o)
+ hash2_o = hash2.digest()
+
+ return hash2_o
+
+def calc_hash_str(blk_hdr):
+ hash = calc_hdr_hash(blk_hdr)
+ hash = bufreverse(hash)
+ hash = wordreverse(hash)
+ hash_str = hash.hex()
+ return hash_str
+
+def get_blk_dt(blk_hdr):
+ members = struct.unpack(" self.maxOutSz):
+ self.outF.close()
+ if self.setFileTime:
+ os.utime(self.outFname, (int(time.time()), self.highTS))
+ self.outF = None
+ self.outFname = None
+ self.outFn = self.outFn + 1
+ self.outsz = 0
+
+ (blkDate, blkTS) = get_blk_dt(blk_hdr)
+ if self.timestampSplit and (blkDate > self.lastDate):
+ print("New month " + blkDate.strftime("%Y-%m") + " @ " + self.hash_str)
+ self.lastDate = blkDate
+ if self.outF:
+ self.outF.close()
+ if self.setFileTime:
+ os.utime(self.outFname, (int(time.time()), self.highTS))
+ self.outF = None
+ self.outFname = None
+ self.outFn = self.outFn + 1
+ self.outsz = 0
+
+ if not self.outF:
+ if self.fileOutput:
+ self.outFname = self.settings['output_file']
+ else:
+ self.outFname = os.path.join(self.settings['output'], "blk%05d.dat" % self.outFn)
+ print("Output file " + self.outFname)
+ self.outF = open(self.outFname, "wb")
+
+ self.outF.write(inhdr)
+ self.outF.write(blk_hdr)
+ self.outF.write(rawblock)
+ self.outsz = self.outsz + len(inhdr) + len(blk_hdr) + len(rawblock)
+
+ self.blkCountOut = self.blkCountOut + 1
+ if blkTS > self.highTS:
+ self.highTS = blkTS
+
+ if (self.blkCountOut % 1000) == 0:
+ print('%i blocks scanned, %i blocks written (of %i, %.1f%% complete)' %
+ (self.blkCountIn, self.blkCountOut, len(self.blkindex), 100.0 * self.blkCountOut / len(self.blkindex)))
+
+ def inFileName(self, fn):
+ return os.path.join(self.settings['input'], "blk%05d.dat" % fn)
+
+ def fetchBlock(self, extent):
+ '''Fetch block contents from disk given extents'''
+ with open(self.inFileName(extent.fn), "rb") as f:
+ f.seek(extent.offset)
+ return f.read(extent.size)
+
+ def copyOneBlock(self):
+ '''Find the next block to be written in the input, and copy it to the output.'''
+ extent = self.blockExtents.pop(self.blkCountOut)
+ if self.blkCountOut in self.outOfOrderData:
+ # If the data is cached, use it from memory and remove from the cache
+ rawblock = self.outOfOrderData.pop(self.blkCountOut)
+ self.outOfOrderSize -= len(rawblock)
+ else: # Otherwise look up data on disk
+ rawblock = self.fetchBlock(extent)
+
+ self.writeBlock(extent.inhdr, extent.blkhdr, rawblock)
+
+ def run(self):
+ while self.blkCountOut < len(self.blkindex):
+ if not self.inF:
+ fname = self.inFileName(self.inFn)
+ print("Input file " + fname)
+ try:
+ self.inF = open(fname, "rb")
+ except IOError:
+ print("Premature end of block data")
+ return
+
+ inhdr = self.inF.read(8)
+ if (not inhdr or (inhdr[0] == "\0")):
+ self.inF.close()
+ self.inF = None
+ self.inFn = self.inFn + 1
+ continue
+
+ inMagic = inhdr[:4]
+ if (inMagic != self.settings['netmagic']):
+ print("Invalid magic: " + inMagic.hex())
+ return
+ inLenLE = inhdr[4:]
+ su = struct.unpack("
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
diff --git a/contrib/macdeploy/README.md b/contrib/macdeploy/README.md
new file mode 100644
index 0000000000..aae58b49a4
--- /dev/null
+++ b/contrib/macdeploy/README.md
@@ -0,0 +1,15 @@
+### MacDeploy ###
+
+For Snow Leopard (which uses [Python 2.6](http://www.python.org/download/releases/2.6/)), you will need the param_parser package:
+
+ sudo easy_install argparse
+
+This script should not be run manually, instead, after building as usual:
+
+ make deploy
+
+During the process, the disk image window will pop up briefly where the fancy
+settings are applied. This is normal, please do not interfere.
+
+When finished, it will produce `Defi-Core.dmg`.
+
diff --git a/contrib/macdeploy/background.svg b/contrib/macdeploy/background.svg
new file mode 100644
index 0000000000..9c330af451
--- /dev/null
+++ b/contrib/macdeploy/background.svg
@@ -0,0 +1,34 @@
+
+
+
diff --git a/contrib/macdeploy/custom_dsstore.py b/contrib/macdeploy/custom_dsstore.py
new file mode 100755
index 0000000000..27f1b408dc
--- /dev/null
+++ b/contrib/macdeploy/custom_dsstore.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+# Copyright (c) 2013-2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+import biplist
+from ds_store import DSStore
+from mac_alias import Alias
+import sys
+
+output_file = sys.argv[1]
+package_name_ns = sys.argv[2]
+
+ds = DSStore.open(output_file, 'w+')
+ds['.']['bwsp'] = {
+ 'ShowStatusBar': False,
+ 'WindowBounds': '{{300, 280}, {500, 343}}',
+ 'ContainerShowSidebar': False,
+ 'SidebarWidth': 0,
+ 'ShowTabView': False,
+ 'PreviewPaneVisibility': False,
+ 'ShowToolbar': False,
+ 'ShowSidebar': False,
+ 'ShowPathbar': True
+}
+
+icvp = {
+ 'gridOffsetX': 0.0,
+ 'textSize': 12.0,
+ 'viewOptionsVersion': 1,
+ 'backgroundImageAlias': b'\x00\x00\x00\x00\x02\x1e\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd1\x94\\\xb0H+\x00\x05\x00\x00\x00\x98\x0fbackground.tiff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x99\xd19\xb0\xf8\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\r\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0b.background\x00\x00\x10\x00\x08\x00\x00\xd1\x94\\\xb0\x00\x00\x00\x11\x00\x08\x00\x00\xd19\xb0\xf8\x00\x00\x00\x01\x00\x04\x00\x00\x00\x98\x00\x0e\x00 \x00\x0f\x00b\x00a\x00c\x00k\x00g\x00r\x00o\x00u\x00n\x00d\x00.\x00t\x00i\x00f\x00f\x00\x0f\x00\x02\x00\x00\x00\x12\x00\x1c/.background/background.tiff\x00\x14\x01\x06\x00\x00\x00\x00\x01\x06\x00\x02\x00\x00\x0cMacintosh HD\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xce\x97\xab\xc3H+\x00\x00\x01\x88[\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02u\xab\x8d\xd1\x94\\\xb0devrddsk\xff\xff\xff\xff\x00\x00\t \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07defi\x00\x00\x10\x00\x08\x00\x00\xce\x97\xab\xc3\x00\x00\x00\x11\x00\x08\x00\x00\xd1\x94\\\xb0\x00\x00\x00\x01\x00\x14\x01\x88[\x88\x00\x16\xa9\t\x00\x08\xfaR\x00\x08\xfaQ\x00\x02d\x8e\x00\x0e\x00\x02\x00\x00\x00\x0f\x00\x1a\x00\x0c\x00M\x00a\x00c\x00i\x00n\x00t\x00o\x00s\x00h\x00 \x00H\x00D\x00\x13\x00\x01/\x00\x00\x15\x00\x02\x00\x14\xff\xff\x00\x00\xff\xff\x00\x00',
+ 'backgroundColorBlue': 1.0,
+ 'iconSize': 96.0,
+ 'backgroundColorGreen': 1.0,
+ 'arrangeBy': 'none',
+ 'showIconPreview': True,
+ 'gridSpacing': 100.0,
+ 'gridOffsetY': 0.0,
+ 'showItemInfo': False,
+ 'labelOnBottom': True,
+ 'backgroundType': 2,
+ 'backgroundColorRed': 1.0
+}
+alias = Alias.from_bytes(icvp['backgroundImageAlias'])
+alias.volume.name = package_name_ns
+alias.volume.posix_path = '/Volumes/' + package_name_ns
+alias.volume.disk_image_alias.target.filename = package_name_ns + '.temp.dmg'
+alias.volume.disk_image_alias.target.carbon_path = 'Macintosh HD:Users:\x00defi:\x00Documents:\x00defi:\x00' + package_name_ns + '.temp.dmg'
+alias.volume.disk_image_alias.target.posix_path = 'Users/defi/Documents/defi/' + package_name_ns + '.temp.dmg'
+alias.target.carbon_path = package_name_ns + ':.background:\x00background.tiff'
+icvp['backgroundImageAlias'] = biplist.Data(alias.to_bytes())
+ds['.']['icvp'] = icvp
+
+ds['.']['vSrn'] = ('long', 1)
+
+ds['Applications']['Iloc'] = (370, 156)
+ds['Defi-Qt.app']['Iloc'] = (128, 156)
+
+ds.flush()
+ds.close()
diff --git a/contrib/macdeploy/detached-sig-apply.sh b/contrib/macdeploy/detached-sig-apply.sh
new file mode 100755
index 0000000000..af2b11fa0d
--- /dev/null
+++ b/contrib/macdeploy/detached-sig-apply.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+# Copyright (c) 2014-2015 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+set -e
+
+UNSIGNED="$1"
+SIGNATURE="$2"
+ARCH=x86_64
+ROOTDIR=dist
+TEMPDIR=signed.temp
+OUTDIR=signed-app
+
+if [ -z "$UNSIGNED" ]; then
+ echo "usage: $0 "
+ exit 1
+fi
+
+if [ -z "$SIGNATURE" ]; then
+ echo "usage: $0 "
+ exit 1
+fi
+
+rm -rf ${TEMPDIR} && mkdir -p ${TEMPDIR}
+tar -C ${TEMPDIR} -xf ${UNSIGNED}
+cp -rf "${SIGNATURE}"/* ${TEMPDIR}
+
+if [ -z "${PAGESTUFF}" ]; then
+ PAGESTUFF=${TEMPDIR}/pagestuff
+fi
+
+if [ -z "${CODESIGN_ALLOCATE}" ]; then
+ CODESIGN_ALLOCATE=${TEMPDIR}/codesign_allocate
+fi
+
+find ${TEMPDIR} -name "*.sign" | while read i; do
+ SIZE=$(stat -c %s "${i}")
+ TARGET_FILE="$(echo "${i}" | sed 's/\.sign$//')"
+
+ echo "Allocating space for the signature of size ${SIZE} in ${TARGET_FILE}"
+ ${CODESIGN_ALLOCATE} -i "${TARGET_FILE}" -a ${ARCH} ${SIZE} -o "${i}.tmp"
+
+ OFFSET=$(${PAGESTUFF} "${i}.tmp" -p | tail -2 | grep offset | sed 's/[^0-9]*//g')
+ if [ -z ${QUIET} ]; then
+ echo "Attaching signature at offset ${OFFSET}"
+ fi
+
+ dd if="$i" of="${i}.tmp" bs=1 seek=${OFFSET} count=${SIZE} 2>/dev/null
+ mv "${i}.tmp" "${TARGET_FILE}"
+ rm "${i}"
+ echo "Success."
+done
+mv ${TEMPDIR}/${ROOTDIR} ${OUTDIR}
+rm -rf ${TEMPDIR}
+echo "Signed: ${OUTDIR}"
diff --git a/contrib/macdeploy/detached-sig-create.sh b/contrib/macdeploy/detached-sig-create.sh
new file mode 100755
index 0000000000..9947bbac99
--- /dev/null
+++ b/contrib/macdeploy/detached-sig-create.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# Copyright (c) 2014-2015 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+set -e
+
+ROOTDIR=dist
+BUNDLE="${ROOTDIR}/Defi-Qt.app"
+CODESIGN=codesign
+TEMPDIR=sign.temp
+TEMPLIST=${TEMPDIR}/signatures.txt
+OUT=signature-osx.tar.gz
+OUTROOT=osx
+
+if [ -z "$1" ]; then
+ echo "usage: $0 "
+ echo "example: $0 -s MyIdentity"
+ exit 1
+fi
+
+rm -rf ${TEMPDIR} ${TEMPLIST}
+mkdir -p ${TEMPDIR}
+
+${CODESIGN} -f --file-list ${TEMPLIST} "$@" "${BUNDLE}"
+
+grep -v CodeResources < "${TEMPLIST}" | while read i; do
+ TARGETFILE="${BUNDLE}/$(echo "${i}" | sed "s|.*${BUNDLE}/||")"
+ SIZE=$(pagestuff "$i" -p | tail -2 | grep size | sed 's/[^0-9]*//g')
+ OFFSET=$(pagestuff "$i" -p | tail -2 | grep offset | sed 's/[^0-9]*//g')
+ SIGNFILE="${TEMPDIR}/${OUTROOT}/${TARGETFILE}.sign"
+ DIRNAME="$(dirname "${SIGNFILE}")"
+ mkdir -p "${DIRNAME}"
+ echo "Adding detached signature for: ${TARGETFILE}. Size: ${SIZE}. Offset: ${OFFSET}"
+ dd if="$i" of="${SIGNFILE}" bs=1 skip=${OFFSET} count=${SIZE} 2>/dev/null
+done
+
+grep CodeResources < "${TEMPLIST}" | while read i; do
+ TARGETFILE="${BUNDLE}/$(echo "${i}" | sed "s|.*${BUNDLE}/||")"
+ RESOURCE="${TEMPDIR}/${OUTROOT}/${TARGETFILE}"
+ DIRNAME="$(dirname "${RESOURCE}")"
+ mkdir -p "${DIRNAME}"
+ echo "Adding resource for: \"${TARGETFILE}\""
+ cp "${i}" "${RESOURCE}"
+done
+
+rm ${TEMPLIST}
+
+tar -C "${TEMPDIR}" -czf "${OUT}" .
+rm -rf "${TEMPDIR}"
+echo "Created ${OUT}"
diff --git a/contrib/macdeploy/extract-osx-sdk.sh b/contrib/macdeploy/extract-osx-sdk.sh
new file mode 100755
index 0000000000..4c175156f4
--- /dev/null
+++ b/contrib/macdeploy/extract-osx-sdk.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+# Copyright (c) 2016 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+set -e
+
+INPUTFILE="Xcode_7.3.1.dmg"
+HFSFILENAME="5.hfs"
+SDKDIR="Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk"
+
+7z x "${INPUTFILE}" "${HFSFILENAME}"
+SDKNAME="$(basename "${SDKDIR}")"
+SDKDIRINODE=$(ifind -n "${SDKDIR}" "${HFSFILENAME}")
+fls "${HFSFILENAME}" -rpF ${SDKDIRINODE} |
+ while read type inode filename; do
+ inode="${inode::-1}"
+ if [ "${filename:0:14}" = "usr/share/man/" ]; then
+ continue
+ fi
+ filename="${SDKNAME}/$filename"
+ echo "Extracting $filename ..."
+ mkdir -p "$(dirname "$filename")"
+ if [ "$type" = "l/l" ]; then
+ ln -s "$(icat "${HFSFILENAME}" $inode)" "$filename"
+ else
+ icat "${HFSFILENAME}" $inode >"$filename"
+ fi
+done
+echo "Building ${SDKNAME}.tar.gz ..."
+MTIME="$(istat "${HFSFILENAME}" "${SDKDIRINODE}" | perl -nle 'm/Content Modified:\s+(.*?)\s\(/ && print $1')"
+find "${SDKNAME}" | sort | tar --no-recursion --mtime="${MTIME}" --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > "${SDKNAME}.tar.gz"
+echo 'All done!'
diff --git a/contrib/macdeploy/fancy.plist b/contrib/macdeploy/fancy.plist
new file mode 100644
index 0000000000..8691c1afd1
--- /dev/null
+++ b/contrib/macdeploy/fancy.plist
@@ -0,0 +1,32 @@
+
+
+
+
+ window_bounds
+
+ 300
+ 300
+ 800
+ 620
+
+ background_picture
+ background.tiff
+ icon_size
+ 96
+ applications_symlink
+
+ items_position
+
+ Applications
+
+ 370
+ 156
+
+ Defi-Qt.app
+
+ 128
+ 156
+
+
+
+
diff --git a/contrib/macdeploy/macdeployqtplus b/contrib/macdeploy/macdeployqtplus
new file mode 100755
index 0000000000..28b26ebe28
--- /dev/null
+++ b/contrib/macdeploy/macdeployqtplus
@@ -0,0 +1,866 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2011 Patrick "p2k" Schneider
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+
+import subprocess, sys, re, os, shutil, stat, os.path, time
+from string import Template
+from argparse import ArgumentParser
+
+# This is ported from the original macdeployqt with modifications
+
+class FrameworkInfo(object):
+ def __init__(self):
+ self.frameworkDirectory = ""
+ self.frameworkName = ""
+ self.frameworkPath = ""
+ self.binaryDirectory = ""
+ self.binaryName = ""
+ self.binaryPath = ""
+ self.version = ""
+ self.installName = ""
+ self.deployedInstallName = ""
+ self.sourceFilePath = ""
+ self.destinationDirectory = ""
+ self.sourceResourcesDirectory = ""
+ self.sourceVersionContentsDirectory = ""
+ self.sourceContentsDirectory = ""
+ self.destinationResourcesDirectory = ""
+ self.destinationVersionContentsDirectory = ""
+
+ def __eq__(self, other):
+ if self.__class__ == other.__class__:
+ return self.__dict__ == other.__dict__
+ else:
+ return False
+
+ def __str__(self):
+ return """ Framework name: %s
+ Framework directory: %s
+ Framework path: %s
+ Binary name: %s
+ Binary directory: %s
+ Binary path: %s
+ Version: %s
+ Install name: %s
+ Deployed install name: %s
+ Source file Path: %s
+ Deployed Directory (relative to bundle): %s
+""" % (self.frameworkName,
+ self.frameworkDirectory,
+ self.frameworkPath,
+ self.binaryName,
+ self.binaryDirectory,
+ self.binaryPath,
+ self.version,
+ self.installName,
+ self.deployedInstallName,
+ self.sourceFilePath,
+ self.destinationDirectory)
+
+ def isDylib(self):
+ return self.frameworkName.endswith(".dylib")
+
+ def isQtFramework(self):
+ if self.isDylib():
+ return self.frameworkName.startswith("libQt")
+ else:
+ return self.frameworkName.startswith("Qt")
+
+ reOLine = re.compile(r'^(.+) \(compatibility version [0-9.]+, current version [0-9.]+\)$')
+ bundleFrameworkDirectory = "Contents/Frameworks"
+ bundleBinaryDirectory = "Contents/MacOS"
+
+ @classmethod
+ def fromOtoolLibraryLine(cls, line):
+ # Note: line must be trimmed
+ if line == "":
+ return None
+
+ # Don't deploy system libraries (exception for libQtuitools and libQtlucene).
+ if line.startswith("/System/Library/") or line.startswith("@executable_path") or (line.startswith("/usr/lib/") and "libQt" not in line):
+ return None
+
+ m = cls.reOLine.match(line)
+ if m is None:
+ raise RuntimeError("otool line could not be parsed: " + line)
+
+ path = m.group(1)
+
+ info = cls()
+ info.sourceFilePath = path
+ info.installName = path
+
+ if path.endswith(".dylib"):
+ dirname, filename = os.path.split(path)
+ info.frameworkName = filename
+ info.frameworkDirectory = dirname
+ info.frameworkPath = path
+
+ info.binaryDirectory = dirname
+ info.binaryName = filename
+ info.binaryPath = path
+ info.version = "-"
+
+ info.installName = path
+ info.deployedInstallName = "@executable_path/../Frameworks/" + info.binaryName
+ info.sourceFilePath = path
+ info.destinationDirectory = cls.bundleFrameworkDirectory
+ else:
+ parts = path.split("/")
+ i = 0
+ # Search for the .framework directory
+ for part in parts:
+ if part.endswith(".framework"):
+ break
+ i += 1
+ if i == len(parts):
+ raise RuntimeError("Could not find .framework or .dylib in otool line: " + line)
+
+ info.frameworkName = parts[i]
+ info.frameworkDirectory = "/".join(parts[:i])
+ info.frameworkPath = os.path.join(info.frameworkDirectory, info.frameworkName)
+
+ info.binaryName = parts[i+3]
+ info.binaryDirectory = "/".join(parts[i+1:i+3])
+ info.binaryPath = os.path.join(info.binaryDirectory, info.binaryName)
+ info.version = parts[i+2]
+
+ info.deployedInstallName = "@executable_path/../Frameworks/" + os.path.join(info.frameworkName, info.binaryPath)
+ info.destinationDirectory = os.path.join(cls.bundleFrameworkDirectory, info.frameworkName, info.binaryDirectory)
+
+ info.sourceResourcesDirectory = os.path.join(info.frameworkPath, "Resources")
+ info.sourceContentsDirectory = os.path.join(info.frameworkPath, "Contents")
+ info.sourceVersionContentsDirectory = os.path.join(info.frameworkPath, "Versions", info.version, "Contents")
+ info.destinationResourcesDirectory = os.path.join(cls.bundleFrameworkDirectory, info.frameworkName, "Resources")
+ info.destinationContentsDirectory = os.path.join(cls.bundleFrameworkDirectory, info.frameworkName, "Contents")
+ info.destinationVersionContentsDirectory = os.path.join(cls.bundleFrameworkDirectory, info.frameworkName, "Versions", info.version, "Contents")
+
+ return info
+
+class ApplicationBundleInfo(object):
+ def __init__(self, path):
+ self.path = path
+ appName = "Defi-Qt"
+ self.binaryPath = os.path.join(path, "Contents", "MacOS", appName)
+ if not os.path.exists(self.binaryPath):
+ raise RuntimeError("Could not find bundle binary for " + path)
+ self.resourcesPath = os.path.join(path, "Contents", "Resources")
+ self.pluginPath = os.path.join(path, "Contents", "PlugIns")
+
+class DeploymentInfo(object):
+ def __init__(self):
+ self.qtPath = None
+ self.pluginPath = None
+ self.deployedFrameworks = []
+
+ def detectQtPath(self, frameworkDirectory):
+ parentDir = os.path.dirname(frameworkDirectory)
+ if os.path.exists(os.path.join(parentDir, "translations")):
+ # Classic layout, e.g. "/usr/local/Trolltech/Qt-4.x.x"
+ self.qtPath = parentDir
+ else:
+ self.qtPath = os.getenv("QTDIR", None)
+
+ if self.qtPath is not None:
+ pluginPath = os.path.join(self.qtPath, "plugins")
+ if os.path.exists(pluginPath):
+ self.pluginPath = pluginPath
+
+ def usesFramework(self, name):
+ nameDot = "%s." % name
+ libNameDot = "lib%s." % name
+ for framework in self.deployedFrameworks:
+ if framework.endswith(".framework"):
+ if framework.startswith(nameDot):
+ return True
+ elif framework.endswith(".dylib"):
+ if framework.startswith(libNameDot):
+ return True
+ return False
+
+def getFrameworks(binaryPath, verbose):
+ if verbose >= 3:
+ print("Inspecting with otool: " + binaryPath)
+ otoolbin=os.getenv("OTOOL", "otool")
+ otool = subprocess.Popen([otoolbin, "-L", binaryPath], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
+ o_stdout, o_stderr = otool.communicate()
+ if otool.returncode != 0:
+ if verbose >= 1:
+ sys.stderr.write(o_stderr)
+ sys.stderr.flush()
+ raise RuntimeError("otool failed with return code %d" % otool.returncode)
+
+ otoolLines = o_stdout.split("\n")
+ otoolLines.pop(0) # First line is the inspected binary
+ if ".framework" in binaryPath or binaryPath.endswith(".dylib"):
+ otoolLines.pop(0) # Frameworks and dylibs list themselves as a dependency.
+
+ libraries = []
+ for line in otoolLines:
+ line = line.replace("@loader_path", os.path.dirname(binaryPath))
+ info = FrameworkInfo.fromOtoolLibraryLine(line.strip())
+ if info is not None:
+ if verbose >= 3:
+ print("Found framework:")
+ print(info)
+ libraries.append(info)
+
+ return libraries
+
+def runInstallNameTool(action, *args):
+ installnametoolbin=os.getenv("INSTALLNAMETOOL", "install_name_tool")
+ subprocess.check_call([installnametoolbin, "-"+action] + list(args))
+
+def changeInstallName(oldName, newName, binaryPath, verbose):
+ if verbose >= 3:
+ print("Using install_name_tool:")
+ print(" in", binaryPath)
+ print(" change reference", oldName)
+ print(" to", newName)
+ runInstallNameTool("change", oldName, newName, binaryPath)
+
+def changeIdentification(id, binaryPath, verbose):
+ if verbose >= 3:
+ print("Using install_name_tool:")
+ print(" change identification in", binaryPath)
+ print(" to", id)
+ runInstallNameTool("id", id, binaryPath)
+
+def runStrip(binaryPath, verbose):
+ stripbin=os.getenv("STRIP", "strip")
+ if verbose >= 3:
+ print("Using strip:")
+ print(" stripped", binaryPath)
+ subprocess.check_call([stripbin, "-x", binaryPath])
+
+def copyFramework(framework, path, verbose):
+ if framework.sourceFilePath.startswith("Qt"):
+ #standard place for Nokia Qt installer's frameworks
+ fromPath = "/Library/Frameworks/" + framework.sourceFilePath
+ else:
+ fromPath = framework.sourceFilePath
+ toDir = os.path.join(path, framework.destinationDirectory)
+ toPath = os.path.join(toDir, framework.binaryName)
+
+ if not os.path.exists(fromPath):
+ raise RuntimeError("No file at " + fromPath)
+
+ if os.path.exists(toPath):
+ return None # Already there
+
+ if not os.path.exists(toDir):
+ os.makedirs(toDir)
+
+ shutil.copy2(fromPath, toPath)
+ if verbose >= 3:
+ print("Copied:", fromPath)
+ print(" to:", toPath)
+
+ permissions = os.stat(toPath)
+ if not permissions.st_mode & stat.S_IWRITE:
+ os.chmod(toPath, permissions.st_mode | stat.S_IWRITE)
+
+ if not framework.isDylib(): # Copy resources for real frameworks
+
+ linkfrom = os.path.join(path, "Contents","Frameworks", framework.frameworkName, "Versions", "Current")
+ linkto = framework.version
+ if not os.path.exists(linkfrom):
+ os.symlink(linkto, linkfrom)
+ if verbose >= 2:
+ print("Linked:", linkfrom, "->", linkto)
+ fromResourcesDir = framework.sourceResourcesDirectory
+ if os.path.exists(fromResourcesDir):
+ toResourcesDir = os.path.join(path, framework.destinationResourcesDirectory)
+ shutil.copytree(fromResourcesDir, toResourcesDir, symlinks=True)
+ if verbose >= 3:
+ print("Copied resources:", fromResourcesDir)
+ print(" to:", toResourcesDir)
+ fromContentsDir = framework.sourceVersionContentsDirectory
+ if not os.path.exists(fromContentsDir):
+ fromContentsDir = framework.sourceContentsDirectory
+ if os.path.exists(fromContentsDir):
+ toContentsDir = os.path.join(path, framework.destinationVersionContentsDirectory)
+ shutil.copytree(fromContentsDir, toContentsDir, symlinks=True)
+ if verbose >= 3:
+ print("Copied Contents:", fromContentsDir)
+ print(" to:", toContentsDir)
+ elif framework.frameworkName.startswith("libQtGui"): # Copy qt_menu.nib (applies to non-framework layout)
+ qtMenuNibSourcePath = os.path.join(framework.frameworkDirectory, "Resources", "qt_menu.nib")
+ qtMenuNibDestinationPath = os.path.join(path, "Contents", "Resources", "qt_menu.nib")
+ if os.path.exists(qtMenuNibSourcePath) and not os.path.exists(qtMenuNibDestinationPath):
+ shutil.copytree(qtMenuNibSourcePath, qtMenuNibDestinationPath, symlinks=True)
+ if verbose >= 3:
+ print("Copied for libQtGui:", qtMenuNibSourcePath)
+ print(" to:", qtMenuNibDestinationPath)
+
+ return toPath
+
+def deployFrameworks(frameworks, bundlePath, binaryPath, strip, verbose, deploymentInfo=None):
+ if deploymentInfo is None:
+ deploymentInfo = DeploymentInfo()
+
+ while len(frameworks) > 0:
+ framework = frameworks.pop(0)
+ deploymentInfo.deployedFrameworks.append(framework.frameworkName)
+
+ if verbose >= 2:
+ print("Processing", framework.frameworkName, "...")
+
+ # Get the Qt path from one of the Qt frameworks
+ if deploymentInfo.qtPath is None and framework.isQtFramework():
+ deploymentInfo.detectQtPath(framework.frameworkDirectory)
+
+ if framework.installName.startswith("@executable_path") or framework.installName.startswith(bundlePath):
+ if verbose >= 2:
+ print(framework.frameworkName, "already deployed, skipping.")
+ continue
+
+ # install_name_tool the new id into the binary
+ changeInstallName(framework.installName, framework.deployedInstallName, binaryPath, verbose)
+
+ # Copy framework to app bundle.
+ deployedBinaryPath = copyFramework(framework, bundlePath, verbose)
+ # Skip the rest if already was deployed.
+ if deployedBinaryPath is None:
+ continue
+
+ if strip:
+ runStrip(deployedBinaryPath, verbose)
+
+ # install_name_tool it a new id.
+ changeIdentification(framework.deployedInstallName, deployedBinaryPath, verbose)
+ # Check for framework dependencies
+ dependencies = getFrameworks(deployedBinaryPath, verbose)
+
+ for dependency in dependencies:
+ changeInstallName(dependency.installName, dependency.deployedInstallName, deployedBinaryPath, verbose)
+
+ # Deploy framework if necessary.
+ if dependency.frameworkName not in deploymentInfo.deployedFrameworks and dependency not in frameworks:
+ frameworks.append(dependency)
+
+ return deploymentInfo
+
+def deployFrameworksForAppBundle(applicationBundle, strip, verbose):
+ frameworks = getFrameworks(applicationBundle.binaryPath, verbose)
+ if len(frameworks) == 0 and verbose >= 1:
+ print("Warning: Could not find any external frameworks to deploy in %s." % (applicationBundle.path))
+ return DeploymentInfo()
+ else:
+ return deployFrameworks(frameworks, applicationBundle.path, applicationBundle.binaryPath, strip, verbose)
+
+def deployPlugins(appBundleInfo, deploymentInfo, strip, verbose):
+ # Lookup available plugins, exclude unneeded
+ plugins = []
+ if deploymentInfo.pluginPath is None:
+ return
+ for dirpath, dirnames, filenames in os.walk(deploymentInfo.pluginPath):
+ pluginDirectory = os.path.relpath(dirpath, deploymentInfo.pluginPath)
+ if pluginDirectory == "designer":
+ # Skip designer plugins
+ continue
+ elif pluginDirectory == "phonon" or pluginDirectory == "phonon_backend":
+ # Deploy the phonon plugins only if phonon is in use
+ if not deploymentInfo.usesFramework("phonon"):
+ continue
+ elif pluginDirectory == "sqldrivers":
+ # Deploy the sql plugins only if QtSql is in use
+ if not deploymentInfo.usesFramework("QtSql"):
+ continue
+ elif pluginDirectory == "script":
+ # Deploy the script plugins only if QtScript is in use
+ if not deploymentInfo.usesFramework("QtScript"):
+ continue
+ elif pluginDirectory == "qmltooling" or pluginDirectory == "qml1tooling":
+ # Deploy the qml plugins only if QtDeclarative is in use
+ if not deploymentInfo.usesFramework("QtDeclarative"):
+ continue
+ elif pluginDirectory == "bearer":
+ # Deploy the bearer plugins only if QtNetwork is in use
+ if not deploymentInfo.usesFramework("QtNetwork"):
+ continue
+ elif pluginDirectory == "position":
+ # Deploy the position plugins only if QtPositioning is in use
+ if not deploymentInfo.usesFramework("QtPositioning"):
+ continue
+ elif pluginDirectory == "sensors" or pluginDirectory == "sensorgestures":
+ # Deploy the sensor plugins only if QtSensors is in use
+ if not deploymentInfo.usesFramework("QtSensors"):
+ continue
+ elif pluginDirectory == "audio" or pluginDirectory == "playlistformats":
+ # Deploy the audio plugins only if QtMultimedia is in use
+ if not deploymentInfo.usesFramework("QtMultimedia"):
+ continue
+ elif pluginDirectory == "mediaservice":
+ # Deploy the mediaservice plugins only if QtMultimediaWidgets is in use
+ if not deploymentInfo.usesFramework("QtMultimediaWidgets"):
+ continue
+
+ for pluginName in filenames:
+ pluginPath = os.path.join(pluginDirectory, pluginName)
+ if pluginName.endswith("_debug.dylib"):
+ # Skip debug plugins
+ continue
+ elif pluginPath == "imageformats/libqsvg.dylib" or pluginPath == "iconengines/libqsvgicon.dylib":
+ # Deploy the svg plugins only if QtSvg is in use
+ if not deploymentInfo.usesFramework("QtSvg"):
+ continue
+ elif pluginPath == "accessible/libqtaccessiblecompatwidgets.dylib":
+ # Deploy accessibility for Qt3Support only if the Qt3Support is in use
+ if not deploymentInfo.usesFramework("Qt3Support"):
+ continue
+ elif pluginPath == "graphicssystems/libqglgraphicssystem.dylib":
+ # Deploy the opengl graphicssystem plugin only if QtOpenGL is in use
+ if not deploymentInfo.usesFramework("QtOpenGL"):
+ continue
+ elif pluginPath == "accessible/libqtaccessiblequick.dylib":
+ # Deploy the accessible qtquick plugin only if QtQuick is in use
+ if not deploymentInfo.usesFramework("QtQuick"):
+ continue
+
+ plugins.append((pluginDirectory, pluginName))
+
+ for pluginDirectory, pluginName in plugins:
+ if verbose >= 2:
+ print("Processing plugin", os.path.join(pluginDirectory, pluginName), "...")
+
+ sourcePath = os.path.join(deploymentInfo.pluginPath, pluginDirectory, pluginName)
+ destinationDirectory = os.path.join(appBundleInfo.pluginPath, pluginDirectory)
+ if not os.path.exists(destinationDirectory):
+ os.makedirs(destinationDirectory)
+
+ destinationPath = os.path.join(destinationDirectory, pluginName)
+ shutil.copy2(sourcePath, destinationPath)
+ if verbose >= 3:
+ print("Copied:", sourcePath)
+ print(" to:", destinationPath)
+
+ if strip:
+ runStrip(destinationPath, verbose)
+
+ dependencies = getFrameworks(destinationPath, verbose)
+
+ for dependency in dependencies:
+ changeInstallName(dependency.installName, dependency.deployedInstallName, destinationPath, verbose)
+
+ # Deploy framework if necessary.
+ if dependency.frameworkName not in deploymentInfo.deployedFrameworks:
+ deployFrameworks([dependency], appBundleInfo.path, destinationPath, strip, verbose, deploymentInfo)
+
+qt_conf="""[Paths]
+Translations=Resources
+Plugins=PlugIns
+"""
+
+ap = ArgumentParser(description="""Improved version of macdeployqt.
+
+Outputs a ready-to-deploy app in a folder "dist" and optionally wraps it in a .dmg file.
+Note, that the "dist" folder will be deleted before deploying on each run.
+
+Optionally, Qt translation files (.qm) and additional resources can be added to the bundle.
+
+Also optionally signs the .app bundle; set the CODESIGNARGS environment variable to pass arguments
+to the codesign tool.
+E.g. CODESIGNARGS='--sign "Developer ID Application: ..." --keychain /encrypted/foo.keychain'""")
+
+ap.add_argument("app_bundle", nargs=1, metavar="app-bundle", help="application bundle to be deployed")
+ap.add_argument("-verbose", type=int, nargs=1, default=[1], metavar="<0-3>", help="0 = no output, 1 = error/warning (default), 2 = normal, 3 = debug")
+ap.add_argument("-no-plugins", dest="plugins", action="store_false", default=True, help="skip plugin deployment")
+ap.add_argument("-no-strip", dest="strip", action="store_false", default=True, help="don't run 'strip' on the binaries")
+ap.add_argument("-sign", dest="sign", action="store_true", default=False, help="sign .app bundle with codesign tool")
+ap.add_argument("-dmg", nargs="?", const="", metavar="basename", help="create a .dmg disk image; if basename is not specified, a camel-cased version of the app name is used")
+ap.add_argument("-fancy", nargs=1, metavar="plist", default=[], help="make a fancy looking disk image using the given plist file with instructions; requires -dmg to work")
+ap.add_argument("-add-qt-tr", nargs=1, metavar="languages", default=[], help="add Qt translation files to the bundle's resources; the language list must be separated with commas, not with whitespace")
+ap.add_argument("-translations-dir", nargs=1, metavar="path", default=None, help="Path to Qt's translation files")
+ap.add_argument("-add-resources", nargs="+", metavar="path", default=[], help="list of additional files or folders to be copied into the bundle's resources; must be the last argument")
+ap.add_argument("-volname", nargs=1, metavar="volname", default=[], help="custom volume name for dmg")
+
+config = ap.parse_args()
+
+verbose = config.verbose[0]
+
+# ------------------------------------------------
+
+app_bundle = config.app_bundle[0]
+
+if not os.path.exists(app_bundle):
+ if verbose >= 1:
+ sys.stderr.write("Error: Could not find app bundle \"%s\"\n" % (app_bundle))
+ sys.exit(1)
+
+app_bundle_name = os.path.splitext(os.path.basename(app_bundle))[0]
+
+# ------------------------------------------------
+translations_dir = None
+if config.translations_dir and config.translations_dir[0]:
+ if os.path.exists(config.translations_dir[0]):
+ translations_dir = config.translations_dir[0]
+ else:
+ if verbose >= 1:
+ sys.stderr.write("Error: Could not find translation dir \"%s\"\n" % (translations_dir))
+ sys.exit(1)
+# ------------------------------------------------
+
+for p in config.add_resources:
+ if verbose >= 3:
+ print("Checking for \"%s\"..." % p)
+ if not os.path.exists(p):
+ if verbose >= 1:
+ sys.stderr.write("Error: Could not find additional resource file \"%s\"\n" % (p))
+ sys.exit(1)
+
+# ------------------------------------------------
+
+if len(config.fancy) == 1:
+ if verbose >= 3:
+ print("Fancy: Importing plistlib...")
+ try:
+ import plistlib
+ except ImportError:
+ if verbose >= 1:
+ sys.stderr.write("Error: Could not import plistlib which is required for fancy disk images.\n")
+ sys.exit(1)
+
+ p = config.fancy[0]
+ if verbose >= 3:
+ print("Fancy: Loading \"%s\"..." % p)
+ if not os.path.exists(p):
+ if verbose >= 1:
+ sys.stderr.write("Error: Could not find fancy disk image plist at \"%s\"\n" % (p))
+ sys.exit(1)
+
+ try:
+ fancy = plistlib.readPlist(p)
+ except:
+ if verbose >= 1:
+ sys.stderr.write("Error: Could not parse fancy disk image plist at \"%s\"\n" % (p))
+ sys.exit(1)
+
+ try:
+ assert "window_bounds" not in fancy or (isinstance(fancy["window_bounds"], list) and len(fancy["window_bounds"]) == 4)
+ assert "background_picture" not in fancy or isinstance(fancy["background_picture"], str)
+ assert "icon_size" not in fancy or isinstance(fancy["icon_size"], int)
+ assert "applications_symlink" not in fancy or isinstance(fancy["applications_symlink"], bool)
+ if "items_position" in fancy:
+ assert isinstance(fancy["items_position"], dict)
+ for key, value in fancy["items_position"].items():
+ assert isinstance(value, list) and len(value) == 2 and isinstance(value[0], int) and isinstance(value[1], int)
+ except:
+ if verbose >= 1:
+ sys.stderr.write("Error: Bad format of fancy disk image plist at \"%s\"\n" % (p))
+ sys.exit(1)
+
+ if "background_picture" in fancy:
+ bp = fancy["background_picture"]
+ if verbose >= 3:
+ print("Fancy: Resolving background picture \"%s\"..." % bp)
+ if not os.path.exists(bp):
+ bp = os.path.join(os.path.dirname(p), bp)
+ if not os.path.exists(bp):
+ if verbose >= 1:
+ sys.stderr.write("Error: Could not find background picture at \"%s\" or \"%s\"\n" % (fancy["background_picture"], bp))
+ sys.exit(1)
+ else:
+ fancy["background_picture"] = bp
+else:
+ fancy = None
+
+# ------------------------------------------------
+
+if os.path.exists("dist"):
+ if verbose >= 2:
+ print("+ Removing old dist folder +")
+
+ shutil.rmtree("dist")
+
+# ------------------------------------------------
+
+if len(config.volname) == 1:
+ volname = config.volname[0]
+else:
+ volname = app_bundle_name
+
+# ------------------------------------------------
+
+target = os.path.join("dist", "Defi-Qt.app")
+
+if verbose >= 2:
+ print("+ Copying source bundle +")
+if verbose >= 3:
+ print(app_bundle, "->", target)
+
+os.mkdir("dist")
+shutil.copytree(app_bundle, target, symlinks=True)
+
+applicationBundle = ApplicationBundleInfo(target)
+
+# ------------------------------------------------
+
+if verbose >= 2:
+ print("+ Deploying frameworks +")
+
+try:
+ deploymentInfo = deployFrameworksForAppBundle(applicationBundle, config.strip, verbose)
+ if deploymentInfo.qtPath is None:
+ deploymentInfo.qtPath = os.getenv("QTDIR", None)
+ if deploymentInfo.qtPath is None:
+ if verbose >= 1:
+ sys.stderr.write("Warning: Could not detect Qt's path, skipping plugin deployment!\n")
+ config.plugins = False
+except RuntimeError as e:
+ if verbose >= 1:
+ sys.stderr.write("Error: %s\n" % str(e))
+ sys.exit(1)
+
+# ------------------------------------------------
+
+if config.plugins:
+ if verbose >= 2:
+ print("+ Deploying plugins +")
+
+ try:
+ deployPlugins(applicationBundle, deploymentInfo, config.strip, verbose)
+ except RuntimeError as e:
+ if verbose >= 1:
+ sys.stderr.write("Error: %s\n" % str(e))
+ sys.exit(1)
+
+# ------------------------------------------------
+
+if len(config.add_qt_tr) == 0:
+ add_qt_tr = []
+else:
+ if translations_dir is not None:
+ qt_tr_dir = translations_dir
+ else:
+ if deploymentInfo.qtPath is not None:
+ qt_tr_dir = os.path.join(deploymentInfo.qtPath, "translations")
+ else:
+ sys.stderr.write("Error: Could not find Qt translation path\n")
+ sys.exit(1)
+ add_qt_tr = ["qt_%s.qm" % lng for lng in config.add_qt_tr[0].split(",")]
+ for lng_file in add_qt_tr:
+ p = os.path.join(qt_tr_dir, lng_file)
+ if verbose >= 3:
+ print("Checking for \"%s\"..." % p)
+ if not os.path.exists(p):
+ if verbose >= 1:
+ sys.stderr.write("Error: Could not find Qt translation file \"%s\"\n" % (lng_file))
+ sys.exit(1)
+
+# ------------------------------------------------
+
+if verbose >= 2:
+ print("+ Installing qt.conf +")
+
+with open(os.path.join(applicationBundle.resourcesPath, "qt.conf"), "wb") as f:
+ f.write(qt_conf.encode())
+
+# ------------------------------------------------
+
+if len(add_qt_tr) > 0 and verbose >= 2:
+ print("+ Adding Qt translations +")
+
+for lng_file in add_qt_tr:
+ if verbose >= 3:
+ print(os.path.join(qt_tr_dir, lng_file), "->", os.path.join(applicationBundle.resourcesPath, lng_file))
+ shutil.copy2(os.path.join(qt_tr_dir, lng_file), os.path.join(applicationBundle.resourcesPath, lng_file))
+
+# ------------------------------------------------
+
+if len(config.add_resources) > 0 and verbose >= 2:
+ print("+ Adding additional resources +")
+
+for p in config.add_resources:
+ t = os.path.join(applicationBundle.resourcesPath, os.path.basename(p))
+ if verbose >= 3:
+ print(p, "->", t)
+ if os.path.isdir(p):
+ shutil.copytree(p, t, symlinks=True)
+ else:
+ shutil.copy2(p, t)
+
+# ------------------------------------------------
+
+if config.sign and 'CODESIGNARGS' not in os.environ:
+ print("You must set the CODESIGNARGS environment variable. Skipping signing.")
+elif config.sign:
+ if verbose >= 1:
+ print("Code-signing app bundle %s"%(target,))
+ subprocess.check_call("codesign --force %s %s"%(os.environ['CODESIGNARGS'], target), shell=True)
+
+# ------------------------------------------------
+
+if config.dmg is not None:
+
+ def runHDIUtil(verb, image_basename, **kwargs):
+ hdiutil_args = ["hdiutil", verb, image_basename + ".dmg"]
+ if "capture_stdout" in kwargs:
+ del kwargs["capture_stdout"]
+ run = subprocess.check_output
+ else:
+ if verbose < 2:
+ hdiutil_args.append("-quiet")
+ elif verbose >= 3:
+ hdiutil_args.append("-verbose")
+ run = subprocess.check_call
+
+ for key, value in kwargs.items():
+ hdiutil_args.append("-" + key)
+ if not value is True:
+ hdiutil_args.append(str(value))
+
+ return run(hdiutil_args, universal_newlines=True)
+
+ if verbose >= 2:
+ if fancy is None:
+ print("+ Creating .dmg disk image +")
+ else:
+ print("+ Preparing .dmg disk image +")
+
+ if config.dmg != "":
+ dmg_name = config.dmg
+ else:
+ spl = app_bundle_name.split(" ")
+ dmg_name = spl[0] + "".join(p.capitalize() for p in spl[1:])
+
+ if fancy is None:
+ try:
+ runHDIUtil("create", dmg_name, srcfolder="dist", format="UDBZ", volname=volname, ov=True)
+ except subprocess.CalledProcessError as e:
+ sys.exit(e.returncode)
+ else:
+ if verbose >= 3:
+ print("Determining size of \"dist\"...")
+ size = 0
+ for path, dirs, files in os.walk("dist"):
+ for file in files:
+ size += os.path.getsize(os.path.join(path, file))
+ size += int(size * 0.15)
+
+ if verbose >= 3:
+ print("Creating temp image for modification...")
+ try:
+ runHDIUtil("create", dmg_name + ".temp", srcfolder="dist", format="UDRW", size=size, volname=volname, ov=True)
+ except subprocess.CalledProcessError as e:
+ sys.exit(e.returncode)
+
+ if verbose >= 3:
+ print("Attaching temp image...")
+ try:
+ output = runHDIUtil("attach", dmg_name + ".temp", readwrite=True, noverify=True, noautoopen=True, capture_stdout=True)
+ except subprocess.CalledProcessError as e:
+ sys.exit(e.returncode)
+
+ m = re.search("/Volumes/(.+$)", output)
+ disk_root = m.group(0)
+ disk_name = m.group(1)
+
+ if verbose >= 2:
+ print("+ Applying fancy settings +")
+
+ if "background_picture" in fancy:
+ bg_path = os.path.join(disk_root, ".background", os.path.basename(fancy["background_picture"]))
+ os.mkdir(os.path.dirname(bg_path))
+ if verbose >= 3:
+ print(fancy["background_picture"], "->", bg_path)
+ shutil.copy2(fancy["background_picture"], bg_path)
+ else:
+ bg_path = None
+
+ if fancy.get("applications_symlink", False):
+ os.symlink("/Applications", os.path.join(disk_root, "Applications"))
+
+ # The Python appscript package broke with OSX 10.8 and isn't being fixed.
+ # So we now build up an AppleScript string and use the osascript command
+ # to make the .dmg file pretty:
+ appscript = Template( """
+ on run argv
+ tell application "Finder"
+ tell disk "$disk"
+ open
+ set current view of container window to icon view
+ set toolbar visible of container window to false
+ set statusbar visible of container window to false
+ set the bounds of container window to {$window_bounds}
+ set theViewOptions to the icon view options of container window
+ set arrangement of theViewOptions to not arranged
+ set icon size of theViewOptions to $icon_size
+ $background_commands
+ $items_positions
+ close -- close/reopen works around a bug...
+ open
+ update without registering applications
+ delay 5
+ eject
+ end tell
+ end tell
+ end run
+ """)
+
+ itemscript = Template('set position of item "${item}" of container window to {${position}}')
+ items_positions = []
+ if "items_position" in fancy:
+ for name, position in fancy["items_position"].items():
+ params = { "item" : name, "position" : ",".join([str(p) for p in position]) }
+ items_positions.append(itemscript.substitute(params))
+
+ params = {
+ "disk" : volname,
+ "window_bounds" : "300,300,800,620",
+ "icon_size" : "96",
+ "background_commands" : "",
+ "items_positions" : "\n ".join(items_positions)
+ }
+ if "window_bounds" in fancy:
+ params["window_bounds"] = ",".join([str(p) for p in fancy["window_bounds"]])
+ if "icon_size" in fancy:
+ params["icon_size"] = str(fancy["icon_size"])
+ if bg_path is not None:
+ # Set background file, then call SetFile to make it invisible.
+ # (note: making it invisible first makes set background picture fail)
+ bgscript = Template("""set background picture of theViewOptions to file ".background:$bgpic"
+ do shell script "SetFile -a V /Volumes/$disk/.background/$bgpic" """)
+ params["background_commands"] = bgscript.substitute({"bgpic" : os.path.basename(bg_path), "disk" : params["disk"]})
+
+ s = appscript.substitute(params)
+ if verbose >= 2:
+ print("Running AppleScript:")
+ print(s)
+
+ p = subprocess.Popen(['osascript', '-'], stdin=subprocess.PIPE)
+ p.communicate(input=s.encode('utf-8'))
+ if p.returncode:
+ print("Error running osascript.")
+
+ if verbose >= 2:
+ print("+ Finalizing .dmg disk image +")
+ time.sleep(5)
+
+ try:
+ runHDIUtil("convert", dmg_name + ".temp", format="UDBZ", o=dmg_name + ".dmg", ov=True)
+ except subprocess.CalledProcessError as e:
+ sys.exit(e.returncode)
+
+ os.unlink(dmg_name + ".temp.dmg")
+
+# ------------------------------------------------
+
+if verbose >= 2:
+ print("+ Done +")
+
+sys.exit(0)
diff --git a/contrib/qos/README.md b/contrib/qos/README.md
new file mode 100644
index 0000000000..dd9c62eb65
--- /dev/null
+++ b/contrib/qos/README.md
@@ -0,0 +1,5 @@
+### QoS (Quality of service) ###
+
+This is a Linux bash script that will set up tc to limit the outgoing bandwidth for connections to the Defi network. It limits outbound TCP traffic with a source or destination port of 8555, but not if the destination IP is within a LAN.
+
+This means one can have an always-on defid instance running, and another local defid/defi-qt instance which connects to this node and receives blocks from it.
diff --git a/contrib/qos/tc.sh b/contrib/qos/tc.sh
new file mode 100644
index 0000000000..46a78c68bd
--- /dev/null
+++ b/contrib/qos/tc.sh
@@ -0,0 +1,62 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2017 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+#network interface on which to limit traffic
+IF="eth0"
+#limit of the network interface in question
+LINKCEIL="1gbit"
+#limit outbound network protocol traffic to this rate
+LIMIT="160kbit"
+#defines the IPv4 address space for which you wish to disable rate limiting
+LOCALNET_V4="192.168.0.0/16"
+#defines the IPv6 address space for which you wish to disable rate limiting
+LOCALNET_V6="fe80::/10"
+
+#delete existing rules
+tc qdisc del dev ${IF} root
+
+#add root class
+tc qdisc add dev ${IF} root handle 1: htb default 10
+
+#add parent class
+tc class add dev ${IF} parent 1: classid 1:1 htb rate ${LINKCEIL} ceil ${LINKCEIL}
+
+#add our two classes. one unlimited, another limited
+tc class add dev ${IF} parent 1:1 classid 1:10 htb rate ${LINKCEIL} ceil ${LINKCEIL} prio 0
+tc class add dev ${IF} parent 1:1 classid 1:11 htb rate ${LIMIT} ceil ${LIMIT} prio 1
+
+#add handles to our classes so packets marked with go into the class with "... handle fw ..."
+tc filter add dev ${IF} parent 1: protocol ip prio 1 handle 1 fw classid 1:10
+tc filter add dev ${IF} parent 1: protocol ip prio 2 handle 2 fw classid 1:11
+
+if [ -n "${LOCALNET_V6}" ] ; then
+ # v6 cannot have the same priority value as v4
+ tc filter add dev ${IF} parent 1: protocol ipv6 prio 3 handle 1 fw classid 1:10
+ tc filter add dev ${IF} parent 1: protocol ipv6 prio 4 handle 2 fw classid 1:11
+fi
+
+#delete any existing rules
+#disable for now
+#ret=0
+#while [ $ret -eq 0 ]; do
+# iptables -t mangle -D OUTPUT 1
+# ret=$?
+#done
+
+#limit outgoing traffic to and from port 8555. but not when dealing with a host on the local network
+# (defined by $LOCALNET_V4 and $LOCALNET_V6)
+# --set-mark marks packages matching these criteria with the number "2" (v4)
+# --set-mark marks packages matching these criteria with the number "4" (v6)
+# these packets are filtered by the tc filter with "handle 2"
+# this filter sends the packages into the 1:11 class, and this class is limited to ${LIMIT}
+iptables -t mangle -A OUTPUT -p tcp -m tcp --dport 8555 ! -d ${LOCALNET_V4} -j MARK --set-mark 0x2
+iptables -t mangle -A OUTPUT -p tcp -m tcp --sport 8555 ! -d ${LOCALNET_V4} -j MARK --set-mark 0x2
+
+if [ -n "${LOCALNET_V6}" ] ; then
+ ip6tables -t mangle -A OUTPUT -p tcp -m tcp --dport 8555 ! -d ${LOCALNET_V6} -j MARK --set-mark 0x4
+ ip6tables -t mangle -A OUTPUT -p tcp -m tcp --sport 8555 ! -d ${LOCALNET_V6} -j MARK --set-mark 0x4
+fi
diff --git a/contrib/seeds/README.md b/contrib/seeds/README.md
new file mode 100644
index 0000000000..502c20d0d6
--- /dev/null
+++ b/contrib/seeds/README.md
@@ -0,0 +1,21 @@
+# Seeds
+
+Utility to generate the seeds.txt list that is compiled into the client
+(see [src/chainparamsseeds.h](/src/chainparamsseeds.h) and other utilities in [contrib/seeds](/contrib/seeds)).
+
+Be sure to update `PATTERN_AGENT` in `makeseeds.py` to include the current version,
+and remove old versions as necessary (at a minimum when GetDesirableServiceFlags
+changes its default return value, as those are the services which seeds are added
+to addrman with).
+
+The seeds compiled into the release are created from sipa's DNS seed data, like this:
+
+ curl -s http://bitcoin.sipa.be/seeds.txt.gz | gzip -dc > seeds_main.txt
+ python3 makeseeds.py < seeds_main.txt > nodes_main.txt
+ python3 generate-seeds.py . > ../../src/chainparamsseeds.h
+
+## Dependencies
+
+Ubuntu:
+
+ sudo apt-get install python3-dnspython
diff --git a/contrib/seeds/generate-seeds.py b/contrib/seeds/generate-seeds.py
new file mode 100755
index 0000000000..5fc19a37c5
--- /dev/null
+++ b/contrib/seeds/generate-seeds.py
@@ -0,0 +1,139 @@
+#!/usr/bin/env python3
+# Copyright (c) 2014-2017 Wladimir J. van der Laan
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+'''
+Script to generate list of seed nodes for chainparams.cpp.
+
+This script expects two text files in the directory that is passed as an
+argument:
+
+ nodes_main.txt
+ nodes_test.txt
+
+These files must consist of lines in the format
+
+
+ :
+ []
+ []:
+ .onion
+ 0xDDBBCCAA (IPv4 little-endian old pnSeeds format)
+
+The output will be two data structures with the peers in binary format:
+
+ static SeedSpec6 pnSeed6_main[]={
+ ...
+ }
+ static SeedSpec6 pnSeed6_test[]={
+ ...
+ }
+
+These should be pasted into `src/chainparamsseeds.h`.
+'''
+
+from base64 import b32decode
+from binascii import a2b_hex
+import sys
+import os
+import re
+
+# ipv4 in ipv6 prefix
+pchIPv4 = bytearray([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff])
+# tor-specific ipv6 prefix
+pchOnionCat = bytearray([0xFD,0x87,0xD8,0x7E,0xEB,0x43])
+
+def name_to_ipv6(addr):
+ if len(addr)>6 and addr.endswith('.onion'):
+ vchAddr = b32decode(addr[0:-6], True)
+ if len(vchAddr) != 16-len(pchOnionCat):
+ raise ValueError('Invalid onion %s' % vchAddr)
+ return pchOnionCat + vchAddr
+ elif '.' in addr: # IPv4
+ return pchIPv4 + bytearray((int(x) for x in addr.split('.')))
+ elif ':' in addr: # IPv6
+ sub = [[], []] # prefix, suffix
+ x = 0
+ addr = addr.split(':')
+ for i,comp in enumerate(addr):
+ if comp == '':
+ if i == 0 or i == (len(addr)-1): # skip empty component at beginning or end
+ continue
+ x += 1 # :: skips to suffix
+ assert(x < 2)
+ else: # two bytes per component
+ val = int(comp, 16)
+ sub[x].append(val >> 8)
+ sub[x].append(val & 0xff)
+ nullbytes = 16 - len(sub[0]) - len(sub[1])
+ assert((x == 0 and nullbytes == 0) or (x == 1 and nullbytes > 0))
+ return bytearray(sub[0] + ([0] * nullbytes) + sub[1])
+ elif addr.startswith('0x'): # IPv4-in-little-endian
+ return pchIPv4 + bytearray(reversed(a2b_hex(addr[2:])))
+ else:
+ raise ValueError('Could not parse address %s' % addr)
+
+def parse_spec(s, defaultport):
+ match = re.match('\[([0-9a-fA-F:]+)\](?::([0-9]+))?$', s)
+ if match: # ipv6
+ host = match.group(1)
+ port = match.group(2)
+ elif s.count(':') > 1: # ipv6, no port
+ host = s
+ port = ''
+ else:
+ (host,_,port) = s.partition(':')
+
+ if not port:
+ port = defaultport
+ else:
+ port = int(port)
+
+ host = name_to_ipv6(host)
+
+ return (host,port)
+
+def process_nodes(g, f, structname, defaultport):
+ g.write('static SeedSpec6 %s[] = {\n' % structname)
+ first = True
+ for line in f:
+ comment = line.find('#')
+ if comment != -1:
+ line = line[0:comment]
+ line = line.strip()
+ if not line:
+ continue
+ if not first:
+ g.write(',\n')
+ first = False
+
+ (host,port) = parse_spec(line, defaultport)
+ hoststr = ','.join(('0x%02x' % b) for b in host)
+ g.write(' {{%s}, %i}' % (hoststr, port))
+ g.write('\n};\n')
+
+def main():
+ if len(sys.argv)<2:
+ print(('Usage: %s ' % sys.argv[0]), file=sys.stderr)
+ sys.exit(1)
+ g = sys.stdout
+ indir = sys.argv[1]
+ g.write('#ifndef DEFI_CHAINPARAMSSEEDS_H\n')
+ g.write('#define DEFI_CHAINPARAMSSEEDS_H\n')
+ g.write('/**\n')
+ g.write(' * List of fixed seed nodes for the DeFi Blockchain Network\n')
+ g.write(' * AUTOGENERATED by contrib/seeds/generate-seeds.py\n')
+ g.write(' *\n')
+ g.write(' * Each line contains a 16-byte IPv6 address and a port.\n')
+ g.write(' * IPv4 as well as onion addresses are wrapped inside an IPv6 address accordingly.\n')
+ g.write(' */\n')
+ with open(os.path.join(indir,'nodes_main.txt'), 'r', encoding="utf8") as f:
+ process_nodes(g, f, 'pnSeed6_main', 8555)
+ g.write('\n')
+ with open(os.path.join(indir,'nodes_test.txt'), 'r', encoding="utf8") as f:
+ process_nodes(g, f, 'pnSeed6_test', 18555)
+ g.write('#endif // DEFI_CHAINPARAMSSEEDS_H\n')
+
+if __name__ == '__main__':
+ main()
+
diff --git a/contrib/seeds/makeseeds.py b/contrib/seeds/makeseeds.py
new file mode 100755
index 0000000000..44158b76fa
--- /dev/null
+++ b/contrib/seeds/makeseeds.py
@@ -0,0 +1,181 @@
+#!/usr/bin/env python3
+# Copyright (c) 2013-2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#
+# Generate seeds.txt from Pieter's DNS seeder
+#
+
+import re
+import sys
+import dns.resolver
+import collections
+
+NSEEDS=512
+
+MAX_SEEDS_PER_ASN=2
+
+MIN_BLOCKS = 337600
+
+# These are hosts that have been observed to be behaving strangely (e.g.
+# aggressively connecting to every node).
+SUSPICIOUS_HOSTS = {
+ "130.211.129.106", "178.63.107.226",
+ "83.81.130.26", "88.198.17.7", "148.251.238.178", "176.9.46.6",
+ "54.173.72.127", "54.174.10.182", "54.183.64.54", "54.194.231.211",
+ "54.66.214.167", "54.66.220.137", "54.67.33.14", "54.77.251.214",
+ "54.94.195.96", "54.94.200.247"
+}
+
+PATTERN_IPV4 = re.compile(r"^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})):(\d+)$")
+PATTERN_IPV6 = re.compile(r"^\[([0-9a-z:]+)\]:(\d+)$")
+PATTERN_ONION = re.compile(r"^([abcdefghijklmnopqrstuvwxyz234567]{16}\.onion):(\d+)$")
+PATTERN_AGENT = re.compile(r"^(/Satoshi:0.14.(0|1|2|99)/|/Satoshi:0.15.(0|1|2|99)|/Satoshi:0.16.(0|1|2|99)/)$")
+
+def parseline(line):
+ sline = line.split()
+ if len(sline) < 11:
+ return None
+ m = PATTERN_IPV4.match(sline[0])
+ sortkey = None
+ ip = None
+ if m is None:
+ m = PATTERN_IPV6.match(sline[0])
+ if m is None:
+ m = PATTERN_ONION.match(sline[0])
+ if m is None:
+ return None
+ else:
+ net = 'onion'
+ ipstr = sortkey = m.group(1)
+ port = int(m.group(2))
+ else:
+ net = 'ipv6'
+ if m.group(1) in ['::']: # Not interested in localhost
+ return None
+ ipstr = m.group(1)
+ sortkey = ipstr # XXX parse IPv6 into number, could use name_to_ipv6 from generate-seeds
+ port = int(m.group(2))
+ else:
+ # Do IPv4 sanity check
+ ip = 0
+ for i in range(0,4):
+ if int(m.group(i+2)) < 0 or int(m.group(i+2)) > 255:
+ return None
+ ip = ip + (int(m.group(i+2)) << (8*(3-i)))
+ if ip == 0:
+ return None
+ net = 'ipv4'
+ sortkey = ip
+ ipstr = m.group(1)
+ port = int(m.group(6))
+ # Skip bad results.
+ if sline[1] == 0:
+ return None
+ # Extract uptime %.
+ uptime30 = float(sline[7][:-1])
+ # Extract Unix timestamp of last success.
+ lastsuccess = int(sline[2])
+ # Extract protocol version.
+ version = int(sline[10])
+ # Extract user agent.
+ agent = sline[11][1:-1]
+ # Extract service flags.
+ service = int(sline[9], 16)
+ # Extract blocks.
+ blocks = int(sline[8])
+ # Construct result.
+ return {
+ 'net': net,
+ 'ip': ipstr,
+ 'port': port,
+ 'ipnum': ip,
+ 'uptime': uptime30,
+ 'lastsuccess': lastsuccess,
+ 'version': version,
+ 'agent': agent,
+ 'service': service,
+ 'blocks': blocks,
+ 'sortkey': sortkey,
+ }
+
+def filtermultiport(ips):
+ '''Filter out hosts with more nodes per IP'''
+ hist = collections.defaultdict(list)
+ for ip in ips:
+ hist[ip['sortkey']].append(ip)
+ return [value[0] for (key,value) in list(hist.items()) if len(value)==1]
+
+# Based on Greg Maxwell's seed_filter.py
+def filterbyasn(ips, max_per_asn, max_total):
+ # Sift out ips by type
+ ips_ipv46 = [ip for ip in ips if ip['net'] in ['ipv4', 'ipv6']]
+ ips_onion = [ip for ip in ips if ip['net'] == 'onion']
+
+ # Filter IPv46 by ASN
+ result = []
+ asn_count = {}
+ for ip in ips_ipv46:
+ if len(result) == max_total:
+ break
+ try:
+ if ip['net'] == 'ipv4':
+ ipaddr = ip['ip']
+ prefix = '.origin'
+ else: # http://www.team-cymru.com/IP-ASN-mapping.html
+ res = str() # 2001:4860:b002:23::68
+ for nb in ip['ip'].split(':')[:4]: # pick the first 4 nibbles
+ for c in nb.zfill(4): # right padded with '0'
+ res += c + '.' # 2001 4860 b002 0023
+ ipaddr = res.rstrip('.') # 2.0.0.1.4.8.6.0.b.0.0.2.0.0.2.3
+ prefix = '.origin6'
+
+ asn = int([x.to_text() for x in dns.resolver.query('.'.join(
+ reversed(ipaddr.split('.'))) + prefix + '.asn.cymru.com',
+ 'TXT').response.answer][0].split('\"')[1].split(' ')[0])
+ if asn not in asn_count:
+ asn_count[asn] = 0
+ if asn_count[asn] == max_per_asn:
+ continue
+ asn_count[asn] += 1
+ result.append(ip)
+ except:
+ sys.stderr.write('ERR: Could not resolve ASN for "' + ip['ip'] + '"\n')
+
+ # Add back Onions
+ result.extend(ips_onion)
+ return result
+
+def main():
+ lines = sys.stdin.readlines()
+ ips = [parseline(line) for line in lines]
+
+ # Skip entries with valid address.
+ ips = [ip for ip in ips if ip is not None]
+ # Skip entries from suspicious hosts.
+ ips = [ip for ip in ips if ip['ip'] not in SUSPICIOUS_HOSTS]
+ # Enforce minimal number of blocks.
+ ips = [ip for ip in ips if ip['blocks'] >= MIN_BLOCKS]
+ # Require service bit 1.
+ ips = [ip for ip in ips if (ip['service'] & 1) == 1]
+ # Require at least 50% 30-day uptime.
+ ips = [ip for ip in ips if ip['uptime'] > 50]
+ # Require a known and recent user agent.
+ ips = [ip for ip in ips if PATTERN_AGENT.match(ip['agent'])]
+ # Sort by availability (and use last success as tie breaker)
+ ips.sort(key=lambda x: (x['uptime'], x['lastsuccess'], x['ip']), reverse=True)
+ # Filter out hosts with multiple defi ports, these are likely abusive
+ ips = filtermultiport(ips)
+ # Look up ASNs and limit results, both per ASN and globally.
+ ips = filterbyasn(ips, MAX_SEEDS_PER_ASN, NSEEDS)
+ # Sort the results by IP address (for deterministic output).
+ ips.sort(key=lambda x: (x['net'], x['sortkey']))
+
+ for ip in ips:
+ if ip['net'] == 'ipv6':
+ print('[%s]:%i' % (ip['ip'], ip['port']))
+ else:
+ print('%s:%i' % (ip['ip'], ip['port']))
+
+if __name__ == '__main__':
+ main()
diff --git a/contrib/seeds/nodes_main.txt b/contrib/seeds/nodes_main.txt
new file mode 100644
index 0000000000..199a81ee77
--- /dev/null
+++ b/contrib/seeds/nodes_main.txt
@@ -0,0 +1,10 @@
+172.104.167.85
+172.104.240.81
+172.105.33.148
+172.105.35.212
+172.105.3.107
+172.105.190.14
+45.56.78.40
+172.105.50.130
+23.239.19.243
+45.33.77.132
\ No newline at end of file
diff --git a/contrib/seeds/nodes_test.txt b/contrib/seeds/nodes_test.txt
new file mode 100644
index 0000000000..7a71c650d2
--- /dev/null
+++ b/contrib/seeds/nodes_test.txt
@@ -0,0 +1,5 @@
+45.79.125.250
+172.105.7.208
+172.105.172.215
+45.56.72.201
+172.105.49.33
diff --git a/contrib/testgen/README.md b/contrib/testgen/README.md
new file mode 100644
index 0000000000..b74a328a9e
--- /dev/null
+++ b/contrib/testgen/README.md
@@ -0,0 +1,8 @@
+### TestGen ###
+
+Utilities to generate test vectors for the data-driven Defi tests.
+
+Usage:
+
+ PYTHONPATH=../../test/functional/test_framework ./gen_key_io_test_vectors.py valid 50 > ../../src/test/data/key_io_keys_valid.json
+ PYTHONPATH=../../test/functional/test_framework ./gen_key_io_test_vectors.py invalid 50 > ../../src/test/data/key_io_keys_invalid.json
diff --git a/contrib/testgen/base58.py b/contrib/testgen/base58.py
new file mode 100644
index 0000000000..1aa8841920
--- /dev/null
+++ b/contrib/testgen/base58.py
@@ -0,0 +1,115 @@
+# Copyright (c) 2012-2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+'''
+Defi base58 encoding and decoding.
+
+Based on https://bitcointalk.org/index.php?topic=1026.0 (public domain)
+'''
+import hashlib
+
+# for compatibility with following code...
+class SHA256:
+ new = hashlib.sha256
+
+if str != bytes:
+ # Python 3.x
+ def ord(c):
+ return c
+ def chr(n):
+ return bytes( (n,) )
+
+__b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
+__b58base = len(__b58chars)
+b58chars = __b58chars
+
+def b58encode(v):
+ """ encode v, which is a string of bytes, to base58.
+ """
+ long_value = 0
+ for (i, c) in enumerate(v[::-1]):
+ if isinstance(c, str):
+ c = ord(c)
+ long_value += (256**i) * c
+
+ result = ''
+ while long_value >= __b58base:
+ div, mod = divmod(long_value, __b58base)
+ result = __b58chars[mod] + result
+ long_value = div
+ result = __b58chars[long_value] + result
+
+ # Defi does a little leading-zero-compression:
+ # leading 0-bytes in the input become leading-1s
+ nPad = 0
+ for c in v:
+ if c == 0:
+ nPad += 1
+ else:
+ break
+
+ return (__b58chars[0]*nPad) + result
+
+def b58decode(v, length = None):
+ """ decode v into a string of len bytes
+ """
+ long_value = 0
+ for i, c in enumerate(v[::-1]):
+ pos = __b58chars.find(c)
+ assert pos != -1
+ long_value += pos * (__b58base**i)
+
+ result = bytes()
+ while long_value >= 256:
+ div, mod = divmod(long_value, 256)
+ result = chr(mod) + result
+ long_value = div
+ result = chr(long_value) + result
+
+ nPad = 0
+ for c in v:
+ if c == __b58chars[0]:
+ nPad += 1
+ continue
+ break
+
+ result = bytes(nPad) + result
+ if length is not None and len(result) != length:
+ return None
+
+ return result
+
+def checksum(v):
+ """Return 32-bit checksum based on SHA256"""
+ return SHA256.new(SHA256.new(v).digest()).digest()[0:4]
+
+def b58encode_chk(v):
+ """b58encode a string, with 32-bit checksum"""
+ return b58encode(v + checksum(v))
+
+def b58decode_chk(v):
+ """decode a base58 string, check and remove checksum"""
+ result = b58decode(v)
+ if result is None:
+ return None
+ if result[-4:] == checksum(result[:-4]):
+ return result[:-4]
+ else:
+ return None
+
+def get_bcaddress_version(strAddress):
+ """ Returns None if strAddress is invalid. Otherwise returns integer version of address. """
+ addr = b58decode_chk(strAddress)
+ if addr is None or len(addr)!=21:
+ return None
+ version = addr[0]
+ return ord(version)
+
+if __name__ == '__main__':
+ # Test case (from http://gitorious.org/bitcoin/python-base58.git)
+ assert get_bcaddress_version('15VjRaDX9zpbA8LVnbrCAFzrVzN7ixHNsC') is 0
+ _ohai = 'o hai'.encode('ascii')
+ _tmp = b58encode(_ohai)
+ assert _tmp == 'DYB3oMS'
+ assert b58decode(_tmp, 5) == _ohai
+ print("Tests passed")
diff --git a/contrib/testgen/gen_key_io_test_vectors.py b/contrib/testgen/gen_key_io_test_vectors.py
new file mode 100755
index 0000000000..a00acb1f41
--- /dev/null
+++ b/contrib/testgen/gen_key_io_test_vectors.py
@@ -0,0 +1,249 @@
+#!/usr/bin/env python3
+# Copyright (c) 2012-2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+'''
+Generate valid and invalid base58 address and private key test vectors.
+
+Usage:
+ PYTHONPATH=../../test/functional/test_framework ./gen_key_io_test_vectors.py valid 50 > ../../src/test/data/key_io_valid.json
+ PYTHONPATH=../../test/functional/test_framework ./gen_key_io_test_vectors.py invalid 50 > ../../src/test/data/key_io_invalid.json
+'''
+# 2012 Wladimir J. van der Laan
+# Released under MIT License
+import os
+from itertools import islice
+from base58 import b58encode_chk, b58decode_chk, b58chars
+import random
+from binascii import b2a_hex
+from segwit_addr import bech32_encode, decode, convertbits, CHARSET
+
+# key types
+PUBKEY_ADDRESS = 0
+SCRIPT_ADDRESS = 5
+PUBKEY_ADDRESS_TEST = 111
+SCRIPT_ADDRESS_TEST = 196
+PUBKEY_ADDRESS_REGTEST = 111
+SCRIPT_ADDRESS_REGTEST = 196
+PRIVKEY = 128
+PRIVKEY_TEST = 239
+PRIVKEY_REGTEST = 239
+
+# script
+OP_0 = 0x00
+OP_1 = 0x51
+OP_2 = 0x52
+OP_16 = 0x60
+OP_DUP = 0x76
+OP_EQUAL = 0x87
+OP_EQUALVERIFY = 0x88
+OP_HASH160 = 0xa9
+OP_CHECKSIG = 0xac
+pubkey_prefix = (OP_DUP, OP_HASH160, 20)
+pubkey_suffix = (OP_EQUALVERIFY, OP_CHECKSIG)
+script_prefix = (OP_HASH160, 20)
+script_suffix = (OP_EQUAL,)
+p2wpkh_prefix = (OP_0, 20)
+p2wsh_prefix = (OP_0, 32)
+
+metadata_keys = ['isPrivkey', 'chain', 'isCompressed', 'tryCaseFlip']
+# templates for valid sequences
+templates = [
+ # prefix, payload_size, suffix, metadata, output_prefix, output_suffix
+ # None = N/A
+ ((PUBKEY_ADDRESS,), 20, (), (False, 'main', None, None), pubkey_prefix, pubkey_suffix),
+ ((SCRIPT_ADDRESS,), 20, (), (False, 'main', None, None), script_prefix, script_suffix),
+ ((PUBKEY_ADDRESS_TEST,), 20, (), (False, 'test', None, None), pubkey_prefix, pubkey_suffix),
+ ((SCRIPT_ADDRESS_TEST,), 20, (), (False, 'test', None, None), script_prefix, script_suffix),
+ ((PUBKEY_ADDRESS_REGTEST,), 20, (), (False, 'regtest', None, None), pubkey_prefix, pubkey_suffix),
+ ((SCRIPT_ADDRESS_REGTEST,), 20, (), (False, 'regtest', None, None), script_prefix, script_suffix),
+ ((PRIVKEY,), 32, (), (True, 'main', False, None), (), ()),
+ ((PRIVKEY,), 32, (1,), (True, 'main', True, None), (), ()),
+ ((PRIVKEY_TEST,), 32, (), (True, 'test', False, None), (), ()),
+ ((PRIVKEY_TEST,), 32, (1,), (True, 'test', True, None), (), ()),
+ ((PRIVKEY_REGTEST,), 32, (), (True, 'regtest', False, None), (), ()),
+ ((PRIVKEY_REGTEST,), 32, (1,), (True, 'regtest', True, None), (), ())
+]
+# templates for valid bech32 sequences
+bech32_templates = [
+ # hrp, version, witprog_size, metadata, output_prefix
+ ('bc', 0, 20, (False, 'main', None, True), p2wpkh_prefix),
+ ('bc', 0, 32, (False, 'main', None, True), p2wsh_prefix),
+ ('bc', 1, 2, (False, 'main', None, True), (OP_1, 2)),
+ ('tb', 0, 20, (False, 'test', None, True), p2wpkh_prefix),
+ ('tb', 0, 32, (False, 'test', None, True), p2wsh_prefix),
+ ('tb', 2, 16, (False, 'test', None, True), (OP_2, 16)),
+ ('bcrt', 0, 20, (False, 'regtest', None, True), p2wpkh_prefix),
+ ('bcrt', 0, 32, (False, 'regtest', None, True), p2wsh_prefix),
+ ('bcrt', 16, 40, (False, 'regtest', None, True), (OP_16, 40))
+]
+# templates for invalid bech32 sequences
+bech32_ng_templates = [
+ # hrp, version, witprog_size, invalid_bech32, invalid_checksum, invalid_char
+ ('tc', 0, 20, False, False, False),
+ ('tb', 17, 32, False, False, False),
+ ('bcrt', 3, 1, False, False, False),
+ ('bc', 15, 41, False, False, False),
+ ('tb', 0, 16, False, False, False),
+ ('bcrt', 0, 32, True, False, False),
+ ('bc', 0, 16, True, False, False),
+ ('tb', 0, 32, False, True, False),
+ ('bcrt', 0, 20, False, False, True)
+]
+
+def is_valid(v):
+ '''Check vector v for validity'''
+ if len(set(v) - set(b58chars)) > 0:
+ return is_valid_bech32(v)
+ result = b58decode_chk(v)
+ if result is None:
+ return is_valid_bech32(v)
+ for template in templates:
+ prefix = bytearray(template[0])
+ suffix = bytearray(template[2])
+ if result.startswith(prefix) and result.endswith(suffix):
+ if (len(result) - len(prefix) - len(suffix)) == template[1]:
+ return True
+ return is_valid_bech32(v)
+
+def is_valid_bech32(v):
+ '''Check vector v for bech32 validity'''
+ for hrp in ['bc', 'tb', 'bcrt']:
+ if decode(hrp, v) != (None, None):
+ return True
+ return False
+
+def gen_valid_base58_vector(template):
+ '''Generate valid base58 vector'''
+ prefix = bytearray(template[0])
+ payload = bytearray(os.urandom(template[1]))
+ suffix = bytearray(template[2])
+ dst_prefix = bytearray(template[4])
+ dst_suffix = bytearray(template[5])
+ rv = b58encode_chk(prefix + payload + suffix)
+ return rv, dst_prefix + payload + dst_suffix
+
+def gen_valid_bech32_vector(template):
+ '''Generate valid bech32 vector'''
+ hrp = template[0]
+ witver = template[1]
+ witprog = bytearray(os.urandom(template[2]))
+ dst_prefix = bytearray(template[4])
+ rv = bech32_encode(hrp, [witver] + convertbits(witprog, 8, 5))
+ return rv, dst_prefix + witprog
+
+def gen_valid_vectors():
+ '''Generate valid test vectors'''
+ glist = [gen_valid_base58_vector, gen_valid_bech32_vector]
+ tlist = [templates, bech32_templates]
+ while True:
+ for template, valid_vector_generator in [(t, g) for g, l in zip(glist, tlist) for t in l]:
+ rv, payload = valid_vector_generator(template)
+ assert is_valid(rv)
+ metadata = {x: y for x, y in zip(metadata_keys,template[3]) if y is not None}
+ hexrepr = b2a_hex(payload)
+ if isinstance(hexrepr, bytes):
+ hexrepr = hexrepr.decode('utf8')
+ yield (rv, hexrepr, metadata)
+
+def gen_invalid_base58_vector(template):
+ '''Generate possibly invalid vector'''
+ # kinds of invalid vectors:
+ # invalid prefix
+ # invalid payload length
+ # invalid (randomized) suffix (add random data)
+ # corrupt checksum
+ corrupt_prefix = randbool(0.2)
+ randomize_payload_size = randbool(0.2)
+ corrupt_suffix = randbool(0.2)
+
+ if corrupt_prefix:
+ prefix = os.urandom(1)
+ else:
+ prefix = bytearray(template[0])
+
+ if randomize_payload_size:
+ payload = os.urandom(max(int(random.expovariate(0.5)), 50))
+ else:
+ payload = os.urandom(template[1])
+
+ if corrupt_suffix:
+ suffix = os.urandom(len(template[2]))
+ else:
+ suffix = bytearray(template[2])
+
+ val = b58encode_chk(prefix + payload + suffix)
+ if random.randint(0,10)<1: # line corruption
+ if randbool(): # add random character to end
+ val += random.choice(b58chars)
+ else: # replace random character in the middle
+ n = random.randint(0, len(val))
+ val = val[0:n] + random.choice(b58chars) + val[n+1:]
+
+ return val
+
+def gen_invalid_bech32_vector(template):
+ '''Generate possibly invalid bech32 vector'''
+ no_data = randbool(0.1)
+ to_upper = randbool(0.1)
+ hrp = template[0]
+ witver = template[1]
+ witprog = bytearray(os.urandom(template[2]))
+
+ if no_data:
+ rv = bech32_encode(hrp, [])
+ else:
+ data = [witver] + convertbits(witprog, 8, 5)
+ if template[3] and not no_data:
+ if template[2] % 5 in {2, 4}:
+ data[-1] |= 1
+ else:
+ data.append(0)
+ rv = bech32_encode(hrp, data)
+
+ if template[4]:
+ i = len(rv) - random.randrange(1, 7)
+ rv = rv[:i] + random.choice(CHARSET.replace(rv[i], '')) + rv[i + 1:]
+ if template[5]:
+ i = len(hrp) + 1 + random.randrange(0, len(rv) - len(hrp) - 4)
+ rv = rv[:i] + rv[i:i + 4].upper() + rv[i + 4:]
+
+ if to_upper:
+ rv = rv.swapcase()
+
+ return rv
+
+def randbool(p = 0.5):
+ '''Return True with P(p)'''
+ return random.random() < p
+
+def gen_invalid_vectors():
+ '''Generate invalid test vectors'''
+ # start with some manual edge-cases
+ yield "",
+ yield "x",
+ glist = [gen_invalid_base58_vector, gen_invalid_bech32_vector]
+ tlist = [templates, bech32_ng_templates]
+ while True:
+ for template, invalid_vector_generator in [(t, g) for g, l in zip(glist, tlist) for t in l]:
+ val = invalid_vector_generator(template)
+ if not is_valid(val):
+ yield val,
+
+if __name__ == '__main__':
+ import sys
+ import json
+ iters = {'valid':gen_valid_vectors, 'invalid':gen_invalid_vectors}
+ try:
+ uiter = iters[sys.argv[1]]
+ except IndexError:
+ uiter = gen_valid_vectors
+ try:
+ count = int(sys.argv[2])
+ except IndexError:
+ count = 0
+
+ data = list(islice(uiter(), count))
+ json.dump(data, sys.stdout, sort_keys=True, indent=4)
+ sys.stdout.write('\n')
+
diff --git a/contrib/valgrind.supp b/contrib/valgrind.supp
new file mode 100644
index 0000000000..969c597595
--- /dev/null
+++ b/contrib/valgrind.supp
@@ -0,0 +1,43 @@
+# Valgrind suppressions file for Defi.
+#
+# Includes known Valgrind warnings in our dependencies that cannot be fixed
+# in-tree.
+#
+# Example use:
+# $ valgrind --suppressions=contrib/valgrind.supp src/test/test_defi
+# $ valgrind --suppressions=contrib/valgrind.supp --leak-check=full \
+# --show-leak-kinds=all src/test/test_defi --log_level=test_suite
+{
+ Suppress libstdc++ warning - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65434
+ Memcheck:Leak
+ match-leak-kinds: reachable
+ fun:malloc
+ obj:*/libstdc++.*
+ fun:call_init.part.0
+ fun:call_init
+ fun:_dl_init
+ obj:*/ld-*.so
+}
+{
+ Suppress libdb warning - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=662917
+ Memcheck:Cond
+ obj:*/libdb_cxx-*.so
+ fun:__log_put
+ obj:*/libdb_cxx-*.so
+ fun:__log_put_record
+}
+{
+ Suppress leveldb warning (leveldb::InitModule()) - https://github.com/google/leveldb/issues/113
+ Memcheck:Leak
+ match-leak-kinds: reachable
+ fun:_Znwm
+ fun:_ZN7leveldbL10InitModuleEv
+}
+{
+ Suppress leveldb warning (leveldb::Env::Default()) - https://github.com/google/leveldb/issues/113
+ Memcheck:Leak
+ match-leak-kinds: reachable
+ fun:_Znwm
+ ...
+ fun:_ZN7leveldbL14InitDefaultEnvEv
+}
diff --git a/contrib/verify-commits/README.md b/contrib/verify-commits/README.md
new file mode 100644
index 0000000000..bb60d7cc6a
--- /dev/null
+++ b/contrib/verify-commits/README.md
@@ -0,0 +1,57 @@
+Tooling for verification of PGP signed commits
+----------------------------------------------
+
+This is an incomplete work in progress, but currently includes a pre-push hook
+script (`pre-push-hook.sh`) for maintainers to ensure that their own commits
+are PGP signed (nearly always merge commits), as well as a Python 3 script to verify
+commits against a trusted keys list.
+
+
+Using verify-commits.py safely
+------------------------------
+
+Remember that you can't use an untrusted script to verify itself. This means
+that checking out code, then running `verify-commits.py` against `HEAD` is
+_not_ safe, because the version of `verify-commits.py` that you just ran could
+be backdoored. Instead, you need to use a trusted version of verify-commits
+prior to checkout to make sure you're checking out only code signed by trusted
+keys:
+
+ ```sh
+ git fetch origin && \
+ ./contrib/verify-commits/verify-commits.py origin/master && \
+ git checkout origin/master
+ ```
+
+Note that the above isn't a good UI/UX yet, and needs significant improvements
+to make it more convenient and reduce the chance of errors; pull-reqs
+improving this process would be much appreciated.
+
+Configuration files
+-------------------
+
+* `trusted-git-root`: This file should contain a single git commit hash which is the first unsigned git commit (hence it is the "root of trust").
+* `trusted-sha512-root-commit`: This file should contain a single git commit hash which is the first commit without a SHA512 root commitment.
+* `trusted-keys`: This file should contain a \n-delimited list of all PGP fingerprints of authorized commit signers (primary, not subkeys).
+* `allow-revsig-commits`: This file should contain a \n-delimited list of git commit hashes. See next section for more info.
+
+Import trusted keys
+-------------------
+In order to check the commit signatures, you must add the trusted PGP keys to your machine. [GnuPG](https://gnupg.org/) may be used to import the trusted keys by running the following command:
+
+```sh
+gpg --recv-keys $(/dev/null)"
+else
+ # Note how we've disabled SHA1 with the --weak-digest option, disabling
+ # signatures - including selfsigs - that use SHA1. While you might think that
+ # collision attacks shouldn't be an issue as they'd be an attack on yourself,
+ # in fact because what's being signed is a commit object that's
+ # semi-deterministically generated by untrusted input (the pull-req) in theory
+ # an attacker could construct a pull-req that results in a commit object that
+ # they've created a collision for. Not the most likely attack, but preventing
+ # it is pretty easy so we do so as a "belt-and-suspenders" measure.
+ GPG_RES=""
+ for LINE in $(gpg --version); do
+ case "$LINE" in
+ "gpg (GnuPG) 1.4.1"*|"gpg (GnuPG) 2.0."*)
+ echo "Please upgrade to at least gpg 2.1.10 to check for weak signatures" > /dev/stderr
+ GPG_RES="$(printf '%s\n' "$INPUT" | gpg --trust-model always "$@" 2>/dev/null)"
+ ;;
+ # We assume if you're running 2.1+, you're probably running 2.1.10+
+ # gpg will fail otherwise
+ # We assume if you're running 1.X, it is either 1.4.1X or 1.4.20+
+ # gpg will fail otherwise
+ esac
+ done
+ [ "$GPG_RES" = "" ] && GPG_RES="$(printf '%s\n' "$INPUT" | gpg --trust-model always --weak-digest sha1 "$@" 2>/dev/null)"
+fi
+for LINE in $GPG_RES; do
+ case "$LINE" in
+ "[GNUPG:] VALIDSIG "*)
+ while read KEY; do
+ [ "${LINE#?GNUPG:? VALIDSIG * * * * * * * * * }" = "$KEY" ] && VALID=true
+ done < ./contrib/verify-commits/trusted-keys
+ ;;
+ "[GNUPG:] REVKEYSIG "*)
+ [ "$DEFI_VERIFY_COMMITS_ALLOW_REVSIG" != 1 ] && exit 1
+ REVSIG=true
+ GOODREVSIG="[GNUPG:] GOODSIG ${LINE#* * *}"
+ ;;
+ "[GNUPG:] EXPKEYSIG "*)
+ [ "$DEFI_VERIFY_COMMITS_ALLOW_REVSIG" != 1 ] && exit 1
+ REVSIG=true
+ GOODREVSIG="[GNUPG:] GOODSIG ${LINE#* * *}"
+ ;;
+ esac
+done
+if ! $VALID; then
+ exit 1
+fi
+if $VALID && $REVSIG; then
+ printf '%s\n' "$INPUT" | gpg --trust-model always "$@" 2>/dev/null | grep "^\[GNUPG:\] \(NEWSIG\|SIG_ID\|VALIDSIG\)"
+ echo "$GOODREVSIG"
+else
+ printf '%s\n' "$INPUT" | gpg --trust-model always "$@" 2>/dev/null
+fi
diff --git a/contrib/verify-commits/pre-push-hook.sh b/contrib/verify-commits/pre-push-hook.sh
new file mode 100755
index 0000000000..4db4a90853
--- /dev/null
+++ b/contrib/verify-commits/pre-push-hook.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+# Copyright (c) 2014-2015 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+if ! [[ "$2" =~ ^(git@)?(www.)?github.com(:|/)bitcoin/bitcoin(.git)?$ ]]; then
+ exit 0
+fi
+
+while read LINE; do
+ set -- A $LINE
+ if [ "$4" != "refs/heads/master" ]; then
+ continue
+ fi
+ if ! ./contrib/verify-commits/verify-commits.py $3 > /dev/null 2>&1; then
+ echo "ERROR: A commit is not signed, can't push"
+ ./contrib/verify-commits/verify-commits.py
+ exit 1
+ fi
+done < /dev/stdin
diff --git a/contrib/verify-commits/trusted-git-root b/contrib/verify-commits/trusted-git-root
new file mode 100644
index 0000000000..c60f8ab695
--- /dev/null
+++ b/contrib/verify-commits/trusted-git-root
@@ -0,0 +1 @@
+82bcf405f6db1d55b684a1f63a4aabad376cdad7
diff --git a/contrib/verify-commits/trusted-keys b/contrib/verify-commits/trusted-keys
new file mode 100644
index 0000000000..27fede6277
--- /dev/null
+++ b/contrib/verify-commits/trusted-keys
@@ -0,0 +1,6 @@
+71A3B16735405025D447E8F274810B012346C9A6
+133EAC179436F14A5CF1B794860FEB804E669320
+32EE5C4C3FA15CCADB46ABE529D4BCB6416F53EC
+B8B3F1C0E58C15DB6A81D30C3648A882F4316B9B
+CA03882CB1FC067B5D3ACFE4D300116E1C875A3D
+E777299FC265DD04793070EB944D35F9AC3DB76A
diff --git a/contrib/verify-commits/trusted-sha512-root-commit b/contrib/verify-commits/trusted-sha512-root-commit
new file mode 100644
index 0000000000..7d41f90ad7
--- /dev/null
+++ b/contrib/verify-commits/trusted-sha512-root-commit
@@ -0,0 +1 @@
+309bf16257b2395ce502017be627186b749ee749
diff --git a/contrib/verify-commits/verify-commits.py b/contrib/verify-commits/verify-commits.py
new file mode 100755
index 0000000000..e14e88f495
--- /dev/null
+++ b/contrib/verify-commits/verify-commits.py
@@ -0,0 +1,165 @@
+#!/usr/bin/env python3
+# Copyright (c) 2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+"""Verify commits against a trusted keys list."""
+import argparse
+import hashlib
+import logging
+import os
+import subprocess
+import sys
+import time
+
+GIT = os.getenv('GIT', 'git')
+
+def tree_sha512sum(commit='HEAD'):
+ """Calculate the Tree-sha512 for the commit.
+
+ This is copied from github-merge.py. See https://github.com/bitcoin-core/bitcoin-maintainer-tools."""
+
+ # request metadata for entire tree, recursively
+ files = []
+ blob_by_name = {}
+ for line in subprocess.check_output([GIT, 'ls-tree', '--full-tree', '-r', commit]).splitlines():
+ name_sep = line.index(b'\t')
+ metadata = line[:name_sep].split() # perms, 'blob', blobid
+ assert metadata[1] == b'blob'
+ name = line[name_sep + 1:]
+ files.append(name)
+ blob_by_name[name] = metadata[2]
+
+ files.sort()
+ # open connection to git-cat-file in batch mode to request data for all blobs
+ # this is much faster than launching it per file
+ p = subprocess.Popen([GIT, 'cat-file', '--batch'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
+ overall = hashlib.sha512()
+ for f in files:
+ blob = blob_by_name[f]
+ # request blob
+ p.stdin.write(blob + b'\n')
+ p.stdin.flush()
+ # read header: blob, "blob", size
+ reply = p.stdout.readline().split()
+ assert reply[0] == blob and reply[1] == b'blob'
+ size = int(reply[2])
+ # hash the blob data
+ intern = hashlib.sha512()
+ ptr = 0
+ while ptr < size:
+ bs = min(65536, size - ptr)
+ piece = p.stdout.read(bs)
+ if len(piece) == bs:
+ intern.update(piece)
+ else:
+ raise IOError('Premature EOF reading git cat-file output')
+ ptr += bs
+ dig = intern.hexdigest()
+ assert p.stdout.read(1) == b'\n' # ignore LF that follows blob data
+ # update overall hash with file hash
+ overall.update(dig.encode("utf-8"))
+ overall.update(" ".encode("utf-8"))
+ overall.update(f)
+ overall.update("\n".encode("utf-8"))
+ p.stdin.close()
+ if p.wait():
+ raise IOError('Non-zero return value executing git cat-file')
+ return overall.hexdigest()
+
+def main():
+
+ # Enable debug logging if running in CI
+ if 'CI' in os.environ and os.environ['CI'].lower() == "true":
+ logging.getLogger().setLevel(logging.DEBUG)
+
+ # Parse arguments
+ parser = argparse.ArgumentParser(usage='%(prog)s [options] [commit id]')
+ parser.add_argument('--disable-tree-check', action='store_false', dest='verify_tree', help='disable SHA-512 tree check')
+ parser.add_argument('--clean-merge', type=float, dest='clean_merge', default=float('inf'), help='Only check clean merge after days ago (default: %(default)s)', metavar='NUMBER')
+ parser.add_argument('commit', nargs='?', default='HEAD', help='Check clean merge up to commit ')
+ args = parser.parse_args()
+
+ # get directory of this program and read data files
+ dirname = os.path.dirname(os.path.abspath(__file__))
+ print("Using verify-commits data from " + dirname)
+ verified_root = open(dirname + "/trusted-git-root", "r", encoding="utf8").read().splitlines()[0]
+ verified_sha512_root = open(dirname + "/trusted-sha512-root-commit", "r", encoding="utf8").read().splitlines()[0]
+ revsig_allowed = open(dirname + "/allow-revsig-commits", "r", encoding="utf-8").read().splitlines()
+ unclean_merge_allowed = open(dirname + "/allow-unclean-merge-commits", "r", encoding="utf-8").read().splitlines()
+ incorrect_sha512_allowed = open(dirname + "/allow-incorrect-sha512-commits", "r", encoding="utf-8").read().splitlines()
+
+ # Set commit and branch and set variables
+ current_commit = args.commit
+ if ' ' in current_commit:
+ print("Commit must not contain spaces", file=sys.stderr)
+ sys.exit(1)
+ verify_tree = args.verify_tree
+ no_sha1 = True
+ prev_commit = ""
+ initial_commit = current_commit
+ branch = subprocess.check_output([GIT, 'show', '-s', '--format=%H', initial_commit]).decode('utf8').splitlines()[0]
+
+ # Iterate through commits
+ while True:
+
+ # Log a message to prevent Travis from timing out
+ logging.debug("verify-commits: [in-progress] processing commit {}".format(current_commit[:8]))
+
+ if current_commit == verified_root:
+ print('There is a valid path from "{}" to {} where all commits are signed!'.format(initial_commit, verified_root))
+ sys.exit(0)
+ if current_commit == verified_sha512_root:
+ if verify_tree:
+ print("All Tree-SHA512s matched up to {}".format(verified_sha512_root), file=sys.stderr)
+ verify_tree = False
+ no_sha1 = False
+
+ os.environ['DEFI_VERIFY_COMMITS_ALLOW_SHA1'] = "0" if no_sha1 else "1"
+ os.environ['DEFI_VERIFY_COMMITS_ALLOW_REVSIG'] = "1" if current_commit in revsig_allowed else "0"
+
+ # Check that the commit (and parents) was signed with a trusted key
+ if subprocess.call([GIT, '-c', 'gpg.program={}/gpg.sh'.format(dirname), 'verify-commit', current_commit], stdout=subprocess.DEVNULL):
+ if prev_commit != "":
+ print("No parent of {} was signed with a trusted key!".format(prev_commit), file=sys.stderr)
+ print("Parents are:", file=sys.stderr)
+ parents = subprocess.check_output([GIT, 'show', '-s', '--format=format:%P', prev_commit]).decode('utf8').splitlines()[0].split(' ')
+ for parent in parents:
+ subprocess.call([GIT, 'show', '-s', parent], stdout=sys.stderr)
+ else:
+ print("{} was not signed with a trusted key!".format(current_commit), file=sys.stderr)
+ sys.exit(1)
+
+ # Check the Tree-SHA512
+ if (verify_tree or prev_commit == "") and current_commit not in incorrect_sha512_allowed:
+ tree_hash = tree_sha512sum(current_commit)
+ if ("Tree-SHA512: {}".format(tree_hash)) not in subprocess.check_output([GIT, 'show', '-s', '--format=format:%B', current_commit]).decode('utf8').splitlines():
+ print("Tree-SHA512 did not match for commit " + current_commit, file=sys.stderr)
+ sys.exit(1)
+
+ # Merge commits should only have two parents
+ parents = subprocess.check_output([GIT, 'show', '-s', '--format=format:%P', current_commit]).decode('utf8').splitlines()[0].split(' ')
+ if len(parents) > 2:
+ print("Commit {} is an octopus merge".format(current_commit), file=sys.stderr)
+ sys.exit(1)
+
+ # Check that the merge commit is clean
+ commit_time = int(subprocess.check_output([GIT, 'show', '-s', '--format=format:%ct', current_commit]).decode('utf8').splitlines()[0])
+ check_merge = commit_time > time.time() - args.clean_merge * 24 * 60 * 60 # Only check commits in clean_merge days
+ allow_unclean = current_commit in unclean_merge_allowed
+ if len(parents) == 2 and check_merge and not allow_unclean:
+ current_tree = subprocess.check_output([GIT, 'show', '--format=%T', current_commit]).decode('utf8').splitlines()[0]
+ subprocess.call([GIT, 'checkout', '--force', '--quiet', parents[0]])
+ subprocess.call([GIT, 'merge', '--no-ff', '--quiet', '--no-gpg-sign', parents[1]], stdout=subprocess.DEVNULL)
+ recreated_tree = subprocess.check_output([GIT, 'show', '--format=format:%T', 'HEAD']).decode('utf8').splitlines()[0]
+ if current_tree != recreated_tree:
+ print("Merge commit {} is not clean".format(current_commit), file=sys.stderr)
+ subprocess.call([GIT, 'diff', current_commit])
+ subprocess.call([GIT, 'checkout', '--force', '--quiet', branch])
+ sys.exit(1)
+ subprocess.call([GIT, 'checkout', '--force', '--quiet', branch])
+
+ prev_commit = current_commit
+ current_commit = parents[0]
+
+if __name__ == '__main__':
+ main()
diff --git a/contrib/verifybinaries/README.md b/contrib/verifybinaries/README.md
new file mode 100644
index 0000000000..5978006cd8
--- /dev/null
+++ b/contrib/verifybinaries/README.md
@@ -0,0 +1,43 @@
+### Verify Binaries
+
+> NOTE: This section is a work in progress for DeFi Blockchain, and may not be applicable at it's current state.
+
+#### Preparation:
+
+Make sure you obtain the proper release signing key and verify the fingerprint with several independent sources.
+
+```sh
+$ gpg --fingerprint "DeFi Blockchain binary release signing key"
+pub 4096R/36C2E964 2015-06-24 [expires: YYYY-MM-DD]
+ Key fingerprint = 01EA 5486 DE18 A882 D4C2 6845 90C8 019E 36C2 E964
+uid DeFi Blockchain Team (DeFi Blockchain binary release signing key)
+```
+
+#### Usage:
+
+This script attempts to download the signature file `SHA256SUMS.asc` from https://bitcoin.org.
+
+It first checks if the signature passes, and then downloads the files specified in the file, and checks if the hashes of these files match those that are specified in the signature file.
+
+The script returns 0 if everything passes the checks. It returns 1 if either the signature check or the hash check doesn't pass. If an error occurs the return value is 2.
+
+
+```sh
+./verify.sh defi-core-0.11.2
+./verify.sh defi-core-0.12.0
+./verify.sh defi-core-0.13.0-rc3
+```
+
+If you only want to download the binaries of certain platform, add the corresponding suffix, e.g.:
+
+```sh
+./verify.sh defi-core-0.11.2-osx
+./verify.sh 0.12.0-linux
+./verify.sh defi-core-0.13.0-rc3-win64
+```
+
+If you do not want to keep the downloaded binaries, specify anything as the second parameter.
+
+```sh
+./verify.sh defi-core-0.13.0 delete
+```
diff --git a/contrib/verifybinaries/verify.sh b/contrib/verifybinaries/verify.sh
new file mode 100755
index 0000000000..2bda8f5f4d
--- /dev/null
+++ b/contrib/verifybinaries/verify.sh
@@ -0,0 +1,177 @@
+#!/usr/bin/env bash
+# Copyright (c) 2016 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+### This script attempts to download the signature file SHA256SUMS.asc from
+### bitcoincore.org and bitcoin.org and compares them.
+### It first checks if the signature passes, and then downloads the files specified in
+### the file, and checks if the hashes of these files match those that are specified
+### in the signature file.
+### The script returns 0 if everything passes the checks. It returns 1 if either the
+### signature check or the hash check doesn't pass. If an error occurs the return value is 2
+
+export LC_ALL=C
+function clean_up {
+ for file in "$@"
+ do
+ rm "$file" 2> /dev/null
+ done
+}
+
+WORKINGDIR="/tmp/defi_verify_binaries"
+TMPFILE="hashes.tmp"
+
+SIGNATUREFILENAME="SHA256SUMS.asc"
+RCSUBDIR="test"
+HOST1="https://bitcoincore.org"
+HOST2="https://bitcoin.org"
+BASEDIR="/bin/"
+VERSIONPREFIX="defi-core-"
+RCVERSIONSTRING="rc"
+
+if [ ! -d "$WORKINGDIR" ]; then
+ mkdir "$WORKINGDIR"
+fi
+
+cd "$WORKINGDIR" || exit 1
+
+#test if a version number has been passed as an argument
+if [ -n "$1" ]; then
+ #let's also check if the version number includes the prefix 'defi-',
+ # and add this prefix if it doesn't
+ if [[ $1 == "$VERSIONPREFIX"* ]]; then
+ VERSION="$1"
+ else
+ VERSION="$VERSIONPREFIX$1"
+ fi
+
+ STRIPPEDLAST="${VERSION%-*}"
+
+ #now let's see if the version string contains "rc" or a platform name (e.g. "osx")
+ if [[ "$STRIPPEDLAST-" == "$VERSIONPREFIX" ]]; then
+ BASEDIR="$BASEDIR$VERSION/"
+ else
+ # let's examine the last part to see if it's rc and/or platform name
+ STRIPPEDNEXTTOLAST="${STRIPPEDLAST%-*}"
+ if [[ "$STRIPPEDNEXTTOLAST-" == "$VERSIONPREFIX" ]]; then
+
+ LASTSUFFIX="${VERSION##*-}"
+ VERSION="$STRIPPEDLAST"
+
+ if [[ $LASTSUFFIX == *"$RCVERSIONSTRING"* ]]; then
+ RCVERSION="$LASTSUFFIX"
+ else
+ PLATFORM="$LASTSUFFIX"
+ fi
+
+ else
+ RCVERSION="${STRIPPEDLAST##*-}"
+ PLATFORM="${VERSION##*-}"
+
+ VERSION="$STRIPPEDNEXTTOLAST"
+ fi
+
+ BASEDIR="$BASEDIR$VERSION/"
+ if [[ $RCVERSION == *"$RCVERSIONSTRING"* ]]; then
+ BASEDIR="$BASEDIR$RCSUBDIR.$RCVERSION/"
+ fi
+ fi
+else
+ echo "Error: need to specify a version on the command line"
+ exit 2
+fi
+
+if ! WGETOUT=$(wget -N "$HOST1$BASEDIR$SIGNATUREFILENAME" 2>&1); then
+ echo "Error: couldn't fetch signature file. Have you specified the version number in the following format?"
+ # shellcheck disable=SC1087
+ echo "[$VERSIONPREFIX]-[$RCVERSIONSTRING[0-9]] (example: ${VERSIONPREFIX}0.10.4-${RCVERSIONSTRING}1)"
+ echo "wget output:"
+ # shellcheck disable=SC2001
+ echo "$WGETOUT"|sed 's/^/\t/g'
+ exit 2
+fi
+
+if ! WGETOUT=$(wget -N -O "$SIGNATUREFILENAME.2" "$HOST2$BASEDIR$SIGNATUREFILENAME" 2>&1); then
+ echo "bitcoin.org failed to provide signature file, but bitcoincore.org did?"
+ echo "wget output:"
+ # shellcheck disable=SC2001
+ echo "$WGETOUT"|sed 's/^/\t/g'
+ clean_up $SIGNATUREFILENAME
+ exit 3
+fi
+
+SIGFILEDIFFS="$(diff $SIGNATUREFILENAME $SIGNATUREFILENAME.2)"
+if [ "$SIGFILEDIFFS" != "" ]; then
+ echo "bitcoin.org and bitcoincore.org signature files were not equal?"
+ clean_up $SIGNATUREFILENAME $SIGNATUREFILENAME.2
+ exit 4
+fi
+
+#then we check it
+GPGOUT=$(gpg --yes --decrypt --output "$TMPFILE" "$SIGNATUREFILENAME" 2>&1)
+
+#return value 0: good signature
+#return value 1: bad signature
+#return value 2: gpg error
+
+RET="$?"
+if [ $RET -ne 0 ]; then
+ if [ $RET -eq 1 ]; then
+ #and notify the user if it's bad
+ echo "Bad signature."
+ elif [ $RET -eq 2 ]; then
+ #or if a gpg error has occurred
+ echo "gpg error. Do you have the DeFi Blockchain binary release signing key installed?"
+ fi
+
+ echo "gpg output:"
+ # shellcheck disable=SC2001
+ echo "$GPGOUT"|sed 's/^/\t/g'
+ clean_up $SIGNATUREFILENAME $SIGNATUREFILENAME.2 $TMPFILE
+ exit "$RET"
+fi
+
+if [ -n "$PLATFORM" ]; then
+ grep $PLATFORM $TMPFILE > "$TMPFILE-plat"
+ TMPFILESIZE=$(stat -c%s "$TMPFILE-plat")
+ if [ $TMPFILESIZE -eq 0 ]; then
+ echo "error: no files matched the platform specified" && exit 3
+ fi
+ mv "$TMPFILE-plat" $TMPFILE
+fi
+
+#here we extract the filenames from the signature file
+FILES=$(awk '{print $2}' "$TMPFILE")
+
+#and download these one by one
+for file in $FILES
+do
+ echo "Downloading $file"
+ wget --quiet -N "$HOST1$BASEDIR$file"
+done
+
+#check hashes
+DIFF=$(diff <(sha256sum $FILES) "$TMPFILE")
+
+if [ $? -eq 1 ]; then
+ echo "Hashes don't match."
+ echo "Offending files:"
+ echo "$DIFF"|grep "^<"|awk '{print "\t"$3}'
+ exit 1
+elif [ $? -gt 1 ]; then
+ echo "Error executing 'diff'"
+ exit 2
+fi
+
+if [ -n "$2" ]; then
+ echo "Clean up the binaries"
+ clean_up $FILES $SIGNATUREFILENAME $SIGNATUREFILENAME.2 $TMPFILE
+else
+ echo "Keep the binaries in $WORKINGDIR"
+ clean_up $TMPFILE
+fi
+
+echo -e "Verified hashes of \n$FILES"
+
+exit 0
diff --git a/contrib/windeploy/detached-sig-create.sh b/contrib/windeploy/detached-sig-create.sh
new file mode 100755
index 0000000000..cc42422b23
--- /dev/null
+++ b/contrib/windeploy/detached-sig-create.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+# Copyright (c) 2014-2015 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+export LC_ALL=C
+if [ -z "$OSSLSIGNCODE" ]; then
+ OSSLSIGNCODE=osslsigncode
+fi
+
+if [ -z "$1" ]; then
+ echo "usage: $0 "
+ echo "example: $0 -key codesign.key"
+ exit 1
+fi
+
+OUT=signature-win.tar.gz
+SRCDIR=unsigned
+WORKDIR=./.tmp
+OUTDIR="${WORKDIR}/out"
+OUTSUBDIR="${OUTDIR}/win"
+TIMESERVER=http://timestamp.comodoca.com
+CERTFILE="win-codesign.cert"
+
+mkdir -p "${OUTSUBDIR}"
+basename -a $(ls -1 "${SRCDIR}"/*-unsigned.exe) | while read UNSIGNED; do
+ echo Signing "${UNSIGNED}"
+ "${OSSLSIGNCODE}" sign -certs "${CERTFILE}" -t "${TIMESERVER}" -in "${SRCDIR}/${UNSIGNED}" -out "${WORKDIR}/${UNSIGNED}" "$@"
+ "${OSSLSIGNCODE}" extract-signature -pem -in "${WORKDIR}/${UNSIGNED}" -out "${OUTSUBDIR}/${UNSIGNED}.pem" && rm "${WORKDIR}/${UNSIGNED}"
+done
+
+rm -f "${OUT}"
+tar -C "${OUTDIR}" -czf "${OUT}" .
+rm -rf "${WORKDIR}"
+echo "Created ${OUT}"
diff --git a/contrib/windeploy/win-codesign.cert b/contrib/windeploy/win-codesign.cert
new file mode 100644
index 0000000000..5bc5dc5809
--- /dev/null
+++ b/contrib/windeploy/win-codesign.cert
@@ -0,0 +1,100 @@
+-----BEGIN CERTIFICATE-----
+MIIFcTCCBFmgAwIBAgIRALWcUnSOxv9FQW3xdaMDO6swDQYJKoZIhvcNAQELBQAw
+fDELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G
+A1UEBxMHU2FsZm9yZDEYMBYGA1UEChMPU2VjdGlnbyBMaW1pdGVkMSQwIgYDVQQD
+ExtTZWN0aWdvIFJTQSBDb2RlIFNpZ25pbmcgQ0EwHhcNMTkwMzI3MDAwMDAwWhcN
+MjAwMzI2MjM1OTU5WjCBtDELMAkGA1UEBhMCQ0gxDTALBgNVBBEMBDgwMDUxCzAJ
+BgNVBAgMAlpIMRAwDgYDVQQHDAdaw7xyaWNoMRcwFQYDVQQJDA5NYXR0ZW5nYXNz
+ZSAyNzEuMCwGA1UECgwlQml0Y29pbiBDb3JlIENvZGUgU2lnbmluZyBBc3NvY2lh
+dGlvbjEuMCwGA1UEAwwlQml0Y29pbiBDb3JlIENvZGUgU2lnbmluZyBBc3NvY2lh
+dGlvbjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK04VDwiY1wxcW3E
+WTTGmnbciCwETwC96DG4qcoH2PPNsVy3dfwGh0C02Qj2vL64IfwIGUFSgREvyjZk
+CNhEuJO2e0nO0rKNNH5v/JO+P7/VYPZkF5a3uUz9ulmihULXioieHB/q0l6BmiJL
++cYaMVfidL9Y+IJwgiTqjnpRhv1Ik083SPsu6GcfQT9MJfY/+xse2EP0l4GfdFE6
+DRcWjiC8UHpfpGYcImzSFZZpbFbqoAyhueCl28QU4f8QAbS6BqNfaAK9MMACWDcK
+eTz3C5JK6CiUxOnGIxilXhljuybFUjR4jGl5eTRpuPWk95NTTYS36q+bx/1nYelx
+0n4nnDMCAwEAAaOCAbMwggGvMB8GA1UdIwQYMBaAFA7hOqhTOjHVir7Bu61nGgOF
+rTQOMB0GA1UdDgQWBBRbN7ECrPCdVvh58enwy3Dix46h2jAOBgNVHQ8BAf8EBAMC
+B4AwDAYDVR0TAQH/BAIwADATBgNVHSUEDDAKBggrBgEFBQcDAzARBglghkgBhvhC
+AQEEBAMCBBAwQAYDVR0gBDkwNzA1BgwrBgEEAbIxAQIBAwIwJTAjBggrBgEFBQcC
+ARYXaHR0cHM6Ly9zZWN0aWdvLmNvbS9DUFMwQwYDVR0fBDwwOjA4oDagNIYyaHR0
+cDovL2NybC5zZWN0aWdvLmNvbS9TZWN0aWdvUlNBQ29kZVNpZ25pbmdDQS5jcmww
+cwYIKwYBBQUHAQEEZzBlMD4GCCsGAQUFBzAChjJodHRwOi8vY3J0LnNlY3RpZ28u
+Y29tL1NlY3RpZ29SU0FDb2RlU2lnbmluZ0NBLmNydDAjBggrBgEFBQcwAYYXaHR0
+cDovL29jc3Auc2VjdGlnby5jb20wKwYDVR0RBCQwIoEgam9uYXNAYml0Y29pbmNv
+cmVjb2Rlc2lnbmluZy5vcmcwDQYJKoZIhvcNAQELBQADggEBAF/AIXcFBWCC2Red
+SHN4Cvko5mdSkDNgzjVFc+OwAJ5RdOgbERde4PnHm3Qmrnx+uMetVnmrC8Fv1Iwb
+kkR0bdbWBj6lF6zMsClIN6WJEfY+qfj1qi7wyucu+3OElYRC9bm5Lf0mEHQr8lJ1
+lGvAjPh+/hmxoVNbHFMZ1Ea+BrbjVwiSznt0gzdMh0CispBZKLWCIwRwi+hFjQrw
+Z7RLH8HeCJ5Ojl/OTDQqh6AylQ7l9w9KHsUt4Jqy/AnCCyAj2/6xjdwnuo3tCZwb
+g/9CydiAacD/83odphEeC2iBa+0wsj9bWmyYKY7S9n0u+wm3wBfZbSVMDDPk/la1
+3qCUDLk=
+-----END CERTIFICATE-----
+-----BEGIN CERTIFICATE-----
+MIIF3jCCA8agAwIBAgIQAf1tMPyjylGoG7xkDjUDLTANBgkqhkiG9w0BAQwFADCB
+iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl
+cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV
+BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTAw
+MjAxMDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCBiDELMAkGA1UEBhMCVVMxEzARBgNV
+BAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0plcnNleSBDaXR5MR4wHAYDVQQKExVU
+aGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNVBAMTJVVTRVJUcnVzdCBSU0EgQ2Vy
+dGlmaWNhdGlvbiBBdXRob3JpdHkwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIK
+AoICAQCAEmUXNg7D2wiz0KxXDXbtzSfTTK1Qg2HiqiBNCS1kCdzOiZ/MPans9s/B
+3PHTsdZ7NygRK0faOca8Ohm0X6a9fZ2jY0K2dvKpOyuR+OJv0OwWIJAJPuLodMkY
+tJHUYmTbf6MG8YgYapAiPLz+E/CHFHv25B+O1ORRxhFnRghRy4YUVD+8M/5+bJz/
+Fp0YvVGONaanZshyZ9shZrHUm3gDwFA66Mzw3LyeTP6vBZY1H1dat//O+T23LLb2
+VN3I5xI6Ta5MirdcmrS3ID3KfyI0rn47aGYBROcBTkZTmzNg95S+UzeQc0PzMsNT
+79uq/nROacdrjGCT3sTHDN/hMq7MkztReJVni+49Vv4M0GkPGw/zJSZrM233bkf6
+c0Plfg6lZrEpfDKEY1WJxA3Bk1QwGROs0303p+tdOmw1XNtB1xLaqUkL39iAigmT
+Yo61Zs8liM2EuLE/pDkP2QKe6xJMlXzzawWpXhaDzLhn4ugTncxbgtNMs+1b/97l
+c6wjOy0AvzVVdAlJ2ElYGn+SNuZRkg7zJn0cTRe8yexDJtC/QV9AqURE9JnnV4ee
+UB9XVKg+/XRjL7FQZQnmWEIuQxpMtPAlR1n6BB6T1CZGSlCBst6+eLf8ZxXhyVeE
+Hg9j1uliutZfVS7qXMYoCAQlObgOK6nyTJccBz8NUvXt7y+CDwIDAQABo0IwQDAd
+BgNVHQ4EFgQUU3m/WqorSs9UgOHYm8Cd8rIDZsswDgYDVR0PAQH/BAQDAgEGMA8G
+A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEMBQADggIBAFzUfA3P9wF9QZllDHPF
+Up/L+M+ZBn8b2kMVn54CVVeWFPFSPCeHlCjtHzoBN6J2/FNQwISbxmtOuowhT6KO
+VWKR82kV2LyI48SqC/3vqOlLVSoGIG1VeCkZ7l8wXEskEVX/JJpuXior7gtNn3/3
+ATiUFJVDBwn7YKnuHKsSjKCaXqeYalltiz8I+8jRRa8YFWSQEg9zKC7F4iRO/Fjs
+8PRF/iKz6y+O0tlFYQXBl2+odnKPi4w2r78NBc5xjeambx9spnFixdjQg3IM8WcR
+iQycE0xyNN+81XHfqnHd4blsjDwSXWXavVcStkNr/+XeTWYRUc+ZruwXtuhxkYze
+Sf7dNXGiFSeUHM9h4ya7b6NnJSFd5t0dCy5oGzuCr+yDZ4XUmFF0sbmZgIn/f3gZ
+XHlKYC6SQK5MNyosycdiyA5d9zZbyuAlJQG03RoHnHcAP9Dc1ew91Pq7P8yF1m9/
+qS3fuQL39ZeatTXaw2ewh0qpKJ4jjv9cJ2vhsE/zB+4ALtRZh8tSQZXq9EfX7mRB
+VXyNWQKV3WKdwrnuWih0hKWbt5DHDAff9Yk2dDLWKMGwsAvgnEzDHNb842m1R0aB
+L6KCq9NjRHDEjf8tM7qtj3u1cIiuPhnPQCjY/MiQu12ZIvVS5ljFH4gxQ+6IHdfG
+jjxDah2nGN59PRbxYvnKkKj9
+-----END CERTIFICATE-----
+-----BEGIN CERTIFICATE-----
+MIIF9TCCA92gAwIBAgIQHaJIMG+bJhjQguCWfTPTajANBgkqhkiG9w0BAQwFADCB
+iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl
+cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV
+BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTgx
+MTAyMDAwMDAwWhcNMzAxMjMxMjM1OTU5WjB8MQswCQYDVQQGEwJHQjEbMBkGA1UE
+CBMSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHEwdTYWxmb3JkMRgwFgYDVQQK
+Ew9TZWN0aWdvIExpbWl0ZWQxJDAiBgNVBAMTG1NlY3RpZ28gUlNBIENvZGUgU2ln
+bmluZyBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIYijTKFehif
+SfCWL2MIHi3cfJ8Uz+MmtiVmKUCGVEZ0MWLFEO2yhyemmcuVMMBW9aR1xqkOUGKl
+UZEQauBLYq798PgYrKf/7i4zIPoMGYmobHutAMNhodxpZW0fbieW15dRhqb0J+V8
+aouVHltg1X7XFpKcAC9o95ftanK+ODtj3o+/bkxBXRIgCFnoOc2P0tbPBrRXBbZO
+oT5Xax+YvMRi1hsLjcdmG0qfnYHEckC14l/vC0X/o84Xpi1VsLewvFRqnbyNVlPG
+8Lp5UEks9wO5/i9lNfIi6iwHr0bZ+UYc3Ix8cSjz/qfGFN1VkW6KEQ3fBiSVfQ+n
+oXw62oY1YdMCAwEAAaOCAWQwggFgMB8GA1UdIwQYMBaAFFN5v1qqK0rPVIDh2JvA
+nfKyA2bLMB0GA1UdDgQWBBQO4TqoUzox1Yq+wbutZxoDha00DjAOBgNVHQ8BAf8E
+BAMCAYYwEgYDVR0TAQH/BAgwBgEB/wIBADAdBgNVHSUEFjAUBggrBgEFBQcDAwYI
+KwYBBQUHAwgwEQYDVR0gBAowCDAGBgRVHSAAMFAGA1UdHwRJMEcwRaBDoEGGP2h0
+dHA6Ly9jcmwudXNlcnRydXN0LmNvbS9VU0VSVHJ1c3RSU0FDZXJ0aWZpY2F0aW9u
+QXV0aG9yaXR5LmNybDB2BggrBgEFBQcBAQRqMGgwPwYIKwYBBQUHMAKGM2h0dHA6
+Ly9jcnQudXNlcnRydXN0LmNvbS9VU0VSVHJ1c3RSU0FBZGRUcnVzdENBLmNydDAl
+BggrBgEFBQcwAYYZaHR0cDovL29jc3AudXNlcnRydXN0LmNvbTANBgkqhkiG9w0B
+AQwFAAOCAgEATWNQ7Uc0SmGk295qKoyb8QAAHh1iezrXMsL2s+Bjs/thAIiaG20Q
+BwRPvrjqiXgi6w9G7PNGXkBGiRL0C3danCpBOvzW9Ovn9xWVM8Ohgyi33i/klPeF
+M4MtSkBIv5rCT0qxjyT0s4E307dksKYjalloUkJf/wTr4XRleQj1qZPea3FAmZa6
+ePG5yOLDCBaxq2NayBWAbXReSnV+pbjDbLXP30p5h1zHQE1jNfYw08+1Cg4LBH+g
+S667o6XQhACTPlNdNKUANWlsvp8gJRANGftQkGG+OY96jk32nw4e/gdREmaDJhlI
+lc5KycF/8zoFm/lv34h/wCOe0h5DekUxwZxNqfBZslkZ6GqNKQQCd3xLS81wvjqy
+VVp4Pry7bwMQJXcVNIr5NsxDkuS6T/FikyglVyn7URnHoSVAaoRXxrKdsbwcCtp8
+Z359LukoTBh+xHsxQXGaSynsCz1XUNLK3f2eBVHlRHjdAd6xdZgNVCT98E7j4viD
+vXK6yz067vBeF5Jobchh+abxKgoLpbn0nu6YMgWFnuv5gynTxix9vTp3Los3QqBq
+gu07SqqUEKThDfgXxbZaeTMYkuO1dfih6Y4KJR7kHvGfWocj/5+kUZ77OYARzdu1
+xKeogG/lU9Tg46LC0lsa+jImLWpXcBw8pFguo/NbSwfcMlnzh6cabVg=
+-----END CERTIFICATE-----
diff --git a/contrib/zmq/zmq_sub.py b/contrib/zmq/zmq_sub.py
new file mode 100644
index 0000000000..0e9c8cd812
--- /dev/null
+++ b/contrib/zmq/zmq_sub.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python3
+# Copyright (c) 2014-2018 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+"""
+ ZMQ example using python3's asyncio
+
+ Defi should be started with the command line arguments:
+ defid -testnet -daemon \
+ -zmqpubrawtx=tcp://127.0.0.1:28554 \
+ -zmqpubrawblock=tcp://127.0.0.1:28554 \
+ -zmqpubhashtx=tcp://127.0.0.1:28554 \
+ -zmqpubhashblock=tcp://127.0.0.1:28554
+
+ We use the asyncio library here. `self.handle()` installs itself as a
+ future at the end of the function. Since it never returns with the event
+ loop having an empty stack of futures, this creates an infinite loop. An
+ alternative is to wrap the contents of `handle` inside `while True`.
+
+ A blocking example using python 2.7 can be obtained from the git history:
+ https://github.com/bitcoin/bitcoin/blob/37a7fe9e440b83e2364d5498931253937abe9294/contrib/zmq/zmq_sub.py
+"""
+
+import binascii
+import asyncio
+import zmq
+import zmq.asyncio
+import signal
+import struct
+import sys
+
+if (sys.version_info.major, sys.version_info.minor) < (3, 5):
+ print("This example only works with Python 3.5 and greater")
+ sys.exit(1)
+
+port = 28554
+
+class ZMQHandler():
+ def __init__(self):
+ self.loop = asyncio.get_event_loop()
+ self.zmqContext = zmq.asyncio.Context()
+
+ self.zmqSubSocket = self.zmqContext.socket(zmq.SUB)
+ self.zmqSubSocket.setsockopt(zmq.RCVHWM, 0)
+ self.zmqSubSocket.setsockopt_string(zmq.SUBSCRIBE, "hashblock")
+ self.zmqSubSocket.setsockopt_string(zmq.SUBSCRIBE, "hashtx")
+ self.zmqSubSocket.setsockopt_string(zmq.SUBSCRIBE, "rawblock")
+ self.zmqSubSocket.setsockopt_string(zmq.SUBSCRIBE, "rawtx")
+ self.zmqSubSocket.connect("tcp://127.0.0.1:%i" % port)
+
+ async def handle(self) :
+ msg = await self.zmqSubSocket.recv_multipart()
+ topic = msg[0]
+ body = msg[1]
+ sequence = "Unknown"
+ if len(msg[-1]) == 4:
+ msgSequence = struct.unpack('/dev/null)
+build_id_string+=$(shell $(build_AR) --version 2>/dev/null)
+build_id_string+=$(shell $(build_CXX) --version 2>/dev/null)
+build_id_string+=$(shell $(build_RANLIB) --version 2>/dev/null)
+build_id_string+=$(shell $(build_STRIP) --version 2>/dev/null)
+
+$(host_arch)_$(host_os)_id_string:=$(HOST_ID_SALT)
+$(host_arch)_$(host_os)_id_string+=$(shell $(host_CC) --version 2>/dev/null)
+$(host_arch)_$(host_os)_id_string+=$(shell $(host_AR) --version 2>/dev/null)
+$(host_arch)_$(host_os)_id_string+=$(shell $(host_CXX) --version 2>/dev/null)
+$(host_arch)_$(host_os)_id_string+=$(shell $(host_RANLIB) --version 2>/dev/null)
+$(host_arch)_$(host_os)_id_string+=$(shell $(host_STRIP) --version 2>/dev/null)
+
+qt_packages_$(NO_QT) = $(qt_packages) $(qt_$(host_os)_packages) $(qt_$(host_arch)_$(host_os)_packages)
+wallet_packages_$(NO_WALLET) = $(wallet_packages)
+upnp_packages_$(NO_UPNP) = $(upnp_packages)
+zmq_packages_$(NO_ZMQ) = $(zmq_packages)
+
+rapidcheck_packages_$(RAPIDCHECK) = $(rapidcheck_packages)
+
+packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(qt_packages_) $(wallet_packages_) $(upnp_packages_)
+native_packages += $($(host_arch)_$(host_os)_native_packages) $($(host_os)_native_packages)
+
+ifneq ($(qt_packages_),)
+native_packages += $(qt_native_packages)
+endif
+
+ifneq ($(zmq_packages_),)
+packages += $(zmq_packages)
+endif
+
+ifeq ($(rapidcheck_packages_),)
+packages += $(rapidcheck_packages)
+endif
+
+all_packages = $(packages) $(native_packages)
+
+meta_depends = Makefile funcs.mk builders/default.mk hosts/default.mk hosts/$(host_os).mk builders/$(build_os).mk
+
+$(host_arch)_$(host_os)_native_toolchain?=$($(host_os)_native_toolchain)
+
+include funcs.mk
+
+toolchain_path=$($($(host_arch)_$(host_os)_native_toolchain)_prefixbin)
+final_build_id_long+=$(shell $(build_SHA256SUM) config.site.in)
+final_build_id+=$(shell echo -n "$(final_build_id_long)" | $(build_SHA256SUM) | cut -c-$(HASH_LENGTH))
+$(host_prefix)/.stamp_$(final_build_id): $(native_packages) $(packages)
+ $(AT)rm -rf $(@D)
+ $(AT)mkdir -p $(@D)
+ $(AT)echo copying packages: $^
+ $(AT)echo to: $(@D)
+ $(AT)cd $(@D); $(foreach package,$^, tar xf $($(package)_cached); )
+ $(AT)touch $@
+
+$(host_prefix)/share/config.site : config.site.in $(host_prefix)/.stamp_$(final_build_id)
+ $(AT)@mkdir -p $(@D)
+ $(AT)sed -e 's|@HOST@|$(host)|' \
+ -e 's|@CC@|$(toolchain_path)$(host_CC)|' \
+ -e 's|@CXX@|$(toolchain_path)$(host_CXX)|' \
+ -e 's|@AR@|$(toolchain_path)$(host_AR)|' \
+ -e 's|@RANLIB@|$(toolchain_path)$(host_RANLIB)|' \
+ -e 's|@NM@|$(toolchain_path)$(host_NM)|' \
+ -e 's|@STRIP@|$(toolchain_path)$(host_STRIP)|' \
+ -e 's|@build_os@|$(build_os)|' \
+ -e 's|@host_os@|$(host_os)|' \
+ -e 's|@CFLAGS@|$(strip $(host_CFLAGS) $(host_$(release_type)_CFLAGS))|' \
+ -e 's|@CXXFLAGS@|$(strip $(host_CXXFLAGS) $(host_$(release_type)_CXXFLAGS))|' \
+ -e 's|@CPPFLAGS@|$(strip $(host_CPPFLAGS) $(host_$(release_type)_CPPFLAGS))|' \
+ -e 's|@LDFLAGS@|$(strip $(host_LDFLAGS) $(host_$(release_type)_LDFLAGS))|' \
+ -e 's|@allow_host_packages@|$(ALLOW_HOST_PACKAGES)|' \
+ -e 's|@no_qt@|$(NO_QT)|' \
+ -e 's|@no_zmq@|$(NO_ZMQ)|' \
+ -e 's|@no_wallet@|$(NO_WALLET)|' \
+ -e 's|@no_upnp@|$(NO_UPNP)|' \
+ -e 's|@debug@|$(DEBUG)|' \
+ $< > $@
+ $(AT)touch $@
+
+
+define check_or_remove_cached
+ mkdir -p $(BASE_CACHE)/$(host)/$(package) && cd $(BASE_CACHE)/$(host)/$(package); \
+ $(build_SHA256SUM) -c $($(package)_cached_checksum) >/dev/null 2>/dev/null || \
+ ( rm -f $($(package)_cached_checksum); \
+ if test -f "$($(package)_cached)"; then echo "Checksum mismatch for $(package). Forcing rebuild.."; rm -f $($(package)_cached_checksum) $($(package)_cached); fi )
+endef
+
+define check_or_remove_sources
+ mkdir -p $($(package)_source_dir); cd $($(package)_source_dir); \
+ test -f $($(package)_fetched) && ( $(build_SHA256SUM) -c $($(package)_fetched) >/dev/null 2>/dev/null || \
+ ( echo "Checksum missing or mismatched for $(package) source. Forcing re-download."; \
+ rm -f $($(package)_all_sources) $($(1)_fetched))) || true
+endef
+
+check-packages:
+ @$(foreach package,$(all_packages),$(call check_or_remove_cached,$(package));)
+check-sources:
+ @$(foreach package,$(all_packages),$(call check_or_remove_sources,$(package));)
+
+$(host_prefix)/share/config.site: check-packages
+
+check-packages: check-sources
+
+clean-all: clean
+ @rm -rf $(SOURCES_PATH) x86_64* i686* mips* arm* aarch64* riscv32* riscv64*
+
+clean:
+ @rm -rf $(WORK_PATH) $(BASE_CACHE) $(BUILD)
+
+install: check-packages $(host_prefix)/share/config.site
+
+
+download-one: check-sources $(all_sources)
+
+download-osx:
+ @$(MAKE) -s HOST=x86_64-apple-darwin14 download-one
+download-linux:
+ @$(MAKE) -s HOST=x86_64-unknown-linux-gnu download-one
+download-win:
+ @$(MAKE) -s HOST=x86_64-w64-mingw32 download-one
+download: download-osx download-linux download-win
+
+$(foreach package,$(all_packages),$(eval $(call ext_add_stages,$(package))))
+
+.PHONY: install cached clean clean-all download-one download-osx download-linux download-win download check-packages check-sources
diff --git a/depends/README.md b/depends/README.md
new file mode 100644
index 0000000000..ca542be13f
--- /dev/null
+++ b/depends/README.md
@@ -0,0 +1,97 @@
+### Usage
+
+To build dependencies for the current arch+OS:
+
+ make
+
+To build for another arch/OS:
+
+ make HOST=host-platform-triplet
+
+For example:
+
+ make HOST=x86_64-w64-mingw32 -j4
+
+**Bitcoin's configure script by default will ignore the depends output.** In
+order for it to pick up libraries, tools, and settings from the depends build,
+you must point it at the appropriate `--prefix` directory generated by the
+build. In the above example, a prefix dir named x86_64-w64-mingw32 will be
+created. To use it for Bitcoin:
+
+ ./configure --prefix=`pwd`/depends/x86_64-w64-mingw32
+
+Common `host-platform-triplets` for cross compilation are:
+
+- `i686-pc-linux-gnu` for Linux 32 bit
+- `x86_64-pc-linux-gnu` for x86 Linux
+- `x86_64-w64-mingw32` for Win64
+- `x86_64-apple-darwin14` for macOS
+- `arm-linux-gnueabihf` for Linux ARM 32 bit
+- `aarch64-linux-gnu` for Linux ARM 64 bit
+- `riscv32-linux-gnu` for Linux RISC-V 32 bit
+- `riscv64-linux-gnu` for Linux RISC-V 64 bit
+
+No other options are needed, the paths are automatically configured.
+
+### Install the required dependencies: Ubuntu & Debian
+
+#### For macOS cross compilation
+
+ sudo apt-get install curl librsvg2-bin libtiff-tools bsdmainutils cmake imagemagick libcap-dev libz-dev libbz2-dev python3-setuptools
+
+#### For Win32/Win64 cross compilation
+
+- see [build-windows.md](../doc/build-windows.md#cross-compilation-for-ubuntu-and-windows-subsystem-for-linux)
+
+#### For linux (including i386, ARM) cross compilation
+
+Common linux dependencies:
+
+ sudo apt-get install make automake cmake curl g++-multilib libtool binutils-gold bsdmainutils pkg-config python3 patch
+
+For linux ARM cross compilation:
+
+ sudo apt-get install g++-arm-linux-gnueabihf binutils-arm-linux-gnueabihf
+
+For linux AARCH64 cross compilation:
+
+ sudo apt-get install g++-aarch64-linux-gnu binutils-aarch64-linux-gnu
+
+For linux RISC-V 64-bit cross compilation (there are no packages for 32-bit):
+
+ sudo apt-get install g++-riscv64-linux-gnu binutils-riscv64-linux-gnu
+
+RISC-V known issue: gcc-7.3.0 and gcc-7.3.1 result in a broken `test_bitcoin` executable (see https://github.com/bitcoin/bitcoin/pull/13543),
+this is apparently fixed in gcc-8.1.0.
+
+### Dependency Options
+The following can be set when running make: make FOO=bar
+
+ SOURCES_PATH: downloaded sources will be placed here
+ BASE_CACHE: built packages will be placed here
+ SDK_PATH: Path where sdk's can be found (used by macOS)
+ FALLBACK_DOWNLOAD_PATH: If a source file can't be fetched, try here before giving up
+ NO_QT: Don't download/build/cache qt and its dependencies
+ NO_ZMQ: Don't download/build/cache packages needed for enabling zeromq
+ NO_WALLET: Don't download/build/cache libs needed to enable the wallet
+ NO_UPNP: Don't download/build/cache packages needed for enabling upnp
+ DEBUG: disable some optimizations and enable more runtime checking
+ RAPIDCHECK: build rapidcheck (experimental, requires cmake)
+ HOST_ID_SALT: Optional salt to use when generating host package ids
+ BUILD_ID_SALT: Optional salt to use when generating build package ids
+
+If some packages are not built, for example `make NO_WALLET=1`, the appropriate
+options will be passed to bitcoin's configure. In this case, `--disable-wallet`.
+
+### Additional targets
+
+ download: run 'make download' to fetch all sources without building them
+ download-osx: run 'make download-osx' to fetch all sources needed for macOS builds
+ download-win: run 'make download-win' to fetch all sources needed for win builds
+ download-linux: run 'make download-linux' to fetch all sources needed for linux builds
+
+### Other documentation
+
+- [description.md](description.md): General description of the depends system
+- [packages.md](packages.md): Steps for adding packages
+
diff --git a/depends/builders/darwin.mk b/depends/builders/darwin.mk
new file mode 100644
index 0000000000..c7671c1548
--- /dev/null
+++ b/depends/builders/darwin.mk
@@ -0,0 +1,22 @@
+build_darwin_CC:=$(shell xcrun -f clang)
+build_darwin_CXX:=$(shell xcrun -f clang++)
+build_darwin_AR:=$(shell xcrun -f ar)
+build_darwin_RANLIB:=$(shell xcrun -f ranlib)
+build_darwin_STRIP:=$(shell xcrun -f strip)
+build_darwin_OTOOL:=$(shell xcrun -f otool)
+build_darwin_NM:=$(shell xcrun -f nm)
+build_darwin_INSTALL_NAME_TOOL:=$(shell xcrun -f install_name_tool)
+build_darwin_SHA256SUM=shasum -a 256
+build_darwin_DOWNLOAD=curl --location --fail --connect-timeout $(DOWNLOAD_CONNECT_TIMEOUT) --retry $(DOWNLOAD_RETRIES) -o
+
+#darwin host on darwin builder. overrides darwin host preferences.
+darwin_CC=$(shell xcrun -f clang) -mmacosx-version-min=$(OSX_MIN_VERSION)
+darwin_CXX:=$(shell xcrun -f clang++) -mmacosx-version-min=$(OSX_MIN_VERSION) -stdlib=libc++
+darwin_AR:=$(shell xcrun -f ar)
+darwin_RANLIB:=$(shell xcrun -f ranlib)
+darwin_STRIP:=$(shell xcrun -f strip)
+darwin_LIBTOOL:=$(shell xcrun -f libtool)
+darwin_OTOOL:=$(shell xcrun -f otool)
+darwin_NM:=$(shell xcrun -f nm)
+darwin_INSTALL_NAME_TOOL:=$(shell xcrun -f install_name_tool)
+darwin_native_toolchain=
diff --git a/depends/builders/default.mk b/depends/builders/default.mk
new file mode 100644
index 0000000000..f097db65d6
--- /dev/null
+++ b/depends/builders/default.mk
@@ -0,0 +1,20 @@
+default_build_CC = gcc
+default_build_CXX = g++
+default_build_AR = ar
+default_build_RANLIB = ranlib
+default_build_STRIP = strip
+default_build_NM = nm
+default_build_OTOOL = otool
+default_build_INSTALL_NAME_TOOL = install_name_tool
+
+define add_build_tool_func
+build_$(build_os)_$1 ?= $$(default_build_$1)
+build_$(build_arch)_$(build_os)_$1 ?= $$(build_$(build_os)_$1)
+build_$1=$$(build_$(build_arch)_$(build_os)_$1)
+endef
+$(foreach var,CC CXX AR RANLIB NM STRIP SHA256SUM DOWNLOAD OTOOL INSTALL_NAME_TOOL,$(eval $(call add_build_tool_func,$(var))))
+define add_build_flags_func
+build_$(build_arch)_$(build_os)_$1 += $(build_$(build_os)_$1)
+build_$1=$$(build_$(build_arch)_$(build_os)_$1)
+endef
+$(foreach flags, CFLAGS CXXFLAGS LDFLAGS, $(eval $(call add_build_flags_func,$(flags))))
diff --git a/depends/builders/linux.mk b/depends/builders/linux.mk
new file mode 100644
index 0000000000..b03f424010
--- /dev/null
+++ b/depends/builders/linux.mk
@@ -0,0 +1,2 @@
+build_linux_SHA256SUM = sha256sum
+build_linux_DOWNLOAD = curl --location --fail --connect-timeout $(DOWNLOAD_CONNECT_TIMEOUT) --retry $(DOWNLOAD_RETRIES) -o
diff --git a/depends/config.guess b/depends/config.guess
new file mode 100755
index 0000000000..2b79f6d837
--- /dev/null
+++ b/depends/config.guess
@@ -0,0 +1,1476 @@
+#! /bin/sh
+# Attempt to guess a canonical system name.
+# Copyright 1992-2018 Free Software Foundation, Inc.
+
+timestamp='2018-07-06'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see .
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that
+# program. This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
+#
+# Originally written by Per Bothner; maintained since 2000 by Ben Elliston.
+#
+# You can get the latest version of this script from:
+# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
+#
+# Please send patches to .
+
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION]
+
+Output the configuration name of the system \`$me' is run on.
+
+Options:
+ -h, --help print this help, then exit
+ -t, --time-stamp print date of last modification, then exit
+ -v, --version print version number, then exit
+
+Report bugs and patches to ."
+
+version="\
+GNU config.guess ($timestamp)
+
+Originally written by Per Bothner.
+Copyright 1992-2018 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions. There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+ case $1 in
+ --time-stamp | --time* | -t )
+ echo "$timestamp" ; exit ;;
+ --version | -v )
+ echo "$version" ; exit ;;
+ --help | --h* | -h )
+ echo "$usage"; exit ;;
+ -- ) # Stop option processing
+ shift; break ;;
+ - ) # Use stdin as input.
+ break ;;
+ -* )
+ echo "$me: invalid option $1$help" >&2
+ exit 1 ;;
+ * )
+ break ;;
+ esac
+done
+
+if test $# != 0; then
+ echo "$me: too many arguments$help" >&2
+ exit 1
+fi
+
+trap 'exit 1' 1 2 15
+
+# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
+# compiler to aid in system detection is discouraged as it requires
+# temporary files to be created and, as you can see below, it is a
+# headache to deal with in a portable fashion.
+
+# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
+# use `HOST_CC' if defined, but it is deprecated.
+
+# Portable tmp directory creation inspired by the Autoconf team.
+
+set_cc_for_build='
+trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
+trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
+: ${TMPDIR=/tmp} ;
+ { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp 2>/dev/null) ; } ||
+ { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } ||
+ { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
+dummy=$tmp/dummy ;
+tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
+case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in
+ ,,) echo "int x;" > "$dummy.c" ;
+ for c in cc gcc c89 c99 ; do
+ if ($c -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then
+ CC_FOR_BUILD="$c"; break ;
+ fi ;
+ done ;
+ if test x"$CC_FOR_BUILD" = x ; then
+ CC_FOR_BUILD=no_compiler_found ;
+ fi
+ ;;
+ ,,*) CC_FOR_BUILD=$CC ;;
+ ,*,*) CC_FOR_BUILD=$HOST_CC ;;
+esac ; set_cc_for_build= ;'
+
+# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
+# (ghazi@noc.rutgers.edu 1994-08-24)
+if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+ PATH=$PATH:/.attbin ; export PATH
+fi
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+case "$UNAME_SYSTEM" in
+Linux|GNU|GNU/*)
+ # If the system lacks a compiler, then just pick glibc.
+ # We could probably try harder.
+ LIBC=gnu
+
+ eval "$set_cc_for_build"
+ cat <<-EOF > "$dummy.c"
+ #include