diff --git a/android/README.md b/android/README.md new file mode 100644 index 0000000..6335063 --- /dev/null +++ b/android/README.md @@ -0,0 +1,20 @@ +# ARM compilation. TODO +Create standalone: https://developer.android.com/ndk/guides/standalone_toolchain +Then change variables for you in setenv-android.sh and preparedepencies.sh ($ST and $NDK_PATH will be for standalone) but ANDROID_NDK_ROOT for real NDK-bundle. +then run preparedepencies.sh +then go to ../src/ and run compile_android.sh +Or change variables in gostcoin-qt-android.pro and compile for Qt... +``` +lialh4@RBH4:~/GTMP/src$ lddandr gostcoind + 0x00000001 (NEEDED) Shared library: [libssl.so.1.1] + 0x00000001 (NEEDED) Shared library: [libcrypto.so.1.1] + 0x00000001 (NEEDED) Shared library: [libz.so] + 0x00000001 (NEEDED) Shared library: [libdl.so] + 0x00000001 (NEEDED) Shared library: [libc++_shared.so] + 0x00000001 (NEEDED) Shared library: [libm.so] + 0x00000001 (NEEDED) Shared library: [libc.so] +``` +Now is static. but some trouble ``` +error: "./gostcoind": executable's TLS segment is underaligned: alignment is 8, needs to be at least 32 for ARM Bionic +libc: error: "./gostcoind": executable's TLS segment is underaligned: alignment is 8, needs to be at least 32 for ARM Bionic``` +You can to try change -lc to LMODE2 in makefile.android but then you will to get segmentation fault. TODO: fix it... diff --git a/android/aliases.sh b/android/aliases.sh new file mode 100644 index 0000000..40d58b8 --- /dev/null +++ b/android/aliases.sh @@ -0,0 +1,9 @@ +if $CROSS_COMPILE_ISCLANG;then + alias gcc="$TOOLCHAIN/$CROSS_COMPILE""clang" + #echo gcc=$C + alias g++="$TOOLCHAIN/$CROSS_COMPILE""clang++" +else + alias gcc="$TOOLCHAIN/$CROSS_COMPILE""gcc" + #echo gcc=$C + alias g++="$TOOLCHAIN/$CROSS_COMPILE""g++" +fi; diff --git a/android/preparedepencies.sh b/android/preparedepencies.sh new file mode 100755 index 0000000..2c54e11 --- /dev/null +++ b/android/preparedepencies.sh @@ -0,0 +1,98 @@ +#!/bin/bash +#Plaz +# ndk/build/tools/make_standalone_toolchain.py for standalone build +preinit(){ + source setenv-android.sh + + export STANDALONE=/home/lialh4/Android/Sdk/ndk/arm-linux-androideabi/ + + export CPPFLAGS=--sysroot=$ANDROID_SYSROOT + export CXXFLAGS="--sysroot=$ANDROID_SYSROOT" + export TOOLCHAIN=$ANDROID_TOOLCHAIN + export NDK_PATH=$ANDROID_NDK_ROOT + export PATH=$TOOLCHAIN/bin/:$PATH:$STANDALONE/bin/ + export ARCH=arm + export bdbv=18.1.40 + export CROSS_COMPILE_ISCLANG=true + export CROSS_COMPILE= +} + +download_depencies(){ + wget -t0 https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_1_1_1k.zip + wget -t0 https://fossies.org/linux/misc/db-$bdbv.tar.gz + wget -t0 https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.gz + git clone https://github.com/GOSTSec/android-ifaddrs-from-android-source +} +check_depencies(){ + if ! test -e OpenSSL_1_1_1k.zip || ! test -e db-*.tar.gz || ! test -e boost*.tar.gz;then + echo "Not exists depencies, download" + download_depencies + fi; + unpack_depencies +} +unpack_depencies(){ + if ! test -d openssl-OpenSSL_1_1_1k || ! test -d "db-$bdbv" || ! test -d boost_1_76_0;then + tar xzvf "db-$bdbv.tar.gz" -C . + 7z x OpenSSL_1_1_1k.zip + tar xvpf boost_1_76_0.tar.gz -C . + fi; +} +compile_openssl(){ + + cd openssl-OpenSSL_1_1_1k + ./Configure android-arm shared no-ssl3 no-comp no-hw no-engine || exit 1 + echo $ANDROID_NDK_ROOT/platforms/android-21/arch-arm/usr/lib/ + make || exit 1 + cd .. +} +compile_db(){ + cd db-$bdbv/dist + if ! test -e config.sub.old;then + mv config.sub config.sub.old + wget 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD' -O config.sub + mv config.guess config.guess.old + wget 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD' -O config.guess + cp config.* ../lang/sql/sqlite/ + fi; + cd ../build_unix + export ANDROID_HOME=$ANDROID_NDK_ROOT + ../dist/configure --enable-cxx --disable-shared --disable-replication --host=arm-linux-androideabi CC=arm-linux-androideabi-gcc CPPFLAGS="-I$ANDROID_HOME/sysroot/usr/include/arm-linux-androideabi/ -I$ANDROID_HOME/sysroot/usr/include/ -I$ANDROID_HOME/sources/cxx-stl/llvm-libc++/include/" + make + cd .. +} +compile_boost(){ + cd boost_1_76_0 + ./bootstrap.sh + echo -e "import option ;\nusing gcc : arm : arm-linux-androideabi-g++ ;\noption.set keep-going : false ; ">project-config.jam + echo "$PATH" + ./b2 --layout=versioned --build-type=complete toolset=gcc-arm variant=release link=static threading=multi threadapi=pthread target-os=android define=BOOST_MATH_DISABLE_FLOAT128 + cd stage/lib + for lib in *.a; + do + normalname=${lib/-*1_76.a/.a} + echo "cp $lib to $normalname" + cp $lib $normalname + done; + cd ../../.. +} + +compile_level_db(){ +#maybe not need... because will be compiled but... automatic + cd ../src/leveldb + TARGET_OS=OS_ANDROID_CROSSCOMPILE make libleveldb.a libmemenv.a + cd ../../android +} +preinit +check_depencies +shopt -s expand_aliases +. aliases.sh +#gcc -v + +compile_openssl +compile_boost +compile_db +#compile_level_db + + +echo "Now cd to ../src/ and run compile_android.sh" + diff --git a/android/setenv-android.sh b/android/setenv-android.sh new file mode 100755 index 0000000..f56d818 --- /dev/null +++ b/android/setenv-android.sh @@ -0,0 +1,277 @@ +#!/bin/bash +# Cross-compile environment for Android +# +# Contents licensed under the terms of the OpenSSL license +# http://www.openssl.org/source/license.html +# +# See http://wiki.openssl.org/index.php/FIPS_Library_and_Android +# and http://wiki.openssl.org/index.php/Android +# +# Originally provided by OpenSSL, modified by R4SAS +# https://github.com/PurpleI2P/OpenSSL-for-Android-Prebuilt + +##################################################################### + +# Example of usage: +# * Building OpenSSL 1.1.1 for armeabi-v7a using llvm (clang) +# * Change _ANDROID_EABI to llvm +# * Change _ANDROID_ARCH to arch-arm +# * Change _ANDROID_API to 14 +# * Run in shell: +# $ . setenv-android.sh +# $ cd openssl-1.1.1 +# $ ./Configure android-arm shared no-ssl3 no-comp no-hw no-engine -D__ARM_MAX_ARCH__=8 +# $ make +# * Take compiled libraries from sources root directory +# +# * Building OpenSSL 1.1.1 for arm64-v8a using llvm (clang) +# * Change _ANDROID_EABI to llvm +# * Change _ANDROID_ARCH to arch-arm64 +# * Change _ANDROID_API to 21 +# * Run in shell: +# $ . setenv-android.sh +# $ cd openssl-1.1.1 +# $ ./Configure android-arm64 shared no-ssl3 no-comp no-hw no-engine +# $ make +# * Take compiled libraries from sources root directory +# +# Note: gcc toolchains is deprecated since NDK r18, prefered to use llvm. + +#################################################################### +#CHANGE TO YOUR PATH +ANDROID_NDK_ROOT="/home/lialh4/Android/Sdk/android-ndk-r21e" + +# Set ANDROID_NDK_ROOT to you NDK location. For example, +# /opt/android-ndk-r8e or /opt/android-ndk-r9. This can be done in a +# login script. If ANDROID_NDK_ROOT is not specified, the script will +# try to pick it up with the value of _ANDROID_NDK_ROOT below. If +# ANDROID_NDK_ROOT is set, then the value is ignored. +_ANDROID_NDK="android-ndk-r21e" + +# Set _ANDROID_EABI to the EABI you want to use. You can find the +# list in $ANDROID_NDK_ROOT/toolchains. This value is always used. +#_ANDROID_EABI="arm-linux-androideabi-4.9" +#_ANDROID_EABI="aarch64-linux-android-4.9" +#_ANDROID_EABI="x86-4.9" +#_ANDROID_EABI="x86_64-4.9" +_ANDROID_EABI="llvm" + +# Set _ANDROID_ARCH to the architecture you are building for. +# This value is always used. +_ANDROID_ARCH=arch-arm +#_ANDROID_ARCH=arch-arm64 +#_ANDROID_ARCH=arch-x86 +#_ANDROID_ARCH=arch-x86_64 + +# Set _ANDROID_API to the API you want to use. +# This value is always used. +# ! If you build for arm64-v8a or x86_64, you MUST use API 21+ ! +#_ANDROID_API="android-14" +_ANDROID_API="android-28" + + +# armeabi/armeabi-v7a toogler (for gcc) +# If you build for armeabi, change to false +IsARMv7=false + +##################################################################### + +# If the user did not specify the NDK location, try and pick it up. +# We expect something like ANDROID_NDK_ROOT=/opt/android-ndk-r8e +# or ANDROID_NDK_ROOT=/usr/local/android-ndk-r8e. + + +if [ -z "$ANDROID_NDK_ROOT" ]; then + + _ANDROID_NDK_ROOT="" + if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "/usr/local/$_ANDROID_NDK" ]; then + _ANDROID_NDK_ROOT="/usr/local/$_ANDROID_NDK" + fi + + if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "/opt/$_ANDROID_NDK" ]; then + _ANDROID_NDK_ROOT="/opt/$_ANDROID_NDK" + fi + + if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "$HOME/$_ANDROID_NDK" ]; then + _ANDROID_NDK_ROOT="$HOME/$_ANDROID_NDK" + fi + + if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "$PWD/$_ANDROID_NDK" ]; then + _ANDROID_NDK_ROOT="$PWD/$_ANDROID_NDK" + fi + + # If a path was set, then export it + if [ ! -z "$_ANDROID_NDK_ROOT" ] && [ -d "$_ANDROID_NDK_ROOT" ]; then + export ANDROID_NDK_ROOT="$_ANDROID_NDK_ROOT" + fi +fi + +# Error checking +# ANDROID_NDK_ROOT should always be set by the user (even when not running this script) +# http://groups.google.com/group/android-ndk/browse_thread/thread/a998e139aca71d77 +if [ -z "$ANDROID_NDK_ROOT" ] || [ ! -d "$ANDROID_NDK_ROOT" ]; then + echo "Error: ANDROID_NDK_ROOT is not a valid path. Please edit this script." + # echo "$ANDROID_NDK_ROOT" + # exit 1 +fi + +# Error checking +if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then + echo "Error: ANDROID_NDK_ROOT/toolchains is not a valid path. Please edit this script." + # echo "$ANDROID_NDK_ROOT/toolchains" + # exit 1 +fi + +# Error checking +if [ ! -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI" ]; then + echo "Error: ANDROID_EABI is not a valid path. Please edit this script." + # echo "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI" + # exit 1 +fi + +##################################################################### + +# Based on ANDROID_NDK_ROOT, try and pick up the required toolchain. We expect something like: +# /opt/android-ndk-r83/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin +# Once we locate the toolchain, we add it to the PATH. Note: this is the 'hard way' of +# doing things according to the NDK documentation for Ice Cream Sandwich. +# https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html + +ANDROID_TOOLCHAIN="" +for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86" +do + if [ -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin" ]; then + ANDROID_TOOLCHAIN="$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin" + break + fi +done + +# Error checking +if [ -z "$ANDROID_TOOLCHAIN" ] || [ ! -d "$ANDROID_TOOLCHAIN" ]; then + echo "Error: ANDROID_TOOLCHAIN is not valid. Please edit this script." + # echo "$ANDROID_TOOLCHAIN" + # exit 1 +fi + +if [ "$_ANDROID_EABI" == "llvm" ]; then + ANDROID_TOOLS="clang llvm-ar llvm-link" +else + case $_ANDROID_ARCH in + arch-arm) + ANDROID_TOOLS="arm-linux-androideabi-gcc arm-linux-androideabi-ranlib arm-linux-androideabi-ld" + ;; + arch-arm64) + ANDROID_TOOLS="aarch64-linux-android-gcc aarch64-linux-android-ranlib aarch64-linux-android-ld" + ;; + arch-x86) + ANDROID_TOOLS="i686-linux-android-gcc i686-linux-android-ranlib i686-linux-android-ld" + ;; + arch-x86_64) + ANDROID_TOOLS="x86_64-linux-android-gcc x86_64-linux-android-ranlib x86_64-linux-android-ld" + ;; + *) + echo "ERROR ERROR ERROR" + ;; + esac +fi + +for tool in $ANDROID_TOOLS +do + # Error checking + if [ ! -e "$ANDROID_TOOLCHAIN/$tool" ]; then + echo "Error: Failed to find $tool. Please edit this script." + # echo "$ANDROID_TOOLCHAIN/$tool" + # exit 1 + fi +done + +# Only modify/export PATH if ANDROID_TOOLCHAIN good +if [ ! -z "$ANDROID_TOOLCHAIN" ]; then + export ANDROID_TOOLCHAIN="$ANDROID_TOOLCHAIN" + export PATH="$ANDROID_TOOLCHAIN":"$PATH" +fi + +##################################################################### + +# For the Android SYSROOT. Can be used on the command line with --sysroot +# https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html +export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH" +export SYSROOT="$ANDROID_SYSROOT" +export NDK_SYSROOT="$ANDROID_SYSROOT" + +# Error checking +if [ -z "$ANDROID_SYSROOT" ] || [ ! -d "$ANDROID_SYSROOT" ]; then + echo "Error: ANDROID_SYSROOT is not valid. Please edit this script." + # echo "$ANDROID_SYSROOT" + # exit 1 +fi + +##################################################################### + +# Most of these should be OK (MACHINE, SYSTEM, ARCH). RELEASE is ignored. +if [ "$_ANDROID_ARCH" == "arch-arm" ]; then + if [ "$IsARMv7" = true ]; then + export MACHINE=armv7 + else + export MACHINE=arm + fi + export RELEASE=2.6.37 + export SYSTEM=android + export ARCH=arm + export CROSS_COMPILE="arm-linux-androideabi-" +fi + +if [ "$_ANDROID_ARCH" == "arch-arm64" ]; then + export MACHINE=arm64 + export RELEASE=2.6.37 + export SYSTEM=android + export ARCH=aarch64 + export CROSS_COMPILE="aarch64-linux-android-" +fi + +if [ "$_ANDROID_ARCH" == "arch-x86" ]; then + export MACHINE=i686 + export RELEASE=2.6.37 + export SYSTEM=android + export ARCH=x86 + export CROSS_COMPILE="i686-linux-android-" +fi + +if [ "$_ANDROID_ARCH" == "arch-x86_64" ]; then + export MACHINE=x86_64 + export RELEASE=2.6.37 + export SYSTEM=android + export ARCH=x86_64 + export CROSS_COMPILE="x86_64-linux-android-" +fi + +if [ "$_ANDROID_EABI" == "llvm" ]; then + unset CROSS_COMPILE +fi + +# For the Android toolchain +# https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html +export ANDROID_NDK="$ANDROID_NDK_ROOT" +export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH" +export SYSROOT="$ANDROID_SYSROOT" +export CROSS_SYSROOT="$ANDROID_SYSROOT" +export NDK_SYSROOT="$ANDROID_SYSROOT" +export ANDROID_NDK_SYSROOT="$ANDROID_SYSROOT" +export ANDROID_API="$_ANDROID_API" + +# CROSS_COMPILE and ANDROID_DEV are DFW (Don't Fiddle With). Its used by OpenSSL build system. +# export CROSS_COMPILE="arm-linux-androideabi-" +export ANDROID_DEV="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr" +#export HOSTCC=gcc + +VERBOSE=1 +if [ ! -z "$VERBOSE" ] && [ "$VERBOSE" != "0" ]; then + echo "ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT" + echo "ANDROID_ARCH: $_ANDROID_ARCH" + echo "ANDROID_EABI: $_ANDROID_EABI" + echo "ANDROID_API: $ANDROID_API" + echo "ANDROID_SYSROOT: $ANDROID_SYSROOT" + echo "ANDROID_TOOLCHAIN: $ANDROID_TOOLCHAIN" + echo "CROSS_COMPILE: $CROSS_COMPILE" + echo "ANDROID_DEV: $ANDROID_DEV" +fi diff --git a/src/compile_android.sh b/src/compile_android.sh new file mode 100755 index 0000000..2ca6c76 --- /dev/null +++ b/src/compile_android.sh @@ -0,0 +1,49 @@ +yn(){ +# echo "$all = all" + if [[ "$all" == "y" ]];then + return 0 + fi; + + echo "$1?[y/n/a]: " + read sure + while [[ "$sure" != "y"* ]] && [[ "$sure" != "n"* ]] && [[ "$sure" != "a"* ]]; + do + echo "$1?[y/n/a]: " + read sure + done; + if [[ $sure == "y"* ]];then + return 0 + elif [[ $sure == "n"* ]] + then + return 1 + else + export all="y" + return 0 + fi; +} + +andr=$(pwd)/../android +source $andr/setenv-android.sh +export BOOST_INCLUDE_PATH=$andr/boost_1_76_0/ +export BDB_INCLUDE_PATH=$andr/db-18.1.40/build_unix/ +export BDB_LIB_PATH=$BDB_INCLUDE_PATH +export OPENSSL_PATH=$andr/openssl-OpenSSL_1_1_1k/ +export OPENSSL_INCLUDE_PATH=$OPENSSL_PATH/include +export IFADDRS_PATH=$andr/android-ifaddrs-from-android-source +export BOOST_LIB_PATH=$BOOST_INCLUDE_PATH/stage/lib +export OPENSSL_LIB_PATH=$OPENSSL_PATH +#export ANDROID_INCLUDE_PATH=$ST/sysroot/usr/include +#export ANDROID_LIB_PATH=$ST/sysroot/usr/lib/arm-linux-androideabi/ +echo "Cd to ../android for run script preparedepencies.sh but before change variables for you in preparedepcnies.sh and setenv-android.sh" +echo "Then (in the src directory) open makefile.android and change CXX/Sysroot variables;" +echo "When is be done - ENTER..." +read +if ! test -e gostcoind;then + make -f makefile.android +else + echo "your gostcoind like to compiled." + if yn "rebuild gostcoind?"; then + make -f makefile.android clean + make -f makefile.android + fi; +fi; diff --git a/src/makefile.android b/src/makefile.android new file mode 100644 index 0000000..1dc4c98 --- /dev/null +++ b/src/makefile.android @@ -0,0 +1,213 @@ +# Copyright (c) 2009-2010 Satoshi Nakamoto +# Distributed under the MIT/X11 software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +# :=1 --> Enable IPv6 support +# :=0 --> Disable IPv6 support +USE_IPV6:=1 +USE_DEBUG:=1 +USE_ASM:=1 +ifneq (${USE_DEBUG}, 0) + DEBUGFLAGS=-ggdb3 +endif + +# CHANGE IT FOR YOU +# +STANDALONE=/home/lialh4/Android/Sdk/ndk/arm-linux-androideabi/ +SYSROOT=--sysroot=$(STANDALONE)/sysroot +CXFLAGS=$SYSROOT +ARCH=armv7a +V=28 +CXX=$(STANDALONE)/bin/clang++ +CC=$(STANDALONE)/bin/clang +# +# # +LINK:=$(CXX) +LDFLAGS= +DEFS=-DBOOST_SPIRIT_THREADSAFE -DBOOST_THREAD_USE_LIB -DBOOST_NO_CXX11_SCOPED_ENUMS -DBOOST_ASIO_ENABLE_OLD_SERVICES -D_FILE_OFFSET_BITS=64 -DUSE_NATIVE_I2P + +DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(CURDIR)/i2psam $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH) $(ANDROID_INCLUDE_PATH) $(STANDALONE)/sysroot/usr/include/) +LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH) $(ANDROID_LIB_PATH) $(STANDALONE)/sysroot/usr/lib/$(ARCH)-linux-android) + +LMODE = static +LMODE2 = dynamic +ifdef STATIC + LMODE = static + ifeq (${STATIC}, all) + LMODE2 = static + endif +else + TESTDEFS += -DBOOST_TEST_DYN_LINK +endif + +# for boost 1.37, add -mt to the boost libraries +LIBS += \ + -Wl,-B$(LMODE) \ + -lboost_system$(BOOST_LIB_SUFFIX) \ + -lboost_filesystem$(BOOST_LIB_SUFFIX) \ + -lboost_program_options$(BOOST_LIB_SUFFIX) \ + -lboost_thread$(BOOST_LIB_SUFFIX) \ + -lboost_chrono$(BOOST_LIB_SUFFIX) \ + -ldb_cxx$(BDB_LIB_SUFFIX) \ + -lssl -lcrypto -lz -ldl -lc + #$(OPENSSL_LIB_PATH)/libssl.a \ + #$(OPENSSL_LIB_PATH)/libcrypto.a + +TESTLIBS += \ + -Wl,-B$(LMODE) \ + -lboost_unit_test_framework$(BOOST_LIB_SUFFIX) + +ifneq (${USE_IPV6}, -) + DEFS += -DUSE_IPV6=$(USE_IPV6) +endif + +LIBS += \ + -Wl,-B$(LMODE2) \ +# -lc \ +# -lpthread + +# Hardening +# Make some classes of vulnerabilities unexploitable in case one is discovered. +# + # This is a workaround for Ubuntu bug #691722, the default -fstack-protector causes + # -fstack-protector-all to be ignored unless -fno-stack-protector is used first. + # see: https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/691722 + HARDENING=#-fno-stack-protector + + # Stack Canaries + # Put numbers at the beginning of each stack frame and check that they are the same. + # If a stack buffer if overflowed, it writes over the canary number and then on return + # when that number is checked, it won't be the same and the program will exit with + # a "Stack smashing detected" error instead of being exploited. + HARDENING+=#-fstack-protector-all -Wstack-protector + + # Make some important things such as the global offset table read only as soon as + # the dynamic linker is finished building it. This will prevent overwriting of addresses + # which would later be jumped to. + LDHARDENING+=#-Wl,-z,relro -Wl,-z,now + + # Build position independent code to take advantage of Address Space Layout Randomization + # offered by some kernels. + # see doc/build-unix.txt for more information. + ifdef PIE + HARDENING+=-fPIE + LDHARDENING+=-pie + endif + + # -D_FORTIFY_SOURCE=2 does some checking for potentially exploitable code patterns in + # the source such overflowing a statically defined buffer. + HARDENING+=-D_FORTIFY_SOURCE=2 +# + + +# CXXFLAGS can be specified on the make command line, so we use xCXXFLAGS that only +# adds some defaults in front. Unfortunately, CXXFLAGS=... $(CXXFLAGS) does not work. +xCXXFLAGS = -std=c++11 -O2 -static -Wall $(SYSROOT) -fstack-protector-strong -fno-builtin-memmove -Wextra -Wformat -Wformat-security -Wno-unused-parameter \ + $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS) + +# LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only +# adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work. +xLDFLAGS=$(LDHARDENING) $(LDFLAGS) + +OBJS = \ + leveldb/libleveldb.a \ + obj/alert.o \ + obj/version.o \ + obj/checkpoints.o \ + obj/netbase.o \ + obj/addrman.o \ + obj/crypter.o \ + obj/key.o \ + obj/db.o \ + obj/init.o \ + obj/keystore.o \ + obj/i2p.o \ + obj/i2psam.o \ + obj/Gost.o \ + obj/main.o \ + obj/net.o \ + obj/protocol.o \ + obj/bitcoinrpc.o \ + obj/rpcdump.o \ + obj/rpcnet.o \ + obj/rpcmining.o \ + obj/rpcwallet.o \ + obj/rpcblockchain.o \ + obj/rpcrawtransaction.o \ + obj/script.o \ + obj/sync.o \ + obj/util.o \ + obj/wallet.o \ + obj/walletdb.o \ + obj/hash.o \ + obj/bloom.o \ + obj/noui.o \ + obj/leveldb.o \ + obj/txdb.o + +all: gostcoind + +test check: test_gostcoin FORCE + ./test_gostcoin + +# +# LevelDB support +# +MAKEOVERRIDES = +LIBS += $(CURDIR)/leveldb/libleveldb.a $(CURDIR)/leveldb/libmemenv.a +DEFS += $(addprefix -I,$(CURDIR)/leveldb/include) +DEFS += $(addprefix -I,$(CURDIR)/leveldb/helpers) + +leveldb/libleveldb.a: + @echo "Building LevelDB ..." && cd leveldb && $(MAKE) CC=$(CC) CXX=$(CXX) OPT="$(xCXXFLAGS)" libleveldb.a libmemenv.a && cd .. + +# auto-generated dependencies: +-include obj/*.P +-include obj-test/*.P + +obj/build.h: FORCE + /bin/sh ../share/genbuild.sh obj/build.h + +version.cpp: obj/build.h + +DEFS += -DHAVE_BUILD_INFO + +obj/%.o: %.cpp + $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $< + @cp $(@:%.o=%.d) $(@:%.o=%.P); \ + sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ + -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ + rm -f $(@:%.o=%.d) + +obj/%.o: i2psam/%.cpp + $(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $< + @cp $(@:%.o=%.d) $(@:%.o=%.P); \ + sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ + -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ + rm -f $(@:%.o=%.d) + +gostcoind: $(OBJS:obj/%=obj/%) + $(LINK) $(xCXXFLAGS) -o $@ $^ $(xLDFLAGS) $(LIBS) + +TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp)) + +obj-test/%.o: test/%.cpp + $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $< + @cp $(@:%.o=%.d) $(@:%.o=%.P); \ + sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ + -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ + rm -f $(@:%.o=%.d) + +test_gostcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%)) + $(LINK) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ $(TESTLIBS) $(xLDFLAGS) $(LIBS) + +clean: + $(RM) -f gostcoind test_gostcoin + $(RM) -f obj/*.o + $(RM) -f obj-test/*.o + $(RM) -f obj/*.P + $(RM) -f obj-test/*.P + $(RM) -f obj/build.h + -cd leveldb && $(MAKE) clean || true + +FORCE: