1*572c4311Sfengbojiang# Redis dependency Makefile 2*572c4311Sfengbojiang 3*572c4311Sfengbojianguname_S:= $(shell sh -c 'uname -s 2>/dev/null || echo not') 4*572c4311Sfengbojiang 5*572c4311SfengbojiangCCCOLOR="\033[34m" 6*572c4311SfengbojiangLINKCOLOR="\033[34;1m" 7*572c4311SfengbojiangSRCCOLOR="\033[33m" 8*572c4311SfengbojiangBINCOLOR="\033[37;1m" 9*572c4311SfengbojiangMAKECOLOR="\033[32;1m" 10*572c4311SfengbojiangENDCOLOR="\033[0m" 11*572c4311Sfengbojiang 12*572c4311Sfengbojiangdefault: 13*572c4311Sfengbojiang @echo "Explicit target required" 14*572c4311Sfengbojiang 15*572c4311Sfengbojiang.PHONY: default 16*572c4311Sfengbojiang 17*572c4311Sfengbojiang# Prerequisites target 18*572c4311Sfengbojiang.make-prerequisites: 19*572c4311Sfengbojiang @touch $@ 20*572c4311Sfengbojiang 21*572c4311Sfengbojiang# Clean everything when CFLAGS is different 22*572c4311Sfengbojiangifneq ($(shell sh -c '[ -f .make-cflags ] && cat .make-cflags || echo none'), $(CFLAGS)) 23*572c4311Sfengbojiang.make-cflags: distclean 24*572c4311Sfengbojiang -(echo "$(CFLAGS)" > .make-cflags) 25*572c4311Sfengbojiang.make-prerequisites: .make-cflags 26*572c4311Sfengbojiangendif 27*572c4311Sfengbojiang 28*572c4311Sfengbojiang# Clean everything when LDFLAGS is different 29*572c4311Sfengbojiangifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'), $(LDFLAGS)) 30*572c4311Sfengbojiang.make-ldflags: distclean 31*572c4311Sfengbojiang -(echo "$(LDFLAGS)" > .make-ldflags) 32*572c4311Sfengbojiang.make-prerequisites: .make-ldflags 33*572c4311Sfengbojiangendif 34*572c4311Sfengbojiang 35*572c4311Sfengbojiangdistclean: 36*572c4311Sfengbojiang -(cd hiredis && $(MAKE) clean) > /dev/null || true 37*572c4311Sfengbojiang -(cd linenoise && $(MAKE) clean) > /dev/null || true 38*572c4311Sfengbojiang -(cd lua && $(MAKE) clean) > /dev/null || true 39*572c4311Sfengbojiang -(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true 40*572c4311Sfengbojiang -(rm -f .make-*) 41*572c4311Sfengbojiang 42*572c4311Sfengbojiang.PHONY: distclean 43*572c4311Sfengbojiang 44*572c4311Sfengbojianghiredis: .make-prerequisites 45*572c4311Sfengbojiang @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 46*572c4311Sfengbojiang cd hiredis && $(MAKE) static 47*572c4311Sfengbojiang 48*572c4311Sfengbojiang.PHONY: hiredis 49*572c4311Sfengbojiang 50*572c4311Sfengbojianglinenoise: .make-prerequisites 51*572c4311Sfengbojiang @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 52*572c4311Sfengbojiang cd linenoise && $(MAKE) 53*572c4311Sfengbojiang 54*572c4311Sfengbojiang.PHONY: linenoise 55*572c4311Sfengbojiang 56*572c4311Sfengbojiangifeq ($(uname_S),SunOS) 57*572c4311Sfengbojiang # Make isinf() available 58*572c4311Sfengbojiang LUA_CFLAGS= -D__C99FEATURES__=1 59*572c4311Sfengbojiangendif 60*572c4311Sfengbojiang 61*572c4311SfengbojiangLUA_CFLAGS+= -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' $(CFLAGS) 62*572c4311SfengbojiangLUA_LDFLAGS+= $(LDFLAGS) 63*572c4311Sfengbojiang# lua's Makefile defines AR="ar rcu", which is unusual, and makes it more 64*572c4311Sfengbojiang# challenging to cross-compile lua (and redis). These defines make it easier 65*572c4311Sfengbojiang# to fit redis into cross-compilation environments, which typically set AR. 66*572c4311SfengbojiangAR=ar 67*572c4311SfengbojiangARFLAGS=rcu 68*572c4311Sfengbojiang 69*572c4311Sfengbojianglua: .make-prerequisites 70*572c4311Sfengbojiang @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 71*572c4311Sfengbojiang cd lua/src && $(MAKE) all CFLAGS="$(LUA_CFLAGS)" MYLDFLAGS="$(LUA_LDFLAGS)" AR="$(AR) $(ARFLAGS)" 72*572c4311Sfengbojiang 73*572c4311Sfengbojiang.PHONY: lua 74*572c4311Sfengbojiang 75*572c4311SfengbojiangJEMALLOC_CFLAGS= -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops $(CFLAGS) 76*572c4311SfengbojiangJEMALLOC_LDFLAGS= $(LDFLAGS) 77*572c4311Sfengbojiang 78*572c4311Sfengbojiangjemalloc: .make-prerequisites 79*572c4311Sfengbojiang @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 80*572c4311Sfengbojiang cd jemalloc && ./configure --with-version=5.1.0-0-g0 --with-lg-quantum=3 --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="$(JEMALLOC_CFLAGS)" LDFLAGS="$(JEMALLOC_LDFLAGS)" 81*572c4311Sfengbojiang cd jemalloc && $(MAKE) CFLAGS="$(JEMALLOC_CFLAGS)" LDFLAGS="$(JEMALLOC_LDFLAGS)" lib/libjemalloc.a 82*572c4311Sfengbojiang 83*572c4311Sfengbojiang.PHONY: jemalloc 84