# Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
# 
# Permission to use, copy, modify, and distribute this material 
# for any purpose and without fee is hereby granted, provided 
# that the above copyright notice and this permission notice 
# appear in all copies, and that the name of Bellcore not be 
# used in advertising or publicity pertaining to this 
# material without the specific, prior written permission 
# of an authorized representative of Bellcore.  BELLCORE 
# MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
# OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
# WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
#

# For the ATOMICMAIL distribution, you want the second of the two following lines
# For the more freely-publishable without-ATOMICMAIL version, you want the first.
# ATOMICMAIL=
ATOMICMAIL=atomicmail

# System V users may change the following to remove the "-s" and all will still work.
LN = ln -s

# To shut rm up on SGI machines (where symlinks have mode 0000)
RM = rm -f

# How to copy files
CP = cp

# You may also want to change the CFLAGS variable, which will be passed on 
# to all subdirectories.    If you do that, the changes will only work right if you
# start your make in the top-level directory, not if you start in a subdirectory.

# Note that the FOOBAR hack is to get -Bstatic on sun4's but nowhere else.
#It is very ugly, but what can you do?
FOOBAR-sun4=-Bstatic

STATICFLAG=FOOBAR${HOST_ARCH}

CFLAGS = -g -I.  ${$(STATICFLAG)} 
# The following is better if you want to make sure you run with SYSV defined
# CFLAGS = -g -I.  ${$(STATICFLAG)}  -DSYSV

# You may have to include other libraries to the link to get things like
# gethostname() resolved or use shared libraries.  This is done with the
# LDLIBS variable.
#
# For Sun and BSD systems, the following should work...
LDLIBS =
# On SGI machines, we need -lsun for getpw...(), and -lc_s saves some space.
# LDLIBS = -lsun -lc_s
# ISC SysVr3.2.2 has a shared C library and requires libinet.a to resolve
# gethostname() references.
# LDLIBS = -linet -lc_s

#
# This is where config.h lives
CONFIGDIR = .

# This is how binaries should be installed
#INSTALL = cp
INSTALL = install -c -s

#
# This is where binaries should be copied
LOCALBINDIR = /usr/local/bin

# This is where man pages should be copied, and their extensions
MAN1DIR = /usr/local/man/man1
MAN1EXT = 1

# This is where the mailcap file should be put
MAILCAPDIR = /usr/local/etc

install: basics ${ATOMICMAIL} 

atomicmail::
	(cd atomicmail ; make CONFIGDIR=.. CFLAGS="${CFLAGS}" LDLIBS="${LDLIBS}")
	-${RM} bin/atomicmail
	(cd bin; ${LN} ../atomicmail/src/atomicmail atomicmail)
	-${RM} bin/docdist.am
	(cd bin; ${LN} ../atomicmail/apps/docdist.am docdist.am)
	-${RM} bin/mrwizard-seed.am
	(cd bin; ${LN} ../atomicmail/apps/mrwizard-seed.am mrwizard-seed.am)
	-${RM} bin/mrwizard.am
	(cd bin; ${LN} ../atomicmail/apps/mrwizard.am mrwizard.am)
	-${RM} bin/nametune.am
	(cd bin; ${LN} ../atomicmail/apps/nametune.am nametune.am)
	-${RM} bin/scheduler.am
	(cd bin; ${LN} ../atomicmail/apps/scheduler.am scheduler.am)
	-${RM} bin/surveyor.am
	(cd bin; ${LN} ../atomicmail/apps/surveyor.am surveyor.am)


basics::
	(cd metamail ; make  CONFIGDIR=../${CONFIGDIR}  CFLAGS="${CFLAGS}" LDLIBS="${LDLIBS}")
	-${RM} bin/metamail
	(cd bin; ${LN} ../metamail/metamail metamail)
	-${RM} bin/mmencode
	(cd bin; ${LN} ../metamail/mmencode mmencode)
	-${RM} bin/mimencode
	(cd bin; ${LN} ../metamail/mmencode mimencode)
	-${RM} man/mimencode.1
	(cd man; ${LN} ../man/mmencode.1 mimencode.1)
	-${RM} bin/mailto
	(cd bin; ${LN} ../metamail/mailto mailto)
	-${RM} bin/splitmail
	(cd bin; ${LN} ../metamail/splitmail splitmail)
	(cd richmail ; make  CONFIGDIR=../${CONFIGDIR}  CFLAGS="${CFLAGS}" LDLIBS="${LDLIBS}")
	-${RM} bin/richtext
	(cd bin; ${LN} ../richmail/richtext richtext)
	-${RM} bin/richtoatk
	(cd bin; ${LN} ../richmail/richtoatk richtoatk)
	(cd fonts ; make  CONFIGDIR=../${CONFIGDIR}  CFLAGS="${CFLAGS}" LDLIBS="${LDLIBS}")
	-${RM} bin/shownonascii
	(cd bin; ${LN} ../fonts/shownonascii shownonascii)
	-${RM} bin/mailto-hebrew
	(cd bin; ${LN} ../fonts/mailto-hebrew mailto-hebrew)

install-all: basics ${ATOMICMAIL} 
	@(cd bin; 				\
	for file in *; 				\
	do 					\
	    target=$(LOCALBINDIR)/$$file; 	\
	    echo "installing binary $$target";	\
	    ${INSTALL} $$file $$target; 	\
	done)
	@(cd man;				\
	for file in *.1;			\
	do 					\
	    target=$(MAN1DIR)/`basename $$file .1`.$(MAN1EXT); \
	    echo "installing man page $$target";\
	    ${CP} $$file $$target; 		\
	done)
	@echo "installing file $(MAILCAPDIR)/mailcap"
	${CP} mailcap $(MAILCAPDIR)

uninstall-all:
	@(cd bin; 				\
	for file in *; 				\
	do 					\
	    target=$(LOCALBINDIR)/$$file; 	\
	    echo "rm-ing binary $$target";\
	    ${RM} $(LOCALBINDIR)/$$file; 	\
	done)
	@(cd man;				\
	for file in *.1;			\
	do 					\
	    target=$(MAN1DIR)/`basename $$file .1`.$(MAN1EXT); \
	    echo "rm-ing man page $$target";\
	    ${RM} $$target; 		\
	done)
	@echo "rm-ing file $(MAILCAPDIR)/mailcap"
	@${RM} $(MAILCAPDIR)/mailcap

clean:
	-${RM} -rf *.BAK
	(cd metamail ; make clean)
	(cd richmail ; make clean)
	(cd fonts ; make clean)
	-(cd atomicmail ; make clean)

cleanambin:
	-${RM} bin/atomicmail
	-${RM} bin/docdist.am
	-${RM} bin/mrwizard-seed.am
	-${RM} bin/mrwizard.am
	-${RM} bin/nametune.am
	-${RM} bin/scheduler.am
	-${RM} bin/surveyor.am

cleanbin:
	-${RM} bin/metamail
	-${RM} bin/mmencode
	-${RM} bin/mimencode
	-${RM} bin/mailto
	-${RM} bin/splitmail
	-${RM} bin/richtext
	-${RM} bin/richtoatk
	-${RM} bin/shownonascii
	-${RM} bin/mailto-hebrew

cleanman:
	-${RM} man/mimencode.1

clobber: clean cleanambin cleanbin cleanman
