#!/usr/bin/make -f
# Based on the multi2 sample debian/rules file:
# ---
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess.

#export DH_VERBOSE=1
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk
#include /usr/share/cdbs/1/rules/simple-patchsys.mk

# The following is for systems that support hardened builds.
# Not all systems have this support, so make it conditional on buildflags.mk
ifneq ($(strip $(wildcard /usr/share/dpkg/buildflags.mk)),)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND = -Wall
include /usr/share/dpkg/buildflags.mk
endif

# where sources are
DEB_SRCDIR = .

# in which directory to build
DEB_BUILDDIR = .

# in which directory to install the sofware
DEB_DESTDIR = $(CURDIR)/debian/tmp

#CDBS automatically handles common flags to pass to the configure script,
#but it is possible to give some extra parameters :
DEB_CONFIGURE_EXTRA_FLAGS := --enable-boost --enable-nls --with-zlib --enable-gui --enable-desktop --with-guisu=/usr/bin/gksu $(BARRY_CONFIGURE_OPTS) --with-libusb --enable-rpathhack --without-evolution
COMMON_CONFIGURE_FLAGS := --prefix=/usr
DEB_INSTALL_DOCS_ALL =

install/barry-util::
ifeq ($(DEB_HOST_ARCH_OS), linux)
	# Install udev rules for the barry-util package
	install -d $(CURDIR)/debian/barry-util/lib/udev/rules.d
	install -m 0644 \
		$(DEB_SRCDIR)/udev/10-blackberry.rules \
		$(DEB_SRCDIR)/udev/99-blackberry-perms.rules \
		$(CURDIR)/debian/barry-util/lib/udev/rules.d
endif
	# Install modprobe blacklist file for bcharge, into barry-util package
	install -d $(CURDIR)/debian/barry-util/etc/modprobe.d
	install -m 0644 $(DEB_SRCDIR)/modprobe/blacklist-berry_charge.conf $(CURDIR)/debian/barry-util/etc/modprobe.d/blacklist-berry_charge.conf
	# Install default ppp options and chat scripts
	install -d $(CURDIR)/debian/barry-util/etc/ppp/peers
	install -m 0644 \
		$(DEB_SRCDIR)/ppp/barry-rogers \
		$(DEB_SRCDIR)/ppp/barry-minimal \
		$(DEB_SRCDIR)/ppp/barry-verizon \
		$(DEB_SRCDIR)/ppp/barry-sprint \
		$(DEB_SRCDIR)/ppp/barry-telus \
		$(DEB_SRCDIR)/ppp/barry-o2ireland \
		$(DEB_SRCDIR)/ppp/barry-emobile \
		$(DEB_SRCDIR)/ppp/barry-tmobileus \
		$(DEB_SRCDIR)/ppp/barry-att_cingular \
		$(DEB_SRCDIR)/ppp/barry-chinamobile \
		$(DEB_SRCDIR)/ppp/barry-kpn \
		$(DEB_SRCDIR)/ppp/barry-orange-spain \
		$(DEB_SRCDIR)/ppp/barry-orangeuk \
		$(DEB_SRCDIR)/ppp/barry-mts \
		$(DEB_SRCDIR)/ppp/barry-optus-au \
		$(DEB_SRCDIR)/ppp/barry-vodafone-au \
		$(CURDIR)/debian/barry-util/etc/ppp/peers
	install -d $(CURDIR)/debian/barry-util/etc/chatscripts
	install -m 0640 \
		$(DEB_SRCDIR)/ppp/barry-rogers.chat \
		$(DEB_SRCDIR)/ppp/barry-minimal.chat \
		$(DEB_SRCDIR)/ppp/barry-verizon.chat \
		$(DEB_SRCDIR)/ppp/barry-sprint.chat \
		$(DEB_SRCDIR)/ppp/barry-telus.chat \
		$(DEB_SRCDIR)/ppp/barry-o2ireland.chat \
		$(DEB_SRCDIR)/ppp/barry-emobile.chat \
		$(DEB_SRCDIR)/ppp/barry-tmobileus.chat \
		$(DEB_SRCDIR)/ppp/barry-att_cingular.chat \
		$(DEB_SRCDIR)/ppp/barry-chinamobile.chat \
		$(DEB_SRCDIR)/ppp/barry-kpn.chat \
		$(DEB_SRCDIR)/ppp/barry-orange-spain.chat \
		$(DEB_SRCDIR)/ppp/barry-orangeuk.chat \
		$(DEB_SRCDIR)/ppp/barry-mts.chat \
		$(DEB_SRCDIR)/ppp/barry-optus-au.chat \
		$(DEB_SRCDIR)/ppp/barry-vodafone-au.chat \
		$(CURDIR)/debian/barry-util/etc/chatscripts
	# Install hal fdi configs
	install -d $(CURDIR)/debian/barry-util/usr/share/hal/fdi/information/10freedesktop
	install -d $(CURDIR)/debian/barry-util/usr/share/hal/fdi/policy/10osvendor
	install -m 0644 $(DEB_SRCDIR)/hal/fdi/information/10freedesktop/10-blackberry.fdi $(CURDIR)/debian/barry-util/usr/share/hal/fdi/information/10freedesktop
	install -m 0644 $(DEB_SRCDIR)/hal/fdi/policy/10osvendor/19-blackberry-acl.fdi $(CURDIR)/debian/barry-util/usr/share/hal/fdi/policy/10osvendor
	# Install hal support script
	install -d $(CURDIR)/debian/barry-util/usr/lib/barry
	install -m 0755 $(DEB_SRCDIR)/hal/hal-blackberry $(CURDIR)/debian/barry-util/usr/lib/barry
	# Install bash and zsh completion scripts
	install -d $(CURDIR)/debian/barry-util/etc/bash_completion.d
	install -m 0644 \
		$(DEB_SRCDIR)/bash/bjavaloader \
		$(DEB_SRCDIR)/bash/btool \
		$(CURDIR)/debian/barry-util/etc/bash_completion.d
	# Install examples/ into libbarry-dev
	install -d $(CURDIR)/debian/libbarry-dev/usr/share/doc/libbarry-dev/examples
	install -m 0644 $(DEB_SRCDIR)/examples/*.cc \
		$(CURDIR)/debian/libbarry-dev/usr/share/doc/libbarry-dev/examples

install/barrybackup-gui::
	# Install barry icon
	install -d $(CURDIR)/debian/barrybackup-gui/usr/share/pixmaps
	install -m 0644 $(DEB_SRCDIR)/logo/barry_logo_debian_menu_icon.xpm $(CURDIR)/debian/barrybackup-gui/usr/share/pixmaps/barry_backup_menu_icon.xpm
	# Install Gnome .desktop file
	install -d $(CURDIR)/debian/barrybackup-gui/usr/share/applications
	install -m 0644 $(DEB_SRCDIR)/menu/barrybackup.desktop $(CURDIR)/debian/barrybackup-gui/usr/share/applications

install/barrydesktop::
	# Install barry icon
	install -d $(CURDIR)/debian/barrydesktop/usr/share/pixmaps
	install -m 0644 $(DEB_SRCDIR)/logo/barry_logo_debian_menu_icon.xpm $(CURDIR)/debian/barrydesktop/usr/share/pixmaps/barry_desktop_menu_icon.xpm
	# Install Gnome .desktop file
	install -d $(CURDIR)/debian/barrydesktop/usr/share/applications
	install -m 0644 $(DEB_SRCDIR)/menu/barrydesktop.desktop $(CURDIR)/debian/barrydesktop/usr/share/applications

install/barry-doc::
	# Build the static version of the docs
	cp -a $(DEB_SRCDIR)/doc/www $(CURDIR)/debian
	cd $(CURDIR)/debian/www && ./static.sh
	# Install to share/doc
	install -d $(CURDIR)/debian/barry-doc/usr/share/doc/barry-doc/www
	install -m 0644 $(CURDIR)/debian/www/*.html $(CURDIR)/debian/www/*.png $(CURDIR)/debian/www/*.css $(CURDIR)/debian/barry-doc/usr/share/doc/barry-doc/www

post-patches::
	@rm -f $(CURDIR)/deb_srcdir
	@ln -s $(DEB_SRCDIR) $(CURDIR)/deb_srcdir
	@test -x $(DEB_SRCDIR)/configure && echo "allready autoreconf" || (cd $(DEB_SRCDIR) && autoreconf -i)

os22-binary::
	# DEB_SRCDIR can be relative, so change into directory to use pwd.
	#
	# Note: that the compiler flags below depend on opensync-plugin's
	# debian/rules having a DESTDIR target of opensync-plugin/debian/tmp
	(cd $(DEB_SRCDIR) && \
		export TREE_BUILD_CXXFLAGS="-I`pwd`/opensync-plugin/debian/tmp/usr/include/barry18" && \
		export TREE_BUILD_LDFLAGS="-L`pwd`/opensync-plugin/debian/tmp/usr/lib" && \
		export PKG_CONFIG_PATH="`pwd`:$(PKG_CONFIG_PATH)" && \
		export LD_LIBRARY_PATH="`pwd`/opensync-plugin/debian/tmp/usr/lib:$(LD_LIBRARY_PATH)" && \
		cd opensync-plugin && \
		debian/rules TREE_BUILD_DIR="`pwd`/.." binary)

os22-clean::
	(cd $(DEB_SRCDIR)/opensync-plugin && debian/rules clean)

os4x-binary::
	# DEB_SRCDIR can be relative, so change into directory to use pwd.
	#
	# Note: that the compiler flags below depend on opensync-plugin-0.4x's
	# debian/rules having a DESTDIR target of opensync-plugin-0.4x/debian/tmp
	(cd $(DEB_SRCDIR) && \
		export TREE_BUILD_CXXFLAGS="-I`pwd`/opensync-plugin-0.4x/debian/tmp/usr/include/barry18" && \
		export TREE_BUILD_LDFLAGS="-L`pwd`/opensync-plugin-0.4x/debian/tmp/usr/lib" && \
		export PKG_CONFIG_PATH="`pwd`:$(PKG_CONFIG_PATH)" && \
		export LD_LIBRARY_PATH="`pwd`/opensync-plugin-0.4x/debian/tmp/usr/lib:$(LD_LIBRARY_PATH)" && \
		cd opensync-plugin-0.4x && \
		debian/rules TREE_BUILD_DIR="`pwd`/.." binary)

os4x-clean::
	(cd $(DEB_SRCDIR)/opensync-plugin-0.4x && debian/rules clean)

clean::
	-@rm -f $(CURDIR)/deb_srcdir

