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 6402925dd9SantirezOBJ = 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 bio.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 \ 89*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 90*b147cb9eSantirezbio.o: bio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 91*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h bio.h 923e2a0bf4Santirezcluster.o: cluster.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 93*b147cb9eSantirez adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 94daa70b17Santirezconfig.o: config.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 95*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 96daa70b17Santirezcrc16.o: crc16.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 97*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 98daa70b17Santirezdb.o: db.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 99*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 100daa70b17Santirezdebug.o: debug.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 101*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 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 \ 108*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 1098fedd04dSantireznetworking.o: networking.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 110*b147cb9eSantirez adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 1118fedd04dSantirezobject.o: object.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 112*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 113e2641e09Santirezpqsort.o: pqsort.c 1148fedd04dSantirezpubsub.o: pubsub.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 115*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 1168fedd04dSantirezrdb.o: rdb.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 117*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h lzf.h 11833388d43Santirezredis-benchmark.o: redis-benchmark.c fmacros.h ae.h \ 11933388d43Santirez ../deps/hiredis/hiredis.h sds.h adlist.h zmalloc.h 120e2641e09Santirezredis-check-aof.o: redis-check-aof.c fmacros.h config.h 121e2641e09Santirezredis-check-dump.o: redis-check-dump.c lzf.h 12233388d43Santirezredis-cli.o: redis-cli.c fmacros.h version.h ../deps/hiredis/hiredis.h \ 12333388d43Santirez sds.h zmalloc.h ../deps/linenoise/linenoise.h help.h 1248fedd04dSantirezredis.o: redis.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 125daa70b17Santirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h slowlog.h \ 126*b147cb9eSantirez bio.h asciilogo.h 127e2641e09Santirezrelease.o: release.c release.h 1288fedd04dSantirezreplication.o: replication.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 129*b147cb9eSantirez adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 130*b147cb9eSantirezscripting.o: scripting.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 \ 132*b147cb9eSantirez sha1.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 \ 139*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h pqsort.h 14033388d43Santirezsyncio.o: syncio.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 141*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 1428fedd04dSantirezt_hash.o: t_hash.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 143*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 1448fedd04dSantirezt_list.o: t_list.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 145*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 1468fedd04dSantirezt_set.o: t_set.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 147*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 1488fedd04dSantirezt_string.o: t_string.c redis.h fmacros.h config.h ae.h sds.h dict.h \ 149*b147cb9eSantirez adlist.h zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 1508fedd04dSantirezt_zset.o: t_zset.c redis.h fmacros.h config.h ae.h sds.h dict.h adlist.h \ 151*b147cb9eSantirez zmalloc.h anet.h zipmap.h ziplist.h intset.h version.h util.h 1523e2a0bf4Santirezutil.o: util.c fmacros.h util.h 1533e2a0bf4Santirezziplist.o: ziplist.c zmalloc.h util.h ziplist.h endian.h 1543e2a0bf4Santirezzipmap.o: zipmap.c zmalloc.h endian.h 1553e2a0bf4Santirezzmalloc.o: zmalloc.c config.h zmalloc.h 156e2641e09Santirez 1579e62dc17Santirez.PHONY: dependencies 158e2641e09Santirez 159c8061392SPieter Noordhuisdependencies: 160db6cea11SHampus Wessman @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)hiredis$(ENDCOLOR) 16135845afbSantirez @cd ../deps/hiredis && $(MAKE) static ARCH="$(ARCH)" 162db6cea11SHampus Wessman @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)linenoise$(ENDCOLOR) 16335845afbSantirez @cd ../deps/linenoise && $(MAKE) ARCH="$(ARCH)" 16421d3294cSantirez @echo $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)Lua ansi$(ENDCOLOR) 16521d3294cSantirez @cd ../deps/lua && $(MAKE) ARCH="$(ARCH)" ansi 166c8061392SPieter Noordhuis 1679e62dc17Santirez../deps/jemalloc/lib/libjemalloc.a: 168e93d36a6Santirez cd ../deps/jemalloc && ./configure $(JEMALLOC_CFLAGS) --with-jemalloc-prefix=je_ --enable-cc-silence && $(MAKE) lib/libjemalloc.a 1699e62dc17Santirez 1704d6bf65cSPieter Noordhuisredis-server: dependencies $(OBJ) 171331bf329Santirez $(QUIET_LINK)$(CC) -o $(PRGNAME) $(CCOPT) $(DEBUG) $(OBJ) $(CCLINK) $(ALLOC_LINK) ../deps/lua/src/liblua.a 172e2641e09Santirez 173c8061392SPieter Noordhuisredis-benchmark: dependencies $(BENCHOBJ) 17435845afbSantirez @cd ../deps/hiredis && $(MAKE) static 1759e62dc17Santirez $(QUIET_LINK)$(CC) -o $(BENCHPRGNAME) $(CCOPT) $(DEBUG) $(BENCHOBJ) ../deps/hiredis/libhiredis.a $(CCLINK) $(ALLOC_LINK) 176ec8f0667SPieter Noordhuis 177ec8f0667SPieter Noordhuisredis-benchmark.o: 17873e71867Santirez $(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis $(DEBUG) $(COMPILE_TIME) $< 179e2641e09Santirez 180c8061392SPieter Noordhuisredis-cli: dependencies $(CLIOBJ) 1819e62dc17Santirez $(QUIET_LINK)$(CC) -o $(CLIPRGNAME) $(CCOPT) $(DEBUG) $(CLIOBJ) ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(CCLINK) $(ALLOC_LINK) 1827fc4ce13SPieter Noordhuis 1837fc4ce13SPieter Noordhuisredis-cli.o: 18473e71867Santirez $(QUIET_CC)$(CC) -c $(CFLAGS) -I../deps/hiredis -I../deps/linenoise $(DEBUG) $(COMPILE_TIME) $< 185e2641e09Santirez 186e2641e09Santirezredis-check-dump: $(CHECKDUMPOBJ) 1879e62dc17Santirez $(QUIET_LINK)$(CC) -o $(CHECKDUMPPRGNAME) $(CCOPT) $(DEBUG) $(CHECKDUMPOBJ) $(CCLINK) $(ALLOC_LINK) 188e2641e09Santirez 189e2641e09Santirezredis-check-aof: $(CHECKAOFOBJ) 1909e62dc17Santirez $(QUIET_LINK)$(CC) -o $(CHECKAOFPRGNAME) $(CCOPT) $(DEBUG) $(CHECKAOFOBJ) $(CCLINK) $(ALLOC_LINK) 191e2641e09Santirez 1929e62dc17Santirez# Because the jemalloc.h header is generated as a part of the jemalloc build 1939e62dc17Santirez# process, building it should complete before building any other object. 1949e62dc17Santirez%.o: %.c $(ALLOC_DEP) 1950d1650f8Santirez $(QUIET_CC)$(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) -I../deps/lua/src $< 196e2641e09Santirez 197e2641e09Santirezclean: 198e2641e09Santirez rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) $(CHECKDUMPPRGNAME) $(CHECKAOFPRGNAME) *.o *.gcda *.gcno *.gcov 199319bb48cSantirez cd ../deps/hiredis && $(MAKE) $@ 200319bb48cSantirez cd ../deps/linenoise && $(MAKE) $@ 201319bb48cSantirez cd ../deps/lua && $(MAKE) $@ 202319bb48cSantirez -(cd ../deps/jemalloc && $(MAKE) distclean) 203e2641e09Santirez 204e2641e09Santirezdep: 20533388d43Santirez $(CC) -MM *.c -I ../deps/hiredis -I ../deps/linenoise 206e2641e09Santirez 207e6fcb5b3Santireztest: redis-server redis-check-aof 208f790bd02Santirez @(cd ..; ./runtest) 209e2641e09Santirez 210e2641e09Santirezbench: 211e2641e09Santirez ./redis-benchmark 212e2641e09Santirez 213e2641e09Santirezlog: 21424110a4dSantirez git log '--pretty=format:%ad %s (%cn)' --date=short > ../Changelog 215e2641e09Santirez 216e2641e09Santirez32bit: 217e2641e09Santirez @echo "" 218e2641e09Santirez @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386" 219e2641e09Santirez @echo "" 220e93d36a6Santirez $(MAKE) ARCH="-m32" JEMALLOC_CFLAGS='CFLAGS="-std=gnu99 -Wall -pipe -g3 -fvisibility=hidden -O3 -funroll-loops -m32"' 221e2641e09Santirez 222e2641e09Santirezgprof: 223a4e48b41SPieter Noordhuis $(MAKE) PROF="-pg" 224e2641e09Santirez 225e2641e09Santirezgcov: 226a4e48b41SPieter Noordhuis $(MAKE) PROF="-fprofile-arcs -ftest-coverage" 227e2641e09Santirez 228e2641e09Santireznoopt: 229a4e48b41SPieter Noordhuis $(MAKE) OPTIMIZATION="" 230e2641e09Santirez 231e2641e09Santirez32bitgprof: 232a4e48b41SPieter Noordhuis $(MAKE) PROF="-pg" ARCH="-arch i386" 233acc01854Santirez 234319bb48cSantirezsrc/help.h: 235319bb48cSantirez @../utils/generate-command-help.rb > help.h 236319bb48cSantirez 237acc01854Santirezinstall: all 238e984050fSPedro Melo mkdir -p $(INSTALL_BIN) 239acc01854Santirez $(INSTALL) $(PRGNAME) $(INSTALL_BIN) 240acc01854Santirez $(INSTALL) $(BENCHPRGNAME) $(INSTALL_BIN) 241acc01854Santirez $(INSTALL) $(CLIPRGNAME) $(INSTALL_BIN) 242acc01854Santirez $(INSTALL) $(CHECKDUMPPRGNAME) $(INSTALL_BIN) 243acc01854Santirez $(INSTALL) $(CHECKAOFPRGNAME) $(INSTALL_BIN) 244