1BINFILES = bin/insomnia
2DATFILES = data/inputrc
3LIBFILES = lib/insomnia-color lib/insomnia-input lib/insomnia-monitor \
4 lib/insomnia-monitor-bell lib/insomnia-output lib/insomnia-sort \
5 lib/insomnia-strftime lib/insomnia-strip-bell lib/insomnia-tail \
6 lib/insomnia-topic lib/insomnia-track-topic lib/insomnia-unix
7
8PREFIX ?= /usr/local
9LIBDIR ?= $(PREFIX)/libexec/insomnia
10BINDIR ?= $(PREFIX)/bin
11DOCDIR ?= $(PREFIX)/share/doc/insomnia
12DATADIR ?= $(PREFIX)/share/insomnia
13
14CFLAGS ?= -Werror -Os
15CFLAGS += -std=c99 -D_POSIX_C_SOURCE=200809L
16CFLAGS += -Wpedantic -Wall -Wextra
17
18ifeq ($(shell uname -s), OpenBSD)
19 # Needed for pledge(2) prototype in unistd.h.
20 CFLAGS += -D_BSD_SOURCE
21endif
22
23all: $(BINFILES) $(DATFILES) $(LIBFILES)
24bin/%: bin/%.in
25 sed -e 's|@LIBDIR@|$(LIBDIR)|' \
26 -e 's|@DATADIR@|$(DATADIR)|' < $< > $@
27 chmod +x $@
28
29lib/insomnia-tail: LDFLAGS += -pthread
30lib/insomnia-%: lib/insomnia-%.c
31 $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS)
32
33install: all
34 install -dm755 "$(DESTDIR)$(BINDIR)" "$(DESTDIR)$(LIBDIR)" "$(DESTDIR)$(DATADIR)"
35 install -Dm755 $(BINFILES) "$(DESTDIR)$(BINDIR)"
36 install -Dm755 $(LIBFILES) "$(DESTDIR)$(LIBDIR)"
37 install -Dm644 $(DATFILES) "$(DESTDIR)$(DATADIR)"
38 install -Dm644 README.md "$(DESTDIR)$(DOCDIR)/README.md"
39
40clean:
41 @git clean -fdX
42
43.PHONY: all install clean