From aee0cd6530c6340f6f0a8256b887c8561f29dde6 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 8 Apr 2021 19:44:53 +0200 Subject: [PATCH] makefiles: static linking enhancements --- Makefile.in | 3 +-- daemons/dmeventd/Makefile.in | 8 ++++---- daemons/lvmlockd/Makefile.in | 14 ++++++-------- libdm/Makefile.in | 6 ++---- libdm/dm-tools/Makefile.in | 25 +++++++++++++------------ libdm/make.tmpl.in | 6 ++---- make.tmpl.in | 6 ++++-- test/Makefile.in | 2 +- test/unit/Makefile | 9 ++++++--- tools/Makefile.in | 13 ++++++------- 10 files changed, 45 insertions(+), 47 deletions(-) diff --git a/Makefile.in b/Makefile.in index 69c73598e..5dd642f63 100644 --- a/Makefile.in +++ b/Makefile.in @@ -18,7 +18,7 @@ top_builddir = @top_builddir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ -SUBDIRS = conf daemons include lib libdaemon libdm man scripts tools +SUBDIRS = libdm conf daemons include lib libdaemon man scripts tools ifeq ("@UDEV_RULES@", "yes") SUBDIRS += udev @@ -56,7 +56,6 @@ tools: lib libdaemon po: tools daemons man: tools all_man: tools -scripts: libdm test: tools daemons unit-test run-unit-test: test diff --git a/daemons/dmeventd/Makefile.in b/daemons/dmeventd/Makefile.in index d688a0d3b..af51198aa 100644 --- a/daemons/dmeventd/Makefile.in +++ b/daemons/dmeventd/Makefile.in @@ -47,6 +47,7 @@ endif LIB_VERSION = $(LIB_VERSION_DM) LIB_SHARED = $(LIB_NAME).$(LIB_SUFFIX) +LIBS = $(PTHREAD_LIBS) -L$(interfacebuilddir) -ldevmapper CLEAN_TARGETS = dmeventd.static $(LIB_NAME).a @@ -67,16 +68,15 @@ device-mapper: $(TARGETS) plugins.device-mapper: $(LIB_SHARED) CFLAGS_dmeventd.o += $(EXTRA_EXEC_CFLAGS) -LIBS += $(PTHREAD_LIBS) -L$(top_builddir)/libdm -ldevmapper dmeventd: $(LIB_SHARED) dmeventd.o @echo " [CC] $@" - $(Q) $(CC) $(CFLAGS) -L. $(LDFLAGS) $(EXTRA_EXEC_LDFLAGS) $(ELDFLAGS) dmeventd.o \ - -o $@ $(DL_LIBS) $(DMEVENT_LIBS) $(LIBS) -lm + $(Q) $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_EXEC_LDFLAGS) $(ELDFLAGS) dmeventd.o \ + -o $@ $(DL_LIBS) $(DMEVENT_LIBS) $(LIBS) dmeventd.static: $(LIB_STATIC) dmeventd.o @echo " [CC] $@" - $(Q) $(CC) $(CFLAGS) $(LDFLAGS) -static -L. -L$(interfacebuilddir) dmeventd.o \ + $(Q) $(CC) $(CFLAGS) $(LDFLAGS) -static dmeventd.o \ -o $@ $(DL_LIBS) $(DMEVENT_LIBS) $(LIBS) $(STATIC_LIBS) ifeq ("@PKGCONFIG@", "yes") diff --git a/daemons/lvmlockd/Makefile.in b/daemons/lvmlockd/Makefile.in index ec5d5750a..e69ab9127 100644 --- a/daemons/lvmlockd/Makefile.in +++ b/daemons/lvmlockd/Makefile.in @@ -37,29 +37,27 @@ TARGETS = lvmlockd lvmlockctl CFLOW_SOURCES = $(addprefix $(srcdir)/, $(SOURCES)) CFLOW_TARGET = lvmlockd -.PHONY: install_lvmlockd +.PHONY: install_lvmlockd install_lvmlockctl include $(top_builddir)/make.tmpl CFLAGS += $(EXTRA_EXEC_CFLAGS) INCLUDES += -I$(top_srcdir)/libdaemon/server LDFLAGS += -L$(top_builddir)/libdaemon/server $(EXTRA_EXEC_LDFLAGS) $(ELDFLAGS) -LIBS += $(RT_LIBS) $(DAEMON_LIBS) $(PTHREAD_LIBS) - +LIBS += $(DAEMON_LIBS) $(PTHREAD_LIBS) ifeq ($(USE_SD_NOTIFY),yes) CFLAGS += $(shell pkg-config --cflags libsystemd) -DUSE_SD_NOTIFY LIBS += $(shell pkg-config --libs libsystemd) endif -lvmlockd: $(OBJECTS) $(top_builddir)/libdaemon/client/libdaemonclient.a \ - $(top_builddir)/libdaemon/server/libdaemonserver.a +lvmlockd: $(OBJECTS) $(top_builddir)/libdaemon/server/libdaemonserver.a $(INTERNAL_LIBS) @echo " [CC] $@" - $(Q) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS) $(LOCK_LIBS) -ldaemonserver $(INTERNAL_LIBS) $(LIBS) + $(Q) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ $(LOCK_LIBS) $(LIBS) -lvmlockctl: lvmlockctl.o $(top_builddir)/libdaemon/client/libdaemonclient.a +lvmlockctl: lvmlockctl.o $(INTERNAL_LIBS) @echo " [CC] $@" - $(Q) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(INTERNAL_LIBS) $(LIBS) + $(Q) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) install_lvmlockd: lvmlockd @echo " [INSTALL] $<" diff --git a/libdm/Makefile.in b/libdm/Makefile.in index a78d2b517..35115d7f0 100644 --- a/libdm/Makefile.in +++ b/libdm/Makefile.in @@ -59,11 +59,9 @@ include $(top_builddir)/libdm/make.tmpl PROGS_CFLAGS = $(UDEV_CFLAGS) -LIBS += $(SELINUX_LIBS) $(UDEV_LIBS) $(PTHREAD_LIBS) $(RT_LIBS) $(M_LIBS) +device-mapper: $(TARGETS) -device-mapper: all - -dm-tools.device-mapper: $(TARGETS) +dm-tools.device-mapper: device-mapper libdevmapper.$(LIB_SUFFIX) libdevmapper.$(LIB_SUFFIX).$(LIB_VERSION): $(LIB_SHARED) @echo " [LN] $<" diff --git a/libdm/dm-tools/Makefile.in b/libdm/dm-tools/Makefile.in index 8fbdfc152..9ddb3c261 100644 --- a/libdm/dm-tools/Makefile.in +++ b/libdm/dm-tools/Makefile.in @@ -52,18 +52,19 @@ include $(top_builddir)/libdm/make.tmpl CFLAGS_dmsetup.o += $(UDEV_CFLAGS) $(EXTRA_EXEC_CFLAGS) CFLAGS_dmfilemapd.o += $(EXTRA_EXEC_CFLAGS) -LDFLAGS += -L$(interfacebuilddir) -DMLIBS = -ldevmapper +LIBDM_LIBS = -L$(interfacebuilddir) -ldevmapper +LIBDM_SHARED = $(interfacebuilddir)/libdevmapper.so +LIBDM_STATIC = $(interfacebuilddir)/libdevmapper.a -dmsetup: dmsetup.o +dmsetup: dmsetup.o $(LIBDM_SHARED) @echo " [CC] $@" $(Q) $(CC) $(CFLAGS) $(LDFLAGS) $(EXTRA_EXEC_LDFLAGS) $(ELDFLAGS) \ - -o $@ $+ $(DMLIBS) + -o $@ $< $(LIBDM_LIBS) $(LIBS) -dmsetup.static: dmsetup.o +dmsetup.static: dmsetup.o $(LIBDM_STATIC) @echo " [CC] $@" $(Q) $(CC) $(CFLAGS) $(LDFLAGS) -static \ - -o $@ $+ $(DMLIBS) $(STATIC_LIBS) + -o $@ $< $(LIBDM_LIBS) $(LIBS) $(STATIC_LIBS) install_dmsetup_dynamic: dmsetup @echo " [INSTALL] $<" @@ -73,18 +74,18 @@ install_dmsetup_dynamic: dmsetup install_dmsetup_static: dmsetup.static @echo " [INSTALL] $<" $(Q) $(INSTALL_PROGRAM) -D $< $(staticdir)/$(