xref: /PHP-5.6/ext/standard/config.m4 (revision ccd215a5)
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
350AC_CHECK_FUNCS(getcwd getwd asinh acosh atanh log1p hypot glob strfmon nice fpclass isinf isnan mempcpy strpncpy)
351AC_FUNC_FNMATCH
352
353dnl
354dnl Check if there is a support means of creating a new process
355dnl and defining which handles it receives
356dnl
357AC_CHECK_FUNCS(fork CreateProcess, [
358  php_can_support_proc_open=yes
359  break
360],[
361  php_can_support_proc_open=no
362])
363AC_MSG_CHECKING([if your OS can spawn processes with inherited handles])
364if test "$php_can_support_proc_open" = "yes"; then
365  AC_MSG_RESULT(yes)
366  AC_DEFINE(PHP_CAN_SUPPORT_PROC_OPEN,1, [Define if your system has fork/vfork/CreateProcess])
367else
368  AC_MSG_RESULT(no)
369fi
370
371PHP_ENABLE_CHROOT_FUNC=no
372case "$PHP_SAPI" in
373  embed)
374    PHP_ENABLE_CHROOT_FUNC=yes
375  ;;
376
377  none)
378    for PROG in $PHP_BINARIES; do
379      case "$PROG" in
380        cgi|cli)
381          PHP_ENABLE_CHROOT_FUNC=yes
382        ;;
383
384        *)
385          PHP_ENABLE_CHROOT_FUNC=no
386          break
387        ;;
388      esac
389   done
390  ;;
391esac
392
393if test "$PHP_ENABLE_CHROOT_FUNC" = "yes"; then
394  AC_DEFINE(ENABLE_CHROOT_FUNC, 1, [Whether to enable chroot() function])
395fi
396
397dnl
398dnl Detect library functions needed by php dns_xxx functions
399dnl ext/standard/php_dns.h will collect these in a single define: HAVE_FULL_DNS_FUNCS
400dnl
401PHP_CHECK_FUNC(res_nsearch, resolv, bind, socket)
402PHP_CHECK_FUNC(dns_search, resolv, bind, socket)
403PHP_CHECK_FUNC(dn_expand, resolv, bind, socket)
404PHP_CHECK_FUNC(dn_skipname, resolv, bind, socket)
405
406dnl
407dnl These are old deprecated functions
408dnl
409
410PHP_CHECK_FUNC(res_search, resolv, bind, socket)
411
412dnl
413dnl Check if atof() accepts NAN
414dnl
415AC_CACHE_CHECK(whether atof() accepts NAN, ac_cv_atof_accept_nan,[
416AC_TRY_RUN([
417#include <math.h>
418#include <stdlib.h>
419
420#ifdef HAVE_ISNAN
421#define zend_isnan(a) isnan(a)
422#elif defined(HAVE_FPCLASS)
423#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))
424#else
425#define zend_isnan(a) 0
426#endif
427
428int main(int argc, char** argv)
429{
430	return zend_isnan(atof("NAN")) ? 0 : 1;
431}
432],[
433  ac_cv_atof_accept_nan=yes
434],[
435  ac_cv_atof_accept_nan=no
436],[
437  ac_cv_atof_accept_nan=no
438])])
439if test "$ac_cv_atof_accept_nan" = "yes"; then
440  AC_DEFINE([HAVE_ATOF_ACCEPTS_NAN], 1, [whether atof() accepts NAN])
441fi
442
443dnl
444dnl Check if atof() accepts INF
445dnl
446AC_CACHE_CHECK(whether atof() accepts INF, ac_cv_atof_accept_inf,[
447AC_TRY_RUN([
448#include <math.h>
449#include <stdlib.h>
450
451#ifdef HAVE_ISINF
452#define zend_isinf(a) isinf(a)
453#elif defined(INFINITY)
454/* Might not work, but is required by ISO C99 */
455#define zend_isinf(a) (((a)==INFINITY)?1:0)
456#elif defined(HAVE_FPCLASS)
457#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))
458#else
459#define zend_isinf(a) 0
460#endif
461
462int main(int argc, char** argv)
463{
464	return zend_isinf(atof("INF")) && zend_isinf(atof("-INF")) ? 0 : 1;
465}
466],[
467  ac_cv_atof_accept_inf=yes
468],[
469  ac_cv_atof_accept_inf=no
470],[
471  ac_cv_atof_accept_inf=no
472])])
473if test "$ac_cv_atof_accept_inf" = "yes"; then
474  AC_DEFINE([HAVE_ATOF_ACCEPTS_INF], 1, [whether atof() accepts INF])
475fi
476
477dnl
478dnl Check if HUGE_VAL == INF
479dnl
480AC_CACHE_CHECK(whether HUGE_VAL == INF, ac_cv_huge_val_inf,[
481AC_TRY_RUN([
482#include <math.h>
483#include <stdlib.h>
484
485#ifdef HAVE_ISINF
486#define zend_isinf(a) isinf(a)
487#elif defined(INFINITY)
488/* Might not work, but is required by ISO C99 */
489#define zend_isinf(a) (((a)==INFINITY)?1:0)
490#elif defined(HAVE_FPCLASS)
491#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))
492#else
493#define zend_isinf(a) 0
494#endif
495
496int main(int argc, char** argv)
497{
498	return zend_isinf(HUGE_VAL) ? 0 : 1;
499}
500],[
501  ac_cv_huge_val_inf=yes
502],[
503  ac_cv_huge_val_inf=no
504],[
505  ac_cv_huge_val_inf=yes
506])])
507dnl This is the most probable fallback so we assume yes in case of cross compile.
508if test "$ac_cv_huge_val_inf" = "yes"; then
509  AC_DEFINE([HAVE_HUGE_VAL_INF], 1, [whether HUGE_VAL == INF])
510fi
511
512dnl
513dnl Check if HUGE_VAL + -HUGEVAL == NAN
514dnl
515AC_CACHE_CHECK(whether HUGE_VAL + -HUGEVAL == NAN, ac_cv_huge_val_nan,[
516AC_TRY_RUN([
517#include <math.h>
518#include <stdlib.h>
519
520#ifdef HAVE_ISNAN
521#define zend_isnan(a) isnan(a)
522#elif defined(HAVE_FPCLASS)
523#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))
524#else
525#define zend_isnan(a) 0
526#endif
527
528int main(int argc, char** argv)
529{
530#if defined(__sparc__) && !(__GNUC__ >= 3)
531	/* prevent bug #27830 */
532	return 1;
533#else
534	return zend_isnan(HUGE_VAL + -HUGE_VAL) ? 0 : 1;
535#endif
536}
537],[
538  ac_cv_huge_val_nan=yes
539],[
540  ac_cv_huge_val_nan=no
541],[
542  ac_cv_huge_val_nan=yes
543])])
544dnl This is the most probable fallback so we assume yes in case of cross compile.
545if test "$ac_cv_huge_val_nan" = "yes"; then
546  AC_DEFINE([HAVE_HUGE_VAL_NAN], 1, [whether HUGE_VAL + -HUGEVAL == NAN])
547fi
548
549dnl
550dnl Check for strptime()
551dnl
552AC_CACHE_CHECK(whether strptime() declaration fails, ac_cv_strptime_decl_fails,[
553AC_TRY_COMPILE([
554#include <time.h>
555],[
556#ifndef HAVE_STRPTIME
557#error no strptime() on this platform
558#else
559/* use invalid strptime() declaration to see if it fails to compile */
560int strptime(const char *s, const char *format, struct tm *tm);
561#endif
562],[
563  ac_cv_strptime_decl_fails=no
564],[
565  ac_cv_strptime_decl_fails=yes
566])])
567if test "$ac_cv_strptime_decl_fails" = "yes"; then
568  AC_DEFINE([HAVE_STRPTIME_DECL_FAILS], 1, [whether strptime() declaration fails])
569fi
570
571dnl
572dnl Check for i18n capabilities
573dnl
574AC_CHECK_HEADERS([wchar.h])
575AC_CHECK_FUNCS([mblen])
576AC_CHECK_FUNCS([mbrlen mbsinit],,,[
577#ifdef HAVE_WCHAR_H
578# include <wchar.h>
579#endif
580])
581AC_CACHE_CHECK([for mbstate_t], [ac_cv_type_mbstate_t],[
582AC_TRY_COMPILE([
583#ifdef HAVE_WCHAR_H
584# include <wchar.h>
585#endif
586],[
587mbstate_t a;
588],[
589  ac_cv_type_mbstate_t=yes
590],[
591  ac_cv_type_mbstate_t=no
592])])
593if test "$ac_cv_type_mbstate_t" = "yes"; then
594  AC_DEFINE([HAVE_MBSTATE_T], 1, [Define if your system has mbstate_t in wchar.h])
595fi
596
597dnl
598dnl Check for atomic operation API availability in Solaris
599dnl
600AC_CHECK_HEADERS([atomic.h])
601
602dnl
603dnl Setup extension sources
604dnl
605PHP_NEW_EXTENSION(standard, array.c base64.c basic_functions.c browscap.c crc32.c crypt.c \
606                            cyr_convert.c datetime.c dir.c dl.c dns.c exec.c file.c filestat.c \
607                            flock_compat.c formatted_print.c fsock.c head.c html.c image.c \
608                            info.c iptc.c lcg.c link.c mail.c math.c md5.c metaphone.c \
609                            microtime.c pack.c pageinfo.c quot_print.c rand.c \
610                            soundex.c string.c scanf.c syslog.c type.c uniqid.c url.c \
611                            var.c versioning.c assert.c strnatcmp.c levenshtein.c \
612                            incomplete_class.c url_scanner_ex.c ftp_fopen_wrapper.c \
613                            http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \
614                            var_unserializer.c ftok.c sha1.c user_filters.c uuencode.c \
615                            filters.c proc_open.c streamsfuncs.c http.c password.c)
616
617PHP_ADD_MAKEFILE_FRAGMENT
618PHP_INSTALL_HEADERS([ext/standard/])
619