xref: /redis-3.2.3/src/Makefile (revision bea60bec)
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
49c83aec9Santirez#
5631539a5SPieter Noordhuis# The Makefile composes the final FINAL_CFLAGS and FINAL_LDFLAGS using
69c83aec9Santirez# what is needed for Redis plus the standard CFLAGS and LDFLAGS passed.
79c83aec9Santirez# However when building the dependencies (Jemalloc, Lua, Hiredis, ...)
89c83aec9Santirez# CFLAGS and LDFLAGS are propagated to the dependencies, so to pass
9631539a5SPieter Noordhuis# flags only to be used when compiling / linking Redis itself REDIS_CFLAGS
10631539a5SPieter Noordhuis# and REDIS_LDFLAGS are used instead (this is the case of 'make gcov').
119c83aec9Santirez#
129c83aec9Santirez# Dependencies are stored in the Makefile.dep file. To rebuild this file
139c83aec9Santirez# Just use 'make dep', but this is only needed by developers.
14e2641e09Santirez
15e2641e09Santirezrelease_hdr := $(shell sh -c './mkreleasehdr.sh')
16e2641e09Santirezuname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
17e2641e09SantirezOPTIMIZATION?=-O2
184b8a6394SPieter NoordhuisDEPENDENCY_TARGETS=hiredis linenoise lua
19b83e9583SBen Noordhuis
20caba5851SPieter Noordhuis# Default settings
210a08d2b0SPieter NoordhuisSTD= -std=c99 -pedantic
220a08d2b0SPieter NoordhuisWARN= -Wall
230a08d2b0SPieter NoordhuisOPT= $(OPTIMIZATION)
240a08d2b0SPieter Noordhuis
255bb2c88eSPieter Noordhuis# Default allocator
265bb2c88eSPieter Noordhuisifeq ($(uname_S),Linux)
27c04278baSPieter Noordhuis  MALLOC=jemalloc
285bb2c88eSPieter Noordhuiselse
29c04278baSPieter Noordhuis  MALLOC=libc
305bb2c88eSPieter Noordhuisendif
315bb2c88eSPieter Noordhuis
325bb2c88eSPieter Noordhuis# Backwards compatibility for selecting an allocator
330a802bd7Santirezifeq ($(USE_TCMALLOC),yes)
345bb2c88eSPieter Noordhuis  MALLOC=tcmalloc
355bb2c88eSPieter Noordhuisendif
365bb2c88eSPieter Noordhuis
375bb2c88eSPieter Noordhuisifeq ($(USE_TCMALLOC_MINIMAL),yes)
385bb2c88eSPieter Noordhuis  MALLOC=tcmalloc_minimal
395bb2c88eSPieter Noordhuisendif
405bb2c88eSPieter Noordhuis
415bb2c88eSPieter Noordhuisifeq ($(USE_JEMALLOC),yes)
425bb2c88eSPieter Noordhuis  MALLOC=jemalloc
435bb2c88eSPieter Noordhuisendif
445bb2c88eSPieter Noordhuis
457e7b69feSPieter Noordhuis# Override default settings if possible
467e7b69feSPieter Noordhuis-include .make-settings
477e7b69feSPieter Noordhuis
48caba5851SPieter NoordhuisFINAL_CFLAGS=$(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS)
49*bea60becSJohan BergströmFINAL_LDFLAGS=$(LDFLAGS) $(REDIS_LDFLAGS) $(DEBUG)
50*bea60becSJohan BergströmFINAL_LIBS=-lm
51*bea60becSJohan BergströmDEBUG=-g -ggdb
52*bea60becSJohan Bergström
53*bea60becSJohan Bergströmifeq ($(uname_S),SunOS)
54*bea60becSJohan Bergström	FINAL_CFLAGS+= -D__EXTENSIONS__ -D_XPG6
55*bea60becSJohan Bergström	FINAL_LIBS+= -ldl -lnsl -lsocket -lpthread
56*bea60becSJohan Bergströmelse ifeq ($(uname_S),Darwin)
57*bea60becSJohan Bergström
58*bea60becSJohan Bergströmelse
59*bea60becSJohan Bergström	FINAL_LDFLAGS+= -rdynamic
60*bea60becSJohan Bergström	FINAL_LIBS+= -pthread
61*bea60becSJohan Bergström	DEBUG+= -rdynamic
62caba5851SPieter Noordhuisendif
63caba5851SPieter Noordhuis
64caba5851SPieter Noordhuis# Include paths to dependencies
65caba5851SPieter NoordhuisFINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src
66caba5851SPieter Noordhuis
675bb2c88eSPieter Noordhuisifeq ($(MALLOC),tcmalloc)
68631539a5SPieter Noordhuis  FINAL_CFLAGS+= -DUSE_TCMALLOC
69631539a5SPieter Noordhuis  FINAL_LIBS+= -ltcmalloc
700a802bd7Santirezendif
7152825621SPieter Noordhuis
725bb2c88eSPieter Noordhuisifeq ($(MALLOC),tcmalloc_minimal)
73631539a5SPieter Noordhuis  FINAL_CFLAGS+= -DUSE_TCMALLOC
74631539a5SPieter Noordhuis  FINAL_LIBS+= -ltcmalloc_minimal
7552825621SPieter Noordhuisendif
7652825621SPieter Noordhuis
775bb2c88eSPieter Noordhuisifeq ($(MALLOC),jemalloc)
784b8a6394SPieter Noordhuis  DEPENDENCY_TARGETS+= jemalloc
79631539a5SPieter Noordhuis  FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
80631539a5SPieter Noordhuis  FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl
8152825621SPieter Noordhuisendif
8252825621SPieter Noordhuis
83631539a5SPieter NoordhuisREDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS)
84631539a5SPieter NoordhuisREDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS)
856b5daa2dSantirezREDIS_INSTALL=$(QUIET_INSTALL)$(INSTALL)
86e2641e09Santirez
878c630146SantirezPREFIX?=/usr/local
880997b411SPedro MeloINSTALL_BIN= $(PREFIX)/bin
89120a36f2SantirezINSTALL= cp -pf
90acc01854Santirez
9135845afbSantirezCCCOLOR="\033[34m"
9235845afbSantirezLINKCOLOR="\033[34;1m"
9335845afbSantirezSRCCOLOR="\033[33m"
9435845afbSantirezBINCOLOR="\033[37;1m"
9535845afbSantirezMAKECOLOR="\033[32;1m"
9635845afbSantirezENDCOLOR="\033[0m"
9735845afbSantirez
9873e71867Santirezifndef V
990a08d2b0SPieter NoordhuisQUIET_CC = @printf '    %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2;
1000a08d2b0SPieter NoordhuisQUIET_LINK = @printf '    %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
1016b5daa2dSantirezQUIET_INSTALL = @printf '    %b %b\n' $(LINKCOLOR)INSTALL$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
10273e71867Santirezendif
10373e71867Santirez
104c18405c9SantirezREDIS_SERVER_NAME= redis-server
1056b5daa2dSantirezREDIS_SENTINEL_NAME= redis-sentinel
1066356cf68SantirezREDIS_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 bitops.o sentinel.o notify.o setproctitle.o
1079c83aec9SantirezREDIS_CLI_NAME= redis-cli
1082f62c966SantirezREDIS_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o crc64.o
1099c83aec9SantirezREDIS_BENCHMARK_NAME= redis-benchmark
1109c83aec9SantirezREDIS_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o
1119c83aec9SantirezREDIS_CHECK_DUMP_NAME= redis-check-dump
11229c8cf01SantirezREDIS_CHECK_DUMP_OBJ= redis-check-dump.o lzf_c.o lzf_d.o crc64.o
1139c83aec9SantirezREDIS_CHECK_AOF_NAME= redis-check-aof
1149c83aec9SantirezREDIS_CHECK_AOF_OBJ= redis-check-aof.o
115e2641e09Santirez
1166b5daa2dSantirezall: $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME)
117c8061392SPieter Noordhuis	@echo ""
118c8061392SPieter Noordhuis	@echo "Hint: To run 'make test' is a good idea ;)"
119c8061392SPieter Noordhuis	@echo ""
120e2641e09Santirez
1210a08d2b0SPieter Noordhuis.PHONY: all
1220a08d2b0SPieter Noordhuis
123e2641e09Santirez# Deps (use make dep to generate this)
1240a08d2b0SPieter Noordhuisinclude Makefile.dep
125e2641e09Santirez
1260a08d2b0SPieter Noordhuisdep:
1279c83aec9Santirez	$(REDIS_CC) -MM *.c > Makefile.dep
128e2641e09Santirez
1290a08d2b0SPieter Noordhuis.PHONY: dep
130c8061392SPieter Noordhuis
1317e7b69feSPieter Noordhuispersist-settings: distclean
1327e7b69feSPieter Noordhuis	echo STD=$(STD) >> .make-settings
1337e7b69feSPieter Noordhuis	echo WARN=$(WARN) >> .make-settings
1347e7b69feSPieter Noordhuis	echo OPT=$(OPT) >> .make-settings
1357e7b69feSPieter Noordhuis	echo MALLOC=$(MALLOC) >> .make-settings
1367e7b69feSPieter Noordhuis	echo CFLAGS=$(CFLAGS) >> .make-settings
1377e7b69feSPieter Noordhuis	echo LDFLAGS=$(LDFLAGS) >> .make-settings
1387e7b69feSPieter Noordhuis	echo REDIS_CFLAGS=$(REDIS_CFLAGS) >> .make-settings
1397e7b69feSPieter Noordhuis	echo REDIS_LDFLAGS=$(REDIS_LDFLAGS) >> .make-settings
1407e7b69feSPieter Noordhuis	echo PREV_FINAL_CFLAGS=$(FINAL_CFLAGS) >> .make-settings
1417e7b69feSPieter Noordhuis	echo PREV_FINAL_LDFLAGS=$(FINAL_LDFLAGS) >> .make-settings
1427e7b69feSPieter Noordhuis	-(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS))
1437e7b69feSPieter Noordhuis
1447e7b69feSPieter Noordhuis.PHONY: persist-settings
1457e7b69feSPieter Noordhuis
1460a08d2b0SPieter Noordhuis# Prerequisites target
1470a08d2b0SPieter Noordhuis.make-prerequisites:
14842c6a5daSPieter Noordhuis	@touch $@
1495bb2c88eSPieter Noordhuis
1507e7b69feSPieter Noordhuis# Clean everything, persist settings and build dependencies if anything changed
1517e7b69feSPieter Noordhuisifneq ($(strip $(PREV_FINAL_CFLAGS)), $(strip $(FINAL_CFLAGS)))
1527e7b69feSPieter Noordhuis.make-prerequisites: persist-settings
1530a08d2b0SPieter Noordhuisendif
154e2641e09Santirez
1557e7b69feSPieter Noordhuisifneq ($(strip $(PREV_FINAL_LDFLAGS)), $(strip $(FINAL_LDFLAGS)))
1567e7b69feSPieter Noordhuis.make-prerequisites: persist-settings
1570a08d2b0SPieter Noordhuisendif
158e2641e09Santirez
1590a08d2b0SPieter Noordhuis# redis-server
160c18405c9Santirez$(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ)
1616b5daa2dSantirez	$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a $(FINAL_LIBS)
1626b5daa2dSantirez
1636b5daa2dSantirez# redis-sentinel
1646b5daa2dSantirez$(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME)
1656b5daa2dSantirez	$(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME)
1667fc4ce13SPieter Noordhuis
1670a08d2b0SPieter Noordhuis# redis-cli
1689c83aec9Santirez$(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
169631539a5SPieter Noordhuis	$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS)
170e2641e09Santirez
1710a08d2b0SPieter Noordhuis# redis-benchmark
1729c83aec9Santirez$(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
173631539a5SPieter Noordhuis	$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS)
174e2641e09Santirez
1750a08d2b0SPieter Noordhuis# redis-check-dump
1769c83aec9Santirez$(REDIS_CHECK_DUMP_NAME): $(REDIS_CHECK_DUMP_OBJ)
177631539a5SPieter Noordhuis	$(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
178e2641e09Santirez
1790a08d2b0SPieter Noordhuis# redis-check-aof
1809c83aec9Santirez$(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ)
181631539a5SPieter Noordhuis	$(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
1820a08d2b0SPieter Noordhuis
1830a08d2b0SPieter Noordhuis# Because the jemalloc.h header is generated as a part of the jemalloc build,
1840a08d2b0SPieter Noordhuis# building it should complete before building any other object. Instead of
1850a08d2b0SPieter Noordhuis# depending on a single artifact, build all dependencies first.
18642c6a5daSPieter Noordhuis%.o: %.c .make-prerequisites
1879c83aec9Santirez	$(REDIS_CC) -c $<
1884b8a6394SPieter Noordhuis
189e2641e09Santirezclean:
1906b5daa2dSantirez	rm -rf $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html
1910a08d2b0SPieter Noordhuis
1920a08d2b0SPieter Noordhuis.PHONY: clean
1934b8a6394SPieter Noordhuis
1944b8a6394SPieter Noordhuisdistclean: clean
1954b8a6394SPieter Noordhuis	-(cd ../deps && $(MAKE) distclean)
1960a08d2b0SPieter Noordhuis	-(rm -f .make-*)
197e2641e09Santirez
1980a08d2b0SPieter Noordhuis.PHONY: distclean
199e2641e09Santirez
200c18405c9Santireztest: $(REDIS_SERVER_NAME) $(REDIS_CHECK_AOF_NAME)
201f790bd02Santirez	@(cd ..; ./runtest)
202e2641e09Santirez
203c35b4e84SPremysl Hrubylcov:
2040342dd76SPieter Noordhuis	$(MAKE) gcov
205c35b4e84SPremysl Hruby	@(set -e; cd ..; ./runtest --clients 1)
206c35b4e84SPremysl Hruby	@geninfo -o redis.info .
207c35b4e84SPremysl Hruby	@genhtml --legend -o lcov-html redis.info
208c35b4e84SPremysl Hruby
2090a08d2b0SPieter Noordhuis.PHONY: lcov
2100a08d2b0SPieter Noordhuis
2119c83aec9Santirezbench: $(REDIS_BENCHMARK_NAME)
2129c83aec9Santirez	./$(REDIS_BENCHMARK_NAME)
213e2641e09Santirez
214e2641e09Santirez32bit:
215e2641e09Santirez	@echo ""
216e2641e09Santirez	@echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
217e2641e09Santirez	@echo ""
21834c943b3SPieter Noordhuis	$(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
219e2641e09Santirez
220e2641e09Santirezgcov:
221631539a5SPieter Noordhuis	$(MAKE) REDIS_CFLAGS="-fprofile-arcs -ftest-coverage -DCOVERAGE_TEST" REDIS_LDFLAGS="-fprofile-arcs -ftest-coverage"
222e2641e09Santirez
223e2641e09Santireznoopt:
2241a27d411Santirez	$(MAKE) OPTIMIZATION="-O0"
2251a27d411Santirez
2261a27d411Santirezvalgrind:
2271a27d411Santirez	$(MAKE) OPTIMIZATION="-O0" MALLOC="libc"
228e2641e09Santirez
229319bb48cSantirezsrc/help.h:
230319bb48cSantirez	@../utils/generate-command-help.rb > help.h
231319bb48cSantirez
232acc01854Santirezinstall: all
2330bb5160cSantirez	mkdir -p $(INSTALL_BIN)
2346b5daa2dSantirez	$(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(INSTALL_BIN)
2356b5daa2dSantirez	$(REDIS_INSTALL) $(REDIS_BENCHMARK_NAME) $(INSTALL_BIN)
2366b5daa2dSantirez	$(REDIS_INSTALL) $(REDIS_CLI_NAME) $(INSTALL_BIN)
2376b5daa2dSantirez	$(REDIS_INSTALL) $(REDIS_CHECK_DUMP_NAME) $(INSTALL_BIN)
2386b5daa2dSantirez	$(REDIS_INSTALL) $(REDIS_CHECK_AOF_NAME) $(INSTALL_BIN)
239