#
# /sources/cvsrepos/majordomo/Makefile,v
# 1.36
# 1996/07/28 09:05:35
# /sources/cvsrepos/majordomo/Makefile,v 1.36 1996/07/28 09:05:35 cwilson Exp
# 

#  This is the Makefile for Majordomo.  
# 
#-------------  Configure these items ----------------# 
#
# Wither perl? 

PERL = 		/bin/perl5

#  
# The location of Majordomo.  Wrapper looks here for programs to run.

W_HOME	=	/usr/test/majordomo-$(VERSION)


# What permissions does wrapper need?   
# (6755 = -rwsr-s-r-x, 4755 = -rwsr-xr-x)
# *** This gets reset below if this is a POSIX system ***

W_CHMOD =	6755

# This is the environment that (along with LOGNAME and USER inherited from the
# parent process, and without the leading "W_" in the variable names) gets
# passed to processes run by "wrapper"

W_PATH = 	/bin:/usr/bin:/usr/ucb
W_BIN =		${W_HOME}
W_SHELL =	/bin/csh
W_MAJORDOMO_CF =	$(W_BIN)/majordomo.cf

# Which user and group will majordomo be running under?  
# Everything under $W_HOME needs to be writable by this user and/or group.

W_USER =	443			# majordomo on my system
W_GROUP =       10			# daemon on my system
W_CHOWN =	${W_USER}.${W_GROUP}

# If installing wrapper 'shared', define what the suffix of wrapper is.
# (I'd like to hear if anybody is using MJ this way)

# ARCHCMD=`arch`
# ARCHCMD=`uname -m`

#------------- POSIX SECTION -----------------------------

# If you're running on a POSIX complient system:
# 	Sun Solaris, 
#	SGI Irix 5 and 6, 
#	Dec Ultrix MIPS, 
#	BSDI,
#	Linux
# make sure the following are uncommented.  
# (Sun SunOS, SGI Irix 4, and HP DomainOS are NOT POSIX!!)
#
W_CHOWN = 	root
W_CHMOD =	4755

POSIX = -DPOSIX_UID=${W_USER} -DPOSIX_GID=${W_GROUP}

# Define this if wrapper should *also* be in the same group as your
# MTA, usually sendmail.  See the INSTALLATION file for more details.
#
# MAIL_GID = 	numeric_gid_of_MTA


#--------YOU SHOULDN'T HAVE TO CHANGE ANYTHING BELOW THIS LINE.-------------

VERSION =	1.94

WRAPPER_FLAGS = -DBIN=\"${W_BIN}\" -DPATH=\"PATH=${W_PATH}\" \
	-DHOME=\"HOME=${W_HOME}\" -DSHELL=\"SHELL=${W_SHELL}\" \
	-DMAJORDOMO_CF=\"MAJORDOMO_CF=${W_MAJORDOMO_CF}\"      \
	${POSIX}

# For those stupid machines that try to use csh. Doh!
SHELL = /bin/sh

TOOLS =		archive2.pl archive.pl archive_mh.pl \
		digest.send makeindex.pl \
		logsummary.pl

BINBIN =	approve bounce medit

BIN = 		bounce-remind config_parse.pl majordomo majordomo.pl \
		majordomo_version.pl new-list request-answer resend resend.README \
		shlock.pl config-test

DIGEST = 	digest

default: 
	@-echo "make what?\n\tinstall: installs everything."
	@-echo "\tinstall-wrapper: only install wrapper."
	@-echo "\tinstall-scripts: only install the scripts."
	@-echo "\twrapper: only make wrapper."

install: install-scripts install-man install-wrapper


install-wrapper: wrapper
	cp wrapper       $(W_BIN)/wrapper
	chown ${W_CHOWN} $(W_BIN)/wrapper
	chmod ${W_CHMOD} $(W_BIN)/wrapper

# fix where perl lives.
# Create a tmp directory to stuff all the files in, so we 
# don't go blithly changing the master copies of stuff.  
#
config-scripts:
	@-test -x $(PERL) || \
		echo "You didn't correctly tell me where Perl is."
	@-test -d tmp || mkdir tmp
	for file in $(TOOLS); do \
		cp contrib/$$file tmp ; \
	done
	cp $(BINBIN) $(BIN) digest/$(DIGEST) tmp
	cd tmp;	$(PERL) -p -i -e 's@^#!\S+perl.*@#!$(PERL)@' $(TOOLS) $(BINBIN) $(BIN) $(DIGEST)


install-scripts: install-cf config-scripts
	@-test -d $(W_HOME) || mkdir $(W_HOME)
	@-test -d $(W_BIN)/bin || mkdir $(W_BIN)/bin
	for file in $(BINBIN); do \
		mv tmp/$$file $(W_BIN)/bin ; \
	done

	for file in $(BIN); do \
		chmod +x tmp/$$file ; \
		mv tmp/$$file $(W_BIN) ; \
	done

	@-test -d $(W_BIN)/Tools || mkdir $(W_BIN)/Tools
	for file in $(TOOLS); do \
		chmod +x tmp/$$file ; \
		mv tmp/$$file $(W_BIN)/Tools ; \
	done

	for file in $(DIGEST); do \
		mv tmp/$$file $(W_BIN)/Tools ; \
	done
	rm -rf tmp	

# the install.cf target will install the sample config file in the
# proper place unless a majordomo.cf file exists in which case the
# majordomo.cf file will be used.
# but now it won't overwrite an existing majordomo.cf file.
install-cf:
	@if [ ! -f $(W_BIN)/majordomo.cf ]; \
	  then \
	    if [ -f majordomo.cf ]; \
	      then \
		echo "Using majordomo.cf"; \
	  	cp majordomo.cf $(W_BIN)/majordomo.cf; \
	      else \
		echo "using sample.cf"; \
		cp sample.cf $(W_BIN)/majordomo.cf; \
	    fi; \
	else \
	   echo "Using installed majordomo.cf"; \
	fi;

install-man:
	@-test -d $(W_BIN)/man || mkdir $(W_BIN)/man
	@-test -d $(W_BIN)/man/man1 || mkdir $(W_BIN)/man/man1
	@-test -d $(W_BIN)/man/man8 || mkdir $(W_BIN)/man/man8
	cp Doc/man/approve.1 $(W_BIN)/man/man1
	cp Doc/man/majordomo.8 $(W_BIN)/man/man8

install-shared: install-wrapper-shared install-scripts

install-wrapper-shared: wrapper
	@test -d $(W_BIN)/wrappers || mkdir $(W_BIN)/wrappers
	@test -d $(W_BIN)/wrappers/$(W_GROUP) || mkdir $(W_BIN)/wrappers/$(W_GROUP)
	strip wrapper
	cp wrapper $(W_BIN)/wrappers/$(W_GROUP)/wrapper.$(ARCHCMD)
	cp wrapper.sh $(W_BIN)/wrappers/$(W_GROUP)/wrapper
	@echo 'run make permissions-shared' as root to set permissions

permissions-shared:
	chown ${W_CHOWN} $(W_BIN)/wrappers/$(W_GROUP)/wrapper.$(ARCHCMD)
	chown ${W_CHOWN} $(W_BIN)/.
	chmod ${W_CHMOD} $(W_BIN)/wrappers/$(W_GROUP)/wrapper.$(ARCHCMD)

wrapper: wrapper.c
	cc  ${WRAPPER_FLAGS} -o wrapper wrapper.c

clean:
	rm -f  wrapper *~

dist-clean: clean
	rm -f majordomo.cf .cvsignore todo.local .dcl archive
	rm -rf regress Doc/samples Tools

distribution: dist-clean
	mkdir majordomo-$(VERSION)
	mv * .??* majordomo-$(VERSION) || exit 0
	rm -rf majordomo-1.93a/CVS majordomo-$(VERSION)/*/CVS \
		majordomo-$(VERSION)/*/*/CVS
	tar -cvf majordomo-$(VERSION).tar.Z\
		  majordomo-$(VERSION)
