# -*- sh -*-
# Build script for IPBT.

module ipbt

set Version $(!builddate).$(vcsid)

# use perl to avoid inconsistent behaviour of echo '\v'
in ipbt/doc do perl -e 'print "\n\\versionid ipbt version $$ARGV[0]\n"' $(Version) >> man-ipbt.but
in ipbt do perl -e 'print "$#define PACKAGE_VERSION \"$$ARGV[0]\"\n"' $(Version) > version.h

# In cmake/gitcommit.cmake, replace the default output "unavailable"
# with the commit string generated by bob, so that people rebuilding
# the source archive will still get a useful value.
in ipbt do sed -i '/set(DEFAULT_COMMIT/s/unavailable/$(vcsfullid)/' cmake/gitcommit.cmake

# Build the man page.
in . do mkdir build-doc
in build-doc do cmake ../ipbt/doc
in build-doc do make -j$(nproc)
in build-doc do cp ipbt.1 ../ipbt

# Test-build the program itself, in STRICT mode. We should ensure this
# works before being willing to ship any tarball based on it.
in . do mkdir build-test
in build-test do cmake ../ipbt -DSTRICT=ON
in build-test do make -j$(nproc)

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

in ipbt/doc do halibut --html=ipbt.html man-ipbt.but

deliver ipbt-$(Version).tar.gz $@
deliver ipbt/doc/ipbt.html $@
