xref: /redis-3.2.3/src/Makefile (revision 5bb2c88e)
1e2641e09Santirez# Redis Makefile
2e2641e09Santirez# Copyright (C) 2009 Salvatore Sanfilippo <antirez at gmail dot com>
3e2641e09Santirez# This file is released under the BSD license, see the COPYING file
4e2641e09Santirez
5e2641e09Santirezrelease_hdr := $(shell sh -c './mkreleasehdr.sh')
6e2641e09Santirezuname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
7e2641e09SantirezOPTIMIZATION?=-O2
84b8a6394SPieter NoordhuisDEPENDENCY_TARGETS=hiredis linenoise lua
9b83e9583SBen Noordhuis
10e2641e09Santirezifeq ($(uname_S),SunOS)
11e2641e09Santirez  CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W -D__EXTENSIONS__ -D_XPG6
12e2641e09Santirez  CCLINK?=-ldl -lnsl -lsocket -lm -lpthread
13ba559326SPieter Noordhuis  DEBUG?=-g -ggdb
14e2641e09Santirezelse
15e2641e09Santirez  CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W $(ARCH) $(PROF)
16e2641e09Santirez  CCLINK?=-lm -pthread
17ba559326SPieter Noordhuis  DEBUG?=-g -rdynamic -ggdb
18e2641e09Santirezendif
190a802bd7Santirez
20*5bb2c88eSPieter Noordhuis# Default allocator
21*5bb2c88eSPieter Noordhuisifeq ($(uname_S),Linux)
22*5bb2c88eSPieter Noordhuis  MALLOC?=jemalloc
23*5bb2c88eSPieter Noordhuiselse
24*5bb2c88eSPieter Noordhuis  MALLOC?=libc
25*5bb2c88eSPieter Noordhuisendif
26*5bb2c88eSPieter Noordhuis
27*5bb2c88eSPieter Noordhuis# Backwards compatibility for selecting an allocator
280a802bd7Santirezifeq ($(USE_TCMALLOC),yes)
29*5bb2c88eSPieter Noordhuis  MALLOC=tcmalloc
30*5bb2c88eSPieter Noordhuisendif
31*5bb2c88eSPieter Noordhuis
32*5bb2c88eSPieter Noordhuisifeq ($(USE_TCMALLOC_MINIMAL),yes)
33*5bb2c88eSPieter Noordhuis  MALLOC=tcmalloc_minimal
34*5bb2c88eSPieter Noordhuisendif
35*5bb2c88eSPieter Noordhuis
36*5bb2c88eSPieter Noordhuisifeq ($(USE_JEMALLOC),yes)
37*5bb2c88eSPieter Noordhuis  MALLOC=jemalloc
38*5bb2c88eSPieter Noordhuisendif
39*5bb2c88eSPieter Noordhuis
40*5bb2c88eSPieter Noordhuisifeq ($(MALLOC),tcmalloc)
4152825621SPieter Noordhuis  ALLOC_LINK=-ltcmalloc
4252825621SPieter Noordhuis  ALLOC_FLAGS=-DUSE_TCMALLOC
430a802bd7Santirezendif
4452825621SPieter Noordhuis
45*5bb2c88eSPieter Noordhuisifeq ($(MALLOC),tcmalloc_minimal)
4652825621SPieter Noordhuis  ALLOC_LINK=-ltcmalloc_minimal
4752825621SPieter Noordhuis  ALLOC_FLAGS=-DUSE_TCMALLOC
4852825621SPieter Noordhuisendif
4952825621SPieter Noordhuis
50*5bb2c88eSPieter Noordhuisifeq ($(MALLOC),jemalloc)
514b8a6394SPieter Noordhuis  ALLOC_LINK=../deps/jemalloc/lib/libjemalloc.a -ldl
529e62dc17Santirez  ALLOC_FLAGS=-DUSE_JEMALLOC -I../deps/jemalloc/include
534b8a6394SPieter Noordhuis  DEPENDENCY_TARGETS+= jemalloc
5452825621SPieter Noordhuisendif
5552825621SPieter Noordhuis
5652825621SPieter NoordhuisCCLINK+= $(ALLOC_LINK)
5752825621SPieter NoordhuisCFLAGS+= $(ALLOC_FLAGS)
589e62dc17SantirezCCOPT= $(CFLAGS) $(ARCH) $(PROF)
59e2641e09Santirez
60e1386503SPedro MeloPREFIX= /usr/local
610997b411SPedro MeloINSTALL_BIN= $(PREFIX)/bin
62acc01854SantirezINSTALL= cp -p
63acc01854Santirez
6435845afbSantirezCCCOLOR="\033[34m"
6535845afbSantirezLINKCOLOR="\033[34;1m"
6635845afbSantirezSRCCOLOR="\033[33m"
6735845afbSantirezBINCOLOR="\033[37;1m"
6835845afbSantirezMAKECOLOR="\033[32;1m"
6935845afbSantirezENDCOLOR="\033[0m"
7035845afbSantirez
7173e71867Santirezifndef V
72db6cea11SHampus WessmanQUIET_CC = @printf '    %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR);
73db6cea11SHampus WessmanQUIET_LINK = @printf '    %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR);
7473e71867Santirezendif
7573e71867Santirez
76cbdac04aSantirezOBJ = 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
77e2641e09SantirezBENCHOBJ = ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o
7811fd0c42SantirezCLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o
79e2641e09SantirezCHECKDUMPOBJ = redis-check-dump.o lzf_c.o lzf_d.o
80e2641e09SantirezCHECKAOFOBJ = redis-check-aof.o
81e2641e09Santirez
82e2641e09SantirezPRGNAME = redis-server
83e2641e09SantirezBENCHPRGNAME = redis-benchmark
84e2641e09SantirezCLIPRGNAME = redis-cli
85e2641e09SantirezCHECKDUMPPRGNAME = redis-check-dump
86e2641e09SantirezCHECKAOFPRGNAME = redis-check-aof
87e2641e09Santirez
88240f8dbfSantirezall: redis-benchmark redis-cli redis-check-dump redis-check-aof redis-server
89c8061392SPieter Noordhuis	@echo ""
90c8061392SPieter Noordhuis	@echo "Hint: To run 'make test' is a good idea ;)"
91c8061392SPieter Noordhuis	@echo ""
92e2641e09Santirez
93e2641e09Santirez# Deps (use make dep to generate this)
94e2641e09Santirezadlist.o: adlist.c adlist.h zmalloc.h
95e2641e09Santirezae.o: ae.c ae.h zmalloc.h config.h ae_kqueue.c
96e2641e09Santirezae_epoll.o: ae_epoll.c
97e2641e09Santirezae_kqueue.o: ae_kqueue.c
98e2641e09Santirezae_select.o: ae_select.c
99e2641e09Santirezanet.o: anet.c fmacros.h anet.h
1008fedd04dSantirezaof.o: aof.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
101b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
102b147cb9eSantirezbio.o: bio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
103b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h bio.h
1043e2a0bf4Santirezcluster.o: cluster.c redis.h fmacros.h config.h ae.h sds.h dict.h \
105b147cb9eSantirez  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
106daa70b17Santirezconfig.o: config.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
107b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
108daa70b17Santirezcrc16.o: crc16.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
109b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
110daa70b17Santirezdb.o: db.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
111b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
112daa70b17Santirezdebug.o: debug.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
113b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h sha1.h
114daa70b17Santirezdict.o: dict.c fmacros.h dict.h zmalloc.h
1153e2a0bf4Santirezendian.o: endian.c
1163e2a0bf4Santirezintset.o: intset.c intset.h zmalloc.h endian.h
117e2641e09Santirezlzf_c.o: lzf_c.c lzfP.h
118e2641e09Santirezlzf_d.o: lzf_d.c lzfP.h
1198fedd04dSantirezmulti.o: multi.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
120b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
1218fedd04dSantireznetworking.o: networking.c redis.h fmacros.h config.h ae.h sds.h dict.h \
122b147cb9eSantirez  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
1238fedd04dSantirezobject.o: object.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
124b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
125e2641e09Santirezpqsort.o: pqsort.c
1268fedd04dSantirezpubsub.o: pubsub.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
127b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
1288fedd04dSantirezrdb.o: rdb.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
129b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h lzf.h
13033388d43Santirezredis-benchmark.o: redis-benchmark.c fmacros.h ae.h \
13133388d43Santirez  ../deps/hiredis/hiredis.h sds.h adlist.h zmalloc.h
132e2641e09Santirezredis-check-aof.o: redis-check-aof.c fmacros.h config.h
133e2641e09Santirezredis-check-dump.o: redis-check-dump.c lzf.h
13433388d43Santirezredis-cli.o: redis-cli.c fmacros.h version.h ../deps/hiredis/hiredis.h \
13533388d43Santirez  sds.h zmalloc.h ../deps/linenoise/linenoise.h help.h
1368fedd04dSantirezredis.o: redis.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
137daa70b17Santirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h \
138b147cb9eSantirez  bio.h asciilogo.h
139e2641e09Santirezrelease.o: release.c release.h
1408fedd04dSantirezreplication.o: replication.c redis.h fmacros.h config.h ae.h sds.h dict.h \
141b147cb9eSantirez  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
142b147cb9eSantirezscripting.o: scripting.c redis.h fmacros.h config.h ae.h sds.h dict.h \
143daa70b17Santirez  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \
144e108bab0Santirez  sha1.h rand.h
1452e4b0e77SPieter Noordhuisrio.o: rio.c sds.h
146e2641e09Santirezsds.o: sds.c sds.h zmalloc.h
1473e2a0bf4Santirezsha1.o: sha1.c sha1.h config.h
148daa70b17Santirezslowlog.o: slowlog.c redis.h fmacros.h config.h ae.h sds.h dict.h \
149daa70b17Santirez  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \
150daa70b17Santirez  slowlog.h
1518fedd04dSantirezsort.o: sort.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
152b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h pqsort.h
15333388d43Santirezsyncio.o: syncio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
154b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
1558fedd04dSantirezt_hash.o: t_hash.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
156b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
1578fedd04dSantirezt_list.o: t_list.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
158b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
1598fedd04dSantirezt_set.o: t_set.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
160b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
1618fedd04dSantirezt_string.o: t_string.c redis.h fmacros.h config.h ae.h sds.h dict.h \
162b147cb9eSantirez  adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
1638fedd04dSantirezt_zset.o: t_zset.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \
164b147cb9eSantirez  zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h
1653e2a0bf4Santirezutil.o: util.c fmacros.h util.h
1663e2a0bf4Santirezziplist.o: ziplist.c zmalloc.h util.h ziplist.h endian.h
1673e2a0bf4Santirezzipmap.o: zipmap.c zmalloc.h endian.h
1683e2a0bf4Santirezzmalloc.o: zmalloc.c config.h zmalloc.h
169e2641e09Santirez
1704b8a6394SPieter Noordhuis# Clean local objects when ARCH is different
1714b8a6394SPieter Noordhuisifneq ($(shell sh -c '[ -f .make-arch ] && cat .make-arch'), $(ARCH))
1724b8a6394SPieter Noordhuis.make-arch: clean
1734b8a6394SPieter Noordhuiselse
1744b8a6394SPieter Noordhuis.make-arch:
1754b8a6394SPieter Noordhuisendif
176e2641e09Santirez
1774b8a6394SPieter Noordhuis.make-arch:
1784b8a6394SPieter Noordhuis	-(cd ../deps && make $(DEPENDENCY_TARGETS) ARCH="$(ARCH)")
1794b8a6394SPieter Noordhuis	-(echo $(ARCH) > .make-arch)
180c8061392SPieter Noordhuis
181*5bb2c88eSPieter Noordhuis# Clean local objects when allocator changes
182*5bb2c88eSPieter Noordhuisifneq ($(shell sh -c '[ -f .make-malloc ] && cat .make-malloc'), $(MALLOC))
183*5bb2c88eSPieter Noordhuis.make-malloc: clean
184*5bb2c88eSPieter Noordhuiselse
185*5bb2c88eSPieter Noordhuis.make-malloc:
186*5bb2c88eSPieter Noordhuisendif
187*5bb2c88eSPieter Noordhuis
188*5bb2c88eSPieter Noordhuis.make-malloc:
189*5bb2c88eSPieter Noordhuis	-(echo $(MALLOC) > .make-malloc)
190*5bb2c88eSPieter Noordhuis
191*5bb2c88eSPieter Noordhuis# Union of prerequisites
192*5bb2c88eSPieter Noordhuis.prerequisites: .make-arch .make-malloc
193*5bb2c88eSPieter Noordhuis
194*5bb2c88eSPieter Noordhuisredis-server: .prerequisites $(OBJ)
195321a0440SPieter Noordhuis	$(QUIET_LINK)$(CC) -o $(PRGNAME) $(CCOPT) $(DEBUG) $(OBJ) ../deps/lua/src/liblua.a $(CCLINK)
196e2641e09Santirez
197*5bb2c88eSPieter Noordhuisredis-benchmark: .prerequisites $(BENCHOBJ)
19861c0e893SPieter Noordhuis	$(QUIET_LINK)$(CC) -o $(BENCHPRGNAME) $(CCOPT) $(DEBUG) $(BENCHOBJ) ../deps/hiredis/libhiredis.a $(CCLINK)
199ec8f0667SPieter Noordhuis
200*5bb2c88eSPieter Noordhuisredis-benchmark.o: redis-benchmark.c .prerequisites
20173e71867Santirez	$(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis $(DEBUG) $(COMPILE_TIME) $<
202e2641e09Santirez
203*5bb2c88eSPieter Noordhuisredis-cli: .prerequisites $(CLIOBJ)
20461c0e893SPieter Noordhuis	$(QUIET_LINK)$(CC) -o $(CLIPRGNAME) $(CCOPT) $(DEBUG) $(CLIOBJ) ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(CCLINK)
2057fc4ce13SPieter Noordhuis
206*5bb2c88eSPieter Noordhuisredis-cli.o: redis-cli.c .prerequisites
20773e71867Santirez	$(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis -I../deps/linenoise $(DEBUG) $(COMPILE_TIME) $<
208e2641e09Santirez
209*5bb2c88eSPieter Noordhuisredis-check-dump: .prerequisites $(CHECKDUMPOBJ)
21061c0e893SPieter Noordhuis	$(QUIET_LINK)$(CC) -o $(CHECKDUMPPRGNAME) $(CCOPT) $(DEBUG) $(CHECKDUMPOBJ) $(CCLINK)
211e2641e09Santirez
212*5bb2c88eSPieter Noordhuisredis-check-aof: .prerequisites $(CHECKAOFOBJ)
21361c0e893SPieter Noordhuis	$(QUIET_LINK)$(CC) -o $(CHECKAOFPRGNAME) $(CCOPT) $(DEBUG) $(CHECKAOFOBJ) $(CCLINK)
214e2641e09Santirez
2159e62dc17Santirez# Because the jemalloc.h header is generated as a part of the jemalloc build
2164b8a6394SPieter Noordhuis# process, building it should complete before building any other object. Instead of
2174b8a6394SPieter Noordhuis# depending on a single artifact, simply build all dependencies first.
218*5bb2c88eSPieter Noordhuis%.o: %.c .prerequisites
2190d1650f8Santirez	$(QUIET_CC)$(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) -I../deps/lua/src $<
220e2641e09Santirez
2214b8a6394SPieter Noordhuis.PHONY: all clean distclean
2224b8a6394SPieter Noordhuis
223e2641e09Santirezclean:
224e2641e09Santirez	rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) $(CHECKDUMPPRGNAME) $(CHECKAOFPRGNAME) *.o *.gcda *.gcno *.gcov
2254b8a6394SPieter Noordhuis
2264b8a6394SPieter Noordhuisdistclean: clean
2274b8a6394SPieter Noordhuis	-(cd ../deps && $(MAKE) distclean)
228*5bb2c88eSPieter Noordhuis	-(rm -f .make-arch .make-malloc)
229e2641e09Santirez
230e2641e09Santirezdep:
23133388d43Santirez	$(CC) -MM *.c -I ../deps/hiredis -I ../deps/linenoise
232e2641e09Santirez
233e6fcb5b3Santireztest: redis-server redis-check-aof
234f790bd02Santirez	@(cd ..; ./runtest)
235e2641e09Santirez
236e2641e09Santirezbench:
237e2641e09Santirez	./redis-benchmark
238e2641e09Santirez
239e2641e09Santirezlog:
24024110a4dSantirez	git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog
241e2641e09Santirez
242e2641e09Santirez32bit:
243e2641e09Santirez	@echo ""
244e2641e09Santirez	@echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
245e2641e09Santirez	@echo ""
246e93d36a6Santirez	$(MAKE) ARCH="-m32" JEMALLOC_CFLAGS='CFLAGS="-std=gnu99 -Wall -pipe -g3 -fvisibility=hidden -O3 -funroll-loops -m32"'
247e2641e09Santirez
248e2641e09Santirezgprof:
249a4e48b41SPieter Noordhuis	$(MAKE) PROF="-pg"
250e2641e09Santirez
251e2641e09Santirezgcov:
252a4e48b41SPieter Noordhuis	$(MAKE) PROF="-fprofile-arcs -ftest-coverage"
253e2641e09Santirez
254e2641e09Santireznoopt:
255a4e48b41SPieter Noordhuis	$(MAKE) OPTIMIZATION=""
256e2641e09Santirez
257e2641e09Santirez32bitgprof:
258a4e48b41SPieter Noordhuis	$(MAKE) PROF="-pg" ARCH="-arch i386"
259acc01854Santirez
260319bb48cSantirezsrc/help.h:
261319bb48cSantirez	@../utils/generate-command-help.rb > help.h
262319bb48cSantirez
263acc01854Santirezinstall: all
2640bb5160cSantirez	mkdir -p $(INSTALL_BIN)
2650bb5160cSantirez	$(INSTALL) $(PRGNAME) $(INSTALL_BIN)
2660bb5160cSantirez	$(INSTALL) $(BENCHPRGNAME) $(INSTALL_BIN)
2670bb5160cSantirez	$(INSTALL) $(CLIPRGNAME) $(INSTALL_BIN)
2680bb5160cSantirez	$(INSTALL) $(CHECKDUMPPRGNAME) $(INSTALL_BIN)
2690bb5160cSantirez	$(INSTALL) $(CHECKAOFPRGNAME) $(INSTALL_BIN)
270