##  $Revision: 1.21 $
SHELL	= /bin/sh
MAKE	= make
LINT	= lint
DESTDIR	=
D	= $(DESTDIR)
##  =()<P	= @<P>@>()=
P	= 

##  =()<CC	= @<CC>@>()=
CC	= gcc
##  =()<DEFS	= @<DEFS>@>()=
DEFS	= -I../include
##  =()<CFLAGS	= @<CFLAGS>@>()=
CFLAGS	= $(DEFS) -g
##  =()<LDFLAGS	= @<LDFLAGS>@>()=
LDFLAGS	= 
##  =()<LINTFLAGS	= @<LINTFLAGS>@>()=
LINTFLAGS	= -b -h -z $(DEFS)
##  =()<LINTFILTER	= @<LINTFILTER>@>()=
LINTFILTER	= | sed -n -f ../sedf.sun
##  =()<CTAGS		= @<CTAGS>@>()=
CTAGS		= ctags -t -w
##  =()<PROF	= @<PROF>@>()=
PROF	= -pg

##  =()<NEWSBIN	= @<_PATH_NEWSBIN>@>()=
NEWSBIN	= /usr/news/bin
## =()<OWNER	= -O @<NEWSUSER>@ -G @<NEWSGROUP>@>()=
OWNER	= -O news -G news

##  =()<LIBS	= @<LIBS>@>()=
LIBS	= -lutil
LIBNEWS	= ../libinn.a
LINTLIB	= ../llib-linn.ln

SOURCES	=	convdate.c expire.c expireover.c fastrm.c grephistory.c \
		makeactive.c makehistory.c newsrequeue.c prunehistory.c
ALL	=	convdate expire expireover fastrm grephistory \
		makeactive makehistory newsrequeue prunehistory

all:		$(ALL)

install:	$D$(NEWSBIN)/convdate $D$(NEWSBIN)/expire \
		$D$(NEWSBIN)/expireover $D$(NEWSBIN)/fastrm \
		$D$(NEWSBIN)/grephistory $D$(NEWSBIN)/makeactive \
		$D$(NEWSBIN)/makehistory $D$(NEWSBIN)/newsrequeue \
		$D$(NEWSBIN)/prunehistory

clobber clean:
	rm -f *.o $(ALL)
	rm -f expirep expireoverp profiled
	rm -f all install lint

tags ctags:	$(SOURCES)
	$(CTAGS) $(SOURCES) ../lib/*.c ../include/*.h

convdate:	$(P) convdate.o $(LIBNEWS)
	$(CC) $(LDFLAGS) -o $@ convdate.o $(LIBNEWS) $(LIBS)

expire:		$(P) expire.o dbz.o $(LIBNEWS)
	$(CC) $(LDFLAGS) -o $@ expire.o dbz.o $(LIBNEWS) $(LIBS)

expireover:	$(P) expireover.o $(LIBNEWS)
	$(CC) $(LDFLAGS) -o $@ expireover.o $(LIBNEWS) $(LIBS)

fastrm:	$(P) fastrm.o $(LIBNEWS)
	$(CC) $(LDFLAGS) -o $@ fastrm.o $(LIBNEWS) $(LIBS)

grephistory:	$(P) grephistory.o $(LIBNEWS)
	$(CC) $(LDFLAGS) -o $@ grephistory.o $(LIBNEWS) $(LIBS)

makeactive:	$(P) makeactive.o $(LIBNEWS)
	$(CC) $(LDFLAGS) -o $@ makeactive.o $(LIBNEWS) $(LIBS)

makehistory:	$(P) makehistory.o dbz.o $(LIBNEWS)
	$(CC) $(LDFLAGS) -o $@ makehistory.o dbz.o $(LIBNEWS) $(LIBS)

newsrequeue:	$(P) newsrequeue.o $(LIBNEWS)
	$(CC) $(LDFLAGS) -o $@ newsrequeue.o $(LIBNEWS) $(LIBS)

prunehistory:	$(P) prunehistory.o $(LIBNEWS)
	$(CC) $(LDFLAGS) -o $@ prunehistory.o $(LIBNEWS) $(LIBS)

lint:		$(ALL)
	@rm -f lint
	-$(LINT) $(LINTFLAGS) convdate.c     $(LINTLIB) $(LINTFILTER)  >lint
	-$(LINT) $(LINTFLAGS) expire.c       $(LINTLIB) $(LINTFILTER) >>lint
	-$(LINT) $(LINTFLAGS) expireover.c   $(LINTLIB) $(LINTFILTER) >>lint
	-$(LINT) $(LINTFLAGS) fastrm.c       $(LINTLIB) $(LINTFILTER) >>lint
	-$(LINT) $(LINTFLAGS) grephistory.c  $(LINTLIB) $(LINTFILTER) >>lint
	-$(LINT) $(LINTFLAGS) makeactive.c   $(LINTLIB) $(LINTFILTER) >>lint
	-$(LINT) $(LINTFLAGS) makehistory.c  $(LINTLIB) $(LINTFILTER) >>lint
	-$(LINT) $(LINTFLAGS) newsrequeue.c  $(LINTLIB) $(LINTFILTER) >>lint
	-$(LINT) $(LINTFLAGS) prunehistory.c $(LINTLIB) $(LINTFILTER) >>lint

# Build our own version of dbz.o for expire and makehistory, to avoid
# any -DMMAP in DBZCFLAGS - using mmap() for dbz in expire can slow it
# down really bad, and has no benefits as it pertains to the *new* .pag.
dbz.o:		../lib/dbz.c
	$(CC) $(CFLAGS) -c ../lib/dbz.c

../include/dbz.h:
	(cd ../lib ; $(MAKE) ../include/dbz.h)
$(LIBNEWS) $(LINTLIB):
	(cd ../lib ; $(MAKE) install)

##  Profiling.  The rules are a bit brute-force, but good enough.
profiled:	expirep expireoverp
	date >$@

NEWFLAGS	= CFLAGS="$(CFLAGS) $(PROF)" LDFLAGS="$(LDFLAGS) $(PROF)"

expirep:	expire.c
	rm -f expire.o
	$(MAKE) expire $(NEWFLAGS) LIBNEWS=../libinn_p.a
	mv expire expirep
	rm -f expire.o

expireoverp:	expireover.c
	rm -f expireover.o
	$(MAKE) expireover $(NEWFLAGS) LIBNEWS=../libinn_p.a
	mv expireover expireoverp
	rm -f expireover.o

##
.SUFFIXES: .c .src
.c.src:
	#load $(CFLAGS) $<

##  Low-level install actions.
$D$(NEWSBIN)/convdate:		convdate
	$(SHELL) ../installit.sh $(OWNER) -m 0555 -b .OLD $? $@
$D$(NEWSBIN)/expire:		expire
	$(SHELL) ../installit.sh $(OWNER) -m 0555 -b .OLD $? $@
$D$(NEWSBIN)/expireover:		expireover
	$(SHELL) ../installit.sh $(OWNER) -m 0555 -b .OLD $? $@
$D$(NEWSBIN)/fastrm:		fastrm
	$(SHELL) ../installit.sh $(OWNER) -m 0555 -b .OLD $? $@
$D$(NEWSBIN)/grephistory:	grephistory
	$(SHELL) ../installit.sh $(OWNER) -m 0555 -b .OLD $? $@
$D$(NEWSBIN)/makeactive:	makeactive
	$(SHELL) ../installit.sh $(OWNER) -m 0555 -b .OLD $? $@
$D$(NEWSBIN)/makehistory:	makehistory
	$(SHELL) ../installit.sh $(OWNER) -m 0555 -b .OLD $? $@
$D$(NEWSBIN)/newsrequeue:	newsrequeue
	$(SHELL) ../installit.sh $(OWNER) -m 0555 -b .OLD $? $@
$D$(NEWSBIN)/prunehistory:	prunehistory
	$(SHELL) ../installit.sh $(OWNER) -m 0555 -b .OLD $? $@

##  Dependencies.  Default list, below, is probably good enough.
depend:		Makefile $(SOURCES)
	makedepend $(DEFS) $(SOURCES)

# DO NOT DELETE THIS LINE -- make depend depends on it.
convdate.o:	../include/clibrary.h
convdate.o:	../include/configdata.h
convdate.o:	../include/libinn.h
convdate.o:	../include/macros.h
dbz.o:		../include/dbz.h
expire.o:	../include/clibrary.h
expire.o:	../include/configdata.h
expire.o:	../include/dbz.h
expire.o:	../include/inndcomm.h
expire.o:	../include/libinn.h
expire.o:	../include/macros.h
expire.o:	../include/paths.h
expire.o:	../include/qio.h
expireover.o:	../include/clibrary.h
expireover.o:	../include/configdata.h
expireover.o:	../include/libinn.h
expireover.o:	../include/macros.h
expireover.o:	../include/mydir.h
expireover.o:	../include/paths.h
expireover.o:	../include/qio.h
fastrm.o:	../include/clibrary.h
fastrm.o:	../include/configdata.h
fastrm.o:	../include/libinn.h
fastrm.o:	../include/macros.h
fastrm.o:	../include/mydir.h
grephistory.o:	../include/clibrary.h
grephistory.o:	../include/configdata.h
grephistory.o:	../include/dbz.h
grephistory.o:	../include/libinn.h
grephistory.o:	../include/macros.h
grephistory.o:	../include/paths.h
makeactive.o:	../include/clibrary.h
makeactive.o:	../include/configdata.h
makeactive.o:	../include/libinn.h
makeactive.o:	../include/macros.h
makeactive.o:	../include/mydir.h
makeactive.o:	../include/paths.h
makehistory.o:	../include/clibrary.h
makehistory.o:	../include/configdata.h
makehistory.o:	../include/dbz.h
makehistory.o:	../include/libinn.h
makehistory.o:	../include/macros.h
makehistory.o:	../include/paths.h
makehistory.o:	../include/qio.h
newsrequeue.o:	../include/clibrary.h
newsrequeue.o:	../include/configdata.h
newsrequeue.o:	../include/dbz.h
newsrequeue.o:	../include/libinn.h
newsrequeue.o:	../include/macros.h
newsrequeue.o:	../include/paths.h
newsrequeue.o:	../include/qio.h
prunehistory.o:	../include/clibrary.h
prunehistory.o:	../include/configdata.h
prunehistory.o:	../include/dbz.h
prunehistory.o:	../include/libinn.h
prunehistory.o:	../include/macros.h
prunehistory.o:	../include/paths.h
prunehistory.o:	../include/paths.h
