From efc9cc54de401cb7e20e02d4edbe85384ecf01a2 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Sun, 19 Mar 2023 11:17:54 -0700
Subject: [PATCH v2 4/8] meson: add install-{quiet, world} targets

---
 meson.build                                | 36 ++++++++++++++++++++++
 src/backend/po/meson.build                 |  2 +-
 src/bin/initdb/po/meson.build              |  2 +-
 src/bin/pg_amcheck/po/meson.build          |  2 +-
 src/bin/pg_archivecleanup/po/meson.build   |  2 +-
 src/bin/pg_basebackup/po/meson.build       |  2 +-
 src/bin/pg_checksums/po/meson.build        |  2 +-
 src/bin/pg_config/po/meson.build           |  2 +-
 src/bin/pg_controldata/po/meson.build      |  2 +-
 src/bin/pg_ctl/po/meson.build              |  2 +-
 src/bin/pg_dump/po/meson.build             |  2 +-
 src/bin/pg_resetwal/po/meson.build         |  2 +-
 src/bin/pg_rewind/po/meson.build           |  2 +-
 src/bin/pg_test_fsync/po/meson.build       |  2 +-
 src/bin/pg_test_timing/po/meson.build      |  2 +-
 src/bin/pg_upgrade/po/meson.build          |  2 +-
 src/bin/pg_verifybackup/po/meson.build     |  2 +-
 src/bin/pg_waldump/po/meson.build          |  2 +-
 src/bin/psql/po/meson.build                |  2 +-
 src/bin/scripts/po/meson.build             |  2 +-
 src/interfaces/libpq/po/meson.build        |  2 +-
 src/interfaces/libpq/test/meson.build      |  4 +--
 src/pl/plperl/po/meson.build               |  2 +-
 src/pl/plpgsql/src/po/meson.build          |  2 +-
 src/pl/plpython/po/meson.build             |  2 +-
 src/pl/tcl/po/meson.build                  |  2 +-
 src/interfaces/ecpg/ecpglib/po/meson.build |  2 +-
 src/interfaces/ecpg/preproc/po/meson.build |  2 +-
 28 files changed, 64 insertions(+), 28 deletions(-)

diff --git a/meson.build b/meson.build
index 33dd5b43ed5..bd1c1bf9f1d 100644
--- a/meson.build
+++ b/meson.build
@@ -2543,6 +2543,7 @@ bin_targets = []
 pl_targets = []
 contrib_targets = []
 testprep_targets = []
+nls_targets = []
 
 
 # Define the tests to distribute them to the correct test styles later
@@ -3185,6 +3186,7 @@ if meson.version().version_compare('>=0.57')
 endif
 
 
+
 ###############################################################
 # Pseudo targets
 ###############################################################
@@ -3195,6 +3197,40 @@ alias_target('pl', pl_targets)
 alias_target('contrib', contrib_targets)
 alias_target('testprep', testprep_targets)
 
+# i18n.gettext() doesn't return the dependencies before 0.60 - but the gettext
+# generation happens during install, so that's not a real issue.
+nls_mo_targets = []
+if libintl.found() and meson.version().version_compare('>=0.60')
+  # use range() to avoid the flattening of the list that forech() would do
+  foreach off : range(0, nls_targets.length())
+    # i18n.gettext() list containing 1) list of built .mo files 2) maintainer
+    # -pot target 3) maintainer -pot target
+    nls_mo_targets += nls_targets[off][0]
+  endforeach
+  alias_target('nls', nls_mo_targets)
+endif
+
+all_built = [
+  backend_targets,
+  bin_targets,
+  libpq_st,
+  pl_targets,
+  contrib_targets,
+  nls_mo_targets,
+  testprep_targets,
+  ecpg_targets,
+]
+
+install_quiet = custom_target('install-quiet',
+  output: 'install-quiet',
+  build_always_stale: true,
+  build_by_default: false,
+  command: meson_args + ['install', '--quiet', '--no-rebuild'],
+  depends: all_built,
+)
+
+alias_target('install-world', install_quiet, installdocs)
+
 
 
 ###############################################################
diff --git a/src/backend/po/meson.build b/src/backend/po/meson.build
index 772399b0bd8..b3cb083eb2c 100644
--- a/src/backend/po/meson.build
+++ b/src/backend/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('postgres-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('postgres-' + pg_version_major.to_string())]
diff --git a/src/bin/initdb/po/meson.build b/src/bin/initdb/po/meson.build
index 6506c5264ee..ad193984175 100644
--- a/src/bin/initdb/po/meson.build
+++ b/src/bin/initdb/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('initdb-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('initdb-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_amcheck/po/meson.build b/src/bin/pg_amcheck/po/meson.build
index 9cb62eaaae2..618de4f4458 100644
--- a/src/bin/pg_amcheck/po/meson.build
+++ b/src/bin/pg_amcheck/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_amcheck-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_amcheck-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_archivecleanup/po/meson.build b/src/bin/pg_archivecleanup/po/meson.build
index 79957fa2b98..c6f33edcad1 100644
--- a/src/bin/pg_archivecleanup/po/meson.build
+++ b/src/bin/pg_archivecleanup/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_archivecleanup-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_archivecleanup-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_basebackup/po/meson.build b/src/bin/pg_basebackup/po/meson.build
index 437f7e0606f..2a39f5ffeba 100644
--- a/src/bin/pg_basebackup/po/meson.build
+++ b/src/bin/pg_basebackup/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_basebackup-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_basebackup-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_checksums/po/meson.build b/src/bin/pg_checksums/po/meson.build
index 273f55d9012..97b20f263cf 100644
--- a/src/bin/pg_checksums/po/meson.build
+++ b/src/bin/pg_checksums/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_checksums-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_checksums-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_config/po/meson.build b/src/bin/pg_config/po/meson.build
index 7e4629ffc4e..f515af816ea 100644
--- a/src/bin/pg_config/po/meson.build
+++ b/src/bin/pg_config/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_config-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_config-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_controldata/po/meson.build b/src/bin/pg_controldata/po/meson.build
index 73a77568b6f..685f1c167a7 100644
--- a/src/bin/pg_controldata/po/meson.build
+++ b/src/bin/pg_controldata/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_controldata-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_controldata-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_ctl/po/meson.build b/src/bin/pg_ctl/po/meson.build
index da7710090e0..3d35f7ad211 100644
--- a/src/bin/pg_ctl/po/meson.build
+++ b/src/bin/pg_ctl/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_ctl-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_ctl-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_dump/po/meson.build b/src/bin/pg_dump/po/meson.build
index 3b627711d73..cc9d3680119 100644
--- a/src/bin/pg_dump/po/meson.build
+++ b/src/bin/pg_dump/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_dump-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_dump-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_resetwal/po/meson.build b/src/bin/pg_resetwal/po/meson.build
index c82c6a4263f..fa75d287526 100644
--- a/src/bin/pg_resetwal/po/meson.build
+++ b/src/bin/pg_resetwal/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_resetwal-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_resetwal-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_rewind/po/meson.build b/src/bin/pg_rewind/po/meson.build
index b0ccd16bbb9..bffe7debea9 100644
--- a/src/bin/pg_rewind/po/meson.build
+++ b/src/bin/pg_rewind/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_rewind-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_rewind-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_test_fsync/po/meson.build b/src/bin/pg_test_fsync/po/meson.build
index b25a6d0f826..46d0ac587e2 100644
--- a/src/bin/pg_test_fsync/po/meson.build
+++ b/src/bin/pg_test_fsync/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_test_fsync-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_test_fsync-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_test_timing/po/meson.build b/src/bin/pg_test_timing/po/meson.build
index 918225a1cf5..7bc84d5c7ff 100644
--- a/src/bin/pg_test_timing/po/meson.build
+++ b/src/bin/pg_test_timing/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_test_timing-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_test_timing-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_upgrade/po/meson.build b/src/bin/pg_upgrade/po/meson.build
index b4ba67b1c5e..8531c3b31ef 100644
--- a/src/bin/pg_upgrade/po/meson.build
+++ b/src/bin/pg_upgrade/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_upgrade-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_upgrade-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_verifybackup/po/meson.build b/src/bin/pg_verifybackup/po/meson.build
index 092b8a95f31..181cf640e71 100644
--- a/src/bin/pg_verifybackup/po/meson.build
+++ b/src/bin/pg_verifybackup/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_verifybackup-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_verifybackup-' + pg_version_major.to_string())]
diff --git a/src/bin/pg_waldump/po/meson.build b/src/bin/pg_waldump/po/meson.build
index 076dbcafb42..c4188032d71 100644
--- a/src/bin/pg_waldump/po/meson.build
+++ b/src/bin/pg_waldump/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pg_waldump-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pg_waldump-' + pg_version_major.to_string())]
diff --git a/src/bin/psql/po/meson.build b/src/bin/psql/po/meson.build
index da257154d4c..103ed93a789 100644
--- a/src/bin/psql/po/meson.build
+++ b/src/bin/psql/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('psql-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('psql-' + pg_version_major.to_string())]
diff --git a/src/bin/scripts/po/meson.build b/src/bin/scripts/po/meson.build
index a28ec9ed049..00a9f208acf 100644
--- a/src/bin/scripts/po/meson.build
+++ b/src/bin/scripts/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pgscripts-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pgscripts-' + pg_version_major.to_string())]
diff --git a/src/interfaces/libpq/po/meson.build b/src/interfaces/libpq/po/meson.build
index 5489b23b795..a7a1df87ae3 100644
--- a/src/interfaces/libpq/po/meson.build
+++ b/src/interfaces/libpq/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('libpq' + '5' + '-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('libpq' + '5' + '-' + pg_version_major.to_string())]
diff --git a/src/interfaces/libpq/test/meson.build b/src/interfaces/libpq/test/meson.build
index b2a4b06fd23..d56b63e1186 100644
--- a/src/interfaces/libpq/test/meson.build
+++ b/src/interfaces/libpq/test/meson.build
@@ -10,7 +10,7 @@ if host_system == 'windows'
     '--FILEDESC', 'libpq test program',])
 endif
 
-executable('libpq_uri_regress',
+testprep_targets += executable('libpq_uri_regress',
   libpq_uri_regress_sources,
   dependencies: [frontend_code, libpq],
   kwargs: default_bin_args + {
@@ -29,7 +29,7 @@ if host_system == 'windows'
     '--FILEDESC', 'libpq test program',])
 endif
 
-executable('libpq_testclient',
+testprep_targets += executable('libpq_testclient',
   libpq_testclient_sources,
   dependencies: [frontend_code, libpq],
   kwargs: default_bin_args + {
diff --git a/src/pl/plperl/po/meson.build b/src/pl/plperl/po/meson.build
index 2c3cd190cd9..f1c8e7d00a1 100644
--- a/src/pl/plperl/po/meson.build
+++ b/src/pl/plperl/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('plperl-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('plperl-' + pg_version_major.to_string())]
diff --git a/src/pl/plpgsql/src/po/meson.build b/src/pl/plpgsql/src/po/meson.build
index 1fa97d6ab50..aad875948b6 100644
--- a/src/pl/plpgsql/src/po/meson.build
+++ b/src/pl/plpgsql/src/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('plpgsql-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('plpgsql-' + pg_version_major.to_string())]
diff --git a/src/pl/plpython/po/meson.build b/src/pl/plpython/po/meson.build
index e5457069b47..ddaa1913b84 100644
--- a/src/pl/plpython/po/meson.build
+++ b/src/pl/plpython/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('plpython-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('plpython-' + pg_version_major.to_string())]
diff --git a/src/pl/tcl/po/meson.build b/src/pl/tcl/po/meson.build
index 3e7d3287f84..9e5c8e95f15 100644
--- a/src/pl/tcl/po/meson.build
+++ b/src/pl/tcl/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('pltcl-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('pltcl-' + pg_version_major.to_string())]
diff --git a/src/interfaces/ecpg/ecpglib/po/meson.build b/src/interfaces/ecpg/ecpglib/po/meson.build
index 95e748d9fa5..39fcc93bfcc 100644
--- a/src/interfaces/ecpg/ecpglib/po/meson.build
+++ b/src/interfaces/ecpg/ecpglib/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('ecpglib' + '6' + '-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('ecpglib' + '6' + '-' + pg_version_major.to_string())]
diff --git a/src/interfaces/ecpg/preproc/po/meson.build b/src/interfaces/ecpg/preproc/po/meson.build
index 1b2ff116547..43f825b88bb 100644
--- a/src/interfaces/ecpg/preproc/po/meson.build
+++ b/src/interfaces/ecpg/preproc/po/meson.build
@@ -1,3 +1,3 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-i18n.gettext('ecpg-' + pg_version_major.to_string())
+nls_targets += [i18n.gettext('ecpg-' + pg_version_major.to_string())]
-- 
2.38.0

