PACKAGE=org.artisanlogiciel.games
PACKAGE_DIR=$(subst .,/,$(PACKAGE))
# maps with ant build.xml
OUT=../build
# external libraries
LIBS=../libs/artgaphics-0.1.0.jar
EDITOR=emacs

$(OUT):
	echo "[ERROR] Missing $(OUT)"
#	mkdir -p $(OUT)

clean:
	@find $(PACKAGE_DIR) -name "*.class" -type f -print0|xargs -0 --no-run-if-empty rm 2>/dev/null
	@find $(OUT) -name "*.class" -type f -print0|xargs -0 --no-run-if-empty rm 2>/dev/null

test:
	echo "$(pwd)/$(PACKAGE_DIR)"
	javac -sourcepath . -cp $(LIBS) -d $(OUT) $(PACKAGE_DIR)/LabyModel.java
	javac -sourcepath . -cp $(LIBS) -d $(OUT) $(PACKAGE_DIR)/Main.java
	java -cp $(OUT):$(LIBS):../lang $(PACKAGE).Main


run/%:	$(OUT)
	javac -cp $(LIBS):$(OUT) -d $(OUT) $(PACKAGE_DIR)/$(subst run/,,$@).java
	java -cp $(OUT):$(LIBS) $(PACKAGE)/$(subst run/,,$@) 

display:	run/Display


display/%: $(OUT)
	javac -cp $(LIBS) -d $(OUT) $(PACKAGE_DIR)/Display.java
	java -cp $(OUT):$(LIBS) $(PACKAGE).Display $(subst display/,,$@)

compile/%:
	javac -d $(OUT) $(PACKAGE_DIR)/$(subst compile/,,$@).java

$(PACKAGE_DIR)/%.java:
	./generate_new.sh class $(subst .java,,$(subst $(PACKAGE_DIR)/,,$@))

interface/%:
	./generate_new.sh interface package_dir=$(PACKAGE_DIR) $(subst interface/,,$@)
	$(EDITOR) $(PACKAGE_DIR)/$(subst interface/,,$@).java

work/%:	$(PACKAGE_DIR)/$(subst work/,,%).java
	$(EDITOR) $<

work:	work/LabyModel

save:	
	git citool

.PHONY: clean test work display work/% run/% save compile/% interface/%

# tried to avoid intermediate file removal : does not work
# .SECONDARY: $(PACKAGE_DIR)/%.java 

# this does work : once precious intermediate file is not removed.
.PRECIOUS: $(PACKAGE_DIR)/%.java 
