aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 2d21588f15ff409556c2c4489c71f13e1996bbd2 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
COV_FILE=coverage.info

.PHONY: all clean test \
	unit-test-with-cov \
	litmus \
	static \
	$(COV_FILE) \
	lcov.info \
	unit-test-deps

GUILE := guile
export GUILE

GUILD := guild

GUILE_VERSION=$(shell $(GUILE) -c '(display (version))')

GUILE_SITE_DIR=$(shell $(GUILE) -c "(display (%site-dir))")
GUILE_CCACHE_DIR=$(shell $(GUILE) -c "(display (%site-ccache-dir))")

SCM_FILES = $(shell find module/ -type f -name \*.scm)
GO_FILES = $(SCM_FILES:%.scm=obj-$(GUILE_VERSION)/%.go)
SCM_UNIT_TESTS = $(shell find tests/unit/ -type f -name \*.scm)
GO_UNIT_TESTS = $(SCM_UNIT_TESTS:%.scm=obj-$(GUILE_VERSION)/%.go)

TEST_FILES = $(shell find tests/unit/util/ -type f -name \*.scm)

GUILE_ENV = GUILE_LOAD_PATH=$(PWD)/module:$(PWD)/tests/unit \
	GUILE_LOAD_COMPILED_PATH=$(PWD)/obj-$(GUILE_VERSION)/module:$(PWD)/obj-$(GUILE_VERSION)/obj-3.0.9/tests/util \
	GUILE_AUTO_COMPILE=0

GUILE_C_FLAGS = -Lmodule -Ltests/util \
				-Wshadowed-toplevel -Wunbound-variable \
				-Wmacro-use-before-definition -Warity-mismatch \
				-Wduplicate-case-datum -Wbad-case-datum

CLIBS = guile-3.0
CFLAGS = -Wall -pedantic -std=c11 $(shell pkg-config --cflags $(CLIBS))
LDLIBS = $(shell pkg-config --libs $(CLIBS))
LDFLAGS = -lrt

# All po-files inside po/, except new.po, and hidden files
PO_FILES = $(shell find po -type f -name \*.po -and -not -name new.po -and -not -name .\*)
LOCALIZATIONS = $(PO_FILES:po/%.po=localization/%/LC_MESSAGES/calp.mo)

# Limit test to these files
LIMIT_FILES=$(LIMIT:%=--only %)
# Skip these files when testing
SKIP=--skip $(PWD)/tests/test/web-server.scm

all: calp $(GO_FILES) static $(LOCALIZATIONS)
	$(MAKE) -C doc/ref

calp: calp.c
	$(CC) -ggdb $(CFLAGS) -DBUILD_ENV $(LDFLAGS) -o $@ $< $(LDLIBS)

calp-release: calp.c
	$(CC) -O2 $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)

cpucount: cpucount.c
	$(CC) -o $@ $<

XGETTEXT_FLAGS = --from-code=UTF-8 --add-comments --indent -kG_

static:
	$(MAKE) -C static

obj-$(GUILE_VERSION)/%.go: %.scm
	@echo $(GUILD) $(GUILE_VERSION) compile $<
	@env $(GUILE_ENV) $(GUILD) compile $(GUILE_C_FLAGS) -o $@ $< >/dev/null

po/%.po: $(SCM_FILES)
	xgettext $(XGETTEXT_FLAGS) --output $@ -L scheme $^ --join-existing --omit-header --no-location

po/new.po: $(SCM_FILES)
	xgettext $(XGETTEXT_FLAGS) --output $@ -L scheme $^

localization/%/LC_MESSAGES/calp.mo: po/%.po
	-@mkdir -p $(shell dirname $@)
	msgfmt --check -o $@ $<

clean:
	-$(MAKE) -C static clean
	-rm -r obj-*
	-rm calp
	-rm calp-release

install: all calp-release
	install -d $(DESTDIR)$(GUILE_SITE_DIR)  $(DESTDIR)$(GUILE_CCACHE_DIR)
	rsync -a module/ $(DESTDIR)$(GUILE_SITE_DIR)
	rsync -a obj-$(GUILE_VERSION)/module $(DESTDIR)$(GUILE_CCACHE_DIR)
	$(MAKE) -C static install
	$(MAKE) -C system install
	$(MAKE) -C doc/ref install
	install -m 644 -D -t $(DESTDIR)/usr/share/doc/calp README.md
	install -m 755 -D -t $(DESTDIR)/usr/lib/calp/ scripts/tzget
	install -m755 -D calp-release $(DESTDIR)/usr/bin/calp

# TODO a test completed with no errors should emit a .test-accepted
# file, which make can then use as a target.

unit-test-deps: calp $(GO_UNIT_TESTS) $(GO_FILES) $(TEST_FILES)

$(COV_FILE): cpucount unit-test-deps
	./testrunner.scm --threads $(shell ./cpucount) --coverage $@ --coverage-supplement tests/unit/coverage-supplement.scm

unit-test-with-cov: $(COV_FILE)

GENHTML_FLAGS=--show-details \
			  --hierarchical \
			  --prefix $(shell pwd) \
			  --no-function-coverage \
			  --quiet

coverage: $(COV_FILE)
	genhtml $(GENHTML_FLAGS) --output-directory $@ $<


CHECK_FLAGS = \
	$(if $(CATCH),--catch) \
	$(if $(VERBOSE),--verbose) \
	$(SKIP) $(LIMIT_FILES)

litmus:
	tests/litmus.scm $(path)