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

P
Pieter Noordhuis 已提交
10 11 12 13
STD= -std=c99 -pedantic
WARN= -Wall
OPT= $(OPTIMIZATION)

14
ifeq ($(uname_S),SunOS)
P
Pieter Noordhuis 已提交
15 16 17 18
  R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) -D__EXTENSIONS__ -D_XPG6
  R_LDFLAGS= $(LDFLAGS)
  R_LIBS= $(LIBS) -ldl -lnsl -lsocket -lm -lpthread
  DEBUG= -g -ggdb
19
else
P
Pieter Noordhuis 已提交
20 21 22 23
  R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS)
  R_LDFLAGS= $(LDFLAGS)
  R_LIBS= $(LIBS) -lm -pthread
  DEBUG= -g -rdynamic -ggdb
24
endif
A
antirez 已提交
25

P
Pieter Noordhuis 已提交
26 27 28
# Include paths to dependencies
R_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src

29 30 31 32 33 34 35 36
# Default allocator
ifeq ($(uname_S),Linux)
  MALLOC?=jemalloc
else
  MALLOC?=libc
endif

# Backwards compatibility for selecting an allocator
A
antirez 已提交
37
ifeq ($(USE_TCMALLOC),yes)
38 39 40 41 42 43 44 45 46 47 48 49
  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 已提交
50 51
  R_CFLAGS+= -DUSE_TCMALLOC
  R_LIBS+= -ltcmalloc
A
antirez 已提交
52
endif
P
Pieter Noordhuis 已提交
53

54
ifeq ($(MALLOC),tcmalloc_minimal)
P
Pieter Noordhuis 已提交
55 56
  R_CFLAGS+= -DUSE_TCMALLOC
  R_LIBS+= -ltcmalloc_minimal
P
Pieter Noordhuis 已提交
57 58
endif

59
ifeq ($(MALLOC),jemalloc)
60
  DEPENDENCY_TARGETS+= jemalloc
P
Pieter Noordhuis 已提交
61 62
  R_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
  R_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl
P
Pieter Noordhuis 已提交
63 64
endif

P
Pieter Noordhuis 已提交
65 66
R_CC=$(QUIET_CC)$(CC) $(R_CFLAGS)
R_LD=$(QUIET_LINK)$(CC) $(R_LDFLAGS)
A
antirez 已提交
67

68
PREFIX= /usr/local
P
Pedro Melo 已提交
69
INSTALL_BIN= $(PREFIX)/bin
70
INSTALL= cp -pf
A
antirez 已提交
71

A
antirez 已提交
72 73 74 75 76 77 78
CCCOLOR="\033[34m"
LINKCOLOR="\033[34;1m"
SRCCOLOR="\033[33m"
BINCOLOR="\033[37;1m"
MAKECOLOR="\033[32;1m"
ENDCOLOR="\033[0m"

79
ifndef V
P
Pieter Noordhuis 已提交
80 81
QUIET_CC = @printf '    %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2;
QUIET_LINK = @printf '    %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
82 83
endif

P
Pieter Noordhuis 已提交
84 85 86 87 88 89 90 91 92 93 94 95
R_SERVER_NAME= redis-server
R_SERVER_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 migrate.o crc16.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o
R_CLI_NAME= redis-cli
R_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o
R_BENCHMARK_NAME= redis-benchmark
R_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o
R_CHECK_DUMP_NAME= redis-check-dump
R_CHECK_DUMP_OBJ= redis-check-dump.o lzf_c.o lzf_d.o
R_CHECK_AOF_NAME= redis-check-aof
R_CHECK_AOF_OBJ= redis-check-aof.o

all: $(R_SERVER_NAME) $(R_CLI_NAME) $(R_BENCHMARK_NAME) $(R_CHECK_DUMP_NAME) $(R_CHECK_AOF_NAME)
P
Pieter Noordhuis 已提交
96 97 98
	@echo ""
	@echo "Hint: To run 'make test' is a good idea ;)"
	@echo ""
A
antirez 已提交
99

P
Pieter Noordhuis 已提交
100
.PHONY: all
P
Pieter Noordhuis 已提交
101

P
Pieter Noordhuis 已提交
102 103
# Deps (use make dep to generate this)
include Makefile.dep
104

P
Pieter Noordhuis 已提交
105
dep:
106
	$(R_CC) -MM *.c > Makefile.dep
107

P
Pieter Noordhuis 已提交
108
.PHONY: dep
109

P
Pieter Noordhuis 已提交
110 111
# Prerequisites target
.make-prerequisites:
112
	@touch $@
113

P
Pieter Noordhuis 已提交
114 115 116 117 118 119 120
# Clean local objects and build dependencies when R_CFLAGS is different
ifneq ($(shell sh -c '[ -f .make-cflags ] && cat .make-cflags || echo none'), $(R_CFLAGS))
.make-cflags: clean
	-(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS))
	-(echo "$(R_CFLAGS)" > .make-cflags)
.make-prerequisites: .make-cflags
endif
A
antirez 已提交
121

P
Pieter Noordhuis 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134
# Clean local objects when R_LDFLAGS is different
ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'), $(R_LDFLAGS))
.make-ldflags: clean
	-(echo "$(R_LDFLAGS)" > .make-ldflags)
.make-prerequisites: .make-ldflags
endif

# Clean local objects when MALLOC is different
ifneq ($(shell sh -c '[ -f .make-malloc ] && cat .make-malloc || echo none'), $(MALLOC))
.make-malloc: clean
	-(echo "$(MALLOC)" > .make-malloc)
.make-prerequisites: .make-malloc
endif
135

P
Pieter Noordhuis 已提交
136 137 138
# redis-server
$(R_SERVER_NAME): $(R_SERVER_OBJ)
	$(R_LD) -o $@ $^ ../deps/lua/src/liblua.a $(R_LIBS)
A
antirez 已提交
139

P
Pieter Noordhuis 已提交
140 141 142
# redis-cli
$(R_CLI_NAME): $(R_CLI_OBJ)
	$(R_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(R_LIBS)
P
Pieter Noordhuis 已提交
143

P
Pieter Noordhuis 已提交
144 145 146
# redis-benchmark
$(R_BENCHMARK_NAME): $(R_BENCHMARK_OBJ)
	$(R_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(R_LIBS)
A
antirez 已提交
147

P
Pieter Noordhuis 已提交
148 149 150
# redis-check-dump
$(R_CHECK_DUMP_NAME): $(R_CHECK_DUMP_OBJ)
	$(R_LD) -o $@ $^ $(R_LIBS)
151

P
Pieter Noordhuis 已提交
152 153 154
# redis-check-aof
$(R_CHECK_AOF_NAME): $(R_CHECK_AOF_OBJ)
	$(R_LD) -o $@ $^ $(R_LIBS)
P
Pieter Noordhuis 已提交
155

P
Pieter Noordhuis 已提交
156 157 158
# Because the jemalloc.h header is generated as a part of the jemalloc build,
# building it should complete before building any other object. Instead of
# depending on a single artifact, build all dependencies first.
159
%.o: %.c .make-prerequisites
P
Pieter Noordhuis 已提交
160
	$(R_CC) -c $<
161

A
antirez 已提交
162
clean:
P
Pieter Noordhuis 已提交
163 164 165
	rm -rf $(R_SERVER_NAME) $(R_CLI_NAME) $(R_BENCHMARK_NAME) $(R_CHECK_DUMP_NAME) $(R_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html

.PHONY: clean
166 167 168

distclean: clean
	-(cd ../deps && $(MAKE) distclean)
P
Pieter Noordhuis 已提交
169
	-(rm -f .make-*)
A
antirez 已提交
170

P
Pieter Noordhuis 已提交
171
.PHONY: distclean
A
antirez 已提交
172

P
Pieter Noordhuis 已提交
173
test: $(R_SERVER_NAME) $(R_CHECK_AOF_NAME)
174
	@(cd ..; ./runtest)
A
antirez 已提交
175

176 177 178 179 180 181
lcov:
	$(MAKE) clean gcov
	@(set -e; cd ..; ./runtest --clients 1)
	@geninfo -o redis.info .
	@genhtml --legend -o lcov-html redis.info

P
Pieter Noordhuis 已提交
182 183 184 185
.PHONY: lcov

bench: $(R_BENCHMARK_NAME)
	./$(R_BENCHMARK_NAME)
A
antirez 已提交
186 187

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

32bit:
191 192 193
	@echo ""
	@echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
	@echo ""
P
Pieter Noordhuis 已提交
194
	$(MAKE) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32"
195 196

gprof:
P
Pieter Noordhuis 已提交
197
	$(MAKE) CFLAGS="$(CFLAGS) -pg" LDFLAGS="$(LDFLAGS) -pg"
198

199
gcov:
P
Pieter Noordhuis 已提交
200
	$(MAKE) CFLAGS="$(CFLAGS) -fprofile-arcs -ftest-coverage -DCOVERAGE_TEST"
201

202
noopt:
P
Pieter Noordhuis 已提交
203
	$(MAKE) OPT="-O0"
204

205
32bitgprof:
P
Pieter Noordhuis 已提交
206
	$(MAKE) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32" gprof
A
antirez 已提交
207

208 209 210
src/help.h:
	@../utils/generate-command-help.rb > help.h

A
antirez 已提交
211
install: all
212
	mkdir -p $(INSTALL_BIN)
P
Pieter Noordhuis 已提交
213 214 215 216 217
	$(INSTALL) $(R_SERVER_NAME) $(INSTALL_BIN)
	$(INSTALL) $(R_BENCHMARK_NAME) $(INSTALL_BIN)
	$(INSTALL) $(R_CLI_NAME) $(INSTALL_BIN)
	$(INSTALL) $(R_CHECK_DUMP_NAME) $(INSTALL_BIN)
	$(INSTALL) $(R_CHECK_AOF_NAME) $(INSTALL_BIN)