Set FLAT_NAMESPACE_FLAGS to -Wl,-flat_namespace in configure only for
macOS and use it unconditionally in Makefiles.

Signed-off-by: Pavel Hrdina <phrd...@redhat.com>
---
 configure.ac      | 13 +++++++++++++
 src/Makefile.am   | 10 +++-------
 tests/Makefile.am |  7 +++----
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/configure.ac b/configure.ac
index e4c0bea94df..75695252898 100644
--- a/configure.ac
+++ b/configure.ac
@@ -189,6 +189,19 @@ esac
 AC_MSG_RESULT([$VERSION_SCRIPT_FLAGS])
 AC_SUBST([VERSION_SCRIPT_FLAGS])
 
+dnl macOS has two-level namespaces by default.
+dnl Override it to allow symbol replacement with DYLD_INSERT_LIBRARIES
+case "$host" in
+  *-*-darwin*)
+    FLAT_NAMESPACE_FLAGS=-Wl,-flat_namespace
+    ;;
+  * )
+    FLAT_NAMESPACE_FLAGS=""
+    ;;
+esac
+AC_MSG_RESULT([$FLAT_NAMESPACE_FLAGS])
+AC_SUBST([FLAT_NAMESPACE_FLAGS])
+
 dnl Specify if we rely on ifconfig instead of iproute2 (e.g. in case
 dnl we're working on BSD)
 want_ifconfig=no
diff --git a/src/Makefile.am b/src/Makefile.am
index 447cff81659..b893f4179e8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -431,13 +431,9 @@ libvirt_la_LDFLAGS = \
                -version-info $(LIBVIRT_VERSION_INFO) \
                $(LIBVIRT_NODELETE) \
                $(NO_UNDEFINED_LDFLAGS) \
-               $(AM_LDFLAGS)
-if WITH_MACOS
-# macOS has two-level namespaces by default.
-# Override it to allow symbol replacement with DYLD_INSERT_LIBRARIES
-libvirt_la_LDFLAGS += -Wl,-flat_namespace
-endif WITH_MACOS
-libvirt_la_LDFLAGS += $(NULL)
+               $(FLAT_NAMESPACE_FLAGS) \
+               $(AM_LDFLAGS) \
+               $(NULL)
 libvirt_la_LIBADD += \
                    $(DLOPEN_LIBS)
 libvirt_la_CFLAGS = -DIN_LIBVIRT $(AM_CFLAGS)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 65d1ceeefdf..06d70ab559c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -55,10 +55,9 @@ MOCKLIBS_LDFLAGS = -avoid-version \
 DRIVERLIB_LDFLAGS = \
        -avoid-version \
        -rpath /evil/libtool/hack/to/force/shared/lib/creation \
-       $(MINGW_EXTRA_LDFLAGS)
-if WITH_MACOS
-DRIVERLIB_LDFLAGS += -Wl,-flat_namespace
-endif WITH_MACOS
+       $(MINGW_EXTRA_LDFLAGS) \
+       $(FLAT_NAMESPACE_FLAGS) \
+       $(NULL)
 
 PROBES_O =
 if WITH_DTRACE_PROBES
-- 
2.26.2

Reply via email to