Build a shared library
This commit is contained in:
parent
7302a5ec69
commit
857c9212d3
6
.gitignore
vendored
6
.gitignore
vendored
@ -1 +1,5 @@
|
|||||||
*.o
|
/hiredis-test
|
||||||
|
/hiredis-example
|
||||||
|
/*.o
|
||||||
|
/*.so
|
||||||
|
/*.dylib
|
||||||
|
41
Makefile
41
Makefile
@ -2,25 +2,31 @@
|
|||||||
# Copyright (C) 2010 Salvatore Sanfilippo <antirez at gmail dot com>
|
# Copyright (C) 2010 Salvatore Sanfilippo <antirez at gmail dot com>
|
||||||
# This file is released under the BSD license, see the COPYING file
|
# This file is released under the BSD license, see the COPYING file
|
||||||
|
|
||||||
|
OBJ = anet.o hiredis.o sds.o
|
||||||
|
BINS = hiredis-example hiredis-test
|
||||||
|
|
||||||
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
|
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
|
||||||
OPTIMIZATION?=-O2
|
OPTIMIZATION?=-O2
|
||||||
ifeq ($(uname_S),SunOS)
|
ifeq ($(uname_S),SunOS)
|
||||||
CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -Wall -W -D__EXTENSIONS__ -D_XPG6
|
CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -D__EXTENSIONS__ -D_XPG6
|
||||||
CCLINK?= -ldl -lnsl -lsocket -lm -lpthread
|
CCLINK?= -ldl -lnsl -lsocket -lm -lpthread
|
||||||
else
|
DYLIBNAME?=libhiredis.so
|
||||||
CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -Wall -W -Wwrite-strings $(ARCH) $(PROF)
|
DYLIB_MAKE_CMD?=gcc -shared -Wl,-soname,${DYLIBNAME} -o ${DYLIBNAME} ${OBJ}
|
||||||
|
else ifeq ($(uname_S),Darwin)
|
||||||
|
CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -Wwrite-strings $(ARCH) $(PROF)
|
||||||
CCLINK?= -lm -pthread
|
CCLINK?= -lm -pthread
|
||||||
|
DYLIBNAME?=libhiredis.dylib
|
||||||
|
DYLIB_MAKE_CMD?=libtool -dynamic -o ${DYLIBNAME} -lm ${DEBUG} - ${OBJ}
|
||||||
|
else
|
||||||
|
CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -fPIC -Wall -W -Wwrite-strings $(ARCH) $(PROF)
|
||||||
|
CCLINK?= -lm -pthread
|
||||||
|
DYLIBNAME?=libhiredis.so
|
||||||
|
DYLIB_MAKE_CMD?=gcc -shared -Wl,-soname,${DYLIBNAME} -o ${DYLIBNAME} ${OBJ}
|
||||||
endif
|
endif
|
||||||
CCOPT= $(CFLAGS) $(CCLINK) $(ARCH) $(PROF)
|
CCOPT= $(CFLAGS) $(CCLINK) $(ARCH) $(PROF)
|
||||||
DEBUG?= -g -rdynamic -ggdb
|
DEBUG?= -g -ggdb
|
||||||
|
|
||||||
OBJ = anet.o hiredis.o sds.o example.o
|
all: ${DYLIBNAME} ${BINS}
|
||||||
TESTOBJ = anet.o hiredis.o sds.o test.o
|
|
||||||
|
|
||||||
PRGNAME = hiredis-example
|
|
||||||
TESTNAME = hiredis-test
|
|
||||||
|
|
||||||
all: hiredis-example hiredis-test
|
|
||||||
|
|
||||||
# Deps (use make dep to generate this)
|
# Deps (use make dep to generate this)
|
||||||
anet.o: anet.c fmacros.h anet.h
|
anet.o: anet.c fmacros.h anet.h
|
||||||
@ -30,18 +36,21 @@ hiredis.o: hiredis.c hiredis.h sds.h anet.h
|
|||||||
sds.o: sds.c sds.h
|
sds.o: sds.c sds.h
|
||||||
hiredis.o: hiredis.c hiredis.h sds.h anet.h
|
hiredis.o: hiredis.c hiredis.h sds.h anet.h
|
||||||
|
|
||||||
hiredis-example: $(OBJ)
|
${DYLIBNAME}: ${OBJ}
|
||||||
$(CC) -o $(PRGNAME) $(CCOPT) $(DEBUG) $(OBJ)
|
${DYLIB_MAKE_CMD}
|
||||||
|
|
||||||
hiredis-test: $(TESTOBJ)
|
# Binaries:
|
||||||
$(CC) -o $(TESTNAME) $(CCOPT) $(DEBUG) $(TESTOBJ)
|
hiredis-%: %.o ${DYLIBNAME}
|
||||||
|
$(CC) -o $@ $(CCOPT) $(DEBUG) -L. -l hiredis -Wl,-rpath,. $<
|
||||||
|
|
||||||
|
test: hiredis-test
|
||||||
./hiredis-test
|
./hiredis-test
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) $<
|
$(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(PRGNAME) $(TESTNAME) *.o *.gcda *.gcno *.gcov
|
rm -rf ${DYLIBNAME} $(BINS) *.o *.gcda *.gcno *.gcov
|
||||||
|
|
||||||
dep:
|
dep:
|
||||||
$(CC) -MM *.c
|
$(CC) -MM *.c
|
||||||
|
Loading…
Reference in New Issue
Block a user