2 # Copyright (C) 2010 Salvatore Sanfilippo <antirez at gmail dot com>
3 # This file is released under the BSD license, see the COPYING file
5 OBJ = net.o hiredis.o sds.o async.o
6 BINS = hiredis-example hiredis-test
8 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
10 ifeq ($(uname_S),SunOS)
11 CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -D__EXTENSIONS__ -D_XPG6 $(ARCH) $(PROF)
12 CCLINK?=-ldl -lnsl -lsocket -lm -lpthread
14 DYLIBNAME?=libhiredis.so
15 DYLIB_MAKE_CMD?=$(CC) -G -o ${DYLIBNAME} ${OBJ}
16 STLIBNAME?=libhiredis.a
17 STLIB_MAKE_CMD?=ar rcs ${STLIBNAME} ${OBJ}
18 else ifeq ($(uname_S),Darwin)
19 CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -Wwrite-strings $(ARCH) $(PROF)
21 LDFLAGS?=-L. -Wl,-rpath,.
22 OBJARCH?=-arch i386 -arch x86_64
23 DYLIBNAME?=libhiredis.dylib
24 DYLIB_MAKE_CMD?=libtool -dynamic -o ${DYLIBNAME} -lm ${DEBUG} - ${OBJ}
25 STLIBNAME?=libhiredis.a
26 STLIB_MAKE_CMD?=libtool -static -o ${STLIBNAME} - ${OBJ}
28 CFLAGS?=-std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -Wwrite-strings $(ARCH) $(PROF)
30 LDFLAGS?=-L. -Wl,-rpath,.
31 DYLIBNAME?=libhiredis.so
32 DYLIB_MAKE_CMD?=gcc -shared -Wl,-soname,${DYLIBNAME} -o ${DYLIBNAME} ${OBJ}
33 STLIBNAME?=libhiredis.a
34 STLIB_MAKE_CMD?=ar rcs ${STLIBNAME} ${OBJ}
36 CCOPT= $(CFLAGS) $(CCLINK)
40 INSTALL_INC= $(PREFIX)/include/hiredis
41 INSTALL_LIB= $(PREFIX)/lib
44 all: ${DYLIBNAME} ${BINS}
46 # Deps (use make dep to generate this)
47 net.o: net.c fmacros.h net.h
48 async.o: async.c async.h hiredis.h sds.h util.h
49 example.o: example.c hiredis.h
50 hiredis.o: hiredis.c hiredis.h net.h sds.h util.h
52 test.o: test.c hiredis.h
64 hiredis-example-libevent: example-libevent.c adapters/libevent.h ${DYLIBNAME}
65 $(CC) -o $@ $(CCOPT) $(DEBUG) $(LDFLAGS) -lhiredis -levent example-libevent.c
67 hiredis-example-libev: example-libev.c adapters/libev.h ${DYLIBNAME}
68 $(CC) -o $@ $(CCOPT) $(DEBUG) $(LDFLAGS) -lhiredis -lev example-libev.c
72 @echo "Please specify AE_DIR (e.g. <redis repository>/src)"
75 hiredis-example-ae: example-ae.c adapters/ae.h ${DYLIBNAME}
76 $(CC) -o $@ $(CCOPT) $(DEBUG) -I$(AE_DIR) $(LDFLAGS) -lhiredis example-ae.c $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o
79 hiredis-%: %.o ${DYLIBNAME}
80 $(CC) -o $@ $(CCOPT) $(DEBUG) $(LDFLAGS) -lhiredis $<
86 $(CC) -c $(CFLAGS) $(OBJARCH) $(DEBUG) $(COMPILE_TIME) $<
89 rm -rf ${DYLIBNAME} ${STLIBNAME} $(BINS) hiredis-example* *.o *.gcda *.gcno *.gcov
94 install: ${DYLIBNAME} ${STLIBNAME}
95 mkdir -p $(INSTALL_INC) $(INSTALL_LIB)
96 $(INSTALL) hiredis.h async.h adapters $(INSTALL_INC)
97 $(INSTALL) ${DYLIBNAME} ${STLIBNAME} $(INSTALL_LIB)
101 @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
109 $(MAKE) PROF="-fprofile-arcs -ftest-coverage"
112 $(MAKE) OPTIMIZATION=""