diff --git a/Makefile.in b/Makefile.in index 6f01dd16..aed6dbc2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -12,7 +12,8 @@ LDFLAGS=@LDFLAGS@ M4FLAGS=@M4FLAGS@ BISONFLAGS=@BISONFLAGS@ LIBS=@LIBS@ -DAEMON_LIBS=@DAEMON_LIBS@ +COMMON_LIBS=@COMMON_LIBS@ +DAEMON_LIBS=@DAEMON_LIBS@ $(COMMON_LIBS) CLIENT_LIBS=@CLIENT_LIBS@ CC=@CC@ M4=@M4@ @@ -25,6 +26,7 @@ INSTALL_DATA=@INSTALL_DATA@ client=$(addprefix $(exedir)/,@CLIENT@) daemon=$(exedir)/bird +common-lib=$(objdir)/libbird.o.txt protocols=@protocols@ PROTO_BUILD := $(protocols) dev kif krt @@ -88,6 +90,7 @@ tests-target-files = $(patsubst %.c,$(o)%,$(tests_src)) all-daemon = $(daemon): $(obj) all-client = $(client): $(obj) +all-lib = $(common-lib): $(obj) s = $(dir $(lastword $(MAKEFILE_LIST))) ifeq ($(srcdir),.) @@ -156,9 +159,24 @@ $(objdir)/.dir-stamp: Makefile $(Q)mkdir -p $(addprefix $(objdir)/,$(dirs) doc) $(Q)touch $@ +# Composing static library; older GCC's and linkers somehow fail +# both with partial linking with LTO and also with static library creation, +# thus we just collect all the deps and add them to the final build +$(common-lib): + $(E)echo TXT $^ > $@ + $(Q)echo $^ > $@ +# Some time in future, somebody may want to try the following recipe again +# $(E)echo LD $(LDFLAGS) -r -o $@ $^ +# +$(Q)$(CC) $(LDFLAGS) -r -o $@ $^ + +# The lib must be linked last +$(daemon): $(common-lib) + +#$(warning $(patsubst $(common-lib),$(shell cat $(common-lib)),whatever obj/libbird.o.txt)) + $(client) $(daemon): $(E)echo LD $(LDFLAGS) -o $@ $^ $(LIBS) - +$(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) + +$(Q)$(CC) $(LDFLAGS) -o $@ $(patsubst $(common-lib),$(shell cat $(common-lib)),$^) $(LIBS) $(objdir)/sysdep/paths.h: Makefile $(E)echo GEN $@ @@ -171,9 +189,9 @@ $(objdir)/sysdep/paths.h: Makefile tests_targets_ok = $(addsuffix .ok,$(tests_targets)) -$(tests_targets): %: %.o $(tests_objs) | prepare +$(tests_targets): %: %.o $(tests_objs) $(common-lib) | prepare $(E)echo LD $(LDFLAGS) -o $@ $< "..." $(LIBS) - +$(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) + +$(Q)$(CC) $(LDFLAGS) -o $@ $(patsubst $(common-lib),$(shell cat $(common-lib)),$^) $(LIBS) # Hack to avoid problems with tests linking everything $(tests_targets): LIBS += $(DAEMON_LIBS) @@ -222,6 +240,7 @@ install-docs: clean:: rm -f $(objdir)/sysdep/paths.h $(objdir)/nest/proto-build.c rm -f $(addprefix $(exedir)/,bird birdc birdcl) + rm -f $(common-lib) find $(objdir) -name "*.[od]" -exec rm -f '{}' '+' testsclean: diff --git a/configure.ac b/configure.ac index a02052ba..ac5be605 100644 --- a/configure.ac +++ b/configure.ac @@ -137,7 +137,7 @@ BIRD_CHECK_PTHREADS if test "$bird_cv_lib_pthreads" = yes ; then CFLAGS="$CFLAGS -pthread" - LDFLAGS="$LDFLAGS -pthread" + COMMON_LIBS="$COMMON_LIBS -pthread" else AC_MSG_ERROR([POSIX threads not available.]) fi @@ -180,9 +180,13 @@ AC_MSG_RESULT([$CFLAGS]) AC_MSG_CHECKING([LDFLAGS]) AC_MSG_RESULT([$LDFLAGS]) +DAEMON_LIBS="${DAEMON_LIBS} ${LIBS}" +AC_SUBST(DAEMON_LIBS) +AC_SUBST(COMMON_LIBS) + AC_PROG_CPP AC_PROG_INSTALL -AC_PROG_RANLIB + AC_CHECK_PROG([FLEX], [flex], [flex]) AC_CHECK_PROG([BISON], [bison], [bison]) AC_CHECK_PROGS([M4], [gm4 m4]) @@ -276,16 +280,13 @@ fi AC_SUBST([iproutedir]) -DAEMON_LIBS= -AC_SUBST(DAEMON_LIBS) - if test "$enable_libssh" != no ; then AC_CHECK_HEADER([libssh/libssh.h], [true], [fail=yes], [ ]) AC_CHECK_LIB([ssh], [ssh_connect], [true], [fail=yes]) if test "$fail" != yes ; then AC_DEFINE([HAVE_LIBSSH], [1], [Define to 1 if you have the `ssh' library (-lssh).]) - DAEMON_LIBS="-lssh $DAEMON_LIBS" + COMMON_LIBS="-lssh $COMMON_LIBS" enable_libssh=yes else if test "$enable_libssh" = yes ; then diff --git a/lib/Makefile b/lib/Makefile index 9d977e67..d71d462d 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,4 +1,8 @@ -src := a-path.c a-set.c bitmap.c bitops.c blake2s.c blake2b.c checksum.c defer.c event.c flowspec.c idm.c ip.c lists.c lockfree.c mac.c md5.c mempool.c net.c netindex.c patmatch.c printf.c rcu.c resource.c runtime.c sha1.c sha256.c sha512.c slab.c slists.c strtoul.c tbf.c timer.c xmalloc.c +src := bitmap.c bitops.c blake2s.c blake2b.c checksum.c defer.c event.c flowspec.c idm.c ip.c lists.c lockfree.c mac.c md5.c mempool.c net.c netindex.c patmatch.c printf.c rcu.c resource.c runtime.c sha1.c sha256.c sha512.c slab.c slists.c strtoul.c tbf.c timer.c xmalloc.c +obj := $(src-o-files) +$(all-lib) + +src := a-path.c a-set.c obj := $(src-o-files) $(all-daemon) diff --git a/nest/Makefile b/nest/Makefile index d5a66727..6017f79e 100644 --- a/nest/Makefile +++ b/nest/Makefile @@ -1,4 +1,8 @@ -src := cli.c cmds.c iface.c iface-cli.c locks.c mpls.c neighbor.c password.c proto.c proto-build.c rt-attr.c rt-dev.c rt-export.c rt-fib.c rt-show.c rt-table.c +src := iface.c neighbor.c +obj := $(src-o-files) +$(all-lib) + +src := cli.c cmds.c iface-cli.c locks.c mpls.c password.c proto.c proto-build.c rt-attr.c rt-dev.c rt-export.c rt-fib.c rt-show.c rt-table.c obj := $(src-o-files) $(all-daemon) $(cf-local) diff --git a/sysdep/unix/Makefile b/sysdep/unix/Makefile index 574d19bd..961d58e4 100644 --- a/sysdep/unix/Makefile +++ b/sysdep/unix/Makefile @@ -1,4 +1,8 @@ -src := alloc.c io.c io-cli.c io-loop.c krt.c log.c main.c random.c domain.c socket.c file.c time.c +src := alloc.c domain.c file.c io-loop.c log.c socket.c random.c time.c +obj := $(src-o-files) +$(all-lib) + +src := io.c io-cli.c krt.c main.c obj := $(src-o-files) $(all-daemon) $(cf-local)