-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
104 lines (84 loc) · 2.92 KB
/
Makefile
File metadata and controls
104 lines (84 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
SHELL := /bin/bash
MAKEFLAGS := $(filter-out w --print-directory,$(MAKEFLAGS))
MAKEFLAGS += --no-print-directory
PROJECT_NAME := $(shell grep -Po '^name = "\K[^"]+' Cargo.toml)
PROJECT_CAP := $(shell echo $(PROJECT_NAME) | tr '[:lower:]' '[:upper:]')
LATEST_TAG ?= $(shell git describe --tags --abbrev=0 2>/dev/null)
TOP_DIR := $(CURDIR)
BUILD_DIR := $(TOP_DIR)/target
SHELL := /bin/bash
ifeq ($(PROJECT_NAME),)
$(error Error: project_name not found in Cargo.toml)
endif
$(info ------------------------------------------)
$(info Project: $(PROJECT_NAME))
$(info ------------------------------------------)
.PHONY: build b config c reconfig run r test t help h clean docs release
build:
@cargo build --release
b: build
config:
@cargo check
reconfig:
@cargo clean
@cargo check
c: config
run:
@./target/release/$(PROJECT_NAME)
r: run
test:
@cargo test --verbose
t: test
help:
@echo
@echo "Usage: make [target]"
@echo
@echo "Available targets:"
@echo " build Build project"
@echo " config Check project configuration"
@echo " reconfig Clean and reconfigure project"
@echo " run Run the main executable"
@echo " test Run tests"
@echo " docs Build documentation (TYPE=mdbook)"
@echo " release Create a new release (TYPE=patch|minor|major)"
@echo
h : help
clean:
@echo "Cleaning build directory..."
@cargo clean
@echo "Build directory cleaned."
docs:
ifeq ($(TYPE),mdbook)
@command -v mdbook >/dev/null 2>&1 || { echo "mdbook is not installed. Please install it first."; exit 1; }
@mdbook build $(TOP_DIR)/book --dest-dir $(TOP_DIR)/docs
@git add --all && git commit -m "docs: building website/mdbook"
else
$(error Invalid documentation type. Use 'make docs TYPE=mdbook')
endif
release:
@if [ -z "$(TYPE)" ]; then \
echo "Release type not specified. Use 'make release TYPE=[patch|minor|major]'"; \
exit 1; \
fi; \
CURRENT_VERSION=$$(grep '^version = ' Cargo.toml | sed -E 's/version = "(.*)"/\1/'); \
IFS='.' read -r MAJOR MINOR PATCH <<< "$$CURRENT_VERSION"; \
case "$(TYPE)" in \
major) MAJOR=$$((MAJOR+1)); MINOR=0; PATCH=0 ;; \
minor) MINOR=$$((MINOR+1)); PATCH=0 ;; \
patch) PATCH=$$((PATCH+1)); ;; \
*) echo "Invalid release type. Use patch, minor or major."; exit 1 ;; \
esac; \
version="$$MAJOR.$$MINOR.$$PATCH"; \
if [ -n "$(LATEST_TAG)" ]; then \
changelog=$$(git cliff $(LATEST_TAG)..HEAD --strip all); \
git cliff --tag $$version $(LATEST_TAG)..HEAD --prepend CHANGELOG.md; \
else \
changelog=$$(git cliff --unreleased --strip all); \
git cliff --tag $$version --unreleased --prepend CHANGELOG.md; \
fi; \
sed -i "s/^version = \".*\"/version = \"$$version\"/" Cargo.toml; \
git add -A && git commit -m "chore(release): prepare for $$version"; \
echo "$$changelog"; \
git tag -a $$version -m "$$version" -m "$$changelog"; \
git push --follow-tags --force --set-upstream origin develop; \
gh release create $$version --notes "$$changelog"