COMPILE_PLATFORM=$(shell uname|sed -e s/_.*//|tr '[:upper:]' '[:lower:]'|sed -e 's/\//_/g')

ifndef VERSION
VERSION=0.6.1
endif
ifndef RELEASE
RELEASE=0
endif
ifndef ARCH
ARCH=x86
endif
ifndef ASSETPATH
ASSETPATH=.
endif
ifndef INSTALLDIR
INSTALLDIR=.
endif
ifndef USE_RENDERER_DLOPEN
USE_RENDERER_DLOPEN=0
endif
ifndef USE_OPENAL_DLOPEN
USE_OPENAL_DLOPEN=1
endif
ifndef USE_CURL_DLOPEN
USE_CURL_DLOPEN=0
endif
ifndef USE_INTERNAL_SPEEX
USE_INTERNAL_SPEEX=1
endif
ifndef USE_INTERNAL_ZLIB
USE_INTERNAL_ZLIB=1
endif
ifndef USE_INTERNAL_JPEG
USE_INTERNAL_JPEG=1
endif

SDLDLL=SDL.dll

DEFINES=
ifeq ($(USE_RENDERER_DLOPEN),1)
	DEFINES+= -DUSE_RENDERER_DLOPEN
endif
ifeq ($(USE_OPENAL_DLOPEN),1)
	DEFINES+= -DUSE_OPENAL_DLOPEN
endif
ifeq ($(USE_CURL_DLOPEN),1)
	DEFINES+= -DUSE_CURL_DLOPEN
endif
ifeq ($(USE_INTERNAL_SPEEX),1)
	DEFINES+= -DUSE_INTERNAL_SPEEX
endif
ifeq ($(USE_INTERNAL_ZLIB),1)
	DEFINES+= -DUSE_INTERNAL_ZLIB
endif
ifeq ($(USE_INTERNAL_JPEG),1)
	DEFINES+= -DUSE_INTERNAL_JPEG
endif


all: turtlearena-$(VERSION)-$(RELEASE).$(ARCH).exe

turtlearena.$(ARCH).nsi: turtlearena.nsi.in
	sed 's|XXXVERSIONXXX|$(VERSION)|;s|XXXRELEASEXXX|$(RELEASE)|;s|x86|$(ARCH)|g;s|XXXASSETPATHXXX|$(ASSETPATH)|;s|SDL.dll|$(SDLDLL)|' < $< > $@

turtlearena-$(VERSION)-$(RELEASE).$(ARCH).exe: turtlearena.$(ARCH).nsi
	cp "../../../GPL-2.txt" .
	cp "../../../CC-BY-SA-3.0.txt" .
	cp "../../../COPYRIGHTS.txt" .
	cp "../../../CREDITS.txt" .
	cp "../../../INSTALLER_README.txt" "README.txt"
ifneq ($(COMPILE_PLATFORM),mingw32)
	todos GPL-2.txt
	todos CC-BY-SA-3.0.txt
	todos COPYRIGHTS.txt
	todos CREDITS.txt
	todos README.txt
endif
	makensis $(DEFINES) turtlearena.$(ARCH).nsi

clean:
	rm -rf *.exe turtlearena.$(ARCH).nsi GPL-2.txt CC-BY-SA-3.0.txt COPYRIGHTS.txt CREDITS.txt README.txt

install:
	mkdir -p $(INSTALLDIR)
	mv turtlearena-$(VERSION)-$(RELEASE).$(ARCH).exe $(INSTALLDIR)

.PHONY: all clean

