xref: /PHP-7.3/ext/standard/config.m4 (revision aa405b7d)
1dnl -*- autoconf -*-
2
3dnl
4dnl Check if flush should be called explicitly after buffered io
5dnl
6AC_CACHE_CHECK([whether flush should be called explicitly after a buffered io], ac_cv_flush_io,[
7AC_RUN_IFELSE([AC_LANG_SOURCE([[
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <unistd.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
54dnl
55dnl Check for crypt() capabilities
56dnl
57if test "$ac_cv_func_crypt" = "no"; then
58  AC_CHECK_LIB(crypt, crypt, [
59    LIBS="-lcrypt $LIBS -lcrypt"
60    AC_DEFINE(HAVE_CRYPT, 1, [ ])
61  ])
62fi
63
64AC_CACHE_CHECK(for standard DES crypt, ac_cv_crypt_des,[
65  AC_RUN_IFELSE([AC_LANG_SOURCE([[
66#include <string.h>
67
68#if HAVE_UNISTD_H
69#include <unistd.h>
70#endif
71
72#if HAVE_CRYPT_H
73#include <crypt.h>
74#endif
75
76int main() {
77#if HAVE_CRYPT
78	char *encrypted = crypt("rasmuslerdorf","rl");
79	return !encrypted || strcmp(encrypted,"rl.3StKT.4T8M");
80#else
81	return 1;
82#endif
83}]])],[
84  ac_cv_crypt_des=yes
85],[
86  ac_cv_crypt_des=no
87],[
88  ac_cv_crypt_des=yes
89])])
90
91AC_CACHE_CHECK(for extended DES crypt, ac_cv_crypt_ext_des,[
92  AC_RUN_IFELSE([AC_LANG_SOURCE([[
93#include <string.h>
94
95#if HAVE_UNISTD_H
96#include <unistd.h>
97#endif
98
99#if HAVE_CRYPT_H
100#include <crypt.h>
101#endif
102
103int main() {
104#if HAVE_CRYPT
105	char *encrypted = crypt("rasmuslerdorf","_J9..rasm");
106	return !encrypted || strcmp(encrypted,"_J9..rasmBYk8r9AiWNc");
107#else
108	return 1;
109#endif
110}]])],[
111  ac_cv_crypt_ext_des=yes
112],[
113  ac_cv_crypt_ext_des=no
114],[
115  ac_cv_crypt_ext_des=no
116])])
117
118AC_CACHE_CHECK(for MD5 crypt, ac_cv_crypt_md5,[
119AC_RUN_IFELSE([AC_LANG_SOURCE([[
120#include <string.h>
121
122#if HAVE_UNISTD_H
123#include <unistd.h>
124#endif
125
126#if HAVE_CRYPT_H
127#include <crypt.h>
128#endif
129
130int main() {
131#if HAVE_CRYPT
132	char salt[15], answer[40];
133	char *encrypted;
134
135	salt[0]='$'; salt[1]='1'; salt[2]='$';
136	salt[3]='r'; salt[4]='a'; salt[5]='s';
137	salt[6]='m'; salt[7]='u'; salt[8]='s';
138	salt[9]='l'; salt[10]='e'; salt[11]='$';
139	salt[12]='\0';
140	strcpy(answer,salt);
141	strcat(answer,"rISCgZzpwk3UhDidwXvin0");
142	encrypted = crypt("rasmuslerdorf",salt);
143	return !encrypted || strcmp(encrypted,answer);
144#else
145	return 1;
146#endif
147}]])],[
148  ac_cv_crypt_md5=yes
149],[
150  ac_cv_crypt_md5=no
151],[
152  ac_cv_crypt_md5=no
153])])
154
155AC_CACHE_CHECK(for Blowfish crypt, ac_cv_crypt_blowfish,[
156AC_RUN_IFELSE([AC_LANG_SOURCE([[
157#include <string.h>
158
159#if HAVE_UNISTD_H
160#include <unistd.h>
161#endif
162
163#if HAVE_CRYPT_H
164#include <crypt.h>
165#endif
166
167int main() {
168#if HAVE_CRYPT
169	char salt[30], answer[70];
170	char *encrypted;
171
172	salt[0]='$'; salt[1]='2'; salt[2]='a'; salt[3]='$'; salt[4]='0'; salt[5]='7'; salt[6]='$'; salt[7]='\0';
173	strcat(salt,"rasmuslerd............");
174	strcpy(answer,salt);
175	strcpy(&answer[29],"nIdrcHdxcUxWomQX9j6kvERCFjTg7Ra");
176	encrypted = crypt("rasmuslerdorf",salt);
177	return !encrypted || strcmp(encrypted,answer);
178#else
179	return 1;
180#endif
181}]])],[
182  ac_cv_crypt_blowfish=yes
183],[
184  ac_cv_crypt_blowfish=no
185],[
186  ac_cv_crypt_blowfish=no
187])])
188
189AC_CACHE_CHECK(for SHA512 crypt, ac_cv_crypt_sha512,[
190AC_RUN_IFELSE([AC_LANG_SOURCE([[
191#include <string.h>
192
193#if HAVE_UNISTD_H
194#include <unistd.h>
195#endif
196
197#if HAVE_CRYPT_H
198#include <crypt.h>
199#endif
200
201int main() {
202#if HAVE_CRYPT
203	char salt[21], answer[21+86];
204	char *encrypted;
205
206	strcpy(salt,"\$6\$rasmuslerdorf\$");
207	strcpy(answer, salt);
208	strcat(answer, "EeHCRjm0bljalWuALHSTs1NB9ipEiLEXLhYeXdOpx22gmlmVejnVXFhd84cEKbYxCo.XuUTrW.RLraeEnsvWs/");
209	encrypted = crypt("rasmuslerdorf",salt);
210	return !encrypted || strcmp(encrypted,answer);
211#else
212	return 1;
213#endif
214}]])],[
215  ac_cv_crypt_sha512=yes
216],[
217  ac_cv_crypt_sha512=no
218],[
219  ac_cv_crypt_sha512=no
220])])
221
222AC_CACHE_CHECK(for SHA256 crypt, ac_cv_crypt_sha256,[
223AC_RUN_IFELSE([AC_LANG_SOURCE([[
224#include <string.h>
225
226#if HAVE_UNISTD_H
227#include <unistd.h>
228#endif
229
230#if HAVE_CRYPT_H
231#include <crypt.h>
232#endif
233
234int main() {
235#if HAVE_CRYPT
236	char salt[21], answer[21+43];
237	char *encrypted;
238
239	strcpy(salt,"\$5\$rasmuslerdorf\$");
240	strcpy(answer, salt);
241	strcat(answer, "cFAm2puLCujQ9t.0CxiFIIvFi4JyQx5UncCt/xRIX23");
242	encrypted = crypt("rasmuslerdorf",salt);
243	return !encrypted || strcmp(encrypted,answer);
244#else
245	return 1;
246#endif
247}]])],[
248  ac_cv_crypt_sha256=yes
249],[
250  ac_cv_crypt_sha256=no
251],[
252  ac_cv_crypt_sha256=no
253])])
254
255
256dnl
257dnl If one of them is missing, use our own implementation, portable code is then possible
258dnl
259if 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 "x$php_crypt_r" = "x0"; then
260
261  dnl
262  dnl Check for __alignof__ support in the compiler
263  dnl
264  AC_CACHE_CHECK(whether the compiler supports __alignof__, ac_cv_alignof_exists,[
265  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
266  ]],[[
267    int align = __alignof__(int);
268  ]])],[
269    ac_cv_alignof_exists=yes
270  ],[
271    ac_cv_alignof_exists=no
272  ])])
273  if test "$ac_cv_alignof_exists" = "yes"; then
274    AC_DEFINE([HAVE_ALIGNOF], 1, [whether the compiler supports __alignof__])
275  fi
276
277  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])
278
279  PHP_ADD_SOURCES(PHP_EXT_DIR(standard), crypt_freesec.c crypt_blowfish.c crypt_sha512.c crypt_sha256.c php_crypt_r.c)
280else
281  AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 0, [Whether PHP has to use its own crypt_r for blowfish, des and ext des])
282fi
283
284dnl
285dnl Check for __attribute__ ((__aligned__)) support in the compiler
286dnl
287AC_CACHE_CHECK(whether the compiler supports aligned attribute, ac_cv_attribute_aligned,[
288AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
289]],[[
290  unsigned char test[32] __attribute__ ((__aligned__ (__alignof__ (int))));
291]])],[
292  ac_cv_attribute_aligned=yes
293],[
294  ac_cv_attribute_aligned=no
295])])
296if test "$ac_cv_attribute_aligned" = "yes"; then
297  AC_DEFINE([HAVE_ATTRIBUTE_ALIGNED], 1, [whether the compiler supports __attribute__ ((__aligned__))])
298fi
299
300dnl
301dnl Check for available functions
302dnl
303dnl log2 could be used to improve the log function, however it requires C99. The check for log2 should be turned on,
304dnl as soon as we support C99.
305AC_CHECK_FUNCS(getcwd getwd asinh acosh atanh log1p hypot glob strfmon nice fpclass mempcpy strpncpy)
306AC_FUNC_FNMATCH
307
308dnl
309dnl Check if there is a support means of creating a new process
310dnl and defining which handles it receives
311dnl
312AC_CHECK_FUNCS(fork CreateProcess, [
313  php_can_support_proc_open=yes
314  break
315],[
316  php_can_support_proc_open=no
317])
318AC_MSG_CHECKING([if your OS can spawn processes with inherited handles])
319if test "$php_can_support_proc_open" = "yes"; then
320  AC_MSG_RESULT(yes)
321  AC_DEFINE(PHP_CAN_SUPPORT_PROC_OPEN,1, [Define if your system has fork/vfork/CreateProcess])
322else
323  AC_MSG_RESULT(no)
324fi
325
326PHP_ENABLE_CHROOT_FUNC=no
327case "$PHP_SAPI" in
328  embed)
329    PHP_ENABLE_CHROOT_FUNC=yes
330  ;;
331
332  none)
333    for PROG in $PHP_BINARIES; do
334      case "$PROG" in
335        cgi|cli|phpdbg)
336          PHP_ENABLE_CHROOT_FUNC=yes
337        ;;
338
339        *)
340          PHP_ENABLE_CHROOT_FUNC=no
341          break
342        ;;
343      esac
344   done
345  ;;
346esac
347
348if test "$PHP_ENABLE_CHROOT_FUNC" = "yes"; then
349  AC_DEFINE(ENABLE_CHROOT_FUNC, 1, [Whether to enable chroot() function])
350fi
351
352dnl
353dnl Detect library functions needed by php dns_xxx functions
354dnl ext/standard/php_dns.h will collect these in a single define: HAVE_FULL_DNS_FUNCS
355dnl
356PHP_CHECK_FUNC(res_nsearch, resolv, bind, socket)
357PHP_CHECK_FUNC(res_ndestroy, resolv, bind, socket)
358PHP_CHECK_FUNC(dns_search, resolv, bind, socket)
359PHP_CHECK_FUNC(dn_expand, resolv, bind, socket)
360PHP_CHECK_FUNC(dn_skipname, resolv, bind, socket)
361
362dnl
363dnl These are old deprecated functions
364dnl
365
366PHP_CHECK_FUNC(res_search, resolv, bind, socket)
367
368dnl
369dnl Check for strptime()
370dnl
371AC_CACHE_CHECK(whether strptime() declaration fails, ac_cv_strptime_decl_fails,[
372AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
373#include <time.h>
374]],[[
375#ifndef HAVE_STRPTIME
376#error no strptime() on this platform
377#else
378/* use invalid strptime() declaration to see if it fails to compile */
379int strptime(const char *s, const char *format, struct tm *tm);
380#endif
381]])],[
382  ac_cv_strptime_decl_fails=no
383],[
384  ac_cv_strptime_decl_fails=yes
385])])
386if test "$ac_cv_strptime_decl_fails" = "yes"; then
387  AC_DEFINE([HAVE_STRPTIME_DECL_FAILS], 1, [whether strptime() declaration fails])
388fi
389
390dnl
391dnl Check for i18n capabilities
392dnl
393AC_CHECK_HEADERS([wchar.h])
394AC_CHECK_FUNCS([mblen mbrlen mbsinit])
395AC_CACHE_CHECK([for mbstate_t], [ac_cv_type_mbstate_t],[
396AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
397#ifdef HAVE_WCHAR_H
398# include <wchar.h>
399#endif
400]],[[
401mbstate_t a;
402]])],[
403  ac_cv_type_mbstate_t=yes
404],[
405  ac_cv_type_mbstate_t=no
406])])
407if test "$ac_cv_type_mbstate_t" = "yes"; then
408  AC_DEFINE([HAVE_MBSTATE_T], 1, [Define if your system has mbstate_t in wchar.h])
409fi
410
411dnl
412dnl Check for atomic operation API availability in Solaris
413dnl
414AC_CHECK_HEADERS([atomic.h])
415
416dnl
417dnl Check for arc4random on BSD systems
418dnl
419AC_CHECK_DECLS([arc4random_buf])
420
421dnl
422dnl Check for argon2
423dnl
424PHP_ARG_WITH(password-argon2, for Argon2 support,
425[  --with-password-argon2[=DIR]
426                          Include Argon2 support in password_*. DIR is the Argon2 shared library path])
427
428if test "$PHP_PASSWORD_ARGON2" != "no"; then
429  AC_MSG_CHECKING([for Argon2 library])
430  for i in $PHP_PASSWORD_ARGON2 /usr /usr/local ; do
431    if test -r $i/include/argon2.h; then
432      ARGON2_DIR=$i;
433      AC_MSG_RESULT(found in $i)
434      break
435    fi
436  done
437
438  if test -z "$ARGON2_DIR"; then
439    AC_MSG_RESULT([not found])
440    AC_MSG_ERROR([Please ensure the argon2 header and library are installed])
441  fi
442
443  PHP_ADD_LIBRARY_WITH_PATH(argon2, $ARGON2_DIR/$PHP_LIBDIR)
444  PHP_ADD_INCLUDE($ARGON2_DIR/include)
445
446  AC_CHECK_LIB(argon2, argon2id_hash_raw, [
447    LIBS="$LIBS -largon2"
448    AC_DEFINE(HAVE_ARGON2LIB, 1, [ Define to 1 if you have the <argon2.h> header file ])
449  ], [
450    AC_MSG_ERROR([Problem with libargon2.(a|so). Please verify that Argon2 header and libaries >= 20161029 are installed])
451  ])
452fi
453
454dnl
455dnl net_get_interfaces
456dnl
457AC_CHECK_HEADERS([net/if.h],[], [],
458[
459  #ifdef HAVE_SYS_SOCKET_H
460  #include <sys/socket.h>
461  #endif
462  #include <net/if.h>
463])
464AC_CHECK_HEADERS([netdb.h])
465AC_MSG_CHECKING([for usable getifaddrs])
466AC_LINK_IFELSE([AC_LANG_PROGRAM([[
467  #include <sys/types.h>
468  #include <ifaddrs.h>
469]],[[
470  struct ifaddrs *interfaces;
471  if (!getifaddrs(&interfaces)) {
472      freeifaddrs(interfaces);
473  }
474]])], [ac_have_getifaddrs=yes], [ac_have_getifaddrs=no])
475if test "$ac_have_getifaddrs" = "yes" ; then
476  AC_DEFINE(HAVE_GETIFADDRS, 1, [whether getifaddrs is present and usable])
477  AC_MSG_RESULT(yes)
478else
479  AC_MSG_RESULT(no)
480fi
481
482dnl
483dnl Setup extension sources
484dnl
485PHP_NEW_EXTENSION(standard, array.c base64.c basic_functions.c browscap.c crc32.c crypt.c \
486                            cyr_convert.c datetime.c dir.c dl.c dns.c exec.c file.c filestat.c \
487                            flock_compat.c formatted_print.c fsock.c head.c html.c image.c \
488                            info.c iptc.c lcg.c link.c mail.c math.c md5.c metaphone.c \
489                            microtime.c pack.c pageinfo.c quot_print.c rand.c mt_rand.c \
490                            soundex.c string.c scanf.c syslog.c type.c uniqid.c url.c \
491                            var.c versioning.c assert.c strnatcmp.c levenshtein.c \
492                            incomplete_class.c url_scanner_ex.c ftp_fopen_wrapper.c \
493                            http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \
494                            var_unserializer.c ftok.c sha1.c user_filters.c uuencode.c \
495                            filters.c proc_open.c streamsfuncs.c http.c password.c \
496                            random.c net.c hrtime.c,,,
497			    -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
498
499PHP_ADD_MAKEFILE_FRAGMENT
500PHP_INSTALL_HEADERS([ext/standard/])
501