|
2 | 2 | FILTER_FILE := $(wildcard *.lua) |
3 | 3 | # Name of the filter, *without* `.lua` file extension |
4 | 4 | FILTER_NAME = $(patsubst %.lua,%,$(FILTER_FILE)) |
| 5 | +# Source files |
| 6 | +# Optional: build the filter file from multiple sources. |
| 7 | +# *Do not comment out!* To deactivate it's safer to |
| 8 | +# define an empty SOURCE_MAIN variable with: |
| 9 | +# SOURCE_MAIN = |
| 10 | +SOURCE_DIR = |
| 11 | +SOURCE_MAIN = |
| 12 | +SOURCE_MODULES = |
| 13 | +# |
| 14 | +SOURCE_FILES = $(SOURCE_MAIN:%=$(SOURCE_DIR)%.lua) $(SOURCE_MODULES:%=$(SOURCE_DIR)%.lua) |
5 | 15 |
|
6 | 16 | # Allow to use a different pandoc binary, e.g. when testing. |
7 | 17 | PANDOC ?= pandoc |
@@ -37,26 +47,70 @@ help: |
37 | 47 | '/^## / h ; /^[^_.$$#][^ ]+:/ { G; s/^(.*):.*##(.*)/\1@\2/; P ; h }' \ |
38 | 48 | $(MAKEFILE_LIST) | tr @ '\t' |
39 | 49 |
|
| 50 | +# |
| 51 | +# Build |
| 52 | +# |
| 53 | + |
| 54 | +## Build the filter file from sources (requires luacc) |
| 55 | +# If SOURCE_MAIN is not empty, combine source files with |
| 56 | +# luacc and replace the filter file. |
| 57 | +# ifeq is safer than ifdef (easier for the user to make |
| 58 | +# the variable empty than to make it undefined). |
| 59 | +.PHONY: build |
| 60 | +build: _build |
| 61 | + |
| 62 | +ifneq ($(SOURCE_MAIN), ) |
| 63 | +.PHONY: _build |
| 64 | +_build: _check_luacc $(SOURCE_FILES) |
| 65 | + @if [ -f $(QUARTO_EXT_DIR)/$(FILTER_FILE) ]; then \ |
| 66 | + luacc -o $(QUARTO_EXT_DIR)/$(FILTER_FILE) -i $(SOURCE_DIR) \ |
| 67 | + $(SOURCE_DIR)/$(SOURCE_MAIN) $(SOURCE_MODULES); \ |
| 68 | + if [ ! -L $(FILTER_FILE) ]; then \ |
| 69 | + ln -s $(QUARTO_EXT_DIR)/$(FILTER_FILE) $(FILTER_FILE); \ |
| 70 | + fi \ |
| 71 | + else \ |
| 72 | + luacc -o $(FILTER_FILE) -i $(SOURCE_DIR) \ |
| 73 | + $(SOURCE_DIR)/$(SOURCE_MAIN) $(SOURCE_MODULES); \ |
| 74 | + fi |
| 75 | +else |
| 76 | +.PHONY: _build |
| 77 | +_build: |
| 78 | + |
| 79 | +endif |
| 80 | + |
| 81 | +.PHONY: check_luacc |
| 82 | +_check_luacc: |
| 83 | + @if ! command -v luacc &> /dev/null ; then \ |
| 84 | + echo "LuaCC is needed to build the filter. Available on LuaRocks:"; \ |
| 85 | + echo " https://luarocks.org/modules/mihacooper/luacc"; \ |
| 86 | + exit; \ |
| 87 | + fi |
| 88 | + |
40 | 89 | # |
41 | 90 | # Test |
42 | 91 | # |
43 | 92 |
|
44 | | -## Test that running the filter on the sample input yields expected output |
| 93 | +## Test that running the filter on the sample input yields expected outputs |
45 | 94 | # The automatic variable `$<` refers to the first dependency |
46 | 95 | # (i.e., the filter file). |
47 | 96 | # let `test` be a PHONY target so that it is run each time it's called. |
48 | 97 | .PHONY: test |
49 | 98 | test: $(FILTER_FILE) test/input.md test/test.yaml |
50 | | - $(PANDOC) --defaults test/test.yaml | \ |
51 | | - $(DIFF) test/expected.native - |
52 | | - |
| 99 | + @for ext in $(FORMAT) ; do \ |
| 100 | + $(PANDOC) --defaults test/test.yaml --to $$ext | \ |
| 101 | + $(DIFF) test/expected.$$ext - ; \ |
| 102 | + done |
53 | 103 |
|
54 | | -## Re-generate the expected output |
55 | | -# This file **must not** be a dependency of the `test` target, as that |
| 104 | +## Generate the expected output |
| 105 | +# This target **must not** be a dependency of the `test` target, as that |
56 | 106 | # would cause it to be regenerated on each run, making the test |
57 | 107 | # pointless. |
58 | | -test/expected.native: $(FILTER_FILE) test/input.md test/test.yaml |
59 | | - $(PANDOC) --defaults test/test.yaml --output=$@ |
| 108 | +.PHONY: generate |
| 109 | +generate: build $(FILTER_FILE) test/input.md test/test.yaml |
| 110 | + @for ext in $(FORMAT) ; do \ |
| 111 | + $(PANDOC) --defaults test/test.yaml --to $$ext \ |
| 112 | + --output test/expected.$$ext ; \ |
| 113 | + done |
60 | 114 |
|
61 | 115 | # |
62 | 116 | # Website |
@@ -132,7 +186,7 @@ $(QUARTO_EXT_DIR)/$(FILTER_FILE): $(FILTER_FILE) $(QUARTO_EXT_DIR) |
132 | 186 |
|
133 | 187 | ## Sets a new release (uses VERSION macro if defined) |
134 | 188 | .PHONY: release |
135 | | -release: quarto-extension |
| 189 | +release: build quarto-extension generate |
136 | 190 | git commit -am "Release $(FILTER_NAME) $(VERSION)" |
137 | 191 | git tag v$(VERSION) -m "$(FILTER_NAME) $(VERSION)" |
138 | 192 | @echo 'Do not forget to push the tag back to github with `git push --tags`' |
|
0 commit comments