Index: aclocal/tcltls_openssl.m4 ================================================================== --- aclocal/tcltls_openssl.m4 +++ aclocal/tcltls_openssl.m4 @@ -49,11 +49,11 @@ TCLTLS_SSL_CFLAGS="-I$openssldir/include" TCLTLS_SSL_CPPFLAGS="-I$openssldir/include" fi pkgConfigExtraArgs='' - if test "$TCLEXT_BUILD" = "static"; then + if test "$TCLEXT_BUILD" = "static" -o "$TCLEXT_TLS_STATIC_SSL" = 'yes'; then pkgConfigExtraArgs='--static' fi dnl Use pkg-config to find the libraries AC_ARG_VAR([TCLTLS_SSL_LIBS], [libraries to pass to the linker for OpenSSL or LibreSSL]) @@ -72,10 +72,34 @@ if test "$TCLEXT_BUILD" = "static"; then dnl If we are doing a static build, save the linker flags for other programs to consume rm -f tcltls.a.linkadd AS_ECHO(["$TCLTLS_SSL_LIBS"]) > tcltls.a.linkadd fi + + dnl If we have been asked to statically link to the SSL library, specifically tell the linker to do so + if test "$TCLEXT_TLS_STATIC_SSL" = 'yes'; then + dnl Don't bother doing this if we aren't actually doing the runtime linking + if test "$TCLEXT_BUILD" != "static"; then + dnl Split the libraries into SSL and non-SSL libraries + new_TCLTLS_SSL_LIBS_normal='' + new_TCLTLS_SSL_LIBS_static='' + for arg in $TCLTLS_SSL_LIBS; do + case "${arg}" in + -ldl|-lrt|-lc|-lpthread|-lm|-lcrypt|-lidn|-lresolv|-lgcc|-lgcc_s|-L*) + new_TCLTLS_SSL_LIBS_normal="${new_TCLTLS_SSL_LIBS_normal} ${arg}" + ;; + -l*) + new_TCLTLS_SSL_LIBS_static="${new_TCLTLS_SSL_LIBS_static} ${arg}" + ;; + *) + new_TCLTLS_SSL_LIBS_normal="${new_TCLTLS_SSL_LIBS_normal} ${arg}" + ;; + esac + done + TCLTLS_SSL_LIBS="${new_TCLTLS_SSL_LIBS_normal} -Wl,-Bstatic ${new_TCLTLS_SSL_LIBS_static} -Wl,-Bdynamic" + fi + fi dnl Save compile-altering variables we are changing SAVE_LIBS="${LIBS}" SAVE_CFLAGS="${CFLAGS}" SAVE_CPPFLAGS="${CPPFLAGS}" Index: configure.in ================================================================== --- configure.in +++ configure.in @@ -113,20 +113,27 @@ dnl Find "xxd" so we can build the tls.tcl.h file AC_CHECK_PROG([XXD], [xxd], [xxd], [__xxd__not__found]) dnl Find "pkg-config" since we need to use it AC_CHECK_TOOL([PKGCONFIG], [pkg-config], [false]) + +dnl Determine if we have been asked to statically link to the SSL library +TCLEXT_TLS_STATIC_SSL='no' +AC_ARG_ENABLE([static-ssl], AS_HELP_STRING([--enable-static-ssl], [enable statically linking to the specified SSL library]), [ + if test "$enableval" = 'yes'; then + TCLEXT_TLS_STATIC_SSL='yes' + fi +]) dnl XXX:TODO: Automatically determine the SSL library to use dnl defaulting to OpenSSL for compatibility reasons if test "$tcltls_ssl_lib" = 'auto'; then tcltls_ssl_lib='openssl' fi AC_MSG_CHECKING([which TLS library to use]) AC_MSG_RESULT([$tcltls_ssl_lib]) - dnl Manually rewrite libressl to OpenSSL since we use the dnl compatibility interface if test "$tcltls_ssl_lib" = "libressl"; then tcltls_ssl_lib='openssl'