Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 31 May 2021 16:26:20 GMT
From:      Marc Fonvieille <blackend@FreeBSD.org>
To:        doc-committers@FreeBSD.org, dev-commits-doc-all@FreeBSD.org
Subject:   git: 5f4322e404 - main - documentation/Makefile: Add PDF targets.
Message-ID:  <202105311626.14VGQKfc005089@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by blackend:

URL: https://cgit.FreeBSD.org/doc/commit/?id=5f4322e404e4ea93f640658f3aef25b7e45a4e95

commit 5f4322e404e4ea93f640658f3aef25b7e45a4e95
Author:     Marc Fonvieille <blackend@FreeBSD.org>
AuthorDate: 2021-05-31 16:16:55 +0000
Commit:     Marc Fonvieille <blackend@FreeBSD.org>
CommitDate: 2021-05-31 16:16:55 +0000

    documentation/Makefile: Add PDF targets.
    
    Addition of various PDF targets allowing the build of books, articles
    with the choice of the language.  For example, to build both en_US and
    fr_FR books, use:
    make DOC_LANG="en,fr" pdf-books
    Documents are installed in documentation/public/lang/.  Targets to clean
    the builds are also available.
    
    Reviewed by:    ceri, gjb, dbaio
    Differential Revision:  <https://reviews.freebsd.org/D30331>;
---
 documentation/Makefile | 132 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 132 insertions(+)

diff --git a/documentation/Makefile b/documentation/Makefile
index 72616084fa..2257cc0061 100644
--- a/documentation/Makefile
+++ b/documentation/Makefile
@@ -20,13 +20,20 @@ LOCALBASE?=	/usr/local
 PYTHON_CMD =	${LOCALBASE}/bin/python3
 RUBY_CMD =	${LOCALBASE}/bin/ruby
 HUGO_CMD =	${LOCALBASE}/bin/hugo
+ASCIIDOCTORPDF_CMD=	/usr/local/bin/asciidoctor-pdf
+.if defined(DOC_LANG) && !empty(DOC_LANG)
+LANGUAGES =	${DOC_LANG}
+.else
 LANGUAGES =	en,es,pt-br,de,ja,zh-cn,zh-tw,ru,el,hu,it,mn,nl,pl,fr
+.endif
+
 RUBYLIB =	../shared/lib
 .export	RUBYLIB
 
 RUN_DEPENDS=	${PYTHON_CMD} \
 		${HUGO_CMD} \
 		${LOCALBASE}/bin/asciidoctor \
+		${LOCALBASE}/bin/asciidoctor-pdf \
 		${LOCALBASE}/bin/rougify
 
 .ifndef HOSTNAME
@@ -72,3 +79,128 @@ run-local: .PHONY
 
 build: .PHONY
 	${HUGO_CMD} --minify
+
+#
+# PDF targets
+# Use DOC_LANG to choose the language, e.g., make DOC_LANG="en,fr" pdf-books
+#
+pdf: pdf-articles pdf-books
+
+pdf-books-target:
+.for _lang in ${LANGUAGES:S|,| |g}
+.if exists(${.CURDIR}/content/${_lang}/books/)
+TMP += ${.CURDIR}/content/${_lang}/books/*/
+.endif
+.endfor
+BOOKSDIR != echo ${TMP}
+
+pdf-articles-target:
+.for _lang in ${LANGUAGES:S|,| |g}
+.if exists(${.CURDIR}/content/${_lang}/articles/)
+TTMP += ${.CURDIR}/content/${_lang}/articles/*/
+.endif
+.endfor
+ARTICLESDIR != echo ${TTMP}
+
+pdf-books: pdf-books-target generate-books-toc
+
+# Books build
+#
+# Notes:
+# pdf-theme=default-with-fallback-font is
+# used instead of pdf-theme=./themes/default-pdf-theme.yml because
+# it allows ja, ru, tr, zh-* fonts to be embedded and rendering is
+# better for other languages.
+#
+# asciidoctor-pdf-cjk and/or specific themes should be used for cjk
+# fonts
+.for _curpdf in ${BOOKSDIR}
+	@mkdir -p ${.CURDIR}/public${_curpdf:S|^${.CURDIR}/content||}
+.if exists(${_curpdf}book.adoc)
+	${ASCIIDOCTORPDF_CMD} \
+	-r ./shared/lib/man-macro.rb \
+	-r ./shared/lib/man-macro.rb \
+	-r ./shared/lib/git-macro.rb \
+	-r ./shared/lib/packages-macro.rb \
+	-r ./shared/lib/inter-document-references-macro.rb \
+	-r ./shared/lib/sectnumoffset-treeprocessor.rb \
+	--doctype=book \
+	-a skip-front-matter \
+	-a pdf-theme=default-with-fallback-font \
+	-o ${.CURDIR}/public${_curpdf:S|^${.CURDIR}/content||}book.pdf \
+	${_curpdf}book.adoc
+.else
+# some books use _index.adoc as main document
+	${ASCIIDOCTORPDF_CMD} \
+	-r ./shared/lib/man-macro.rb \
+	-r ./shared/lib/man-macro.rb \
+	-r ./shared/lib/git-macro.rb \
+	-r ./shared/lib/packages-macro.rb \
+	-r ./shared/lib/inter-document-references-macro.rb \
+	-r ./shared/lib/sectnumoffset-treeprocessor.rb \
+	--doctype=book \
+	-a skip-front-matter \
+	-a pdf-theme=default-with-fallback-font \
+	-o ${.CURDIR}/public${_curpdf:S|^${.CURDIR}/content||}book.pdf \
+	${_curpdf}_index.adoc
+.endif
+.endfor
+
+pdf-articles: pdf-articles-target
+
+# Articles build
+.for _curpdf in ${ARTICLESDIR}
+	@mkdir -p ${.CURDIR}/public${_curpdf:S|^${.CURDIR}/content||}
+	${ASCIIDOCTORPDF_CMD} \
+	-r ./shared/lib/man-macro.rb \
+	-r ./shared/lib/man-macro.rb \
+	-r ./shared/lib/git-macro.rb \
+	-r ./shared/lib/packages-macro.rb \
+	-r ./shared/lib/inter-document-references-macro.rb \
+	-r ./shared/lib/sectnumoffset-treeprocessor.rb \
+	--doctype=article \
+	-a skip-front-matter \
+	-a pdf-theme=default-with-fallback-font \
+	-o ${.CURDIR}/public${_curpdf:S|^${.CURDIR}/content||}article.pdf \
+	${_curpdf}_index.adoc
+.if exists(${.CURDIR}/static/source/articles/${_curpdf:H:T})
+	cp -R ${.CURDIR}/static/source/articles/${_curpdf:H:T}/ \
+		${.CURDIR}/public${_curpdf:S|^${.CURDIR}/content||}
+.endif
+.endfor
+
+pdf-clean: pdf-articles-clean pdf-books-clean
+
+pdf-books-clean: pdf-books-target
+.for _curpdf in ${BOOKSDIR}
+	rm -f ${.CURDIR}/public${_curpdf:S|^${.CURDIR}/content||}book.pdf ${_curpdf}toc*.adoc
+	rm -fr ${.CURDIR}/public${_curpdf:S|^${.CURDIR}/content||}
+.endfor
+.for _lang in ${LANGUAGES:S|,| |g}
+	rm -fr ${.CURDIR}/public/${_lang}/books
+.if !exists(${.CURDIR}/public/${_lang}/articles)
+	rm -fr ${.CURDIR}/public/${_lang}
+.endif
+.endfor
+	@if [ -d ${.CURDIR}/public/ ]; then \
+		if [ -z "`ls -A ${.CURDIR}/public/`" ]; then \
+			rm -fr ${.CURDIR}/public; \
+		fi;	\
+	fi
+
+pdf-articles-clean: pdf-articles-target
+.for _curpdf in ${ARTICLESDIR}
+	rm -f ${.CURDIR}/public${_curpdf:S|^${.CURDIR}/content||}article.pdf
+	rm -fr ${.CURDIR}/public${_curpdf:S|^${.CURDIR}/content||}
+.endfor
+.for _lang in ${LANGUAGES:S|,| |g}
+	rm -fr ${.CURDIR}/public/${_lang}/articles
+.if !exists(${.CURDIR}/public/${_lang}/books)
+	rm -fr ${.CURDIR}/public/${_lang}
+.endif
+.endfor
+	@if [ -d ${.CURDIR}/public/ ]; then \
+		if [ -z "`ls -A ${.CURDIR}/public/`" ]; then \
+			rm -fr ${.CURDIR}/public; \
+		fi;	\
+	fi



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202105311626.14VGQKfc005089>