BYACCJ=@BYACCJ@
JFLEX=@JAVA@ -cp @LIBCLASSPATH@ JFlex.Main
# We aim to use a conservative/old Java release.
#
#  * v1.8 seems to be the oldest version I can easily get my hands on
#  * And MarkT suggests that targeting v1.8 is least likely to inconvenience anyone

# Note: if necessary,
#   BOOTCLASSPATH=-bootclasspath path/to/rt5.jar
# may make some warnings go away.
BOOTCLASSPATH=
JAVAC=@JAVAC@ -source 8 -target 8 $(BOOTCLASSPATH) -deprecation -encoding UTF-8
JAR=@JAR@
JAVADOC=@JAVADOC@

INSTALL=@INSTALL@
#MKDIR_P=mkdir -p
MKDIR_P=@MKDIR_P@

PACKAGE_VERSION=@PACKAGE_VERSION@
LIBRARY_HOMEPAGE=@LIBRARY_HOMEPAGE@

PARSERS=@PARSERLIST@
CP=uk/me/nxg/unity

prefix=@prefix@
exec_prefix=@exec_prefix@
javadir=@datarootdir@/java


all: unity.jar

# We have to explicitly mention SimpleCSVReader, because we want it to
# be included in the jar file (for tests and as a general utility)
# even though it's not referred to by UnitParser.
unity.jar: build/$(CP)/UnitParser.class build/$(CP)/util/SimpleCSVReader.class
	rm -f $@
	echo "Main-Class: uk.me.nxg.unity.UnitParser" >manifest.txt
	cd build; $(JAR) cmf ../manifest.txt ../$@ .
	rm manifest.txt

# dummy-ish target to make sure that the build directory is created early
build/STAMP:
	mkdir -p build/jdk
	mkdir -p gen/$(CP)
	date >build/STAMP

build/$(CP)/UnitParser.class: $(CP)/UnitParser.java \
		$(CP)/OneUnit.java \
		$(patsubst %,gen/$(CP)/Parser_%.java,$(PARSERS)) \
		gen/$(CP)/UnityUnitDefinitionMap.java \
		gen/$(CP)/UnityFunctionDefinitionMap.java \
		gen/$(CP)/UnityFunctionDefinitionMap.java \
		gen/$(CP)/Version.java \
		build/STAMP
	$(JAVAC) -encoding UTF8 -classpath .:gen -Xlint -d build $(CP)/UnitParser.java

build/$(CP)/util/SimpleCSVReader.class: $(CP)/util/SimpleCSVReader.java build/STAMP
	$(JAVAC) -encoding UTF8 -classpath . -Xlint -d build $(CP)/util/SimpleCSVReader.java
build/$(CP)/Dimensions.class: $(CP)/Dimensions.java
	$(JAVAC) -encoding UTF8 -classpath . -Xlint -d build $(CP)/Dimensions.java


install: unity.jar
	test -d $(javadir) || $(MKDIR_P) $(javadir)
	$(INSTALL) unity.jar $(javadir)


check: unity.jar
	cd test; $(MAKE) check

clean:
	rm -Rf build unity.jar
	cd test; $(MAKE) clean
