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