makefile 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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' -or -name '*.ico' -or -name '*.txt')
  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_EMB_FILES)
  20. BUILD_VERSION := $(shell git describe)
  21. BUILD_DATE := $(shell date "+%F")
  22. PANDOC_GEN := pandoc --template src/templates/main.html --metadata-file src/meta.yml --metadata=build-date:$(BUILD_DATE) --metadata=build-version:$(BUILD_VERSION) --wrap=none --metadata-file $(GEN_LIST_YML)
  23. 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": .}'
  24. # Functions
  25. extract_category = $(word 2, $(subst /, ,$(1)))
  26. extract_update_date = $(shell git log -1 --pretty="format:%cs" $(1))
  27. # Build
  28. .PHONY: build
  29. build: $(GEN_CONTENT_FILES)
  30. $(info HTML generated)
  31. %.gen.html: %.src.html %.meta.yml $(SRC_TEMPLATES) $(GEN_LIST_YML)
  32. $(PANDOC_GEN) --metadata-file $*.meta.yml --metadata=category-$(call extract_category,$*) --metadata=update-date:$(call extract_update_date,$<) --output $@ $<
  33. %.gen.html: %.src.md %.meta.yml $(SRC_TEMPLATES) $(GEN_LIST_YML)
  34. $(PANDOC_GEN) --metadata-file $*.meta.yml --metadata=category-$(call extract_category,$*) --metadata=update-date:$(call extract_update_date,$<) --output $@ $<
  35. # Build lists
  36. $(GEN_LIST_YML): $(SRC_LIST_YML)
  37. $(LIST_GEN) $(SRC_LIST_YML) > $@
  38. # Distribution
  39. .PHONY: install
  40. install: $(DIST_DIR)
  41. $(info Distributed folder generated)
  42. $(DIST_DIR): $(DIST_FILES)
  43. $(DIST_DIR)/%.html: src/%.gen.html
  44. mkdir --parents $(dir $@)
  45. cp $< $@
  46. $(DIST_DIR)/%: src/%
  47. mkdir --parents $(dir $@)
  48. cp $< $@
  49. # Cleaning
  50. .PHONY: clean
  51. clean:
  52. rm -f $(GEN_FILES)
  53. .PHONY: clean-dist
  54. clean-dist:
  55. rm -rf $(DIST_DIR)/*
  56. .PHONY: clean-all
  57. clean-all: clean clean-dist
  58. .PHONY: debug
  59. debug:
  60. $(info SRC_HTMLS $(SRC_HTMLS))
  61. $(info SRC_MDS $(SRC_MDS))
  62. $(info SRC_TEMPLATES $(SRC_TEMPLATES))
  63. $(info GEN_HTMLS $(GEN_HTMLS))
  64. $(info GEN_MDS $(GEN_MDS))
  65. $(info GEN_FILES $(GEN_FILES))
  66. $(info GEN_CONTENT_FILES $(GEN_CONTENT_FILES))
  67. $(info INCLUDED_FILES $(INCLUDED_FILES))
  68. $(info EMBEDDED_FILES $(EMBEDDED_FILES))
  69. $(info DIST_FILES $(DIST_FILES))