summaryrefslogtreecommitdiff
path: root/Makefile
blob: ae74a05e52ff962ac370189d08d6e3b861f28dac (plain) (blame)
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
# clectio -- tiny, fast, suckless daily readings
# Configure by editing config.h (copied from config.def.h on first build).

CC     ?= cc
CFLAGS  = -std=c99 -Os -Wall -Wextra
# -no-pie: this is a local CLI reading static embedded data with no attack
# surface, so it does not need PIE/ASLR. Dropping it lets the linker bake the
# string-table pointers in at link time instead of emitting ~57 KB of runtime
# relocations -- a ~6% smaller binary for free.
LDFLAGS = -s -no-pie
PREFIX  = /usr/local

# The form to build is read from config.h so there is one source of truth.
FORM   := $(shell grep -Eq '^[[:space:]]*\#[[:space:]]*define[[:space:]]+FORM_EF' config.h 2>/dev/null && echo ef || echo of)
# Bring your own Bible: `make CORPUS=/path/to/mybible.tsv` (same 6-column TSV
# format as gen/, Vulgate-numbered). Empty = use the shipped Vulgate text.
CORPUS ?=

.PHONY: all clean size install uninstall

all: clectio

config.h:
	cp config.def.h config.h

mktext: mktext.c
	$(CC) $(CFLAGS) -o $@ mktext.c

bin2h: bin2h.c
	$(CC) $(CFLAGS) -o $@ bin2h.c

# With CORPUS set, repack the text for the chosen form from that corpus;
# otherwise the shipped text_<form>.lz (default Vulgate) is used as-is. The
# verse keys ship gzipped (they are only needed here), so unpack them first.
ifneq ($(CORPUS),)
gen/verses_$(FORM).keys: gen/verses_$(FORM).keys.gz
	gzip -dc $< > $@
text_$(FORM).lz: mktext gen/verses_$(FORM).keys $(CORPUS)
	./mktext gen/verses_$(FORM).keys $(CORPUS) $@
endif

text.lz.h: bin2h text_$(FORM).lz
	./bin2h text_$(FORM).lz > $@

clectio: clectio.c puff.c puff.h config.h text.lz.h gen/liturgy_$(FORM).h
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ clectio.c puff.c

size: clectio
	@ls -l clectio | awk '{printf "clectio (%s): %d bytes = %.0f KB\n","$(FORM)",$$5,$$5/1024}'

install: clectio
	install -Dm755 clectio $(DESTDIR)$(PREFIX)/bin/clectio

uninstall:
	rm -f $(DESTDIR)$(PREFIX)/bin/clectio

clean:
	rm -f clectio mktext bin2h text.lz.h gen/verses_of.keys gen/verses_ef.keys