# -*- makefile -*-
# $Id: Makefile,v 1.16 1997/07/20 00:28:31 agulbra Exp $
SHELL = /bin/sh
CC = gcc
DEBUG = -g -Wall -Wformat -Wstrict-prototypes -Wmissing-prototypes 
CFLAGS = $(DEBUG)
LIBS = 
PREFIX_USR = /usr/local
PREFIX_VAR = /var
BINDIR = $(PREFIX_USR)/sbin
MANDIR = $(PREFIX_USR)/man
VERSION = 1.6.2
#
# this is the directory where the news is stored.
SPOOLDIR = $(PREFIX_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/lock/news/fetch.lck"

LIBFILES = nntputil.o configutil.o xoverutil.o activutil.o miscutil.o

all: libutil.a nntpd fetch texpire checkgroups

libutil.a: $(LIBFILES) leafnode.h
	$(AR) rc libutil.a $(LIBFILES)
	$(AR) s libutil.a

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

fetch: fetch.o config.o libutil.a
	$(CC) -o $@ fetch.o config.o libutil.a

texpire: texpire.o config.o libutil.a
	$(CC) -o $@ texpire.o config.o libutil.a

checkgroups: checkgroups.o config.o libutil.a
	$(CC) -o $@ checkgroups.o config.o libutil.a

nntpd.o: nntpd.c leafnode.h
	$(CC) -c $(CFLAGS) nntpd.c

fetch.o: fetch.c leafnode.h
	$(CC) -c $(CFLAGS) fetch.c

texpire.o: texpire.c leafnode.h
	$(CC) -c $(CFLAGS) texpire.c

checkgroups.o: checkgroups.c leafnode.h
	$(CC) -c $(CFLAGS) checkgroups.c

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

update:
	@./update.sh $(SPOOLDIR) $(LIBDIR)

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

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

install: nntpd fetch texpire checkgroups
	install -d -o root -g root -m 755 $(MANDIR)/man1
	install -d -o root -g root -m 755 $(MANDIR)/man8
	install -d -o root -g bin -m 755 $(BINDIR)
	install -g news -m 750 -o news -s nntpd $(BINDIR)/leafnode
	install -g news -m 750 -o news -s fetch $(BINDIR)/fetch
	install -g news -m 750 -o news -s texpire $(BINDIR)/texpire
	install -g news -m 750 -o news -s checkgroups $(BINDIR)/checkgroups
	cp *.8 $(MANDIR)/man8
	cp *.1 $(MANDIR)/man1
	-mkdir -p `dirname $(LOCKFILE)`
	chown news.news `dirname $(LOCKFILE)`
	-mkdir -p $(SPOOLDIR) $(LIBDIR)
	-mkdir -p $(SPOOLDIR)/leaf.node
	-mkdir -p $(SPOOLDIR)/{message.id,interesting.groups,out.going}
	-chown news.news $(SPOOLDIR) $(LIBDIR)
	-chown news.news $(SPOOLDIR)/leaf.node
	-chown news.news $(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 ; \
			chown news.news $${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)
	chmod 2755 $(SPOOLDIR)
	@echo Edit /etc/inetd.conf to start $(BINDIR)/leafnode and restart inetd
	@echo If you update from a leafnode version \< 1.6, do a "make update"

uninstall:
	-rm $(BINDIR)/{fetch,checkgroups,texpire,leafnode}
	-rm $(MANDIR)/man8/{fetch.8,checkgroups.8,texpire.8,leafnode.8}
	-rm $(MANDIR)/man1/newsq.1
	-rm -r $(LIBDIR)
	-rm -r $(SPOOLDIR)/leaf.node
	-rm -r $(SPOOLDIR)/interesting.groups
	-rm -r $(SPOOLDIR)/message.id/*
	-rmdir $(SPOOLDIR)/out.going
	@echo Edit /etc/inetd.conf to remove $(BINDIR)/leafnode and restart inetd

dist:
	mkdir -p leafnode-$(VERSION)
	cp *[a-z].8 newsq.1 leafnode.h *.c archivefaq.pl Makefile newsq \
		INSTALL README COPYING TODO CHANGES config.example \
		update.sh leafnode-$(VERSION).lsm \
		leafnode-$(VERSION)
	chmod 644 leafnode-$(VERSION)/*
	chmod 755 leafnode-$(VERSION)/update.sh
	chmod 755 leafnode-$(VERSION)/newsq
	tar cf leafnode-$(VERSION).tar leafnode-$(VERSION)
	gzip -f9 leafnode-$(VERSION).tar
	rm -rf leafnode-$(VERSION)

patch:
	rm -f ../leafnode-$(VERSION).patch
	rm -f ../leafnode-$(VERSION).patch.gz
	@for i in * ; \
	do \
	  if [ -e $$i.orig ] ; \
	  then \
	    echo "diff --unified $$i.orig $$i" ; \
	    diff --unified $$i.orig $$i >> ../leafnode-$(VERSION).patch ; \
	  fi ; \
	done
	gzip -f9 ../leafnode-$(VERSION).patch
# DO NOT DELETE
