# 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 -f Makefile.release' or 'make -f Makefile.release 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...

RELEASENAME = 3.12

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/local/bin/svn
GPG = /usr/local/bin/gpg
GPG_KEY = ronys@users.sourceforge.net
GPG_SIGN = $(GPG) --detach-sign --default-key $(GPG_KEY)
MD5SUM = /usr/bin/md5sum
SHA1SUM = /usr/bin/sha1sum
FTP_PUT = /usr/local/bin/ncftpput -v upload.sourceforge.net incoming
PYTHON = /usr/bin/python
SVN2LOG = ../../python/svn2log.py
MAKENSIS = /cygdrive/c/local/NSIS/makensis.exe
WIXDIR = /cygdrive/c/local/WIX/bin
CANDLE = $(WIXDIR)/candle.exe
LIGHT = $(WIXDIR)/light.exe

BIN_MANIFEST = README.txt docs/ReleaseNotes.txt LICENSE \
    xml/pwsafe.xsd xml/pwsafe.xsl \
	docs/ChangeLog.txt Release/pwsafe.exe help/default/pwsafe.chm

.PHONY: all release bin-release src-release installables signatures \
	upload md5sums sha1sums msi nsis upload-latest updat-pos i18n

all: release installables signatures sha1sums

upload: upload-latest
	(cd $(RELEASEDIR); \
	 $(FTP_PUT) pwsafe-$(RELEASENAME).exe \
	 $(BINRELNAME).zip $(SRCRELNAME).zip \
	 pwsafe-$(RELEASENAME).msi \
	 pwsafe-$(RELEASENAME).msi.sig \
	 pwsafe-$(RELEASENAME).exe.sig \
	 $(BINRELNAME).zip.sig $(SRCRELNAME).zip.sig)

upload-latest: latest.xml
	scp $< ronys@passwordsafe.sourceforge.net:~/mygroupdir/htdocs/

latest.xml: version.h
	Misc/make-latest-xml.pl > $@
	chmod 644 $@

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

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/$(RELEASENAME)/' \
		< 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: bin-release src-release i18n

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

src-release: ChangeLog I18N/pwsafe.pot
	$(SVN) export --non-interactive . $(RELEASEDIR)/$(SRCRELNAME)
	$(MV) ChangeLog $(RELEASEDIR)/$(SRCRELNAME)
	$(CP) version.h $(RELEASEDIR)/$(SRCRELNAME)
	$(CP) I18N/pwsafe.pot $(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

I18N/pwsafe.pot: bin/language/pwsafe_base.dll
	$(MAKE) -C I18N pwsafe.pot

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

i18n:
	$(MAKE) -C I18N dlls


# Local variables:
# mode: Makefile
# End:
