From 8ec3b76315f8f99292c5c82860c3fa528fe7365b Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Wed, 3 Jul 2024 16:30:30 +0200 Subject: [PATCH] Autotools: Refactor ext/standard cache variables - Cache variables renamed from ac_cv_* to php_cv_* - CS synced a bit - Error message for crypt function separated from crypt algorithms checks - AH_TEMPLATE defines help text on one place --- ext/standard/config.m4 | 182 +++++++++++++++++++---------------------- 1 file changed, 85 insertions(+), 97 deletions(-) diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 index 386b3939bc676..54809a929bfef 100644 --- a/ext/standard/config.m4 +++ b/ext/standard/config.m4 @@ -1,8 +1,9 @@ dnl dnl Check if flush should be called explicitly after buffered io dnl -AC_CACHE_CHECK([whether flush should be called explicitly after a buffered io], ac_cv_flush_io,[ -AC_RUN_IFELSE([AC_LANG_SOURCE([[ +AC_CACHE_CHECK([whether flush should be called explicitly after a buffered io], +[php_cv_have_flush_io], +[AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include #include #ifdef HAVE_UNISTD_H @@ -40,17 +41,17 @@ int main(int argc, char **argv) exit(result); } -]])],[ - ac_cv_flush_io=no -],[ - ac_cv_flush_io=yes -],[ - ac_cv_flush_io=no -])]) -if test "$ac_cv_flush_io" = "yes"; then - AC_DEFINE(HAVE_FLUSHIO, 1, [Define if flush should be called explicitly after a buffered io.]) -fi +]])], +[php_cv_have_flush_io=no], +[php_cv_have_flush_io=yes], +[php_cv_have_flush_io=no])]) +AS_VAR_IF([php_cv_have_flush_io], [yes], + [AC_DEFINE([HAVE_FLUSHIO], [1], + [Define to 1 if flush should be called explicitly after a buffered io.])]) +dnl +dnl Check whether to use PHP's crypt or external crypt library. +dnl PHP_ARG_WITH([external-libcrypt], [for external libcrypt or libxcrypt], [AS_HELP_STRING([--with-external-libcrypt], @@ -58,16 +59,23 @@ PHP_ARG_WITH([external-libcrypt], [no], [no]) -if test "$PHP_EXTERNAL_LIBCRYPT" != "no"; then +AH_TEMPLATE([PHP_USE_PHP_CRYPT_R], + [Define to 1 if PHP uses its own crypt_r, and to 0 if using external crypt.]) + +AS_VAR_IF([PHP_EXTERNAL_LIBCRYPT], [no], [ + AC_DEFINE([PHP_USE_PHP_CRYPT_R], [1]) + PHP_ADD_SOURCES([PHP_EXT_DIR([standard])], + [crypt_freesec.c crypt_blowfish.c crypt_sha512.c crypt_sha256.c php_crypt_r.c]) +], [ PHP_CHECK_FUNC(crypt, crypt) PHP_CHECK_FUNC(crypt_r, crypt) AC_CHECK_HEADERS([crypt.h]) - if test "$ac_cv_func_crypt_r" = "yes"; then - PHP_CRYPT_R_STYLE - fi + AS_VAR_IF([ac_cv_func_crypt_r], [yes], + [PHP_CRYPT_R_STYLE], + [AC_MSG_ERROR([Cannot use external libcrypt as crypt_r() is missing.])]) - AC_CACHE_CHECK(for standard DES crypt, ac_cv_crypt_des,[ - AC_RUN_IFELSE([AC_LANG_SOURCE([[ +AC_CACHE_CHECK([for standard DES crypt], [php_cv_lib_crypt_des], + [AC_RUN_IFELSE([AC_LANG_SOURCE([ #ifdef HAVE_UNISTD_H #include #endif @@ -86,16 +94,13 @@ int main(void) { #else return 1; #endif -}]])],[ - ac_cv_crypt_des=yes -],[ - ac_cv_crypt_des=no -],[ - ac_cv_crypt_des=yes -])]) +}])], + [php_cv_lib_crypt_des=yes], + [php_cv_lib_crypt_des=no], + [php_cv_lib_crypt_des=yes])]) - AC_CACHE_CHECK(for extended DES crypt, ac_cv_crypt_ext_des,[ - AC_RUN_IFELSE([AC_LANG_SOURCE([[ +AC_CACHE_CHECK([for extended DES crypt], [php_cv_lib_crypt_ext_des], + [AC_RUN_IFELSE([AC_LANG_SOURCE([ #ifdef HAVE_UNISTD_H #include #endif @@ -114,16 +119,13 @@ int main(void) { #else return 1; #endif -}]])],[ - ac_cv_crypt_ext_des=yes - ],[ - ac_cv_crypt_ext_des=no - ],[ - ac_cv_crypt_ext_des=no - ])]) - - AC_CACHE_CHECK(for MD5 crypt, ac_cv_crypt_md5,[ - AC_RUN_IFELSE([AC_LANG_SOURCE([[ +}])], + [php_cv_lib_crypt_ext_des=yes], + [php_cv_lib_crypt_ext_des=no], + [php_cv_lib_crypt_ext_des=no])]) + +AC_CACHE_CHECK([for MD5 crypt], [php_cv_lib_crypt_md5], + [AC_RUN_IFELSE([AC_LANG_SOURCE([[ #ifdef HAVE_UNISTD_H #include #endif @@ -152,16 +154,13 @@ int main(void) { #else return 1; #endif -}]])],[ - ac_cv_crypt_md5=yes - ],[ - ac_cv_crypt_md5=no - ],[ - ac_cv_crypt_md5=no - ])]) - - AC_CACHE_CHECK(for Blowfish crypt, ac_cv_crypt_blowfish,[ - AC_RUN_IFELSE([AC_LANG_SOURCE([[ +}]])], + [php_cv_lib_crypt_md5=yes], + [php_cv_lib_crypt_md5=no], + [php_cv_lib_crypt_md5=no])]) + +AC_CACHE_CHECK([for Blowfish crypt], [php_cv_lib_crypt_blowfish], + [AC_RUN_IFELSE([AC_LANG_SOURCE([[ #ifdef HAVE_UNISTD_H #include #endif @@ -178,7 +177,8 @@ int main(void) { char salt[30], answer[70]; char *encrypted; - salt[0]='$'; salt[1]='2'; salt[2]='a'; salt[3]='$'; salt[4]='0'; salt[5]='7'; salt[6]='$'; salt[7]='\0'; + salt[0]='$'; salt[1]='2'; salt[2]='a'; salt[3]='$'; + salt[4]='0'; salt[5]='7'; salt[6]='$'; salt[7]='\0'; strcat(salt,"rasmuslerd............"); strcpy(answer,salt); strcpy(&answer[29],"nIdrcHdxcUxWomQX9j6kvERCFjTg7Ra"); @@ -187,16 +187,13 @@ int main(void) { #else return 1; #endif -}]])],[ - ac_cv_crypt_blowfish=yes - ],[ - ac_cv_crypt_blowfish=no - ],[ - ac_cv_crypt_blowfish=no - ])]) - - AC_CACHE_CHECK(for SHA512 crypt, ac_cv_crypt_sha512,[ - AC_RUN_IFELSE([AC_LANG_SOURCE([[ +}]])], + [php_cv_lib_crypt_blowfish=yes], + [php_cv_lib_crypt_blowfish=no], + [php_cv_lib_crypt_blowfish=no])]) + +AC_CACHE_CHECK([for SHA512 crypt], [php_cv_lib_crypt_sha512], + [AC_RUN_IFELSE([AC_LANG_SOURCE([[ #ifdef HAVE_UNISTD_H #include #endif @@ -221,16 +218,13 @@ int main(void) { #else return 1; #endif - }]])],[ - ac_cv_crypt_sha512=yes - ],[ - ac_cv_crypt_sha512=no - ],[ - ac_cv_crypt_sha512=no - ])]) - - AC_CACHE_CHECK(for SHA256 crypt, ac_cv_crypt_sha256,[ - AC_RUN_IFELSE([AC_LANG_SOURCE([[ + }]])], + [php_cv_lib_crypt_sha512=yes], + [php_cv_lib_crypt_sha512=no], + [php_cv_lib_crypt_sha512=no])]) + +AC_CACHE_CHECK([for SHA256 crypt], [php_cv_lib_crypt_sha256], + [AC_RUN_IFELSE([AC_LANG_SOURCE([[ #ifdef HAVE_UNISTD_H #include #endif @@ -255,25 +249,22 @@ int main(void) { #else return 1; #endif -}]])],[ - ac_cv_crypt_sha256=yes - ],[ - ac_cv_crypt_sha256=no - ],[ - ac_cv_crypt_sha256=no - ])]) - - - if test "$ac_cv_crypt_blowfish" = "no" || test "$ac_cv_crypt_des" = "no" || test "$ac_cv_crypt_ext_des" = "no" || test "$ac_cv_crypt_md5" = "no" || test "$ac_cv_crypt_sha512" = "no" || test "$ac_cv_crypt_sha256" = "no" || test "$ac_cv_func_crypt_r" != "yes"; then - AC_MSG_ERROR([Cannot use external libcrypt as some algo are missing]) +}]])], + [php_cv_lib_crypt_sha256=yes], + [php_cv_lib_crypt_sha256=no], + [php_cv_lib_crypt_sha256=no])]) + + if test "$php_cv_lib_crypt_des" = "no" || \ + test "$php_cv_lib_crypt_ext_des" = "no" || \ + test "$php_cv_lib_crypt_md5" = "no" || \ + test "$php_cv_lib_crypt_blowfish" = "no" || \ + test "$php_cv_lib_crypt_sha512" = "no" || \ + test "$php_cv_lib_crypt_sha256" = "no"; then + AC_MSG_ERROR([Cannot use external libcrypt as some algorithms are missing.]) fi - AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 0, [Whether PHP has to use its own crypt_r]) -else - AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 1, [Whether PHP has to use its own crypt_r]) - - PHP_ADD_SOURCES(PHP_EXT_DIR(standard), crypt_freesec.c crypt_blowfish.c crypt_sha512.c crypt_sha256.c php_crypt_r.c) -fi + AC_DEFINE([PHP_USE_PHP_CRYPT_R], [0]) +]) AS_VAR_IF([cross_compiling], [no], [AC_FUNC_FNMATCH], [AS_CASE([$host_alias], [*linux*], @@ -345,24 +336,21 @@ AC_CHECK_FUNCS([posix_spawn_file_actions_addchdir_np]) dnl dnl Check for strptime() dnl -AC_CACHE_CHECK(whether strptime() declaration fails, ac_cv_strptime_decl_fails,[ -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ -#include -]],[[ +AC_CACHE_CHECK([whether strptime is declared], + [php_cv_have_decl_strptime], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ], [ #ifndef HAVE_STRPTIME #error no strptime() on this platform #else /* use invalid strptime() declaration to see if it fails to compile */ int strptime(const char *s, const char *format, struct tm *tm); #endif -]])],[ - ac_cv_strptime_decl_fails=no -],[ - ac_cv_strptime_decl_fails=yes -])]) -if test "$ac_cv_strptime_decl_fails" = "yes"; then - AC_DEFINE([HAVE_STRPTIME_DECL_FAILS], 1, [whether strptime() declaration fails]) -fi +])], + [php_cv_have_decl_strptime=no], + [php_cv_have_decl_strptime=yes])]) +AS_VAR_IF([php_cv_have_decl_strptime], [yes], + [AC_DEFINE([HAVE_STRPTIME_DECL_FAILS], [1], + [Define to 1 if 'strptime' has declaration.])]) dnl dnl Check for argon2