# $Cambridge: hermes/src/prayer/files/Makefile,v 1.10 2008/10/30 11:28:59 dpc22 Exp $
#
# Prayer - a Webmail Interface
#
# Copyright (c) University of Cambridge 2000 - 2002
# See the file NOTICE for conditions of use and distribution.

ifeq ($(strip $(RPM_BUILD)), true)
include ../Config-RPM
else
include ../Config
endif

all:	./etc/prayer.cf ./init.d/prayer

./etc/prayer.cf: ./etc/prayer.cf.SRC
	perl -pe "s&__PREFIX__&${PREFIX}&; s&__VAR_PREFIX__&${VAR_PREFIX}&; s&__BIN_DIR__&${BIN_DIR}&;" < ./etc/prayer.cf.SRC > ./etc/prayer.cf

./init.d/prayer: ./init.d/prayer.SRC
	perl -pe "s&__PREFIX__&${PREFIX}&; s&__VAR_PREFIX__&${VAR_PREFIX}&; s&__BIN_DIR__&${BIN_DIR}&; s&__PRAYER_CONFIG_FILE__&${PRAYER_CONFIG_FILE}&;" < ./init.d/prayer.SRC > ./init.d/prayer


ifeq ($(strip $(SSL_ENABLE)), true)
cert:
	rm -f ./certs/prayer.pem
	$(OPENSSL) req -new -x509 -days 365 -nodes \
		-config ./certs/prayer.cnf \
		-out    ./certs/prayer.pem \
		-keyout ./certs/prayer.pem
	$(OPENSSL) x509 -subject -dates -fingerprint -noout \
		-in ./certs/prayer.pem
else
cert:
	echo "SSL disabled"
endif

clean:
	rm -f  core *.o *.flc *~ \#*\#
	rm -f  etc/prayer.cf etc/*~ etc/\#*\#
	rm -f  init.d/prayer init.d/*~ init.d/\#*\#
	rm -rf sending
	rm -rf sockets/?    # Split spool
	find sockets    \! -path "sockets/CVS*"    \! -type d | xargs rm -f
	find tmp        \! -path "tmp/CVS*"        \! -type d | xargs rm -f
	find pid        \! -path "pid/CVS*"        \! -type d | xargs rm -f
	find ssl_scache \! -path "ssl_scache/CVS*" \! -type d | xargs rm -f
	find logs       \! -path "logs/CVS*"       \! -type d | xargs rm -f
	rm -f  certs/*~ certs/\#*\#

distclean:
	rm -f certs/prayer.pem

install-cert:
	if [ -f certs/prayer.pem ]; then \
	$(INSTALL) -o $(RO_USER) -g $(RO_GROUP) \
	-m $(PRIVATE_FILE) certs/prayer.pem ${BROOT}${PREFIX}/certs; \
	fi

install-config: etc/prayer.cf
	$(INSTALL) -D -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_FILE) \
	etc/prayer.cf ${BROOT}${PRAYER_CONFIG_FILE}

install-aconfig:
	$(INSTALL) -D -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_FILE) \
	etc/prayer-accountd.cf ${BROOT}${ACCOUNTD_CONFIG_FILE}

install-motd:
	$(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_FILE) \
	etc/motd.html ${BROOT}${PREFIX}/etc

install:
	PREFIX=$(BROOT)$(PREFIX) VAR_PREFIX=$(BROOT)$(VAR_PREFIX) \
	RO_USER=$(RO_USER) RO_GROUP=$(RO_GROUP) \
	RW_USER=$(RW_USER) RW_GROUP=$(RW_GROUP) \
	PUBLIC_DIR=$(PUBLIC_DIR) PRIVATE_DIR=$(PRIVATE_DIR) \
	PUBLIC_FILE=$(PUBLIC_FILE) PRIVATE_FILE=$(PRIVATE_FILE) \
	PUBLIC_EXEC=$(PUBLIC_FILE) PRIVATE_EXEC=$(PRIVATE_EXEC) \
	BIN_DIR=$(BIN_DIR) INSTALL=$(INSTALL) \
	./install.sh
	if [ ! -f $(BROOT)$(PREFIX)/certs/prayer.pem ]; then $(MAKE) install-cert; fi
	if [ ! -f $(BROOT)$(PRAYER_CONFIG_FILE) ]; then $(MAKE) install-config; fi
	if [ ! -f $(BROOT)$(ACCOUNTD_CONFIG_FILE) ]; then $(MAKE) install-aconfig; fi
	if [ ! -f $(BROOT)$(PREFIX)/etc/motd.html ]; then $(MAKE) install-motd; fi

redhat-install-init.d:
	install -D -o root -g root -m 755 \
		./init.d/prayer $(BROOT)/etc/rc.d/init.d/prayer
	#chkconfig prayer --level 2345 on
