# makefile for C news relaynews

# =()<NEWSARTS = @<NEWSARTS>@>()=
NEWSARTS = /usr/spool/news
# =()<NEWSBIN = @<NEWSBIN>@>()=
NEWSBIN = /usr/lib/newsbin
# =()<NEWSCTL = @<NEWSCTL>@>()=
NEWSCTL = /usr/lib/news
# workaround for System V make bug
SHELL = /bin/sh

BIN=/bin
NPROC=2
# -DVOID=int for libc.h & old lint libraries
DEFINES= -I../include -I. -DVOID=int -DFLUSHEVERY=6
#CC=CC +V
#CC=gcc -ansi -pedantic -Wall -S
#CC=redcc
COPTS= -O # -pg -g
CFLAGS=$(DEFINES) $(COPTS)
DBM = -ldbm
LIBS= $(DBM)
LINT=lint
LINTFLAGS=-haz $(DEFINES)
LLIBS=-llocal
# I wish I could make lint shut the fk up about some things.  Grrr!
LINTFILT=egrep -v '(possible pointer|long assign|can.t take|never used|nnfree|g
tdate|:$$)'
PROPTS=
P=stpr
PP=pp -Tpsc -fR # lazywriter
PPBACK=dps | stps # lazywriter

LIBOBJS=../libcnews.a
SRC=relaynews.c active.c article.c caches.c mkdirs.c control.c fileart.c \
	hdrdefs.c hdrcommon.c hdrparse.c hdrmunge.c \
	history.c io.c msgs.c procart.c \
	sys.c transmit.c trbatch.c ihave.c $(LIBSRCS)
OBJ=relaynews.o active.o article.o caches.o mkdirs.o control.o fileart.o \
	hdrdefs.o hdrcommon.o hdrparse.o hdrmunge.o \
	history.o io.o msgs.o procart.o \
	sys.o transmit.o trbatch.o ihave.o $(LIBOBJS)
FILES=$(NONCFILES) $(CFILES)
NONCFILES= TODO* README ads/README ads/[0-9]* \
	sh/inews sh/tear sh/anne.jones sh/defhdrs.awk \
	sh/realrnews sh/serverrnews makefile
CFILES= ../include/*.h \
	active.h article.h caches.h mkdirs.h control.h cpu.h fileart.h \
	hdrint.h headers.h history.h system.h transmit.h trbatch.h $(SRC)

all: makefile relaynews

mkfile: makefile
	sed '/mkfile/d' makefile | mkconv | sed 's/make/mk/g' >$@

relaynews: $(OBJ)
	$(CC) $(CFLAGS) $(OBJ) $(LIBS) $(LIBOBJS) -o $@
lint: $(SRC)
	$(LINT) $(LINTFLAGS) $(SRC) $(LLIBS) | $(LINTFILT)
lint-p: $(SRC)
	$(LINT) $(LINTFLAGS) -p $(SRC) $(LLIBS) | $(LINTFILT)

newsinstall:
	: nothing

# bininstall: make directories, install programs
bininstall: install
install: $(NEWSBIN)/relay/relaynews
$(NEWSBIN)/relay/relaynews: relaynews
	-mkdir $(NEWSBIN)/relay $(NEWSBIN)/inject $(NEWSBIN)/ctl
	cp relaynews $(NEWSBIN)/relay
	: needs to be news-owned, setuid -- build looks after that
	chmod +x sh/* aux/* ctl/*
	cp sh/* $(NEWSBIN)/inject
	cp ctl/* $(NEWSBIN)/ctl
	cp aux/* $(NEWSBIN)/relay
	cp sh/postnews sh/inews $(BIN)

TODO.grep: TODO
	-egrep TODO ../include/*.h *.h *.c sh/* | tr -s " \11" " " >$@
	-egrep TODO ../lib*/*.[ch] | tr -s " \11" " " >>$@

v7 v8 v9 usg bsd42:
	test -d libos && exit 1
	mv lib$@ libos # or ln -s lib$@ libos
	make

print: printc printnonc
	touch $@
printc: $(CFILES)
	$(PP) $? | $(PPBACK)
	touch $@
printnonc: $(NONCFILES)
	pr $(PROPTS) $? | $P
	touch $@
distr: $(FILES)
	(echo relaynews update of `date`; echo ""; bundle $?) | /bin/mail cnews-update

	touch $@
clean:
	rm -f core a.out relaynews *.o
	
# header dependencies follow
active.o: ../include/libc.h ../include/news.h ../include/config.h
active.o: active.h
article.o: ../include/news.h article.h headers.h
caches.o: ../include/news.h active.h caches.h transmit.h
mkdirs.o: ../include/libc.h ../include/news.h
control.o: ../include/libc.h ../include/news.h ../include/config.h
control.o: headers.h article.h caches.h history.h
fileart.o: ../include/libc.h ../include/news.h ../include/config.h
fileart.o: active.h mkdirs.h headers.h article.h history.h system.h
hdrcommon.o: ../include/news.h headers.h hdrint.h
hdrdefs.o: ../include/news.h headers.h hdrint.h
hdrmunge.o: ../include/libc.h ../include/news.h fileart.h headers.h
hdrmunge.o: article.h hdrint.h
hdrparse.o: ../include/libc.h ../include/news.h headers.h hdrint.h
history.o: ../include/libc.h ../include/news.h ../include/config.h
history.o: ../include/fgetmfs.h headers.h article.h history.h
hostname.o: ../include/news.h ../include/config.h
ihave.o: ../include/libc.h ../include/news.h ../include/config.h
ihave.o: headers.h article.h caches.h history.h
io.o: ../include/news.h headers.h article.h
msgs.o: ../include/news.h headers.h article.h
procart.o: ../include/libc.h ../include/news.h active.h control.h
procart.o: headers.h article.h history.h system.h
relaynews.o: ../include/libc.h ../include/news.h ../include/config.h
relaynews.o: ../include/fgetmfs.h active.h caches.h cpu.h headers.h
relaynews.o: history.h
string.o: ../include/libc.h ../include/news.h
sys.o: ../include/libc.h ../include/fgetmfs.h ../include/news.h
sys.o: ../include/config.h system.h
transmit.o: ../include/libc.h ../include/news.h ../include/config.h
transmit.o: headers.h active.h article.h system.h trbatch.h transmit.h
trbatch.o: ../include/libc.h ../include/news.h trbatch.h
