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 read.o 7EXAMPLES=hiredis-example hiredis-example-libevent hiredis-example-libev hiredis-example-glib 8TESTS=hiredis-test 9LIBNAME=libhiredis 10PKGCONFNAME=hiredis.pc 11 12HIREDIS_MAJOR=$(shell grep HIREDIS_MAJOR hiredis.h | awk '{print $$3}') 13HIREDIS_MINOR=$(shell grep HIREDIS_MINOR hiredis.h | awk '{print $$3}') 14HIREDIS_PATCH=$(shell grep HIREDIS_PATCH hiredis.h | awk '{print $$3}') 15HIREDIS_SONAME=$(shell grep HIREDIS_SONAME hiredis.h | awk '{print $$3}') 16 17# Installation related variables and target 18PREFIX?=/usr/local 19INCLUDE_PATH?=include/hiredis 20LIBRARY_PATH?=lib 21PKGCONF_PATH?=pkgconfig 22INSTALL_INCLUDE_PATH= $(DESTDIR)$(PREFIX)/$(INCLUDE_PATH) 23INSTALL_LIBRARY_PATH= $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH) 24INSTALL_PKGCONF_PATH= $(INSTALL_LIBRARY_PATH)/$(PKGCONF_PATH) 25 26# redis-server configuration used for testing 27REDIS_PORT=56379 28REDIS_SERVER=redis-server 29define REDIS_TEST_CONFIG 30 daemonize yes 31 pidfile /tmp/hiredis-test-redis.pid 32 port $(REDIS_PORT) 33 bind 127.0.0.1 34 unixsocket /tmp/hiredis-test-redis.sock 35endef 36export REDIS_TEST_CONFIG 37 38# Fallback to gcc when $CC is not in $PATH. 39CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc') 40CXX:=$(shell sh -c 'type $(CXX) >/dev/null 2>/dev/null && echo $(CXX) || echo g++') 41OPTIMIZATION?=-O3 42WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings 43DEBUG_FLAGS?= -g -ggdb 44REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CFLAGS) $(WARNINGS) $(DEBUG_FLAGS) $(ARCH) 45REAL_LDFLAGS=$(LDFLAGS) $(ARCH) 46 47DYLIBSUFFIX=so 48STLIBSUFFIX=a 49DYLIB_MINOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_SONAME) 50DYLIB_MAJOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR) 51DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX) 52DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS) 53STLIBNAME=$(LIBNAME).$(STLIBSUFFIX) 54STLIB_MAKE_CMD=ar rcs $(STLIBNAME) 55 56# Platform-specific overrides 57uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') 58ifeq ($(uname_S),SunOS) 59 REAL_LDFLAGS+= -ldl -lnsl -lsocket 60 DYLIB_MAKE_CMD=$(CC) -G -o $(DYLIBNAME) -h $(DYLIB_MINOR_NAME) $(LDFLAGS) 61 INSTALL= cp -r 62endif 63ifeq ($(uname_S),Darwin) 64 DYLIBSUFFIX=dylib 65 DYLIB_MINOR_NAME=$(LIBNAME).$(HIREDIS_SONAME).$(DYLIBSUFFIX) 66 DYLIB_MAKE_CMD=$(CC) -shared -Wl,-install_name,$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS) 67endif 68 69all: $(DYLIBNAME) $(STLIBNAME) hiredis-test $(PKGCONFNAME) 70 71# Deps (use make dep to generate this) 72async.o: async.c fmacros.h async.h hiredis.h read.h sds.h net.h dict.c dict.h 73dict.o: dict.c fmacros.h dict.h 74hiredis.o: hiredis.c fmacros.h hiredis.h read.h sds.h net.h 75net.o: net.c fmacros.h net.h hiredis.h read.h sds.h 76read.o: read.c fmacros.h read.h sds.h 77sds.o: sds.c sds.h 78test.o: test.c fmacros.h hiredis.h read.h sds.h 79 80$(DYLIBNAME): $(OBJ) 81 $(DYLIB_MAKE_CMD) $(OBJ) 82 83$(STLIBNAME): $(OBJ) 84 $(STLIB_MAKE_CMD) $(OBJ) 85 86dynamic: $(DYLIBNAME) 87static: $(STLIBNAME) 88 89# Binaries: 90hiredis-example-libevent: examples/example-libevent.c adapters/libevent.h $(STLIBNAME) 91 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -levent $(STLIBNAME) 92 93hiredis-example-libev: examples/example-libev.c adapters/libev.h $(STLIBNAME) 94 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -lev $(STLIBNAME) 95 96hiredis-example-glib: examples/example-glib.c adapters/glib.h $(STLIBNAME) 97 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) $(shell pkg-config --cflags --libs glib-2.0) -I. $< $(STLIBNAME) 98 99hiredis-example-ivykis: examples/example-ivykis.c adapters/ivykis.h $(STLIBNAME) 100 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -livykis $(STLIBNAME) 101 102hiredis-example-macosx: examples/example-macosx.c adapters/macosx.h $(STLIBNAME) 103 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< -framework CoreFoundation $(STLIBNAME) 104 105ifndef AE_DIR 106hiredis-example-ae: 107 @echo "Please specify AE_DIR (e.g. <redis repository>/src)" 108 @false 109else 110hiredis-example-ae: examples/example-ae.c adapters/ae.h $(STLIBNAME) 111 $(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) 112endif 113 114ifndef LIBUV_DIR 115hiredis-example-libuv: 116 @echo "Please specify LIBUV_DIR (e.g. ../libuv/)" 117 @false 118else 119hiredis-example-libuv: examples/example-libuv.c adapters/libuv.h $(STLIBNAME) 120 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(LIBUV_DIR)/include $< $(LIBUV_DIR)/.libs/libuv.a -lpthread -lrt $(STLIBNAME) 121endif 122 123ifeq ($(and $(QT_MOC),$(QT_INCLUDE_DIR),$(QT_LIBRARY_DIR)),) 124hiredis-example-qt: 125 @echo "Please specify QT_MOC, QT_INCLUDE_DIR AND QT_LIBRARY_DIR" 126 @false 127else 128hiredis-example-qt: examples/example-qt.cpp adapters/qt.h $(STLIBNAME) 129 $(QT_MOC) adapters/qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \ 130 $(CXX) -x c++ -o qt-adapter-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore 131 $(QT_MOC) examples/example-qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \ 132 $(CXX) -x c++ -o qt-example-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore 133 $(CXX) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore -L$(QT_LIBRARY_DIR) qt-adapter-moc.o qt-example-moc.o $< -pthread $(STLIBNAME) -lQtCore 134endif 135 136hiredis-example: examples/example.c $(STLIBNAME) 137 $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< $(STLIBNAME) 138 139examples: $(EXAMPLES) 140 141hiredis-test: test.o $(STLIBNAME) 142 143hiredis-%: %.o $(STLIBNAME) 144 $(CC) $(REAL_CFLAGS) -o $@ $(REAL_LDFLAGS) $< $(STLIBNAME) 145 146test: hiredis-test 147 ./hiredis-test 148 149check: hiredis-test 150 @echo "$$REDIS_TEST_CONFIG" | $(REDIS_SERVER) - 151 $(PRE) ./hiredis-test -h 127.0.0.1 -p $(REDIS_PORT) -s /tmp/hiredis-test-redis.sock || \ 152 ( kill `cat /tmp/hiredis-test-redis.pid` && false ) 153 kill `cat /tmp/hiredis-test-redis.pid` 154 155.c.o: 156 $(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $< 157 158clean: 159 rm -rf $(DYLIBNAME) $(STLIBNAME) $(TESTS) $(PKGCONFNAME) examples/hiredis-example* *.o *.gcda *.gcno *.gcov 160 161dep: 162 $(CC) -MM *.c 163 164ifeq ($(uname_S),SunOS) 165 INSTALL?= cp -r 166endif 167 168INSTALL?= cp -a 169 170$(PKGCONFNAME): hiredis.h 171 @echo "Generating $@ for pkgconfig..." 172 @echo prefix=$(PREFIX) > $@ 173 @echo exec_prefix=\$${prefix} >> $@ 174 @echo libdir=$(PREFIX)/$(LIBRARY_PATH) >> $@ 175 @echo includedir=$(PREFIX)/$(INCLUDE_PATH) >> $@ 176 @echo >> $@ 177 @echo Name: hiredis >> $@ 178 @echo Description: Minimalistic C client library for Redis. >> $@ 179 @echo Version: $(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(HIREDIS_PATCH) >> $@ 180 @echo Libs: -L\$${libdir} -lhiredis >> $@ 181 @echo Cflags: -I\$${includedir} -D_FILE_OFFSET_BITS=64 >> $@ 182 183install: $(DYLIBNAME) $(STLIBNAME) $(PKGCONFNAME) 184 mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH) 185 $(INSTALL) hiredis.h async.h read.h sds.h adapters $(INSTALL_INCLUDE_PATH) 186 $(INSTALL) $(DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_MINOR_NAME) 187 cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MINOR_NAME) $(DYLIBNAME) 188 $(INSTALL) $(STLIBNAME) $(INSTALL_LIBRARY_PATH) 189 mkdir -p $(INSTALL_PKGCONF_PATH) 190 $(INSTALL) $(PKGCONFNAME) $(INSTALL_PKGCONF_PATH) 191 19232bit: 193 @echo "" 194 @echo "WARNING: if this fails under Linux you probably need to install libc6-dev-i386" 195 @echo "" 196 $(MAKE) CFLAGS="-m32" LDFLAGS="-m32" 197 19832bit-vars: 199 $(eval CFLAGS=-m32) 200 $(eval LDFLAGS=-m32) 201 202gprof: 203 $(MAKE) CFLAGS="-pg" LDFLAGS="-pg" 204 205gcov: 206 $(MAKE) CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs" 207 208coverage: gcov 209 make check 210 mkdir -p tmp/lcov 211 lcov -d . -c -o tmp/lcov/hiredis.info 212 genhtml --legend -o tmp/lcov/report tmp/lcov/hiredis.info 213 214noopt: 215 $(MAKE) OPTIMIZATION="" 216 217.PHONY: all test check clean dep install 32bit 32bit-vars gprof gcov noopt 218