Back to home page

Redis cross reference

 
 

    


0001 # Redis Makefile
0002 # Copyright (C) 2009 Salvatore Sanfilippo <antirez at gmail dot com>
0003 # This file is released under the BSD license, see the COPYING file
0004 #
0005 # The Makefile composes the final FINAL_CFLAGS and FINAL_LDFLAGS using
0006 # what is needed for Redis plus the standard CFLAGS and LDFLAGS passed.
0007 # However when building the dependencies (Jemalloc, Lua, Hiredis, ...)
0008 # CFLAGS and LDFLAGS are propagated to the dependencies, so to pass
0009 # flags only to be used when compiling / linking Redis itself REDIS_CFLAGS
0010 # and REDIS_LDFLAGS are used instead (this is the case of 'make gcov').
0011 #
0012 # Dependencies are stored in the Makefile.dep file. To rebuild this file
0013 # Just use 'make dep', but this is only needed by developers.
0014 
0015 release_hdr := $(shell sh -c './mkreleasehdr.sh')
0016 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
0017 OPTIMIZATION?=-O2
0018 DEPENDENCY_TARGETS=hiredis linenoise lua
0019 
0020 # Default settings
0021 STD= -std=c99 -pedantic
0022 WARN= -Wall
0023 OPT= $(OPTIMIZATION)
0024 
0025 # Default allocator
0026 ifeq ($(uname_S),Linux)
0027   MALLOC=jemalloc
0028 else
0029   MALLOC=libc
0030 endif
0031 
0032 # Backwards compatibility for selecting an allocator
0033 ifeq ($(USE_TCMALLOC),yes)
0034   MALLOC=tcmalloc
0035 endif
0036 
0037 ifeq ($(USE_TCMALLOC_MINIMAL),yes)
0038   MALLOC=tcmalloc_minimal
0039 endif
0040 
0041 ifeq ($(USE_JEMALLOC),yes)
0042   MALLOC=jemalloc
0043 endif
0044 
0045 # Override default settings if possible
0046  (uname_S),SunOS)
0047   FINAL_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS) -D__EXTENSIONS__ -D_XPG6
0048   FINAL_LDFLAGS= $(LDFLAGS) $(REDIS_LDFLAGS) -g -ggdb
0049   FINAL_LIBS= -ldl -lnsl -lsocket -lm -lpthread
0050   DEBUG= -g -ggdb
0051 else
0052   FINAL_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS)
0053   FINAL_LDFLAGS= $(LDFLAGS) $(REDIS_LDFLAGS) -g -rdynamic -ggdb
0054   FINAL_LIBS= -lm -pthread
0055   DEBUG= -g -rdynamic -ggdb
0056 endif
0057 
0058 # Include paths to dependencies
0059 FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src
0060 
0061 ifeq ($(MALLOC),tcmalloc)
0062   FINAL_CFLAGS+= -DUSE_TCMALLOC
0063   FINAL_LIBS+= -ltcmalloc
0064 endif
0065 
0066 ifeq ($(MALLOC),tcmalloc_minimal)
0067   FINAL_CFLAGS+= -DUSE_TCMALLOC
0068   FINAL_LIBS+= -ltcmalloc_minimal
0069 endif
0070 
0071 ifeq ($(MALLOC),jemalloc)
0072   DEPENDENCY_TARGETS+= jemalloc
0073   FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/
0074 (QUIET_CC)$(CC) $(FINAL_CFLAGS)
0075 REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS)
0076 REDIS_INSTALL=$(QUIET_INSTALL)$(INSTALL)
0077 
0078 PREFIX?=/usr/local
0079 INSTALL_BIN= $(PREFIX)/bin
0080 INSTALL= cp -pf
0081 
0082 CCCOLOR="\033[34m"
0083 LINKCOLOR="\033[34;1m"
0084 SRCCOLOR="\033[33m"
0085 BINCOLOR="\033[37;1m"
0086 MAKECOLOR="\033[32;1m"
0087 ENDCOLOR="\033[0m"
0088 
0089 ifndef V
0090 QUIET_CC = @printf '    %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2;
0091 QUIET_LINK = @printf '    %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
0092 QUIET_INSTALL = @printf '    %b %b\n' $(LINKCOLOR)INSTALL$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
0093 endif
0094 
0095 REDIS_SERVER_NAME= redis-server
0096 REDIS_SENTINEL_NAME= redis-sentinel
0097 REDIS_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 migrate.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o bitops.o sentinel.o
0098 REDIS_CLI_NAME= redis-cli
0099 REDIS_CLI_OBJ= anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o
0100 REDIS_BENCHMARK_NAME= redis-benchmark
0101 REDIS_BENCHMARK_OBJ= ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o redis-benchmark.o
0102 REDIS_CHECK_DUMP_NAME= redis-check-dump
0103 REDIS_CHECK_DUMP_OBJ= redis-check-dump.o lzf_c.o lzf_d.o crc64.o
0104 REDIS_CHECK_AOF_NAME= redis-check-aof
0105 REDIS_CHECK_AOF_OBJ= redis-check-aof.o
0106 
0107 all: $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_DUMP_NAME) $(REDIS_CHECK_AOF_NAME)
0108         @echo ""
0109         @echo "Hint: To run 'make test' is a good idea ;)"
0110         @echo ""
0111 
0112 .PHONY: all
0113 
0114 # Deps (use make dep to generate this)
0115         (REDIS_CC) -MM *.c > Makefile.dep
0116 
0117 .PHONY: dep
0118 
0119 persist-settings: distclean
0120         echo STD=$(STD) >> .make-settings
0121         echo WARN=$(WARN) >> .make-settings
0122         echo OPT=$(OPT) >> .make-settings
0123         echo MALLOC=$(MALLOC) >> .make-settings
0124         echo CFLAGS=$(CFLAGS) >> .make-settings
0125         echo LDFLAGS=$(LDFLAGS) >> .make-settings
0126         echo REDIS_CFLAGS=$(REDIS_CFLAGS) >> .make-settings
0127         echo REDIS_LDFLAGS=$(REDIS_LDFLAGS) >> .make-settings
0128         echo PREV_FINAL_CFLAGS=$(FINAL_CFLAGS) >> .make-settings
0129         echo PREV_FINAL_LDFLAGS=$(FINAL_LDFLAGS) >> .make-settings
0130         -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS))
0131 
0132 .PHONY: persist-settings
0133 
0134 # Prerequisites target
0135 .make-prerequisites:
0136         @touch $@
0137 
0138 # Clean everything, persist settings and build dependencies if anything changed
0139 ifneq ($(strip $(PREV_FINAL_CFLAGS)), $(strip $(FINAL_CFLAGS)))
0140 .make-prerequisites: persist-settings
0141 endif
0142 
0143 ifneq ($(strip $(PREV_FINAL_LDFLAGS)), $(strip $(FINAL_LDFLAGS)))
0144 .make-prerequisites: persist-settings
0145 endif
0146 
0147 # redis-server
0148 $(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ)
0149         $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a $(FINAL_LIBS)
0150 
0151 # redis-sentinel
0152 $(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME)
0153         $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME)
0154 
0155 # redis-cli
0156 $(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
0157         $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS)
0158 
0159 # redis-benchmark
0160 $(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
0161         $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS)
0162 
0163 # redis-check-dump
0164 $(REDIS_CHECK_DUMP_NAME): $(REDIS_CHECK_DUMP_OBJ)
0165         $(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
0166 
0167 # redis-check-aof
0168 $(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ)
0169         $(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
0170 
0171 # Because the jemalloc.h header is generated as a part of the jemalloc build,
0172 # building it should complete before building any other object. Instead of
0173 # depending on a single artifact, build all dependencies first.
0174 %.o: %.c .make-prerequisites
0175         $(REDIS_CC) -c $<
0176 
0177 clean:
0178         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
0179 
0180 .PHONY: clean
0181 
0182 distclean: clean
0183         -(cd ../deps && $(MAKE) distclean)
0184         -(rm -f .make-*)
0185 
0186 .PHONY: distclean
0187 
0188 test: $(REDIS_SERVER_NAME) $(REDIS_CHECK_AOF_NAME)
0189         @(cd ..; ./runtest)
0190 
0191 lcov:
0192         $(MAKE) gcov
0193         @(set -e; cd ..; ./runtest --clients 1)
0194         @geninfo -o redis.info .
0195         @genhtml --legend -o lcov-html redis.info
0196 
0197 .PHONY: lcov
0198 
0199 bench: $(REDIS_BENCHMARK_NAME)
0200         ./$(REDIS_BENCHMARK_NAME)
0201 
0202 32bit:
0203         @echo ""
0204         @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
0205         @echo ""
0206         $(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
0207 
0208 gcov:
0209         $(MAKE) REDIS_CFLAGS="-fprofile-arcs -ftest-coverage -DCOVERAGE_TEST" REDIS_LDFLAGS="-fprofile-arcs -ftest-coverage"
0210 
0211 noopt:
0212         $(MAKE) OPTIMIZATION="-O0"
0213 
0214 valgrind:
0215         $(MAKE) OPTIMIZATION="-O0" MALLOC="libc"
0216 
0217 src/help.h:
0218         @../utils/generate-command-help.rb > help.h
0219 
0220 install: all
0221         mkdir -p $(INSTALL_BIN)
0222         $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(INSTALL_BIN)
0223         $(REDIS_INSTALL) $(REDIS_BENCHMARK_NAME) $(INSTALL_BIN)
0224         $(REDIS_INSTALL) $(REDIS_CLI_NAME) $(INSTALL_BIN)
0225         $(REDIS_INSTALL) $(REDIS_CHECK_DUMP_NAME) $(INSTALL_BIN)
0226         $(REDIS_INSTALL) $(REDIS_CHECK_AOF_NAME) $(INSTALL_BIN)