]> git.saurik.com Git - redis.git/blob - src/Makefile
Redis 2.6 branch obtained from unstable removing all the cluster related code.
[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 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 ifeq ($(uname_S),SunOS)
11 CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W -D__EXTENSIONS__ -D_XPG6
12 CCLINK?=-ldl -lnsl -lsocket -lm -lpthread
13 DEBUG?=-g -ggdb
14 else
15 CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W $(ARCH) $(PROF)
16 CCLINK?=-lm -pthread
17 DEBUG?=-g -rdynamic -ggdb
18 endif
19
20 # Default allocator
21 ifeq ($(uname_S),Linux)
22 MALLOC?=jemalloc
23 else
24 MALLOC?=libc
25 endif
26
27 # Backwards compatibility for selecting an allocator
28 ifeq ($(USE_TCMALLOC),yes)
29 MALLOC=tcmalloc
30 endif
31
32 ifeq ($(USE_TCMALLOC_MINIMAL),yes)
33 MALLOC=tcmalloc_minimal
34 endif
35
36 ifeq ($(USE_JEMALLOC),yes)
37 MALLOC=jemalloc
38 endif
39
40 ifeq ($(MALLOC),tcmalloc)
41 ALLOC_LINK=-ltcmalloc
42 ALLOC_FLAGS=-DUSE_TCMALLOC
43 endif
44
45 ifeq ($(MALLOC),tcmalloc_minimal)
46 ALLOC_LINK=-ltcmalloc_minimal
47 ALLOC_FLAGS=-DUSE_TCMALLOC
48 endif
49
50 ifeq ($(MALLOC),jemalloc)
51 ALLOC_LINK=../deps/jemalloc/lib/libjemalloc.a -ldl
52 ALLOC_FLAGS=-DUSE_JEMALLOC -I../deps/jemalloc/include
53 DEPENDENCY_TARGETS+= jemalloc
54 endif
55
56 CCLINK+= $(ALLOC_LINK)
57 CFLAGS+= $(ALLOC_FLAGS)
58 CCOPT= $(CFLAGS) $(ARCH) $(PROF)
59
60 PREFIX= /usr/local
61 INSTALL_BIN= $(PREFIX)/bin
62 INSTALL= cp -pf
63
64 CCCOLOR="\033[34m"
65 LINKCOLOR="\033[34;1m"
66 SRCCOLOR="\033[33m"
67 BINCOLOR="\033[37;1m"
68 MAKECOLOR="\033[32;1m"
69 ENDCOLOR="\033[0m"
70
71 ifndef V
72 QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR);
73 QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR);
74 endif
75
76 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 crc16.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o
77 BENCHOBJ = ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o
78 CLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o
79 CHECKDUMPOBJ = redis-check-dump.o lzf_c.o lzf_d.o
80 CHECKAOFOBJ = redis-check-aof.o
81
82 PRGNAME = redis-server
83 BENCHPRGNAME = redis-benchmark
84 CLIPRGNAME = redis-cli
85 CHECKDUMPPRGNAME = redis-check-dump
86 CHECKAOFPRGNAME = redis-check-aof
87
88 all: redis-benchmark redis-cli redis-check-dump redis-check-aof redis-server
89 @echo ""
90 @echo "Hint: To run 'make test' is a good idea ;)"
91 @echo ""
92
93 # Deps (use make dep to generate this)
94 adlist.o: adlist.c adlist.h zmalloc.h
95 ae.o: ae.c ae.h zmalloc.h config.h ae_kqueue.c
96 ae_epoll.o: ae_epoll.c
97 ae_kqueue.o: ae_kqueue.c
98 ae_select.o: ae_select.c
99 anet.o: anet.c fmacros.h anet.h
100 aof.o: aof.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
101 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
102 bio.o: bio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
103 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h bio.h
104 config.o: config.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
105 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
106 crc16.o: crc16.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
107 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
108 db.o: db.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
109 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
110 debug.o: debug.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
111 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h sha1.h
112 dict.o: dict.c fmacros.h dict.h zmalloc.h
113 endianconv.o: endianconv.c
114 intset.o: intset.c intset.h zmalloc.h endianconv.h
115 lzf_c.o: lzf_c.c lzfP.h
116 lzf_d.o: lzf_d.c lzfP.h
117 multi.o: multi.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
118 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
119 networking.o: networking.c redis.h fmacros.h config.h ae.h sds.h dict.h \
120 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
121 object.o: object.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
122 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
123 pqsort.o: pqsort.c
124 pubsub.o: pubsub.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
125 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
126 rdb.o: rdb.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
127 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h lzf.h
128 redis-benchmark.o: redis-benchmark.c fmacros.h ae.h \
129 ../deps/hiredis/hiredis.h sds.h adlist.h zmalloc.h
130 redis-check-aof.o: redis-check-aof.c fmacros.h config.h
131 redis-check-dump.o: redis-check-dump.c lzf.h
132 redis-cli.o: redis-cli.c fmacros.h version.h ../deps/hiredis/hiredis.h \
133 sds.h zmalloc.h ../deps/linenoise/linenoise.h help.h
134 redis.o: redis.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
135 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h \
136 bio.h asciilogo.h
137 release.o: release.c release.h
138 replication.o: replication.c redis.h fmacros.h config.h ae.h sds.h dict.h \
139 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
140 scripting.o: scripting.c redis.h fmacros.h config.h ae.h sds.h dict.h \
141 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \
142 sha1.h rand.h
143 rio.o: rio.c sds.h
144 sds.o: sds.c sds.h zmalloc.h
145 sha1.o: sha1.c sha1.h config.h
146 slowlog.o: slowlog.c redis.h fmacros.h config.h ae.h sds.h dict.h \
147 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \
148 slowlog.h
149 sort.o: sort.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
150 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h pqsort.h
151 syncio.o: syncio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
152 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
153 t_hash.o: t_hash.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
154 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
155 t_list.o: t_list.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
156 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
157 t_set.o: t_set.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
158 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
159 t_string.o: t_string.c redis.h fmacros.h config.h ae.h sds.h dict.h \
160 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
161 t_zset.o: t_zset.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
162 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
163 util.o: util.c fmacros.h util.h
164 ziplist.o: ziplist.c zmalloc.h util.h ziplist.h endianconv.h
165 zipmap.o: zipmap.c zmalloc.h endianconv.h
166 zmalloc.o: zmalloc.c config.h zmalloc.h
167
168 # Clean local objects when ARCH is different
169 ifneq ($(shell sh -c '[ -f .make-arch ] && cat .make-arch'), $(ARCH))
170 .make-arch: clean
171 else
172 .make-arch:
173 endif
174
175 .make-arch:
176 -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS) ARCH="$(ARCH)")
177 -(echo $(ARCH) > .make-arch)
178
179 # Clean local objects when allocator changes
180 ifneq ($(shell sh -c '[ -f .make-malloc ] && cat .make-malloc'), $(MALLOC))
181 .make-malloc: clean
182 else
183 .make-malloc:
184 endif
185
186 .make-malloc:
187 -(echo $(MALLOC) > .make-malloc)
188
189 # Union of make-prerequisites
190 .make-prerequisites: .make-arch .make-malloc
191 @touch $@
192
193 redis-server: .make-prerequisites $(OBJ)
194 $(QUIET_LINK)$(CC) -o $(PRGNAME) $(CCOPT) $(DEBUG) $(OBJ) ../deps/lua/src/liblua.a $(CCLINK)
195
196 redis-benchmark: .make-prerequisites $(BENCHOBJ)
197 $(QUIET_LINK)$(CC) -o $(BENCHPRGNAME) $(CCOPT) $(DEBUG) $(BENCHOBJ) ../deps/hiredis/libhiredis.a $(CCLINK)
198
199 redis-benchmark.o: redis-benchmark.c .make-prerequisites
200 $(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis $(DEBUG) $(COMPILE_TIME) $<
201
202 redis-cli: .make-prerequisites $(CLIOBJ)
203 $(QUIET_LINK)$(CC) -o $(CLIPRGNAME) $(CCOPT) $(DEBUG) $(CLIOBJ) ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(CCLINK)
204
205 redis-cli.o: redis-cli.c .make-prerequisites
206 $(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis -I../deps/linenoise $(DEBUG) $(COMPILE_TIME) $<
207
208 redis-check-dump: .make-prerequisites $(CHECKDUMPOBJ)
209 $(QUIET_LINK)$(CC) -o $(CHECKDUMPPRGNAME) $(CCOPT) $(DEBUG) $(CHECKDUMPOBJ) $(CCLINK)
210
211 redis-check-aof: .make-prerequisites $(CHECKAOFOBJ)
212 $(QUIET_LINK)$(CC) -o $(CHECKAOFPRGNAME) $(CCOPT) $(DEBUG) $(CHECKAOFOBJ) $(CCLINK)
213
214 # Because the jemalloc.h header is generated as a part of the jemalloc build
215 # process, building it should complete before building any other object. Instead of
216 # depending on a single artifact, simply build all dependencies first.
217 %.o: %.c .make-prerequisites
218 $(QUIET_CC)$(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) -I../deps/lua/src $<
219
220 .PHONY: all clean distclean
221
222 clean:
223 rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) $(CHECKDUMPPRGNAME) $(CHECKAOFPRGNAME) *.o *.gcda *.gcno *.gcov
224
225 distclean: clean
226 -(cd ../deps && $(MAKE) distclean)
227 -(rm -f .make-arch .make-malloc)
228
229 dep:
230 $(CC) -MM *.c -I ../deps/hiredis -I ../deps/linenoise
231
232 test: redis-server redis-check-aof
233 @(cd ..; ./runtest)
234
235 bench:
236 ./redis-benchmark
237
238 log:
239 git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog
240
241 32bit:
242 @echo ""
243 @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
244 @echo ""
245 $(MAKE) ARCH="-m32" JEMALLOC_CFLAGS='CFLAGS="-std=gnu99 -Wall -pipe -g3 -fvisibility=hidden -O3 -funroll-loops -m32"'
246
247 gprof:
248 $(MAKE) PROF="-pg"
249
250 gcov:
251 $(MAKE) PROF="-fprofile-arcs -ftest-coverage"
252
253 noopt:
254 $(MAKE) OPTIMIZATION=""
255
256 32bitgprof:
257 $(MAKE) PROF="-pg" ARCH="-arch i386"
258
259 src/help.h:
260 @../utils/generate-command-help.rb > help.h
261
262 install: all
263 mkdir -p $(INSTALL_BIN)
264 $(INSTALL) $(PRGNAME) $(INSTALL_BIN)
265 $(INSTALL) $(BENCHPRGNAME) $(INSTALL_BIN)
266 $(INSTALL) $(CLIPRGNAME) $(INSTALL_BIN)
267 $(INSTALL) $(CHECKDUMPPRGNAME) $(INSTALL_BIN)
268 $(INSTALL) $(CHECKAOFPRGNAME) $(INSTALL_BIN)