
ifdef JAVA_BIN
JAVAC=$(JAVA_BIN)/javac
JAVA=$(JAVA_BIN)/java
else
JAVAC=javac
JAVA=java
endif

#### Different options for Windows or Linux:
host:=$(shell uname | cut -d _ -f 1)
ifeq ($(host),MINGW32)  # host is MINGW32 on Windows:
CLASSPATH_SEP=;
RUNTIME_PATH_VAR=PATH
RUNTIME_LIB_DIR=../bin
LIB_EXT=dll
LIB_PREFIX=
else
CLASSPATH_SEP=:
RUNTIME_PATH_VAR=LD_LIBRARY_PATH
RUNTIME_LIB_DIR=../lib
LIB_EXT=so
LIB_PREFIX=lib
endif


BASECLASSPATH=../java/BaseArnl.jar$(CLASSPATH_SEP)../java/Aria.jar$(CLASSPATH_SEP)../java/ArNetworking.jar
BASEJARS=$(subst $(CLASSPATH_SEP), ,$(BASECLASSPATH))


all: $(patsubst %.java,%.class,$(wildcard *.java))

Arnl%.class: Arnl%.java $(BASEJARS) ../java/Arnl.jar 
	"$(JAVAC)" -classpath "$(BASECLASSPATH)$(CLASSPATH_SEP)../java/Arnl.jar" $<

SonArnl%.class: SonArnl%.java $(BASEJARS) ../java/SonArnl.jar 
	"$(JAVAC)" -classpath "$(BASECLASSPATH)$(CLASSPATH_SEP)../java/SonArnl.jar" $<

Mogs%.class: Mogs%.java $(BASEJARS) ../java/Mogs.jar 
	"$(JAVAC)" -classpath "$(BASECLASSPATH)$(CLASSPATH_SEP)../java/Mogs.jar" $<

runArnl%: Arnl%.class 
	$(RUNTIME_PATH_VAR)=$$$(RUNTIME_PATH_VAR):$(RUNTIME_LIB_DIR)  "$(JAVA)" -cp "$(BASECLASSPATH)$(CLASSPATH_SEP)../java/Arnl.jar$(CLASSPATH_SEP)." Arnl$* $(ARGS)

runSonArnl%: SonArnl%.class 
	$(RUNTIME_PATH_VAR)=$$$(RUNTIME_PATH_VAR):$(RUNTIME_LIB_DIR)  "$(JAVA)" -cp "$(BASECLASSPATH)$(CLASSPATH_SEP)../java/SonArnl.jar$(CLASSPATH_SEP)." SonArnl$* $(ARGS)

runMogs%: Mogs%.class 
	$(RUNTIME_PATH_VAR)=$$$(RUNTIME_PATH_VAR):../bin:$(RUNTIME_LIB_DIR) "$(JAVA)" -cp "$(BASECLASSPATH)$(CLASSPATH_SEP)../java/Mogs.jar$(CLASSPATH_SEP)." Mogs$* $(ARGS)

#defaults, link to all:
%.class: %.java ../java/BaseArnl.jar ../java/Mogs.jar ../java/Arnl.jar ../java/Aria.jar ../java/SonArnl.jar ../java/ArNetworking.jar $(RUNTIME_LIB_DIR)/$(LIB_PREFIX)Arnl.$(LIB_EXT) $(RUNTIME_LIB_DIR)/$(LIB_PREFIX)SonArnl.$(LIB_EXT) $(RUNTIME_LIB_DIR)/$(LIB_PREFIX)BaseArnl.$(LIB_EXT) $(RUNTIME_LIB_DIR)/$(LIB_PREFIX)Mogs.$(LIB_EXT)
	"$(JAVAC)" -classpath "$(BASECLASSPATH)$(CLASSPATH_SEP)../java/Arnl.jar$(CLASSPATH_SEP)../java/SonArnl.jar$(CLASSPATH_SEP)../java/Mogs.jar" $<

run%: %.class
	$(RUNTIME_PATH_VAR)=$$$(RUNTIME_PATH_VAR):$(RUNTIME_LIB_DIR) "$(JAVA)" -cp "$(BASECLASSPATH):../java/Arnl.jar:../java/SonArnl.jar:../java/Mogs.jar:." $* $(ARGS)

gdb%: %.class
	$(RUNTIME_PATH_VAR)=$$$(RUNTIME_PATH_VAR):$(RUNTIME_LIB_DIR) gdb --args $(JAVA) -cp "$(BASECLASSPATH):../java/Arnl.jar:../java/SonArnl.jar:../java/Mogs.jar:." $* $(ARGS)

info:
	@echo host=$(host)
	@echo "JAVA_BIN=$(JAVA_BIN)"
	@echo "JAVAC=$(JAVAC)"
	@echo "JAVA=$(JAVA)"
	@echo "BASECLASSPATH=$(BASECLASSPATH)"
	@echo "BASEJARS=$(BASEJARS)"
	@echo "RUNTIME_PATH_VAR=$(RUNTIME_PATH_VAR)"
	@echo "RUNTIME_LIB_DIR=$(RUNTIME_LIB_DIR)"
	@echo "LIB_EXT=$(LIB_EXT)"
	
