2014-01-25 04:21:40 -05:00
|
|
|
##
|
|
|
|
## Gophernicus server Makefile
|
|
|
|
##
|
|
|
|
|
|
|
|
#
|
|
|
|
# Variables and default configuration
|
|
|
|
#
|
2016-01-01 03:55:49 -05:00
|
|
|
NAME = gophernicus
|
|
|
|
PACKAGE = $(NAME)
|
|
|
|
BINARY = in.$(NAME)
|
2018-01-28 10:01:42 -05:00
|
|
|
VERSION = `./version`
|
2019-02-18 11:11:04 -05:00
|
|
|
CODENAME = Dungeon Edition
|
2019-03-01 17:28:28 -05:00
|
|
|
AUTHOR = Kim Holviala and others
|
|
|
|
EMAIL = hb9kns+gophernicus@gmail.com
|
2018-01-28 10:23:34 -05:00
|
|
|
STARTED = 2009
|
2014-01-25 04:21:40 -05:00
|
|
|
|
|
|
|
SOURCES = $(NAME).c file.c menu.c string.c platform.c session.c options.c
|
|
|
|
HEADERS = functions.h files.h
|
|
|
|
OBJECTS = $(SOURCES:.c=.o)
|
|
|
|
DOCS = LICENSE README INSTALL TODO ChangeLog README.Gophermap gophertag
|
|
|
|
|
|
|
|
INSTALL = PATH=$$PATH:/usr/sbin ./install-sh -o 0 -g 0
|
|
|
|
DESTDIR = /usr
|
2015-12-29 03:46:48 -05:00
|
|
|
OSXDEST = /usr/local
|
2014-01-25 04:21:40 -05:00
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
CC = gcc
|
|
|
|
HOSTCC = $(CC)
|
|
|
|
CFLAGS = -O2 -Wall
|
|
|
|
LDFLAGS =
|
|
|
|
|
2015-12-31 02:30:39 -05:00
|
|
|
IPCRM = /usr/bin/ipcrm
|
|
|
|
|
2014-01-25 04:21:40 -05:00
|
|
|
|
|
|
|
#
|
|
|
|
# Platform support, compatible with both BSD and GNU make
|
|
|
|
#
|
|
|
|
all:
|
|
|
|
@case `uname` in \
|
2016-01-01 03:12:19 -05:00
|
|
|
Darwin) $(MAKE) ROOT="$(OSXROOT)" DESTDIR="$(OSXDEST)" $(BINARY); ;; \
|
2018-01-29 07:42:12 -05:00
|
|
|
Haiku) $(MAKE) EXTRA_LIBS="-lnetwork" $(BINARY); ;; \
|
2016-01-01 03:12:19 -05:00
|
|
|
*) if [ -f "/usr/include/tcpd.h" ]; then $(MAKE) withwrap; else $(MAKE) $(BINARY); fi; ;; \
|
2014-01-25 04:21:40 -05:00
|
|
|
esac
|
|
|
|
|
|
|
|
generic: $(BINARY)
|
|
|
|
|
2016-01-01 03:12:19 -05:00
|
|
|
withwrap:
|
2018-01-29 07:42:12 -05:00
|
|
|
$(MAKE) EXTRA_CFLAGS="-DHAVE_LIBWRAP" EXTRA_LIBS="-lwrap" $(BINARY)
|
2016-01-01 03:12:19 -05:00
|
|
|
|
2014-01-25 04:21:40 -05:00
|
|
|
|
|
|
|
#
|
|
|
|
# Special targets
|
|
|
|
#
|
2017-06-16 03:09:49 -04:00
|
|
|
deb:
|
2018-01-28 10:01:42 -05:00
|
|
|
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
|
2016-11-13 05:54:53 -05:00
|
|
|
dpkg-buildpackage -rfakeroot -uc -us
|
2014-01-25 04:21:40 -05:00
|
|
|
|
2014-01-25 05:45:23 -05:00
|
|
|
ChangeLog:
|
2014-01-25 07:45:00 -05:00
|
|
|
if [ -d .git ]; then \
|
2017-06-16 03:09:49 -04:00
|
|
|
(./git2changelog > ChangeLog; \
|
|
|
|
cat changelog.old >> ChangeLog); \
|
2014-01-25 07:45:00 -05:00
|
|
|
else true; fi
|
2014-01-25 05:45:23 -05:00
|
|
|
|
|
|
|
.PHONY: ChangeLog
|
|
|
|
|
2014-01-25 04:21:40 -05:00
|
|
|
|
|
|
|
#
|
|
|
|
# Building
|
|
|
|
#
|
|
|
|
$(NAME).c: $(NAME).h $(HEADERS)
|
|
|
|
|
|
|
|
$(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
|
|
|
|
|
|
|
|
|
|
|
headers: $(HEADERS)
|
|
|
|
@echo
|
|
|
|
|
|
|
|
functions.h:
|
|
|
|
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
|
|
|
|
|
|
|
|
bin2c: bin2c.c
|
|
|
|
$(HOSTCC) bin2c.c -o $@
|
|
|
|
@echo
|
|
|
|
|
|
|
|
files.h: bin2c
|
|
|
|
sed -n -e "1,/^ $$/p" 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:
|
2018-01-28 10:55:27 -05:00
|
|
|
rm -f $(BINARY) $(OBJECTS) $(HEADERS) README.options 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:
|
|
|
|
if [ -x $(IPCRM) ]; then $(IPCRM) -M `awk '/SHM_KEY/ { print $$3 }' $(NAME).h` || true; fi
|
|
|
|
|
2014-01-25 04:21:40 -05:00
|
|
|
|
|
|
|
#
|
|
|
|
# Install targets
|
|
|
|
#
|
2015-12-31 02:30:39 -05:00
|
|
|
install: ChangeLog clean-shm
|
2014-01-25 04:21:40 -05:00
|
|
|
@case `uname` in \
|
2015-12-29 03:46:48 -05:00
|
|
|
Darwin) $(MAKE) ROOT="$(OSXROOT)" DESTDIR="$(OSXDEST)" 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; \
|
2016-01-01 03:21:56 -05:00
|
|
|
elif [ -f "$(INETD)" ]; then $(MAKE) install-inetd; fi
|
2014-01-25 04:21:40 -05:00
|
|
|
|
|
|
|
.PHONY: install
|
|
|
|
|
|
|
|
install-done:
|
|
|
|
@echo
|
|
|
|
@echo "======================================================================"
|
|
|
|
@echo
|
|
|
|
@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
|
|
|
|
|
|
|
|
install-files:
|
|
|
|
mkdir -p $(SBINDIR)
|
|
|
|
$(INSTALL) -s -m 755 $(BINARY) $(SBINDIR)
|
|
|
|
@echo
|
|
|
|
|
|
|
|
install-docs:
|
|
|
|
mkdir -p $(DOCDIR)
|
|
|
|
$(INSTALL) -m 644 $(DOCS) $(DOCDIR)
|
|
|
|
@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); \
|
|
|
|
$(INSTALL) -m 644 $(MAP) $(ROOT); \
|
|
|
|
ln -s $(DOCDIR) $(ROOT)/docs; \
|
|
|
|
fi
|
|
|
|
@echo
|
|
|
|
|
|
|
|
install-inetd:
|
|
|
|
@echo
|
|
|
|
@echo "======================================================================"
|
|
|
|
@echo
|
|
|
|
@echo "Looks like your system has the traditional internet superserver inetd."
|
|
|
|
@echo "Automatic installations aren't supported, so please add the following"
|
|
|
|
@echo "line to the end of your /etc/inetd.conf and restart or kill -HUP the"
|
|
|
|
@echo "inetd process."
|
|
|
|
@echo
|
|
|
|
@echo "gopher stream tcp nowait nobody $(SBINDIR)/$(BINARY) $(BINARY) -h `hostname`"
|
|
|
|
@echo
|
|
|
|
@echo "======================================================================"
|
|
|
|
@echo
|
|
|
|
|
|
|
|
install-xinetd:
|
|
|
|
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 \
|
2015-12-29 08:21:36 -05:00
|
|
|
sed -e "s/@HOSTNAME@/`hostname`/g" $(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
|
|
|
|
|
2015-12-29 08:21:36 -05:00
|
|
|
install-systemd:
|
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 \
|
|
|
|
$(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; \
|
2016-12-11 03:52:13 -05:00
|
|
|
for DIR in $(SYSTEMD); do \
|
|
|
|
if [ -d "$$DIR" ]; then \
|
|
|
|
$(INSTALL) -m 644 $(NAME).socket $(NAME)\@.service $$DIR; \
|
|
|
|
break; \
|
|
|
|
fi; \
|
|
|
|
done; \
|
2015-12-29 08:21:36 -05:00
|
|
|
systemctl daemon-reload; \
|
|
|
|
systemctl enable $(NAME).socket; \
|
|
|
|
systemctl start $(NAME).socket; \
|
|
|
|
fi
|
|
|
|
@echo
|
|
|
|
|
2014-01-25 04:21:40 -05:00
|
|
|
#
|
|
|
|
# Uninstall targets
|
|
|
|
#
|
2015-12-29 08:21:36 -05:00
|
|
|
uninstall: uninstall-xinetd uninstall-launchd uninstall-systemd
|
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
|
|
|
|
@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
|
|
|
|
|
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
|
2014-01-25 04:21:40 -05:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# List all C defines
|
|
|
|
#
|
2017-06-16 03:09:49 -04:00
|
|
|
defines: functions.h files.h
|
2014-01-25 04:21:40 -05:00
|
|
|
$(CC) -dM -E $(NAME).c
|
|
|
|
|
2014-01-25 04:54:00 -05:00
|
|
|
|
|
|
|
#
|
|
|
|
# LOC
|
|
|
|
#
|
|
|
|
loc:
|
|
|
|
@wc -l *.c
|
|
|
|
|
2018-01-28 10:23:34 -05:00
|
|
|
|
|
|
|
#
|
|
|
|
# Fix copyright notes
|
|
|
|
#
|
|
|
|
copyright:
|
|
|
|
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
|
|
|
|
|