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