-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
103 lines (73 loc) · 2.3 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
CC=gcc
COMMONFLAGS=-g -Wall -I./include -I./
CFLAGS=$(COMMONFLAGS) -O0 -DDEBUG
LIBDEPEND=-lpthread
PROJNAME=nanofuzz
SRC=src
SRCS=$(wildcard $(SRC)/*.c)
OBJ=obj
OBJS=$(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SRCS))
BINDIR=bin
BIN=$(BINDIR)/$(PROJNAME)
LIB=lib
SLIBOUT=$(LIB)/lib$(PROJNAME).a
DLIBOUT=$(LIB)/lib$(PROJNAME).so
TEST=tests
TESTS=$(wildcard $(TEST)/*.c)
TESTOBJ=$(TEST)/obj
TESTBIN=$(TEST)/bin
TESTOBJS=$(patsubst $(TEST)/%.c, $(TESTOBJ)/%.o, $(TESTS))
TESTBINS=$(patsubst $(TEST)/%.c, $(TESTBIN)/%, $(TESTS))
TEST_COMPLIANCE=$(TEST)/compliance.py
TEST_PROFILING=$(TEST)/profiling.py
TEST_ITERS=200
.PHONY: release all clean slib profile tests
# By default, don't run tests. Just build the application.
all: $(BIN)
# Profiling build.
profile: CFLAGS=$(COMMONFLAGS) -O3 -DDEBUG -DFUNCTION_PROFILING -finstrument-functions
profile: NO_PIE=-no-pie
profile: $(BIN)
if [ ! -f $(TEST_PROFILING) ]; then exit 1; fi
if [ ! -x $(TEST_PROFILING) ]; then chmod +x $(TEST_PROFILING); fi
$(TEST_PROFILING) $(TEST_ITERS)0
# Static library file for testing. Excludes the main.o object.
slib: $(SLIBOUT)
$(LIB):
-mkdir $(LIB)
$(SLIBOUT): $(LIB) $(OBJ) $(OBJS)
ar rcs $(SLIBOUT) $$(echo -n "$(OBJS)" | sed 's/$(OBJ)\/main.o//')
# Release build is intended the be 'optimized' and tested thoroughly.
release: clean
release: EXTFLAGS=-O3 -DNDEBUG
release: TEST_ITERS=5000
release: tests
# Clean structures.
clean:
-rm -r $(BINDIR) $(OBJ)
-rm -r $(TESTBIN) $(TESTOBJ)
-rm -r $(LIB)
# Create the actual CLI executable.
$(OBJ):
-mkdir $(OBJ)
$(BINDIR):
-mkdir $(BINDIR)
$(OBJ)/%.o: $(SRC)/%.c
$(CC) $(CFLAGS) -c $< -o $@ $(LIBDEPEND)
$(BIN): $(OBJ) $(BINDIR) $(OBJS)
-rm $(BIN)
$(CC) $(CFLAGS) $(OBJS) -o $@ $(LIBDEPEND) $(NO_PIE)
# TEST CASES. Creates the necessary folder structure for Criterion tests, and run them.
tests: CFLAGS=-L./lib/ -L/usr/local/lib64 -Wl,-rpath,/usr/local/lib64 $(COMMONFLAGS) $(EXTFLAGS)
tests: all slib $(TESTOBJ) $(TESTBIN) $(TESTBINS)
for x in $(TESTBINS) ; do ./$$x ; done
if [ ! -x $(TEST_COMPLIANCE) ]; then chmod +x $(TEST_COMPLIANCE); fi
$(TEST_COMPLIANCE) $(TEST_ITERS)
$(TESTOBJ):
-mkdir $(TESTOBJ)
$(TESTBIN):
-mkdir $(TESTBIN)
$(TESTOBJ)/%.o: $(TEST)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(TESTBIN)/%: $(TESTOBJS)
$(CC) $(CFLAGS) $(TESTOBJS) -o $@ -l$(PROJNAME) $(LIBDEPEND) -lcriterion