forked from nefelim4ag/systemd-swap
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (82 loc) · 2.98 KB
/
Makefile
File metadata and controls
110 lines (82 loc) · 2.98 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
prefix ?= $(PREFIX)
# this avoids /usr/local/usr/* when
# installing with prefix=/usr/local
ifeq ($(prefix), /usr/local)
exec_prefix ?= $(prefix)
datarootdir ?= $(prefix)/share
else
exec_prefix ?= $(prefix)/usr
datarootdir ?= $(prefix)/usr/share
endif
bindir ?= $(exec_prefix)/bin
libdir ?= $(exec_prefix)/lib
datadir ?= $(datarootdir)
mandir ?= $(datarootdir)/man
sysconfdir ?= $(prefix)/etc
localstatedir ?= $(prefix)/var
CARGO ?= cargo
CARGO_FLAGS ?= --release
GITB := $(shell command -v git 2>/dev/null)
ifdef GITB
REPO := $(shell git rev-parse --is-inside-work-tree 2>/dev/null)
endif
LIB_T := $(DESTDIR)$(localstatedir)/lib/systemd-swap
BIN_T := $(DESTDIR)$(bindir)/systemd-swap
PRE_BIN_T := $(DESTDIR)$(bindir)/pre-systemd-swap
SVC_T := $(DESTDIR)$(libdir)/systemd/system/systemd-swap.service
PRE_SVC_T := $(DESTDIR)$(libdir)/systemd/system/pre-systemd-swap.service
DFL_T := $(DESTDIR)$(datadir)/systemd-swap/swap-default.conf
CNF_T := $(DESTDIR)$(sysconfdir)/systemd/swap.conf
MAN5_T := $(DESTDIR)$(mandir)/man5/swap.conf.5
MAN8_T := $(DESTDIR)$(mandir)/man8/systemd-swap.8
SYSCTL_T := $(DESTDIR)$(sysconfdir)/sysctl.d/91-memory.conf
.PHONY: build files dirs install uninstall clean help
default: build
build: ## Build Rust binary
$(CARGO) build $(CARGO_FLAGS)
$(LIB_T):
mkdir -p $@
dirs: $(LIB_T)
$(BIN_T): target/release/systemd-swap
install -p -Dm755 $< $@
$(PRE_BIN_T): src/pre-systemd-swap
install -p -Dm755 $< $@
$(SVC_T): include/systemd-swap.service
install -p -Dm644 $< $@
$(PRE_SVC_T): include/pre-systemd-swap.service
install -p -Dm644 $< $@
$(DFL_T): include/swap-default.conf
install -p -Dm644 $< $@
$(CNF_T): swap.conf
install -p -bDm644 -S .old $< $@
$(MAN5_T): man/swap.conf.5
install -p -Dm644 $< $@
$(MAN8_T): man/systemd-swap.8
install -p -Dm644 $< $@
$(SYSCTL_T): include/91-memory.conf
install -p -Dm644 $< $@
define banner
# This file is part of systemd-swap.\n#\n# Entries in this file show the systemd-swap defaults as\n# specified in $(datarootdir)/systemd-swap/swap-default.conf\n# You can change settings by editing this file.\n# Defaults can be restored by simply deleting this file.\n#\n# See swap.conf(5) and $(datarootdir)/systemd-swap/swap-default.conf for details.\n\n
endef
swap.conf: include/swap-default.conf ## Generate swap.conf
@echo '** Generating swap.conf..'
@printf "$(banner)" > $@
@cat $< >> $@
target/release/systemd-swap: build
files: $(BIN_T) $(PRE_BIN_T) $(SVC_T) $(PRE_SVC_T) $(DFL_T) $(CNF_T) $(MAN5_T) $(MAN8_T) $(SYSCTL_T)
install: ## Install systemd-swap
install: build dirs files
uninstall: ## Delete systemd-swap (stop systemd-swap first)
uninstall:
test ! -f /run/systemd/swap/swap.conf
rm -v $(BIN_T) $(PRE_BIN_T) $(SVC_T) $(PRE_SVC_T) $(DFL_T) $(CNF_T) $(MAN5_T) $(MAN8_T) $(SYSCTL_T)
rm -rv $(LIB_T) $(DESTDIR)$(datadir)/systemd-swap
clean: ## Remove generated files
ifdef REPO
git clean -fxd
else
rm -vf swap.conf *.new
$(CARGO) clean
endif
help: ## Show help
@grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed 's/\\$$//;s/##/\t/'