-
Notifications
You must be signed in to change notification settings - Fork 27
/
Makefile
175 lines (156 loc) · 5.24 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
# SPDX-License-Identifier: GPL-2.0-only
BUGADDR = Martin V\"ath <[email protected]>
EXENAME ?= zram-init
PREFIX ?= /usr/local
SYSCONFDIR ?= $(PREFIX)/etc
DESTDIR ?=
BINDIR ?= $(DESTDIR)$(PREFIX)/sbin
MODPROBEDIR ?= $(DESTDIR)$(SYSCONFDIR)/modprobe.d
MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
MANSUBDIR ?= man8
MANI18NAPP ?=
MODIR_PLAIN ?= $(PREFIX)/share/locale
MODIR ?= $(DESTDIR)$(MODIR_PLAIN)
COMP_ZSHDIR ?= $(DESTDIR)$(PREFIX)/share/zsh/site-functions
SYSTEMDDIR ?= $(DESTDIR)$(PREFIX)/lib/systemd/system
CONFDIR ?= $(DESTDIR)$(SYSCONFDIR)/conf.d
INITDIR ?= $(DESTDIR)$(SYSCONFDIR)/init.d
PO ?= i18n/de.po i18n/fr.po
MANI18N ?= de fr
GETTEXT ?= TRUE
MODIFY_SHEBANG ?= TRUE
MODPROBED ?= TRUE
MANPAGE ?= TRUE
ZSH_COMPLETION ?= TRUE
SYSTEMD ?= TRUE
OPENRC ?= TRUE
INSTALL_EXE ?= install -D --mode=755
INSTALL_DATA ?= install -D --mode=644
RM ?= rm -f
MSGFMT ?= msgfmt --check --statistics --verbose
FXGETTEXT ?= --no-wrap
MSGMERGE ?= msgmerge $(FXGETTEXT) --update --backup=existing --verbose
XGETTEXT ?= xgettext $(FXGETTEXT) --from-code=UTF-8 --add-comments="TRANSLATION:" \
--keyword="Echo" --flag="Echo:1:no-sh-format" --keyword="xEcho" \
--keyword="xWarning" --keyword="Fatal" --flag="Fatal:1:no-sh-format" \
--keyword="xFatal" --language=Shell --add-location=never \
--copyright-holder="$(BUGADDR)" \
--package-name="$(EXENAME)" --msgid-bugs-address="$(BUGADDR)"
.PHONY: all
ifeq ($(GETTEXT), TRUE)
all: $(PO:.po=.mo) sbin/$(EXENAME)
else
all: sbin/$(EXENAME)
endif
.PHONY: po
po: $(PO)
i18n/$(EXENAME).pot: sbin/$(EXENAME).in
@echo 'Creating the Portable Object Template file: $@…'
$(XGETTEXT) '$<' -o '$@'
i18n/%.po: i18n/$(EXENAME).pot
@echo 'Merging the Portable Object Template file into $@…'
$(MSGMERGE) '$@' '$<'
i18n/%.mo: i18n/%.po
@echo 'Compiling the Portable Object file: $<…'
$(MSGFMT) '$<' -o '$@'
sbin/$(EXENAME): sbin/$(EXENAME).in
@echo 'Setting TEXTDOMAINDIR and TEXTDOMAIN variables'
sed -e "s'@MODIR@'$(MODIR_PLAIN)'g" -e "s'@EXENAME@'$(EXENAME)'g" \
-- '$<' >'$@'
chmod 755 -- '$@' || echo 'warn: chmod 755 $@ failed'
ifeq ($(MODIFY_SHEBANG), TRUE)
@echo 'Modifying shebang…'
sed -e "1s'"'^\#\!.*$$'"'$${SHEBANG:-#!`command -v sh 2>/dev/null`}'" \
-i -- '$@'
endif
.PHONY: install
install: all
@echo 'Installing the executable…'
$(INSTALL_EXE) 'sbin/$(EXENAME)' '$(BINDIR)/$(EXENAME)'
ifeq ($(MODPROBED), TRUE)
@echo 'Installing the modprobe.d file…'
$(INSTALL_DATA) modprobe.d/zram.conf '$(MODPROBEDIR)/zram.conf'
endif
ifeq ($(MANPAGE), TRUE)
@echo 'Installing the man pages…'
$(INSTALL_DATA) 'man/$(EXENAME).8' '$(MANDIR)/$(MANSUBDIR)/$(EXENAME).8'
for i in $(MANI18N); do \
! test -r "man/$(EXENAME).$$i.8" || \
$(INSTALL_DATA) "man/$(EXENAME).$$i.8" \
"$(MANDIR)/$$i$(MANI18NAPP)/$(MANSUBDIR)/$(EXENAME).8" ; \
done
endif
ifeq ($(GETTEXT), TRUE)
@echo 'Installing the Machine Object files…'
for i in $(notdir $(basename $(PO))); do \
$(INSTALL_DATA) "i18n/$$i.mo" "$(MODIR)/$$i/LC_MESSAGES/$(EXENAME).mo"; \
done
endif
ifeq ($(ZSH_COMPLETION), TRUE)
@echo 'Installing the completion files…'
$(INSTALL_DATA) 'zsh/_$(EXENAME)' '$(COMP_ZSHDIR)/_$(EXENAME)'
endif
ifeq ($(SYSTEMD), TRUE)
@echo 'Installing the systemd service files…'
$(INSTALL_DATA) systemd/system/zram_btrfs.service '$(SYSTEMDDIR)/zram_btrfs.service'
$(INSTALL_DATA) systemd/system/zram_swap.service '$(SYSTEMDDIR)/zram_swap.service'
$(INSTALL_DATA) systemd/system/zram_tmp.service '$(SYSTEMDDIR)/zram_tmp.service'
$(INSTALL_DATA) systemd/system/zram_var_tmp.service '$(SYSTEMDDIR)/zram_var_tmp.service'
endif
ifeq ($(OPENRC), TRUE)
@echo 'Installing the OpenRC files…'
$(INSTALL_DATA) 'openrc/conf.d/$(EXENAME)' '$(CONFDIR)/$(EXENAME)'
$(INSTALL_EXE) 'openrc/init.d/$(EXENAME)' '$(INITDIR)/$(EXENAME)'
endif
.PHONY: uninstall
uninstall:
@echo 'Uninstalling the executable…'
$(RM) '$(BINDIR)/$(EXENAME)'
ifeq ($(MODPROBED), TRUE)
@echo 'Uninstalling the modprobe.d file…'
$(RM) '$(MODPROBEDIR)/zram.conf'
endif
ifeq ($(MANPAGE), TRUE)
@echo 'Uninstalling the man page…'
$(RM) '$(MANDIR)/$(EXENAME).8'
endif
ifeq ($(GETTEXT), TRUE)
@echo 'Uninstalling the Machine Object files…'
for i in $(notdir $(basename $(PO))); do \
$(RM) '$(MODIR)/$$i/LC_MESSAGES/$(EXENAME).mo'; \
done
endif
ifeq ($(ZSH_COMPLETION), TRUE)
@echo 'Uninstalling the completion files…'
$(RM) '$(COMP_ZSHDIR)/_$(EXENAME)'
endif
ifeq ($(SYSTEMD), TRUE)
@echo 'Uninstalling the systemd service files…'
$(RM) '$(SYSTEMDDIR)/zram_btrfs.service'
$(RM) '$(SYSTEMDDIR)/zram_swap.service'
$(RM) '$(SYSTEMDDIR)/zram_tmp.service'
$(RM) '$(SYSTEMDDIR)/zram_var_tmp.service'
endif
ifeq ($(OPENRC), TRUE)
@echo 'Uninstalling the OpenRC files…'
$(RM) '$(CONFDIR)/$(EXENAME)'
$(RM) '$(INITDIR)/$(EXENAME)'
endif
.PHONY: clean
clean:
@echo 'Deleting the executable…'
$(RM) sbin/$(EXENAME)
@echo 'Deleting all Machine Object files…'
$(RM) i18n/*.mo
@echo 'Deleting all Portable Object backups…'
$(RM) i18n/*.po~
.PHONY: mrproper
mrproper: clean
@echo 'Deleting the Portable Object Template file…'
$(RM) i18n/$(EXENAME).pot
@echo 'Deleting archives and similar stuff…'
$(RM) *.asc *.gz *.tar *.xz *.zip *.tar.*
.PHONY: distclean
distclean: mrproper
.PHONY: maintainer-clean
maintainer-clean: mrproper