22FILTER_FILE := $(wildcard * .lua)
33# Name of the filter, *without* `.lua` file extension
44FILTER_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 )
515
616# Allow to use a different pandoc binary, e.g. when testing.
717PANDOC ?= pandoc
4252 ' /^## / h ; /^[^_.$$#][^ ]+:/ { G; s/^(.*):.*##(.*)/\1@\2/; P ; h ; }' \
4353 $(MAKEFILE_LIST ) | tr @ ' \t'
4454
55+ #
56+ # Build
57+ #
58+
59+ # # Build the filter file from sources (requires luacc)
60+ # If SOURCE_MAIN is not empty, combine source files with
61+ # luacc and replace the filter file.
62+ # ifeq is safer than ifdef (easier for the user to make
63+ # the variable empty than to make it undefined).
64+ .PHONY : build
65+ build : _build
66+
67+ ifneq ($(SOURCE_MAIN ) , )
68+ .PHONY : _build
69+ _build : _check_luacc $(SOURCE_FILES )
70+ @if [ -f $( QUARTO_EXT_DIR) /$( FILTER_FILE) ]; then \
71+ luacc -o $(QUARTO_EXT_DIR ) /$(FILTER_FILE ) -i $(SOURCE_DIR ) \
72+ $(SOURCE_DIR ) /$(SOURCE_MAIN ) $(SOURCE_MODULES ) ; \
73+ if [ ! -L $( FILTER_FILE) ]; then \
74+ ln -s $(QUARTO_EXT_DIR ) /$(FILTER_FILE ) $(FILTER_FILE ) ; \
75+ fi \
76+ else \
77+ luacc -o $(FILTER_FILE ) -i $(SOURCE_DIR ) \
78+ $(SOURCE_DIR ) /$(SOURCE_MAIN ) $(SOURCE_MODULES ) ; \
79+ fi
80+ else
81+ .PHONY : _build
82+ _build :
83+
84+ endif
85+
86+ .PHONY : check_luacc
87+ _check_luacc :
88+ @if ! command -v luacc & > /dev/null ; then \
89+ echo " LuaCC is needed to build the filter. Available on LuaRocks:" ; \
90+ echo " https://luarocks.org/modules/mihacooper/luacc" ; \
91+ exit ; \
92+ fi
93+
4594#
4695# Test
4796#
@@ -62,7 +111,7 @@ test: $(FILTER_FILE) test/input.md test/test.yaml
62111# would cause it to be regenerated on each run, making the test
63112# pointless.
64113.PHONY : generate
65- generate : $(FILTER_FILE ) test/input.md test/test.yaml
114+ generate : build $(FILTER_FILE ) test/input.md test/test.yaml
66115 @for ext in $(FORMAT ) ; do \
67116 $(PANDOC ) --defaults test/test.yaml --to $$ ext \
68117 --output test/expected.$$ ext ; \
@@ -142,7 +191,7 @@ $(QUARTO_EXT_DIR)/$(FILTER_FILE): $(FILTER_FILE) $(QUARTO_EXT_DIR)
142191
143192# # Sets a new release (uses VERSION macro if defined)
144193.PHONY : release
145- release : quarto-extension regenerate
194+ release : build quarto-extension generate
146195 git commit -am " Release $( FILTER_NAME) $( VERSION) "
147196 git tag v$(VERSION ) -m " $( FILTER_NAME) $( VERSION) "
148197 @echo ' Do not forget to push the tag back to github with `git push --tags`'
0 commit comments