Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
80 lines (63 loc) · 2.29 KB
/
Copy pathMakefile
File metadata and controls
80 lines (63 loc) · 2.29 KB
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
# libstatemachines -- library build.
#
# Targets:
# make -> build/libstate_machine.a
# make test -> build + run all smoke tests
# make clean -> wipe build/
CC ?= cc
AR ?= ar
WARN := -Wall -Wextra -Wpedantic -Werror -Wshadow -Wconversion -Wstrict-prototypes
CFLAGS ?= -std=c11 -O2 -fno-strict-aliasing -fstack-usage $(WARN)
CPPFLAGS ?= -Iinclude
LDFLAGS ?=
BUILD := build
LIB := $(BUILD)/libstate_machine.a
LIB_SRC := src/state_machine.c
LIB_OBJ := $(BUILD)/state_machine.o
SMOKE_BINS := $(BUILD)/smoke_flat $(BUILD)/smoke_hsm $(BUILD)/smoke_invalid \
$(BUILD)/smoke_action
EXAMPLE_BIN := $(BUILD)/circuit_breaker
CONFORMANCE_BIN := $(BUILD)/conformance
CONFORMANCE_SRCS := test/conformance/harness.c \
test/conformance/fixture.c \
test/conformance/guards.c \
test/conformance/jp.c
CONFORMANCE_FIXTURES := $(wildcard test/conformance/*.json)
.PHONY: all test example conformance clean
all: $(LIB)
$(BUILD):
mkdir -p $(BUILD)
$(LIB_OBJ): $(LIB_SRC) include/state_machine.h include/state_machine_schema.h | $(BUILD)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
$(LIB): $(LIB_OBJ)
$(AR) rcs $@ $^
$(BUILD)/smoke_%: test/smoke_%.c $(LIB) | $(BUILD)
$(CC) $(CFLAGS) $(CPPFLAGS) $< $(LIB) $(LDFLAGS) -o $@
test: $(SMOKE_BINS) $(CONFORMANCE_BIN) $(EXAMPLE_BIN)
@set -e; for t in $(SMOKE_BINS); do \
echo "== $$t =="; \
$$t; \
done
@echo "all smoke tests passed"
@$(CONFORMANCE_BIN) $(CONFORMANCE_FIXTURES)
@echo "== $(EXAMPLE_BIN) =="
@$(EXAMPLE_BIN)
# Reference consumer.
$(EXAMPLE_BIN): examples/circuit_breaker/main.c \
examples/circuit_breaker/circuit_breaker.c \
examples/circuit_breaker/circuit_breaker.h \
$(LIB) | $(BUILD)
$(CC) $(CFLAGS) $(CPPFLAGS) -Iexamples/circuit_breaker \
examples/circuit_breaker/main.c \
examples/circuit_breaker/circuit_breaker.c \
$(LIB) $(LDFLAGS) -o $@
example: $(EXAMPLE_BIN)
@echo "== $< =="
@$<
# Conformance harness.
$(CONFORMANCE_BIN): $(CONFORMANCE_SRCS) $(LIB) | $(BUILD)
$(CC) $(CFLAGS) $(CPPFLAGS) -Itest/conformance $(CONFORMANCE_SRCS) $(LIB) $(LDFLAGS) -o $@
conformance: $(CONFORMANCE_BIN)
@$(CONFORMANCE_BIN) $(CONFORMANCE_FIXTURES)
clean:
rm -rf $(BUILD)