author | herrick |
Thu, 28 Mar 2019 13:49:38 -0400 | |
branch | JDK-8200758-branch |
changeset 57292 | 7a683c461b80 |
parent 54076 | 4b4745d185eb |
child 55469 | e00591da418d |
permissions | -rw-r--r-- |
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
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 |
||
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
29 |
include TextFileProcessing.gmk |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
30 |
|
44983 | 31 |
# Helper function for SetupProcessMarkdown |
32 |
# $1: The $1 from SetupProcessMarkdown |
|
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
33 |
# $2: The name of the current source file, relative to the dir given in $3 |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
34 |
# $3: The directory of the current source file |
44983 | 35 |
define ProcessMarkdown |
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
36 |
$1_$2_OUTPUT_FILE := $$($1_DEST)/$$(basename $2)$$($1_FILE_EXT) |
44983 | 37 |
$1_$2_TARGET_DIR := $$(dir $$($1_$2_OUTPUT_FILE)) |
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
38 |
$1_$2_INPUT_FILE := $3/$2 |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
39 |
$1_$2_MARKER := $$(subst /,_,$1_$2) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
40 |
|
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
41 |
ifneq ($$($1_REPLACEMENTS), ) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
42 |
$1_$2_PANDOC_INPUT := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_pre.tmp |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
43 |
|
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
44 |
$$(eval $$(call SetupTextFileProcessing, $1_$2_PREPROCESSED, \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
45 |
SOURCE_FILES := $$($1_$2_INPUT_FILE), \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
46 |
OUTPUT_FILE := $$($1_$2_PANDOC_INPUT), \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
47 |
REPLACEMENTS := $$($1_REPLACEMENTS), \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
48 |
)) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
49 |
else |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
50 |
$1_$2_PANDOC_INPUT := $$($1_$2_INPUT_FILE) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
51 |
endif |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
52 |
|
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
53 |
ifneq ($$($1_POST_PROCESS), ) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
54 |
$1_$2_PANDOC_OUTPUT := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_post.tmp |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
55 |
else |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
56 |
$1_$2_PANDOC_OUTPUT := $$($1_$2_OUTPUT_FILE) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
57 |
endif |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
58 |
|
44983 | 59 |
ifneq ($$($1_CSS), ) |
60 |
ifneq ($$(findstring http:/, $$($1_CSS)), ) |
|
61 |
$1_$2_CSS_OPTION := --css '$$($1_CSS)' |
|
62 |
else |
|
45227 | 63 |
$1_$2_CSS := $$(strip $$(call RelativePath, $$($1_CSS), $$($1_$2_TARGET_DIR))) |
44983 | 64 |
$1_$2_CSS_OPTION := --css '$$($1_$2_CSS)' |
65 |
endif |
|
66 |
endif |
|
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
67 |
|
54076
4b4745d185eb
8220383: Incremental build is broken and inefficient
erikj
parents:
53830
diff
changeset
|
68 |
# This does not need to be included in VARDEPS since it's from the actual |
4b4745d185eb
8220383: Incremental build is broken and inefficient
erikj
parents:
53830
diff
changeset
|
69 |
# source file. Only run the shell if the recipe gets executed below. |
4b4745d185eb
8220383: Incremental build is broken and inefficient
erikj
parents:
53830
diff
changeset
|
70 |
$1_$2_OPTIONS_FROM_SRC = \ |
4b4745d185eb
8220383: Incremental build is broken and inefficient
erikj
parents:
53830
diff
changeset
|
71 |
$$(shell $$(GREP) _pandoc-options_: $3/$2 | $$(CUT) -d : -f 2-) |
44983 | 72 |
|
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
73 |
ifneq ($$($1_FILTER), ) |
54076
4b4745d185eb
8220383: Incremental build is broken and inefficient
erikj
parents:
53830
diff
changeset
|
74 |
$1_$2_OPTIONS := --filter $$($1_FILTER) |
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
75 |
endif |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
76 |
|
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
77 |
$1_$2_VARDEPS := $$($1_OPTIONS) $$($1_$2_OPTIONS) $$($1_CSS) \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
78 |
$$($1_REPLACEMENTS) $$($1_POST_PROCESS) |
44983 | 79 |
$1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \ |
80 |
$$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER).vardeps) |
|
81 |
||
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
82 |
$$($1_$2_PANDOC_OUTPUT): $$($1_$2_PANDOC_INPUT) $$($1_$2_VARDEPS_FILE) $$($1_EXTRA_DEPS) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
83 |
$$(call LogInfo, Converting $2 to $$($1_FORMAT)) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
84 |
$$(call MakeDir, $$(SUPPORT_OUTPUTDIR)/markdown $$(dir $$($1_$2_PANDOC_OUTPUT))) |
44983 | 85 |
$$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER), \ |
53830 | 86 |
$$(PANDOC) $$($1_OPTIONS) -f $$(PANDOC_MARKDOWN_FLAG) \ |
87 |
-t $$($1_FORMAT) --standalone \ |
|
54076
4b4745d185eb
8220383: Incremental build is broken and inefficient
erikj
parents:
53830
diff
changeset
|
88 |
$$($1_$2_CSS_OPTION) $$($1_$2_OPTIONS_FROM_SRC) $$($1_$2_OPTIONS) \ |
4b4745d185eb
8220383: Incremental build is broken and inefficient
erikj
parents:
53830
diff
changeset
|
89 |
'$$($1_$2_PANDOC_INPUT)' -o '$$($1_$2_PANDOC_OUTPUT)') |
44983 | 90 |
ifneq ($$(findstring $$(LOG_LEVEL), debug trace),) |
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
91 |
TOO_LONG_LINES=`$$(GREP) -E -e '^.{80}.+$$$$' $$<` || true ; \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
92 |
if [ "x$$$$TOO_LONG_LINES" != x ]; then \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
93 |
$$(ECHO) "Warning: Unsuitable markdown in $$<:" ; \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
94 |
$$(ECHO) "The following lines are longer than 80 characters:" ; \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
95 |
$$(GREP) -E -n -e '^.{80}.+$$$$' $$< || true ; \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
96 |
fi |
44983 | 97 |
endif |
98 |
||
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
99 |
# If we have no post processing, PANDOC_OUTPUT is set to OUTPUT_FILE. Otherwise |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
100 |
# PANDOC_OUTPUT is a temporary file, and we must now create the real OUTPUT_FILE. |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
101 |
ifneq ($$($1_POST_PROCESS), ) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
102 |
$$($1_$2_OUTPUT_FILE): $$($1_$2_PANDOC_OUTPUT) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
103 |
$$(call LogInfo, Post-processing markdown file $2) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
104 |
$$(call MakeDir, $$(SUPPORT_OUTPUTDIR)/markdown $$($1_$2_TARGET_DIR)) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
105 |
$$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_post, \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
106 |
$$($1_POST_PROCESS) < $$($1_$2_PANDOC_OUTPUT) > $$($1_$2_OUTPUT_FILE)) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
107 |
endif |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
108 |
|
44983 | 109 |
$1 += $$($1_$2_OUTPUT_FILE) |
110 |
endef |
|
111 |
||
112 |
################################################################################ |
|
113 |
# Setup make rules for converting a markdown file to html. |
|
114 |
# |
|
115 |
# Parameter 1 is the name of the rule. This name is used as variable prefix, |
|
116 |
# and the targets generated are listed in a variable by that name. |
|
117 |
# |
|
118 |
# Remaining parameters are named arguments. These include: |
|
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
119 |
# DEST : Destination root dir |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
120 |
# FILES : List of files to copy with absolute paths, or path relative to SRC. |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
121 |
# SRC : Source root dir; if given keep input files hierarchy relative to |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
122 |
# SRC in DEST, otherwise flatten structure into DEST. |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
123 |
# FORMAT : The target format (defaults to html5) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
124 |
# FILE_EXT : The file extension to replace .md with (defaults to .html) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
125 |
# OPTIONS : Additional options to pandoc |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
126 |
# EXTRA_DEPS : Additional dependencies to add to each pandoc call |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
127 |
# FILTER : Optional pandoc filter command |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
128 |
# POST_PROCESS : Optional command-line to post-process generated markdown |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
129 |
# REPLACEMENTS : Text replacements to perform on input file before processing |
44983 | 130 |
# |
131 |
SetupProcessMarkdown = $(NamedParamsMacroTemplate) |
|
132 |
define SetupProcessMarkdownBody |
|
133 |
ifeq ($$($1_FILES), ) |
|
134 |
$$(error FILES is missing in SetupProcessMarkdown $1) |
|
135 |
endif |
|
136 |
||
137 |
ifeq ($$($1_DEST), ) |
|
138 |
$$(error DEST is missing in SetupProcessMarkdown $1) |
|
139 |
endif |
|
140 |
||
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
141 |
# If no target format is specified, default to html5. |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
142 |
ifeq ($$($1_FORMAT), ) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
143 |
$1_FORMAT := html5 |
44983 | 144 |
endif |
145 |
||
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
146 |
ifeq ($$($1_FORMAT), man) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
147 |
# If no file extension is specified, default to '.1'. |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
148 |
ifeq ($$($1_FILE_EXT), ) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
149 |
$1_FILE_EXT := .1 |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
150 |
endif |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
151 |
else ifeq ($$($1_FORMAT), html5) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
152 |
ifeq ($$($1_FILE_EXT), ) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
153 |
$1_FILE_EXT := .html |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
154 |
endif |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
155 |
else ifeq ($$($1_FORMAT), html) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
156 |
ifeq ($$($1_FILE_EXT), ) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
157 |
$1_FILE_EXT := .html |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
158 |
endif |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
159 |
endif |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
160 |
|
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
161 |
# Remove any trailing slash |
44983 | 162 |
$1_DEST := $$(patsubst %/,%,$$($1_DEST)) |
163 |
||
52714
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
164 |
ifeq ($$($1_SRC), ) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
165 |
# No SRC given, assume we're flattening all files into output dir. |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
166 |
$$(foreach f, $$($1_FILES), \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
167 |
$$(eval $$(call ProcessMarkdown,$1,$$(notdir $$f),$$(patsubst %/,%,$$(dir $$f)))) \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
168 |
) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
169 |
else |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
170 |
# Remove any trailing slash |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
171 |
$1_SRC := $$(patsubst %/,%,$$($1_SRC)) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
172 |
|
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
173 |
$$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
174 |
$$(eval $$(call ProcessMarkdown,$1,$$f,$$($1_SRC))) \ |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
175 |
) |
2e52aa822c57
8178317: Create man pages using pandoc from markdown sources
ihse
parents:
45227
diff
changeset
|
176 |
endif |
44983 | 177 |
endef |