#
# Make any modifications to Makefile.in *NOT* Makefile, as it will be
# overwritten by configure.
#

SHELL = /bin/sh

srcdir = @srcdir@
top_srcdir = @top_srcdir@

perl = @PROG_PERL@
perl5 = @PROG_PERL5@

CRONTAB = @PROG_CRONTAB@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@

all:
	$(perl) -pi -e "s=^\#\!(.*)/perl(.*)=\#\!$(perl) -I/usr/local/bandmin=;" bandmin
	$(perl) -pi -e "s=^\#\!(.*)/perl(.*)=\#\!$(perl) -I/usr/local/bandmin=;" bandmin.conf
	$(perl) -pi -e "s=^\#\!(.*)/perl(.*)=\#\!$(perl) -I/usr/local/bandmin=;" bandminhtml
	$(perl) -pi -e "s=^\#\!(.*)/perl(.*)=\#\!$(perl) -I/usr/local/bandmin=;" bandminstart
	$(perl) -pi -e "s=^\#\!(.*)/perl(.*)=\#\!$(perl) -I/usr/local/bandmin=;" bandminstop
	$(perl) -pi -e "s=^\#\!(.*)/perl(.*)=\#\!$(perl) -I/usr/local/bandmin=;" ipaddrmap
	$(perl) -pi -e "s=^\#\!(.*)/perl(.*)=\#\!$(perl) -I/usr/local/bandmin=;" bmversion.pl
	$(perl) -pi -e "s=^\#\!(.*)/perl(.*)=\#\!$(perl) -I/usr/local/bandmin=;" bandminconf
	@echo perl scripts have been reconfigured
	@echo
	@echo -----
	@echo "Please read the INSTALL file do not just mindlessly"
	@echo "type make install"
	@echo -----

config:
	$(perl) bandminconf

install:
	@echo "If you are upgrading from a pre 0.80 bandmin please type make update"
	@echo "before you preceed."
	@echo "When ready type \"make install-real\""

install-real:
	$(INSTALL_PROGRAM) -m755 -c -d /usr/local/bandmin
	$(INSTALL_PROGRAM) -m755 -c -d /usr/local/bandmin/htdocs
	$(INSTALL_PROGRAM) -m755 -c -d /var/log/bandwidth
	$(INSTALL_PROGRAM) -m744 -c bandmin /usr/local/bandmin/bandmin
	$(INSTALL_PROGRAM) -m744 -c bandminconf /usr/local/bandmin/bandminconf
	$(INSTALL_PROGRAM) -m744 -c bandmin.conf /usr/local/bandmin/bandmin.conf
	$(INSTALL_PROGRAM) -m744 -c bmversion.pl /usr/local/bandmin/bmversion.pl
	$(INSTALL_PROGRAM) -m744 -c bandminstart /usr/local/bandmin/bandminstart
	$(INSTALL_PROGRAM) -m744 -c bandminstop /usr/local/bandmin/bandminstop
	$(INSTALL_PROGRAM) -m744 -c bandminhtml /usr/local/bandmin/bandminhtml
	$(INSTALL_PROGRAM) -m744 -c ipaddrmap /usr/local/bandmin/ipaddrmap

	$(INSTALL_PROGRAM) -m755 -c -d /usr/local/bandmin/IP
	$(INSTALL_PROGRAM) -m744 -c perlmod/Acct.pm /usr/local/bandmin/IP/Acct.pm
	$(INSTALL_PROGRAM) -m744 -c perlmod/UserAcct.pm /usr/local/bandmin/IP/UserAcct.pm

	$(INSTALL_PROGRAM) -m644 -c images/bandmin_Apr.gif /usr/local/bandmin/htdocs/bandmin_Apr.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_Aug.gif /usr/local/bandmin/htdocs/bandmin_Aug.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_Dec.gif /usr/local/bandmin/htdocs/bandmin_Dec.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_Feb.gif /usr/local/bandmin/htdocs/bandmin_Feb.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_Jan.gif /usr/local/bandmin/htdocs/bandmin_Jan.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_Jul.gif /usr/local/bandmin/htdocs/bandmin_Jul.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_Jun.gif /usr/local/bandmin/htdocs/bandmin_Jun.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_Mar.gif /usr/local/bandmin/htdocs/bandmin_Mar.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_May.gif /usr/local/bandmin/htdocs/bandmin_May.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_Nov.gif /usr/local/bandmin/htdocs/bandmin_Nov.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_Oct.gif /usr/local/bandmin/htdocs/bandmin_Oct.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_Sep.gif /usr/local/bandmin/htdocs/bandmin_Sep.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_bar.gif /usr/local/bandmin/htdocs/bandmin_bar.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_current.gif /usr/local/bandmin/htdocs/bandmin_current.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_daily.gif /usr/local/bandmin/htdocs/bandmin_daily.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_day.gif /usr/local/bandmin/htdocs/bandmin_day.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_domain.gif /usr/local/bandmin/htdocs/bandmin_domain.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_summary.gif /usr/local/bandmin/htdocs/bandmin_summary.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_logo.gif /usr/local/bandmin/htdocs/bandmin_logo.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_background.gif /usr/local/bandmin/htdocs/bandmin_background.gif
	$(INSTALL_PROGRAM) -m644 -c images/bandmin_madeingimp.gif /usr/local/bandmin/htdocs/bandmin_madeingimp.gif

cron:
	echo "`$(CRONTAB) -l | grep -v "^#" | \
	grep -v "bandmin" | grep -v "ipaddrmap"`" > $(top_srcdir)/.crontab
	echo "2,58 * * * * /usr/local/bandmin/bandmin" >> $(top_srcdir)/.crontab
	echo "15 * * * * /usr/local/bandmin/bandminhtml" >> $(top_srcdir)/.crontab
	echo "0 0 * * * /usr/local/bandmin/ipaddrmap" >> $(top_srcdir)/.crontab
	$(CRONTAB) $(top_srcdir)/.crontab
	rm -f $(top_srcdir)/.crontab

date:
	date > RELEASE.DATE

dist: date reconfig

reconfig:
	sh autogen.sh
	./configure
	rm -f config.log
	rm -f config.cache
	rm -f config.status

update:
	perl ./upgrade.pl

bandmin: reconfig cron all install

