# Makefile -- for mail server
# SCCS Status     : %Z%@ %M%	%I%
# Author          : Johan Vromans
# Created On      : Fri May  1 15:44:47 1992
# Last Modified By: Johan Vromans
# Last Modified On: Wed Dec 23 23:13:14 1992
# Update Count    : 109
# Status          : 

SHELL	= /bin/sh
CC	= gcc -Wall
CFLAGS	= -O

# Perl 4.035 needs fixes!
PERL	= /usr/local/bin/perl
# Where programs and files reside.
LIBDIR	= /usr/local/lib/mserv
# Where help data will be installed.
PUBDIR	= $(LIBDIR)/pub
# The owner of the mail server files
SERVER	= mserv

# Perl scripts that will be public executable.
PEARLS	= process dorequest unpack makeindex chkconfig report do_report
# Misc. files.
FILES	= rfc822.pl ms_common.pl patchlevel.h \
	ms_lock.pl ftp.pl chat2.pl dateconv.pl \
	dr_mail.pl dr_uucp.pl dr_pack.pl \
	pr_isearch.pl pr_dsearch.pl pr_doindex.pl pr_dowork.pl \
	pr_parse.pl pr_ftp.pl pr_help.pl
# Config data. Will not replace existing files.
CONFIG	= ms_config.pl mserv.hints mserv.notes mserv.notesi
# Public executable shell scripts.
SHELLS	= do_runq
# These files will be created, if needed
TOUCH	= logfile lockfile queue .errrun
# Public services.
AIDS	= HELP unpack.pl

all:	$(PEARLS) mlistener
	@echo "Use \"make listener\" to generate the listener program"
	@echo "Use \"make ixlookup\" if you selected index lookup"

$(PEARLS) mlistener:
	@for prog in $(PEARLS) mlistener; do \
		echo "Preparing $$prog..."; \
		rm -f $$prog; \
		sed -e '1s|/usr/local/bin/perl|$(PERL)|' \
		    -e 's|/usr/local/lib/mserv|$(LIBDIR)|' \
			$$prog.pl >$$prog; \
	done

install: $(PEARLS)
	-mkdir $(LIBDIR)
	@for prog in $(PEARLS); do \
		echo "Installing $$prog..."; \
		install -c -m 0555 $$prog $(LIBDIR)/$$prog; \
	done
	@for prog in $(SHELLS); do \
		echo "Installing $$prog..."; \
		install -c -m 0555 $$prog.sh $(LIBDIR)/$$prog; \
	done
	@for prog in $(FILES); do \
		echo "Installing $$prog..."; \
		install -c -m 0444 $$prog $(LIBDIR); \
	done
	@for prog in $(TOUCH); do \
	    if [ -f $(LIBDIR)/$$prog ]; then \
		true; \
	    else \
		echo "Creating $$prog..."; \
		cat < /dev/null > $(LIBDIR)/$$prog; \
	    fi; \
	done
	@for prog in $(CONFIG); do \
	    if [ -f $(LIBDIR)/$$prog ]; then \
		echo "Installing $$prog as NEW-$$prog..."; \
		echo "IMPORTANT: Update $$prog by hand if needed!"; \
		install -c -m 0644 $$prog $(LIBDIR)/NEW-$$prog; \
	    else \
		echo "Installing $$prog..."; \
		install -c -m 0644 $$prog $(LIBDIR); \
	    fi \
	done
	-mkdir $(PUBDIR)
	@for prog in $(AIDS); do \
		echo "Installing $$prog in $(PUBDIR)..."; \
		install -c -m 0444 $$prog $(PUBDIR)/$$prog; \
	done
	-(cd $(PUBDIR); rm -f help; ln HELP help)
	@echo "Use \"make install-listener\" to install the listener program"
	@echo "Use \"make install-ixlookup\" to install the ixlookup program"

################ Listener ################

listener: mlistener
	rm -f listener listener.c
	$(PERL) mlistener -verbose > listener.c
	$(CC) $(CFLAGS) -o listener listener.c

# Install setuid to the installer...
install-listener:	listener
	rm -f $(LIBDIR)/listener
	install -s -c listener $(LIBDIR)/listener
	chmod -w,+x,u+s $(LIBDIR)/listener

################ ixlookup ################

# ixlookup is based on GNU find/locate.
# If you have GNU find 3.6 or later, you can use the locate program.
# For locate 3.5, a patch is available to create a customized version
# of this program. "make ixlookup" will build it.
# Set GNUFIND to indicate where the source of GNU locate, includes
# and find lib can be found.
# Reference version is GNU find 3.5.
GNUFIND = /beethoven/arch/GNU/find-3.5

ixlookup.c: $(GNUFIND)/locate/locate.c ixlookup.patch
	rm -f ixlookup.c
	cp  $(GNUFIND)/locate/locate.c ixlookup.c
	patch -p0 -N < ixlookup.patch

ixlookup:	ixlookup.c
	rm -f ixlookup
	$(CC) $(CFLAGS) '-DFCODES="$(LIBDIR)/find.codes"' \
		-I$(GNUFIND)/lib -o ixlookup ixlookup.c \
		$(GNUFIND)/lib/libfind.a

install-ixlookup:	ixlookup
	install -s -m 0555 -c ixlookup $(LIBDIR)

################ Cleanup ################

clean:
	rm -f *~ core a.out $(PEARLS) mlistener listener listener.c \
	    *.orig *.rej ixlookup.c ixlookup

################ Maintenance ################

REV	= X3.01

dist:	tar.Z

tar.Z:	HELP INSTALL
	rm -f mserv-$(REV)
	ln -s . mserv-$(REV)
	sed < MANIFEST -e "s/^/mserv-$(REV)\//" | \
	    pdtar -zcv -T - -f mserv-$(REV).tar.Z
	rm -f mserv-$(REV)

shar:	HELP INSTALL
	rm -f mserv-$(REV)
	ln -s . mserv-$(REV)
	rm -f mserv-$(REV).shar.*
	sed < MANIFEST -e "s/^/mserv-$(REV)\//" | \
	    shar -p -F -S -L 50 -o mserv-$(REV).shar \
		-a -n mserv-$(REV).shar -s 'jv@mh.nl (Johan Vromans)'
	rm -f mserv-$(REV)
	ls -l mserv-$(REV).shar.*

AUX   = Makefile ms_config.pl ChangeLog* Misc

TZ:
	tar cvf - $(AUX) SCCS | compress > mserv.TZ

#
# Create formatted documents (Ascii or PostScript)
#
.SUFFIXES:	.ps .txt .asc
MH_DOC	= mh_doc -language uk

.txt.ps:
	rm -f $@
	$(MH_DOC) -expert -verbose -ps -printer foo:ps -output $@ $<

.txt.asc:
	rm -f $@
	$(MH_DOC) -text -output $@ $<

HELP:	usrguide.asc
	rm -f $@ && cp $< $@ && chmod -w $@

INSTALL:	mservmgr.asc
	rm -f $@ && cp $< $@ && chmod -w $@
