xref: /PHP-8.4/ext/standard/config.m4 (revision 7e1e450b)
1dnl
2dnl Check if flush should be called explicitly after buffered io
3dnl
4AC_CACHE_CHECK([whether flush should be called explicitly after a buffered io],
5[php_cv_have_flush_io],
6[AC_RUN_IFELSE([AC_LANG_SOURCE([[
7#include <stdio.h>
8#include <stdlib.h>
9#ifdef HAVE_UNISTD_H
10#include <unistd.h>
11#endif
12#include <string.h>
13
14int main(void)
15{
16  char *filename = tmpnam(NULL);
17  char buffer[64];
18  int result = 0;
19
20  FILE *fp = fopen(filename, "wb");
21  if (NULL == fp) {
22    return 0;
23  }
24
25  fputs("line 1\n", fp);
26  fputs("line 2\n", fp);
27  fclose(fp);
28
29  fp = fopen(filename, "rb+");
30  if (NULL == fp) {
31    return 0;
32  }
33
34  if (fgets(buffer, sizeof(buffer), fp) == NULL) {
35    fclose(fp);
36    return 0;
37  }
38
39  fputs("line 3\n", fp);
40  rewind(fp);
41  if (fgets(buffer, sizeof(buffer), fp) == NULL) {
42    fclose(fp);
43    return 0;
44  }
45
46  if (0 != strcmp(buffer, "line 1\n")) {
47    result = 1;
48  }
49
50  if (fgets(buffer, sizeof(buffer), fp) == NULL) {
51    fclose(fp);
52    return 0;
53  }
54
55  if (0 != strcmp(buffer, "line 3\n")) {
56    result = 1;
57  }
58
59  fclose(fp);
60  unlink(filename);
61
62  return result;
63}
64]])],
65[php_cv_have_flush_io=no],
66[php_cv_have_flush_io=yes],
67[php_cv_have_flush_io=no])])
68AS_VAR_IF([php_cv_have_flush_io], [yes],
69  [AC_DEFINE([HAVE_FLUSHIO], [1],
70    [Define to 1 if flush should be called explicitly after a buffered io.])])
71
72PHP_ARG_WITH([external-libcrypt],
73  [for external libcrypt or libxcrypt],
74  [AS_HELP_STRING([--with-external-libcrypt],
75    [Use external libcrypt or libxcrypt])],
76  [no],
77  [no])
78
79AH_TEMPLATE([PHP_USE_PHP_CRYPT_R],
80  [Define to 1 if PHP uses its own crypt_r, and to 0 if using the external crypt
81  library.])
82
83php_ext_standard_sources=
84AS_VAR_IF([PHP_EXTERNAL_LIBCRYPT], [no], [
85  AC_DEFINE([PHP_USE_PHP_CRYPT_R], [1])
86  php_ext_standard_sources=m4_normalize(["
87    crypt_blowfish.c
88    crypt_freesec.c
89    crypt_sha256.c
90    crypt_sha512.c
91    php_crypt_r.c
92  "])
93], [
94AC_SEARCH_LIBS([crypt], [crypt],
95  [AC_DEFINE([HAVE_CRYPT], [1],
96    [Define to 1 if you have the 'crypt' function.])],
97  [AC_MSG_FAILURE([Cannot use external libcrypt as crypt() is missing.])])
98
99AC_SEARCH_LIBS([crypt_r], [crypt],
100  [AC_DEFINE([HAVE_CRYPT_R], [1],
101    [Define to 1 if you have the 'crypt_r' function.])],
102  [AC_MSG_FAILURE([Cannot use external libcrypt as crypt_r() is missing.])])
103
104PHP_CRYPT_R_STYLE
105AC_CHECK_HEADERS([crypt.h])
106
107AC_CACHE_CHECK([for standard DES crypt], [ac_cv_crypt_des],
108  [AC_RUN_IFELSE([AC_LANG_SOURCE([
109#ifdef HAVE_UNISTD_H
110#include <unistd.h>
111#endif
112
113#ifdef HAVE_CRYPT_H
114#include <crypt.h>
115#endif
116
117#include <stdlib.h>
118#include <string.h>
119
120int main(void) {
121  char *encrypted = crypt("rasmuslerdorf","rl");
122  return !encrypted || strcmp(encrypted,"rl.3StKT.4T8M");
123}])],
124  [ac_cv_crypt_des=yes],
125  [ac_cv_crypt_des=no],
126  [ac_cv_crypt_des=yes])])
127
128AC_CACHE_CHECK([for extended DES crypt], [ac_cv_crypt_ext_des],
129  [AC_RUN_IFELSE([AC_LANG_SOURCE([
130#ifdef HAVE_UNISTD_H
131#include <unistd.h>
132#endif
133
134#ifdef HAVE_CRYPT_H
135#include <crypt.h>
136#endif
137
138#include <stdlib.h>
139#include <string.h>
140
141int main(void) {
142  char *encrypted = crypt("rasmuslerdorf","_J9..rasm");
143  return !encrypted || strcmp(encrypted,"_J9..rasmBYk8r9AiWNc");
144}])],
145  [ac_cv_crypt_ext_des=yes],
146  [ac_cv_crypt_ext_des=no],
147  [ac_cv_crypt_ext_des=no])])
148
149AC_CACHE_CHECK([for MD5 crypt], [ac_cv_crypt_md5],
150  [AC_RUN_IFELSE([AC_LANG_SOURCE([[
151#ifdef HAVE_UNISTD_H
152#include <unistd.h>
153#endif
154
155#ifdef HAVE_CRYPT_H
156#include <crypt.h>
157#endif
158
159#include <stdlib.h>
160#include <string.h>
161
162int main(void) {
163  char salt[15], answer[40];
164  char *encrypted;
165
166  salt[0]='$'; salt[1]='1'; salt[2]='$';
167  salt[3]='r'; salt[4]='a'; salt[5]='s';
168  salt[6]='m'; salt[7]='u'; salt[8]='s';
169  salt[9]='l'; salt[10]='e'; salt[11]='$';
170  salt[12]='\0';
171  strcpy(answer,salt);
172  strcat(answer,"rISCgZzpwk3UhDidwXvin0");
173  encrypted = crypt("rasmuslerdorf",salt);
174  return !encrypted || strcmp(encrypted,answer);
175}]])],
176  [ac_cv_crypt_md5=yes],
177  [ac_cv_crypt_md5=no],
178  [ac_cv_crypt_md5=no])])
179
180AC_CACHE_CHECK([for Blowfish crypt], [ac_cv_crypt_blowfish],
181  [AC_RUN_IFELSE([AC_LANG_SOURCE([[
182#ifdef HAVE_UNISTD_H
183#include <unistd.h>
184#endif
185
186#ifdef HAVE_CRYPT_H
187#include <crypt.h>
188#endif
189
190#include <stdlib.h>
191#include <string.h>
192
193int main(void) {
194  char salt[30], answer[70];
195  char *encrypted;
196
197  salt[0]='$'; salt[1]='2'; salt[2]='a'; salt[3]='$';
198  salt[4]='0'; salt[5]='7'; salt[6]='$'; salt[7]='\0';
199  strcat(salt,"rasmuslerd............");
200  strcpy(answer,salt);
201  strcpy(&answer[29],"nIdrcHdxcUxWomQX9j6kvERCFjTg7Ra");
202  encrypted = crypt("rasmuslerdorf",salt);
203  return !encrypted || strcmp(encrypted,answer);
204}]])],
205  [ac_cv_crypt_blowfish=yes],
206  [ac_cv_crypt_blowfish=no],
207  [ac_cv_crypt_blowfish=no])])
208
209AC_CACHE_CHECK([for SHA512 crypt], [ac_cv_crypt_sha512],
210  [AC_RUN_IFELSE([AC_LANG_SOURCE([[
211#ifdef HAVE_UNISTD_H
212#include <unistd.h>
213#endif
214
215#ifdef HAVE_CRYPT_H
216#include <crypt.h>
217#endif
218
219#include <stdlib.h>
220#include <string.h>
221
222int main(void) {
223  char salt[21], answer[21+86];
224  char *encrypted;
225
226  strcpy(salt,"\$6\$rasmuslerdorf\$");
227  strcpy(answer, salt);
228  strcat(answer, "EeHCRjm0bljalWuALHSTs1NB9ipEiLEXLhYeXdOpx22gmlmVejnVXFhd84cEKbYxCo.XuUTrW.RLraeEnsvWs/");
229  encrypted = crypt("rasmuslerdorf",salt);
230  return !encrypted || strcmp(encrypted,answer);
231}]])],
232  [ac_cv_crypt_sha512=yes],
233  [ac_cv_crypt_sha512=no],
234  [ac_cv_crypt_sha512=no])])
235
236AC_CACHE_CHECK([for SHA256 crypt], [ac_cv_crypt_sha256],
237  [AC_RUN_IFELSE([AC_LANG_SOURCE([[
238#ifdef HAVE_UNISTD_H
239#include <unistd.h>
240#endif
241
242#ifdef HAVE_CRYPT_H
243#include <crypt.h>
244#endif
245
246#include <stdlib.h>
247#include <string.h>
248
249int main(void) {
250  char salt[21], answer[21+43];
251  char *encrypted;
252
253  strcpy(salt,"\$5\$rasmuslerdorf\$");
254  strcpy(answer, salt);
255  strcat(answer, "cFAm2puLCujQ9t.0CxiFIIvFi4JyQx5UncCt/xRIX23");
256  encrypted = crypt("rasmuslerdorf",salt);
257  return !encrypted || strcmp(encrypted,answer);
258}]])],
259  [ac_cv_crypt_sha256=yes],
260  [ac_cv_crypt_sha256=no],
261  [ac_cv_crypt_sha256=no])])
262
263  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"; then
264    AC_MSG_FAILURE([Cannot use external libcrypt as some algo are missing.])
265  fi
266
267  AC_DEFINE([PHP_USE_PHP_CRYPT_R], [0])
268])
269
270AS_VAR_IF([cross_compiling], [yes],
271  [AS_CASE([$host_alias], [*linux*],
272    [AC_DEFINE([HAVE_FNMATCH], [1])])],
273  [AC_FUNC_FNMATCH])
274
275dnl
276dnl Check if there is a support means of creating a new process and defining
277dnl which handles it receives
278dnl
279AC_CHECK_FUNCS([fork CreateProcess],
280  [php_can_support_proc_open=yes; break;],
281  [php_can_support_proc_open=no])
282AC_MSG_CHECKING([if your OS can spawn processes with inherited handles])
283AS_VAR_IF([php_can_support_proc_open], [yes],
284  [AC_DEFINE([PHP_CAN_SUPPORT_PROC_OPEN], [1],
285    [Define to 1 if your system has fork/vfork/CreateProcess.])])
286AC_MSG_RESULT([$php_can_support_proc_open])
287
288PHP_ENABLE_CHROOT_FUNC=no
289case "$PHP_SAPI" in
290  embed)
291    PHP_ENABLE_CHROOT_FUNC=yes
292  ;;
293
294  none)
295    for PROG in $PHP_BINARIES; do
296      case "$PROG" in
297        cgi|cli|phpdbg)
298          PHP_ENABLE_CHROOT_FUNC=yes
299        ;;
300
301        *)
302          PHP_ENABLE_CHROOT_FUNC=no
303          break
304        ;;
305      esac
306   done
307  ;;
308esac
309
310AS_VAR_IF([PHP_ENABLE_CHROOT_FUNC], [yes],
311  [AC_DEFINE([ENABLE_CHROOT_FUNC], [1],
312    [Define to 1 to enable the 'chroot' function.])])
313
314dnl
315dnl Detect library functions needed by php dns_xxx functions
316dnl ext/standard/php_dns.h will collect these in a single define
317dnl HAVE_FULL_DNS_FUNCS
318dnl
319PHP_CHECK_FUNC(res_nsearch, resolv, socket)
320PHP_CHECK_FUNC(res_ndestroy, resolv, socket)
321PHP_CHECK_FUNC(dns_search, resolv, socket)
322PHP_CHECK_FUNC(dn_expand, resolv, socket)
323PHP_CHECK_FUNC(dn_skipname, resolv, socket)
324
325dnl
326dnl These are old deprecated functions
327dnl
328
329PHP_CHECK_FUNC(res_search, resolv, socket)
330
331AC_CHECK_FUNCS([posix_spawn_file_actions_addchdir_np elf_aux_info])
332
333dnl
334dnl Obsolete check for strptime() declaration. The strptime, where available,
335dnl needs the _GNU_SOURCE defined or compiler flag -std=gnuXX appended to be
336dnl declared in time.h. PHP's strptime is also deprecated as of PHP 8.1.
337dnl
338AC_CHECK_DECL([strptime],
339  [AC_DEFINE([HAVE_DECL_STRPTIME], [1],
340    [Define to 1 if you have the declaration of 'strptime'.])],,
341  [#include <time.h>])
342
343dnl
344dnl Check for argon2
345dnl
346PHP_ARG_WITH([password-argon2],
347  [for Argon2 support],
348  [AS_HELP_STRING([--with-password-argon2],
349    [Include Argon2 support in password_*])])
350
351AS_VAR_IF([PHP_PASSWORD_ARGON2], [no],, [
352  PKG_CHECK_MODULES([ARGON2], [libargon2])
353  PHP_EVAL_INCLINE([$ARGON2_CFLAGS])
354  PHP_EVAL_LIBLINE([$ARGON2_LIBS])
355
356  AC_DEFINE([HAVE_ARGON2LIB], [1],
357    [Define to 1 if the system has the 'libargon2' library.])
358])
359
360dnl
361dnl Check net/if.h for net_get_interfaces. Darwin and BSD-like systems need
362dnl sys/socket.h to be included with net/if.h.
363dnl
364AC_CHECK_HEADERS([net/if.h],,, [dnl
365  #ifdef HAVE_SYS_SOCKET_H
366  #include <sys/socket.h>
367  #endif
368])
369
370AC_CACHE_CHECK([for usable getifaddrs], [php_cv_func_getifaddrs],
371[AC_LINK_IFELSE([AC_LANG_PROGRAM([
372  #include <sys/types.h>
373  #include <ifaddrs.h>
374], [
375  struct ifaddrs *interfaces;
376  if (!getifaddrs(&interfaces)) {
377    freeifaddrs(interfaces);
378  }
379])],
380[php_cv_func_getifaddrs=yes],
381[php_cv_func_getifaddrs=no])])
382AS_VAR_IF([php_cv_func_getifaddrs], [yes],
383  [AC_DEFINE([HAVE_GETIFADDRS], [1],
384    [Define to 1 if you have the 'getifaddrs' function.])])
385
386dnl
387dnl Setup extension sources
388dnl
389PHP_NEW_EXTENSION([standard], m4_normalize([
390    array.c
391    assert.c
392    base64.c
393    basic_functions.c
394    browscap.c
395    crc32_x86.c
396    crc32.c
397    credits.c
398    crypt.c
399    css.c
400    datetime.c
401    dir.c
402    dl.c
403    dns.c
404    exec.c
405    file.c
406    filestat.c
407    filters.c
408    flock_compat.c
409    formatted_print.c
410    fsock.c
411    ftok.c
412    ftp_fopen_wrapper.c
413    head.c
414    hrtime.c
415    html.c
416    http_fopen_wrapper.c
417    http.c
418    image.c
419    incomplete_class.c
420    info.c
421    iptc.c
422    levenshtein.c
423    libavifinfo/avifinfo.c
424    link.c
425    mail.c
426    math.c
427    md5.c
428    metaphone.c
429    microtime.c
430    net.c
431    pack.c
432    pageinfo.c
433    password.c
434    php_fopen_wrapper.c
435    proc_open.c
436    quot_print.c
437    scanf.c
438    sha1.c
439    soundex.c
440    streamsfuncs.c
441    string.c
442    strnatcmp.c
443    syslog.c
444    type.c
445    uniqid.c
446    url_scanner_ex.c
447    url.c
448    user_filters.c
449    uuencode.c
450    var_unserializer.c
451    var.c
452    versioning.c
453    $php_ext_standard_sources
454  ]),
455  [no],,
456  [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
457
458PHP_ADD_BUILD_DIR([$ext_builddir/libavifinfo])
459
460PHP_ADD_MAKEFILE_FRAGMENT
461PHP_INSTALL_HEADERS([ext/standard/])
462