This option can be used to get statically linked binaries.
Note: libfrr.la is removed from modules' library dependency list. This
is intentional and explained in a comment in lib/subdir.am.
Signed-off-by: David Lamparter <equinox@diac24.net>
-I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/lib
AM_LDFLAGS = \
-export-dynamic \
+ $(AC_LDFLAGS) \
$(SAN_FLAGS) \
# end
DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" -DCONFDATE=$(CONFDATE)
aclocal.m4 \
README.md \
m4/README.txt \
+ m4/libtool-whole-archive.patch \
\
python/clidef.py \
python/clippy/__init__.py \
dnl -------
dnl libtool
dnl -------
+AC_ARG_ENABLE(static-bin,
+ AS_HELP_STRING([--enable-static-bin], [link binaries statically]))
LT_INIT
+_LT_CONFIG_LIBTOOL([
+ patch -N -i "${srcdir}/m4/libtool-whole-archive.patch" libtool >&AS_MESSAGE_LOG_FD || \
+ AC_MSG_WARN([Could not patch libtool for static linking support. Loading modules into a statically linked daemon will fail.])
+])
+if test "$enable_static_bin" = "yes"; then
+ AC_LDFLAGS="-static"
+fi
+AC_SUBST(AC_LDFLAGS)
+AM_CONDITIONAL([STATIC_BIN], [test "x$enable_static_bin" = "xyes"])
dnl ----------------------
dnl Packages configuration
lib/plist_int.h \
#end
+# General note about module and module helper library (libfrrsnmp, libfrrzmq)
+# linking: If we're linking libfrr statically into daemons, we *must* remove
+# libfrr from modules because modules will always link it in dynamically and
+# thus 2 copies of libfrr will be loaded... hilarity ensues.
+#
+# Not linking libfrr into modules should generally work fine because the
+# executable refers to libfrr either way and the dynamic linker should make
+# libfrr available to modules. If some OS platform has a dynamic linker that
+# doesn't do that, libfrr needs to be readded to modules, but _only_ _if_
+# it's not linked into daemons statically.
+
#
# SNMP support
#
lib_libfrrsnmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) -std=gnu99
lib_libfrrsnmp_la_LDFLAGS = -version-info 0:0:0
-lib_libfrrsnmp_la_LIBADD = lib/libfrr.la $(SNMP_LIBS)
+lib_libfrrsnmp_la_LIBADD = $(SNMP_LIBS)
lib_libfrrsnmp_la_SOURCES = \
lib/agentx.c \
lib/snmp.c \
lib_libfrrzmq_la_CFLAGS = $(WERROR) $(ZEROMQ_CFLAGS)
lib_libfrrzmq_la_LDFLAGS = -version-info 0:0:0
-lib_libfrrzmq_la_LIBADD = lib/libfrr.la $(ZEROMQ_LIBS)
+lib_libfrrzmq_la_LIBADD = $(ZEROMQ_LIBS)
lib_libfrrzmq_la_SOURCES = \
lib/frr_zmq.c \
#end
*.m4
+!*.patch
!ax_compare_version.m4
!ax_prog_perl_modules.m4
--- /dev/null
+--- /usr/share/libtool/build-aux/ltmain.sh 2017-08-01 07:13:09.611041402 +0200
++++ ltmain.sh 2018-08-31 17:32:15.381903718 +0200
+@@ -8439,8 +8439,13 @@
+ # shared platforms.
+ if test unsupported != "$hardcode_direct"; then
+ test -n "$old_library" && linklib=$old_library
+- compile_deplibs="$dir/$linklib $compile_deplibs"
+- finalize_deplibs="$dir/$linklib $finalize_deplibs"
++ if test yes,yes = "$export_dynamic,$with_gnu_ld"; then
++ compile_deplibs="-Wl,--no-whole-archive $dir/$linklib -Wl,--whole-archive $compile_deplibs"
++ finalize_deplibs="-Wl,--no-whole-archive $dir/$linklib -Wl,--whole-archive $finalize_deplibs"
++ else
++ compile_deplibs="$dir/$linklib $compile_deplibs"
++ finalize_deplibs="$dir/$linklib $finalize_deplibs"
++ fi
+ else
+ compile_deplibs="-l$name -L$dir $compile_deplibs"
+ finalize_deplibs="-l$name -L$dir $finalize_deplibs"
ospfclient_ospfclient_LDADD = \
ospfclient/libfrrospfapiclient.la \
- lib/libfrr.la \
@LIBCAP@ \
# end
+
+if STATIC_BIN
+# libfrr is linked in through libfrrospfapiclient. If we list it here too,
+# it gets linked twice and we get a ton of symbol collisions.
+
+else # !STATIC_BIN
+# For most systems we don't need this, except Debian, who patch their linker
+# to disallow transitive references *while* *als* not patching their libtool
+# to work appropriately. RedHat has the same linker behaviour, but things
+# work as expected since they also patch libtool.
+ospfclient_ospfclient_LDADD += lib/libfrr.la
+endif
+
ospfclient_ospfclient_SOURCES = \
ospfclient/ospfclient.c \
# end