xref: /redis-3.2.3/src/Makefile (revision d01d4ddc)
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
227e3ccddcSantirezWARN=-Wall -W
230a08d2b0SPieter NoordhuisOPT=$(OPTIMIZATION)
240a08d2b0SPieter Noordhuis
258080e1cfSJohan BergströmPREFIX?=/usr/local
268080e1cfSJohan BergströmINSTALL_BIN=$(PREFIX)/bin
278080e1cfSJohan BergströmINSTALL=install
288080e1cfSJohan Bergström
295bb2c88eSPieter Noordhuis# Default allocator
305bb2c88eSPieter Noordhuisifeq ($(uname_S),Linux)
31c04278baSPieter Noordhuis	MALLOC=jemalloc
325bb2c88eSPieter Noordhuiselse
33c04278baSPieter Noordhuis	MALLOC=libc
345bb2c88eSPieter Noordhuisendif
355bb2c88eSPieter Noordhuis
365bb2c88eSPieter Noordhuis# Backwards compatibility for selecting an allocator
370a802bd7Santirezifeq ($(USE_TCMALLOC),yes)
385bb2c88eSPieter Noordhuis	MALLOC=tcmalloc
395bb2c88eSPieter Noordhuisendif
405bb2c88eSPieter Noordhuis
415bb2c88eSPieter Noordhuisifeq ($(USE_TCMALLOC_MINIMAL),yes)
425bb2c88eSPieter Noordhuis	MALLOC=tcmalloc_minimal
435bb2c88eSPieter Noordhuisendif
445bb2c88eSPieter Noordhuis
455bb2c88eSPieter Noordhuisifeq ($(USE_JEMALLOC),yes)
465bb2c88eSPieter Noordhuis	MALLOC=jemalloc
475bb2c88eSPieter Noordhuisendif
485bb2c88eSPieter Noordhuis
49*d01d4ddcSMatt Stancliffifeq ($(USE_JEMALLOC),no)
50*d01d4ddcSMatt Stancliff	MALLOC=libc
51*d01d4ddcSMatt Stancliffendif
52*d01d4ddcSMatt Stancliff
537e7b69feSPieter Noordhuis# Override default settings if possible
547e7b69feSPieter Noordhuis-include .make-settings
557e7b69feSPieter Noordhuis
56caba5851SPieter NoordhuisFINAL_CFLAGS=$(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS)
57bea60becSJohan BergströmFINAL_LDFLAGS=$(LDFLAGS) $(REDIS_LDFLAGS) $(DEBUG)
58bea60becSJohan BergströmFINAL_LIBS=-lm
59bea60becSJohan BergströmDEBUG=-g -ggdb
60bea60becSJohan Bergström
61bea60becSJohan Bergströmifeq ($(uname_S),SunOS)
62452dea30Santirez	# SunOS
638080e1cfSJohan Bergström	INSTALL=cp -pf
64bea60becSJohan Bergström	FINAL_CFLAGS+= -D__EXTENSIONS__ -D_XPG6
65951eefaeSNanXiao	FINAL_LIBS+= -ldl -lnsl -lsocket -lresolv -lpthread
66bea60becSJohan Bergströmelse
67452dea30Santirezifeq ($(uname_S),Darwin)
68452dea30Santirez	# Darwin (nothing to do)
69452dea30Santirezelse
70009cabf1Ssiahlifeq ($(uname_S),AIX)
71009cabf1Ssiahl        # AIX
72009cabf1Ssiahl        FINAL_LDFLAGS+= -Wl,-bexpall
73009cabf1Ssiahl        FINAL_LIBS+= -pthread -lcrypt -lbsd
74009cabf1Ssiahl
75009cabf1Ssiahlelse
76452dea30Santirez	# All the other OSes (notably Linux)
77bea60becSJohan Bergström	FINAL_LDFLAGS+= -rdynamic
78bea60becSJohan Bergström	FINAL_LIBS+= -pthread
79caba5851SPieter Noordhuisendif
80452dea30Santirezendif
81009cabf1Ssiahlendif
82caba5851SPieter Noordhuis# Include paths to dependencies
83caba5851SPieter NoordhuisFINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src
84caba5851SPieter Noordhuis
855bb2c88eSPieter Noordhuisifeq ($(MALLOC),tcmalloc)
86631539a5SPieter Noordhuis	FINAL_CFLAGS+= -DUSE_TCMALLOC
87631539a5SPieter Noordhuis	FINAL_LIBS+= -ltcmalloc
880a802bd7Santirezendif
8952825621SPieter Noordhuis
905bb2c88eSPieter Noordhuisifeq ($(MALLOC),tcmalloc_minimal)
91631539a5SPieter Noordhuis	FINAL_CFLAGS+= -DUSE_TCMALLOC
92631539a5SPieter Noordhuis	FINAL_LIBS+= -ltcmalloc_minimal
9352825621SPieter Noordhuisendif
9452825621SPieter Noordhuis
955bb2c88eSPieter Noordhuisifeq ($(MALLOC),jemalloc)
964b8a6394SPieter Noordhuis	DEPENDENCY_TARGETS+= jemalloc
97631539a5SPieter Noordhuis	FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
98631539a5SPieter Noordhuis	FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl
9952825621SPieter Noordhuisendif
10052825621SPieter Noordhuis
101631539a5SPieter NoordhuisREDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS)
102631539a5SPieter NoordhuisREDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS)
1036b5daa2dSantirezREDIS_INSTALL=$(QUIET_INSTALL)$(INSTALL)
104e2641e09Santirez
10535845afbSantirezCCCOLOR="\033[34m"
10635845afbSantirezLINKCOLOR="\033[34;1m"
10735845afbSantirezSRCCOLOR="\033[33m"
10835845afbSantirezBINCOLOR="\033[37;1m"
10935845afbSantirezMAKECOLOR="\033[32;1m"
11035845afbSantirezENDCOLOR="\033[0m"
11135845afbSantirez
11273e71867Santirezifndef V
1130a08d2b0SPieter NoordhuisQUIET_CC = @printf '    %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2;
1140a08d2b0SPieter NoordhuisQUIET_LINK = @printf '    %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
1156b5daa2dSantirezQUIET_INSTALL = @printf '    %b %b\n' $(LINKCOLOR)INSTALL$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
11673e71867Santirezendif
11773e71867Santirez
118c18405c9SantirezREDIS_SERVER_NAME=redis-server
1196b5daa2dSantirezREDIS_SENTINEL_NAME=redis-sentinel
120cc4df5a6SantirezREDIS_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 blocked.o hyperloglog.o latency.o sparkline.o
1219c83aec9SantirezREDIS_CLI_NAME=redis-cli
1222f62c966SantirezREDIS_CLI_OBJ=anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o crc64.o
1239c83aec9SantirezREDIS_BENCHMARK_NAME=redis-benchmark
1249c83aec9SantirezREDIS_BENCHMARK_OBJ=ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o
1259c83aec9SantirezREDIS_CHECK_DUMP_NAME=redis-check-dump
12629c8cf01SantirezREDIS_CHECK_DUMP_OBJ=redis-check-dump.o lzf_c.o lzf_d.o crc64.o
1279c83aec9SantirezREDIS_CHECK_AOF_NAME=redis-check-aof
1289c83aec9SantirezREDIS_CHECK_AOF_OBJ=redis-check-aof.o
129e2641e09Santirez
1306b5daa2dSantirezall: $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME)
131c8061392SPieter Noordhuis	@echo ""
1327a2450a7SJoshua Anderson	@echo "Hint: It's a good idea to run 'make test' ;)"
133c8061392SPieter Noordhuis	@echo ""
134e2641e09Santirez
1350a08d2b0SPieter Noordhuis.PHONY: all
1360a08d2b0SPieter Noordhuis
137e2641e09Santirez# Deps (use make dep to generate this)
1380a08d2b0SPieter Noordhuisinclude Makefile.dep
139e2641e09Santirez
1400a08d2b0SPieter Noordhuisdep:
1419c83aec9Santirez	$(REDIS_CC) -MM *.c > Makefile.dep
142e2641e09Santirez
1430a08d2b0SPieter Noordhuis.PHONY: dep
144c8061392SPieter Noordhuis
1457e7b69feSPieter Noordhuispersist-settings: distclean
1467e7b69feSPieter Noordhuis	echo STD=$(STD) >> .make-settings
1477e7b69feSPieter Noordhuis	echo WARN=$(WARN) >> .make-settings
1487e7b69feSPieter Noordhuis	echo OPT=$(OPT) >> .make-settings
1497e7b69feSPieter Noordhuis	echo MALLOC=$(MALLOC) >> .make-settings
1507e7b69feSPieter Noordhuis	echo CFLAGS=$(CFLAGS) >> .make-settings
1517e7b69feSPieter Noordhuis	echo LDFLAGS=$(LDFLAGS) >> .make-settings
1527e7b69feSPieter Noordhuis	echo REDIS_CFLAGS=$(REDIS_CFLAGS) >> .make-settings
1537e7b69feSPieter Noordhuis	echo REDIS_LDFLAGS=$(REDIS_LDFLAGS) >> .make-settings
1547e7b69feSPieter Noordhuis	echo PREV_FINAL_CFLAGS=$(FINAL_CFLAGS) >> .make-settings
1557e7b69feSPieter Noordhuis	echo PREV_FINAL_LDFLAGS=$(FINAL_LDFLAGS) >> .make-settings
1567e7b69feSPieter Noordhuis	-(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS))
1577e7b69feSPieter Noordhuis
1587e7b69feSPieter Noordhuis.PHONY: persist-settings
1597e7b69feSPieter Noordhuis
1600a08d2b0SPieter Noordhuis# Prerequisites target
1610a08d2b0SPieter Noordhuis.make-prerequisites:
16242c6a5daSPieter Noordhuis	@touch $@
1635bb2c88eSPieter Noordhuis
1647e7b69feSPieter Noordhuis# Clean everything, persist settings and build dependencies if anything changed
1657e7b69feSPieter Noordhuisifneq ($(strip $(PREV_FINAL_CFLAGS)), $(strip $(FINAL_CFLAGS)))
1667e7b69feSPieter Noordhuis.make-prerequisites: persist-settings
1670a08d2b0SPieter Noordhuisendif
168e2641e09Santirez
1697e7b69feSPieter Noordhuisifneq ($(strip $(PREV_FINAL_LDFLAGS)), $(strip $(FINAL_LDFLAGS)))
1707e7b69feSPieter Noordhuis.make-prerequisites: persist-settings
1710a08d2b0SPieter Noordhuisendif
172e2641e09Santirez
1730a08d2b0SPieter Noordhuis# redis-server
174c18405c9Santirez$(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ)
1756b5daa2dSantirez	$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a $(FINAL_LIBS)
1766b5daa2dSantirez
1776b5daa2dSantirez# redis-sentinel
1786b5daa2dSantirez$(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME)
1796b5daa2dSantirez	$(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME)
1807fc4ce13SPieter Noordhuis
1810a08d2b0SPieter Noordhuis# redis-cli
1829c83aec9Santirez$(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
183631539a5SPieter Noordhuis	$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS)
184e2641e09Santirez
1850a08d2b0SPieter Noordhuis# redis-benchmark
1869c83aec9Santirez$(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
187631539a5SPieter Noordhuis	$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS)
188e2641e09Santirez
1890a08d2b0SPieter Noordhuis# redis-check-dump
1909c83aec9Santirez$(REDIS_CHECK_DUMP_NAME): $(REDIS_CHECK_DUMP_OBJ)
191631539a5SPieter Noordhuis	$(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
192e2641e09Santirez
1930a08d2b0SPieter Noordhuis# redis-check-aof
1949c83aec9Santirez$(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ)
195631539a5SPieter Noordhuis	$(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
1960a08d2b0SPieter Noordhuis
1970a08d2b0SPieter Noordhuis# Because the jemalloc.h header is generated as a part of the jemalloc build,
1980a08d2b0SPieter Noordhuis# building it should complete before building any other object. Instead of
1990a08d2b0SPieter Noordhuis# depending on a single artifact, build all dependencies first.
20042c6a5daSPieter Noordhuis%.o: %.c .make-prerequisites
2019c83aec9Santirez	$(REDIS_CC) -c $<
2024b8a6394SPieter Noordhuis
203e2641e09Santirezclean:
2046b5daa2dSantirez	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
2050a08d2b0SPieter Noordhuis
2060a08d2b0SPieter Noordhuis.PHONY: clean
2074b8a6394SPieter Noordhuis
2084b8a6394SPieter Noordhuisdistclean: clean
2094b8a6394SPieter Noordhuis	-(cd ../deps && $(MAKE) distclean)
2100a08d2b0SPieter Noordhuis	-(rm -f .make-*)
211e2641e09Santirez
2120a08d2b0SPieter Noordhuis.PHONY: distclean
213e2641e09Santirez
214c18405c9Santireztest: $(REDIS_SERVER_NAME) $(REDIS_CHECK_AOF_NAME)
215f790bd02Santirez	@(cd ..; ./runtest)
216e2641e09Santirez
217a89c8bb8Santireztest-sentinel: $(REDIS_SENTINEL_NAME)
218a89c8bb8Santirez	@(cd ..; ./runtest-sentinel)
219a89c8bb8Santirez
220978c895bSJohan Bergströmcheck: test
221978c895bSJohan Bergström
222c35b4e84SPremysl Hrubylcov:
2230342dd76SPieter Noordhuis	$(MAKE) gcov
224c35b4e84SPremysl Hruby	@(set -e; cd ..; ./runtest --clients 1)
225c35b4e84SPremysl Hruby	@geninfo -o redis.info .
226c35b4e84SPremysl Hruby	@genhtml --legend -o lcov-html redis.info
227c35b4e84SPremysl Hruby
2280195afaeSantireztest-sds: sds.c sds.h
2290195afaeSantirez	$(REDIS_CC) sds.c zmalloc.c -DSDS_TEST_MAIN -o /tmp/sds_test
2300195afaeSantirez	/tmp/sds_test
2310195afaeSantirez
2320a08d2b0SPieter Noordhuis.PHONY: lcov
2330a08d2b0SPieter Noordhuis
2349c83aec9Santirezbench: $(REDIS_BENCHMARK_NAME)
2359c83aec9Santirez	./$(REDIS_BENCHMARK_NAME)
236e2641e09Santirez
237e2641e09Santirez32bit:
238e2641e09Santirez	@echo ""
239e2641e09Santirez	@echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
240e2641e09Santirez	@echo ""
24134c943b3SPieter Noordhuis	$(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
242e2641e09Santirez
243e2641e09Santirezgcov:
244631539a5SPieter Noordhuis	$(MAKE) REDIS_CFLAGS="-fprofile-arcs -ftest-coverage -DCOVERAGE_TEST" REDIS_LDFLAGS="-fprofile-arcs -ftest-coverage"
245e2641e09Santirez
246e2641e09Santireznoopt:
2471a27d411Santirez	$(MAKE) OPTIMIZATION="-O0"
2481a27d411Santirez
2491a27d411Santirezvalgrind:
2501a27d411Santirez	$(MAKE) OPTIMIZATION="-O0" MALLOC="libc"
251e2641e09Santirez
252319bb48cSantirezsrc/help.h:
253319bb48cSantirez	@../utils/generate-command-help.rb > help.h
254319bb48cSantirez
255acc01854Santirezinstall: all
256dc4003beSJohan Bergström	@mkdir -p $(INSTALL_BIN)
2576b5daa2dSantirez	$(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(INSTALL_BIN)
2586b5daa2dSantirez	$(REDIS_INSTALL) $(REDIS_BENCHMARK_NAME) $(INSTALL_BIN)
2596b5daa2dSantirez	$(REDIS_INSTALL) $(REDIS_CLI_NAME) $(INSTALL_BIN)
2606b5daa2dSantirez	$(REDIS_INSTALL) $(REDIS_CHECK_DUMP_NAME) $(INSTALL_BIN)
2616b5daa2dSantirez	$(REDIS_INSTALL) $(REDIS_CHECK_AOF_NAME) $(INSTALL_BIN)
26224f4c018SRhommel Lamas	@ln -sf $(REDIS_SERVER_NAME) $(INSTALL_BIN)/$(REDIS_SENTINEL_NAME)
263