39 else |
39 else |
40 $1_$2_CSS := $$(strip $$(call RelativePath, $$($1_CSS), $$($1_$2_TARGET_DIR))) |
40 $1_$2_CSS := $$(strip $$(call RelativePath, $$($1_CSS), $$($1_$2_TARGET_DIR))) |
41 $1_$2_CSS_OPTION := --css '$$($1_$2_CSS)' |
41 $1_$2_CSS_OPTION := --css '$$($1_$2_CSS)' |
42 endif |
42 endif |
43 endif |
43 endif |
44 $1_$2_OPTIONS = $$(shell $$(GREP) _pandoc-options_: $$($1_SRC)/$2 | $$(CUT) -d : -f 2-) |
44 $1_$2_OPTIONS := $$(shell $$(GREP) _pandoc-options_: $$($1_SRC)/$2 | $$(CUT) -d : -f 2-) |
45 $1_$2_MARKER := $$(subst /,_,$1_$2) |
45 $1_$2_MARKER := $$(subst /,_,$1_$2) |
46 |
46 |
47 $1_$2_VARDEPS := $$($1_OPTIONS) $$($1_CSS) |
47 ifneq ($$($1_POST_PROCESS), ) |
|
48 $1_$2_REAL_OUTPUT_FILE := $$($1_$2_OUTPUT_FILE) |
|
49 $1_$2_OUTPUT_FILE := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER).tmp |
|
50 endif |
|
51 |
|
52 $1_$2_VARDEPS := $$($1_OPTIONS) $$($1_$2_OPTIONS) $$($1_CSS) |
48 $1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \ |
53 $1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \ |
49 $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER).vardeps) |
54 $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER).vardeps) |
50 |
55 |
51 $$($1_$2_OUTPUT_FILE): $$($1_SRC)/$2 $$($1_$2_VARDEPS_FILE) |
56 $$($1_$2_OUTPUT_FILE): $$($1_SRC)/$2 $$($1_$2_VARDEPS_FILE) |
52 $$(call LogInfo, Converting $2 to $$($1_TO_TYPE)) |
57 $$(call LogInfo, Converting $2 to $$($1_FORMAT)) |
53 $$(call MakeDir, $$($1_$2_TARGET_DIR) $$(SUPPORT_OUTPUTDIR)/markdown) |
58 $$(call MakeDir, $$($1_$2_TARGET_DIR) $$(SUPPORT_OUTPUTDIR)/markdown) |
54 $$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER), \ |
59 $$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER), \ |
55 $$(PANDOC) $$($1_OPTIONS) -f markdown -t $$($1_TO_TYPE) --standalone \ |
60 $$(PANDOC) $$($1_OPTIONS) -f markdown -t $$($1_FORMAT) --standalone \ |
56 $$($1_$2_CSS_OPTION) $$($1_$2_OPTIONS) '$$<' -o '$$@') |
61 $$($1_$2_CSS_OPTION) $$($1_$2_OPTIONS) '$$<' -o '$$@') |
|
62 ifneq ($$($1_POST_PROCESS), ) |
|
63 $$($1_POST_PROCESS) < $$($1_$2_OUTPUT_FILE) > $$($1_$2_REAL_OUTPUT_FILE) |
|
64 endif |
57 ifneq ($$(findstring $$(LOG_LEVEL), debug trace),) |
65 ifneq ($$(findstring $$(LOG_LEVEL), debug trace),) |
58 TOO_LONG_LINES=`$$(GREP) -E -e '^.{80}.+$$$$' $$<` || true ; \ |
66 TOO_LONG_LINES=`$$(GREP) -E -e '^.{80}.+$$$$' $$<` || true ; \ |
59 if [ "x$$$$TOO_LONG_LINES" != x ]; then \ |
67 if [ "x$$$$TOO_LONG_LINES" != x ]; then \ |
60 $$(ECHO) "Warning: Unsuitable markdown in $$<:" ; \ |
68 $$(ECHO) "Warning: Unsuitable markdown in $$<:" ; \ |
61 $$(ECHO) "The following lines are longer than 80 characters:" ; \ |
69 $$(ECHO) "The following lines are longer than 80 characters:" ; \ |
62 $$(GREP) -E -n -e '^.{80}.+$$$$' $$< || true ; \ |
70 $$(GREP) -E -n -e '^.{80}.+$$$$' $$< || true ; \ |
63 fi |
71 fi |
64 endif |
72 endif |
65 |
73 |
66 $1 += $$($1_$2_OUTPUT_FILE) |
74 $1 += $$($1_$2_OUTPUT_FILE) |
67 endef |
75 endef |
68 |
76 |
75 # Remaining parameters are named arguments. These include: |
83 # Remaining parameters are named arguments. These include: |
76 # SRC : Source root dir (defaults to dir of first file) |
84 # SRC : Source root dir (defaults to dir of first file) |
77 # DEST : Dest root dir |
85 # DEST : Dest root dir |
78 # FILES : List of files to copy with absolute paths, or path relative to SRC. |
86 # FILES : List of files to copy with absolute paths, or path relative to SRC. |
79 # Must be in SRC. |
87 # Must be in SRC. |
80 # FORMAT : The target format (defaults to html) |
88 # FORMAT : The target format (defaults to html5) |
81 # FILE_EXT : The file extension to replace .md with (defaults to .html) |
89 # FILE_EXT : The file extension to replace .md with (defaults to .html) |
82 # OPTIONS : Additional options to pandoc |
90 # OPTIONS : Additional options to pandoc |
83 # |
91 # |
84 SetupProcessMarkdown = $(NamedParamsMacroTemplate) |
92 SetupProcessMarkdown = $(NamedParamsMacroTemplate) |
85 define SetupProcessMarkdownBody |
93 define SetupProcessMarkdownBody |
94 # Default SRC to the dir of the first file. |
102 # Default SRC to the dir of the first file. |
95 ifeq ($$($1_SRC), ) |
103 ifeq ($$($1_SRC), ) |
96 $1_SRC := $$(dir $$(firstword $$($1_FILES))) |
104 $1_SRC := $$(dir $$(firstword $$($1_FILES))) |
97 endif |
105 endif |
98 |
106 |
99 # If no target format is specified, default to html. |
107 # If no target format is specified, default to html5. |
100 ifeq ($$($1_FORMAT), ) |
108 ifeq ($$($1_FORMAT), ) |
101 $1_FORMAT := html |
109 $1_FORMAT := html5 |
102 endif |
110 endif |
103 |
111 |
104 ifeq ($$($1_FORMAT), man) |
112 ifeq ($$($1_FORMAT), man) |
|
113 $1_PRE_PROCESS := $(SED) -e 's/@@VERSION_SHORT@@/$(VERSION_SHORT)/g' |
|
114 |
105 # Pandoc's default behavior is to convert `code` to \f[C], which do not |
115 # Pandoc's default behavior is to convert `code` to \f[C], which do not |
106 # show up in normal man page rendering (but shows correctly when generating |
116 # show up in normal man page rendering (but shows correctly when generating |
107 # html). Normally, we could fix this by a pandoc filter, but pandoc prior |
117 # html). Normally, we could fix this by a pandoc filter, but pandoc prior |
108 # to version 2.0 cannot properly produced nested formatting in man pages |
118 # to version 2.0 cannot properly produced nested formatting in man pages |
109 # (see https://github.com/jgm/pandoc/issues/3568). |
119 # (see https://github.com/jgm/pandoc/issues/3568). |
111 $1_POST_PROCESS := $(SED) -e 's/\\f\[C\]/\\f\[CB\]/g' |
121 $1_POST_PROCESS := $(SED) -e 's/\\f\[C\]/\\f\[CB\]/g' |
112 |
122 |
113 # FIXME: We also need a pandoc filter that removes link targets for internal |
123 # FIXME: We also need a pandoc filter that removes link targets for internal |
114 # links (#options)... |
124 # links (#options)... |
115 # FIXME: Perhaps it should also make h1 headings ALL CAPS. |
125 # FIXME: Perhaps it should also make h1 headings ALL CAPS. |
116 $1_TO_TYPE := man |
|
117 # If no file extension is specified, default to '.1'. |
126 # If no file extension is specified, default to '.1'. |
118 ifeq ($$($1_FILE_EXT), ) |
127 ifeq ($$($1_FILE_EXT), ) |
119 $1_FILE_EXT := .1 |
128 $1_FILE_EXT := .1 |
120 endif |
129 endif |
|
130 else ifeq ($$($1_FORMAT), html5) |
|
131 ifeq ($$($1_FILE_EXT), ) |
|
132 $1_FILE_EXT := .html |
|
133 endif |
121 else ifeq ($$($1_FORMAT), html) |
134 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), ) |
135 ifeq ($$($1_FILE_EXT), ) |
125 $1_FILE_EXT := .html |
136 $1_FILE_EXT := .html |
126 endif |
137 endif |
127 endif |
138 endif |
128 |
139 |