# $OpenIMAPD$
#
# Targets OpenBSD's make(1) + the base system's bsd.prog.mk. This will not
# build on a non-OpenBSD host: it depends on <imsg.h>, pledge(2), unveil(2),
# and libutil's imsgbuf_* API, none of which exist outside OpenBSD.

PROG=		imapd

SRCS=		main.c parent.c log.c imsgev.c parse.y utf8.c mboxname.c \
		listener.c auth_cmd.c mailbox_cmd.c append_cmd.c fetch_cmd.c \
		search_cmd.c store_cmd.c store_ipc.c \
		auth.c \
		keymgr.c \
		parser.c \
		store.c index.c mime.c envelope.c mbox_fetch.c mbox_search.c \
		mbox_store.c mbox_manage.c mbox_copy.c search_match.c \
		store_cache.c

BINDIR=		/usr/local/sbin
MANDIR=		/usr/local/man/man

RELINK=		./${PROG} -V > /dev/null

# bsd.prog.mk's built-in .y suffix rule runs yacc(1) on parse.y and
# compiles the result.

# imsg_init(3): imsgbuf_init/imsgbuf_read/imsgbuf_write/imsg_get/
# imsg_compose live in libutil on OpenBSD.
LDADD=		-lutil
DPADD=		${LIBUTIL}

# event_init/event_set/event_add/event_del/event_dispatch.
LDADD+=		-levent
DPADD+=		${LIBEVENT}

# TLS (STARTTLS on 143, implicit TLS on 993 per RFC 8314).
LDADD+=		-ltls -lssl -lcrypto
DPADD+=		${LIBTLS} ${LIBSSL} ${LIBCRYPTO}

MAN=		imapd.8 imapd.conf.5

CFLAGS+=	-Wall -Wstrict-prototypes -Wmissing-prototypes
CFLAGS+=	-Wmissing-declarations -Wshadow -Wpointer-arith
CFLAGS+=	-Wsign-compare -Wcast-align

# Explicit -g: bsd.prog.mk's DEBUG?=-g default apparently isn't reaching
# the actual compile line in this tree (the crash-diagnosis gdb session
# on the test machine showed "no debugging symbols found" against a plain `make`
# build), so force it directly rather than relying on that default.
DEBUG=		-g

# Sample imapd.conf, installed read-only at /usr/local/share/examples/
# imapd/imapd.conf.
#
# afterinstall: is bsd.prog.mk's own documented extension point for
# exactly this (".if !target(afterinstall)" guards its default no-op,
# so defining it here before the .include below takes over instead).
EXAMPLEDIR=	/usr/local/share/examples/imapd

afterinstall:
	install -d -o root -g wheel -m 755 ${DESTDIR}${EXAMPLEDIR}
	install -c -o root -g bin -m 444 ${.CURDIR}/imapd.conf.example \
	    ${DESTDIR}${EXAMPLEDIR}/imapd.conf
	install -c -o root -g bin -m 555 ${.CURDIR}/../contrib/imapduser \
	    ${DESTDIR}${BINDIR}/imapduser
	install -c -o root -g bin -m 444 ${.CURDIR}/../contrib/imapduser.8 \
	    ${DESTDIR}${MANDIR}8/imapduser.8

# imapduser: the account-provisioning tool for imapd's own bespoke
# credentials store (see contrib/imapduser's own header comment and
# imapduser.8).

.include <bsd.prog.mk>
