program = amavis-logwatch
program_logwatch = amavis

src = $(program) $(program).conf Changes Bugs Makefile README LICENSE

prefix_logwatch = /etc/logwatch
prefix_standalone = /usr/local

scriptdir_logwatch = $(prefix_logwatch)/scripts/services
confdir_logwatch   = $(prefix_logwatch)/conf/services

scriptdir_standalone = $(prefix_standalone)/bin
confdir_standalone = $(prefix_standalone)/etc

INSTALL = /usr/bin/install -c

install:
	@echo 'Run "make install-logwatch" to install as a logwatch filter'
	@echo 'Run "make install-standalone" to install as a standalone utility'
	@echo 'Run "make install-all" to install both'

install-logwatch:
	$(INSTALL) -d -m 0755 $(DESTDIR)$(scriptdir_logwatch) $(DESTDIR)$(confdir_logwatch) || exit 1;
	$(INSTALL) -m 0644 $(program) $(DESTDIR)$(scriptdir_logwatch)/$(program_logwatch) || exit 1;
	$(INSTALL) -m 0644 $(program).conf $(DESTDIR)$(confdir_logwatch)/$(program_logwatch).conf || exit 1;

install-standalone:
	$(INSTALL) -d -m 0755 $(DESTDIR)$(scriptdir_standalone) $(DESTDIR)$(confdir_standalone) || exit 1;
	$(INSTALL) -m 0755 $(program) $(DESTDIR)$(scriptdir_standalone)/$(program) || exit 1;
	$(INSTALL) -m 0644 $(program).conf $(DESTDIR)$(confdir_standalone)/$(program).conf || exit 1;

install-all: install-logwatch install-standalone

uninstall-logwatch:
	-rm $(DESTDIR)$(scriptdir_logwatch)/$(program_logwatch) $(DESTDIR)$(confdir_logwatch)/$(program_logwatch).conf

uninstall-standalone:
	-rm $(DESTDIR)$(scriptdir_standalone)/$(program) $(DESTDIR)$(confdir_standalone)/$(program).conf

uninstall-all: uninstall-logwatch uninstall-standalone

PKGDIR = /tmp/$(program)-package

release:
	vers=`egrep 'Version[ ]*=' $(program) | sed 's/.*"\(.*\)";/\1/'` ; \
	echo Preparing version $$vers; \
	rel=$(program)-$$vers ; \
	$(INSTALL) -o 0 -g 0 -m 0755 -d $(PKGDIR)/$$rel ; \
	$(INSTALL) -o 0 -g 0 -m 0644 $(src) $(PKGDIR)/$$rel ; \
	cd $(PKGDIR) && \
	    gtar -czvf $${rel}.tgz --group=0 --owner=0 $${rel} ; \
	md5sum $${rel}.tgz  > $(PKGDIR)/$${rel}.tgz.md5 ; \
	chmod 644 $(PKGDIR)/$${rel}.tgz  $(PKGDIR)/$${rel}.tgz.md5 ; \
	cd $(PKGDIR) && rm -f $(program) $(program).tgz $(program).tgz.md5 ; \
	ln -s $${rel}     $(program) ; \
	ln -s $${rel}.tgz     $(program).tgz ; \
	ln -s $${rel}.tgz.md5 $(program).tgz.md5
