-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
85 lines (64 loc) · 1.87 KB
/
Makefile
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
OS := $(shell uname -s | tr A-Z a-z)
CFLAGS := -DNDEBUG -O2 -std=c11
CXXFLAGS := -DNDEBUG -O2 -std=c++17
ARFLAGS := -rcs
LDFLAGS := -fPIC
# lib/libxchg.so & lib/libxchg_static.a
SRC := $(wildcard src/*.c)
OBJ := $(SRC:.c=.o)
%.o: %.c
$(CC) $(CFLAGS) -Iinclude -o $@ -c $<
%.o: %.cpp
$(CXX) $(CXXFLAGS) -Iinclude -o $@ -c $<
.PHONY: all shared static test fuzz examples docs clean
all: shared static
shared: $(OBJ)
ifeq ($(OS),darwin)
$(CC) $(LDFLAGS) -dynamiclib -o lib/libxchg.dylib $^
else
$(CC) $(LDFLAGS) -shared -o lib/libxchg.so $^
endif
static: $(OBJ)
$(AR) $(ARFLAGS) lib/libxchg_static.a $^
# bin/xchg_tests
TEST_SRC := $(wildcard tests/*.cpp)
TEST_OBJ := $(TEST_SRC:.cpp=.o)
TEST_CFLAGS ?= $(CFLAGS)
TEST_CXXFLAGS ?= $(CXXFLAGS)
TEST_LDFLAGS ?= $(LDFLAGS)
test: CFLAGS := $(TEST_CFLAGS)
test: CXXFLAGS := $(TEST_CXXFLAGS)
test: LDFLAGS := $(TEST_LDFLAGS)
test: $(TEST_OBJ) | all
$(CXX) $(CXXFLAGS) -Iinclude $(LDFLAGS) -Llib -lxchg_static -o bin/xchg_tests $^
@bin/xchg_tests -s -r compact
# bin/xchg_fuzz
FUZZ_SRC := $(wildcard tests/fuzz/*.cpp)
FUZZ_OBJ := $(FUZZ_SRC:.cpp=.o)
AFL_CC := afl-clang
AFL_CXX := afl-clang++
AFL_CFLAGS := -DDEBUG -O0 -std=c11
AFL_CXXFLAGS := -DDEBUG -O0 -std=c++17
AFL_LDFLAGS ?= $(LDFLAGS)
fuzz: CC := $(AFL_CC)
fuzz: CXX := $(AFL_CXX)
fuzz: CFLAGS := $(AFL_CFLAGS)
fuzz: CXXFLAGS := $(AFL_CXXFLAGS)
fuzz: LDFLAGS := $(AFL_LDFLAGS)
fuzz: export AFL_HARDEN=1
fuzz: $(FUZZ_OBJ) | all
$(CXX) $(CXXFLAGS) -Iinclude $(LDFLAGS) -Llib -lxchg_static -o bin/xchg_fuzz $^
@afl-fuzz -i tests/fuzz/testcases -o tests/fuzz/findings -- bin/xchg_fuzz
# bin/examples_serialization
examples:
$(CC) $(CFLAGS) -Iinclude $(LDFLAGS) -Llib -lxchg_static -o bin/xchg_examples_serialization examples/serialization.c
# misc
docs:
doxygen
clean:
@rm -rf bin/*
@rm -rf lib/*
@rm -f src/*.o
@rm -f tests/*.o
@rm -f tests/fuzz/*.o
@rm -rf tests/fuzz/findings/*