From c8794fa84b4a200841ccafe274378f1cd578c8f6 Mon Sep 17 00:00:00 2001
From: Zsolt Parragi <zsolt.parragi@percona.com>
Date: Sat, 14 Mar 2026 15:10:45 +0000
Subject: [PATCH 2/3] Extend header list files to libpq, ecpg, and PL languages

Apply the same shared-list-file approach from src/include/ to
all other src/ directories that install headers: libpq, ecpg,
plpgsql, plperl, and plpython. Each directory now has its own
list file(s) that both make and meson read, eliminating duplicate
header lists in the two build systems.
---
 src/interfaces/ecpg/include/Makefile          |  6 +--
 .../ecpg/include/informix_headers.list        |  4 ++
 src/interfaces/ecpg/include/meson.build       | 39 ++++++++-----------
 .../ecpg/include/public_headers.list          | 17 ++++++++
 src/interfaces/libpq/Makefile                 | 17 ++++----
 src/interfaces/libpq/internal_headers.list    |  4 ++
 src/interfaces/libpq/meson.build              | 28 +++++++------
 src/interfaces/libpq/public_headers.list      |  3 ++
 src/pl/plperl/GNUmakefile                     |  6 ++-
 src/pl/plperl/install_headers.list            |  4 ++
 src/pl/plperl/meson.build                     | 14 ++++---
 src/pl/plpgsql/src/Makefile                   |  7 ++--
 src/pl/plpgsql/src/install_headers.list       |  2 +
 src/pl/plpgsql/src/meson.build                | 12 ++++--
 src/pl/plpython/Makefile                      | 17 +-------
 src/pl/plpython/install_headers.list          | 15 +++++++
 src/pl/plpython/meson.build                   | 25 ++++--------
 17 files changed, 125 insertions(+), 95 deletions(-)
 create mode 100644 src/interfaces/ecpg/include/informix_headers.list
 create mode 100644 src/interfaces/ecpg/include/public_headers.list
 create mode 100644 src/interfaces/libpq/internal_headers.list
 create mode 100644 src/interfaces/libpq/public_headers.list
 create mode 100644 src/pl/plperl/install_headers.list
 create mode 100644 src/pl/plpgsql/src/install_headers.list
 create mode 100644 src/pl/plpython/install_headers.list

diff --git a/src/interfaces/ecpg/include/Makefile b/src/interfaces/ecpg/include/Makefile
index 3476409cefb..e2d7ece3392 100644
--- a/src/interfaces/ecpg/include/Makefile
+++ b/src/interfaces/ecpg/include/Makefile
@@ -13,10 +13,8 @@ all: $(ecpg_config_h)
 install: all installdirs install-headers
 
 .PHONY: install-headers
-ecpg_headers = ecpgerrno.h ecpglib.h ecpgtype.h sqlca.h sql3types.h ecpg_informix.h \
-	pgtypes_error.h pgtypes_numeric.h pgtypes_timestamp.h pgtypes_date.h pgtypes_interval.h pgtypes.h \
-	sqlda.h sqlda-compat.h sqlda-native.h
-informix_headers = datetime.h decimal.h sqltypes.h
+ecpg_headers := $(shell grep -v '^\#' $(srcdir)/public_headers.list | grep -v '^$$')
+informix_headers := $(shell grep -v '^\#' $(srcdir)/informix_headers.list | grep -v '^$$')
 
 install-headers: $(ecpg_headers) $(informix_headers) installdirs
 	$(INSTALL_DATA) $(addprefix $(srcdir)/,$(ecpg_headers)) '$(DESTDIR)$(includedir)/'
diff --git a/src/interfaces/ecpg/include/informix_headers.list b/src/interfaces/ecpg/include/informix_headers.list
new file mode 100644
index 00000000000..47fb1ea552f
--- /dev/null
+++ b/src/interfaces/ecpg/include/informix_headers.list
@@ -0,0 +1,4 @@
+# Informix compatibility headers installed to $(pkgincludedir)/informix/esql
+datetime.h
+decimal.h
+sqltypes.h
diff --git a/src/interfaces/ecpg/include/meson.build b/src/interfaces/ecpg/include/meson.build
index a34a4e30f38..4ddcd1bb739 100644
--- a/src/interfaces/ecpg/include/meson.build
+++ b/src/interfaces/ecpg/include/meson.build
@@ -26,27 +26,20 @@ configure_files += ecpg_config_h
 
 generated_sources_ac += {'src/interfaces/ecpg/include': ['stamp-h']}
 
-install_headers(
-  'ecpg_informix.h',
-  'ecpgerrno.h',
-  'ecpglib.h',
-  'ecpgtype.h',
-  'pgtypes.h',
-  'pgtypes_date.h',
-  'pgtypes_error.h',
-  'pgtypes_interval.h',
-  'pgtypes_numeric.h',
-  'pgtypes_timestamp.h',
-  'sql3types.h',
-  'sqlca.h',
-  'sqlda.h',
-  'sqlda-compat.h',
-  'sqlda-native.h',
-)
+_h = []
+foreach l : fs.read('public_headers.list').strip().split('\n')
+  l = l.strip()
+  if l != '' and not l.startswith('#')
+    _h += l
+  endif
+endforeach
+install_headers(_h)
 
-install_headers(
-  'datetime.h',
-  'decimal.h',
-  'sqltypes.h',
-  install_dir: dir_include_pkg / 'informix' / 'esql',
-)
+_h = []
+foreach l : fs.read('informix_headers.list').strip().split('\n')
+  l = l.strip()
+  if l != '' and not l.startswith('#')
+    _h += l
+  endif
+endforeach
+install_headers(_h, install_dir: dir_include_pkg / 'informix' / 'esql')
diff --git a/src/interfaces/ecpg/include/public_headers.list b/src/interfaces/ecpg/include/public_headers.list
new file mode 100644
index 00000000000..8adc7e6dff5
--- /dev/null
+++ b/src/interfaces/ecpg/include/public_headers.list
@@ -0,0 +1,17 @@
+# Public ecpg headers installed to $(includedir)
+# Generated header ecpg_config.h is not listed here.
+ecpg_informix.h
+ecpgerrno.h
+ecpglib.h
+ecpgtype.h
+pgtypes.h
+pgtypes_date.h
+pgtypes_error.h
+pgtypes_interval.h
+pgtypes_numeric.h
+pgtypes_timestamp.h
+sql3types.h
+sqlca.h
+sqlda-compat.h
+sqlda-native.h
+sqlda.h
diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile
index 0963995eed4..b9319fab869 100644
--- a/src/interfaces/libpq/Makefile
+++ b/src/interfaces/libpq/Makefile
@@ -15,6 +15,9 @@ subdir = src/interfaces/libpq
 top_builddir = ../../..
 include $(top_builddir)/src/Makefile.global
 
+PUBLIC_HEADERS := $(shell grep -v '^\#' $(srcdir)/public_headers.list | grep -v '^$$')
+INTERNAL_HEADERS := $(shell grep -v '^\#' $(srcdir)/internal_headers.list | grep -v '^$$')
+
 export with_ssl with_gssapi with_krb_srvnam
 
 PGFILEDESC = "PostgreSQL Access Library"
@@ -155,11 +158,8 @@ $(top_builddir)/src/port/pg_config_paths.h:
 	$(CC) $(CFLAGS) $(CFLAGS_SL) $(CPPFLAGS) $(CPPFLAGS_SHLIB) -c $< -o $@
 
 install: all installdirs install-lib
-	$(INSTALL_DATA) $(srcdir)/libpq-fe.h '$(DESTDIR)$(includedir)'
-	$(INSTALL_DATA) $(srcdir)/libpq-events.h '$(DESTDIR)$(includedir)'
-	$(INSTALL_DATA) $(srcdir)/libpq-int.h '$(DESTDIR)$(includedir_internal)'
-	$(INSTALL_DATA) $(srcdir)/fe-auth-sasl.h '$(DESTDIR)$(includedir_internal)'
-	$(INSTALL_DATA) $(srcdir)/pqexpbuffer.h '$(DESTDIR)$(includedir_internal)'
+	$(INSTALL_DATA) $(addprefix $(srcdir)/,$(PUBLIC_HEADERS)) '$(DESTDIR)$(includedir)'
+	$(INSTALL_DATA) $(addprefix $(srcdir)/,$(INTERNAL_HEADERS)) '$(DESTDIR)$(includedir_internal)'
 	$(INSTALL_DATA) $(srcdir)/pg_service.conf.sample '$(DESTDIR)$(datadir)/pg_service.conf.sample'
 
 test-build:
@@ -177,11 +177,8 @@ installdirs: installdirs-lib
 	$(MKDIR_P) '$(DESTDIR)$(includedir)' '$(DESTDIR)$(includedir_internal)' '$(DESTDIR)$(datadir)'
 
 uninstall: uninstall-lib
-	rm -f '$(DESTDIR)$(includedir)/libpq-fe.h'
-	rm -f '$(DESTDIR)$(includedir)/libpq-events.h'
-	rm -f '$(DESTDIR)$(includedir_internal)/libpq-int.h'
-	rm -f '$(DESTDIR)$(includedir_internal)/fe-auth-sasl.h'
-	rm -f '$(DESTDIR)$(includedir_internal)/pqexpbuffer.h'
+	rm -f $(addprefix '$(DESTDIR)$(includedir)'/, $(PUBLIC_HEADERS))
+	rm -f $(addprefix '$(DESTDIR)$(includedir_internal)'/, $(INTERNAL_HEADERS))
 	rm -f '$(DESTDIR)$(datadir)/pg_service.conf.sample'
 
 clean distclean: clean-lib
diff --git a/src/interfaces/libpq/internal_headers.list b/src/interfaces/libpq/internal_headers.list
new file mode 100644
index 00000000000..635f735b0ad
--- /dev/null
+++ b/src/interfaces/libpq/internal_headers.list
@@ -0,0 +1,4 @@
+# Internal libpq headers installed to $(includedir_internal)
+fe-auth-sasl.h
+libpq-int.h
+pqexpbuffer.h
diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson.build
index b0ae72167a1..09f7f8c85c0 100644
--- a/src/interfaces/libpq/meson.build
+++ b/src/interfaces/libpq/meson.build
@@ -132,17 +132,23 @@ pkgconfig.generate(
   libraries_private: private_deps,
 )
 
-install_headers(
-  'libpq-fe.h',
-  'libpq-events.h',
-)
-
-install_headers(
-  'libpq-int.h',
-  'pqexpbuffer.h',
-  'fe-auth-sasl.h',
-  install_dir: dir_include_internal,
-)
+_h = []
+foreach l : fs.read('public_headers.list').strip().split('\n')
+  l = l.strip()
+  if l != '' and not l.startswith('#')
+    _h += l
+  endif
+endforeach
+install_headers(_h)
+
+_h = []
+foreach l : fs.read('internal_headers.list').strip().split('\n')
+  l = l.strip()
+  if l != '' and not l.startswith('#')
+    _h += l
+  endif
+endforeach
+install_headers(_h, install_dir: dir_include_internal)
 install_data('pg_service.conf.sample',
   install_dir: dir_data,
 )
diff --git a/src/interfaces/libpq/public_headers.list b/src/interfaces/libpq/public_headers.list
new file mode 100644
index 00000000000..26dbe72b8ea
--- /dev/null
+++ b/src/interfaces/libpq/public_headers.list
@@ -0,0 +1,3 @@
+# Public libpq headers installed to $(includedir)
+libpq-events.h
+libpq-fe.h
diff --git a/src/pl/plperl/GNUmakefile b/src/pl/plperl/GNUmakefile
index d7c8917f822..341c180c730 100644
--- a/src/pl/plperl/GNUmakefile
+++ b/src/pl/plperl/GNUmakefile
@@ -75,6 +75,8 @@ endif
 # where to find xsubpp for building XS.
 XSUBPPDIR = $(shell $(PERL) -e 'use List::Util qw(first); print first { -r "$$_/ExtUtils/xsubpp" } @INC')
 
+INSTALL_HDRS := $(shell grep -v '^\#' $(srcdir)/install_headers.list | grep -v '^$$')
+
 include $(top_srcdir)/src/Makefile.shlib
 
 plperl.o: perlchunks.h plperl_opmask.h
@@ -108,11 +110,11 @@ uninstall: uninstall-lib uninstall-data
 
 install-data: installdirs
 	$(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) '$(DESTDIR)$(datadir)/extension/'
-	$(INSTALL_DATA) $(srcdir)/plperl.h $(srcdir)/plperl_system.h $(srcdir)/ppport.h '$(DESTDIR)$(includedir_server)'
+	$(INSTALL_DATA) $(addprefix $(srcdir)/,$(INSTALL_HDRS)) '$(DESTDIR)$(includedir_server)'
 
 uninstall-data:
 	rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(DATA)))
-	rm -f $(addprefix '$(DESTDIR)$(includedir_server)'/, plperl.h plperl_system.h ppport.h)
+	rm -f $(addprefix '$(DESTDIR)$(includedir_server)'/, $(INSTALL_HDRS))
 
 .PHONY: install-data uninstall-data
 
diff --git a/src/pl/plperl/install_headers.list b/src/pl/plperl/install_headers.list
new file mode 100644
index 00000000000..f443f21887f
--- /dev/null
+++ b/src/pl/plperl/install_headers.list
@@ -0,0 +1,4 @@
+# PL/Perl headers installed to $(includedir_server)
+plperl.h
+plperl_system.h
+ppport.h
diff --git a/src/pl/plperl/meson.build b/src/pl/plperl/meson.build
index ff41812ca46..5aaa18aa93b 100644
--- a/src/pl/plperl/meson.build
+++ b/src/pl/plperl/meson.build
@@ -69,12 +69,14 @@ install_data(
   install_dir: dir_data_extension,
 )
 
-install_headers(
-  'plperl.h',
-  'plperl_system.h',
-  'ppport.h',
-  install_dir: dir_include_server,
-)
+_h = []
+foreach l : fs.read('install_headers.list').strip().split('\n')
+  l = l.strip()
+  if l != '' and not l.startswith('#')
+    _h += l
+  endif
+endforeach
+install_headers(_h, install_dir: dir_include_server)
 
 tests += {
   'name': 'plperl',
diff --git a/src/pl/plpgsql/src/Makefile b/src/pl/plpgsql/src/Makefile
index 63cb96fae3e..e9e91a99070 100644
--- a/src/pl/plpgsql/src/Makefile
+++ b/src/pl/plpgsql/src/Makefile
@@ -42,6 +42,8 @@ TOOLSDIR = $(top_srcdir)/src/tools
 GEN_KEYWORDLIST = $(PERL) -I $(TOOLSDIR) $(TOOLSDIR)/gen_keywordlist.pl
 GEN_KEYWORDLIST_DEPS = $(TOOLSDIR)/gen_keywordlist.pl $(TOOLSDIR)/PerfectHash.pm
 
+INSTALL_HDRS := $(shell grep -v '^\#' $(srcdir)/install_headers.list | grep -v '^$$')
+
 all: all-lib
 
 # Shared library stuff
@@ -59,15 +61,14 @@ uninstall: uninstall-lib uninstall-data uninstall-headers
 install-data: installdirs
 	$(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) '$(DESTDIR)$(datadir)/extension/'
 
-# The plpgsql.h header file is needed by instrumentation plugins
 install-headers: installdirs
-	$(INSTALL_DATA) '$(srcdir)/plpgsql.h' '$(DESTDIR)$(includedir_server)'
+	$(INSTALL_DATA) $(addprefix $(srcdir)/,$(INSTALL_HDRS)) '$(DESTDIR)$(includedir_server)'
 
 uninstall-data:
 	rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(DATA)))
 
 uninstall-headers:
-	rm -f '$(DESTDIR)$(includedir_server)/plpgsql.h'
+	rm -f $(addprefix '$(DESTDIR)$(includedir_server)'/, $(INSTALL_HDRS))
 
 .PHONY: install-data install-headers uninstall-data uninstall-headers
 
diff --git a/src/pl/plpgsql/src/install_headers.list b/src/pl/plpgsql/src/install_headers.list
new file mode 100644
index 00000000000..a39a9485d16
--- /dev/null
+++ b/src/pl/plpgsql/src/install_headers.list
@@ -0,0 +1,2 @@
+# PL/pgSQL headers installed to $(includedir_server)
+plpgsql.h
diff --git a/src/pl/plpgsql/src/meson.build b/src/pl/plpgsql/src/meson.build
index 6ff27006cfc..7f84b15b15f 100644
--- a/src/pl/plpgsql/src/meson.build
+++ b/src/pl/plpgsql/src/meson.build
@@ -63,10 +63,14 @@ install_data(
   install_dir: dir_data_extension,
 )
 
-install_headers(
-  'plpgsql.h',
-  install_dir: dir_include_server
-)
+_h = []
+foreach l : fs.read('install_headers.list').strip().split('\n')
+  l = l.strip()
+  if l != '' and not l.startswith('#')
+    _h += l
+  endif
+endforeach
+install_headers(_h, install_dir: dir_include_server)
 
 
 tests += {
diff --git a/src/pl/plpython/Makefile b/src/pl/plpython/Makefile
index 25f295c3709..2b82b6f89c6 100644
--- a/src/pl/plpython/Makefile
+++ b/src/pl/plpython/Makefile
@@ -37,21 +37,8 @@ OBJS = \
 DATA = $(NAME)u.control $(NAME)u--1.0.sql
 
 # header files to install - it's not clear which of these might be needed
-# so install them all.
-INCS = 	plpython.h \
-	plpython_system.h \
-	plpy_cursorobject.h \
-	plpy_elog.h \
-	plpy_exec.h \
-	plpy_main.h \
-	plpy_planobject.h \
-	plpy_plpymodule.h \
-	plpy_procedure.h \
-	plpy_resultobject.h \
-	plpy_spi.h \
-	plpy_subxactobject.h \
-	plpy_typeio.h \
-	plpy_util.h
+# so install them all.  See install_headers.list for the list.
+INCS := $(shell grep -v '^\#' $(srcdir)/install_headers.list | grep -v '^$$')
 
 # Python on win32 ships with import libraries only for Microsoft Visual C++,
 # which are not compatible with mingw gcc. Therefore we need to build a
diff --git a/src/pl/plpython/install_headers.list b/src/pl/plpython/install_headers.list
new file mode 100644
index 00000000000..e9a39405cb7
--- /dev/null
+++ b/src/pl/plpython/install_headers.list
@@ -0,0 +1,15 @@
+# PL/Python headers installed to $(includedir_server)
+plpy_cursorobject.h
+plpy_elog.h
+plpy_exec.h
+plpy_main.h
+plpy_planobject.h
+plpy_plpymodule.h
+plpy_procedure.h
+plpy_resultobject.h
+plpy_spi.h
+plpy_subxactobject.h
+plpy_typeio.h
+plpy_util.h
+plpython.h
+plpython_system.h
diff --git a/src/pl/plpython/meson.build b/src/pl/plpython/meson.build
index ef8aba56539..2a973e25d15 100644
--- a/src/pl/plpython/meson.build
+++ b/src/pl/plpython/meson.build
@@ -53,23 +53,14 @@ install_data(
   install_dir: dir_data_extension,
 )
 
-install_headers(
-  'plpy_cursorobject.h',
-  'plpy_elog.h',
-  'plpy_exec.h',
-  'plpy_main.h',
-  'plpy_planobject.h',
-  'plpy_plpymodule.h',
-  'plpy_procedure.h',
-  'plpy_resultobject.h',
-  'plpy_spi.h',
-  'plpy_subxactobject.h',
-  'plpy_typeio.h',
-  'plpy_util.h',
-  'plpython.h',
-  'plpython_system.h',
-  install_dir: dir_include_server,
-)
+_h = []
+foreach l : fs.read('install_headers.list').strip().split('\n')
+  l = l.strip()
+  if l != '' and not l.startswith('#')
+    _h += l
+  endif
+endforeach
+install_headers(_h, install_dir: dir_include_server)
 
 plpython_regress = [
   'plpython_schema',
-- 
2.43.0

