]> git.saurik.com Git - redis.git/blame - src/Makefile
Make inline functions rioRead/Write/Tell static. This fixes issue #447.
[redis.git] / src / Makefile
CommitLineData
ed9b544e 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
73287b2b 5release_hdr := $(shell sh -c './mkreleasehdr.sh')
325d1eb4 6uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
25fd2cb2 7OPTIMIZATION?=-O2
4b8a6394 8DEPENDENCY_TARGETS=hiredis linenoise lua
b83e9583 9
de07849e
PN
10STD= -std=c99 -pedantic
11WARN= -Wall
12OPT= $(OPTIMIZATION)
13
325d1eb4 14ifeq ($(uname_S),SunOS)
de07849e
PN
15 R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) -D__EXTENSIONS__ -D_XPG6
16 R_LDFLAGS= $(LDFLAGS)
17 R_LIBS= $(LIBS) -ldl -lnsl -lsocket -lm -lpthread
18 DEBUG= -g -ggdb
325d1eb4 19else
de07849e
PN
20 R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS)
21 R_LDFLAGS= $(LDFLAGS)
22 R_LIBS= $(LIBS) -lm -pthread
23 DEBUG= -g -rdynamic -ggdb
325d1eb4 24endif
0a802bd7 25
de07849e
PN
26# Include paths to dependencies
27R_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src
28
5bb2c88e
PN
29# Default allocator
30ifeq ($(uname_S),Linux)
31 MALLOC?=jemalloc
32else
33 MALLOC?=libc
34endif
35
36# Backwards compatibility for selecting an allocator
0a802bd7 37ifeq ($(USE_TCMALLOC),yes)
5bb2c88e
PN
38 MALLOC=tcmalloc
39endif
40
41ifeq ($(USE_TCMALLOC_MINIMAL),yes)
42 MALLOC=tcmalloc_minimal
43endif
44
45ifeq ($(USE_JEMALLOC),yes)
46 MALLOC=jemalloc
47endif
48
49ifeq ($(MALLOC),tcmalloc)
de07849e
PN
50 R_CFLAGS+= -DUSE_TCMALLOC
51 R_LIBS+= -ltcmalloc
0a802bd7 52endif
52825621 53
5bb2c88e 54ifeq ($(MALLOC),tcmalloc_minimal)
de07849e
PN
55 R_CFLAGS+= -DUSE_TCMALLOC
56 R_LIBS+= -ltcmalloc_minimal
52825621
PN
57endif
58
5bb2c88e 59ifeq ($(MALLOC),jemalloc)
4b8a6394 60 DEPENDENCY_TARGETS+= jemalloc
de07849e
PN
61 R_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
62 R_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl
52825621
PN
63endif
64
de07849e
PN
65R_CC=$(QUIET_CC)$(CC) $(R_CFLAGS)
66R_LD=$(QUIET_LINK)$(CC) $(R_LDFLAGS)
ed9b544e 67
e1386503 68PREFIX= /usr/local
0997b411 69INSTALL_BIN= $(PREFIX)/bin
120a36f2 70INSTALL= cp -pf
acc01854 71
35845afb 72CCCOLOR="\033[34m"
73LINKCOLOR="\033[34;1m"
74SRCCOLOR="\033[33m"
75BINCOLOR="\033[37;1m"
76MAKECOLOR="\033[32;1m"
77ENDCOLOR="\033[0m"
78
73e71867 79ifndef V
de07849e
PN
80QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2;
81QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
73e71867 82endif
83
de07849e
PN
84R_SERVER_NAME= redis-server
85R_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
86R_CLI_NAME= redis-cli
87R_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o
88R_BENCHMARK_NAME= redis-benchmark
89R_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o
90R_CHECK_DUMP_NAME= redis-check-dump
91R_CHECK_DUMP_OBJ= redis-check-dump.o lzf_c.o lzf_d.o
92R_CHECK_AOF_NAME= redis-check-aof
93R_CHECK_AOF_OBJ= redis-check-aof.o
94
95all: $(R_SERVER_NAME) $(R_CLI_NAME) $(R_BENCHMARK_NAME) $(R_CHECK_DUMP_NAME) $(R_CHECK_AOF_NAME)
c8061392
PN
96 @echo ""
97 @echo "Hint: To run 'make test' is a good idea ;)"
98 @echo ""
ed9b544e 99
de07849e 100.PHONY: all
c8061392 101
de07849e
PN
102# Deps (use make dep to generate this)
103include Makefile.dep
9e62dc17 104
de07849e
PN
105dep:
106 $(R_CC) -MM *.c
5bb2c88e 107
de07849e 108.PHONY: dep
5bb2c88e 109
de07849e
PN
110# Prerequisites target
111.make-prerequisites:
42c6a5da 112 @touch $@
5bb2c88e 113
de07849e
PN
114# Clean local objects and build dependencies when R_CFLAGS is different
115ifneq ($(shell sh -c '[ -f .make-cflags ] && cat .make-cflags || echo none'), $(R_CFLAGS))
116.make-cflags: clean
117 -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS))
118 -(echo "$(R_CFLAGS)" > .make-cflags)
119.make-prerequisites: .make-cflags
120endif
ed9b544e 121
de07849e
PN
122# Clean local objects when R_LDFLAGS is different
123ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'), $(R_LDFLAGS))
124.make-ldflags: clean
125 -(echo "$(R_LDFLAGS)" > .make-ldflags)
126.make-prerequisites: .make-ldflags
127endif
128
129# Clean local objects when MALLOC is different
130ifneq ($(shell sh -c '[ -f .make-malloc ] && cat .make-malloc || echo none'), $(MALLOC))
131.make-malloc: clean
132 -(echo "$(MALLOC)" > .make-malloc)
133.make-prerequisites: .make-malloc
134endif
ec8f0667 135
de07849e
PN
136# redis-server
137$(R_SERVER_NAME): $(R_SERVER_OBJ)
138 $(R_LD) -o $@ $^ ../deps/lua/src/liblua.a $(R_LIBS)
ed9b544e 139
de07849e
PN
140# redis-cli
141$(R_CLI_NAME): $(R_CLI_OBJ)
142 $(R_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(R_LIBS)
7fc4ce13 143
de07849e
PN
144# redis-benchmark
145$(R_BENCHMARK_NAME): $(R_BENCHMARK_OBJ)
146 $(R_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(R_LIBS)
ed9b544e 147
de07849e
PN
148# redis-check-dump
149$(R_CHECK_DUMP_NAME): $(R_CHECK_DUMP_OBJ)
150 $(R_LD) -o $@ $^ $(R_LIBS)
08af4d5c 151
de07849e
PN
152# redis-check-aof
153$(R_CHECK_AOF_NAME): $(R_CHECK_AOF_OBJ)
154 $(R_LD) -o $@ $^ $(R_LIBS)
b4bd0524 155
de07849e
PN
156# Because the jemalloc.h header is generated as a part of the jemalloc build,
157# building it should complete before building any other object. Instead of
158# depending on a single artifact, build all dependencies first.
42c6a5da 159%.o: %.c .make-prerequisites
de07849e 160 $(R_CC) -c $<
4b8a6394 161
ed9b544e 162clean:
de07849e
PN
163 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
164
165.PHONY: clean
4b8a6394
PN
166
167distclean: clean
168 -(cd ../deps && $(MAKE) distclean)
de07849e 169 -(rm -f .make-*)
ed9b544e 170
de07849e 171.PHONY: distclean
ed9b544e 172
de07849e 173test: $(R_SERVER_NAME) $(R_CHECK_AOF_NAME)
f790bd02 174 @(cd ..; ./runtest)
ed9b544e 175
9f899440
PH
176lcov:
177 $(MAKE) clean gcov
178 @(set -e; cd ..; ./runtest --clients 1)
179 @geninfo -o redis.info .
180 @genhtml --legend -o lcov-html redis.info
181
de07849e
PN
182.PHONY: lcov
183
184bench: $(R_BENCHMARK_NAME)
185 ./$(R_BENCHMARK_NAME)
378fd421 186
187log:
24110a4d 188 git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog
fd8ccf44 189
19032bit:
9ebed7cf 191 @echo ""
192 @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
193 @echo ""
de07849e 194 $(MAKE) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32"
d0ccebcf 195
196gprof:
de07849e 197 $(MAKE) CFLAGS="$(CFLAGS) -pg" LDFLAGS="$(LDFLAGS) -pg"
d0ccebcf 198
fc77604c 199gcov:
de07849e 200 $(MAKE) CFLAGS="$(CFLAGS) -fprofile-arcs -ftest-coverage -DCOVERAGE_TEST"
fc77604c 201
25fd2cb2 202noopt:
de07849e 203 $(MAKE) OPT="-O0"
25fd2cb2 204
d0ccebcf 20532bitgprof:
de07849e 206 $(MAKE) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32" gprof
acc01854 207
319bb48c 208src/help.h:
209 @../utils/generate-command-help.rb > help.h
210
acc01854 211install: all
0bb5160c 212 mkdir -p $(INSTALL_BIN)
de07849e
PN
213 $(INSTALL) $(R_SERVER_NAME) $(INSTALL_BIN)
214 $(INSTALL) $(R_BENCHMARK_NAME) $(INSTALL_BIN)
215 $(INSTALL) $(R_CLI_NAME) $(INSTALL_BIN)
216 $(INSTALL) $(R_CHECK_DUMP_NAME) $(INSTALL_BIN)
217 $(INSTALL) $(R_CHECK_AOF_NAME) $(INSTALL_BIN)