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 # 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').
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.
15 release_hdr := $(shell sh -c './mkreleasehdr.sh')
16 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
18 DEPENDENCY_TARGETS=hiredis linenoise lua
21 STD= -std=c99 -pedantic
26 ifeq ($(uname_S),Linux)
32 # Backwards compatibility for selecting an allocator
33 ifeq ($(USE_TCMALLOC),yes)
37 ifeq ($(USE_TCMALLOC_MINIMAL),yes)
38 MALLOC=tcmalloc_minimal
41 ifeq ($(USE_JEMALLOC),yes)
45 ifeq ($(uname_S),SunOS)
46 FINAL_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS) -D__EXTENSIONS__ -D_XPG6
47 FINAL_LDFLAGS= $(LDFLAGS) $(REDIS_LDFLAGS)
48 FINAL_LIBS= $(LIBS) -ldl -lnsl -lsocket -lm -lpthread
51 FINAL_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS)
52 FINAL_LDFLAGS= $(LDFLAGS) $(REDIS_LDFLAGS)
53 FINAL_LIBS= $(LIBS) -lm -pthread
54 DEBUG= -g -rdynamic -ggdb
57 # Include paths to dependencies
58 FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src
60 ifeq ($(MALLOC),tcmalloc)
61 FINAL_CFLAGS+= -DUSE_TCMALLOC
62 FINAL_LIBS+= -ltcmalloc
65 ifeq ($(MALLOC),tcmalloc_minimal)
66 FINAL_CFLAGS+= -DUSE_TCMALLOC
67 FINAL_LIBS+= -ltcmalloc_minimal
70 ifeq ($(MALLOC),jemalloc)
71 DEPENDENCY_TARGETS+= jemalloc
72 FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
73 FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl
76 REDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS)
77 REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS)
80 INSTALL_BIN= $(PREFIX)/bin
84 LINKCOLOR="\033[34;1m"
87 MAKECOLOR="\033[32;1m"
91 QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2;
92 QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
95 REDIS_SERVER_NAME= redis-server
96 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 cluster.o crc16.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o
97 REDIS_CLI_NAME= redis-cli
98 REDIS_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o
99 REDIS_BENCHMARK_NAME= redis-benchmark
100 REDIS_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o
101 REDIS_CHECK_DUMP_NAME= redis-check-dump
102 REDIS_CHECK_DUMP_OBJ= redis-check-dump.o lzf_c.o lzf_d.o
103 REDIS_CHECK_AOF_NAME= redis-check-aof
104 REDIS_CHECK_AOF_OBJ= redis-check-aof.o
106 all: $(REDIS_SERVER_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME)
108 @echo "Hint: To run 'make test' is a good idea ;)"
113 # Deps (use make dep to generate this)
117 $(REDIS_CC) -MM *.c > Makefile.dep
121 # Prerequisites target
125 # Clean local objects and build dependencies when FINAL_CFLAGS is different
126 ifneq ($(shell sh -c '[ -f .make-cflags ] && cat .make-cflags || echo none'), $(FINAL_CFLAGS))
128 -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS))
129 -(echo "$(FINAL_CFLAGS)" > .make-cflags)
130 .make-prerequisites: .make-cflags
133 # Clean local objects when FINAL_LDFLAGS is different
134 ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'), $(FINAL_LDFLAGS))
136 -(echo "$(FINAL_LDFLAGS)" > .make-ldflags)
137 .make-prerequisites: .make-ldflags
140 # Clean local objects when MALLOC is different
141 ifneq ($(shell sh -c '[ -f .make-malloc ] && cat .make-malloc || echo none'), $(MALLOC))
143 -(echo "$(MALLOC)" > .make-malloc)
144 .make-prerequisites: .make-malloc
148 $(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ)
149 $(REDIS_LD) -o $@ $^ ../deps/lua/src/liblua.a $(FINAL_LIBS)
152 $(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
153 $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS)
156 $(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
157 $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS)
160 $(REDIS_CHECK_DUMP_NAME): $(REDIS_CHECK_DUMP_OBJ)
161 $(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
164 $(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ)
165 $(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
167 # Because the jemalloc.h header is generated as a part of the jemalloc build,
168 # building it should complete before building any other object. Instead of
169 # depending on a single artifact, build all dependencies first.
170 %.o: %.c .make-prerequisites
174 rm -rf $(REDIS_SERVER_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html
179 -(cd ../deps && $(MAKE) distclean)
184 test: $(REDIS_SERVER_NAME) $(REDIS_CHECK_AOF_NAME)
189 @(set -e; cd ..; ./runtest --clients 1)
190 @geninfo -o redis.info .
191 @genhtml --legend -o lcov-html redis.info
195 bench: $(REDIS_BENCHMARK_NAME)
196 ./$(REDIS_BENCHMARK_NAME)
200 @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
202 $(MAKE) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32"
205 $(MAKE) REDIS_CFLAGS="-fprofile-arcs -ftest-coverage -DCOVERAGE_TEST" REDIS_LDFLAGS="-fprofile-arcs -ftest-coverage"
211 @../utils/generate-command-help.rb > help.h
214 mkdir -p $(INSTALL_BIN)
215 $(INSTALL) $(REDIS_SERVER_NAME) $(INSTALL_BIN)
216 $(INSTALL) $(REDIS_BENCHMARK_NAME) $(INSTALL_BIN)
217 $(INSTALL) $(REDIS_CLI_NAME) $(INSTALL_BIN)
218 $(INSTALL) $(REDIS_CHECK_DUMP_NAME) $(INSTALL_BIN)
219 $(INSTALL) $(REDIS_CHECK_AOF_NAME) $(INSTALL_BIN)