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