From 96d6424087cf2d35b81df032050e2c1fc07ee74a Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Fri, 3 Nov 2023 10:06:00 -0700
Subject: [PATCH v3 5/5] meson: Add -Dpkglibdir option

Author:
Reviewed-by:
Discussion: https://postgr.es/m/20231103163848.26egkh5qdgw3vmil@awork3.anarazel.de
Backpatch:
---
 meson.build                    |  9 ++++++---
 meson_options.txt              |  3 +++
 doc/src/sgml/installation.sgml | 18 +++++++++++++++---
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/meson.build b/meson.build
index ee58ee7a065..ed4c664e6eb 100644
--- a/meson.build
+++ b/meson.build
@@ -492,9 +492,12 @@ endif
 
 dir_lib = get_option('libdir')
 
-dir_lib_pkg = dir_lib
-if not (dir_prefix_contains_pg or dir_lib_pkg.contains('pgsql') or dir_lib_pkg.contains('postgres'))
-  dir_lib_pkg = dir_lib_pkg / pkg
+dir_lib_pkg = get_option('pkglibdir')
+if dir_lib_pkg == ''
+  dir_lib_pkg = dir_lib
+  if not (dir_prefix_contains_pg or dir_lib_pkg.contains('pgsql') or dir_lib_pkg.contains('postgres'))
+    dir_lib_pkg = dir_lib_pkg / pkg
+  endif
 endif
 
 dir_pgxs = dir_lib_pkg / 'pgxs'
diff --git a/meson_options.txt b/meson_options.txt
index be1b327f544..82441b4d524 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -70,6 +70,9 @@ option('darwin_sysroot', type: 'string', value: '',
 option('rpath', type: 'boolean', value: true,
   description: 'Embed shared library search path in executables')
 
+option('pkglibdir', type: 'string', value: '',
+  description: 'Directory to install / load dynamically loadable modules from')
+
 
 # External dependencies
 
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index b23b35cd8e7..3b6e49dbdbb 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -2254,9 +2254,21 @@ ninja install
        <term><option>--libdir=<replaceable>DIRECTORY</replaceable></option></term>
        <listitem>
         <para>
-         Sets the location to install libraries and dynamically loadable
-         modules. The default is
-         <filename><replaceable>PREFIX</replaceable>/lib</filename>.
+         Sets the location to install libraries. The default is
+         <filename><replaceable>PREFIX</replaceable>/lib</filename>. This
+         option, unless <xref linkend='configure-pkglibdir-meson'/> is
+         specified, also controls where dynamically loadable modules get
+         installed.
+        </para>
+       </listitem>
+      </varlistentry>
+
+      <varlistentry id="configure-pkglibdir-meson">
+       <term><option>-Dpkglibdir=<replaceable>DIRECTORY</replaceable></option></term>
+       <listitem>
+        <para>
+         Sets the location to dynamically loadable modules. The default is set
+         by <xref linkend='configure-libdir-meson'/>.
         </para>
        </listitem>
       </varlistentry>
-- 
2.38.0

