Makefile 9.5 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 9 10 11 12 13 14

ifeq ($(uname_S),Linux)
  ifneq ($(FORCE_LIBC_MALLOC),yes)
    USE_JEMALLOC=yes
  endif
endif

15
ifeq ($(uname_S),SunOS)
16 17 18
  CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W -D__EXTENSIONS__ -D_XPG6
  CCLINK?=-ldl -lnsl -lsocket -lm -lpthread
  DEBUG?=-g -ggdb 
19
else
20 21 22
  CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W $(ARCH) $(PROF)
  CCLINK?=-lm -pthread
  DEBUG?=-g -rdynamic -ggdb 
23
endif
A
antirez 已提交
24 25

ifeq ($(USE_TCMALLOC),yes)
26
  ALLOD_DEPS=
P
Pieter Noordhuis 已提交
27 28
  ALLOC_LINK=-ltcmalloc
  ALLOC_FLAGS=-DUSE_TCMALLOC
A
antirez 已提交
29
endif
P
Pieter Noordhuis 已提交
30 31

ifeq ($(USE_TCMALLOC_MINIMAL),yes)
32
  ALLOD_DEPS=
P
Pieter Noordhuis 已提交
33 34 35 36 37
  ALLOC_LINK=-ltcmalloc_minimal
  ALLOC_FLAGS=-DUSE_TCMALLOC
endif

ifeq ($(USE_JEMALLOC),yes)
38
  ALLOC_DEP=../deps/jemalloc/lib/libjemalloc.a
39
  ALLOC_LINK=$(ALLOC_DEP) -ldl
40
  ALLOC_FLAGS=-DUSE_JEMALLOC -I../deps/jemalloc/include
P
Pieter Noordhuis 已提交
41 42 43 44 45
endif

CCLINK+= $(ALLOC_LINK)
CFLAGS+= $(ALLOC_FLAGS)

46
CCOPT= $(CFLAGS) $(ARCH) $(PROF)
A
antirez 已提交
47

48
PREFIX= /usr/local
P
Pedro Melo 已提交
49
INSTALL_BIN= $(PREFIX)/bin
A
antirez 已提交
50 51
INSTALL= cp -p

A
antirez 已提交
52 53 54 55 56 57 58
CCCOLOR="\033[34m"
LINKCOLOR="\033[34;1m"
SRCCOLOR="\033[33m"
BINCOLOR="\033[37;1m"
MAKECOLOR="\033[32;1m"
ENDCOLOR="\033[0m"

59
ifndef V
H
Hampus Wessman 已提交
60 61
QUIET_CC = @printf '    %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR);
QUIET_LINK = @printf '    %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR);
62 63
endif

64
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
65
BENCHOBJ = ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o
66
CLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o
67
CHECKDUMPOBJ = redis-check-dump.o lzf_c.o lzf_d.o
P
Pieter Noordhuis 已提交
68
CHECKAOFOBJ = redis-check-aof.o
A
antirez 已提交
69 70 71 72

PRGNAME = redis-server
BENCHPRGNAME = redis-benchmark
CLIPRGNAME = redis-cli
73
CHECKDUMPPRGNAME = redis-check-dump
P
Pieter Noordhuis 已提交
74
CHECKAOFPRGNAME = redis-check-aof
A
antirez 已提交
75

76
all: redis-benchmark redis-cli redis-check-dump redis-check-aof redis-server
P
Pieter Noordhuis 已提交
77 78 79
	@echo ""
	@echo "Hint: To run 'make test' is a good idea ;)"
	@echo ""
A
antirez 已提交
80 81

# Deps (use make dep to generate this)
A
antirez 已提交
82
adlist.o: adlist.c adlist.h zmalloc.h
83 84 85
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
86
ae_select.o: ae_select.c
A
antirez 已提交
87
anet.o: anet.c fmacros.h anet.h
A
antirez 已提交
88
aof.o: aof.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
89 90 91
  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 已提交
92
cluster.o: cluster.c redis.h fmacros.h config.h ae.h sds.h dict.h \
A
antirez 已提交
93
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
94
config.o: config.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
95
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
96
crc16.o: crc16.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
97
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
98
db.o: db.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
99
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
100
debug.o: debug.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
101
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h sha1.h
102
dict.o: dict.c fmacros.h dict.h zmalloc.h
A
antirez 已提交
103 104
endian.o: endian.c
intset.o: intset.c intset.h zmalloc.h endian.h
A
antirez 已提交
105 106
lzf_c.o: lzf_c.c lzfP.h
lzf_d.o: lzf_d.c lzfP.h
A
antirez 已提交
107
multi.o: multi.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
108
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
109
networking.o: networking.c redis.h fmacros.h config.h ae.h sds.h dict.h \
A
antirez 已提交
110
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
111
object.o: object.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
112
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
113
pqsort.o: pqsort.c
A
antirez 已提交
114
pubsub.o: pubsub.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
115
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
116
rdb.o: rdb.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
117
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h lzf.h
118 119
redis-benchmark.o: redis-benchmark.c fmacros.h ae.h \
  ../deps/hiredis/hiredis.h sds.h adlist.h zmalloc.h
A
antirez 已提交
120
redis-check-aof.o: redis-check-aof.c fmacros.h config.h
121
redis-check-dump.o: redis-check-dump.c lzf.h
122 123
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 已提交
124
redis.o: redis.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
125
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h \
A
antirez 已提交
126
  bio.h asciilogo.h
127
release.o: release.c release.h
A
antirez 已提交
128
replication.o: replication.c redis.h fmacros.h config.h ae.h sds.h dict.h \
A
antirez 已提交
129 130
  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 \
131
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \
132
  sha1.h rand.h
133
rio.o: rio.c sds.h
A
antirez 已提交
134
sds.o: sds.c sds.h zmalloc.h
A
antirez 已提交
135
sha1.o: sha1.c sha1.h config.h
136 137 138
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 已提交
139
sort.o: sort.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
140
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h pqsort.h
141
syncio.o: syncio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
142
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
143
t_hash.o: t_hash.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
144
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
145
t_list.o: t_list.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
146
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
147
t_set.o: t_set.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
148
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
149
t_string.o: t_string.c redis.h fmacros.h config.h ae.h sds.h dict.h \
A
antirez 已提交
150
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
151
t_zset.o: t_zset.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
A
antirez 已提交
153 154 155 156
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 已提交
157

158
.PHONY: dependencies
A
antirez 已提交
159

P
Pieter Noordhuis 已提交
160
dependencies:
H
Hampus Wessman 已提交
161
	@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)hiredis$(ENDCOLOR)
A
antirez 已提交
162
	@cd ../deps/hiredis && $(MAKE) static ARCH="$(ARCH)"
H
Hampus Wessman 已提交
163
	@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)linenoise$(ENDCOLOR)
A
antirez 已提交
164
	@cd ../deps/linenoise && $(MAKE) ARCH="$(ARCH)"
165 166
	@echo $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)Lua ansi$(ENDCOLOR)
	@cd ../deps/lua && $(MAKE) ARCH="$(ARCH)" ansi
P
Pieter Noordhuis 已提交
167

168
../deps/jemalloc/lib/libjemalloc.a:
169
	cd ../deps/jemalloc && ./configure $(JEMALLOC_CFLAGS) --with-jemalloc-prefix=je_ --enable-cc-silence && $(MAKE) lib/libjemalloc.a
170

171
redis-server: dependencies $(OBJ)
172
	$(QUIET_LINK)$(CC) -o $(PRGNAME) $(CCOPT) $(DEBUG) $(OBJ) $(CCLINK) $(ALLOC_LINK) ../deps/lua/src/liblua.a
A
antirez 已提交
173

P
Pieter Noordhuis 已提交
174
redis-benchmark: dependencies $(BENCHOBJ)
A
antirez 已提交
175
	@cd ../deps/hiredis && $(MAKE) static
176
	$(QUIET_LINK)$(CC) -o $(BENCHPRGNAME) $(CCOPT) $(DEBUG) $(BENCHOBJ) ../deps/hiredis/libhiredis.a $(CCLINK) $(ALLOC_LINK)
177 178

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

P
Pieter Noordhuis 已提交
181
redis-cli: dependencies $(CLIOBJ)
182
	$(QUIET_LINK)$(CC) -o $(CLIPRGNAME) $(CCOPT) $(DEBUG) $(CLIOBJ) ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(CCLINK) $(ALLOC_LINK)
P
Pieter Noordhuis 已提交
183 184

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

187
redis-check-dump: $(CHECKDUMPOBJ)
188
	$(QUIET_LINK)$(CC) -o $(CHECKDUMPPRGNAME) $(CCOPT) $(DEBUG) $(CHECKDUMPOBJ) $(CCLINK) $(ALLOC_LINK)
189

P
Pieter Noordhuis 已提交
190
redis-check-aof: $(CHECKAOFOBJ)
191
	$(QUIET_LINK)$(CC) -o $(CHECKAOFPRGNAME) $(CCOPT) $(DEBUG) $(CHECKAOFOBJ) $(CCLINK) $(ALLOC_LINK)
P
Pieter Noordhuis 已提交
192

193 194 195
# Because the jemalloc.h header is generated as a part of the jemalloc build
# process, building it should complete before building any other object.
%.o: %.c $(ALLOC_DEP)
A
antirez 已提交
196
	$(QUIET_CC)$(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) -I../deps/lua/src $<
A
antirez 已提交
197 198

clean:
P
Pieter Noordhuis 已提交
199
	rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) $(CHECKDUMPPRGNAME) $(CHECKAOFPRGNAME) *.o *.gcda *.gcno *.gcov
200 201 202 203
	cd ../deps/hiredis && $(MAKE) $@
	cd ../deps/linenoise && $(MAKE) $@
	cd ../deps/lua && $(MAKE) $@
	-(cd ../deps/jemalloc && $(MAKE) distclean)
A
antirez 已提交
204 205

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

208
test: redis-server redis-check-aof
209
	@(cd ..; ./runtest)
A
antirez 已提交
210 211 212

bench:
	./redis-benchmark
A
antirez 已提交
213 214

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

32bit:
218 219 220
	@echo ""
	@echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
	@echo ""
221
	$(MAKE) ARCH="-m32" JEMALLOC_CFLAGS='CFLAGS="-std=gnu99 -Wall -pipe -g3 -fvisibility=hidden -O3 -funroll-loops -m32"'
222 223

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

226
gcov:
P
Pieter Noordhuis 已提交
227
	$(MAKE) PROF="-fprofile-arcs -ftest-coverage"
228

229
noopt:
P
Pieter Noordhuis 已提交
230
	$(MAKE) OPTIMIZATION=""
231

232
32bitgprof:
P
Pieter Noordhuis 已提交
233
	$(MAKE) PROF="-pg" ARCH="-arch i386"
A
antirez 已提交
234

235 236 237
src/help.h:
	@../utils/generate-command-help.rb > help.h

A
antirez 已提交
238
install: all
239 240 241 242 243 244
	mkdir -p $(INSTALL_BIN)
	$(INSTALL) $(PRGNAME) $(INSTALL_BIN)
	$(INSTALL) $(BENCHPRGNAME) $(INSTALL_BIN)
	$(INSTALL) $(CLIPRGNAME) $(INSTALL_BIN)
	$(INSTALL) $(CHECKDUMPPRGNAME) $(INSTALL_BIN)
	$(INSTALL) $(CHECKAOFPRGNAME) $(INSTALL_BIN)