]> git.saurik.com Git - redis.git/blame_incremental - src/Makefile
Archive (do not delete) keys due to memory limits.
[redis.git] / src / Makefile
... / ...
CommitLineData
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#
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').
11#
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.
14
15release_hdr := $(shell sh -c './mkreleasehdr.sh')
16uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
17OPTIMIZATION?=-O2
18DEPENDENCY_TARGETS=hiredis liblmdb linenoise lua
19
20# Default settings
21STD= -std=c99 -pedantic
22WARN= -Wall
23OPT= $(OPTIMIZATION)
24
25# Default allocator
26ifeq ($(uname_S),Linux)
27 MALLOC=jemalloc
28else
29 MALLOC=libc
30endif
31
32# Backwards compatibility for selecting an allocator
33ifeq ($(USE_TCMALLOC),yes)
34 MALLOC=tcmalloc
35endif
36
37ifeq ($(USE_TCMALLOC_MINIMAL),yes)
38 MALLOC=tcmalloc_minimal
39endif
40
41ifeq ($(USE_JEMALLOC),yes)
42 MALLOC=jemalloc
43endif
44
45# Override default settings if possible
46-include .make-settings
47
48ifeq ($(uname_S),SunOS)
49 FINAL_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS) -D__EXTENSIONS__ -D_XPG6
50 FINAL_LDFLAGS= $(LDFLAGS) $(REDIS_LDFLAGS) -g -ggdb
51 FINAL_LIBS= -ldl -lnsl -lsocket -lm -lpthread
52 DEBUG= -g -ggdb
53else
54 FINAL_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS)
55 FINAL_LDFLAGS= $(LDFLAGS) $(REDIS_LDFLAGS) -g -rdynamic -ggdb
56 FINAL_LIBS= -lm -pthread
57 DEBUG= -g -rdynamic -ggdb
58endif
59
60# Include paths to dependencies
61FINAL_CFLAGS+= -I../deps/hiredis -I../deps/liblmdb -I../deps/linenoise -I../deps/lua/src
62
63ifeq ($(MALLOC),tcmalloc)
64 FINAL_CFLAGS+= -DUSE_TCMALLOC
65 FINAL_LIBS+= -ltcmalloc
66endif
67
68ifeq ($(MALLOC),tcmalloc_minimal)
69 FINAL_CFLAGS+= -DUSE_TCMALLOC
70 FINAL_LIBS+= -ltcmalloc_minimal
71endif
72
73ifeq ($(MALLOC),jemalloc)
74 DEPENDENCY_TARGETS+= jemalloc
75 FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
76 FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl
77endif
78
79FINAL_LIBS+= ../deps/liblmdb/liblmdb.a
80
81REDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS)
82REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS)
83REDIS_INSTALL=$(QUIET_INSTALL)$(INSTALL)
84
85PREFIX?=/usr/local
86INSTALL_BIN= $(PREFIX)/bin
87INSTALL= cp -pf
88
89CCCOLOR="\033[34m"
90LINKCOLOR="\033[34;1m"
91SRCCOLOR="\033[33m"
92BINCOLOR="\033[37;1m"
93MAKECOLOR="\033[32;1m"
94ENDCOLOR="\033[0m"
95
96ifndef V
97QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2;
98QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
99QUIET_INSTALL = @printf ' %b %b\n' $(LINKCOLOR)INSTALL$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
100endif
101
102REDIS_SERVER_NAME= redis-server
103REDIS_SENTINEL_NAME= redis-sentinel
104REDIS_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 endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o bitops.o sentinel.o
105REDIS_CLI_NAME= redis-cli
106REDIS_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o
107REDIS_BENCHMARK_NAME= redis-benchmark
108REDIS_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o
109REDIS_CHECK_DUMP_NAME= redis-check-dump
110REDIS_CHECK_DUMP_OBJ= redis-check-dump.o lzf_c.o lzf_d.o crc64.o
111REDIS_CHECK_AOF_NAME= redis-check-aof
112REDIS_CHECK_AOF_OBJ= redis-check-aof.o
113
114all: $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME)
115 @echo ""
116 @echo "Hint: To run 'make test' is a good idea ;)"
117 @echo ""
118
119.PHONY: all
120
121# Deps (use make dep to generate this)
122include Makefile.dep
123
124dep:
125 $(REDIS_CC) -MM *.c > Makefile.dep
126
127.PHONY: dep
128
129persist-settings: distclean
130 echo STD=$(STD) >> .make-settings
131 echo WARN=$(WARN) >> .make-settings
132 echo OPT=$(OPT) >> .make-settings
133 echo MALLOC=$(MALLOC) >> .make-settings
134 echo CFLAGS=$(CFLAGS) >> .make-settings
135 echo LDFLAGS=$(LDFLAGS) >> .make-settings
136 echo REDIS_CFLAGS=$(REDIS_CFLAGS) >> .make-settings
137 echo REDIS_LDFLAGS=$(REDIS_LDFLAGS) >> .make-settings
138 echo PREV_FINAL_CFLAGS=$(FINAL_CFLAGS) >> .make-settings
139 echo PREV_FINAL_LDFLAGS=$(FINAL_LDFLAGS) >> .make-settings
140 -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS))
141
142.PHONY: persist-settings
143
144# Prerequisites target
145.make-prerequisites:
146 @touch $@
147
148# Clean everything, persist settings and build dependencies if anything changed
149ifneq ($(strip $(PREV_FINAL_CFLAGS)), $(strip $(FINAL_CFLAGS)))
150.make-prerequisites: persist-settings
151endif
152
153ifneq ($(strip $(PREV_FINAL_LDFLAGS)), $(strip $(FINAL_LDFLAGS)))
154.make-prerequisites: persist-settings
155endif
156
157# redis-server
158$(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ)
159 $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a $(FINAL_LIBS)
160
161# redis-sentinel
162$(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME)
163 $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME)
164
165# redis-cli
166$(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
167 $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS)
168
169# redis-benchmark
170$(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
171 $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS)
172
173# redis-check-dump
174$(REDIS_CHECK_DUMP_NAME): $(REDIS_CHECK_DUMP_OBJ)
175 $(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
176
177# redis-check-aof
178$(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ)
179 $(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
180
181# Because the jemalloc.h header is generated as a part of the jemalloc build,
182# building it should complete before building any other object. Instead of
183# depending on a single artifact, build all dependencies first.
184%.o: %.c .make-prerequisites
185 $(REDIS_CC) -c $<
186
187clean:
188 rm -rf $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html
189
190.PHONY: clean
191
192distclean: clean
193 -(cd ../deps && $(MAKE) distclean)
194 -(rm -f .make-*)
195
196.PHONY: distclean
197
198test: $(REDIS_SERVER_NAME) $(REDIS_CHECK_AOF_NAME)
199 @(cd ..; ./runtest)
200
201lcov:
202 $(MAKE) gcov
203 @(set -e; cd ..; ./runtest --clients 1)
204 @geninfo -o redis.info .
205 @genhtml --legend -o lcov-html redis.info
206
207.PHONY: lcov
208
209bench: $(REDIS_BENCHMARK_NAME)
210 ./$(REDIS_BENCHMARK_NAME)
211
21232bit:
213 @echo ""
214 @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
215 @echo ""
216 $(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
217
218gcov:
219 $(MAKE) REDIS_CFLAGS="-fprofile-arcs -ftest-coverage -DCOVERAGE_TEST" REDIS_LDFLAGS="-fprofile-arcs -ftest-coverage"
220
221noopt:
222 $(MAKE) OPT="-O0"
223
224src/help.h:
225 @../utils/generate-command-help.rb > help.h
226
227install: all
228 mkdir -p $(INSTALL_BIN)
229 $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(INSTALL_BIN)
230 $(REDIS_INSTALL) $(REDIS_BENCHMARK_NAME) $(INSTALL_BIN)
231 $(REDIS_INSTALL) $(REDIS_CLI_NAME) $(INSTALL_BIN)
232 $(REDIS_INSTALL) $(REDIS_CHECK_DUMP_NAME) $(INSTALL_BIN)
233 $(REDIS_INSTALL) $(REDIS_CHECK_AOF_NAME) $(INSTALL_BIN)