From 14270f6cea5466c08f0df79f01b926ab82a9c770 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Fri, 5 Apr 2013 14:42:53 +0200 Subject: [PATCH] quick hack to create shared library (use configure --with-shared) --- Makefile.in | 29 +++++++++++++++++++++++++++-- configure.in | 8 +++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Makefile.in b/Makefile.in index 0ded496d..2c807cc3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -10,6 +10,7 @@ VERSION:=@PACKAGE_VERSION@ # tools @SET_MAKE@ +RANLIB=@RANLIB@ SHELL = /bin/sh MKDIR = mkdir ETAGS = @ETAGS@ @@ -31,18 +32,39 @@ DISTDIR=$(top_builddir)/$(package) SUBDIRS:=examples doc @TESTS@ FILES:=ChangeLog README LICENSE.BSD LICENSE.GPL Makefile.in configure configure.in config.h.in $(SOURCES) $(HEADERS) LIB:=libcoap.a +LDSOFLAGS=-shared LDFLAGS:=@LIBS@ ARFLAGS:=cru examples:=examples doc:=doc +@BUILD_SO@ +ifdef BUILD_SO + MACHINE?=$(shell $(CC) -dumpmachine) + ifeq ($(findstring Darwin, $(MACHINE)), Darwin) + LDSOFLAGS=-dynamiclib + LIBSO=libcoap.dylib + endif + ifeq ($(findstring Windows, $(MACHINE)), Windows) + LIBSO=libcoap.dll + endif + # more platforms go here + ifndef LIBSO + LIBSO=libcoap.so + endif + ifndef PICFLAG + CFLAGS+=-fPIC + else + CFLAGS+=$(PICFLAG) + endif +endif .PHONY: all dirs clean distclean .gitignore doc TAGS .SUFFIXES: .SUFFIXES: .c .o -all: $(LIB) dirs +all: $(LIB) $(LIBSO) dirs check: echo DISTDIR: $(DISTDIR) @@ -56,7 +78,10 @@ dirs: $(SUBDIRS) $(LIB): $(OBJECTS) $(AR) $(ARFLAGS) $@ $^ - ranlib $@ + $(RANLIB) $@ + +$(LIBSO): $(OBJECTS) + $(LD) $(LDSOFLAGS) $(LDFLAGS) -o $@ $^ clean: @rm -f $(PROGRAM) main.o $(LIB) $(OBJECTS) diff --git a/configure.in b/configure.in index de06f8a9..47631073 100644 --- a/configure.in +++ b/configure.in @@ -7,7 +7,7 @@ # README for terms of use. AC_PREREQ([2.65]) -AC_INIT([libcoap], [4.0.1]) +AC_INIT([libcoap], [4.0.2]) AC_CONFIG_SRCDIR([coap.h]) # First check for Contiki build to quit configure before any other test @@ -65,6 +65,11 @@ AC_ARG_WITH(tests, [TESTS="tests"], []) +AC_ARG_WITH(shared, + [AS_HELP_STRING([--with-shared],[build shared library])], + [BUILD_SO="BUILD_SO=1"], + []) + # Checks for header files. AC_CHECK_HEADERS([assert.h arpa/inet.h limits.h netdb.h netinet/in.h stdlib.h string.h strings.h sys/socket.h sys/time.h time.h unistd.h sys/unistd.h]) @@ -77,6 +82,7 @@ AC_FUNC_MALLOC AC_CHECK_FUNCS([memset select socket strcasecmp strrchr getaddrinfo strnlen]) AC_SUBST(TESTS) +AC_SUBST(BUILD_SO) AC_CONFIG_HEADERS([config.h])