Makefile 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. FENNEL ?= fennel
  2. FNL_ARGS := --add-macro-path './fnl/?.fnl' --add-fennel-path './fnl/?.fnl;fnl/?/init.fnl'
  3. uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
  4. reverse = $(if $(wordlist 2,2,$(1)), \
  5. $(call reverse,$(wordlist 2,$(words $(1)),$(1))) \
  6. $(firstword $(1)),$(1))
  7. rwildcard = $(foreach d,$(wildcard $1/*),$(call rwildcard,$d,$2) \
  8. $(filter $(subst *,%,$2),$d))
  9. FNL_SRC := $(foreach p, \
  10. $(filter-out %macros.fnl,$(call rwildcard,./fnl,*.fnl)), \
  11. $(if $(findstring /plug/,${p}),,$p))
  12. LUA_DST := $(subst ./fnl/,./lua/,${FNL_SRC:.fnl=.lua})
  13. LUA_DIRS := $(sort $(call uniq,$(foreach _,${LUA_DST},$(call dir,$_))))
  14. .PHONY: all
  15. all: lua
  16. .PHONY: fnl
  17. fnl: fnl.init
  18. .PHONY: lua
  19. lua: lua.init
  20. ${LUA_DST}: lua/%.lua: fnl/%.fnl ${LUA_DIRS}
  21. @ compiled="$$($(FENNEL) ${FNL_ARGS} -c $<)" \
  22. && printf '%s\n' "$${compiled}" > $@ \
  23. && printf '%s -> %s\n' '$<' '$@'
  24. ${LUA_DIRS}:
  25. @mkdir -v -- $@
  26. .PHONY: lua.init
  27. lua.init: init rm.init ${LUA_DST}
  28. sed '/fnl/d' < $< > init.lua
  29. .PHONY: fnl.init
  30. fnl.init: init.fnl.lua clean_lua rm.init
  31. ln -s $< init.lua
  32. init.fnl.lua: init.fnl
  33. fennel --add-macro-path './fnl/?.fnl' -c $< > $@
  34. .PHONY: rm.init
  35. rm.init:
  36. rm -f -- init.lua
  37. .PHONY: clean_lua
  38. clean_lua:
  39. @rm -vf -- ${LUA_DST}
  40. @rm -vfd -- $(call reverse,${LUA_DIRS})
  41. .PHONY: clean
  42. clean: clean_lua rm.init
  43. rm -f -- init.fnl.lua