While rpath is frowned upon by Debian and other distro packagers; it
appears embraced by in the world of NetBSD ports and packages.  This is
because ldconfig(8) on NetBSD doesn't put /usr/pkg/lib in its search
path by default.  This behavior differs from the ports and packaging
systems of FreeBSD and OpenBSD which do search library paths of
pkg*-installed packages (and presumably ports).
---
 lib/PublicInbox/XapHelperCxx.pm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/PublicInbox/XapHelperCxx.pm b/lib/PublicInbox/XapHelperCxx.pm
index a22dda1e..1c9a314f 100644
--- a/lib/PublicInbox/XapHelperCxx.pm
+++ b/lib/PublicInbox/XapHelperCxx.pm
@@ -54,6 +54,15 @@ sub build () {
        my $cmd = "$pkg_config --libs --cflags xapian-core";
        chomp(my $fl = `$cmd`);
        die "$cmd failed: \$?=$?" if $?;
+
+       # Using rpath seems acceptable/encouraged in the NetBSD packaging world
+       # since /usr/pkg/lib isn't searched by the dynamic loader by default.
+       # Not sure if other OSes need this, but rpath seems fine for JAOT
+       # binaries (like this one) even if other distros discourage it for
+       # distributed packages.
+       $^O eq 'netbsd' and $fl =~ s/(\A|[ \t])\-L([^ \t]+)([ \t]|\z)/
+                               "$1-L$2 -Wl,-rpath=$2$3"/egsx;
+
        my $cxx = $ENV{CXX} // 'c++';
        $cmd = "$cxx $src $fl $xflags -o $tmp/$prog";
        system($cmd) and die "$cmd failed: \$?=$?";

Reply via email to