From 7f49573af55ea8824c919cf12271175cb8983497 Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Sat, 12 Nov 2022 16:20:59 -0600
Subject: [PATCH 4/4] rebase and convert to meson

---
 src/backend/Makefile                          | 12 ------------
 src/backend/libpq/pqcomm.c                    |  4 ++--
 src/backend/utils/misc/guc_funcs.c            |  4 ++--
 src/backend/utils/misc/guc_tables.c           |  4 +++-
 src/backend/utils/misc/postgresql.conf.sample |  1 +
 src/common/meson.build                        |  4 +++-
 6 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/src/backend/Makefile b/src/backend/Makefile
index d7041c9aede..181c217fae4 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -55,18 +55,6 @@ ifeq ($(with_systemd),yes)
 LIBS += -lsystemd
 endif
 
-ifeq ($(with_zstd),yes)
-LIBS += -lzstd
-endif
-
-ifeq ($(with_lz4),yes)
-LIBS += -llz4
-endif
-
-ifeq ($(with_zlib),yes)
-LIBS += -lz
-endif
-
 ##########################################################################
 
 all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(POSTGRES_IMP)
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 9bf4672950c..55fede3dc7d 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -111,7 +111,7 @@ int			Unix_socket_permissions;
 char	   *Unix_socket_group;
 
 /* GUC variable containing the allowed compression algorithms list (separated by comma) */
-char	   *libpq_compress_algorithms;
+char	   *libpq_compress_algorithms = "on";
 
 /* Where the Unix socket files are (list of palloc'd strings) */
 static List *sock_paths = NIL;
@@ -2209,7 +2209,7 @@ retry:
 	return true;
 }
 
-PG_FUNCTION_INFO_V1(pg_compression_algorithm);
+// PG_FUNCTION_INFO_V1(pg_compression_algorithm);
 
 Datum
 pg_compression_algorithm(PG_FUNCTION_ARGS)
diff --git a/src/backend/utils/misc/guc_funcs.c b/src/backend/utils/misc/guc_funcs.c
index 5585f992702..767764bfcbf 100644
--- a/src/backend/utils/misc/guc_funcs.c
+++ b/src/backend/utils/misc/guc_funcs.c
@@ -1052,9 +1052,9 @@ show_all_file_settings(PG_FUNCTION_ARGS)
 
 
 #include "common/zpq_stream.h"
-static bool check_libpq_compression(char **newval, void **extra, GucSource source);
+bool check_libpq_compression(char **newval, void **extra, GucSource source);
 
-static bool
+bool
 check_libpq_compression(char **newval, void **extra, GucSource source)
 {
 	zpq_compressor *compressors;
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index e1e5cab63af..d270d339e0e 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -3691,6 +3691,8 @@ struct config_real ConfigureNamesReal[] =
 };
 
 
+extern bool check_libpq_compression(char **newval, void **extra, GucSource source);
+
 struct config_string ConfigureNamesString[] =
 {
 	{
@@ -4453,7 +4455,7 @@ struct config_string ConfigureNamesString[] =
 			NULL
 		},
 		&libpq_compress_algorithms,
-		"zlib",
+		"on",
 		check_libpq_compression, NULL, NULL
 	},
 
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 868d21c351e..da3d0bfcc16 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -742,6 +742,7 @@
 #dynamic_library_path = '$libdir'
 #gin_fuzzy_search_limit = 0
 
+#libpq_compression = on
 
 #------------------------------------------------------------------------------
 # LOCK MANAGEMENT
diff --git a/src/common/meson.build b/src/common/meson.build
index 1c9b8a3a018..c6b3bae6b54 100644
--- a/src/common/meson.build
+++ b/src/common/meson.build
@@ -30,6 +30,8 @@ common_sources = files(
   'username.c',
   'wait_error.c',
   'wchar.c',
+  'z_stream.c',
+  'zpq_stream.c',
 )
 
 if ssl.found()
@@ -132,7 +134,7 @@ pgcommon_variants = {
   '_shlib': default_lib_args + {
     'pic': true,
     'sources': common_sources_frontend_shlib,
-    'dependencies': [frontend_common_code],
+    'dependencies': [frontend_common_code, lz4],
   },
 }
 
-- 
2.25.1

