2 # Copyright (C) 2009 Salvatore Sanfilippo <antirez at gmail dot com>
3 # This file is released under the BSD license, see the COPYING file
5 release_hdr := $(shell sh -c './mkreleasehdr.sh')
6 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
9 ifeq ($(uname_S),Linux)
10 ifneq ($(FORCE_LIBC_MALLOC),yes)
15 ifeq ($(uname_S),SunOS)
16 CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W -D__EXTENSIONS__ -D_XPG6
17 CCLINK?=-ldl -lnsl -lsocket -lm -lpthread
20 CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W $(ARCH) $(PROF)
22 DEBUG?=-g -rdynamic -ggdb
25 ifeq ($(USE_TCMALLOC),yes)
28 ALLOC_FLAGS=-DUSE_TCMALLOC
31 ifeq ($(USE_TCMALLOC_MINIMAL),yes)
33 ALLOC_LINK=-ltcmalloc_minimal
34 ALLOC_FLAGS=-DUSE_TCMALLOC
37 ifeq ($(USE_JEMALLOC),yes)
38 ALLOC_DEP=../deps/jemalloc/lib/libjemalloc.a
39 ALLOC_LINK=$(ALLOC_DEP)
40 ALLOC_FLAGS=-DUSE_JEMALLOC -I../deps/jemalloc/include
43 CCLINK+= $(ALLOC_LINK)
44 CFLAGS+= $(ALLOC_FLAGS)
46 CCOPT= $(CFLAGS) $(ARCH) $(PROF)
49 INSTALL_BIN= $(PREFIX)/bin
53 LINKCOLOR="\033[34;1m"
56 MAKECOLOR="\033[32;1m"
60 QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR);
61 QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR);
64 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 dscache.o pubsub.o multi.o debug.o sort.o intset.o syncio.o diskstore.o cluster.o crc16.o endian.o
65 BENCHOBJ = ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o
66 CLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o
67 CHECKDUMPOBJ = redis-check-dump.o lzf_c.o lzf_d.o
68 CHECKAOFOBJ = redis-check-aof.o
70 PRGNAME = redis-server
71 BENCHPRGNAME = redis-benchmark
72 CLIPRGNAME = redis-cli
73 CHECKDUMPPRGNAME = redis-check-dump
74 CHECKAOFPRGNAME = redis-check-aof
76 all: redis-benchmark redis-cli redis-check-dump redis-check-aof redis-server
78 @echo "Hint: To run 'make test' is a good idea ;)"
81 # Deps (use make dep to generate this)
82 adlist.o: adlist.c adlist.h zmalloc.h
83 ae.o: ae.c ae.h zmalloc.h config.h ae_kqueue.c
84 ae_epoll.o: ae_epoll.c
85 ae_kqueue.o: ae_kqueue.c
86 ae_select.o: ae_select.c
87 anet.o: anet.c fmacros.h anet.h
88 aof.o: aof.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
90 config.o: config.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
91 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h
92 db.o: db.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
93 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h
94 debug.o: debug.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
95 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h sha1.h
96 dict.o: dict.c fmacros.h dict.h zmalloc.h
97 diskstore.o: diskstore.c redis.h fmacros.h config.h ae.h sds.h dict.h \
98 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h
99 dscache.o: dscache.c redis.h fmacros.h config.h ae.h sds.h dict.h \
100 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h
101 intset.o: intset.c intset.h zmalloc.h
102 lzf_c.o: lzf_c.c lzfP.h
103 lzf_d.o: lzf_d.c lzfP.h
104 multi.o: multi.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
106 networking.o: networking.c redis.h fmacros.h config.h ae.h sds.h dict.h \
107 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h
108 object.o: object.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
111 pubsub.o: pubsub.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
112 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h
113 rdb.o: rdb.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
114 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h lzf.h
115 redis-benchmark.o: redis-benchmark.c fmacros.h ae.h \
116 ../deps/hiredis/hiredis.h sds.h adlist.h zmalloc.h
117 redis-check-aof.o: redis-check-aof.c fmacros.h config.h
118 redis-check-dump.o: redis-check-dump.c lzf.h
119 redis-cli.o: redis-cli.c fmacros.h version.h ../deps/hiredis/hiredis.h \
120 sds.h zmalloc.h ../deps/linenoise/linenoise.h help.h
121 redis.o: redis.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 asciilogo.h
123 release.o: release.c release.h
124 replication.o: replication.c redis.h fmacros.h config.h ae.h sds.h dict.h \
125 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h
126 sds.o: sds.c sds.h zmalloc.h
127 sha1.o: sha1.c sha1.h
128 sort.o: sort.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
129 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h pqsort.h
130 syncio.o: syncio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
131 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h
132 t_hash.o: t_hash.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
133 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h
134 t_list.o: t_list.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
136 t_set.o: t_set.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
137 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h
138 t_string.o: t_string.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
140 t_zset.o: t_zset.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
141 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h
142 util.o: util.c util.h
143 cluster.o: redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
144 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h
145 ziplist.o: ziplist.c zmalloc.h ziplist.h
146 zipmap.o: zipmap.c zmalloc.h
147 zmalloc.o: zmalloc.c config.h
152 @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)hiredis$(ENDCOLOR)
153 @cd ../deps/hiredis && $(MAKE) static ARCH="$(ARCH)"
154 @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)linenoise$(ENDCOLOR)
155 @cd ../deps/linenoise && $(MAKE) ARCH="$(ARCH)"
157 ../deps/jemalloc/lib/libjemalloc.a:
158 cd ../deps/jemalloc && ./configure --with-jemalloc-prefix=je_ --enable-cc-silence && $(MAKE) lib/libjemalloc.a
161 $(QUIET_CC)$(CC) -o $(PRGNAME) $(CCOPT) $(DEBUG) $(OBJ) $(CCLINK) $(ALLOC_LINK)
163 redis-benchmark: dependencies $(BENCHOBJ)
164 @cd ../deps/hiredis && $(MAKE) static
165 $(QUIET_LINK)$(CC) -o $(BENCHPRGNAME) $(CCOPT) $(DEBUG) $(BENCHOBJ) ../deps/hiredis/libhiredis.a $(CCLINK) $(ALLOC_LINK)
168 $(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis $(DEBUG) $(COMPILE_TIME) $<
170 redis-cli: dependencies $(CLIOBJ)
171 $(QUIET_LINK)$(CC) -o $(CLIPRGNAME) $(CCOPT) $(DEBUG) $(CLIOBJ) ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(CCLINK) $(ALLOC_LINK)
174 $(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis -I../deps/linenoise $(DEBUG) $(COMPILE_TIME) $<
176 redis-check-dump: $(CHECKDUMPOBJ)
177 $(QUIET_LINK)$(CC) -o $(CHECKDUMPPRGNAME) $(CCOPT) $(DEBUG) $(CHECKDUMPOBJ) $(CCLINK) $(ALLOC_LINK)
179 redis-check-aof: $(CHECKAOFOBJ)
180 $(QUIET_LINK)$(CC) -o $(CHECKAOFPRGNAME) $(CCOPT) $(DEBUG) $(CHECKAOFOBJ) $(CCLINK) $(ALLOC_LINK)
182 # Because the jemalloc.h header is generated as a part of the jemalloc build
183 # process, building it should complete before building any other object.
184 %.o: %.c $(ALLOC_DEP)
185 $(QUIET_CC)$(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) $<
188 rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) $(CHECKDUMPPRGNAME) $(CHECKAOFPRGNAME) *.o *.gcda *.gcno *.gcov
191 $(CC) -MM *.c -I ../deps/hiredis -I ../deps/linenoise
194 (cd ..; tclsh8.5 tests/test_helper.tcl --tags "${TAGS}" --file "${FILE}")
200 git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog
204 @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
212 $(MAKE) PROF="-fprofile-arcs -ftest-coverage"
215 $(MAKE) OPTIMIZATION=""
218 $(MAKE) PROF="-pg" ARCH="-arch i386"
221 mkdir -p $(INSTALL_BIN)
222 $(INSTALL) $(PRGNAME) $(INSTALL_BIN)
223 $(INSTALL) $(BENCHPRGNAME) $(INSTALL_BIN)
224 $(INSTALL) $(CLIPRGNAME) $(INSTALL_BIN)
225 $(INSTALL) $(CHECKDUMPPRGNAME) $(INSTALL_BIN)
226 $(INSTALL) $(CHECKAOFPRGNAME) $(INSTALL_BIN)