#!/bin/make -f
# @(#)pd/binmail/Makefile	1.7 9/6/92 04:39:40
#
# Makefile for binmail
#
# IMPORTANT NOTE:  Due to potential problems with installing binmail,
#		   binmail in not built or installed by higher level
#		   makefiles.  Read LMAIL comments in EDITME-dist
#		   and build/install binmail by hand if you want to.

SHELL=/bin/sh
MAKE=make
GET=sccs get
AR=ar
LINT=lint
CLEAN=sccs clean
MK=${MAKE} -${MAKEFLAGS} SHELL=${SHELL}
SRC_PREFIX=
MKDEPEND=${ROOT}/conf/lib/mkdepend.sh
MKDEFS=${ROOT}/conf/lib/mkdefs.sh
CHECKDEFS=${ROOT}/conf/lib/checkdefs.sh
MKDIRS=${ROOT}/conf/lib/mkdefs.sh
INST=${ROOT}/conf/lib/inst.sh
INSTM=${ROOT}/conf/lib/instm.sh
XEXEC=${SHELL} ${ROOT}/conf/lib/xexec.sh
DEFS_SH=defs.sh
DEFS_H=defs.h
DEFS_SED=defs.sed

ROOT=../..
SMAILSRC=${ROOT}/src
TARGETS=binmail
CSRC=binmail.c
MISCSRC=Makefile
SRC=${CSRC} ${MISCSRC}
OBJ=binmail.o

all:	${TARGETS}

binmail: binmail.o ${DEFS_SH}
	@. ./${DEFS_SH}; if [ -z "$$LMAIL" ]; then \
	    echo "LMAIL not defined in EDITME, can not make binmail"; \
	    exit 1; \
	fi
	@. ./${DEFS_SH}; ${XEXEC} $$CC $$CFLAGS $$LDFLAGS binmail.o -o \
		binmail $$LIBS

binmail.o: binmail.c ${DEFS_SH}
	@. ./${DEFS_SH}; \
	   case "$$LMAIL" in \
	   '')	echo "LMAIL not defined in EDITME, can not make binmail"; \
		exit 0;; \
	   esac; \
	   ${XEXEC} $$CC $$CFLAGS $$INCLUDES -c binmail.c

sources: ${SRC}

${SRC}:
	${GET} $@

${DEFS_H} ${DEFS_SH} ${DEFS_SED}: ${MISCSRC}
	ROOT=${ROOT} ${SHELL} ${MKDEFS}

names:
	@for i in ${SRC}; do echo ${SRC_PREFIX}$$i; done

depend local_depend: ${SRC} check_defs
	. ./${DEFS_SH}; \
		${XEXEC} ${SHELL} ${MKDEPEND} $$CPPFLAGS $$INCLUDES \
		Makefile ${CSRC}
	. ./${DEFS_SH}; echo "$$DEFS_DEPEND" >> Makefile
	chmod -w Makefile

check_defs:
	SHELL=${SHELL} ROOT=${ROOT} ${SHELL} ${CHECKDEFS}

# install with care!
#
install: ${UTIL_TARGETS} ${DEFS_SH}
	@. ./${DEFS_SH}; \
	   case "$$DONT_INSTALL" in \
	   ?*)	echo Testing ... install ignored; exit 0;;\
	   esac; \
	   case "$$LMAIL" in \
	   '')	echo LMAIL not defined in EDITME, binmail not installed; \
		exit 0;;\
	   esac; \
	   ${SHELL} -c "if [ -f $$LMAIL ]; then \
	     echo $$LMAIL already exists, it is the old /bin/mail program'?'; \
	     echo perhaps you should copy $$LMAIL back to /bin/mail'?'; \
	     echo install not done to be on the safe side; \
	   else \
	     ${XEXEC} mv /bin/mail /bin/lmail; \
	     ${XEXEC} ${SHELL} ${INST} -m 0555 binmail /bin/mail; \
	   fi"

clean:
	rm -f ${DEFS_SH} ${DEFS_H} ${DEFS_SED}
	rm -f ${OBJ} core a.out

clobber: clean
	rm -f ${TARGETS}

nuke:	clobber
	-${CLEAN}
	-${GET} Makefile

# DO NOT REMOVE THIS LINE, OR "make depend" WILL NOT WORK
