CC = gcc
PREFIX = /usr/local
SBINDIR = $(PREFIX)/sbin
DATADIR = /var/run/smfs
CONFDIR = /etc/mail/smfs
USER = smfs
GROUP = smfs
CFLAGS = -g -D_REENTRANT -I/usr/local/include -O2 # -fomit-frame-pointer

# Linux
LDFLAGS = -lpq -lmilter -lpthread -L/usr/local/lib

# FreeBSD
#LDFLAGS = -lmilter -pthread -L/usr/local/lib

# Solaris
#LDFLAGS = -lmilter -lpthread -lsocket -lnsl

# Sendmail v8.11
#LDFLAGS += -lsmutil

all: smf-sql-grey

smf-sql-grey: smf-sql-grey.o
	$(CC) -o smf-sql-grey smf-sql-grey.o $(LDFLAGS)
#	strip smf-sql-grey

smf-sql-grey.o: smf-sql-grey.c
	$(CC) $(CFLAGS) -c smf-sql-grey.c

clean:
	rm -f smf-sql-grey.o smf-sql-grey

install:
	./install.sh
	cp -f -p smf-sql-grey $(SBINDIR)
	if test ! -d $(DATADIR); then \
	mkdir -m 700 $(DATADIR); \
	chown $(USER):$(GROUP) $(DATADIR); \
	fi
	if test ! -d $(CONFDIR); then \
	mkdir -m 755 $(CONFDIR); \
	fi
	if test ! -f $(CONFDIR)/smf-sql-grey.conf; then \
	cp -p smf-sql-grey.conf $(CONFDIR)/smf-sql-grey.conf; \
	else \
	cp -p smf-sql-grey.conf $(CONFDIR)/smf-sql-grey.conf.new; \
	fi
	@echo
	@echo Please, inspect and edit the $(CONFDIR)/smf-sql-grey.conf file.
	@echo You may need to run the following commands on initial installation ONLY:
	@echo --------------------------------------------
	@fgrep -- '--# ' postgres.sql | sed 's/--\# //'
