#
#	@(#)Makefile	3.20 (motonori/WIDE) 8/17/95
#
#	Makefile for generation of sendmail.cf files
#

# your object files (*.cf)
MYOBJS=

# if you have perl installed, perl will be used instead of sed.
PERL=		perl

WHICH=		Master/Which
PERLPATH=	`${WHICH} ${PERL}`

# sample.cf files
STDDIR=		Standards
OBJS=		${STDDIR}/sample-v1.cf ${STDDIR}/sample.cf \
		${STDDIR}/null-v1.cf ${STDDIR}/null.cf ${STDDIR}/nmtc.cf

# prototypes
MASTERDIR=	Master
OSTYPEDIR=	${MASTERDIR}/OSTYPE

PROTOS=		${MASTERDIR}/proto \
		${MASTERDIR}/proto.v1 \
		${MASTERDIR}/proto-null \
		${MASTERDIR}/proto-null.v1
FEATURES=	${MASTERDIR}/files \
		${MASTERDIR}/files.v1 \
		${MASTERDIR}/files-null \
		${MASTERDIR}/files-null.v1 \
		${MASTERDIR}/files.nmtc

# filters
FILTERDIR=	${MASTERDIR}
MKFILT=		${FILTERDIR}/Mkfilter
MKSAMPLE=	${FILTERDIR}/Mksample

# cf selector
CFSELECT=	cf_select

# default configuration reader
DEFAULT=	default

# for getting making information
MKINFO=		Mkinfo
THEMKINFO=	${FILTERDIR}/${MKINFO}

# variable confilicts checker
CONFLICT=	Checkenv
THECONFLICT=	${MASTERDIR}/${CONFLICT}

# automatically generated files
TOOLDIR=	Tools
CONFIG=		${TOOLDIR}/Configure
CLEANUP=	Cleanup
THECLEANUP=	${TOOLDIR}/${CLEANUP}

# sample definition files
SAMPLES=	${STDDIR}/sample.def \
		${STDDIR}/sample-v1.def \
		${STDDIR}/null.def \
		${STDDIR}/null-v1.def \
		${STDDIR}/nmtc.def

# version information
VERSION=	${MASTERDIR}/version
VINFO=		VERSION

# for packaging
PACKAGE=	`expr $$PWD : '.*/\([^/]*\)'`
TAR=		/bin/tar cvfF -
COMPRESS=	gzip
SUFFIX=		.tar.gz

###

samples:	${SAMPLES}

tools:		${CONFIG} ${THECLEANUP}

all:	samples ${OBJS} ${MYOBJS}

clean:
	rm -f ${OBJS} ${MYOBJS}

cleantools:
	rm -f ${CONFIG} ${THECLEANUP}

cleanall:
	rm -f ${CONFIG} ${THECLEANUP} ${SAMPLES} ${OBJS} ${MYOBJS}

conflict:
	(cd ${MASTERDIR}; ./${CONFLICT})

mode:
	test -x ${MKFILT} || chmod +x ${MKFILT}
	test -x ${MKSAMPLE} || chmod +x ${MKSAMPLE}
	test -x ${THECONFLICT} || chmod +x ${THECONFLICT}
	test -x ${WHICH} || chmod +x ${WHICH}

${VINFO}:	mode samples ${OBJS}
	echo -n "version: " > ${VINFO}
	grep '^: $${VERSION=' ${VERSION} | sed 's/.*=\(.*\)}.*/\1/' >> ${VINFO}
	echo "package:" ${PACKAGE} >> ${VINFO}
	echo -n "packed: " >> ${VINFO}
	date >> ${VINFO}

${CONFIG} ${THECLEANUP}:	${MKFILT} ${PROTOS} \
		${MASTERDIR}/* ${OSTYPEDIR}/*
	MASTERDIR=${MASTERDIR} TOOLDIR=${TOOLDIR} CLEANUP=${CLEANUP} \
	CONFIG=${CONFIG} CFSELECT=${CFSELECT} MKINFO=${MKINFO} \
	DEFAULT=${DEFAULT} PERL=${PERLPATH} ${MKFILT} ${PROTOS}
	make conflict

dist:	${VINFO}
	(cd ..; ${TAR} ${PACKAGE} | ${COMPRESS} > ${PACKAGE}${SUFFIX})

.SUFFIXES: .cf .def .in

.def.cf:
	MASTER=${MASTERDIR} TOOLS=${TOOLDIR} \
	${CONFIG} $< > $@.tmp
	mv -f $@.tmp $@

.in.def:
	MASTERDIR=${MASTERDIR} TOOLDIR=${TOOLDIR} \
	${MKSAMPLE} $< > $@.tmp
	mv -f $@.tmp $@

${OBJS} ${MYOBJS}:	${CONFIG} ${THECLEANUP} ${THEMKINFO} ${PROTOS} \
			${MASTERDIR}/* ${OSTYPEDIR}/*

${SAMPLES}:	${PROTOS} ${FEATURES} ${MASTERDIR}/* ${OSTYPEDIR}/*

depend:
	mv -f Makefile Makefile.bak
	sed -n '1,/^# DO NOT DELETE THIS LINE/p' Makefile.bak > Makefile
	echo >> Makefile
	-(for i in ${MYOBJS} ; do\
		sed -n -e '/^$$/d' -e '/^#/d' -e 's/^.*FILE=//p' \
		`basename $$i .cf`.def | sed 's/#.*$$//' \
		| sed '/\/tmp\//d' \
		| sort -u | xargs echo $$i: >> Makefile ; \
	done)

# DO NOT DELETE THIS LINE -- make depend uses it

