+# For our use of pandoc for full documents, we create a template suitable
+# for us.
+inc/pandoc-template.html5: inc/pandoc-header.html5 inc/pandoc-body-prologue.html5 inc/pandoc-body-epilogue.html5 bin/mk-pandoc-template Makefile
+ pandoc --print-default-template=html5 \
+ | ./bin/mk-pandoc-template html5 > $@
+# Make bin/md-to-html5 depend on inc/pandoc-template.html5
+bin/md-to-html5: inc/pandoc-template.html5
+
+######################################################################
+##
+## Man-page building section
+##
+## This is quite a complex set of rules, because there are many
+## things that need to be built:
+##
+## - The man-pages themselves
+## - Apropos-like listings
+## - Cross-references between man-pages in different OpenSSL
+## versions
+##
+## A lot of the work is made with generated rules.
+
+# makemanpagetts1 and makemanpagetts3 creates rules for targets like man-pagetts-1.1.1,
+# to build the set of man-page templates. makemanpagetts1 is used for pre-3.0 OpenSSL,
+# while makemanpagetts3 is used for OpenSSL 3.0 and on.
+# makemanapropos creates rules for targets like man-apropos-1.1.1, to build
+# 'apropos' like indexes for all the manpages.
+# makemanindexes creates rules for targets like man-index-1.1.1, to build the
+# main HTML index for a set of man-pages.
+#
+# $(1) = input directory in CHECKOUTS, $(2) = release version
+
+# This variant is for pre-3.0 documentation
+define makemanpagetts1
+man-pagetts-$(2):
+ @rm -rf docs/man$(2)
+ @mkdir -p docs/man$(2) \
+ docs/man$(2)/man1 \
+ docs/man$(2)/man3 \
+ docs/man$(2)/man5 \
+ docs/man$(2)/man7
+ ./bin/mk-manpagetts $(CHECKOUTS)/$(1)/doc $(2) docs/man$(2)
+endef
+# This variant is for 3.0 documentation
+define makemanpagetts3
+man-pagetts-$(2):
+ @rm -rf docs/man$(2)
+ @mkdir -p docs/man$(2) \
+ docs/man$(2)/man1 \
+ docs/man$(2)/man3 \
+ docs/man$(2)/man5 \
+ docs/man$(2)/man7
+ ./bin/mk-manpagetts3 $(CHECKOUTS)/$(1) $(2) docs/man$(2)
+endef
+define makemanapropos
+docs/man$(2)/man1/index.inc: bin/mk-apropos Makefile
+ ./bin/mk-apropos docs/man$(2)/man1 > $$@
+docs/man$(2)/man3/index.inc: bin/mk-apropos Makefile
+ ./bin/mk-apropos docs/man$(2)/man3 > $$@
+docs/man$(2)/man5/index.inc: bin/mk-apropos Makefile
+ ./bin/mk-apropos docs/man$(2)/man5 > $$@
+docs/man$(2)/man7/index.inc: bin/mk-apropos Makefile
+ ./bin/mk-apropos docs/man$(2)/man7 > $$@
+endef
+define makemanindexes
+docs/man$(2)/man1/index.md: docs/sub-man1-index.md.tt \
+ docs/man$(2)/man1/index.inc \
+ bin/from-tt Makefile
+ ./bin/from-tt -d docs/man$(2)/man1 \
+ releases='$(MANSERIES)' release='$(2)' \
+ < $$< > $$@
+docs/man$(2)/man3/index.md: docs/sub-man3-index.md.tt \
+ docs/man$(2)/man3/index.inc \
+ bin/from-tt Makefile
+ ./bin/from-tt -d docs/man$(2)/man3 \
+ releases='$(MANSERIES)' release='$(2)' \
+ < $$< > $$@
+docs/man$(2)/man5/index.md: docs/sub-man5-index.md.tt \
+ docs/man$(2)/man5/index.inc \
+ bin/from-tt Makefile
+ ./bin/from-tt -d docs/man$(2)/man5 \
+ releases='$(MANSERIES)' release='$(2)' \
+ < $$< > $$@
+docs/man$(2)/man7/index.md: docs/sub-man7-index.md.tt \
+ docs/man$(2)/man7/index.inc \
+ bin/from-tt Makefile
+ ./bin/from-tt -d docs/man$(2)/man7 \
+ releases='$(MANSERIES)' release='$(2)' \
+ < $$< > $$@
+docs/man$(2)/index.md: docs/sub-index.md.tt bin/from-tt Makefile
+ ./bin/from-tt -d docs/man$(2) \
+ releases='$(MANSERIES)' release='$(2)' \
+ < $$< > $$@
+endef
+define makemandirdata
+docs/man$(2)/man1/dirdata.yaml: docs/sub-dirdata.yaml.tt bin/from-tt Makefile
+ ./bin/from-tt -d docs/man$(2)/man1 \
+ releases='$(MANSERIES)' release='$(2)' sectnum=1 \
+ < $$< > $$@
+docs/man$(2)/man3/dirdata.yaml: docs/sub-dirdata.yaml.tt bin/from-tt Makefile
+ ./bin/from-tt -d docs/man$(2)/man3 \
+ releases='$(MANSERIES)' release='$(2)' sectnum=3 \
+ < $$< > $$@
+docs/man$(2)/man5/dirdata.yaml: docs/sub-dirdata.yaml.tt bin/from-tt Makefile
+ ./bin/from-tt -d docs/man$(2)/man5 \
+ releases='$(MANSERIES)' release='$(2)' sectnum=5 \
+ < $$< > $$@
+docs/man$(2)/man7/dirdata.yaml: docs/sub-dirdata.yaml.tt bin/from-tt Makefile
+ ./bin/from-tt -d docs/man$(2)/man7 \
+ releases='$(MANSERIES)' release='$(2)' sectnum=7 \
+ < $$< > $$@
+docs/man$(2)/dirdata.yaml: docs/sub-dirdata.yaml.tt bin/from-tt Makefile
+ ./bin/from-tt -d docs/man$(2) \
+ releases='$(MANSERIES)' release='$(2)' \
+ < $$< > $$@
+endef
+define makemanuals1
+$(eval $(call makemanpagetts1,$(1),$(2)))
+$(eval $(call makemanapropos,$(1),$(2)))
+$(eval $(call makemanindexes,$(1),$(2)))
+$(eval $(call makemandirdata,$(1),$(2)))
+endef
+define makemanuals3
+$(eval $(call makemanpagetts3,$(1),$(2)))
+$(eval $(call makemanapropos,$(1),$(2)))
+$(eval $(call makemanindexes,$(1),$(2)))
+$(eval $(call makemandirdata,$(1),$(2)))
+endef
+
+# Now that we have the generating macros in place, let's use them!
+#
+# Start off with creating the 'manpages-master' target, taking the
+# source from $(CHECKOUTS)/openssl/doc
+$(eval $(call makemanuals3,openssl,master))
+
+# Next, create 'manpages-x.y' for all current releases from 3.0 and on,
+# taking the source from $(CHECKOUTS)/openssl-x.y/doc
+$(foreach S,$(MANSERIES3),$(eval $(call makemanuals3,openssl-$(S),$(S))))
+
+# Next, create 'manpages-x.y.z' for all current pre-3.0 releases, taking the
+# source from $(CHECKOUTS)/openssl-x.y.z-stable/doc
+$(foreach S,$(MANSERIES1),$(eval $(call makemanuals1,openssl-$(S)-stable,$(S))))
+
+MANMASTER_DIRS = \
+ $(foreach SEC,1 3 5 7, docs/manmaster/man$(SEC))
+MANMASTERTT_TARGETS = \
+ man-pagetts-master \
+ docs/manmaster/dirdata.yaml docs/manmaster/index.html \
+ $(foreach D,$(MANMASTER_DIRS), $(D)/dirdata.yaml $(D)/index.html)
+manmastertts: $(MANMASTERTT_TARGETS)
+MANPAGE_DIRS = \
+ $(foreach S,$(MANSERIES), \
+ $(foreach SEC,1 3 5 7, docs/man$(S)/man$(SEC)))
+MANPAGETT_TARGETS = \
+ $(foreach S,$(MANSERIES), man-pagetts-$(S) \
+ docs/man$(S)/dirdata.yaml docs/man$(S)/index.html) \
+ $(foreach D,$(MANPAGE_DIRS), $(D)/dirdata.yaml $(D)/index.html)
+manpagetts: manmastertts $(MANPAGETT_TARGETS)
+
+mancross:
+ ./bin/mk-mancross master $(MANSERIES)
+
+# We can't get all the files when make is started, but we can make the
+# patterns for a for loop.
+MANHTML_TTPATTERNS=$(foreach D,$(MANMASTER_DIRS) $(MANPAGE_DIRS), $(D)/*.md.tt)
+manhtml:
+ ./bin/mk-manhtml '$(MANHTML_TTPATTERNS)'
+
+docs/manpages.md: docs/manpages.md.tt Makefile bin/from-tt
+ @rm -f $@
+ ./bin/from-tt releases='master $(MANSERIES)' $<
+
+docs/mansidebar.html: docs/mansidebar.html.tt Makefile bin/from-tt
+ @rm -f $@
+ ./bin/from-tt releases='master $(MANSERIES)' $<
+
+######################################################################
+##
+## Policy page building section
+##