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