]> git.saurik.com Git - redis.git/blob - src/Makefile
First implementation of Redis Sentinel.
[redis.git] / src / Makefile
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 # The Makefile composes the final FINAL_CFLAGS and FINAL_LDFLAGS using
6 # what is needed for Redis plus the standard CFLAGS and LDFLAGS passed.
7 # However when building the dependencies (Jemalloc, Lua, Hiredis, ...)
8 # CFLAGS and LDFLAGS are propagated to the dependencies, so to pass
9 # flags only to be used when compiling / linking Redis itself REDIS_CFLAGS
10 # and REDIS_LDFLAGS are used instead (this is the case of 'make gcov').
11 #
12 # Dependencies are stored in the Makefile.dep file. To rebuild this file
13 # Just use 'make dep', but this is only needed by developers.
14
15 release_hdr := $(shell sh -c './mkreleasehdr.sh')
16 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
17 OPTIMIZATION?=-O2
18 DEPENDENCY_TARGETS=hiredis linenoise lua
19
20 # Default settings
21 STD= -std=c99 -pedantic
22 WARN= -Wall
23 OPT= $(OPTIMIZATION)
24
25 # Default allocator
26 ifeq ($(uname_S),Linux)
27 MALLOC=jemalloc
28 else
29 MALLOC=libc
30 endif
31
32 # Backwards compatibility for selecting an allocator
33 ifeq ($(USE_TCMALLOC),yes)
34 MALLOC=tcmalloc
35 endif
36
37 ifeq ($(USE_TCMALLOC_MINIMAL),yes)
38 MALLOC=tcmalloc_minimal
39 endif
40
41 ifeq ($(USE_JEMALLOC),yes)
42 MALLOC=jemalloc
43 endif
44
45 # Override default settings if possible
46 -include .make-settings
47
48 ifeq ($(uname_S),SunOS)
49 FINAL_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS) -D__EXTENSIONS__ -D_XPG6
50 FINAL_LDFLAGS= $(LDFLAGS) $(REDIS_LDFLAGS) -g -ggdb
51 FINAL_LIBS= -ldl -lnsl -lsocket -lm -lpthread
52 DEBUG= -g -ggdb
53 else
54 FINAL_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS)
55 FINAL_LDFLAGS= $(LDFLAGS) $(REDIS_LDFLAGS) -g -rdynamic -ggdb
56 FINAL_LIBS= -lm -pthread
57 DEBUG= -g -rdynamic -ggdb
58 endif
59
60 # Include paths to dependencies
61 FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src
62
63 ifeq ($(MALLOC),tcmalloc)
64 FINAL_CFLAGS+= -DUSE_TCMALLOC
65 FINAL_LIBS+= -ltcmalloc
66 endif
67
68 ifeq ($(MALLOC),tcmalloc_minimal)
69 FINAL_CFLAGS+= -DUSE_TCMALLOC
70 FINAL_LIBS+= -ltcmalloc_minimal
71 endif
72
73 ifeq ($(MALLOC),jemalloc)
74 DEPENDENCY_TARGETS+= jemalloc
75 FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
76 FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl
77 endif
78
79 REDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS)
80 REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS)
81 REDIS_INSTALL=$(QUIET_INSTALL)$(INSTALL)
82
83 PREFIX?=/usr/local
84 INSTALL_BIN= $(PREFIX)/bin
85 INSTALL= cp -pf
86
87 CCCOLOR="\033[34m"
88 LINKCOLOR="\033[34;1m"
89 SRCCOLOR="\033[33m"
90 BINCOLOR="\033[37;1m"
91 MAKECOLOR="\033[32;1m"
92 ENDCOLOR="\033[0m"
93
94 ifndef V
95 QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2;
96 QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
97 QUIET_INSTALL = @printf ' %b %b\n' $(LINKCOLOR)INSTALL$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
98 endif
99
100 REDIS_SERVER_NAME= redis-server
101 REDIS_SENTINEL_NAME= redis-sentinel
102 REDIS_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 migrate.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o bitops.o sentinel.o
103 REDIS_CLI_NAME= redis-cli
104 REDIS_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o
105 REDIS_BENCHMARK_NAME= redis-benchmark
106 REDIS_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o
107 REDIS_CHECK_DUMP_NAME= redis-check-dump
108 REDIS_CHECK_DUMP_OBJ= redis-check-dump.o lzf_c.o lzf_d.o crc64.o
109 REDIS_CHECK_AOF_NAME= redis-check-aof
110 REDIS_CHECK_AOF_OBJ= redis-check-aof.o
111
112 all: $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME)
113 @echo ""
114 @echo "Hint: To run 'make test' is a good idea ;)"
115 @echo ""
116
117 .PHONY: all
118
119 # Deps (use make dep to generate this)
120 include Makefile.dep
121
122 dep:
123 $(REDIS_CC) -MM *.c > Makefile.dep
124
125 .PHONY: dep
126
127 persist-settings: distclean
128 echo STD=$(STD) >> .make-settings
129 echo WARN=$(WARN) >> .make-settings
130 echo OPT=$(OPT) >> .make-settings
131 echo MALLOC=$(MALLOC) >> .make-settings
132 echo CFLAGS=$(CFLAGS) >> .make-settings
133 echo LDFLAGS=$(LDFLAGS) >> .make-settings
134 echo REDIS_CFLAGS=$(REDIS_CFLAGS) >> .make-settings
135 echo REDIS_LDFLAGS=$(REDIS_LDFLAGS) >> .make-settings
136 echo PREV_FINAL_CFLAGS=$(FINAL_CFLAGS) >> .make-settings
137 echo PREV_FINAL_LDFLAGS=$(FINAL_LDFLAGS) >> .make-settings
138 -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS))
139
140 .PHONY: persist-settings
141
142 # Prerequisites target
143 .make-prerequisites:
144 @touch $@
145
146 # Clean everything, persist settings and build dependencies if anything changed
147 ifneq ($(strip $(PREV_FINAL_CFLAGS)), $(strip $(FINAL_CFLAGS)))
148 .make-prerequisites: persist-settings
149 endif
150
151 ifneq ($(strip $(PREV_FINAL_LDFLAGS)), $(strip $(FINAL_LDFLAGS)))
152 .make-prerequisites: persist-settings
153 endif
154
155 # redis-server
156 $(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ)
157 $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a $(FINAL_LIBS)
158
159 # redis-sentinel
160 $(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME)
161 $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME)
162
163 # redis-cli
164 $(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
165 $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS)
166
167 # redis-benchmark
168 $(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
169 $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS)
170
171 # redis-check-dump
172 $(REDIS_CHECK_DUMP_NAME): $(REDIS_CHECK_DUMP_OBJ)
173 $(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
174
175 # redis-check-aof
176 $(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ)
177 $(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
178
179 # Because the jemalloc.h header is generated as a part of the jemalloc build,
180 # building it should complete before building any other object. Instead of
181 # depending on a single artifact, build all dependencies first.
182 %.o: %.c .make-prerequisites
183 $(REDIS_CC) -c $<
184
185 clean:
186 rm -rf $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html
187
188 .PHONY: clean
189
190 distclean: clean
191 -(cd ../deps && $(MAKE) distclean)
192 -(rm -f .make-*)
193
194 .PHONY: distclean
195
196 test: $(REDIS_SERVER_NAME) $(REDIS_CHECK_AOF_NAME)
197 @(cd ..; ./runtest)
198
199 lcov:
200 $(MAKE) gcov
201 @(set -e; cd ..; ./runtest --clients 1)
202 @geninfo -o redis.info .
203 @genhtml --legend -o lcov-html redis.info
204
205 .PHONY: lcov
206
207 bench: $(REDIS_BENCHMARK_NAME)
208 ./$(REDIS_BENCHMARK_NAME)
209
210 32bit:
211 @echo ""
212 @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
213 @echo ""
214 $(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
215
216 gcov:
217 $(MAKE) REDIS_CFLAGS="-fprofile-arcs -ftest-coverage -DCOVERAGE_TEST" REDIS_LDFLAGS="-fprofile-arcs -ftest-coverage"
218
219 noopt:
220 $(MAKE) OPT="-O0"
221
222 src/help.h:
223 @../utils/generate-command-help.rb > help.h
224
225 install: all
226 mkdir -p $(INSTALL_BIN)
227 $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(INSTALL_BIN)
228 $(REDIS_INSTALL) $(REDIS_BENCHMARK_NAME) $(INSTALL_BIN)
229 $(REDIS_INSTALL) $(REDIS_CLI_NAME) $(INSTALL_BIN)
230 $(REDIS_INSTALL) $(REDIS_CHECK_DUMP_NAME) $(INSTALL_BIN)
231 $(REDIS_INSTALL) $(REDIS_CHECK_AOF_NAME) $(INSTALL_BIN)