asciidoc.mk 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. ok = asciideck:to_manpage(asciideck:parse_file(F), #{
  35. compress => gzip,
  36. outdir => filename:dirname(F),
  37. extra2 => "$(MAN_PROJECT) $(MAN_VERSION)",
  38. extra3 => "$(MAN_PROJECT) Function Reference"
  39. })
  40. end || F <- [$(shell echo $(addprefix $(comma)\",$(addsuffix \",$1)) | sed 's/^.//')]],
  41. halt(0)
  42. catch _:_ ->
  43. halt(1)
  44. end.
  45. endef
  46. asciidoc-manual:: doc-deps
  47. asciidoc-manual:: $(ASCIIDOC_MANUAL_FILES)
  48. $(call erlang,$(call asciidoc2man.erl,$?))
  49. $(foreach s,$(MAN_SECTIONS),mkdir -p doc/man$s/ && mv doc/src/manual/*.$s.gz doc/man$s/)
  50. install-docs:: install-asciidoc
  51. install-asciidoc: asciidoc-manual
  52. $(foreach s,$(MAN_SECTIONS),\
  53. mkdir -p $(MAN_INSTALL_PATH)/man$s/ && \
  54. install -g `id -u` -o `id -g` -m 0644 doc/man$s/*.gz $(MAN_INSTALL_PATH)/man$s/)
  55. distclean-asciidoc-manual:
  56. $(gen_verbose) rm -rf $(addprefix doc/man,$(MAN_SECTIONS))
  57. endif
  58. endif