xref: /PHP-8.0/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
270dnl
271dnl If one of them is missing, use our own implementation, portable code is then possible
272dnl
273dnl TODO This is currently always enabled
274if 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" || true; then
275  AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 1, [Whether PHP has to use its own crypt_r for blowfish, des, ext des and md5])
276
277  PHP_ADD_SOURCES(PHP_EXT_DIR(standard), crypt_freesec.c crypt_blowfish.c crypt_sha512.c crypt_sha256.c php_crypt_r.c)
278else
279  AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 0, [Whether PHP has to use its own crypt_r for blowfish, des and ext des])
280fi
281
282dnl
283dnl Check for __attribute__ ((__aligned__)) support in the compiler
284dnl
285AC_CACHE_CHECK(whether the compiler supports aligned attribute, ac_cv_attribute_aligned,[
286AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
287]],[[
288  unsigned char test[32] __attribute__ ((__aligned__ (__alignof__ (int))));
289]])],[
290  ac_cv_attribute_aligned=yes
291],[
292  ac_cv_attribute_aligned=no
293])])
294if test "$ac_cv_attribute_aligned" = "yes"; then
295  AC_DEFINE([HAVE_ATTRIBUTE_ALIGNED], 1, [whether the compiler supports __attribute__ ((__aligned__))])
296fi
297
298AC_FUNC_FNMATCH
299
300dnl
301dnl Check if there is a support means of creating a new process and defining
302dnl which handles it receives
303dnl
304AC_CHECK_FUNCS(fork CreateProcess, [
305  php_can_support_proc_open=yes
306  break
307],[
308  php_can_support_proc_open=no
309])
310AC_MSG_CHECKING([if your OS can spawn processes with inherited handles])
311if test "$php_can_support_proc_open" = "yes"; then
312  AC_MSG_RESULT(yes)
313  AC_DEFINE(PHP_CAN_SUPPORT_PROC_OPEN,1, [Define if your system has fork/vfork/CreateProcess])
314else
315  AC_MSG_RESULT(no)
316fi
317
318PHP_ENABLE_CHROOT_FUNC=no
319case "$PHP_SAPI" in
320  embed)
321    PHP_ENABLE_CHROOT_FUNC=yes
322  ;;
323
324  none)
325    for PROG in $PHP_BINARIES; do
326      case "$PROG" in
327        cgi|cli|phpdbg)
328          PHP_ENABLE_CHROOT_FUNC=yes
329        ;;
330
331        *)
332          PHP_ENABLE_CHROOT_FUNC=no
333          break
334        ;;
335      esac
336   done
337  ;;
338esac
339
340if test "$PHP_ENABLE_CHROOT_FUNC" = "yes"; then
341  AC_DEFINE(ENABLE_CHROOT_FUNC, 1, [Whether to enable chroot() function])
342fi
343
344dnl
345dnl Detect library functions needed by php dns_xxx functions
346dnl ext/standard/php_dns.h will collect these in a single define
347dnl HAVE_FULL_DNS_FUNCS
348dnl
349PHP_CHECK_FUNC(res_nsearch, resolv, bind, socket)
350PHP_CHECK_FUNC(res_ndestroy, resolv, bind, socket)
351PHP_CHECK_FUNC(dns_search, resolv, bind, socket)
352PHP_CHECK_FUNC(dn_expand, resolv, bind, socket)
353PHP_CHECK_FUNC(dn_skipname, resolv, bind, socket)
354
355dnl
356dnl These are old deprecated functions
357dnl
358
359PHP_CHECK_FUNC(res_search, resolv, bind, socket)
360
361dnl
362dnl Check for strptime()
363dnl
364AC_CACHE_CHECK(whether strptime() declaration fails, ac_cv_strptime_decl_fails,[
365AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
366#include <time.h>
367]],[[
368#ifndef HAVE_STRPTIME
369#error no strptime() on this platform
370#else
371/* use invalid strptime() declaration to see if it fails to compile */
372int strptime(const char *s, const char *format, struct tm *tm);
373#endif
374]])],[
375  ac_cv_strptime_decl_fails=no
376],[
377  ac_cv_strptime_decl_fails=yes
378])])
379if test "$ac_cv_strptime_decl_fails" = "yes"; then
380  AC_DEFINE([HAVE_STRPTIME_DECL_FAILS], 1, [whether strptime() declaration fails])
381fi
382
383dnl
384dnl Check for arc4random on BSD systems
385dnl
386AC_CHECK_DECLS([arc4random_buf])
387
388dnl
389dnl Check for CCRandomGenerateBytes
390dnl header absent in previous macOs releases
391dnl
392AC_CHECK_HEADERS([CommonCrypto/CommonRandom.h])
393
394dnl
395dnl Check for argon2
396dnl
397PHP_ARG_WITH([password-argon2],
398  [for Argon2 support],
399  [AS_HELP_STRING([[--with-password-argon2[=DIR]]],
400    [Include Argon2 support in password_*. DIR is the Argon2 shared library
401    path])])
402
403if test "$PHP_PASSWORD_ARGON2" != "no"; then
404  AC_MSG_CHECKING([for Argon2 library])
405  for i in $PHP_PASSWORD_ARGON2 /usr /usr/local ; do
406    if test -r $i/include/argon2.h; then
407      ARGON2_DIR=$i;
408      AC_MSG_RESULT(found in $i)
409      break
410    fi
411  done
412
413  if test -z "$ARGON2_DIR"; then
414    AC_MSG_RESULT([not found])
415    AC_MSG_ERROR([Please ensure the argon2 header and library are installed])
416  fi
417
418  PHP_ADD_LIBRARY_WITH_PATH(argon2, $ARGON2_DIR/$PHP_LIBDIR)
419  PHP_ADD_INCLUDE($ARGON2_DIR/include)
420
421  AC_CHECK_LIB(argon2, argon2id_hash_raw, [
422    LIBS="$LIBS -largon2"
423    AC_DEFINE(HAVE_ARGON2LIB, 1, [ Define to 1 if you have the <argon2.h> header file ])
424  ], [
425    AC_MSG_ERROR([Problem with libargon2.(a|so). Please verify that Argon2 header and libraries >= 20161029 are installed])
426  ])
427fi
428
429dnl
430dnl net_get_interfaces
431dnl
432AC_CHECK_HEADERS([net/if.h],[], [],
433[
434  #ifdef HAVE_SYS_SOCKET_H
435  #include <sys/socket.h>
436  #endif
437  #include <net/if.h>
438])
439AC_MSG_CHECKING([for usable getifaddrs])
440AC_LINK_IFELSE([AC_LANG_PROGRAM([[
441  #include <sys/types.h>
442  #include <ifaddrs.h>
443]],[[
444  struct ifaddrs *interfaces;
445  if (!getifaddrs(&interfaces)) {
446      freeifaddrs(interfaces);
447  }
448]])], [ac_have_getifaddrs=yes], [ac_have_getifaddrs=no])
449if test "$ac_have_getifaddrs" = "yes" ; then
450  AC_DEFINE(HAVE_GETIFADDRS, 1, [whether getifaddrs is present and usable])
451  AC_MSG_RESULT(yes)
452else
453  AC_MSG_RESULT(no)
454fi
455
456dnl
457dnl Setup extension sources
458dnl
459PHP_NEW_EXTENSION(standard, array.c base64.c basic_functions.c browscap.c crc32.c crypt.c \
460                            datetime.c dir.c dl.c dns.c exec.c file.c filestat.c \
461                            flock_compat.c formatted_print.c fsock.c head.c html.c image.c \
462                            info.c iptc.c lcg.c link.c mail.c math.c md5.c metaphone.c \
463                            microtime.c pack.c pageinfo.c quot_print.c rand.c mt_rand.c \
464                            soundex.c string.c scanf.c syslog.c type.c uniqid.c url.c \
465                            var.c versioning.c assert.c strnatcmp.c levenshtein.c \
466                            incomplete_class.c url_scanner_ex.c ftp_fopen_wrapper.c \
467                            http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \
468                            var_unserializer.c ftok.c sha1.c user_filters.c uuencode.c \
469                            filters.c proc_open.c streamsfuncs.c http.c password.c \
470                            random.c net.c hrtime.c crc32_x86.c,,,
471			    -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
472
473PHP_ADD_MAKEFILE_FRAGMENT
474PHP_INSTALL_HEADERS([ext/standard/])
475