This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
139 lines (100 loc) · 3.74 KB
/
Makefile
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
.DEFAULT_GOAL := build-release
SHELL := /bin/bash
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
CONTAINER_MGR ?= podman
KEEP_TOOLBOX_IMAGES ?= 2
WAKETIMED_BUILD_PROFILE ?= --release
WAKETIMED_INSTALL_PROFILE ?= release
WAKETIMED_INSTALL_BIN_DIR ?= /usr/local/bin
WAKETIMED_INSTALL_BIN_NAME ?= waketimed
WAKETIMED_INSTALL_SERVICE_DIR ?= /etc/systemd/system
WAKETIMED_INSTALL_SERVICE_NAME ?= waketimed.service
WAKETIMED_TEST_INT_ARGS ?= -- --nocapture
export WAKETIMED_BUS_ADDRESS ?= $(DBUS_SESSION_BUS_ADDRESS)
# BUILD
build:
cargo build $(WAKETIMED_BUILD_PROFILE)
build-debug: WAKETIMED_BUILD_PROFILE =
build-debug: build
build-release: WAKETIMED_BUILD_PROFILE = --release
build-release: build
build-release-aarch64: export PKG_CONFIG_ALLOW_CROSS = 1
build-release-aarch64: WAKETIMED_BUILD_PROFILE = --release --target aarch64-unknown-linux-gnu
build-release-aarch64: cross-prep-cargo build
install:
install -m 0755 target/$(WAKETIMED_INSTALL_PROFILE)/waketimed $(WAKETIMED_INSTALL_BIN_DIR)/$(WAKETIMED_INSTALL_BIN_NAME)
install-service:
install -m 0644 waketimed/config/systemd/waketimed.service $(WAKETIMED_INSTALL_SERVICE_DIR)/$(WAKETIMED_INSTALL_SERVICE_NAME)
clean:
cargo clean
deps-check-outdated:
if ! cargo outdated -h &> /dev/null; then \
cargo install cargo-outdated; \
fi; \
cargo outdated
deps-update:
cargo update
doc:
cargo doc
publish: lint test
cargo publish -p waketimed
# LINT
lint: lint-commit-messages lint-clippy lint-fmt
lint-commit-messages:
./scripts/lint-commit-messages.sh
lint-fmt:
cargo fmt --check
lint-clippy:
cargo clippy -- -D warnings $(WAKETIMED_LINT_CLIPPY_ARGS)
fix: fix-clippy fix-fmt
fix-clippy:
cargo clippy --fix --allow-dirty --allow-staged
fix-fmt:
cargo fmt
# TEST
test: test-unit test-int
test-unit: test-unit-waketimed
test-int: test-int-waketimed
test-unit-waketimed:
cd waketimed && cargo test --bins
test-int-waketimed:
cd waketimed && RUST_BACKTRACE=1 cargo test --test '*' $(WAKETIMED_TEST_INT_ARGS)
# TOOLBOX
toolbox-build:
cd toolbox && \
$(CONTAINER_MGR) build --no-cache -t localhost/waketimed_toolbox_builder:latest . && \
$(CONTAINER_MGR) tag localhost/waketimed_toolbox_builder:latest localhost/waketimed_toolbox_builder:$$(date "+%Y_%m_%d")
toolbox-clean: KEEP_TOOLBOX_IMAGES=0
toolbox-clean: toolbox-expire
$(CONTAINER_MGR) rmi localhost/waketimed_toolbox_builder:latest || true
toolbox-expire:
TAGS=$$(podman images | grep '^localhost/waketimed_toolbox_builder ' | grep -E ' [0-9]{4}_[0-9]{2}_[0-9]{2} ' | awk '{ print $$2;}' | sort -r); \
IDX=0 ; \
for TAG in $$TAGS; do \
if [ "$$IDX" -ge "$(KEEP_TOOLBOX_IMAGES)" ]; then \
podman rmi localhost/waketimed_toolbox_builder:$$TAG; \
fi; \
: $$(( IDX++ )); \
done
cross-toolbox-build:
cd toolbox && \
$(CONTAINER_MGR) build --no-cache -f Containerfile_cross -t localhost/waketimed_toolbox_cross:latest . && \
$(CONTAINER_MGR) tag localhost/waketimed_toolbox_cross:latest localhost/waketimed_toolbox_cross:$$(date "+%Y_%m_%d")
cross-toolbox-clean: KEEP_TOOLBOX_IMAGES=0
cross-toolbox-clean: cross-toolbox-expire
$(CONTAINER_MGR) rmi localhost/waketimed_toolbox_cross:latest || true
cross-toolbox-expire:
TAGS=$$(podman images | grep '^localhost/waketimed_toolbox_cross ' | grep -E ' [0-9]{4}_[0-9]{2}_[0-9]{2} ' | awk '{ print $$2;}' | sort -r); \
IDX=0 ; \
for TAG in $$TAGS; do \
if [ "$$IDX" -ge "$(KEEP_TOOLBOX_IMAGES)" ]; then \
podman rmi localhost/waketimed_toolbox_cross:$$TAG; \
fi; \
: $$(( IDX++ )); \
done
cross-prep-cargo:
mkdir -p tmp/cargo-cross; \
if ! grep /usr/bin/aarch64-linux-gnu-gcc tmp/cargo-cross/config &> /dev/null; then \
echo '[target.aarch64-unknown-linux-gnu]' >>tmp/cargo-cross/config; \
echo 'linker = "/usr/bin/aarch64-linux-gnu-gcc"' >>tmp/cargo-cross/config; \
fi