xref: /PHP-7.0/ext/standard/config.m4 (revision 2e830826)
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 "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  dnl
264  dnl Check for __attribute__ ((__aligned__)) support in the compiler
265  dnl
266  AC_CACHE_CHECK(whether the compiler supports aligned attribute, ac_cv_attribute_aligned,[
267  AC_TRY_COMPILE([
268  ],[
269    unsigned char test[32] __attribute__ ((__aligned__ (__alignof__ (int))));
270  ],[
271    ac_cv_attribute_aligned=yes
272  ],[
273    ac_cv_attribute_aligned=no
274  ])])
275  if test "$ac_cv_attribute_aligned" = "yes"; then
276    AC_DEFINE([HAVE_ATTRIBUTE_ALIGNED], 1, [whether the compiler supports __attribute__ ((__aligned__))])
277  fi
278
279
280  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])
281  AC_DEFINE_UNQUOTED(PHP_STD_DES_CRYPT, 1, [Whether the system supports standard DES salt])
282  AC_DEFINE_UNQUOTED(PHP_BLOWFISH_CRYPT, 1, [Whether the system supports BlowFish salt])
283  AC_DEFINE_UNQUOTED(PHP_EXT_DES_CRYPT, 1, [Whether the system supports extended DES salt])
284  AC_DEFINE_UNQUOTED(PHP_MD5_CRYPT, 1, [Whether the system supports MD5 salt])
285  AC_DEFINE_UNQUOTED(PHP_SHA512_CRYPT, 1, [Whether the system supports SHA512 salt])
286  AC_DEFINE_UNQUOTED(PHP_SHA256_CRYPT, 1, [Whether the system supports SHA256 salt])
287
288  PHP_ADD_SOURCES(PHP_EXT_DIR(standard), crypt_freesec.c crypt_blowfish.c crypt_sha512.c crypt_sha256.c php_crypt_r.c)
289else
290  if test "$ac_cv_crypt_des" = "yes"; then
291    ac_result=1
292    ac_crypt_des=1
293  else
294    ac_result=0
295    ac_crypt_des=0
296  fi
297  AC_DEFINE_UNQUOTED(PHP_STD_DES_CRYPT, $ac_result, [Whether the system supports standard DES salt])
298
299  if test "$ac_cv_crypt_blowfish" = "yes"; then
300    ac_result=1
301    ac_crypt_blowfish=1
302  else
303    ac_result=0
304    ac_crypt_blowfish=0
305  fi
306  AC_DEFINE_UNQUOTED(PHP_BLOWFISH_CRYPT, $ac_result, [Whether the system supports BlowFish salt])
307
308  if test "$ac_cv_crypt_ext_des" = "yes"; then
309    ac_result=1
310    ac_crypt_edes=1
311  else
312    ac_result=0
313    ac_crypt_edes=0
314  fi
315  AC_DEFINE_UNQUOTED(PHP_EXT_DES_CRYPT, $ac_result, [Whether the system supports extended DES salt])
316
317  if test "$ac_cv_crypt_md5" = "yes"; then
318    ac_result=1
319    ac_crypt_md5=1
320  else
321    ac_result=0
322    ac_crypt_md5=0
323  fi
324  AC_DEFINE_UNQUOTED(PHP_MD5_CRYPT, $ac_result, [Whether the system supports MD5 salt])
325
326  if test "$ac_cv_crypt_sha512" = "yes"; then
327    ac_result=1
328    ac_crypt_sha512=1
329  else
330    ac_result=0
331    ac_crypt_sha512=0
332  fi
333  AC_DEFINE_UNQUOTED(PHP_SHA512_CRYPT, $ac_result, [Whether the system supports SHA512 salt])
334
335  if test "$ac_cv_crypt_sha256" = "yes"; then
336    ac_result=1
337    ac_crypt_sha256=1
338  else
339    ac_result=0
340    ac_crypt_sha256=0
341  fi
342  AC_DEFINE_UNQUOTED(PHP_SHA256_CRYPT, $ac_result, [Whether the system supports SHA256 salt])
343
344  AC_DEFINE_UNQUOTED(PHP_USE_PHP_CRYPT_R, 0, [Whether PHP has to use its own crypt_r for blowfish, des and ext des])
345fi
346
347dnl
348dnl Check for available functions
349dnl
350dnl log2 could be used to improve the log function, however it requires C99. The check for log2 should be turned on,
351dnl as soon as we support C99.
352AC_CHECK_FUNCS(getcwd getwd asinh acosh atanh log1p hypot glob strfmon nice fpclass mempcpy strpncpy)
353AC_CHECK_DECLS([isnan, isinf], [], [], [[#include <math.h>]])
354AC_FUNC_FNMATCH
355
356dnl
357dnl Check if there is a support means of creating a new process
358dnl and defining which handles it receives
359dnl
360AC_CHECK_FUNCS(fork CreateProcess, [
361  php_can_support_proc_open=yes
362  break
363],[
364  php_can_support_proc_open=no
365])
366AC_MSG_CHECKING([if your OS can spawn processes with inherited handles])
367if test "$php_can_support_proc_open" = "yes"; then
368  AC_MSG_RESULT(yes)
369  AC_DEFINE(PHP_CAN_SUPPORT_PROC_OPEN,1, [Define if your system has fork/vfork/CreateProcess])
370else
371  AC_MSG_RESULT(no)
372fi
373
374PHP_ENABLE_CHROOT_FUNC=no
375case "$PHP_SAPI" in
376  embed)
377    PHP_ENABLE_CHROOT_FUNC=yes
378  ;;
379
380  none)
381    for PROG in $PHP_BINARIES; do
382      case "$PROG" in
383        cgi|cli)
384          PHP_ENABLE_CHROOT_FUNC=yes
385        ;;
386
387        *)
388          PHP_ENABLE_CHROOT_FUNC=no
389          break
390        ;;
391      esac
392   done
393  ;;
394esac
395
396if test "$PHP_ENABLE_CHROOT_FUNC" = "yes"; then
397  AC_DEFINE(ENABLE_CHROOT_FUNC, 1, [Whether to enable chroot() function])
398fi
399
400dnl
401dnl Detect library functions needed by php dns_xxx functions
402dnl ext/standard/php_dns.h will collect these in a single define: HAVE_FULL_DNS_FUNCS
403dnl
404PHP_CHECK_FUNC(res_nsearch, resolv, bind, socket)
405PHP_CHECK_FUNC(res_ndestroy, resolv, bind, socket)
406PHP_CHECK_FUNC(dns_search, resolv, bind, socket)
407PHP_CHECK_FUNC(dn_expand, resolv, bind, socket)
408PHP_CHECK_FUNC(dn_skipname, resolv, bind, socket)
409
410dnl
411dnl These are old deprecated functions
412dnl
413
414PHP_CHECK_FUNC(res_search, resolv, bind, socket)
415
416dnl
417dnl Check if atof() accepts NAN
418dnl
419AC_CACHE_CHECK(whether atof() accepts NAN, ac_cv_atof_accept_nan,[
420AC_TRY_RUN([
421#include <math.h>
422#include <stdlib.h>
423
424#if HAVE_DECL_ISNAN
425#define zend_isnan(a) isnan(a)
426#elif defined(HAVE_FPCLASS)
427#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))
428#else
429#define zend_isnan(a) 0
430#endif
431
432int main(int argc, char** argv)
433{
434	return zend_isnan(atof("NAN")) ? 0 : 1;
435}
436],[
437  ac_cv_atof_accept_nan=yes
438],[
439  ac_cv_atof_accept_nan=no
440],[
441  ac_cv_atof_accept_nan=no
442])])
443if test "$ac_cv_atof_accept_nan" = "yes"; then
444  AC_DEFINE([HAVE_ATOF_ACCEPTS_NAN], 1, [whether atof() accepts NAN])
445fi
446
447dnl
448dnl Check if atof() accepts INF
449dnl
450AC_CACHE_CHECK(whether atof() accepts INF, ac_cv_atof_accept_inf,[
451AC_TRY_RUN([
452#include <math.h>
453#include <stdlib.h>
454
455#if HAVE_DECL_ISINF
456#define zend_isinf(a) isinf(a)
457#elif defined(INFINITY)
458/* Might not work, but is required by ISO C99 */
459#define zend_isinf(a) (((a)==INFINITY || (a)==-INFINITY)?1:0)
460#elif defined(HAVE_FPCLASS)
461#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))
462#else
463#define zend_isinf(a) 0
464#endif
465
466int main(int argc, char** argv)
467{
468	return zend_isinf(atof("INF")) && zend_isinf(atof("-INF")) ? 0 : 1;
469}
470],[
471  ac_cv_atof_accept_inf=yes
472],[
473  ac_cv_atof_accept_inf=no
474],[
475  ac_cv_atof_accept_inf=no
476])])
477if test "$ac_cv_atof_accept_inf" = "yes"; then
478  AC_DEFINE([HAVE_ATOF_ACCEPTS_INF], 1, [whether atof() accepts INF])
479fi
480
481dnl
482dnl Check if HUGE_VAL == INF
483dnl
484AC_CACHE_CHECK(whether HUGE_VAL == INF, ac_cv_huge_val_inf,[
485AC_TRY_RUN([
486#include <math.h>
487#include <stdlib.h>
488
489#if HAVE_DECL_ISINF
490#define zend_isinf(a) isinf(a)
491#elif defined(INFINITY)
492/* Might not work, but is required by ISO C99 */
493#define zend_isinf(a) (((a)==INFINITY || (a)==-INFINITY)?1:0)
494#elif defined(HAVE_FPCLASS)
495#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))
496#else
497#define zend_isinf(a) 0
498#endif
499
500int main(int argc, char** argv)
501{
502	return zend_isinf(HUGE_VAL) ? 0 : 1;
503}
504],[
505  ac_cv_huge_val_inf=yes
506],[
507  ac_cv_huge_val_inf=no
508],[
509  ac_cv_huge_val_inf=yes
510])])
511dnl This is the most probable fallback so we assume yes in case of cross compile.
512if test "$ac_cv_huge_val_inf" = "yes"; then
513  AC_DEFINE([HAVE_HUGE_VAL_INF], 1, [whether HUGE_VAL == INF])
514fi
515
516dnl
517dnl Check if HUGE_VAL + -HUGEVAL == NAN
518dnl
519AC_CACHE_CHECK(whether HUGE_VAL + -HUGEVAL == NAN, ac_cv_huge_val_nan,[
520AC_TRY_RUN([
521#include <math.h>
522#include <stdlib.h>
523
524#if HAVE_DECL_ISNAN
525#define zend_isnan(a) isnan(a)
526#elif defined(HAVE_FPCLASS)
527#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))
528#else
529#define zend_isnan(a) 0
530#endif
531
532int main(int argc, char** argv)
533{
534#if defined(__sparc__) && !(__GNUC__ >= 3)
535	/* prevent bug #27830 */
536	return 1;
537#else
538	return zend_isnan(HUGE_VAL + -HUGE_VAL) ? 0 : 1;
539#endif
540}
541],[
542  ac_cv_huge_val_nan=yes
543],[
544  ac_cv_huge_val_nan=no
545],[
546  ac_cv_huge_val_nan=yes
547])])
548dnl This is the most probable fallback so we assume yes in case of cross compile.
549if test "$ac_cv_huge_val_nan" = "yes"; then
550  AC_DEFINE([HAVE_HUGE_VAL_NAN], 1, [whether HUGE_VAL + -HUGEVAL == NAN])
551fi
552
553dnl
554dnl Check for strptime()
555dnl
556AC_CACHE_CHECK(whether strptime() declaration fails, ac_cv_strptime_decl_fails,[
557AC_TRY_COMPILE([
558#include <time.h>
559],[
560#ifndef HAVE_STRPTIME
561#error no strptime() on this platform
562#else
563/* use invalid strptime() declaration to see if it fails to compile */
564int strptime(const char *s, const char *format, struct tm *tm);
565#endif
566],[
567  ac_cv_strptime_decl_fails=no
568],[
569  ac_cv_strptime_decl_fails=yes
570])])
571if test "$ac_cv_strptime_decl_fails" = "yes"; then
572  AC_DEFINE([HAVE_STRPTIME_DECL_FAILS], 1, [whether strptime() declaration fails])
573fi
574
575dnl
576dnl Check for i18n capabilities
577dnl
578AC_CHECK_HEADERS([wchar.h])
579AC_CHECK_FUNCS([mblen])
580AC_CHECK_FUNCS([mbrlen mbsinit],,,[
581#ifdef HAVE_WCHAR_H
582# include <wchar.h>
583#endif
584])
585AC_CACHE_CHECK([for mbstate_t], [ac_cv_type_mbstate_t],[
586AC_TRY_COMPILE([
587#ifdef HAVE_WCHAR_H
588# include <wchar.h>
589#endif
590],[
591mbstate_t a;
592],[
593  ac_cv_type_mbstate_t=yes
594],[
595  ac_cv_type_mbstate_t=no
596])])
597if test "$ac_cv_type_mbstate_t" = "yes"; then
598  AC_DEFINE([HAVE_MBSTATE_T], 1, [Define if your system has mbstate_t in wchar.h])
599fi
600
601dnl
602dnl Check for atomic operation API availability in Solaris
603dnl
604AC_CHECK_HEADERS([atomic.h])
605
606dnl
607dnl Check for arc4random on BSD systems
608dnl
609AC_CHECK_DECLS([arc4random_buf])
610
611dnl
612dnl Setup extension sources
613dnl
614PHP_NEW_EXTENSION(standard, array.c base64.c basic_functions.c browscap.c crc32.c crypt.c \
615                            cyr_convert.c datetime.c dir.c dl.c dns.c exec.c file.c filestat.c \
616                            flock_compat.c formatted_print.c fsock.c head.c html.c image.c \
617                            info.c iptc.c lcg.c link.c mail.c math.c md5.c metaphone.c \
618                            microtime.c pack.c pageinfo.c quot_print.c rand.c \
619                            soundex.c string.c scanf.c syslog.c type.c uniqid.c url.c \
620                            var.c versioning.c assert.c strnatcmp.c levenshtein.c \
621                            incomplete_class.c url_scanner_ex.c ftp_fopen_wrapper.c \
622                            http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \
623                            var_unserializer.c ftok.c sha1.c user_filters.c uuencode.c \
624                            filters.c proc_open.c streamsfuncs.c http.c password.c \
625                            random.c,,,
626			    -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
627
628PHP_ADD_MAKEFILE_FRAGMENT
629PHP_INSTALL_HEADERS([ext/standard/])
630