#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk
export JAVA_HOME=/usr/lib/jvm/default-java
# needed by some tests
export ANDROID_HOME=/usr/lib/android-sdk

%:
	dh $@ --with maven_repo_helper --buildsystem=gradle --with bash-completion

override_dh_auto_build:
	$(foreach patch,$(shell cat debian/additionalSrc/patches/series),patch --batch --fuzz=0 --forward -p1 --unified --version-control=never < debian/additionalSrc/patches/$(patch);)
	dh_auto_build -- -x test --settings-file debian/settings.gradle assemble -x :base:testutils:assemble

override_dh_install:
	dh_install
	chmod -x debian/libgradle-android-plugin-java-doc/usr/share/doc/libgradle-android-plugin-java/templates/gradle-projects/NewAndroidAutoProject/template.xml

override_dh_auto_clean:
	dh_auto_clean
	# Quilt does not work on patches on files under debian/
	-$(foreach patch,$(shell tac debian/additionalSrc/patches/series),patch --reverse --batch --fuzz=0 --forward -p1 --unified --version-control=never < debian/additionalSrc/patches/$(patch);)

get-orig-source: gradle_$(DEB_VERSION_UPSTREAM).tar.gz
	mkdir $(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM)
	tar -f $< --gz -x --directory $(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM)
	cd $(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM); tar --create --xz -f ../../$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM).orig.tar.xz --exclude-from ../debian/orig.excludes --mtime=2011-12-21 * .gitignore .eclipse .idea
	$(RM) -r $(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM)

gradle_$(DEB_VERSION_UPSTREAM).tar.gz:
	wget https://android.googlesource.com/platform/tools/base/+archive/gradle_$(DEB_VERSION_UPSTREAM).tar.gz
