]>
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 |
4b8a6394 | 18 | DEPENDENCY_TARGETS=hiredis 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 | ||
61e8825e PN |
45 | ifeq ($(uname_S),SunOS) |
46 | FINAL_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS) -D__EXTENSIONS__ -D_XPG6 | |
47 | FINAL_LDFLAGS= $(LDFLAGS) $(REDIS_LDFLAGS) | |
3126e087 | 48 | FINAL_LIBS= -ldl -lnsl -lsocket -lm -lpthread |
61e8825e PN |
49 | DEBUG= -g -ggdb |
50 | else | |
51 | FINAL_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS) | |
52 | FINAL_LDFLAGS= $(LDFLAGS) $(REDIS_LDFLAGS) | |
3126e087 | 53 | FINAL_LIBS= -lm -pthread |
61e8825e PN |
54 | DEBUG= -g -rdynamic -ggdb |
55 | endif | |
56 | ||
57 | # Include paths to dependencies | |
58 | FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src | |
59 | ||
5bb2c88e | 60 | ifeq ($(MALLOC),tcmalloc) |
6cedb4d4 PN |
61 | FINAL_CFLAGS+= -DUSE_TCMALLOC |
62 | FINAL_LIBS+= -ltcmalloc | |
0a802bd7 | 63 | endif |
52825621 | 64 | |
5bb2c88e | 65 | ifeq ($(MALLOC),tcmalloc_minimal) |
6cedb4d4 PN |
66 | FINAL_CFLAGS+= -DUSE_TCMALLOC |
67 | FINAL_LIBS+= -ltcmalloc_minimal | |
52825621 PN |
68 | endif |
69 | ||
5bb2c88e | 70 | ifeq ($(MALLOC),jemalloc) |
4b8a6394 | 71 | DEPENDENCY_TARGETS+= jemalloc |
6cedb4d4 PN |
72 | FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include |
73 | FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl | |
52825621 PN |
74 | endif |
75 | ||
6cedb4d4 PN |
76 | REDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS) |
77 | REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS) | |
ed9b544e | 78 | |
e1386503 | 79 | PREFIX= /usr/local |
0997b411 | 80 | INSTALL_BIN= $(PREFIX)/bin |
120a36f2 | 81 | INSTALL= cp -pf |
acc01854 | 82 | |
35845afb | 83 | CCCOLOR="\033[34m" |
84 | LINKCOLOR="\033[34;1m" | |
85 | SRCCOLOR="\033[33m" | |
86 | BINCOLOR="\033[37;1m" | |
87 | MAKECOLOR="\033[32;1m" | |
88 | ENDCOLOR="\033[0m" | |
89 | ||
73e71867 | 90 | ifndef V |
de07849e PN |
91 | QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2; |
92 | QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2; | |
73e71867 | 93 | endif |
94 | ||
236adc28 | 95 | REDIS_SERVER_NAME= redis-server |
96 | 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 crc16.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o | |
69ac4d06 | 97 | REDIS_CLI_NAME= redis-cli |
98 | REDIS_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o | |
99 | REDIS_BENCHMARK_NAME= redis-benchmark | |
100 | REDIS_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o | |
101 | REDIS_CHECK_DUMP_NAME= redis-check-dump | |
102 | REDIS_CHECK_DUMP_OBJ= redis-check-dump.o lzf_c.o lzf_d.o | |
103 | REDIS_CHECK_AOF_NAME= redis-check-aof | |
104 | REDIS_CHECK_AOF_OBJ= redis-check-aof.o | |
105 | ||
236adc28 | 106 | all: $(REDIS_SERVER_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME) |
c8061392 PN |
107 | @echo "" |
108 | @echo "Hint: To run 'make test' is a good idea ;)" | |
109 | @echo "" | |
ed9b544e | 110 | |
de07849e | 111 | .PHONY: all |
c8061392 | 112 | |
de07849e PN |
113 | # Deps (use make dep to generate this) |
114 | include Makefile.dep | |
9e62dc17 | 115 | |
de07849e | 116 | dep: |
69ac4d06 | 117 | $(REDIS_CC) -MM *.c > Makefile.dep |
5bb2c88e | 118 | |
de07849e | 119 | .PHONY: dep |
5bb2c88e | 120 | |
de07849e PN |
121 | # Prerequisites target |
122 | .make-prerequisites: | |
42c6a5da | 123 | @touch $@ |
5bb2c88e | 124 | |
6cedb4d4 PN |
125 | # Clean local objects and build dependencies when FINAL_CFLAGS is different |
126 | ifneq ($(shell sh -c '[ -f .make-cflags ] && cat .make-cflags || echo none'), $(FINAL_CFLAGS)) | |
de07849e PN |
127 | .make-cflags: clean |
128 | -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS)) | |
6cedb4d4 | 129 | -(echo "$(FINAL_CFLAGS)" > .make-cflags) |
de07849e PN |
130 | .make-prerequisites: .make-cflags |
131 | endif | |
ed9b544e | 132 | |
6cedb4d4 PN |
133 | # Clean local objects when FINAL_LDFLAGS is different |
134 | ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'), $(FINAL_LDFLAGS)) | |
de07849e | 135 | .make-ldflags: clean |
6cedb4d4 | 136 | -(echo "$(FINAL_LDFLAGS)" > .make-ldflags) |
de07849e PN |
137 | .make-prerequisites: .make-ldflags |
138 | endif | |
139 | ||
140 | # Clean local objects when MALLOC is different | |
141 | ifneq ($(shell sh -c '[ -f .make-malloc ] && cat .make-malloc || echo none'), $(MALLOC)) | |
142 | .make-malloc: clean | |
143 | -(echo "$(MALLOC)" > .make-malloc) | |
144 | .make-prerequisites: .make-malloc | |
145 | endif | |
ec8f0667 | 146 | |
de07849e | 147 | # redis-server |
236adc28 | 148 | $(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ) |
6cedb4d4 | 149 | $(REDIS_LD) -o $@ $^ ../deps/lua/src/liblua.a $(FINAL_LIBS) |
ed9b544e | 150 | |
de07849e | 151 | # redis-cli |
69ac4d06 | 152 | $(REDIS_CLI_NAME): $(REDIS_CLI_OBJ) |
6cedb4d4 | 153 | $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS) |
7fc4ce13 | 154 | |
de07849e | 155 | # redis-benchmark |
69ac4d06 | 156 | $(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ) |
6cedb4d4 | 157 | $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS) |
ed9b544e | 158 | |
de07849e | 159 | # redis-check-dump |
69ac4d06 | 160 | $(REDIS_CHECK_DUMP_NAME): $(REDIS_CHECK_DUMP_OBJ) |
6cedb4d4 | 161 | $(REDIS_LD) -o $@ $^ $(FINAL_LIBS) |
08af4d5c | 162 | |
de07849e | 163 | # redis-check-aof |
69ac4d06 | 164 | $(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ) |
6cedb4d4 | 165 | $(REDIS_LD) -o $@ $^ $(FINAL_LIBS) |
b4bd0524 | 166 | |
de07849e PN |
167 | # Because the jemalloc.h header is generated as a part of the jemalloc build, |
168 | # building it should complete before building any other object. Instead of | |
169 | # depending on a single artifact, build all dependencies first. | |
42c6a5da | 170 | %.o: %.c .make-prerequisites |
69ac4d06 | 171 | $(REDIS_CC) -c $< |
4b8a6394 | 172 | |
ed9b544e | 173 | clean: |
236adc28 | 174 | 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 |
de07849e PN |
175 | |
176 | .PHONY: clean | |
4b8a6394 PN |
177 | |
178 | distclean: clean | |
179 | -(cd ../deps && $(MAKE) distclean) | |
de07849e | 180 | -(rm -f .make-*) |
ed9b544e | 181 | |
de07849e | 182 | .PHONY: distclean |
ed9b544e | 183 | |
236adc28 | 184 | test: $(REDIS_SERVER_NAME) $(REDIS_CHECK_AOF_NAME) |
f790bd02 | 185 | @(cd ..; ./runtest) |
ed9b544e | 186 | |
9f899440 | 187 | lcov: |
0b27a55f | 188 | $(MAKE) gcov |
9f899440 PH |
189 | @(set -e; cd ..; ./runtest --clients 1) |
190 | @geninfo -o redis.info . | |
191 | @genhtml --legend -o lcov-html redis.info | |
192 | ||
de07849e PN |
193 | .PHONY: lcov |
194 | ||
69ac4d06 | 195 | bench: $(REDIS_BENCHMARK_NAME) |
196 | ./$(REDIS_BENCHMARK_NAME) | |
fd8ccf44 | 197 | |
198 | 32bit: | |
9ebed7cf | 199 | @echo "" |
200 | @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386" | |
201 | @echo "" | |
86422958 | 202 | $(MAKE) CFLAGS="-m32" LDFLAGS="-m32" |
d0ccebcf | 203 | |
fc77604c | 204 | gcov: |
6cedb4d4 | 205 | $(MAKE) REDIS_CFLAGS="-fprofile-arcs -ftest-coverage -DCOVERAGE_TEST" REDIS_LDFLAGS="-fprofile-arcs -ftest-coverage" |
fc77604c | 206 | |
25fd2cb2 | 207 | noopt: |
de07849e | 208 | $(MAKE) OPT="-O0" |
25fd2cb2 | 209 | |
319bb48c | 210 | src/help.h: |
211 | @../utils/generate-command-help.rb > help.h | |
212 | ||
acc01854 | 213 | install: all |
0bb5160c | 214 | mkdir -p $(INSTALL_BIN) |
236adc28 | 215 | $(INSTALL) $(REDIS_SERVER_NAME) $(INSTALL_BIN) |
69ac4d06 | 216 | $(INSTALL) $(REDIS_BENCHMARK_NAME) $(INSTALL_BIN) |
217 | $(INSTALL) $(REDIS_CLI_NAME) $(INSTALL_BIN) | |
218 | $(INSTALL) $(REDIS_CHECK_DUMP_NAME) $(INSTALL_BIN) | |
219 | $(INSTALL) $(REDIS_CHECK_AOF_NAME) $(INSTALL_BIN) |