# This makefile automates the build of releases for sourceforge
# The RELEASENAME should be changed per release
# The RELEASEDIR should be set to whatever works for you.
#
# 'make' or 'make release'
# will build both binary and source zipfiles.
# bin-release or src-release will build only what their names imply.
#
# Oh, this works with GNU make under Cygwin. YMMV on other makes...

RELEASENUM := 3.25
RELEASE_SPECIAL := 
RELEASENAME= $(RELEASENUM)$(RELEASE_SPECIAL)

RELEASEDIR := /cygdrive/c/local/src/PasswordSafe/Releases

# Shouldn't need to change anything below this line

BINRELNAME := pwsafe-$(RELEASENAME)-bin
SRCRELNAME := pwsafe-$(RELEASENAME)-src

RM := /usr/bin/rm
CP := /usr/bin/cp
MV := /usr/bin/mv
SED := /usr/bin/sed
ZIP := /usr/bin/zip
SVN := /usr/bin/svn
GPG := /usr/local/bin/gpg
GPG_KEY := ronys@users.sourceforge.net
GPG_SIGN := $(GPG) --detach-sign --default-key $(GPG_KEY)
SHA1SUM := /usr/bin/sha1sum
UPLOAD_CMD := /usr/local/bin/rsync -avP -e ssh
UPLOAD_DST :=  ronys@frs.sourceforge.net:/home/pfs/project/p/pa/passwordsafe/passwordsafe/$(RELEASENUM)
PYTHON := /usr/bin/python
SVN2LOG := ../../python/svn2log.py
MAKENSIS := /cygdrive/c/local/NSIS/makensis.exe
WIXDIR := /cygdrive/c/local/WIX
CANDLE := $(WIXDIR)/candle.exe
LIGHT := $(WIXDIR)/light.exe

SVN_REPO := https://passwordsafe.svn.sourceforge.net/svnroot/passwordsafe
SVN_TRUNK := $(SVN_REPO)/trunk/pwsafe/pwsafe
SVN_TAG := $(SVN_REPO)/tags
RELTAG = V$(subst .,_,$(RELEASENAME))


I18N_DIR := ./src/ui/Windows/I18N
I18N_DLL_DIR := ./build/bin/pwsafe/I18N
POT_FILE := $(I18N_DIR)/pwsafe.pot
HELP_DIR := ./help
BIN_DIR := ./build/bin/pwsafe/releasem
TMPDIR := /cygdrive/c/tmp
RELNOTES := $(CURDIR)/docs/ReleaseNotes.txt

BIN_MANIFEST = README.txt docs/ReleaseNotes.txt docs/ReleaseNotes.html LICENSE \
    xml/pwsafe.xsd xml/pwsafe_filter.xsd xml/pwsafe.xsl \
		docs/ChangeLog.txt $(BIN_DIR)/pwsafe.exe $(BIN_DIR)/pws_at.dll \
		$(BIN_DIR)/pws_osk.dll help/default/pwsafe.chm \
		docs/pad_file.xml
I18N_MANIFEST := help/pwsafeDE/pwsafeDE.chm help/pwsafeZH/pwsafeZH.chm \
								 help/pwsafeES/pwsafeES.chm\
								$(I18N_DLL_DIR)/pwsafeDE.dll $(I18N_DLL_DIR)/pwsafeES.dll \
								$(I18N_DLL_DIR)/pwsafePL.dll $(I18N_DLL_DIR)/pwsafeRU.dll \
	              $(I18N_DLL_DIR)/pwsafeSV.dll $(I18N_DLL_DIR)/pwsafeZH.dll \
								$(I18N_DLL_DIR)/pwsafeFR.dll $(I18N_DLL_DIR)/pwsafeDA.dll \
								$(I18N_DLL_DIR)/pwsafeKR.dll $(I18N_DLL_DIR)/pwsafeNL.dll

.PHONY: all release bin-release src-release installables signatures \
	upload sha1sums msi nsis upload-latest updat-pos i18n save-map help \
	svn-tag

all: help release installables signatures sha1sums

upload: upload-latest
	(cd $(RELEASEDIR); \
	 $(UPLOAD_CMD) pwsafe-$(RELEASENAME).exe \
	 $(BINRELNAME).zip $(SRCRELNAME).zip \
	 pwsafe-$(RELEASENAME).msi \
	 pwsafe-$(RELEASENAME)-map+pdb.zip \
	$(RELNOTES) \
	 pwsafe-$(RELEASENAME).msi.sig \
	 pwsafe-$(RELEASENAME).exe.sig \
	 $(BINRELNAME).zip.sig $(SRCRELNAME).zip.sig $(UPLOAD_DST))

upload-latest: latest.xml
	echo "cd htdocs" > putlatest.tmp
	echo "put $<" >> putlatest.tmp
	sftp -b putlatest.tmp ronys,passwordsafe@web.sourceforge.net
	$(RM) putlatest.tmp

latest.xml: src/ui/Windows/version.h src/ui/wxWidgets/version.h
	Misc/make-latest-xml.pl $^ > $@
	chmod 644 $@

src/ui/wxWidgets/version.h:
	Misc/mkversion.pl src/ui/wxWidgets/version.in $@

sha1sums:
	(cd $(RELEASEDIR); \
	 $(SHA1SUM) pwsafe-$(RELEASENAME).exe \
	 pwsafe-$(RELEASENAME).msi \
	 $(BINRELNAME).zip $(SRCRELNAME).zip)

signatures:
	$(GPG_SIGN) $(RELEASEDIR)/pwsafe-$(RELEASENAME).exe
	$(GPG_SIGN) $(RELEASEDIR)/$(BINRELNAME).zip
	$(GPG_SIGN) $(RELEASEDIR)/$(SRCRELNAME).zip
	$(GPG_SIGN) $(RELEASEDIR)/pwsafe-$(RELEASENAME).msi

installables: nsis msi

nsis:
	$(MAKENSIS) /DVERSION=$(RELEASENAME) install/pwsafe.nsi
	$(MV) install/pwsafe-$(RELEASENAME).exe $(RELEASEDIR)

msi:
	$(SED) 's/PWSAFE_VERSION/$(RELEASENUM)/' \
		< install/pwsafe-template.wxs > install/pwsafe.wxs
	$(CANDLE) install/pwsafe.wxs
	$(LIGHT) -ext WixUIExtension -cultures:en-us pwsafe.wixobj \
					-out pwsafe.msi
	$(RM) pwsafe.wixobj
	$(MV) pwsafe.msi $(RELEASEDIR)/pwsafe-$(RELEASENAME).msi

release:  i18n bin-release src-release

bin-release: save-map
	@-mkdir $(RELEASEDIR)/$(BINRELNAME)

	$(CP) $(BIN_MANIFEST) $(RELEASEDIR)/$(BINRELNAME)
	$(CP) $(I18N_MANIFEST) $(RELEASEDIR)/$(BINRELNAME)
	(cd $(RELEASEDIR); $(ZIP) -9 -r  foo ./$(BINRELNAME); \
	$(MV) foo.zip $(BINRELNAME).zip)
	@$(RM) -rf $(RELEASEDIR)/$(BINRELNAME)

save-map:
	$(ZIP) -9 $(RELEASEDIR)/pwsafe-$(RELEASENAME)-map+pdb.zip \
	 $(BIN_DIR)/pwsafe.map $(BIN_DIR)/pwsafe.pdb \
   $(BIN_DIR)/pws_*.pdb		

src-release: ChangeLog $(POT_FILE)
	$(SVN) export --non-interactive . $(TMPDIR)/$(SRCRELNAME)
	$(MV) $(TMPDIR)/$(SRCRELNAME) $(RELEASEDIR)
	$(MV) ChangeLog $(RELEASEDIR)/$(SRCRELNAME)
	$(CP) src/ui/Windows/version.h $(RELEASEDIR)/$(SRCRELNAME)/src/ui/Windows
	$(CP) $(POT_FILE) $(RELEASEDIR)/$(SRCRELNAME)
	(cd $(RELEASEDIR); $(ZIP) -9 -r  bar ./$(SRCRELNAME); \
	$(MV) bar.zip $(SRCRELNAME).zip)
	@$(RM) -rf $(RELEASEDIR)/$(SRCRELNAME)

ChangeLog:
	$(SVN) log -v --xml | $(PYTHON) $(SVN2LOG) -L -H -s -O

$(POT_FILE): $(BIN_DIR)/../release/pwsafe_base.dll
	$(MAKE) -C $(I18N_DIR) pwsafe.pot

update-pos:
	$(MAKE) -C $(I18N_DIR) $@

i18n:
	$(MAKE) -C $(I18N_DIR) dlls

help:
	$(MAKE) -C $(HELP_DIR)

svn-tag:
	$(SVN) cp $(SVN_TRUNK) $(SVN_TAG)/$(RELTAG) -m "tag $(RELEASENAME) release"

# Local variables:
# mode: Makefile
# End:
