From b5e50a342f7312330dc56026c223b1f17bab1fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 31 Oct 2016 23:28:38 +0200 Subject: Switch asciidoc-manual to using Asciideck This is a start for moving from Python's Asciidoc to the Erlang implementation. Please report any issue with this change, I will fix everything at lightning speed! --- plugins/asciidoc.mk | 80 +++++++++++++++++++++++++++++++++++-------------- test/plugin_asciidoc.mk | 26 +++++++++++++++- 2 files changed, 82 insertions(+), 24 deletions(-) diff --git a/plugins/asciidoc.mk b/plugins/asciidoc.mk index 76ca6d5..5a40848 100644 --- a/plugins/asciidoc.mk +++ b/plugins/asciidoc.mk @@ -1,46 +1,80 @@ # Copyright (c) 2015-2016, Loïc Hoguin # This file is part of erlang.mk and subject to the terms of the ISC License. -.PHONY: asciidoc asciidoc-guide asciidoc-manual install-asciidoc distclean-asciidoc +ifeq ($(filter asciideck,$(DEPS) $(DOC_DEPS)),asciideck) -MAN_INSTALL_PATH ?= /usr/local/share/man -MAN_SECTIONS ?= 3 7 +.PHONY: asciidoc asciidoc-guide asciidoc-manual install-asciidoc distclean-asciidoc-guide distclean-asciidoc-manual + +# Core targets. docs:: asciidoc +distclean:: distclean-asciidoc-guide distclean-asciidoc-manual + +# Plugin-specific targets. + asciidoc: asciidoc-guide asciidoc-manual +# User guide. + ifeq ($(wildcard doc/src/guide/book.asciidoc),) asciidoc-guide: else -asciidoc-guide: distclean-asciidoc doc-deps +asciidoc-guide: distclean-asciidoc-guide doc-deps a2x -v -f pdf doc/src/guide/book.asciidoc && mv doc/src/guide/book.pdf doc/guide.pdf a2x -v -f chunked doc/src/guide/book.asciidoc && mv doc/src/guide/book.chunked/ doc/html/ + +distclean-asciidoc-guide: + $(gen_verbose) rm -rf doc/html/ doc/guide.pdf endif -ifeq ($(wildcard doc/src/manual/*.asciidoc),) +# Man pages. + +ASCIIDOC_MANUAL_FILES := $(wildcard doc/src/manual/*.asciidoc) + +ifeq ($(ASCIIDOC_MANUAL_FILES),) asciidoc-manual: else -asciidoc-manual: distclean-asciidoc doc-deps - for f in doc/src/manual/*.asciidoc ; do \ - a2x -v -f manpage $$f ; \ - done - for s in $(MAN_SECTIONS); do \ - mkdir -p doc/man$$s/ ; \ - mv doc/src/manual/*.$$s doc/man$$s/ ; \ - gzip doc/man$$s/*.$$s ; \ - done + +# Configuration. + +MAN_INSTALL_PATH ?= /usr/local/share/man +MAN_SECTIONS ?= 3 7 +MAN_PROJECT ?= $(shell echo $(PROJECT) | sed 's/^./\U&\E/') +MAN_VERSION ?= $(PROJECT_VERSION) + +# Plugin-specific targets. + +define asciidoc2man.erl +try + [begin + ok = asciideck:to_manpage(asciideck:parse_file(F), #{ + compress => gzip, + outdir => filename:dirname(F), + extra2 => "$(MAN_PROJECT) $(MAN_VERSION)", + extra3 => "$(MAN_PROJECT) Function Reference" + }) + end || F <- [$(shell echo $(addprefix $(comma)\",$(addsuffix \",$1)) | sed 's/^.//')]], + halt(0) +catch _:_ -> + halt(1) +end. +endef + +asciidoc-manual:: doc-deps + +asciidoc-manual:: $(ASCIIDOC_MANUAL_FILES) + $(call erlang,$(call asciidoc2man.erl,$?)) + $(foreach s,$(MAN_SECTIONS),mkdir -p doc/man$s/ && mv doc/src/manual/*.$s.gz doc/man$s/) install-docs:: install-asciidoc install-asciidoc: asciidoc-manual - for s in $(MAN_SECTIONS); do \ - mkdir -p $(MAN_INSTALL_PATH)/man$$s/ ; \ - install -g `id -u` -o `id -g` -m 0644 doc/man$$s/*.gz $(MAN_INSTALL_PATH)/man$$s/ ; \ - done -endif - -distclean:: distclean-asciidoc + $(foreach s,$(MAN_SECTIONS),\ + mkdir -p $(MAN_INSTALL_PATH)/man$s/ && \ + install -g `id -u` -o `id -g` -m 0644 doc/man$s/*.gz $(MAN_INSTALL_PATH)/man$s/) -distclean-asciidoc: - $(gen_verbose) rm -rf doc/html/ doc/guide.pdf doc/man3/ doc/man7/ +distclean-asciidoc-manual: + $(gen_verbose) rm -rf $(addprefix doc/man,$(MAN_SECTIONS)) +endif +endif diff --git a/test/plugin_asciidoc.mk b/test/plugin_asciidoc.mk index a583585..8f20fae 100644 --- a/test/plugin_asciidoc.mk +++ b/test/plugin_asciidoc.mk @@ -14,6 +14,9 @@ asciidoc-build: build clean $t cp ../erlang.mk $(APP)/ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v + $i "Add asciideck to the local dependencies" + $t perl -ni.bak -e 'print;if ($$.==1) {print "DOC_DEPS = asciideck\n"}' $(APP)/Makefile + $i "Only enable man pages section 3" $t perl -ni.bak -e 'print;if ($$.==1) {print "MAN_SECTIONS = 3\n"}' $(APP)/Makefile @@ -68,6 +71,9 @@ asciidoc-docs: build clean $t cp ../erlang.mk $(APP)/ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v + $i "Add asciideck to the local dependencies" + $t perl -ni.bak -e 'print;if ($$.==1) {print "DOC_DEPS = asciideck\n"}' $(APP)/Makefile + $i "Generate AsciiDoc documentation" $t mkdir -p $(APP)/doc/src/guide/ $t printf "%s\n" \ @@ -86,6 +92,9 @@ asciidoc-guide: build clean $t cp ../erlang.mk $(APP)/ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v + $i "Add asciideck to the local dependencies" + $t perl -ni.bak -e 'print;if ($$.==1) {print "DOC_DEPS = asciideck\n"}' $(APP)/Makefile + $i "Generate AsciiDoc documentation" $t mkdir -p $(APP)/doc/src/guide/ $(APP)/doc/src/manual/ $t printf "%s\n" \ @@ -111,6 +120,9 @@ asciidoc-install: build clean $t cp ../erlang.mk $(APP)/ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v + $i "Add asciideck to the local dependencies" + $t perl -ni.bak -e 'print;if ($$.==1) {print "DOC_DEPS = asciideck\n"}' $(APP)/Makefile + $i "Only enable man pages section 3" $t perl -ni.bak -e 'print;if ($$.==1) {print "MAN_SECTIONS = 3\n"}' $(APP)/Makefile @@ -136,6 +148,9 @@ asciidoc-manual: build clean $t cp ../erlang.mk $(APP)/ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v + $i "Add asciideck to the local dependencies" + $t perl -ni.bak -e 'print;if ($$.==1) {print "DOC_DEPS = asciideck\n"}' $(APP)/Makefile + $i "Only enable man pages section 3" $t perl -ni.bak -e 'print;if ($$.==1) {print "MAN_SECTIONS = 3\n"}' $(APP)/Makefile @@ -150,9 +165,18 @@ asciidoc-manual: build clean "erlang_mk - Erlang.mk test" "" \ "== Description" "" \ "Hello world!" > $(APP)/doc/src/manual/erlang_mk.asciidoc + $t printf "%s\n" \ + "= name_changed(3)" "" \ + "== Name" "" \ + "name_changed - Manual page name different than output" "" \ + "== Description" "" \ + "Name changed!" > $(APP)/doc/src/manual/change_name.asciidoc - $i "Check that only the manual is generated on 'make asciidoc-manual'" + $i "Run 'make asciidoc-manual'" $t $(MAKE) -C $(APP) asciidoc-manual $v + + $i "Check that only the manual was generated" $t test ! -e $(APP)/doc/guide.pdf $t test ! -e $(APP)/doc/html/ $t test -f $(APP)/doc/man3/erlang_mk.3.gz + $t test -f $(APP)/doc/man3/name_changed.3.gz -- cgit v1.2.3