# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
#
# SPDX-License-Identifier: MPL-2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0.  If a copy of the MPL was not distributed with this
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.

srcdir =	@srcdir@
VPATH =		@srcdir@
top_srcdir =	@top_srcdir@

@BIND9_MAKE_RULES@

PERL = @PERL@

MANOBJS = options

doc man:: ${MANOBJS}

docclean manclean maintainer-clean::
	rm -f options

# Do not make options depend on ../../bin/tests/cfg_test, doing so
# will cause excessively clever versions of make to attempt to build
# that program right here, right now, if it is missing, which will
# cause make doc to bomb.

CFG_TEST = ../../bin/tests/cfg_test

options: FORCE
	if test -x ${CFG_TEST} ; \
	then \
		${CFG_TEST} --named --grammar > $@.raw ; \
		${PERL} ${srcdir}/sort-options.pl < $@.raw > $@.sorted ; \
		${PERL} ${srcdir}/format-options.pl < $@.sorted > $@.new ; \
		mv -f $@.new $@ ; \
		${CFG_TEST} --named --grammar --active > $@.raw ; \
		${PERL} ${srcdir}/sort-options.pl < $@.raw > $@.sorted ; \
		${PERL} ${srcdir}/format-options.pl < $@.sorted > $@.new ; \
		mv -f $@.new $@.active ; \
		rm -f $@.raw $@.sorted ; \
		${CFG_TEST} --zonegrammar master --active > master.zoneopt ; \
		${CFG_TEST} --zonegrammar slave --active > slave.zoneopt ; \
		${CFG_TEST} --zonegrammar mirror --active > mirror.zoneopt ; \
		${CFG_TEST} --zonegrammar forward --active > forward.zoneopt ; \
		${CFG_TEST} --zonegrammar hint --active > hint.zoneopt ; \
		${CFG_TEST} --zonegrammar stub --active > stub.zoneopt ; \
		${CFG_TEST} --zonegrammar static-stub --active > static-stub.zoneopt ; \
		${CFG_TEST} --zonegrammar redirect --active > redirect.zoneopt ; \
		${CFG_TEST} --zonegrammar delegation-only --active > delegation-only.zoneopt ; \
		${CFG_TEST} --zonegrammar in-view --active > in-view.zoneopt ; \
	else \
		rm -f $@.new $@.raw $@.sorted ; \
	fi

rst: options rst-options.pl rst-zoneopt.pl rst-grammars.pl
	${PERL} rst-options.pl options.active > ${top_srcdir}/bin/named/named.conf.rst
	${PERL} rst-zoneopt.pl master.zoneopt > master.zoneopt.rst
	${PERL} rst-zoneopt.pl slave.zoneopt > slave.zoneopt.rst
	${PERL} rst-zoneopt.pl mirror.zoneopt > mirror.zoneopt.rst
	${PERL} rst-zoneopt.pl forward.zoneopt > forward.zoneopt.rst
	${PERL} rst-zoneopt.pl hint.zoneopt > hint.zoneopt.rst
	${PERL} rst-zoneopt.pl stub.zoneopt > stub.zoneopt.rst
	${PERL} rst-zoneopt.pl static-stub.zoneopt > static-stub.zoneopt.rst
	${PERL} rst-zoneopt.pl redirect.zoneopt > redirect.zoneopt.rst
	${PERL} rst-zoneopt.pl delegation-only.zoneopt > delegation-only.zoneopt.rst
	${PERL} rst-zoneopt.pl in-view.zoneopt > in-view.zoneopt.rst
	${PERL} rst-grammars.pl options.active acl > acl.grammar.rst
	${PERL} rst-grammars.pl options.active controls > controls.grammar.rst
	${PERL} rst-grammars.pl options.active key > key.grammar.rst
	${PERL} rst-grammars.pl options.active logging > logging.grammar.rst
	${PERL} rst-grammars.pl options.active parental-agents > parental-agents.grammar.rst
	${PERL} rst-grammars.pl options.active primaries > primaries.grammar.rst
	${PERL} rst-grammars.pl options.active options > options.grammar.rst
	${PERL} rst-grammars.pl options.active server > server.grammar.rst
	${PERL} rst-grammars.pl options.active statistics-channels > statistics-channels.grammar.rst
	${PERL} rst-grammars.pl options.active trust-anchors > trust-anchors.grammar.rst
	${PERL} rst-grammars.pl options.active managed-keys > managed-keys.grammar.rst
	${PERL} rst-grammars.pl options.active trusted-keys > trusted-keys.grammar.rst
