forked from plasma-umass/DoubleTake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
145 lines (113 loc) · 3.78 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
# optimization level, to build at -O2: make O=2
O = 0
# x86
ARCH = amd64
FEATURE_FLAGS := \
-DDEBUG_LEVEL=3 \
-DDETECT_OVERFLOW \
-DDETECT_USAGE_AFTER_FREE \
# -DDETECT_MEMORY_LEAKS \
WARNFLAGS := \
-Werror \
-Wall -Wextra -Wpedantic \
-Wundef \
-Wno-unused-parameter \
-Wno-nested-anon-types
SUBDIRS = tests tests/unit
SUBDIR_BUILDFILES = $(addsuffix /build.mk,$(SUBDIRS))
# prefer clang
CC = clang
CXX = clang++
AR = ar
RANLIB = ranlib
# want stdatomic.h in C, which is a c11 feature
CVER = c11
CXXVER = c++11
CFLAGS = -g -pedantic -fPIC -fno-omit-frame-pointer -D_DEFAULT_SOURCE -D_BSD_SOURCE \
$(WARNFLAGS) $(FEATURE_FLAGS) -Iinclude -Iheaplayers
CXXFLAGS = -std=$(CXXVER) $(CFLAGS)
ASFLAGS =
# this is for generic linker flags - target specific $LIB dependencies
# are added later.
LDFLAGS =
ifeq ($(ARCH), x86)
CFLAGS += -m32 -DX86_32BIT
LDFLAGS += -m32
endif
LIB = libdoubletake.so
LIB_DEPS = dl pthread
LIB_SRCS = $(wildcard source/*.cpp) $(wildcard source/*.c) $(wildcard source/*_$(ARCH).s)
LIB_OBJS = $(patsubst source/%,build/%,$(patsubst %_$(ARCH).s,%.o,$(patsubst %.cpp,%.o,$(patsubst %.c,%.o,$(LIB_SRCS)))))
# these object files contain the global initialization and
# interposition functions needed for libdoubletake - but we don't want
# to include them when building unit tests
LIB_GLOBAL_OBJS = build/libdoubletake.o
LIB_UNITTEST_OBJS = $(filter-out $(LIB_GLOBAL_OBJS),$(LIB_OBJS))
# used for unit tests
TESTLIB = libdttest_s.a
BUILDDIR = build/.stamp
TARGETS = $(LIB)
# make sure we recompile when the Makefile (and associated
# CFLAGS/LDFLAGS change)
CONFIG = Makefile
# quiet output, but allow us to look at what commands are being
# executed by passing 'V=1' to make, without requiring temporarily
# editing the Makefile.
ifneq ($V, 1)
MAKEFLAGS += -s
endif
# GNU make, you are the worst. Remove a bunch of the built in rules
# for version control systems that haven't been used this millenium.
.SUFFIXES:
%: %,v
%: RCS/%,v
%: RCS/%
%: s.%
%: SCCS/s.%
# list only those we use
.SUFFIXES: .d .c .cpp .s .o .test
# test-bin is a bit of a hack so that we can declare the all target
# first (this making it the default target) before we include the
# build.mk files in subdirs, which add an arbitrary number fof entries
# to TEST_TARGETS
all: $(TARGETS) test-bin
include $(SUBDIR_BUILDFILES)
test-bin: $(TEST_BIN_TARGETS)
test: $(TESTS)
# make sure build/ exists in the current directory
$(BUILDDIR):
mkdir -p build
touch $(BUILDDIR)
build/%.o: source/%_$(ARCH).s $(CONFIG) $(BUILDDIR)
@echo " AS $@"
$(CC) -O$(O) $(ASFLAGS) -o $@ -c $<
build/%.o: source/%.c $(CONFIG) $(BUILDDIR)
@echo " CC $@"
$(CC) -O$(O) -std=$(CVER) $(CFLAGS) -MMD -o $@ -c $<
build/%.o: source/%.cpp $(CONFIG) $(BUILDDIR)
@echo " CXX $@"
$(CXX) -O$(O) $(CXXFLAGS) -MMD -o $@ -c $<
$(LIB): $(LIB_OBJS) $(CONFIG)
@echo " LD $@"
$(CXX) -shared $(LDFLAGS) $(addprefix -l,$(LIB_DEPS)) -o $@ $(LIB_OBJS)
$(TESTLIB): $(LIB_UNITTEST_OBJS) $(CONFIG)
@echo " AR $@"
$(AR) rcD $@ $(LIB_UNITTEST_OBJS)
$(RANLIB) $@
# emacs-compatible tagfile generation - for navigating around in emacs
TAGS: include/*.hh source/*.cpp
etags -a include/*.hh source/*.cpp
format:
clang-format -i include/*.hh source/*.cpp
clean:
find . -name '*.o' -print0 | xargs -0 rm -f
find . -name '*.d' -print0 | xargs -0 rm -f
find . -name '*.gcno' -print0 | xargs -0 rm -f
find . -name '*.gcda' -print0 | xargs -0 rm -f
find . -name '*.gcov' -print0 | xargs -0 rm -f
rm -f $(TARGETS) $(TEST_BIN_TARGETS) $(TESTLIB)
distclean: clean
find . -name '*.d' -print0 | xargs -0 rm -f
find . -name '*~' -print0 | xargs -0 rm -f
-include $(LIB_OBJS:.o=.d)
.PHONY: all test-bin format clean distclean $(PHONY_TARGETS)