sphinx.mk 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright 2017, Stanislaw Klekot <dozzie@jarowit.net>
  2. # This file is part of erlang.mk and subject to the terms of the ISC License.
  3. .PHONY: distclean-sphinx sphinx
  4. # Configuration.
  5. SPHINX_BUILD ?= sphinx-build
  6. SPHINX_SOURCE ?= doc
  7. SPHINX_CONFDIR ?=
  8. SPHINX_FORMATS ?= html
  9. SPHINX_DOCTREES ?= $(ERLANG_MK_TMP)/sphinx.doctrees
  10. SPHINX_OPTS ?=
  11. #sphinx_html_opts =
  12. #sphinx_html_output = html
  13. #sphinx_man_opts =
  14. #sphinx_man_output = man
  15. #sphinx_latex_opts =
  16. #sphinx_latex_output = latex
  17. # Helpers.
  18. sphinx_build_0 = @echo " SPHINX" $1; $(SPHINX_BUILD) -N -q
  19. sphinx_build_1 = $(SPHINX_BUILD) -N
  20. sphinx_build_2 = set -x; $(SPHINX_BUILD)
  21. sphinx_build = $(sphinx_build_$(V))
  22. define sphinx.build
  23. $(call sphinx_build,$1) -b $1 -d $(SPHINX_DOCTREES) $(if $(SPHINX_CONFDIR),-c $(SPHINX_CONFDIR)) $(SPHINX_OPTS) $(sphinx_$1_opts) -- $(SPHINX_SOURCE) $(call sphinx.output,$1)
  24. endef
  25. define sphinx.output
  26. $(if $(sphinx_$1_output),$(sphinx_$1_output),$1)
  27. endef
  28. # Targets.
  29. ifneq ($(wildcard $(if $(SPHINX_CONFDIR),$(SPHINX_CONFDIR),$(SPHINX_SOURCE))/conf.py),)
  30. docs:: sphinx
  31. distclean:: distclean-sphinx
  32. endif
  33. help::
  34. $(verbose) printf "%s\n" "" \
  35. "Sphinx targets:" \
  36. " sphinx Generate Sphinx documentation." \
  37. "" \
  38. "ReST sources and 'conf.py' file are expected in directory pointed by" \
  39. "SPHINX_SOURCE ('doc' by default). SPHINX_FORMATS lists formats to build (only" \
  40. "'html' format is generated by default); target directory can be specified by" \
  41. 'setting sphinx_$${format}_output, for example: sphinx_html_output = output/html' \
  42. "Additional Sphinx options can be set in SPHINX_OPTS."
  43. # Plugin-specific targets.
  44. sphinx:
  45. $(foreach F,$(SPHINX_FORMATS),$(call sphinx.build,$F))
  46. distclean-sphinx:
  47. $(gen_verbose) rm -rf $(filter-out $(SPHINX_SOURCE),$(foreach F,$(SPHINX_FORMATS),$(call sphinx.output,$F)))