Makefile 9.0 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

A
antirez 已提交
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
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
cluster.o: cluster.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
A
antirez 已提交
92
config.o: config.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
93 94 95
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
crc16.o: crc16.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
A
antirez 已提交
96
db.o: db.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
debug.o: debug.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 sha1.h
A
antirez 已提交
100
dict.o: dict.c fmacros.h dict.h zmalloc.h
101
diskstore.o: diskstore.c redis.h fmacros.h config.h ae.h sds.h dict.h \
A
antirez 已提交
102 103
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \
  sha1.h
104
dscache.o: dscache.c redis.h fmacros.h config.h ae.h sds.h dict.h \
A
antirez 已提交
105 106 107
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
endian.o: endian.c
intset.o: intset.c intset.h zmalloc.h endian.h
A
antirez 已提交
108 109
lzf_c.o: lzf_c.c lzfP.h
lzf_d.o: lzf_d.c lzfP.h
A
antirez 已提交
110
multi.o: multi.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
networking.o: networking.c redis.h fmacros.h config.h ae.h sds.h dict.h \
A
antirez 已提交
113
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
114
object.o: object.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
pqsort.o: pqsort.c
A
antirez 已提交
117
pubsub.o: pubsub.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
118
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
119
rdb.o: rdb.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 lzf.h
121 122
redis-benchmark.o: redis-benchmark.c fmacros.h ae.h \
  ../deps/hiredis/hiredis.h sds.h adlist.h zmalloc.h
A
antirez 已提交
123
redis-check-aof.o: redis-check-aof.c fmacros.h config.h
124
redis-check-dump.o: redis-check-dump.c lzf.h
125 126
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 已提交
127
redis.o: redis.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
128 129
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \
  asciilogo.h
130
release.o: release.c release.h
A
antirez 已提交
131
replication.o: replication.c redis.h fmacros.h config.h ae.h sds.h dict.h \
A
antirez 已提交
132
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
133
sds.o: sds.c sds.h zmalloc.h
A
antirez 已提交
134
sha1.o: sha1.c sha1.h config.h
A
antirez 已提交
135
sort.o: sort.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
136
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h pqsort.h
137
syncio.o: syncio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
138
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
139
t_hash.o: t_hash.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
A
antirez 已提交
141
t_list.o: t_list.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_set.o: t_set.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_string.o: t_string.c redis.h fmacros.h config.h ae.h sds.h dict.h \
A
antirez 已提交
146
  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
A
antirez 已提交
147
t_zset.o: t_zset.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
A
antirez 已提交
148 149 150 151 152
  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
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 已提交
153

154 155
.PHONY: dependencies

P
Pieter Noordhuis 已提交
156
dependencies:
H
Hampus Wessman 已提交
157
	@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)hiredis$(ENDCOLOR)
A
antirez 已提交
158
	@cd ../deps/hiredis && $(MAKE) static ARCH="$(ARCH)"
H
Hampus Wessman 已提交
159
	@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)linenoise$(ENDCOLOR)
A
antirez 已提交
160
	@cd ../deps/linenoise && $(MAKE) ARCH="$(ARCH)"
P
Pieter Noordhuis 已提交
161

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

165
redis-server: $(OBJ)
166
	$(QUIET_CC)$(CC) -o $(PRGNAME) $(CCOPT) $(DEBUG) $(OBJ) $(CCLINK) $(ALLOC_LINK)
A
antirez 已提交
167

P
Pieter Noordhuis 已提交
168
redis-benchmark: dependencies $(BENCHOBJ)
A
antirez 已提交
169
	@cd ../deps/hiredis && $(MAKE) static
170
	$(QUIET_LINK)$(CC) -o $(BENCHPRGNAME) $(CCOPT) $(DEBUG) $(BENCHOBJ) ../deps/hiredis/libhiredis.a $(CCLINK) $(ALLOC_LINK)
171 172

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

P
Pieter Noordhuis 已提交
175
redis-cli: dependencies $(CLIOBJ)
176
	$(QUIET_LINK)$(CC) -o $(CLIPRGNAME) $(CCOPT) $(DEBUG) $(CLIOBJ) ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(CCLINK) $(ALLOC_LINK)
P
Pieter Noordhuis 已提交
177 178

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

181
redis-check-dump: $(CHECKDUMPOBJ)
182
	$(QUIET_LINK)$(CC) -o $(CHECKDUMPPRGNAME) $(CCOPT) $(DEBUG) $(CHECKDUMPOBJ) $(CCLINK) $(ALLOC_LINK)
183

P
Pieter Noordhuis 已提交
184
redis-check-aof: $(CHECKAOFOBJ)
185
	$(QUIET_LINK)$(CC) -o $(CHECKAOFPRGNAME) $(CCOPT) $(DEBUG) $(CHECKAOFOBJ) $(CCLINK) $(ALLOC_LINK)
P
Pieter Noordhuis 已提交
186

187 188 189
# 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)
190
	$(QUIET_CC)$(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) $<
A
antirez 已提交
191 192

clean:
P
Pieter Noordhuis 已提交
193
	rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) $(CHECKDUMPPRGNAME) $(CHECKAOFPRGNAME) *.o *.gcda *.gcno *.gcov
A
antirez 已提交
194 195

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

P
Pieter Noordhuis 已提交
198
test: redis-server
199
	@(cd ..; (which tclsh >/dev/null && tclsh tests/test_helper.tcl --tags "${TAGS}" --file "${FILE}") || echo "You need to install Tcl in order to run tests.")
A
antirez 已提交
200 201 202

bench:
	./redis-benchmark
A
antirez 已提交
203 204

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

32bit:
208 209 210
	@echo ""
	@echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
	@echo ""
211
	$(MAKE) ARCH="-m32" JEMALLOC_CFLAGS='CFLAGS="-std=gnu99 -Wall -pipe -g3 -fvisibility=hidden -O3 -funroll-loops -m32"'
212 213

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

216
gcov:
P
Pieter Noordhuis 已提交
217
	$(MAKE) PROF="-fprofile-arcs -ftest-coverage"
218

219
noopt:
P
Pieter Noordhuis 已提交
220
	$(MAKE) OPTIMIZATION=""
221

222
32bitgprof:
P
Pieter Noordhuis 已提交
223
	$(MAKE) PROF="-pg" ARCH="-arch i386"
A
antirez 已提交
224 225

install: all
226
	mkdir -p $(INSTALL_BIN)
A
antirez 已提交
227 228 229 230 231
	$(INSTALL) $(PRGNAME) $(INSTALL_BIN)
	$(INSTALL) $(BENCHPRGNAME) $(INSTALL_BIN)
	$(INSTALL) $(CLIPRGNAME) $(INSTALL_BIN)
	$(INSTALL) $(CHECKDUMPPRGNAME) $(INSTALL_BIN)
	$(INSTALL) $(CHECKAOFPRGNAME) $(INSTALL_BIN)