# grm version
VERSION = "$(shell grep '"version"' haxelib.json | cut -d '"' -f 4)"

nothing:
	@echo "Use \"make release\" or \"make debug\" to compile the binaries."
	@echo "See the other commands in Makefile."

debug:
	haxe debug.hxml
	mkdir -p build/debug
	mv build/debug/cpp/grm-to-json/Main-debug build/debug/grm-to-json
	mv build/debug/cpp/grm-definition-to-json/Main-debug build/debug/grm-definition-to-json

release:
	haxe release.hxml
	mkdir -p build/release
	mv build/release/cpp/grm-to-json/Main build/release/grm-to-json
	mv build/release/cpp/grm-definition-to-json/Main build/release/grm-definition-to-json

test:
	@echo "No unit tests available."

doc:
	haxe doc.hxml
	mkdir -p build/doc
	@echo "This directory contains generated XML files for generated the API documentation." > doc-xml/README
	@echo "You can ignore this directory and even remove it if you want." >> doc-xml/README
	rm -rf build/doc/doc-xml
	mv doc-xml build/doc/doc-xml
	haxelib run dox -i build/doc/doc-xml -o doc

dist: clean
	mkdir grm-dist-$(VERSION)
	cp -r grm grm-dist-$(VERSION)
	cp -r tests grm-dist-$(VERSION)
	cp README.md Makefile haxelib.json test.hxml\
		grm-dist-$(VERSION)
	zip -r grm-dist-$(VERSION).zip grm-dist-$(VERSION)
	rm -rf grm-dist-$(VERSION)

clean:
	rm -rf build
	rm -rf doc-xml
	rm -rf doc
	rm -rf grm-lib-$(VERSION).zip
	rm -rf grm-dist-$(VERSION).zip
	rm -rf grm-lib-$(VERSION)
	rm -rf grm-dist-$(VERSION)


# To distribute only the library
lib: clean
	mkdir grm-lib-$(VERSION)
	cp -r src/grm grm-lib-$(VERSION)
	cp README.md Makefile haxelib.json\
		grm-lib-$(VERSION)
	zip -r grm-lib-$(VERSION).zip grm-lib-$(VERSION)
	rm -rf grm-lib-$(VERSION)

# To install the library.
install: lib
	haxelib install grm-lib-$(VERSION).zip

.PHONY: clean debug dist doc release test install
