# -*- sh -*-
#
# bob script to build the agedu tarball.

module agedu

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

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

# Build the man page. While we're in there, we also ensure agedu
# builds, and runs its help.
in . do mkdir docbuild
in docbuild do cmake ../agedu
in docbuild do make -j$(nproc) VERBOSE=1
in docbuild do ./agedu --help

in . do cp -R agedu agedu-$(Version)
in . do cp -R docbuild/agedu.1 agedu-$(Version)
in . do tar chzvf agedu-$(Version).tar.gz agedu-$(Version)

in agedu do halibut --html=manpage.html agedu.but
in agedu do halibut --html=tree.html tree.but

deliver agedu-$(Version).tar.gz $@
deliver agedu/manpage.html $@
deliver agedu/tree.html $@

in . do mkdir winbuild
in winbuild do cmake ../agedu -DCMAKE_TOOLCHAIN_FILE=$(cmake_toolchain_clangcl64) -DCMAKE_BUILD_TYPE=Release -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_C_FLAGS_RELEASE="/MT /O2"
in winbuild do make -j$(nproc) VERBOSE=1
# Code-sign this Windows binary, if the local bob config provides a
# script to do so. We assume here that the script accepts an -i
# option to provide a 'more info' URL, and that it signs the file in
# place.
ifneq "$(cross_winsigncode)" "" in winbuild do $(cross_winsigncode) -i https://www.chiark.greenend.org.uk/~sgtatham/agedu/ ageduscan.exe

deliver winbuild/ageduscan.exe $@
