Skip to content

Commit c215825

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

23 files changed

+52
-28
lines changed

Makefile

Lines changed: 51 additions & 16 deletions
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-
4075
.PHONY: $(TARGET)
41-
example-%:
42-
DUNE_CONFIG__GLOBAL_LOCK=disabled opam exec -- dune exec $*-example
76+
example-%: ## Run example with specified target, e.g. make example-global-transformation
77+
opam exec -- dune exec $*-example

doc/dune

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,2 @@
11
(documentation
22
(package ppxlib))
3-
4-
(rule
5-
(alias doc)
6-
(deps
7-
(glob_files ./images/*))
8-
(action
9-
(progn
10-
(system "mkdir -p %{project_root}/_doc/_html/ppxlib/assets/images")
11-
(system "chmod -R a+rw %{project_root}/_doc/_html/ppxlib/assets/images")
12-
(system
13-
"cp -R ./images/ %{project_root}/_doc/_html/ppxlib/assets/images/"))))

doc/example-ast.mld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ As the AST represents the structure of the source code in a tree-like format, it
291291
I know that it can be a lot, but don't worry; we are going step by step, and you are going to understand it.
292292

293293
{1 Samples}
294-
To help you understand a little bit more about the AST, let's show it with some highlighted examples:
294+
To help you understand a little bit more about the AST, let's show it with some examples with the {{:https://astexplorer.net/} AST Explorer}:
295295

296296
{table
297297
{tr

doc/images/attribute_name-ast.png

-57.3 KB
Binary file not shown.

doc/images/attribute_name.png

-14.9 KB
Binary file not shown.
-73.7 KB
Binary file not shown.

doc/images/attribute_payload.png

-14.7 KB
Binary file not shown.

doc/images/extension_node-ast.png

-48.6 KB
Binary file not shown.

doc/images/extension_node.png

-13.7 KB
Binary file not shown.
-41.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)