# Autoconf Variables
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = ..
prefix = @prefix@
exec_prefix = @exec_prefix@
subdir = contrib

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
install_sh = @install_sh@
install_sh_PROGRAM = $(install_sh) -c
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs

CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
DEFS = @DEFS@
LDFLAGS = @LDFLAGS@
#LIBS = @LIBS@
PACKAGE = @PACKAGE@
SHELL = @SHELL@
VERSION = @VERSION@

SPASM_USER = @SPASM_USER
APACHE_GROUP = @APACHE_GROUP@
CGIDIR = @CGIDIR@
CONTRIBDIR = @CONTRIBDIR@

# Programs
bin_PROGRAMS = lookup_filter lookup_filter get_blacklist get_whitelist set_filter set_blacklist add_blacklist add_whitelist set_whitelist archivelog authuser delete_qfile upgrade_filters
PROGRAMS = $(bin_PROGRAMS)

# Program Variables
lookup_filter_SOURCES = lookup_filter.c $(top_srcdir)/src/dbfunc.c
lookup_filter_OBJECTS = lookup_filter.o $(top_srcdir)/src/dbfunc.o
lookup_filter_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h
lookup_filter_LIBS = -ldb

set_filter_SOURCES = set_filter.c $(top_srcdir)/src/dbfunc.c
set_filter_OBJECTS = set_filter.o $(top_srcdir)/src/dbfunc.o
set_filter_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h
set_filter_LIBS = -ldb

get_blacklist_SOURCES = get_blacklist.c $(top_srcdir)/src/dbfunc.c
get_blacklist_OBJECTS = get_blacklist.o $(top_srcdir)/src/dbfunc.o
get_blacklist_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h
get_blacklist_LIBS = -ldb

set_blacklist_SOURCES = set_blacklist.c $(top_srcdir)/src/dbfunc.c
set_blacklist_OBJECTS = set_blacklist.o $(top_srcdir)/src/dbfunc.o
set_blacklist_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h
set_blacklist_LIBS = -ldb

add_blacklist_SOURCES = add_blacklist.c $(top_srcdir)/src/dbfunc.c
add_blacklist_OBJECTS = add_blacklist.o $(top_srcdir)/src/dbfunc.o
add_blacklist_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h
add_blacklist_LIBS = -ldb

get_whitelist_SOURCES = get_whitelist.c $(top_srcdir)/src/dbfunc.c
get_whitelist_OBJECTS = get_whitelist.o $(top_srcdir)/src/dbfunc.o
get_whitelist_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h
get_whitelist_LIBS = -ldb

add_whitelist_SOURCES = add_whitelist.c $(top_srcdir)/src/dbfunc.c
add_whitelist_OBJECTS = add_whitelist.o $(top_srcdir)/src/dbfunc.o
add_whitelist_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h
add_whitelist_LIBS = -ldb

set_whitelist_SOURCES = set_whitelist.c $(top_srcdir)/src/dbfunc.c
set_whitelist_OBJECTS = set_whitelist.o $(top_srcdir)/src/dbfunc.o
set_whitelist_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h
set_whitelist_LIBS = -ldb

archivelog_SOURCES = archivelog.c $(top_srcdir)/src/dbfunc.c
archivelog_OBJECTS = archivelog.o $(top_srcdir)/src/dbfunc.o
archivelog_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h
archivelog_LIBS = -ldb

delete_qfile_SOURCES = delete_qfile.c
delete_qfile_OBJECTS = delete_qfile.o
delete_qfile_DEPENDENCIES = $(top_srcdir)/include/spasm.h
delete_qfile_LIBS = -ldb

authuser_SOURCES = authuser.c
authuser_OBJECTS = authuser.o
authuser_LIBS = -lpam

upgrade_filters_SOURCES = upgrade_filters.c $(top_srcdir)/src/dbfunc.c
upgrade_filters_OBJECTS = upgrade_filters.o $(top_srcdir)/src/dbfunc.o
upgrade_filters_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h oldvars.h
upgrade_filters_LIBS = -ldb

# Compiler Variables
INCLUDES = -I$(top_srcdir)/include
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c -o $@
CCLD = $(CC)
LINK = $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@

# Compilation Targets
all: Makefile $(PROGRAMS)

Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@

add_blacklist: $(add_blacklist_OBJECTS) $(add_blacklist_DEPENDENCIES) 
	@rm -f add_blacklist
	$(LINK) $(add_blacklist_OBJECTS) $(add_blacklist_LIBS) $(LIBS)

add_whitelist: $(add_whitelist_OBJECTS) $(add_whitelist_DEPENDENCIES) 
	@rm -f add_whitelist
	$(LINK) $(add_whitelist_OBJECTS) $(add_whitelist_LIBS) $(LIBS)

archivelog: $(archivelog_OBJECTS) $(archivelog_DEPENDENCIES) 
	@rm -f archivelog
	$(LINK) $(archivelog_OBJECTS) $(archivelog_LIBS) $(LIBS)

authuser: $(authuser_OBJECTS) $(authuser_DEPENDENCIES) 
	@rm -f authuser
	$(LINK) $(authuser_OBJECTS) $(authuser_LIBS) $(LIBS)

delete_qfile: $(delete_qfile_OBJECTS) $(delete_qfile_DEPENDENCIES) 
	@rm -f delete_qfile
	$(LINK) $(delete_qfile_OBJECTS) $(delete_qfile_LIBS) $(LIBS)

get_blacklist: $(get_blacklist_OBJECTS) $(get_blacklist_DEPENDENCIES) 
	@rm -f get_blacklist
	$(LINK) $(get_blacklist_OBJECTS) $(get_blacklist_LIBS) $(LIBS)

get_whitelist: $(get_whitelist_OBJECTS) $(get_whitelist_DEPENDENCIES) 
	@rm -f get_whitelist
	$(LINK) $(get_whitelist_OBJECTS) $(get_whitelist_LIBS) $(LIBS)

lookup_filter: $(lookup_filter_OBJECTS) $(lookup_filter_DEPENDENCIES) 
	@rm -f lookup_filter
	$(LINK) $(lookup_filter_OBJECTS) $(lookup_filter_LIBS) $(LIBS)

set_blacklist: $(set_blacklist_OBJECTS) $(set_blacklist_DEPENDENCIES) 
	@rm -f set_blacklist
	$(LINK) $(set_blacklist_OBJECTS) $(set_blacklist_LIBS) $(LIBS)

set_filter: $(set_filter_OBJECTS) $(set_filter_DEPENDENCIES) 
	@rm -f set_filter
	$(LINK) $(set_filter_OBJECTS) $(set_filter_LIBS) $(LIBS)

set_whitelist: $(set_whitelist_OBJECTS) $(set_whitelist_DEPENDENCIES) 
	@rm -f set_whitelist
	$(LINK) $(set_whitelist_OBJECTS) $(set_whitelist_LIBS) $(LIBS)

upgrade_filters: $(upgrade_filters_OBJECTS) $(upgrade_filters_DEPENDENCIES) 
	@rm -f upgrade_filters
	$(LINK) $(upgrade_filters_OBJECTS) $(upgrade_filters_LIBS) $(LIBS)

.c.o:
	@rm -f $@
	$(COMPILE) $<

# Installation Targets
install: all
	@$(MAKE) install-binPROGRAMS

install-binPROGRAMS: $(bin_PROGRAMS)
	$(mkinstalldirs) $(CONTRIBDIR)
	$(INSTALL_PROGRAM) -m 4555 -o $(SPASM_USER) -g $(APACHE_GROUP) lookup_filter $(CONTRIBDIR)
	$(INSTALL_PROGRAM) -m 4555 -o $(SPASM_USER) -g $(APACHE_GROUP) set_filter $(CONTRIBDIR)
	$(INSTALL_PROGRAM) -m 4555 -o $(SPASM_USER) -g $(APACHE_GROUP) get_blacklist $(CONTRIBDIR)
	$(INSTALL_PROGRAM) -m 4555 -o $(SPASM_USER) -g $(APACHE_GROUP) set_blacklist $(CONTRIBDIR)
	$(INSTALL_PROGRAM) -m 4555 -o $(SPASM_USER) -g $(APACHE_GROUP) add_blacklist $(CONTRIBDIR)
	$(INSTALL_PROGRAM) -m 4555 -o $(SPASM_USER) -g $(APACHE_GROUP) get_whitelist $(CONTRIBDIR)
	$(INSTALL_PROGRAM) -m 4555 -o $(SPASM_USER) -g $(APACHE_GROUP) add_whitelist $(CONTRIBDIR)
	$(INSTALL_PROGRAM) -m 4555 -o $(SPASM_USER) -g $(APACHE_GROUP) set_whitelist $(CONTRIBDIR)
	$(INSTALL_PROGRAM) -m 4555 -o $(SPASM_USER) -g $(APACHE_GROUP) archivelog $(CONTRIBDIR)
	$(INSTALL_PROGRAM) -m 4555 -o $(SPASM_USER) -g $(APACHE_GROUP) delete_qfile $(CONTRIBDIR)
	$(INSTALL_PROGRAM) -m 4555 -o root -g $(APACHE_GROUP) authuser $(CONTRIBDIR)
	$(mkinstalldirs) $(CGIDIR)
	$(INSTALL_PROGRAM) -m 0555 -o $(SPASM_USER) -g $(APACHE_GROUP) spasm.cgi $(CGIDIR)

uninstall: uninstall-binPROGRAMS

uninstall-binPROGRAMS:
	rm -f $(CONTRIBDIR)/lookup_filter $(CONTRIBDIR)/set_filter $(CONTRIBDIR)/get_blacklist $(CONTRIBDIR)/set_blacklist \
		$(CONTRIBDIR)/add_blacklist $(CONTRIBDIR)/get_whitelist $(CONTRIBDIR)/add_whitelist $(CONTRIBDIR)/set_whitelist \
		$(CONTRIBDIR)/archivelog $(CONTRIBDIR)/delete_qfile $(CONTRIBDIR)/authuser $(CGIDIR)/spasm.cgi

# Cleaning Targets
clean:
	rm -f $(PROGRAMS) *.o

distclean: clean
	rm -f Makefile

# Dist Targets
DIST_COMMON = Makefile.in README
DIST_SOURCES = add_blacklist.c add_whitelist.c archivelog.c authuser.c delete_qfile.c get_blacklist.c \
	get_whitelist.c lookup_filter.c set_blacklist.c set_filter.c set_whitelist.c upgrade_filters.c oldvars.h
EXTRA_DIST = cleanQuarantine spasm.cgi spasm.init spasm.pam spasm.user_prefs
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(EXTRA_DIST)

top_distdir = ..
distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)

distdir: $(DISTFILES)
	@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
	list='$(DISTFILES)'; for file in $$list; do \
	  case $$file in \
	    $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
	    $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
	  esac; \
	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
	    dir="/$$dir"; \
	    $(mkinstalldirs) "$(distdir)$$dir"; \
	  else \
	    dir=''; \
	  fi; \
	  if test -d $$d/$$file; then \
	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
	    fi; \
	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
	  else \
	    test -f $(distdir)/$$file \
	    || cp -p $$d/$$file $(distdir)/$$file \
	    || exit 1; \
	  fi; \
	done
check: all

# Done
