#
# Makefile for the mklist/rmlist mailing list suite
# By Alan Schwartz, 1996
#
# The following targets are defined:
#  mklist: the mklist program
#  rmlist: the rmlist program
#  all: both mklist and rmlist
#  install.dirs: create the mailing list directory
#  install.bin: install mklist and rmlist
#  install.cron: install this Makefile and the inclist script for cron
#  install.man: install the manual pages for mklist, rmlist, and inclist
#  install: install everything
#  aliases: rebuild /etc/aliases using inclist. This target should be
#           run from root's crontab every 15 minutes or so.
#  help: this list

# The location of your sendmail aliases file
ALIASES=/etc/aliases

# The name of a lock file; if this file exists, inclist won't modify
# your aliases file.
LOCKFILE=/etc/aliases.lock

# The location of perl on your system
PERL=/usr/local/bin/perl

# The directory where you want to store mailing list subscriber files
LISTDIR=/usr/local/etc/mailing-lists

# The mode for LISTDIR and rmlist
# If your system supports the sticky bit on directories
LISTDIRMODE=1777
RMLISTMODE=755
# If you system doesn't, uncomment this
#LISTDIRMODE=755
#RMLISTMODE=4755

# The mode for mklist
# If your system supports sticky bit, and /etc/aliases is world-readable:
MKLISTMODE=755
# Otherwise:
#MKLISTMODE=4755

# The directory where you want to install the mklist and rmlist programs
INSTBINDIR=/usr/local/bin

# The directory where you want to install the man pages
INSTMANDIR=/usr/local/man

# The directory where you want to install this Makefile and the inclist
# script, which are called from root's crontab. The Makefile will be
# renamed to Make.mailing-lists
INSTCRONDIR=/usr/local/etc

# Where should users email if they have problems?
TROUBLEADDR=staff

### Probably no need to modify anything below this line ###

# Some systems need this
MAKE=make
SHELL=/bin/sh
CC=cc
CCFLAGS=-O -DLISTDIR=\"$(LISTDIR)\" -DALIASES=\"$(ALIASES)\" \
	-DTROUBLEADDR=\"$(TROUBLEADDR)\"

all: mklist rmlist

mklist: mklist.c
	$(CC) $(CCFLAGS) -o mklist mklist.c

rmlist: rmlist.c
	$(CC) $(CCFLAGS) -o rmlist rmlist.c

install: install.dirs install.bin install.cron install.man

install.dirs: all
	-mkdir $(LISTDIR)
	chown root ($LISTDIR)
	chmod $(LISTDIRMODE) $(LISTDIR)

install.bin: all
	-mkdir $(INSTBINDIR)
	cp mklist $(INSTBINDIR)/mklist
	-strip $(INSTBINDIR)/mklist
	chown root $(INSTBINDIR)/mklist
	chmod $(MKLISTMODE) $(INSTBINDIR)/mklist
	cp rmlist $(INSTBINDIR)/rmlist
	-strip $(INSTBINDIR)/rmlist
	chown root $(INSTBINDIR)/rmlist
	chmod $(RMLISTMODE) $(INSTBINDIR)/rmlist

install.man: $(INSTMANDIR)/man1/mklist.1 \
$(INSTMANDIR)/man1/rmlist.1 $(INSTMANDIR)/man8/inclist.8

$(INSTMANDIR)/man1/mklist.1: mklist.1
	cp mklist.1 $(INSTMANDIR)/man1/mklist.1
	$(PERL) -npi~ -e 's/@@LISTDIR@@/$(LISTDIR)/g' $(INSTMANDIR)/man1/mklist.1
	-rm $(INSTMANDIR)/man1/mklist.1~

$(INSTMANDIR)/man1/rmlist.1: mklist.1
	cp mklist.1 $(INSTMANDIR)/man1/rmlist.1
	$(PERL) -npi~ -e 's/@@LISTDIR@@/$(LISTDIR)/g' $(INSTMANDIR)/man1/rmlist.1
	-rm $(INSTMANDIR)/man1/rmlist.1~

$(INSTMANDIR)/man8/inclist.8: inclist.8
	cp inclist.8 $(INSTMANDIR)/man8/inclist.8
	$(PERL) -npi~ -e 's/@@LISTDIR@@/$(LISTDIR)/g' \
	-e 's/@@LOCKFILE@@/$(LOCKFILE)/g' $(INSTMANDIR)/man8/inclist.8
	-rm $(INSTMANDIR)/man8/inclist.8~

install.cron: inclist Makefile
	-mkdir ($INSTCRONDIR)
	cp inclist $(INSTCRONDIR)/inclist
	chown root $(INSTCRONDIR)/inclist
	chmod 700 $(INSTCRONDIR)/inclist
	cp Makefile $(INSTCRONDIR)/Make.mailing-lists
	chown root $(INSTCRONDIR)/Make.mailing-lists
	chmod 600 $(INSTCRONDIR)/Make.mailing-lists


# This target is actually used in day-to-day operations. We check to
# see if /etc/aliases is older than LISTDIR and if so, we run
# inclist
aliases:
	$(MAKE) -f $(INSTCRONDIR)/Make.mailing-lists $(ALIASES)

$(ALIASES): $(LISTDIR)
	$(PERL) $(INSTCRONDIR)/inclist $(LISTDIR) $(ALIASES) $(LOCKFILE)
        

help: 
	@echo "The following targets are defined:"
	@echo " mklist: the mklist program"
	@echo " rmlist: the rmlist program"
	@echo " all: both mklist and rmlist"
	@echo " install.dirs: create the mailing list directory"
	@echo " install.bin: install mklist and rmlist"
	@echo " install.cron: install this Makefile and the inclist script for cron"
	@echo " install.man: install the manual pages for mklist, rmlist, and inclist"
	@echo " install: install everything"
	@echo " aliases: rebuild /etc/aliases using inclist. This target should be"
	@echo "          run from root's crontab every 15 minutes or so."
	@echo " help: this list"
