Makefile 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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
  6. EXAMPLES=hiredis-example hiredis-example-libevent hiredis-example-libev hiredis-example-glib
  7. TESTS=hiredis-test
  8. LIBNAME=libhiredis
  9. PKGCONFNAME=hiredis.pc
  10. HIREDIS_MAJOR=$(shell grep HIREDIS_MAJOR hiredis.h | awk '{print $$3}')
  11. HIREDIS_MINOR=$(shell grep HIREDIS_MINOR hiredis.h | awk '{print $$3}')
  12. HIREDIS_PATCH=$(shell grep HIREDIS_PATCH hiredis.h | awk '{print $$3}')
  13. HIREDIS_SONAME=$(shell grep HIREDIS_SONAME hiredis.h | awk '{print $$3}')
  14. # Installation related variables and target
  15. PREFIX?=/usr/local
  16. INCLUDE_PATH?=include/hiredis
  17. LIBRARY_PATH?=lib
  18. PKGCONF_PATH?=pkgconfig
  19. INSTALL_INCLUDE_PATH= $(DESTDIR)$(PREFIX)/$(INCLUDE_PATH)
  20. INSTALL_LIBRARY_PATH= $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH)
  21. INSTALL_PKGCONF_PATH= $(INSTALL_LIBRARY_PATH)/$(PKGCONF_PATH)
  22. # redis-server configuration used for testing
  23. REDIS_PORT=56379
  24. REDIS_SERVER=redis-server
  25. define REDIS_TEST_CONFIG
  26. daemonize yes
  27. pidfile /tmp/hiredis-test-redis.pid
  28. port $(REDIS_PORT)
  29. bind 127.0.0.1
  30. unixsocket /tmp/hiredis-test-redis.sock
  31. endef
  32. export REDIS_TEST_CONFIG
  33. # Fallback to gcc when $CC is not in $PATH.
  34. CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
  35. CXX:=$(shell sh -c 'type $(CXX) >/dev/null 2>/dev/null && echo $(CXX) || echo g++')
  36. OPTIMIZATION?=-O3
  37. WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings
  38. DEBUG_FLAGS?= -g -ggdb
  39. REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CFLAGS) $(WARNINGS) $(DEBUG_FLAGS) $(ARCH)
  40. REAL_LDFLAGS=$(LDFLAGS) $(ARCH)
  41. DYLIBSUFFIX=so
  42. STLIBSUFFIX=a
  43. DYLIB_MINOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_SONAME)
  44. DYLIB_MAJOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR)
  45. DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX)
  46. DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
  47. STLIBNAME=$(LIBNAME).$(STLIBSUFFIX)
  48. STLIB_MAKE_CMD=ar rcs $(STLIBNAME)
  49. # Platform-specific overrides
  50. uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
  51. ifeq ($(uname_S),SunOS)
  52. REAL_LDFLAGS+= -ldl -lnsl -lsocket
  53. DYLIB_MAKE_CMD=$(CC) -G -o $(DYLIBNAME) -h $(DYLIB_MINOR_NAME) $(LDFLAGS)
  54. INSTALL= cp -r
  55. endif
  56. ifeq ($(uname_S),Darwin)
  57. DYLIBSUFFIX=dylib
  58. DYLIB_MINOR_NAME=$(LIBNAME).$(HIREDIS_SONAME).$(DYLIBSUFFIX)
  59. DYLIB_MAKE_CMD=$(CC) -shared -Wl,-install_name,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
  60. endif
  61. all: $(DYLIBNAME) $(STLIBNAME) hiredis-test $(PKGCONFNAME)
  62. # Deps (use make dep to generate this)
  63. async.o: async.c fmacros.h async.h hiredis.h read.h sds.h net.h dict.c dict.h
  64. dict.o: dict.c fmacros.h dict.h
  65. hiredis.o: hiredis.c fmacros.h hiredis.h read.h sds.h net.h
  66. net.o: net.c fmacros.h net.h hiredis.h read.h sds.h
  67. read.o: read.c fmacros.h read.h sds.h
  68. sds.o: sds.c sds.h
  69. test.o: test.c fmacros.h hiredis.h read.h sds.h
  70. $(DYLIBNAME): $(OBJ)
  71. $(DYLIB_MAKE_CMD) $(OBJ)
  72. $(STLIBNAME): $(OBJ)
  73. $(STLIB_MAKE_CMD) $(OBJ)
  74. dynamic: $(DYLIBNAME)
  75. static: $(STLIBNAME)
  76. # Binaries:
  77. hiredis-example-libevent: examples/example-libevent.c adapters/libevent.h $(STLIBNAME)
  78. $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -levent $(STLIBNAME)
  79. hiredis-example-libev: examples/example-libev.c adapters/libev.h $(STLIBNAME)
  80. $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -lev $(STLIBNAME)
  81. hiredis-example-glib: examples/example-glib.c adapters/glib.h $(STLIBNAME)
  82. $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) $(shell pkg-config --cflags --libs glib-2.0) -I. $< $(STLIBNAME)
  83. hiredis-example-ivykis: examples/example-ivykis.c adapters/ivykis.h $(STLIBNAME)
  84. $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -livykis $(STLIBNAME)
  85. hiredis-example-macosx: examples/example-macosx.c adapters/macosx.h $(STLIBNAME)
  86. $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -framework CoreFoundation $(STLIBNAME)
  87. ifndef AE_DIR
  88. hiredis-example-ae:
  89. @echo "Please specify AE_DIR (e.g. <redis repository>/src)"
  90. @false
  91. else
  92. hiredis-example-ae: examples/example-ae.c adapters/ae.h $(STLIBNAME)
  93. $(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)
  94. endif
  95. ifndef LIBUV_DIR
  96. hiredis-example-libuv:
  97. @echo "Please specify LIBUV_DIR (e.g. ../libuv/)"
  98. @false
  99. else
  100. hiredis-example-libuv: examples/example-libuv.c adapters/libuv.h $(STLIBNAME)
  101. $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(LIBUV_DIR)/include $< $(LIBUV_DIR)/.libs/libuv.a -lpthread -lrt $(STLIBNAME)
  102. endif
  103. ifeq ($(and $(QT_MOC),$(QT_INCLUDE_DIR),$(QT_LIBRARY_DIR)),)
  104. hiredis-example-qt:
  105. @echo "Please specify QT_MOC, QT_INCLUDE_DIR AND QT_LIBRARY_DIR"
  106. @false
  107. else
  108. hiredis-example-qt: examples/example-qt.cpp adapters/qt.h $(STLIBNAME)
  109. $(QT_MOC) adapters/qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \
  110. $(CXX) -x c++ -o qt-adapter-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore
  111. $(QT_MOC) examples/example-qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \
  112. $(CXX) -x c++ -o qt-example-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore
  113. $(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
  114. endif
  115. hiredis-example: examples/example.c $(STLIBNAME)
  116. $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< $(STLIBNAME)
  117. examples: $(EXAMPLES)
  118. hiredis-test: test.o $(STLIBNAME)
  119. hiredis-%: %.o $(STLIBNAME)
  120. $(CC) $(REAL_CFLAGS) -o $@ $(REAL_LDFLAGS) $< $(STLIBNAME)
  121. test: hiredis-test
  122. ./hiredis-test
  123. check: hiredis-test
  124. @echo "$$REDIS_TEST_CONFIG" | $(REDIS_SERVER) -
  125. $(PRE) ./hiredis-test -h 127.0.0.1 -p $(REDIS_PORT) -s /tmp/hiredis-test-redis.sock || \
  126. ( kill `cat /tmp/hiredis-test-redis.pid` && false )
  127. kill `cat /tmp/hiredis-test-redis.pid`
  128. .c.o:
  129. $(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $<
  130. clean:
  131. rm -rf $(DYLIBNAME) $(STLIBNAME) $(TESTS) $(PKGCONFNAME) examples/hiredis-example* *.o *.gcda *.gcno *.gcov
  132. dep:
  133. $(CC) -MM *.c
  134. ifeq ($(uname_S),SunOS)
  135. INSTALL?= cp -r
  136. endif
  137. INSTALL?= cp -a
  138. $(PKGCONFNAME): hiredis.h
  139. @echo "Generating $@ for pkgconfig..."
  140. @echo prefix=$(PREFIX) > $@
  141. @echo exec_prefix=\$${prefix} >> $@
  142. @echo libdir=$(PREFIX)/$(LIBRARY_PATH) >> $@
  143. @echo includedir=$(PREFIX)/$(INCLUDE_PATH) >> $@
  144. @echo >> $@
  145. @echo Name: hiredis >> $@
  146. @echo Description: Minimalistic C client library for Redis. >> $@
  147. @echo Version: $(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(HIREDIS_PATCH) >> $@
  148. @echo Libs: -L\$${libdir} -lhiredis >> $@
  149. @echo Cflags: -I\$${includedir} -D_FILE_OFFSET_BITS=64 >> $@
  150. install: $(DYLIBNAME) $(STLIBNAME) $(PKGCONFNAME)
  151. mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH)
  152. $(INSTALL) hiredis.h async.h read.h sds.h adapters $(INSTALL_INCLUDE_PATH)
  153. $(INSTALL) $(DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_MINOR_NAME)
  154. cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MINOR_NAME) $(DYLIBNAME)
  155. $(INSTALL) $(STLIBNAME) $(INSTALL_LIBRARY_PATH)
  156. mkdir -p $(INSTALL_PKGCONF_PATH)
  157. $(INSTALL) $(PKGCONFNAME) $(INSTALL_PKGCONF_PATH)
  158. 32bit:
  159. @echo ""
  160. @echo "WARNING: if this fails under Linux you probably need to install libc6-dev-i386"
  161. @echo ""
  162. $(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
  163. 32bit-vars:
  164. $(eval CFLAGS=-m32)
  165. $(eval LDFLAGS=-m32)
  166. gprof:
  167. $(MAKE) CFLAGS="-pg" LDFLAGS="-pg"
  168. gcov:
  169. $(MAKE) CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs"
  170. coverage: gcov
  171. make check
  172. mkdir -p tmp/lcov
  173. lcov -d . -c -o tmp/lcov/hiredis.info
  174. genhtml --legend -o tmp/lcov/report tmp/lcov/hiredis.info
  175. noopt:
  176. $(MAKE) OPTIMIZATION=""
  177. .PHONY: all test check clean dep install 32bit 32bit-vars gprof gcov noopt