
#-----------------------------------------------------------------------
# Copyright (C) 2000-2001, Jean-Sebastien Morisset <jsmoriss@mvlan.net>
#-----------------------------------------------------------------------
# $Id: Makefile,v 1.55 2001/12/15 19:25:50 jsmoriss Exp $
#-----------------------------------------------------------------------
#  $RCSfile: Makefile,v $
#   $Author: jsmoriss $
# $Revision: 1.55 $
#     $Date: 2001/12/15 19:25:50 $
#   $Locker:  $ 
#     $Name:  $
#-----------------------------------------------------------------------
#
# 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 <http://www.gnu.org/copyleft/gpl.txt>.
# 
# 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 (LICENSE file in archive) for more details.
#
#-----------------------------------------------------------------------
# README
#-----------------------------------------------------------------------
#
# INSTALLATION:
#
#   # make install
#
# You can follow the backup and install options with an installation
# prefix. i.e. "make backup PREFIX=/usr/local/rcf". By default, all
# files and directories are created from the root directory
# (/etc/firewall/, /usr/man/, /sbin/rcf, etc.).
#
# DEVELOPERS:
#
# You can use the same steps as above, although you'll probably want to
# use 'install_quick' to avoid the 'rcf -uc' command. Other make 
# commands are available to generate distribution packages, etc.
#
#    # make rpm
#     (create tar/gz/rpm distros under /var/tmp/rcfpkg)
#
#   # make tar gzip bzip2
#     (create tar/gz/bzip2 - you must create a tar first for gzip/bzip2)
#
#   # make distros PKG_SAVEDIR=/var/tmp
#     (create tar/gz/bzip2/rpm/lrp distros in /var/tmp)
#
#   # make deb
#     (creates debian binary package of CVS version of RCF - requires
#     'fakeroot', 'devscripts' and 'debhelper' packages)
#
#-----------------------------------------------------------------------

PROJECT_NAME     = rcf
PROJECT_VERSION  = 5.2.1
# a)lpha, b)eta, c)andidate, or s)table
PROJECT_MATURITY = s
PROJECT_RELEASE  = 1

CVS_MODULE = $(PROJECT_NAME)-$(PROJECT_VERSION)
CVS_BRANCH = $(PROJECT_MATURITY)$(PROJECT_RELEASE)

PKG_RELEASE   = 1
PKG_VERSION   = $(PROJECT_VERSION)$(PROJECT_MATURITY)$(PROJECT_RELEASE)
PKG_FILENAME  = $(PROJECT_NAME)-$(PKG_VERSION)
PKG_SAVEDIR   = /var/tmp/rcfpkg
PKG_BUILDROOT = /var/tmp/$(PROJECT_NAME)-buildroot
PKG_SOURCE    = http://rcf.mvlan.net/dist/dev/$(PKG_FILENAME).tar.gz

LRP_FILENAME = `echo $(PKG_FILENAME)|sed -e 's/[^a-zA-Z0-9]//g'`

DATE   = `date +'%Y%m%d%H%M'`
SHELL  = /bin/sh
PREFIX = 

# default target
all: check_pwd man link

	@echo ""
	@echo "--------------------------------------------------------------------------------"
	@echo "sub-directories, man pages, and symbolic links have been created."
	@echo "--------------------------------------------------------------------------------"
	@echo ""


check_pwd:
	@#
	@# make sure we're in the rcf source directory and all files are present.
	@# called by all, clean, and rpm sections.
	@#
	if [ ! -f ./.spec      ]; then exit 1; fi
	if [ ! -f ./ChangeLog  ]; then exit 1; fi
	if [ ! -f ./FAQ.html   ]; then exit 1; fi
	if [ ! -f ./INSTALL    ]; then exit 1; fi
	if [ ! -f ./LICENSE    ]; then exit 1; fi
	if [ ! -f ./Makefile   ]; then exit 1; fi
	if [ ! -f ./TODO       ]; then exit 1; fi
	if [ ! -d ./etc	       ]; then exit 1; fi
	if [ ! -f ./fwinit     ]; then exit 1; fi
	if [ ! -d ./sbin       ]; then exit 1; fi
	if [ ! -d ./usr        ]; then exit 1; fi


check_clean:
	@if [ -d ./var -o -L ./etc/firewall/modules/private/services/750-BLOCK-LOCAL-PORTS ]; then \
		echo ""; \
		echo "--------------------------------------------------------------------------------"; \
		echo "please execute \"make clean\" first..."; \
		echo "--------------------------------------------------------------------------------"; \
		echo ""; \
		exit 1; \
	fi


backup:
	if [ -f $(PREFIX)/etc/firewall.conf ]; then \
		cp $(PREFIX)/etc/firewall.conf $(PREFIX)/etc/firewall.conf-$(DATE); fi

	@# some files and/or directories should be moved...
	for file in \
		$(PREFIX)/etc/firewall-modules \
		; \
	do if [ -e "$$file" ]; then mv $$file $$file-$(DATE); fi; done

	@# but others are better copied...
	for file in \
		$(PREFIX)/etc/firewall \
		$(PREFIX)/etc/rc.d/init.d/firewall \
		$(PREFIX)/sbin/rcf \
		; \
	do \
		if [ -d "$$file" ]; then \
			mkdir -p $$file-$(DATE) && \
				cd $$file && \
					tar -cf - . | tar -C $$file-$(DATE) -xf -; \
		elif [ -f "$$file" ]; then \
			cp -p $$file $$file-$(DATE); \
		fi; \
	done

	@echo ""
	@echo "--------------------------------------------------------------------------------"
	@echo "essential files/directories have been backed-up with the $(DATE) suffix."
	@echo "--------------------------------------------------------------------------------"
	@echo ""


install: all install_pre install_doc install_tar install_rc install_uc clean


install_quick: all install_pre install_doc install_tar install_rc clean


install_pre:

	rm -f $(PREFIX)/var/catman/cat5/rcf-groups.5.gz
	rm -f $(PREFIX)/var/catman/cat5/rcf-modules.5.gz
	rm -f $(PREFIX)/var/catman/cat8/rcf.8.gz

	@#
	@# remove out-dated directories and files...
	@#
	rm -rf $(PREFIX)/etc/firewall/modules/contrib
	rm -f $(PREFIX)/etc/firewall/functions/illegal_malformed_address_rules.sh
	rm -f $(PREFIX)/etc/firewall/functions/interface_in_type.sh
	rm -f $(PREFIX)/etc/firewall/functions/private_networks_chains.sh
	rm -f $(PREFIX)/etc/firewall/functions/private_networks_spoofing_chains.sh

	rm -f $(PREFIX)/etc/firewall/modules/*/services/[0-9][0-9][0-9]-*-ports
	rm -f $(PREFIX)/etc/firewall/modules/*/services/250-simap-clients
	rm -f $(PREFIX)/etc/firewall/modules/*/services/260-spop3-clients
	rm -f $(PREFIX)/etc/firewall/modules/*/services/260-spop3-servers
	rm -f $(PREFIX)/etc/firewall/modules/*/services/270-imap2-clients
	rm -f $(PREFIX)/etc/firewall/modules/*/services/270-imap2-servers

	rm -f $(PREFIX)/etc/firewall/modules/public/block-remote-ports/imap

	if [ -f "$(PREFIX)/etc/rc.d/init.d/firewall" -a -x /sbin/chkconfig ]; \
	then \
		/sbin/chkconfig --del firewall; \
	elif [ -d "$(PREFIX)/etc/init.d" ]; \
	then \
		for num in 2 3 4 5; \
		do \
			rm -f $(PREFIX)/etc/rc$${num}.d/S[0-9][0-9]firewall; \
		done; \
		for num in 0 1 6; \
		do \
			rm -f $(PREFIX)/etc/rc$${num}.d/K[0-9][0-9]firewall; \
		done; \
	fi


install_doc:
	@#
	@# copy documentation 
	@#
	if [ -d $(PREFIX)/usr/doc ]; \
	then \
		umask 077; \
		mkdir -p $(PREFIX)/usr/doc/$(PROJECT_NAME)-$(VERSION); \
		cp ./ChangeLog ./FAQ.html ./INSTALL ./LICENSE ./TODO $(PREFIX)/usr/doc/$(PROJECT_NAME)-$(VERSION); \
	fi


install_tar:

	umask 077; \
	tar --exclude CVS -cf - \
		./etc/firewall \
		./usr/man/*/firewall.conf.[0-9].gz \
		./usr/man/*/rcf.[0-9].gz \
		./usr/man/*/rcf-*[0-9].gz \
		./sbin/rcf \
			| tar -C $(PREFIX)/ -xf -

	chmod -R u+rwX,u-s,g-srwx,o-rwx \
		$(PREFIX)/etc/firewall \
		$(PREFIX)/usr/man/*/firewall.conf.[0-9].gz \
		$(PREFIX)/usr/man/*/rcf.[0-9].gz \
		$(PREFIX)/usr/man/*/rcf-*[0-9].gz \
		$(PREFIX)/sbin/rcf \
	; \

	if [ `id -u` -eq 0 ]; then \
		chown -R 0:0 \
			$(PREFIX)/etc/firewall \
			$(PREFIX)/usr/man/*/firewall.conf.[0-9].gz \
			$(PREFIX)/usr/man/*/rcf.[0-9].gz \
			$(PREFIX)/usr/man/*/rcf-*[0-9].gz \
			$(PREFIX)/sbin/rcf \
		; \
	fi

	sed -e "s!^\(PROJECT_VERSION=\).*\$$!\1$(PROJECT_VERSION)!" \
		-e "s!^\(PROJECT_MATURITY=\).*\$$!\1$(PROJECT_MATURITY)!" \
		-e "s!^\(PROJECT_RELEASE=\).*\$$!\1$(PROJECT_RELEASE)!" ./sbin/rcf > $(PREFIX)/sbin/rcf

	chmod 700 $(PREFIX)/sbin/rcf

	touch $(PREFIX)/etc/firewall.conf
	chmod 0600 $(PREFIX)/etc/firewall.conf


install_rc:
	@#
	@# install and/or link startup scripts 
	@#
	for init_dir in $(PREFIX)/etc/init.d $(PREFIX)/etc/rc.d/init.d; \
	do \
		if [ -d $${init_dir} ]; \
		then \
			install -o root -g root -m 0700 fwinit $${init_dir}/firewall; \
		fi; \
	done

	if [ -f "$(PREFIX)/etc/rc.d/init.d/firewall" -a -x /sbin/chkconfig ]; \
	then \
		/sbin/chkconfig --add firewall; \
	elif [ -d "$(PREFIX)/etc/init.d" ]; \
	then \
		for num in 2 3 4 5; \
		do \
			ln -fs ../init.d/firewall $(PREFIX)/etc/rc$${num}.d/S12firewall; \
		done; \
		for num in 0 1 6; \
		do \
			ln -fs ../init.d/firewall $(PREFIX)/etc/rc$${num}.d/K90firewall; \
		done; \
	fi


install_uc:

	@echo ""
	@echo "--------------------------------------------------------------------------------"
	@echo "updating configuration file..."
	@echo "--------------------------------------------------------------------------------"

	@$(PREFIX)/sbin/rcf --prefix $(PREFIX)/etc/firewall --config $(PREFIX)/etc/firewall.conf --update-config

	@echo ""
	@echo "--------------------------------------------------------------------------------"
	@echo "Please review the options in $(PREFIX)/etc/firewall.conf and execute"
	@echo "$(PREFIX)/sbin/rcf again to implement the firewall rules."
	@echo "--------------------------------------------------------------------------------"
	@echo ""


install_rpm_rc:

	@#
	@# create startup script directories and symbolic links
	@# THIS IS ONLY USED BY THE RED-HAT RPM
	@#
	if [ ! -d $(PREFIX)/etc/rc.d/init.d ]; \
	then \
		mkdir -p $(PREFIX)/etc/rc.d/init.d; \
	fi

	install -o root -g root -m 0700 fwinit $(PREFIX)/etc/rc.d/init.d/firewall

	for num in 0 1 2 3 4 5 6; do mkdir -p $(PREFIX)/etc/rc.d/rc$${num}.d; done
	for num in 2 3 4 5; do ln -fs ../init.d/firewall $(PREFIX)/etc/rc.d/rc$${num}.d/S12firewall; done
	for num in 0 1 6  ; do ln -fs ../init.d/firewall $(PREFIX)/etc/rc.d/rc$${num}.d/K90firewall; done


clean distclean: check_pwd clean_lrp clean_man clean_link clean_dir


clean_lrp:
	@#
	@# remove the init.d directory used to create the lrp package
	@#
	if [ -d ./etc/init.d ]; then \
		rm -f ./etc/init.d/*; \
		rmdir ./etc/init.d; \
	fi
	@#
	@# remove the lrpkg directory used to create the lrp package
	@#
	if [ -d ./var/lib/lrpkg ]; then \
		rm -f ./var/lib/lrpkg/*; \
		rmdir ./var/lib/lrpkg; \
		rmdir ./var/lib; \
		rmdir ./var; \
	fi


clean_man:

	rm -f ./usr/man/man5/* ./usr/man/man8/*
	if [ -d ./usr/man/man5  ]; then rmdir ./usr/man/man5; fi
	if [ -d ./usr/man/man8  ]; then rmdir ./usr/man/man8; fi


clean_link:
	@#
	@# remove symbolic links to modules
	@#
	find ./etc -type l -exec rm -f {} \;


clean_dir:
	@#
	@# remove empty directories
	@#
	find ./etc -type d -depth -exec rmdir {} 2>/dev/null \;


dir:
	@#
	@# create missing (empty) directories
	@#
	umask 077; \
	for dir in \
		private \
		public \
		; \
	do \
		for subdir in \
			block-local-ports \
			block-remote-ports \
			online-games \
			port-forwarding \
			services \
			; \
		do \
			mkdir -p ./etc/firewall/modules/$$dir/$$subdir; \
		done; \
	done; \
	mkdir -p ./etc/rc.d/init.d


link: dir link_private_modules link_public_modules


link_private_modules:

	@#
	@# WARNING: The more modules are linked, the slower configuration
	@# file updates will be. Please only link essential modules. Users
	@# can always link additional modules manually. These additional
	@# links will not be removed when rcf is upgraded.
	@#

	@#
	@# create symbolic links under ./etc/firewall/modules/private.
	@#
	cd ./etc/firewall/modules/private/block-local-ports && \
		for file in \
			trinityv3-root-shell \
			; \
		do \
			if [ ! -L "$$file" ]; then \
				ln -s ../../common/block-local-ports/$$file; \
			fi; \
		done

	cd ./etc/firewall/modules/private/online-games && \
		for file in \
			directx \
			msnzone \
			; \
		do \
			if [ ! -L "$$file" ]; then \
				ln -s ../../common/online-games/$$file; \
			fi; \
		done

	cd ./etc/firewall/modules/private/services && \
		for file in \
			010-dns-servers \
			020-blacklist-hosts \
			080-dhcp-clients \
			100-nntp-clients \
			100-nntp-servers \
			110-http-clients \
			110-http-servers \
			115-https-clients \
			115-https-servers \
			120-smtp-clients \
			120-smtp-servers \
			130-proxy-clients \
			180-mysql-clients \
			180-mysql-servers \
			190-dns-clients \
			210-real-servers \
			260-pop3s-clients \
			270-imap-clients \
			270-imap-servers \
			280-pop3-clients \
			280-pop3-servers \
			300-ssh-clients \
			300-ssh-servers \
			310-ftpactv-clients \
			320-nfs-clients \
			320-nfs-servers \
			330-smb-hosts \
			340-cvspserver-clients \
			340-cvspserver-servers \
			440-telnet-servers \
			450-telnet-clients \
			470-syslog-clients \
			480-syslog-servers \
			490-printer-clients \
			500-printer-servers \
			510-auth-clients \
			510-auth-servers \
			520-ftp-servers \
			560-ldap-servers \
			750-BLOCK-LOCAL-PORTS \
			755-securemote-servers \
			760-ftpactv-servers \
			780-ntp-clients \
			780-ntp-servers \
			790-time-servers \
			800-wmstream-servers \
			850-ftppasv-clients \
			910-ftppasv-servers \
			950-icmp-clients \
			950-icmp-servers \
			; \
		do \
			if [ ! -L "$$file" ]; then \
				ln -s ../../common/services/$$file; \
			fi; \
		done


link_public_modules:

	@#
	@# WARNING: The more modules are linked, the slower configuration
	@# file updates will be. Please only link essential modules. Users
	@# can always link additional modules manually. These additional
	@# links will not be removed when rcf is upgraded.
	@#

	@#
	@# create symbolic links under ./etc/firewall/modules/public.
	@#
	cd ./etc/firewall/modules/public/block-local-ports && \
		for file in \
			stacheldraht \
			trinityv3-root-shell \
			; \
		do \
			if [ ! -L "$$file" ]; then \
				ln -s ../../common/block-local-ports/$$file; \
			fi; \
		done

	cd ./etc/firewall/modules/public/block-remote-ports && \
		for file in \
			chargen \
			exec \
			imap \
			ipsec \
			login \
			netstat \
			news \
			nfs \
			open-windows \
			pptp \
			printer \
			remote-winsock \
			reserved \
			shell \
			smb \
			socket-de-troy \
			socks \
			sql \
			stacheldraht \
			sunrpc \
			systat \
			telnet \
			tftp \
			trin00 \
			trinityv3 \
			xdmcp \
			xwindows \
			; \
		do \
			if [ ! -L "$$file" ]; then \
				ln -s ../../common/block-remote-ports/$$file; \
			fi; \
		done

	cd ./etc/firewall/modules/public/online-games && \
		for file in \
			battlenet \
			directx \
			halflife \
			quake \
			unrealtournament \
			msnzone \
			; \
		do \
			if [ ! -L "$$file" ]; then \
				ln -s ../../common/online-games/$$file; \
			fi; \
		done

	cd ./etc/firewall/modules/public/port-forwarding && \
		for file in \
			battlenet \
			directx \
			quake3 \
			unrealtournament \
			; \
		do \
			if [ ! -L "$$file" ]; then \
				ln -s ../../common/port-forwarding/$$file; \
			fi; \
		done

	cd ./etc/firewall/modules/public/services && \
		for file in \
			010-dns-servers \
			020-blacklist-hosts \
			050-ipsecvpn-hosts \
			080-dhcp-servers \
			100-nntp-clients \
			100-nntp-servers \
			110-http-clients \
			110-http-servers \
			115-https-clients \
			115-https-servers \
			120-smtp-clients \
			120-smtp-servers \
			130-proxy-clients \
			190-dns-clients \
			210-real-servers \
			250-imaps-clients \
			260-pop3s-clients \
			270-imap-clients \
			270-imap-servers \
			280-pop3-clients \
			280-pop3-servers \
			300-ssh-clients \
			300-ssh-servers \
			310-ftpactv-clients \
			330-smb-hosts \
			340-cvspserver-clients \
			340-cvspserver-servers \
			380-irc-clients \
			400-icqdirect-clients \
			400-icqdirect-servers \
			460-squidicp-servers \
			470-syslog-clients \
			480-syslog-servers \
			490-printer-clients \
			500-printer-servers \
			510-auth-clients \
			510-auth-servers \
			520-ftp-servers \
			560-ldap-servers \
			700-bootp-clients \
			750-BLOCK-LOCAL-PORTS \
			755-securemote-servers \
			760-ftpactv-servers \
			770-icq-servers \
			780-ntp-servers \
			790-time-servers \
			800-wmstream-servers \
			850-ftppasv-clients \
			910-ftppasv-servers \
			920-irc-servers \
			950-icmp-clients \
			950-icmp-servers \
			; \
		do \
			if [ ! -L "$$file" ]; then \
				ln -s ../../common/services/$$file; \
			fi; \
		done


man gzip_man:
	mkdir -p ./usr/man/man5 ./usr/man/man8
	gzip -c ./usr/man/rcf-groups.5    > ./usr/man/man5/rcf-groups.5.gz
	gzip -c ./usr/man/rcf-modules.5   > ./usr/man/man5/rcf-modules.5.gz
	gzip -c ./usr/man/firewall.conf.5 > ./usr/man/man5/firewall.conf.5.gz
	gzip -c ./usr/man/rcf.8	   > ./usr/man/man8/rcf.8.gz


rpm: check_pwd tar gzip

	@if [ ! -w /usr/src/redhat/SPECS \
		-o ! -w /usr/src/redhat/SOURCES \
		-o ! -w /usr/src/redhat/RPMS/noarch ]; \
	then \
		echo ""; \
		echo "--------------------------------------------------------------------------------"; \
		echo "sorry, write access to /usr/src/redhat/[SPECS|SOURCES|RPMS/noarch] is required."; \
		echo "--------------------------------------------------------------------------------"; \
		echo ""; \
		exit 1; \
	fi

	rpm -tb --clean $(PKG_SAVEDIR)/$(PKG_FILENAME).tar.gz
	mv /usr/src/redhat/RPMS/noarch/$(PKG_FILENAME)-$(PKG_RELEASE).noarch.rpm $(PKG_SAVEDIR)


tar: check_clean

	if [ -d $(PKG_SAVEDIR)/$(PKG_FILENAME)     ]; then rm -rf $(PKG_SAVEDIR)/$(PKG_FILENAME); fi
	if [ -e $(PKG_SAVEDIR)/$(PKG_FILENAME).tar ]; then rm -f  $(PKG_SAVEDIR)/$(PKG_FILENAME).tar; fi

	@#
	@# copy all files to be included in tarball
	@#
	mkdir -p $(PKG_SAVEDIR)/$(PKG_FILENAME)
	tar --exclude CVS -cf - . | tar -C $(PKG_SAVEDIR)/$(PKG_FILENAME) -xf -
	chmod -R u+rwX,u-s,g-srwx,o-rwx $(PKG_SAVEDIR)/$(PKG_FILENAME)
	if [ `id -u` -eq 0 ]; then chown -R 0:0 $(PKG_SAVEDIR)/$(PKG_FILENAME); fi

	sed -e "s!^\(PROJECT_VERSION=\).*\$$!\1$(PROJECT_VERSION)!" \
		-e "s!^\(PROJECT_MATURITY=\).*\$$!\1$(PROJECT_MATURITY)!" \
		-e "s!^\(PROJECT_RELEASE=\).*\$$!\1$(PROJECT_RELEASE)!" ./sbin/rcf > $(PKG_SAVEDIR)/$(PKG_FILENAME)/sbin/rcf

	sed -e "s!^\(Version:\).*\$$!\1 $(PKG_VERSION)!" \
		-e "s!^\(Release:\).*\$$!\1 $(PKG_RELEASE)!" \
		-e "s!^\(Source:\).*\$$!\1 $(PKG_SOURCE)!" \
		-e "s!^\(BuildRoot:\).*\$$!\1 $(PKG_BUILDROOT)!" ./.spec > $(PKG_SAVEDIR)/$(PKG_FILENAME)/.spec

	find $(PKG_SAVEDIR)/$(PKG_FILENAME)/ -exec touch {} \;
	cd $(PKG_SAVEDIR) && tar -cf $(PKG_SAVEDIR)/$(PKG_FILENAME).tar ./$(PKG_FILENAME)
	if [ -d $(PKG_SAVEDIR)/$(PKG_FILENAME) ]; then rm -rf $(PKG_SAVEDIR)/$(PKG_FILENAME); fi


gzip: tar
	gzip -9 -c $(PKG_SAVEDIR)/$(PKG_FILENAME).tar > $(PKG_SAVEDIR)/$(PKG_FILENAME).tar.gz


bzip2:
	bzip2 -c $(PKG_SAVEDIR)/$(PKG_FILENAME).tar > $(PKG_SAVEDIR)/$(PKG_FILENAME).tar.bz2


lrp: link lrp_prep lrp_tgz


lrp_prep:

	@#
	@# prepare lrp distribution files
	@#
	if [ ! -d ./var/lib/lrpkg ]; then mkdir -p ./var/lib/lrpkg; fi
	if [ ! -d ./etc/init.d    ]; then mkdir -p ./etc/init.d; fi

	{ \
		echo "/etc/firewall.conf	rcf firewall configuration file"; \
		echo ""; \
	} > ./var/lib/lrpkg/$(LRP_FILENAME).conf

	{ \
		echo "/etc/firewall"; \
		echo "/etc/init.d/firewall"; \
		echo "/sbin/rcf"; \
		echo "/var/lib/lrpkg/$(LRP_FILENAME).*"; \
		echo ""; \
	} >./var/lib/lrpkg/$(LRP_FILENAME).list

	{ \
		echo "$(VERSION)-$(RELEASE)"; \
		echo ""; \
	} > ./var/lib/lrpkg/$(LRP_FILENAME).version

	sh ./sbin/rcf --help >./var/lib/lrpkg/$(LRP_FILENAME).help


lrp_tgz:
	if [ -d $(PKG_SAVEDIR)/$(PKG_FILENAME) ]; then rm -rf $(PKG_SAVEDIR)/$(PKG_FILENAME); fi

	mkdir -p $(PKG_SAVEDIR)/$(PKG_FILENAME)
	tar --exclude CVS -cf - ./etc ./sbin ./var | tar -C $(PKG_SAVEDIR)/$(PKG_FILENAME) -xf -
	chmod -R u+rwX,u-s,g-srwx,o-rwx $(PKG_SAVEDIR)/$(PKG_FILENAME)/
	if [ `id -u` -eq 0 ]; then chown -R 0:0 $(PKG_SAVEDIR)/$(PKG_FILENAME)/; fi

	cp ./fwinit $(PKG_SAVEDIR)/$(PKG_FILENAME)/etc/init.d/firewall

	sed -e "s!^\(PROJECT_VERSION=\).*\$$!\1$(PROJECT_VERSION)!" \
		-e "s!^\(PROJECT_MATURITY=\).*\$$!\1$(PROJECT_MATURITY)!" \
		-e "s!^\(PROJECT_RELEASE=\).*\$$!\1$(PROJECT_RELEASE)!" ./sbin/rcf > $(PKG_SAVEDIR)/$(PKG_FILENAME)/sbin/rcf

	chmod 700 $(PKG_SAVEDIR)/$(PKG_FILENAME)/etc/init.d/firewall
	chmod 700 $(PKG_SAVEDIR)/$(PKG_FILENAME)/sbin/rcf

	find $(PKG_SAVEDIR)/$(PKG_FILENAME)/ -exec touch {} \;

	cd $(PKG_SAVEDIR)/$(PKG_FILENAME)/ && tar -cf - . | gzip -9 -c - > $(PKG_SAVEDIR)/$(LRP_FILENAME).lrp
	if [ -d $(PKG_SAVEDIR)/$(PKG_FILENAME) ]; then rm -rf $(PKG_SAVEDIR)/$(PKG_FILENAME); fi


distros: rpm bzip2 lrp clean

	@echo ""
	@echo "--------------------------------------------------------------------------------"
	@echo "tar, gzip, rpm, bzip2, and lrp distributions are located in $(PKG_SAVEDIR)..."
	@echo "--------------------------------------------------------------------------------"
	@echo ""


deb: deb_clean

	@echo "Building debian package of RCF $(PKG_VERSION) from the current CVS version..."
	@echo ""

	cp debian/changelog.base debian/changelog
	chmod +rw debian/changelog
	EMAIL="jhiggs@iprsystems.com"; export EMAIL; dch -p -v $(PKG_VERSION)-0-$(DATE) "Current version at $(DATE)"; unset EMAIL
	fakeroot debian/rules binary

	@echo ""
	@echo "--------------------------------------------------------------------------------"
	@echo "Debian binary package is located in previous directory (../) ..."
	@echo "To install, type (as root) 'dpkg --install <package>'."
	@echo "--------------------------------------------------------------------------------"
	@echo ""

	fakeroot debian/rules clean


deb_clean: 

	@echo "Removing working files from previous builds (if neccessary)..."
	@echo ""

	fakeroot debian/rules clean


