]>
Commit | Line | Data |
---|---|---|
1 | # Redis Makefile | |
2 | # Copyright (C) 2009 Salvatore Sanfilippo <antirez at gmail dot com> | |
3 | # This file is released under the BSD license, see the COPYING file | |
4 | ||
5 | release_hdr := $(shell sh -c './mkreleasehdr.sh') | |
6 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') | |
7 | OPTIMIZATION?=-O2 | |
8 | DEPENDENCY_TARGETS=hiredis linenoise lua | |
9 | ||
10 | STD= -std=c99 -pedantic | |
11 | WARN= -Wall | |
12 | OPT= $(OPTIMIZATION) | |
13 | ||
14 | ifeq ($(uname_S),SunOS) | |
15 | R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) -D__EXTENSIONS__ -D_XPG6 | |
16 | R_LDFLAGS= $(LDFLAGS) | |
17 | R_LIBS= $(LIBS) -ldl -lnsl -lsocket -lm -lpthread | |
18 | DEBUG= -g -ggdb | |
19 | else | |
20 | R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) | |
21 | R_LDFLAGS= $(LDFLAGS) | |
22 | R_LIBS= $(LIBS) -lm -pthread | |
23 | DEBUG= -g -rdynamic -ggdb | |
24 | endif | |
25 | ||
26 | # Include paths to dependencies | |
27 | R_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src | |
28 | ||
29 | # Default allocator | |
30 | ifeq ($(uname_S),Linux) | |
31 | MALLOC?=jemalloc | |
32 | else | |
33 | MALLOC?=libc | |
34 | endif | |
35 | ||
36 | # Backwards compatibility for selecting an allocator | |
37 | ifeq ($(USE_TCMALLOC),yes) | |
38 | MALLOC=tcmalloc | |
39 | endif | |
40 | ||
41 | ifeq ($(USE_TCMALLOC_MINIMAL),yes) | |
42 | MALLOC=tcmalloc_minimal | |
43 | endif | |
44 | ||
45 | ifeq ($(USE_JEMALLOC),yes) | |
46 | MALLOC=jemalloc | |
47 | endif | |
48 | ||
49 | ifeq ($(MALLOC),tcmalloc) | |
50 | R_CFLAGS+= -DUSE_TCMALLOC | |
51 | R_LIBS+= -ltcmalloc | |
52 | endif | |
53 | ||
54 | ifeq ($(MALLOC),tcmalloc_minimal) | |
55 | R_CFLAGS+= -DUSE_TCMALLOC | |
56 | R_LIBS+= -ltcmalloc_minimal | |
57 | endif | |
58 | ||
59 | ifeq ($(MALLOC),jemalloc) | |
60 | DEPENDENCY_TARGETS+= jemalloc | |
61 | R_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include | |
62 | R_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl | |
63 | endif | |
64 | ||
65 | R_CC=$(QUIET_CC)$(CC) $(R_CFLAGS) | |
66 | R_LD=$(QUIET_LINK)$(CC) $(R_LDFLAGS) | |
67 | ||
68 | PREFIX= /usr/local | |
69 | INSTALL_BIN= $(PREFIX)/bin | |
70 | INSTALL= cp -pf | |
71 | ||
72 | CCCOLOR="\033[34m" | |
73 | LINKCOLOR="\033[34;1m" | |
74 | SRCCOLOR="\033[33m" | |
75 | BINCOLOR="\033[37;1m" | |
76 | MAKECOLOR="\033[32;1m" | |
77 | ENDCOLOR="\033[0m" | |
78 | ||
79 | ifndef V | |
80 | QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2; | |
81 | QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2; | |
82 | endif | |
83 | ||
84 | R_SERVER_NAME= redis-server | |
85 | R_SERVER_OBJ= adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o | |
86 | R_CLI_NAME= redis-cli | |
87 | R_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o | |
88 | R_BENCHMARK_NAME= redis-benchmark | |
89 | R_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o | |
90 | R_CHECK_DUMP_NAME= redis-check-dump | |
91 | R_CHECK_DUMP_OBJ= redis-check-dump.o lzf_c.o lzf_d.o | |
92 | R_CHECK_AOF_NAME= redis-check-aof | |
93 | R_CHECK_AOF_OBJ= redis-check-aof.o | |
94 | ||
95 | all: $(R_SERVER_NAME) $(R_CLI_NAME) $(R_BENCHMARK_NAME) $(R_CHECK_DUMP_NAME) $(R_CHECK_AOF_NAME) | |
96 | @echo "" | |
97 | @echo "Hint: To run 'make test' is a good idea ;)" | |
98 | @echo "" | |
99 | ||
100 | .PHONY: all | |
101 | ||
102 | # Deps (use make dep to generate this) | |
103 | include Makefile.dep | |
104 | ||
105 | dep: | |
106 | $(R_CC) -MM *.c | |
107 | ||
108 | .PHONY: dep | |
109 | ||
110 | # Prerequisites target | |
111 | .make-prerequisites: | |
112 | @touch $@ | |
113 | ||
114 | # Clean local objects and build dependencies when R_CFLAGS is different | |
115 | ifneq ($(shell sh -c '[ -f .make-cflags ] && cat .make-cflags || echo none'), $(R_CFLAGS)) | |
116 | .make-cflags: clean | |
117 | -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS)) | |
118 | -(echo "$(R_CFLAGS)" > .make-cflags) | |
119 | .make-prerequisites: .make-cflags | |
120 | endif | |
121 | ||
122 | # Clean local objects when R_LDFLAGS is different | |
123 | ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'), $(R_LDFLAGS)) | |
124 | .make-ldflags: clean | |
125 | -(echo "$(R_LDFLAGS)" > .make-ldflags) | |
126 | .make-prerequisites: .make-ldflags | |
127 | endif | |
128 | ||
129 | # Clean local objects when MALLOC is different | |
130 | ifneq ($(shell sh -c '[ -f .make-malloc ] && cat .make-malloc || echo none'), $(MALLOC)) | |
131 | .make-malloc: clean | |
132 | -(echo "$(MALLOC)" > .make-malloc) | |
133 | .make-prerequisites: .make-malloc | |
134 | endif | |
135 | ||
136 | # redis-server | |
137 | $(R_SERVER_NAME): $(R_SERVER_OBJ) | |
138 | $(R_LD) -o $@ $^ ../deps/lua/src/liblua.a $(R_LIBS) | |
139 | ||
140 | # redis-cli | |
141 | $(R_CLI_NAME): $(R_CLI_OBJ) | |
142 | $(R_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(R_LIBS) | |
143 | ||
144 | # redis-benchmark | |
145 | $(R_BENCHMARK_NAME): $(R_BENCHMARK_OBJ) | |
146 | $(R_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(R_LIBS) | |
147 | ||
148 | # redis-check-dump | |
149 | $(R_CHECK_DUMP_NAME): $(R_CHECK_DUMP_OBJ) | |
150 | $(R_LD) -o $@ $^ $(R_LIBS) | |
151 | ||
152 | # redis-check-aof | |
153 | $(R_CHECK_AOF_NAME): $(R_CHECK_AOF_OBJ) | |
154 | $(R_LD) -o $@ $^ $(R_LIBS) | |
155 | ||
156 | # Because the jemalloc.h header is generated as a part of the jemalloc build, | |
157 | # building it should complete before building any other object. Instead of | |
158 | # depending on a single artifact, build all dependencies first. | |
159 | %.o: %.c .make-prerequisites | |
160 | $(R_CC) -c $< | |
161 | ||
162 | clean: | |
163 | rm -rf $(R_SERVER_NAME) $(R_CLI_NAME) $(R_BENCHMARK_NAME) $(R_CHECK_DUMP_NAME) $(R_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html | |
164 | ||
165 | .PHONY: clean | |
166 | ||
167 | distclean: clean | |
168 | -(cd ../deps && $(MAKE) distclean) | |
169 | -(rm -f .make-*) | |
170 | ||
171 | .PHONY: distclean | |
172 | ||
173 | test: $(R_SERVER_NAME) $(R_CHECK_AOF_NAME) | |
174 | @(cd ..; ./runtest) | |
175 | ||
176 | lcov: | |
177 | $(MAKE) clean gcov | |
178 | @(set -e; cd ..; ./runtest --clients 1) | |
179 | @geninfo -o redis.info . | |
180 | @genhtml --legend -o lcov-html redis.info | |
181 | ||
182 | .PHONY: lcov | |
183 | ||
184 | bench: $(R_BENCHMARK_NAME) | |
185 | ./$(R_BENCHMARK_NAME) | |
186 | ||
187 | log: | |
188 | git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog | |
189 | ||
190 | 32bit: | |
191 | @echo "" | |
192 | @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386" | |
193 | @echo "" | |
194 | $(MAKE) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32" | |
195 | ||
196 | gprof: | |
197 | $(MAKE) CFLAGS="$(CFLAGS) -pg" LDFLAGS="$(LDFLAGS) -pg" | |
198 | ||
199 | gcov: | |
200 | $(MAKE) CFLAGS="$(CFLAGS) -fprofile-arcs -ftest-coverage -DCOVERAGE_TEST" | |
201 | ||
202 | noopt: | |
203 | $(MAKE) OPT="-O0" | |
204 | ||
205 | 32bitgprof: | |
206 | $(MAKE) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32" gprof | |
207 | ||
208 | src/help.h: | |
209 | @../utils/generate-command-help.rb > help.h | |
210 | ||
211 | install: all | |
212 | mkdir -p $(INSTALL_BIN) | |
213 | $(INSTALL) $(R_SERVER_NAME) $(INSTALL_BIN) | |
214 | $(INSTALL) $(R_BENCHMARK_NAME) $(INSTALL_BIN) | |
215 | $(INSTALL) $(R_CLI_NAME) $(INSTALL_BIN) | |
216 | $(INSTALL) $(R_CHECK_DUMP_NAME) $(INSTALL_BIN) | |
217 | $(INSTALL) $(R_CHECK_AOF_NAME) $(INSTALL_BIN) |