#!/usr/bin/make -f
include /usr/share/dpkg/pkg-info.mk

# Upstream version without the +ds repack suffix.
VERSION = $(firstword $(subst +, ,$(DEB_VERSION_UPSTREAM)))
# Scala 2.12 compiler from the scala package (series links, so a later
# Scala series owning the unversioned names does not change this build).
# Debian's scala-compiler does not shade ASM, so scala-asm goes on the
# compiler's classpath.
SCALA = /usr/share/java
ASM = /usr/share/maven-repo/org/scala-lang/modules/scala-asm/debian/scala-asm-debian.jar
SCALAC = java -cp $(SCALA)/scala-compiler-2.12.jar:$(SCALA)/scala-library-2.12.jar:$(SCALA)/scala-reflect-2.12.jar:$(ASM) \
  scala.tools.nsc.Main -nowarn -target:jvm-1.8 -bootclasspath $(SCALA)/scala-library-2.12.jar

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

override_dh_auto_build:
	# Pure Scala. Compile the JVM source set (shared + jvm; exclude js)
	# directly with scalac (no sbt). The quilt patch makes the (now
	# non-implicit) CharSequence conversions explicit so it builds against
	# modern Scala 2.12.
	mkdir -p target/classes
	$(SCALAC) -d target/classes \
	  $$(find shared/src/main/scala jvm/src/main/scala -name '*.scala')
	jar cf scala-parser-combinators_2.12-$(VERSION).jar -C target/classes .

override_dh_auto_test:

override_dh_auto_clean:
	rm -rf target scala-parser-combinators_2.12-$(VERSION).jar
