# -*- sh -*-
# Build script for making Tweak release archives.

module tweak

# Determine the version number.
set Version $(!builddate).$(vcsid)
ifneq $(RELEASE) "" set Version $(RELEASE)

# Put versionids into the docs. (Use perl to avoid inconsistent
# behaviour of echo '\v'.)
in tweak do perl -e 'print "\n\\versionid tweak version $$ARGV[0]\n"' $(Version) >> manpage.but
in tweak do perl -e 'print "\n\\versionid tweak version $$ARGV[0]\n"' $(Version) >> btree.but

# Fiddle with tweak.h to include the version number. Note use of $#
# to escape a hash sign from the build script lexer.
in tweak do perl -i~ -pe 's/(?<=$#define VER ")(?=")/$(Version)/' tweak.h

# Build the man page. This also tests that the main program builds.
in . do mkdir build-doc
in build-doc do cmake ../tweak
in build-doc do make -j$(nproc)
in build-doc do cp tweak.1 ../tweak

# Build a source archive with the right name.
in . do ln -s tweak tweak-$(Version)
in . do tar chzvf tweak-$(Version).tar.gz tweak-$(Version)

# And deliver it.
deliver tweak-$(Version).tar.gz $@

# Make and deliver the HTML man page and the B-tree article.
in tweak do halibut --html=manpage-$(Version).html manpage.but
in tweak do halibut --html=btree.html btree.but
deliver tweak/manpage-$(Version).html $@
deliver tweak/btree.html $@
