2
0

Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. # Hiredis Makefile
  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
  5. OBJ=alloc.o net.o hiredis.o sds.o async.o read.o sockcompat.o
  6. SSL_OBJ=ssl.o
  7. EXAMPLES=hiredis-example hiredis-example-libevent hiredis-example-libev hiredis-example-glib hiredis-example-push
  8. ifeq ($(USE_SSL),1)
  9. EXAMPLES+=hiredis-example-ssl hiredis-example-libevent-ssl
  10. endif
  11. TESTS=hiredis-test
  12. LIBNAME=libhiredis
  13. PKGCONFNAME=hiredis.pc
  14. SSL_LIBNAME=libhiredis_ssl
  15. SSL_PKGCONFNAME=hiredis_ssl.pc
  16. HIREDIS_MAJOR=$(shell grep HIREDIS_MAJOR hiredis.h | awk '{print $$3}')
  17. HIREDIS_MINOR=$(shell grep HIREDIS_MINOR hiredis.h | awk '{print $$3}')
  18. HIREDIS_PATCH=$(shell grep HIREDIS_PATCH hiredis.h | awk '{print $$3}')
  19. HIREDIS_SONAME=$(shell grep HIREDIS_SONAME hiredis.h | awk '{print $$3}')
  20. # Installation related variables and target
  21. PREFIX?=/usr/local
  22. INCLUDE_PATH?=include/hiredis
  23. LIBRARY_PATH?=lib
  24. PKGCONF_PATH?=pkgconfig
  25. INSTALL_INCLUDE_PATH= $(DESTDIR)$(PREFIX)/$(INCLUDE_PATH)
  26. INSTALL_LIBRARY_PATH= $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH)
  27. INSTALL_PKGCONF_PATH= $(INSTALL_LIBRARY_PATH)/$(PKGCONF_PATH)
  28. # redis-server configuration used for testing
  29. REDIS_PORT=56379
  30. REDIS_SERVER=redis-server
  31. define REDIS_TEST_CONFIG
  32. daemonize yes
  33. pidfile /tmp/hiredis-test-redis.pid
  34. port $(REDIS_PORT)
  35. bind 127.0.0.1
  36. unixsocket /tmp/hiredis-test-redis.sock
  37. endef
  38. export REDIS_TEST_CONFIG
  39. # Fallback to gcc when $CC is not in $PATH.
  40. CC:=$(shell sh -c 'type $${CC%% *} >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
  41. CXX:=$(shell sh -c 'type $${CXX%% *} >/dev/null 2>/dev/null && echo $(CXX) || echo g++')
  42. OPTIMIZATION?=-O3
  43. WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers
  44. DEBUG_FLAGS?= -g -ggdb
  45. REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CPPFLAGS) $(CFLAGS) $(WARNINGS) $(DEBUG_FLAGS)
  46. REAL_LDFLAGS=$(LDFLAGS)
  47. DYLIBSUFFIX=so
  48. STLIBSUFFIX=a
  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)
  53. STLIBNAME=$(LIBNAME).$(STLIBSUFFIX)
  54. STLIB_MAKE_CMD=$(AR) rcs
  55. SSL_DYLIB_MINOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_SONAME)
  56. SSL_DYLIB_MAJOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR)
  57. SSL_DYLIBNAME=$(SSL_LIBNAME).$(DYLIBSUFFIX)
  58. SSL_STLIBNAME=$(SSL_LIBNAME).$(STLIBSUFFIX)
  59. SSL_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(SSL_DYLIB_MINOR_NAME)
  60. # Platform-specific overrides
  61. uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
  62. USE_SSL?=0
  63. # This is required for test.c only
  64. ifeq ($(USE_SSL),1)
  65. CFLAGS+=-DHIREDIS_TEST_SSL
  66. endif
  67. ifeq ($(uname_S),Linux)
  68. ifdef OPENSSL_PREFIX
  69. CFLAGS+=-I$(OPENSSL_PREFIX)/include
  70. SSL_LDFLAGS+=-L$(OPENSSL_PREFIX)/lib -lssl -lcrypto
  71. else
  72. SSL_LDFLAGS=-lssl -lcrypto
  73. endif
  74. else
  75. OPENSSL_PREFIX?=/usr/local/opt/openssl
  76. CFLAGS+=-I$(OPENSSL_PREFIX)/include
  77. SSL_LDFLAGS+=-L$(OPENSSL_PREFIX)/lib -lssl -lcrypto
  78. endif
  79. ifeq ($(uname_S),SunOS)
  80. IS_SUN_CC=$(shell sh -c '$(CC) -V 2>&1 |egrep -i -c "sun|studio"')
  81. ifeq ($(IS_SUN_CC),1)
  82. SUN_SHARED_FLAG=-G
  83. else
  84. SUN_SHARED_FLAG=-shared
  85. endif
  86. REAL_LDFLAGS+= -ldl -lnsl -lsocket
  87. DYLIB_MAKE_CMD=$(CC) $(SUN_SHARED_FLAG) -o $(DYLIBNAME) -h $(DYLIB_MINOR_NAME) $(LDFLAGS)
  88. SSL_DYLIB_MAKE_CMD=$(CC) $(SUN_SHARED_FLAG) -o $(SSL_DYLIBNAME) -h $(SSL_DYLIB_MINOR_NAME) $(LDFLAGS) $(SSL_LDFLAGS)
  89. endif
  90. ifeq ($(uname_S),Darwin)
  91. DYLIBSUFFIX=dylib
  92. DYLIB_MINOR_NAME=$(LIBNAME).$(HIREDIS_SONAME).$(DYLIBSUFFIX)
  93. DYLIB_MAKE_CMD=$(CC) -dynamiclib -Wl,-install_name,$(PREFIX)/$(LIBRARY_PATH)/$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
  94. SSL_DYLIB_MAKE_CMD=$(CC) -dynamiclib -Wl,-install_name,$(PREFIX)/$(LIBRARY_PATH)/$(SSL_DYLIB_MINOR_NAME) -o $(SSL_DYLIBNAME) $(LDFLAGS) $(SSL_LDFLAGS)
  95. DYLIB_PLUGIN=-Wl,-undefined -Wl,dynamic_lookup
  96. endif
  97. all: $(DYLIBNAME) $(STLIBNAME) hiredis-test $(PKGCONFNAME)
  98. ifeq ($(USE_SSL),1)
  99. all: $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(SSL_PKGCONFNAME)
  100. endif
  101. # Deps (use make dep to generate this)
  102. alloc.o: alloc.c fmacros.h alloc.h
  103. async.o: async.c fmacros.h alloc.h async.h hiredis.h read.h sds.h net.h dict.c dict.h win32.h async_private.h
  104. dict.o: dict.c fmacros.h alloc.h dict.h
  105. hiredis.o: hiredis.c fmacros.h hiredis.h read.h sds.h alloc.h net.h async.h win32.h
  106. net.o: net.c fmacros.h net.h hiredis.h read.h sds.h alloc.h sockcompat.h win32.h
  107. read.o: read.c fmacros.h alloc.h read.h sds.h win32.h
  108. sds.o: sds.c sds.h sdsalloc.h alloc.h
  109. sockcompat.o: sockcompat.c sockcompat.h
  110. ssl.o: ssl.c hiredis.h read.h sds.h alloc.h async.h win32.h async_private.h
  111. test.o: test.c fmacros.h hiredis.h read.h sds.h alloc.h net.h sockcompat.h win32.h
  112. $(DYLIBNAME): $(OBJ)
  113. $(DYLIB_MAKE_CMD) -o $(DYLIBNAME) $(OBJ) $(REAL_LDFLAGS)
  114. $(STLIBNAME): $(OBJ)
  115. $(STLIB_MAKE_CMD) $(STLIBNAME) $(OBJ)
  116. $(SSL_DYLIBNAME): $(SSL_OBJ)
  117. $(SSL_DYLIB_MAKE_CMD) $(DYLIB_PLUGIN) -o $(SSL_DYLIBNAME) $(SSL_OBJ) $(REAL_LDFLAGS) $(LDFLAGS) $(SSL_LDFLAGS)
  118. $(SSL_STLIBNAME): $(SSL_OBJ)
  119. $(STLIB_MAKE_CMD) $(SSL_STLIBNAME) $(SSL_OBJ)
  120. dynamic: $(DYLIBNAME)
  121. static: $(STLIBNAME)
  122. ifeq ($(USE_SSL),1)
  123. dynamic: $(SSL_DYLIBNAME)
  124. static: $(SSL_STLIBNAME)
  125. endif
  126. # Binaries:
  127. hiredis-example-libevent: examples/example-libevent.c adapters/libevent.h $(STLIBNAME)
  128. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -levent $(STLIBNAME) $(REAL_LDFLAGS)
  129. hiredis-example-libevent-ssl: examples/example-libevent-ssl.c adapters/libevent.h $(STLIBNAME) $(SSL_STLIBNAME)
  130. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -levent $(STLIBNAME) $(SSL_STLIBNAME) $(REAL_LDFLAGS) $(SSL_LDFLAGS)
  131. hiredis-example-libev: examples/example-libev.c adapters/libev.h $(STLIBNAME)
  132. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -lev $(STLIBNAME) $(REAL_LDFLAGS)
  133. hiredis-example-glib: examples/example-glib.c adapters/glib.h $(STLIBNAME)
  134. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(shell pkg-config --cflags --libs glib-2.0) $(STLIBNAME) $(REAL_LDFLAGS)
  135. hiredis-example-ivykis: examples/example-ivykis.c adapters/ivykis.h $(STLIBNAME)
  136. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -livykis $(STLIBNAME) $(REAL_LDFLAGS)
  137. hiredis-example-macosx: examples/example-macosx.c adapters/macosx.h $(STLIBNAME)
  138. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -framework CoreFoundation $(STLIBNAME) $(REAL_LDFLAGS)
  139. hiredis-example-ssl: examples/example-ssl.c $(STLIBNAME) $(SSL_STLIBNAME)
  140. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(SSL_STLIBNAME) $(REAL_LDFLAGS) $(SSL_LDFLAGS)
  141. ifndef AE_DIR
  142. hiredis-example-ae:
  143. @echo "Please specify AE_DIR (e.g. <redis repository>/src)"
  144. @false
  145. else
  146. hiredis-example-ae: examples/example-ae.c adapters/ae.h $(STLIBNAME)
  147. $(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)
  148. endif
  149. ifndef LIBUV_DIR
  150. hiredis-example-libuv:
  151. @echo "Please specify LIBUV_DIR (e.g. ../libuv/)"
  152. @false
  153. else
  154. hiredis-example-libuv: examples/example-libuv.c adapters/libuv.h $(STLIBNAME)
  155. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. -I$(LIBUV_DIR)/include $< $(LIBUV_DIR)/.libs/libuv.a -lpthread -lrt $(STLIBNAME) $(REAL_LDFLAGS)
  156. endif
  157. ifeq ($(and $(QT_MOC),$(QT_INCLUDE_DIR),$(QT_LIBRARY_DIR)),)
  158. hiredis-example-qt:
  159. @echo "Please specify QT_MOC, QT_INCLUDE_DIR AND QT_LIBRARY_DIR"
  160. @false
  161. else
  162. hiredis-example-qt: examples/example-qt.cpp adapters/qt.h $(STLIBNAME)
  163. $(QT_MOC) adapters/qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \
  164. $(CXX) -x c++ -o qt-adapter-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore
  165. $(QT_MOC) examples/example-qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \
  166. $(CXX) -x c++ -o qt-example-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore
  167. $(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
  168. endif
  169. hiredis-example: examples/example.c $(STLIBNAME)
  170. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(REAL_LDFLAGS)
  171. hiredis-example-push: examples/example-push.c $(STLIBNAME)
  172. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(REAL_LDFLAGS)
  173. examples: $(EXAMPLES)
  174. TEST_LIBS = $(STLIBNAME)
  175. ifeq ($(USE_SSL),1)
  176. TEST_LIBS += $(SSL_STLIBNAME)
  177. TEST_LDFLAGS = $(SSL_LDFLAGS) -lssl -lcrypto -lpthread
  178. endif
  179. hiredis-test: test.o $(TEST_LIBS)
  180. $(CC) -o $@ $(REAL_CFLAGS) -I. $^ $(REAL_LDFLAGS) $(TEST_LDFLAGS)
  181. hiredis-%: %.o $(STLIBNAME)
  182. $(CC) $(REAL_CFLAGS) -o $@ $< $(TEST_LIBS) $(REAL_LDFLAGS)
  183. test: hiredis-test
  184. ./hiredis-test
  185. check: hiredis-test
  186. TEST_SSL=$(USE_SSL) ./test.sh
  187. .c.o:
  188. $(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $<
  189. clean:
  190. rm -rf $(DYLIBNAME) $(STLIBNAME) $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(TESTS) $(PKGCONFNAME) examples/hiredis-example* *.o *.gcda *.gcno *.gcov
  191. dep:
  192. $(CC) $(CPPFLAGS) $(CFLAGS) -MM *.c
  193. INSTALL?= cp -pPR
  194. $(PKGCONFNAME): hiredis.h
  195. @echo "Generating $@ for pkgconfig..."
  196. @echo prefix=$(PREFIX) > $@
  197. @echo exec_prefix=\$${prefix} >> $@
  198. @echo libdir=$(PREFIX)/$(LIBRARY_PATH) >> $@
  199. @echo includedir=$(PREFIX)/$(INCLUDE_PATH) >> $@
  200. @echo >> $@
  201. @echo Name: hiredis >> $@
  202. @echo Description: Minimalistic C client library for Redis. >> $@
  203. @echo Version: $(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(HIREDIS_PATCH) >> $@
  204. @echo Libs: -L\$${libdir} -lhiredis >> $@
  205. @echo Cflags: -I\$${includedir} -D_FILE_OFFSET_BITS=64 >> $@
  206. $(SSL_PKGCONFNAME): hiredis_ssl.h
  207. @echo "Generating $@ for pkgconfig..."
  208. @echo prefix=$(PREFIX) > $@
  209. @echo exec_prefix=\$${prefix} >> $@
  210. @echo libdir=$(PREFIX)/$(LIBRARY_PATH) >> $@
  211. @echo includedir=$(PREFIX)/$(INCLUDE_PATH) >> $@
  212. @echo >> $@
  213. @echo Name: hiredis_ssl >> $@
  214. @echo Description: SSL Support for hiredis. >> $@
  215. @echo Version: $(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(HIREDIS_PATCH) >> $@
  216. @echo Requires: hiredis >> $@
  217. @echo Libs: -L\$${libdir} -lhiredis_ssl >> $@
  218. @echo Libs.private: -lssl -lcrypto >> $@
  219. install: $(DYLIBNAME) $(STLIBNAME) $(PKGCONFNAME)
  220. mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_INCLUDE_PATH)/adapters $(INSTALL_LIBRARY_PATH)
  221. $(INSTALL) hiredis.h async.h read.h sds.h alloc.h $(INSTALL_INCLUDE_PATH)
  222. $(INSTALL) adapters/*.h $(INSTALL_INCLUDE_PATH)/adapters
  223. $(INSTALL) $(DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_MINOR_NAME)
  224. cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MINOR_NAME) $(DYLIBNAME)
  225. $(INSTALL) $(STLIBNAME) $(INSTALL_LIBRARY_PATH)
  226. mkdir -p $(INSTALL_PKGCONF_PATH)
  227. $(INSTALL) $(PKGCONFNAME) $(INSTALL_PKGCONF_PATH)
  228. ifeq ($(USE_SSL),1)
  229. install: install-ssl
  230. install-ssl: $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(SSL_PKGCONFNAME)
  231. mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH)
  232. $(INSTALL) hiredis_ssl.h $(INSTALL_INCLUDE_PATH)
  233. $(INSTALL) $(SSL_DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(SSL_DYLIB_MINOR_NAME)
  234. cd $(INSTALL_LIBRARY_PATH) && ln -sf $(SSL_DYLIB_MINOR_NAME) $(SSL_DYLIBNAME)
  235. $(INSTALL) $(SSL_STLIBNAME) $(INSTALL_LIBRARY_PATH)
  236. mkdir -p $(INSTALL_PKGCONF_PATH)
  237. $(INSTALL) $(SSL_PKGCONFNAME) $(INSTALL_PKGCONF_PATH)
  238. endif
  239. 32bit:
  240. @echo ""
  241. @echo "WARNING: if this fails under Linux you probably need to install libc6-dev-i386"
  242. @echo ""
  243. $(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
  244. 32bit-vars:
  245. $(eval CFLAGS=-m32)
  246. $(eval LDFLAGS=-m32)
  247. gprof:
  248. $(MAKE) CFLAGS="-pg" LDFLAGS="-pg"
  249. gcov:
  250. $(MAKE) CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs"
  251. coverage: gcov
  252. make check
  253. mkdir -p tmp/lcov
  254. lcov -d . -c -o tmp/lcov/hiredis.info
  255. genhtml --legend -o tmp/lcov/report tmp/lcov/hiredis.info
  256. noopt:
  257. $(MAKE) OPTIMIZATION=""
  258. .PHONY: all test check clean dep install 32bit 32bit-vars gprof gcov noopt