meson.build: only set build variables for non-default values

Some preprocessor -Defines have defaults set 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 and DEFAULT_PAGER have appropriate defaults ('vi' 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. Also, the 'git-var' documentation contains some conditional text which documents the chosen compiled in value, which would not read well for the standard values. Similar to the above, only add the corresponding '-a' attribute arguments to the 'asciidoc_common_options' variable, if the values set in the 'options' are different to these standard values. Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramsay Jones committed Apr 17, 2025 at 00:18 UTC 65e3757c240422f4e1ffb8892786a1dfc24894f7
2 files changed +31 -2
Documentation/meson.build
+20
@@ -242,6 +242,16 @@ if docs_backend == 'asciidoc'
242 '--attribute=build_dir=' + meson.current_build_dir(),
243 ]
244
245 + pager_opt = get_option('default_pager')
246 + if pager_opt != '' and pager_opt != 'less'
247 + asciidoc_common_options += '-agit-default-pager=' + pager_opt
248 + endif
249 +
250 + editor_opt = get_option('default_editor')
251 + if editor_opt != '' and editor_opt != 'vi'
252 + asciidoc_common_options += '-agit-default-editor=' + editor_opt
253 + endif
254 +
255 documentation_deps = [
256 asciidoc_conf,
257 ]
@@ -279,6 +289,16 @@ elif docs_backend == 'asciidoctor'
289 '--require', 'asciidoctor-extensions',
290 ]
291
292 + pager_opt = get_option('default_pager')
293 + if pager_opt != '' and pager_opt != 'less'
294 + asciidoc_common_options += '-agit-default-pager=' + pager_opt
295 + endif
296 +
297 + editor_opt = get_option('default_editor')
298 + if editor_opt != '' and editor_opt != 'vi'
299 + asciidoc_common_options += '-agit-default-editor=' + editor_opt
300 + endif
301 +
302 documentation_deps = [
303 asciidoctor_extensions,
304 ]
meson.build
+11 -2
@@ -693,10 +693,8 @@ endif
693 # These variables are used for building libgit.a.
694 libgit_c_args = [
695 '-DBINDIR="' + get_option('bindir') + '"',
696 - '-DDEFAULT_EDITOR="' + get_option('default_editor') + '"',
696 '-DDEFAULT_GIT_TEMPLATE_DIR="' + get_option('datadir') / 'git-core/templates' + '"',
697 '-DDEFAULT_HELP_FORMAT="' + get_option('default_help_format') + '"',
699 - '-DDEFAULT_PAGER="' + get_option('default_pager') + '"',
698 '-DETC_GITATTRIBUTES="' + get_option('gitattributes') + '"',
699 '-DETC_GITCONFIG="' + get_option('gitconfig') + '"',
700 '-DFALLBACK_RUNTIME_PREFIX="' + get_option('prefix') + '"',
@@ -708,6 +706,17 @@ libgit_c_args = [
706 '-DPAGER_ENV="' + get_option('pager_environment') + '"',
707 '-DSHELL_PATH="' + fs.as_posix(shell.full_path()) + '"',
708 ]
709 +
710 +editor_opt = get_option('default_editor')
711 +if editor_opt != '' and editor_opt != 'vi'
712 + libgit_c_args += '-DDEFAULT_EDITOR="' + editor_opt + '"'
713 +endif
714 +
715 +pager_opt = get_option('default_pager')
716 +if pager_opt != '' and pager_opt != 'less'
717 + libgit_c_args += '-DDEFAULT_PAGER="' + pager_opt + '"'
718 +endif
719 +
720 libgit_include_directories = [ '.' ]
721 libgit_dependencies = [ ]
722