#!/usr/bin/make -f

PKG_VERSION = 0.4.6
DEB_TARBALL = xarchiver-$(PKG_VERSION).tar.bz2
DEB_TAR_SRCDIR = xarchiver-$(PKG_VERSION)
DEB_DH_INSTALL_SOURCEDIR = build-tree/$(DEB_TAR_SRCDIR)

include /usr/share/cdbs/1/rules/tarball.mk
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/dpatch.mk

DEB_CONFIGURE_EXTRA_FLAGS += --libexecdir="\$${prefix}/lib"
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    MAKEFLAGS += -j$(NUMJOBS)
endif
ifneq (,$(findstring thumb,$(DEB_BUILD_OPTIONS)))
    CFLAGS += -mthumb
endif

# Damnit... dpatch.mk does not include a way to add dpatch options,
# thus we have to do a trick in order to apply patches to our subdirectory ...
export PATH := $(CURDIR):$(PATH)
debian/stamp-patched deapply-dpatches: dpatch
dpatch:
	echo '#!/bin/sh' >$@
	echo 'exec /usr/bin/dpatch -d $(DEB_DH_INSTALL_SOURCEDIR) $$*' >>$@
	chmod a+x $@

clean::
	rm -f dpatch *.cdbs-config_list

post-patches::
	cd $(DEB_DH_INSTALL_SOURCEDIR) && \
		autoheader && \
		autoconf && \
		automake-1.9

install/xarchiver::
	uudecode debian/xarchiver-26.b64 -o debian/xarchiver/usr/share/icons/hicolor/26x26/apps/xarchiver.png
	uudecode debian/xarchiver-40.b64 -o debian/xarchiver/usr/share/icons/hicolor/40x40/apps/xarchiver.png
	uudecode debian/xarchiver-64.b64 -o debian/xarchiver/usr/share/icons/hicolor/64x64/apps/xarchiver.png
	uudecode debian/application-x-cd-image-26.b64 -o debian/xarchiver/usr/share/icons/hicolor/26x26/mimetypes/application-x-cd-image.png
	uudecode debian/application-x-cd-image-48.b64 -o debian/xarchiver/usr/share/icons/hicolor/48x48/mimetypes/application-x-cd-image.png
	uudecode debian/application-x-cd-image-64.b64 -o debian/xarchiver/usr/share/icons/hicolor/64x64/mimetypes/application-x-cd-image.png

binary-post-install/xarchiver::
	echo "X-Osso-Type=application/x-executable" >>debian/xarchiver/usr/share/applications/xarchiver.desktop
	echo "X-Osso-Service=org.maemo.xarchiver" >>debian/xarchiver/usr/share/applications/xarchiver.desktop
	mv debian/xarchiver/usr/share/applications/xarchiver.desktop debian/xarchiver/usr/share/applications/hildon
	mv -f debian/xarchiver/usr/share/doc/xarchiver/html debian/xarchiver/usr/share/xarchiver/html
	rm -rf debian/xarchiver/usr/share/doc/xarchiver
	rm -rf debian/xarchiver/usr/lib
	rm -rf debian/xarchiver/usr/share/doc
