#!/bin/sh
#
# Run this shell script to bootstrap as necessary after a fresh checkout.
#
# Written by Russ Allbery <eagle@eyrie.org>
# Copyright 2022 Russ Allbery <eagle@eyrie.org>
# Copyright 2016 Dropbox, Inc.
# Copyright 2005-2006, 2008-2013
#     The Board of Trustees of the Leland Stanford Junior University
#
# SPDX-License-Identifier: MIT

set -e

# Regenerate all the autotools files.
autoreconf -i --force

# Generate manual pages.
version=`grep '^remctl' NEWS | head -1 | cut -d' ' -f2`
pod2man --release="$version" --center="remctl" docs/remctl.pod > docs/remctl.1
pod2man --release="$version" --center="remctl" --section=8 \
    docs/remctl-shell.pod > docs/remctl-shell.8.in
pod2man --release="$version" --center="remctl" --section=8 docs/remctld.pod \
    > docs/remctld.8.in
for doc in remctl remctl_close remctl_command remctl_error remctl_new \
           remctl_noop remctl_open remctl_output remctl_set_ccache \
           remctl_set_source_ip remctl_set_timeout ; do
    pod2man --release="$version" --center="remctl Library Reference" \
        --section=3 --name=`echo "$doc" | tr a-z A-Z` docs/api/"$doc".pod \
        > docs/api/"$doc".3
done

# Generate protocol documentation if xml2rfc is available.
if command -v xml2rfc 2>&1 >/dev/null ; then
    cd docs
    xml2rfc protocol.xml --text --html
else
    echo 'xml2rfc not found, not building protocol documentation' >&2
fi
