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