author | ihse |
Tue, 18 Sep 2018 14:28:49 +0200 | |
branch | ihse-manpages-branch |
changeset 56951 | 79c99e08deb2 |
parent 56950 | 55725429863a |
child 56972 | e134eea44a09 |
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)) |
56891
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
35 |
|
44983 | 36 |
ifneq ($$($1_CSS), ) |
37 |
ifneq ($$(findstring http:/, $$($1_CSS)), ) |
|
38 |
$1_$2_CSS_OPTION := --css '$$($1_CSS)' |
|
39 |
else |
|
45227 | 40 |
$1_$2_CSS := $$(strip $$(call RelativePath, $$($1_CSS), $$($1_$2_TARGET_DIR))) |
44983 | 41 |
$1_$2_CSS_OPTION := --css '$$($1_$2_CSS)' |
42 |
endif |
|
43 |
endif |
|
44 |
$1_$2_OPTIONS = $$(shell $$(GREP) _pandoc-options_: $$($1_SRC)/$2 | $$(CUT) -d : -f 2-) |
|
45 |
$1_$2_MARKER := $$(subst /,_,$1_$2) |
|
46 |
||
47 |
$1_$2_VARDEPS := $$($1_OPTIONS) $$($1_CSS) |
|
48 |
$1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \ |
|
49 |
$$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER).vardeps) |
|
50 |
||
51 |
$$($1_$2_OUTPUT_FILE): $$($1_SRC)/$2 $$($1_$2_VARDEPS_FILE) |
|
56950 | 52 |
$$(call LogInfo, Converting $2 to $$($1_TO_TYPE)) |
44983 | 53 |
$$(call MakeDir, $$($1_$2_TARGET_DIR) $$(SUPPORT_OUTPUTDIR)/markdown) |
54 |
$$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER), \ |
|
56950 | 55 |
$$(PANDOC) $$($1_OPTIONS) -f markdown -t $$($1_TO_TYPE) --standalone \ |
44983 | 56 |
$$($1_$2_CSS_OPTION) $$($1_$2_OPTIONS) '$$<' -o '$$@') |
57 |
ifneq ($$(findstring $$(LOG_LEVEL), debug trace),) |
|
58 |
TOO_LONG_LINES=`$$(GREP) -E -e '^.{80}.+$$$$' $$<` || true ; \ |
|
59 |
if [ "x$$$$TOO_LONG_LINES" != x ]; then \ |
|
60 |
$$(ECHO) "Warning: Unsuitable markdown in $$<:" ; \ |
|
61 |
$$(ECHO) "The following lines are longer than 80 characters:" ; \ |
|
62 |
$$(GREP) -E -n -e '^.{80}.+$$$$' $$< || true ; \ |
|
63 |
fi |
|
64 |
endif |
|
65 |
||
66 |
$1 += $$($1_$2_OUTPUT_FILE) |
|
67 |
endef |
|
68 |
||
69 |
################################################################################ |
|
70 |
# Setup make rules for converting a markdown file to html. |
|
71 |
# |
|
72 |
# Parameter 1 is the name of the rule. This name is used as variable prefix, |
|
73 |
# and the targets generated are listed in a variable by that name. |
|
74 |
# |
|
75 |
# Remaining parameters are named arguments. These include: |
|
56891
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
76 |
# 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
|
77 |
# DEST : Dest root dir |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
78 |
# 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
|
79 |
# Must be in SRC. |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
80 |
# FORMAT : The target format (defaults to html) |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
81 |
# 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
|
82 |
# OPTIONS : Additional options to pandoc |
44983 | 83 |
# |
84 |
SetupProcessMarkdown = $(NamedParamsMacroTemplate) |
|
85 |
define SetupProcessMarkdownBody |
|
86 |
ifeq ($$($1_FILES), ) |
|
87 |
$$(error FILES is missing in SetupProcessMarkdown $1) |
|
88 |
endif |
|
89 |
||
90 |
ifeq ($$($1_DEST), ) |
|
91 |
$$(error DEST is missing in SetupProcessMarkdown $1) |
|
92 |
endif |
|
93 |
||
94 |
# Default SRC to the dir of the first file. |
|
95 |
ifeq ($$($1_SRC), ) |
|
96 |
$1_SRC := $$(dir $$(firstword $$($1_FILES))) |
|
97 |
endif |
|
98 |
||
56891
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
99 |
# If no target format is specified, default to html. |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
100 |
ifeq ($$($1_FORMAT), ) |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
101 |
$1_FORMAT := html |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
102 |
endif |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
103 |
|
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
104 |
ifeq ($$($1_FORMAT), man) |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
105 |
# 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
|
106 |
# show up in normal man page rendering (but shows correctly when generating |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
107 |
# html). Normally, we could fix this by a pandoc filter, but pandoc prior |
56951
79c99e08deb2
Revive "Missed version number." (changeset 83ccb8e9cd3c in
ihse
parents:
56950
diff
changeset
|
108 |
# 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
|
109 |
# (see https://github.com/jgm/pandoc/issues/3568). |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
110 |
# As a workaround, use post-processing with sed. |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
111 |
$1_POST_PROCESS := $(SED) -e 's/\\f\[C\]/\\f\[CB\]/g' |
56893
2d3320d628a0
Revive "Add FIXMEs." (changeset e2615f537dfe from ihse-javadoc-branch in
ihse
parents:
56891
diff
changeset
|
112 |
|
2d3320d628a0
Revive "Add FIXMEs." (changeset e2615f537dfe from ihse-javadoc-branch in
ihse
parents:
56891
diff
changeset
|
113 |
# FIXME: We also need a pandoc filter that removes link targets for internal |
2d3320d628a0
Revive "Add FIXMEs." (changeset e2615f537dfe from ihse-javadoc-branch in
ihse
parents:
56891
diff
changeset
|
114 |
# links (#options)... |
2d3320d628a0
Revive "Add FIXMEs." (changeset e2615f537dfe from ihse-javadoc-branch in
ihse
parents:
56891
diff
changeset
|
115 |
# FIXME: Perhaps it should also make h1 headings ALL CAPS. |
56950 | 116 |
$1_TO_TYPE := man |
117 |
# If no file extension is specified, default to '.1'. |
|
118 |
ifeq ($$($1_FILE_EXT), ) |
|
119 |
$1_FILE_EXT := .1 |
|
120 |
endif |
|
121 |
else ifeq ($$($1_FORMAT), html) |
|
122 |
# If no file extension is specified, default to '.html'. |
|
123 |
$1_TO_TYPE := html5 |
|
124 |
ifeq ($$($1_FILE_EXT), ) |
|
125 |
$1_FILE_EXT := .html |
|
126 |
endif |
|
56891
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
127 |
endif |
78ed9c424877
Revive "Support for generating man pages from markdown." (changeset f00e76e7d53f
ihse
parents:
45227
diff
changeset
|
128 |
|
44983 | 129 |
# Remove any trailing slash from SRC and DEST |
130 |
$1_SRC := $$(patsubst %/,%,$$($1_SRC)) |
|
131 |
$1_DEST := $$(patsubst %/,%,$$($1_DEST)) |
|
132 |
||
133 |
$$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \ |
|
134 |
$$(eval $$(call ProcessMarkdown,$1,$$f)) \ |
|
135 |
) |
|
136 |
endef |