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