#!/usr/bin/make -f

include /usr/share/javahelper/java-vars.mk

MDWN_DOCS = $(patsubst %.md,%.html,$(wildcard $(CURDIR)/*.md))

export LEIN_HOME=$(CURDIR)/.lein
export LEIN_OFFLINE=true
NAME=comidi

%:
	dh $@ --with javahelper --with jh_maven_repo_helper

override_dh_auto_configure:
	cd debian && ln -sf /usr/share/maven-repo .

override_dh_clean:
	rm -f debian/maven-repo
	rm -Rf target
	rm -f debian/pom.xml
	dh_clean

override_dh_auto_build:
	lein pom debian/pom.xml
	lein jar
	# symlink so we don't need a version in debian/*.poms
	cd target && ln -sf $(NAME)-$(DEB_VERSION_UPSTREAM).jar $(NAME).jar

%.html:%.md
	cat debian/header.html > $@
	sed -i'' -e 's#@TITLE@#$(shell head -n 1 $< | sed 's/^#*\s*//')#g' $@
	markdown $< >> $@
	cat debian/footer.html >> $@

override_dh_auto_test:
	if ! lein test ; then \
		cat /tmp/clojure-*.edn ; \
		exit 1 ; \
	fi
