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 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 61bea60becSJohan Bergström FINAL_LIBS+= -ldl -lnsl -lsocket -lpthread 62bea60becSJohan Bergströmelse 63452dea30Santirezifeq ($(uname_S),Darwin) 64452dea30Santirez # Darwin (nothing to do) 65452dea30Santirezelse 66452dea30Santirez # All the other OSes (notably Linux) 67bea60becSJohan Bergström FINAL_LDFLAGS+= -rdynamic 68bea60becSJohan Bergström FINAL_LIBS+= -pthread 69caba5851SPieter Noordhuisendif 70452dea30Santirezendif 71caba5851SPieter Noordhuis 72caba5851SPieter Noordhuis# Include paths to dependencies 73caba5851SPieter NoordhuisFINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src 74caba5851SPieter Noordhuis 755bb2c88eSPieter Noordhuisifeq ($(MALLOC),tcmalloc) 76631539a5SPieter Noordhuis FINAL_CFLAGS+= -DUSE_TCMALLOC 77631539a5SPieter Noordhuis FINAL_LIBS+= -ltcmalloc 780a802bd7Santirezendif 7952825621SPieter Noordhuis 805bb2c88eSPieter Noordhuisifeq ($(MALLOC),tcmalloc_minimal) 81631539a5SPieter Noordhuis FINAL_CFLAGS+= -DUSE_TCMALLOC 82631539a5SPieter Noordhuis FINAL_LIBS+= -ltcmalloc_minimal 8352825621SPieter Noordhuisendif 8452825621SPieter Noordhuis 855bb2c88eSPieter Noordhuisifeq ($(MALLOC),jemalloc) 864b8a6394SPieter Noordhuis DEPENDENCY_TARGETS+= jemalloc 87631539a5SPieter Noordhuis FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include 88631539a5SPieter Noordhuis FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -ldl 8952825621SPieter Noordhuisendif 9052825621SPieter Noordhuis 91631539a5SPieter NoordhuisREDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS) 92631539a5SPieter NoordhuisREDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS) 936b5daa2dSantirezREDIS_INSTALL=$(QUIET_INSTALL)$(INSTALL) 94e2641e09Santirez 9535845afbSantirezCCCOLOR="\033[34m" 9635845afbSantirezLINKCOLOR="\033[34;1m" 9735845afbSantirezSRCCOLOR="\033[33m" 9835845afbSantirezBINCOLOR="\033[37;1m" 9935845afbSantirezMAKECOLOR="\033[32;1m" 10035845afbSantirezENDCOLOR="\033[0m" 10135845afbSantirez 10273e71867Santirezifndef V 1030a08d2b0SPieter NoordhuisQUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2; 1040a08d2b0SPieter NoordhuisQUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2; 1056b5daa2dSantirezQUIET_INSTALL = @printf ' %b %b\n' $(LINKCOLOR)INSTALL$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2; 10673e71867Santirezendif 10773e71867Santirez 108c18405c9SantirezREDIS_SERVER_NAME=redis-server 1096b5daa2dSantirezREDIS_SENTINEL_NAME=redis-sentinel 11082b672f6SantirezREDIS_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 1119c83aec9SantirezREDIS_CLI_NAME=redis-cli 1122f62c966SantirezREDIS_CLI_OBJ=anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o crc64.o 1139c83aec9SantirezREDIS_BENCHMARK_NAME=redis-benchmark 1149c83aec9SantirezREDIS_BENCHMARK_OBJ=ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o 1159c83aec9SantirezREDIS_CHECK_DUMP_NAME=redis-check-dump 11629c8cf01SantirezREDIS_CHECK_DUMP_OBJ=redis-check-dump.o lzf_c.o lzf_d.o crc64.o 1179c83aec9SantirezREDIS_CHECK_AOF_NAME=redis-check-aof 1189c83aec9SantirezREDIS_CHECK_AOF_OBJ=redis-check-aof.o 119e2641e09Santirez 1206b5daa2dSantirezall: $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME) 121c8061392SPieter Noordhuis @echo "" 122c8061392SPieter Noordhuis @echo "Hint: To run 'make test' is a good idea ;)" 123c8061392SPieter Noordhuis @echo "" 124e2641e09Santirez 1250a08d2b0SPieter Noordhuis.PHONY: all 1260a08d2b0SPieter Noordhuis 127e2641e09Santirez# Deps (use make dep to generate this) 1280a08d2b0SPieter Noordhuisinclude Makefile.dep 129e2641e09Santirez 1300a08d2b0SPieter Noordhuisdep: 1319c83aec9Santirez $(REDIS_CC) -MM *.c > Makefile.dep 132e2641e09Santirez 1330a08d2b0SPieter Noordhuis.PHONY: dep 134c8061392SPieter Noordhuis 1357e7b69feSPieter Noordhuispersist-settings: distclean 1367e7b69feSPieter Noordhuis echo STD=$(STD) >> .make-settings 1377e7b69feSPieter Noordhuis echo WARN=$(WARN) >> .make-settings 1387e7b69feSPieter Noordhuis echo OPT=$(OPT) >> .make-settings 1397e7b69feSPieter Noordhuis echo MALLOC=$(MALLOC) >> .make-settings 1407e7b69feSPieter Noordhuis echo CFLAGS=$(CFLAGS) >> .make-settings 1417e7b69feSPieter Noordhuis echo LDFLAGS=$(LDFLAGS) >> .make-settings 1427e7b69feSPieter Noordhuis echo REDIS_CFLAGS=$(REDIS_CFLAGS) >> .make-settings 1437e7b69feSPieter Noordhuis echo REDIS_LDFLAGS=$(REDIS_LDFLAGS) >> .make-settings 1447e7b69feSPieter Noordhuis echo PREV_FINAL_CFLAGS=$(FINAL_CFLAGS) >> .make-settings 1457e7b69feSPieter Noordhuis echo PREV_FINAL_LDFLAGS=$(FINAL_LDFLAGS) >> .make-settings 1467e7b69feSPieter Noordhuis -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS)) 1477e7b69feSPieter Noordhuis 1487e7b69feSPieter Noordhuis.PHONY: persist-settings 1497e7b69feSPieter Noordhuis 1500a08d2b0SPieter Noordhuis# Prerequisites target 1510a08d2b0SPieter Noordhuis.make-prerequisites: 15242c6a5daSPieter Noordhuis @touch $@ 1535bb2c88eSPieter Noordhuis 1547e7b69feSPieter Noordhuis# Clean everything, persist settings and build dependencies if anything changed 1557e7b69feSPieter Noordhuisifneq ($(strip $(PREV_FINAL_CFLAGS)), $(strip $(FINAL_CFLAGS))) 1567e7b69feSPieter Noordhuis.make-prerequisites: persist-settings 1570a08d2b0SPieter Noordhuisendif 158e2641e09Santirez 1597e7b69feSPieter Noordhuisifneq ($(strip $(PREV_FINAL_LDFLAGS)), $(strip $(FINAL_LDFLAGS))) 1607e7b69feSPieter Noordhuis.make-prerequisites: persist-settings 1610a08d2b0SPieter Noordhuisendif 162e2641e09Santirez 1630a08d2b0SPieter Noordhuis# redis-server 164c18405c9Santirez$(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ) 1656b5daa2dSantirez $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a $(FINAL_LIBS) 1666b5daa2dSantirez 1676b5daa2dSantirez# redis-sentinel 1686b5daa2dSantirez$(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME) 1696b5daa2dSantirez $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) 1707fc4ce13SPieter Noordhuis 1710a08d2b0SPieter Noordhuis# redis-cli 1729c83aec9Santirez$(REDIS_CLI_NAME): $(REDIS_CLI_OBJ) 173631539a5SPieter Noordhuis $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS) 174e2641e09Santirez 1750a08d2b0SPieter Noordhuis# redis-benchmark 1769c83aec9Santirez$(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ) 177631539a5SPieter Noordhuis $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS) 178e2641e09Santirez 1790a08d2b0SPieter Noordhuis# redis-check-dump 1809c83aec9Santirez$(REDIS_CHECK_DUMP_NAME): $(REDIS_CHECK_DUMP_OBJ) 181631539a5SPieter Noordhuis $(REDIS_LD) -o $@ $^ $(FINAL_LIBS) 182e2641e09Santirez 1830a08d2b0SPieter Noordhuis# redis-check-aof 1849c83aec9Santirez$(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ) 185631539a5SPieter Noordhuis $(REDIS_LD) -o $@ $^ $(FINAL_LIBS) 1860a08d2b0SPieter Noordhuis 1870a08d2b0SPieter Noordhuis# Because the jemalloc.h header is generated as a part of the jemalloc build, 1880a08d2b0SPieter Noordhuis# building it should complete before building any other object. Instead of 1890a08d2b0SPieter Noordhuis# depending on a single artifact, build all dependencies first. 19042c6a5daSPieter Noordhuis%.o: %.c .make-prerequisites 1919c83aec9Santirez $(REDIS_CC) -c $< 1924b8a6394SPieter Noordhuis 193e2641e09Santirezclean: 1946b5daa2dSantirez 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 1950a08d2b0SPieter Noordhuis 1960a08d2b0SPieter Noordhuis.PHONY: clean 1974b8a6394SPieter Noordhuis 1984b8a6394SPieter Noordhuisdistclean: clean 1994b8a6394SPieter Noordhuis -(cd ../deps && $(MAKE) distclean) 2000a08d2b0SPieter Noordhuis -(rm -f .make-*) 201e2641e09Santirez 2020a08d2b0SPieter Noordhuis.PHONY: distclean 203e2641e09Santirez 204c18405c9Santireztest: $(REDIS_SERVER_NAME) $(REDIS_CHECK_AOF_NAME) 205f790bd02Santirez @(cd ..; ./runtest) 206e2641e09Santirez 207*a89c8bb8Santireztest-sentinel: $(REDIS_SENTINEL_NAME) 208*a89c8bb8Santirez @(cd ..; ./runtest-sentinel) 209*a89c8bb8Santirez 210978c895bSJohan Bergströmcheck: test 211978c895bSJohan Bergström 212c35b4e84SPremysl Hrubylcov: 2130342dd76SPieter Noordhuis $(MAKE) gcov 214c35b4e84SPremysl Hruby @(set -e; cd ..; ./runtest --clients 1) 215c35b4e84SPremysl Hruby @geninfo -o redis.info . 216c35b4e84SPremysl Hruby @genhtml --legend -o lcov-html redis.info 217c35b4e84SPremysl Hruby 2180a08d2b0SPieter Noordhuis.PHONY: lcov 2190a08d2b0SPieter Noordhuis 2209c83aec9Santirezbench: $(REDIS_BENCHMARK_NAME) 2219c83aec9Santirez ./$(REDIS_BENCHMARK_NAME) 222e2641e09Santirez 223e2641e09Santirez32bit: 224e2641e09Santirez @echo "" 225e2641e09Santirez @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386" 226e2641e09Santirez @echo "" 22734c943b3SPieter Noordhuis $(MAKE) CFLAGS="-m32" LDFLAGS="-m32" 228e2641e09Santirez 229e2641e09Santirezgcov: 230631539a5SPieter Noordhuis $(MAKE) REDIS_CFLAGS="-fprofile-arcs -ftest-coverage -DCOVERAGE_TEST" REDIS_LDFLAGS="-fprofile-arcs -ftest-coverage" 231e2641e09Santirez 232e2641e09Santireznoopt: 2331a27d411Santirez $(MAKE) OPTIMIZATION="-O0" 2341a27d411Santirez 2351a27d411Santirezvalgrind: 2361a27d411Santirez $(MAKE) OPTIMIZATION="-O0" MALLOC="libc" 237e2641e09Santirez 238319bb48cSantirezsrc/help.h: 239319bb48cSantirez @../utils/generate-command-help.rb > help.h 240319bb48cSantirez 241acc01854Santirezinstall: all 242dc4003beSJohan Bergström @mkdir -p $(INSTALL_BIN) 2436b5daa2dSantirez $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(INSTALL_BIN) 2446b5daa2dSantirez $(REDIS_INSTALL) $(REDIS_BENCHMARK_NAME) $(INSTALL_BIN) 2456b5daa2dSantirez $(REDIS_INSTALL) $(REDIS_CLI_NAME) $(INSTALL_BIN) 2466b5daa2dSantirez $(REDIS_INSTALL) $(REDIS_CHECK_DUMP_NAME) $(INSTALL_BIN) 2476b5daa2dSantirez $(REDIS_INSTALL) $(REDIS_CHECK_AOF_NAME) $(INSTALL_BIN) 248