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

[PATCH 03/12] meson.build: only set build variables for non-default values

From
Ramsay Jones <ramsay@ramsayjones.plus.com>
Date
Mar 15, 2025, 02:46 UTC
Message-ID
<5d0112ae-98b5-46f2-91ad-35ed11358c3e@ramsayjones.plus.com>

Some preprocessor -Defines have defaults sets in the source code when they have not been provided to the C compiler. In this case, there is no need to pass them on the command-line, unless the build requires a non-standard value.

The build variables for DEFAULT_EDITOR, DEFAULT_HELP_FORMAT along with DEFAULT_PAGER have appropriate defaults ('vi', 'man' and 'less') set in the code. Add the preprocessor -Defines to the 'libgit_c_args' only if the values set with the corresponding 'options' are different to these standard values.

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---
 meson.build | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/meson.build b/meson.build
index 88a29fd043..24a4c2e3c2 100644
--- a/meson.build
+++ b/meson.build
@@ -693,10 +693,7 @@ endif
 # These variables are used for building libgit.a.
 libgit_c_args = [
   '-DBINDIR="' + get_option('bindir') + '"',
-  '-DDEFAULT_EDITOR="' + get_option('default_editor') + '"',
   '-DDEFAULT_GIT_TEMPLATE_DIR="' + get_option('datadir') / 'git-core/templates' + '"',
-  '-DDEFAULT_HELP_FORMAT="' + get_option('default_help_format') + '"',
-  '-DDEFAULT_PAGER="' + get_option('default_pager') + '"',
   '-DETC_GITATTRIBUTES="' + get_option('gitattributes') + '"',
   '-DETC_GITCONFIG="' + get_option('gitconfig') + '"',
   '-DFALLBACK_RUNTIME_PREFIX="' + get_option('prefix') + '"',
@@ -708,6 +705,16 @@ libgit_c_args = [
   '-DPAGER_ENV="' + get_option('pager_environment') + '"',
   '-DSHELL_PATH="' + fs.as_posix(shell.full_path()) + '"',
 ]
+if get_option('default_editor') != 'vi'
+  libgit_c_args += '-DDEFAULT_EDITOR="' + get_option('default_editor') + '"'
+endif
+if get_option('default_pager') != 'less'
+  libgit_c_args += '-DDEFAULT_PAGER="' + get_option('default_pager') + '"'
+endif
+if get_option('default_help_format') != 'man'
+  libgit_c_args += '-DDEFAULT_HELP_FORMAT="' + get_option('default_help_format') + '"'
+endif
+
 libgit_include_directories = [ '.' ]
 libgit_dependencies = [ ]
 
-- 
2.49.0
Next: Patrick Steinhardt
Message 1 of 4 in “meson.build: only set build variables for non-default values”
  1. 03/12 meson.build: only set build variables for non-default valuesRamsay Jones, Mar 15, 2025
  2. Patrick SteinhardtMar 19, 2025
  3. Ramsay JonesMar 20, 2025
  4. Patrick SteinhardtMar 20, 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.