]> git.saurik.com Git - redis.git/blame_incremental - src/Makefile
redis_init_script template updated.
[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
5release_hdr := $(shell sh -c './mkreleasehdr.sh')
6uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
7OPTIMIZATION?=-O2
8DEPENDENCY_TARGETS=hiredis linenoise lua
9
10ifeq ($(uname_S),SunOS)
11 CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W -D__EXTENSIONS__ -D_XPG6
12 CCLINK?=-ldl -lnsl -lsocket -lm -lpthread
13 DEBUG?=-g -ggdb
14else
15 CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W $(ARCH) $(PROF)
16 CCLINK?=-lm -pthread
17 DEBUG?=-g -rdynamic -ggdb
18endif
19
20# Default allocator
21ifeq ($(uname_S),Linux)
22 MALLOC?=jemalloc
23else
24 MALLOC?=libc
25endif
26
27# Backwards compatibility for selecting an allocator
28ifeq ($(USE_TCMALLOC),yes)
29 MALLOC=tcmalloc
30endif
31
32ifeq ($(USE_TCMALLOC_MINIMAL),yes)
33 MALLOC=tcmalloc_minimal
34endif
35
36ifeq ($(USE_JEMALLOC),yes)
37 MALLOC=jemalloc
38endif
39
40ifeq ($(MALLOC),tcmalloc)
41 ALLOC_LINK=-ltcmalloc
42 ALLOC_FLAGS=-DUSE_TCMALLOC
43endif
44
45ifeq ($(MALLOC),tcmalloc_minimal)
46 ALLOC_LINK=-ltcmalloc_minimal
47 ALLOC_FLAGS=-DUSE_TCMALLOC
48endif
49
50ifeq ($(MALLOC),jemalloc)
51 ALLOC_LINK=../deps/jemalloc/lib/libjemalloc.a -ldl
52 ALLOC_FLAGS=-DUSE_JEMALLOC -I../deps/jemalloc/include
53 DEPENDENCY_TARGETS+= jemalloc
54endif
55
56CCLINK+= $(ALLOC_LINK)
57CFLAGS+= $(ALLOC_FLAGS)
58CCOPT= $(CFLAGS) $(ARCH) $(PROF)
59
60PREFIX= /usr/local
61INSTALL_BIN= $(PREFIX)/bin
62INSTALL= cp -pf
63
64CCCOLOR="\033[34m"
65LINKCOLOR="\033[34;1m"
66SRCCOLOR="\033[33m"
67BINCOLOR="\033[37;1m"
68MAKECOLOR="\033[32;1m"
69ENDCOLOR="\033[0m"
70
71ifndef V
72QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR);
73QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR);
74endif
75
76OBJ = 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
77BENCHOBJ = ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o
78CLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o
79CHECKDUMPOBJ = redis-check-dump.o lzf_c.o lzf_d.o
80CHECKAOFOBJ = redis-check-aof.o
81
82PRGNAME = redis-server
83BENCHPRGNAME = redis-benchmark
84CLIPRGNAME = redis-cli
85CHECKDUMPPRGNAME = redis-check-dump
86CHECKAOFPRGNAME = redis-check-aof
87
88all: redis-benchmark redis-cli redis-check-dump redis-check-aof redis-server
89 @echo ""
90 @echo "Hint: To run 'make test' is a good idea ;)"
91 @echo ""
92
93# Deps (use make dep to generate this)
94adlist.o: adlist.c adlist.h zmalloc.h
95ae.o: ae.c ae.h zmalloc.h config.h ae_kqueue.c
96ae_epoll.o: ae_epoll.c
97ae_kqueue.o: ae_kqueue.c
98ae_select.o: ae_select.c
99anet.o: anet.c fmacros.h anet.h
100aof.o: aof.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
101 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h bio.h
102bio.o: bio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
103 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h bio.h
104cluster.o: cluster.c redis.h fmacros.h config.h ae.h sds.h dict.h \
105 adlist.h zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h \
106 rio.h
107config.o: config.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
108 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h
109crc16.o: crc16.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
110 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h
111db.o: db.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
112 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h
113debug.o: debug.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
114 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h sha1.h
115dict.o: dict.c fmacros.h dict.h zmalloc.h
116endianconv.o: endianconv.c
117intset.o: intset.c intset.h zmalloc.h endianconv.h
118lzf_c.o: lzf_c.c lzfP.h
119lzf_d.o: lzf_d.c lzfP.h
120multi.o: multi.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
121 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h
122networking.o: networking.c redis.h fmacros.h config.h ae.h sds.h dict.h \
123 adlist.h zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h \
124 rio.h
125object.o: object.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
126 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h
127pqsort.o: pqsort.c
128pubsub.o: pubsub.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
129 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h
130rand.o: rand.c
131rdb.o: rdb.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
132 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h lzf.h \
133 zipmap.h
134redis-benchmark.o: redis-benchmark.c fmacros.h ae.h \
135 ../deps/hiredis/hiredis.h sds.h adlist.h zmalloc.h
136redis-check-aof.o: redis-check-aof.c fmacros.h config.h
137redis-check-dump.o: redis-check-dump.c lzf.h
138redis-cli.o: redis-cli.c fmacros.h version.h ../deps/hiredis/hiredis.h \
139 sds.h zmalloc.h ../deps/linenoise/linenoise.h help.h
140redis.o: redis.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
141 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h \
142 slowlog.h bio.h asciilogo.h
143release.o: release.c release.h
144replication.o: replication.c redis.h fmacros.h config.h ae.h sds.h dict.h \
145 adlist.h zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h \
146 rio.h
147rio.o: rio.c fmacros.h rio.h sds.h util.h
148scripting.o: scripting.c redis.h fmacros.h config.h ae.h sds.h dict.h \
149 adlist.h zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h \
150 rio.h sha1.h rand.h
151sds.o: sds.c sds.h zmalloc.h
152sha1.o: sha1.c sha1.h config.h
153slowlog.o: slowlog.c redis.h fmacros.h config.h ae.h sds.h dict.h \
154 adlist.h zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h \
155 rio.h slowlog.h
156sort.o: sort.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
157 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h \
158 pqsort.h
159syncio.o: syncio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
160 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h
161t_hash.o: t_hash.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
162 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h
163t_list.o: t_list.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
164 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h
165t_set.o: t_set.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
166 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h
167t_string.o: t_string.c redis.h fmacros.h config.h ae.h sds.h dict.h \
168 adlist.h zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h \
169 rio.h
170t_zset.o: t_zset.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
171 zmalloc.h anet.h ziplist.h intset.h version.h util.h rdb.h rio.h
172util.o: util.c fmacros.h util.h
173ziplist.o: ziplist.c zmalloc.h util.h ziplist.h endianconv.h
174zipmap.o: zipmap.c zmalloc.h endianconv.h
175zmalloc.o: zmalloc.c config.h zmalloc.h
176
177# Clean local objects when ARCH is different
178ifneq ($(shell sh -c '[ -f .make-arch ] && cat .make-arch'), $(ARCH))
179.make-arch: clean
180else
181.make-arch:
182endif
183
184.make-arch:
185 -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS) ARCH="$(ARCH)")
186 -(echo $(ARCH) > .make-arch)
187
188# Clean local objects when allocator changes
189ifneq ($(shell sh -c '[ -f .make-malloc ] && cat .make-malloc'), $(MALLOC))
190.make-malloc: clean
191else
192.make-malloc:
193endif
194
195.make-malloc:
196 -(echo $(MALLOC) > .make-malloc)
197
198# Union of make-prerequisites
199.make-prerequisites: .make-arch .make-malloc
200 @touch $@
201
202redis-server: .make-prerequisites $(OBJ)
203 $(QUIET_LINK)$(CC) -o $(PRGNAME) $(CCOPT) $(DEBUG) $(OBJ) ../deps/lua/src/liblua.a $(CCLINK)
204
205redis-benchmark: .make-prerequisites $(BENCHOBJ)
206 $(QUIET_LINK)$(CC) -o $(BENCHPRGNAME) $(CCOPT) $(DEBUG) $(BENCHOBJ) ../deps/hiredis/libhiredis.a $(CCLINK)
207
208redis-benchmark.o: redis-benchmark.c .make-prerequisites
209 $(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis $(DEBUG) $(COMPILE_TIME) $<
210
211redis-cli: .make-prerequisites $(CLIOBJ)
212 $(QUIET_LINK)$(CC) -o $(CLIPRGNAME) $(CCOPT) $(DEBUG) $(CLIOBJ) ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(CCLINK)
213
214redis-cli.o: redis-cli.c .make-prerequisites
215 $(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis -I../deps/linenoise $(DEBUG) $(COMPILE_TIME) $<
216
217redis-check-dump: .make-prerequisites $(CHECKDUMPOBJ)
218 $(QUIET_LINK)$(CC) -o $(CHECKDUMPPRGNAME) $(CCOPT) $(DEBUG) $(CHECKDUMPOBJ) $(CCLINK)
219
220redis-check-aof: .make-prerequisites $(CHECKAOFOBJ)
221 $(QUIET_LINK)$(CC) -o $(CHECKAOFPRGNAME) $(CCOPT) $(DEBUG) $(CHECKAOFOBJ) $(CCLINK)
222
223# Because the jemalloc.h header is generated as a part of the jemalloc build
224# process, building it should complete before building any other object. Instead of
225# depending on a single artifact, simply build all dependencies first.
226%.o: %.c .make-prerequisites
227 $(QUIET_CC)$(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) -I../deps/lua/src $<
228
229.PHONY: all clean distclean
230
231clean:
232 rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) $(CHECKDUMPPRGNAME) $(CHECKAOFPRGNAME) *.o *.gcda *.gcno *.gcov
233
234distclean: clean
235 -(cd ../deps && $(MAKE) distclean)
236 -(rm -f .make-arch .make-malloc)
237
238dep:
239 $(CC) -MM *.c -I ../deps/hiredis -I ../deps/linenoise
240
241test: redis-server redis-check-aof
242 @(cd ..; ./runtest)
243
244bench:
245 ./redis-benchmark
246
247log:
248 git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog
249
25032bit:
251 @echo ""
252 @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
253 @echo ""
254 $(MAKE) ARCH="-m32" JEMALLOC_CFLAGS='CFLAGS="-std=gnu99 -Wall -pipe -g3 -fvisibility=hidden -O3 -funroll-loops -m32"'
255
256gprof:
257 $(MAKE) PROF="-pg"
258
259gcov:
260 $(MAKE) PROF="-fprofile-arcs -ftest-coverage"
261
262noopt:
263 $(MAKE) OPTIMIZATION=""
264
26532bitgprof:
266 $(MAKE) PROF="-pg" ARCH="-arch i386"
267
268src/help.h:
269 @../utils/generate-command-help.rb > help.h
270
271install: all
272 mkdir -p $(INSTALL_BIN)
273 $(INSTALL) $(PRGNAME) $(INSTALL_BIN)
274 $(INSTALL) $(BENCHPRGNAME) $(INSTALL_BIN)
275 $(INSTALL) $(CLIPRGNAME) $(INSTALL_BIN)
276 $(INSTALL) $(CHECKDUMPPRGNAME) $(INSTALL_BIN)
277 $(INSTALL) $(CHECKAOFPRGNAME) $(INSTALL_BIN)