#!/usr/bin/make -f

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

export DEB_VERSION_UPSTREAM
export DEB_HOST_MULTIARCH
export DEB_CFLAGS_MAINT_APPEND = -fPIC -DNDEBUG
export DEB_CXXFLAGS_MAINT_APPEND = -fPIC -DNDEBUG
export DEB_LDFLAGS_MAINT_APPEND = -fPIC

debian/out/lib%.so: debian/lib%.mk
	dh_auto_build --buildsystem=makefile -- --file=$<

debian/out/%: debian/%.mk
	dh_auto_build --buildsystem=makefile -- --file=$<

debian/%.1: debian/%.1.md
	pandoc --standalone --from=markdown-smart --to=man --output=$@ $<

%:
	dh $@ --with javahelper

override_dh_auto_build-indep:
	dh_auto_build --buildsystem=gradle -- \
	              --settings-file debian/settings.gradle
	mkdir -p debian/out
	sed 's,^ *libdir=.*,libdir=/usr/share/dexdeps,' tools/dexdeps/etc/dexdeps > debian/out/dexdeps
	jh_build --no-javadoc --main=com.android.dexdeps.Main debian/out/dexdeps.jar tools/dexdeps/src
	pandoc --standalone --from=markdown-smart --to=man --output=debian/dexdeps.1 debian/dexdeps.1.md

override_dh_auto_clean-indep:
	dh_auto_clean --indep --buildsystem=gradle
	jh_clean
	mh_clean

override_dh_auto_build-arch: debian/out/hprof-conv

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