2
0

Makefile 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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=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
  8. ifeq ($(USE_SSL),1)
  9. EXAMPLES+=hiredis-example-ssl hiredis-example-libevent-ssl
  10. endif
  11. TESTS=hiredis-test
  12. LIBNAME=libhiredis
  13. SSL_LIBNAME=libhiredis_ssl
  14. PKGCONFNAME=hiredis.pc
  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. SSL_DYLIBNAME=$(SSL_LIBNAME).$(DYLIBSUFFIX)
  53. DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(DYLIB_MINOR_NAME)
  54. STLIBNAME=$(LIBNAME).$(STLIBSUFFIX)
  55. SSL_STLIBNAME=$(SSL_LIBNAME).$(STLIBSUFFIX)
  56. STLIB_MAKE_CMD=$(AR) rcs
  57. # Platform-specific overrides
  58. uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
  59. USE_SSL?=0
  60. # This is required for test.c only
  61. ifeq ($(USE_SSL),1)
  62. CFLAGS+=-DHIREDIS_TEST_SSL
  63. endif
  64. ifeq ($(uname_S),Linux)
  65. SSL_LDFLAGS=-lssl -lcrypto
  66. else
  67. OPENSSL_PREFIX?=/usr/local/opt/openssl
  68. CFLAGS+=-I$(OPENSSL_PREFIX)/include
  69. SSL_LDFLAGS+=-L$(OPENSSL_PREFIX)/lib -lssl -lcrypto
  70. endif
  71. ifeq ($(uname_S),SunOS)
  72. REAL_LDFLAGS+= -ldl -lnsl -lsocket
  73. DYLIB_MAKE_CMD=$(CC) -G -o $(DYLIBNAME) -h $(DYLIB_MINOR_NAME) $(LDFLAGS)
  74. endif
  75. ifeq ($(uname_S),Darwin)
  76. DYLIBSUFFIX=dylib
  77. DYLIB_MINOR_NAME=$(LIBNAME).$(HIREDIS_SONAME).$(DYLIBSUFFIX)
  78. DYLIB_MAKE_CMD=$(CC) -dynamiclib -Wl,-install_name,$(PREFIX)/$(LIBRARY_PATH)/$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
  79. endif
  80. all: $(DYLIBNAME) $(STLIBNAME) hiredis-test $(PKGCONFNAME)
  81. ifeq ($(USE_SSL),1)
  82. all: $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(SSL_PKGCONFNAME)
  83. endif
  84. # Deps (use make dep to generate this)
  85. async.o: async.c fmacros.h async.h hiredis.h read.h sds.h net.h dict.c dict.h
  86. dict.o: dict.c fmacros.h dict.h
  87. hiredis.o: hiredis.c fmacros.h hiredis.h read.h sds.h net.h win32.h
  88. net.o: net.c fmacros.h net.h hiredis.h read.h sds.h sockcompat.h win32.h
  89. read.o: read.c fmacros.h read.h sds.h
  90. sds.o: sds.c sds.h
  91. sockcompat.o: sockcompat.c sockcompat.h
  92. ssl.o: ssl.c hiredis.h
  93. test.o: test.c fmacros.h hiredis.h read.h sds.h
  94. $(DYLIBNAME): $(OBJ)
  95. $(DYLIB_MAKE_CMD) -o $(DYLIBNAME) $(OBJ) $(REAL_LDFLAGS)
  96. $(STLIBNAME): $(OBJ)
  97. $(STLIB_MAKE_CMD) $(STLIBNAME) $(OBJ)
  98. $(SSL_DYLIBNAME): $(SSL_OBJ)
  99. $(DYLIB_MAKE_CMD) -o $(SSL_DYLIBNAME) $(SSL_OBJ) $(REAL_LDFLAGS) $(SSL_LDFLAGS)
  100. $(SSL_STLIBNAME): $(SSL_OBJ)
  101. $(STLIB_MAKE_CMD) $(SSL_STLIBNAME) $(SSL_OBJ)
  102. dynamic: $(DYLIBNAME)
  103. static: $(STLIBNAME)
  104. ifeq ($(USE_SSL),1)
  105. dynamic: $(SSL_DYLIBNAME)
  106. static: $(SSL_STLIBNAME)
  107. endif
  108. # Binaries:
  109. hiredis-example-libevent: examples/example-libevent.c adapters/libevent.h $(STLIBNAME)
  110. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -levent $(STLIBNAME) $(REAL_LDFLAGS)
  111. hiredis-example-libevent-ssl: examples/example-libevent-ssl.c adapters/libevent.h $(STLIBNAME) $(SSL_STLIBNAME)
  112. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -levent $(STLIBNAME) $(SSL_STLIBNAME) $(REAL_LDFLAGS) $(SSL_LDFLAGS)
  113. hiredis-example-libev: examples/example-libev.c adapters/libev.h $(STLIBNAME)
  114. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -lev $(STLIBNAME) $(REAL_LDFLAGS)
  115. hiredis-example-glib: examples/example-glib.c adapters/glib.h $(STLIBNAME)
  116. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(shell pkg-config --cflags --libs glib-2.0) $(STLIBNAME) $(REAL_LDFLAGS)
  117. hiredis-example-ivykis: examples/example-ivykis.c adapters/ivykis.h $(STLIBNAME)
  118. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -livykis $(STLIBNAME) $(REAL_LDFLAGS)
  119. hiredis-example-macosx: examples/example-macosx.c adapters/macosx.h $(STLIBNAME)
  120. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -framework CoreFoundation $(STLIBNAME) $(REAL_LDFLAGS)
  121. hiredis-example-ssl: examples/example-ssl.c $(STLIBNAME) $(SSL_STLIBNAME)
  122. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(SSL_STLIBNAME) $(REAL_LDFLAGS) $(SSL_LDFLAGS)
  123. ifndef AE_DIR
  124. hiredis-example-ae:
  125. @echo "Please specify AE_DIR (e.g. <redis repository>/src)"
  126. @false
  127. else
  128. hiredis-example-ae: examples/example-ae.c adapters/ae.h $(STLIBNAME)
  129. $(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)
  130. endif
  131. ifndef LIBUV_DIR
  132. hiredis-example-libuv:
  133. @echo "Please specify LIBUV_DIR (e.g. ../libuv/)"
  134. @false
  135. else
  136. hiredis-example-libuv: examples/example-libuv.c adapters/libuv.h $(STLIBNAME)
  137. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. -I$(LIBUV_DIR)/include $< $(LIBUV_DIR)/.libs/libuv.a -lpthread -lrt $(STLIBNAME) $(REAL_LDFLAGS)
  138. endif
  139. ifeq ($(and $(QT_MOC),$(QT_INCLUDE_DIR),$(QT_LIBRARY_DIR)),)
  140. hiredis-example-qt:
  141. @echo "Please specify QT_MOC, QT_INCLUDE_DIR AND QT_LIBRARY_DIR"
  142. @false
  143. else
  144. hiredis-example-qt: examples/example-qt.cpp adapters/qt.h $(STLIBNAME)
  145. $(QT_MOC) adapters/qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \
  146. $(CXX) -x c++ -o qt-adapter-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore
  147. $(QT_MOC) examples/example-qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \
  148. $(CXX) -x c++ -o qt-example-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore
  149. $(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
  150. endif
  151. hiredis-example: examples/example.c $(STLIBNAME)
  152. $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(REAL_LDFLAGS)
  153. examples: $(EXAMPLES)
  154. TEST_LIBS = $(STLIBNAME)
  155. ifeq ($(USE_SSL),1)
  156. TEST_LIBS += $(SSL_STLIBNAME) -lssl -lcrypto -lpthread
  157. endif
  158. hiredis-test: test.o $(TEST_LIBS)
  159. hiredis-%: %.o $(STLIBNAME)
  160. $(CC) $(REAL_CFLAGS) -o $@ $< $(TEST_LIBS) $(REAL_LDFLAGS)
  161. test: hiredis-test
  162. ./hiredis-test
  163. check: hiredis-test
  164. TEST_SSL=$(USE_SSL) ./test.sh
  165. .c.o:
  166. $(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $<
  167. clean:
  168. rm -rf $(DYLIBNAME) $(STLIBNAME) $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(TESTS) $(PKGCONFNAME) examples/hiredis-example* *.o *.gcda *.gcno *.gcov
  169. dep:
  170. $(CC) $(CPPFLAGS) $(CFLAGS) -MM *.c
  171. INSTALL?= cp -pPR
  172. $(PKGCONFNAME): hiredis.h
  173. @echo "Generating $@ for pkgconfig..."
  174. @echo prefix=$(PREFIX) > $@
  175. @echo exec_prefix=\$${prefix} >> $@
  176. @echo libdir=$(PREFIX)/$(LIBRARY_PATH) >> $@
  177. @echo includedir=$(PREFIX)/$(INCLUDE_PATH) >> $@
  178. @echo >> $@
  179. @echo Name: hiredis >> $@
  180. @echo Description: Minimalistic C client library for Redis. >> $@
  181. @echo Version: $(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(HIREDIS_PATCH) >> $@
  182. @echo Libs: -L\$${libdir} -lhiredis >> $@
  183. @echo Cflags: -I\$${includedir} -D_FILE_OFFSET_BITS=64 >> $@
  184. $(SSL_PKGCONFNAME): hiredis.h
  185. @echo "Generating $@ for pkgconfig..."
  186. @echo prefix=$(PREFIX) > $@
  187. @echo exec_prefix=\$${prefix} >> $@
  188. @echo libdir=$(PREFIX)/$(LIBRARY_PATH) >> $@
  189. @echo includedir=$(PREFIX)/$(INCLUDE_PATH) >> $@
  190. @echo >> $@
  191. @echo Name: hiredis_ssl >> $@
  192. @echo Description: SSL Support for hiredis. >> $@
  193. @echo Version: $(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(HIREDIS_PATCH) >> $@
  194. @echo Requires: hiredis >> $@
  195. @echo Libs: -L\$${libdir} -lhiredis_ssl >> $@
  196. @echo Libs.private: -lssl -lcrypto >> $@
  197. install: $(DYLIBNAME) $(STLIBNAME) $(PKGCONFNAME)
  198. mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_INCLUDE_PATH)/adapters $(INSTALL_LIBRARY_PATH)
  199. $(INSTALL) hiredis.h async.h read.h sds.h $(INSTALL_INCLUDE_PATH)
  200. $(INSTALL) adapters/*.h $(INSTALL_INCLUDE_PATH)/adapters
  201. $(INSTALL) $(DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_MINOR_NAME)
  202. cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MINOR_NAME) $(DYLIBNAME)
  203. $(INSTALL) $(STLIBNAME) $(INSTALL_LIBRARY_PATH)
  204. mkdir -p $(INSTALL_PKGCONF_PATH)
  205. $(INSTALL) $(PKGCONFNAME) $(INSTALL_PKGCONF_PATH)
  206. 32bit:
  207. @echo ""
  208. @echo "WARNING: if this fails under Linux you probably need to install libc6-dev-i386"
  209. @echo ""
  210. $(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
  211. 32bit-vars:
  212. $(eval CFLAGS=-m32)
  213. $(eval LDFLAGS=-m32)
  214. gprof:
  215. $(MAKE) CFLAGS="-pg" LDFLAGS="-pg"
  216. gcov:
  217. $(MAKE) CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs"
  218. coverage: gcov
  219. make check
  220. mkdir -p tmp/lcov
  221. lcov -d . -c -o tmp/lcov/hiredis.info
  222. genhtml --legend -o tmp/lcov/report tmp/lcov/hiredis.info
  223. noopt:
  224. $(MAKE) OPTIMIZATION=""
  225. .PHONY: all test check clean dep install 32bit 32bit-vars gprof gcov noopt