]> git.saurik.com Git - redis.git/blame_incremental - src/Makefile
Clean up Makefiles
[redis.git] / src / Makefile
... / ...
CommitLineData
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
5release_hdr := $(shell sh -c './mkreleasehdr.sh')
6uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
7OPTIMIZATION?=-O2
8DEPENDENCY_TARGETS=hiredis linenoise lua
9
10STD= -std=c99 -pedantic
11WARN= -Wall
12OPT= $(OPTIMIZATION)
13
14ifeq ($(uname_S),SunOS)
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
19else
20 R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS)
21 R_LDFLAGS= $(LDFLAGS)
22 R_LIBS= $(LIBS) -lm -pthread
23 DEBUG= -g -rdynamic -ggdb
24endif
25
26# Include paths to dependencies
27R_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src
28
29# Default allocator
30ifeq ($(uname_S),Linux)
31 MALLOC?=jemalloc
32else
33 MALLOC?=libc
34endif
35
36# Backwards compatibility for selecting an allocator
37ifeq ($(USE_TCMALLOC),yes)
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)
50 R_CFLAGS+= -DUSE_TCMALLOC
51 R_LIBS+= -ltcmalloc
52endif
53
54ifeq ($(MALLOC),tcmalloc_minimal)
55 R_CFLAGS+= -DUSE_TCMALLOC
56 R_LIBS+= -ltcmalloc_minimal
57endif
58
59ifeq ($(MALLOC),jemalloc)
60 DEPENDENCY_TARGETS+= jemalloc
61 R_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
62 R_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl
63endif
64
65R_CC=$(QUIET_CC)$(CC) $(R_CFLAGS)
66R_LD=$(QUIET_LINK)$(CC) $(R_LDFLAGS)
67
68PREFIX= /usr/local
69INSTALL_BIN= $(PREFIX)/bin
70INSTALL= cp -pf
71
72CCCOLOR="\033[34m"
73LINKCOLOR="\033[34;1m"
74SRCCOLOR="\033[33m"
75BINCOLOR="\033[37;1m"
76MAKECOLOR="\033[32;1m"
77ENDCOLOR="\033[0m"
78
79ifndef V
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;
82endif
83
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 cluster.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)
96 @echo ""
97 @echo "Hint: To run 'make test' is a good idea ;)"
98 @echo ""
99
100.PHONY: all
101
102# Deps (use make dep to generate this)
103include Makefile.dep
104
105dep:
106 $(R_CC) -MM *.c
107
108.PHONY: dep
109
110# Prerequisites target
111.make-prerequisites:
112 @touch $@
113
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
121
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
135
136# redis-server
137$(R_SERVER_NAME): $(R_SERVER_OBJ)
138 $(R_LD) -o $@ $^ ../deps/lua/src/liblua.a $(R_LIBS)
139
140# redis-cli
141$(R_CLI_NAME): $(R_CLI_OBJ)
142 $(R_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(R_LIBS)
143
144# redis-benchmark
145$(R_BENCHMARK_NAME): $(R_BENCHMARK_OBJ)
146 $(R_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(R_LIBS)
147
148# redis-check-dump
149$(R_CHECK_DUMP_NAME): $(R_CHECK_DUMP_OBJ)
150 $(R_LD) -o $@ $^ $(R_LIBS)
151
152# redis-check-aof
153$(R_CHECK_AOF_NAME): $(R_CHECK_AOF_OBJ)
154 $(R_LD) -o $@ $^ $(R_LIBS)
155
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.
159%.o: %.c .make-prerequisites
160 $(R_CC) -c $<
161
162clean:
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
166
167distclean: clean
168 -(cd ../deps && $(MAKE) distclean)
169 -(rm -f .make-*)
170
171.PHONY: distclean
172
173test: $(R_SERVER_NAME) $(R_CHECK_AOF_NAME)
174 @(cd ..; ./runtest)
175
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
182.PHONY: lcov
183
184bench: $(R_BENCHMARK_NAME)
185 ./$(R_BENCHMARK_NAME)
186
187log:
188 git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog
189
19032bit:
191 @echo ""
192 @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
193 @echo ""
194 $(MAKE) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32"
195
196gprof:
197 $(MAKE) CFLAGS="$(CFLAGS) -pg" LDFLAGS="$(LDFLAGS) -pg"
198
199gcov:
200 $(MAKE) CFLAGS="$(CFLAGS) -fprofile-arcs -ftest-coverage -DCOVERAGE_TEST"
201
202noopt:
203 $(MAKE) OPT="-O0"
204
20532bitgprof:
206 $(MAKE) CFLAGS="$(CFLAGS) -m32" LDFLAGS="$(LDFLAGS) -m32" gprof
207
208src/help.h:
209 @../utils/generate-command-help.rb > help.h
210
211install: all
212 mkdir -p $(INSTALL_BIN)
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)