#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

UPSTREAM_TAG = android-$(subst +,_,$(DEB_VERSION_UPSTREAM))
# See sdk/build_tools_source.prop_template in platform/development
export BUILD_TOOLS_VERSION = 23.0.2
GRADLE_OPTIONS = --settings-file debian/settings.gradle

%:
	dh $@

override_dh_auto_build-indep:
	dh_auto_build --buildsystem=gradle -- $(GRADLE_OPTIONS) assemble poms

override_dh_auto_clean-indep:
	dh_auto_clean --indep --buildsystem=gradle
	mh_clean
	$(RM) -r debian/.gradle

override_dh_auto_build-arch:
	make -f debian/libdex.mk
	make -f debian/dexdump.mk
	pandoc -s -o debian/dexdump.1 debian/dexdump.1.md
	make -f debian/dmtracedump.mk
	pandoc -s -o debian/dmtracedump.1 debian/dmtracedump.1.md
	make -f debian/hprof-conv.mk
	pandoc -s -o debian/hprof-conv.1 debian/hprof-conv.1.md

override_dh_auto_clean-arch:
	dh_auto_clean --arch
	make clean -f debian/libdex.mk
	make clean -f debian/dexdump.mk
	make clean -f debian/dmtracedump.mk
	make clean -f debian/hprof-conv.mk
	$(RM) debian/*.1

override_dh_install-indep:
	dh_install --indep
	chmod +x debian/dalvik-exchange/usr/lib/android-sdk/build-tools/${BUILD_TOOLS_VERSION}/dx
	mh_install
	jh_depends

override_dh_shlibdeps:
	dh_shlibdeps -l/usr/lib/android

get-orig-source: $(UPSTREAM_TAG).tar.gz
	mk-origtargz --repack --compression xz $<

$(UPSTREAM_TAG).tar.gz:
	wget https://android.googlesource.com/platform/dalvik/+archive/$(UPSTREAM_TAG).tar.gz