# Makefile for  PGPsendmail  by  Richard Gooch
#
###############################################################################
#			Configuration Section
#
# The SENDMAIL line should be uncommented if you don't have privilege to
# replace  /usr/lib/sendmail  .You will then need to manually install
# PGPsendmail somewhere and make sure your Mail User Agent is told to use
# PGPsendmail instead of  /usr/lib/sendmail or wherever your sendmail is.
# For EMACS ViewMail, you might add the following to your  ~/.emacs  file:
# (setq sendmail-program "/user/fred/pgp/bin/pgpsendmail")
# If you do have privilege, make sure the SENDMAIL line is commented out,
# otherwise your machine will be rooted (ask an Australian what that means;-).
# Check this for every new version of PGPsendmail/Unix
#
#SENDMAIL = -DUSE_OLD_SENDMAIL

# Some systems don't have a paths.h file, which means that you have to work out
# the location of sendmail and the system spool area. The following section
# should be uncommented and configured if you get a compiler error complaining
# about missing paths.h
#
#NO_PATH_H = -DNO_PATH_H
#PATH_SENDMAIL = '-D_PATH_SENDMAIL="/usr/lib/sendmail"'
#PATH_MAILDIR = '-D_PATH_MAILDIR="/var/spool/mail"'

# Any extra definitions you want (these can be passed on the command line)
#
DEFINES =

# Where do your manpages reside?
#
MANDIR = /usr/man


# Various compilers: if you have problems compiling, you may comment out the
# generic one and uncomment the one that's right for you. If you create you own
# please send me a patch

# Generic ANSI compiler
CC = cc

# HP/UX compiler
#CC = cc -Aa -D_HPUX_SOURCE

# System with no ANSI compiler other than gcc
#CC = gcc


# Maybe you want debugging instead, or more optimisation?
COPTIMISE = -O

###############################################################################
#			No user servicable parts below
#
CFLAGS = $(DEFINES) -Iinclude $(COPTIMISE) $(NO_PATH_H) $(PATH_SENDMAIL) \
	$(PATH_MAILDIR)

LDFLAGS = -s $(COPTIMISE) -Llib -lpgpsendmail

TARGETS =	dummy pgpsendmail pgpdaemon sendpgppass pgppipe \
		pgpsign extract-addrs match-email-addr reminder

all:	$(TARGETS) clean

lib/libpgpsendmail.a:
	(cd lib; make)

dummy:
	(cd lib; make)


pgpsendmail.o:	pgpsendmail.c
	$(CC) $(CFLAGS) $(SENDMAIL) -c pgpsendmail.c

pgpsendmail:	pgpsendmail.o lib/libpgpsendmail.a
	$(CC) -o pgpsendmail pgpsendmail.o $(LDFLAGS)
	@echo ""
	@echo "***WARNING***"
	@echo ""
	@echo -n "PGPsendmail will expect that the real sendmail is "
	@echo -n "`fgrep PATH_SENDMAIL /usr/include/paths.h |cut -d'"' -f 2`"
	@if [ "$(SENDMAIL)" = "-DUSE_OLD_SENDMAIL" ]; then \
		echo ""; \
		else echo ".real"; \
		fi
	@echo "If this is not true, you will have problems!"
	@echo ""


pgpdaemon:	pgpdaemon.o lib/libpgpsendmail.a
	$(CC) -o pgpdaemon pgpdaemon.o $(LDFLAGS)


sendpgppass:	sendpgppass.o lib/libpgpsendmail.a
	$(CC) -o sendpgppass sendpgppass.o $(LDFLAGS)


pgppipe:	pgppipe.o lib/libpgpsendmail.a
	$(CC) -o pgppipe pgppipe.o $(LDFLAGS)


pgpsign:	pgpsign.o lib/libpgpsendmail.a
	$(CC) -o pgpsign pgpsign.o $(LDFLAGS)


extract-addrs:	extract-addrs.o lib/libpgpsendmail.a
	$(CC) -o extract-addrs extract-addrs.o $(LDFLAGS)


match-email-addr:	match-email-addr.o lib/libpgpsendmail.a
	$(CC) -o match-email-addr match-email-addr.o $(LDFLAGS)


install: dummy pgpsendmail pgpdaemon sendpgppass pgppipe pgpsign extract-addrs\
		match-email-addr install.man
	./install pgpsendmail $(SENDMAIL)
	./install pgpdaemon
	./install sendpgppass
	./install pgppipe
	./install pgpsign
	./install extract-addrs
	./install match-email-addr

install.man: clean
	cp -rp man/* $(MANDIR)


reminder:
	@echo ""
	@echo "REMEMBER to do 'make install'"
	@echo ""


clean:
	rm -f *.BAK *.log *.sed .#* *~ *.bak */*.bak */tmp* */*~ */*/*~
	-chmod u+rw,go-w * 2> /dev/null

distclean:
	rm -f *.BAK *.log *.sed .#* *~ */*~ */*/*~ *.bak */*.bak */tmp* .*defaults
	rm -f $(TARGETS) *.o lib/*.o lib/libpgpsendmail.a
	-chmod u+rw,go-w * 2> /dev/null

treesum:
	@make distclean > /dev/null
	@cat `find . -type f -print | sort` | md5sum

# Dependencies
pgpdaemon.o:	     include/pgpsendmail.h include/karma.h include/version.h
pgppipe.o:	     include/pgpsendmail.h include/karma.h include/version.h
pgpsendmail.o:	     include/pgpsendmail.h include/karma.h include/version.h
pgpsign.o:	     include/pgpsendmail.h include/karma.h include/version.h
sendpgppass.o:	     include/pgpsendmail.h include/karma.h
extract-addrs.o:     include/pgpsendmail.h include/karma.h
match-email-addr.o:  include/pgpsendmail.h include/karma.h
