PACKAGE = fr.monlouyan.bakefile
ENTRY = Main
SOURCEDIR = ./src/fr/monlouyan/bakefile/
BUILDDIR = ./build/
DOCDIR = ./doc/
JARNAME = bakefile.jar
CLASSP = ./build
MANIFESTPATH = Manifest.MF
SOURCEDIR = ./src/
TESTDIR = ./tests/

SOURCES := $(shell find $(SOURCEDIR) -name '*.java')

all:
	@make clean
	@make compile
	@make jar

compile:
	@echo "Compiling..."
	javac -cp $(CLASSP) -d $(BUILDDIR) $(SOURCES) -Xlint:unchecked -Xlint:deprecation
	@echo "Done."

clean:
	@echo "Cleaning up..."
	@rm -rf $(BUILDDIR)* $(DOCDIR)*
	@rm -f $(JARNAME)
	@find $(TESTDIR) -name "$(JARNAME)" -delete
	@echo "Done."

javadoc:
	@echo "Generating javadoc..."
	@javadoc -d $(DOCDIR) -sourcepath src -subpackages $(PACKAGE)
	@echo "Done."

jar:
	@echo "Creating jar..."
	@jar cfm $(JARNAME) $(MANIFESTPATH) -C $(BUILDDIR) fr/monlouyan/bakefile
	@echo "Done."
	@make deploy-tests

deploy-tests:
	@echo "Deploying JAR to 'bake' directories..."
	@find $(TESTDIR) -type d -name 'bake' -exec cp $(JARNAME) {} \;
	@echo "Done."

run_test:
	@echo "Running tests..."
	@java -cp build fr.monlouyan.bakefile.tests.BakeTestRunner
	@echo "Done."