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