# Copyright 2014-2024 The Khronos Group Inc.
# SPDX-License-Identifier: Apache-2.0

# Configure Vulkan spec Antora tree with generated files and transformed
# markup files.
# Branch selection will come later. For now it is the current branch.

RMRF = rm -rf

JSAPIMAP = ./gen/apimap.cjs
XREFMAPS = $(PYXREFMAP) $(JSXREFMAP)
PYXREFMAP = antora/xrefMap.py
JSXREFMAP = antora/xrefMap.cjs
JSPAGEMAP = antora/modules/ROOT/partials/gen/pageMap.cjs

setup: setup_spec setup_proposals

# Rewrite Vulkan spec sources and images into the module directory, ROOT
# component
# Page headers are added to pull in required attributes
# Also creates apimap.cjs, pageMap.cjs, and xrefMap.cjs for use by the
# Antora version of the spec macros. They are copied into the Antora
# playbook repository prior to building the site.
setup_spec: xrefmaps spec_pages

# Generate the (anchor name -> [ chapter anchor, anchor title ]) maps
# (xrefMap.py / xrefMap.cjs), and the API information (jsapi /
# apimap.cjs) from spec HTML
xrefmaps:
	$(RMRF) gen
	./makeSpec QUIET=@ -clean -spec all -genpath gen generated jsapi html
	scripts/map_html_anchors.py gen/out/html/vkspec.html \
	    -pyfile $(PYXREFMAP) -jsfile $(JSXREFMAP)

# Rewrite spec sources
# Individual files must be specified last
spec_pages:
	scripts/antora-prep.py \
	    -root . \
	    -component $(shell realpath antora/modules/ROOT) \
	    -xrefpath antora \
	    -pageHeaders antora/pageHeaders-spec.adoc \
	    -pagemappath $(JSPAGEMAP) \
	    ./config/attribs.adoc \
	    ./config/copyright-ccby.adoc \
	    ./config/copyright-spec.adoc \
	    ./images/*.svg \
	    `find ./gen ./chapters ./appendices -name '[A-Za-z]*.adoc' | grep -v /vulkanscdeviations.adoc` \
	    $(JSAPIMAP)

# Rewrite proposals into the module directory, 'proposals' component
# No additional pageHeaders required.
setup_proposals:
	scripts/antora-prep.py \
	    -root . \
	    -component $(shell realpath antora/modules/proposals) \
	    -xrefpath antora \
	    ./images/tile_image.svg \
	    `find ./proposals -name '[A-Za-z]*.adoc'`

# Files generated by 'setup' target
ANTORA_GENERATED = \
	antora/modules/ROOT/images \
	antora/modules/ROOT/pages/appendices \
	antora/modules/ROOT/pages/chapters \
	antora/modules/ROOT/pages/gen \
	antora/modules/ROOT/partials \
	antora/modules/proposals/pages/proposals \
	antora/modules/proposals/partials \
	antora/modules/proposals/images \
	$(JSXREFMAP) \
	$(PYXREFMAP)

clean:
	$(RMRF) $(ANTORA_GENERATED)
