prefix=@prefix@

PACKAGE_NAME=@PACKAGE_NAME@
PACKAGE_VERSION=@PACKAGE_VERSION@
IN_SOURCE_TREE=@IN_SOURCE_TREE@


# Language implementations
LANGS=src/c src/java


# In this target, explicitly build buildtools first.  This will
# usually happen automatically, through expressed dependencies, but it
# can sometimes fail to happen in time, when we run with `make -j`.
# That is, this allows `make -j` to work reliably.
all:
	if $(IN_SOURCE_TREE); then (cd src/buildtools; $(MAKE)) && (cd src/grammar; $(MAKE)); else :; fi
	for d in $(LANGS); do (cd $$d; $(MAKE)) || exit 1; done
install:
	for d in $(LANGS); do (cd $$d; $(MAKE) install) || exit 1; done

# Install the unity jar into a local Maven repository as a snapshot
install-mvn:
	cd src/java; $(MAKE) unity.jar
	mvn install:install-file -Dfile=src/java/unity.jar \
		-DgroupId=uk.me.nxg -DartifactId=unity \
		-Dversion=$(PACKAGE_VERSION) -Dpackaging=jar

Makefile: config.status \
		Makefile.in \
		src/c/Makefile.in \
		src/c/test/Makefile.in \
		src/java/Makefile.in \
		src/java/test/Makefile.in
	./config.status
pom.xml: config.status pom.xml.in
	./config.status pom.xml
config.status: configure
	./config.status --recheck

check: all
	for d in $(LANGS); do (cd $$d; $(MAKE) check) || exit 1; done

# The `test -d` is because buildtools isn't present in the distribution tarball
clean:
	for d in $(LANGS); do test -d $$d && (cd $$d; $(MAKE) clean); done
	rm -f pom.xml
