]> git.saurik.com Git - redis.git/blame - deps/hiredis/Makefile
Fix 32bit build of hiredis
[redis.git] / deps / hiredis / Makefile
CommitLineData
24f753a8 1# Hiredis Makefile
b66e5add 2# Copyright (C) 2010-2011 Salvatore Sanfilippo <antirez at gmail dot com>
3# Copyright (C) 2010-2011 Pieter Noordhuis <pcnoordhuis at gmail dot com>
24f753a8
PN
4# This file is released under the BSD license, see the COPYING file
5
b66e5add 6OBJ=net.o hiredis.o sds.o async.o
7BINS=hiredis-example hiredis-test
8LIBNAME=libhiredis
24f753a8 9
b66e5add 10HIREDIS_MAJOR=0
11HIREDIS_MINOR=10
12
13# Fallback to gcc when $CC is not in $PATH.
14CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
a1e97d69 15OPTIMIZATION?=-O3
b66e5add 16WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings
17DEBUG?= -g -ggdb
ad0df18f 18REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CFLAGS) $(WARNINGS) $(DEBUG) $(ARCH)
19REAL_LDFLAGS=$(LDFLAGS) $(ARCH)
b66e5add 20
21DYLIBSUFFIX=so
22STLIBSUFFIX=a
23DYLIB_MINOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR).$(HIREDIS_MINOR)
24DYLIB_MAJOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR)
25DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX)
26DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
27STLIBNAME=$(LIBNAME).$(STLIBSUFFIX)
28STLIB_MAKE_CMD=ar rcs $(STLIBNAME)
29
30# Platform-specific overrides
31uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
24f753a8 32ifeq ($(uname_S),SunOS)
b66e5add 33 REAL_LDFLAGS+= -ldl -lnsl -lsocket
34 DYLIB_MAKE_CMD=$(CC) -G -o $(DYLIBNAME) -h $(DYLIB_MINOR_NAME) $(LDFLAGS)
35 INSTALL= cp -r
24f753a8 36endif
b66e5add 37ifeq ($(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)
9703b1b3
PN
42endif
43
b66e5add 44all: $(DYLIBNAME) $(BINS)
24f753a8
PN
45
46# Deps (use make dep to generate this)
b66e5add 47net.o: net.c fmacros.h net.h hiredis.h
48async.o: async.c async.h hiredis.h sds.h dict.c dict.h
24f753a8 49example.o: example.c hiredis.h
b66e5add 50hiredis.o: hiredis.c fmacros.h hiredis.h net.h sds.h
24f753a8
PN
51sds.o: sds.c sds.h
52test.o: test.c hiredis.h
53
b66e5add 54$(DYLIBNAME): $(OBJ)
55 $(DYLIB_MAKE_CMD) $(OBJ)
24f753a8 56
b66e5add 57$(STLIBNAME): $(OBJ)
58 $(STLIB_MAKE_CMD) $(OBJ)
24f753a8 59
b66e5add 60dynamic: $(DYLIBNAME)
61static: $(STLIBNAME)
24f753a8
PN
62
63# Binaries:
b66e5add 64hiredis-example-libevent: example-libevent.c adapters/libevent.h $(STLIBNAME)
65 $(CC) -o $@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -levent example-libevent.c $(STLIBNAME)
a1e97d69 66
b66e5add 67hiredis-example-libev: example-libev.c adapters/libev.h $(STLIBNAME)
68 $(CC) -o $@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -lev example-libev.c $(STLIBNAME)
24f753a8 69
a1e97d69
PN
70ifndef AE_DIR
71hiredis-example-ae:
72 @echo "Please specify AE_DIR (e.g. <redis repository>/src)"
73 @false
74else
b66e5add 75hiredis-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)
a1e97d69 77endif
24f753a8 78
b66e5add 79hiredis-%: %.o $(STLIBNAME)
80 $(CC) -o $@ $(REAL_LDFLAGS) $< $(STLIBNAME)
24f753a8
PN
81
82test: hiredis-test
83 ./hiredis-test
84
b66e5add 85check: 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
24f753a8 97.c.o:
b66e5add 98 $(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $<
24f753a8
PN
99
100clean:
b66e5add 101 rm -rf $(DYLIBNAME) $(STLIBNAME) $(BINS) hiredis-example* *.o *.gcda *.gcno *.gcov
24f753a8
PN
102
103dep:
104 $(CC) -MM *.c
105
b66e5add 106# Installation related variables and target
107PREFIX?=/usr/local
108INCLUDE_PATH?=include/hiredis
109LIBRARY_PATH?=lib
110INSTALL_INCLUDE_PATH= $(PREFIX)/$(INCLUDE_PATH)
111INSTALL_LIBRARY_PATH= $(PREFIX)/$(LIBRARY_PATH)
112
113ifeq ($(uname_S),SunOS)
114 INSTALL?= cp -r
115endif
116
117INSTALL?= cp -a
118
119install: $(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)
24f753a8
PN
126
12732bit:
128 @echo ""
b66e5add 129 @echo "WARNING: if this fails under Linux you probably need to install libc6-dev-i386"
24f753a8 130 @echo ""
b66e5add 131 $(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
24f753a8
PN
132
133gprof:
b66e5add 134 $(MAKE) CFLAGS="-pg" LDFLAGS="-pg"
24f753a8
PN
135
136gcov:
b66e5add 137 $(MAKE) CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs"
138
139coverage: 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
24f753a8
PN
144
145noopt:
a4e48b41 146 $(MAKE) OPTIMIZATION=""
b66e5add 147
148.PHONY: all test check clean dep install 32bit gprof gcov noopt