#$Modified: Tue Oct  8 22:30:29 1996 by cwilson $
#
# /sources/cvsrepos/majordomo/Makefile,v
# 1.48
# 1996/10/08 20:46:16
# /sources/cvsrepos/majordomo/Makefile,v 1.48 1996/10/08 20:46:16 cwilson Exp
# 

#  This is the Makefile for Majordomo.  
# 
#-------------  Configure these items ----------------# 
#
# Where is Perl located?

PERL = 		/bin/perl5

# 
# If your default 'chown' doesn't support the USER.GROUP syntax,
# specify one that does here.

CHOWN = 	chown

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

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

# 
# Where do you want the manual pages installed?  By default, this is 
# $(W_HOME)/man/man[18]
#
MAN1 = $(W_HOME)/man/man1
MAN8 = $(W_HOME)/man/man8

# 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.

# majordomo on my system
#
W_USER =	443
#
# daemon on my system
#
W_GROUP =       1
#
# You might need to change : to .
#
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!!)
#
WRAPPER_CHOWN = 	root
WRAPPER_CHMOD =	4755

POSIX = -DPOSIX_UID=$(W_USER) -DPOSIX_GID=$(W_GROUP)

# Define this if the majordomo programs should *also* be run in the same
# group as your MTA, usually sendmail.  This is rarely needed, but some
# MTAs require certain group memberships before allowing the message sender
# to be set arbitrarily.
#
# 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 new-list sequencer digest

BINBIN =	approve bounce medit

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

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

install: wrapper install-scripts install-cf install-man
	@echo ""
	@echo "To finish the installation, 'su' to root and type:"
	@echo ""
	@echo "	    make install-wrapper"
	@echo ""
	@echo "If not installing the wrapper, type"
	@echo ""
	@echo "	    cd $(W_HOME); ./wrapper config-test"
	@echo ""
	@echo "(no 'su' necessary) to verify the installation."


install-wrapper: wrapper
	@echo "Installing wrapper in $(W_BIN), owner/group $(WRAPPER_CHOWN), perms $(WRAPPER_CHMOD)"
	@cp wrapper       $(W_BIN)/wrapper
	$(CHOWN) $(WRAPPER_CHOWN) $(W_BIN)/wrapper
	chmod $(WRAPPER_CHMOD) $(W_BIN)/wrapper
	@echo ""
	@echo "To verify that all the permissions and etc are correct,"
	@echo "run the command"
	@echo ""
	@echo "	     cd $(W_HOME); ./wrapper config-test"

# 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:
	@echo "Testing for perl ($(PERL))..."
	@test -x $(PERL) || \
		{ echo "You didn't correctly tell me where Perl is."; exit 1; } 
	@test -d tmp || mkdir tmp
	@echo "Configuring scripts..."
	@-for file in $(TOOLS); do \
		cp contrib/$$file tmp ; \
	done
	@cp $(BINBIN) $(BIN) tmp
	@cd tmp;	$(PERL) -p -i -e 's@^#!\S+perl.*@#!$(PERL)@' $(TOOLS) $(BINBIN) $(BIN) 


install-scripts: config-scripts
	@test -d $(W_HOME) || (mkdir $(W_HOME); chmod 750 $(W_HOME))
	@-$(CHOWN) $(W_CHOWN) $(W_HOME) || \
		( echo ""; \
		  echo "Hmmm, if $(W_HOME) doesn't have an owner and group of"; \
		  echo "	$(W_USER) $(W_GROUP), do a ";\
		  echo "" ; \
		  echo "	$(CHOWN) $(W_CHOWN) $(W_HOME)"; \
		  echo "(as root.)"; \
		ls -lLnd $(W_HOME); echo "")
	@test -d $(W_BIN)/bin || (mkdir $(W_BIN)/bin; \
		$(CHOWN) $(W_CHOWN) $(W_BIN)/bin)

	@echo "Copying tools to $(W_BIN)/bin"

	@for file in $(BINBIN); do \
		chmod +x tmp/$$file ; \
		rm -f $(W_BIN)/bin/$$file; \
		mv tmp/$$file $(W_BIN)/bin ; \
		$(CHOWN) $(W_CHOWN) $(W_BIN)/bin/$$file ; \
	done

	@echo "Copying Majordomo files to $(W_BIN)"

	@for file in $(BIN); do \
		chmod +x tmp/$$file ; \
		rm -f $(W_BIN)/$$file ; \
		mv tmp/$$file $(W_BIN) ; \
		$(CHOWN) $(W_CHOWN) $(W_BIN)/$$file ; \
	done

	@echo "Copying archiving and other tools to $(W_BIN)/Tools"

	@test -d $(W_BIN)/Tools || (mkdir $(W_BIN)/Tools; \
		$(CHOWN) $(W_CHOWN) $(W_BIN)/Tools)
	@for file in $(TOOLS); do \
		chmod +x tmp/$$file ; \
		rm -f $(W_BIN)/Tools/$$file ; \
		mv tmp/$$file $(W_BIN)/Tools ; \
		$(CHOWN) $(W_CHOWN) $(W_BIN)/Tools/$$file ; \
	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;
	@rm -f $(W_BIN)/sample.cf; cp sample.cf $(W_BIN); \
		$(CHOWN) $(W_CHOWN) $(W_BIN)/sample.cf
	@-$(CHOWN) $(W_CHOWN) $(W_BIN)/majordomo.cf  || \
		( echo ""; \
		  echo "Hmmm, if $(W_HOME) doesn't have an owner and group of"; \
		  echo "	$(W_USER) $(W_GROUP), do a "; \
		  echo ""; \
		  echo "	$(CHOWN) $(W_CHOWN) $(W_HOME)" ; \
		  echo "(as root.)"; \
		ls -lLnd $(W_HOME); echo "")


install-man:
	@echo "Copying manual pages to $(MAN1) and $(MAN8)"
	@test -w $(MAN1) || (mkdir $(MAN1); \
		$(CHOWN) $(W_CHOWN) $(MAN1) )
	@test -w $(MAN8) || (mkdir $(MAN8); \
		$(CHOWN) $(W_CHOWN) $(MAN8) )
	@cp Doc/man/approve.1 $(MAN1)
	@cp Doc/man/digest.1 $(MAN1)
	@cp Doc/man/bounce-remind.1 $(MAN1)
	@cp Doc/man/majordomo.8 $(MAN8)
#	@-$(CHOWN) $(W_CHOWN) $(W_BIN)/man/man[18]/*


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-$(VERSION)/CVS majordomo-$(VERSION)/*/CVS \
		majordomo-$(VERSION)/*/*/CVS
	tar -cvf majordomo-$(VERSION).tar.Z\
		  majordomo-$(VERSION)
