asciidoc.mk 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright (c) 2015-2016, Loïc Hoguin <essen@ninenines.eu>
  2. # This file is part of erlang.mk and subject to the terms of the ISC License.
  3. ifeq ($(filter asciideck,$(DEPS) $(DOC_DEPS)),asciideck)
  4. .PHONY: asciidoc asciidoc-guide asciidoc-manual install-asciidoc distclean-asciidoc-guide distclean-asciidoc-manual
  5. # Core targets.
  6. docs:: asciidoc
  7. distclean:: distclean-asciidoc-guide distclean-asciidoc-manual
  8. # Plugin-specific targets.
  9. asciidoc: asciidoc-guide asciidoc-manual
  10. # User guide.
  11. ifeq ($(wildcard doc/src/guide/book.asciidoc),)
  12. asciidoc-guide:
  13. else
  14. asciidoc-guide: distclean-asciidoc-guide doc-deps
  15. a2x -v -f pdf doc/src/guide/book.asciidoc && mv doc/src/guide/book.pdf doc/guide.pdf
  16. a2x -v -f chunked doc/src/guide/book.asciidoc && mv doc/src/guide/book.chunked/ doc/html/
  17. distclean-asciidoc-guide:
  18. $(gen_verbose) rm -rf doc/html/ doc/guide.pdf
  19. endif
  20. # Man pages.
  21. ASCIIDOC_MANUAL_FILES := $(wildcard doc/src/manual/*.asciidoc)
  22. ifeq ($(ASCIIDOC_MANUAL_FILES),)
  23. asciidoc-manual:
  24. else
  25. # Configuration.
  26. MAN_INSTALL_PATH ?= /usr/local/share/man
  27. MAN_SECTIONS ?= 3 7
  28. MAN_PROJECT ?= $(shell echo $(PROJECT) | sed 's/^./\U&\E/')
  29. MAN_VERSION ?= $(PROJECT_VERSION)
  30. # Plugin-specific targets.
  31. define asciidoc2man.erl
  32. try
  33. [begin
  34. io:format(" ADOC ~s~n", [F]),
  35. ok = asciideck:to_manpage(asciideck:parse_file(F), #{
  36. compress => gzip,
  37. outdir => filename:dirname(F),
  38. extra2 => "$(MAN_PROJECT) $(MAN_VERSION)",
  39. extra3 => "$(MAN_PROJECT) Function Reference"
  40. })
  41. end || F <- [$(shell echo $(addprefix $(comma)\",$(addsuffix \",$1)) | sed 's/^.//')]],
  42. halt(0)
  43. catch C:E ->
  44. io:format("Exception ~p:~p~nStacktrace: ~p~n", [C, E, erlang:get_stacktrace()]),
  45. halt(1)
  46. end.
  47. endef
  48. asciidoc-manual:: doc-deps
  49. asciidoc-manual:: $(ASCIIDOC_MANUAL_FILES)
  50. $(gen_verbose) $(call erlang,$(call asciidoc2man.erl,$?))
  51. $(verbose) $(foreach s,$(MAN_SECTIONS),mkdir -p doc/man$s/ && mv doc/src/manual/*.$s.gz doc/man$s/;)
  52. install-docs:: install-asciidoc
  53. install-asciidoc: asciidoc-manual
  54. $(foreach s,$(MAN_SECTIONS),\
  55. mkdir -p $(MAN_INSTALL_PATH)/man$s/ && \
  56. install -g `id -g` -o `id -u` -m 0644 doc/man$s/*.gz $(MAN_INSTALL_PATH)/man$s/;)
  57. distclean-asciidoc-manual:
  58. $(gen_verbose) rm -rf $(addprefix doc/man,$(MAN_SECTIONS))
  59. endif
  60. endif