#!/usr/bin/make -f

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

# See sdk/build_tools_source.prop_template in platform/development
export BUILD_TOOLS_VERSION = 23.0.2
export DEB_HOST_MULTIARCH
export DEB_CFLAGS_MAINT_APPEND = -fPIC -DNDEBUG
export DEB_CPPLAGS_MAINT_APPEND = -include android/arch/AndroidConfig.h
export DEB_CXXFLAGS_MAINT_APPEND = -fPIC -DNDEBUG
export DEB_LDFLAGS_MAINT_APPEND = -fPIC
# See com/android/dx/Version.java
DX_VERSION = 1.11
UPSTREAM_TAG = android-$(subst +,_,$(DEB_VERSION_UPSTREAM))

%:
	dh $@

override_dh_auto_build-indep:
	dh_auto_build --buildsystem=gradle -- \
	              --settings-file debian/settings.gradle \
	              --project-prop dxVersion=$(DX_VERSION) assemble
	java -jar /usr/share/java/jarjar.jar \
	     process \
	     debian/jack-dx.jarjar-rules \
	     debian/build/libs/dx-$(DX_VERSION).jar \
	     debian/build/libs/jack-dx.jar

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

override_dh_shlibdeps:
	dh_shlibdeps -l/usr/lib/$(DEB_HOST_MULTIARCH)/android

get-orig-source: $(UPSTREAM_TAG).tar.gz
	uscan --download-current-version --force-download