2
0

Makefile 4.4 KB

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