#!/usr/bin/make -f

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

%:
	dh $@

override_dh_auto_configure:
	# Setup symlinks: ant
	mkdir -p lib/ant/lib
	ln -sf /usr/share/ant/lib/ant.jar lib/ant/lib

	# JUnit
	mkdir -p lib/junit
	ln -sf /usr/share/java/junit.jar  lib/junit

	# commons-logging
	mkdir -p lib/commons
	ln -sf /usr/share/java/commons-logging.jar lib/commons/commons.jar

	# asm
	ant -f debian/bootstrap.xml rename-asm

	dh_auto_configure

override_dh_auto_build:
	# Build the manpages
	docbook-to-man debian/aj.sgml        > debian/aj.1
	docbook-to-man debian/ajbrowser.sgml > debian/ajbrowser.1
	sh debian/manpage_from.sh docs/devGuideDB/ajc.xml   > debian/ajc.1
	sh debian/manpage_from.sh docs/devGuideDB/ajdoc.xml > debian/ajdoc.1

	# Build AspectJ
	ant -f debian/bootstrap.xml
	dh_auto_build
	ant -f docs/build.xml dist '-Dbuild.time=$(shell date '--date=@$(SOURCE_DATE_EPOCH)' --utc +'%A %b %d, %Y at %H:%M:%S %Z')'

override_dh_auto_install:
	mh_installpom -plibaspectj-java -e$(DEB_VERSION_UPSTREAM) build/aspectjrt.pom
	mh_installjar -plibaspectj-java -e$(DEB_VERSION_UPSTREAM) -l build/aspectjrt.pom aspectjrt/target/aspectjrt-$(DEB_VERSION_UPSTREAM).jar
	mh_installpom -plibaspectj-java -e$(DEB_VERSION_UPSTREAM) build/aspectjtools.pom
	mh_installjar -plibaspectj-java -e$(DEB_VERSION_UPSTREAM) -l build/aspectjtools.pom aspectjtools/target/aspectjtools-$(DEB_VERSION_UPSTREAM).jar
	mh_installpom -plibaspectj-java -e$(DEB_VERSION_UPSTREAM) build/aspectjweaver.pom
	mh_installjar -plibaspectj-java -e$(DEB_VERSION_UPSTREAM) -l build/aspectjweaver.pom aspectjweaver/target/aspectjweaver-$(DEB_VERSION_UPSTREAM).jar

	cp docs/dist/doc/changes.html docs/target/changelog.html
	html2text -o docs/target/changelog.txt docs/target/changelog.html
	dh_installchangelogs docs/target/changelog.html
	dh_installchangelogs docs/target/changelog.txt
