-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
191 lines (149 loc) · 4.1 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
NAME = project_name
PKGNAME = $(NAME)
DOCKERNAME = $(NAME)
TAR = tar
TARFLAGS = -cf $(PKGNAME).tar
ZIP = gzip
ZIPFLAGS =
CARGO = cargo
CARGO_BUILD_FLAGS =
CARGO_FETCH_FLAGS =
CARGO_PKG_FLAGS =
CARGO_TEST_FLAGS =
CARGO_LINT_ALL_FLAGS = -- \
-D warnings -D clippy::all -D clippy::pedantic \
-D non-ascii-idents \
-D clippy::non-ascii-literal \
-D clippy::dbg-macro \
-D clippy::default-union-representation \
-D clippy::else-if-without-else \
-D clippy::mixed-read-write-in-expression \
-D clippy::try-err
CARGO_LINT_CODE_FLAGS = $(CARGO_LINT_ALL_FLAGS) \
-D clippy::panic \
-D clippy::todo \
-D clippy::unimplemented \
-D clippy::unreachable \
-D clippy::unwrap-used \
-D clippy::expect-used \
-D clippy::indexing-slicing
CARGO_FMT_FLAGS =
CARGO_RUN_FLAGS =
CARGO_CLEAN_FLAGS =
RUN_FLAGS =
DOCKER = docker
DOCKER_FLAGS = \
--build-arg CARGO='$(CARGO)' \
--build-arg CARGO_BUILD_FLAGS='$(CARGO_BUILD_FLAGS)' \
--build-arg CARGO_FETCH_FLAGS='$(CARGO_FETCH_FLAGS)'
DOCKER_RUN_FLAGS = -it --rm --init --name $(DOCKERNAME)
DOCKER_CMD =
DESTDIR =
prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
sbindir = $(exec_prefix)/sbin
libexecdir = $(exec_prefix)/libexec
libdir = $(exec_prefix)/lib
includedir = $(prefix)/include
datarootdir = $(prefix)/share
datadir = $(datarootdir)
sysconfdir = $(prefix)/etc
localstatedir = $(prefix)/var
runstatedir = $(localstatedir)/run
mandir = $(datarootdir)/man
man1dir = $(mandir)/man1
man3dir = $(mandir)/man3
all:
-include version.mk
-include config.mk
.PHONY: all bin lib deps
.PHONY: dist crate version release
.PHONY: install install-bin install-lib install-man-bin install-man-lib
.PHONY: uninstall uninstall-bin uninstall-lib
.PHONY: uninstall-man-bin uninstall-man-lib
.PHONY: check test lint fmt fmt-check
.PHONY: run dev
.PHONY: docker docker-run
.PHONY: clean distclean cleanall
all:
$(CARGO) build $(CARGO_BUILD_FLAGS)
bin:
$(CARGO) build --bins $(CARGO_BUILD_FLAGS)
lib:
$(CARGO) build --lib $(CARGO_BUILD_FLAGS)
deps:
$(CARGO) fetch $(CARGO_FETCH_FLAGS)
dist:
mkdir $(PKGNAME)
find . ! -name . -prune ! -name .git ! -name target \
! -name $(PKGNAME) ! -name '$(NAME)-*' \
-exec cp -RPf {} $(PKGNAME) \;
cd $(PKGNAME) && $(MAKE) distclean
$(TAR) $(TARFLAGS) $(PKGNAME)
$(ZIP) $(ZIPFLAGS) $(PKGNAME).tar
rm -Rf $(PKGNAME).tar $(PKGNAME)
crate:
$(CARGO) package $(CARGO_PKG_FLAGS)
version: make/version.sh
{ \
./$< && printf '%s\n' '' \
'PKGNAME = $$(NAME)-$$(VERSION)' \
'DOCKERNAME = $$(NAME):$$(VERSION)'; \
} >| version.mk
release: make/release.sh
./$<
install: install-bin install-lib install-man-bin install-man-lib
install-bin: target/release/hello
mkdir -p $(DESTDIR)$(bindir)
cp -f target/release/hello $(DESTDIR)$(bindir)
chmod +x $(DESTDIR)$(bindir)/hello
install-lib:
mkdir -p $(DESTDIR)$(libdir)
install-man-bin: man/hello.1
mkdir -p $(DESTDIR)$(man1dir)
cp -f man/hello.1 $(DESTDIR)$(man1dir)
install-man-lib:
mkdir -p $(DESTDIR)$(man3dir)
uninstall: uninstall-man-lib uninstall-man-bin
uninstall: uninstall-lib uninstall-bin
uninstall-bin:
rm -f $(DESTDIR)$(bindir)/hello
-cd $(DESTDIR)/ && rmdir -p .$(bindir)
uninstall-lib:
-cd $(DESTDIR)/ && rmdir -p .$(libdir)
uninstall-man-bin:
rm -f $(DESTDIR)$(man1dir)/hello.1
-cd $(DESTDIR)/ && rmdir -p .$(man1dir)
uninstall-man-lib:
-cd $(DESTDIR)/ && rmdir -p .$(man3dir)
check: fmt-check lint test
test:
$(CARGO) test $(CARGO_TEST_FLAGS)
lint: make/lint.sh
$(CARGO) clippy --all-targets $(CARGO_LINT_ALL_FLAGS)
$(CARGO) clippy $(CARGO_LINT_CODE_FLAGS)
./$<
fmt: make/fmt.sh
$(CARGO) fmt $(CARGO_FMT_FLAGS)
./$<
fmt-check: make/fmt-check.sh
$(CARGO) fmt --check $(CARGO_FMT_FLAGS)
./$<
run:
$(CARGO) run $(CARGO_RUN_FLAGS) -- $(RUN_FLAGS)
dev:
$(CARGO) watch -x run $(CARGO_RUN_FLAGS)-- $(RUN_FLAGS)
docker:
$(DOCKER) build $(DOCKER_FLAGS) -t $(DOCKERNAME) .
docker-run:
$(DOCKER) run $(DOCKER_RUN_FLAGS) $(DOCKERNAME) $(DOCKER_CMD)
clean:
rm -Rf $(PKGNAME).* $(PKGNAME) $(NAME)-*
$(CARGO) clean $(CARGO_CLEAN_FLAGS)
distclean: clean
rm -f Cargo.lock config.mk
cleanall: distclean
rm -f version.mk
target/release/hello:
$(CARGO) build --bins -r $(CARGO_BUILD_FLAGS)