From 2aeef20ae820ee69c40a16e67d60358c7b285927 Mon Sep 17 00:00:00 2001 From: Pedro B S Lisboa Date: Mon, 23 Dec 2024 12:23:18 -0300 Subject: [PATCH] Improve Makefile --- Makefile | 67 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index e0f79b0d..1607f744 100644 --- a/Makefile +++ b/Makefile @@ -1,42 +1,77 @@ +# Define installation arguments with optional prefix INSTALL_ARGS := $(if $(PREFIX),--prefix $(PREFIX),) +# Define examples with their descriptions +EXAMPLE_DESCRIPTIONS := \ + "example-building-ast:Demonstrates how to build AST" \ + "example-destructuring-ast:Demonstrates how to destructure an AST" \ -# Default rule -default: +.PHONY: help +help: ## Print this help message + @echo ""; + @echo "List of available make commands"; + @echo ""; + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'; + @echo ""; + @echo "Available examples:"; + @echo ""; + @for desc in $(EXAMPLE_DESCRIPTIONS); do \ + target=$$(echo $$desc | cut -d: -f1); \ + description=$$(echo $$desc | cut -d: -f2); \ + printf " \033[36m%-30s\033[0m %s\n" "$$target" "$$description"; \ + done + @echo ""; + +.PHONY: default +default: ## Build the project with auto-promote dune build --auto-promote @install -install: +.PHONY: install +install: ## Install the project dune install $(INSTALL_ARGS) -uninstall: +.PHONY: uninstall +uninstall: ## Uninstall the project dune uninstall $(INSTALL_ARGS) -reinstall: uninstall reinstall +.PHONY: reinstall +reinstall: ## Reinstall the project + uninstall reinstall -test: +.PHONY: test +test: ## Run tests dune runtest -doc: +.PHONY: doc +doc: ## Build documentation dune build @doc -clean: +.PHONY: doc-dev +doc-dev: ## Build and watch documentation + dune build @doc --watch & dune_pid=$$!; \ + trap 'kill $$dune_pid' EXIT; \ + sleep 2 && open _build/default/_doc/_html/index.html & \ + wait $$dune_pid + +.PHONY: clean +clean: ## Clean the build artifacts dune clean -all-supported-ocaml-versions: +.PHONY: all-supported-ocaml-versions +all-supported-ocaml-versions: ## Build for all supported OCaml versions dune build @install --workspace dune-workspace.dev --root . -opam-release: +.PHONY: opam-release +opam-release: ## Release the project using opam dune-release distrib --skip-build --skip-lint --skip-tests dune-release publish distrib --verbose dune-release opam pkg dune-release opam submit -bench: +.PHONY: bench +bench: ## Run benchmarks dune build bench --profile release dune exec bench/bench.exe -.PHONY: default install uninstall reinstall clean test doc bench -.PHONY: all-supported-ocaml-versions opam-release - -.PHONY: $(TARGET) -example-%: +.PHONY: example- +example-%: ## Run example with specified target, e.g. make example-global-transformation DUNE_CONFIG__GLOBAL_LOCK=disabled opam exec -- dune exec $*-example