makefile 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Environment vars
  2. DIST_DIR := dist
  3. DIR_OF_PROJECTS := src/projets
  4. # Computed vars
  5. SRC_HTMLS := $(shell find src -name '*.src.html')
  6. SRC_MDS := $(shell find src -name '*.src.md')
  7. SRC_TEMPLATES := $(shell find src/templates -name '*.html')
  8. SRC_LIST_YML := $(shell echo $(DIR_OF_PROJECTS)/*/*.meta.yml)
  9. GEN_HTMLS := $(SRC_HTMLS:%.src.html=%.gen.html)
  10. GEN_MDS := $(SRC_MDS:%.src.md=%.gen.html)
  11. GEN_LIST_YML := $(DIR_OF_PROJECTS)/list.gen.yml
  12. GEN_CONTENT_FILES := $(GEN_HTMLS) $(GEN_MDS)
  13. GEN_FILES := $(GEN_CONTENT_FILES) $(GEN_LIST_YML)
  14. INCLUDED_FILES := $(shell find src/include -type f)
  15. EMBEDDED_FILES := $(shell find src -name '*.png' -or -name '*.svg' -or -name '*.pdf')
  16. DIST_GEN_FILES := $(GEN_CONTENT_FILES:src/%.gen.html=$(DIST_DIR)/%.html)
  17. DIST_INC_FILES := $(INCLUDED_FILES:src/%=$(DIST_DIR)/%)
  18. DIST_EMB_FILES := $(EMBEDDED_FILES:src/%=$(DIST_DIR)/%)
  19. DIST_FILES := $(DIST_GEN_FILES) $(DIST_INC_FILES) $(DIST_DWN_FILES) $(DIST_EMB_FILES) $(DIST_DIR)/favicon.ico
  20. PANDOC_GEN := pandoc --template src/templates/main.html --metadata-file src/meta.yml --wrap=none
  21. LIST_GEN := yq eval-all '{"data": ., "target": {"content": filename | sub("meta.yml", "html") | sub(".*/", ""), "dir": filename | sub("$(DIR_OF_PROJECTS)/", "") | sub("/[^/]*.yml", "")}} as $$item ireduce ([]; . + $$item) | {"list": .}'
  22. # Build
  23. .PHONY: build
  24. build: $(GEN_CONTENT_FILES)
  25. $(info HTML generated)
  26. %.gen.html: %.src.html %.meta.yml $(SRC_TEMPLATES)
  27. $(PANDOC_GEN) --metadata-file $*.meta.yml --output $@ $<
  28. %.gen.html: %.src.md %.meta.yml $(SRC_TEMPLATES)
  29. $(PANDOC_GEN) --metadata-file $*.meta.yml --output $@ $<
  30. # Build lists
  31. $(GEN_LIST_YML): $(SRC_LIST_YML)
  32. $(LIST_GEN) $(SRC_LIST_YML) > $@
  33. $(DIR_OF_PROJECTS)/content.gen.html: $(DIR_OF_PROJECTS)/content.src.html $(DIR_OF_PROJECTS)/content.meta.yml $(GEN_LIST_YML) $(SRC_TEMPLATES)
  34. $(PANDOC_GEN) --metadata-file $(DIR_OF_PROJECTS)/content.meta.yml --metadata-file $(GEN_LIST_YML) --output $@ $<
  35. # Distribution
  36. .PHONY: dist
  37. dist: $(DIST_DIR)
  38. $(info Distributed folder generated)
  39. $(DIST_DIR): $(DIST_FILES)
  40. $(DIST_DIR)/%.html: src/%.gen.html
  41. mkdir --parents $(dir $@)
  42. cp $< $@
  43. $(DIST_DIR)/%: src/%
  44. mkdir --parents $(dir $@)
  45. cp $< $@
  46. # Cleaning
  47. .PHONY: clean
  48. clean:
  49. rm -f $(GEN_FILES)
  50. .PHONY: clean-dist
  51. clean-dist:
  52. rm -rf $(DIST_DIR)/*
  53. .PHONY: clean-all
  54. clean-all: clean clean-dist
  55. .PHONY: debug
  56. debug:
  57. $(info SRC_HTMLS $(SRC_HTMLS))
  58. $(info SRC_MDS $(SRC_MDS))
  59. $(info SRC_TEMPLATES $(SRC_TEMPLATES))
  60. $(info GEN_HTMLS $(GEN_HTMLS))
  61. $(info GEN_MDS $(GEN_MDS))
  62. $(info GEN_FILES $(GEN_FILES))
  63. $(info GEN_CONTENT_FILES $(GEN_CONTENT_FILES))
  64. $(info INCLUDED_FILES $(INCLUDED_FILES))
  65. $(info EMBEDDED_FILES $(EMBEDDED_FILES))
  66. $(info DIST_FILES $(DIST_FILES))