#
# Makefile for TkMail 2.0
#
# Paul Raines (raines@slac.stanford.edu)
# 		Hacked from Makefile for TkMan from Tom Phelps
#
VERSION = 2.0p6

# This Makefile includes the most critical and site specific
# settings needed to run TkMail. See the SETTINGS section at
# the top of the tkmail file for other settings.
SHELL = /bin/sh

# # # PATH SETTINGS # # #

# Location of your wish binary.
WISH = wish

# Location of your perl binary
PERL = perl

# Directory to put support scripts in
# WARNING: by popular demand, I have included a line in the install
#   procedure to copy any existing library directory to ${LIBDIR}.old
#   If you don't want this, delete the apropriate lines below
LIBDIR = /usr/local/lib/tkmail

# Directory to put tkmail executable script
BINDIR = /usr/local/bin

# Name of the tkmail executable script
TKMAIL = tkmail

# # # MAIL SETTINGS # # #

# sendmail style mail delivery agent
# the -t options makes it parse the message for delivery info
DELIVER = /usr/lib/sendmail -bm -odb -t
 
# directory where system inboxes reside. User's login name will 
# be appended
SYSTEM = /usr/spool/mail

# name of users mbox (the file Mail automatically moves new mail
# messages to after read in the system inbox). This name is
# relative to the user home directory
MBOX = mbox

# if your Mail is stored with >'s in front of From lines, and tkmail
# doesn't otherwise work, make this ">*". I hate mail systems that
# do that.
STUPIDFORMAT = 0

# # # INCORPORATION SETTINGS # # #

# The trickiest thing for a mail program is to safely move mail from
# the system spool area to a user's own directories. Since two widely
# used packages, Emacs and Procmail, have well tested programs for
# doing this, I suggest you use one of them. Beware though, that
# several system administrators fail to install these programs
# properly. On most systems they must be SETUID or SETGID depending on
# the permissions of the system spool directory

# Whether to use Emac's movemail for safe incorporation You can test
# movemail by sending yourself a message to make sure you have new
# mail and running movemail with your spool file's pathname as the
# first argument and some temp file to move it to as the second
USEMOVEMAIL = 1
MOVEMAIL = /usr/lib/emacs/19.28/i486-slackware-linux/movemail

# Whether to use Procmail's lockfile for safe incorporation
USELOCKFILE = 0;
LOCKFILE = /usr/local/bin/lockfile

# If neither USEMOVEMAIL or USELOCKFILE are set true, then tkmail will
# try to do its own locking which probably won't work on your system,
# but you can test it using 'make locktest' after setting the lock
# defines below correctly and the path and mail settings above.

# File locking defines for flock() from <sys/file.h>
# If your system does not have flock(), ignore this and EWOULDBLOCK
# You can type 'make getdefines' to create a small program that will
# print out all the defines needed in this Makfile
# -- SunOS, IRIX, AIX, ULTRIX, OSF/1
LOCK_SH = 1
LOCK_EX = 2
LOCK_NB = 4
LOCK_UN = 8

# define from <sys/errno.h>
# -- AIX, Linux, IRIX 5.2
EWOULDBLOCK = 11
# -- SunOS, ULTRIX, OSF/1
# EWOULDBLOCK = 35

# # # MIME SETTTINGS # # #

# Eventually, I might have Perl itself handle decoding, but till then...

# command to decode base64 encoded text from standard input
BASE64DEC = /usr/local/bin/mmencode -u -b

# command to decode quoted printable encoded text from standard input
QUOTPRDEC = /usr/local/bin/mmencode -u -q

# command to encode base64 encoded text from standard input
BASE64ENC = /usr/local/bin/mmencode -b

# command to encode quoted printable encoded text from standard input
QUOTPRENC = /usr/local/bin/mmencode -q

# In order to use mime, you will need to customize the following
# variables in your ~/.tkmailrc file
#
#   set mf(mime-parse) 1
#
#   set mf(mime-external-viewers) { 
#     {Image xv} \
#     {Audio {cat %F > /dev/audio}} \
#     {Application/PostScript ghostview} }
#
# The format of the last is a list of pairs in which the first element
# of the pairs is a mime type optionally appended with a slash and
# mime subtype. The second element is the unix command to run on the
# contents for that type.  The %F placeholder signifies the name of 
# the file holding the contents. If not given, it is placed as the
# last argument to the commmand.
#
# Remember that MIME support in tkmail is still under construction
# and is probably the least bug tested part in it.

# # # ISPELL SETTINGS # # #

# whether you have ispell (not GNU ispell!). Set to 1 if you do, 0 if not.
# Read the top of ispell.tk file for more info. If you set this to 0,
# there is no need to change the two below.
HAVEISPELL = 1

# Location of ispell hash files
ISPELLLIB = /usr/local/lib/ispell

# whether your version of ispell puts out an initial version line
# when you start it with 'ispell -a'. Set to 1 if you do, 0 if not.
ISPELLNEW = 1

# name of ispell program (may need full path)
ISPELLPROG = ispell

# whether your ispell requires an adjustment to returned offsets
# to test for this type at the command line
#	ispell -a
#	!
#	^What is not Waht
# If you get the output '& Waht 10 12: ...', you need no adjustment
# If you get the output '& Waht 12 13: ...', you do need the adjustment
ISPELLADJ = 0

# # # MISC SETTINGS # # #

# ascii text print command for your site (%F is place holder for filename)
PRINTCMD = lpr %F

# directory to use for temporary files
TEMPDIR = /usr/tmp

# bitmap directory containing flagdown, flagup, and letters bitmaps
BITMAPDIR = /usr/include/X11/bitmaps

# Socket defines from <sys/socket.h>
# These need to be correct or the Perl/Wish communication may hang
# -- SunOS, AIX, Motorola-SysV4, Linux, HP-UX, ULTRIX, OSF/1
SOCK_STREAM = 1
AF_UNIX = 1
# -- Solaris, IRIX 5.2
# SOCK_STREAM = 2
# AF_UNIX = 1

# Waitpid defines from <sys/wait.h> Needs to be correct so Perl can
# successfully detect if Wish is killed non-gracefully. Test with
# 'make childtest'. Some HPUX users have reported that this causes
# problems with interrupted system calls in which case one must turn
# this feature off by editing the tkmail file and removing the line
#		$SIG{'CHLD'} = "testpid";
# nearest to the bottom of the file.
# -- SunOS, AIX, Linux, HP-UX, ULTRIX, OSF/1
WNOHANG = 1
# -- Solaris, Motorola-SysV4, IRIX 5.2
# WNOHANG = 64


#--------------------------------------------------
#
# you shouldn't modify anything below here
#
#--------------------------------------------------

srcs = tkmail
objs = settings
libs = compose.tk mail.tk ispell.tk help.txt maildb.pl \
	altedit.tk disjoint.tk bindings.tk dbperl.tcl \
	mime.tk mime.pl viewer.tcl utils.tk options.tk \
	options2.tk focus.tk mailtime.pl tclIndex
aux = example.tkmailrc lock.test io.test child.test getdefines.c
support = README Makefile ChangeLog BETANOTES newvar.sed
distrib = $(srcs) $(libs) $(aux) $(support)
work = TAGS 

tcllibs = compose.tk mail.tk ispell.tk focus.tk \
	altedit.tk disjoint.tk bindings.tk dbperl.tcl \
	mime.tk mime.pl viewer.tcl utils.tk options.tk \
	options2.tk

ndxlibs = mail.tk compose.tk ispell.tk mime.tk options.tk \
	options2.tk utils.tk focus.tk

all: ispell.tk altedit.tk settings tkmail

tags:
	tcltags $(tcllibs)

tkmail: Makefile
	mv tkmail tkmail.src
	echo '#!$(PERL)' > tkmail
	echo '$$tkmaillib = "$(LIBDIR)";' >> tkmail
	echo '$$wishbin = "$(WISH)";' >> tkmail
	echo '$$version = "$(VERSION)";' >> tkmail
	echo '$$base64dec = "$(BASE64DEC)";' >> tkmail
	echo '$$quotprdec = "$(QUOTPRDEC)";' >> tkmail
	echo '$$base64enc = "$(BASE64ENC)";' >> tkmail
	echo '$$quotprenc = "$(QUOTPRENC)";' >> tkmail
	echo '$$stupidformat = $(STUPIDFORMAT);' >> tkmail
	echo '$$usemovemail = $(USEMOVEMAIL);' >> tkmail
	echo '$$movemail = "$(MOVEMAIL)";' >> tkmail
	echo '$$uselockfile = $(USELOCKFILE);' >> tkmail
	echo '$$lockfile = "$(LOCKFILE)";' >> tkmail
	echo '$$LOCK_SH = $(LOCK_SH);' >> tkmail
	echo '$$LOCK_EX = $(LOCK_EX);' >> tkmail
	echo '$$LOCK_NB = $(LOCK_NB);' >> tkmail
	echo '$$LOCK_UN = $(LOCK_UN);' >> tkmail
	echo '$$EWOULDBLOCK = $(EWOULDBLOCK);' >> tkmail
	echo '$$SOCK_STREAM = $(SOCK_STREAM);' >> tkmail
	echo '$$AF_UNIX = $(AF_UNIX);' >> tkmail
	echo '$$WNOHANG = $(WNOHANG);' >> tkmail
	tail +22 tkmail.src >> tkmail
	chmod +x tkmail
	rm tkmail.src

altedit.tk: Makefile
	mv altedit.tk altedit.tk.src
	echo '#!$(WISH) -f' > altedit.tk
	tail +2 altedit.tk.src >> altedit.tk
	chmod +x altedit.tk
	rm altedit.tk.src

ispell.tk: Makefile
	mv ispell.tk ispell.tk.src
	echo 'global tkisp' > ispell.tk
	echo 'set tkisp(ispell_lib) $(ISPELLLIB)' >> ispell.tk
	echo 'set tkisp(have_new) $(ISPELLNEW)' >> ispell.tk
	echo 'set tkisp(binary) $(ISPELLPROG)' >> ispell.tk
	echo 'set tkisp(adj_offset) $(ISPELLADJ)' >> ispell.tk
	tail +6 ispell.tk.src >> ispell.tk
	rm ispell.tk.src

settings: Makefile
	rm -f settings
	echo '# TkMail global settings file' > settings
	echo 'global mf mfp env' >> settings
	echo '' >> settings
	echo '# name of mail delivery command' >> settings
	echo 'set mf(mail-deliver) "$(DELIVER)"' >> settings
	echo '# name of main MBOX' >> settings
	echo 'set mf(mail-mbox) $$env(HOME)/$(MBOX)' >> settings
	echo '# name of system inbox' >> settings
	echo 'set mf(mail-system) $(SYSTEM)/[exec whoami]' >> settings
	echo '' >> settings
	echo '# whether or not you have ispell' >> settings
	echo 'set mf(ispell-present) $(HAVEISPELL)' >> settings
	echo '# print command (%F is file placeholder)' >> settings
	echo 'set mf(viewer-print) "$(PRINTCMD)"' >> settings
	echo '# temporary directory' >> settings
	echo 'set mf(mail-tmpdir) $(TEMPDIR)' >> settings
	echo '# bitmaps' >> settings
	echo 'set mf(viewer-bitmap-nomail) $(BITMAPDIR)/flagdown' >> settings
	echo 'set mf(viewer-bitmap-mail) $(BITMAPDIR)/flagup' >> settings
	echo 'set mf(compose-icon-bitmap) $(BITMAPDIR)/letters' >> settings

locktest: Makefile
	mv lock.test lock.test.src
	echo '#!$(PERL)' > lock.test
	echo '$$sendmail = "$(DELIVER)";' >> lock.test
	echo '$$spooldir = "$(SYSTEM)";' >> lock.test
	tail +4 lock.test.src >> lock.test
	chmod +x lock.test
	rm lock.test.src
	./lock.test

childtest: Makefile
	mv child.test child.test.src
	echo '#!$(PERL)' > child.test
	echo '$$wishbin = "$(WISH)";' >> child.test
	echo '$$SOCK_STREAM = $(SOC_STREAM);' >> child.test
	echo '$$AF_UNIX = $(AF_UNIX);' >> child.test
	echo '$$WNOHANG = $(WNOHANG);' >> child.test
	tail +6 child.test.src >> child.test
	chmod +x child.test
	rm child.test.src
	./child.test

iotest: Makefile
	$(PERL) io.test

getdefines: getdefines.c
	$(CC) -o getdefines getdefines.c
	- ./getdefines
	rm -f getdefines

install: settings tkmail $(libs) $(aux) Makefile
# WARNING: the following "if" clause will move any existing LIBDIR to ${LIBDIR}.old
	@if [ -d $(LIBDIR) ]; then \
	  rm -rf $(LIBDIR).old; mv -f $(LIBDIR) $(LIBDIR).old; mkdir $(LIBDIR); \
	else (set -x; mkdir $(LIBDIR)); fi
	chmod 755 $(LIBDIR)
	for f in $(libs) $(aux) $(objs) ; do \
	  cp $$f $(LIBDIR) ; \
	  chmod a+r $(LIBDIR)/$$f ; \
	done
	chmod 755 $(LIBDIR)/altedit.tk
	if [ -d $(BINDIR) ]; then set +x; \
	else (set -x; mkdir $(BINDIR)); fi
	if [ -r $(BINDIR)/$(TKMAIL) ]; then \
	  mv -f $(BINDIR)/$(TKMAIL) $(BINDIR)/$(TKMAIL).old; else true; fi
	cp tkmail $(BINDIR)/$(TKMAIL)
	chmod 755 $(BINDIR)/$(TKMAIL)

index:
	tclndx . $(ndxlibs)

tar:
	rm -f tkmail*.tar.g*[zZ]*
	mkdir tkmail-$(VERSION)
	cp -r tkmail $(distrib) tkmail-$(VERSION)
	# rm -rf tkmail-$(VERSION)/test/CVS
	tar chvf tkmail-$(VERSION).tar tkmail-$(VERSION)
	gzip tkmail-$(VERSION).tar
	rm -rf tkmail-$(VERSION)
	@echo "*** Did you remember to cvs commit first?"

uu: tar
	uuencode tkmail-$(VERSION).tar.Z tkmail-$(VERSION).tar.Z > tkmail-$(VERSION).tar.Z.uu

tgz:
	cd .. ; \
	rm -f tkmail2.tgz ; \
	tar cf - tkmail2 | gzip > tkmail2.tgz


