Makefile 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Detect operating system
  2. ifeq ($(OS),Windows_NT)
  3. PLATFORM_SHELL := powershell
  4. SCRIPT_EXT := .ps1
  5. SCRIPT_DIR := hack/windows
  6. else
  7. PLATFORM_SHELL := /bin/bash
  8. SCRIPT_EXT := .sh
  9. SCRIPT_DIR := hack
  10. endif
  11. # Borrowed from https://stackoverflow.com/questions/18136918/how-to-get-current-relative-directory-of-your-makefile
  12. curr_dir := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
  13. # Borrowed from https://stackoverflow.com/questions/2214575/passing-arguments-to-make-run
  14. rest_args := $(wordlist 2, $(words $(MAKECMDGOALS)), $(MAKECMDGOALS))
  15. $(eval $(rest_args):;@:)
  16. # List targets based on script extension and directory
  17. ifeq ($(OS),Windows_NT)
  18. targets := $(shell powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem -Path $(curr_dir)/$(SCRIPT_DIR) | Select-Object -ExpandProperty BaseName")
  19. else
  20. targets := $(shell ls $(curr_dir)/$(SCRIPT_DIR) | grep $(SCRIPT_EXT) | sed 's/$(SCRIPT_EXT)$$//')
  21. endif
  22. $(targets):
  23. @$(eval TARGET_NAME=$@)
  24. ifeq ($(PLATFORM_SHELL),/bin/bash)
  25. $(curr_dir)/$(SCRIPT_DIR)/$(TARGET_NAME)$(SCRIPT_EXT) $(rest_args)
  26. else
  27. powershell -NoProfile -ExecutionPolicy Bypass "$(curr_dir)/$(SCRIPT_DIR)/$(TARGET_NAME)$(SCRIPT_EXT) $(rest_args)"
  28. endif
  29. help:
  30. #
  31. # Usage:
  32. #
  33. # * [dev] `make install`, install development tools, like uv, pre-commit hooks and so on.
  34. #
  35. # * [dev] `make deps`, prepare all dependencies.
  36. #
  37. # * [dev] `make generate`, generate codes.
  38. #
  39. # * [dev] `make lint`, check style.
  40. #
  41. # * [dev] `make test`, execute unit testing.
  42. #
  43. # * [dev] `make build`, execute building.
  44. #
  45. # * [dev] `make build-docs`, build docs, not supported on Windows.
  46. #
  47. # * [dev] `make serve-docs`, serve docs, not supported on Windows.
  48. #
  49. # * [ci] `make package`, build container images, not supported on Windows.
  50. #
  51. # * [ci] `make ci`, execute `make install`, `make deps`, `make lint`, `make test`, `make build`.
  52. #
  53. @echo
  54. .DEFAULT_GOAL := build
  55. .PHONY: $(targets)