#
# Makefile for the Mason firewall builder
#
#Copyleft:
#    Mason interactively creates a Linux packet filtering firewall.
#    Copyright (C) 1998-2000 William Stearns <wstearns@pobox.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#    The author can also be reached at:
#        William Stearns
#email:  wstearns@pobox.com              (preferred)
#web:    http://www.pobox.com/~wstearns
#snail:  6 Manchester Dr.
#        Lebanon NH, 03766, USA
#

# Modified for Debian GNU/Linux.
DESTDIR =

##Make sure mason has MASONVER updated when this changes
MASONVER = 1.0.0

#No quotes around multi file specs.
BINDIR=$(DESTDIR)/usr/bin/
BINFILES=mason mason-gui-text mason-decide
CONFDIR=$(DESTDIR)/etc/
CONFFILE=masonrc
LIBDIR=$(DESTDIR)/var/lib/mason/
LIBFILES=masonlib baserules.sample graffiti-services moreservices nmap-services portsdb-services regression-test all-ip-numbers.txt
DOCDIR=$(DESTDIR)/usr/doc/mason-${MASONVER}/
DOCFILES=COPYING index.html mason.sgml mason.txt mason.html mason-1.html mason-2.html mason-3.html mason-4.html mason-5.html mason-6.html mason-7.html mason-8.html mason-9.html mason-10.html mason-11.html toc.gif prev.gif next.gif mason-banner.gif
#DOCDIR=$(DESTDIR)/usr/doc/mason/
#DOCFILES=index.html mason.sgml mason.txt mason.html mason-1.html mason-2.html mason-3.html mason-4.html mason-5.html mason-6.html mason-7.html mason-8.html mason-9.html mason-10.html mason-11.html toc.gif prev.gif next.gif
MANDIR=$(DESTDIR)/usr/man/man1/
MANFILES=mason.1 mason-gui-text.1
SYSVDIR=$(DESTDIR)/etc/rc.d/init.d/
SYSVFILES=firewall
# SYSVDIR=/etc/rc.d/init.d/
# SYSVFILES=firewall

install:
	@echo -n "Installing files... "
	@echo -n "${BINFILES}... "
	@install -o root -g root -m 0755 ${BINFILES} ${BINDIR}
	@echo -n "lib directory... "
	@install -o root -g root -m 0755 -d ${LIBDIR}
	@echo -n "${LIBFILES}... "
	@install -o root -g root -m 0644 ${LIBFILES} ${LIBDIR}
	@echo -n "doc directory... "
	@install -o root -g root -m 0755 -d ${DOCDIR}
	@echo -n "${DOCFILES}... "
	@install -o root -g root -m 0644 ${DOCFILES} ${DOCDIR}
	@echo -n "${MANFILES}... "
	@install -o root -g root -m 0644 ${MANFILES} ${MANDIR}
	@echo -n "${SYSVFILES}... "
	@install -o root -g root -m 0755 ${SYSVFILES} ${SYSVDIR}
	@if [ ! -f ${LIBDIR}baserules ] ; then \
	install -o root -g root -m 0600 ${LIBDIR}baserules.sample ${LIBDIR}baserules ; \
	echo -n "baserules... " ; \
	else \
	echo -n "${LIBDIR}baserules already exists, not overwriting... " ; \
	fi
	@if [ ! -f ${CONFDIR}${CONFFILE} ] ; then \
	install -o root -g root -m 0600 ${CONFFILE} ${CONFDIR}${CONFFILE} ; \
	echo -n "${CONFFILE}... " ; \
	else \
	rm -f ${CONFDIR}${CONFFILE}.old ; \
	mv -f ${CONFDIR}${CONFFILE} ${CONFDIR}${CONFFILE}.old ; \
	install -o root -g root -m 0600 ${CONFFILE} ${CONFDIR}${CONFFILE} ; \
	echo "" >>${CONFDIR}${CONFFILE} ; \
	echo "#Your previous settings, if any:" >>${CONFDIR}${CONFFILE} ; \
	cat ${CONFDIR}${CONFFILE}.old | grep -v "^#" | grep -v "^$$" >>${CONFDIR}${CONFFILE} ; \
	echo -n "${CONFDIR}${CONFFILE} already exists, appending your settings to the new ${CONFFILE}... " ; \
	fi
	@echo done!

docs:
	sgml2html --imagebuttons mason.sgml \
	&& sgml2txt -f mason.sgml \
	&& makedoc mason.txt mason.pdb 'The Mason HOWTO'

regress:
	@if ./regression-test ; then \
	echo Regression test succeeded. ; \
	else \
	echo Regression test failed, exiting. ; \
	exit 1 ; \
	fi

distribs: regress docs
	@echo This should only need to be used by the author in 
	@echo packing up the mason package.
	@cat /etc/services | grep -v PRIVATE >moreservices
	cd .. \
	&& tar cf - mason-${MASONVER}/ | \
	gzip -9 > mason-${MASONVER}.tar.gz \
	&& rm -f mason-current \
	&& ln -sf mason-${MASONVER} mason-current \
	&& tar cf - mason-current/* | \
	gzip -9 > mason-current.tar.gz \
	&& cp mason-${MASONVER}.tar.gz /usr/src/redhat/SOURCES/ \
	&& cd mason-${MASONVER} \
	&& cp -f redhat/mason.spec /usr/src/redhat/SPECS/ \
	&& rpm --sign -ba /usr/src/redhat/SPECS/mason.spec \
	&& mv -f /usr/src/mason-*.tar.gz /usr/src/mysource/ \
	&& mv -f /usr/src/redhat/RPMS/noarch/mason-*.noarch.rpm /usr/src/mysource/ \
	&& mv -f /usr/src/redhat/SRPMS/mason-*.src.rpm /usr/src/mysource/

mini-install:
	cp -pf mason mason-decide mason-gui-text /usr/bin ; cp -pf masonlib baserules.sample /var/lib/mason

