summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 1de61161d6da644e777a88b6d229952b670fe7f4 (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
# Development tasks.
#
#   make            list the targets
#   make build      compile the library into build/libcepis.a
#   make test       run the suite against the local fake API
#   make lint       compile every unit for syntax and warnings, no output
#   make check      lint, then test, then build
#
# Requires GnuCOBOL 3.x (cobc), a C compiler, libcurl with its headers and
# python3 for the test server. Nothing else.

COBC ?= cobc
CC ?= cc
PYTHON ?= python3
AR ?= ar

COPYDIR := copy
BUILDDIR := build

# Free source format, GnuCOBOL's default dialect. -fstatic-call resolves
# CALL "literal" at link time, which is what lets the archive below work
# without a runtime module search path.
COBFLAGS ?= -free -Wall -I $(COPYDIR) -fstatic-call
CFLAGS ?= -O2 -Wall -Wextra
LDLIBS ?= -lcurl

MODULES := \
	cepis-config \
	cepis-normalize-cep \
	cepis-json \
	cepis-csv \
	cepis-request \
	cepis-lookup \
	cepis-lookup-many \
	cepis-health

COBSRC := $(addprefix src/,$(addsuffix .cob,$(MODULES)))
COBOBJ := $(addprefix $(BUILDDIR)/,$(addsuffix .o,$(MODULES)))
COBJ := $(BUILDDIR)/cepis-http.o
LIB := $(BUILDDIR)/libcepis.a
TESTBIN := $(BUILDDIR)/cepis-tests
COPYBOOKS := $(wildcard $(COPYDIR)/*.cpy)

.DEFAULT_GOAL := help
.PHONY: help build test lint check clean

help:
	@echo 'Targets:'
	@echo '  build      compile the library into $(LIB)'
	@echo '  test       run the suite against the local fake API'
	@echo '  lint       syntax and warning check only, writes nothing'
	@echo '  check      lint + test + build, in that order'
	@echo '  clean      remove build artefacts'
	@echo
	@echo 'COBOL has no standard formatter, so there is no format target.'

build: $(LIB)

$(LIB): $(COBOBJ) $(COBJ)
	$(AR) rcs $@ $^

$(BUILDDIR)/%.o: src/%.cob $(COPYBOOKS)
	@mkdir -p $(BUILDDIR)
	$(COBC) -c $(COBFLAGS) -o $@ $<

$(COBJ): src/cepis-http.c
	@mkdir -p $(BUILDDIR)
	$(CC) $(CFLAGS) -c -o $@ $<

$(TESTBIN): tests/cepis-tests.cob $(LIB)
	$(COBC) -x $(COBFLAGS) -o $@ $< $(LIB) $(LDLIBS)

test: $(TESTBIN)
	$(PYTHON) tests/server.py ./$(TESTBIN)

# Read-only by design, so it is safe in CI and in a pre-commit hook.
lint:
	$(CC) $(CFLAGS) -fsyntax-only src/cepis-http.c
	$(COBC) -fsyntax-only $(COBFLAGS) $(COBSRC)
	$(COBC) -fsyntax-only $(COBFLAGS) tests/cepis-tests.cob

# The order matters: lint is the fastest to fail, so a broken run reports
# the cheapest problem first.
check: lint test build

clean:
	rm -rf $(BUILDDIR)