]>
Commit | Line | Data |
---|---|---|
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 | |
69ac4d06 | 4 | # |
6cedb4d4 | 5 | # The Makefile composes the final FINAL_CFLAGS and FINAL_LDFLAGS using |
69ac4d06 | 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 | |
6cedb4d4 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'). | |
69ac4d06 | 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 | 15 | release_hdr := $(shell sh -c './mkreleasehdr.sh') |
325d1eb4 | 16 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') |
25fd2cb2 | 17 | OPTIMIZATION?=-O2 |
9035e23d | 18 | DEPENDENCY_TARGETS=hiredis liblmdb linenoise lua |
b83e9583 | 19 | |
61e8825e | 20 | # Default settings |
de07849e PN |
21 | STD= -std=c99 -pedantic |
22 | WARN= -Wall | |
23 | OPT= $(OPTIMIZATION) | |
24 | ||
5bb2c88e PN |
25 | # Default allocator |
26 | ifeq ($(uname_S),Linux) | |
95bc1951 | 27 | MALLOC=jemalloc |
5bb2c88e | 28 | else |
95bc1951 | 29 | MALLOC=libc |
5bb2c88e PN |
30 | endif |
31 | ||
32 | # Backwards compatibility for selecting an allocator | |
0a802bd7 | 33 | ifeq ($(USE_TCMALLOC),yes) |
5bb2c88e PN |
34 | MALLOC=tcmalloc |
35 | endif | |
36 | ||
37 | ifeq ($(USE_TCMALLOC_MINIMAL),yes) | |
38 | MALLOC=tcmalloc_minimal | |
39 | endif | |
40 | ||
41 | ifeq ($(USE_JEMALLOC),yes) | |
42 | MALLOC=jemalloc | |
43 | endif | |
44 | ||
d0cd262f PN |
45 | # Override default settings if possible |
46 | -include .make-settings | |
47 | ||
61e8825e PN |
48 | ifeq ($(uname_S),SunOS) |
49 | FINAL_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS) -D__EXTENSIONS__ -D_XPG6 | |
e69e76d4 | 50 | FINAL_LDFLAGS= $(LDFLAGS) $(REDIS_LDFLAGS) -g -ggdb |
3126e087 | 51 | FINAL_LIBS= -ldl -lnsl -lsocket -lm -lpthread |
61e8825e PN |
52 | DEBUG= -g -ggdb |
53 | else | |
54 | FINAL_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS) | |
e69e76d4 | 55 | FINAL_LDFLAGS= $(LDFLAGS) $(REDIS_LDFLAGS) -g -rdynamic -ggdb |
3126e087 | 56 | FINAL_LIBS= -lm -pthread |
61e8825e PN |
57 | DEBUG= -g -rdynamic -ggdb |
58 | endif | |
59 | ||
60 | # Include paths to dependencies | |
8e2a225a | 61 | FINAL_CFLAGS+= -I../deps/hiredis -I../deps/liblmdb -I../deps/linenoise -I../deps/lua/src |
61e8825e | 62 | |
5bb2c88e | 63 | ifeq ($(MALLOC),tcmalloc) |
6cedb4d4 PN |
64 | FINAL_CFLAGS+= -DUSE_TCMALLOC |
65 | FINAL_LIBS+= -ltcmalloc | |
0a802bd7 | 66 | endif |
52825621 | 67 | |
5bb2c88e | 68 | ifeq ($(MALLOC),tcmalloc_minimal) |
6cedb4d4 PN |
69 | FINAL_CFLAGS+= -DUSE_TCMALLOC |
70 | FINAL_LIBS+= -ltcmalloc_minimal | |
52825621 PN |
71 | endif |
72 | ||
5bb2c88e | 73 | ifeq ($(MALLOC),jemalloc) |
4b8a6394 | 74 | DEPENDENCY_TARGETS+= jemalloc |
6cedb4d4 PN |
75 | FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include |
76 | FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl | |
52825621 PN |
77 | endif |
78 | ||
8e2a225a JF |
79 | FINAL_LIBS+= ../deps/liblmdb/liblmdb.a |
80 | ||
6cedb4d4 PN |
81 | REDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS) |
82 | REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS) | |
120ba392 | 83 | REDIS_INSTALL=$(QUIET_INSTALL)$(INSTALL) |
ed9b544e | 84 | |
91d18504 | 85 | PREFIX?=/usr/local |
0997b411 | 86 | INSTALL_BIN= $(PREFIX)/bin |
120a36f2 | 87 | INSTALL= cp -pf |
acc01854 | 88 | |
35845afb | 89 | CCCOLOR="\033[34m" |
90 | LINKCOLOR="\033[34;1m" | |
91 | SRCCOLOR="\033[33m" | |
92 | BINCOLOR="\033[37;1m" | |
93 | MAKECOLOR="\033[32;1m" | |
94 | ENDCOLOR="\033[0m" | |
95 | ||
73e71867 | 96 | ifndef V |
de07849e PN |
97 | QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2; |
98 | QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2; | |
120ba392 | 99 | QUIET_INSTALL = @printf ' %b %b\n' $(LINKCOLOR)INSTALL$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2; |
73e71867 | 100 | endif |
101 | ||
236adc28 | 102 | REDIS_SERVER_NAME= redis-server |
120ba392 | 103 | REDIS_SENTINEL_NAME= redis-sentinel |
104 | 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 migrate.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o bitops.o sentinel.o | |
69ac4d06 | 105 | REDIS_CLI_NAME= redis-cli |
dd4e8203 | 106 | REDIS_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o |
69ac4d06 | 107 | REDIS_BENCHMARK_NAME= redis-benchmark |
108 | REDIS_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o | |
109 | REDIS_CHECK_DUMP_NAME= redis-check-dump | |
12a042f8 | 110 | REDIS_CHECK_DUMP_OBJ= redis-check-dump.o lzf_c.o lzf_d.o crc64.o |
69ac4d06 | 111 | REDIS_CHECK_AOF_NAME= redis-check-aof |
112 | REDIS_CHECK_AOF_OBJ= redis-check-aof.o | |
113 | ||
120ba392 | 114 | all: $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME) |
c8061392 PN |
115 | @echo "" |
116 | @echo "Hint: To run 'make test' is a good idea ;)" | |
117 | @echo "" | |
ed9b544e | 118 | |
de07849e | 119 | .PHONY: all |
c8061392 | 120 | |
de07849e PN |
121 | # Deps (use make dep to generate this) |
122 | include Makefile.dep | |
9e62dc17 | 123 | |
de07849e | 124 | dep: |
69ac4d06 | 125 | $(REDIS_CC) -MM *.c > Makefile.dep |
5bb2c88e | 126 | |
de07849e | 127 | .PHONY: dep |
5bb2c88e | 128 | |
d0cd262f PN |
129 | persist-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 | ||
de07849e PN |
144 | # Prerequisites target |
145 | .make-prerequisites: | |
42c6a5da | 146 | @touch $@ |
5bb2c88e | 147 | |
d0cd262f PN |
148 | # Clean everything, persist settings and build dependencies if anything changed |
149 | ifneq ($(strip $(PREV_FINAL_CFLAGS)), $(strip $(FINAL_CFLAGS))) | |
150 | .make-prerequisites: persist-settings | |
de07849e PN |
151 | endif |
152 | ||
d0cd262f PN |
153 | ifneq ($(strip $(PREV_FINAL_LDFLAGS)), $(strip $(FINAL_LDFLAGS))) |
154 | .make-prerequisites: persist-settings | |
de07849e | 155 | endif |
ec8f0667 | 156 | |
de07849e | 157 | # redis-server |
236adc28 | 158 | $(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ) |
120ba392 | 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) | |
ed9b544e | 164 | |
de07849e | 165 | # redis-cli |
69ac4d06 | 166 | $(REDIS_CLI_NAME): $(REDIS_CLI_OBJ) |
6cedb4d4 | 167 | $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS) |
7fc4ce13 | 168 | |
de07849e | 169 | # redis-benchmark |
69ac4d06 | 170 | $(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ) |
6cedb4d4 | 171 | $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS) |
ed9b544e | 172 | |
de07849e | 173 | # redis-check-dump |
69ac4d06 | 174 | $(REDIS_CHECK_DUMP_NAME): $(REDIS_CHECK_DUMP_OBJ) |
6cedb4d4 | 175 | $(REDIS_LD) -o $@ $^ $(FINAL_LIBS) |
08af4d5c | 176 | |
de07849e | 177 | # redis-check-aof |
69ac4d06 | 178 | $(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ) |
6cedb4d4 | 179 | $(REDIS_LD) -o $@ $^ $(FINAL_LIBS) |
b4bd0524 | 180 | |
de07849e PN |
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. | |
42c6a5da | 184 | %.o: %.c .make-prerequisites |
69ac4d06 | 185 | $(REDIS_CC) -c $< |
4b8a6394 | 186 | |
ed9b544e | 187 | clean: |
120ba392 | 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 |
de07849e PN |
189 | |
190 | .PHONY: clean | |
4b8a6394 PN |
191 | |
192 | distclean: clean | |
193 | -(cd ../deps && $(MAKE) distclean) | |
de07849e | 194 | -(rm -f .make-*) |
ed9b544e | 195 | |
de07849e | 196 | .PHONY: distclean |
ed9b544e | 197 | |
236adc28 | 198 | test: $(REDIS_SERVER_NAME) $(REDIS_CHECK_AOF_NAME) |
f790bd02 | 199 | @(cd ..; ./runtest) |
ed9b544e | 200 | |
9f899440 | 201 | lcov: |
0b27a55f | 202 | $(MAKE) gcov |
9f899440 PH |
203 | @(set -e; cd ..; ./runtest --clients 1) |
204 | @geninfo -o redis.info . | |
205 | @genhtml --legend -o lcov-html redis.info | |
206 | ||
de07849e PN |
207 | .PHONY: lcov |
208 | ||
69ac4d06 | 209 | bench: $(REDIS_BENCHMARK_NAME) |
210 | ./$(REDIS_BENCHMARK_NAME) | |
fd8ccf44 | 211 | |
212 | 32bit: | |
9ebed7cf | 213 | @echo "" |
214 | @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386" | |
215 | @echo "" | |
86422958 | 216 | $(MAKE) CFLAGS="-m32" LDFLAGS="-m32" |
d0ccebcf | 217 | |
fc77604c | 218 | gcov: |
6cedb4d4 | 219 | $(MAKE) REDIS_CFLAGS="-fprofile-arcs -ftest-coverage -DCOVERAGE_TEST" REDIS_LDFLAGS="-fprofile-arcs -ftest-coverage" |
fc77604c | 220 | |
25fd2cb2 | 221 | noopt: |
de07849e | 222 | $(MAKE) OPT="-O0" |
25fd2cb2 | 223 | |
319bb48c | 224 | src/help.h: |
225 | @../utils/generate-command-help.rb > help.h | |
226 | ||
acc01854 | 227 | install: all |
0bb5160c | 228 | mkdir -p $(INSTALL_BIN) |
120ba392 | 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) |