Skip to content

Commit

Permalink
Autotools: Refactor ext/standard cache variables
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
petk committed Jul 3, 2024
1 parent ec277ce commit 8ec3b76
Showing 1 changed file with 85 additions and 97 deletions.
182 changes: 85 additions & 97 deletions ext/standard/config.m4
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
Expand Down Expand Up @@ -40,34 +41,41 @@ 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],
[Use external libcrypt or libxcrypt])],
[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 <unistd.h>
#endif
Expand All @@ -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 <unistd.h>
#endif
Expand All @@ -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 <unistd.h>
#endif
Expand Down Expand Up @@ -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 <unistd.h>
#endif
Expand All @@ -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");
Expand All @@ -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 <unistd.h>
#endif
Expand All @@ -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 <unistd.h>
#endif
Expand All @@ -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*],
Expand Down Expand Up @@ -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 <time.h>
]],[[
AC_CACHE_CHECK([whether strptime is declared],
[php_cv_have_decl_strptime],
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <time.h>], [
#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
Expand Down

0 comments on commit 8ec3b76

Please sign in to comment.