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