#
# Makefile for TkMail
#
# Paul Raines (raines@bohr.physics.upenn.edu)
# 		Hacked from Makefile for TkMan from Tom Phelps
#

# 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

# # # SITE SETTINGS # # #

# You can get this by typing 'info tclversion' in wish
# I believe everything should still work in 6.7, but I
# haven't tested it. Next version will require 7.0+
#TCLVERSION = 6.7
TCLVERSION = 7.0

# where is your wish binary
WISH = /usr/local/bin/wish

# directory to put *.tk support scripts
# the only library that must be at this location is disjoint.tk
# as long as the others are at locations in the auto_path with
# appropriate tclIndex files, they will be found
# WARNING: by popular demand, I have included 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

# # # BSD MAIL SETTINGS # # #

# BSD style mail command
MAILCMD = Mail

# sendmail style mail delivery agent
# the -t options makes it parse the message for delivery info
DELIVER = /usr/lib/sendmail -bm -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

# # # 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

# # # MISC SETTINGS # # #

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

# temporary file directory to use
TEMPDIR = /usr/tmp

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


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

version = 1.6p5
srcs = tkmail
objs = settings tclIndex
libs = compose.tk mail.tk utils.tk ispell.tk help.txt mailcmd.tk\
	altedit.tk disjoint.tk bindings.tk topgetopt.tcl \
	parse.tk mailcmd2.tk
aux = example.tkmail disjoint.test newvar.sed contrib
support = tclIndex.6.7 tclIndex.7.0 README Makefile ChangeLog NEWS
distrib = $(libs) $(aux) $(support) test
work = TAGS 

all: ispell mail altedit


mail: settings tkmail Makefile
	mv tkmail tkmail.src
	echo '#!$(WISH) -f' > tkmail
	echo 'global mf mfp' >> tkmail
	echo 'set mfp(tkmaillib) $(LIBDIR)' >> tkmail
	echo 'set mfp(globalset) $(LIBDIR)/settings' >> tkmail
	tail +5 tkmail.src >> tkmail
	chmod +x tkmail
	rm tkmail.src
	cp tclIndex.$(TCLVERSION) tclIndex

altedit: 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: 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
	tail +4 ispell.tk.src >> ispell.tk
	rm ispell.tk.src

tests: test/mtest test/mtest.box Makefile
	rm -f mtest
	echo '#!$(WISH) -f' > mtest
	echo 'global mfp' >> mtest
	echo 'set mf(mail-command) "$(MAILCMD)"' >> mtest
	echo 'set mf(mail-system) $(SYSTEM)/[exec whoami]' >> mtest
	echo 'set mf(mail-mbox) $$env(HOME)/$(MBOX)' >> mtest
	echo 'set mf(mail-deliver) "$(DELIVER)"' >> mtest
	tail +7 test/mtest >> mtest
	chmod +x mtest
	mv -f mtest test/mtest
	(cd test; ./mtest)

settings: Makefile
	rm -f settings
	echo '# TkMail global settings file' > settings
	echo 'global mf mfp env' >> settings
	echo '' >> settings
	echo '# BSD style mail command (do not put options here!)' >> settings
	echo 'set mf(mail-command) "$(MAILCMD)"' >> 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

install: settings tkmail tclIndex $(libs) $(aux) Makefile
	@if [ -d $(BINDIR) ]; then set +x; \
	else (set -x; mkdir $(BINDIR)); fi
	if [ -r $(BINDIR)/tkmail ]; then \
	  mv -f $(BINDIR)/tkmail $(BINDIR)/tkmail.old; fi
	cp tkmail $(BINDIR)
	chmod 755 $(BINDIR)/tkmail
# 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
	for f in $(libs) $(aux) $(objs) ; do \
	  cp -r $$f $(LIBDIR) ; \
	  chmod a+r $(LIBDIR)/$$f ; \
	done
	chmod 755 $(LIBDIR)/altedit.tk

clean:
	rm -f $(objs) test/mtest2.box test/mtest3.box

tar:
	rm -f tkmail*.tar.[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

star:
	rm -f tkmail.tgz
	mv tkmail tkmail.src
	mkdir tkmail
	cp -R tkmail.src $(distrib) $(work) tkmail
	rm -rf tkmail/test/CVS
	mv tkmail/tkmail.src tkmail/tkmail
	tar chvf tkmail.tar tkmail
	gzip tkmail.tar
	mv tkmail.tar.*z tkmail.tgz
	rm -rf tkmail
	mv tkmail.src tkmail


