xref: /PHP-7.1/acinclude.m4 (revision 65d81833)
1dnl
2dnl $Id$
3dnl
4dnl This file contains local autoconf functions.
5dnl
6
7dnl -------------------------------------------------------------------------
8dnl Output stylize macros for configure (help/runtime)
9dnl -------------------------------------------------------------------------
10
11dnl
12dnl PHP_HELP_SEPARATOR(title)
13dnl
14dnl Adds separator title into the configure --help display.
15dnl
16AC_DEFUN([PHP_HELP_SEPARATOR],[
17AC_ARG_ENABLE([],[
18$1
19],[])
20])
21
22dnl
23dnl PHP_CONFIGURE_PART(title)
24dnl
25dnl Adds separator title configure output (idea borrowed from mm)
26dnl
27AC_DEFUN([PHP_CONFIGURE_PART],[
28  AC_MSG_RESULT()
29  AC_MSG_RESULT([${T_MD}$1${T_ME}])
30])
31
32dnl -------------------------------------------------------------------------
33dnl Build system helper macros
34dnl -------------------------------------------------------------------------
35
36dnl
37dnl PHP_DEF_HAVE(what)
38dnl
39dnl Generates 'AC_DEFINE(HAVE_WHAT, 1, [ ])'
40dnl
41AC_DEFUN([PHP_DEF_HAVE],[AC_DEFINE([HAVE_]translit($1,a-z_.-,A-Z___), 1, [ ])])
42
43dnl
44dnl PHP_RUN_ONCE(namespace, variable, code)
45dnl
46dnl execute code, if variable is not set in namespace
47dnl
48AC_DEFUN([PHP_RUN_ONCE],[
49  changequote({,})
50  unique=`echo $2|$SED 's/[^a-zA-Z0-9]/_/g'`
51  changequote([,])
52  cmd="echo $ac_n \"\$$1$unique$ac_c\""
53  if test -n "$unique" && test "`eval $cmd`" = "" ; then
54    eval "$1$unique=set"
55    $3
56  fi
57])
58
59dnl
60dnl PHP_EXPAND_PATH(path, variable)
61dnl
62dnl expands path to an absolute path and assigns it to variable
63dnl
64AC_DEFUN([PHP_EXPAND_PATH],[
65  if test -z "$1" || echo "$1" | grep '^/' >/dev/null ; then
66    $2=$1
67  else
68    changequote({,})
69    ep_dir=`echo $1|$SED 's%/*[^/][^/]*/*$%%'`
70    changequote([,])
71    ep_realdir=`(cd "$ep_dir" && pwd)`
72    $2="$ep_realdir"/`basename "$1"`
73  fi
74])
75
76dnl
77dnl PHP_DEFINE(WHAT [, value[, directory]])
78dnl
79dnl Creates builddir/include/what.h and in there #define WHAT value
80dnl
81AC_DEFUN([PHP_DEFINE],[
82  [echo "#define ]$1[]ifelse([$2],,[ 1],[ $2])[" > ]ifelse([$3],,[include],[$3])[/php_]translit($1,A-Z,a-z)[.h]
83])
84
85dnl
86dnl PHP_SUBST(varname)
87dnl
88dnl Adds variable with it's value into Makefile, e.g.:
89dnl CC = gcc
90dnl
91AC_DEFUN([PHP_SUBST],[
92  PHP_VAR_SUBST="$PHP_VAR_SUBST $1"
93])
94
95dnl
96dnl PHP_SUBST_OLD(varname)
97dnl
98dnl Same as PHP_SUBST() but also substitutes all @VARNAME@
99dnl instances in every file passed to AC_OUTPUT()
100dnl
101AC_DEFUN([PHP_SUBST_OLD],[
102  PHP_SUBST($1)
103  AC_SUBST($1)
104])
105
106dnl
107dnl PHP_OUTPUT(file)
108dnl
109dnl Adds "file" to the list of files generated by AC_OUTPUT
110dnl This macro can be used several times.
111dnl
112AC_DEFUN([PHP_OUTPUT],[
113  PHP_OUTPUT_FILES="$PHP_OUTPUT_FILES $1"
114])
115
116
117dnl -------------------------------------------------------------------------
118dnl Build system base macros
119dnl -------------------------------------------------------------------------
120
121dnl
122dnl PHP_CANONICAL_HOST_TARGET
123dnl
124AC_DEFUN([PHP_CANONICAL_HOST_TARGET],[
125  AC_REQUIRE([AC_CANONICAL_HOST])dnl
126  AC_REQUIRE([AC_CANONICAL_TARGET])dnl
127  dnl Make sure we do not continue if host_alias is empty.
128  if test -z "$host_alias" && test -n "$host"; then
129    host_alias=$host
130  fi
131  if test -z "$host_alias"; then
132    AC_MSG_ERROR([host_alias is not set!])
133  fi
134])
135
136dnl
137dnl PHP_INIT_BUILD_SYSTEM
138dnl
139AC_DEFUN([PHP_INIT_BUILD_SYSTEM],[
140AC_REQUIRE([PHP_CANONICAL_HOST_TARGET])dnl
141test -d include || $php_shtool mkdir include
142> Makefile.objects
143> Makefile.fragments
144dnl We need to play tricks here to avoid matching the grep line itself
145pattern=define
146$EGREP $pattern'.*include/php' $srcdir/configure|$SED 's/.*>//'|xargs touch 2>/dev/null
147])
148
149dnl
150dnl PHP_GEN_GLOBAL_MAKEFILE
151dnl
152dnl Generates the global makefile.
153dnl
154AC_DEFUN([PHP_GEN_GLOBAL_MAKEFILE],[
155  cat >Makefile <<EOF
156srcdir = $abs_srcdir
157builddir = $abs_builddir
158top_srcdir = $abs_srcdir
159top_builddir = $abs_builddir
160EOF
161  for i in $PHP_VAR_SUBST; do
162    eval echo "$i = \$$i" >> Makefile
163  done
164
165  cat $abs_srcdir/Makefile.global Makefile.fragments Makefile.objects >> Makefile
166])
167
168dnl
169dnl PHP_ADD_MAKEFILE_FRAGMENT([srcfile [, ext_srcdir [, ext_builddir]]])
170dnl
171dnl Processes a file called Makefile.frag in the source directory
172dnl of the most recently added extension. $(srcdir) and $(builddir)
173dnl are substituted with the proper paths. Can be used to supply
174dnl custom rules and/or additional targets.
175dnl
176AC_DEFUN([PHP_ADD_MAKEFILE_FRAGMENT],[
177  ifelse($1,,src=$ext_srcdir/Makefile.frag,src=$1)
178  ifelse($2,,ac_srcdir=$ext_srcdir,ac_srcdir=$2)
179  ifelse($3,,ac_builddir=$ext_builddir,ac_builddir=$3)
180  test -f "$src" && $SED -e "s#\$(srcdir)#$ac_srcdir#g" -e "s#\$(builddir)#$ac_builddir#g" $src  >> Makefile.fragments
181])
182
183dnl
184dnl PHP_ADD_SOURCES(source-path, sources [, special-flags [, type]])
185dnl
186dnl Adds sources which are located relative to source-path to the
187dnl array of type type.  Sources are processed with optional
188dnl special-flags which are passed to the compiler.  Sources
189dnl can be either written in C or C++ (filenames shall end in .c
190dnl or .cpp, respectively).
191dnl
192dnl Note: If source-path begins with a "/", the "/" is removed and
193dnl the path is interpreted relative to the top build-directory.
194dnl
195dnl which array to append to?
196AC_DEFUN([PHP_ADD_SOURCES],[
197  PHP_ADD_SOURCES_X($1, $2, $3, ifelse($4,sapi,PHP_SAPI_OBJS,PHP_GLOBAL_OBJS))
198])
199
200dnl
201dnl _PHP_ASSIGN_BUILD_VARS(type)
202dnl internal, don't use
203AC_DEFUN([_PHP_ASSIGN_BUILD_VARS],[
204ifelse($1,shared,[
205  b_c_pre=$shared_c_pre
206  b_cxx_pre=$shared_cxx_pre
207  b_c_meta=$shared_c_meta
208  b_cxx_meta=$shared_cxx_meta
209  b_c_post=$shared_c_post
210  b_cxx_post=$shared_cxx_post
211],[
212  b_c_pre=$php_c_pre
213  b_cxx_pre=$php_cxx_pre
214  b_c_meta=$php_c_meta
215  b_cxx_meta=$php_cxx_meta
216  b_c_post=$php_c_post
217  b_cxx_post=$php_cxx_post
218])dnl
219  b_lo=[$]$1_lo
220])
221
222dnl
223dnl PHP_ADD_SOURCES_X(source-path, sources[, special-flags[, target-var[, shared[, special-post-flags]]]])
224dnl
225dnl Additional to PHP_ADD_SOURCES (see above), this lets you set the
226dnl name of the array target-var directly, as well as whether
227dnl shared objects will be built from the sources.
228dnl
229dnl Should not be used directly.
230dnl
231AC_DEFUN([PHP_ADD_SOURCES_X],[
232dnl relative to source- or build-directory?
233dnl ac_srcdir/ac_bdir include trailing slash
234  case $1 in
235  ""[)] ac_srcdir="$abs_srcdir/"; unset ac_bdir; ac_inc="-I. -I$abs_srcdir" ;;
236  /*[)] ac_srcdir=`echo "$1"|cut -c 2-`"/"; ac_bdir=$ac_srcdir; ac_inc="-I$ac_bdir -I$abs_srcdir/$ac_bdir" ;;
237  *[)] ac_srcdir="$abs_srcdir/$1/"; ac_bdir="$1/"; ac_inc="-I$ac_bdir -I$ac_srcdir" ;;
238  esac
239
240dnl how to build .. shared or static?
241  ifelse($5,yes,_PHP_ASSIGN_BUILD_VARS(shared),_PHP_ASSIGN_BUILD_VARS(php))
242
243dnl iterate over the sources
244  old_IFS=[$]IFS
245  for ac_src in $2; do
246
247dnl remove the suffix
248      IFS=.
249      set $ac_src
250      ac_obj=[$]1
251      IFS=$old_IFS
252
253dnl append to the array which has been dynamically chosen at m4 time
254      $4="[$]$4 [$]ac_bdir[$]ac_obj.lo"
255
256dnl choose the right compiler/flags/etc. for the source-file
257      case $ac_src in
258        *.c[)] ac_comp="$b_c_pre $3 $ac_inc $b_c_meta -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;
259        *.s[)] ac_comp="$b_c_pre $3 $ac_inc $b_c_meta -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;
260        *.S[)] ac_comp="$b_c_pre $3 $ac_inc $b_c_meta -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;
261        *.cpp|*.cc|*.cxx[)] ac_comp="$b_cxx_pre $3 $ac_inc $b_cxx_meta -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_cxx_post" ;;
262      esac
263
264dnl create a rule for the object/source combo
265    cat >>Makefile.objects<<EOF
266$ac_bdir[$]ac_obj.lo: $ac_srcdir[$]ac_src
267	$ac_comp
268EOF
269  done
270])
271
272dnl -------------------------------------------------------------------------
273dnl Compiler characteristics checks
274dnl -------------------------------------------------------------------------
275
276dnl
277dnl PHP_TARGET_RDYNAMIC
278dnl
279dnl Checks whether -rdynamic is supported by the compiler.  This
280dnl is necessary for some targets to populate the global symbol
281dnl table.  Otherwise, dynamic modules would not be able to resolve
282dnl PHP-related symbols.
283dnl
284dnl If successful, adds -rdynamic to PHP_LDFLAGS.
285dnl
286AC_DEFUN([PHP_TARGET_RDYNAMIC],[
287  if test -n "$GCC"; then
288    dnl we should use a PHP-specific macro here
289    PHP_CHECK_GCC_ARG(-rdynamic, gcc_rdynamic=yes)
290    if test "$gcc_rdynamic" = "yes"; then
291      PHP_LDFLAGS="$PHP_LDFLAGS -rdynamic"
292    fi
293  fi
294])
295
296dnl
297dnl PHP_RUNPATH_SWITCH
298dnl
299dnl Checks for -R, etc. switch
300dnl
301AC_DEFUN([PHP_RUNPATH_SWITCH],[
302AC_MSG_CHECKING([if compiler supports -R])
303AC_CACHE_VAL(php_cv_cc_dashr,[
304  SAVE_LIBS=$LIBS
305  LIBS="-R /usr/$PHP_LIBDIR $LIBS"
306  AC_TRY_LINK([], [], php_cv_cc_dashr=yes, php_cv_cc_dashr=no)
307  LIBS=$SAVE_LIBS])
308AC_MSG_RESULT([$php_cv_cc_dashr])
309if test $php_cv_cc_dashr = "yes"; then
310  ld_runpath_switch=-R
311else
312  AC_MSG_CHECKING([if compiler supports -Wl,-rpath,])
313  AC_CACHE_VAL(php_cv_cc_rpath,[
314    SAVE_LIBS=$LIBS
315    LIBS="-Wl,-rpath,/usr/$PHP_LIBDIR $LIBS"
316    AC_TRY_LINK([], [], php_cv_cc_rpath=yes, php_cv_cc_rpath=no)
317    LIBS=$SAVE_LIBS])
318  AC_MSG_RESULT([$php_cv_cc_rpath])
319  if test $php_cv_cc_rpath = "yes"; then
320    ld_runpath_switch=-Wl,-rpath,
321  else
322    dnl something innocuous
323    ld_runpath_switch=-L
324  fi
325fi
326if test "$PHP_RPATH" = "no"; then
327  ld_runpath_switch=
328fi
329])
330
331dnl
332dnl PHP_CHECK_GCC_ARG(arg, action-if-found, action-if-not-found)
333dnl
334AC_DEFUN([PHP_CHECK_GCC_ARG],[
335  gcc_arg_name=[ac_cv_gcc_arg]translit($1,A-Z-,a-z_)
336  AC_CACHE_CHECK([whether $CC supports $1], [ac_cv_gcc_arg]translit($1,A-Z-,a-z_), [
337  echo 'void somefunc() { };' > conftest.c
338  cmd='$CC $1 -c conftest.c'
339  if eval $cmd 2>&1 | $EGREP -e $1 >/dev/null ; then
340    ac_result=no
341  else
342    ac_result=yes
343  fi
344  eval $gcc_arg_name=$ac_result
345  rm -f conftest.*
346  ])
347  if eval test "\$$gcc_arg_name" = "yes"; then
348    $2
349  else
350    :
351    $3
352  fi
353])
354
355dnl
356dnl PHP_LIBGCC_LIBPATH(gcc)
357dnl
358dnl Stores the location of libgcc in libgcc_libpath
359dnl
360AC_DEFUN([PHP_LIBGCC_LIBPATH],[
361  changequote({,})
362  libgcc_libpath=`$1 --print-libgcc-file-name|$SED 's%/*[^/][^/]*$%%'`
363  changequote([,])
364])
365
366dnl -------------------------------------------------------------------------
367dnl Macros to modify LIBS, INCLUDES, etc. variables
368dnl -------------------------------------------------------------------------
369
370dnl
371dnl PHP_REMOVE_USR_LIB(NAME)
372dnl
373dnl Removes all -L/usr/$PHP_LIBDIR entries from variable NAME
374dnl
375AC_DEFUN([PHP_REMOVE_USR_LIB],[
376  unset ac_new_flags
377  for i in [$]$1; do
378    case [$]i in
379    -L/usr/$PHP_LIBDIR|-L/usr/$PHP_LIBDIR/[)] ;;
380    *[)] ac_new_flags="[$]ac_new_flags [$]i" ;;
381    esac
382  done
383  $1=[$]ac_new_flags
384])
385
386dnl
387dnl PHP_EVAL_LIBLINE(libline, SHARED-LIBADD)
388dnl
389dnl Use this macro, if you need to add libraries and or library search
390dnl paths to the PHP build system which are only given in compiler
391dnl notation.
392dnl
393AC_DEFUN([PHP_EVAL_LIBLINE],[
394  for ac_i in $1; do
395    case $ac_i in
396    -pthread[)]
397      if test "$ext_shared" = "yes"; then
398        $2="[$]$2 -pthread"
399      else
400        PHP_RUN_ONCE(EXTRA_LDFLAGS, [$ac_i], [EXTRA_LDFLAGS="$EXTRA_LDFLAGS $ac_i"])
401      fi
402    ;;
403    -l*[)]
404      ac_ii=`echo $ac_i|cut -c 3-`
405      PHP_ADD_LIBRARY($ac_ii,1,$2)
406    ;;
407    -L*[)]
408      ac_ii=`echo $ac_i|cut -c 3-`
409      PHP_ADD_LIBPATH($ac_ii,$2)
410    ;;
411    esac
412  done
413])
414
415dnl
416dnl PHP_EVAL_INCLINE(headerline)
417dnl
418dnl Use this macro, if you need to add header search paths to the PHP
419dnl build system which are only given in compiler notation.
420dnl
421AC_DEFUN([PHP_EVAL_INCLINE],[
422  for ac_i in $1; do
423    case $ac_i in
424    -I*[)]
425      ac_ii=`echo $ac_i|cut -c 3-`
426      PHP_ADD_INCLUDE($ac_ii)
427    ;;
428    esac
429  done
430])
431
432dnl internal, don't use
433AC_DEFUN([_PHP_ADD_LIBPATH_GLOBAL],[
434  PHP_RUN_ONCE(LIBPATH, $1, [
435    test -n "$ld_runpath_switch" && LDFLAGS="$LDFLAGS $ld_runpath_switch$1"
436    LDFLAGS="$LDFLAGS -L$1"
437    PHP_RPATHS="$PHP_RPATHS $1"
438  ])
439])dnl
440dnl
441dnl
442dnl PHP_ADD_LIBPATH(path [, SHARED-LIBADD])
443dnl
444dnl Adds a path to linkpath/runpath (LDFLAGS)
445dnl
446AC_DEFUN([PHP_ADD_LIBPATH],[
447  if test "$1" != "/usr/$PHP_LIBDIR" && test "$1" != "/usr/lib"; then
448    PHP_EXPAND_PATH($1, ai_p)
449    ifelse([$2],,[
450      _PHP_ADD_LIBPATH_GLOBAL([$ai_p])
451    ],[
452      if test "$ext_shared" = "yes"; then
453        $2="-L$ai_p [$]$2"
454        test -n "$ld_runpath_switch" && $2="$ld_runpath_switch$ai_p [$]$2"
455      else
456        _PHP_ADD_LIBPATH_GLOBAL([$ai_p])
457      fi
458    ])
459  fi
460])
461
462dnl
463dnl PHP_UTILIZE_RPATHS()
464dnl
465dnl builds RPATHS/LDFLAGS from PHP_RPATHS
466dnl
467AC_DEFUN([PHP_UTILIZE_RPATHS],[
468  OLD_RPATHS=$PHP_RPATHS
469  unset PHP_RPATHS
470
471  for i in $OLD_RPATHS; do
472dnl Can be passed to native cc/libtool
473    PHP_LDFLAGS="$PHP_LDFLAGS -L$i"
474dnl Libtool-specific
475    PHP_RPATHS="$PHP_RPATHS -R $i"
476dnl cc-specific
477    NATIVE_RPATHS="$NATIVE_RPATHS $ld_runpath_switch$i"
478  done
479
480  if test "$PHP_RPATH" = "no"; then
481    unset PHP_RPATHS
482    unset NATIVE_RPATHS
483  fi
484])
485
486dnl
487dnl PHP_ADD_INCLUDE(path [,before])
488dnl
489dnl add an include path.
490dnl if before is 1, add in the beginning of INCLUDES.
491dnl
492AC_DEFUN([PHP_ADD_INCLUDE],[
493  if test "$1" != "/usr/include"; then
494    PHP_EXPAND_PATH($1, ai_p)
495    PHP_RUN_ONCE(INCLUDEPATH, $ai_p, [
496      if test "$2"; then
497        INCLUDES="-I$ai_p $INCLUDES"
498      else
499        INCLUDES="$INCLUDES -I$ai_p"
500      fi
501    ])
502  fi
503])
504
505dnl internal, don't use
506AC_DEFUN([_PHP_X_ADD_LIBRARY],[dnl
507  ifelse([$2],,$3="-l$1 [$]$3", $3="[$]$3 -l$1") dnl
508])dnl
509dnl
510dnl internal, don't use
511AC_DEFUN([_PHP_ADD_LIBRARY_SKELETON],[
512  case $1 in
513  c|c_r|pthread*[)] ;;
514  *[)] ifelse($3,,[
515    _PHP_X_ADD_LIBRARY($1,$2,$5)
516  ],[
517    if test "$ext_shared" = "yes"; then
518      _PHP_X_ADD_LIBRARY($1,$2,$3)
519    else
520      $4($1,$2)
521    fi
522  ]) ;;
523  esac
524])dnl
525dnl
526dnl
527dnl PHP_ADD_LIBRARY(library[, append[, shared-libadd]])
528dnl
529dnl add a library to the link line
530dnl
531AC_DEFUN([PHP_ADD_LIBRARY],[
532  _PHP_ADD_LIBRARY_SKELETON([$1],[$2],[$3],[PHP_ADD_LIBRARY],[LIBS])
533])
534
535dnl
536dnl PHP_ADD_LIBRARY_DEFER(library[, append[, shared-libadd]])
537dnl
538dnl add a library to the link line (deferred, not used during configure)
539dnl
540AC_DEFUN([PHP_ADD_LIBRARY_DEFER],[
541  _PHP_ADD_LIBRARY_SKELETON([$1],[$2],[$3],[PHP_ADD_LIBRARY_DEFER],[DLIBS])
542])
543
544dnl
545dnl PHP_ADD_LIBRARY_WITH_PATH(library, path[, shared-libadd])
546dnl
547dnl add a library to the link line and path to linkpath/runpath.
548dnl if shared-libadd is not empty and $ext_shared is yes,
549dnl shared-libadd will be assigned the library information
550dnl
551AC_DEFUN([PHP_ADD_LIBRARY_WITH_PATH],[
552ifelse($3,,[
553  if test -n "$2"; then
554    PHP_ADD_LIBPATH($2)
555  fi
556  PHP_ADD_LIBRARY($1)
557],[
558  if test "$ext_shared" = "yes"; then
559    $3="-l$1 [$]$3"
560    if test -n "$2"; then
561      PHP_ADD_LIBPATH($2,$3)
562    fi
563  else
564    PHP_ADD_LIBRARY_WITH_PATH($1,$2)
565  fi
566])
567])
568
569dnl
570dnl PHP_ADD_LIBRARY_DEFER_WITH_PATH(library, path[, shared-libadd])
571dnl
572dnl add a library to the link line (deferred)
573dnl and path to linkpath/runpath (not deferred)
574dnl if shared-libadd is not empty and $ext_shared is yes,
575dnl shared-libadd will be assigned the library information
576dnl
577AC_DEFUN([PHP_ADD_LIBRARY_DEFER_WITH_PATH],[
578ifelse($3,,[
579  if test -n "$2"; then
580    PHP_ADD_LIBPATH($2)
581  fi
582  PHP_ADD_LIBRARY_DEFER($1)
583],[
584  if test "$ext_shared" = "yes"; then
585    $3="-l$1 [$]$3"
586    if test -n "$2"; then
587      PHP_ADD_LIBPATH($2,$3)
588    fi
589  else
590    PHP_ADD_LIBRARY_DEFER_WITH_PATH($1,$2)
591  fi
592])
593])
594
595dnl
596dnl PHP_ADD_FRAMEWORK(framework [,before])
597dnl
598dnl add a (Darwin / Mac OS X) framework to the link
599dnl line. if before is 1, the framework is added
600dnl to the beginning of the line.
601dnl
602AC_DEFUN([PHP_ADD_FRAMEWORK], [
603  PHP_RUN_ONCE(FRAMEWORKS, $1, [
604    if test "$2"; then
605      PHP_FRAMEWORKS="-framework $1 $PHP_FRAMEWORKS"
606    else
607      PHP_FRAMEWORKS="$PHP_FRAMEWORKS -framework $1"
608    fi
609  ])
610])
611
612dnl
613dnl PHP_ADD_FRAMEWORKPATH(path [,before])
614dnl
615dnl add a (Darwin / Mac OS X) framework path to the link
616dnl and include lines. default paths include (but are
617dnl not limited to) /Local/Library/Frameworks and
618dnl /System/Library/Frameworks, so these don't need
619dnl to be specifically added. if before is 1, the
620dnl framework path is added to the beginning of the
621dnl relevant lines.
622dnl
623AC_DEFUN([PHP_ADD_FRAMEWORKPATH], [
624  PHP_EXPAND_PATH($1, ai_p)
625  PHP_RUN_ONCE(FRAMEWORKPATH, $ai_p, [
626    if test "$2"; then
627      PHP_FRAMEWORKPATH="-F$ai_p $PHP_FRAMEWORKPATH"
628    else
629      PHP_FRAMEWORKPATH="$PHP_FRAMEWORKPATH -F$ai_p"
630    fi
631  ])
632])
633
634dnl
635dnl PHP_ADD_FRAMEWORK_WITH_PATH(framework, path)
636dnl
637dnl Adds a (Darwin / Mac OS X) framework path and the
638dnl framework itself to the link and include lines.
639dnl
640AC_DEFUN([PHP_ADD_FRAMEWORK_WITH_PATH], [
641  PHP_ADD_FRAMEWORKPATH($2)
642  PHP_ADD_FRAMEWORK($1)
643])
644
645dnl
646dnl PHP_SET_LIBTOOL_VARIABLE(var)
647dnl
648dnl Set libtool variable
649dnl
650AC_DEFUN([PHP_SET_LIBTOOL_VARIABLE],[
651  if test -z "$LIBTOOL"; then
652    LIBTOOL='$(SHELL) $(top_builddir)/libtool $1'
653  else
654    LIBTOOL="$LIBTOOL $1"
655  fi
656])
657
658dnl -------------------------------------------------------------------------
659dnl Wrapper macros for AC_ARG_WITH / AC_ARG_ENABLE
660dnl -------------------------------------------------------------------------
661
662dnl PHP_ARG_ANALYZE_EX
663dnl internal
664AC_DEFUN([PHP_ARG_ANALYZE_EX],[
665ext_output="yes, shared"
666ext_shared=yes
667case [$]$1 in
668shared,*[)]
669  $1=`echo "[$]$1"|$SED 's/^shared,//'`
670  ;;
671shared[)]
672  $1=yes
673  ;;
674no[)]
675  ext_output=no
676  ext_shared=no
677  ;;
678*[)]
679  ext_output=yes
680  ext_shared=no
681  ;;
682esac
683
684PHP_ALWAYS_SHARED([$1])
685])
686
687dnl PHP_ARG_ANALYZE
688dnl internal
689AC_DEFUN([PHP_ARG_ANALYZE],[
690ifelse([$3],yes,[PHP_ARG_ANALYZE_EX([$1])],[ext_output=ifelse([$]$1,,no,[$]$1)])
691ifelse([$2],,,[AC_MSG_RESULT([$ext_output])])
692])
693
694dnl
695dnl PHP_ARG_WITH(arg-name, check message, help text[, default-val[, extension-or-not]])
696dnl Sets PHP_ARG_NAME either to the user value or to the default value.
697dnl default-val defaults to no.  This will also set the variable ext_shared,
698dnl and will overwrite any previous variable of that name.
699dnl If extension-or-not is yes (default), then do the ENABLE_ALL check and run
700dnl the PHP_ARG_ANALYZE_EX.
701dnl
702AC_DEFUN([PHP_ARG_WITH],[
703php_with_[]translit($1,A-Z0-9-,a-z0-9_)=ifelse($4,,no,$4)
704PHP_REAL_ARG_WITH([$1],[$2],[$3],[$4],PHP_[]translit($1,a-z0-9-,A-Z0-9_),[ifelse($5,,yes,$5)])
705])
706
707dnl PHP_REAL_ARG_WITH
708dnl internal
709AC_DEFUN([PHP_REAL_ARG_WITH],[
710ifelse([$2],,,[AC_MSG_CHECKING([$2])])
711AC_ARG_WITH($1,[$3],$5=[$]withval,
712[
713  $5=ifelse($4,,no,$4)
714  ifelse($6,yes,[test "$PHP_ENABLE_ALL" && $5=$PHP_ENABLE_ALL])
715])
716PHP_ARG_ANALYZE($5,[$2],$6)
717])
718
719dnl
720dnl PHP_ARG_ENABLE(arg-name, check message, help text[, default-val[, extension-or-not]])
721dnl Sets PHP_ARG_NAME either to the user value or to the default value.
722dnl default-val defaults to no.  This will also set the variable ext_shared,
723dnl and will overwrite any previous variable of that name.
724dnl If extension-or-not is yes (default), then do the ENABLE_ALL check and run
725dnl the PHP_ARG_ANALYZE_EX.
726dnl
727AC_DEFUN([PHP_ARG_ENABLE],[
728php_enable_[]translit($1,A-Z0-9-,a-z0-9_)=ifelse($4,,no,$4)
729PHP_REAL_ARG_ENABLE([$1],[$2],[$3],[$4],PHP_[]translit($1,a-z0-9-,A-Z0-9_),[ifelse($5,,yes,$5)])
730])
731
732dnl PHP_REAL_ARG_ENABLE
733dnl internal
734AC_DEFUN([PHP_REAL_ARG_ENABLE],[
735ifelse([$2],,,[AC_MSG_CHECKING([$2])])
736AC_ARG_ENABLE($1,[$3],$5=[$]enableval,
737[
738  $5=ifelse($4,,no,$4)
739  ifelse($6,yes,[test "$PHP_ENABLE_ALL" && $5=$PHP_ENABLE_ALL])
740])
741PHP_ARG_ANALYZE($5,[$2],$6)
742])
743
744dnl -------------------------------------------------------------------------
745dnl Build macros
746dnl -------------------------------------------------------------------------
747
748dnl
749dnl PHP_BUILD_THREAD_SAFE
750dnl
751AC_DEFUN([PHP_BUILD_THREAD_SAFE],[
752  enable_maintainer_zts=yes
753  if test "$pthreads_working" != "yes"; then
754    AC_MSG_ERROR([ZTS currently requires working POSIX threads. We were unable to verify that your system supports Pthreads.])
755  fi
756])
757
758dnl
759dnl PHP_REQUIRE_CXX
760dnl
761AC_DEFUN([PHP_REQUIRE_CXX],[
762  if test -z "$php_cxx_done"; then
763    AC_PROG_CXX
764    AC_PROG_CXXCPP
765    PHP_ADD_LIBRARY(stdc++)
766    php_cxx_done=yes
767  fi
768])
769
770dnl
771dnl PHP_BUILD_SHARED
772dnl
773AC_DEFUN([PHP_BUILD_SHARED],[
774  PHP_BUILD_PROGRAM
775  OVERALL_TARGET=libphp[]$PHP_MAJOR_VERSION[.la]
776  php_sapi_module=shared
777
778  php_c_pre=$shared_c_pre
779  php_c_meta=$shared_c_meta
780  php_c_post=$shared_c_post
781  php_cxx_pre=$shared_cxx_pre
782  php_cxx_meta=$shared_cxx_meta
783  php_cxx_post=$shared_cxx_post
784  php_lo=$shared_lo
785])
786
787dnl
788dnl PHP_BUILD_STATIC
789dnl
790AC_DEFUN([PHP_BUILD_STATIC],[
791  PHP_BUILD_PROGRAM
792  OVERALL_TARGET=libphp[]$PHP_MAJOR_VERSION[.la]
793  php_sapi_module=static
794])
795
796dnl
797dnl PHP_BUILD_BUNDLE
798dnl
799AC_DEFUN([PHP_BUILD_BUNDLE],[
800  PHP_BUILD_PROGRAM
801  OVERALL_TARGET=libs/libphp[]$PHP_MAJOR_VERSION[.bundle]
802  php_sapi_module=static
803])
804
805dnl
806dnl PHP_BUILD_PROGRAM
807dnl
808AC_DEFUN([PHP_BUILD_PROGRAM],[
809  php_c_pre='$(LIBTOOL) --mode=compile $(CC)'
810  php_c_meta='$(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS)'
811  php_c_post=
812  php_cxx_pre='$(LIBTOOL) --mode=compile $(CXX)'
813  php_cxx_meta='$(COMMON_FLAGS) $(CXXFLAGS_CLEAN) $(EXTRA_CXXFLAGS)'
814  php_cxx_post=
815  php_lo=lo
816
817  case $with_pic in
818    yes) pic_setting='-prefer-pic';;
819    no)  pic_setting='-prefer-non-pic';;
820  esac
821
822  shared_c_pre='$(LIBTOOL) --mode=compile $(CC)'
823  shared_c_meta='$(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) '$pic_setting
824  shared_c_post=
825  shared_cxx_pre='$(LIBTOOL) --mode=compile $(CXX)'
826  shared_cxx_meta='$(COMMON_FLAGS) $(CXXFLAGS_CLEAN) $(EXTRA_CXXFLAGS) '$pic_setting
827  shared_cxx_post=
828  shared_lo=lo
829])
830
831dnl
832dnl PHP_SHARED_MODULE(module-name, object-var, build-dir, cxx, zend_ext)
833dnl
834dnl Basically sets up the link-stage for building module-name
835dnl from object_var in build-dir.
836dnl
837AC_DEFUN([PHP_SHARED_MODULE],[
838  install_modules="install-modules"
839
840  case $host_alias in
841    *aix*[)]
842      suffix=so
843      link_cmd='$(LIBTOOL) --mode=link ifelse($4,,[$(CC)],[$(CXX)]) $(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) -Wl,-G -o '$3'/$1.la -export-dynamic -avoid-version -prefer-pic -module -rpath $(phplibdir) $(EXTRA_LDFLAGS) $($2) $(translit($1,a-z_-,A-Z__)_SHARED_LIBADD) && mv -f '$3'/.libs/$1.so '$3'/$1.so'
844      ;;
845    *netware*[)]
846      suffix=nlm
847      link_cmd='$(LIBTOOL) --mode=link ifelse($4,,[$(CC)],[$(CXX)]) $(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) -o [$]@ -shared -export-dynamic -avoid-version -prefer-pic -module -rpath $(phplibdir) $(EXTRA_LDFLAGS) $($2) ifelse($1, php7lib, , -L$(top_builddir)/netware -lphp7lib) $(translit(ifelse($1, php7lib, $1, m4_substr($1, 3)),a-z_-,A-Z__)_SHARED_LIBADD)'
848      ;;
849    *[)]
850      suffix=la
851      link_cmd='$(LIBTOOL) --mode=link ifelse($4,,[$(CC)],[$(CXX)]) $(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) -o [$]@ -export-dynamic -avoid-version -prefer-pic -module -rpath $(phplibdir) $(EXTRA_LDFLAGS) $($2) $(translit($1,a-z_-,A-Z__)_SHARED_LIBADD)'
852      ;;
853  esac
854
855  if test "x$5" = "xyes"; then
856    PHP_ZEND_EX="$PHP_ZEND_EX \$(phplibdir)/$1.$suffix"
857  else
858    PHP_MODULES="$PHP_MODULES \$(phplibdir)/$1.$suffix"
859  fi
860  PHP_SUBST($2)
861  cat >>Makefile.objects<<EOF
862\$(phplibdir)/$1.$suffix: $3/$1.$suffix
863	\$(LIBTOOL) --mode=install cp $3/$1.$suffix \$(phplibdir)
864
865$3/$1.$suffix: \$($2) \$(translit($1,a-z_-,A-Z__)_SHARED_DEPENDENCIES)
866	$link_cmd
867
868EOF
869])
870
871dnl
872dnl PHP_SELECT_SAPI(name, type[, sources [, extra-cflags [, build-target]]])
873dnl
874dnl Selects the SAPI name and type (static, shared, bundle, program)
875dnl and optionally also the source-files for the SAPI-specific
876dnl objects.
877dnl
878AC_DEFUN([PHP_SELECT_SAPI],[
879  if test "$2" = "program"; then
880    PHP_BINARIES="$PHP_BINARIES $1"
881  elif test "$PHP_SAPI" != "none"; then
882    AC_MSG_ERROR([
883+--------------------------------------------------------------------+
884|                        *** ATTENTION ***                           |
885|                                                                    |
886| You've configured multiple SAPIs to be build. You can build only   |
887| one SAPI module plus CGI, CLI and FPM binaries at the same time.   |
888+--------------------------------------------------------------------+
889])
890  else
891    PHP_SAPI=$1
892  fi
893
894  PHP_ADD_BUILD_DIR([sapi/$1])
895
896  PHP_INSTALLED_SAPIS="$PHP_INSTALLED_SAPIS $1"
897
898  ifelse($2,program,[
899    PHP_BUILD_PROGRAM
900    install_binaries="install-binaries"
901    install_binary_targets="$install_binary_targets install-$1"
902    PHP_SUBST(PHP_[]translit($1,a-z0-9-,A-Z0-9_)[]_OBJS)
903    ifelse($3,,,[PHP_ADD_SOURCES_X([sapi/$1],[$3],[$4],PHP_[]translit($1,a-z0-9-,A-Z0-9_)[]_OBJS)])
904  ],[
905    case "$2" in
906    static[)] PHP_BUILD_STATIC;;
907    shared[)] PHP_BUILD_SHARED;;
908    bundle[)] PHP_BUILD_BUNDLE;;
909    esac
910    install_sapi="install-sapi"
911    ifelse($3,,,[PHP_ADD_SOURCES([sapi/$1],[$3],[$4],[sapi])])
912  ])
913])
914
915dnl deprecated
916AC_DEFUN([PHP_EXTENSION],[
917  sources=`$AWK -f $abs_srcdir/build/scan_makefile_in.awk < []PHP_EXT_SRCDIR($1)[]/Makefile.in`
918
919  PHP_NEW_EXTENSION($1, $sources, $2, $3)
920
921  if test -r "$ext_srcdir/Makefile.frag"; then
922    PHP_ADD_MAKEFILE_FRAGMENT
923  fi
924])
925
926AC_DEFUN([PHP_ADD_BUILD_DIR],[
927  ifelse($2,,[
928    BUILD_DIR="$BUILD_DIR $1"
929  ], [
930    $php_shtool mkdir -p $1
931  ])
932])
933
934AC_DEFUN([PHP_GEN_BUILD_DIRS],[
935  $php_shtool mkdir -p $BUILD_DIR
936])
937
938dnl
939dnl PHP_NEW_EXTENSION(extname, sources [, shared [, sapi_class [, extra-cflags [, cxx [, zend_ext]]]]])
940dnl
941dnl Includes an extension in the build.
942dnl
943dnl "extname" is the name of the extension.
944dnl "sources" is a list of files relative to the subdir which are used
945dnl to build the extension.
946dnl "shared" can be set to "shared" or "yes" to build the extension as
947dnl a dynamically loadable library. Optional parameter "sapi_class" can
948dnl be set to "cli" to mark extension build only with CLI or CGI sapi's.
949dnl "extra-cflags" are passed to the compiler, with
950dnl @ext_srcdir@ and @ext_builddir@ being substituted.
951dnl "cxx" can be used to indicate that a C++ shared module is desired.
952dnl "zend_ext" indicates a zend extension.
953AC_DEFUN([PHP_NEW_EXTENSION],[
954  ext_builddir=[]PHP_EXT_BUILDDIR($1)
955  ext_srcdir=[]PHP_EXT_SRCDIR($1)
956  ext_dir=[]PHP_EXT_DIR($1)
957
958  ifelse($5,,ac_extra=,[ac_extra=`echo "$5"|$SED s#@ext_srcdir@#$ext_srcdir#g|$SED s#@ext_builddir@#$ext_builddir#g`])
959
960  if test "$3" != "shared" && test "$3" != "yes" && test "$4" != "cli"; then
961dnl ---------------------------------------------- Static module
962    [PHP_]translit($1,a-z_-,A-Z__)[_SHARED]=no
963    PHP_ADD_SOURCES($ext_dir,$2,$ac_extra,)
964    EXT_STATIC="$EXT_STATIC $1;$ext_dir"
965    if test "$3" != "nocli"; then
966      EXT_CLI_STATIC="$EXT_CLI_STATIC $1;$ext_dir"
967    fi
968  else
969    if test "$3" = "shared" || test "$3" = "yes"; then
970dnl ---------------------------------------------- Shared module
971      [PHP_]translit($1,a-z_-,A-Z__)[_SHARED]=yes
972      PHP_ADD_SOURCES_X($ext_dir,$2,$ac_extra,shared_objects_$1,yes)
973      case $host_alias in
974        *netware*[)]
975          PHP_SHARED_MODULE(php$1,shared_objects_$1, $ext_builddir, $6, $7)
976          ;;
977        *[)]
978          PHP_SHARED_MODULE($1,shared_objects_$1, $ext_builddir, $6, $7)
979          ;;
980      esac
981      AC_DEFINE_UNQUOTED([COMPILE_DL_]translit($1,a-z_-,A-Z__), 1, Whether to build $1 as dynamic module)
982    fi
983  fi
984
985  if test "$3" != "shared" && test "$3" != "yes" && test "$4" = "cli"; then
986dnl ---------------------------------------------- CLI static module
987    [PHP_]translit($1,a-z_-,A-Z__)[_SHARED]=no
988    case "$PHP_SAPI" in
989      cgi|embed[)]
990        PHP_ADD_SOURCES($ext_dir,$2,$ac_extra,)
991        EXT_STATIC="$EXT_STATIC $1;$ext_dir"
992        ;;
993      *[)]
994        PHP_ADD_SOURCES($ext_dir,$2,$ac_extra,cli)
995        ;;
996    esac
997    EXT_CLI_STATIC="$EXT_CLI_STATIC $1;$ext_dir"
998  fi
999  PHP_ADD_BUILD_DIR($ext_builddir)
1000
1001dnl Set for phpize builds only
1002dnl ---------------------------
1003  if test "$ext_builddir" = "."; then
1004    PHP_PECL_EXTENSION=$1
1005    PHP_SUBST(PHP_PECL_EXTENSION)
1006  fi
1007])
1008
1009dnl
1010dnl PHP_WITH_SHARED
1011dnl
1012dnl Checks whether $withval is "shared" or starts with "shared,XXX"
1013dnl and sets $shared to "yes" or "no", and removes "shared,?" stuff
1014dnl from $withval.
1015dnl
1016AC_DEFUN([PHP_WITH_SHARED],[
1017  PHP_ARG_ANALYZE_EX(withval)
1018  shared=$ext_shared
1019  unset ext_shared ext_output
1020])
1021
1022dnl
1023dnl PHP_ADD_EXTENSION_DEP(extname, depends [, depconf])
1024dnl
1025dnl This macro is scanned by genif.sh when it builds the internal functions
1026dnl list, so that modules can be init'd in the correct order
1027dnl $1 = name of extension, $2 = extension upon which it depends
1028dnl $3 = optional: if true, it's ok for $2 to have not been configured
1029dnl default is false and should halt the build.
1030dnl To be effective, this macro must be invoked *after* PHP_NEW_EXTENSION.
1031dnl The extension on which it depends must also have been configured.
1032dnl See ADD_EXTENSION_DEP in win32 build
1033dnl
1034AC_DEFUN([PHP_ADD_EXTENSION_DEP], [
1035  am_i_shared=$[PHP_]translit($1,a-z_-,A-Z__)[_SHARED]
1036  is_it_shared=$[PHP_]translit($2,a-z_-,A-Z__)[_SHARED]
1037  is_it_enabled=$[PHP_]translit($2,a-z_-,A-Z__)
1038  if test "$am_i_shared" = "no" && test "$is_it_shared" = "yes" ; then
1039    AC_MSG_ERROR([
1040You've configured extension $1 to build statically, but it
1041depends on extension $2, which you've configured to build shared.
1042You either need to build $1 shared or build $2 statically for the
1043build to be successful.
1044])
1045  fi
1046  if test "x$is_it_enabled" = "xno" && test "x$3" != "xtrue"; then
1047    AC_MSG_ERROR([
1048You've configured extension $1, which depends on extension $2,
1049but you've either not enabled $2, or have disabled it.
1050])
1051  fi
1052  dnl Some systems require that we link $2 to $1 when building
1053])
1054
1055dnl -------------------------------------------------------------------------
1056dnl Checks for structures, typedefs, broken functions, etc.
1057dnl -------------------------------------------------------------------------
1058
1059dnl Internal helper macros
1060dnl
1061dnl _PHP_DEF_HAVE_FILE(what, filename)
1062AC_DEFUN([_PHP_DEF_HAVE_FILE], [
1063  php_def_have_what=HAVE_[]`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz-' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_' `
1064  echo "#define $php_def_have_what 1" >> $2
1065])
1066dnl
1067dnl _PHP_CHECK_SIZEOF(type, cross-value, extra-headers [, found-action [, not-found-action]])
1068dnl
1069AC_DEFUN([_PHP_CHECK_SIZEOF], [
1070  php_cache_value=php_cv_sizeof_[]$1
1071  AC_CACHE_VAL(php_cv_sizeof_[]$1, [
1072    old_LIBS=$LIBS
1073    LIBS=
1074    old_LDFLAGS=$LDFLAGS
1075    LDFLAGS=
1076    AC_TRY_RUN([#include <stdio.h>
1077#if STDC_HEADERS
1078#include <stdlib.h>
1079#include <stddef.h>
1080#endif
1081#ifdef HAVE_INTTYPES_H
1082#include <inttypes.h>
1083#endif
1084#ifdef HAVE_UNISTD_H
1085#include <unistd.h>
1086#endif
1087$3
1088
1089int main()
1090{
1091	FILE *fp = fopen("conftestval", "w");
1092	if (!fp) return(1);
1093	fprintf(fp, "%d\n", sizeof($1));
1094	return(0);
1095}
1096  ], [
1097    eval $php_cache_value=`cat conftestval`
1098  ], [
1099    eval $php_cache_value=0
1100  ], [
1101    ifelse([$2],,[eval $php_cache_value=0], [eval $php_cache_value=$2])
1102])
1103  LDFLAGS=$old_LDFLAGS
1104  LIBS=$old_LIBS
1105])
1106  if eval test "\$$php_cache_value" != "0"; then
1107ifelse([$4],[],:,[$4])
1108ifelse([$5],[],,[else $5])
1109  fi
1110])
1111
1112dnl
1113dnl PHP_CHECK_SIZEOF(type, cross-value, extra-headers)
1114dnl
1115AC_DEFUN([PHP_CHECK_SIZEOF], [
1116  AC_MSG_CHECKING([size of $1])
1117  _PHP_CHECK_SIZEOF($1, $2, $3, [
1118    AC_DEFINE_UNQUOTED([SIZEOF_]translit($1,a-z,A-Z_), [$]php_cv_sizeof_[]$1, [Size of $1])
1119    AC_DEFINE_UNQUOTED([HAVE_]translit($1,a-z,A-Z_), 1, [Whether $1 is available])
1120  ])
1121  AC_MSG_RESULT([[$][php_cv_sizeof_]translit($1, ,_)])
1122])
1123
1124dnl
1125dnl PHP_CHECK_TYPES(type-list, include-file [, extra-headers])
1126dnl
1127AC_DEFUN([PHP_CHECK_TYPES], [
1128  for php_typename in $1; do
1129    AC_MSG_CHECKING([whether $php_typename exists])
1130    _PHP_CHECK_SIZEOF($php_typename, 0, $3, [
1131      _PHP_DEF_HAVE_FILE($php_typename, $2)
1132      AC_MSG_RESULT([yes])
1133    ], [
1134      AC_MSG_RESULT([no])
1135    ])
1136  done
1137])
1138
1139dnl
1140dnl PHP_CHECK_IN_ADDR_T
1141dnl
1142AC_DEFUN([PHP_CHECK_IN_ADDR_T], [
1143dnl AIX keeps in_addr_t in /usr/include/netinet/in.h
1144AC_MSG_CHECKING([for in_addr_t])
1145AC_CACHE_VAL(ac_cv_type_in_addr_t,
1146[AC_EGREP_CPP(dnl
1147changequote(<<,>>)dnl
1148<<in_addr_t[^a-zA-Z_0-9]>>dnl
1149changequote([,]), [#include <sys/types.h>
1150#if STDC_HEADERS
1151#include <stdlib.h>
1152#include <stddef.h>
1153#endif
1154#ifdef HAVE_NETINET_IN_H
1155#include <netinet/in.h>
1156#endif], ac_cv_type_in_addr_t=yes, ac_cv_type_in_addr_t=no)])dnl
1157AC_MSG_RESULT([$ac_cv_type_in_addr_t])
1158if test $ac_cv_type_in_addr_t = no; then
1159  AC_DEFINE(in_addr_t, u_int, [ ])
1160fi
1161])
1162
1163dnl
1164dnl PHP_TIME_R_TYPE
1165dnl
1166dnl Check type of reentrant time-related functions
1167dnl Type can be: irix, hpux or POSIX
1168dnl
1169AC_DEFUN([PHP_TIME_R_TYPE],[
1170AC_CACHE_CHECK(for type of reentrant time-related functions, ac_cv_time_r_type,[
1171AC_TRY_RUN([
1172#include <time.h>
1173
1174main() {
1175char buf[27];
1176struct tm t;
1177time_t old = 0;
1178int r, s;
1179
1180s = gmtime_r(&old, &t);
1181r = (int) asctime_r(&t, buf, 26);
1182if (r == s && s == 0) return (0);
1183return (1);
1184}
1185],[
1186  ac_cv_time_r_type=hpux
1187],[
1188  AC_TRY_RUN([
1189#include <time.h>
1190main() {
1191  struct tm t, *s;
1192  time_t old = 0;
1193  char buf[27], *p;
1194
1195  s = gmtime_r(&old, &t);
1196  p = asctime_r(&t, buf, 26);
1197  if (p == buf && s == &t) return (0);
1198  return (1);
1199}
1200  ],[
1201    ac_cv_time_r_type=irix
1202  ],[
1203    ac_cv_time_r_type=POSIX
1204  ],[
1205    ac_cv_time_r_type=POSIX
1206  ])
1207],[
1208  ac_cv_time_r_type=POSIX
1209])
1210])
1211  case $ac_cv_time_r_type in
1212  hpux[)] AC_DEFINE(PHP_HPUX_TIME_R,1,[Whether you have HP-UX 10.x]) ;;
1213  irix[)] AC_DEFINE(PHP_IRIX_TIME_R,1,[Whether you have IRIX-style functions]) ;;
1214  esac
1215])
1216
1217dnl
1218dnl PHP_DOES_PWRITE_WORK
1219dnl internal
1220AC_DEFUN([PHP_DOES_PWRITE_WORK],[
1221  AC_TRY_RUN([
1222#include <sys/types.h>
1223#include <sys/stat.h>
1224#include <fcntl.h>
1225#include <unistd.h>
1226#include <errno.h>
1227$1
1228    main() {
1229    int fd = open("conftest_in", O_WRONLY|O_CREAT, 0600);
1230
1231    if (fd < 0) exit(1);
1232    if (pwrite(fd, "text", 4, 0) != 4) exit(1);
1233    /* Linux glibc breakage until 2.2.5 */
1234    if (pwrite(fd, "text", 4, -1) != -1 || errno != EINVAL) exit(1);
1235    exit(0);
1236    }
1237
1238  ],[
1239    ac_cv_pwrite=yes
1240  ],[
1241    ac_cv_pwrite=no
1242  ],[
1243    ac_cv_pwrite=no
1244  ])
1245])
1246
1247dnl PHP_DOES_PREAD_WORK
1248dnl internal
1249AC_DEFUN([PHP_DOES_PREAD_WORK],[
1250  echo test > conftest_in
1251  AC_TRY_RUN([
1252#include <sys/types.h>
1253#include <sys/stat.h>
1254#include <fcntl.h>
1255#include <unistd.h>
1256#include <errno.h>
1257$1
1258    main() {
1259    char buf[3];
1260    int fd = open("conftest_in", O_RDONLY);
1261    if (fd < 0) exit(1);
1262    if (pread(fd, buf, 2, 0) != 2) exit(1);
1263    /* Linux glibc breakage until 2.2.5 */
1264    if (pread(fd, buf, 2, -1) != -1 || errno != EINVAL) exit(1);
1265    exit(0);
1266    }
1267  ],[
1268    ac_cv_pread=yes
1269  ],[
1270    ac_cv_pread=no
1271  ],[
1272    ac_cv_pread=no
1273  ])
1274  rm -f conftest_in
1275])
1276
1277dnl
1278dnl PHP_PWRITE_TEST
1279dnl
1280AC_DEFUN([PHP_PWRITE_TEST],[
1281  AC_CACHE_CHECK(whether pwrite works,ac_cv_pwrite,[
1282    PHP_DOES_PWRITE_WORK
1283    if test "$ac_cv_pwrite" = "no"; then
1284      PHP_DOES_PWRITE_WORK([ssize_t pwrite(int, void *, size_t, off64_t);])
1285      if test "$ac_cv_pwrite" = "yes"; then
1286        ac_cv_pwrite=64
1287      fi
1288    fi
1289  ])
1290
1291  if test "$ac_cv_pwrite" != "no"; then
1292    AC_DEFINE(HAVE_PWRITE, 1, [ ])
1293    if test "$ac_cv_pwrite" = "64"; then
1294      AC_DEFINE(PHP_PWRITE_64, 1, [whether pwrite64 is default])
1295    fi
1296  fi
1297])
1298
1299dnl
1300dnl PHP_PREAD_TEST
1301dnl
1302AC_DEFUN([PHP_PREAD_TEST],[
1303  AC_CACHE_CHECK(whether pread works,ac_cv_pread,[
1304    PHP_DOES_PREAD_WORK
1305    if test "$ac_cv_pread" = "no"; then
1306      PHP_DOES_PREAD_WORK([ssize_t pread(int, void *, size_t, off64_t);])
1307      if test "$ac_cv_pread" = "yes"; then
1308        ac_cv_pread=64
1309      fi
1310    fi
1311  ])
1312
1313  if test "$ac_cv_pread" != "no"; then
1314    AC_DEFINE(HAVE_PREAD, 1, [ ])
1315    if test "$ac_cv_pread" = "64"; then
1316      AC_DEFINE(PHP_PREAD_64, 1, [whether pread64 is default])
1317    fi
1318  fi
1319])
1320
1321dnl
1322dnl PHP_MISSING_TIME_R_DECL
1323dnl
1324AC_DEFUN([PHP_MISSING_TIME_R_DECL],[
1325  AC_MSG_CHECKING([for missing declarations of reentrant functions])
1326  AC_TRY_COMPILE([#include <time.h>],[struct tm *(*func)() = localtime_r],[
1327    :
1328  ],[
1329    AC_DEFINE(MISSING_LOCALTIME_R_DECL,1,[Whether localtime_r is declared])
1330  ])
1331  AC_TRY_COMPILE([#include <time.h>],[struct tm *(*func)() = gmtime_r],[
1332    :
1333  ],[
1334    AC_DEFINE(MISSING_GMTIME_R_DECL,1,[Whether gmtime_r is declared])
1335  ])
1336  AC_TRY_COMPILE([#include <time.h>],[char *(*func)() = asctime_r],[
1337    :
1338  ],[
1339    AC_DEFINE(MISSING_ASCTIME_R_DECL,1,[Whether asctime_r is declared])
1340  ])
1341  AC_TRY_COMPILE([#include <time.h>],[char *(*func)() = ctime_r],[
1342    :
1343  ],[
1344    AC_DEFINE(MISSING_CTIME_R_DECL,1,[Whether ctime_r is declared])
1345  ])
1346  AC_TRY_COMPILE([#include <string.h>],[char *(*func)() = strtok_r],[
1347    :
1348  ],[
1349    AC_DEFINE(MISSING_STRTOK_R_DECL,1,[Whether strtok_r is declared])
1350  ])
1351  AC_MSG_RESULT([done])
1352])
1353
1354dnl
1355dnl PHP_READDIR_R_TYPE
1356dnl
1357AC_DEFUN([PHP_READDIR_R_TYPE],[
1358  dnl HAVE_READDIR_R is also defined by libmysql
1359  AC_CHECK_FUNC(readdir_r,ac_cv_func_readdir_r=yes,ac_cv_func_readdir=no)
1360  if test "$ac_cv_func_readdir_r" = "yes"; then
1361  AC_CACHE_CHECK(for type of readdir_r, ac_cv_what_readdir_r,[
1362    AC_TRY_RUN([
1363#define _REENTRANT
1364#include <sys/types.h>
1365#include <dirent.h>
1366
1367#ifndef PATH_MAX
1368#define PATH_MAX 1024
1369#endif
1370
1371main() {
1372  DIR *dir;
1373  char entry[sizeof(struct dirent)+PATH_MAX];
1374  struct dirent *pentry = (struct dirent *) &entry;
1375
1376  dir = opendir("/");
1377  if (!dir)
1378    exit(1);
1379  if (readdir_r(dir, (struct dirent *) entry, &pentry) == 0) {
1380    close(dir);
1381    exit(0);
1382  }
1383  close(dir);
1384  exit(1);
1385}
1386    ],[
1387      ac_cv_what_readdir_r=POSIX
1388    ],[
1389      AC_TRY_CPP([
1390#define _REENTRANT
1391#include <sys/types.h>
1392#include <dirent.h>
1393int readdir_r(DIR *, struct dirent *);
1394        ],[
1395          ac_cv_what_readdir_r=old-style
1396        ],[
1397          ac_cv_what_readdir_r=none
1398      ])
1399    ],[
1400      ac_cv_what_readdir_r=none
1401   ])
1402  ])
1403    case $ac_cv_what_readdir_r in
1404    POSIX)
1405      AC_DEFINE(HAVE_POSIX_READDIR_R,1,[whether you have POSIX readdir_r]);;
1406    old-style)
1407      AC_DEFINE(HAVE_OLD_READDIR_R,1,[whether you have old-style readdir_r]);;
1408    esac
1409  fi
1410])
1411
1412dnl
1413dnl PHP_TM_GMTOFF
1414dnl
1415AC_DEFUN([PHP_TM_GMTOFF],[
1416AC_CACHE_CHECK([for tm_gmtoff in struct tm], ac_cv_struct_tm_gmtoff,
1417[AC_TRY_COMPILE([#include <sys/types.h>
1418#include <$ac_cv_struct_tm>], [struct tm tm; tm.tm_gmtoff;],
1419  ac_cv_struct_tm_gmtoff=yes, ac_cv_struct_tm_gmtoff=no)])
1420
1421if test "$ac_cv_struct_tm_gmtoff" = yes; then
1422  AC_DEFINE(HAVE_TM_GMTOFF,1,[whether you have tm_gmtoff in struct tm])
1423fi
1424])
1425
1426dnl
1427dnl PHP_STRUCT_FLOCK
1428dnl
1429AC_DEFUN([PHP_STRUCT_FLOCK],[
1430AC_CACHE_CHECK(for struct flock,ac_cv_struct_flock,
1431    AC_TRY_COMPILE([
1432#include <unistd.h>
1433#include <fcntl.h>
1434        ],
1435        [struct flock x;],
1436        [
1437          ac_cv_struct_flock=yes
1438        ],[
1439          ac_cv_struct_flock=no
1440        ])
1441)
1442if test "$ac_cv_struct_flock" = "yes" ; then
1443    AC_DEFINE(HAVE_STRUCT_FLOCK, 1,[whether you have struct flock])
1444fi
1445])
1446
1447dnl
1448dnl PHP_SOCKLEN_T
1449dnl
1450AC_DEFUN([PHP_SOCKLEN_T],[
1451AC_CACHE_CHECK(for socklen_t,ac_cv_socklen_t,
1452  AC_TRY_COMPILE([
1453#include <sys/types.h>
1454#include <sys/socket.h>
1455],[
1456socklen_t x;
1457],[
1458  ac_cv_socklen_t=yes
1459],[
1460  ac_cv_socklen_t=no
1461]))
1462if test "$ac_cv_socklen_t" = "yes"; then
1463  AC_DEFINE(HAVE_SOCKLEN_T, 1, [Whether you have socklen_t])
1464fi
1465])
1466
1467dnl
1468dnl PHP_MISSING_FCLOSE_DECL
1469dnl
1470dnl See if we have broken header files like SunOS has.
1471dnl
1472AC_DEFUN([PHP_MISSING_FCLOSE_DECL],[
1473  AC_MSG_CHECKING([for fclose declaration])
1474  AC_TRY_COMPILE([#include <stdio.h>],[int (*func)() = fclose],[
1475    AC_DEFINE(MISSING_FCLOSE_DECL,0,[ ])
1476    AC_MSG_RESULT([ok])
1477  ],[
1478    AC_DEFINE(MISSING_FCLOSE_DECL,1,[ ])
1479    AC_MSG_RESULT([missing])
1480  ])
1481])
1482
1483dnl
1484dnl PHP_AC_BROKEN_SPRINTF
1485dnl
1486dnl Check for broken sprintf(), C99 conformance
1487dnl
1488AC_DEFUN([PHP_AC_BROKEN_SPRINTF],[
1489  AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[
1490    AC_TRY_RUN([main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[
1491      ac_cv_broken_sprintf=no
1492    ],[
1493      ac_cv_broken_sprintf=yes
1494    ],[
1495      ac_cv_broken_sprintf=no
1496    ])
1497  ])
1498  if test "$ac_cv_broken_sprintf" = "yes"; then
1499    AC_DEFINE(PHP_BROKEN_SPRINTF, 1, [Whether sprintf is C99 conform])
1500  else
1501    AC_DEFINE(PHP_BROKEN_SPRINTF, 0, [Whether sprintf is C99 conform])
1502  fi
1503])
1504
1505dnl
1506dnl PHP_AC_BROKEN_SNPRINTF
1507dnl
1508dnl Check for broken snprintf(), C99 conformance
1509dnl
1510AC_DEFUN([PHP_AC_BROKEN_SNPRINTF],[
1511  AC_CACHE_CHECK(whether snprintf is broken, ac_cv_broken_snprintf,[
1512    AC_TRY_RUN([
1513#define NULL (0L)
1514main() {
1515  char buf[20];
1516  int res = 0;
1517  res = res || (snprintf(buf, 2, "marcus") != 6);
1518  res = res || (buf[1] != '\0');
1519  /* Implementations may consider this as an encoding error */
1520  snprintf(buf, 0, "boerger");
1521  /* However, they MUST ignore the pointer */
1522  res = res || (buf[0] != 'm');
1523  res = res || (snprintf(NULL, 0, "boerger") != 7);
1524  res = res || (snprintf(buf, sizeof(buf), "%f", 0.12345678) != 8);
1525  exit(res);
1526}
1527    ],[
1528      ac_cv_broken_snprintf=no
1529    ],[
1530      ac_cv_broken_snprintf=yes
1531    ],[
1532      ac_cv_broken_snprintf=no
1533    ])
1534  ])
1535  if test "$ac_cv_broken_snprintf" = "yes"; then
1536    AC_DEFINE(PHP_BROKEN_SNPRINTF, 1, [Whether snprintf is C99 conform])
1537  else
1538    AC_DEFINE(PHP_BROKEN_SNPRINTF, 0, [Whether snprintf is C99 conform])
1539  fi
1540])
1541
1542dnl
1543dnl PHP_SOLARIS_PIC_WEIRDNESS
1544dnl
1545dnl Solaris requires main code to be position independent in order
1546dnl to let shared objects find symbols.  Weird.  Ugly.
1547dnl
1548dnl Must be run after all --with-NN options that let the user
1549dnl choose dynamic extensions, and after the gcc test.
1550dnl
1551AC_DEFUN([PHP_SOLARIS_PIC_WEIRDNESS],[
1552  AC_MSG_CHECKING([whether -fPIC is required])
1553  if test -n "$EXT_SHARED"; then
1554    os=`uname -sr 2>/dev/null`
1555    case $os in
1556      "SunOS 5.6"|"SunOS 5.7"[)]
1557        case $CC in
1558          gcc*|egcs*)
1559            CFLAGS="$CFLAGS -fPIC";;
1560          *[)]
1561            CFLAGS="$CFLAGS -fpic";;
1562        esac
1563        AC_MSG_RESULT([yes]);;
1564      *[)]
1565        AC_MSG_RESULT([no]);;
1566    esac
1567  else
1568    AC_MSG_RESULT([no])
1569  fi
1570])
1571
1572dnl
1573dnl PHP_SYS_LFS
1574dnl
1575dnl The problem is that the default compilation flags in Solaris 2.6 won't
1576dnl let programs access large files;  you need to tell the compiler that
1577dnl you actually want your programs to work on large files.  For more
1578dnl details about this brain damage please see:
1579dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
1580dnl
1581dnl Written by Paul Eggert <eggert@twinsun.com>.
1582dnl
1583AC_DEFUN([PHP_SYS_LFS],
1584[dnl
1585  # If available, prefer support for large files unless the user specified
1586  # one of the CPPFLAGS, LDFLAGS, or LIBS variables.
1587  AC_MSG_CHECKING([whether large file support needs explicit enabling])
1588  ac_getconfs=''
1589  ac_result=yes
1590  ac_set=''
1591  ac_shellvars='CPPFLAGS LDFLAGS LIBS'
1592  for ac_shellvar in $ac_shellvars; do
1593    case $ac_shellvar in
1594      CPPFLAGS[)] ac_lfsvar=LFS_CFLAGS ;;
1595      *[)] ac_lfsvar=LFS_$ac_shellvar ;;
1596    esac
1597    eval test '"${'$ac_shellvar'+set}"' = set && ac_set=$ac_shellvar
1598    (getconf $ac_lfsvar) >/dev/null 2>&1 || { ac_result=no; break; }
1599    ac_getconf=`getconf $ac_lfsvar`
1600    ac_getconfs=$ac_getconfs$ac_getconf
1601    eval ac_test_$ac_shellvar=\$ac_getconf
1602  done
1603  case "$ac_result$ac_getconfs" in
1604    yes[)] ac_result=no ;;
1605  esac
1606  case "$ac_result$ac_set" in
1607    yes?*[)] ac_result="yes, but $ac_set is already set, so use its settings"
1608  esac
1609  AC_MSG_RESULT([$ac_result])
1610  case $ac_result in
1611    yes[)]
1612      for ac_shellvar in $ac_shellvars; do
1613        eval $ac_shellvar=\$ac_test_$ac_shellvar
1614      done ;;
1615  esac
1616])
1617
1618dnl
1619dnl PHP_SOCKADDR_CHECKS
1620dnl
1621AC_DEFUN([PHP_SOCKADDR_CHECKS], [
1622  dnl Check for struct sockaddr_storage exists
1623  AC_CACHE_CHECK([for struct sockaddr_storage], ac_cv_sockaddr_storage,
1624    [AC_TRY_COMPILE([#include <sys/types.h>
1625#include <sys/socket.h>],
1626    [struct sockaddr_storage s; s],
1627    [ac_cv_sockaddr_storage=yes], [ac_cv_sockaddr_storage=no])
1628  ])
1629  if test "$ac_cv_sockaddr_storage" = "yes"; then
1630    AC_DEFINE(HAVE_SOCKADDR_STORAGE, 1, [Whether you have struct sockaddr_storage])
1631  fi
1632  dnl Check if field sa_len exists in struct sockaddr
1633  AC_CACHE_CHECK([for field sa_len in struct sockaddr],ac_cv_sockaddr_sa_len,[
1634    AC_TRY_COMPILE([#include <sys/types.h>
1635#include <sys/socket.h>],
1636    [static struct sockaddr sa; int n = (int) sa.sa_len; return n;],
1637    [ac_cv_sockaddr_sa_len=yes], [ac_cv_sockaddr_sa_len=no])
1638  ])
1639  if test "$ac_cv_sockaddr_sa_len" = "yes"; then
1640    AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has field sa_len])
1641  fi
1642])
1643
1644dnl
1645dnl PHP_DECLARED_TIMEZONE
1646dnl
1647AC_DEFUN([PHP_DECLARED_TIMEZONE],[
1648  AC_CACHE_CHECK(for declared timezone, ac_cv_declared_timezone,[
1649    AC_TRY_COMPILE([
1650#include <sys/types.h>
1651#include <time.h>
1652#ifdef HAVE_SYS_TIME_H
1653#include <sys/time.h>
1654#endif
1655],[
1656    time_t foo = (time_t) timezone;
1657],[
1658  ac_cv_declared_timezone=yes
1659],[
1660  ac_cv_declared_timezone=no
1661])])
1662  if test "$ac_cv_declared_timezone" = "yes"; then
1663    AC_DEFINE(HAVE_DECLARED_TIMEZONE, 1, [Whether system headers declare timezone])
1664  fi
1665])
1666
1667dnl
1668dnl PHP_EBCDIC
1669dnl
1670AC_DEFUN([PHP_EBCDIC], [
1671  AC_CACHE_CHECK([whether system uses EBCDIC],ac_cv_ebcdic,[
1672  AC_TRY_RUN( [
1673int main(void) {
1674  return (unsigned char)'A' != (unsigned char)0xC1;
1675}
1676],[
1677  ac_cv_ebcdic=yes
1678],[
1679  ac_cv_ebcdic=no
1680],[
1681  ac_cv_ebcdic=no
1682])])
1683  if test "$ac_cv_ebcdic" = "yes"; then
1684    AC_DEFINE(CHARSET_EBCDIC,1, [Define if system uses EBCDIC])
1685  fi
1686])
1687
1688dnl
1689dnl PHP_BROKEN_GETCWD
1690dnl
1691dnl Some systems, notably Solaris, cause getcwd() or realpath to fail if a
1692dnl component of the path has execute but not read permissions
1693dnl
1694AC_DEFUN([PHP_BROKEN_GETCWD],[
1695  AC_MSG_CHECKING([for broken getcwd])
1696  os=`uname -sr 2>/dev/null`
1697  case $os in
1698    SunOS*[)]
1699      AC_DEFINE(HAVE_BROKEN_GETCWD,1, [Define if system has broken getcwd])
1700      AC_MSG_RESULT([yes]);;
1701    *[)]
1702      AC_MSG_RESULT([no]);;
1703  esac
1704])
1705
1706dnl
1707dnl PHP_BROKEN_GLIBC_FOPEN_APPEND
1708dnl
1709AC_DEFUN([PHP_BROKEN_GLIBC_FOPEN_APPEND], [
1710  AC_MSG_CHECKING([for broken libc stdio])
1711  AC_CACHE_VAL(_cv_have_broken_glibc_fopen_append,[
1712  AC_TRY_RUN([
1713#include <stdio.h>
1714int main(int argc, char *argv[])
1715{
1716  FILE *fp;
1717  long position;
1718  char *filename = tmpnam(NULL);
1719
1720  fp = fopen(filename, "w");
1721  if (fp == NULL) {
1722    perror("fopen");
1723    exit(2);
1724  }
1725  fputs("foobar", fp);
1726  fclose(fp);
1727
1728  fp = fopen(filename, "a+");
1729  position = ftell(fp);
1730  fclose(fp);
1731  unlink(filename);
1732  if (position == 0)
1733  return 1;
1734  return 0;
1735}
1736],
1737[_cv_have_broken_glibc_fopen_append=no],
1738[_cv_have_broken_glibc_fopen_append=yes ],
1739AC_TRY_COMPILE([
1740#include <features.h>
1741],[
1742#if !__GLIBC_PREREQ(2,2)
1743choke me
1744#endif
1745],
1746[_cv_have_broken_glibc_fopen_append=yes],
1747[_cv_have_broken_glibc_fopen_append=no ])
1748)])
1749
1750  if test "$_cv_have_broken_glibc_fopen_append" = "yes"; then
1751    AC_MSG_RESULT(yes)
1752    AC_DEFINE(HAVE_BROKEN_GLIBC_FOPEN_APPEND,1, [Define if your glibc borks on fopen with mode a+])
1753  else
1754    AC_MSG_RESULT(no)
1755  fi
1756])
1757
1758dnl
1759dnl PHP_FOPENCOOKIE
1760dnl
1761AC_DEFUN([PHP_FOPENCOOKIE], [
1762  AC_CHECK_FUNC(fopencookie, [have_glibc_fopencookie=yes])
1763
1764  if test "$have_glibc_fopencookie" = "yes"; then
1765dnl this comes in two flavors:
1766dnl newer glibcs (since 2.1.2 ? )
1767dnl have a type called cookie_io_functions_t
1768AC_TRY_COMPILE([
1769#define _GNU_SOURCE
1770#include <stdio.h>
1771], [cookie_io_functions_t cookie;], [have_cookie_io_functions_t=yes], [])
1772
1773    if test "$have_cookie_io_functions_t" = "yes"; then
1774      cookie_io_functions_t=cookie_io_functions_t
1775      have_fopen_cookie=yes
1776
1777dnl even newer glibcs have a different seeker definition...
1778AC_TRY_RUN([
1779#define _GNU_SOURCE
1780#include <stdio.h>
1781
1782struct cookiedata {
1783  __off64_t pos;
1784};
1785
1786__ssize_t reader(void *cookie, char *buffer, size_t size)
1787{ return size; }
1788__ssize_t writer(void *cookie, const char *buffer, size_t size)
1789{ return size; }
1790int closer(void *cookie)
1791{ return 0; }
1792int seeker(void *cookie, __off64_t *position, int whence)
1793{ ((struct cookiedata*)cookie)->pos = *position; return 0; }
1794
1795cookie_io_functions_t funcs = {reader, writer, seeker, closer};
1796
1797main() {
1798  struct cookiedata g = { 0 };
1799  FILE *fp = fopencookie(&g, "r", funcs);
1800
1801  if (fp && fseek(fp, 8192, SEEK_SET) == 0 && g.pos == 8192)
1802    exit(0);
1803  exit(1);
1804}
1805
1806], [
1807  cookie_io_functions_use_off64_t=yes
1808], [
1809  cookie_io_functions_use_off64_t=no
1810], [
1811  cookie_io_functions_use_off64_t=no
1812])
1813
1814    else
1815
1816dnl older glibc versions (up to 2.1.2 ?)
1817dnl call it _IO_cookie_io_functions_t
1818AC_TRY_COMPILE([
1819#define _GNU_SOURCE
1820#include <stdio.h>
1821], [ _IO_cookie_io_functions_t cookie; ], [have_IO_cookie_io_functions_t=yes], [])
1822      if test "$have_cookie_io_functions_t" = "yes" ; then
1823        cookie_io_functions_t=_IO_cookie_io_functions_t
1824        have_fopen_cookie=yes
1825      fi
1826    fi
1827
1828    if test "$have_fopen_cookie" = "yes" ; then
1829      AC_DEFINE(HAVE_FOPENCOOKIE, 1, [ ])
1830      AC_DEFINE_UNQUOTED(COOKIE_IO_FUNCTIONS_T, $cookie_io_functions_t, [ ])
1831      if test "$cookie_io_functions_use_off64_t" = "yes" ; then
1832        AC_DEFINE(COOKIE_SEEKER_USES_OFF64_T, 1, [ ])
1833      fi
1834    fi
1835  fi
1836])
1837
1838dnl -------------------------------------------------------------------------
1839dnl Library/function existence and build sanity checks
1840dnl -------------------------------------------------------------------------
1841
1842dnl
1843dnl PHP_CHECK_LIBRARY(library, function [, action-found [, action-not-found [, extra-libs]]])
1844dnl
1845dnl Wrapper for AC_CHECK_LIB
1846dnl
1847AC_DEFUN([PHP_CHECK_LIBRARY], [
1848  save_old_LDFLAGS=$LDFLAGS
1849  ac_stuff="$5"
1850
1851  save_ext_shared=$ext_shared
1852  ext_shared=yes
1853  PHP_EVAL_LIBLINE([$]ac_stuff, LDFLAGS)
1854  AC_CHECK_LIB([$1],[$2],[
1855    LDFLAGS=$save_old_LDFLAGS
1856    ext_shared=$save_ext_shared
1857    $3
1858  ],[
1859    LDFLAGS=$save_old_LDFLAGS
1860    ext_shared=$save_ext_shared
1861    unset ac_cv_lib_$1[]_$2
1862    $4
1863  ])dnl
1864])
1865
1866dnl
1867dnl PHP_CHECK_FRAMEWORK(framework, function [, action-found [, action-not-found ]])
1868dnl
1869dnl El cheapo wrapper for AC_CHECK_LIB
1870dnl
1871AC_DEFUN([PHP_CHECK_FRAMEWORK], [
1872  save_old_LDFLAGS=$LDFLAGS
1873  LDFLAGS="-framework $1 $LDFLAGS"
1874  dnl supplying "c" to AC_CHECK_LIB is technically cheating, but
1875  dnl rewriting AC_CHECK_LIB is overkill and this only affects
1876  dnl the "checking.." output anyway.
1877  AC_CHECK_LIB(c,[$2],[
1878    LDFLAGS=$save_old_LDFLAGS
1879    $3
1880  ],[
1881    LDFLAGS=$save_old_LDFLAGS
1882    $4
1883  ])
1884])
1885
1886dnl
1887dnl PHP_CHECK_FUNC_LIB(func, libs)
1888dnl
1889dnl This macro checks whether 'func' or '__func' exists
1890dnl in the specified library.
1891dnl Defines HAVE_func and HAVE_library if found and adds the library to LIBS.
1892dnl This should be called in the ACTION-IF-NOT-FOUND part of PHP_CHECK_FUNC
1893dnl
1894dnl
1895dnl autoconf undefines the builtin "shift" :-(
1896dnl If possible, we use the builtin shift anyway, otherwise we use
1897dnl the ubercool definition I have tested so far with FreeBSD/GNU m4
1898ifdef([builtin],[builtin(define, phpshift, [builtin(shift, $@)])],[
1899define([phpshift],[ifelse(index([$@],[,]),-1,,[substr([$@],incr(index([$@],[,])))])])
1900])
1901dnl
1902AC_DEFUN([PHP_CHECK_FUNC_LIB],[
1903  ifelse($2,,:,[
1904  unset ac_cv_lib_$2[]_$1
1905  unset ac_cv_lib_$2[]___$1
1906  unset found
1907  AC_CHECK_LIB($2, $1, [found=yes], [
1908    AC_CHECK_LIB($2, __$1, [found=yes], [found=no])
1909  ])
1910
1911  if test "$found" = "yes"; then
1912    ac_libs=$LIBS
1913    LIBS="$LIBS -l$2"
1914    AC_TRY_RUN([main() { return (0); }],[found=yes],[found=no],[found=no])
1915    LIBS=$ac_libs
1916  fi
1917
1918  if test "$found" = "yes"; then
1919    PHP_ADD_LIBRARY($2)
1920    PHP_DEF_HAVE($1)
1921    PHP_DEF_HAVE(lib$2)
1922    ac_cv_func_$1=yes
1923  else
1924    PHP_CHECK_FUNC_LIB($1,phpshift(phpshift($@)))
1925  fi
1926  ])
1927])
1928
1929dnl
1930dnl PHP_CHECK_FUNC(func, ...)
1931dnl
1932dnl This macro checks whether 'func' or '__func' exists
1933dnl in the default libraries and as a fall back in the specified library.
1934dnl Defines HAVE_func and HAVE_library if found and adds the library to LIBS.
1935dnl
1936AC_DEFUN([PHP_CHECK_FUNC],[
1937  unset ac_cv_func_$1
1938  unset ac_cv_func___$1
1939  unset found
1940
1941  AC_CHECK_FUNC($1, [found=yes],[ AC_CHECK_FUNC(__$1,[found=yes],[found=no]) ])
1942
1943  case $found in
1944  yes[)]
1945    PHP_DEF_HAVE($1)
1946    ac_cv_func_$1=yes
1947  ;;
1948  ifelse($#,1,,[
1949    *[)] PHP_CHECK_FUNC_LIB($@) ;;
1950  ])
1951  esac
1952])
1953
1954dnl
1955dnl PHP_TEST_BUILD(function, action-if-ok, action-if-not-ok [, extra-libs [, extra-source]])
1956dnl
1957dnl This macro checks whether build works and given function exists.
1958dnl
1959AC_DEFUN([PHP_TEST_BUILD], [
1960  old_LIBS=$LIBS
1961  LIBS="$4 $LIBS"
1962  AC_TRY_RUN([
1963    $5
1964    char $1();
1965    int main() {
1966      $1();
1967      return 0;
1968    }
1969  ], [
1970    LIBS=$old_LIBS
1971    $2
1972  ],[
1973    LIBS=$old_LIBS
1974    $3
1975  ],[
1976    LIBS=$old_LIBS
1977  ])
1978])
1979
1980dnl -------------------------------------------------------------------------
1981dnl Platform characteristics checks
1982dnl -------------------------------------------------------------------------
1983
1984dnl
1985dnl PHP_SHLIB_SUFFIX_NAMES
1986dnl
1987dnl Determines link library suffix SHLIB_SUFFIX_NAME
1988dnl which can be: .so, .sl or .dylib
1989dnl
1990dnl Determines shared library suffix SHLIB_DL_SUFFIX_NAME
1991dnl suffix can be: .so or .sl
1992dnl
1993AC_DEFUN([PHP_SHLIB_SUFFIX_NAMES],[
1994 AC_REQUIRE([PHP_CANONICAL_HOST_TARGET])dnl
1995 PHP_SUBST_OLD(SHLIB_SUFFIX_NAME)
1996 PHP_SUBST_OLD(SHLIB_DL_SUFFIX_NAME)
1997 SHLIB_SUFFIX_NAME=so
1998 SHLIB_DL_SUFFIX_NAME=$SHLIB_SUFFIX_NAME
1999 case $host_alias in
2000 *hpux*[)]
2001   SHLIB_SUFFIX_NAME=sl
2002   SHLIB_DL_SUFFIX_NAME=sl
2003   ;;
2004 *darwin*[)]
2005   SHLIB_SUFFIX_NAME=dylib
2006   SHLIB_DL_SUFFIX_NAME=so
2007   ;;
2008 esac
2009])
2010
2011dnl
2012dnl PHP_CHECK_64BIT([do if 32], [do if 64])
2013dnl
2014dnl This macro is used to detect if we're at 64-bit platform or not.
2015dnl It could be useful for those external libs, that have different precompiled
2016dnl versions in different directories.
2017dnl
2018AC_DEFUN([PHP_CHECK_64BIT],[
2019  AC_CHECK_SIZEOF(long int, 4)
2020  AC_MSG_CHECKING([checking if we're at 64-bit platform])
2021  if test "$ac_cv_sizeof_long_int" = "4" ; then
2022    AC_MSG_RESULT([no])
2023    $1
2024  else
2025    AC_MSG_RESULT([yes])
2026    $2
2027  fi
2028])
2029
2030dnl
2031dnl PHP_C_BIGENDIAN
2032dnl
2033dnl Replacement macro for AC_C_BIGENDIAN
2034dnl
2035AC_DEFUN([PHP_C_BIGENDIAN],
2036[AC_CACHE_CHECK([whether byte ordering is bigendian], ac_cv_c_bigendian_php,
2037 [
2038  ac_cv_c_bigendian_php=unknown
2039  AC_TRY_RUN(
2040  [
2041int main(void)
2042{
2043  short one = 1;
2044  char *cp = (char *)&one;
2045
2046  if (*cp == 0) {
2047    return(0);
2048  } else {
2049    return(1);
2050  }
2051}
2052  ], [ac_cv_c_bigendian_php=yes], [ac_cv_c_bigendian_php=no], [ac_cv_c_bigendian_php=unknown])
2053 ])
2054 if test $ac_cv_c_bigendian_php = yes; then
2055   AC_DEFINE(WORDS_BIGENDIAN, [], [Define if processor uses big-endian word])
2056 fi
2057])
2058
2059dnl -------------------------------------------------------------------------
2060dnl Checks for programs: PHP_PROG_<program>
2061dnl -------------------------------------------------------------------------
2062
2063dnl
2064dnl PHP_PROG_SENDMAIL
2065dnl
2066dnl Search for the sendmail binary
2067dnl
2068AC_DEFUN([PHP_PROG_SENDMAIL], [
2069  PHP_ALT_PATH=/usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib
2070  AC_PATH_PROG(PROG_SENDMAIL, sendmail,[], $PATH:$PHP_ALT_PATH)
2071  PHP_SUBST(PROG_SENDMAIL)
2072])
2073
2074dnl
2075dnl PHP_PROG_AWK
2076dnl
2077dnl Some vendors force mawk before gawk; mawk is broken so we don't like that
2078dnl
2079AC_DEFUN([PHP_PROG_AWK], [
2080  AC_CHECK_PROGS(AWK, gawk nawk awk mawk, bork, /usr/xpg4/bin/:$PATH)
2081  case "$AWK" in
2082    *mawk)
2083      AC_MSG_WARN([mawk is known to have problems on some systems. You should install GNU awk])
2084      ;;
2085    *gawk)
2086      ;;
2087    bork)
2088      AC_MSG_ERROR([Could not find awk; Install GNU awk])
2089      ;;
2090    *)
2091      AC_MSG_CHECKING([if $AWK is broken])
2092      if ! $AWK 'function foo() {}' >/dev/null 2>&1 ; then
2093        AC_MSG_RESULT([yes])
2094        AC_MSG_ERROR([You should install GNU awk])
2095      else
2096        AC_MSG_RESULT([no])
2097      fi
2098      ;;
2099  esac
2100  PHP_SUBST(AWK)
2101])
2102
2103dnl
2104dnl PHP_PROG_BISON
2105dnl
2106dnl Search for bison and check it's version
2107dnl
2108AC_DEFUN([PHP_PROG_BISON], [
2109  AC_PROG_YACC
2110  LIBZEND_BISON_CHECK
2111  PHP_SUBST(YACC)
2112])
2113
2114dnl
2115dnl PHP_PROG_LEX
2116dnl
2117dnl Search for (f)lex and check it's version
2118dnl
2119AC_DEFUN([PHP_PROG_LEX], [
2120dnl we only support certain flex versions
2121  flex_version_list="2.5.4"
2122
2123  AC_PROG_LEX
2124  if test "$LEX" = "flex"; then
2125dnl AC_DECL_YYTEXT is obsolete since autoconf 2.50 and merged into AC_PROG_LEX
2126dnl this is what causes that annoying "PHP_PROG_LEX is expanded from" warning with autoconf 2.50+
2127dnl it should be removed once we drop support of autoconf 2.13 (if ever)
2128    AC_DECL_YYTEXT
2129    :
2130  fi
2131  dnl ## Make flex scanners use const if they can, even if __STDC__ is not
2132  dnl ## true, for compilers like Sun's that only set __STDC__ true in
2133  dnl ## "limit-to-ANSI-standard" mode, not in "ANSI-compatible" mode
2134  AC_C_CONST
2135  if test "$ac_cv_c_const" = "yes" ; then
2136    LEX_CFLAGS="-DYY_USE_CONST"
2137  fi
2138
2139  if test "$LEX" = "flex"; then
2140    AC_CACHE_CHECK([for flex version], php_cv_flex_version, [
2141      flex_version=`$LEX -V -v --version 2>/dev/null | $SED -e 's/^.* //'`
2142      php_cv_flex_version=invalid
2143      for flex_check_version in $flex_version_list; do
2144        if test "$flex_version" = "$flex_check_version"; then
2145          php_cv_flex_version="$flex_check_version (ok)"
2146        fi
2147      done
2148    ])
2149  else
2150    flex_version=none
2151  fi
2152
2153  case $php_cv_flex_version in
2154    ""|invalid[)]
2155      if test -f "$abs_srcdir/Zend/zend_language_scanner.c" && test -f "$abs_srcdir/Zend/zend_ini_scanner.c"; then
2156        AC_MSG_WARN([flex versions supported for regeneration of the Zend/PHP parsers: $flex_version_list  (found: $flex_version)])
2157      else
2158        flex_msg="Supported flex versions are: $flex_version_list"
2159        if test "$flex_version" = "none"; then
2160          flex_msg="flex not found. flex is required to generate the Zend/PHP parsers! $flex_msg"
2161        else
2162          flex_msg="Found invalid flex version: $flex_version. $flex_msg"
2163        fi
2164        AC_MSG_ERROR([$flex_msg])
2165      fi
2166      LEX="exit 0;"
2167      ;;
2168  esac
2169  PHP_SUBST(LEX)
2170])
2171
2172dnl
2173dnl PHP_PROG_RE2C
2174dnl
2175dnl Search for the re2c binary and check the version
2176dnl
2177AC_DEFUN([PHP_PROG_RE2C],[
2178  AC_CHECK_PROG(RE2C, re2c, re2c)
2179  if test -n "$RE2C"; then
2180    AC_CACHE_CHECK([for re2c version], php_cv_re2c_version, [
2181      re2c_vernum=`$RE2C --vernum 2>/dev/null`
2182      if test -z "$re2c_vernum" || test "$re2c_vernum" -lt "1304"; then
2183        php_cv_re2c_version=invalid
2184      else
2185        php_cv_re2c_version="`$RE2C --version | cut -d ' ' -f 2  2>/dev/null` (ok)"
2186      fi
2187    ])
2188  fi
2189  case $php_cv_re2c_version in
2190    ""|invalid[)]
2191      AC_MSG_WARN([You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.])
2192      RE2C="exit 0;"
2193      ;;
2194  esac
2195  PHP_SUBST(RE2C)
2196])
2197
2198dnl -------------------------------------------------------------------------
2199dnl Common setup macros: PHP_SETUP_<what>
2200dnl -------------------------------------------------------------------------
2201
2202dnl
2203dnl PHP_SETUP_ICU([shared-add])
2204dnl
2205dnl Common setup macro for ICU
2206dnl
2207AC_DEFUN([PHP_SETUP_ICU],[
2208  PHP_ARG_WITH(icu-dir,,
2209  [  --with-icu-dir=DIR      Specify where ICU libraries and headers can be found], DEFAULT, no)
2210
2211  if test "$PHP_ICU_DIR" = "no"; then
2212    PHP_ICU_DIR=DEFAULT
2213  fi
2214
2215  AC_MSG_CHECKING([for location of ICU headers and libraries])
2216  found_icu=no
2217
2218  dnl First try to find pkg-config
2219  if test -z "$PKG_CONFIG"; then
2220    AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
2221  fi
2222
2223  dnl If pkg-config is found try using it
2224  if test "$PHP_ICU_DIR" = "DEFAULT" && test -x "$PKG_CONFIG" && $PKG_CONFIG --exists icu-uc icu-io icu-i18n; then
2225    if $PKG_CONFIG --atleast-version=40 icu-uc; then
2226      found_icu=yes
2227      icu_version_full=`$PKG_CONFIG --modversion icu-uc`
2228      ac_IFS=$IFS
2229      IFS="."
2230      set $icu_version_full
2231      IFS=$ac_IFS
2232      icu_version=`expr [$]1 \* 1000 + [$]2`
2233      AC_MSG_RESULT([found $icu_version_full])
2234
2235      ICU_LIBS=`$PKG_CONFIG --libs icu-uc icu-io icu-i18n`
2236      ICU_INCS=`$PKG_CONFIG --cflags-only-I icu-uc icu-io icu-i18n`
2237      ICU_CXXFLAGS="-DU_USING_ICU_NAMESPACE=1"
2238
2239      AC_MSG_RESULT([found $ICU_VERSION])
2240
2241      PHP_EVAL_LIBLINE($ICU_LIBS, $1)
2242      PHP_EVAL_INCLINE($ICU_INCS)
2243    else
2244      AC_MSG_ERROR([ICU version 4.0 or later required.])
2245    fi
2246  fi
2247
2248  dnl If pkg-config fails for some reason, revert to the old method
2249  if test "$found_icu" = "no"; then
2250    if test "$PHP_ICU_DIR" = "DEFAULT"; then
2251      dnl Try to find icu-config
2252      AC_PATH_PROG(ICU_CONFIG, icu-config, no, [$PATH:/usr/local/bin])
2253    else
2254      ICU_CONFIG="$PHP_ICU_DIR/bin/icu-config"
2255    fi
2256
2257    dnl Trust icu-config to know better what the install prefix is..
2258    icu_install_prefix=`$ICU_CONFIG --prefix 2> /dev/null`
2259    if test "$?" != "0" || test -z "$icu_install_prefix"; then
2260      AC_MSG_RESULT([not found])
2261      AC_MSG_ERROR([Unable to detect ICU prefix or $ICU_CONFIG failed. Please verify ICU install prefix and make sure icu-config works.])
2262    else
2263      AC_MSG_RESULT([$icu_install_prefix])
2264
2265      dnl Check ICU version
2266      AC_MSG_CHECKING([for ICU 4.0 or greater])
2267      icu_version_full=`$ICU_CONFIG --version`
2268      ac_IFS=$IFS
2269      IFS="."
2270      set $icu_version_full
2271      IFS=$ac_IFS
2272      icu_version=`expr [$]1 \* 1000 + [$]2`
2273      AC_MSG_RESULT([found $icu_version_full])
2274
2275      if test "$icu_version" -lt "4000"; then
2276        AC_MSG_ERROR([ICU version 4.0 or later is required])
2277      fi
2278
2279      ICU_VERSION=$icu_version
2280      ICU_INCS=`$ICU_CONFIG --cppflags-searchpath`
2281      ICU_LIBS=`$ICU_CONFIG --ldflags --ldflags-icuio`
2282      PHP_EVAL_INCLINE($ICU_INCS)
2283      PHP_EVAL_LIBLINE($ICU_LIBS, $1)
2284
2285      ICU_CXXFLAGS=`$ICU_CONFIG --cxxflags`
2286      ICU_CXXFLAGS="$ICU_CXXFLAGS -DU_USING_ICU_NAMESPACE=1"
2287    fi
2288  fi
2289])
2290
2291dnl
2292dnl PHP_SETUP_KERBEROS(shared-add [, action-found [, action-not-found]])
2293dnl
2294dnl Common setup macro for kerberos
2295dnl
2296AC_DEFUN([PHP_SETUP_KERBEROS],[
2297  found_kerberos=no
2298  unset KERBEROS_CFLAGS
2299  unset KERBEROS_LIBS
2300
2301  dnl First try to find krb5-config
2302  if test -z "$KRB5_CONFIG"; then
2303    AC_PATH_PROG(KRB5_CONFIG, krb5-config, no, [$PATH:/usr/kerberos/bin:/usr/local/bin])
2304  fi
2305
2306  dnl If krb5-config is found try using it
2307  if test "$PHP_KERBEROS" != "no" && test -x "$KRB5_CONFIG"; then
2308    KERBEROS_LIBS=`$KRB5_CONFIG --libs gssapi`
2309    KERBEROS_CFLAGS=`$KRB5_CONFIG --cflags gssapi`
2310
2311    if test -n "$KERBEROS_LIBS"; then
2312      found_kerberos=yes
2313      PHP_EVAL_LIBLINE($KERBEROS_LIBS, $1)
2314      PHP_EVAL_INCLINE($KERBEROS_CFLAGS)
2315    fi
2316  fi
2317
2318  dnl If still not found use old skool method
2319  if test "$found_kerberos" = "no"; then
2320
2321    if test "$PHP_KERBEROS" = "yes"; then
2322      PHP_KERBEROS="/usr/kerberos /usr/local /usr"
2323    fi
2324
2325    for i in $PHP_KERBEROS; do
2326      if test -f $i/$PHP_LIBDIR/libkrb5.a || test -f $i/$PHP_LIBDIR/libkrb5.$SHLIB_SUFFIX_NAME; then
2327        PHP_KERBEROS_DIR=$i
2328        break
2329      fi
2330    done
2331
2332    if test "$PHP_KERBEROS_DIR"; then
2333      found_kerberos=yes
2334      PHP_ADD_LIBPATH($PHP_KERBEROS_DIR/$PHP_LIBDIR, $1)
2335      PHP_ADD_LIBRARY(gssapi_krb5, 1, $1)
2336      PHP_ADD_LIBRARY(krb5, 1, $1)
2337      PHP_ADD_LIBRARY(k5crypto, 1, $1)
2338      PHP_ADD_LIBRARY(com_err,  1, $1)
2339      PHP_ADD_INCLUDE($PHP_KERBEROS_DIR/include)
2340    fi
2341  fi
2342
2343  if test "$found_kerberos" = "yes"; then
2344ifelse([$2],[],:,[$2])
2345ifelse([$3],[],,[else $3])
2346  fi
2347])
2348
2349dnl
2350dnl PHP_SETUP_OPENSSL(shared-add [, action-found [, action-not-found]])
2351dnl
2352dnl Common setup macro for openssl
2353dnl
2354AC_DEFUN([PHP_SETUP_OPENSSL],[
2355  found_openssl=no
2356  unset OPENSSL_INCDIR
2357  unset OPENSSL_LIBDIR
2358
2359  dnl Empty variable means 'no'
2360  test -z "$PHP_OPENSSL" && PHP_OPENSSL=no
2361  test -z "$PHP_IMAP_SSL" && PHP_IMAP_SSL=no
2362
2363  dnl Fallbacks for different configure options
2364  if test "$PHP_OPENSSL" != "no"; then
2365    PHP_OPENSSL_DIR=$PHP_OPENSSL
2366  elif test "$PHP_IMAP_SSL" != "no"; then
2367    PHP_OPENSSL_DIR=$PHP_IMAP_SSL
2368  fi
2369
2370  dnl First try to find pkg-config
2371  if test -z "$PKG_CONFIG"; then
2372    AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
2373  fi
2374
2375  dnl If pkg-config is found try using it
2376  if test "$PHP_OPENSSL_DIR" = "yes" && test -x "$PKG_CONFIG" && $PKG_CONFIG --exists openssl; then
2377    if $PKG_CONFIG --atleast-version=1.0.1 openssl; then
2378      found_openssl=yes
2379      OPENSSL_LIBS=`$PKG_CONFIG --libs openssl`
2380      OPENSSL_INCS=`$PKG_CONFIG --cflags-only-I openssl`
2381      OPENSSL_INCDIR=`$PKG_CONFIG --variable=includedir openssl`
2382    else
2383      AC_MSG_ERROR([OpenSSL version 1.0.1 or greater required.])
2384    fi
2385
2386    if test -n "$OPENSSL_LIBS"; then
2387      PHP_EVAL_LIBLINE($OPENSSL_LIBS, $1)
2388    fi
2389    if test -n "$OPENSSL_INCS"; then
2390      PHP_EVAL_INCLINE($OPENSSL_INCS)
2391    fi
2392  fi
2393
2394  dnl If pkg-config fails for some reason, revert to the old method
2395  if test "$found_openssl" = "no"; then
2396
2397    if test "$PHP_OPENSSL_DIR" = "yes"; then
2398      PHP_OPENSSL_DIR="/usr/local/ssl /usr/local /usr /usr/local/openssl"
2399    fi
2400
2401    for i in $PHP_OPENSSL_DIR; do
2402      if test -r $i/include/openssl/evp.h; then
2403        OPENSSL_INCDIR=$i/include
2404      fi
2405      if test -r $i/$PHP_LIBDIR/libssl.a -o -r $i/$PHP_LIBDIR/libssl.$SHLIB_SUFFIX_NAME; then
2406        OPENSSL_LIBDIR=$i/$PHP_LIBDIR
2407      fi
2408      test -n "$OPENSSL_INCDIR" && test -n "$OPENSSL_LIBDIR" && break
2409    done
2410
2411    if test -z "$OPENSSL_INCDIR"; then
2412      AC_MSG_ERROR([Cannot find OpenSSL's <evp.h>])
2413    fi
2414
2415    if test -z "$OPENSSL_LIBDIR"; then
2416      AC_MSG_ERROR([Cannot find OpenSSL's libraries])
2417    fi
2418
2419    old_CPPFLAGS=$CPPFLAGS
2420    CPPFLAGS=-I$OPENSSL_INCDIR
2421    AC_MSG_CHECKING([for OpenSSL version])
2422    AC_EGREP_CPP(yes,[
2423#include <openssl/opensslv.h>
2424#if OPENSSL_VERSION_NUMBER >= 0x10001001L
2425  yes
2426#endif
2427    ],[
2428      AC_MSG_RESULT([>= 1.0.1])
2429    ],[
2430      AC_MSG_ERROR([OpenSSL version 1.0.1 or greater required.])
2431    ])
2432    CPPFLAGS=$old_CPPFLAGS
2433
2434    PHP_ADD_INCLUDE($OPENSSL_INCDIR)
2435
2436    PHP_CHECK_LIBRARY(crypto, CRYPTO_free, [
2437      PHP_ADD_LIBRARY(crypto,,$1)
2438    ],[
2439      AC_MSG_ERROR([libcrypto not found!])
2440    ],[
2441      -L$OPENSSL_LIBDIR
2442    ])
2443
2444    old_LIBS=$LIBS
2445    LIBS="$LIBS -lcrypto"
2446    PHP_CHECK_LIBRARY(ssl, SSL_CTX_set_ssl_version, [
2447      found_openssl=yes
2448    ],[
2449      AC_MSG_ERROR([libssl not found!])
2450    ],[
2451      -L$OPENSSL_LIBDIR
2452    ])
2453    LIBS=$old_LIBS
2454    PHP_ADD_LIBRARY(ssl,,$1)
2455    PHP_ADD_LIBRARY(crypto,,$1)
2456
2457    PHP_ADD_LIBPATH($OPENSSL_LIBDIR, $1)
2458  fi
2459
2460  if test "$found_openssl" = "yes"; then
2461  dnl For apache 1.3.x static build
2462  OPENSSL_INCDIR_OPT=-I$OPENSSL_INCDIR
2463  AC_SUBST(OPENSSL_INCDIR_OPT)
2464
2465ifelse([$2],[],:,[$2])
2466ifelse([$3],[],,[else $3])
2467  fi
2468])
2469
2470dnl
2471dnl PHP_SETUP_ICONV(shared-add [, action-found [, action-not-found]])
2472dnl
2473dnl Common setup macro for iconv
2474dnl
2475AC_DEFUN([PHP_SETUP_ICONV], [
2476  found_iconv=no
2477  unset ICONV_DIR
2478
2479  # Create the directories for a VPATH build:
2480  $php_shtool mkdir -p ext/iconv
2481
2482  echo > ext/iconv/php_have_bsd_iconv.h
2483  echo > ext/iconv/php_have_ibm_iconv.h
2484  echo > ext/iconv/php_have_glibc_iconv.h
2485  echo > ext/iconv/php_have_libiconv.h
2486  echo > ext/iconv/php_have_iconv.h
2487  echo > ext/iconv/php_php_iconv_impl.h
2488  echo > ext/iconv/php_iconv_aliased_libiconv.h
2489  echo > ext/iconv/php_php_iconv_h_path.h
2490  echo > ext/iconv/php_iconv_supports_errno.h
2491
2492  dnl
2493  dnl Check libc first if no path is provided in --with-iconv
2494  dnl
2495
2496  if test "$PHP_ICONV" = "yes"; then
2497    dnl Reset LIBS temporarily as it may have already been included
2498    dnl -liconv in.
2499    LIBS_save="$LIBS"
2500    LIBS=
2501    AC_CHECK_FUNC(iconv, [
2502      found_iconv=yes
2503    ],[
2504      AC_CHECK_FUNC(libiconv,[
2505        PHP_DEFINE(HAVE_LIBICONV,1,[ext/iconv])
2506        AC_DEFINE(HAVE_LIBICONV, 1, [ ])
2507        found_iconv=yes
2508      ])
2509    ])
2510    LIBS="$LIBS_save"
2511  fi
2512
2513  dnl
2514  dnl Check external libs for iconv funcs
2515  dnl
2516  if test "$found_iconv" = "no"; then
2517
2518    for i in $PHP_ICONV /usr/local /usr; do
2519      if test -r $i/include/giconv.h; then
2520        AC_DEFINE(HAVE_GICONV_H, 1, [ ])
2521        ICONV_DIR=$i
2522        iconv_lib_name=giconv
2523        break
2524      elif test -r $i/include/iconv.h; then
2525        ICONV_DIR=$i
2526        iconv_lib_name=iconv
2527        break
2528      fi
2529    done
2530
2531    if test -z "$ICONV_DIR"; then
2532      AC_MSG_ERROR([Please specify the install prefix of iconv with --with-iconv=<DIR>])
2533    fi
2534
2535    if test -f $ICONV_DIR/$PHP_LIBDIR/lib$iconv_lib_name.a ||
2536       test -f $ICONV_DIR/$PHP_LIBDIR/lib$iconv_lib_name.$SHLIB_SUFFIX_NAME
2537    then
2538      PHP_CHECK_LIBRARY($iconv_lib_name, libiconv, [
2539        found_iconv=yes
2540        PHP_DEFINE(HAVE_LIBICONV,1,[ext/iconv])
2541        AC_DEFINE(HAVE_LIBICONV,1,[ ])
2542        PHP_DEFINE([ICONV_ALIASED_LIBICONV],1,[ext/iconv])
2543        AC_DEFINE([ICONV_ALIASED_LIBICONV],1,[iconv() is aliased to libiconv() in -liconv])
2544      ], [
2545        PHP_CHECK_LIBRARY($iconv_lib_name, iconv, [
2546          found_iconv=yes
2547        ], [], [
2548          -L$ICONV_DIR/$PHP_LIBDIR
2549        ])
2550      ], [
2551        -L$ICONV_DIR/$PHP_LIBDIR
2552      ])
2553    fi
2554  fi
2555
2556  if test "$found_iconv" = "yes"; then
2557    PHP_DEFINE(HAVE_ICONV,1,[ext/iconv])
2558    AC_DEFINE(HAVE_ICONV,1,[ ])
2559    if test -n "$ICONV_DIR"; then
2560      PHP_ADD_LIBRARY_WITH_PATH($iconv_lib_name, $ICONV_DIR/$PHP_LIBDIR, $1)
2561      PHP_ADD_INCLUDE($ICONV_DIR/include)
2562    fi
2563    $2
2564ifelse([$3],[],,[else $3])
2565  fi
2566])
2567
2568dnl
2569dnl PHP_SETUP_LIBXML(shared-add [, action-found [, action-not-found]])
2570dnl
2571dnl Common setup macro for libxml
2572dnl
2573AC_DEFUN([PHP_SETUP_LIBXML], [
2574  found_libxml=no
2575
2576  dnl First try to find xml2-config
2577  AC_CACHE_CHECK([for xml2-config path], ac_cv_php_xml2_config_path,
2578  [
2579    for i in $PHP_LIBXML_DIR /usr/local /usr; do
2580      if test -x "$i/bin/xml2-config"; then
2581        ac_cv_php_xml2_config_path="$i/bin/xml2-config"
2582        break
2583      fi
2584    done
2585  ])
2586
2587  if test -x "$ac_cv_php_xml2_config_path"; then
2588    XML2_CONFIG="$ac_cv_php_xml2_config_path"
2589    libxml_full_version=`$XML2_CONFIG --version`
2590    ac_IFS=$IFS
2591    IFS="."
2592    set $libxml_full_version
2593    IFS=$ac_IFS
2594    LIBXML_VERSION=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3`
2595    if test "$LIBXML_VERSION" -ge "2006011"; then
2596      found_libxml=yes
2597      LIBXML_LIBS=`$XML2_CONFIG --libs`
2598      LIBXML_INCS=`$XML2_CONFIG --cflags`
2599    else
2600      AC_MSG_ERROR([libxml2 version 2.6.11 or greater required.])
2601    fi
2602  fi
2603
2604  dnl If xml2-config fails, try pkg-config
2605  if test "$found_libxml" = "no"; then
2606    if test -z "$PKG_CONFIG"; then
2607      AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
2608    fi
2609
2610    dnl If pkg-config is found try using it
2611    if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libxml-2.0; then
2612      if $PKG_CONFIG --atleast-version=2.6.11 libxml-2.0; then
2613        found_libxml=yes
2614        LIBXML_LIBS=`$PKG_CONFIG --libs libxml-2.0`
2615        LIBXML_INCS=`$PKG_CONFIG --cflags-only-I libxml-2.0`
2616      else
2617        AC_MSG_ERROR([libxml2 version 2.6.11 or greater required.])
2618      fi
2619    fi
2620  fi
2621
2622  if test "$found_libxml" = "yes"; then
2623    PHP_EVAL_LIBLINE($LIBXML_LIBS, $1)
2624    PHP_EVAL_INCLINE($LIBXML_INCS)
2625
2626    dnl Check that build works with given libs
2627    AC_CACHE_CHECK(whether libxml build works, php_cv_libxml_build_works, [
2628      PHP_TEST_BUILD(xmlInitParser,
2629      [
2630        php_cv_libxml_build_works=yes
2631      ], [
2632        AC_MSG_RESULT(no)
2633        AC_MSG_ERROR([build test failed.  Please check the config.log for details.])
2634      ], [
2635        [$]$1
2636      ])
2637    ])
2638    if test "$php_cv_libxml_build_works" = "yes"; then
2639      AC_DEFINE(HAVE_LIBXML, 1, [ ])
2640    fi
2641    $2
2642ifelse([$3],[],,[else $3])
2643  fi
2644])
2645
2646dnl -------------------------------------------------------------------------
2647dnl Misc. macros
2648dnl -------------------------------------------------------------------------
2649
2650dnl
2651dnl PHP_INSTALL_HEADERS(path [, file ...])
2652dnl
2653dnl PHP header files to be installed
2654dnl
2655AC_DEFUN([PHP_INSTALL_HEADERS],[
2656  ifelse([$2],[],[
2657    for header_file in $1; do
2658      PHP_RUN_ONCE(INSTALLHEADERS, $header_file, [
2659        INSTALL_HEADERS="$INSTALL_HEADERS $header_file"
2660      ])
2661    done
2662  ], [
2663    header_path=$1
2664    for header_file in $2; do
2665      hp_hf="$header_path/$header_file"
2666      PHP_RUN_ONCE(INSTALLHEADERS, $hp_hf, [
2667        INSTALL_HEADERS="$INSTALL_HEADERS $hp_hf"
2668      ])
2669    done
2670  ])
2671])
2672
2673dnl
2674dnl PHP_AP_EXTRACT_VERSION(/path/httpd)
2675dnl
2676dnl This macro is used to get a comparable
2677dnl version for apache1/2.
2678dnl
2679AC_DEFUN([PHP_AP_EXTRACT_VERSION],[
2680  ac_output=`$1 -v 2>&1 | grep version | $SED -e 's/Oracle-HTTP-//'`
2681  ac_IFS=$IFS
2682IFS="- /.
2683"
2684  set $ac_output
2685  IFS=$ac_IFS
2686
2687  APACHE_VERSION=`expr [$]4 \* 1000000 + [$]5 \* 1000 + [$]6`
2688])
2689
2690dnl
2691dnl PHP_DEBUG_MACRO(filename)
2692dnl
2693AC_DEFUN([PHP_DEBUG_MACRO],[
2694  DEBUG_LOG=$1
2695  cat >$1 <<X
2696CONFIGURE:  $CONFIGURE_COMMAND
2697CC:         $CC
2698CFLAGS:     $CFLAGS
2699CPPFLAGS:   $CPPFLAGS
2700CXX:        $CXX
2701CXXFLAGS:   $CXXFLAGS
2702INCLUDES:   $INCLUDES
2703LDFLAGS:    $LDFLAGS
2704LIBS:       $LIBS
2705DLIBS:      $DLIBS
2706SAPI:       $PHP_SAPI
2707PHP_RPATHS: $PHP_RPATHS
2708uname -a:   `uname -a`
2709
2710X
2711    cat >conftest.$ac_ext <<X
2712main()
2713{
2714  exit(0);
2715}
2716X
2717    (eval echo \"$ac_link\"; eval $ac_link && ./conftest) >>$1 2>&1
2718    rm -fr conftest*
2719])
2720
2721dnl
2722dnl PHP_CONFIG_NICE(filename)
2723dnl
2724dnl Generates the config.nice file
2725dnl
2726AC_DEFUN([PHP_CONFIG_NICE],[
2727  AC_REQUIRE([AC_PROG_EGREP])
2728  AC_REQUIRE([LT_AC_PROG_SED])
2729  PHP_SUBST_OLD(EGREP)
2730  PHP_SUBST_OLD(SED)
2731  test -f $1 && mv $1 $1.old
2732  rm -f $1.old
2733  cat >$1<<EOF
2734#! /bin/sh
2735#
2736# Created by configure
2737
2738EOF
2739
2740  clean_configure_args=$ac_configure_args
2741  for var in CFLAGS CXXFLAGS CPPFLAGS LDFLAGS EXTRA_LDFLAGS_PROGRAM LIBS CC CXX; do
2742    eval val=\$$var
2743    if test -n "$val"; then
2744      echo "$var='$val' \\" >> $1
2745      if test `expr "X$ac_configure_args" : ".*${var}.*"` != 0; then
2746        clean_configure_args=$(echo $clean_configure_args | sed -e "s#'$var=$val'##")
2747      fi
2748    fi
2749  done
2750
2751  echo "'[$]0' \\" >> $1
2752  if test `expr " [$]0" : " '.*"` = 0; then
2753    CONFIGURE_COMMAND="$CONFIGURE_COMMAND '[$]0'"
2754  else
2755    CONFIGURE_COMMAND="$CONFIGURE_COMMAND [$]0"
2756  fi
2757  CONFIGURE_ARGS="$clean_configure_args"
2758  while test "X$CONFIGURE_ARGS" != "X";
2759  do
2760   if CURRENT_ARG=`expr "X$CONFIGURE_ARGS" : "X *\('[[^']]*'\)"`
2761   then
2762     CONFIGURE_ARGS=`expr "X$CONFIGURE_ARGS" : "X *'[[^']]*' \(.*\)"`
2763   elif CURRENT_ARG=`expr "X$CONFIGURE_ARGS" : "X *\([[^ ]]*\)"`
2764   then
2765     CONFIGURE_ARGS=`expr "X$CONFIGURE_ARGS" : "X *[[^ ]]* \(.*\)"`
2766     CURRENT_ARG="'$CURRENT_ARG'"
2767   else
2768    break
2769   fi
2770   $as_echo "$CURRENT_ARG \\" >>$1
2771   CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS $CURRENT_ARG"
2772  done
2773  echo '"[$]@"' >> $1
2774  chmod +x $1
2775  CONFIGURE_COMMAND="$CONFIGURE_COMMAND $CONFIGURE_OPTIONS"
2776  PHP_SUBST_OLD(CONFIGURE_COMMAND)
2777  PHP_SUBST_OLD(CONFIGURE_OPTIONS)
2778])
2779
2780dnl
2781dnl PHP_CHECK_CONFIGURE_OPTIONS
2782dnl
2783AC_DEFUN([PHP_CHECK_CONFIGURE_OPTIONS],[
2784  for arg in $ac_configure_args; do
2785    case $arg in
2786      --with-*[)]
2787        arg_name="`echo [$]arg | $SED -e 's/--with-/with-/g' -e 's/=.*//g'`"
2788        ;;
2789      --without-*[)]
2790        arg_name="`echo [$]arg | $SED -e 's/--without-/with-/g' -e 's/=.*//g'`"
2791        ;;
2792      --enable-*[)]
2793        arg_name="`echo [$]arg | $SED -e 's/--enable-/enable-/g' -e 's/=.*//g'`"
2794        ;;
2795      --disable-*[)]
2796        arg_name="`echo [$]arg | $SED -e 's/--disable-/enable-/g' -e 's/=.*//g'`"
2797        ;;
2798      *[)]
2799        continue
2800        ;;
2801    esac
2802    case $arg_name in
2803      # Allow --disable-all / --enable-all
2804      enable-all[)];;
2805
2806      # Allow certain libtool options
2807      enable-libtool-lock | with-pic | with-tags | enable-shared | enable-static | enable-fast-install | with-gnu-ld[)];;
2808
2809      # Allow certain TSRM options
2810      with-tsrm-pth | with-tsrm-st | with-tsrm-pthreads [)];;
2811
2812      # Allow certain Zend options
2813      with-zend-vm | enable-maintainer-zts | enable-inline-optimization[)];;
2814
2815      # All the rest must be set using the PHP_ARG_* macros
2816      # PHP_ARG_* macros set php_enable_<arg_name> or php_with_<arg_name>
2817      *[)]
2818        # Options that exist before PHP 6
2819        if test "$PHP_MAJOR_VERSION" -lt "6"; then
2820          case $arg_name in
2821            enable-zend-multibyte[)] continue;;
2822          esac
2823        fi
2824
2825        is_arg_set=php_[]`echo [$]arg_name | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-' 'abcdefghijklmnopqrstuvwxyz_'`
2826        if eval test "x\$$is_arg_set" = "x"; then
2827          PHP_UNKNOWN_CONFIGURE_OPTIONS="$PHP_UNKNOWN_CONFIGURE_OPTIONS
2828[$]arg"
2829        fi
2830        ;;
2831    esac
2832  done
2833])
2834
2835dnl
2836dnl PHP_CHECK_PDO_INCLUDES([found [, not-found]])
2837dnl
2838AC_DEFUN([PHP_CHECK_PDO_INCLUDES],[
2839  AC_CACHE_CHECK([for PDO includes], pdo_cv_inc_path, [
2840    AC_MSG_CHECKING([for PDO includes])
2841    if test -f $abs_srcdir/include/php/ext/pdo/php_pdo_driver.h; then
2842      pdo_cv_inc_path=$abs_srcdir/ext
2843    elif test -f $abs_srcdir/ext/pdo/php_pdo_driver.h; then
2844      pdo_cv_inc_path=$abs_srcdir/ext
2845    elif test -f $phpincludedir/ext/pdo/php_pdo_driver.h; then
2846      pdo_cv_inc_path=$phpincludedir/ext
2847    fi
2848  ])
2849  if test -n "$pdo_cv_inc_path"; then
2850ifelse([$1],[],:,[$1])
2851  else
2852ifelse([$2],[],[AC_MSG_ERROR([Cannot find php_pdo_driver.h.])],[$2])
2853  fi
2854])
2855
2856dnl
2857dnl PHP_DETECT_ICC
2858dnl Detect Intel C++ Compiler and unset $GCC if ICC found
2859AC_DEFUN([PHP_DETECT_ICC],
2860[
2861  ICC="no"
2862  AC_MSG_CHECKING([for icc])
2863  AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
2864    ICC="no"
2865    AC_MSG_RESULT([no]),
2866    ICC="yes"
2867    GCC="no"
2868    AC_MSG_RESULT([yes])
2869  )
2870])
2871
2872dnl PHP_DETECT_SUNCC
2873dnl Detect if the systems default compiler is suncc.
2874dnl We also set some useful CFLAGS if the user didn't set any
2875AC_DEFUN([PHP_DETECT_SUNCC],[
2876  SUNCC="no"
2877  AC_MSG_CHECKING([for suncc])
2878  AC_EGREP_CPP([^__SUNPRO_C], [__SUNPRO_C],
2879    SUNCC="no"
2880    AC_MSG_RESULT([no]),
2881    SUNCC="yes"
2882    GCC="no"
2883    test -n "$auto_cflags" && CFLAGS="-O -xs -xstrconst -zlazyload"
2884    GCC=""
2885    AC_MSG_RESULT([yes])
2886  )
2887])
2888
2889dnl
2890dnl PHP_CRYPT_R_STYLE
2891dnl detect the style of crypt_r() is any is available
2892dnl see APR_CHECK_CRYPT_R_STYLE() for original version
2893dnl
2894AC_DEFUN([PHP_CRYPT_R_STYLE],
2895[
2896  AC_CACHE_CHECK([which data struct is used by crypt_r], php_cv_crypt_r_style,[
2897    php_cv_crypt_r_style=none
2898    AC_TRY_COMPILE([
2899#define _REENTRANT 1
2900#include <crypt.h>
2901],[
2902CRYPTD buffer;
2903crypt_r("passwd", "hash", &buffer);
2904],
2905php_cv_crypt_r_style=cryptd)
2906
2907    if test "$php_cv_crypt_r_style" = "none"; then
2908      AC_TRY_COMPILE([
2909#define _REENTRANT 1
2910#include <crypt.h>
2911],[
2912struct crypt_data buffer;
2913crypt_r("passwd", "hash", &buffer);
2914],
2915php_cv_crypt_r_style=struct_crypt_data)
2916    fi
2917
2918    if test "$php_cv_crypt_r_style" = "none"; then
2919      AC_TRY_COMPILE([
2920#define _REENTRANT 1
2921#define _GNU_SOURCE
2922#include <crypt.h>
2923],[
2924struct crypt_data buffer;
2925crypt_r("passwd", "hash", &buffer);
2926],
2927php_cv_crypt_r_style=struct_crypt_data_gnu_source)
2928    fi
2929    ])
2930
2931  if test "$php_cv_crypt_r_style" = "cryptd"; then
2932    AC_DEFINE(CRYPT_R_CRYPTD, 1, [Define if crypt_r has uses CRYPTD])
2933  fi
2934  if test "$php_cv_crypt_r_style" = "struct_crypt_data" -o "$php_cv_crypt_r_style" = "struct_crypt_data_gnu_source"; then
2935    AC_DEFINE(CRYPT_R_STRUCT_CRYPT_DATA, 1, [Define if crypt_r uses struct crypt_data])
2936  fi
2937  if test "$php_cv_crypt_r_style" = "struct_crypt_data_gnu_source"; then
2938    AC_DEFINE(CRYPT_R_GNU_SOURCE, 1, [Define if struct crypt_data requires _GNU_SOURCE])
2939  fi
2940  if test "$php_cv_crypt_r_style" = "none"; then
2941    AC_MSG_ERROR([Unable to detect data struct used by crypt_r])
2942  fi
2943])
2944
2945dnl
2946dnl PHP_TEST_WRITE_STDOUT
2947dnl
2948AC_DEFUN([PHP_TEST_WRITE_STDOUT],[
2949  AC_CACHE_CHECK(whether writing to stdout works,ac_cv_write_stdout,[
2950    AC_TRY_RUN([
2951#ifdef HAVE_UNISTD_H
2952#include <unistd.h>
2953#endif
2954
2955#define TEXT "This is the test message -- "
2956
2957main()
2958{
2959  int n;
2960
2961  n = write(1, TEXT, sizeof(TEXT)-1);
2962  return (!(n == sizeof(TEXT)-1));
2963}
2964    ],[
2965      ac_cv_write_stdout=yes
2966    ],[
2967      ac_cv_write_stdout=no
2968    ],[
2969      ac_cv_write_stdout=no
2970    ])
2971  ])
2972  if test "$ac_cv_write_stdout" = "yes"; then
2973    AC_DEFINE(PHP_WRITE_STDOUT, 1, [whether write(2) works])
2974  fi
2975])
2976
2977dnl
2978dnl PHP_INIT_DTRACE(providerdesc, header-file, sources [, module])
2979dnl
2980AC_DEFUN([PHP_INIT_DTRACE],[
2981dnl Set paths properly when called from extension
2982  case "$4" in
2983    ""[)] ac_srcdir="$abs_srcdir/"; unset ac_bdir;;
2984    /*[)] ac_srcdir=`echo "$4"|cut -c 2-`"/"; ac_bdir=$ac_srcdir;;
2985    *[)] ac_srcdir="$abs_srcdir/$1/"; ac_bdir="$4/";;
2986  esac
2987
2988dnl providerdesc
2989  ac_provsrc=$1
2990  old_IFS=[$]IFS
2991  IFS=.
2992  set $ac_provsrc
2993  ac_provobj=[$]1
2994  IFS=$old_IFS
2995
2996dnl header-file
2997  ac_hdrobj=$2
2998
2999dnl Add providerdesc.o or .lo into global objects when needed
3000  case $host_alias in
3001  *freebsd*)
3002    PHP_GLOBAL_OBJS="[$]PHP_GLOBAL_OBJS [$]ac_bdir[$]ac_provsrc.o"
3003    PHP_LDFLAGS="$PHP_LDFLAGS -lelf"
3004    ;;
3005  *solaris*)
3006    PHP_GLOBAL_OBJS="[$]PHP_GLOBAL_OBJS [$]ac_bdir[$]ac_provsrc.lo"
3007    ;;
3008  *linux*)
3009    PHP_GLOBAL_OBJS="[$]PHP_GLOBAL_OBJS [$]ac_bdir[$]ac_provsrc.lo"
3010    ;;
3011  esac
3012
3013dnl DTrace objects
3014  old_IFS=[$]IFS
3015  for ac_src in $3; do
3016    IFS=.
3017    set $ac_src
3018    ac_obj=[$]1
3019    IFS=$old_IFS
3020
3021    PHP_DTRACE_OBJS="[$]PHP_DTRACE_OBJS [$]ac_bdir[$]ac_obj.lo"
3022  done;
3023
3024  case [$]php_sapi_module in
3025  shared[)]
3026    for ac_lo in $PHP_DTRACE_OBJS; do
3027      dtrace_objs="[$]dtrace_objs `echo $ac_lo | $SED -e 's,\.lo$,.o,' -e 's#\(.*\)\/#\1\/.libs\/#'`"
3028    done;
3029    ;;
3030  *[)]
3031    dtrace_objs='$(PHP_DTRACE_OBJS:.lo=.o)'
3032    ;;
3033  esac
3034
3035dnl Generate Makefile.objects entries
3036dnl The empty $ac_provsrc command stops an implicit circular dependency
3037dnl in GNU Make which causes the .d file to be overwritten (Bug 61268)
3038  cat>>Makefile.objects<<EOF
3039
3040$abs_srcdir/$ac_provsrc:;
3041
3042$ac_bdir[$]ac_hdrobj: $abs_srcdir/$ac_provsrc
3043	CFLAGS="\$(CFLAGS_CLEAN)" dtrace -h -C -s $ac_srcdir[$]ac_provsrc -o \$[]@.bak && \$(SED) -e 's,PHP_,DTRACE_,g' \$[]@.bak > \$[]@
3044
3045\$(PHP_DTRACE_OBJS): $ac_bdir[$]ac_hdrobj
3046
3047EOF
3048
3049  case $host_alias in
3050  *solaris*|*linux*)
3051    dtrace_prov_name="`echo $ac_provsrc | $SED -e 's#\(.*\)\/##'`.o"
3052    dtrace_lib_dir="`echo $ac_bdir[$]ac_provsrc | $SED -e 's#\(.*\)/[^/]*#\1#'`/.libs"
3053    dtrace_d_obj="`echo $ac_bdir[$]ac_provsrc | $SED -e 's#\(.*\)/\([^/]*\)#\1/.libs/\2#'`.o"
3054    dtrace_nolib_objs='$(PHP_DTRACE_OBJS:.lo=.o)'
3055    for ac_lo in $PHP_DTRACE_OBJS; do
3056      dtrace_lib_objs="[$]dtrace_lib_objs `echo $ac_lo | $SED -e 's,\.lo$,.o,' -e 's#\(.*\)\/#\1\/.libs\/#'`"
3057    done;
3058dnl Always attempt to create both PIC and non-PIC DTrace objects (Bug 63692)
3059    cat>>Makefile.objects<<EOF
3060$ac_bdir[$]ac_provsrc.lo: \$(PHP_DTRACE_OBJS)
3061	echo "[#] Generated by Makefile for libtool" > \$[]@
3062	@test -d "$dtrace_lib_dir" || mkdir $dtrace_lib_dir
3063	if CFLAGS="\$(CFLAGS_CLEAN)" dtrace -G -o $dtrace_d_obj -s $abs_srcdir/$ac_provsrc $dtrace_lib_objs 2> /dev/null && test -f "$dtrace_d_obj"; then [\\]
3064	  echo "pic_object=['].libs/$dtrace_prov_name[']" >> \$[]@ [;\\]
3065	else [\\]
3066	  echo "pic_object='none'" >> \$[]@ [;\\]
3067	fi
3068	if CFLAGS="\$(CFLAGS_CLEAN)" dtrace -G -o $ac_bdir[$]ac_provsrc.o -s $abs_srcdir/$ac_provsrc $dtrace_nolib_objs 2> /dev/null && test -f "$ac_bdir[$]ac_provsrc.o"; then [\\]
3069	  echo "non_pic_object=[']$dtrace_prov_name[']" >> \$[]@ [;\\]
3070	else [\\]
3071	  echo "non_pic_object='none'" >> \$[]@ [;\\]
3072	fi
3073
3074EOF
3075
3076    ;;
3077  *)
3078cat>>Makefile.objects<<EOF
3079$ac_bdir[$]ac_provsrc.o: \$(PHP_DTRACE_OBJS)
3080	CFLAGS="\$(CFLAGS_CLEAN)" dtrace -G -o \$[]@ -s $abs_srcdir/$ac_provsrc $dtrace_objs
3081
3082EOF
3083    ;;
3084  esac
3085])
3086
3087dnl
3088dnl PHP_CHECK_STDINT_TYPES
3089dnl
3090AC_DEFUN([PHP_CHECK_STDINT_TYPES], [
3091  AC_CHECK_SIZEOF([short], 2)
3092  AC_CHECK_SIZEOF([int], 4)
3093  AC_CHECK_SIZEOF([long], 4)
3094  AC_CHECK_SIZEOF([long long], 8)
3095  AC_CHECK_TYPES([int8, int16, int32, int64, int8_t, int16_t, int32_t, int64_t, uint8, uint16, uint32, uint64, uint8_t, uint16_t, uint32_t, uint64_t, u_int8_t, u_int16_t, u_int32_t, u_int64_t], [], [], [
3096#if HAVE_STDINT_H
3097# include <stdint.h>
3098#endif
3099#if HAVE_SYS_TYPES_H
3100# include <sys/types.h>
3101#endif
3102  ])
3103  AC_DEFINE([PHP_HAVE_STDINT_TYPES], [1], [Checked for stdint types])
3104])
3105
3106dnl PHP_CHECK_BUILTIN_EXPECT
3107AC_DEFUN([PHP_CHECK_BUILTIN_EXPECT], [
3108  AC_MSG_CHECKING([for __builtin_expect])
3109
3110  AC_TRY_LINK(, [
3111    return __builtin_expect(1,1) ? 1 : 0;
3112  ], [
3113    have_builtin_expect=1
3114    AC_MSG_RESULT([yes])
3115  ], [
3116    have_builtin_expect=0
3117    AC_MSG_RESULT([no])
3118  ])
3119
3120  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_EXPECT], [$have_builtin_expect], [Whether the compiler supports __builtin_expect])
3121
3122])
3123
3124dnl PHP_CHECK_BUILTIN_CLZ
3125AC_DEFUN([PHP_CHECK_BUILTIN_CLZ], [
3126  AC_MSG_CHECKING([for __builtin_clz])
3127
3128  AC_TRY_LINK(, [
3129    return __builtin_clz(1) ? 1 : 0;
3130  ], [
3131    have_builtin_clz=1
3132    AC_MSG_RESULT([yes])
3133  ], [
3134    have_builtin_clz=0
3135    AC_MSG_RESULT([no])
3136  ])
3137
3138  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_CLZ], [$have_builtin_clz], [Whether the compiler supports __builtin_clz])
3139
3140])
3141
3142dnl PHP_CHECK_BUILTIN_CTZL
3143AC_DEFUN([PHP_CHECK_BUILTIN_CTZL], [
3144  AC_MSG_CHECKING([for __builtin_ctzl])
3145
3146  AC_TRY_LINK(, [
3147    return __builtin_ctzl(2L) ? 1 : 0;
3148  ], [
3149    have_builtin_ctzl=1
3150    AC_MSG_RESULT([yes])
3151  ], [
3152    have_builtin_ctzl=0
3153    AC_MSG_RESULT([no])
3154  ])
3155
3156  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_CTZL], [$have_builtin_ctzl], [Whether the compiler supports __builtin_ctzl])
3157
3158])
3159
3160dnl PHP_CHECK_BUILTIN_CTZLL
3161AC_DEFUN([PHP_CHECK_BUILTIN_CTZLL], [
3162  AC_MSG_CHECKING([for __builtin_ctzll])
3163
3164  AC_TRY_LINK(, [
3165    return __builtin_ctzll(2LL) ? 1 : 0;
3166  ], [
3167    have_builtin_ctzll=1
3168    AC_MSG_RESULT([yes])
3169  ], [
3170    have_builtin_ctzll=0
3171    AC_MSG_RESULT([no])
3172  ])
3173
3174  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_CTZLL], [$have_builtin_ctzll], [Whether the compiler supports __builtin_ctzll])
3175
3176])
3177
3178dnl Load the AX_CHECK_COMPILE_FLAG macro from the autoconf archive.
3179m4_include([build/ax_check_compile_flag.m4])
3180