git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 3/5] meson: correct path to system config/attribute files

From
Ramsay Jones <ramsay@ramsayjones.plus.com>
Date
May 19, 2025, 16:25 UTC
Message-ID
<20250519162523.1001478-4-ramsay@ramsayjones.plus.com>
In-Reply-To
<20250519162523.1001478-1-ramsay@ramsayjones.plus.com>

The path to the system-wide config and attributes files are not being set correctly in the meson build. Unless explicitly overridden on the command line during setup, the 'gitconfig' and 'gitattributes' options are defaulting to absolute paths in the '/etc' system directory. This is only appropriate if the <prefix> is set specifically to '/usr'.

The directory in which these files are placed is generally referred to as the 'system configuration directory' or 'sysconfdir' for short. When the prefix is '/usr' then the sysconfdir is usually set to '/etc', but any other value for prefix results in the relative directory value 'etc' instead. (eg if prefix is '/usr/local', then the 'etc' relative value results in a system configuration directory of '/usr/local/etc'). When setting the 'sysconfdir' builtin option value, the meson system uses exactly this algorithm, so we can use get_option('sysconfdir') directly when setting the (non-overridden) build variables.

In order to allow for overriding from the command line, remove the default values specified for the 'gitconfig' and 'gitattributes' options in the 'meson_options.txt' file. This allows the user to specify any pathname for those options, while being able to test for the unset (empty) value. An absolute pathname will be used unchanged and a relative pathname will be appended to '<prefix>/'. These values are then used to set the 'ETC_GITCONFIG' and 'ETC_GITATTRIBUTES' build variables which are, in turn, passed to the compiler as '-D' arguments.

When the 'gitconfig' or 'gitattributes' options are not used, then use the built-in 'sysconfdir' and set the ETC_GITCONFIG build variable to the string "<sysconfdir>/gitconfig". Similarly, set ETC_ATTRIBUTES to "<sysconfdir>/gitattributes".

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---
 meson.build       | 16 ++++++++++++++--
 meson_options.txt |  8 ++++----
 2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/meson.build b/meson.build
index 48f31157a0..8e8f228a37 100644
--- a/meson.build
+++ b/meson.build
@@ -757,8 +757,6 @@ endif
 libgit_c_args = [
   '-DBINDIR="' + get_option('bindir') + '"',
   '-DDEFAULT_GIT_TEMPLATE_DIR="' + get_option('datadir') / 'git-core/templates' + '"',
-  '-DETC_GITATTRIBUTES="' + get_option('gitattributes') + '"',
-  '-DETC_GITCONFIG="' + get_option('gitconfig') + '"',
   '-DFALLBACK_RUNTIME_PREFIX="' + get_option('prefix') + '"',
   '-DGIT_HOST_CPU="' + host_machine.cpu_family() + '"',
   '-DGIT_HTML_PATH="' + get_option('datadir') / 'doc/git-doc"',
@@ -769,6 +767,20 @@ libgit_c_args = [
   '-DSHELL_PATH="' + fs.as_posix(target_shell.full_path()) + '"',
 ]
 
+system_attributes = get_option('gitattributes')
+if system_attributes != ''
+  libgit_c_args += '-DETC_GITATTRIBUTES="' + system_attributes + '"'
+else
+  libgit_c_args += '-DETC_GITATTRIBUTES="' + get_option('sysconfdir') / 'gitattributes"'
+endif
+
+system_config = get_option('gitconfig')
+if system_config != ''
+  libgit_c_args += '-DETC_GITCONFIG="' + system_config + '"'
+else
+  libgit_c_args += '-DETC_GITCONFIG="' + get_option('sysconfdir') / 'gitconfig"'
+endif
+
 editor_opt = get_option('default_editor')
 if editor_opt != '' and editor_opt != 'vi'
   libgit_c_args += '-DDEFAULT_EDITOR="' + editor_opt + '"'
diff --git a/meson_options.txt b/meson_options.txt
index 8547c0eb47..5afbf8ec00 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -3,10 +3,10 @@ option('default_pager', type: 'string', value: 'less',
   description: 'Fall-back pager.')
 option('default_editor', type: 'string', value: 'vi',
   description: 'Fall-back editor.')
-option('gitconfig', type: 'string', value: '/etc/gitconfig',
-  description: 'Path to the global git configuration file.')
-option('gitattributes', type: 'string', value: '/etc/gitattributes',
-  description: 'Path to the global git attributes file.')
+option('gitconfig', type: 'string',
+  description: 'Path to the global git configuration file. (default: etc/gitconfig)')
+option('gitattributes', type: 'string',
+  description: 'Path to the global git attributes file. (default: etc/gitattributes)')
 option('pager_environment', type: 'string', value: 'LESS=FRX LV=-c',
   description: 'Environment used when spawning the pager')
 option('perl_cpan_fallback', type: 'boolean', value: true,
-- 
2.49.0
Previous: Ramsay JonesNext: Ramsay Jones
Message 42 of 48 in “miscellaneous build mods (part 2)”
  1. 0/5 miscellaneous build mods (part 2)Ramsay Jones, May 8, 2025
  2. 1/5 meson.build: quote the GITWEBDIR build configurationRamsay Jones, May 8, 2025
  3. 2/5 meson: correct install location of YAML.pmRamsay Jones, May 8, 2025
  4. 3/5 meson: correct path to system config/attribute filesRamsay Jones, May 8, 2025
  5. 4/5 meson.build: correct setting of GIT_EXEC_PATHRamsay Jones, May 8, 2025
  6. 5/5 configure.ac: upgrade to a compilation check for sysinfoRamsay Jones, May 8, 2025
  7. Eli SchwartzMay 8, 2025
  8. Ramsay JonesMay 8, 2025
  9. Eli SchwartzMay 15, 2025
  10. Junio C HamanoMay 8, 2025
  11. Junio C HamanoMay 8, 2025
  12. Eli SchwartzMay 8, 2025
  13. Junio C HamanoMay 9, 2025
  14. Ramsay JonesMay 8, 2025
  15. Patrick SteinhardtMay 9, 2025
  16. Ramsay JonesMay 9, 2025
  17. Ramsay JonesMay 8, 2025
  18. 0/5 miscellaneous build mods (part 2)Ramsay Jones, May 13, 2025
  19. 1/5 meson.build: quote the GITWEBDIR build configurationRamsay Jones, May 13, 2025
  20. 2/5 meson: correct install location of YAML.pmRamsay Jones, May 13, 2025
  21. 3/5 meson: correct path to system config/attribute filesRamsay Jones, May 13, 2025
  22. Patrick SteinhardtMay 14, 2025
  23. Ramsay JonesMay 15, 2025
  24. Eli SchwartzMay 15, 2025
  25. Ramsay JonesMay 15, 2025
  26. Patrick SteinhardtMay 16, 2025
  27. 4/5 meson.build: correct setting of GIT_EXEC_PATHRamsay Jones, May 13, 2025
  28. irecca.kun@gmail.comJun 16, 2025
  29. 5/5 configure.ac: upgrade to a compilation check for sysinfoRamsay Jones, May 13, 2025
  30. Junio C HamanoMay 13, 2025
  31. Ramsay JonesMay 13, 2025
  32. 0/5 miscellaneous build mods (part 2)Ramsay Jones, May 16, 2025
  33. 1/5 meson.build: quote the GITWEBDIR build configurationRamsay Jones, May 16, 2025
  34. 2/5 meson: correct install location of YAML.pmRamsay Jones, May 16, 2025
  35. 3/5 meson: correct path to system config/attribute filesRamsay Jones, May 16, 2025
  36. Patrick SteinhardtMay 19, 2025
  37. 4/5 meson.build: correct setting of GIT_EXEC_PATHRamsay Jones, May 16, 2025
  38. 5/5 configure.ac: upgrade to a compilation check for sysinfoRamsay Jones, May 16, 2025
  39. 0/5 miscellaneous build mods (part 2)Ramsay Jones, May 19, 2025
  40. 1/5 meson.build: quote the GITWEBDIR build configurationRamsay Jones, May 19, 2025
  41. 2/5 meson: correct install location of YAML.pmRamsay Jones, May 19, 2025
  42. 3/5 meson: correct path to system config/attribute filesRamsay Jones, May 19, 2025
  43. 4/5 meson.build: correct setting of GIT_EXEC_PATHRamsay Jones, May 19, 2025
  44. 5/5 configure.ac: upgrade to a compilation check for sysinfoRamsay Jones, May 19, 2025
  45. Junio C HamanoMay 19, 2025
  46. Patrick SteinhardtMay 19, 2025
  47. Ramsay JonesMay 19, 2025
  48. Junio C HamanoMay 19, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.