From f4576268a7c364e4e22f707e897ba4eb3bc53101 Mon Sep 17 00:00:00 2001 From: Boyuan Yang <073plan@gmail.com> Date: Wed, 14 Oct 2015 12:04:15 +0800 Subject: [PATCH] add option in configure to use shared libraries --- Makefile.am | 4 ++++ configure.ac | 12 ++++++++++++ src/Makefile.am | 28 ++++++++++++++++++++++------ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index e02138da..5d84f1e8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,8 @@ +if USE_SYSTEM_SHARED_LIB +SUBDIRS = libcork libipset src +else SUBDIRS = libsodium libcork libipset libudns libev src +endif ACLOCAL_AMFLAGS = -I m4 man_MANS = man/shadowsocks-libev.8 man/ss-server.1 man/ss-local.1 man/ss-redir.1\ diff --git a/configure.ac b/configure.ac index 2c136df9..4380e48e 100755 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,18 @@ AC_DISABLE_STATIC AC_DISABLE_SHARED LT_INIT([dlopen]) +dnl Checks for using shared libraries from system +AC_ARG_ENABLE( + [system-shared-lib], + AS_HELP_STRING([--enable-system-shared-lib], [build against shared libraries when possible]), + [ + case "${enableval}" in + yes) enable_system_shared_lib=true ;; + no) enable_system_shared_lib=false ;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-system-shared-lib]) ;; + esac], [enable_system_shared_lib=false]) +AM_CONDITIONAL([USE_SYSTEM_SHARED_LIB], [test x$enable_system_shared_lib = xtrue]) + dnl Checks for crypto library AC_ARG_WITH( [crypto-library], diff --git a/src/Makefile.am b/src/Makefile.am index 968f9516..68f455d2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,17 +2,23 @@ VERSION_INFO = 1:0:0 AM_CFLAGS = -g -O2 -Wall -Werror -Wno-deprecated-declarations -fno-strict-aliasing -std=gnu99 -D_GNU_SOURCE AM_CFLAGS += $(PTHREAD_CFLAGS) +if !USE_SYSTEM_SHARED_LIB AM_CFLAGS += -I$(top_srcdir)/libev AM_CFLAGS += -I$(top_srcdir)/libudns +AM_CFLAGS += -I$(top_srcdir)/libsodium/src/libsodium/include +endif AM_CFLAGS += -I$(top_srcdir)/libipset/include AM_CFLAGS += -I$(top_srcdir)/libcork/include -AM_CFLAGS += -I$(top_srcdir)/libsodium/src/libsodium/include -SS_COMMON_LIBS = $(top_builddir)/libev/libev.la \ - $(top_builddir)/libipset/libipset.la \ - $(top_builddir)/libcork/libcork.la \ - $(top_builddir)/libsodium/src/libsodium/libsodium.la \ - $(INET_NTOP_LIB) +SS_COMMON_LIBS = $(top_builddir)/libipset/libipset.la \ + $(top_builddir)/libcork/libcork.la \ + $(INET_NTOP_LIB) +if USE_SYSTEM_SHARED_LIB +SS_COMMON_LIBS += -lev -lsodium -lm +else +SS_COMMON_LIBS += $(top_builddir)/libev/libev.la \ + $(top_builddir)/libsodium/src/libsodium/libsodium.la +endif bin_PROGRAMS = ss-local ss-tunnel if !BUILD_WINCOMPAT @@ -61,9 +67,15 @@ ss_local_LDADD = $(SS_COMMON_LIBS) ss_tunnel_LDADD = $(SS_COMMON_LIBS) ss_server_LDADD = $(SS_COMMON_LIBS) ss_manager_LDADD = $(SS_COMMON_LIBS) +if USE_SYSTEM_SHARED_LIB +ss_local_LDADD += -ludns +ss_tunnel_LDADD += -ludns +ss_server_LDADD += -ludns +else ss_local_LDADD += $(top_builddir)/libudns/libudns.la ss_tunnel_LDADD += $(top_builddir)/libudns/libudns.la ss_server_LDADD += $(top_builddir)/libudns/libudns.la +endif ss_local_CFLAGS = $(AM_CFLAGS) -DUDPRELAY_LOCAL ss_tunnel_CFLAGS = $(AM_CFLAGS) -DUDPRELAY_LOCAL -DUDPRELAY_TUNNEL @@ -87,8 +99,12 @@ ss_redir_SOURCES = utils.c \ redir.c ss_redir_CFLAGS = $(AM_CFLAGS) -DUDPRELAY_REDIR -DUDPRELAY_LOCAL ss_redir_LDADD = $(SS_COMMON_LIBS) +if USE_SYSTEM_SHARED_LIB +ss_redir_LDADD += -ludns +else ss_redir_LDADD += $(top_builddir)/libudns/libudns.la endif +endif lib_LTLIBRARIES = libshadowsocks.la libshadowsocks_la_SOURCES = $(ss_local_SOURCES)