TEMPLATE = app
TARGET = gostcoin-qt
VERSION = 0.8.5.12
INCLUDEPATH += ../src ../src/json ../src/qt ../src/i2psam
QT += core gui network widgets androidextras
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE BOOST_NO_CXX11_SCOPED_ENUMS _FILE_OFFSET_BITS=64 ANDROID=1 __ANDROID__
CONFIG += no_include_pwd
CONFIG += thread
QMAKE_CXXFLAGS = -std=c++11 -fstack-protector-strong -fno-builtin-memmove

OBJECTS_DIR = build
MOC_DIR = build
UI_DIR = build

USE_IPV6=0
USE_LEVELDB=1
USE_ASM=1

# git clone https://github.com/PurpleI2P/Boost-for-Android-Prebuilt.git
# git clone https://github.com/PurpleI2P/OpenSSL-for-Android-Prebuilt.git
# git clone https://github.com/PurpleI2P/MiniUPnP-for-Android-Prebuilt.git
# git clone https://github.com/GOSTSec/android-ifaddrs-from-android-source.git
MAIN_PATH = /path/to/libraries
ANDROID_NDK_PLATFORM = /path/to/android-ndk
ANDROID_PLATFORM = android-14

QMAKE_CXXFLAGS += -DANDROID --sysroot=$$ANDROID_NDK_ROOT/platforms/$$ANDROID_PLATFORM/arch-arm/ -std=c++11

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

CONFIG += mobility

MOBILITY =

INCLUDEPATH += \
        $$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/4.9/include \
        $$ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include \
        $$BOOST_PATH/include \
        $$OPENSSL_PATH/include \
        $$IFADDRS_PATH \
        $$BDB_PATH \
        build

DISTFILES += AndroidManifest.xml

ANDROID_PACKAGE_SOURCE_DIR = $$PWD/

SOURCES += $$IFADDRS_PATH/ifaddrs.cpp $$IFADDRS_PATH/bionic_netlink.cpp
HEADERS += $$IFADDRS_PATH/ifaddrs.h $$IFADDRS_PATH/ErrnoRestorer.h $$IFADDRS_PATH/bionic_netlink.h $$IFADDRS_PATH/bionic_macros.h

#LIBS += -Wl,-Bstatic

equals(ANDROID_TARGET_ARCH, armeabi-v7a){
    DEFINES += ANDROID_ARM7A
    LIBS += $${BOOST_LIB_PATH}/libboost_atomic.a \
            $${BOOST_LIB_PATH}/libboost_chrono.a \
            $${BOOST_LIB_PATH}/libboost_filesystem.a \
            $${BOOST_LIB_PATH}/libboost_program_options.a \
            $${BOOST_LIB_PATH}/libboost_system.a \
            $${BOOST_LIB_PATH}/libboost_thread.a \
            $${OPENSSL_LIB_PATH}/libssl.a \
            $${OPENSSL_LIB_PATH}/libcrypto.a
}

equals(ANDROID_TARGET_ARCH, x86){
    error("Android BDB: don't know how to build BDB for Android x86")
}

# linking with libdb-c++
LIBS += $$BDB_PATH/libdb_cxx.a

# use: qmake "USE_QRCODE=1"
# libqrencode (http://fukuchi.org/works/qrencode/index.en.html) must be installed for support
contains(USE_QRCODE, 1) {
    message(Building with QRCode support)
    DEFINES += USE_QRCODE
    LIBS += -lqrencode
}

# use: qmake "USE_IPV6=1" ( enabled by default; default)
#  or: qmake "USE_IPV6=0" (disabled by default)
#  or: qmake "USE_IPV6=-" (not supported)
contains(USE_IPV6, -) {
    message(Building without IPv6 support)
} else {
    count(USE_IPV6, 0) {
        USE_IPV6=1
    }
    DEFINES += USE_IPV6=$$USE_IPV6
}

contains(BITCOIN_NEED_QT_PLUGINS, 1) {
    DEFINES += BITCOIN_NEED_QT_PLUGINS
    QTPLUGIN += qcncodecs qjpcodecs qtwcodecs qkrcodecs qtaccessiblewidgets
}

INCLUDEPATH += ../src/leveldb/include ../src/leveldb/helpers
LIBS += $$PWD/../src/leveldb/libleveldb.a $$PWD/../src/leveldb/libmemenv.a

# TODO: rewrite!
#!android {
#    genleveldb.commands = echo "QMAKE_CXXFLAGS $$QMAKE_CXXFLAGS" && cd $$PWD/../src/leveldb && TARGET_OS=OS_ANDROID_CROSSCOMPILE CC=$$QMAKE_CC CXX=$$QMAKE_CXX AR=$$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar $(MAKE) OPT=\"-I $$ANDROID_NDK_ROOT/platforms/$$ANDROID_PLATFORM/arch-arm/usr/include/ -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/ $$QMAKE_CXXFLAGS \" libleveldb.a libmemenv.a
#}
#genleveldb.target = $$PWD/../src/leveldb/libleveldb.a
#genleveldb.depends = FORCE

#PRE_TARGETDEPS += $$PWD/../src/leveldb/libleveldb.a
#QMAKE_EXTRA_TARGETS += genleveldb
# Gross ugly hack that depends on qmake internals, unfortunately there is no other way to do it.
#QMAKE_CLEAN += $$PWD/../src/leveldb/libleveldb.a; cd $$PWD/../src/leveldb ; $(MAKE) clean

# regenerate ../src/build.h
#contains(USE_BUILD_INFO, 1) {
#    genbuild.depends = FORCE
#    # TODO: make it compatible with android
#    genbuild.commands = cd $$PWD; /bin/sh ../share/genbuild.sh $$OUT_PWD/build/build.h
#    genbuild.target = $$OUT_PWD/build/build.h
#    PRE_TARGETDEPS += $$OUT_PWD/build/build.h
#    QMAKE_EXTRA_TARGETS += genbuild
#    DEFINES += HAVE_BUILD_INFO
#}

#QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -Wstack-protector
QMAKE_CXXFLAGS_WARN_ON = -Wno-unused-parameter

# Input
DEPENDPATH += ../src ../src/json ../src/qt
HEADERS += ../src/qt/bitcoingui.h \
    ../src/qt/transactiontablemodel.h \
    ../src/qt/addresstablemodel.h \
    ../src/qt/optionsdialog.h \
    ../src/qt/sendcoinsdialog.h \
    ../src/qt/coincontroldialog.h \
    ../src/qt/coincontroltreewidget.h \
    ../src/qt/addressbookpage.h \
    ../src/qt/signverifymessagedialog.h \
    ../src/qt/aboutdialog.h \
    ../src/qt/editaddressdialog.h \
    ../src/qt/bitcoinaddressvalidator.h \
    ../src/alert.h \
    ../src/addrman.h \
    ../src/base58.h \
    ../src/bignum.h \
    ../src/checkpoints.h \
    ../src/coincontrol.h \
    ../src/compat.h \
    ../src/sync.h \
    ../src/util.h \
    ../src/hash.h \
    ../src/uint256.h \
    ../src/serialize.h \
    ../src/main.h \
    ../src/net.h \
    ../src/key.h \
    ../src/db.h \
    ../src/walletdb.h \
    ../src/script.h \
    ../src/init.h \
    ../src/bloom.h \
    ../src/mruset.h \
    ../src/checkqueue.h \
    ../src/json/json_spirit_writer_template.h \
    ../src/json/json_spirit_writer.h \
    ../src/json/json_spirit_value.h \
    ../src/json/json_spirit_utils.h \
    ../src/json/json_spirit_stream_reader.h \
    ../src/json/json_spirit_reader_template.h \
    ../src/json/json_spirit_reader.h \
    ../src/json/json_spirit_error_position.h \
    ../src/json/json_spirit.h \
    ../src/i2psam/i2psam.h \
    ../src/qt/clientmodel.h \
    ../src/qt/guiutil.h \
    ../src/qt/transactionrecord.h \
    ../src/qt/guiconstants.h \
    ../src/qt/optionsmodel.h \
    ../src/qt/monitoreddatamapper.h \
    ../src/qt/transactiondesc.h \
    ../src/qt/transactiondescdialog.h \
    ../src/qt/bitcoinamountfield.h \
    ../src/wallet.h \
    ../src/keystore.h \
    ../src/qt/transactionfilterproxy.h \
    ../src/qt/transactionview.h \
    ../src/qt/walletmodel.h \
    ../src/qt/walletview.h \
    ../src/qt/walletstack.h \
    ../src/qt/walletframe.h \
    ../src/bitcoinrpc.h \
    ../src/qt/overviewpage.h \
    ../src/qt/csvmodelwriter.h \
    ../src/crypter.h \
    ../src/qt/sendcoinsentry.h \
    ../src/qt/qvalidatedlineedit.h \
    ../src/qt/bitcoinunits.h \
    ../src/qt/qvaluecombobox.h \
    ../src/qt/askpassphrasedialog.h \
    ../src/protocol.h \
    ../src/qt/notificator.h \
    ../src/qt/paymentserver.h \
    ../src/allocators.h \
    ../src/ui_interface.h \
    ../src/qt/rpcconsole.h \
    ../src/i2p.h \
    ../src/Gost.h \
    ../src/version.h \
    ../src/netbase.h \
    ../src/clientversion.h \
    ../src/txdb.h \
    ../src/leveldb.h \
    ../src/threadsafety.h \
    ../src/limitedmap.h \
    ../src/qt/macnotificationhandler.h \
    ../src/qt/splashscreen.h \
    ../src/qt/showi2paddresses.h \
    ../src/qt/setupdarknet.h

SOURCES += ../src/qt/gostcoin.cpp \
    ../src/qt/bitcoingui.cpp \
    ../src/qt/transactiontablemodel.cpp \
    ../src/qt/addresstablemodel.cpp \
    ../src/qt/optionsdialog.cpp \
    ../src/qt/sendcoinsdialog.cpp \
    ../src/qt/coincontroldialog.cpp \
    ../src/qt/coincontroltreewidget.cpp \
    ../src/qt/addressbookpage.cpp \
    ../src/qt/signverifymessagedialog.cpp \
    ../src/qt/aboutdialog.cpp \
    ../src/qt/editaddressdialog.cpp \
    ../src/qt/bitcoinaddressvalidator.cpp \
    ../src/alert.cpp \
    ../src/version.cpp \
    ../src/sync.cpp \
    ../src/util.cpp \
    ../src/hash.cpp \
    ../src/netbase.cpp \
    ../src/key.cpp \
    ../src/script.cpp \
    ../src/main.cpp \
    ../src/init.cpp \
    ../src/net.cpp \
    ../src/bloom.cpp \
    ../src/checkpoints.cpp \
    ../src/addrman.cpp \
    ../src/db.cpp \
    ../src/walletdb.cpp \
    ../src/qt/clientmodel.cpp \
    ../src/qt/guiutil.cpp \
    ../src/qt/transactionrecord.cpp \
    ../src/qt/optionsmodel.cpp \
    ../src/qt/monitoreddatamapper.cpp \
    ../src/qt/transactiondesc.cpp \
    ../src/qt/transactiondescdialog.cpp \
    ../src/qt/bitcoinstrings.cpp \
    ../src/qt/bitcoinamountfield.cpp \
    ../src/wallet.cpp \
    ../src/keystore.cpp \
    ../src/qt/transactionfilterproxy.cpp \
    ../src/qt/transactionview.cpp \
    ../src/qt/walletmodel.cpp \
    ../src/qt/walletview.cpp \
    ../src/qt/walletstack.cpp \
    ../src/qt/walletframe.cpp \
    ../src/bitcoinrpc.cpp \
    ../src/rpcdump.cpp \
    ../src/rpcnet.cpp \
    ../src/rpcmining.cpp \
    ../src/rpcwallet.cpp \
    ../src/rpcblockchain.cpp \
    ../src/rpcrawtransaction.cpp \
    ../src/qt/overviewpage.cpp \
    ../src/qt/csvmodelwriter.cpp \
    ../src/crypter.cpp \
    ../src/qt/sendcoinsentry.cpp \
    ../src/qt/qvalidatedlineedit.cpp \
    ../src/qt/bitcoinunits.cpp \
    ../src/qt/qvaluecombobox.cpp \
    ../src/qt/askpassphrasedialog.cpp \
    ../src/protocol.cpp \
    ../src/qt/notificator.cpp \
    ../src/qt/paymentserver.cpp \
    ../src/qt/rpcconsole.cpp \
    ../src/i2p.cpp \
    ../src/Gost.cpp \
    ../src/noui.cpp \
    ../src/leveldb.cpp \
    ../src/txdb.cpp \
    ../src/qt/splashscreen.cpp \
    ../src/qt/showi2paddresses.cpp \
    ../src/i2psam/i2psam.cpp \
    ../src/qt/setupdarknet.cpp

RESOURCES += ../src/qt/gostcoin.qrc

FORMS += ../src/qt/forms/sendcoinsdialog.ui \
    ../src/qt/forms/coincontroldialog.ui \
    ../src/qt/forms/addressbookpage.ui \
    ../src/qt/forms/signverifymessagedialog.ui \
    ../src/qt/forms/aboutdialog.ui \
    ../src/qt/forms/editaddressdialog.ui \
    ../src/qt/forms/transactiondescdialog.ui \
    ../src/qt/forms/overviewpage.ui \
    ../src/qt/forms/sendcoinsentry.ui \
    ../src/qt/forms/askpassphrasedialog.ui \
    ../src/qt/forms/rpcconsole.ui \
    ../src/qt/forms/optionsdialog.ui \
    ../src/qt/forms/showi2paddresses.ui

contains(USE_QRCODE, 1) {
    HEADERS += ../src/qt/qrcodedialog.h
    SOURCES += ../src/qt/qrcodedialog.cpp
    FORMS += ../src/qt/forms/qrcodedialog.ui
}

contains(BITCOIN_QT_TEST, 1) {
    SOURCES += ../src/qt/test/test_main.cpp \
        ../src/qt/test/uritests.cpp
    HEADERS += ../src/qt/test/uritests.h
    DEPENDPATH += ../src/qt/test
    QT += testlib
    TARGET = anoncoin-qt_test
    DEFINES += BITCOIN_QT_TEST
    macx: CONFIG -= app_bundle
}

# for lrelease/lupdate
# also add new translations to ../src/qt/gostcoin.qrc under translations/
TRANSLATIONS = $$files(../src/qt/locale/gostcoin_*.ts)

isEmpty(QMAKE_LRELEASE) {
    QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease
}
isEmpty(QM_DIR):QM_DIR = $$PWD/../src/qt/locale
# automatically build translations, so they can be included in resource file
TSQM.name = lrelease ${QMAKE_FILE_IN}
TSQM.input = TRANSLATIONS
TSQM.output = $$QM_DIR/${QMAKE_FILE_BASE}.qm
TSQM.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} -qm ${QMAKE_FILE_OUT}
TSQM.CONFIG = no_link
QMAKE_EXTRA_COMPILERS += TSQM

# "Other files" to show in Qt Creator
OTHER_FILES += README.md \
    doc/*.rst \
    doc/*.txt \
    doc/*.md \
    ../src/qt/res/bitcoin-qt.rc \
    ../src/test/*.cpp \
    ../src/test/*.h \
    ../src/qt/test/*.cpp \
    ../src/qt/test/*.h

system($$QMAKE_LRELEASE -silent $$TRANSLATIONS)

DISTFILES += \
    ../../../S2_ATHOME/git_gostcoin/gostcoin/android/AndroidManifest.xml \
    ../../../S2_ATHOME/git_gostcoin/gostcoin/android/res/values/libs.xml \
    ../../../S2_ATHOME/git_gostcoin/gostcoin/android/build.gradle \
    ../docs/gost_android_take3.txt \
    AndroidManifest.xml \
    res/values/libs.xml
