PREFIX  ?= /usr
BINDIR  ?= $(PREFIX)/bin
DOCDIR  ?= $(PREFIX)/doc/attach-filter
LIBDIR  ?= $(PREFIX)/lib/attach-filter
SYSCONFDIR ?= /etc
CONFDIR ?= $(SYSCONFDIR)/attach-filter

FILTROS = filtro_asunto filtro_adjuntos filtro_clamav
DISTFILES = attach-filter $(addprefix filtros/,$(FILTROS))

INSTFILES = $(addsuffix .inst,$(DISTFILES))

all: $(INSTFILES)
	
install: all
	install -d $(DESTDIR)/$(LIBDIR)/filtros
	install -d $(DESTDIR)/$(CONFDIR)
	install -d $(DESTDIR)/$(BINDIR)
	install -d $(DESTDIR)/$(DOCDIR)/sample-config
	install -o root -m 0644 -t $(DESTDIR)/$(DOCDIR)/sample-config sample-config/*
	install -p -o root -m 0755 attach-filter.inst $(DESTDIR)/$(BINDIR)/attach-filter
	install -p -o root -m 0644 aflib $(DESTDIR)/$(LIBDIR)
	$(foreach filtro,$(FILTROS),install -o root -m 0644 filtros/$(filtro).inst $(DESTDIR)/$(LIBDIR)/filtros/$(filtro); ) 
	
%.inst: $*
	sed 's%MAKEFILE_PREFIX%$(PREFIX)%g; s%MAKEFILE_LIBDIR%$(LIBDIR)%g;s%MAKEFILE_BINDIR%$(BINDIR)%g; s%MAKEFILE_CONFDIR%$(CONFDIR)%g'  $* > $@
	
clean:
	rm -f $(addsuffix .inst,$(DISTFILES))
