rebased patch attached, no functionality changes

On 2019-06-27 13:45, Peter Eisentraut wrote:
> On several popular operating systems, we can use relative rpaths, using
> the $ORIGIN placeholder, so that the resulting installation is
> relocatable.  Then we also don't need to set LD_LIBRARY_PATH during make
> check.
> 
> This implementation will use a relative rpath if bindir and libdir are
> under the same common parent directory.
> 
> Supported platforms are: freebsd, linux, netbsd, openbsd, solaris
> 
> Information from https://lekensteyn.nl/rpath.html
> 
> (Yes, something for macOS would be nice, to work around SIP issues, but
> I'll leave that as a separate future item.)

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From 6a86e8c64d5bb416c3001dea2dae3f6365085e9b Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Fri, 5 Jul 2019 11:35:44 +0200
Subject: [PATCH v2] Use relative rpath if possible

On several popular operating systems, we can use relative rpaths, using
the $ORIGIN placeholder, so that the resulting installation is
relocatable. Then we also don't need to set LD_LIBRARY_PATH during make
check.

This implementation will use a relative rpath if bindir and libdir are
under the same common parent directory.
---
 src/Makefile.global.in         |  2 +-
 src/makefiles/Makefile.freebsd |  5 +++++
 src/makefiles/Makefile.linux   |  5 +++++
 src/makefiles/Makefile.netbsd  |  5 +++++
 src/makefiles/Makefile.openbsd |  5 +++++
 src/makefiles/Makefile.solaris | 10 ++++++++++
 6 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 321af38b0c..69657e8ab8 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -422,7 +422,7 @@ ld_library_path_var = LD_LIBRARY_PATH
 # nothing.
 with_temp_install = \
        PATH="$(abs_top_builddir)/tmp_install$(bindir):$$PATH" \
-       $(call add_to_path,$(strip 
$(ld_library_path_var)),$(abs_top_builddir)/tmp_install$(libdir)) \
+       $(if $(strip $(ld_library_path_var)),$(call add_to_path,$(strip 
$(ld_library_path_var)),$(abs_top_builddir)/tmp_install$(libdir))) \
        $(with_temp_install_extra)
 
 ifeq ($(enable_tap_tests),yes)
diff --git a/src/makefiles/Makefile.freebsd b/src/makefiles/Makefile.freebsd
index c462e2fd58..ae92dba5ee 100644
--- a/src/makefiles/Makefile.freebsd
+++ b/src/makefiles/Makefile.freebsd
@@ -1,7 +1,12 @@
 AROPT = cr
 
 export_dynamic = -Wl,-export-dynamic
+ifeq ($(dir $(bindir)),$(dir $(libdir)))
+rpath = -Wl,-R'$(subst $(dir $(libdir)),$$ORIGIN/../,$(rpathdir))',-z,origin
+ld_library_path_var =
+else
 rpath = -Wl,-R'$(rpathdir)'
+endif
 
 DLSUFFIX = .so
 
diff --git a/src/makefiles/Makefile.linux b/src/makefiles/Makefile.linux
index ac58fe45de..d967eec9de 100644
--- a/src/makefiles/Makefile.linux
+++ b/src/makefiles/Makefile.linux
@@ -3,7 +3,12 @@ AROPT = crs
 export_dynamic = -Wl,-E
 # Use --enable-new-dtags to generate DT_RUNPATH instead of DT_RPATH.
 # This allows LD_LIBRARY_PATH to still work when needed.
+ifeq ($(dir $(bindir)),$(dir $(libdir)))
+rpath = -Wl,-rpath,'$(subst $(dir 
$(libdir)),$$ORIGIN/../,$(rpathdir))',--enable-new-dtags
+ld_library_path_var =
+else
 rpath = -Wl,-rpath,'$(rpathdir)',--enable-new-dtags
+endif
 
 DLSUFFIX = .so
 
diff --git a/src/makefiles/Makefile.netbsd b/src/makefiles/Makefile.netbsd
index 15695fb65c..4a96be9121 100644
--- a/src/makefiles/Makefile.netbsd
+++ b/src/makefiles/Makefile.netbsd
@@ -1,7 +1,12 @@
 AROPT = cr
 
 export_dynamic = -Wl,-E
+ifeq ($(dir $(bindir)),$(dir $(libdir)))
+rpath = -Wl,-R'$(subst $(dir $(libdir)),$$ORIGIN/../,$(rpathdir))'
+ld_library_path_var =
+else
 rpath = -Wl,-R'$(rpathdir)'
+endif
 
 DLSUFFIX = .so
 
diff --git a/src/makefiles/Makefile.openbsd b/src/makefiles/Makefile.openbsd
index 15695fb65c..36b7420057 100644
--- a/src/makefiles/Makefile.openbsd
+++ b/src/makefiles/Makefile.openbsd
@@ -1,7 +1,12 @@
 AROPT = cr
 
 export_dynamic = -Wl,-E
+ifeq ($(dir $(bindir)),$(dir $(libdir)))
+rpath = -Wl,-R'$(subst $(dir $(libdir)),$$ORIGIN/../,$(rpathdir))',-z,origin
+ld_library_path_var =
+else
 rpath = -Wl,-R'$(rpathdir)'
+endif
 
 DLSUFFIX = .so
 
diff --git a/src/makefiles/Makefile.solaris b/src/makefiles/Makefile.solaris
index a7f5652f0c..b61fdabbad 100644
--- a/src/makefiles/Makefile.solaris
+++ b/src/makefiles/Makefile.solaris
@@ -4,10 +4,20 @@ AROPT = crs
 
 ifeq ($(with_gnu_ld), yes)
 export_dynamic = -Wl,-E
+ifeq ($(dir $(bindir)),$(dir $(libdir)))
+rpath = -Wl,-rpath,'$(subst $(dir $(libdir)),$$ORIGIN/../,$(rpathdir))'
+ld_library_path_var =
+else
 rpath = -Wl,-rpath,'$(rpathdir)'
+endif
+else
+ifeq ($(dir $(bindir)),$(dir $(libdir)))
+rpath = -Wl,-R'$(subst $(dir $(libdir)),$$ORIGIN/../,$(rpathdir))'
+ld_library_path_var =
 else
 rpath = -Wl,-R'$(rpathdir)'
 endif
+endif
 
 DLSUFFIX = .so
 ifeq ($(GCC), yes)

base-commit: 594df378ffb04a72b713a13cc0a7166b3bced7b7
-- 
2.22.0

Reply via email to