# makefile for C news relaynews

# =()<NEWSARTS = @<NEWSARTS>@>()=
NEWSARTS = /usr/spool/news
# =()<NEWSBIN = @<NEWSBIN>@>()=
NEWSBIN = /usr/local/lib/news/bin
# =()<NEWSCTL = @<NEWSCTL>@>()=
NEWSCTL = /usr/local/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
COPTS= -O # -pg -g -O
CFLAGS=$(DEFINES) $(COPTS)
DBM = # -ldbm
LIBS= $(DBM)
LINT=lint
LINTFLAGS=-haz $(DEFINES)
LLIBS= # -lmalloc
# I wish I could make lint shut the fk up about some things.  Grrr!
LINTFILT=egrep -v '(possible pointer|long assign|nnfree|getdate|:$$)'
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 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 hdrparse.o hdrmunge.o \
	history.o io.o msgs.o procart.o \
	sys.o transmit.o trbatch.o ihave.o
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 fileart.h \
	hdrint.h headers.h history.h system.h transmit.h trbatch.h $(SRC)

all: makefile relaynews
	chmod +x sh/[a-z]* aux/[a-z]* ctl/[a-z]*

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

relaynews: $(OBJ) $(LIBOBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) $(PRE) $(LIBS) $(LIBOBJS) $(POST) -o $@
lint: $(SRC)
	$(LINT) $(LINTFLAGS) $(SRC) $(LLIBS) 2>&1 | $(LINTFILT)
lint-p: $(SRC)
	$(LINT) $(LINTFLAGS) -p $(SRC) $(LLIBS) 2>&1 | $(LINTFILT)

newsinstall:	$(NEWSBIN)/inject/inews
	rm -f $(NEWSCTL)/inews
	ln $(NEWSBIN)/inject/inews $(NEWSCTL)/inews 2>/dev/null || cp sh/inews $(NEWSCTL)

# bininstall: make directories, install programs
bininstall: install
install: $(NEWSBIN)/relay/relaynews
$(NEWSBIN)/relay/relaynews: relaynews
	-mkdir $(NEWSBIN)/relay $(NEWSBIN)/inject $(NEWSBIN)/ctl
	cp sh/[a-z]* $(NEWSBIN)/inject
	cp ctl/[a-z]* $(NEWSBIN)/ctl
	cp aux/[a-z]* $(NEWSBIN)/relay
	rm -f $(BIN)/inews
	ln $(NEWSBIN)/inject/inews $(BIN)/inews 2>/dev/null || cp sh/inews $(BIN)
	rm -f $(NEWSBIN)/relay/relaynews
	cp relaynews $(NEWSBIN)/relay
	: needs to be news-owned, setuid -- build looks after that

cmp:	relaynews
	cmp $(NEWSBIN)/relay/relaynews relaynews
	for f in `../xls sh` ; do cmp $(NEWSBIN)/inject/$$f sh/$$f ; done
	for f in `../xls ctl` ; do cmp $(NEWSBIN)/ctl/$$f ctl/$$f ; done
	for f in `../xls aux` ; do cmp $(NEWSBIN)/relay/$$f aux/$$f ; done
	cmp $(BIN)/inews sh/inews
	cmp $(NEWSCTL)/inews sh/inews
	ls -lg $(NEWSBIN)/relay/relaynews | egrep -s '^-rwsrwsr-x  1 news     news'

check:	relaynews
	cmp $(NEWSBIN)/relay/relaynews relaynews || true
	for f in `../xls sh` ; do cmp $(NEWSBIN)/inject/$$f sh/$$f || true ; done
	for f in `../xls ctl` ; do cmp $(NEWSBIN)/ctl/$$f ctl/$$f || true ; done
	for f in `../xls aux` ; do cmp $(NEWSBIN)/relay/$$f aux/$$f || true ; done
	cmp $(BIN)/inews sh/inews || true
	cmp $(NEWSCTL)/inews sh/inews || true
	ls -lg $(NEWSBIN)/relay/relaynews | egrep -s '^-rwsrwsr-x  1 news     news'

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

print: printc printnonc
	touch $@
printc: $(CFILES)
	$(PP) $? | $(PPBACK)
	touch $@
printnonc: $(NONCFILES)
	pr $(PROPTS) $? | $P
	touch $@
clean:
	rm -rf core a.out relaynews *.o	regress/tmp

r:	relaynews
	chmod +x regress/regress
	(cd regress; ./regress)
	
# 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
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 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
