##
##  Makefile for mail/news gateway programs.
##  $Header: /nfs/papaya/u2/rsalz/src/newsgate/RCS/Makefile,v 1.18 91/07/22 10:26:34 rsalz Exp Locker: rsalz $
##
SHELL	= /bin/sh

##  The header-reader in rfc822 needs a date parser.  You have three choices:
##  1.  If you want to use the getdate.y routine (which has problems with
##	numeric timezones, among others), NEWSSRC to point to the
##	directory where you have a copy of it.  This routine came with B
##	News.
##  2.  If you want to use the C News getabsdate routine, comment out the
##	NEWSSRC and GETDATE lines; edit DATELIB to point to your C News
##	library (make sure your linker knows the difference between
##	Split and split!)and add -DUSE_GETABSDATE to DATEDEF.
##  3.  If you want to use the INN getdate routine, comment out the
##	NEWSSRC and GETDATE lines; edit DATELIB to point to your INN library
##	and add -DUSE_PARSEDATE to DATEDEF.
#NEWSSRC		= ../news2.11/src
#GETDATE		= getdate.o
#DATELIB		= ../cnews/libcnews.a
#DATEDEF		= -DUSE_GETABSDATE
DATELIB		= /usr/local/src/inn/libinn.a
DATEDEF		= -DUSE_PARSEDATE

##  Edit appropriately.  See gate.h before you touch UUCP_INET.
UUCP_INET	= /usr/lib/news/.admin/uucp-2-inet
DESTDIR		= /usr/uucp/bin
OPT		= -g
#OPT		= -O
DEFS		= $(DATEDEF)
CFLAGS		= $(OPT) $(DEFS)
LINKFLAGS	=
#LINKFLAGS	= -s -Bstatic

##  Get just filenames from a standard manifest.
SEDCOMMANDS = -e 1,2d -e '/(Directory)/d' -e 's/ .*//'

##  Gag, the gateway alias generator.
G_SRCS	= gag.c lex.c misc.c
G_OBJS	= gag.o lex.o misc.o

##  Mail2News, the mail into news part of the gateway.
M_SRCS	= misc.c regex.c hdr.c mail2news.c rfc822.c
M_OBJS	= misc.o regex.o hdr.o mail2news.o rfc822.o $(GETDATE)

##  News2Mail, the news into mail part of the gateway.
N_SRCS	= misc.c news2mail.c
N_OBJS	= misc.o news2mail.o

##  Manpages for the programs.
DOCS	= gag.1 mail2news.1 mkmailpost.1 news2mail.1 signoff.1

all:			mail2news news2mail gag mkmailpost tags lint

install:		all
	@echo "Install as directed in the README file."
#	@rm -f $(DESTDIR)/gag $(DESTDIR)/mail2news $(DESTDIR)/news2mail
#	cp gag mail2news news2mail $(DESTDIR)/.
#	cp uucp-2-inet $(UUCP_INET)

clean clobber:
	rm -f mail2news news2mail gag mkmailpost hdrtest *.o
	rm -f tags lint.? core gag.c gag.h lex.c
	rm -f Part0? newsgate.tar.Z


tags:			$(N_SRCS) $(M_SRCS)
	ctags -tw $(N_SRCS) $(M_SRCS) $(G_SRCS) gate.h

lint:			lint.d lint.g lint.m lint.n


##
mail2news:		$(M_OBJS)
	@rm -f mail2news
	$(CC) $(CFLAGS) $(LINKFLAGS) -o mail2news $(M_OBJS) $(DATELIB)

news2mail:		$(N_OBJS)
	@rm -f news2mail
	$(CC) $(CFLAGS) $(LINKFLAGS) -o news2mail $(N_OBJS)

gag:			$(G_OBJS)
	@rm -f gag
	$(CC) $(CFLAGS) $(LINKFLAGS) -o gag $(G_OBJS)

mkmailpost:		mkmailpost.sh
	@rm -f mkmailpost
	cp mkmailpost.sh mkmailpost
	chmod 755 mkmailpost

##
$(G_OBJS) $(M_OBJS) $(N_OBJS):	gate.h


##
lint.d:			$(DOCS)
	checknr -c.IR.BI.RI $(DOCS) regex.3 >lint.d
lint.g:			gag
	lint -a    -h $(DEFS) $(G_SRCS) |grep -v yaccpar >lint.g
lint.m:			mail2news
	lint -a -b -h $(DEFS) $(M_SRCS) >lint.m
lint.n:			news2mail
	lint -a -b -h $(DEFS) $(N_SRCS) >lint.n

##
TESTFILES	= hdr.c rfc822.o $(GETDATE)
hdrtest:		$(TESTFILES)
	@rm -f hdr.o hdrtest
	$(CC) -DTEST $(CFLAGS) $(LINKFLAGS) -o hdrtest $(TESTFILES) $(DATELIB)
	@rm -f hdr.o
	./hdrtest <test-addr

##  Keep intermediate files around.
lex.o:			lex.c
gag.o:			gag.c
gag.c:			gag.y
	@rm -f gag.c gag.h
	yacc -d gag.y
	@mv y.tab.c gag.c
	@mv y.tab.h gag.h


##  Distribution kits.
shar:
	@rm -f Part0?
	makekit -m
	@rm -f MANIFEST.BAK
	@touch Part0?
	@-chmod 444 Part0?
tar:
	@rm -f newsgate.tar.Z
	tar cf newsgate.tar `sed $(SEDCOMMANDS) <MANIFEST`
	compress newsgate.tar


##  Get the date parser from 2.11 news.
getdate.o:
	@rm -f getdate.o
	cd $(NEWSSRC) ; make getdate.o
	cp $(NEWSSRC)/getdate.o .

##  Saber stuff
.SUFFIXES: .c .o .src .obj
.c.src:
	#load $(CFLAGS) $<
.c.obj:
	#load $(CFLAGS) $<
saber:		$(SABER_SRC)
	#load $(CFLAGS) $(SABER_SRC)
