# -*- sh -*-
# Build script to build Halibut releases.

module halibut

ifnexist halibut/charset checkout charset halibut/charset

set Version $(!builddate).$(vcsid)
ifneq "$(RELEASE)" "" set Version $(RELEASE)

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

# Write out a version.h that contains the real version number.
in halibut do echo '/* Generated by automated build script */' > version.h
in halibut do echo '$#define VERSION "version $(Version)"' >> version.h

set Rel
ifneq "$(RELEASE)" "" set Rel RELEASE=$(RELEASE)

set Basename halibut-$(Version)

# Make the source archive.
in halibut do ./release.sh $(Basename) $(Version)

# Build a Windows binary of Halibut using clang-cl.
in halibut with clangcl64 do make CC='clang --target=x86_64-pc-windows-msvc18.0.0 -D_CRT_SECURE_NO_WARNINGS' CC_LINK='lld-link -defaultlib:libcmt -out:$$@' EXE=.exe
in halibut do mv build/halibut.exe .
in halibut do rm -rf build
delegate windows
    # Code-sign the 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 "$(winsigncode)" "" in halibut do $(winsigncode) -i http://www.chiark.greenend.org.uk/~sgtatham/halibut/ halibut.exe
    return halibut/halibut.exe
enddelegate

# Build a local binary of Halibut in order to build the docs. Make
# sure to tag it with the supplied version number, so that the
# release docs announce themselves as having been built with the
# release Halibut (e.g. PDF's Producer property).
in halibut do make $(Rel)

# And now build the docs.
in halibut/doc do make

deliver halibut/*.tar.gz $@
deliver halibut/halibut.exe $@
deliver halibut/doc/halibut.pdf $@
deliver halibut/doc/halibut.txt $@
deliver halibut/doc/halibut.chm $@
deliver halibut/doc/*.html $@
