#!/usr/bin/make -f

MEGA_BUILD_ID := $(shell cat MEGA_BUILD_ID || echo "1")
DPKGXZ := $(shell cat /etc/issue | grep "Ubuntu 23\|Lunar Lobster\|Ubuntu 22\|Jammy Jellyfish\|Ubuntu 21.10" >/dev/null && echo "-- -Zxz" || echo "")

build: build-stamp
build-stamp:
	dh_testdir
	sed -i -E "0,/dolphin-megasync \(([0-9.]*)[^\)]*\)/s//dolphin-megasync \(\1-$(MEGA_BUILD_ID).1)/" debian.changelog || :
	cmake -DCMAKE_INSTALL_PREFIX="`qtpaths --install-prefix`" -DPLUGIN_INSTALL_DIR="`qtpaths --plugin-dir`" .
	make
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

install: build
	dh_auto_install --destdir=debian/dolphin-megasync

# Build architecture-independent files here.
binary-indep: build install

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
	dh_installcron
	dh_installman
	dh_installinfo
#	dh_undocumented
	dh_installchangelogs
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
#	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb $(DPKGXZ)

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
