aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 72dff20d16e2517c577617d2f69c0af16b8571c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
CC      ?= cc
CFLAGS  ?= -O2 -g
VERSION  = 0.1.0-dev

WARN     = -Wall -Wextra -Wshadow -Wstrict-prototypes -Wmissing-prototypes \
           -Wpointer-arith -Wvla -Wformat=2
CPPFLAGS = -Isrc -Ivendor -Ivendor/argon2
DEFS     = -D_GNU_SOURCE -DARGON2_NO_THREADS -DBOKF_VERSION=\"$(VERSION)\"

BUILD = build

VENDOR_SRC = vendor/sqlite3.c vendor/yyjson.c vendor/sha256.c \
             vendor/argon2/argon2.c vendor/argon2/core.c \
             vendor/argon2/encoding.c vendor/argon2/ref.c \
             vendor/argon2/thread.c vendor/argon2/blake2/blake2b.c

CORE_SRC = src/util.c src/log.c src/config.c src/db.c src/auth.c \
           src/sessions.c src/audit.c src/protocol.c src/commands.c \
           src/seed.c src/ledger.c src/reports.c src/sie.c src/formula.c

VENDOR_OBJ = $(patsubst %.c,$(BUILD)/%.o,$(VENDOR_SRC))
CORE_OBJ   = $(patsubst %.c,$(BUILD)/%.o,$(CORE_SRC))

all: $(BUILD)/bokfd $(BUILD)/bokfctl $(BUILD)/bokftui

$(BUILD)/bokfd: $(BUILD)/src/bokfd.o $(CORE_OBJ) $(VENDOR_OBJ)
	$(CC) $(CFLAGS) -o $@ $^ -lm

$(BUILD)/bokfctl: $(BUILD)/clients/bokfctl.o $(BUILD)/src/util.o \
                  $(BUILD)/src/log.o $(BUILD)/vendor/yyjson.o \
                  $(BUILD)/vendor/sha256.o
	$(CC) $(CFLAGS) -o $@ $^ -lm

$(BUILD)/bokftui: $(BUILD)/clients/bokftui.o $(BUILD)/clients/client.o \
                  $(BUILD)/src/util.o $(BUILD)/src/log.o $(BUILD)/src/formula.o \
                  $(BUILD)/vendor/yyjson.o $(BUILD)/vendor/sha256.o
	$(CC) $(CFLAGS) -o $@ $^ -lm -lncursesw

$(BUILD)/test_core: $(BUILD)/tests/test_core.o $(CORE_OBJ) $(VENDOR_OBJ)
	$(CC) $(CFLAGS) -o $@ $^ -lm

test: $(BUILD)/test_core
	$(BUILD)/test_core

$(BUILD)/vendor/%.o: vendor/%.c
	@mkdir -p $(dir $@)
	$(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) -w -c $< -o $@

$(BUILD)/src/%.o: src/%.c
	@mkdir -p $(dir $@)
	$(CC) $(CFLAGS) $(WARN) $(CPPFLAGS) $(DEFS) -c $< -o $@

$(BUILD)/clients/%.o: clients/%.c
	@mkdir -p $(dir $@)
	$(CC) $(CFLAGS) $(WARN) $(CPPFLAGS) $(DEFS) -c $< -o $@

$(BUILD)/tests/%.o: tests/%.c
	@mkdir -p $(dir $@)
	$(CC) $(CFLAGS) $(WARN) $(CPPFLAGS) $(DEFS) -c $< -o $@

install: all
	install -d $(DESTDIR)/usr/local/bin $(DESTDIR)/usr/local/share/bokf
	install -m 0755 $(BUILD)/bokfd $(BUILD)/bokfctl $(BUILD)/bokftui \
	    $(DESTDIR)/usr/local/bin/
	install -m 0644 data/bas_k2.csv data/bas_k3.csv $(DESTDIR)/usr/local/share/bokf/

clean:
	rm -rf $(BUILD)

.PHONY: all test install clean