#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.
#export DH_VERBOSE = 1

export PYBUILD_NAME=rocm-docs
# Skip Online test
export PYBUILD_TEST_ARGS=--ignore tests/test_projects.py

url=https://github.com/ROCm/rocm-docs-core
# When you set branch=latest you SHOULD get latest_version value in the header
# With branch=experimental you SHOULD get no version displayed
# See ./src/rocm_docs/rocm_docs_theme/flavors/rocm/header.jinja
#branch=experimental
branch=latest

# https://raw.githubusercontent.com/ROCm/rocm-docs-core/data/latest_version.txt
latest_version="6.4.1"
# https://raw.githubusercontent.com/ROCm/rocm-docs-core/data/release_candidate.txt
release_candidate="6.4.2"
# https://raw.githubusercontent.com/ROCm/rocm-docs-core/data/google_site_verification.txt
google_site_verification = "vo35SZt_GASsTHAEmdww7AYKPCvZyzLvOXBl8guBME4"

%:
	dh $@ --with sphinxdoc --buildsystem=pybuild

# To rebuild the Sphinx documentation when it will be possible
execute_after_dh_auto_build-indep: export http_proxy=127.0.0.1:9
execute_after_dh_auto_build-indep: export https_proxy=127.0.0.1:9
execute_after_dh_auto_build-indep:
		# Disabling net access during build
		# Disabling git request for sbuild
		export PYTHONPATH=.:..:../build/lib:./build/lib:../src:./src ; \
		export latest_version="$(latest_version)" ; \
		export release_candidate="$(release_candidate)" ; \
		export google_site_verification="$(google_site_verification)" ; \
		export ROCM_DOCS_REMOTE_DETAILS="$(url),$(branch)" ; \
		cd docs ; python3 -m sphinx \
		-T -E -b html -d ../_build/doctrees \
		-D language=en \
		. ../_build/html
		# Remove fonts that will be symlinks
		rm -rf _build/html/_static/fonts
		rm -rf _build/html/_static/vendor

override_dh_install:
	dh_install
	# Fix font files permissions
	find . -name '*.woff*' -exec chmod ugo-x {} \;
	# Remove vcs-control-file gitignore
	find . -name '*.gitignore*' -exec rm -f {} \;
	# Fix vectorial images permissions
	find . -name '*.svg*' -exec chmod ugo-x {} \;

override_dh_compress:
	# Do not compress sphinx doc (ttf fonts for example)
	dh_compress -Xpython-rocm-docs-doc/html

override_dh_clean:
	dh_clean
	# Remove various possibly generated doc to allow easy local rebuild (debuild) \
	# See README.source for more info
	-rm -rf docs/_doxygen/ docs/demo/doxygen/html/ docs/_build/ \
		docs/demo/doxygen/xml/ .pybuild/ _build/ src/rocm_docs/_doxygen
	-rm -f docs/sphinx/_toc.yml
