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 22*7e3ccddcSantirezWARN=-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 497e7b69feSPieter Noordhuis# Override default settings if possible 507e7b69feSPieter Noordhuis-include .make-settings 517e7b69feSPieter Noordhuis 52caba5851SPieter NoordhuisFINAL_CFLAGS=$(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS) 53bea60becSJohan BergströmFINAL_LDFLAGS=$(LDFLAGS) $(REDIS_LDFLAGS) $(DEBUG) 54bea60becSJohan BergströmFINAL_LIBS=-lm 55bea60becSJohan BergströmDEBUG=-g -ggdb 56bea60becSJohan Bergström 57bea60becSJohan Bergströmifeq ($(uname_S),SunOS) 58452dea30Santirez # SunOS 598080e1cfSJohan Bergström INSTALL=cp -pf 60bea60becSJohan Bergström FINAL_CFLAGS+= -D__EXTENSIONS__ -D_XPG6 61951eefaeSNanXiao FINAL_LIBS+= -ldl -lnsl -lsocket -lresolv -lpthread 62bea60becSJohan Bergströmelse 63452dea30Santirezifeq ($(uname_S),Darwin) 64452dea30Santirez # Darwin (nothing to do) 65452dea30Santirezelse 66009cabf1Ssiahlifeq ($(uname_S),AIX) 67009cabf1Ssiahl # AIX 68009cabf1Ssiahl FINAL_LDFLAGS+= -Wl,-bexpall 69009cabf1Ssiahl FINAL_LIBS+= -pthread -lcrypt -lbsd 70009cabf1Ssiahl 71009cabf1Ssiahlelse 72452dea30Santirez # All the other OSes (notably Linux) 73bea60becSJohan Bergström FINAL_LDFLAGS+= -rdynamic 74bea60becSJohan Bergström FINAL_LIBS+= -pthread 75caba5851SPieter Noordhuisendif 76452dea30Santirezendif 77009cabf1Ssiahlendif 78caba5851SPieter Noordhuis# Include paths to dependencies 79caba5851SPieter NoordhuisFINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src 80caba5851SPieter Noordhuis 815bb2c88eSPieter Noordhuisifeq ($(MALLOC),tcmalloc) 82631539a5SPieter Noordhuis FINAL_CFLAGS+= -DUSE_TCMALLOC 83631539a5SPieter Noordhuis FINAL_LIBS+= -ltcmalloc 840a802bd7Santirezendif 8552825621SPieter Noordhuis 865bb2c88eSPieter Noordhuisifeq ($(MALLOC),tcmalloc_minimal) 87631539a5SPieter Noordhuis FINAL_CFLAGS+= -DUSE_TCMALLOC 88631539a5SPieter Noordhuis FINAL_LIBS+= -ltcmalloc_minimal 8952825621SPieter Noordhuisendif 9052825621SPieter Noordhuis 915bb2c88eSPieter Noordhuisifeq ($(MALLOC),jemalloc) 924b8a6394SPieter Noordhuis DEPENDENCY_TARGETS+= jemalloc 93631539a5SPieter Noordhuis FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include 94631539a5SPieter Noordhuis FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl 9552825621SPieter Noordhuisendif 9652825621SPieter Noordhuis 97631539a5SPieter NoordhuisREDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS) 98631539a5SPieter NoordhuisREDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS) 996b5daa2dSantirezREDIS_INSTALL=$(QUIET_INSTALL)$(INSTALL) 100e2641e09Santirez 10135845afbSantirezCCCOLOR="\033[34m" 10235845afbSantirezLINKCOLOR="\033[34;1m" 10335845afbSantirezSRCCOLOR="\033[33m" 10435845afbSantirezBINCOLOR="\033[37;1m" 10535845afbSantirezMAKECOLOR="\033[32;1m" 10635845afbSantirezENDCOLOR="\033[0m" 10735845afbSantirez 10873e71867Santirezifndef V 1090a08d2b0SPieter NoordhuisQUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2; 1100a08d2b0SPieter NoordhuisQUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2; 1116b5daa2dSantirezQUIET_INSTALL = @printf ' %b %b\n' $(LINKCOLOR)INSTALL$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2; 11273e71867Santirezendif 11373e71867Santirez 114c18405c9SantirezREDIS_SERVER_NAME=redis-server 1156b5daa2dSantirezREDIS_SENTINEL_NAME=redis-sentinel 116cc4df5a6SantirezREDIS_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 1179c83aec9SantirezREDIS_CLI_NAME=redis-cli 1182f62c966SantirezREDIS_CLI_OBJ=anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o crc64.o 1199c83aec9SantirezREDIS_BENCHMARK_NAME=redis-benchmark 1209c83aec9SantirezREDIS_BENCHMARK_OBJ=ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o 1219c83aec9SantirezREDIS_CHECK_DUMP_NAME=redis-check-dump 12229c8cf01SantirezREDIS_CHECK_DUMP_OBJ=redis-check-dump.o lzf_c.o lzf_d.o crc64.o 1239c83aec9SantirezREDIS_CHECK_AOF_NAME=redis-check-aof 1249c83aec9SantirezREDIS_CHECK_AOF_OBJ=redis-check-aof.o 125e2641e09Santirez 1266b5daa2dSantirezall: $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME) 127c8061392SPieter Noordhuis @echo "" 1287a2450a7SJoshua Anderson @echo "Hint: It's a good idea to run 'make test' ;)" 129c8061392SPieter Noordhuis @echo "" 130e2641e09Santirez 1310a08d2b0SPieter Noordhuis.PHONY: all 1320a08d2b0SPieter Noordhuis 133e2641e09Santirez# Deps (use make dep to generate this) 1340a08d2b0SPieter Noordhuisinclude Makefile.dep 135e2641e09Santirez 1360a08d2b0SPieter Noordhuisdep: 1379c83aec9Santirez $(REDIS_CC) -MM *.c > Makefile.dep 138e2641e09Santirez 1390a08d2b0SPieter Noordhuis.PHONY: dep 140c8061392SPieter Noordhuis 1417e7b69feSPieter Noordhuispersist-settings: distclean 1427e7b69feSPieter Noordhuis echo STD=$(STD) >> .make-settings 1437e7b69feSPieter Noordhuis echo WARN=$(WARN) >> .make-settings 1447e7b69feSPieter Noordhuis echo OPT=$(OPT) >> .make-settings 1457e7b69feSPieter Noordhuis echo MALLOC=$(MALLOC) >> .make-settings 1467e7b69feSPieter Noordhuis echo CFLAGS=$(CFLAGS) >> .make-settings 1477e7b69feSPieter Noordhuis echo LDFLAGS=$(LDFLAGS) >> .make-settings 1487e7b69feSPieter Noordhuis echo REDIS_CFLAGS=$(REDIS_CFLAGS) >> .make-settings 1497e7b69feSPieter Noordhuis echo REDIS_LDFLAGS=$(REDIS_LDFLAGS) >> .make-settings 1507e7b69feSPieter Noordhuis echo PREV_FINAL_CFLAGS=$(FINAL_CFLAGS) >> .make-settings 1517e7b69feSPieter Noordhuis echo PREV_FINAL_LDFLAGS=$(FINAL_LDFLAGS) >> .make-settings 1527e7b69feSPieter Noordhuis -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS)) 1537e7b69feSPieter Noordhuis 1547e7b69feSPieter Noordhuis.PHONY: persist-settings 1557e7b69feSPieter Noordhuis 1560a08d2b0SPieter Noordhuis# Prerequisites target 1570a08d2b0SPieter Noordhuis.make-prerequisites: 15842c6a5daSPieter Noordhuis @touch $@ 1595bb2c88eSPieter Noordhuis 1607e7b69feSPieter Noordhuis# Clean everything, persist settings and build dependencies if anything changed 1617e7b69feSPieter Noordhuisifneq ($(strip $(PREV_FINAL_CFLAGS)), $(strip $(FINAL_CFLAGS))) 1627e7b69feSPieter Noordhuis.make-prerequisites: persist-settings 1630a08d2b0SPieter Noordhuisendif 164e2641e09Santirez 1657e7b69feSPieter Noordhuisifneq ($(strip $(PREV_FINAL_LDFLAGS)), $(strip $(FINAL_LDFLAGS))) 1667e7b69feSPieter Noordhuis.make-prerequisites: persist-settings 1670a08d2b0SPieter Noordhuisendif 168e2641e09Santirez 1690a08d2b0SPieter Noordhuis# redis-server 170c18405c9Santirez$(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ) 1716b5daa2dSantirez $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a $(FINAL_LIBS) 1726b5daa2dSantirez 1736b5daa2dSantirez# redis-sentinel 1746b5daa2dSantirez$(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME) 1756b5daa2dSantirez $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) 1767fc4ce13SPieter Noordhuis 1770a08d2b0SPieter Noordhuis# redis-cli 1789c83aec9Santirez$(REDIS_CLI_NAME): $(REDIS_CLI_OBJ) 179631539a5SPieter Noordhuis $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS) 180e2641e09Santirez 1810a08d2b0SPieter Noordhuis# redis-benchmark 1829c83aec9Santirez$(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ) 183631539a5SPieter Noordhuis $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS) 184e2641e09Santirez 1850a08d2b0SPieter Noordhuis# redis-check-dump 1869c83aec9Santirez$(REDIS_CHECK_DUMP_NAME): $(REDIS_CHECK_DUMP_OBJ) 187631539a5SPieter Noordhuis $(REDIS_LD) -o $@ $^ $(FINAL_LIBS) 188e2641e09Santirez 1890a08d2b0SPieter Noordhuis# redis-check-aof 1909c83aec9Santirez$(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ) 191631539a5SPieter Noordhuis $(REDIS_LD) -o $@ $^ $(FINAL_LIBS) 1920a08d2b0SPieter Noordhuis 1930a08d2b0SPieter Noordhuis# Because the jemalloc.h header is generated as a part of the jemalloc build, 1940a08d2b0SPieter Noordhuis# building it should complete before building any other object. Instead of 1950a08d2b0SPieter Noordhuis# depending on a single artifact, build all dependencies first. 19642c6a5daSPieter Noordhuis%.o: %.c .make-prerequisites 1979c83aec9Santirez $(REDIS_CC) -c $< 1984b8a6394SPieter Noordhuis 199e2641e09Santirezclean: 2006b5daa2dSantirez 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 2010a08d2b0SPieter Noordhuis 2020a08d2b0SPieter Noordhuis.PHONY: clean 2034b8a6394SPieter Noordhuis 2044b8a6394SPieter Noordhuisdistclean: clean 2054b8a6394SPieter Noordhuis -(cd ../deps && $(MAKE) distclean) 2060a08d2b0SPieter Noordhuis -(rm -f .make-*) 207e2641e09Santirez 2080a08d2b0SPieter Noordhuis.PHONY: distclean 209e2641e09Santirez 210c18405c9Santireztest: $(REDIS_SERVER_NAME) $(REDIS_CHECK_AOF_NAME) 211f790bd02Santirez @(cd ..; ./runtest) 212e2641e09Santirez 213a89c8bb8Santireztest-sentinel: $(REDIS_SENTINEL_NAME) 214a89c8bb8Santirez @(cd ..; ./runtest-sentinel) 215a89c8bb8Santirez 216978c895bSJohan Bergströmcheck: test 217978c895bSJohan Bergström 218c35b4e84SPremysl Hrubylcov: 2190342dd76SPieter Noordhuis $(MAKE) gcov 220c35b4e84SPremysl Hruby @(set -e; cd ..; ./runtest --clients 1) 221c35b4e84SPremysl Hruby @geninfo -o redis.info . 222c35b4e84SPremysl Hruby @genhtml --legend -o lcov-html redis.info 223c35b4e84SPremysl Hruby 2240a08d2b0SPieter Noordhuis.PHONY: lcov 2250a08d2b0SPieter Noordhuis 2269c83aec9Santirezbench: $(REDIS_BENCHMARK_NAME) 2279c83aec9Santirez ./$(REDIS_BENCHMARK_NAME) 228e2641e09Santirez 229e2641e09Santirez32bit: 230e2641e09Santirez @echo "" 231e2641e09Santirez @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386" 232e2641e09Santirez @echo "" 23334c943b3SPieter Noordhuis $(MAKE) CFLAGS="-m32" LDFLAGS="-m32" 234e2641e09Santirez 235e2641e09Santirezgcov: 236631539a5SPieter Noordhuis $(MAKE) REDIS_CFLAGS="-fprofile-arcs -ftest-coverage -DCOVERAGE_TEST" REDIS_LDFLAGS="-fprofile-arcs -ftest-coverage" 237e2641e09Santirez 238e2641e09Santireznoopt: 2391a27d411Santirez $(MAKE) OPTIMIZATION="-O0" 2401a27d411Santirez 2411a27d411Santirezvalgrind: 2421a27d411Santirez $(MAKE) OPTIMIZATION="-O0" MALLOC="libc" 243e2641e09Santirez 244319bb48cSantirezsrc/help.h: 245319bb48cSantirez @../utils/generate-command-help.rb > help.h 246319bb48cSantirez 247acc01854Santirezinstall: all 248dc4003beSJohan Bergström @mkdir -p $(INSTALL_BIN) 2496b5daa2dSantirez $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(INSTALL_BIN) 2506b5daa2dSantirez $(REDIS_INSTALL) $(REDIS_BENCHMARK_NAME) $(INSTALL_BIN) 2516b5daa2dSantirez $(REDIS_INSTALL) $(REDIS_CLI_NAME) $(INSTALL_BIN) 2526b5daa2dSantirez $(REDIS_INSTALL) $(REDIS_CHECK_DUMP_NAME) $(INSTALL_BIN) 2536b5daa2dSantirez $(REDIS_INSTALL) $(REDIS_CHECK_AOF_NAME) $(INSTALL_BIN) 254