]>
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 | |
4 | ||
73287b2b | 5 | release_hdr := $(shell sh -c './mkreleasehdr.sh') |
325d1eb4 | 6 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') |
25fd2cb2 | 7 | OPTIMIZATION?=-O2 |
4b8a6394 | 8 | DEPENDENCY_TARGETS=hiredis linenoise lua |
b83e9583 | 9 | |
0a08d2b0 PN |
10 | STD= -std=c99 -pedantic |
11 | WARN= -Wall | |
12 | OPT= $(OPTIMIZATION) | |
13 | ||
325d1eb4 | 14 | ifeq ($(uname_S),SunOS) |
0a08d2b0 PN |
15 | R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) -D__EXTENSIONS__ -D_XPG6 |
16 | R_LDFLAGS= $(LDFLAGS) | |
17 | R_LIBS= $(LIBS) -ldl -lnsl -lsocket -lm -lpthread | |
18 | DEBUG= -g -ggdb | |
325d1eb4 | 19 | else |
0a08d2b0 PN |
20 | R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) |
21 | R_LDFLAGS= $(LDFLAGS) | |
22 | R_LIBS= $(LIBS) -lm -pthread | |
23 | DEBUG= -g -rdynamic -ggdb | |
325d1eb4 | 24 | endif |
0a802bd7 | 25 | |
0a08d2b0 PN |
26 | # Include paths to dependencies |
27 | R_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src | |
28 | ||
5bb2c88e PN |
29 | # Default allocator |
30 | ifeq ($(uname_S),Linux) | |
31 | MALLOC?=jemalloc | |
32 | else | |
33 | MALLOC?=libc | |
34 | endif | |
35 | ||
36 | # Backwards compatibility for selecting an allocator | |
0a802bd7 | 37 | ifeq ($(USE_TCMALLOC),yes) |
5bb2c88e PN |
38 | MALLOC=tcmalloc |
39 | endif | |
40 | ||
41 | ifeq ($(USE_TCMALLOC_MINIMAL),yes) | |
42 | MALLOC=tcmalloc_minimal | |
43 | endif | |
44 | ||
45 | ifeq ($(USE_JEMALLOC),yes) | |
46 | MALLOC=jemalloc | |
47 | endif | |
48 | ||
49 | ifeq ($(MALLOC),tcmalloc) | |
0a08d2b0 PN |
50 | R_CFLAGS+= -DUSE_TCMALLOC |
51 | R_LIBS+= -ltcmalloc | |
0a802bd7 | 52 | endif |
52825621 | 53 | |
5bb2c88e | 54 | ifeq ($(MALLOC),tcmalloc_minimal) |
0a08d2b0 PN |
55 | R_CFLAGS+= -DUSE_TCMALLOC |
56 | R_LIBS+= -ltcmalloc_minimal | |
52825621 PN |
57 | endif |
58 | ||
5bb2c88e | 59 | ifeq ($(MALLOC),jemalloc) |
4b8a6394 | 60 | DEPENDENCY_TARGETS+= jemalloc |
0a08d2b0 PN |
61 | R_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include |
62 | R_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl | |
52825621 PN |
63 | endif |
64 | ||
0a08d2b0 PN |
65 | R_CC=$(QUIET_CC)$(CC) $(R_CFLAGS) |
66 | R_LD=$(QUIET_LINK)$(CC) $(R_LDFLAGS) | |
ed9b544e | 67 | |
e1386503 | 68 | PREFIX= /usr/local |
0997b411 | 69 | INSTALL_BIN= $(PREFIX)/bin |
120a36f2 | 70 | INSTALL= cp -pf |
acc01854 | 71 | |
35845afb | 72 | CCCOLOR="\033[34m" |
73 | LINKCOLOR="\033[34;1m" | |
74 | SRCCOLOR="\033[33m" | |
75 | BINCOLOR="\033[37;1m" | |
76 | MAKECOLOR="\033[32;1m" | |
77 | ENDCOLOR="\033[0m" | |
78 | ||
73e71867 | 79 | ifndef V |
0a08d2b0 PN |
80 | QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2; |
81 | QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2; | |
73e71867 | 82 | endif |
83 | ||
0a08d2b0 PN |
84 | R_SERVER_NAME= redis-server |
85 | R_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 | |
86 | R_CLI_NAME= redis-cli | |
87 | R_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o | |
88 | R_BENCHMARK_NAME= redis-benchmark | |
89 | R_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o | |
90 | R_CHECK_DUMP_NAME= redis-check-dump | |
91 | R_CHECK_DUMP_OBJ= redis-check-dump.o lzf_c.o lzf_d.o | |
92 | R_CHECK_AOF_NAME= redis-check-aof | |
93 | R_CHECK_AOF_OBJ= redis-check-aof.o | |
94 | ||
95 | all: $(R_SERVER_NAME) $(R_CLI_NAME) $(R_BENCHMARK_NAME) $(R_CHECK_DUMP_NAME) $(R_CHECK_AOF_NAME) | |
c8061392 PN |
96 | @echo "" |
97 | @echo "Hint: To run 'make test' is a good idea ;)" | |
98 | @echo "" | |
ed9b544e | 99 | |
0a08d2b0 | 100 | .PHONY: all |
c8061392 | 101 | |
0a08d2b0 PN |
102 | # Deps (use make dep to generate this) |
103 | include Makefile.dep | |
9e62dc17 | 104 | |
0a08d2b0 | 105 | dep: |
a470689d | 106 | $(R_CC) -MM *.c > Makefile.dep |
5bb2c88e | 107 | |
0a08d2b0 | 108 | .PHONY: dep |
5bb2c88e | 109 | |
0a08d2b0 PN |
110 | # Prerequisites target |
111 | .make-prerequisites: | |
42c6a5da | 112 | @touch $@ |
5bb2c88e | 113 | |
0a08d2b0 PN |
114 | # Clean local objects and build dependencies when R_CFLAGS is different |
115 | ifneq ($(shell sh -c '[ -f .make-cflags ] && cat .make-cflags || echo none'), $(R_CFLAGS)) | |
116 | .make-cflags: clean | |
117 | -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS)) | |
118 | -(echo "$(R_CFLAGS)" > .make-cflags) | |
119 | .make-prerequisites: .make-cflags | |
120 | endif | |
ed9b544e | 121 | |
0a08d2b0 PN |
122 | # Clean local objects when R_LDFLAGS is different |
123 | ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'), $(R_LDFLAGS)) | |
124 | .make-ldflags: clean | |
125 | -(echo "$(R_LDFLAGS)" > .make-ldflags) | |
126 | .make-prerequisites: .make-ldflags | |
127 | endif | |
128 | ||
129 | # Clean local objects when MALLOC is different | |
130 | ifneq ($(shell sh -c '[ -f .make-malloc ] && cat .make-malloc || echo none'), $(MALLOC)) | |
131 | .make-malloc: clean | |
132 | -(echo "$(MALLOC)" > .make-malloc) | |
133 | .make-prerequisites: .make-malloc | |
134 | endif | |
ec8f0667 | 135 | |
0a08d2b0 PN |
136 | # redis-server |
137 | $(R_SERVER_NAME): $(R_SERVER_OBJ) | |
138 | $(R_LD) -o $@ $^ ../deps/lua/src/liblua.a $(R_LIBS) | |
ed9b544e | 139 | |
0a08d2b0 PN |
140 | # redis-cli |
141 | $(R_CLI_NAME): $(R_CLI_OBJ) | |
142 | $(R_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(R_LIBS) | |
7fc4ce13 | 143 | |
0a08d2b0 PN |
144 | # redis-benchmark |
145 | $(R_BENCHMARK_NAME): $(R_BENCHMARK_OBJ) | |
146 | $(R_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(R_LIBS) | |
ed9b544e | 147 | |
0a08d2b0 PN |
148 | # redis-check-dump |
149 | $(R_CHECK_DUMP_NAME): $(R_CHECK_DUMP_OBJ) | |
150 | $(R_LD) -o $@ $^ $(R_LIBS) | |
08af4d5c | 151 | |
0a08d2b0 PN |
152 | # redis-check-aof |
153 | $(R_CHECK_AOF_NAME): $(R_CHECK_AOF_OBJ) | |
154 | $(R_LD) -o $@ $^ $(R_LIBS) | |
b4bd0524 | 155 | |
0a08d2b0 PN |
156 | # Because the jemalloc.h header is generated as a part of the jemalloc build, |
157 | # building it should complete before building any other object. Instead of | |
158 | # depending on a single artifact, build all dependencies first. | |
42c6a5da | 159 | %.o: %.c .make-prerequisites |
0a08d2b0 | 160 | $(R_CC) -c $< |
4b8a6394 | 161 | |
ed9b544e | 162 | clean: |
0a08d2b0 PN |
163 | rm -rf $(R_SERVER_NAME) $(R_CLI_NAME) $(R_BENCHMARK_NAME) $(R_CHECK_DUMP_NAME) $(R_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html |
164 | ||
165 | .PHONY: clean | |
4b8a6394 PN |
166 | |
167 | distclean: clean | |
168 | -(cd ../deps && $(MAKE) distclean) | |
0a08d2b0 | 169 | -(rm -f .make-*) |
ed9b544e | 170 | |
0a08d2b0 | 171 | .PHONY: distclean |
ed9b544e | 172 | |
0a08d2b0 | 173 | test: $(R_SERVER_NAME) $(R_CHECK_AOF_NAME) |
f790bd02 | 174 | @(cd ..; ./runtest) |
ed9b544e | 175 | |
c35b4e84 PH |
176 | lcov: |
177 | $(MAKE) clean gcov | |
178 | @(set -e; cd ..; ./runtest --clients 1) | |
179 | @geninfo -o redis.info . | |
180 | @genhtml --legend -o lcov-html redis.info | |
181 | ||
0a08d2b0 PN |
182 | .PHONY: lcov |
183 | ||
184 | bench: $(R_BENCHMARK_NAME) | |
185 | ./$(R_BENCHMARK_NAME) | |
378fd421 | 186 | |
187 | log: | |
24110a4d | 188 | git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog |
fd8ccf44 | 189 | |
190 | 32bit: | |
9ebed7cf | 191 | @echo "" |
192 | @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386" | |
193 | @echo "" | |
0a08d2b0 | 194 | $(MAKE) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32" |
d0ccebcf | 195 | |
196 | gprof: | |
0a08d2b0 | 197 | $(MAKE) CFLAGS="$(CFLAGS) -pg" LDFLAGS="$(LDFLAGS) -pg" |
d0ccebcf | 198 | |
fc77604c | 199 | gcov: |
0a08d2b0 | 200 | $(MAKE) CFLAGS="$(CFLAGS) -fprofile-arcs -ftest-coverage -DCOVERAGE_TEST" |
fc77604c | 201 | |
25fd2cb2 | 202 | noopt: |
0a08d2b0 | 203 | $(MAKE) OPT="-O0" |
25fd2cb2 | 204 | |
d0ccebcf | 205 | 32bitgprof: |
0a08d2b0 | 206 | $(MAKE) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32" gprof |
acc01854 | 207 | |
319bb48c | 208 | src/help.h: |
209 | @../utils/generate-command-help.rb > help.h | |
210 | ||
acc01854 | 211 | install: all |
0bb5160c | 212 | mkdir -p $(INSTALL_BIN) |
0a08d2b0 PN |
213 | $(INSTALL) $(R_SERVER_NAME) $(INSTALL_BIN) |
214 | $(INSTALL) $(R_BENCHMARK_NAME) $(INSTALL_BIN) | |
215 | $(INSTALL) $(R_CLI_NAME) $(INSTALL_BIN) | |
216 | $(INSTALL) $(R_CHECK_DUMP_NAME) $(INSTALL_BIN) | |
217 | $(INSTALL) $(R_CHECK_AOF_NAME) $(INSTALL_BIN) |