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
12 CCLINK?= -ldl -lnsl -lsocket -lm -lpthread
13 DYLIBNAME?=libhiredis.so
14 DYLIB_MAKE_CMD?=gcc -shared -Wl,-soname,${DYLIBNAME} -o ${DYLIBNAME} ${OBJ}
15 STLIBNAME?=libhiredis.a
16 STLIB_MAKE_CMD?=ar rcs ${STLIBNAME} ${OBJ}
17 else ifeq ($(uname_S),Darwin)
18 CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -Wwrite-strings $(ARCH) $(PROF)
20 OBJARCH?= -arch i386 -arch x86_64
21 DYLIBNAME?=libhiredis.dylib
22 DYLIB_MAKE_CMD?=libtool -dynamic -o ${DYLIBNAME} -lm ${DEBUG} - ${OBJ}
23 STLIBNAME?=libhiredis.a
24 STLIB_MAKE_CMD?=libtool -static -o ${STLIBNAME} - ${OBJ}
26 CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -Wwrite-strings $(ARCH) $(PROF)
28 DYLIBNAME?=libhiredis.so
29 DYLIB_MAKE_CMD?=gcc -shared -Wl,-soname,${DYLIBNAME} -o ${DYLIBNAME} ${OBJ}
30 STLIBNAME?=libhiredis.a
31 STLIB_MAKE_CMD?=ar rcs ${STLIBNAME} ${OBJ}
33 CCOPT= $(CFLAGS) $(CCLINK) $(ARCH) $(PROF)
37 INSTALL_INC= $(PREFIX)/include/hiredis
38 INSTALL_LIB= $(PREFIX)/lib
41 all: ${DYLIBNAME} ${BINS}
43 # Deps (use make dep to generate this)
44 net.o: net.c fmacros.h net.h
45 async.o: async.c async.h hiredis.h sds.h util.h
46 example-libev.o: example-libev.c hiredis.h async.h adapters/libev.h
47 example-libevent.o: example-libevent.c hiredis.h async.h adapters/libevent.h
48 example.o: example.c hiredis.h
49 hiredis.o: hiredis.c hiredis.h net.h sds.h util.h
51 test.o: test.c hiredis.h
63 hiredis-example-libevent: example-libevent.o ${DYLIBNAME}
64 $(CC) -o $@ $(CCOPT) $(DEBUG) -L. -lhiredis -levent -Wl,-rpath,. example-libevent.c
66 hiredis-example-libev: example-libev.o ${DYLIBNAME}
67 $(CC) -o $@ $(CCOPT) $(DEBUG) -L. -lhiredis -lev -Wl,-rpath,. example-libev.c
69 hiredis-%: %.o ${DYLIBNAME}
70 $(CC) -o $@ $(CCOPT) $(DEBUG) -L. -lhiredis -Wl,-rpath,. $<
76 $(CC) -c $(CFLAGS) $(OBJARCH) $(DEBUG) $(COMPILE_TIME) $<
79 rm -rf ${DYLIBNAME} ${STLIBNAME} $(BINS) hiredis-example* *.o *.gcda *.gcno *.gcov
84 install: ${DYLIBNAME} ${STLIBNAME}
85 mkdir -p $(INSTALL_INC) $(INSTALL_LIB)
86 $(INSTALL) hiredis.h async.h adapters $(INSTALL_INC)
87 $(INSTALL) ${DYLIBNAME} ${STLIBNAME} $(INSTALL_LIB)
91 @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
99 make PROF="-fprofile-arcs -ftest-coverage"