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