#
# Makefile for antibadmail
#
# $Id: Makefile,v 1.16 2007/05/31 02:04:48 yuuji Exp yuuji $
#

CC	= gcc
D_FLAGS	= -DSYSLOG -g -DHEADER_REGEX
CFLAGS	= `cat CFLAGS`
OBJ	= antibadmail.o h.o r.o q.o s.o rq.o
LIB	= `cat resolv.lib` `cat nsl.lib`
PREFIX	= `cat PREFIX`
INSTALL	= cp -p
# INSTALL	= install -cs
TARGET	= antibadmail f2d
CVSREP	= :pserver:anonymous@yatex.org:/qmail

all: ${TARGET} q
clean:
	for f in `awk -F: '/^[.a-z0-9]*:/ {print $$1}'  Makefile \
		| egrep -v 'all|clean|install|spamdb'`; do \
	 rm -f $$f; done

distclean:
	-@make clean
	rm -f PREFIX CFLAGS
antibadmail:	CFLAGS ${OBJ} nsl.lib resolv.lib
	${CC} -g -o $@ ${OBJ} ${LIB}

antibadmail.o:	antibadmail.c antibadmail.h r.h
f2d:		f2d.c
		${CC} -g -o $@ f2d.c
h.o:		h.c h.h
r.o:		r.c r.h
q.o:		q.c CFLAGS
s.o:		s.c s.h
rq.o:		rq.c antibadmail.h

r:	r.c
	${CC} ${CFLAGS} -DR_MAIN_ -o r r.c

s:	s.c s.h
	${CC} ${CFLAGS} -DS_MAIN_ -o s -g s.c

q:	antibadmail.h s.o q.c CFLAGS
	${CC} ${CFLAGS} -DQ_MAIN_ -o q q.c s.o

h:	antibadmail.h s.c h.c
	${CC} ${CFLAGS} -DH_MAIN_ -o h h.c s.c

rqtest:	rq.c antibadmail.h s.o
	${CC} ${CFLAGS} -DRQ_TEST -o $@ rq.c s.o

nsl.lib:	nsl.c
	(${CC} -o nsl nsl.c -lsocket -lnsl >/dev/null 2>&1 \
	  && echo -lsocket -lnsl || exit 0 ) > $@
	rm -f nsl

resolv.lib:	nsl.c
	(${CC} -o nsl nsl.c -lresolv >/dev/null 2>&1 \
	  && echo -lresolv || exit 0 ) > $@
	rm -f nsl

nsl.c:
	echo "main(){}" > nsl.c

config:
	./setup
CFLAGS:	PREFIX
	./setup CFLAGS
PREFIX:	Makefile
	./setup

nullsmtpd:	nullsmtpd.c

install:	all
	-[ -d ${PREFIX}/bin ] || mkdir -p ${PREFIX}/bin
	-[ -d ${PREFIX}/control ] || mkdir -p ${PREFIX}/control
	for f in ${TARGET}; do \
	 ${INSTALL} $$f ${PREFIX}/bin; done

install-spamdb:	spamdb
	if [ -d spamdb ]; then \
		tar cf - spamdb | (cd ${PREFIX}/control; tar xpf -) && \
		(cd ${PREFIX}/control/spamdb && \
		 make > /dev/null 2>&1 && \
		 cd .. && for d in helo mailfrom rcptto; do\
			    ln -s spamdb/bad$${d}dir .; done) \
	fi


spamdb:
	-cvs -d ${CVSREP} -z1 -q co spamdb

# $Id: Makefile,v 1.16 2007/05/31 02:04:48 yuuji Exp yuuji $
