-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
157 lines (128 loc) · 5.25 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#==============================================================================
# MACROS
#==============================================================================
CC := gcc
CSTD := -std=c11
DEV_CFLAGS := -Wall -Wextra -Wpedantic -Wformat=2 -Wno-unused-parameter \
-Wshadow -Wwrite-strings -Wstrict-prototypes \
-Wold-style-definition -Wredundant-decls -Wnested-externs \
-Wmissing-include-dirs -Og
LINK_FLAGS := -lm -lfdb_c -lpthread
FDB_VERSION := 710
PARAMS := -DFDB_API_VERSION=$(FDB_VERSION)
BIN_DIR := bin/
DEP_DIR := dep/
OBJ_DIR := obj/
SRC_DIR := src/
TEST_DEP_DIR := dep/test/
TEST_OBJ_DIR := obj/test/
TEST_SRC_DIR := src/test/
BENCH_DEP_DIR := dep/benchmark/
BENCH_OBJ_DIR := obj/benchmark/
BENCH_SRC_DIR := src/benchmark/
SOURCES := $(shell ls $(SRC_DIR)*.c)
OBJECTS := $(subst $(SRC_DIR),$(OBJ_DIR),$(subst .c,.o,$(SOURCES)))
DEPFILES := $(subst $(SRC_DIR),$(DEP_DIR),$(subst .c,.d,$(SOURCES)))
TEST_SOURCES := $(shell ls $(TEST_SRC_DIR)*.c)
TEST_OBJECTS := $(subst $(TEST_SRC_DIR),$(TEST_OBJ_DIR),$(subst .c,.o,$(TEST_SOURCES)))
TEST_DEPFILES := $(subst $(TEST_SRC_DIR),$(TEST_DEP_DIR),$(subst .c,.d,$(TEST_SOURCES)))
BENCH_SOURCES := $(shell ls $(BENCH_SRC_DIR)*.c)
BENCH_OBJECTS := $(subst $(BENCH_SRC_DIR),$(BENCH_OBJ_DIR),$(subst .c,.o,$(BENCH_SOURCES)))
BENCH_DEPFILES := $(subst $(BENCH_SRC_DIR),$(BENCH_DEP_DIR),$(subst .c,.d,$(BENCH_SOURCES)))
TEST_UNIT_CMD := $(addprefix $(BIN_DIR),seguro-test-unit)
TEST_INTEG_CMD := $(addprefix $(BIN_DIR),seguro-test-integ)
BENCHMARK_WRITE_CMD := $(addprefix $(BIN_DIR),seguro-benchmark-write)
#==============================================================================
# RULES
#==============================================================================
# Default target. Compile & link all source files, then print usage instructions.
#
default : $(BENCHMARK_CMD) help
# Helpful rule which lists all other rules and encourages documentation
#
# target: help - Display all targets in makefile
#
help :
@egrep "^# target:" makefile
# Run Seguro tests
#
# target: test - Run all Seguro tests
#
test : test-unit test-integ
# Run Seguro unit tests
#
# target: test-unit - Run Seguro unit tests
#
test-unit : $(TEST_UNIT_CMD)
@$(TEST_UNIT_CMD)
# Link unit tests into an executable binary
#
$(TEST_UNIT_CMD) : $(OBJECTS) $(addprefix $(TEST_OBJ_DIR),unit.o)
@mkdir -p $(BIN_DIR)
$(CC) $(addprefix $(TEST_OBJ_DIR),unit.o) $(OBJECTS) $(LINK_FLAGS) -o $@
# Run Seguro integration tests
#
# target: test-unit - Run Seguro integration tests
#
test-integ : $(TEST_INTEG_CMD)
@$(TEST_INTEG_CMD)
# Link integration tests into an executable binary
#
$(TEST_INTEG_CMD) : $(OBJECTS) $(addprefix $(TEST_OBJ_DIR),integ.o)
@mkdir -p $(BIN_DIR)
$(CC) $(addprefix $(TEST_OBJ_DIR),integ.o) $(OBJECTS) $(LINK_FLAGS) -o $@
# Run Seguro benchmarks
#
# target: benchmark - Run all Seguro benchmarks
#
benchmark : benchmark-write
# Run Seguro write benchmarks
#
# target: benchmark-write - Run Seguro write benchmarks
#
benchmark-write : $(BENCHMARK_WRITE_CMD)
@$(BENCHMARK_WRITE_CMD)
# Link benchmark suite into an executable binary
#
$(BENCHMARK_WRITE_CMD) : $(OBJECTS) $(addprefix $(BENCH_OBJ_DIR),write.o)
@mkdir -p $(BIN_DIR)
$(CC) $(addprefix $(BENCH_OBJ_DIR),write.o) $(OBJECTS) $(LINK_FLAGS) -o $@
# Compile all source files, but do not link. As a side effect, compile a dependency file for each source file.
#
# Dependency files are a common makefile feature used to speed up builds by auto-generating granular makefile targets.
# These files minimize the number of targets that need to be recomputed when source files are modified and can lead to
# massive build-time improvements.
# For more information, see the "-M" option documentation in the GCC man page, as well as this paper:
# https://web.archive.org/web/20150319074420/http://aegis.sourceforge.net/auug97.pdf
#
$(addprefix $(DEP_DIR),%.d): $(addprefix $(SRC_DIR),%.c)
@mkdir -p $(OBJ_DIR)
@mkdir -p $(DEP_DIR)
$(CC) -MD -MP -MF $@ -MT '$@ $(subst $(DEP_DIR),$(OBJ_DIR),$(@:.d=.o))' \
$< -c -o $(subst $(DEP_DIR),$(OBJ_DIR),$(@:.d=.o)) $(CSTD) $(PARAMS) $(DEV_CFLAGS)
# Same as above, but specifically for test files
#
$(addprefix $(TEST_DEP_DIR),%.d): $(addprefix $(TEST_SRC_DIR),%.c)
@mkdir -p $(TEST_OBJ_DIR)
@mkdir -p $(TEST_DEP_DIR)
$(CC) -MD -MP -MF $@ -MT '$@ $(subst $(DEP_DIR),$(OBJ_DIR),$(@:.d=.o))' \
$< -c -o $(subst $(DEP_DIR),$(OBJ_DIR),$(@:.d=.o)) $(CSTD) $(PARAMS) $(DEV_CFLAGS)
# Same as above, but specifically for benchmarking files
#
$(addprefix $(BENCH_DEP_DIR),%.d): $(addprefix $(BENCH_SRC_DIR),%.c)
@mkdir -p $(BENCH_OBJ_DIR)
@mkdir -p $(BENCH_DEP_DIR)
$(CC) -MD -MP -MF $@ -MT '$@ $(subst $(DEP_DIR),$(OBJ_DIR),$(@:.d=.o))' \
$< -c -o $(subst $(DEP_DIR),$(OBJ_DIR),$(@:.d=.o)) $(CSTD) $(PARAMS) $(DEV_CFLAGS)
# Force build of dependency and object files to import additional makefile targets
#
-include $(DEPFILES) $(TEST_DEPFILES) $(BENCH_DEPFILES)
# Clean up files produced by the makefile. Any invocation should execute, regardless of file modification date, hence
# dependency on FRC.
#
# target: clean - Remove all files produced by this makefile
clean : FRC
@rm -rf $(BIN_DIR) $(DEP_DIR) $(OBJ_DIR)
# Special pseudo target which always needs to be recomputed. Forces full rebuild of target every time when used as a
# component.
FRC :