#!/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://downloads.sourceforge.net/sourceforge/bitcoin
DEB_UPSTREAM_TARBALL_BASENAME_MANGLE = s/~(alpha|beta|rc)/\1/,s/$$/-src/
DEB_UPSTREAM_TARBALL_SRCDIR = $(DEB_UPSTREAM_PACKAGE)-$(DEB_UPSTREAM_TARBALL_VERSION)
DEB_UPSTREAM_TARBALL_MD5 = 4db3074a810d6bf457aa5e7468b745df

# Silence .ico and .mo files in addition to the default debian files
DEB_COPYRIGHT_CHECK_IGNORE_REGEX = ^contrib/Bitcoin.app/Contents/Resources/BitcoinAppIcon\.icns|contrib/gitian-downloader/sipa-key\.pgp|locale/.*/LC_MESSAGES/.*.mo|debian/(changelog|copyright(|_hints|_newhints))$

DEB_BUILDDIR = src

DEB_MAKE_MAKEFILE = makefile.unix

# Avoid GUI until wxWidget 2.9 is in Debian
DEB_MAKE_BUILD_TARGET = bitcoind

DEB_MAKE_CHECK_TARGET = test_bitcoin
build/bitcoind::
	$(if $(filter nocheck,$(DEB_BUILD_OPTIONS)),,src/test_bitcoin)

# Readd default flags
CXXFLAGS += -D__WXGTK__ -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, libcrypto++-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)

# FIXME: when available, enable this and install into -gui package
#CDBS_BUILD_DEPENDS += , libwxgtk2.9-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

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