#=========================== begin_copyright_notice ============================
#
# Copyright (C) 2019-2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
#============================ end_copyright_notice =============================

# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS    =
SPHINXBUILD   = sphinx-build
SPHINXPROJ    = VCIntrinsics
SOURCEDIR     = .
BUILDDIR      = _build
AUTOGENDIR    = _build/autogenerated

# Put it first so that "make" without argument is like "make help".
help:
	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile.sphinx

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile.sphinx autogen
	echo "$@"
	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

# AUTOGENSED : auto-generation of docs from source files
# 1. Remove initial "/// ", and blank any line that does not have it.
# 2. Change ".. include <file>.<ext>" into ".. include autogen/<file>.rstinc"
AUTOGENSEDCXX='/^ *\/\/\/ /!s/.*//; s/^ *\/\/\/ //; s/\(\.\. include:: \)\(.*\)\.[a-z]*/\1$(AUTOGENDIR)\/\2.rstinc/'
AUTOGENSEDPY='/^ *\#\#\# /!s/.*//; s/^ *\#\#\# //'
autogen:
	@mkdir -p $(AUTOGENDIR)
	@rm -f $(AUTOGENDIR)/*
	@sed $(AUTOGENSEDPY) ../include/llvm/GenXIntrinsics/Intrinsic_definitions.py > $(AUTOGENDIR)/GenXLangRef.rstinc
