author | ihse |
Wed, 17 Oct 2018 11:41:33 +0200 | |
branch | ihse-manpages-branch |
changeset 56977 | 9221e7c3bf36 |
parent 56974 | 8139ac807fc9 |
child 57000 | 03413eb7301f |
permissions | -rw-r--r-- |
56950 | 1 |
# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
44983 | 2 |
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 |
# |
|
4 |
# This code is free software; you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU General Public License version 2 only, as |
|
6 |
# published by the Free Software Foundation. Oracle designates this |
|
7 |
# particular file as subject to the "Classpath" exception as provided |
|
8 |
# by Oracle in the LICENSE file that accompanied this code. |
|
9 |
# |
|
10 |
# This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
# version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
# accompanied this code). |
|
15 |
# |
|
16 |
# You should have received a copy of the GNU General Public License version |
|
17 |
# 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
# |
|
20 |
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 |
# or visit www.oracle.com if you need additional information or have any |
|
22 |
# questions. |
|
23 |
# |
|
24 |
||
25 |
ifeq (,$(_MAKEBASE_GMK)) |
|
26 |
$(error You must include MakeBase.gmk prior to including ProcessMarkdown.gmk) |
|
27 |
endif |
|
28 |
||
29 |
# Helper function for SetupProcessMarkdown |
|
30 |
# $1: The $1 from SetupProcessMarkdown |
|
31 |
# $2: The name of the current source file, relative to $1_SRC |
|
32 |
define ProcessMarkdown |
|
56891
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
33 |
$1_$2_OUTPUT_FILE := $$($1_DEST)/$$(basename $2)$$($1_FILE_EXT) |
44983 | 34 |
$1_$2_TARGET_DIR := $$(dir $$($1_$2_OUTPUT_FILE)) |
56973 | 35 |
$1_$2_INPUT_FILE := $$($1_SRC)/$2 |
36 |
$1_$2_MARKER := $$(subst /,_,$1_$2) |
|
37 |
||
38 |
ifneq ($$($1_PRE_PROCESS), ) |
|
39 |
$1_$2_PANDOC_INPUT := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_pre.tmp |
|
40 |
else |
|
41 |
$1_$2_PANDOC_INPUT := $$($1_$2_INPUT_FILE) |
|
42 |
endif |
|
43 |
||
44 |
ifneq ($$($1_POST_PROCESS), ) |
|
45 |
$1_$2_PANDOC_OUTPUT := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_post.tmp |
|
46 |
else |
|
47 |
$1_$2_PANDOC_OUTPUT := $$($1_$2_OUTPUT_FILE) |
|
48 |
endif |
|
56891
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
49 |
|
44983 | 50 |
ifneq ($$($1_CSS), ) |
51 |
ifneq ($$(findstring http:/, $$($1_CSS)), ) |
|
52 |
$1_$2_CSS_OPTION := --css '$$($1_CSS)' |
|
53 |
else |
|
45227 | 54 |
$1_$2_CSS := $$(strip $$(call RelativePath, $$($1_CSS), $$($1_$2_TARGET_DIR))) |
44983 | 55 |
$1_$2_CSS_OPTION := --css '$$($1_$2_CSS)' |
56 |
endif |
|
57 |
endif |
|
56977
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
58 |
|
56972 | 59 |
$1_$2_OPTIONS := $$(shell $$(GREP) _pandoc-options_: $$($1_SRC)/$2 | $$(CUT) -d : -f 2-) |
60 |
||
56977
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
61 |
ifneq ($$($1_FILTER), ) |
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
62 |
$1_$2_OPTIONS += --filter $$($1_FILTER) |
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
63 |
endif |
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
64 |
|
56972 | 65 |
$1_$2_VARDEPS := $$($1_OPTIONS) $$($1_$2_OPTIONS) $$($1_CSS) |
44983 | 66 |
$1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \ |
67 |
$$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER).vardeps) |
|
68 |
||
56977
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
69 |
$$($1_$2_OUTPUT_FILE): $$($1_$2_INPUT_FILE) $$($1_$2_VARDEPS_FILE) $$($1_EXTRA_DEPS) |
56972 | 70 |
$$(call LogInfo, Converting $2 to $$($1_FORMAT)) |
44983 | 71 |
$$(call MakeDir, $$($1_$2_TARGET_DIR) $$(SUPPORT_OUTPUTDIR)/markdown) |
56973 | 72 |
ifneq ($$($1_PRE_PROCESS), ) |
73 |
$$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_pre, \ |
|
74 |
$$($1_PRE_PROCESS) < $$($1_$2_INPUT_FILE) > $$($1_$2_PANDOC_INPUT)) |
|
75 |
endif |
|
44983 | 76 |
$$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER), \ |
56972 | 77 |
$$(PANDOC) $$($1_OPTIONS) -f markdown -t $$($1_FORMAT) --standalone \ |
56973 | 78 |
$$($1_$2_CSS_OPTION) $$($1_$2_OPTIONS) '$$($1_$2_PANDOC_INPUT)' \ |
79 |
-o '$$($1_$2_PANDOC_OUTPUT)') |
|
56972 | 80 |
ifneq ($$($1_POST_PROCESS), ) |
56973 | 81 |
$$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_post, \ |
82 |
$$($1_POST_PROCESS) < $$($1_$2_PANDOC_OUTPUT) > $$($1_$2_OUTPUT_FILE)) |
|
56972 | 83 |
endif |
44983 | 84 |
ifneq ($$(findstring $$(LOG_LEVEL), debug trace),) |
56972 | 85 |
TOO_LONG_LINES=`$$(GREP) -E -e '^.{80}.+$$$$' $$<` || true ; \ |
86 |
if [ "x$$$$TOO_LONG_LINES" != x ]; then \ |
|
87 |
$$(ECHO) "Warning: Unsuitable markdown in $$<:" ; \ |
|
88 |
$$(ECHO) "The following lines are longer than 80 characters:" ; \ |
|
89 |
$$(GREP) -E -n -e '^.{80}.+$$$$' $$< || true ; \ |
|
90 |
fi |
|
44983 | 91 |
endif |
92 |
||
93 |
$1 += $$($1_$2_OUTPUT_FILE) |
|
94 |
endef |
|
95 |
||
96 |
################################################################################ |
|
97 |
# Setup make rules for converting a markdown file to html. |
|
98 |
# |
|
99 |
# Parameter 1 is the name of the rule. This name is used as variable prefix, |
|
100 |
# and the targets generated are listed in a variable by that name. |
|
101 |
# |
|
102 |
# Remaining parameters are named arguments. These include: |
|
56891
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
103 |
# SRC : Source root dir (defaults to dir of first file) |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
104 |
# DEST : Dest root dir |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
105 |
# FILES : List of files to copy with absolute paths, or path relative to SRC. |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
106 |
# Must be in SRC. |
56972 | 107 |
# FORMAT : The target format (defaults to html5) |
56891
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
108 |
# FILE_EXT : The file extension to replace .md with (defaults to .html) |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
109 |
# OPTIONS : Additional options to pandoc |
56977
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
110 |
# EXTRA_DEPS : Additional dependencies to add to each pandoc call |
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
111 |
# FILTER : Optional pandoc filter command |
44983 | 112 |
# |
113 |
SetupProcessMarkdown = $(NamedParamsMacroTemplate) |
|
114 |
define SetupProcessMarkdownBody |
|
115 |
ifeq ($$($1_FILES), ) |
|
116 |
$$(error FILES is missing in SetupProcessMarkdown $1) |
|
117 |
endif |
|
118 |
||
119 |
ifeq ($$($1_DEST), ) |
|
120 |
$$(error DEST is missing in SetupProcessMarkdown $1) |
|
121 |
endif |
|
122 |
||
123 |
# Default SRC to the dir of the first file. |
|
124 |
ifeq ($$($1_SRC), ) |
|
125 |
$1_SRC := $$(dir $$(firstword $$($1_FILES))) |
|
126 |
endif |
|
127 |
||
56972 | 128 |
# If no target format is specified, default to html5. |
56891
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
129 |
ifeq ($$($1_FORMAT), ) |
56972 | 130 |
$1_FORMAT := html5 |
56891
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
131 |
endif |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
132 |
|
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
133 |
ifeq ($$($1_FORMAT), man) |
56974 | 134 |
# Use preprocessing to inject the current version. |
56977
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
135 |
$1_PRE_PROCESS := $(SED) -e 's/@@VERSION_SHORT@@/$(VERSION_SHORT)/g' |
56972 | 136 |
|
56891
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
137 |
# Pandoc's default behavior is to convert `code` to \f[C], which do not |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
138 |
# show up in normal man page rendering (but shows correctly when generating |
56977
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
139 |
# html). The norm for man pages is to show code as bold, so this should be |
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
140 |
# transformed. However, even if we fix this in our pandoc filter, pandoc prior |
56951
79c99e08deb2
Revive "Missed version number." (changeset 83ccb8e9cd3c in
ihse
parents:
56950
diff
changeset
|
141 |
# to version 2.0 cannot properly produced nested formatting in man pages |
56891
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
142 |
# (see https://github.com/jgm/pandoc/issues/3568). |
56977
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
143 |
# As a workaround, use post-processing with sed instead. |
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
144 |
# |
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
145 |
# As of pandoc 2.3, the termination of formatting is still broken |
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
146 |
# (see https://github.com/jgm/pandoc/issues/4973). We need to replace |
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
147 |
# \f[] with \f[R]. |
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
148 |
$1_POST_PROCESS := $(SED) -e 's/\\f\[C\]/\\f\[CB\]/g' \ |
9221e7c3bf36
Add a pandoc filter for man pages written in javascript, to transform man pages.
ihse
parents:
56974
diff
changeset
|
149 |
-e 's/\\f\[\]/\\f\[R\]/g' |
56893
2d3320d628a0
Revive "Add FIXMEs." (changeset e2615f537dfe from ihse-javadoc-branch in
ihse
parents:
56891
diff
changeset
|
150 |
|
56950 | 151 |
# If no file extension is specified, default to '.1'. |
152 |
ifeq ($$($1_FILE_EXT), ) |
|
153 |
$1_FILE_EXT := .1 |
|
154 |
endif |
|
56972 | 155 |
else ifeq ($$($1_FORMAT), html5) |
156 |
ifeq ($$($1_FILE_EXT), ) |
|
157 |
$1_FILE_EXT := .html |
|
158 |
endif |
|
56950 | 159 |
else ifeq ($$($1_FORMAT), html) |
160 |
ifeq ($$($1_FILE_EXT), ) |
|
161 |
$1_FILE_EXT := .html |
|
162 |
endif |
|
56891
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
163 |
endif |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
164 |
|
44983 | 165 |
# Remove any trailing slash from SRC and DEST |
166 |
$1_SRC := $$(patsubst %/,%,$$($1_SRC)) |
|
167 |
$1_DEST := $$(patsubst %/,%,$$($1_DEST)) |
|
168 |
||
169 |
$$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \ |
|
170 |
$$(eval $$(call ProcessMarkdown,$1,$$f)) \ |
|
171 |
) |
|
172 |
endef |