# MingW Makefile for the mswindows subdirectory
# This Makefile is intended to create the PyTables installer for Windows

#Variables for software versions: PyTables, Python and required libraries
VERSIONFILE=..\VERSION
FULLVERSION=$(shell type ..\VERSION)
VERSION = $(subst pro,,${FULLVERSION})

# Split the versions in major, minor and revision
VERSIONS = $(shell python get_pytables_version.py ..\VERSION)
VER_MAJOR = $(word 1, $(VERSIONS))
VER_MINOR = $(word 2, $(VERSIONS))
VER_REVISION = $(word 3, $(VERSIONS))


ifeq ($(PYTHONVERSION), 24)
	DOTPYTHONVERSION=2.4
	PLATFORM=win32
endif
ifeq ($(PYTHONVERSION), 25)
	DOTPYTHONVERSION=2.5
	PLATFORM=win32
endif
ifeq ($(PYTHONVERSION), 26)
	DOTPYTHONVERSION=2.6
	PLATFORM=win32
endif
ifeq ($(PYTHONVERSION), 27)
	DOTPYTHONVERSION=2.7
	PLATFORM=win32
endif
ifeq ($(PYTHONVERSION), 26_64)
	DOTPYTHONVERSION=2.6
	PLATFORM=win-amd64
endif
ifeq ($(PYTHONVERSION), 27_64)
	DOTPYTHONVERSION=2.7
	PLATFORM=win-amd64
endif

ifeq ($(LICENSE), development)
	LICENSEFILE=..\LICENSE-development.txt
	LICENSEFILENAME=LICENSE-development.txt
endif
ifeq ($(LICENSE), site)
	LICENSEFILE=..\LICENSE-site.txt
	LICENSEFILENAME=LICENSE-site.txt
endif
ifeq ($(LICENSE), personal)
	LICENSEFILE=..\LICENSE-personal.txt
	LICENSEFILENAME=LICENSE-personal.txt
endif
ifeq ($(LICENSE),evaluation)
        LICENSEFILE=..\LICENSE-evaluation.txt
        LICENSEFILENAME=LICENSE-evaluation.txt
endif

# The NSIS intstaller script
PTPRONSIS=pytables-py$(DOTPYTHONVERSION).nsi

# Required paths
SVN_PT=..
TABLES_ORIG=C:\\Python$(PYTHONVERSION)\\Lib\\site-packages\\tables_orig
NUMPY=C:\\Python$(PYTHONVERSION)\\Lib\\site-packages\\numpy_orig
NUMEXPR=C:\\Python$(PYTHONVERSION)\\Lib\\site-packages\\numexpr_orig

NUMPYVERSION = $(shell python get_numpy_version.py $(NUMPY)\\version.py)
NUMEXPRVERSION = $(shell python get_numexpr_version.py $(NUMEXPR)\\version.py)

dist:
	$(MAKE) -f Makefile_windows -C ..

clean:
	$(MAKE) -f Makefile_windows -C .. $@
	-del $(PTPRONSIS)
	-del PyTables*.win32-py$(DOTPYTHONVERSION).exe
	-del PyTables*.win-amd64-py$(DOTPYTHONVERSION).exe


# $(info $(NUMPYVERSION))
installer: dist pytables.nsi.in $(VERSIONFILE) $(LICENSEFILE)
	type pytables.nsi.in | sed -e "s/@VERSION@/$(VERSION)/g" \
	-e "s/@PTVERSION@/$(VERSION)/g" \
	-e "s/@NUMPYVERSION@/$(NUMPYVERSION)/g" \
	-e "s/@NUMEXPRVERSION@/$(NUMEXPRVERSION)/g" \
	-e "s/@PYTHONVERSION@/$(PYTHONVERSION)/g" \
	-e "s/@DOTPYTHONVERSION@/$(DOTPYTHONVERSION)/g" \
	-e "s/@PLATFORM@/$(PLATFORM)/g" \
	-e "s/@SVN_PT@/$(SVN_PT)/g" \
	-e "s/@TABLES_ORIG@/$(TABLES_ORIG)/g" \
	-e "s/@NUMPY@/$(NUMPY)/g" \
	-e "s/@NUMEXPR@/$(NUMEXPR)/g" \
	-e "s/@LICENSE@/$(LICENSE)/g" \
	-e "s/@LICENSEFILENAME@/$(LICENSEFILENAME)/g" \
	> $(PTPRONSIS)
	makensis /DVER_MAJOR=$(VER_MAJOR) /DVER_MINOR=$(VER_MINOR) \
	/DVER_REVISION=$(VER_REVISION) $(PTPRONSIS)

