File: Makefile

package info (click to toggle)
yrmcds 1.1.8-1.1
  • links: PTS
  • area: main
  • in suites: buster, sid
  • size: 1,000 kB
  • sloc: cpp: 11,157; sh: 148; makefile: 117
file content (107 lines) | stat: -rw-r--r-- 3,150 bytes parent folder | download | duplicates (2)
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
# Makefile for yrmcds
# Prerequisites: gcc 4.8+ or clang 3.3+

PREFIX = /usr/local
DEFAULT_CONFIG = /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++11 $(OPTFLAGS) $(DEBUGFLAGS) $(shell getconf LFS_CFLAGS) $(WARNFLAGS) $(CPUFLAGS)
LDFLAGS += -L. $(shell getconf LFS_LDFLAGS)
LDLIBS = $(shell getconf LFS_LIBS) -lyrmcds $(LIBTCMALLOC) -latomic -lpthread
CLDOC := LD_LIBRARY_PATH=$(shell llvm-config --libdir 2>/dev/null) cldoc

HEADERS = $(wildcard src/*.hpp src/*/*.hpp cybozu/*.hpp)
SOURCES = $(wildcard src/*.cpp src/*/*.cpp cybozu/*.cpp)
OBJECTS = $(patsubst %.cpp,%.o,$(SOURCES))

EXE = yrmcdsd
TESTS = $(patsubst %.cpp,%,$(wildcard test/*.cpp))
LIB = libyrmcds.a
LIB_OBJECTS = $(filter-out src/main.o,$(OBJECTS))
PACKAGES = build-essential libgoogle-perftools-dev python-pip

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 $@.exe
	./$@.exe
	@echo

html:
	@clang++ -v 2>/dev/null || (echo "No clang++ in PATH." && false)
	rm -rf html
	$(CLDOC) generate $(CPPFLAGS) $(CXXFLAGS) -w -D__STRICT_ANSI__ -- --output html --merge docs $(HEADERS)

serve: html
	@cd html; python -m SimpleHTTPServer 8888 || true

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)
	sudo pip install cldoc --upgrade

.PHONY: all strip lib tests install install-service html serve clean setup test_env $(TESTS)