forked from gophernicus/gophernicus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
338 lines (284 loc) · 8.99 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
##
## Gophernicus server Makefile
##
#
# Variables and default configuration
#
NAME = gophernicus
PACKAGE = $(NAME)
BINARY = in.$(NAME)
VERSION = `./version`
CODENAME = Dungeon Edition
AUTHOR = Kim Holviala and others
EMAIL = gophernicus@gophernicus.org
STARTED = 2009
SOURCES = $(NAME).c file.c menu.c string.c platform.c session.c options.c
HEADERS = functions.h files.h
OBJECTS = $(SOURCES:.c=.o)
README = README.md
DOCS = LICENSE README.md INSTALL.md TODO ChangeLog README.Gophermap gophertag
INSTALL = PATH=$$PATH:/usr/sbin ./install-sh -o 0 -g 0
DESTDIR = /usr
OSXDEST = /usr/local
SBINDIR = $(DESTDIR)/sbin
DOCDIR = $(DESTDIR)/share/doc/$(PACKAGE)
ROOT = /var/gopher
OSXROOT = /Library/GopherServer
WRTROOT = /gopher
MAP = gophermap
INETD = /etc/inetd.conf
XINETD = /etc/xinetd.d
INETLIN = "gopher stream tcp nowait nobody $(SBINDIR)/$(BINARY) $(BINARY) -h `hostname`"
INETPID = /var/run/inetd.pid
LAUNCHD = /Library/LaunchDaemons
PLIST = org.$(NAME).server.plist
NET_SRV = /boot/common/settings/network/services
SYSTEMD = /lib/systemd/system /usr/lib/systemd/system
HAS_STD = /run/systemd/system
SYSCONF = /etc/sysconfig
DEFAULT = /etc/default
CC = gcc
HOSTCC = $(CC)
CFLAGS = -O2 -Wall
LDFLAGS =
IPCRM = /usr/bin/ipcrm
#
# Platform support, compatible with both BSD and GNU make
#
all: headers
@case `uname` in \
Darwin) $(MAKE) ROOT="$(OSXROOT)" DESTDIR="$(OSXDEST)" $(BINARY); ;; \
Haiku) $(MAKE) EXTRA_LIBS="-lnetwork" $(BINARY); ;; \
*) if [ -f "/usr/include/tcpd.h" ]; then $(MAKE) withwrap; else $(MAKE) $(BINARY); fi; ;; \
esac
generic: $(BINARY)
withwrap:
$(MAKE) EXTRA_CFLAGS="-DHAVE_LIBWRAP" EXTRA_LIBS="-lwrap" $(BINARY)
#
# Special targets
#
deb:
printf "$(PACKAGE) ($(VERSION)) unstable; urgency=low\n\n * Automatically generated changelog\n\n" > debian/changelog
printf " -- $(AUTHOR) <$(EMAIL)> %s\n" "`LC_ALL=POSIX date "+%a, %d %b %Y %H:%M:%S %z"`" >> debian/changelog
dpkg-buildpackage -rfakeroot -uc -us
ChangeLog:
if [ -d .git ]; then \
(./git2changelog > ChangeLog; \
cat changelog.old >> ChangeLog); \
else true; fi
.PHONY: ChangeLog
#
# Building
#
$(NAME).c: headers $(NAME).h
$(BINARY): $(OBJECTS)
$(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) $(OBJECTS) $(EXTRA_LIBS) -o $@
.c.o:
$(CC) -c $(CFLAGS) $(EXTRA_CFLAGS) -DVERSION="\"$(VERSION)\"" -DCODENAME="\"$(CODENAME)\"" -DDEFAULT_ROOT="\"$(ROOT)\"" $< -o $@
headers: $(HEADERS)
@echo
functions.h:
echo "/* Automatically generated function definitions */" > $@
echo >> $@
grep -h "^[a-z]" $(SOURCES) | \
grep -v "int main" | \
grep -v "strlc" | \
grep -v "[a-z]:" | \
sed -e "s/ =.*$$//" -e "s/ *$$/;/" >> $@
@echo
bin2c: bin2c.c
$(HOSTCC) bin2c.c -o $@
@echo
README: $(README)
cat $(README) > $@
files.h: bin2c README
sed -e '/^(end of option list)/,$$d' README > README.options
./bin2c -0 -n README README.options > $@
./bin2c -0 LICENSE >> $@
./bin2c -n ERROR_GIF error.gif >> $@
@echo
#
# Cleanup after building
#
clean: clean-build clean-deb
clean-build:
rm -f $(BINARY) $(OBJECTS) $(HEADERS) README.options README bin2c
clean-deb:
if [ -d debian/$(PACKAGE) ]; then fakeroot debian/rules clean; fi
clean-shm:
if [ -x $(IPCRM) ]; then $(IPCRM) -M `awk '/SHM_KEY/ { print $$3 }' $(NAME).h` || true; fi
#
# Install targets
#
install: ChangeLog clean-shm
@case `uname` in \
Darwin) $(MAKE) ROOT="$(OSXROOT)" DESTDIR="$(OSXDEST)" install-files install-docs install-root install-osx install-done; ;; \
Haiku) $(MAKE) SBINDIR=/boot/common/bin DOCDIR=/boot/common/share/doc/$(PACKAGE) \
install-files install-docs install-root install-haiku install-done; ;; \
*) $(MAKE) install-files install-docs install-root; ;; \
esac
@if [ -d "$(HAS_STD)" ]; then $(MAKE) install-systemd install-done; \
elif [ -d "$(XINETD)" ]; then $(MAKE) install-xinetd install-done; \
elif [ -f "$(INETD)" ]; then $(MAKE) install-inetd install-done; fi
.PHONY: install
install-done:
@echo
@echo "======================================================================"
@echo
@echo "If there were no errors shown above,"
@echo "Gophernicus has now been succesfully installed. To try it out, launch"
@echo "your favorite gopher browser and navigate to your gopher root."
@echo
@echo "Gopher URL...: gopher://`hostname`/"
@for CONFFILE in /etc/sysconfig/gophernicus \
/etc/default/gophernicus \
/Library/LaunchDaemons/org.gophernicus.server.plist \
/boot/common/settings/network/services \
/lib/systemd/system/gophernicus\@.service \
/etc/xinetd.d/gophernicus \
/etc/inetd.conf; do \
if [ -f $$CONFFILE ]; then echo "Configuration: $$CONFFILE"; break; fi; done;
@echo
@echo "======================================================================"
@echo
install-files: $(BINARY)
mkdir -p $(SBINDIR)
$(INSTALL) -s -m 755 $(BINARY) $(SBINDIR)
@echo
install-docs:
mkdir -p $(DOCDIR)
$(INSTALL) -m 644 $(DOCS) $(DOCDIR)
@echo
install-root:
if [ ! -d "$(ROOT)" -o ! -f "$(ROOT)/$(MAP)" ]; then \
mkdir -p $(ROOT); \
$(INSTALL) -m 644 $(MAP) $(ROOT); \
ln -s $(DOCDIR) $(ROOT)/docs; \
fi
@echo
install-inetd: install-files install-docs install-root
@if update-inetd --add $(INETLIN); then \
echo update-inetd install worked ; \
else if grep '^gopher' $(INETD) >/dev/null 2>&1 ; then \
echo "::::: Gopher entry in $(INETD) already present -- please check! :::::"; \
else echo "Trying to add gopher entry to $(INETD)" ; \
echo "$(INETLIN)" >> $(INETD) ; \
if [ -r $(INETPID) ] ; then kill -HUP `cat $(INETPID)` ; \
else echo "::::: No PID for inetd found, not restarted -- please check! :::::" ; fi ; \
fi ; \
fi
@echo
install-xinetd: install-files install-docs install-root
if [ -d "$(XINETD)" -a ! -f "$(XINETD)/$(NAME)" ]; then \
sed -e "s/@HOSTNAME@/`hostname`/g" $(NAME).xinetd > $(XINETD)/$(NAME); \
[ -x /sbin/service ] && /sbin/service xinetd reload; \
fi
@echo
install-osx:
if [ -d "$(LAUNCHD)" -a ! -f "$(LAUNCHD)/$(PLIST)" ]; then \
sed -e "s/@HOSTNAME@/`hostname`/g" $(PLIST) > $(LAUNCHD)/$(PLIST); \
launchctl load $(LAUNCHD)/$(PLIST); \
fi
@echo
chown -h root:admin $(ROOT) $(ROOT)/*
chmod -h 0775 $(ROOT) $(ROOT)/docs
@echo
install-haiku:
if [ -f "$(NET_SRV)" -a ! "`grep -m1 gopher $(NET_SRV)`" ]; then \
(echo ""; \
echo "service gopher {"; \
echo " family inet"; \
echo " protocol tcp"; \
echo " port 70"; \
echo " launch $(BINARY) -h `hostname`"; \
echo "}") >> $(NET_SRV); \
fi
@echo
chown user:root $(DOCDIR)/* $(SBINDIR)/$(BINARY) $(ROOT)/$(MAP)
@echo
ps | grep net_server | grep -v grep | awk '{ print $$2 }' | xargs kill
nohup /boot/system/servers/net_server >/dev/null 2>/dev/null &
@echo
install-systemd: install-files install-docs install-root
if [ -d "$(HAS_STD)" ]; then \
if [ -d "$(SYSCONF)" -a ! -f "$(SYSCONF)/$(NAME)" ]; then \
$(INSTALL) -m 644 $(NAME).env $(SYSCONF)/$(NAME); \
fi; \
if [ ! -d "$(SYSCONF)" -a -d "$(DEFAULT)" -a ! -f $(DEFAULT)/$(NAME) ]; then \
$(INSTALL) -m 644 $(NAME).env $(DEFAULT)/$(NAME); \
fi; \
for DIR in $(SYSTEMD); do \
if [ -d "$$DIR" ]; then \
$(INSTALL) -m 644 $(NAME).socket $(NAME)\@.service $$DIR; \
break; \
fi; \
done; \
systemctl daemon-reload; \
systemctl enable $(NAME).socket; \
systemctl start $(NAME).socket; \
fi
@echo
#
# Uninstall targets
#
uninstall: uninstall-xinetd uninstall-launchd uninstall-systemd uninstall-inetd
rm -f $(SBINDIR)/$(BINARY)
for DOC in $(DOCS); do rm -f $(DOCDIR)/$$DOC; done
rmdir -p $(SBINDIR) $(DOCDIR) 2>/dev/null || true
@echo
uninstall-inetd:
@if [ -f "$(INETD)" ] && update-inetd --remove "^gopher.*gophernicus" ; then \
echo update-inetd remove worked ; \
else if grep '^gopher' $(INETD) >/dev/null 2>&1 && \
sed -i .bak -e 's/^gopher/#gopher/' $(INETD) ; then \
echo "commented out gopher entry in $(INETD), reloading inetd" ; \
[ -r $(INETPID) ] && kill -HUP `cat $(INETPID)` ; \
else echo "::::: could not find gopher entry in $(INETD) :::::" ; \
fi ; \
fi
@echo
uninstall-xinetd:
if grep -q $(BINARY) "$(XINETD)/gopher" 2>/dev/null; then \
rm -f $(XINETD)/gopher; \
[ -x /sbin/service ] && service xinetd reload; \
fi
@echo
uninstall-launchd:
if [ -f $(LAUNCHD)/$(PLIST) ]; then \
launchctl unload $(LAUNCHD)/$(PLIST); \
rm -f $(LAUNCHD)/$(PLIST); \
fi
if [ -L $(ROOT) ]; then \
rm -f $(ROOT); \
fi
@echo
uninstall-systemd:
if [ -d "$(HAS_STD)" ]; then \
for DIR in $(SYSTEMD); do \
if [ -f "$$DIR/$(NAME).socket" ]; then \
systemctl stop $(NAME).socket; \
systemctl disable $(NAME).socket; \
rm -f $$DIR/$(NAME).socket $$DIR/$(NAME)\@.service $(SYSCONF)/$(NAME) $(DEFAULT)/$(NAME); \
systemctl daemon-reload; \
break; \
fi; \
done; \
fi
@echo
#
# List all C defines
#
defines: functions.h files.h
$(CC) -dM -E $(NAME).c
#
# LOC
#
loc:
@wc -l *.c
#
# Fix copyright notes
#
copyright: README
sed -i .stupid -e "s/Copyright .c. 2.*$$/Copyright (c) $(STARTED)-`date +%Y` $(AUTHOR) <$(EMAIL)>/" *.c *.h LICENSE $(README) debian/copyright
sed -i .stupid -e "s/Maintainer: .*$$/Maintainer: $(AUTHOR) <$(EMAIL)>/" debian/control
rm -f *.stupid debian/*.stupid