DEPTH = ../../..

include $(DEPTH)/Makefile.version
include $(DEPTH)/Makefile.os

.PHONY: all
all :

ifeq ($(SHELLTYPE), sh)
.PHONY: setup
setup : setup_nsis

.PHONY: setup_nsis
setup_nsis :
	ln -s $(DEPTH)/release/FreeDoko_$(VERSION) FreeDoko_$(VERSION)
	$(MAKE) FreeDoko.de.nsi
	$(MAKE) FreeDoko.en.nsi
	makensis -V4 FreeDoko.de.nsi
	makensis -V4 FreeDoko.en.nsi
	rm FreeDoko_$(VERSION)

FreeDoko.de.nsi : always
	sed "s/FREEDOKO_VERSION/${VERSION}/" template/$@ > $@
	cp template/FreeDoko.de.ini .

FreeDoko.en.nsi : always
	sed "s/FREEDOKO_VERSION/${VERSION}/" template/$@ > $@
	cp template/FreeDoko.en.ini .

.PHONY: setup_setup2go
setup_setup2go : FreeDoko.en.s2g FreeDoko.de.s2g
	make FreeDoko.en.full.s2g FreeDoko.de.full.s2g
	setup2go &



FreeDoko.en.s2g : always
	rm -rf ${DEPTH}/../FreeDoko_${VERSION}.setup
	cp -rL ${DEPTH}/FreeDoko_${VERSION} ${DEPTH}/../FreeDoko_${VERSION}.setup
	mkdir ${DEPTH}/../FreeDoko_${VERSION}.setup/gtkmm.dll
	cp -r ${DEPTH}/data/gtkmm.dll/* ${DEPTH}/../FreeDoko_${VERSION}.setup/gtkmm.dll/
	cat template/$@ \
	| sed "s/ProductVersion=.*/ProductVersion=${VERSION}/" \
	| sed "s/RequiredDiskSpace=.*/RequiredDiskSpace=`du -ks ${DEPTH}/../FreeDoko_${VERSION}.setup | sed "s/\([0-9]*\).*/\1/"`/" \
	| sed "s/OutputFolder=.*/OutputFolder=Y:\\\\Programme\\\\FreeDoko_${VERSION}.release/" \
	| sed "s/SetupFilename=.*/SetupFilename=FreeDoko_${VERSION}.en.Setup.exe/" \
	> $@
	cd ${DEPTH}/../FreeDoko_${VERSION}.setup && \
	find * -type d -exec echo "Folder=%AppDir%/"\{\} \; > ../FreeDoko_${VERSION}.Files && \
	find * -type f -exec echo "File=%AppDir%/"\{\}",Y:/Programme/FreeDoko_${VERSION}.setup/"\{\},17,0,32 \; >> ../FreeDoko_${VERSION}.Files
	cat ${DEPTH}/../FreeDoko_${VERSION}.Files \
	| sed "s_/./_/_g" \
	| sed "s_/_\\\\_g" \
	> Files_${VERSION}
	cat Files_${VERSION} >> $@
	rm Files_${VERSION} ${DEPTH}/../FreeDoko_${VERSION}.Files
	flip -bm $@

FreeDoko.en.full.s2g : FreeDoko.en.s2g
	cd ${DEPTH}/../FreeDoko_${VERSION}.setup && \
	tar xzf ~/Daten/FreeDoko/cardsets.full.tgz
	cat template/FreeDoko.en.s2g \
	| sed "s/ProductDescription=.*/ProductDescription=Ein Doppelkopf-Spiel/" \
	| sed "s/ProductVersion=.*/ProductVersion=${VERSION}/" \
	| sed "s/RequiredDiskSpace=.*/RequiredDiskSpace=`du -ks ${DEPTH}/../FreeDoko_${VERSION}.setup | sed "s/\([0-9]*\).*/\1/"`/" \
	| sed "s/OutputFolder=.*/OutputFolder=Y:\\\\Programme\\\\FreeDoko_${VERSION}.release/" \
	| sed "s/SetupFilename=.*/SetupFilename=FreeDoko_${VERSION}.en.full.Setup.exe/" \
	> $@
	cd ${DEPTH}/../FreeDoko_${VERSION}.setup && \
	find * -type d -exec echo "Folder=%AppDir%/"\{\} \; > ../FreeDoko_${VERSION}.Files && \
	find * -type f -exec echo "File=%AppDir%/"\{\}",Y:/Programme/FreeDoko_${VERSION}.setup/"\{\},17,0,32 \; >> ../FreeDoko_${VERSION}.Files 
	cat ${DEPTH}/../FreeDoko_${VERSION}.Files \
	| sed "s_/./_/_g" \
	| sed "s_/_\\\\_g" \
	> Files_${VERSION}
	cat Files_${VERSION} >> $@
	rm Files_${VERSION} ${DEPTH}/../FreeDoko_${VERSION}.Files
	flip -bm $@



FreeDoko.de.s2g : FreeDoko.en.s2g
	cat $< \
	| sed "s/ProductDescription=A Doppelkopf game/ProductDescription=Ein Doppelkopf Spiel/" \
	| sed "s/DefaultSetupLanguage=English/DefaultSetupLanguage=Deutsch/" \
	| sed "s/Readme_Pathname=\(.*\)doc\\\\en\\\\introduction.txt/Readme_Pathname=\1doc\\\\de\\\\Einfuehrung.txt/" \
	| sed "s/SetupFilename=FreeDoko_${VERSION}\\.en\\./SetupFilename=FreeDoko_${VERSION}.de./" \
	| sed "s/License_Pathname=\(.*\)\\doc\\GPL/License_Pathname=\1\\\\doc\\\\GPL.de/" \
	> $@

FreeDoko.de.full.s2g : FreeDoko.en.full.s2g
	cat $< \
	| sed "s/DefaultSetupLanguage=English/DefaultSetupLanguage=Deutsch/" \
	| sed "s/Readme_Pathname=\(.*\)doc\\\\en\\\\introduction.txt/Readme_Pathname=\1doc\\\\de\\\\Einfuehrung.txt/" \
	| sed "s/SetupFilename=FreeDoko_${VERSION}\\.en\\.full\\./SetupFilename=FreeDoko_${VERSION}.de.gesamt./" \
	| sed "s/License_Pathname=\(.*\)\\doc\\GPL/License_Pathname=\1\\\\doc\\\\GPL.de/" \
	> $@

endif

clean :
	rm FreeDoko*.s2g

always :
