#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/ant.mk

PACKAGE              := $(DEB_SOURCE_PACKAGE)
VERSION              := $(DEB_UPSTREAM_VERSION)
JAVA_HOME            := /usr/lib/jvm/default-java
DEB_JARS             := ant-trax
DEB_ANT_BUILD_TARGET := maven-compile
DEB_ANT_CLEAN_TARGET := clean-bootstrap
DEB_ANT_BUILDFILE    := build.xml
DEB_ANT_ARGS         := -Dpackage=$(PACKAGE) -Dversion=$(VERSION) -Dmaven.repo.local=$(realpath $(DEB_BUILDDIR))/debian/tmp/maven-repo
API_DOCS             := build/doc/api
BASE_MODULES         := apache-maven maven-artifact-manager maven-artifact \
			maven-core maven-error-diagnostics maven-model maven-monitor \
			maven-plugin-api maven-plugin-descriptor maven-plugin-parameter-documenter \
			maven-plugin-registry maven-profile maven-project maven-repository-metadata \
			maven-settings maven-toolchain

get-orig-source:
	-uscan --download-version $(DEB_UPSTREAM_VERSION) --force-download --rename

configure/$(PACKAGE)::
	mh_patchpoms -p$(PACKAGE)

makebuilddir/$(PACKAGE)::
	install -d $(DEB_BUILDDIR)/debian/tmp/bootstrap/META-INF/plexus
	install debian/components.xml $(DEB_BUILDDIR)/debian/tmp/bootstrap/META-INF/plexus/
	install -d $(DEB_BUILDDIR)/debian/tmp/maven-repo
	cp -rL /usr/share/maven-repo/* $(DEB_BUILDDIR)/debian/tmp/maven-repo/

binary-post-install/$(PACKAGE)::
	dh_install -p$(PACKAGE) apache-maven/target/maven-debian-uber.jar usr/share/maven2/lib/
	# compress manpages
	find $(DEB_BUILDDIR)/debian/$(PACKAGE)/usr/share/maven2/man -type f | xargs gzip -9v -n
	chmod 0755 $(DEB_BUILDDIR)/debian/$(PACKAGE)/usr/share/maven2/bin/mvnDebug

clean::
	# The poms are already unpatched at the end of the build but the pom.xml.save files are still there, why?
	rm -Rf  apache-maven/pom.xml.save pom.xml.save
	-rm -rf debian/tmp/mvn-repo
	-find . -name target -type d | xargs rm -rf

# No documentation released yet.
#binary-post-install/$(PACKAGE)-doc::

