]>
Commit | Line | Data |
---|---|---|
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 | 6 | OBJ=net.o hiredis.o sds.o async.o |
7 | BINS=hiredis-example hiredis-test | |
8 | LIBNAME=libhiredis | |
24f753a8 | 9 | |
b66e5add | 10 | HIREDIS_MAJOR=0 |
11 | HIREDIS_MINOR=10 | |
12 | ||
13 | # Fallback to gcc when $CC is not in $PATH. | |
14 | CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc') | |
a1e97d69 | 15 | OPTIMIZATION?=-O3 |
b66e5add | 16 | WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings |
17 | DEBUG?= -g -ggdb | |
ad0df18f | 18 | REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CFLAGS) $(WARNINGS) $(DEBUG) $(ARCH) |
19 | REAL_LDFLAGS=$(LDFLAGS) $(ARCH) | |
b66e5add | 20 | |
21 | DYLIBSUFFIX=so | |
22 | STLIBSUFFIX=a | |
23 | DYLIB_MINOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR).$(HIREDIS_MINOR) | |
24 | DYLIB_MAJOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR) | |
25 | DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX) | |
26 | DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS) | |
27 | STLIBNAME=$(LIBNAME).$(STLIBSUFFIX) | |
28 | STLIB_MAKE_CMD=ar rcs $(STLIBNAME) | |
29 | ||
30 | # Platform-specific overrides | |
31 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') | |
24f753a8 | 32 | ifeq ($(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 | 36 | endif |
b66e5add | 37 | ifeq ($(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 |
42 | endif |
43 | ||
b66e5add | 44 | all: $(DYLIBNAME) $(BINS) |
24f753a8 PN |
45 | |
46 | # Deps (use make dep to generate this) | |
b66e5add | 47 | net.o: net.c fmacros.h net.h hiredis.h |
48 | async.o: async.c async.h hiredis.h sds.h dict.c dict.h | |
24f753a8 | 49 | example.o: example.c hiredis.h |
b66e5add | 50 | hiredis.o: hiredis.c fmacros.h hiredis.h net.h sds.h |
24f753a8 PN |
51 | sds.o: sds.c sds.h |
52 | test.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 | 60 | dynamic: $(DYLIBNAME) |
61 | static: $(STLIBNAME) | |
24f753a8 PN |
62 | |
63 | # Binaries: | |
b66e5add | 64 | hiredis-example-libevent: example-libevent.c adapters/libevent.h $(STLIBNAME) |
65 | $(CC) -o $@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -levent example-libevent.c $(STLIBNAME) | |
a1e97d69 | 66 | |
b66e5add | 67 | hiredis-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 |
70 | ifndef AE_DIR |
71 | hiredis-example-ae: | |
72 | @echo "Please specify AE_DIR (e.g. <redis repository>/src)" | |
73 | @false | |
74 | else | |
b66e5add | 75 | hiredis-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 | 77 | endif |
24f753a8 | 78 | |
b66e5add | 79 | hiredis-%: %.o $(STLIBNAME) |
80 | $(CC) -o $@ $(REAL_LDFLAGS) $< $(STLIBNAME) | |
24f753a8 PN |
81 | |
82 | test: hiredis-test | |
83 | ./hiredis-test | |
84 | ||
b66e5add | 85 | check: 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 | |
100 | clean: | |
b66e5add | 101 | rm -rf $(DYLIBNAME) $(STLIBNAME) $(BINS) hiredis-example* *.o *.gcda *.gcno *.gcov |
24f753a8 PN |
102 | |
103 | dep: | |
104 | $(CC) -MM *.c | |
105 | ||
b66e5add | 106 | # Installation related variables and target |
107 | PREFIX?=/usr/local | |
108 | INCLUDE_PATH?=include/hiredis | |
109 | LIBRARY_PATH?=lib | |
110 | INSTALL_INCLUDE_PATH= $(PREFIX)/$(INCLUDE_PATH) | |
111 | INSTALL_LIBRARY_PATH= $(PREFIX)/$(LIBRARY_PATH) | |
112 | ||
113 | ifeq ($(uname_S),SunOS) | |
114 | INSTALL?= cp -r | |
115 | endif | |
116 | ||
117 | INSTALL?= cp -a | |
118 | ||
119 | install: $(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 | |
127 | 32bit: | |
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 | |
133 | gprof: | |
b66e5add | 134 | $(MAKE) CFLAGS="-pg" LDFLAGS="-pg" |
24f753a8 PN |
135 | |
136 | gcov: | |
b66e5add | 137 | $(MAKE) CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs" |
138 | ||
139 | coverage: 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 | |
145 | noopt: | |
a4e48b41 | 146 | $(MAKE) OPTIMIZATION="" |
b66e5add | 147 | |
148 | .PHONY: all test check clean dep install 32bit gprof gcov noopt |