1# Redis Makefile 2# Copyright (C) 2009 Salvatore Sanfilippo <antirez at gmail dot com> 3# This file is released under the BSD license, see the COPYING file 4 5release_hdr := $(shell sh -c './mkreleasehdr.sh') 6uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') 7OPTIMIZATION?=-O2 8 9ifeq ($(uname_S),Linux) 10 ifneq ($(FORCE_LIBC_MALLOC),yes) 11 USE_JEMALLOC=yes 12 endif 13endif 14 15ifeq ($(uname_S),SunOS) 16 CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W -D__EXTENSIONS__ -D_XPG6 17 CCLINK?=-ldl -lnsl -lsocket -lm -lpthread 18 DEBUG?=-g -ggdb 19else 20 CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W $(ARCH) $(PROF) 21 CCLINK?=-lm -pthread 22 DEBUG?=-g -rdynamic -ggdb 23endif 24 25ifeq ($(USE_TCMALLOC),yes) 26 ALLOD_DEPS= 27 ALLOC_LINK=-ltcmalloc 28 ALLOC_FLAGS=-DUSE_TCMALLOC 29endif 30 31ifeq ($(USE_TCMALLOC_MINIMAL),yes) 32 ALLOD_DEPS= 33 ALLOC_LINK=-ltcmalloc_minimal 34 ALLOC_FLAGS=-DUSE_TCMALLOC 35endif 36 37ifeq ($(USE_JEMALLOC),yes) 38 ALLOC_DEP=../deps/jemalloc/lib/libjemalloc.a 39 ALLOC_LINK=$(ALLOC_DEP) -ldl 40 ALLOC_FLAGS=-DUSE_JEMALLOC -I../deps/jemalloc/include 41endif 42 43CCLINK+= $(ALLOC_LINK) 44CFLAGS+= $(ALLOC_FLAGS) 45 46CCOPT= $(CFLAGS) $(ARCH) $(PROF) 47 48PREFIX= /usr/local 49INSTALL_BIN= $(PREFIX)/bin 50INSTALL= cp -p 51 52CCCOLOR="\033[34m" 53LINKCOLOR="\033[34;1m" 54SRCCOLOR="\033[33m" 55BINCOLOR="\033[37;1m" 56MAKECOLOR="\033[32;1m" 57ENDCOLOR="\033[0m" 58 59ifndef V 60QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR); 61QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR); 62endif 63 64OBJ = 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 endian.o 65BENCHOBJ = ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o 66CLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o 67CHECKDUMPOBJ = redis-check-dump.o lzf_c.o lzf_d.o 68CHECKAOFOBJ = redis-check-aof.o 69 70PRGNAME = redis-server 71BENCHPRGNAME = redis-benchmark 72CLIPRGNAME = redis-cli 73CHECKDUMPPRGNAME = redis-check-dump 74CHECKAOFPRGNAME = redis-check-aof 75 76all: redis-benchmark redis-cli redis-check-dump redis-check-aof redis-server 77 @echo "" 78 @echo "Hint: To run 'make test' is a good idea ;)" 79 @echo "" 80 81# Deps (use make dep to generate this) 82adlist.o: adlist.c adlist.h zmalloc.h 83ae.o: ae.c ae.h zmalloc.h config.h ae_kqueue.c 84ae_epoll.o: ae_epoll.c 85ae_kqueue.o: ae_kqueue.c 86ae_select.o: ae_select.c 87anet.o: anet.c fmacros.h anet.h 88aof.o: aof.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 89 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 90cluster.o: cluster.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 91 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 92config.o: config.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 93 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 94crc16.o: crc16.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 95 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 96db.o: db.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 97 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 98debug.o: debug.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 99 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h sha1.h 100dict.o: dict.c fmacros.h dict.h zmalloc.h 101diskstore.o: diskstore.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 102 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \ 103 sha1.h 104dscache.o: dscache.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 105 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 106endian.o: endian.c 107intset.o: intset.c intset.h zmalloc.h endian.h 108lzf_c.o: lzf_c.c lzfP.h 109lzf_d.o: lzf_d.c lzfP.h 110multi.o: multi.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 111 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 112networking.o: networking.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 113 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 114object.o: object.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 115 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 116pqsort.o: pqsort.c 117pubsub.o: pubsub.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 118 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 119rdb.o: rdb.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 120 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h lzf.h 121redis-benchmark.o: redis-benchmark.c fmacros.h ae.h \ 122 ../deps/hiredis/hiredis.h sds.h adlist.h zmalloc.h 123redis-check-aof.o: redis-check-aof.c fmacros.h config.h 124redis-check-dump.o: redis-check-dump.c lzf.h 125redis-cli.o: redis-cli.c fmacros.h version.h ../deps/hiredis/hiredis.h \ 126 sds.h zmalloc.h ../deps/linenoise/linenoise.h help.h 127redis.o: redis.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 128 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \ 129 asciilogo.h 130release.o: release.c release.h 131replication.o: replication.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 132 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 133sds.o: sds.c sds.h zmalloc.h 134sha1.o: sha1.c sha1.h config.h 135sort.o: sort.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 136 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h pqsort.h 137syncio.o: syncio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 138 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 139t_hash.o: t_hash.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 140 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 141t_list.o: t_list.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 142 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 143t_set.o: t_set.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 144 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 145t_string.o: t_string.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 146 adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 147t_zset.o: t_zset.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 148 zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 149util.o: util.c fmacros.h util.h 150ziplist.o: ziplist.c zmalloc.h util.h ziplist.h endian.h 151zipmap.o: zipmap.c zmalloc.h endian.h 152zmalloc.o: zmalloc.c config.h zmalloc.h 153 154.PHONY: dependencies 155 156dependencies: 157 @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)hiredis$(ENDCOLOR) 158 @cd ../deps/hiredis && $(MAKE) static ARCH="$(ARCH)" 159 @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)linenoise$(ENDCOLOR) 160 @cd ../deps/linenoise && $(MAKE) ARCH="$(ARCH)" 161 162../deps/jemalloc/lib/libjemalloc.a: 163 cd ../deps/jemalloc && ./configure $(JEMALLOC_CFLAGS) --with-jemalloc-prefix=je_ --enable-cc-silence && $(MAKE) lib/libjemalloc.a 164 165redis-server: $(OBJ) 166 $(QUIET_CC)$(CC) -o $(PRGNAME) $(CCOPT) $(DEBUG) $(OBJ) $(CCLINK) $(ALLOC_LINK) 167 168redis-benchmark: dependencies $(BENCHOBJ) 169 @cd ../deps/hiredis && $(MAKE) static 170 $(QUIET_LINK)$(CC) -o $(BENCHPRGNAME) $(CCOPT) $(DEBUG) $(BENCHOBJ) ../deps/hiredis/libhiredis.a $(CCLINK) $(ALLOC_LINK) 171 172redis-benchmark.o: 173 $(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis $(DEBUG) $(COMPILE_TIME) $< 174 175redis-cli: dependencies $(CLIOBJ) 176 $(QUIET_LINK)$(CC) -o $(CLIPRGNAME) $(CCOPT) $(DEBUG) $(CLIOBJ) ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(CCLINK) $(ALLOC_LINK) 177 178redis-cli.o: 179 $(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis -I../deps/linenoise $(DEBUG) $(COMPILE_TIME) $< 180 181redis-check-dump: $(CHECKDUMPOBJ) 182 $(QUIET_LINK)$(CC) -o $(CHECKDUMPPRGNAME) $(CCOPT) $(DEBUG) $(CHECKDUMPOBJ) $(CCLINK) $(ALLOC_LINK) 183 184redis-check-aof: $(CHECKAOFOBJ) 185 $(QUIET_LINK)$(CC) -o $(CHECKAOFPRGNAME) $(CCOPT) $(DEBUG) $(CHECKAOFOBJ) $(CCLINK) $(ALLOC_LINK) 186 187# Because the jemalloc.h header is generated as a part of the jemalloc build 188# process, building it should complete before building any other object. 189%.o: %.c $(ALLOC_DEP) 190 $(QUIET_CC)$(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) $< 191 192clean: 193 rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) $(CHECKDUMPPRGNAME) $(CHECKAOFPRGNAME) *.o *.gcda *.gcno *.gcov 194 195dep: 196 $(CC) -MM *.c -I ../deps/hiredis -I ../deps/linenoise 197 198test: redis-server 199 (cd ..; tclsh8.5 tests/test_helper.tcl --tags "${TAGS}" --file "${FILE}") 200 201bench: 202 ./redis-benchmark 203 204log: 205 git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog 206 20732bit: 208 @echo "" 209 @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386" 210 @echo "" 211 $(MAKE) ARCH="-m32" JEMALLOC_CFLAGS='CFLAGS="-std=gnu99 -Wall -pipe -g3 -fvisibility=hidden -O3 -funroll-loops -m32"' 212 213gprof: 214 $(MAKE) PROF="-pg" 215 216gcov: 217 $(MAKE) PROF="-fprofile-arcs -ftest-coverage" 218 219noopt: 220 $(MAKE) OPTIMIZATION="" 221 22232bitgprof: 223 $(MAKE) PROF="-pg" ARCH="-arch i386" 224 225install: all 226 mkdir -p $(INSTALL_BIN) 227 $(INSTALL) $(PRGNAME) $(INSTALL_BIN) 228 $(INSTALL) $(BENCHPRGNAME) $(INSTALL_BIN) 229 $(INSTALL) $(CLIPRGNAME) $(INSTALL_BIN) 230 $(INSTALL) $(CHECKDUMPPRGNAME) $(INSTALL_BIN) 231 $(INSTALL) $(CHECKAOFPRGNAME) $(INSTALL_BIN) 232