Makefile 9.7 KB
Newer Older
A
antirez 已提交
1 2 3 4
# Redis Makefile
# Copyright (C) 2009 Salvatore Sanfilippo <antirez at gmail dot com>
# This file is released under the BSD license, see the COPYING file

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),SunOS)
11 12 13
  CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W -D__EXTENSIONS__ -D_XPG6
  CCLINK?=-ldl -lnsl -lsocket -lm -lpthread
  DEBUG?=-g -ggdb 
14
else
15 16 17
  CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W $(ARCH) $(PROF)
  CCLINK?=-lm -pthread
  DEBUG?=-g -rdynamic -ggdb 
18
endif
A
antirez 已提交
19

20 21 22 23 24 25 26 27
# Default allocator
ifeq ($(uname_S),Linux)
  MALLOC?=jemalloc
else
  MALLOC?=libc
endif

# Backwards compatibility for selecting an allocator
A
antirez 已提交
28
ifeq ($(USE_TCMALLOC),yes)
29 30 31 32 33 34 35 36 37 38 39 40
  MALLOC=tcmalloc
endif

ifeq ($(USE_TCMALLOC_MINIMAL),yes)
  MALLOC=tcmalloc_minimal
endif

ifeq ($(USE_JEMALLOC),yes)
  MALLOC=jemalloc
endif

ifeq ($(MALLOC),tcmalloc)
P
Pieter Noordhuis 已提交
41 42
  ALLOC_LINK=-ltcmalloc
  ALLOC_FLAGS=-DUSE_TCMALLOC
A
antirez 已提交
43
endif
P
Pieter Noordhuis 已提交
44

45
ifeq ($(MALLOC),tcmalloc_minimal)
P
Pieter Noordhuis 已提交
46 47 48 49
  ALLOC_LINK=-ltcmalloc_minimal
  ALLOC_FLAGS=-DUSE_TCMALLOC
endif

50
ifeq ($(MALLOC),jemalloc)
51
  ALLOC_LINK=../deps/jemalloc/lib/libjemalloc.a -ldl
52
  ALLOC_FLAGS=-DUSE_JEMALLOC -I../deps/jemalloc/include
53
  DEPENDENCY_TARGETS+= jemalloc
P
Pieter Noordhuis 已提交
54 55 56 57
endif

CCLINK+= $(ALLOC_LINK)
CFLAGS+= $(ALLOC_FLAGS)
58
CCOPT= $(CFLAGS) $(ARCH) $(PROF)
A
antirez 已提交
59

60
PREFIX= /usr/local
P
Pedro Melo 已提交
61
INSTALL_BIN= $(PREFIX)/bin
A
antirez 已提交
62 63
INSTALL= cp -p

A
antirez 已提交
64 65 66 67 68 69 70
CCCOLOR="\033[34m"
LINKCOLOR="\033[34;1m"
SRCCOLOR="\033[33m"
BINCOLOR="\033[37;1m"
MAKECOLOR="\033[32;1m"
ENDCOLOR="\033[0m"

71
ifndef V
H
Hampus Wessman 已提交
72 73
QUIET_CC = @printf '    %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR);
QUIET_LINK = @printf '    %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR);
74 75
endif

76
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
77
BENCHOBJ = ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o
78
CLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o
79
CHECKDUMPOBJ = redis-check-dump.o lzf_c.o lzf_d.o
P
Pieter Noordhuis 已提交
80
CHECKAOFOBJ = redis-check-aof.o
A
antirez 已提交
81 82 83 84

PRGNAME = redis-server
BENCHPRGNAME = redis-benchmark
CLIPRGNAME = redis-cli
85
CHECKDUMPPRGNAME = redis-check-dump
P
Pieter Noordhuis 已提交
86
CHECKAOFPRGNAME = redis-check-aof
A
antirez 已提交
87

88
all: redis-benchmark redis-cli redis-check-dump redis-check-aof redis-server
P
Pieter Noordhuis 已提交
89 90 91
	@echo ""
	@echo "Hint: To run 'make test' is a good idea ;)"
	@echo ""
A
antirez 已提交
92 93

# Deps (use make dep to generate this)
A
antirez 已提交
94
adlist.o: adlist.c adlist.h zmalloc.h
95 96 97
ae.o: ae.c ae.h zmalloc.h config.h ae_kqueue.c
ae_epoll.o: ae_epoll.c
ae_kqueue.o: ae_kqueue.c
98
ae_select.o: ae_select.c
A
antirez 已提交
99
anet.o: anet.c fmacros.h anet.h
A
antirez 已提交
100
aof.o: aof.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
101 102 103
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
bio.o: bio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h bio.h
A
antirez 已提交
104
cluster.o: cluster.c redis.h fmacros.h config.h ae.h sds.h dict.h \
A
antirez 已提交
105
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
106
config.o: config.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
107
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
108
crc16.o: crc16.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
109
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
110
db.o: db.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
111
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
112
debug.o: debug.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
113
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h sha1.h
114
dict.o: dict.c fmacros.h dict.h zmalloc.h
A
antirez 已提交
115 116
endian.o: endian.c
intset.o: intset.c intset.h zmalloc.h endian.h
A
antirez 已提交
117 118
lzf_c.o: lzf_c.c lzfP.h
lzf_d.o: lzf_d.c lzfP.h
A
antirez 已提交
119
multi.o: multi.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
120
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
121
networking.o: networking.c redis.h fmacros.h config.h ae.h sds.h dict.h \
A
antirez 已提交
122
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
123
object.o: object.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
124
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
125
pqsort.o: pqsort.c
A
antirez 已提交
126
pubsub.o: pubsub.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
127
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
128
rdb.o: rdb.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
129
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h lzf.h
130 131
redis-benchmark.o: redis-benchmark.c fmacros.h ae.h \
  ../deps/hiredis/hiredis.h sds.h adlist.h zmalloc.h
A
antirez 已提交
132
redis-check-aof.o: redis-check-aof.c fmacros.h config.h
133
redis-check-dump.o: redis-check-dump.c lzf.h
134 135
redis-cli.o: redis-cli.c fmacros.h version.h ../deps/hiredis/hiredis.h \
  sds.h zmalloc.h ../deps/linenoise/linenoise.h help.h
A
antirez 已提交
136
redis.o: redis.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
137
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h \
A
antirez 已提交
138
  bio.h asciilogo.h
139
release.o: release.c release.h
A
antirez 已提交
140
replication.o: replication.c redis.h fmacros.h config.h ae.h sds.h dict.h \
A
antirez 已提交
141 142
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
scripting.o: scripting.c redis.h fmacros.h config.h ae.h sds.h dict.h \
143
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \
144
  sha1.h rand.h
145
rio.o: rio.c sds.h
A
antirez 已提交
146
sds.o: sds.c sds.h zmalloc.h
A
antirez 已提交
147
sha1.o: sha1.c sha1.h config.h
148 149 150
slowlog.o: slowlog.c redis.h fmacros.h config.h ae.h sds.h dict.h \
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \
  slowlog.h
A
antirez 已提交
151
sort.o: sort.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
152
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h pqsort.h
153
syncio.o: syncio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
154
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
155
t_hash.o: t_hash.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
156
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
157
t_list.o: t_list.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
158
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
159
t_set.o: t_set.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
160
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
161
t_string.o: t_string.c redis.h fmacros.h config.h ae.h sds.h dict.h \
A
antirez 已提交
162
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
163
t_zset.o: t_zset.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
164
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
165 166 167 168
util.o: util.c fmacros.h util.h
ziplist.o: ziplist.c zmalloc.h util.h ziplist.h endian.h
zipmap.o: zipmap.c zmalloc.h endian.h
zmalloc.o: zmalloc.c config.h zmalloc.h
A
antirez 已提交
169

170 171 172 173 174 175
# Clean local objects when ARCH is different
ifneq ($(shell sh -c '[ -f .make-arch ] && cat .make-arch'), $(ARCH))
.make-arch: clean
else
.make-arch:
endif
P
Pieter Noordhuis 已提交
176

177 178 179
.make-arch:
	-(cd ../deps && make $(DEPENDENCY_TARGETS) ARCH="$(ARCH)")
	-(echo $(ARCH) > .make-arch)
180

181 182 183 184 185 186 187 188 189 190 191 192 193 194
# Clean local objects when allocator changes
ifneq ($(shell sh -c '[ -f .make-malloc ] && cat .make-malloc'), $(MALLOC))
.make-malloc: clean
else
.make-malloc:
endif

.make-malloc:
	-(echo $(MALLOC) > .make-malloc)

# Union of prerequisites
.prerequisites: .make-arch .make-malloc

redis-server: .prerequisites $(OBJ)
P
Pieter Noordhuis 已提交
195
	$(QUIET_LINK)$(CC) -o $(PRGNAME) $(CCOPT) $(DEBUG) $(OBJ) ../deps/lua/src/liblua.a $(CCLINK)
A
antirez 已提交
196

197
redis-benchmark: .prerequisites $(BENCHOBJ)
198
	$(QUIET_LINK)$(CC) -o $(BENCHPRGNAME) $(CCOPT) $(DEBUG) $(BENCHOBJ) ../deps/hiredis/libhiredis.a $(CCLINK)
199

200
redis-benchmark.o: redis-benchmark.c .prerequisites
201
	$(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis $(DEBUG) $(COMPILE_TIME) $<
A
antirez 已提交
202

203
redis-cli: .prerequisites $(CLIOBJ)
204
	$(QUIET_LINK)$(CC) -o $(CLIPRGNAME) $(CCOPT) $(DEBUG) $(CLIOBJ) ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(CCLINK)
P
Pieter Noordhuis 已提交
205

206
redis-cli.o: redis-cli.c .prerequisites
207
	$(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis -I../deps/linenoise $(DEBUG) $(COMPILE_TIME) $<
A
antirez 已提交
208

209
redis-check-dump: .prerequisites $(CHECKDUMPOBJ)
210
	$(QUIET_LINK)$(CC) -o $(CHECKDUMPPRGNAME) $(CCOPT) $(DEBUG) $(CHECKDUMPOBJ) $(CCLINK)
211

212
redis-check-aof: .prerequisites $(CHECKAOFOBJ)
213
	$(QUIET_LINK)$(CC) -o $(CHECKAOFPRGNAME) $(CCOPT) $(DEBUG) $(CHECKAOFOBJ) $(CCLINK)
P
Pieter Noordhuis 已提交
214

215
# Because the jemalloc.h header is generated as a part of the jemalloc build
216 217
# process, building it should complete before building any other object. Instead of
# depending on a single artifact, simply build all dependencies first.
218
%.o: %.c .prerequisites
A
antirez 已提交
219
	$(QUIET_CC)$(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) -I../deps/lua/src $<
A
antirez 已提交
220

221 222
.PHONY: all clean distclean

A
antirez 已提交
223
clean:
P
Pieter Noordhuis 已提交
224
	rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) $(CHECKDUMPPRGNAME) $(CHECKAOFPRGNAME) *.o *.gcda *.gcno *.gcov
225 226 227

distclean: clean
	-(cd ../deps && $(MAKE) distclean)
228
	-(rm -f .make-arch .make-malloc)
A
antirez 已提交
229 230

dep:
231
	$(CC) -MM *.c -I ../deps/hiredis -I ../deps/linenoise
A
antirez 已提交
232

233
test: redis-server redis-check-aof
234
	@(cd ..; ./runtest)
A
antirez 已提交
235 236 237

bench:
	./redis-benchmark
A
antirez 已提交
238 239

log:
A
antirez 已提交
240
	git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog
241 242

32bit:
243 244 245
	@echo ""
	@echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
	@echo ""
246
	$(MAKE) ARCH="-m32" JEMALLOC_CFLAGS='CFLAGS="-std=gnu99 -Wall -pipe -g3 -fvisibility=hidden -O3 -funroll-loops -m32"'
247 248

gprof:
P
Pieter Noordhuis 已提交
249
	$(MAKE) PROF="-pg"
250

251
gcov:
P
Pieter Noordhuis 已提交
252
	$(MAKE) PROF="-fprofile-arcs -ftest-coverage"
253

254
noopt:
P
Pieter Noordhuis 已提交
255
	$(MAKE) OPTIMIZATION=""
256

257
32bitgprof:
P
Pieter Noordhuis 已提交
258
	$(MAKE) PROF="-pg" ARCH="-arch i386"
A
antirez 已提交
259

260 261 262
src/help.h:
	@../utils/generate-command-help.rb > help.h

A
antirez 已提交
263
install: all
264 265 266 267 268 269
	mkdir -p $(INSTALL_BIN)
	$(INSTALL) $(PRGNAME) $(INSTALL_BIN)
	$(INSTALL) $(BENCHPRGNAME) $(INSTALL_BIN)
	$(INSTALL) $(CLIPRGNAME) $(INSTALL_BIN)
	$(INSTALL) $(CHECKDUMPPRGNAME) $(INSTALL_BIN)
	$(INSTALL) $(CHECKAOFPRGNAME) $(INSTALL_BIN)