Skip to content

Commit f08cc55

Browse files
committed
Improve Makefile
Signed-off-by: Pedro B S Lisboa <[email protected]>
1 parent de3b85e commit f08cc55

File tree

1 file changed

+51
-16
lines changed

1 file changed

+51
-16
lines changed

Makefile

+51-16
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,77 @@
1+
# Define installation arguments with optional prefix
12
INSTALL_ARGS := $(if $(PREFIX),--prefix $(PREFIX),)
3+
# Define examples with their descriptions
4+
EXAMPLE_DESCRIPTIONS := \
5+
"example-building-ast:Demonstrates how to build AST" \
6+
"example-destructuring-ast:Demonstrates how to destructure an AST" \
27

3-
# Default rule
4-
default:
8+
.PHONY: help
9+
help: ## Print this help message
10+
@echo "";
11+
@echo "List of available make commands";
12+
@echo "";
13+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}';
14+
@echo "";
15+
@echo "Available examples:";
16+
@echo "";
17+
@for desc in $(EXAMPLE_DESCRIPTIONS); do \
18+
target=$$(echo $$desc | cut -d: -f1); \
19+
description=$$(echo $$desc | cut -d: -f2); \
20+
printf " \033[36m%-30s\033[0m %s\n" "$$target" "$$description"; \
21+
done
22+
@echo "";
23+
24+
.PHONY: default
25+
default: ## Build the project with auto-promote
526
dune build --auto-promote @install
627

7-
install:
28+
.PHONY: install
29+
install: ## Install the project
830
dune install $(INSTALL_ARGS)
931

10-
uninstall:
32+
.PHONY: uninstall
33+
uninstall: ## Uninstall the project
1134
dune uninstall $(INSTALL_ARGS)
1235

13-
reinstall: uninstall reinstall
36+
.PHONY: reinstall
37+
reinstall: ## Reinstall the project
38+
uninstall reinstall
1439

15-
test:
40+
.PHONY: test
41+
test: ## Run tests
1642
dune runtest
1743

18-
doc:
44+
.PHONY: doc
45+
doc: ## Build documentation
1946
dune build @doc
2047

21-
clean:
48+
.PHONY: doc-dev
49+
doc-dev: ## Build and watch documentation
50+
dune build @doc --watch & dune_pid=$$!; \
51+
trap 'kill $$dune_pid' EXIT; \
52+
sleep 2 && open _build/default/_doc/_html/index.html & \
53+
wait $$dune_pid
54+
55+
.PHONY: clean
56+
clean: ## Clean the build artifacts
2257
dune clean
2358

24-
all-supported-ocaml-versions:
59+
.PHONY: all-supported-ocaml-versions
60+
all-supported-ocaml-versions: ## Build for all supported OCaml versions
2561
dune build @install --workspace dune-workspace.dev --root .
2662

27-
opam-release:
63+
.PHONY: opam-release
64+
opam-release: ## Release the project using opam
2865
dune-release distrib --skip-build --skip-lint --skip-tests
2966
dune-release publish distrib --verbose
3067
dune-release opam pkg
3168
dune-release opam submit
3269

33-
bench:
70+
.PHONY: bench
71+
bench: ## Run benchmarks
3472
dune build bench --profile release
3573
dune exec bench/bench.exe
3674

37-
.PHONY: default install uninstall reinstall clean test doc bench
38-
.PHONY: all-supported-ocaml-versions opam-release
39-
40-
.PHONY: $(TARGET)
41-
example-%:
75+
.PHONY: example-<target>
76+
example-%: ## Run example with specified target, e.g. make example-global-transformation
4277
DUNE_CONFIG__GLOBAL_LOCK=disabled opam exec -- dune exec $*-example

0 commit comments

Comments
 (0)