#
# Makefile for top level of nmh distribution
#
# $Id: Makefile.in,v 1.5 1999/12/01 16:31:01 danw Exp $
#

# nmh version
VERSION = @VERSION@

SHELL = /bin/sh
@SET_MAKE@

srcdir = @srcdir@
VPATH  = @srcdir@

# ========== USER CONFIGURATION SECTION ==========
#
# If `make' is executed in the directory containing this Makefile,
# any changes made in this section will override the values of
# these parameters in makefiles in any of the subdirectories.
 
prefix      = @prefix@
exec_prefix = @exec_prefix@

# location of standard commands
bindir      = @bindir@

# location of support binaries and scripts
libdir      = @libexecdir@

# location of nmh configuration and formats files
etcdir      = /usr/athena/etc

# location of man pages
mandir      = @mandir@
 
# location of incoming mail
mailspool   = @mailspool@

# location of mail transport agent
sendmailpath = @sendmailpath@

# default editor
default_editor = @editorpath@

# default pager
default_pager = @pagerpath@

CC       = @CC@
CPPFLAGS = @CPPFLAGS@
DEFS     = @DEFS@
CFLAGS   = @CFLAGS@
LDFLAGS  = @LDFLAGS@
LIBS     = @LIBS@
 
# ========== YOU SHOULDN'T HAVE TO CHANGE ANYTHING BELOW HERE ==========

# flags passed to recursive makes in subdirectories
MAKEDEFS = CC='$(CC)' CPPFLAGS='$(CPPFLAGS)' DEFS='$(DEFS)' \
CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' LIBS='$(LIBS)' DESTDIR='$(DESTDIR)' \
prefix='$(prefix)' exec_prefix='$(exec_prefix)' bindir='$(bindir)' \
etcdir='$(etcdir)' libdir='$(libdir)' mandir='$(mandir)' \
mailspool='$(mailspool)' sendmailpath='$(sendmailpath)' \
default_editor='$(default_editor)' default_pager='$(default_pager)'

INSTALL         = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA    = @INSTALL_DATA@

.SUFFIXES:

# all files in this directory included in the distribution
DIST = README INSTALL MACHINES COPYRIGHT VERSION DIFFERENCES FAQ \
       TODO ZSH.COMPLETION MAIL.FILTERING ChangeLog install-sh \
       mkinstalldirs Makefile.in aclocal.m4 acconfig.h config.h.in \
       configure.in configure stamp-h.in

# subdirectories in distribution
SUBDIRS = h config sbr zotnet mts uip etc man

# ========== DEPENDENCIES FOR BUILDING AND INSTALLING ==========

# default target
all: config.h Makefile all-recursive

all-recursive:
	for subdir in $(SUBDIRS); do \
	  (cd $$subdir && $(MAKE) $(MAKEDEFS) all) || exit 1; \
	done

install uninstall:
	for subdir in $(SUBDIRS); do \
	  (cd $$subdir && $(MAKE) $(MAKEDEFS) $@) || exit 1; \
	done

# ========== DEPENDENCIES FOR CLEANUP ==========

mostlyclean: mostlyclean-recursive mostlyclean-local
clean:       clean-recursive       clean-local
distclean:   distclean-recursive   distclean-local
realclean:   realclean-recursive   realclean-local
superclean:  superclean-recursive  superclean-local

mostlyclean-local:
	rm -f *~

clean-local: mostlyclean-local

distclean-local: clean-local
	rm -f Makefile config.h config.status config.log config.cache stamp-h distname

realclean-local: distclean-local

superclean-local: realclean-local
	cd $(srcdir) && rm -f config.h.in stamp-h.in configure

mostlyclean-recursive clean-recursive distclean-recursive realclean-recursive superclean-recursive:
	for subdir in $(SUBDIRS); do \
	  target=`echo $@ | sed 's/-recursive//'`; \
	  (cd $$subdir && $(MAKE) $(MAKEDEFS) $$target) || exit 1; \
	done

# ========== DEPENDENCIES FOR MAINTENANCE ==========

Makefile: Makefile.in config.status
	CONFIG_FILES=$@ CONFIG_HEADERS= ./config.status

config.status: configure VERSION
	./config.status --recheck

config.h: stamp-h
stamp-h: config.h.in config.status
	CONFIG_FILES= CONFIG_HEADERS=config.h ./config.status

# rebuild all autoconf files
reset:
	cd $(srcdir) && autoheader
	cd $(srcdir) && autoconf
	cd $(srcdir) && echo > stamp-h.in

# name of new nmh distribution tar file
tarfile = nmh-$(VERSION).tar.gz

# ftp directory location
ftpdir = /ftp/nmh

# file containing name of new nmh distribution
distname:
	@echo nmh-$(VERSION) > distname

# build nmh distribution
distdir = `cat distname`
nmhdist: $(DIST) distname
	@echo "Begin building nmh-$(VERSION) distribution"
	rm -rf $(distdir)
	mkdir $(distdir)
	@chmod 755 $(distdir)
	@echo "Copying distribution files in main directory"
	@for file in $(DIST); do \
	  cp -p $(srcdir)/$$file $(distdir); \
	done
	@for subdir in $(SUBDIRS); do \
	  mkdir $(distdir)/$$subdir; \
	  chmod 755 $(distdir)/$$subdir; \
	  (cd $$subdir && $(MAKE) $@) || exit 1; \
	done
	chmod -R a+r $(distdir)
	tar chf - $(distdir) | gzip -c > $(tarfile)
	rm -rf $(distdir) distname
	@echo "Done building nmh-$(VERSION) distribution"

# release a new nmh distribution into ftp directory
nmhrelease:
	rm -f $(ftpdir)/$(tarfile)
	rm -f $(ftpdir)/nmh.tar.gz
	mv $(tarfile) $(ftpdir)/$(tarfile)
	cd $(ftpdir) && ln -s $(tarfile) nmh.tar.gz
	cd $(ftpdir) && md5sum *.gz > MD5SUM

