-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
134 lines (107 loc) · 4.13 KB
/
Makefile
File metadata and controls
134 lines (107 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
ifeq (1,$(words $(MAKEFILE_LIST))) # if not included
.DEFAULT_GOAL:=help
endif
define HELP
Makefile for documents converting using pandoc.
Source: *.text (extension defined by SOURCE_EXT).
Target(s): enumerated in commandline (otherwise can be set in .DEFAULT_GOAL)
Usage:
make some_doc.html
Convert some_doc.text to some_doc.html.
Instead of ".html" any other pandoc-supported file type can be used.
make html
Convert *.text to *.html.
Instead of ".html" any other supported extension can be used, incl. hlf (must be enumerated in TARGET_EXT).
make some_doc.hlf
make hlf
Convert to .hlf using pandoc and HtmlToFarHelp.
make some_doc.forum
make forum
Convert to phpBB-flavored markdown (Litedown).
make clean
Clean current directory from all files with extensions specified in TARGET_EXT.
make help
This help
make install
Copy *.lua to $(APPDATA)\pandoc\filters
Or to $$(DATA_DIR)\filters (if defined).
Notes:
1. pandoc.exe and HtmlToFarHelp.exe must be available.
It is also possible to define full paths in env variables PANDOC/HTMLTOFARHELP.
2. Some conversions may require additional lua filters, which must be present in current directory.
Alternatively they can reside in $(DATA_DIR)\filters
(See `make install`)
3. Some conversions may require lua writers, which must be present in current directory.
Alternatively they can reside in $(DATA_DIR)\custom
4. The best way to customize this Makefile is including it in own Makefile, adding new rules
and (re)defining corresponding variables.
endef
SOURCE_EXT:=text
SOURCE_FORMAT?=--from=markdown-auto_identifiers-raw_tex+autolink_bare_uris
TARGET_EXT+=hlfhtml htm html md plain native json forum hlf
ifneq (,$(filter $(TARGET_EXT),$(SOURCE_EXT)))
$(error TARGET_EXT cannot include SOURCE_EXT)
else ifneq (1,$(words $(SOURCE_EXT)))
$(error SOURCE_EXT must be single ext)
endif
#https://pandoc.org/installing.html
PANDOC?=pandoc.exe
TARGET_FORMAT:= # deduced from extension; defaulting to html
FLAGS+=--wrap=preserve
EXTRA+=--lua-filter=FarLinks.lua --strip-comments
#https://www.nuget.org/packages/HtmlToFarHelp
HTMLTOFARHELP?=HtmlToFarHelp.exe
SHELL:=$(ComSpec)
RM:=del
ifdef DATA_DIR
FLAGS+= --data-dir=$(DATA_DIR)
else
DATA_DIR:=$(APPDATA)\pandoc#default
endif
LUA_PATH:=$(LUA_PATH);$(DATA_DIR)\filters\?.lua;$(DATA_DIR)\filters\?\init.lua
# Far Manager help file
%.hlf: %.hlfhtml
@$(HTMLTOFARHELP) from="$<"; to="$@"
$(info $@)
# intermediate file for hlf
%.hlfhtml: TARGET_FORMAT:= --to=html --no-highlight
%.hlfhtml: FLAGS+= --lua-filter=ChmLinks.lua --lua-filter=unDetails.lua
%.hlfhtml: EXTRA:=
# full-featured html, with headers, styles, ... (otherwise use `htm`)
%.html: FLAGS+= --standalone --lua-filter=HeaderToTitle.lua
# github-flavored markdown (pandoc --list-extensions=gfm)
%.md: TARGET_FORMAT:= --to=gfm --lua-filter=DefinitionToBulletList.lua --lua-filter=mdHeadersLinks.lua
# prepare text for posting on forum.farmanager.com
%.forum: TARGET_FORMAT:=--to=markdown_strict+fenced_code_blocks-raw_html-smart --lua-filter=DefinitionToBulletList.lua
%.forum: FLAGS+= \
--lua-filter=fold.lua \
--lua-filter=forum.lua \
--lua-filter=DetailsToSpoiler.lua \
--lua-filter=addLinks.lua
%.forum: EXTRA:=--shift-heading-level-by=1
#prevent circular dependencies
%.text %.lua: ;
$(MAKEFILE_LIST): ;
.SECONDEXPANSION: #https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html#Secondary-Expansion
%: $$(basename %).$(SOURCE_EXT) $(MAKEFILE_LIST) $(wildcard *.lua)
@$(PANDOC) $(SOURCE_FORMAT) $(TARGET_FORMAT) $(FLAGS) $(EXTRA) --output=$@ $<
$(info $@)
.PHONY: $(TARGET_EXT) clean help install
# targets like html md hlf...
SOURCES:=$(wildcard *.$(SOURCE_EXT))
NAMES:=$(basename $(SOURCES))
$(TARGET_EXT): %: $(addsuffix .%,$(NAMES))
TARGETS_MASK:=$(addprefix *.,$(TARGET_EXT))
clean:
$(info $(wildcard $(TARGETS_MASK)))
@$(RM) $(TARGETS_MASK)
help:
$(info $(HELP))
@rem
install: $(DATA_DIR)/filters $(addprefix $(DATA_DIR)/filters/, $(wildcard *.lua))
$(DATA_DIR)/filters:
mkdir $(subst /,\,$@)
$(DATA_DIR)/filters/%: %
@rem copy $< $(subst /,\,$@)
@rem cmd /c mklink $(subst /,\, $@ $(realpath $<))
@ln -s $(subst /,\, $(realpath $<) $@) || true