#!/usr/bin/make -f

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
endif

ifeq (,$(NUMJOBS))
	NUMJOBS = 1
endif

BUILDDIR = builddir

CMAKEOPTS = -DCMAKE_BUILD_TYPE=RelWithDebInfo \
            -DCMAKE_INSTALL_PREFIX=/usr \
            -DUSE_MINIUPNP=ON -DLOCAL_MINIUPNP=OFF \
            -DLUA_SCRIPT=ON -DWITH_LUASCRIPTS=ON \
            -DPERL_REGEX=ON -DWITH_DHT=OFF \
            -DWITH_SOUNDS=ON \
            -DUSE_QT=ON \
            -DUSE_ASPELL=ON -DFREE_SPACE_BAR_C=ON -DUSE_JS=ON \
            -DUSE_QT_SQLITE=ON \
            -DUSE_GTK=ON \
            -DUSE_LIBGNOME2=OFF -DUSE_LIBNOTIFY=ON \
            -DCREATE_MO=ON -DUPDATE_PO=OFF \
            -DNO_UI_DAEMON=ON \
            -DXMLRPC_DAEMON=OFF \
            ..

# This option is for daily builds of the EiskaltDC++ packages on Launchpad
# See https://launchpad.net/~tehnick/+archive/tehnick for more information
#REVISION = $(shell /bin/sh -c "head -n 1 debian/changelog | sed -e 's/^.*-[0-9]\{6,6\}-//' -e 's/-0ppa.*$$//'")
#CMAKEOPTS += -DDCPP_REVISION="$(REVISION)"


configure: configure-stamp
configure-stamp:
	dh_testdir
	mkdir -p $(BUILDDIR) && cd $(BUILDDIR) && cmake $(CMAKEOPTS)
	touch $@
build: configure build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
	dh_testdir
	cd $(BUILDDIR) && $(MAKE) -j$(NUMJOBS)
	touch $@
clean: do-clean
do-clean:
	dh_testdir
	dh_testroot
	[ ! -f Makefile ] || ( cd $(BUILDDIR) && $(MAKE) clean )
	test ! -d $(BUILDDIR) || rm -r $(BUILDDIR)
	dh_clean
install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	cd $(BUILDDIR) && $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
binary-indep: build install
	dh_testdir -i
	dh_testroot -i
	dh_movefiles -i
	dh_installdocs -i
	dh_installchangelogs -i ChangeLog.txt
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_installdebconf -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i
binary-arch: build install
	dh_testdir -a
	dh_testroot -a
	dh_movefiles -a
	dh_installchangelogs -a ChangeLog.txt
	dh_installdocs -a
	dh_installman -a
	dh_link -a
	dh_strip -Nlibeiskaltdcpp2.2 -Neiskaltdcpp-qt -Neiskaltdcpp-gtk -Neiskaltdcpp-daemon
	dh_strip -plibeiskaltdcpp2.2 --dbg-package=libeiskaltdcpp2.2-dbg
	dh_strip -peiskaltdcpp-qt --dbg-package=eiskaltdcpp-qt-dbg
	dh_strip -peiskaltdcpp-gtk --dbg-package=eiskaltdcpp-gtk-dbg
	dh_strip -peiskaltdcpp-daemon --dbg-package=eiskaltdcpp-daemon-dbg
	dh_compress -a
	dh_fixperms -a
	dh_makeshlibs -plibeiskaltdcpp2.2
	dh_installdeb -a
	dh_shlibdeps -a -ldebian/libeiskaltdcpp2.2/usr/lib
	dh_installdebconf -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure patch unpatch do-clean
