2 # Copyright (C) 2010-2011 Salvatore Sanfilippo <antirez at gmail dot com>
3 # Copyright (C) 2010-2011 Pieter Noordhuis <pcnoordhuis at gmail dot com>
4 # This file is released under the BSD license, see the COPYING file
6 OBJ=net.o hiredis.o sds.o async.o
7 BINS=hiredis-example hiredis-test
13 # Fallback to gcc when $CC is not in $PATH.
14 CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
16 WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings
18 REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CFLAGS) $(WARNINGS) $(DEBUG) $(ARCH)
19 REAL_LDFLAGS=$(LDFLAGS) $(ARCH)
23 DYLIB_MINOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR).$(HIREDIS_MINOR)
24 DYLIB_MAJOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR)
25 DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX)
26 DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
27 STLIBNAME=$(LIBNAME).$(STLIBSUFFIX)
28 STLIB_MAKE_CMD=ar rcs $(STLIBNAME)
30 # Platform-specific overrides
31 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
32 ifeq ($(uname_S),SunOS)
33 REAL_LDFLAGS+= -ldl -lnsl -lsocket
34 DYLIB_MAKE_CMD=$(CC) -G -o $(DYLIBNAME) -h $(DYLIB_MINOR_NAME) $(LDFLAGS)
37 ifeq ($(uname_S),Darwin)
39 DYLIB_MINOR_NAME=$(LIBNAME).$(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(DYLIBSUFFIX)
40 DYLIB_MAJOR_NAME=$(LIBNAME).$(HIREDIS_MAJOR).$(DYLIBSUFFIX)
41 DYLIB_MAKE_CMD=$(CC) -shared -Wl,-install_name,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
44 all: $(DYLIBNAME) $(BINS)
46 # Deps (use make dep to generate this)
47 net.o: net.c fmacros.h net.h hiredis.h
48 async.o: async.c async.h hiredis.h sds.h dict.c dict.h
49 example.o: example.c hiredis.h
50 hiredis.o: hiredis.c fmacros.h hiredis.h net.h sds.h
52 test.o: test.c hiredis.h
55 $(DYLIB_MAKE_CMD) $(OBJ)
58 $(STLIB_MAKE_CMD) $(OBJ)
64 hiredis-example-libevent: example-libevent.c adapters/libevent.h $(STLIBNAME)
65 $(CC) -o $@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -levent example-libevent.c $(STLIBNAME)
67 hiredis-example-libev: example-libev.c adapters/libev.h $(STLIBNAME)
68 $(CC) -o $@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -lev example-libev.c $(STLIBNAME)
72 @echo "Please specify AE_DIR (e.g. <redis repository>/src)"
75 hiredis-example-ae: example-ae.c adapters/ae.h $(STLIBNAME)
76 $(CC) -o $@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I$(AE_DIR) $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o example-ae.c $(STLIBNAME)
79 hiredis-%: %.o $(STLIBNAME)
80 $(CC) -o $@ $(REAL_LDFLAGS) $< $(STLIBNAME)
88 "pidfile /tmp/hiredis-test-redis.pid\n" \
91 "unixsocket /tmp/hiredis-test-redis.sock" \
93 ./hiredis-test -h 127.0.0.1 -p 56379 -s /tmp/hiredis-test-redis.sock || \
94 ( kill `cat /tmp/hiredis-test-redis.pid` && false )
95 kill `cat /tmp/hiredis-test-redis.pid`
98 $(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $<
101 rm -rf $(DYLIBNAME) $(STLIBNAME) $(BINS) hiredis-example* *.o *.gcda *.gcno *.gcov
106 # Installation related variables and target
108 INCLUDE_PATH?=include/hiredis
110 INSTALL_INCLUDE_PATH= $(PREFIX)/$(INCLUDE_PATH)
111 INSTALL_LIBRARY_PATH= $(PREFIX)/$(LIBRARY_PATH)
113 ifeq ($(uname_S),SunOS)
119 install: $(DYLIBNAME) $(STLIBNAME)
120 mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH)
121 $(INSTALL) hiredis.h async.h adapters $(INSTALL_INCLUDE_PATH)
122 $(INSTALL) $(DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_MINOR_NAME)
123 cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MINOR_NAME) $(DYLIB_MAJOR_NAME)
124 cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MAJOR_NAME) $(DYLIBNAME)
125 $(INSTALL) $(STLIBNAME) $(INSTALL_LIBRARY_PATH)
129 @echo "WARNING: if this fails under Linux you probably need to install libc6-dev-i386"
131 $(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
134 $(MAKE) CFLAGS="-pg" LDFLAGS="-pg"
137 $(MAKE) CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs"
142 lcov -d . -c -o tmp/lcov/hiredis.info
143 genhtml --legend -o tmp/lcov/report tmp/lcov/hiredis.info
146 $(MAKE) OPTIMIZATION=""
148 .PHONY: all test check clean dep install 32bit gprof gcov noopt