Makefile 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # ---------- ---------- ---------- ---------- ---------- ----------
  2. #
  3. # fenrisg Makefile
  4. #
  5. # 1) config, vars, and target
  6. # 2) functions
  7. # 3) phonies
  8. #
  9. # ---------- ---------- ---------- ---------- ---------- ----------
  10. BUILD=bin
  11. BIN=$(BUILD)/fenrisg
  12. MAN=$(BUILD)/fenrisg.1
  13. BIN_DIR=$(if $(i),$(i),$$HOME/.local/bin)
  14. MAN_DIR=$(if $(m),$(m),$$HOME/.local/share/man/man1)
  15. target: help
  16. # ---------- ---------- ---------- ---------- ---------- ----------
  17. # functions
  18. # ---------- ---------- ---------- ---------- ---------- ----------
  19. define append_to_build
  20. @cat $(1) >> $(BIN)
  21. @echo "\n" >> $(BIN)
  22. endef
  23. define lint_bin
  24. @shellcheck bin/fenrisg || echo ""
  25. endef
  26. define lint_src
  27. @shellcheck -s bash \
  28. src/*.sh \
  29. src/rss/*.sh \
  30. src/site/*.sh \
  31. src/sitemap/*.sh \
  32. src/utils/*.sh \
  33. || \
  34. echo ""
  35. @#shellcheck -s bash src/sitemap/*.sh
  36. endef
  37. define lint_tests
  38. @shellcheck -s bash \
  39. tests/*.sh \
  40. tests/mocks/coreutils/* \
  41. tests/mocks/fenrisg/*.sh \
  42. || \
  43. echo ""
  44. @shellcheck -s bash \
  45. tests/test_* -e SC1090 \
  46. || \
  47. echo ""
  48. endef
  49. define run_tests
  50. @cd ./tests && \
  51. ./test_file_extentions && \
  52. ./test_get_directory_depth_offset && \
  53. ./test_get_absolute_path && \
  54. ./test_get_output_file && \
  55. ./test_main
  56. endef
  57. # ---------- ---------- ---------- ---------- ---------- ----------
  58. # phonies
  59. # ---------- ---------- ---------- ---------- ---------- ----------
  60. .PHONY: help
  61. help:
  62. @echo "Usage: make [PHONY] [OPTIONS]"
  63. @echo "PHONY:"
  64. @sed -n -e "/sed/! s/\.PHONY: / /p" Makefile
  65. @echo "OPTIONS:"
  66. @echo " i=[installation directory for binaries] - Defaults to \$$HOME/.local/bin"
  67. @echo " m=[installation directory for manuals] - Defaults to \$$HOME/.local/share/man/man1"
  68. .PHONY: build
  69. build: clean build-bin build-manual
  70. .PHONY: build-bin
  71. build-bin:
  72. @mkdir -p $(BUILD) && touch $(BIN) && chmod +x $(BIN)
  73. @$(call append_to_build,src/shebang.sh)
  74. @$(call append_to_build,src/usage.sh)
  75. @$(call append_to_build,src/version.sh)
  76. @$(call append_to_build,src/utils/functions.sh)
  77. @$(call append_to_build,src/inputs.sh)
  78. @$(call append_to_build,src/rss/build_rss.sh)
  79. @$(call append_to_build,src/site/build_site.sh)
  80. @$(call append_to_build,src/site/process_file.sh)
  81. @$(call append_to_build,src/sitemap/build_sitemap.sh)
  82. @$(call append_to_build,src/main_function.sh)
  83. @$(call append_to_build,src/main_script_call.sh)
  84. .PHONY: build-manual
  85. build-manual:
  86. @mkdir -p $(BUILD) && touch $(MAN)
  87. @pandoc -s -f markdown-smart -t man fenrisg.1.md -o $(MAN) || exit
  88. .PHONY: clean
  89. clean:
  90. @rm -rf $(BUILD)
  91. .PHONY: install
  92. install: build
  93. @mkdir -p $(BIN_DIR) && \
  94. mkdir -p $(MAN_DIR)
  95. @echo "Installing into "$(BIN_DIR)
  96. @install -Dm755 $(BIN) $(BIN_DIR)
  97. @echo "Manual into "$(MAN_DIR)
  98. @install -Dm644 $(MAN) $(MAN_DIR)
  99. .PHONY: lint
  100. lint: lint-src lint-tests lint-bin
  101. .PHONY: lint-bin
  102. lint-bin: build
  103. @$(call lint_bin)
  104. .PHONY: lint-src
  105. lint-src:
  106. @$(call lint_src)
  107. .PHONY: lint-tests
  108. lint-tests:
  109. @$(call lint_tests)
  110. .PHONY: tests
  111. tests: build
  112. @$(call run_tests)