2020-01-11 14:41:11 -05:00
|
|
|
NAME = gophernicus
|
|
|
|
PACKAGE = $(NAME)
|
|
|
|
BINARY = $(NAME)
|
|
|
|
VERSION = 3.1
|
2019-02-18 11:11:04 -05:00
|
|
|
CODENAME = Dungeon Edition
|
2014-01-25 04:21:40 -05:00
|
|
|
|
2020-01-11 14:41:11 -05:00
|
|
|
SOURCES = src/$(NAME).c src/file.c src/menu.c src/string.c src/platform.c src/session.c src/options.c
|
2020-01-20 17:36:02 -05:00
|
|
|
HEADERS = src/functions.h src/files.h src/filetypes.h
|
2014-01-25 04:21:40 -05:00
|
|
|
OBJECTS = $(SOURCES:.c=.o)
|
2020-01-11 14:41:11 -05:00
|
|
|
README = README.md
|
|
|
|
DOCS = LICENSE README.md INSTALL.md changelog README.Gophermap gophertag
|
2014-01-25 04:21:40 -05:00
|
|
|
|
|
|
|
DESTDIR = /usr
|
2020-01-11 14:41:11 -05:00
|
|
|
OSXDIR = /usr/local
|
2014-01-25 04:21:40 -05:00
|
|
|
SBINDIR = $(DESTDIR)/sbin
|
2020-01-11 14:41:11 -05:00
|
|
|
DOCDIR = $(DESTDIR)/share/doc/$(PACKAGE)
|
|
|
|
MANPAGE = gophernicus.1.man
|
2019-10-01 03:33:31 -04:00
|
|
|
MANDEST = $(DESTDIR)/share/man/man1/gophernicus.1
|
2014-01-25 04:21:40 -05:00
|
|
|
|
2020-01-11 14:41:11 -05:00
|
|
|
INSTALL = PATH=$$PATH:/usr/sbin ./install-sh -o 0 -g 0
|
|
|
|
ROOT = /var/gopher
|
2014-01-25 04:21:40 -05:00
|
|
|
OSXROOT = /Library/GopherServer
|
|
|
|
WRTROOT = /gopher
|
|
|
|
MAP = gophermap
|
|
|
|
|
|
|
|
INETD = /etc/inetd.conf
|
|
|
|
XINETD = /etc/xinetd.d
|
2020-01-20 17:36:02 -05:00
|
|
|
# get OPTIONS line from gophernicus.env and use that also for inetd
|
|
|
|
INETOPT = `grep '^OPTIONS=' $(NAME).env | tail -n 1 | sed -e 's/OPTIONS="*//;s/"*$$//'`
|
|
|
|
INETLIN = "gopher stream tcp nowait nobody $(SBINDIR)/$(BINARY) $(BINARY) $(INETOPT)"
|
2019-03-09 11:54:45 -05:00
|
|
|
INETPID = /var/run/inetd.pid
|
2014-01-25 04:21:40 -05:00
|
|
|
LAUNCHD = /Library/LaunchDaemons
|
2015-12-29 08:21:36 -05:00
|
|
|
PLIST = org.$(NAME).server.plist
|
2014-01-25 04:21:40 -05:00
|
|
|
NET_SRV = /boot/common/settings/network/services
|
2016-12-11 03:52:13 -05:00
|
|
|
SYSTEMD = /lib/systemd/system /usr/lib/systemd/system
|
2016-01-01 03:21:56 -05:00
|
|
|
HAS_STD = /run/systemd/system
|
2015-12-30 05:32:41 -05:00
|
|
|
SYSCONF = /etc/sysconfig
|
|
|
|
DEFAULT = /etc/default
|
2014-01-25 04:21:40 -05:00
|
|
|
|
2019-12-30 18:55:43 -05:00
|
|
|
CC ?= gcc
|
2014-01-25 04:21:40 -05:00
|
|
|
CFLAGS = -O2 -Wall
|
2019-01-03 00:31:52 -05:00
|
|
|
LDFLAGS =
|
2014-01-25 04:21:40 -05:00
|
|
|
|
2015-12-31 02:30:39 -05:00
|
|
|
IPCRM = /usr/bin/ipcrm
|
|
|
|
|
2019-09-30 02:46:56 -04:00
|
|
|
all:
|
2014-01-25 04:21:40 -05:00
|
|
|
@case `uname` in \
|
2020-01-12 07:00:45 -05:00
|
|
|
Darwin) $(MAKE) ROOT="$(OSXROOT)" DESTDIR="$(OSXDIr)" src/$(BINARY); ;; \
|
2020-01-11 14:41:11 -05:00
|
|
|
Haiku) $(MAKE) EXTRA_LIBS="-lnetwork" src/$(BINARY); ;; \
|
|
|
|
*) if [ -f "/usr/include/tcpd.h" ]; then $(MAKE) withwrap; else $(MAKE) src/$(BINARY); fi; ;; \
|
2014-01-25 04:21:40 -05:00
|
|
|
esac
|
|
|
|
|
2016-01-01 03:12:19 -05:00
|
|
|
withwrap:
|
2020-01-11 14:41:11 -05:00
|
|
|
$(MAKE) EXTRA_CFLAGS="-DHAVE_LIBWRAP" EXTRA_LIBS="-lwrap" src/$(BINARY)
|
2016-01-01 03:12:19 -05:00
|
|
|
|
2017-06-16 03:09:49 -04:00
|
|
|
deb:
|
2016-11-13 05:54:53 -05:00
|
|
|
dpkg-buildpackage -rfakeroot -uc -us
|
2014-01-25 04:21:40 -05:00
|
|
|
|
2019-09-30 02:46:56 -04:00
|
|
|
headers: $(HEADERS)
|
|
|
|
|
2020-01-11 14:41:11 -05:00
|
|
|
src/$(NAME).c: headers src/$(NAME).h
|
2019-01-03 00:31:52 -05:00
|
|
|
|
2020-01-11 14:41:11 -05:00
|
|
|
src/$(BINARY): $(OBJECTS)
|
2018-01-29 07:42:12 -05:00
|
|
|
$(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) $(OBJECTS) $(EXTRA_LIBS) -o $@
|
2014-01-25 04:21:40 -05:00
|
|
|
|
|
|
|
.c.o:
|
2016-01-01 03:55:49 -05:00
|
|
|
$(CC) -c $(CFLAGS) $(EXTRA_CFLAGS) -DVERSION="\"$(VERSION)\"" -DCODENAME="\"$(CODENAME)\"" -DDEFAULT_ROOT="\"$(ROOT)\"" $< -o $@
|
2014-01-25 04:21:40 -05:00
|
|
|
|
2020-01-11 14:41:11 -05:00
|
|
|
src/functions.h:
|
2014-01-25 04:21:40 -05:00
|
|
|
echo "/* Automatically generated function definitions */" > $@
|
|
|
|
echo >> $@
|
2014-11-10 04:15:55 -05:00
|
|
|
grep -h "^[a-z]" $(SOURCES) | \
|
|
|
|
grep -v "int main" | \
|
|
|
|
grep -v "strlc" | \
|
2017-02-02 07:27:52 -05:00
|
|
|
grep -v "[a-z]:" | \
|
2014-11-10 04:15:55 -05:00
|
|
|
sed -e "s/ =.*$$//" -e "s/ *$$/;/" >> $@
|
2014-01-25 04:21:40 -05:00
|
|
|
@echo
|
|
|
|
|
2020-01-20 17:36:02 -05:00
|
|
|
src/filetypes.h: src/filetypes.conf
|
|
|
|
sh src/filetypes.sh < src/filetypes.conf > $@
|
|
|
|
|
2020-01-11 14:41:11 -05:00
|
|
|
src/bin2c: src/bin2c.c
|
|
|
|
$(CC) src/bin2c.c -o $@
|
2014-01-25 04:21:40 -05:00
|
|
|
|
2019-03-05 19:23:07 -05:00
|
|
|
README: $(README)
|
|
|
|
cat $(README) > $@
|
|
|
|
|
2020-01-11 14:41:11 -05:00
|
|
|
src/files.h: src/bin2c README
|
2019-03-05 19:23:07 -05:00
|
|
|
sed -e '/^(end of option list)/,$$d' README > README.options
|
2020-01-11 14:41:11 -05:00
|
|
|
./src/bin2c -0 -n README README.options > $@
|
|
|
|
./src/bin2c -0 LICENSE >> $@
|
|
|
|
./src/bin2c -n ERROR_GIF error.gif >> $@
|
2014-01-25 04:21:40 -05:00
|
|
|
@echo
|
|
|
|
|
2020-01-11 14:41:11 -05:00
|
|
|
# Clean cases
|
2014-01-25 04:21:40 -05:00
|
|
|
|
|
|
|
clean: clean-build clean-deb
|
|
|
|
|
|
|
|
clean-build:
|
2020-01-11 14:41:11 -05:00
|
|
|
rm -rf src/$(BINARY) $(OBJECTS) $(HEADERS) README.options README src/bin2c
|
2014-01-25 04:21:40 -05:00
|
|
|
|
|
|
|
clean-deb:
|
|
|
|
if [ -d debian/$(PACKAGE) ]; then fakeroot debian/rules clean; fi
|
|
|
|
|
2015-12-31 02:30:39 -05:00
|
|
|
clean-shm:
|
2020-01-11 14:41:11 -05:00
|
|
|
if [ -x $(IPCRM) ]; then $(IPCRM) -M `awk '/SHM_KEY/ { print $$3 }' src/$(NAME).h` || true; fi
|
2015-12-31 02:30:39 -05:00
|
|
|
|
2020-01-11 14:41:11 -05:00
|
|
|
# Install cases
|
2014-01-25 04:21:40 -05:00
|
|
|
|
2019-06-14 20:31:02 -04:00
|
|
|
install: clean-shm
|
2014-01-25 04:21:40 -05:00
|
|
|
@case `uname` in \
|
2020-01-12 07:00:45 -05:00
|
|
|
Darwin) $(MAKE) ROOT="$(OSXROOT)" DESTDIR="$(OSXDIR)" install-files install-docs install-root install-osx install-done; ;; \
|
2014-01-25 04:21:40 -05:00
|
|
|
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
|
2016-01-01 03:21:56 -05:00
|
|
|
@if [ -d "$(HAS_STD)" ]; then $(MAKE) install-systemd install-done; \
|
2015-12-29 08:21:36 -05:00
|
|
|
elif [ -d "$(XINETD)" ]; then $(MAKE) install-xinetd install-done; \
|
2019-01-02 23:47:39 -05:00
|
|
|
elif [ -f "$(INETD)" ]; then $(MAKE) install-inetd install-done; fi
|
2014-01-25 04:21:40 -05:00
|
|
|
|
|
|
|
.PHONY: install
|
|
|
|
|
|
|
|
install-done:
|
|
|
|
@echo
|
|
|
|
@echo "======================================================================"
|
|
|
|
@echo
|
2019-03-09 11:54:45 -05:00
|
|
|
@echo "If there were no errors shown above,"
|
2014-01-25 04:21:40 -05:00
|
|
|
@echo "Gophernicus has now been succesfully installed. To try it out, launch"
|
2015-12-30 05:51:49 -05:00
|
|
|
@echo "your favorite gopher browser and navigate to your gopher root."
|
2014-01-25 04:21:40 -05:00
|
|
|
@echo
|
2015-12-30 05:51:49 -05:00
|
|
|
@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;
|
2014-01-25 04:21:40 -05:00
|
|
|
@echo
|
|
|
|
@echo "======================================================================"
|
|
|
|
@echo
|
|
|
|
|
2020-01-11 14:41:11 -05:00
|
|
|
install-files: src/$(BINARY)
|
2014-01-25 04:21:40 -05:00
|
|
|
mkdir -p $(SBINDIR)
|
2020-01-11 14:41:11 -05:00
|
|
|
$(INSTALL) -s -m 755 src/$(BINARY) $(SBINDIR)
|
2014-01-25 04:21:40 -05:00
|
|
|
@echo
|
|
|
|
|
|
|
|
install-docs:
|
|
|
|
mkdir -p $(DOCDIR)
|
|
|
|
$(INSTALL) -m 644 $(DOCS) $(DOCDIR)
|
2019-10-01 03:33:31 -04:00
|
|
|
$(INSTALL) -m 644 $(MANPAGE) $(MANDEST)
|
2014-01-25 04:21:40 -05:00
|
|
|
@echo
|
|
|
|
|
|
|
|
install-root:
|
2015-12-30 04:37:11 -05:00
|
|
|
if [ ! -d "$(ROOT)" -o ! -f "$(ROOT)/$(MAP)" ]; then \
|
2014-01-25 04:21:40 -05:00
|
|
|
mkdir -p $(ROOT); \
|
2019-10-19 16:50:37 -04:00
|
|
|
$(INSTALL) -m 644 $(MAP).sample $(ROOT); \
|
2020-01-12 05:35:16 -05:00
|
|
|
ln -fs $(DOCDIR) $(ROOT)/docs; \
|
2014-01-25 04:21:40 -05:00
|
|
|
fi
|
|
|
|
@echo
|
|
|
|
|
2019-01-02 23:47:39 -05:00
|
|
|
install-inetd: install-files install-docs install-root
|
2019-03-12 08:18:43 -04:00
|
|
|
@if update-inetd --add $(INETLIN); then \
|
2019-03-09 16:06:38 -05:00
|
|
|
echo update-inetd install worked ; \
|
2019-03-09 10:22:03 -05:00
|
|
|
else if grep '^gopher' $(INETD) >/dev/null 2>&1 ; then \
|
2019-03-12 08:25:03 -04:00
|
|
|
echo "::::: Gopher entry in $(INETD) already present -- please check! :::::"; \
|
2019-03-12 08:23:40 -04:00
|
|
|
else echo "Trying to add gopher entry to $(INETD)" ; \
|
2019-03-09 11:54:45 -05:00
|
|
|
echo "$(INETLIN)" >> $(INETD) ; \
|
|
|
|
if [ -r $(INETPID) ] ; then kill -HUP `cat $(INETPID)` ; \
|
2019-03-12 08:25:03 -04:00
|
|
|
else echo "::::: No PID for inetd found, not restarted -- please check! :::::" ; fi ; \
|
2019-03-09 10:22:03 -05:00
|
|
|
fi ; \
|
|
|
|
fi
|
|
|
|
@echo
|
2014-01-25 04:21:40 -05:00
|
|
|
|
2019-01-02 23:47:39 -05:00
|
|
|
install-xinetd: install-files install-docs install-root
|
2014-01-25 04:21:40 -05:00
|
|
|
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 \
|
2020-01-11 14:41:11 -05:00
|
|
|
sed -e "s/@HOSTNAME@/`hostname`/g" src/$(PLIST) > $(LAUNCHD)/$(PLIST); \
|
2014-01-25 04:21:40 -05:00
|
|
|
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"; \
|
2015-12-29 08:21:36 -05:00
|
|
|
echo " launch $(BINARY) -h `hostname`"; \
|
2014-01-25 04:21:40 -05:00
|
|
|
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
|
|
|
|
|
2019-01-02 23:47:39 -05:00
|
|
|
install-systemd: install-files install-docs install-root
|
2016-12-11 03:52:13 -05:00
|
|
|
if [ -d "$(HAS_STD)" ]; then \
|
2015-12-30 05:32:41 -05:00
|
|
|
if [ -d "$(SYSCONF)" -a ! -f "$(SYSCONF)/$(NAME)" ]; then \
|
2020-01-11 14:41:11 -05:00
|
|
|
$(INSTALL) -m 644 init/$(NAME).env $(SYSCONF)/$(NAME); \
|
2015-12-30 05:32:41 -05:00
|
|
|
fi; \
|
|
|
|
if [ ! -d "$(SYSCONF)" -a -d "$(DEFAULT)" -a ! -f $(DEFAULT)/$(NAME) ]; then \
|
2020-01-11 14:41:11 -05:00
|
|
|
$(INSTALL) -m 644 init/$(NAME).env $(DEFAULT)/$(NAME); \
|
2015-12-30 05:32:41 -05:00
|
|
|
fi; \
|
2016-12-11 03:52:13 -05:00
|
|
|
for DIR in $(SYSTEMD); do \
|
|
|
|
if [ -d "$$DIR" ]; then \
|
2020-01-11 14:41:11 -05:00
|
|
|
$(INSTALL) -m 644 init/$(NAME).socket init/$(NAME)\@.service $$DIR; \
|
2016-12-11 03:52:13 -05:00
|
|
|
break; \
|
|
|
|
fi; \
|
|
|
|
done; \
|
2019-06-14 21:01:19 -04:00
|
|
|
if pidof systemd ; then \
|
|
|
|
systemctl daemon-reload; \
|
|
|
|
systemctl enable $(NAME).socket; \
|
|
|
|
systemctl start $(NAME).socket; \
|
|
|
|
fi; \
|
2015-12-29 08:21:36 -05:00
|
|
|
fi
|
|
|
|
@echo
|
|
|
|
|
2020-01-11 14:41:11 -05:00
|
|
|
# Uninstall cases
|
2019-03-09 16:06:38 -05:00
|
|
|
uninstall: uninstall-xinetd uninstall-launchd uninstall-systemd uninstall-inetd
|
2014-01-25 04:21:40 -05:00
|
|
|
rm -f $(SBINDIR)/$(BINARY)
|
|
|
|
for DOC in $(DOCS); do rm -f $(DOCDIR)/$$DOC; done
|
|
|
|
rmdir -p $(SBINDIR) $(DOCDIR) 2>/dev/null || true
|
2020-01-11 14:41:11 -05:00
|
|
|
rm -rf $(MANDEST)
|
2014-01-25 04:21:40 -05:00
|
|
|
@echo
|
|
|
|
|
2019-01-03 00:25:45 -05:00
|
|
|
uninstall-inetd:
|
2019-03-09 16:06:38 -05:00
|
|
|
@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 ; \
|
2019-01-03 00:25:45 -05:00
|
|
|
fi
|
2019-03-09 16:06:38 -05:00
|
|
|
@echo
|
2019-01-03 00:25:45 -05:00
|
|
|
|
2014-01-25 04:21:40 -05:00
|
|
|
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
|
|
|
|
|
2015-12-29 08:21:36 -05:00
|
|
|
uninstall-systemd:
|
2016-12-11 03:52:13 -05:00
|
|
|
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; \
|
2015-12-29 08:21:36 -05:00
|
|
|
fi
|
|
|
|
@echo
|