Makefile 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # Hiredis Makefile
  2. # Copyright (C) 2010 Salvatore Sanfilippo <antirez at gmail dot com>
  3. # This file is released under the BSD license, see the COPYING file
  4. OBJ = net.o hiredis.o sds.o async.o
  5. BINS = hiredis-example hiredis-test
  6. uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
  7. OPTIMIZATION?=-O3
  8. ifeq ($(uname_S),SunOS)
  9. CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -D__EXTENSIONS__ -D_XPG6 $(ARCH) $(PROF)
  10. CCLINK?=-ldl -lnsl -lsocket -lm -lpthread
  11. LDFLAGS?=-L. -Wl,-R,.
  12. DYLIBNAME?=libhiredis.so
  13. DYLIB_MAKE_CMD?=$(CC) -G -o ${DYLIBNAME} ${OBJ}
  14. STLIBNAME?=libhiredis.a
  15. STLIB_MAKE_CMD?=ar rcs ${STLIBNAME} ${OBJ}
  16. else
  17. ifeq ($(uname_S),Darwin)
  18. CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -Wwrite-strings $(ARCH) $(PROF)
  19. CCLINK?=-lm -pthread
  20. LDFLAGS?=-L. -Wl,-rpath,.
  21. OBJARCH?=-arch i386 -arch x86_64
  22. DYLIBNAME?=libhiredis.dylib
  23. DYLIB_MAKE_CMD?=libtool -dynamic -o ${DYLIBNAME} -lm ${DEBUG} - ${OBJ}
  24. STLIBNAME?=libhiredis.a
  25. STLIB_MAKE_CMD?=libtool -static -o ${STLIBNAME} - ${OBJ}
  26. else
  27. CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -Wwrite-strings $(ARCH) $(PROF)
  28. CCLINK?=-lm -pthread
  29. LDFLAGS?=-L. -Wl,-rpath,.
  30. DYLIBNAME?=libhiredis.so
  31. DYLIB_MAKE_CMD?=gcc -shared -Wl,-soname,${DYLIBNAME} -o ${DYLIBNAME} ${OBJ}
  32. STLIBNAME?=libhiredis.a
  33. STLIB_MAKE_CMD?=ar rcs ${STLIBNAME} ${OBJ}
  34. endif
  35. endif
  36. CCOPT= $(CFLAGS) $(CCLINK)
  37. DEBUG?= -g -ggdb
  38. PREFIX?= /usr/local
  39. INSTALL_INC= $(PREFIX)/include/hiredis
  40. INSTALL_LIB= $(PREFIX)/lib
  41. INSTALL= cp -a
  42. all: ${DYLIBNAME} ${BINS}
  43. # Deps (use make dep to generate this)
  44. net.o: net.c fmacros.h net.h
  45. async.o: async.c async.h hiredis.h sds.h util.h
  46. example.o: example.c hiredis.h
  47. hiredis.o: hiredis.c hiredis.h net.h sds.h util.h
  48. sds.o: sds.c sds.h
  49. test.o: test.c hiredis.h
  50. ${DYLIBNAME}: ${OBJ}
  51. ${DYLIB_MAKE_CMD}
  52. ${STLIBNAME}: ${OBJ}
  53. ${STLIB_MAKE_CMD}
  54. dynamic: ${DYLIBNAME}
  55. static: ${STLIBNAME}
  56. # Binaries:
  57. hiredis-example-libevent: example-libevent.c adapters/libevent.h ${DYLIBNAME}
  58. $(CC) -o $@ $(CCOPT) $(DEBUG) $(LDFLAGS) -lhiredis -levent example-libevent.c
  59. hiredis-example-libev: example-libev.c adapters/libev.h ${DYLIBNAME}
  60. $(CC) -o $@ $(CCOPT) $(DEBUG) $(LDFLAGS) -lhiredis -lev example-libev.c
  61. ifndef AE_DIR
  62. hiredis-example-ae:
  63. @echo "Please specify AE_DIR (e.g. <redis repository>/src)"
  64. @false
  65. else
  66. hiredis-example-ae: example-ae.c adapters/ae.h ${DYLIBNAME}
  67. $(CC) -o $@ $(CCOPT) $(DEBUG) -I$(AE_DIR) $(LDFLAGS) -lhiredis example-ae.c $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o
  68. endif
  69. hiredis-%: %.o ${DYLIBNAME}
  70. $(CC) -o $@ $(CCOPT) $(DEBUG) $(LDFLAGS) -lhiredis $<
  71. test: hiredis-test
  72. ./hiredis-test
  73. .c.o:
  74. $(CC) -c $(CFLAGS) $(OBJARCH) $(DEBUG) $(COMPILE_TIME) $<
  75. clean:
  76. rm -rf ${DYLIBNAME} ${STLIBNAME} $(BINS) hiredis-example* *.o *.gcda *.gcno *.gcov
  77. dep:
  78. $(CC) -MM *.c
  79. install: ${DYLIBNAME} ${STLIBNAME}
  80. mkdir -p $(INSTALL_INC) $(INSTALL_LIB)
  81. $(INSTALL) hiredis.h async.h adapters $(INSTALL_INC)
  82. $(INSTALL) ${DYLIBNAME} ${STLIBNAME} $(INSTALL_LIB)
  83. 32bit:
  84. @echo ""
  85. @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
  86. @echo ""
  87. $(MAKE) ARCH="-m32"
  88. gprof:
  89. $(MAKE) PROF="-pg"
  90. gcov:
  91. $(MAKE) PROF="-fprofile-arcs -ftest-coverage"
  92. noopt:
  93. $(MAKE) OPTIMIZATION=""