plugin_sphinx.mk 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # Sphinx plugin.
  2. SPHINX_CASES = build source-dir formats format-opts
  3. SPHINX_TARGETS = $(addprefix sphinx-,$(SPHINX_CASES))
  4. .PHONY: sphinx $(SPHINX_TARGETS)
  5. sphinx: $(SPHINX_TARGETS)
  6. sphinx-build: build clean
  7. $i "Bootstrap a new OTP application named $(APP)"
  8. $t mkdir $(APP)/
  9. $t cp ../erlang.mk $(APP)/
  10. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  11. $i "Generate Sphinx config"
  12. $(call sphinx-generate-doc-skeleton)
  13. $i "Run Sphinx"
  14. $t $(MAKE) -C $(APP) sphinx $v
  15. $i "Check that documentation was generated"
  16. $t test -f $(APP)/html/index.html
  17. $t test -f $(APP)/html/manpage.html
  18. $i "Distclean the application"
  19. $t $(MAKE) -C $(APP) distclean $v
  20. $i "Check that the generated documentation was removed"
  21. $t test ! -e $(APP)/html/index.html
  22. $t test ! -e $(APP)/html/manpage.html
  23. $i "Set 'today' macro with command-line options"
  24. $t echo "SPHINX_OPTS = -D 'today=erlang_mk_sphinx_today'" >> $(APP)/Makefile
  25. $i "Run Sphinx"
  26. $t $(MAKE) -C $(APP) sphinx $v
  27. $i "Check that the 'today' macro was defined"
  28. $t grep -q erlang_mk_sphinx_today $(APP)/html/manpage.html
  29. sphinx-source-dir: build clean
  30. $i "Bootstrap a new OTP application named $(APP)"
  31. $t mkdir $(APP)/
  32. $t cp ../erlang.mk $(APP)/
  33. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  34. $i "Change documentation source directory"
  35. $t echo "SPHINX_SOURCE = documentation" >> $(APP)/Makefile
  36. $i "Generate Sphinx config"
  37. $(call sphinx-generate-doc-skeleton,documentation)
  38. $i "Run Sphinx (html)"
  39. $t $(MAKE) -C $(APP) sphinx $v
  40. $i "Check that documentation was generated"
  41. $t test -f $(APP)/html/index.html
  42. $t test -f $(APP)/html/manpage.html
  43. sphinx-formats: build clean
  44. $i "Bootstrap a new OTP application named $(APP)"
  45. $t mkdir $(APP)/
  46. $t cp ../erlang.mk $(APP)/
  47. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  48. $i "Define formats generated by Sphinx"
  49. $t echo "SPHINX_FORMATS = html man" >> $(APP)/Makefile
  50. $i "Generate Sphinx config"
  51. $(call sphinx-generate-doc-skeleton)
  52. $i "Run Sphinx (html + man)"
  53. $t $(MAKE) -C $(APP) sphinx $v
  54. $i "Check that documentation was generated"
  55. $t test -f $(APP)/man/sphinx_$(APP).1
  56. $t test -f $(APP)/html/index.html
  57. $t test -f $(APP)/html/manpage.html
  58. $i "Distclean the application"
  59. $t $(MAKE) -C $(APP) distclean $v
  60. $i "Check that the generated documentation was removed"
  61. $t test ! -e $(APP)/man/sphinx_$(APP).1
  62. $t test ! -e $(APP)/html/index.html
  63. $t test ! -e $(APP)/html/manpage.html
  64. $i "Change documentation output directories"
  65. $t echo "sphinx_html_output = sphinx/html_output" >> $(APP)/Makefile
  66. $t echo "sphinx_man_output = sphinx/man_output" >> $(APP)/Makefile
  67. $i "Run Sphinx (html + man)"
  68. $t $(MAKE) -C $(APP) sphinx $v
  69. $i "Check that documentation was generated"
  70. $t test -f $(APP)/sphinx/man_output/sphinx_$(APP).1
  71. $t test -f $(APP)/sphinx/html_output/index.html
  72. $t test -f $(APP)/sphinx/html_output/manpage.html
  73. $i "Distclean the application"
  74. $t $(MAKE) -C $(APP) distclean $v
  75. $i "Check that the generated documentation was removed"
  76. $t test ! -e $(APP)/sphinx/man_output/sphinx_$(APP).1
  77. $t test ! -e $(APP)/sphinx/html_output/index.html
  78. $t test ! -e $(APP)/sphinx/html_output/manpage.html
  79. sphinx-format-opts: build clean
  80. $i "Bootstrap a new OTP application named $(APP)"
  81. $t mkdir $(APP)/
  82. $t cp ../erlang.mk $(APP)/
  83. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  84. $i "Define formats generated by Sphinx"
  85. $t echo "SPHINX_FORMATS = html man" >> $(APP)/Makefile
  86. $i "Change format-specific options"
  87. $t echo "sphinx_html_opts = -D 'today=erlang_mk_sphinx_html_today'" >> $(APP)/Makefile
  88. $t echo "sphinx_man_opts = -D 'today=erlang_mk_sphinx_man_today'" >> $(APP)/Makefile
  89. $i "Generate Sphinx config"
  90. $(call sphinx-generate-doc-skeleton)
  91. $i "Run Sphinx (html + man)"
  92. $t $(MAKE) -C $(APP) sphinx $v
  93. $i "Check that the 'today' macro was defined correctly"
  94. $t grep -q erlang_mk_sphinx_html_today $(APP)/html/manpage.html
  95. $t grep -q erlang_mk_sphinx_man_today $(APP)/man/sphinx_$(APP).1
  96. define sphinx-generate-doc-skeleton
  97. $t mkdir $(APP)/$(if $1,$1,doc)/
  98. $t printf "%s\n" \
  99. "project = '$(APP)'" \
  100. "master_doc = 'index'" \
  101. "source_suffix = '.rst'" \
  102. "man_pages = [('manpage', 'sphinx_$(APP)', 'Man Page', [], 1)]" \
  103. "" > $(APP)/$(if $1,$1,doc)/conf.py
  104. $t printf "%s\n" \
  105. "***********" \
  106. "Sphinx Docs" \
  107. "***********" \
  108. "" \
  109. "ToC" \
  110. "===" \
  111. "" \
  112. ".. toctree::" \
  113. "" \
  114. " manpage" \
  115. "" \
  116. "Indices" \
  117. "=======" \
  118. "" \
  119. '* :ref:`genindex`' \
  120. '* :ref:`modindex`' \
  121. '* :ref:`search`' \
  122. "" > $(APP)/$(if $1,$1,doc)/index.rst
  123. $t printf "%s\n" \
  124. "********" \
  125. "Man Page" \
  126. "********" \
  127. "" \
  128. "Synopsis" \
  129. "========" \
  130. "" \
  131. ".. code-block:: none" \
  132. "" \
  133. " erlang-sphinx-mk-man [--help]" \
  134. "" \
  135. "today = |today|" \
  136. "" > $(APP)/$(if $1,$1,doc)/manpage.rst
  137. endef