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 4e2641e09Santirez 5e2641e09Santirezrelease_hdr := $(shell sh -c './mkreleasehdr.sh') 6e2641e09Santirezuname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') 7e2641e09SantirezOPTIMIZATION?=-O2 89e62dc17Santirez 99e62dc17Santirezifeq ($(uname_S),Linux) 109e62dc17Santirez ifneq ($(FORCE_LIBC_MALLOC),yes) 119e62dc17Santirez USE_JEMALLOC=yes 129e62dc17Santirez endif 139e62dc17Santirezendif 149e62dc17Santirez 15e2641e09Santirezifeq ($(uname_S),SunOS) 16e2641e09Santirez CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W -D__EXTENSIONS__ -D_XPG6 17e2641e09Santirez CCLINK?=-ldl -lnsl -lsocket -lm -lpthread 18ba559326SPieter Noordhuis DEBUG?=-g -ggdb 19e2641e09Santirezelse 20e2641e09Santirez CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -Wall -W $(ARCH) $(PROF) 21e2641e09Santirez CCLINK?=-lm -pthread 22ba559326SPieter Noordhuis DEBUG?=-g -rdynamic -ggdb 23e2641e09Santirezendif 240a802bd7Santirez 250a802bd7Santirezifeq ($(USE_TCMALLOC),yes) 269e62dc17Santirez ALLOD_DEPS= 2752825621SPieter Noordhuis ALLOC_LINK=-ltcmalloc 2852825621SPieter Noordhuis ALLOC_FLAGS=-DUSE_TCMALLOC 290a802bd7Santirezendif 3052825621SPieter Noordhuis 3152825621SPieter Noordhuisifeq ($(USE_TCMALLOC_MINIMAL),yes) 329e62dc17Santirez ALLOD_DEPS= 3352825621SPieter Noordhuis ALLOC_LINK=-ltcmalloc_minimal 3452825621SPieter Noordhuis ALLOC_FLAGS=-DUSE_TCMALLOC 3552825621SPieter Noordhuisendif 3652825621SPieter Noordhuis 3752825621SPieter Noordhuisifeq ($(USE_JEMALLOC),yes) 389e62dc17Santirez ALLOC_DEP=../deps/jemalloc/lib/libjemalloc.a 397d9ba156Santirez ALLOC_LINK=$(ALLOC_DEP) -ldl 409e62dc17Santirez ALLOC_FLAGS=-DUSE_JEMALLOC -I../deps/jemalloc/include 4152825621SPieter Noordhuisendif 4252825621SPieter Noordhuis 4352825621SPieter NoordhuisCCLINK+= $(ALLOC_LINK) 4452825621SPieter NoordhuisCFLAGS+= $(ALLOC_FLAGS) 4552825621SPieter Noordhuis 469e62dc17SantirezCCOPT= $(CFLAGS) $(ARCH) $(PROF) 47e2641e09Santirez 48e1386503SPedro MeloPREFIX= /usr/local 490997b411SPedro MeloINSTALL_BIN= $(PREFIX)/bin 50acc01854SantirezINSTALL= cp -p 51acc01854Santirez 5235845afbSantirezCCCOLOR="\033[34m" 5335845afbSantirezLINKCOLOR="\033[34;1m" 5435845afbSantirezSRCCOLOR="\033[33m" 5535845afbSantirezBINCOLOR="\033[37;1m" 5635845afbSantirezMAKECOLOR="\033[32;1m" 5735845afbSantirezENDCOLOR="\033[0m" 5835845afbSantirez 5973e71867Santirezifndef V 60db6cea11SHampus WessmanQUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR); 61db6cea11SHampus WessmanQUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR); 6273e71867Santirezendif 6373e71867Santirez 640681c5adSantirezOBJ = 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 slowlog.o scripting.o 65e2641e09SantirezBENCHOBJ = ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o 6611fd0c42SantirezCLIOBJ = anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o 67e2641e09SantirezCHECKDUMPOBJ = redis-check-dump.o lzf_c.o lzf_d.o 68e2641e09SantirezCHECKAOFOBJ = redis-check-aof.o 69e2641e09Santirez 70e2641e09SantirezPRGNAME = redis-server 71e2641e09SantirezBENCHPRGNAME = redis-benchmark 72e2641e09SantirezCLIPRGNAME = redis-cli 73e2641e09SantirezCHECKDUMPPRGNAME = redis-check-dump 74e2641e09SantirezCHECKAOFPRGNAME = redis-check-aof 75e2641e09Santirez 76240f8dbfSantirezall: redis-benchmark redis-cli redis-check-dump redis-check-aof redis-server 77c8061392SPieter Noordhuis @echo "" 78c8061392SPieter Noordhuis @echo "Hint: To run 'make test' is a good idea ;)" 79c8061392SPieter Noordhuis @echo "" 80e2641e09Santirez 81e2641e09Santirez# Deps (use make dep to generate this) 82e2641e09Santirezadlist.o: adlist.c adlist.h zmalloc.h 83e2641e09Santirezae.o: ae.c ae.h zmalloc.h config.h ae_kqueue.c 84e2641e09Santirezae_epoll.o: ae_epoll.c 85e2641e09Santirezae_kqueue.o: ae_kqueue.c 86e2641e09Santirezae_select.o: ae_select.c 87e2641e09Santirezanet.o: anet.c fmacros.h anet.h 888fedd04dSantirezaof.o: aof.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 89daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h 903e2a0bf4Santirezcluster.o: cluster.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 913e2a0bf4Santirez adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \ 92daa70b17Santirez slowlog.h 93daa70b17Santirezconfig.o: config.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 94daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h 95daa70b17Santirezcrc16.o: crc16.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 96daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h 97daa70b17Santirezdb.o: db.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 98daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h 99daa70b17Santirezdebug.o: debug.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 100daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h \ 1013e2a0bf4Santirez sha1.h 102daa70b17Santirezdict.o: dict.c fmacros.h dict.h zmalloc.h 1033e2a0bf4Santirezendian.o: endian.c 1043e2a0bf4Santirezintset.o: intset.c intset.h zmalloc.h endian.h 105e2641e09Santirezlzf_c.o: lzf_c.c lzfP.h 106e2641e09Santirezlzf_d.o: lzf_d.c lzfP.h 1078fedd04dSantirezmulti.o: multi.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 108daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h 1098fedd04dSantireznetworking.o: networking.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 110daa70b17Santirez adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \ 111daa70b17Santirez slowlog.h 1128fedd04dSantirezobject.o: object.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 113daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h 114e2641e09Santirezpqsort.o: pqsort.c 1158fedd04dSantirezpubsub.o: pubsub.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 116daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h 1178fedd04dSantirezrdb.o: rdb.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 118daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h \ 119daa70b17Santirez lzf.h 12033388d43Santirezredis-benchmark.o: redis-benchmark.c fmacros.h ae.h \ 12133388d43Santirez ../deps/hiredis/hiredis.h sds.h adlist.h zmalloc.h 122e2641e09Santirezredis-check-aof.o: redis-check-aof.c fmacros.h config.h 123e2641e09Santirezredis-check-dump.o: redis-check-dump.c lzf.h 12433388d43Santirezredis-cli.o: redis-cli.c fmacros.h version.h ../deps/hiredis/hiredis.h \ 12533388d43Santirez sds.h zmalloc.h ../deps/linenoise/linenoise.h help.h 1268fedd04dSantirezredis.o: redis.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 127daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h \ 1283e2a0bf4Santirez asciilogo.h 129e2641e09Santirezrelease.o: release.c release.h 1308fedd04dSantirezreplication.o: replication.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 131daa70b17Santirez adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \ 132daa70b17Santirez slowlog.h 133e2641e09Santirezsds.o: sds.c sds.h zmalloc.h 1343e2a0bf4Santirezsha1.o: sha1.c sha1.h config.h 135daa70b17Santirezslowlog.o: slowlog.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 136daa70b17Santirez adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \ 137daa70b17Santirez slowlog.h 1388fedd04dSantirezsort.o: sort.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 139daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h \ 140daa70b17Santirez pqsort.h 14133388d43Santirezsyncio.o: syncio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 142daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h 1438fedd04dSantirezt_hash.o: t_hash.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 144daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h 1458fedd04dSantirezt_list.o: t_list.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 146daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h 1478fedd04dSantirezt_set.o: t_set.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 148daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h 1498fedd04dSantirezt_string.o: t_string.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 150daa70b17Santirez adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h \ 151daa70b17Santirez slowlog.h 1528fedd04dSantirezt_zset.o: t_zset.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 153daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h 1543e2a0bf4Santirezutil.o: util.c fmacros.h util.h 1553e2a0bf4Santirezziplist.o: ziplist.c zmalloc.h util.h ziplist.h endian.h 1563e2a0bf4Santirezzipmap.o: zipmap.c zmalloc.h endian.h 1573e2a0bf4Santirezzmalloc.o: zmalloc.c config.h zmalloc.h 158e2641e09Santirez 1599e62dc17Santirez.PHONY: dependencies 160e2641e09Santirez 161c8061392SPieter Noordhuisdependencies: 162db6cea11SHampus Wessman @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)hiredis$(ENDCOLOR) 16335845afbSantirez @cd ../deps/hiredis && $(MAKE) static ARCH="$(ARCH)" 164db6cea11SHampus Wessman @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)linenoise$(ENDCOLOR) 16535845afbSantirez @cd ../deps/linenoise && $(MAKE) ARCH="$(ARCH)" 16621d3294cSantirez @echo $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)Lua ansi$(ENDCOLOR) 16721d3294cSantirez @cd ../deps/lua && $(MAKE) ARCH="$(ARCH)" ansi 168c8061392SPieter Noordhuis 1699e62dc17Santirez../deps/jemalloc/lib/libjemalloc.a: 170e93d36a6Santirez cd ../deps/jemalloc && ./configure $(JEMALLOC_CFLAGS) --with-jemalloc-prefix=je_ --enable-cc-silence && $(MAKE) lib/libjemalloc.a 1719e62dc17Santirez 172e2641e09Santirezredis-server: $(OBJ) 173331bf329Santirez $(QUIET_LINK)$(CC) -o $(PRGNAME) $(CCOPT) $(DEBUG) $(OBJ) $(CCLINK) $(ALLOC_LINK) ../deps/lua/src/liblua.a 174e2641e09Santirez 175c8061392SPieter Noordhuisredis-benchmark: dependencies $(BENCHOBJ) 17635845afbSantirez @cd ../deps/hiredis && $(MAKE) static 1779e62dc17Santirez $(QUIET_LINK)$(CC) -o $(BENCHPRGNAME) $(CCOPT) $(DEBUG) $(BENCHOBJ) ../deps/hiredis/libhiredis.a $(CCLINK) $(ALLOC_LINK) 178ec8f0667SPieter Noordhuis 179ec8f0667SPieter Noordhuisredis-benchmark.o: 18073e71867Santirez $(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis $(DEBUG) $(COMPILE_TIME) $< 181e2641e09Santirez 182c8061392SPieter Noordhuisredis-cli: dependencies $(CLIOBJ) 1839e62dc17Santirez $(QUIET_LINK)$(CC) -o $(CLIPRGNAME) $(CCOPT) $(DEBUG) $(CLIOBJ) ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(CCLINK) $(ALLOC_LINK) 1847fc4ce13SPieter Noordhuis 1857fc4ce13SPieter Noordhuisredis-cli.o: 18673e71867Santirez $(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis -I../deps/linenoise $(DEBUG) $(COMPILE_TIME) $< 187e2641e09Santirez 188e2641e09Santirezredis-check-dump: $(CHECKDUMPOBJ) 1899e62dc17Santirez $(QUIET_LINK)$(CC) -o $(CHECKDUMPPRGNAME) $(CCOPT) $(DEBUG) $(CHECKDUMPOBJ) $(CCLINK) $(ALLOC_LINK) 190e2641e09Santirez 191e2641e09Santirezredis-check-aof: $(CHECKAOFOBJ) 1929e62dc17Santirez $(QUIET_LINK)$(CC) -o $(CHECKAOFPRGNAME) $(CCOPT) $(DEBUG) $(CHECKAOFOBJ) $(CCLINK) $(ALLOC_LINK) 193e2641e09Santirez 1949e62dc17Santirez# Because the jemalloc.h header is generated as a part of the jemalloc build 1959e62dc17Santirez# process, building it should complete before building any other object. 1969e62dc17Santirez%.o: %.c $(ALLOC_DEP) 1970d1650f8Santirez $(QUIET_CC)$(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) -I../deps/lua/src $< 198e2641e09Santirez 199e2641e09Santirezclean: 200e2641e09Santirez rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) $(CHECKDUMPPRGNAME) $(CHECKAOFPRGNAME) *.o *.gcda *.gcno *.gcov 201319bb48cSantirez cd ../deps/hiredis && $(MAKE) $@ 202319bb48cSantirez cd ../deps/linenoise && $(MAKE) $@ 203319bb48cSantirez cd ../deps/lua && $(MAKE) $@ 204319bb48cSantirez -(cd ../deps/jemalloc && $(MAKE) distclean) 205e2641e09Santirez 206e2641e09Santirezdep: 20733388d43Santirez $(CC) -MM *.c -I ../deps/hiredis -I ../deps/linenoise 208e2641e09Santirez 209e6fcb5b3Santireztest: redis-server redis-check-aof 210*f790bd02Santirez @(cd ..; ./runtest) 211e2641e09Santirez 212e2641e09Santirezbench: 213e2641e09Santirez ./redis-benchmark 214e2641e09Santirez 215e2641e09Santirezlog: 21624110a4dSantirez git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog 217e2641e09Santirez 218e2641e09Santirez32bit: 219e2641e09Santirez @echo "" 220e2641e09Santirez @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386" 221e2641e09Santirez @echo "" 222e93d36a6Santirez $(MAKE) ARCH="-m32" JEMALLOC_CFLAGS='CFLAGS="-std=gnu99 -Wall -pipe -g3 -fvisibility=hidden -O3 -funroll-loops -m32"' 223e2641e09Santirez 224e2641e09Santirezgprof: 225a4e48b41SPieter Noordhuis $(MAKE) PROF="-pg" 226e2641e09Santirez 227e2641e09Santirezgcov: 228a4e48b41SPieter Noordhuis $(MAKE) PROF="-fprofile-arcs -ftest-coverage" 229e2641e09Santirez 230e2641e09Santireznoopt: 231a4e48b41SPieter Noordhuis $(MAKE) OPTIMIZATION="" 232e2641e09Santirez 233e2641e09Santirez32bitgprof: 234a4e48b41SPieter Noordhuis $(MAKE) PROF="-pg" ARCH="-arch i386" 235acc01854Santirez 236319bb48cSantirezsrc/help.h: 237319bb48cSantirez @../utils/generate-command-help.rb > help.h 238319bb48cSantirez 239acc01854Santirezinstall: all 240e984050fSPedro Melo mkdir -p $(INSTALL_BIN) 241acc01854Santirez $(INSTALL) $(PRGNAME) $(INSTALL_BIN) 242acc01854Santirez $(INSTALL) $(BENCHPRGNAME) $(INSTALL_BIN) 243acc01854Santirez $(INSTALL) $(CLIPRGNAME) $(INSTALL_BIN) 244acc01854Santirez $(INSTALL) $(CHECKDUMPPRGNAME) $(INSTALL_BIN) 245acc01854Santirez $(INSTALL) $(CHECKAOFPRGNAME) $(INSTALL_BIN) 246