# Autoconf Variables
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = ..
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
subdir = src

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

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

SPASM_USER = @SPASM_USER@

# Programs
bin_PROGRAMS = spasm spasmdb
sbin_PROGRAMS = spasmd
PROGRAMS = $(bin_PROGRAMS) $(sbin_PROGRAMS)

# spasm Variables
spasm_SOURCES = spasm.c dbfunc.c
spasm_OBJECTS = spasm.o dbfunc.o
spasm_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h $(top_srcdir)/include/filters.h
spasm_LIBS = -ldb -lncurses

# spasmdb Variables
spasmdb_SOURCES = spasmdb.c dbfunc.c
spasmdb_OBJECTS = spasmdb.o dbfunc.o
spasmdb_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h
spasmdb_LIBS = -ldb

# spasmd Variables
spasmd_SOURCES = spasmd.c dbfunc.c
spasmd_OBJECTS = spasmd.o dbfunc.o
spasmd_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h $(top_srcdir)/include/filters.h
spasmd_LIBS = -ldb -lmilter -lpthread -lresolv

# dbfunc Variables
dbfunc_DEPENDENCIES = $(top_srcdir)/include/spasm.h $(top_srcdir)/include/dbfunc.h

# 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)/$@

spasm: $(spasm_OBJECTS) $(spasm_DEPENDENCIES)
	@rm -f spasm
	$(LINK) $(spasm_OBJECTS) $(spasm_LIBS) $(LIBS)

spasmdb: $(spasmdb_OBJECTS) $(spasmdb_DEPENDENCIES)
	@rm -f spasmdb
	$(LINK) $(spasmdb_OBJECTS) $(spasmdb_LIBS) $(LIBS)

spasmd: $(spasmd_OBJECTS) $(spasmd_DEPENDENCIES)
	@rm -f spasmd
	$(LINK) $(spasmd_OBJECTS) $(spasmd_LIBS) $(LIBS)

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

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

install-binPROGRAMS: $(bin_PROGRAMS)
	$(mkinstalldirs) $(bindir)
	$(INSTALL_PROGRAM) -o $(SPASM_USER) spasm $(bindir)
	$(INSTALL_PROGRAM) -o $(SPASM_USER) spasmdb $(bindir)
	chmod 4555 $(bindir)/spasm
	chmod 0555 $(bindir)/spasmdb

install-sbinPROGRAMS: $(sbin_PROGRAMS)
	$(mkinstalldirs) $(sbindir)
	$(INSTALL_PROGRAM) -o $(SPASM_USER) spasmd $(sbindir)
	chmod 0555 $(sbindir)/spasmd

uninstall: uninstall-binPROGRAMS uninstall-sbinPROGRAMS

uninstall-binPROGRAMS:
	rm -f $(bindir)/spasm
	rm -f $(bindir)/spasmdb

uninstall-sbinPROGRAMS:
	rm -f $(sbindir)/spasmd


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

distclean: clean
	rm -f Makefile

# Dist Targets
DIST_COMMON = Makefile.in
DIST_SOURCES = spasm.c spasmd.c spasmdb.c dbfunc.c
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES)

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
