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