On 11.01.23 12:05, Peter Eisentraut wrote:
I think there is also an adjacent issue:  The subdir options may be absolute or relative.  So if you specify --prefix=/usr/local and --sysconfdir=/etc/postgresql, then

     config_paths_data.set_quoted('SYSCONFDIR', dir_prefix / dir_sysconf)

would produce something like /usr/local/etc/postgresql.

I think maybe we should make all the dir_* variables absolute right at the beginning, like

     dir_lib = get_option('libdir')
     if not fs.is_absolute(dir_lib)
         dir_lib = dir_prefix / dir_lib
     endif

And then the appending stuff could be done after that, keeping the current code.

Here is a proposed patch.  This should fix all these issues.
From cad243b60e0a45514f48dfc189069eaf883fc5a6 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Thu, 19 Jan 2023 21:05:01 +0100
Subject: [PATCH] meson: Make all subdirectory variables absolute

Meson subdirectory options may be returned as absolute or relative,
depending on whether they are under prefix.  Meson itself can handle
both, but we might need an absolute path in some cases, so to simplify
this turn all paths to absolute right at the beginning.
---
 meson.build             | 45 +++++++++++++++++++++++++++++++++--------
 src/include/meson.build | 24 +++++++++++-----------
 2 files changed, 49 insertions(+), 20 deletions(-)

diff --git a/meson.build b/meson.build
index 45fb9dd616..edbec530e2 100644
--- a/meson.build
+++ b/meson.build
@@ -457,27 +457,46 @@ endif
 # Directories
 ###############################################################
 
-# These are set by the equivalent --xxxdir configure options.  We
-# append "postgresql" to some of them, if the string does not already
-# contain "pgsql" or "postgres", in order to avoid directory clutter.
+# These are set by the equivalent --xxxdir configure options.
+#
+# Subdirectory options may be returned as absolute or relative,
+# depending on whether they are under prefix.  Meson itself can handle
+# both, but we might need an absolute path in some cases, so to
+# simplify this we turn all paths to absolute here.
+#
+# We append "postgresql" to some of the directories, if the string
+# does not already contain "pgsql" or "postgres", in order to avoid
+# directory clutter.
 
 pkg = 'postgresql'
 
 dir_prefix = get_option('prefix')
 
 dir_bin = get_option('bindir')
+if not fs.is_absolute(dir_bin)
+  dir_bin = dir_prefix / dir_bin
+endif
 
 dir_data = get_option('datadir')
+if not fs.is_absolute(dir_data)
+  dir_data = dir_prefix / dir_data
+endif
 if not (dir_data.contains('pgsql') or dir_data.contains('postgres'))
   dir_data = dir_data / pkg
 endif
 
 dir_sysconf = get_option('sysconfdir')
+if not fs.is_absolute(dir_sysconf)
+  dir_sysconf = dir_prefix / dir_sysconf
+endif
 if not (dir_sysconf.contains('pgsql') or dir_sysconf.contains('postgres'))
   dir_sysconf = dir_sysconf / pkg
 endif
 
 dir_lib = get_option('libdir')
+if not fs.is_absolute(dir_lib)
+  dir_lib = dir_prefix / dir_lib
+endif
 
 dir_lib_pkg = dir_lib
 if not (dir_lib_pkg.contains('pgsql') or dir_lib_pkg.contains('postgres'))
@@ -487,21 +506,31 @@ endif
 dir_pgxs = dir_lib_pkg / 'pgxs'
 
 dir_include = get_option('includedir')
+if not fs.is_absolute(dir_include)
+  dir_include = dir_prefix / dir_include
+endif
 
 dir_include_pkg = dir_include
-dir_include_pkg_rel = ''
 if not (dir_include_pkg.contains('pgsql') or 
dir_include_pkg.contains('postgres'))
   dir_include_pkg = dir_include_pkg / pkg
-  dir_include_pkg_rel = pkg
 endif
 
 dir_man = get_option('mandir')
+if not fs.is_absolute(dir_man)
+  dir_man = dir_prefix / dir_man
+endif
 
 # FIXME: These used to be separately configurable - worth adding?
 dir_doc = get_option('datadir') / 'doc' / 'postgresql'
+if not fs.is_absolute(dir_doc)
+  dir_doc = dir_prefix / dir_doc
+endif
 dir_doc_html = dir_doc
 
 dir_locale = get_option('localedir')
+if not fs.is_absolute(dir_locale)
+  dir_locale = dir_prefix / dir_locale
+endif
 
 
 # Derived values
@@ -2560,9 +2589,9 @@ mod_install_rpaths = []
 if host_system != 'darwin'
   # Add absolute path to libdir to rpath. This ensures installed binaries /
   # libraries find our libraries (mainly libpq).
-  bin_install_rpaths += dir_prefix / dir_lib
-  lib_install_rpaths += dir_prefix / dir_lib
-  mod_install_rpaths += dir_prefix / dir_lib
+  bin_install_rpaths += dir_lib
+  lib_install_rpaths += dir_lib
+  mod_install_rpaths += dir_lib
 
   # Add extra_lib_dirs to rpath. This ensures we find libraries we depend on.
   #
diff --git a/src/include/meson.build b/src/include/meson.build
index 51ad06cecb..b70ffdf785 100644
--- a/src/include/meson.build
+++ b/src/include/meson.build
@@ -28,18 +28,18 @@ configure_files += pg_config
 
 
 config_paths_data = configuration_data()
-config_paths_data.set_quoted('PGBINDIR', dir_prefix / dir_bin)
-config_paths_data.set_quoted('PGSHAREDIR', dir_prefix / dir_data)
-config_paths_data.set_quoted('SYSCONFDIR', dir_prefix / dir_sysconf)
-config_paths_data.set_quoted('INCLUDEDIR', dir_prefix / dir_include)
-config_paths_data.set_quoted('PKGINCLUDEDIR', dir_prefix / dir_include_pkg)
-config_paths_data.set_quoted('INCLUDEDIRSERVER', dir_prefix / 
dir_include_server)
-config_paths_data.set_quoted('LIBDIR', dir_prefix / dir_lib)
-config_paths_data.set_quoted('PKGLIBDIR', dir_prefix / dir_lib_pkg)
-config_paths_data.set_quoted('LOCALEDIR', dir_prefix / dir_locale)
-config_paths_data.set_quoted('DOCDIR', dir_prefix / dir_doc)
-config_paths_data.set_quoted('HTMLDIR', dir_prefix / dir_doc_html)
-config_paths_data.set_quoted('MANDIR', dir_prefix / dir_man)
+config_paths_data.set_quoted('PGBINDIR', dir_bin)
+config_paths_data.set_quoted('PGSHAREDIR', dir_data)
+config_paths_data.set_quoted('SYSCONFDIR', dir_sysconf)
+config_paths_data.set_quoted('INCLUDEDIR', dir_include)
+config_paths_data.set_quoted('PKGINCLUDEDIR', dir_include_pkg)
+config_paths_data.set_quoted('INCLUDEDIRSERVER', dir_include_server)
+config_paths_data.set_quoted('LIBDIR', dir_lib)
+config_paths_data.set_quoted('PKGLIBDIR', dir_lib_pkg)
+config_paths_data.set_quoted('LOCALEDIR', dir_locale)
+config_paths_data.set_quoted('DOCDIR', dir_doc)
+config_paths_data.set_quoted('HTMLDIR', dir_doc_html)
+config_paths_data.set_quoted('MANDIR', dir_man)
 
 
 var_cc = ' '.join(cc.cmd_array())
-- 
2.39.0

Reply via email to