forked from vergoh/vnstat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
217 lines (185 loc) · 6.2 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# bin and man dirs for Linux
BIN ?= $(DESTDIR)/usr/bin
SBIN ?= $(DESTDIR)/usr/sbin
MAN ?= $(DESTDIR)/usr/share/man
ETC ?= $(DESTDIR)/etc/
# bin and man dirs for *BSD
BIN_BSD ?= $(DESTDIR)/usr/local/bin
SBIN_BSD ?= $(DESTDIR)/usr/local/sbin
MAN_BSD ?= $(DESTDIR)/usr/local/man
ETC_BSD ?= $(DESTDIR)/etc
.PHONY: vnstat tests check all clean debug install uninstall bsdinstall bsduninstall dist
default: vnstat
vnstat:
$(MAKE) -C src
tests:
$(MAKE) -C tests
check: tests
all:
$(MAKE) -C src all
clean:
$(MAKE) -C src clean
$(MAKE) -C tests clean
debug:
$(MAKE) CFLAGS='-Wall -Wextra -g' -C src all
install:
@echo "Installing vnStat..."
# check that system is really Linux
@if [ `uname` != "Linux" ]; \
then echo "This isn't a Linux system. Maybe 'make bsdinstall' is what you need?"; \
false; \
fi
# check that there's something to install
@if [ ! -f "src/vnstat" ] || [ ! -f "src/vnstatd" ]; \
then echo "Nothing to install, run make first."; \
false; \
fi
# move some really old version database(s) if found
@if [ -d "$(DESTDIR)/var/spool/vnstat" ]; \
then echo "Moving old database(s) to new location..."; \
mv -f $(DESTDIR)/var/spool/vnstat $(DESTDIR)/var/lib/; \
fi
# remove some really old version binary if found
@if [ -x "$(DESTDIR)/usr/local/bin/vnstat" ]; \
then echo "Removing old binary..."; \
rm -f $(DESTDIR)/usr/local/bin/vnstat; \
fi
# install default config if such doesn't exist
@if [ ! -f "$(ETC)/vnstat.conf" ]; \
then echo "Installing config to $(ETC)/vnstat.conf"; \
install -d -m 755 $(ETC); \
install -m 644 cfg/vnstat.conf $(ETC)/vnstat.conf; \
fi
# install everything else
install -d -m 755 $(BIN) $(SBIN) $(MAN)/man1 $(MAN)/man5
install -s -m 755 src/vnstat $(BIN)
install -s -m 755 src/vnstatd $(SBIN)
@if [ -f "src/vnstati" ]; \
then echo install -s -m 755 src/vnstati $(BIN); \
install -s -m 755 src/vnstati $(BIN); \
fi
# update man pages, gzip it if previous version was done so
install -m 644 man/vnstat.1 $(MAN)/man1
install -m 644 man/vnstatd.1 $(MAN)/man1
install -m 644 man/vnstat.conf.5 $(MAN)/man5
@if [ -f "src/vnstati" ]; \
then echo install -m 644 man/vnstati.1 $(MAN)/man1; \
install -m 644 man/vnstati.1 $(MAN)/man1; \
fi
@if [ -f "$(MAN)/man1/vnstat.1.gz" ]; \
then gzip -f9 $(MAN)/man1/vnstat.1; \
gzip -f9 $(MAN)/man1/vnstatd.1; \
gzip -f9 $(MAN)/man5/vnstat.conf.5; \
if [ -f "src/vnstati" ]; \
then gzip -f9 $(MAN)/man1/vnstati.1; \
fi; \
fi
# remove vnstat.conf.1 is such exists in the wrong place
@if [ -f "$(MAN)/man1/vnstat.conf.1.gz" ]; \
then rm -f $(MAN)/man1/vnstat.conf.1.gz; \
fi
@if [ -f "$(MAN)/man1/vnstat.conf.1" ]; \
then rm -f $(MAN)/man1/vnstat.conf.1; \
fi
@echo " "
@echo "No service file or startup script has been installed. See the"
@echo "INSTALL document for instructions on how to enable vnStat."
uninstall:
@echo "Uninstalling vnStat..."
@echo
@echo "Note: this will also remove the database directory"
@echo "including any database located there."
@echo
@echo "Press CTRL-C within 10 seconds to abort."
@sleep 10
rm -fr $(DESTDIR)/var/lib/vnstat
rm -f $(BIN)/vnstat
rm -f $(BIN)/vnstati
rm -f $(SBIN)/vnstatd
rm -f $(MAN)/man1/vnstat*
rm -f $(MAN)/man5/vnstat*
rm -f $(DESTDIR)/etc/cron.d/vnstat
rm -f $(ETC)/vnstat.conf
rm -f $(DESTDIR)/etc/ppp/ip-up.d/vnstat
rm -f $(DESTDIR)/etc/ppp/ip-down.d/vnstat
bsdinstall:
@echo "Installing vnStat (BSD)..."
# check that system isn't Linux
@if [ `uname` = "Linux" ]; \
then echo "This is a Linux system. You shouldn't be using 'bsdinstall'"; \
false; \
fi
# check that there's something to install
@if [ ! -f "src/vnstat" ] || [ ! -f "src/vnstatd" ]; \
then echo "Nothing to install, run make first."; \
false; \
fi
# install binaries
install -d -m 755 $(DESTDIR)/var/db/vnstat
install -s -m 755 src/vnstat $(BIN_BSD)
install -s -m 755 src/vnstatd $(SBIN_BSD)
@if [ -f "src/vnstati" ]; \
then echo install -s -m 755 src/vnstati $(BIN_BSD); \
install -s -m 755 src/vnstati $(BIN_BSD); \
fi
# install default config if such doesn't exist
@if [ ! -f "$(ETC_BSD)/vnstat.conf" ]; \
then echo "Installing config to $(ETC_BSD)/vnstat.conf"; \
install -d -m 755 $(ETC_BSD); \
install -m 644 cfg/vnstat.conf $(ETC_BSD)/vnstat.conf; \
sed -e 's:/lib/:/db/:g' $(ETC_BSD)/vnstat.conf >$(ETC_BSD)/vnstat.conf.bsd; \
mv -f $(ETC_BSD)/vnstat.conf.bsd $(ETC_BSD)/vnstat.conf; \
fi
# update man page
for m in vnstat.1 vnstati.1 vnstatd.1 vnstat.conf.5; do \
sed -e 's:/lib/:/db/:g' man/$$m > man/$$m.tmp; \
mv -f man/$$m.tmp man/$$m; \
done
install -m 644 man/vnstat.1 $(MAN_BSD)/man1
install -m 644 man/vnstatd.1 $(MAN_BSD)/man1
install -m 644 man/vnstat.conf.5 $(MAN_BSD)/man5
gzip -f9 $(MAN_BSD)/man1/vnstat.1
gzip -f9 $(MAN_BSD)/man1/vnstatd.1
gzip -f9 $(MAN_BSD)/man5/vnstat.conf.5
@if [ -f "src/vnstati" ]; \
then echo install -m 644 man/vnstati.1 $(MAN_BSD)/man1; \
install -m 644 man/vnstati.1 $(MAN_BSD)/man1; \
echo gzip -f9 $(MAN_BSD)/man1/vnstati.1; \
gzip -f9 $(MAN_BSD)/man1/vnstati.1; \
fi
# remove vnstat.conf.1 is such exists in the wrong place
@if [ -f "$(MAN_BSD)/man1/vnstat.conf.1.gz" ]; \
then rm -f $(MAN_BSD)/man1/vnstat.conf.1.gz; \
fi
@if [ -f "$(MAN_BSD)/man1/vnstat.conf.1" ]; \
then rm -f $(MAN_BSD)/man1/vnstat.conf.1; \
fi
@echo " "
@echo "No service file or startup script has been installed. See the"
@echo "INSTALL_BSD document for instructions on how to enable vnStat."
bsduninstall:
@echo "Uninstalling vnStat (BSD)..."
@echo
@echo "Note: this will also remove the database directory"
@echo "including any database located there."
@echo
@echo "Press CTRL-C within 10 seconds to abort."
@sleep 10
rm -fr $(DESTDIR)/var/db/vnstat
rm -f $(BIN_BSD)/vnstat
rm -f $(BIN_BSD)/vnstati
rm -f $(SBIN_BSD)/vnstatd
rm -f $(MAN_BSD)/man1/vnstat*
rm -f $(MAN_BSD)/man5/vnstat*
rm -f $(ETC_BSD)/vnstat.conf
@echo "A possible cron entry needs to be removed manually if such exists."
dist: clean
$(eval VER := $(shell grep VNSTATVERSION src/common.h | cut -d\" -f2 | sed 's: :_:g'))
@echo
@echo "Packaging $(VER)..."
@rm -fr "../vnstat-$(VER).tar.gz" "../vnstat-$(VER)"
@mkdir "../vnstat-$(VER)"
@cp -ax * "../vnstat-$(VER)/"
@fakeroot tar zcf "../vnstat-$(VER).tar.gz" "../vnstat-$(VER)"
@rm -fr "../vnstat-$(VER)"
@ls -l "../vnstat-$(VER).tar.gz"