# -*- makefile -*-
# $Id: Makefile,v 1.16 1997/07/20 00:28:31 agulbra Exp $
CC = gcc
DEBUG = -g -Wall -Wformat -Wstrict-prototypes -Wmissing-prototypes 
CFLAGS = $(DEBUG)
LIBS = 
BINDIR = /usr/local/sbin
MANDIR = /usr/local/man
VERSION = 1.4
#
# this is the directory where the news is stored.
SPOOLDIR = /var/spool/news
#
# this is the directory where the configuration and group information is
# kept.  It should preferably not be on the same partition as spooldir
LIBDIR = /usr/lib/leafnode
#
# This is the lock file for fetch.  The normal locations for such lock
# files are /var/run or /var/lock.
LOCKFILE = "/var/run/news/fetch.lck"

all: nntpd fetch texpire checkgroups

nntpd: nntpd.o util.o config.o
	$(CC) -g -o $@ nntpd.o util.o config.o

fetch: fetch.o util.o config.o
	$(CC) -o $@ fetch.o util.o config.o

texpire: texpire.o util.o config.o
	$(CC) -o $@ texpire.o util.o config.o

checkgroups: checkgroups.o util.o config.o
	$(CC) -o $@ checkgroups.o util.o config.o

clean:
	-@rm -f *.o core nntpd fetch texpire checkgroups

depend:
	makedepend *.c 2> /dev/null

config.o: config.c Makefile
	$(CC) -c -DSPOOLDIR=\"$(SPOOLDIR)\" \
		-DLIBDIR=\"$(LIBDIR)\" \
		-DLOCKFILE=\"$(LOCKFILE)\" \
		-DVERSION=\"$(VERSION)\" $<

install: nntpd fetch texpire checkgroups
	cp nntpd $(BINDIR)/leafnode
	cp fetch $(BINDIR)/fetch
	cp texpire $(BINDIR)/texpire
	cp checkgroups $(BINDIR)/checkgroups
	cp *.8 $(MANDIR)/man8
	-mkdir -p /var/run/news
	chown news.news /var/run/news
	-mkdir -p $(SPOOLDIR) $(LIBDIR)
	-mkdir -p $(SPOOLDIR)/{message.id,interesting.groups,out.going}
	cd $(SPOOLDIR)/message.id ; for a in 0 1 2 3 4 5 6 7 8 9 ; do \
		for b in 0 1 2 3 4 5 6 7 8 9 ; do \
			mkdir -p $${a}$${b}0 $${a}$${b}1 $${a}$${b}2 \
				$${a}$${b}3 $${a}$${b}4 $${a}$${b}5 \
				$${a}$${b}6 $${a}$${b}7 $${a}$${b}8 \
				$${a}$${b}9 ; \
			done ; done
	cp config.example $(LIBDIR)
	chown -R news.news $(LIBDIR) $(SPOOLDIR)
	chmod 2750 $(SPOOLDIR)
	chmod 750 $(BINDIR)/{leafnode,fetch,texpire,checkgroups}
	chown news.news $(BINDIR)/{leafnode,fetch,texpire,checkgroups}
	@echo edit /etc/inetd.conf to start $(BINDIR)/leafnode

dist:
	mkdir leafnode-$(VERSION)
	sed 's/^VERSION *= *[0-9.]*/VERSION = '$(VERSION)'/' \
		 < Makefile > leafnode-$(VERSION)/Makefile
	cp *[a-z].8 leafnode.h INSTALL README COPYING config.example \
		nntpd.c texpire.c fetch.c checkgroups.c util.c config.c \
		archivefaq.pl newsq leafnode-$(VERSION)
	chmod 644 leafnode-$(VERSION)/*
	tar cf leafnode-$(VERSION).tar leafnode-$(VERSION)
	gzip -f9 leafnode-$(VERSION).tar
	rm -rf leafnode-$(VERSION)
