From b2b8c15decc29fc058923d63c6e86bcedf564648 Mon Sep 17 00:00:00 2001 From: wipedlife Date: Tue, 1 Jun 2021 00:14:58 +0300 Subject: [PATCH] Android scripts pre init --- android/compile_standalone.sh | 126 ++++++++++++++++ android/setenv-android.sh | 277 ++++++++++++++++++++++++++++++++++ src/compile_android.sh | 23 +++ src/makefile.android | 203 +++++++++++++++++++++++++ 4 files changed, 629 insertions(+) create mode 100755 android/compile_standalone.sh create mode 100755 android/setenv-android.sh create mode 100755 src/compile_android.sh create mode 100644 src/makefile.android diff --git a/android/compile_standalone.sh b/android/compile_standalone.sh new file mode 100755 index 0000000..b65300e --- /dev/null +++ b/android/compile_standalone.sh @@ -0,0 +1,126 @@ +#!/bin/bash +# ndk/build/tools/make_standalone_toolchain.py for standalone build +preinit(){ + #CHANGE TO YOUR PATH + ANDROID_NDK_ROOT="/home/lialh4/Android/Sdk/android-ndk-r21e" + + export CPPFLAGS=--sysroot=$ANDROID_NDK_ROOT/platforms/android-21/arch-arm/ + export CXXFLAGS="--sysroot=$ANDROID_NDK_ROOT/platforms/android-21/arch-arm/ -I$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/4.9/include -I$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include" + + export ST=/home/lialh4/Android/Sdk/ndk/arm-linux-androideabi + export NDK_PATH=$ST + export boost=`pwd`/boost_1_57_0 + export C=$NDK_PATH/bin/arm-linux-androideabi-gcc + export CXX=$NDK_PATH/bin/arm-linux-androideabi-g++ + export NDK_PROJECT_PATH=$NDK_PATH + export ANDROID_NDK_ROOT=$NDK_PATH + export ANDROID_NDK_HOST=linux-x86_64 + export PATH=$ST/bin/:$PATH + export CROSS_COMPILE=arm-linux-androideabi- + export ARCH=arm + #export PREINITED_SOURCES=/home/lialh4/Android/Sdk/ndk/crystax-ndk-10.3.1/sources/ + #arm-linux-androideabi-g++ -v + export AR=$NDK_PATH/bin/arm-linux-androideabi-ar + export AS=$NDK_PATH/bin/arm-linux-androideabi-as + export CC=$NDK_PATH/bin/arm-linux-androideabi-gcc + export bdbv=18.1.40 + +} + +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; + + #if ! test -e $boost ; then + # echo "Please download libboost for android http://sourceforge.net/projects/boost/files/boost/1.57.0/boost_1_57_0.7z/download and put in the $(pwd) directory" + #fi; + #git clone https://github.com/moritz-wundke/Boost-for-Android.git + 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 -D__ARM_MAX_ARCH__=8 + echo $ANDROID_NDK_ROOT/platforms/android-21/arch-arm/usr/lib/ + make + 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 + #echo $ANDROID_HOME//sysroot/usr/include/ + #exit +#sources/cxx-stl/llvm-libc++/include/atomic + + ../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/" +# ../dist/configure --host=arm-linux-androideabi --enable-cxx --enable-shared --disable-replication + + make + cd .. +} +compile_boost(){ + cd boost_1_76_0 + ./bootstrap.sh + echo 'import option ; using gcc : arm : arm-linux-androideabi-g++ ;option.set keep-going : false ; '>project-config.jam + ./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 include=$NDK_PATH/sources/cxx-stl/gnu-libstdc++/4.9/include include=$NDK_PATH/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include include=$NDK_PATH/platforms/android-14/arch-arm/usr/include + cd stage/lib + for lib in *.a; + do + normalname=${lib/-gcc-mt-s-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 +source setenv-android.sh +gcc -v + +compile_db + +compile_openssl + +compile_boost +compile_level_db + +#BOOST_PATH = $$MAIN_PATH/Boost-for-Android-Prebuilt/boost_1_64_0 +#OPENSSL_PATH = $$MAIN_PATH/OpenSSL-for-Android-Prebuilt/openssl-1.1.1 +#IFADDRS_PATH = $$MAIN_PATH/android-ifaddrs-from-android-source +#BDB_PATH = $$MAIN_PATH/db-6.0.20/build_unix +#BOOST_LIB_PATH = $$BOOST_PATH/$$ANDROID_TARGET_ARCH/lib +#OPENSSL_LIB_PATH = $$OPENSSL_PATH/$$ANDROID_TARGET_ARCH/lib +#cd ../src/ +#make -f makefile.android +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..f2c6caa --- /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-r17c" + +# 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-21" + + +# armeabi/armeabi-v7a toogler (for gcc) +# If you build for armeabi, change to false +IsARMv7=true + +##################################################################### + +# 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..8cadb70 --- /dev/null +++ b/src/compile_android.sh @@ -0,0 +1,23 @@ +andr=$(pwd)/../android +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/ +#read +if ! test -e gostcoind;then + make -f makefile.android +fi; + +#mkdir -p android_build +#cd android_build +#cp ../gostcoind . +#cp $OPENSSL_LIB_PATH/*.so* . +#tar cvpf gostcoind.tar * +#ls $BOOST_LIB_PATH # there is static... +#ls $BDB_LIB_PATH # there is too diff --git a/src/makefile.android b/src/makefile.android new file mode 100644 index 0000000..a66f415 --- /dev/null +++ b/src/makefile.android @@ -0,0 +1,203 @@ +# 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:=0 +CXX=/home/lialh4/Android/Sdk/ndk/arm-linux-androideabi/bin/arm-linux-androideabi-g++ +LINK:=$(CXX) +LDFLAGS=-static +DEFS=-DBOOST_SPIRIT_THREADSAFE -DBOOST_NO_CXX11_SCOPED_ENUMS -DBOOST_ASIO_ENABLE_OLD_SERVICES -D_FILE_OFFSET_BITS=64 -DUSE_NATIVE_I2P -static + +DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(CURDIR)/i2psam $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH) $(ANDROID_INCLUDE_PATH)) +LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH) $(ANDROID_LIB_PATH)) + +TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data) + +LMODE = dynamic +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 + +TESTLIBS += \ + -Wl,-B$(LMODE) \ + -lboost_unit_test_framework$(BOOST_LIB_SUFFIX) + +ifneq (${USE_IPV6}, -) + DEFS += -DUSE_IPV6=$(USE_IPV6) +endif + +LIBS += \ + -Wl,-B$(LMODE2) \ + -lz \ + -ldl \ + #-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 +# + +ifneq (${USE_DEBUG}, 0) + DEBUGFLAGS=-g +endif + +# 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-libgcc -static-libstdc++ -static -Wall -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: