makefile 2.3 KB

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