# Copyright 2009, Martin Gregorie.
# 
# This file is part of the Spamkiller package.
#
# Spamkiller is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# Spamkiller 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
#              

BIN     = spamkiller
CONF1   = spamkdiscards.conf
CONF2   = spamkerrors.conf
CRON    = /etc/cron.daily
DIR     = spamkiller
EXE	= /usr/local/bin
INC     = -I/usr/local/include
LIB     = -L/usr/local/lib
LWSCR	= /etc/logwatch/scripts/services
LWCONF	= /etc/logwatch/conf/services
MAN     = /usr/local/man/man1
MANP	= spamkiller.1
RPT1    = spamkdiscards
RPT2    = spamkerrors
SCRIPT  = spamclean
TARBALL = spamkiller.tgz
PHPHOME = public_html
QISUSER = /home/getmail
QISDIR  = $(QISUSER)/quarantined
QISHTML = $(QISUSER)/$(PHPHOME)
QISPHP  = qis.php

CFLAGS  = $(INC) -c
LDFLAGS = $(LIB) -lenviron

all: $(BIN)

install:
	cp $(BIN)    $(EXE)
	chmod uga+rx $(EXE)/$(BIN) 
	cp $(MANP)   $(MAN)
	chmod a-wx   $(MAN)/$(MANP)
	chmod uga+r  $(MAN)/$(MANP)
	cp $(RPT1)   $(RPT2) $(LWSCR)
	chmod uga-w  $(LWSCR)/$(RPT1) $(LWSCR)/$(RPT2)
	chmod uga+rx $(LWSCR)/$(RPT1) $(LWSCR)/$(RPT2)
	cp $(CONF1)  $(CONF2) $(LWCONF)
	chmod uga-wx $(LWCONF)/$(CONF1) $(LWCONF)/$(CONF2)
	chmod uga+r  $(LWCONF)/$(CONF1) $(LWCONF)/$(CONF2)
	cp $(SCRIPT) $(CRON)
	chmod uga-w  $(CRON)/$(SCRIPT)
	chmod uga+rx $(CRON)/$(SCRIPT)
	mkdir -p     $(QISHTML) $(QISDIR)
	cp           $(PHPHOME)/$(QISPHP) $(QISHTML)
	chmod uga-w  $(QISHTML)/$(QISPHP)
	chmod uga+rx $(QISHTML)/$(QISPHP)

clean:
	rm -f *.o $(BIN)

tarball:
	rm -f $(TARBALL) *.o $(BIN)
	cd ..; tar czvf $(DIR)/$(TARBALL) $(DIR)/* \
               --exclude results --exclude test_data \
               --exclude versions --exclude CVS 

spamkiller: spamkiller.o
	cc spamkiller.o $(LDFLAGS) -o spamkiller

spamkiller.o: spamkiller.c spamkiller.h
	cc spamkiller.c $(CFLAGS) 

