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 read.o
7 EXAMPLES=hiredis-example hiredis-example-libevent hiredis-example-libev hiredis-example-glib
10 PKGCONFNAME=hiredis.pc
12 HIREDIS_MAJOR=$(shell grep HIREDIS_MAJOR hiredis.h | awk '{print $$3}')
13 HIREDIS_MINOR=$(shell grep HIREDIS_MINOR hiredis.h | awk '{print $$3}')
14 HIREDIS_PATCH=$(shell grep HIREDIS_PATCH hiredis.h | awk '{print $$3}')
15 HIREDIS_SONAME=$(shell grep HIREDIS_SONAME hiredis.h | awk '{print $$3}')
17 # Installation related variables and target
19 INCLUDE_PATH?=include/hiredis
21 PKGCONF_PATH?=pkgconfig
22 INSTALL_INCLUDE_PATH= $(DESTDIR)$(PREFIX)/$(INCLUDE_PATH)
23 INSTALL_LIBRARY_PATH= $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH)
24 INSTALL_PKGCONF_PATH= $(INSTALL_LIBRARY_PATH)/$(PKGCONF_PATH)
26 # redis-server configuration used for testing
28 REDIS_SERVER=redis-server
29 define REDIS_TEST_CONFIG
31 pidfile /tmp/hiredis-test-redis.pid
34 unixsocket /tmp/hiredis-test-redis.sock
36 export REDIS_TEST_CONFIG
38 # Fallback to gcc when $CC is not in $PATH.
39 CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
40 CXX:=$(shell sh -c 'type $(CXX) >/dev/null 2>/dev/null && echo $(CXX) || echo g++')
42 WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings
44 REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CFLAGS) $(WARNINGS) $(DEBUG) $(ARCH)
45 REAL_LDFLAGS=$(LDFLAGS) $(ARCH)
49 DYLIB_MINOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_SONAME)
50 DYLIB_MAJOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR)
51 DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX)
52 DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
53 STLIBNAME=$(LIBNAME).$(STLIBSUFFIX)
54 STLIB_MAKE_CMD=ar rcs $(STLIBNAME)
56 # Platform-specific overrides
57 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
58 ifeq ($(uname_S),SunOS)
59 REAL_LDFLAGS+= -ldl -lnsl -lsocket
60 DYLIB_MAKE_CMD=$(CC) -G -o $(DYLIBNAME) -h $(DYLIB_MINOR_NAME) $(LDFLAGS)
63 ifeq ($(uname_S),Darwin)
65 DYLIB_MINOR_NAME=$(LIBNAME).$(HIREDIS_SONAME).$(DYLIBSUFFIX)
66 DYLIB_MAKE_CMD=$(CC) -shared -Wl,-install_name,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
69 all: $(DYLIBNAME) $(STLIBNAME) hiredis-test $(PKGCONFNAME)
71 # Deps (use make dep to generate this)
72 async.o: async.c fmacros.h async.h hiredis.h read.h sds.h net.h dict.c dict.h
73 dict.o: dict.c fmacros.h dict.h
74 hiredis.o: hiredis.c fmacros.h hiredis.h read.h sds.h net.h
75 net.o: net.c fmacros.h net.h hiredis.h read.h sds.h
76 read.o: read.c fmacros.h read.h sds.h
78 test.o: test.c fmacros.h hiredis.h read.h sds.h
81 $(DYLIB_MAKE_CMD) $(OBJ)
84 $(STLIB_MAKE_CMD) $(OBJ)
90 hiredis-example-libevent: examples/example-libevent.c adapters/libevent.h $(STLIBNAME)
91 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -levent $(STLIBNAME)
93 hiredis-example-libev: examples/example-libev.c adapters/libev.h $(STLIBNAME)
94 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -lev $(STLIBNAME)
96 hiredis-example-glib: examples/example-glib.c adapters/glib.h $(STLIBNAME)
97 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) $(shell pkg-config --cflags --libs glib-2.0) -I. $< $(STLIBNAME)
99 hiredis-example-ivykis: examples/example-ivykis.c adapters/ivykis.h $(STLIBNAME)
100 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -livykis $(STLIBNAME)
102 hiredis-example-macosx: examples/example-macosx.c adapters/macosx.h $(STLIBNAME)
103 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -framework CoreFoundation $(STLIBNAME)
107 @echo "Please specify AE_DIR (e.g. <redis repository>/src)"
110 hiredis-example-ae: examples/example-ae.c adapters/ae.h $(STLIBNAME)
111 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(AE_DIR) $< $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o $(AE_DIR)/../deps/jemalloc/lib/libjemalloc.a -pthread $(STLIBNAME)
115 hiredis-example-libuv:
116 @echo "Please specify LIBUV_DIR (e.g. ../libuv/)"
119 hiredis-example-libuv: examples/example-libuv.c adapters/libuv.h $(STLIBNAME)
120 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(LIBUV_DIR)/include $< $(LIBUV_DIR)/.libs/libuv.a -lpthread -lrt $(STLIBNAME)
123 ifeq ($(and $(QT_MOC),$(QT_INCLUDE_DIR),$(QT_LIBRARY_DIR)),)
125 @echo "Please specify QT_MOC, QT_INCLUDE_DIR AND QT_LIBRARY_DIR"
128 hiredis-example-qt: examples/example-qt.cpp adapters/qt.h $(STLIBNAME)
129 $(QT_MOC) adapters/qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \
130 $(CXX) -x c++ -o qt-adapter-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore
131 $(QT_MOC) examples/example-qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \
132 $(CXX) -x c++ -o qt-example-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore
133 $(CXX) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore -L$(QT_LIBRARY_DIR) qt-adapter-moc.o qt-example-moc.o $< -pthread $(STLIBNAME) -lQtCore
136 hiredis-example: examples/example.c $(STLIBNAME)
137 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< $(STLIBNAME)
139 examples: $(EXAMPLES)
141 hiredis-test: test.o $(STLIBNAME)
143 hiredis-%: %.o $(STLIBNAME)
144 $(CC) $(REAL_CFLAGS) -o $@ $(REAL_LDFLAGS) $< $(STLIBNAME)
150 @echo "$$REDIS_TEST_CONFIG" | $(REDIS_SERVER) -
151 $(PRE) ./hiredis-test -h 127.0.0.1 -p $(REDIS_PORT) -s /tmp/hiredis-test-redis.sock || \
152 ( kill `cat /tmp/hiredis-test-redis.pid` && false )
153 kill `cat /tmp/hiredis-test-redis.pid`
156 $(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $<
159 rm -rf $(DYLIBNAME) $(STLIBNAME) $(TESTS) $(PKGCONFNAME) examples/hiredis-example* *.o *.gcda *.gcno *.gcov
164 ifeq ($(uname_S),SunOS)
170 $(PKGCONFNAME): hiredis.h
171 @echo "Generating $@ for pkgconfig..."
172 @echo prefix=$(PREFIX) > $@
173 @echo exec_prefix=\$${prefix} >> $@
174 @echo libdir=$(PREFIX)/$(LIBRARY_PATH) >> $@
175 @echo includedir=$(PREFIX)/$(INCLUDE_PATH) >> $@
177 @echo Name: hiredis >> $@
178 @echo Description: Minimalistic C client library for Redis. >> $@
179 @echo Version: $(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(HIREDIS_PATCH) >> $@
180 @echo Libs: -L\$${libdir} -lhiredis >> $@
181 @echo Cflags: -I\$${includedir} -D_FILE_OFFSET_BITS=64 >> $@
183 install: $(DYLIBNAME) $(STLIBNAME) $(PKGCONFNAME)
184 mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH)
185 $(INSTALL) hiredis.h async.h read.h sds.h adapters $(INSTALL_INCLUDE_PATH)
186 $(INSTALL) $(DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_MINOR_NAME)
187 cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MINOR_NAME) $(DYLIBNAME)
188 $(INSTALL) $(STLIBNAME) $(INSTALL_LIBRARY_PATH)
189 mkdir -p $(INSTALL_PKGCONF_PATH)
190 $(INSTALL) $(PKGCONFNAME) $(INSTALL_PKGCONF_PATH)
194 @echo "WARNING: if this fails under Linux you probably need to install libc6-dev-i386"
196 $(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
203 $(MAKE) CFLAGS="-pg" LDFLAGS="-pg"
206 $(MAKE) CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs"
211 lcov -d . -c -o tmp/lcov/hiredis.info
212 genhtml --legend -o tmp/lcov/report tmp/lcov/hiredis.info
215 $(MAKE) OPTIMIZATION=""
217 .PHONY: all test check clean dep install 32bit 32bit-vars gprof gcov noopt