123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- FENNEL ?= fennel
- FNL_ARGS := --add-macro-path './fnl/?.fnl' --add-fennel-path './fnl/?.fnl;fnl/?/init.fnl'
- uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
- reverse = $(if $(wordlist 2,2,$(1)), \
- $(call reverse,$(wordlist 2,$(words $(1)),$(1))) \
- $(firstword $(1)),$(1))
- rwildcard = $(foreach d,$(wildcard $1/*),$(call rwildcard,$d,$2) \
- $(filter $(subst *,%,$2),$d))
- FNL_SRC := $(foreach p, \
- $(filter-out %macros.fnl,$(call rwildcard,./fnl,*.fnl)), \
- $(if $(findstring /plug/,${p}),,$p))
- LUA_DST := $(subst ./fnl/,./lua/,${FNL_SRC:.fnl=.lua})
- LUA_DIRS := $(sort $(call uniq,$(foreach _,${LUA_DST},$(call dir,$_))))
- .PHONY: all
- all: lua
- .PHONY: fnl
- fnl: fnl.init
- .PHONY: lua
- lua: lua.init
- ${LUA_DST}: lua/%.lua: fnl/%.fnl ${LUA_DIRS}
- @ compiled="$$($(FENNEL) ${FNL_ARGS} -c $<)" \
- && printf '%s\n' "$${compiled}" > $@ \
- && printf '%s -> %s\n' '$<' '$@'
- ${LUA_DIRS}:
- @mkdir -v -- $@
- .PHONY: lua.init
- lua.init: init rm.init ${LUA_DST}
- sed '/fnl/d' < $< > init.lua
- .PHONY: fnl.init
- fnl.init: init.fnl.lua clean_lua rm.init
- ln -s $< init.lua
- init.fnl.lua: init.fnl
- fennel --add-macro-path './fnl/?.fnl' -c $< > $@
- .PHONY: rm.init
- rm.init:
- rm -f -- init.lua
- .PHONY: clean_lua
- clean_lua:
- @rm -vf -- ${LUA_DST}
- @rm -vfd -- $(call reverse,${LUA_DIRS})
- .PHONY: clean
- clean: clean_lua rm.init
- rm -f -- init.fnl.lua
|