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