# =()<NEWSARTS = @<NEWSARTS>@>()=
NEWSARTS = /usr/spool/news
# =()<NEWSBIN = @<NEWSBIN>@>()=
NEWSBIN = /usr/public/lib/news/bin
# =()<NEWSCTL = @<NEWSCTL>@>()=
NEWSCTL = /usr/public/lib/news
# workaround for System V make bug
SHELL = /bin/sh
NEWSUSER=news
NEWSGROUP=news
COPTS = -O
CFLAGS = $(COPTS) -I../include '-DNEWSUSER="$(NEWSUSER)"' '-DNEWSGROUP="$(NEWSGROUP)"'
LIBS = ../libcnews.a
LIBDIRS = libbig libbsd42 libc libcnews libfake \
	libsmall libstdio libusg libv7 libv8 dbz
DIRS = batch conf expire h hfake input $(LIBDIRS) misc relay rna
CMPDIRS = batch conf expire input man misc relay rna
RDIRS = batch dbz expire input relay
SHS = doit.root doit.bin doit.news again.root

PGMS = spacefor queuelen

all:	$(PGMS)
	chmod +x $(PGMS)
	-if test -r hostname ; then chmod +x hostname ; fi

bininstall:	$(PGMS)
	cp $(PGMS) $(NEWSBIN)
	-if test -r hostname ; then cp hostname $(NEWSBIN) ; fi
	: and build takes care of setnewsids if needed

pcmp:	$(PGMS)
	for f in $(PGMS) ; do cmp $(NEWSBIN)/$$f $$f ; done

cmp:
	: nothing

newsinstall:
	: build stuff does the real work

substs:	subst.hs subst.gc substitutions subst
	chmod +x subst
	: too late for h and hfake, include has already been built
	-egrep '^(h|hfake)/' subst.hs subst.gc >junk
	: so test to make sure they do not need it
	test ! -s junk ;
	rm -f junk
	./subst -f substitutions `sed 's;^;../;' subst.hs subst.gc`
	touch $@

spacefor.bsd:	spacefor.proto Makefile
	cp spacefor.proto $@

spacefor.v7:	spacefor.proto Makefile
	sed '/dfunit=/s/1024/512/;/nr = 2/s//nr = 1/;/nf = 4/s//nf = 2/;/stupid/d' spacefor.proto >$@

spacefor.sysv:	spacefor.proto Makefile
	sed '/dfunit=/s/1024/512/;/awk/s~|~| sed "s/.*:/: :/" |~;/nf = 4/s//nf = 3/;/stupid/s/4BSD/System V/' spacefor.proto >$@

spacefor.xenix:	spacefor.proto Makefile
	sed '/dfunit=/s/1024/512/;/awk/s~|~| sed "s/.*:/: :/" |~;/nr = 2/s//nr = 1/;/nf = 4/s//nf = 3/;/stupid/s/4BSD/Xenix/' spacefor.proto >$@

spacefor.sgi:	spacefor.proto Makefile
	sed '/dfunit=/s/1024/512/;/nf = 4/s//nf = 5/;/stupid/s/4BSD/SGI/' spacefor.proto >$@

spacefor.ultrix:	spacefor.proto Makefile
	sed '/nr = 2/s//nr = 3/;/stupid/s/4BSD/Ultrix/' spacefor.proto >$@

spacefor.null:	Makefile
	echo '#! /bin/sh' >$@
	echo 'echo 100' >>$@

queuelen.hdb:
	: okay

queuelen.sub:
	: okay

queuelen.old:
	: okay

queuelen.pre:	queuelen.old
	sed '/grade=d/s//grade=./' queuelen.old >$@

queuelen.null:
	echo '#! /bin/sh' >$@
	echo 'echo 0' >>$@

setnewsids:	setnewsids.o $(LIBS)
	$(CC) $(CFLAGS) $(LDFLAGS) setnewsids.o $(PRE) $(LIBS) $(POST) -o $@

../ranlibed:	../libcnews.a
	ranlib ../libcnews.a
	touch ../ranlibed

clean:
	rm -f spacefor.sysv spacefor.v7 spacefor.null queuelen.null
	rm -f spacefor.sgi spacefor.xenix queuelen.pre
	rm -f config mailname organization server whoami hostname errlog
	rm -f history history.pag history.dir active localgroups
	rm -f log mailpaths sys cron rc setnewsids setnewsids.o spacefor.bsd
	rm -rf replyusepath spacefor queuelen junk save

gclean:	tidy
	rm -f ../libcnews.a ../ranlibed
	rm -rf ../include

tidy:
	for d in $(DIRS) ; do cd ../$$d ; make clean ; done

spotless:	gclean
	rm -f $(SHS)
	rm -f substs substitutions

lclean:
	rm -f ../ranlibed
	for d in $(LIBDIRS) ; do cd ../$$d ; make clean ; done

cmps:
	for d in $(CMPDIRS) ; do cd ../$$d ; make cmp RBIN=/usr/lib/uucp/bin ; done

rs:
	for d in $(RDIRS) ; do cd ../$$d ; make r ; done

save:	$(SHS)
	mkdir save
	mv $(SHS) save

check:
	-for f in $(SHS) ; do diff save/$$f $$f ; done
