#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2010-2011 Jonas Smedegaard <dr@jones.dk>
# Description: Main Debian packaging script for Bitcoin
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

-include /usr/share/cdbs/1/rules/upstream-tarball.mk
include /usr/share/cdbs/1/class/makefile.mk
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/rules/utils.mk

DEB_UPSTREAM_URL = http://githubredir.debian.net/github/bitcoin/bitcoin
DEB_UPSTREAM_TARBALL_BASENAME = v$(DEB_UPSTREAM_TARBALL_VERSION)
DEB_UPSTREAM_TARBALL_BASENAME_MANGLE = s/~(alpha|beta|rc)/\1/
DEB_UPSTREAM_WGET_OPTS += --no-check-certificate
DEB_UPSTREAM_TARBALL_MD5 = 35dd6d3a67b1fd6ebe79409ce1dfa7e0

# Ignore graphics and .mo files in addition to the default debian files
DEB_COPYRIGHT_CHECK_IGNORE_REGEX = ^(doc/bitcoin_logo_doxygen\.png|src/qt/res/icons/.*\.png|contrib/Bitcoin.app/Contents/Resources/BitcoinAppIcon\.icns|contrib/gitian-downloader/sipa-key\.pgp|debian/(changelog|copyright(|_hints|_newhints)))$

DEB_SRCDIR = src

DEB_MAKE_MAKEFILE = makefile.unix

DEB_MAKE_CHECK_TARGET = test_bitcoin
build/bitcoind::
	mkdir -p testhome
	$(if $(filter nocheck,$(DEB_BUILD_OPTIONS)),,HOME="testhome" src/test_bitcoin)

# Readd default flags
CXXFLAGS += -DNOPCH -DUSE_SSL
#CXXFLAGS += -Wno-invalid-offsetof -Wformat

# Silence seemingly harmless noise about unused variables
CXXFLAGS += -Wno-unused-variable

# Use optimized miner for amd64 only
CXXFLAGS += $(if $(filter amd64,$(DEB_HOST_ARCH)),-DFOURWAYSSE2)

DEB_INSTALL_EXAMPLES_bitcoind += debian/examples/*
DEB_INSTALL_MANPAGES_bitcoind += debian/manpages/*

# Apparently any recent boost is ok.  Unversioned Boost in Lenny is too
# old, however (do not include libboost-system*), so add fallback to
# ease backporting
boostver =
boostoldver = 1.35
boostdep = $(foreach dep,$1,libboost-$(dep)$(boostver)-dev (>> $(boostoldver)) | libboost-$(dep)$(boostoldver)-dev$(comma) )

CDBS_BUILD_DEPENDS += , $(call boostdep,system), libdb++-dev | libdb4.6++-dev, libssl-dev, pkg-config, libglib2.0-dev, libminiupnpc-dev
# TODO: Drop this when maybe system json is used some day
CDBS_BUILD_DEPENDS += , $(call boostdep,filesystem program-options thread test)

# TODO: fix support DEB_QMAKE_BUILDDIR and install binary into -qt package
#CDBS_BUILD_DEPENDS += , qt4-qmake, libqt4-dev

CDBS_SUGGESTS_bitcoind = db-util, db4.8-util, db4.7-util

# Upstream README contains no parts relevant for Debian usage
DEB_INSTALL_DOCS_ALL =

pre-build::
	mkdir -p src/obj/nogui
clean::
	find src/obj -type f -not -name .gitignore -delete
	rm -f src/bitcoind
	rm -rf testhome

# Ensure wrapper is set executable
binary-post-install/bitcoind::
	chmod +x $(cdbs_curdestdir)usr/bin/bitcoind
