-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (93 loc) · 3.78 KB
/
Makefile
File metadata and controls
116 lines (93 loc) · 3.78 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
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright (c) 2023 University of Oxford.
# Copyright (c) 2023 Red Hat, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
NAME = criu-coordinator
.PHONY: all
all: $(NAME) ## Build criu-coordinator binary
BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions
ZSHINSTALLDIR=${PREFIX}/share/zsh/site-functions
FISHINSTALLDIR=${PREFIX}/share/fish/vendor_completions.d
PREFIX ?= $(DESTDIR)/usr/local
BINDIR ?= $(PREFIX)/bin
BUILD ?= release
BUILD_FLAGS=
ifeq ($(BUILD),release)
BUILD_FLAGS+=--release
endif
DEPS = $(wildcard src/*.rs src/**/*.rs) Cargo.toml
CARGO=$(HOME)/.cargo/bin/cargo
ifeq (,$(wildcard $(CARGO)))
CARGO=cargo
endif
target/$(BUILD)/$(NAME): $(DEPS)
$(CARGO) build $(BUILD_FLAGS)
$(NAME): target/$(BUILD)/$(NAME)
cp -a $< $@
.PHONY: install
install: target/$(BUILD)/$(NAME) install.completions ## Install binary and completions
@echo " INSTALL " $<
@mkdir -p $(DESTDIR)$(BINDIR)
@install -m0755 $< $(BINDIR)/$(NAME)
.PHONY: uninstall
uninstall: uninstall.completions ## Uninstall binary and completions
@echo " UNINSTALL" $(NAME)
$(RM) $(addprefix $(DESTDIR)$(BINDIR)/,$(NAME))
.PHONY: lint
lint: ## Run clippy lint checks
$(CARGO) clippy --all-targets --all-features -- -D warnings
.PHONY: lint-fix
lint-fix: ## Automatically fix lint issues
$(CARGO) clippy --fix --all-targets --all-features -- -D warnings
.PHONY: test
test: ## Run tests sequentially to avoid mixing the outputs of the tests
$(CARGO) test -- --test-threads=1
test-e2e: ## Run e2e tests and require root privileges.
$(CARGO) test -- --test --test-threads=1 --ignored
.PHONY: completions
completions: $(NAME) ## Generate shell completions
declare -A outfiles=([bash]=%s [zsh]=_%s [fish]=%s.fish);\
for shell in $${!outfiles[*]}; do \
outfile=$$(printf "completions/$$shell/$${outfiles[$$shell]}" $(NAME)); \
./$(NAME) completions $$shell >| $$outfile; \
done
.PHONY: validate.completions
validate.completions: SHELL:=/usr/bin/env bash # Set shell to bash for this target
validate.completions: ## Validate generated completions with their shells
# Check if the files can be loaded by the shell
. completions/bash/$(NAME)
if [ -x /bin/zsh ]; then \
/bin/zsh -c 'autoload -Uz compinit; compinit; source completions/zsh/_$(NAME)'; \
fi
if [ -x /bin/fish ]; then /bin/fish completions/fish/$(NAME).fish; fi
.PHONY: install.completions
install.completions: ## Install generated completions
@install -d -m 755 ${DESTDIR}${BASHINSTALLDIR}
@install -m 644 completions/bash/$(NAME) ${DESTDIR}${BASHINSTALLDIR}
@install -d -m 755 ${DESTDIR}${ZSHINSTALLDIR}
@install -m 644 completions/zsh/_$(NAME) ${DESTDIR}${ZSHINSTALLDIR}
@install -d -m 755 ${DESTDIR}${FISHINSTALLDIR}
@install -m 644 completions/fish/$(NAME).fish ${DESTDIR}${FISHINSTALLDIR}
.PHONY: uninstall.completions
uninstall.completions: ## Remove installed completions
@$(RM) $(addprefix ${DESTDIR}${BASHINSTALLDIR}/,$(NAME))
@$(RM) $(addprefix ${DESTDIR}${ZSHINSTALLDIR}/,_$(NAME))
@$(RM) $(addprefix ${DESTDIR}${FISHINSTALLDIR}/,$(NAME).fish)
.PHONY: clean
clean: ## Clean build artifacts
rm -rf target $(NAME)
.PHONY: help
help: ## Show this help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make <target>\n\nTargets:\n"} \
/^[a-zA-Z0-9_.-]+:.*##/ { printf " * \033[36m%s\033[0m -%s\n", $$1, $$2 }' $(MAKEFILE_LIST)