#
#  Makefile for the entire MSG mail system
#
#         (C) Copyright 1986, Dave Taylor
#
#  Last modification: February 12th, 1986
 
#########################
#
# The following entries need to be customized for the local site:  
#    The first is the address of the data-cassette drive to allow
# easy tape copies to be made, and the second is the final location 
# that all the software should be installed in when 'make install'
# is run.
#
#########################

TAPE=   /dev/rct
DEST=   /usr/local/bin

LIB=    /usr/local/lib
MAN=	/usr/man/man1
CATMAN=/usr/man/cat1
SHAR=   /usr/local/bin/shar

# if on a Berkeley system:
# DEFINE = -DBSD
# else if on a UTS system:
# DEFINE = -DUTS
# otherwise;
DEFINE=

#########################

LIBS=   -ltermcap
CFLAGS= -O
CC=	/bin/cc
RM=	/bin/rm -f
MV=     /bin/mv
CP=	/bin/cp

DOCS=   Config.guide Msg.guide README msg.1 from.1 \
	printmail.1 newalias.1 newmail.1 answer.1 \
	grabalias.1 fastmail.1 readmsg.1 autoreply.1

UTILSRC=utils/newmail.c utils/answer.c utils/from.c 	        \
	utils/readmsg.c utils/printmail.c utils/newalias.c 	\
	utils/fastmail.c utils/cutfile.c utils/arepdaemon.c	\
	utils/autoreply.c

MSGSRC=	src/addr_utils.c src/alias.c src/aliasdb.c src/aliaslib.c src/args.c  \
        src/curses.c src/date.c src/delete.c src/encode.c src/file.c          \
	src/file_utils.c src/fileio.c src/hdrconfg.c src/help.c 	      \
	src/initialize.c src/input_utils.c src/mailout.c src/mailtime.c       \
	src/mkhdrs.c src/msg.c src/newmbox.c src/notesfile.c  \
	src/output_utils.c src/pattern.c src/quit.c src/read_rc.c src/reply.c \
	src/return_addr.c src/screen.c src/showmsg.c src/strings.c 	      \
	src/syscall.c src/utils.c src/validname.c src/savecopy.c

################

all:	documentation msg utils
	@echo Everything is up to date!

documentation:  doc/Msg.guide.fmtd  doc/Config.fmtd
	
doc/Msg.guide.fmtd: doc/Msg.guide
	nroff -mm doc/Msg.guide > doc/Msg.guide.fmtd

doc/Config.fmtd:  doc/Config.guide
	nroff -mm doc/Config.guide > doc/Config.fmtd

bin/msg: ${MSGSRC}
	cd src; make DEFINE=${DEFINE} msg; cd ..
	
bin/utils: ${UTILSRC}
	cd utils; make all; cd ..
	@touch bin/utils

install: all
	${MV} bin/msg          ${DEST}/msg
	${MV} bin/from         ${DEST}/from
	${MV} bin/newalias     ${DEST}/newalias
	${MV} bin/printmail    ${DEST}/printmail
	${MV} bin/fastmail     ${DEST}/fastmail
	${MV} bin/readmsg      ${DEST}/readmsg
	${MV} bin/newmail      ${DEST}/newmail
	${MV} bin/cutfile      ${DEST}/cutfile
	${MV} bin/checkalias   ${DEST}/checkalias
	${MV} bin/arepdaemon   ${DEST}/arepdaemon
	${MV} bin/autoreply    ${DEST}/autoreply
	${RM} ${CATMAN}/msg.1 ${CATMAN}/from.1 ${CATMAN}/newalias.1 \
	      ${CATMAN}/printmail.1 ${CATMAN}/fastmail.1 ${CATMAN}/msg.1 \
	      ${CATMAN}/checkalias.1 ${CATMAN}/autoreply.1
	${CP} doc/msg.1        ${MAN}/msg.1
	${CP} doc/from.1       ${MAN}/from.1
	${CP} doc/newalias.1   ${MAN}/newalias.1
	${CP} doc/printmail.1  ${MAN}/printmail.1
	${CP} doc/fastmail.1   ${MAN}/fastmail.1
	${CP} doc/checkalias.1 ${MAN}/checkalias.1
	${CP} doc/autoreply.1  ${MAN}/autoreply.1
	${CP} doc/helpfile     ${LIB}/msg-help.main
	chmod a+rx ${DEST}/from ${DEST}/newalias ${DEST}/printmail \
	           ${DEST}/fastmail ${DEST}/readmsg ${DEST}/cutfile \
		   ${DEST}/checkalias ${DEST}/autoreply
	chown root ${DEST}/msg
	chmod 4755 ${DEST}/msg
	@echo Done with installation.

rmt-install: remote-defined
	@echo " "
	@echo Warning: This assumes "install" has been done on the
	@echo "         remote machine.  If this is not the case you"
	@echo "         better hit BREAK quickly!"
	@echo " "
	${CP} ${REMOTE}${DEST}/msg          ${DEST}/msg
	${CP} ${REMOTE}${DEST}/from         ${DEST}/from
	${CP} ${REMOTE}${DEST}/newalias     ${DEST}/newalias
	${CP} ${REMOTE}${DEST}/printmail    ${DEST}/printmail
	${CP} ${REMOTE}${DEST}/fastmail     ${DEST}/fastmail
	${CP} ${REMOTE}${DEST}/readmsg      ${DEST}/readmsg
	${CP} ${REMOTE}${DEST}/newmail      ${DEST}/newmail
	${CP} ${REMOTE}${DEST}/cutfile      ${DEST}/cutfile
	${CP} ${REMOTE}${DEST}/checkalias   ${DEST}/checkalias
	${CP} ${REMOTE}${DEST}/arepdaemon   ${DEST}/arepdaemon
	${CP} ${REMOTE}${DEST}/autoreply    ${DEST}/autoreply
	${RM} ${CATMAN}/msg.1 \
	      ${CATMAN}/from.1 \
              ${CATMAN}/newalias.1 \
	      ${CATMAN}/printmail.1 \
	      ${CATMAN}/fastmail.1 \
              ${CATMAN}/checkalias.1 \
              ${CATMAN}/autoreply.1 \
              ${CATMAN}/msg.1
	${CP} ${REMOTE}${MAN}/msg.1        ${MAN}/msg.1
	${CP} ${REMOTE}${MAN}/from.1       ${MAN}/from.1
	${CP} ${REMOTE}${MAN}/newalias.1   ${MAN}/newalias.1
	${CP} ${REMOTE}${MAN}/printmail.1  ${MAN}/printmail.1
	${CP} ${REMOTE}${MAN}/fastmail.1   ${MAN}/fastmail.1
	${CP} ${REMOTE}${MAN}/checkalias.1 ${MAN}/checkalias.1
	${CP} ${REMOTE}${MAN}/autoreply.1  ${MAN}/autoreply.1
	${CP} ${REMOTE}${LIB}/helpfile     ${LIB}/msg-help.main
	chmod a+rx ${DEST}/from ${DEST}/newalias ${DEST}/printmail \
	           ${DEST}/fastmail ${DEST}/readmsg ${DEST}/cutfile \
		   ${DEST}/checkalias ${DEST}/autoreply
	chown root ${DEST}/msg
	chmod 4755 ${DEST}/msg
	@echo everything is installed based on files from ${REMOTE}

source: 
	tar cvf ${TAPE} bin/makelisting utils/*.c src/*.c doc/* hdrs/* \
	Instructions Makefile README utils/Makefile src/Makefile test/*

shar:   
	@echo \\nMaking Part One...
	${SHAR} Overview Instructions Makefile README \
	     bin/makelisting doc/Config.guide doc/*.1 doc/helpfile \
	     doc/msgrc.sample
	@rm -f Shar.part.1
	@/bin/echo \\n# Msg Shar part 1 of 7 | cat - Shell-Archive > Shar.part.1
	@echo \\nMaking Part Two...
	${SHAR} doc/Msg.guide hdrs/*.h
	@rm -f Shar.part.2
	@/bin/echo \\n# Msg Shar part 2 of 7 | cat - Shell-Archive > Shar.part.2
	@echo \\nMaking Part Three...
	${SHAR} src/[a-e]*.c src/file.c
	@rm -f Shar.part.3
	@/bin/echo \\n# Msg Shar part 3 of 7 | cat - Shell-Archive > Shar.part.3
	@echo \\nMaking Part Four...
	${SHAR} src/file?*.c src/[g-m]*.c 
	@rm -f Shar.part.4
	@/bin/echo \\n# Msg Shar part 4 of 7 | cat - Shell-Archive > Shar.part.4
	@echo \\nMaking Part Five...
	${SHAR} src/n[n-z]*.c src/[o-r]*.c src/s[a-q]*.c
	@rm -f Shar.part.5
	@/bin/echo \\n# Msg Shar part 5 of 7 | cat - Shell-Archive > Shar.part.5
	@echo \\nMaking Part Six...
	${SHAR} src/n[a-m]*.c src/s[r-z]*.c src/[t-z]*.c src/Makefile \
		utils/a*.c
	@rm -f Shar.part.6
	@/bin/echo \\n# Msg Shar part 6 of 7 | cat - Shell-Archive > Shar.part.6
	@echo \\nMaking Part Seven...
	${SHAR} utils/[b-z]*.c utils/Makefile test/test.*
	@rm -f Shar.part.7
	@/bin/echo \\n# Msg Shar part 7 of 7 | cat - Shell-Archive > Shar.part.7
	@rm -f Shell-Archive
	@echo ' '
	@echo Created shar files one through seven \(Shar.part.\<n\>\)

lint:
	lint ${UTILSRC} > lint.out

listing:
	@echo listing all source files 
	@/bin/echo \\f > LISTING
	@echo adding README...
	@cat README >> LISTING
	@/bin/echo \\f >> LISTING
	@echo adding Instructions...
	@cat Instructions >> LISTING
	@bin/makelisting Makefile ${UTILSRC} src/Makefile src/*.c hdrs/*.h
	@echo LISTING generated.

msg-listing: 
	@echo listing just the MSG system source files
	@echo ' ' > src/LISTING
	@cd src ; make listing ; cd ..
	@echo LISTING generated \(in directory /src\).

clean:
	@cd src ; make clean ; cd ..
	@cd utils; make clean ; cd ..
	@echo All spurious files removed

msg: bin/msg
utils: bin/utils
utils/checkalias:
doc/Msg.guide:
doc/Config.guide:

remote-defined:
	@if ( "${REMOTE}" == "" ) then; \
	   echo " " ; \
	   echo "You need to define 'REMOTE' as the remote file system" ; \
	   echo "for this particular command.   The easiest way to do " ; \
	   echo "this is to type:" ;\
	   echo "    make -f <makefile> REMOTE=<remote file system> rmt-install" ; \
	   echo " " ; \
	 endif
	@if ( "${REMOTE}" == "" ) exit 1
