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

module agedu

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

in agedu do sed '/AC_INIT/s/6.66/$(Version)/' configure.ac > tmp.ac
in agedu do mv tmp.ac configure.ac
in agedu do ./mkauto.sh

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

# Build the man page. This also tests the automake setup to ensure
# configure actually works; but we use a self-delegation (i.e. do all
# of this in a throwaway copy of the build directory) to avoid
# accidentally shipping any outputs of configure. Instead we return
# only the actual man page from the delegation environment.
#
# While we're in there, we also ensure agedu builds, and runs its help.
delegate -
  in agedu do ./configure
  in agedu do make doc
  in agedu do make -j$(nproc)
  in agedu do ./agedu --help
  return agedu/*.1
enddelegate

in . do cp -R agedu 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 $@

ifneq "$(VISUAL_STUDIO)" "yes" then
  in agedu with clangcl64 do clang-cl /c winscan.c && lld-link /out:winscan.exe winscan.obj
  # 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 agedu do $(cross_winsigncode) -i https://www.chiark.greenend.org.uk/~sgtatham/agedu/ winscan.exe
else
  delegate windows
    in agedu with visualstudio do/win cl winscan.c
    ifneq "$(winsigncode)" "" in agedu do $(winsigncode) -i https://www.chiark.greenend.org.uk/~sgtatham/agedu/ winscan.exe
    return agedu/winscan.exe
  enddelegate
endif

deliver agedu/winscan.exe ageduscan.exe
