From f5772a98feb9c803cec888c905043fe135829f05 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 14 Nov 2024 14:31:35 +0100 Subject: [PATCH 1/5] Extract SETUP_ZLIB_LIB() configuration function This is a mere refactoring for core readability and maintainability reasons. Note that this function is similar to `SETUP_OPENSSL`, but since the zlib headers are not necessarily required, we append `_LIB`. --- ext/curl/config.w32 | 3 +-- ext/gd/config.w32 | 3 +-- ext/mysqlnd/config.w32 | 4 +--- win32/build/confutils.js | 7 +++++++ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ext/curl/config.w32 b/ext/curl/config.w32 index 253c3e3cb6356..db584c29e7ff4 100644 --- a/ext/curl/config.w32 +++ b/ext/curl/config.w32 @@ -8,8 +8,7 @@ if (PHP_CURL != "no") { SETUP_OPENSSL("curl", PHP_CURL) >= 2 && CHECK_LIB("winmm.lib", "curl", PHP_CURL) && CHECK_LIB("wldap32.lib", "curl", PHP_CURL) && - (((PHP_ZLIB=="no") && (CHECK_LIB("zlib_a.lib;zlib.lib", "curl", PHP_CURL))) || - (PHP_ZLIB_SHARED && CHECK_LIB("zlib.lib", "curl", PHP_CURL)) || (PHP_ZLIB == "yes" && (!PHP_ZLIB_SHARED))) && + SETUP_ZLIB_LIB("curl", PHP_CURL) && (CHECK_LIB("normaliz.lib", "curl", PHP_CURL) && CHECK_LIB("libssh2.lib", "curl", PHP_CURL) && CHECK_LIB("nghttp2.lib", "curl", PHP_CURL)) diff --git a/ext/gd/config.w32 b/ext/gd/config.w32 index 939755bf539d1..9877e0be2118b 100644 --- a/ext/gd/config.w32 +++ b/ext/gd/config.w32 @@ -16,8 +16,7 @@ if (PHP_GD != "no") { CHECK_HEADER_ADD_INCLUDE("png.h", "CFLAGS_GD", PHP_GD + ";" + PHP_PHP_BUILD + "\\include\\libpng12")) && (CHECK_LIB("libiconv_a.lib;libiconv.lib", "gd", PHP_GD) || CHECK_LIB("iconv_a.lib;iconv.lib", "gd", PHP_GD)) && CHECK_HEADER_ADD_INCLUDE("iconv.h", "CFLAGS_GD", PHP_GD) && - (((PHP_ZLIB=="no") && (CHECK_LIB("zlib_a.lib;zlib.lib", "gd", PHP_GD) )) || - (PHP_ZLIB_SHARED && CHECK_LIB("zlib.lib", "gd", PHP_GD)) || (PHP_ZLIB == "yes" && (!PHP_ZLIB_SHARED))) + SETUP_ZLIB_LIB("gd", PHP_GD) ) { if (CHECK_LIB("libXpm_a.lib", "gd", PHP_GD) && diff --git a/ext/mysqlnd/config.w32 b/ext/mysqlnd/config.w32 index e9ff75f237ced..af19e84cbfd0d 100644 --- a/ext/mysqlnd/config.w32 +++ b/ext/mysqlnd/config.w32 @@ -28,9 +28,7 @@ if (PHP_MYSQLND != "no") { "mysqlnd_wireprotocol.c " + "php_mysqlnd.c "; EXTENSION("mysqlnd", mysqlnd_source, false, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); - if ((((PHP_ZLIB=="no") && (CHECK_LIB("zlib_a.lib;zlib.lib", "mysqlnd", PHP_MYSQLND))) || - (PHP_ZLIB_SHARED && CHECK_LIB("zlib.lib", "mysqlnd", PHP_MYSQLND)) || - (PHP_ZLIB == "yes" && (!PHP_ZLIB_SHARED))) && + if (SETUP_ZLIB_LIB("mysqlnd", PHP_MYSQLND) && CHECK_HEADER_ADD_INCLUDE("zlib.h", "CFLAGS", "..\\zlib;" + php_usual_include_suspects) ) { diff --git a/win32/build/confutils.js b/win32/build/confutils.js index 3623dcf7e25e1..59429b5e21848 100644 --- a/win32/build/confutils.js +++ b/win32/build/confutils.js @@ -3626,6 +3626,13 @@ function ADD_MAKEFILE_FRAGMENT(src_file) } } +function SETUP_ZLIB_LIB(target, path_to_check) +{ + return ((PHP_ZLIB=="no") && (CHECK_LIB("zlib_a.lib;zlib.lib", target, path_to_check))) || + (PHP_ZLIB_SHARED && CHECK_LIB("zlib.lib", target, path_to_check)) || + (PHP_ZLIB == "yes" && (!PHP_ZLIB_SHARED)); +} + function SETUP_OPENSSL(target, path_to_check, common_name, use_env, add_dir_part, add_to_flag_only) { var ret = 0; From d13b9e944d617d15b873bccfc84e7c3065d46984 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 14 Nov 2024 15:09:38 +0100 Subject: [PATCH 2/5] Be more liberal regarding zlib(_a).lib Extensions requiring zlib are looking only for zlib.lib if ext/zlib has been built as shared extension. This is overly restrictive at best, and actually makes no sense, since (a) we're not shipping shared zlib builds for years, and (b) users could have a zlib.lib which is a static build (they could even just rename zlib_a.lib to zlib.lib). --- win32/build/confutils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win32/build/confutils.js b/win32/build/confutils.js index 59429b5e21848..37eb97d7d9996 100644 --- a/win32/build/confutils.js +++ b/win32/build/confutils.js @@ -3629,7 +3629,7 @@ function ADD_MAKEFILE_FRAGMENT(src_file) function SETUP_ZLIB_LIB(target, path_to_check) { return ((PHP_ZLIB=="no") && (CHECK_LIB("zlib_a.lib;zlib.lib", target, path_to_check))) || - (PHP_ZLIB_SHARED && CHECK_LIB("zlib.lib", target, path_to_check)) || + (PHP_ZLIB_SHARED && CHECK_LIB("zlib_a.lib;zlib.lib", target, path_to_check)) || (PHP_ZLIB == "yes" && (!PHP_ZLIB_SHARED)); } From 89db321b8e3e347c25bdbf2c9f155f8ea85759a6 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 14 Nov 2024 15:10:48 +0100 Subject: [PATCH 3/5] Refactor We now can simplify `SETUP_ZLIB_LIB()`, and clean up formatting. --- ext/mysqlnd/config.w32 | 3 +-- win32/build/confutils.js | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ext/mysqlnd/config.w32 b/ext/mysqlnd/config.w32 index af19e84cbfd0d..cf6bf4b61ccc1 100644 --- a/ext/mysqlnd/config.w32 +++ b/ext/mysqlnd/config.w32 @@ -30,8 +30,7 @@ if (PHP_MYSQLND != "no") { EXTENSION("mysqlnd", mysqlnd_source, false, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); if (SETUP_ZLIB_LIB("mysqlnd", PHP_MYSQLND) && CHECK_HEADER_ADD_INCLUDE("zlib.h", "CFLAGS", "..\\zlib;" + php_usual_include_suspects) - ) - { + ) { AC_DEFINE("MYSQLND_COMPRESSION_ENABLED", 1, "Define to 1 if mysqlnd has compressed protocol support."); AC_DEFINE("MYSQLND_SSL_SUPPORTED", 1, "Define to 1 if mysqlnd core SSL is enabled."); if (CHECK_LIB("crypt32.lib", "mysqlnd")) { diff --git a/win32/build/confutils.js b/win32/build/confutils.js index 37eb97d7d9996..3c78a3274d58d 100644 --- a/win32/build/confutils.js +++ b/win32/build/confutils.js @@ -3628,9 +3628,8 @@ function ADD_MAKEFILE_FRAGMENT(src_file) function SETUP_ZLIB_LIB(target, path_to_check) { - return ((PHP_ZLIB=="no") && (CHECK_LIB("zlib_a.lib;zlib.lib", target, path_to_check))) || - (PHP_ZLIB_SHARED && CHECK_LIB("zlib_a.lib;zlib.lib", target, path_to_check)) || - (PHP_ZLIB == "yes" && (!PHP_ZLIB_SHARED)); + return ((PHP_ZLIB == "no" || PHP_ZLIB_SHARED) && CHECK_LIB("zlib_a.lib;zlib.lib", target, path_to_check)) || + (PHP_ZLIB == "yes" && !PHP_ZLIB_SHARED); } function SETUP_OPENSSL(target, path_to_check, common_name, use_env, add_dir_part, add_to_flag_only) From 48e14cfbbf4bb862109bb6a641e72aaa30556a90 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 14 Nov 2024 15:21:03 +0100 Subject: [PATCH 4/5] Fail early when building ext/gd without ext/zlib The bundled libgd relies on zlib; we're setting up the library, but don't check for the header (which is included by gd_gd2.c), which may pass configure, although the build fails. We better fail early if the required header is not available. --- ext/gd/config.w32 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/gd/config.w32 b/ext/gd/config.w32 index 9877e0be2118b..4e168fc3474f6 100644 --- a/ext/gd/config.w32 +++ b/ext/gd/config.w32 @@ -16,7 +16,8 @@ if (PHP_GD != "no") { CHECK_HEADER_ADD_INCLUDE("png.h", "CFLAGS_GD", PHP_GD + ";" + PHP_PHP_BUILD + "\\include\\libpng12")) && (CHECK_LIB("libiconv_a.lib;libiconv.lib", "gd", PHP_GD) || CHECK_LIB("iconv_a.lib;iconv.lib", "gd", PHP_GD)) && CHECK_HEADER_ADD_INCLUDE("iconv.h", "CFLAGS_GD", PHP_GD) && - SETUP_ZLIB_LIB("gd", PHP_GD) + SETUP_ZLIB_LIB("gd", PHP_GD) && + CHECK_HEADER_ADD_INCLUDE("zlib.h", "CFLAGS", "..\\zlib;" + php_usual_include_suspects) ) { if (CHECK_LIB("libXpm_a.lib", "gd", PHP_GD) && From 27cf6648026fccb250bd240e59ccae3a2a0c9d75 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 18 Nov 2024 23:34:41 +0100 Subject: [PATCH 5/5] Fix condition See https://github.com/php/php-src/pull/16801#discussion_r1843652081. --- win32/build/confutils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/win32/build/confutils.js b/win32/build/confutils.js index 3c78a3274d58d..e847417bc77b0 100644 --- a/win32/build/confutils.js +++ b/win32/build/confutils.js @@ -3628,8 +3628,7 @@ function ADD_MAKEFILE_FRAGMENT(src_file) function SETUP_ZLIB_LIB(target, path_to_check) { - return ((PHP_ZLIB == "no" || PHP_ZLIB_SHARED) && CHECK_LIB("zlib_a.lib;zlib.lib", target, path_to_check)) || - (PHP_ZLIB == "yes" && !PHP_ZLIB_SHARED); + return (PHP_ZLIB != "no" && !PHP_ZLIB_SHARED) || CHECK_LIB("zlib_a.lib;zlib.lib", target, path_to_check); } function SETUP_OPENSSL(target, path_to_check, common_name, use_env, add_dir_part, add_to_flag_only)