-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
97 lines (78 loc) · 2.73 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
# Makefile for yrmcds
# Prerequisites: gcc 11.1+ or clang 14+
PREFIX = /usr/local
DEFAULT_CONFIG = $(PREFIX)/etc/yrmcds.conf
CACHELINE_SIZE := $(shell getconf LEVEL1_DCACHE_LINESIZE)
ifeq ($(CACHELINE_SIZE), 0)
CACHELINE_SIZE = 32
endif
CC = gcc
CXX = g++
CPPFLAGS = -I. -DCACHELINE_SIZE=$(CACHELINE_SIZE) $(TCMALLOC_FLAGS)
CPPFLAGS += -DDEFAULT_CONFIG=$(DEFAULT_CONFIG)
OPTFLAGS = -O2 #-flto
DEBUGFLAGS = -gdwarf-3 #-fsanitize=address
WARNFLAGS = -Wall -Wnon-virtual-dtor -Woverloaded-virtual
CPUFLAGS = #-march=core2 -mtune=corei7
CXXFLAGS = -std=gnu++17 $(OPTFLAGS) $(DEBUGFLAGS) $(shell getconf LFS_CFLAGS) $(WARNFLAGS) $(CPUFLAGS)
LDFLAGS = -L. $(shell getconf LFS_LDFLAGS)
LDLIBS = $(shell getconf LFS_LIBS) -lyrmcds $(LIBTCMALLOC) -latomic -lpthread
HEADERS = $(sort $(wildcard src/*.hpp src/*/*.hpp cybozu/*.hpp))
SOURCES = $(sort $(wildcard src/*.cpp src/*/*.cpp cybozu/*.cpp))
OBJECTS = $(patsubst %.cpp,%.o,$(SOURCES))
EXE = yrmcdsd
TESTS = $(patsubst %.cpp,%,$(sort $(wildcard test/*.cpp)))
LIB = libyrmcds.a
LIB_OBJECTS = $(filter-out src/main.o,$(OBJECTS))
PACKAGES = build-essential libgoogle-perftools-dev
TCMALLOC_HEADER := $(shell sh ./detect_tcmalloc.sh $(CXX) $(CPPFLAGS))
ifeq ($(TCMALLOC_HEADER), gperftools/tcmalloc.h)
TCMALLOC_FLAGS = -DUSE_TCMALLOC
LIBTCMALLOC = -ltcmalloc_minimal
export TCMALLOC_FLAGS LIBTCMALLOC
else ifeq ($(TCMALLOC_HEADER), google/tcmalloc.h)
TCMALLOC_FLAGS = -DUSE_TCMALLOC -DTCMALLOC_IN_GOOGLE
LIBTCMALLOC = -ltcmalloc_minimal
export TCMALLOC_FLAGS LIBTCMALLOC
endif
all: $(EXE)
lib: $(LIB)
tests: $(TESTS)
strip: $(EXE)
nm -n $(EXE) | grep -v '\( [aNUw] \)\|\(__crc_\)\|\( \$$[adt]\)' > $(EXE).map
strip $(EXE)
ifeq ($(wildcard /run/systemd/system), /run/systemd/system)
install-service:
cp etc/yrmcds.service /etc/systemd/system/yrmcds.service
systemctl daemon-reload
else
install-service:
cp etc/upstart /etc/init/yrmcds.conf
endif
install: $(EXE)
$(MAKE) install-service
cp etc/logrotate /etc/logrotate.d/yrmcds
cp etc/yrmcds.conf $(DEFAULT_CONFIG)
cp $(EXE) $(PREFIX)/sbin/yrmcdsd
install -o nobody -g nogroup -m 644 /dev/null /var/log/yrmcds.log
COPYING.hpp: COPYING
echo -n 'static char COPYING[] = R"(' > $@
cat $< >>$@
echo ')";' >>$@
src/main.o: COPYING.hpp
$(OBJECTS): $(HEADERS)
$(LIB): $(LIB_OBJECTS)
$(AR) rcs $@ $^
$(EXE): src/main.o $(LIB)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
test/%.exe: test/%.o $(LIB)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
$(TESTS): $(LIB)
@$(MAKE) -s [email protected]
@echo
clean:
rm -f src/*.o src/*/*.o cybozu/*.o test/*.o test/*.exe COPYING.hpp $(EXE) $(EXE).map $(LIB)
setup:
sudo apt-get install -y --install-recommends $(PACKAGES)
.PHONY: all strip lib tests install install-service clean setup test_env $(TESTS)