ifneq (,$(wildcard ../xgaf/.build/release/xgaf))
XGAF:=../xgaf/.build/release/xgaf
else
ifneq (,$(wildcard ../xgaf/.build/debug/xgaf))
XGAF:=../xgaf/.build/debug/xgaf
else
XGAF:=C:\Program Files (x86)\XGAF\xgaf.exe
endif
endif

UNAME = ${shell uname}
ifneq ($(findstring CYGWIN,$(UNAME)),)  
  UNAME := CYGWIN
endif

ifeq ($(UNAME), CYGWIN)
XGAF:=$(shell cygpath --unix "$(XGAF)")
endif

FIND=/usr/bin/find

WLX_FILES = $(shell $(FIND) world -type f -name '*.wlx')
WLD_FILES = $(addprefix world/compiled/, $(patsubst world/%.wlx, %.wld, $(WLX_FILES)))

MOX_FILES = $(shell $(FIND) world -type f -name '*.mox')
MOB_FILES = $(addprefix world/compiled/, $(patsubst world/%.mox, %.mob, $(MOX_FILES)))

OBX_FILES = $(shell $(FIND) world -type f -name '*.obx')
OBJ_FILES = $(addprefix world/compiled/, $(patsubst world/%.obx, %.obj, $(OBX_FILES)))

all: $(WLD_FILES) $(MOB_FILES) $(OBJ_FILES)

rebuild: clean all

clean:
	rm -rf world/compiled

$(WLD_FILES): world/compiled/%.wld: world/%.wlx
	@mkdir -p "$(dir $@)"
	@echo "xgaf $< $@"
	@"$(XGAF)" "$<" "$@" world/xgaf_dat

$(MOB_FILES): world/compiled/%.mob: world/%.mox
	@mkdir -p "$(dir $@)"
	@echo "xgaf $< $@"
	@"$(XGAF)" "$<" "$@" world/xgaf_dat

$(OBJ_FILES): world/compiled/%.obj: world/%.obx
	@mkdir -p "$(dir $@)"
	@echo "xgaf $< $@"
	@"$(XGAF)" "$<" "$@" world/xgaf_dat

.PHONY: rebuild clean all
