#!/usr/bin/make -f

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

VERSION := $(shell echo $(DEB_VERSION_UPSTREAM) | sed 's/+ds.*//')
JAR := h2-mvstore.jar

%:
	dh $@

# What h2's Build.jarMVStore does: compile the MVStore sources (here all
# of h2/src/main, which the orig limits to them), the Java 9 version of
# Bits into the multi-release part, and use the MVStore manifest without
# upstream's build JDK lines (jar adds its own Created-By).
override_dh_auto_build:
	mkdir -p build/classes/META-INF/versions/9
	javac --release 8 -encoding UTF-8 -nowarn -d build/classes \
		$$(find h2/src/main -name '*.java' | LC_ALL=C sort)
	javac --release 9 -encoding UTF-8 -nowarn \
		-d build/classes/META-INF/versions/9 -cp build/classes \
		h2/src/java9/src/org/h2/util/Bits.java
	grep -v -e '^Build-Jdk:' -e '^Created-By:' h2/src/installer/mvstore/MANIFEST.MF \
		| sed 's/$${version}/$(VERSION)/g' > build/MANIFEST.MF
	jar --create --file $(JAR) --manifest build/MANIFEST.MF -C build/classes .

override_dh_auto_clean:
	rm -rf build $(JAR)
