2
0

Makefile 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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
  6. EXAMPLES=hiredis-example hiredis-example-libevent hiredis-example-libev
  7. TESTS=hiredis-test
  8. LIBNAME=libhiredis
  9. HIREDIS_MAJOR=0
  10. HIREDIS_MINOR=11
  11. # redis-server configuration used for testing
  12. REDIS_PORT=56379
  13. REDIS_SERVER=redis-server
  14. define REDIS_TEST_CONFIG
  15. daemonize yes
  16. pidfile /tmp/hiredis-test-redis.pid
  17. port $(REDIS_PORT)
  18. bind 127.0.0.1
  19. unixsocket /tmp/hiredis-test-redis.sock
  20. endef
  21. export REDIS_TEST_CONFIG
  22. # Fallback to gcc when $CC is not in $PATH.
  23. CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
  24. OPTIMIZATION?=-O3
  25. WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings
  26. DEBUG?= -g -ggdb
  27. REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CFLAGS) $(WARNINGS) $(DEBUG) $(ARCH)
  28. REAL_LDFLAGS=$(LDFLAGS) $(ARCH)
  29. DYLIBSUFFIX=so
  30. STLIBSUFFIX=a
  31. DYLIB_MINOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR).$(HIREDIS_MINOR)
  32. DYLIB_MAJOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR)
  33. DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX)
  34. DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
  35. STLIBNAME=$(LIBNAME).$(STLIBSUFFIX)
  36. STLIB_MAKE_CMD=ar rcs $(STLIBNAME)
  37. # Platform-specific overrides
  38. uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
  39. ifeq ($(uname_S),SunOS)
  40. REAL_LDFLAGS+= -ldl -lnsl -lsocket
  41. DYLIB_MAKE_CMD=$(CC) -G -o $(DYLIBNAME) -h $(DYLIB_MINOR_NAME) $(LDFLAGS)
  42. INSTALL= cp -r
  43. endif
  44. ifeq ($(uname_S),Darwin)
  45. DYLIBSUFFIX=dylib
  46. DYLIB_MINOR_NAME=$(LIBNAME).$(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(DYLIBSUFFIX)
  47. DYLIB_MAJOR_NAME=$(LIBNAME).$(HIREDIS_MAJOR).$(DYLIBSUFFIX)
  48. DYLIB_MAKE_CMD=$(CC) -shared -Wl,-install_name,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
  49. endif
  50. all: $(DYLIBNAME)
  51. # Deps (use make dep to generate this)
  52. net.o: net.c fmacros.h net.h hiredis.h
  53. async.o: async.c async.h hiredis.h sds.h dict.c dict.h
  54. hiredis.o: hiredis.c fmacros.h hiredis.h net.h sds.h
  55. sds.o: sds.c sds.h
  56. test.o: test.c hiredis.h
  57. $(DYLIBNAME): $(OBJ)
  58. $(DYLIB_MAKE_CMD) $(OBJ)
  59. $(STLIBNAME): $(OBJ)
  60. $(STLIB_MAKE_CMD) $(OBJ)
  61. dynamic: $(DYLIBNAME)
  62. static: $(STLIBNAME)
  63. # Binaries:
  64. hiredis-example-libevent: examples/example-libevent.c adapters/libevent.h $(STLIBNAME)
  65. $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -levent $(STLIBNAME)
  66. hiredis-example-libev: examples/example-libev.c adapters/libev.h $(STLIBNAME)
  67. $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -lev $(STLIBNAME)
  68. ifndef AE_DIR
  69. hiredis-example-ae:
  70. @echo "Please specify AE_DIR (e.g. <redis repository>/src)"
  71. @false
  72. else
  73. hiredis-example-ae: examples/example-ae.c adapters/ae.h $(STLIBNAME)
  74. $(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)
  75. endif
  76. ifndef LIBUV_DIR
  77. hiredis-example-libuv:
  78. @echo "Please specify LIBUV_DIR (e.g. ../libuv/)"
  79. @false
  80. else
  81. hiredis-example-libuv: examples/example-libuv.c adapters/libuv.h $(STLIBNAME)
  82. $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(LIBUV_DIR)/include $< $(LIBUV_DIR)/.libs/libuv.a -lpthread $(STLIBNAME)
  83. endif
  84. hiredis-example: examples/example.c $(STLIBNAME)
  85. $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< $(STLIBNAME)
  86. examples: $(EXAMPLES)
  87. hiredis-test: test.o $(STLIBNAME)
  88. $(CC) -o $@ $(REAL_LDFLAGS) $< $(STLIBNAME)
  89. test: hiredis-test
  90. ./hiredis-test
  91. check: hiredis-test
  92. @echo "$$REDIS_TEST_CONFIG" | $(REDIS_SERVER) -
  93. ./hiredis-test -h 127.0.0.1 -p $(REDIS_PORT) -s /tmp/hiredis-test-redis.sock || \
  94. ( kill `cat /tmp/hiredis-test-redis.pid` && false )
  95. kill `cat /tmp/hiredis-test-redis.pid`
  96. .c.o:
  97. $(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $<
  98. clean:
  99. rm -rf $(DYLIBNAME) $(STLIBNAME) $(TESTS) examples/hiredis-example* *.o *.gcda *.gcno *.gcov
  100. dep:
  101. $(CC) -MM *.c
  102. # Installation related variables and target
  103. PREFIX?=/usr/local
  104. INSTALL_INCLUDE_PATH= $(PREFIX)/include/hiredis
  105. INSTALL_LIBRARY_PATH= $(PREFIX)/lib
  106. ifeq ($(uname_S),SunOS)
  107. INSTALL?= cp -r
  108. endif
  109. INSTALL?= cp -a
  110. install: $(DYLIBNAME) $(STLIBNAME)
  111. mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH)
  112. $(INSTALL) hiredis.h async.h adapters $(INSTALL_INCLUDE_PATH)
  113. $(INSTALL) $(DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_MINOR_NAME)
  114. cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MINOR_NAME) $(DYLIB_MAJOR_NAME)
  115. cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MAJOR_NAME) $(DYLIBNAME)
  116. $(INSTALL) $(STLIBNAME) $(INSTALL_LIBRARY_PATH)
  117. 32bit:
  118. @echo ""
  119. @echo "WARNING: if this fails under Linux you probably need to install libc6-dev-i386"
  120. @echo ""
  121. $(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
  122. gprof:
  123. $(MAKE) CFLAGS="-pg" LDFLAGS="-pg"
  124. gcov:
  125. $(MAKE) CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs"
  126. coverage: gcov
  127. make check
  128. mkdir -p tmp/lcov
  129. lcov -d . -c -o tmp/lcov/hiredis.info
  130. genhtml --legend -o tmp/lcov/report tmp/lcov/hiredis.info
  131. noopt:
  132. $(MAKE) OPTIMIZATION=""
  133. .PHONY: all test check clean dep install 32bit gprof gcov noopt