PREFIX ?= /usr/local
MANDIR ?= ${PREFIX}/share/man

CFLAGS += -std=c11 -Wall -Wextra -Wpedantic
LDLIBS = -ltls

-include config.mk

BINS = notemap git-notemap

OBJS += getservinfo.o
OBJS += imap.o
OBJS += notemap.o

all: ${BINS}

notemap: ${OBJS}
	${CC} ${LDFLAGS} ${OBJS} ${LDLIBS} -o $@

${OBJS}: imap.h

clean:
	rm -f ${BINS} ${OBJS}

install: ${BINS} notemap.1
	install -d ${DESTDIR}${PREFIX}/bin ${DESTDIR}${MANDIR}/man1
	install ${BINS} ${DESTDIR}${PREFIX}/bin
	install -m 644 notemap.1 ${DESTDIR}${MANDIR}/man1
	ln -fs notemap.1 ${DESTDIR}${MANDIR}/man1/git-notemap.1

uninstall:
	rm -f ${BINS:%=${DESTDIR}${PREFIX}/bin/%}
	rm -f ${DESTDIR}${MANDIR}/man1/notemap.1
	rm -f ${DESTDIR}${MANDIR}/man1/git-notemap.1