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')
8 DEPENDENCY_TARGETS=hiredis linenoise lua
10 STD= -std=c99 -pedantic
14 ifeq ($(uname_S),SunOS)
15 R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) -D__EXTENSIONS__ -D_XPG6
17 R_LIBS= $(LIBS) -ldl -lnsl -lsocket -lm -lpthread
20 R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS)
22 R_LIBS= $(LIBS) -lm -pthread
23 DEBUG= -g -rdynamic -ggdb
26 # Include paths to dependencies
27 R_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src
30 ifeq ($(uname_S),Linux)
36 # Backwards compatibility for selecting an allocator
37 ifeq ($(USE_TCMALLOC),yes)
41 ifeq ($(USE_TCMALLOC_MINIMAL),yes)
42 MALLOC=tcmalloc_minimal
45 ifeq ($(USE_JEMALLOC),yes)
49 ifeq ($(MALLOC),tcmalloc)
50 R_CFLAGS+= -DUSE_TCMALLOC
54 ifeq ($(MALLOC),tcmalloc_minimal)
55 R_CFLAGS+= -DUSE_TCMALLOC
56 R_LIBS+= -ltcmalloc_minimal
59 ifeq ($(MALLOC),jemalloc)
60 DEPENDENCY_TARGETS+= jemalloc
61 R_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
62 R_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl
65 R_CC=$(QUIET_CC)$(CC) $(R_CFLAGS)
66 R_LD=$(QUIET_LINK)$(CC) $(R_LDFLAGS)
69 INSTALL_BIN= $(PREFIX)/bin
73 LINKCOLOR="\033[34;1m"
76 MAKECOLOR="\033[32;1m"
80 QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2;
81 QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
84 R_SERVER_NAME= redis-server
85 R_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 migrate.o crc16.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o
87 R_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o
88 R_BENCHMARK_NAME= redis-benchmark
89 R_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o
90 R_CHECK_DUMP_NAME= redis-check-dump
91 R_CHECK_DUMP_OBJ= redis-check-dump.o lzf_c.o lzf_d.o
92 R_CHECK_AOF_NAME= redis-check-aof
93 R_CHECK_AOF_OBJ= redis-check-aof.o
95 all: $(R_SERVER_NAME) $(R_CLI_NAME) $(R_BENCHMARK_NAME) $(R_CHECK_DUMP_NAME) $(R_CHECK_AOF_NAME)
97 @echo "Hint: To run 'make test' is a good idea ;)"
102 # Deps (use make dep to generate this)
110 # Prerequisites target
114 # Clean local objects and build dependencies when R_CFLAGS is different
115 ifneq ($(shell sh -c '[ -f .make-cflags ] && cat .make-cflags || echo none'), $(R_CFLAGS))
117 -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS))
118 -(echo "$(R_CFLAGS)" > .make-cflags)
119 .make-prerequisites: .make-cflags
122 # Clean local objects when R_LDFLAGS is different
123 ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'), $(R_LDFLAGS))
125 -(echo "$(R_LDFLAGS)" > .make-ldflags)
126 .make-prerequisites: .make-ldflags
129 # Clean local objects when MALLOC is different
130 ifneq ($(shell sh -c '[ -f .make-malloc ] && cat .make-malloc || echo none'), $(MALLOC))
132 -(echo "$(MALLOC)" > .make-malloc)
133 .make-prerequisites: .make-malloc
137 $(R_SERVER_NAME): $(R_SERVER_OBJ)
138 $(R_LD) -o $@ $^ ../deps/lua/src/liblua.a $(R_LIBS)
141 $(R_CLI_NAME): $(R_CLI_OBJ)
142 $(R_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(R_LIBS)
145 $(R_BENCHMARK_NAME): $(R_BENCHMARK_OBJ)
146 $(R_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(R_LIBS)
149 $(R_CHECK_DUMP_NAME): $(R_CHECK_DUMP_OBJ)
150 $(R_LD) -o $@ $^ $(R_LIBS)
153 $(R_CHECK_AOF_NAME): $(R_CHECK_AOF_OBJ)
154 $(R_LD) -o $@ $^ $(R_LIBS)
156 # Because the jemalloc.h header is generated as a part of the jemalloc build,
157 # building it should complete before building any other object. Instead of
158 # depending on a single artifact, build all dependencies first.
159 %.o: %.c .make-prerequisites
163 rm -rf $(R_SERVER_NAME) $(R_CLI_NAME) $(R_BENCHMARK_NAME) $(R_CHECK_DUMP_NAME) $(R_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html
168 -(cd ../deps && $(MAKE) distclean)
173 test: $(R_SERVER_NAME) $(R_CHECK_AOF_NAME)
178 @(set -e; cd ..; ./runtest --clients 1)
179 @geninfo -o redis.info .
180 @genhtml --legend -o lcov-html redis.info
184 bench: $(R_BENCHMARK_NAME)
185 ./$(R_BENCHMARK_NAME)
188 git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog
192 @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
194 $(MAKE) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32"
197 $(MAKE) CFLAGS="$(CFLAGS) -pg" LDFLAGS="$(LDFLAGS) -pg"
200 $(MAKE) CFLAGS="$(CFLAGS) -fprofile-arcs -ftest-coverage -DCOVERAGE_TEST"
206 $(MAKE) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32" gprof
209 @../utils/generate-command-help.rb > help.h
212 mkdir -p $(INSTALL_BIN)
213 $(INSTALL) $(R_SERVER_NAME) $(INSTALL_BIN)
214 $(INSTALL) $(R_BENCHMARK_NAME) $(INSTALL_BIN)
215 $(INSTALL) $(R_CLI_NAME) $(INSTALL_BIN)
216 $(INSTALL) $(R_CHECK_DUMP_NAME) $(INSTALL_BIN)
217 $(INSTALL) $(R_CHECK_AOF_NAME) $(INSTALL_BIN)