Busybox: Upgrade to 1.21.1 (stable). lsof active.
[tomato.git] / release / src / router / php / acinclude.m4
blobadb9599ce4887b0a56852a91f255bf65e703fae5
1 dnl
2 dnl $Id$
3 dnl
4 dnl This file contains local autoconf functions.
5 dnl
7 dnl -------------------------------------------------------------------------
8 dnl Output stylize macros for configure (help/runtime)
9 dnl -------------------------------------------------------------------------
11 dnl
12 dnl PHP_HELP_SEPARATOR(title)
13 dnl
14 dnl Adds separator title into the configure --help display.
15 dnl 
16 AC_DEFUN([PHP_HELP_SEPARATOR],[
17 AC_ARG_ENABLE([],[
19 ],[])
22 dnl
23 dnl PHP_CONFIGURE_PART(title)
24 dnl
25 dnl Adds separator title configure output (idea borrowed from mm)
26 dnl
27 AC_DEFUN([PHP_CONFIGURE_PART],[
28   AC_MSG_RESULT()
29   AC_MSG_RESULT([${T_MD}$1${T_ME}])
32 dnl -------------------------------------------------------------------------
33 dnl Build system helper macros
34 dnl -------------------------------------------------------------------------
36 dnl
37 dnl PHP_DEF_HAVE(what)
38 dnl
39 dnl Generates 'AC_DEFINE(HAVE_WHAT, 1, [ ])'
40 dnl
41 AC_DEFUN([PHP_DEF_HAVE],[AC_DEFINE([HAVE_]translit($1,a-z_.-,A-Z___), 1, [ ])])
43 dnl
44 dnl PHP_RUN_ONCE(namespace, variable, code)
45 dnl
46 dnl execute code, if variable is not set in namespace
47 dnl
48 AC_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
59 dnl
60 dnl PHP_EXPAND_PATH(path, variable)
61 dnl
62 dnl expands path to an absolute path and assigns it to variable
63 dnl
64 AC_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
76 dnl
77 dnl PHP_DEFINE(WHAT [, value[, directory]])
78 dnl
79 dnl Creates builddir/include/what.h and in there #define WHAT value
80 dnl
81 AC_DEFUN([PHP_DEFINE],[
82   [echo "#define ]$1[]ifelse([$2],,[ 1],[ $2])[" > ]ifelse([$3],,[include],[$3])[/php_]translit($1,A-Z,a-z)[.h]
85 dnl
86 dnl PHP_SUBST(varname)
87 dnl
88 dnl Adds variable with it's value into Makefile, e.g.:
89 dnl CC = gcc
90 dnl
91 AC_DEFUN([PHP_SUBST],[
92   PHP_VAR_SUBST="$PHP_VAR_SUBST $1"
95 dnl
96 dnl PHP_SUBST_OLD(varname)
97 dnl
98 dnl Same as PHP_SUBST() but also substitutes all @VARNAME@
99 dnl instances in every file passed to AC_OUTPUT()
101 AC_DEFUN([PHP_SUBST_OLD],[
102   PHP_SUBST($1)
103   AC_SUBST($1)
107 dnl PHP_OUTPUT(file)
109 dnl Adds "file" to the list of files generated by AC_OUTPUT
110 dnl This macro can be used several times.
112 AC_DEFUN([PHP_OUTPUT],[
113   PHP_OUTPUT_FILES="$PHP_OUTPUT_FILES $1"
117 dnl -------------------------------------------------------------------------
118 dnl Build system base macros
119 dnl -------------------------------------------------------------------------
122 dnl PHP_CANONICAL_HOST_TARGET
124 AC_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
137 dnl PHP_INIT_BUILD_SYSTEM
139 AC_DEFUN([PHP_INIT_BUILD_SYSTEM],[
140 AC_REQUIRE([PHP_CANONICAL_HOST_TARGET])dnl
141 test -d include || $php_shtool mkdir include
142 > Makefile.objects
143 > Makefile.fragments
144 dnl We need to play tricks here to avoid matching the grep line itself
145 pattern=define
146 $EGREP $pattern'.*include/php' $srcdir/configure|$SED 's/.*>//'|xargs touch 2>/dev/null
150 dnl PHP_GEN_GLOBAL_MAKEFILE
151 dnl 
152 dnl Generates the global makefile.
154 AC_DEFUN([PHP_GEN_GLOBAL_MAKEFILE],[
155   cat >Makefile <<EOF
156 srcdir = $abs_srcdir
157 builddir = $abs_builddir
158 top_srcdir = $abs_srcdir
159 top_builddir = $abs_builddir
161   for i in $PHP_VAR_SUBST; do
162     eval echo "$i = \$$i" >> Makefile
163   done
165   cat $abs_srcdir/Makefile.global Makefile.fragments Makefile.objects >> Makefile
169 dnl PHP_ADD_MAKEFILE_FRAGMENT([srcfile [, ext_srcdir [, ext_builddir]]])
171 dnl Processes a file called Makefile.frag in the source directory
172 dnl of the most recently added extension. $(srcdir) and $(builddir)
173 dnl are substituted with the proper paths. Can be used to supply
174 dnl custom rules and/or additional targets.
176 AC_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
184 dnl PHP_ADD_SOURCES(source-path, sources [, special-flags [, type]])
186 dnl Adds sources which are located relative to source-path to the 
187 dnl array of type type.  Sources are processed with optional 
188 dnl special-flags which are passed to the compiler.  Sources
189 dnl can be either written in C or C++ (filenames shall end in .c 
190 dnl or .cpp, respectively).
192 dnl Note: If source-path begins with a "/", the "/" is removed and
193 dnl the path is interpreted relative to the top build-directory.
195 dnl which array to append to?
196 AC_DEFUN([PHP_ADD_SOURCES],[
197   PHP_ADD_SOURCES_X($1, $2, $3, ifelse($4,sapi,PHP_SAPI_OBJS,PHP_GLOBAL_OBJS))
201 dnl _PHP_ASSIGN_BUILD_VARS(type)
202 dnl internal, don't use
203 AC_DEFUN([_PHP_ASSIGN_BUILD_VARS],[
204 ifelse($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
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
223 dnl PHP_ADD_SOURCES_X(source-path, sources[, special-flags[, target-var[, shared[, special-post-flags]]]])
225 dnl Additional to PHP_ADD_SOURCES (see above), this lets you set the
226 dnl name of the array target-var directly, as well as whether
227 dnl shared objects will be built from the sources.
229 dnl Should not be used directly.
230 dnl 
231 AC_DEFUN([PHP_ADD_SOURCES_X],[
232 dnl relative to source- or build-directory?
233 dnl 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   
240 dnl how to build .. shared or static?
241   ifelse($5,yes,_PHP_ASSIGN_BUILD_VARS(shared),_PHP_ASSIGN_BUILD_VARS(php))
243 dnl iterate over the sources
244   old_IFS=[$]IFS
245   for ac_src in $2; do
246   
247 dnl remove the suffix
248       IFS=.
249       set $ac_src
250       ac_obj=[$]1
251       IFS=$old_IFS
252       
253 dnl append to the array which has been dynamically chosen at m4 time
254       $4="[$]$4 [$]ac_bdir[$]ac_obj.lo"
256 dnl 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
264 dnl 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
269   done
272 dnl -------------------------------------------------------------------------
273 dnl Compiler characteristics checks
274 dnl -------------------------------------------------------------------------
277 dnl PHP_TARGET_RDYNAMIC
279 dnl Checks whether -rdynamic is supported by the compiler.  This
280 dnl is necessary for some targets to populate the global symbol
281 dnl table.  Otherwise, dynamic modules would not be able to resolve
282 dnl PHP-related symbols.
284 dnl If successful, adds -rdynamic to PHP_LDFLAGS.
286 AC_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
297 dnl PHP_RUNPATH_SWITCH
299 dnl Checks for -R, etc. switch
301 AC_DEFUN([PHP_RUNPATH_SWITCH],[
302 AC_MSG_CHECKING([if compiler supports -R])
303 AC_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])
308 AC_MSG_RESULT([$php_cv_cc_dashr])
309 if test $php_cv_cc_dashr = "yes"; then
310   ld_runpath_switch=-R
311 else
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
326 if test "$PHP_RPATH" = "no"; then
327   ld_runpath_switch=
332 dnl PHP_CHECK_GCC_ARG(arg, action-if-found, action-if-not-found)
334 AC_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
356 dnl PHP_LIBGCC_LIBPATH(gcc)
358 dnl Stores the location of libgcc in libgcc_libpath
360 AC_DEFUN([PHP_LIBGCC_LIBPATH],[
361   changequote({,})
362   libgcc_libpath=`$1 --print-libgcc-file-name|$SED 's%/*[^/][^/]*$%%'`
363   changequote([,])
366 dnl -------------------------------------------------------------------------
367 dnl Macros to modify LIBS, INCLUDES, etc. variables 
368 dnl -------------------------------------------------------------------------
371 dnl PHP_REMOVE_USR_LIB(NAME)
373 dnl Removes all -L/usr/$PHP_LIBDIR entries from variable NAME
375 AC_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
387 dnl PHP_EVAL_LIBLINE(libline, SHARED-LIBADD)
389 dnl Use this macro, if you need to add libraries and or library search
390 dnl paths to the PHP build system which are only given in compiler
391 dnl notation.
393 AC_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
416 dnl PHP_EVAL_INCLINE(headerline)
418 dnl Use this macro, if you need to add header search paths to the PHP
419 dnl build system which are only given in compiler notation.
421 AC_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
432 dnl internal, don't use
433 AC_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
442 dnl PHP_ADD_LIBPATH(path [, SHARED-LIBADD])
444 dnl Adds a path to linkpath/runpath (LDFLAGS)
446 AC_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
463 dnl PHP_UTILIZE_RPATHS()
465 dnl builds RPATHS/LDFLAGS from PHP_RPATHS
467 AC_DEFUN([PHP_UTILIZE_RPATHS],[
468   OLD_RPATHS=$PHP_RPATHS
469   unset PHP_RPATHS
471   for i in $OLD_RPATHS; do
472 dnl Can be passed to native cc/libtool
473     PHP_LDFLAGS="$PHP_LDFLAGS -L$i"
474 dnl Libtool-specific
475     PHP_RPATHS="$PHP_RPATHS -R $i"
476 dnl cc-specific
477     NATIVE_RPATHS="$NATIVE_RPATHS $ld_runpath_switch$i"
478   done
480   if test "$PHP_RPATH" = "no"; then
481     unset PHP_RPATHS
482     unset NATIVE_RPATHS
483   fi
487 dnl PHP_ADD_INCLUDE(path [,before])
489 dnl add an include path. 
490 dnl if before is 1, add in the beginning of INCLUDES.
492 AC_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
505 dnl internal, don't use
506 AC_DEFUN([_PHP_X_ADD_LIBRARY],[dnl
507   ifelse([$2],,$3="-l$1 [$]$3", $3="[$]$3 -l$1") dnl
508 ])dnl
510 dnl internal, don't use
511 AC_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
527 dnl PHP_ADD_LIBRARY(library[, append[, shared-libadd]])
529 dnl add a library to the link line
531 AC_DEFUN([PHP_ADD_LIBRARY],[
532   _PHP_ADD_LIBRARY_SKELETON([$1],[$2],[$3],[PHP_ADD_LIBRARY],[LIBS])
536 dnl PHP_ADD_LIBRARY_DEFER(library[, append[, shared-libadd]])
538 dnl add a library to the link line (deferred, not used during configure)
540 AC_DEFUN([PHP_ADD_LIBRARY_DEFER],[
541   _PHP_ADD_LIBRARY_SKELETON([$1],[$2],[$3],[PHP_ADD_LIBRARY_DEFER],[DLIBS])
545 dnl PHP_ADD_LIBRARY_WITH_PATH(library, path[, shared-libadd])
547 dnl add a library to the link line and path to linkpath/runpath.
548 dnl if shared-libadd is not empty and $ext_shared is yes,
549 dnl shared-libadd will be assigned the library information
551 AC_DEFUN([PHP_ADD_LIBRARY_WITH_PATH],[
552 ifelse($3,,[
553   if test -n "$2"; then
554     PHP_ADD_LIBPATH($2)
555   fi
556   PHP_ADD_LIBRARY($1)
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
570 dnl PHP_ADD_LIBRARY_DEFER_WITH_PATH(library, path[, shared-libadd])
572 dnl add a library to the link line (deferred)
573 dnl and path to linkpath/runpath (not deferred)
574 dnl if shared-libadd is not empty and $ext_shared is yes,
575 dnl shared-libadd will be assigned the library information
577 AC_DEFUN([PHP_ADD_LIBRARY_DEFER_WITH_PATH],[
578 ifelse($3,,[
579   if test -n "$2"; then
580     PHP_ADD_LIBPATH($2)
581   fi
582   PHP_ADD_LIBRARY_DEFER($1)
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
596 dnl PHP_ADD_FRAMEWORK(framework [,before])
598 dnl add a (Darwin / Mac OS X) framework to the link
599 dnl line. if before is 1, the framework is added
600 dnl to the beginning of the line.
602 AC_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   ])
613 dnl PHP_ADD_FRAMEWORKPATH(path [,before])
615 dnl add a (Darwin / Mac OS X) framework path to the link
616 dnl and include lines. default paths include (but are
617 dnl not limited to) /Local/Library/Frameworks and
618 dnl /System/Library/Frameworks, so these don't need
619 dnl to be specifically added. if before is 1, the
620 dnl framework path is added to the beginning of the
621 dnl relevant lines.
623 AC_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   ])
635 dnl PHP_ADD_FRAMEWORK_WITH_PATH(framework, path)
637 dnl Adds a (Darwin / Mac OS X) framework path and the
638 dnl framework itself to the link and include lines.
640 AC_DEFUN([PHP_ADD_FRAMEWORK_WITH_PATH], [
641   PHP_ADD_FRAMEWORKPATH($2)
642   PHP_ADD_FRAMEWORK($1)
646 dnl PHP_SET_LIBTOOL_VARIABLE(var)
648 dnl Set libtool variable
650 AC_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
658 dnl -------------------------------------------------------------------------
659 dnl Wrapper macros for AC_ARG_WITH / AC_ARG_ENABLE
660 dnl -------------------------------------------------------------------------
662 dnl PHP_ARG_ANALYZE_EX
663 dnl internal
664 AC_DEFUN([PHP_ARG_ANALYZE_EX],[
665 ext_output="yes, shared"
666 ext_shared=yes
667 case [$]$1 in
668 shared,*[)]
669   $1=`echo "[$]$1"|$SED 's/^shared,//'`
670   ;;
671 shared[)]
672   $1=yes
673   ;;
674 no[)]
675   ext_output=no
676   ext_shared=no
677   ;;
678 *[)]
679   ext_output=yes
680   ext_shared=no
681   ;;
682 esac
684 PHP_ALWAYS_SHARED([$1])
687 dnl PHP_ARG_ANALYZE
688 dnl internal
689 AC_DEFUN([PHP_ARG_ANALYZE],[
690 ifelse([$3],yes,[PHP_ARG_ANALYZE_EX([$1])],[ext_output=ifelse([$]$1,,no,[$]$1)])
691 ifelse([$2],,,[AC_MSG_RESULT([$ext_output])])
695 dnl PHP_ARG_WITH(arg-name, check message, help text[, default-val[, extension-or-not]])
696 dnl Sets PHP_ARG_NAME either to the user value or to the default value.
697 dnl default-val defaults to no.  This will also set the variable ext_shared,
698 dnl and will overwrite any previous variable of that name.
699 dnl If extension-or-not is yes (default), then do the ENABLE_ALL check and run
700 dnl the PHP_ARG_ANALYZE_EX.
702 AC_DEFUN([PHP_ARG_WITH],[
703 php_with_[]translit($1,A-Z0-9-,a-z0-9_)=ifelse($4,,no,$4)
704 PHP_REAL_ARG_WITH([$1],[$2],[$3],[$4],PHP_[]translit($1,a-z0-9-,A-Z0-9_),[ifelse($5,,yes,$5)])
707 dnl PHP_REAL_ARG_WITH
708 dnl internal
709 AC_DEFUN([PHP_REAL_ARG_WITH],[
710 ifelse([$2],,,[AC_MSG_CHECKING([$2])])
711 AC_ARG_WITH($1,[$3],$5=[$]withval,
713   $5=ifelse($4,,no,$4)
714   ifelse($6,yes,[test "$PHP_ENABLE_ALL" && $5=$PHP_ENABLE_ALL])
716 PHP_ARG_ANALYZE($5,[$2],$6)
720 dnl PHP_ARG_ENABLE(arg-name, check message, help text[, default-val[, extension-or-not]])
721 dnl Sets PHP_ARG_NAME either to the user value or to the default value.
722 dnl default-val defaults to no.  This will also set the variable ext_shared,
723 dnl and will overwrite any previous variable of that name.
724 dnl If extension-or-not is yes (default), then do the ENABLE_ALL check and run
725 dnl the PHP_ARG_ANALYZE_EX.
727 AC_DEFUN([PHP_ARG_ENABLE],[
728 php_enable_[]translit($1,A-Z0-9-,a-z0-9_)=ifelse($4,,no,$4)
729 PHP_REAL_ARG_ENABLE([$1],[$2],[$3],[$4],PHP_[]translit($1,a-z0-9-,A-Z0-9_),[ifelse($5,,yes,$5)])
732 dnl PHP_REAL_ARG_ENABLE
733 dnl internal
734 AC_DEFUN([PHP_REAL_ARG_ENABLE],[
735 ifelse([$2],,,[AC_MSG_CHECKING([$2])])
736 AC_ARG_ENABLE($1,[$3],$5=[$]enableval,
738   $5=ifelse($4,,no,$4)
739   ifelse($6,yes,[test "$PHP_ENABLE_ALL" && $5=$PHP_ENABLE_ALL])
741 PHP_ARG_ANALYZE($5,[$2],$6)
744 dnl -------------------------------------------------------------------------
745 dnl Build macros
746 dnl -------------------------------------------------------------------------
749 dnl PHP_BUILD_THREAD_SAFE
751 AC_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
759 dnl PHP_REQUIRE_CXX
761 AC_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
771 dnl PHP_BUILD_SHARED
773 AC_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
788 dnl PHP_BUILD_STATIC
790 AC_DEFUN([PHP_BUILD_STATIC],[
791   PHP_BUILD_PROGRAM
792   OVERALL_TARGET=libphp[]$PHP_MAJOR_VERSION[.la]
793   php_sapi_module=static
797 dnl PHP_BUILD_BUNDLE
799 AC_DEFUN([PHP_BUILD_BUNDLE],[
800   PHP_BUILD_PROGRAM
801   OVERALL_TARGET=libs/libphp[]$PHP_MAJOR_VERSION[.bundle]
802   php_sapi_module=static
806 dnl PHP_BUILD_PROGRAM
808 AC_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
817   case $with_pic in
818     yes) pic_setting='-prefer-pic';;
819     no)  pic_setting='-prefer-non-pic';;
820   esac
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
832 dnl PHP_SHARED_MODULE(module-name, object-var, build-dir, cxx, zend_ext)
834 dnl Basically sets up the link-stage for building module-name
835 dnl from object_var in build-dir.
837 AC_DEFUN([PHP_SHARED_MODULE],[
838   install_modules="install-modules"
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, php5lib, , -L$(top_builddir)/netware -lphp5lib) $(translit(ifelse($1, php5lib, $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
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)
865 $3/$1.$suffix: \$($2) \$(translit($1,a-z_-,A-Z__)_SHARED_DEPENDENCIES)
866         $link_cmd
872 dnl PHP_SELECT_SAPI(name, type[, sources [, extra-cflags [, build-target]]])
874 dnl Selects the SAPI name and type (static, shared, bundle, program)
875 dnl and optionally also the source-files for the SAPI-specific
876 dnl objects.
878 AC_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 +--------------------------------------------------------------------+
890   else
891     PHP_SAPI=$1
892   fi  
894   PHP_ADD_BUILD_DIR([sapi/$1])
896   PHP_INSTALLED_SAPIS="$PHP_INSTALLED_SAPIS $1"
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   ])
915 dnl deprecated
916 AC_DEFUN([PHP_EXTENSION],[
917   sources=`$AWK -f $abs_srcdir/build/scan_makefile_in.awk < []PHP_EXT_SRCDIR($1)[]/Makefile.in`
919   PHP_NEW_EXTENSION($1, $sources, $2, $3)
921   if test -r "$ext_srcdir/Makefile.frag"; then
922     PHP_ADD_MAKEFILE_FRAGMENT
923   fi
926 AC_DEFUN([PHP_ADD_BUILD_DIR],[
927   ifelse($2,,[
928     BUILD_DIR="$BUILD_DIR $1"
929   ], [
930     $php_shtool mkdir -p $1
931   ])
934 AC_DEFUN([PHP_GEN_BUILD_DIRS],[
935   $php_shtool mkdir -p $BUILD_DIR
939 dnl PHP_NEW_EXTENSION(extname, sources [, shared [, sapi_class [, extra-cflags [, cxx [, zend_ext]]]]])
941 dnl Includes an extension in the build.
943 dnl "extname" is the name of the ext/ subdir where the extension resides.
944 dnl "sources" is a list of files relative to the subdir which are used
945 dnl to build the extension.
946 dnl "shared" can be set to "shared" or "yes" to build the extension as
947 dnl a dynamically loadable library. Optional parameter "sapi_class" can
948 dnl be set to "cli" to mark extension build only with CLI or CGI sapi's.
949 dnl "extra-cflags" are passed to the compiler, with 
950 dnl @ext_srcdir@ and @ext_builddir@ being substituted.
951 dnl "cxx" can be used to indicate that a C++ shared module is desired.
952 dnl "zend_ext" indicates a zend extension.
953 AC_DEFUN([PHP_NEW_EXTENSION],[
954   ext_builddir=[]PHP_EXT_BUILDDIR($1)
955   ext_srcdir=[]PHP_EXT_SRCDIR($1)
957   ifelse($5,,ac_extra=,[ac_extra=`echo "$5"|$SED s#@ext_srcdir@#$ext_srcdir#g|$SED s#@ext_builddir@#$ext_builddir#g`])
959   if test "$3" != "shared" && test "$3" != "yes" && test "$4" != "cli"; then
960 dnl ---------------------------------------------- Static module
961     [PHP_]translit($1,a-z_-,A-Z__)[_SHARED]=no
962     PHP_ADD_SOURCES(PHP_EXT_DIR($1),$2,$ac_extra,)
963     EXT_STATIC="$EXT_STATIC $1"
964     if test "$3" != "nocli"; then
965       EXT_CLI_STATIC="$EXT_CLI_STATIC $1"
966     fi
967   else
968     if test "$3" = "shared" || test "$3" = "yes"; then
969 dnl ---------------------------------------------- Shared module
970       [PHP_]translit($1,a-z_-,A-Z__)[_SHARED]=yes
971       PHP_ADD_SOURCES_X(PHP_EXT_DIR($1),$2,$ac_extra,shared_objects_$1,yes)
972       case $host_alias in
973         *netware*[)]
974           PHP_SHARED_MODULE(php$1,shared_objects_$1, $ext_builddir, $6, $7)
975           ;;
976         *[)]
977           PHP_SHARED_MODULE($1,shared_objects_$1, $ext_builddir, $6, $7)
978           ;;
979       esac
980       AC_DEFINE_UNQUOTED([COMPILE_DL_]translit($1,a-z_-,A-Z__), 1, Whether to build $1 as dynamic module)
981     fi
982   fi
984   if test "$3" != "shared" && test "$3" != "yes" && test "$4" = "cli"; then
985 dnl ---------------------------------------------- CLI static module
986     [PHP_]translit($1,a-z_-,A-Z__)[_SHARED]=no
987     case "$PHP_SAPI" in
988       cgi|embed[)]
989         PHP_ADD_SOURCES(PHP_EXT_DIR($1),$2,$ac_extra,)
990         EXT_STATIC="$EXT_STATIC $1"
991         ;;
992       *[)]
993         PHP_ADD_SOURCES(PHP_EXT_DIR($1),$2,$ac_extra,cli)
994         ;;
995     esac
996     EXT_CLI_STATIC="$EXT_CLI_STATIC $1"
997   fi
998   PHP_ADD_BUILD_DIR($ext_builddir)
1000 dnl Set for phpize builds only
1001 dnl --------------------------- 
1002   if test "$ext_builddir" = "."; then
1003     PHP_PECL_EXTENSION=$1
1004     PHP_SUBST(PHP_PECL_EXTENSION)
1005   fi
1009 dnl PHP_WITH_SHARED
1011 dnl Checks whether $withval is "shared" or starts with "shared,XXX"
1012 dnl and sets $shared to "yes" or "no", and removes "shared,?" stuff
1013 dnl from $withval.
1015 AC_DEFUN([PHP_WITH_SHARED],[
1016   PHP_ARG_ANALYZE_EX(withval)
1017   shared=$ext_shared
1018   unset ext_shared ext_output
1022 dnl PHP_ADD_EXTENSION_DEP(extname, depends [, depconf])
1024 dnl This macro is scanned by genif.sh when it builds the internal functions
1025 dnl list, so that modules can be init'd in the correct order
1026 dnl $1 = name of extension, $2 = extension upon which it depends
1027 dnl $3 = optional: if true, it's ok for $2 to have not been configured
1028 dnl default is false and should halt the build.
1029 dnl To be effective, this macro must be invoked *after* PHP_NEW_EXTENSION.
1030 dnl The extension on which it depends must also have been configured.
1031 dnl See ADD_EXTENSION_DEP in win32 build 
1033 AC_DEFUN([PHP_ADD_EXTENSION_DEP], [
1034   am_i_shared=$[PHP_]translit($1,a-z_-,A-Z__)[_SHARED]
1035   is_it_shared=$[PHP_]translit($2,a-z_-,A-Z__)[_SHARED]
1036   is_it_enabled=$[PHP_]translit($2,a-z_-,A-Z__)
1037   if test "$am_i_shared" = "no" && test "$is_it_shared" = "yes" ; then
1038     AC_MSG_ERROR([
1039 You've configured extension $1 to build statically, but it
1040 depends on extension $2, which you've configured to build shared.
1041 You either need to build $1 shared or build $2 statically for the
1042 build to be successful.
1044   fi
1045   if test "x$is_it_enabled" = "xno" && test "x$3" != "xtrue"; then
1046     AC_MSG_ERROR([
1047 You've configured extension $1, which depends on extension $2,
1048 but you've either not enabled $2, or have disabled it.
1050   fi
1051   dnl Some systems require that we link $2 to $1 when building
1054 dnl -------------------------------------------------------------------------
1055 dnl Checks for structures, typedefs, broken functions, etc.
1056 dnl -------------------------------------------------------------------------
1058 dnl Internal helper macros
1060 dnl _PHP_DEF_HAVE_FILE(what, filename)
1061 AC_DEFUN([_PHP_DEF_HAVE_FILE], [
1062   php_def_have_what=HAVE_[]`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz-' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_' `
1063   echo "#define $php_def_have_what 1" >> $2
1066 dnl _PHP_CHECK_SIZEOF(type, cross-value, extra-headers [, found-action [, not-found-action]])
1068 AC_DEFUN([_PHP_CHECK_SIZEOF], [
1069   php_cache_value=php_cv_sizeof_[]$1
1070   AC_CACHE_VAL(php_cv_sizeof_[]$1, [
1071     old_LIBS=$LIBS
1072     LIBS=
1073     old_LDFLAGS=$LDFLAGS
1074     LDFLAGS=
1075     AC_TRY_RUN([#include <stdio.h>
1076 #if STDC_HEADERS
1077 #include <stdlib.h>
1078 #include <stddef.h>
1079 #endif
1080 #ifdef HAVE_INTTYPES_H
1081 #include <inttypes.h>
1082 #endif
1083 #ifdef HAVE_UNISTD_H
1084 #include <unistd.h>
1085 #endif
1088 int main()
1090         FILE *fp = fopen("conftestval", "w");
1091         if (!fp) return(1);
1092         fprintf(fp, "%d\n", sizeof($1));
1093         return(0);
1095   ], [
1096     eval $php_cache_value=`cat conftestval`
1097   ], [
1098     eval $php_cache_value=0
1099   ], [
1100     ifelse([$2],,[eval $php_cache_value=0], [eval $php_cache_value=$2])
1102   LDFLAGS=$old_LDFLAGS
1103   LIBS=$old_LIBS
1105   if eval test "\$$php_cache_value" != "0"; then
1106 ifelse([$4],[],:,[$4])
1107 ifelse([$5],[],,[else $5])
1108   fi
1112 dnl PHP_CHECK_SIZEOF(type, cross-value, extra-headers)
1114 AC_DEFUN([PHP_CHECK_SIZEOF], [
1115   AC_MSG_CHECKING([size of $1])
1116   _PHP_CHECK_SIZEOF($1, $2, $3, [
1117     AC_DEFINE_UNQUOTED([SIZEOF_]translit($1,a-z,A-Z_), [$]php_cv_sizeof_[]$1, [Size of $1])
1118     AC_DEFINE_UNQUOTED([HAVE_]translit($1,a-z,A-Z_), 1, [Whether $1 is available])
1119   ])
1120   AC_MSG_RESULT([[$][php_cv_sizeof_]translit($1, ,_)])
1124 dnl PHP_CHECK_TYPES(type-list, include-file [, extra-headers])
1126 AC_DEFUN([PHP_CHECK_TYPES], [
1127   for php_typename in $1; do
1128     AC_MSG_CHECKING([whether $php_typename exists])
1129     _PHP_CHECK_SIZEOF($php_typename, 0, $3, [
1130       _PHP_DEF_HAVE_FILE($php_typename, $2)
1131       AC_MSG_RESULT([yes])
1132     ], [
1133       AC_MSG_RESULT([no])
1134     ])
1135   done
1139 dnl PHP_CHECK_IN_ADDR_T
1141 AC_DEFUN([PHP_CHECK_IN_ADDR_T], [
1142 dnl AIX keeps in_addr_t in /usr/include/netinet/in.h
1143 AC_MSG_CHECKING([for in_addr_t])
1144 AC_CACHE_VAL(ac_cv_type_in_addr_t,
1145 [AC_EGREP_CPP(dnl
1146 changequote(<<,>>)dnl
1147 <<in_addr_t[^a-zA-Z_0-9]>>dnl
1148 changequote([,]), [#include <sys/types.h>
1149 #if STDC_HEADERS
1150 #include <stdlib.h>
1151 #include <stddef.h>
1152 #endif
1153 #ifdef HAVE_NETINET_IN_H
1154 #include <netinet/in.h>
1155 #endif], ac_cv_type_in_addr_t=yes, ac_cv_type_in_addr_t=no)])dnl
1156 AC_MSG_RESULT([$ac_cv_type_in_addr_t])
1157 if test $ac_cv_type_in_addr_t = no; then
1158   AC_DEFINE(in_addr_t, u_int, [ ])
1163 dnl PHP_TIME_R_TYPE
1165 dnl Check type of reentrant time-related functions
1166 dnl Type can be: irix, hpux or POSIX
1168 AC_DEFUN([PHP_TIME_R_TYPE],[
1169 AC_CACHE_CHECK(for type of reentrant time-related functions, ac_cv_time_r_type,[
1170 AC_TRY_RUN([
1171 #include <time.h>
1173 main() {
1174 char buf[27];
1175 struct tm t;
1176 time_t old = 0;
1177 int r, s;
1179 s = gmtime_r(&old, &t);
1180 r = (int) asctime_r(&t, buf, 26);
1181 if (r == s && s == 0) return (0);
1182 return (1);
1185   ac_cv_time_r_type=hpux
1187   AC_TRY_RUN([
1188 #include <time.h>
1189 main() {
1190   struct tm t, *s;
1191   time_t old = 0;
1192   char buf[27], *p;
1193   
1194   s = gmtime_r(&old, &t);
1195   p = asctime_r(&t, buf, 26);
1196   if (p == buf && s == &t) return (0);
1197   return (1);
1199   ],[
1200     ac_cv_time_r_type=irix
1201   ],[
1202     ac_cv_time_r_type=POSIX
1203   ],[
1204     ac_cv_time_r_type=POSIX
1205   ])
1207   ac_cv_time_r_type=POSIX
1210   case $ac_cv_time_r_type in
1211   hpux[)] AC_DEFINE(PHP_HPUX_TIME_R,1,[Whether you have HP-UX 10.x]) ;;
1212   irix[)] AC_DEFINE(PHP_IRIX_TIME_R,1,[Whether you have IRIX-style functions]) ;;
1213   esac
1217 dnl PHP_DOES_PWRITE_WORK
1218 dnl internal
1219 AC_DEFUN([PHP_DOES_PWRITE_WORK],[
1220   AC_TRY_RUN([
1221 #include <sys/types.h>
1222 #include <sys/stat.h>
1223 #include <fcntl.h>
1224 #include <unistd.h>
1225 #include <errno.h>
1227     main() {
1228     int fd = open("conftest_in", O_WRONLY|O_CREAT, 0600);
1230     if (fd < 0) exit(1);
1231     if (pwrite(fd, "text", 4, 0) != 4) exit(1);
1232     /* Linux glibc breakage until 2.2.5 */
1233     if (pwrite(fd, "text", 4, -1) != -1 || errno != EINVAL) exit(1);
1234     exit(0);
1235     }
1237   ],[
1238     ac_cv_pwrite=yes
1239   ],[
1240     ac_cv_pwrite=no
1241   ],[
1242     ac_cv_pwrite=no
1243   ])
1246 dnl PHP_DOES_PREAD_WORK
1247 dnl internal
1248 AC_DEFUN([PHP_DOES_PREAD_WORK],[
1249   echo test > conftest_in
1250   AC_TRY_RUN([
1251 #include <sys/types.h>
1252 #include <sys/stat.h>
1253 #include <fcntl.h>
1254 #include <unistd.h>
1255 #include <errno.h>
1257     main() {
1258     char buf[3]; 
1259     int fd = open("conftest_in", O_RDONLY);
1260     if (fd < 0) exit(1);
1261     if (pread(fd, buf, 2, 0) != 2) exit(1);
1262     /* Linux glibc breakage until 2.2.5 */
1263     if (pread(fd, buf, 2, -1) != -1 || errno != EINVAL) exit(1);
1264     exit(0);
1265     }
1266   ],[
1267     ac_cv_pread=yes
1268   ],[
1269     ac_cv_pread=no
1270   ],[
1271     ac_cv_pread=no
1272   ])
1273   rm -f conftest_in
1277 dnl PHP_PWRITE_TEST
1279 AC_DEFUN([PHP_PWRITE_TEST],[
1280   AC_CACHE_CHECK(whether pwrite works,ac_cv_pwrite,[
1281     PHP_DOES_PWRITE_WORK
1282     if test "$ac_cv_pwrite" = "no"; then
1283       PHP_DOES_PWRITE_WORK([ssize_t pwrite(int, void *, size_t, off64_t);])
1284       if test "$ac_cv_pwrite" = "yes"; then
1285         ac_cv_pwrite=64
1286       fi
1287     fi
1288   ])
1290   if test "$ac_cv_pwrite" != "no"; then
1291     AC_DEFINE(HAVE_PWRITE, 1, [ ])
1292     if test "$ac_cv_pwrite" = "64"; then
1293       AC_DEFINE(PHP_PWRITE_64, 1, [whether pwrite64 is default])
1294     fi
1295   fi  
1299 dnl PHP_PREAD_TEST
1301 AC_DEFUN([PHP_PREAD_TEST],[
1302   AC_CACHE_CHECK(whether pread works,ac_cv_pread,[
1303     PHP_DOES_PREAD_WORK
1304     if test "$ac_cv_pread" = "no"; then
1305       PHP_DOES_PREAD_WORK([ssize_t pread(int, void *, size_t, off64_t);])
1306       if test "$ac_cv_pread" = "yes"; then
1307         ac_cv_pread=64
1308       fi
1309     fi
1310   ])
1312   if test "$ac_cv_pread" != "no"; then
1313     AC_DEFINE(HAVE_PREAD, 1, [ ])
1314     if test "$ac_cv_pread" = "64"; then
1315       AC_DEFINE(PHP_PREAD_64, 1, [whether pread64 is default])
1316     fi
1317   fi  
1321 dnl PHP_MISSING_TIME_R_DECL
1323 AC_DEFUN([PHP_MISSING_TIME_R_DECL],[
1324   AC_MSG_CHECKING([for missing declarations of reentrant functions])
1325   AC_TRY_COMPILE([#include <time.h>],[struct tm *(*func)() = localtime_r],[
1326     :
1327   ],[
1328     AC_DEFINE(MISSING_LOCALTIME_R_DECL,1,[Whether localtime_r is declared])
1329   ])
1330   AC_TRY_COMPILE([#include <time.h>],[struct tm *(*func)() = gmtime_r],[
1331     :
1332   ],[
1333     AC_DEFINE(MISSING_GMTIME_R_DECL,1,[Whether gmtime_r is declared])
1334   ])
1335   AC_TRY_COMPILE([#include <time.h>],[char *(*func)() = asctime_r],[
1336     :
1337   ],[
1338     AC_DEFINE(MISSING_ASCTIME_R_DECL,1,[Whether asctime_r is declared])
1339   ])
1340   AC_TRY_COMPILE([#include <time.h>],[char *(*func)() = ctime_r],[
1341     :
1342   ],[
1343     AC_DEFINE(MISSING_CTIME_R_DECL,1,[Whether ctime_r is declared])
1344   ])
1345   AC_TRY_COMPILE([#include <string.h>],[char *(*func)() = strtok_r],[
1346     :
1347   ],[
1348     AC_DEFINE(MISSING_STRTOK_R_DECL,1,[Whether strtok_r is declared])
1349   ])
1350   AC_MSG_RESULT([done])
1354 dnl PHP_READDIR_R_TYPE
1355 dnl 
1356 AC_DEFUN([PHP_READDIR_R_TYPE],[
1357   dnl HAVE_READDIR_R is also defined by libmysql
1358   AC_CHECK_FUNC(readdir_r,ac_cv_func_readdir_r=yes,ac_cv_func_readdir=no)
1359   if test "$ac_cv_func_readdir_r" = "yes"; then
1360   AC_CACHE_CHECK(for type of readdir_r, ac_cv_what_readdir_r,[
1361     AC_TRY_RUN([
1362 #define _REENTRANT
1363 #include <sys/types.h>
1364 #include <dirent.h>
1366 #ifndef PATH_MAX
1367 #define PATH_MAX 1024
1368 #endif
1370 main() {
1371   DIR *dir;
1372   char entry[sizeof(struct dirent)+PATH_MAX];
1373   struct dirent *pentry = (struct dirent *) &entry;
1375   dir = opendir("/");
1376   if (!dir) 
1377     exit(1);
1378   if (readdir_r(dir, (struct dirent *) entry, &pentry) == 0)
1379     exit(0);
1380   exit(1);
1382     ],[
1383       ac_cv_what_readdir_r=POSIX
1384     ],[
1385       AC_TRY_CPP([
1386 #define _REENTRANT
1387 #include <sys/types.h>
1388 #include <dirent.h>
1389 int readdir_r(DIR *, struct dirent *);
1390         ],[
1391           ac_cv_what_readdir_r=old-style
1392         ],[
1393           ac_cv_what_readdir_r=none
1394       ])
1395     ],[
1396       ac_cv_what_readdir_r=none
1397    ])
1398   ])
1399     case $ac_cv_what_readdir_r in
1400     POSIX)
1401       AC_DEFINE(HAVE_POSIX_READDIR_R,1,[whether you have POSIX readdir_r]);;
1402     old-style)
1403       AC_DEFINE(HAVE_OLD_READDIR_R,1,[whether you have old-style readdir_r]);;
1404     esac
1405   fi
1409 dnl PHP_TM_GMTOFF
1410 dnl 
1411 AC_DEFUN([PHP_TM_GMTOFF],[
1412 AC_CACHE_CHECK([for tm_gmtoff in struct tm], ac_cv_struct_tm_gmtoff,
1413 [AC_TRY_COMPILE([#include <sys/types.h>
1414 #include <$ac_cv_struct_tm>], [struct tm tm; tm.tm_gmtoff;],
1415   ac_cv_struct_tm_gmtoff=yes, ac_cv_struct_tm_gmtoff=no)])
1417 if test "$ac_cv_struct_tm_gmtoff" = yes; then
1418   AC_DEFINE(HAVE_TM_GMTOFF,1,[whether you have tm_gmtoff in struct tm])
1423 dnl PHP_STRUCT_FLOCK
1425 AC_DEFUN([PHP_STRUCT_FLOCK],[
1426 AC_CACHE_CHECK(for struct flock,ac_cv_struct_flock,
1427     AC_TRY_COMPILE([
1428 #include <unistd.h>
1429 #include <fcntl.h>
1430         ],
1431         [struct flock x;],
1432         [
1433           ac_cv_struct_flock=yes
1434         ],[
1435           ac_cv_struct_flock=no
1436         ])
1438 if test "$ac_cv_struct_flock" = "yes" ; then
1439     AC_DEFINE(HAVE_STRUCT_FLOCK, 1,[whether you have struct flock])
1444 dnl PHP_SOCKLEN_T
1446 AC_DEFUN([PHP_SOCKLEN_T],[
1447 AC_CACHE_CHECK(for socklen_t,ac_cv_socklen_t,
1448   AC_TRY_COMPILE([
1449 #include <sys/types.h>
1450 #include <sys/socket.h>
1452 socklen_t x;
1454   ac_cv_socklen_t=yes
1456   ac_cv_socklen_t=no
1458 if test "$ac_cv_socklen_t" = "yes"; then
1459   AC_DEFINE(HAVE_SOCKLEN_T, 1, [Whether you have socklen_t])
1464 dnl PHP_MISSING_FCLOSE_DECL
1466 dnl See if we have broken header files like SunOS has.
1468 AC_DEFUN([PHP_MISSING_FCLOSE_DECL],[
1469   AC_MSG_CHECKING([for fclose declaration])
1470   AC_TRY_COMPILE([#include <stdio.h>],[int (*func)() = fclose],[
1471     AC_DEFINE(MISSING_FCLOSE_DECL,0,[ ])
1472     AC_MSG_RESULT([ok])
1473   ],[
1474     AC_DEFINE(MISSING_FCLOSE_DECL,1,[ ])
1475     AC_MSG_RESULT([missing])
1476   ])
1480 dnl PHP_AC_BROKEN_SPRINTF
1482 dnl Check for broken sprintf(), C99 conformance
1484 AC_DEFUN([PHP_AC_BROKEN_SPRINTF],[
1485   AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[
1486     AC_TRY_RUN([main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[
1487       ac_cv_broken_sprintf=no
1488     ],[
1489       ac_cv_broken_sprintf=yes
1490     ],[
1491       ac_cv_broken_sprintf=no
1492     ])
1493   ])
1494   if test "$ac_cv_broken_sprintf" = "yes"; then
1495     AC_DEFINE(PHP_BROKEN_SPRINTF, 1, [Whether sprintf is C99 conform])
1496   else
1497     AC_DEFINE(PHP_BROKEN_SPRINTF, 0, [Whether sprintf is C99 conform])
1498   fi
1502 dnl PHP_AC_BROKEN_SNPRINTF
1504 dnl Check for broken snprintf(), C99 conformance
1506 AC_DEFUN([PHP_AC_BROKEN_SNPRINTF],[
1507   AC_CACHE_CHECK(whether snprintf is broken, ac_cv_broken_snprintf,[
1508     AC_TRY_RUN([
1509 #define NULL (0L)
1510 main() {
1511   char buf[20];
1512   int res = 0;
1513   res = res || (snprintf(buf, 2, "marcus") != 6); 
1514   res = res || (buf[1] != '\0');
1515   /* Implementations may consider this as an encoding error */
1516   snprintf(buf, 0, "boerger");
1517   /* However, they MUST ignore the pointer */
1518   res = res || (buf[0] != 'm');
1519   res = res || (snprintf(NULL, 0, "boerger") != 7);
1520   res = res || (snprintf(buf, sizeof(buf), "%f", 0.12345678) != 8);
1521   exit(res); 
1523     ],[
1524       ac_cv_broken_snprintf=no
1525     ],[
1526       ac_cv_broken_snprintf=yes
1527     ],[
1528       ac_cv_broken_snprintf=no
1529     ])
1530   ])
1531   if test "$ac_cv_broken_snprintf" = "yes"; then
1532     AC_DEFINE(PHP_BROKEN_SNPRINTF, 1, [Whether snprintf is C99 conform])
1533   else
1534     AC_DEFINE(PHP_BROKEN_SNPRINTF, 0, [Whether snprintf is C99 conform])
1535   fi
1539 dnl PHP_SOLARIS_PIC_WEIRDNESS
1541 dnl Solaris requires main code to be position independent in order
1542 dnl to let shared objects find symbols.  Weird.  Ugly.
1544 dnl Must be run after all --with-NN options that let the user
1545 dnl choose dynamic extensions, and after the gcc test.
1547 AC_DEFUN([PHP_SOLARIS_PIC_WEIRDNESS],[
1548   AC_MSG_CHECKING([whether -fPIC is required])
1549   if test -n "$EXT_SHARED"; then
1550     os=`uname -sr 2>/dev/null`
1551     case $os in
1552       "SunOS 5.6"|"SunOS 5.7"[)]
1553         case $CC in
1554           gcc*|egcs*)
1555             CFLAGS="$CFLAGS -fPIC";;
1556           *[)]
1557             CFLAGS="$CFLAGS -fpic";;
1558         esac
1559         AC_MSG_RESULT([yes]);;
1560       *[)]
1561         AC_MSG_RESULT([no]);;
1562     esac
1563   else
1564     AC_MSG_RESULT([no])
1565   fi
1569 dnl PHP_SYS_LFS
1571 dnl The problem is that the default compilation flags in Solaris 2.6 won't
1572 dnl let programs access large files;  you need to tell the compiler that
1573 dnl you actually want your programs to work on large files.  For more
1574 dnl details about this brain damage please see:
1575 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
1577 dnl Written by Paul Eggert <eggert@twinsun.com>.
1579 AC_DEFUN([PHP_SYS_LFS],
1580 [dnl
1581   # If available, prefer support for large files unless the user specified
1582   # one of the CPPFLAGS, LDFLAGS, or LIBS variables.
1583   AC_MSG_CHECKING([whether large file support needs explicit enabling])
1584   ac_getconfs=''
1585   ac_result=yes
1586   ac_set=''
1587   ac_shellvars='CPPFLAGS LDFLAGS LIBS'
1588   for ac_shellvar in $ac_shellvars; do
1589     case $ac_shellvar in
1590       CPPFLAGS[)] ac_lfsvar=LFS_CFLAGS ;;
1591       *[)] ac_lfsvar=LFS_$ac_shellvar ;;
1592     esac
1593     eval test '"${'$ac_shellvar'+set}"' = set && ac_set=$ac_shellvar
1594     (getconf $ac_lfsvar) >/dev/null 2>&1 || { ac_result=no; break; }
1595     ac_getconf=`getconf $ac_lfsvar`
1596     ac_getconfs=$ac_getconfs$ac_getconf
1597     eval ac_test_$ac_shellvar=\$ac_getconf
1598   done
1599   case "$ac_result$ac_getconfs" in
1600     yes[)] ac_result=no ;;
1601   esac
1602   case "$ac_result$ac_set" in
1603     yes?*[)] ac_result="yes, but $ac_set is already set, so use its settings"
1604   esac
1605   AC_MSG_RESULT([$ac_result])
1606   case $ac_result in
1607     yes[)]
1608       for ac_shellvar in $ac_shellvars; do
1609         eval $ac_shellvar=\$ac_test_$ac_shellvar
1610       done ;;
1611   esac
1615 dnl PHP_SOCKADDR_CHECKS
1617 AC_DEFUN([PHP_SOCKADDR_CHECKS], [
1618   dnl Check for struct sockaddr_storage exists
1619   AC_CACHE_CHECK([for struct sockaddr_storage], ac_cv_sockaddr_storage,
1620     [AC_TRY_COMPILE([#include <sys/types.h>
1621 #include <sys/socket.h>],
1622     [struct sockaddr_storage s; s],
1623     [ac_cv_sockaddr_storage=yes], [ac_cv_sockaddr_storage=no])
1624   ])
1625   if test "$ac_cv_sockaddr_storage" = "yes"; then
1626     AC_DEFINE(HAVE_SOCKADDR_STORAGE, 1, [Whether you have struct sockaddr_storage])
1627   fi
1628   dnl Check if field sa_len exists in struct sockaddr 
1629   AC_CACHE_CHECK([for field sa_len in struct sockaddr],ac_cv_sockaddr_sa_len,[
1630     AC_TRY_COMPILE([#include <sys/types.h>
1631 #include <sys/socket.h>],
1632     [static struct sockaddr sa; int n = (int) sa.sa_len; return n;],
1633     [ac_cv_sockaddr_sa_len=yes], [ac_cv_sockaddr_sa_len=no])
1634   ])
1635   if test "$ac_cv_sockaddr_sa_len" = "yes"; then
1636     AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has field sa_len])
1637   fi
1641 dnl PHP_DECLARED_TIMEZONE
1643 AC_DEFUN([PHP_DECLARED_TIMEZONE],[
1644   AC_CACHE_CHECK(for declared timezone, ac_cv_declared_timezone,[
1645     AC_TRY_COMPILE([
1646 #include <sys/types.h>
1647 #include <time.h>
1648 #ifdef HAVE_SYS_TIME_H
1649 #include <sys/time.h>
1650 #endif
1652     time_t foo = (time_t) timezone;
1654   ac_cv_declared_timezone=yes
1656   ac_cv_declared_timezone=no
1657 ])])
1658   if test "$ac_cv_declared_timezone" = "yes"; then
1659     AC_DEFINE(HAVE_DECLARED_TIMEZONE, 1, [Whether system headers declare timezone])
1660   fi
1664 dnl PHP_EBCDIC
1666 AC_DEFUN([PHP_EBCDIC], [
1667   AC_CACHE_CHECK([whether system uses EBCDIC],ac_cv_ebcdic,[
1668   AC_TRY_RUN( [
1669 int main(void) { 
1670   return (unsigned char)'A' != (unsigned char)0xC1; 
1673   ac_cv_ebcdic=yes
1675   ac_cv_ebcdic=no
1677   ac_cv_ebcdic=no
1678 ])])
1679   if test "$ac_cv_ebcdic" = "yes"; then
1680     AC_DEFINE(CHARSET_EBCDIC,1, [Define if system uses EBCDIC])
1681   fi
1685 dnl PHP_BROKEN_GETCWD
1687 dnl Some systems, notably Solaris, cause getcwd() or realpath to fail if a
1688 dnl component of the path has execute but not read permissions
1690 AC_DEFUN([PHP_BROKEN_GETCWD],[
1691   AC_MSG_CHECKING([for broken getcwd])
1692   os=`uname -sr 2>/dev/null`
1693   case $os in
1694     SunOS*[)]
1695       AC_DEFINE(HAVE_BROKEN_GETCWD,1, [Define if system has broken getcwd])
1696       AC_MSG_RESULT([yes]);;
1697     *[)]
1698       AC_MSG_RESULT([no]);;
1699   esac
1703 dnl PHP_BROKEN_GLIBC_FOPEN_APPEND
1705 AC_DEFUN([PHP_BROKEN_GLIBC_FOPEN_APPEND], [
1706   AC_MSG_CHECKING([for broken libc stdio])
1707   AC_CACHE_VAL(_cv_have_broken_glibc_fopen_append,[
1708   AC_TRY_RUN([
1709 #include <stdio.h>
1710 int main(int argc, char *argv[])
1712   FILE *fp;
1713   long position;
1714   char *filename = "/tmp/phpglibccheck";
1715   
1716   fp = fopen(filename, "w");
1717   if (fp == NULL) {
1718     perror("fopen");
1719     exit(2);
1720   }
1721   fputs("foobar", fp);
1722   fclose(fp);
1724   fp = fopen(filename, "a+");
1725   position = ftell(fp);
1726   fclose(fp);
1727   unlink(filename);
1728   if (position == 0)
1729   return 1;
1730   return 0;
1733 [_cv_have_broken_glibc_fopen_append=no],
1734 [_cv_have_broken_glibc_fopen_append=yes ],
1735 AC_TRY_COMPILE([
1736 #include <features.h>
1738 #if !__GLIBC_PREREQ(2,2)
1739 choke me
1740 #endif
1742 [_cv_have_broken_glibc_fopen_append=yes],
1743 [_cv_have_broken_glibc_fopen_append=no ])
1746   if test "$_cv_have_broken_glibc_fopen_append" = "yes"; then
1747     AC_MSG_RESULT(yes)
1748     AC_DEFINE(HAVE_BROKEN_GLIBC_FOPEN_APPEND,1, [Define if your glibc borks on fopen with mode a+])
1749   else
1750     AC_MSG_RESULT(no)
1751   fi
1755 dnl PHP_FOPENCOOKIE
1757 AC_DEFUN([PHP_FOPENCOOKIE], [
1758   AC_CHECK_FUNC(fopencookie, [have_glibc_fopencookie=yes])
1760   if test "$have_glibc_fopencookie" = "yes"; then
1761 dnl this comes in two flavors:
1762 dnl newer glibcs (since 2.1.2 ? )
1763 dnl have a type called cookie_io_functions_t
1764 AC_TRY_COMPILE([
1765 #define _GNU_SOURCE
1766 #include <stdio.h>
1767 ], [cookie_io_functions_t cookie;], [have_cookie_io_functions_t=yes], [])
1769     if test "$have_cookie_io_functions_t" = "yes"; then
1770       cookie_io_functions_t=cookie_io_functions_t
1771       have_fopen_cookie=yes
1773 dnl even newer glibcs have a different seeker definition...
1774 AC_TRY_RUN([
1775 #define _GNU_SOURCE
1776 #include <stdio.h>
1778 struct cookiedata {
1779   __off64_t pos;
1782 __ssize_t reader(void *cookie, char *buffer, size_t size)
1783 { return size; }
1784 __ssize_t writer(void *cookie, const char *buffer, size_t size)
1785 { return size; }
1786 int closer(void *cookie)
1787 { return 0; }
1788 int seeker(void *cookie, __off64_t *position, int whence)
1789 { ((struct cookiedata*)cookie)->pos = *position; return 0; }
1791 cookie_io_functions_t funcs = {reader, writer, seeker, closer};
1793 main() {
1794   struct cookiedata g = { 0 };
1795   FILE *fp = fopencookie(&g, "r", funcs);
1797   if (fp && fseek(fp, 8192, SEEK_SET) == 0 && g.pos == 8192)
1798     exit(0);
1799   exit(1);
1802 ], [
1803   cookie_io_functions_use_off64_t=yes
1804 ], [
1805   cookie_io_functions_use_off64_t=no
1806 ], [
1807   cookie_io_functions_use_off64_t=no
1809     
1810     else
1812 dnl older glibc versions (up to 2.1.2 ?)
1813 dnl call it _IO_cookie_io_functions_t
1814 AC_TRY_COMPILE([
1815 #define _GNU_SOURCE
1816 #include <stdio.h>
1817 ], [ _IO_cookie_io_functions_t cookie; ], [have_IO_cookie_io_functions_t=yes], [])
1818       if test "$have_cookie_io_functions_t" = "yes" ; then
1819         cookie_io_functions_t=_IO_cookie_io_functions_t
1820         have_fopen_cookie=yes
1821       fi
1822     fi
1824     if test "$have_fopen_cookie" = "yes" ; then
1825       AC_DEFINE(HAVE_FOPENCOOKIE, 1, [ ])
1826       AC_DEFINE_UNQUOTED(COOKIE_IO_FUNCTIONS_T, $cookie_io_functions_t, [ ])
1827       if test "$cookie_io_functions_use_off64_t" = "yes" ; then
1828         AC_DEFINE(COOKIE_SEEKER_USES_OFF64_T, 1, [ ])
1829       fi
1830     fi
1831   fi
1834 dnl -------------------------------------------------------------------------
1835 dnl Library/function existance and build sanity checks
1836 dnl -------------------------------------------------------------------------
1839 dnl PHP_CHECK_LIBRARY(library, function [, action-found [, action-not-found [, extra-libs]]])
1841 dnl Wrapper for AC_CHECK_LIB
1843 AC_DEFUN([PHP_CHECK_LIBRARY], [
1844   save_old_LDFLAGS=$LDFLAGS
1845   ac_stuff="$5"
1846   
1847   save_ext_shared=$ext_shared
1848   ext_shared=yes
1849   PHP_EVAL_LIBLINE([$]ac_stuff, LDFLAGS)
1850   AC_CHECK_LIB([$1],[$2],[
1851     LDFLAGS=$save_old_LDFLAGS
1852     ext_shared=$save_ext_shared
1853     $3
1854   ],[
1855     LDFLAGS=$save_old_LDFLAGS
1856     ext_shared=$save_ext_shared
1857     unset ac_cv_lib_$1[]_$2
1858     $4
1859   ])dnl
1863 dnl PHP_CHECK_FRAMEWORK(framework, function [, action-found [, action-not-found ]])
1865 dnl El cheapo wrapper for AC_CHECK_LIB
1867 AC_DEFUN([PHP_CHECK_FRAMEWORK], [
1868   save_old_LDFLAGS=$LDFLAGS
1869   LDFLAGS="-framework $1 $LDFLAGS"
1870   dnl supplying "c" to AC_CHECK_LIB is technically cheating, but
1871   dnl rewriting AC_CHECK_LIB is overkill and this only affects
1872   dnl the "checking.." output anyway.
1873   AC_CHECK_LIB(c,[$2],[
1874     LDFLAGS=$save_old_LDFLAGS
1875     $3
1876   ],[
1877     LDFLAGS=$save_old_LDFLAGS
1878     $4
1879   ])
1883 dnl PHP_CHECK_FUNC_LIB(func, libs)
1885 dnl This macro checks whether 'func' or '__func' exists
1886 dnl in the specified library.
1887 dnl Defines HAVE_func and HAVE_library if found and adds the library to LIBS.
1888 dnl This should be called in the ACTION-IF-NOT-FOUND part of PHP_CHECK_FUNC
1891 dnl autoconf undefines the builtin "shift" :-(
1892 dnl If possible, we use the builtin shift anyway, otherwise we use
1893 dnl the ubercool definition I have tested so far with FreeBSD/GNU m4
1894 ifdef([builtin],[builtin(define, phpshift, [builtin(shift, $@)])],[
1895 define([phpshift],[ifelse(index([$@],[,]),-1,,[substr([$@],incr(index([$@],[,])))])])
1898 AC_DEFUN([PHP_CHECK_FUNC_LIB],[
1899   ifelse($2,,:,[
1900   unset ac_cv_lib_$2[]_$1
1901   unset ac_cv_lib_$2[]___$1
1902   unset found
1903   AC_CHECK_LIB($2, $1, [found=yes], [
1904     AC_CHECK_LIB($2, __$1, [found=yes], [found=no])
1905   ])
1907   if test "$found" = "yes"; then
1908     ac_libs=$LIBS
1909     LIBS="$LIBS -l$2"
1910     AC_TRY_RUN([main() { return (0); }],[found=yes],[found=no],[found=no])
1911     LIBS=$ac_libs
1912   fi
1914   if test "$found" = "yes"; then
1915     PHP_ADD_LIBRARY($2)
1916     PHP_DEF_HAVE($1)
1917     PHP_DEF_HAVE(lib$2)
1918     ac_cv_func_$1=yes
1919   else
1920     PHP_CHECK_FUNC_LIB($1,phpshift(phpshift($@)))
1921   fi
1922   ])
1926 dnl PHP_CHECK_FUNC(func, ...)
1928 dnl This macro checks whether 'func' or '__func' exists
1929 dnl in the default libraries and as a fall back in the specified library.
1930 dnl Defines HAVE_func and HAVE_library if found and adds the library to LIBS.
1932 AC_DEFUN([PHP_CHECK_FUNC],[
1933   unset ac_cv_func_$1
1934   unset ac_cv_func___$1
1935   unset found
1936   
1937   AC_CHECK_FUNC($1, [found=yes],[ AC_CHECK_FUNC(__$1,[found=yes],[found=no]) ])
1939   case $found in
1940   yes[)] 
1941     PHP_DEF_HAVE($1)
1942     ac_cv_func_$1=yes
1943   ;;
1944   ifelse($#,1,,[
1945     *[)] PHP_CHECK_FUNC_LIB($@) ;;
1946   ])
1947   esac
1951 dnl PHP_TEST_BUILD(function, action-if-ok, action-if-not-ok [, extra-libs [, extra-source]])
1953 dnl This macro checks whether build works and given function exists.
1955 AC_DEFUN([PHP_TEST_BUILD], [
1956   old_LIBS=$LIBS
1957   LIBS="$4 $LIBS"
1958   AC_TRY_RUN([
1959     $5
1960     char $1();
1961     int main() {
1962       $1();
1963       return 0;
1964     }
1965   ], [
1966     LIBS=$old_LIBS
1967     $2
1968   ],[
1969     LIBS=$old_LIBS
1970     $3
1971   ],[
1972     LIBS=$old_LIBS
1973   ])
1976 dnl -------------------------------------------------------------------------
1977 dnl Platform characteristics checks
1978 dnl -------------------------------------------------------------------------
1981 dnl PHP_SHLIB_SUFFIX_NAMES
1983 dnl Determines link library suffix SHLIB_SUFFIX_NAME
1984 dnl which can be: .so, .sl or .dylib
1986 dnl Determines shared library suffix SHLIB_DL_SUFFIX_NAME
1987 dnl suffix can be: .so or .sl
1989 AC_DEFUN([PHP_SHLIB_SUFFIX_NAMES],[
1990  AC_REQUIRE([PHP_CANONICAL_HOST_TARGET])dnl
1991  PHP_SUBST_OLD(SHLIB_SUFFIX_NAME)
1992  PHP_SUBST_OLD(SHLIB_DL_SUFFIX_NAME)
1993  SHLIB_SUFFIX_NAME=so
1994  SHLIB_DL_SUFFIX_NAME=$SHLIB_SUFFIX_NAME
1995  case $host_alias in
1996  *hpux*[)]
1997    SHLIB_SUFFIX_NAME=sl
1998    SHLIB_DL_SUFFIX_NAME=sl
1999    ;;
2000  *darwin*[)]
2001    SHLIB_SUFFIX_NAME=dylib
2002    SHLIB_DL_SUFFIX_NAME=so
2003    ;;
2004  esac
2008 dnl PHP_CHECK_64BIT([do if 32], [do if 64])
2010 dnl This macro is used to detect if we're at 64-bit platform or not.
2011 dnl It could be useful for those external libs, that have different precompiled 
2012 dnl versions in different directories.
2014 AC_DEFUN([PHP_CHECK_64BIT],[
2015   AC_CHECK_SIZEOF(long int, 4)
2016   AC_MSG_CHECKING([checking if we're at 64-bit platform])
2017   if test "$ac_cv_sizeof_long_int" = "4" ; then
2018     AC_MSG_RESULT([no])
2019     $1
2020   else
2021     AC_MSG_RESULT([yes])
2022     $2
2023   fi
2027 dnl PHP_C_BIGENDIAN
2029 dnl Replacement macro for AC_C_BIGENDIAN
2031 AC_DEFUN([PHP_C_BIGENDIAN],
2032 [AC_CACHE_CHECK([whether byte ordering is bigendian], ac_cv_c_bigendian_php,
2034   ac_cv_c_bigendian_php=unknown
2035   AC_TRY_RUN(
2036   [
2037 int main(void)
2039   short one = 1;
2040   char *cp = (char *)&one;
2042   if (*cp == 0) {
2043     return(0);
2044   } else {
2045     return(1);
2046   }
2048   ], [ac_cv_c_bigendian_php=yes], [ac_cv_c_bigendian_php=no], [ac_cv_c_bigendian_php=unknown])
2049  ])
2050  if test $ac_cv_c_bigendian_php = yes; then
2051    AC_DEFINE(WORDS_BIGENDIAN, [], [Define if processor uses big-endian word])
2052  fi
2055 dnl -------------------------------------------------------------------------
2056 dnl Checks for programs: PHP_PROG_<program>
2057 dnl -------------------------------------------------------------------------
2060 dnl PHP_PROG_SENDMAIL
2062 dnl Search for the sendmail binary
2064 AC_DEFUN([PHP_PROG_SENDMAIL], [
2065   PHP_ALT_PATH=/usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib
2066   AC_PATH_PROG(PROG_SENDMAIL, sendmail,[], $PATH:$PHP_ALT_PATH)
2067   PHP_SUBST(PROG_SENDMAIL)
2071 dnl PHP_PROG_AWK
2073 dnl Some vendors force mawk before gawk; mawk is broken so we don't like that
2075 AC_DEFUN([PHP_PROG_AWK], [
2076   AC_CHECK_PROGS(AWK, gawk nawk awk mawk, bork, /usr/xpg4/bin/:$PATH)
2077   case "$AWK" in
2078     *mawk)
2079       AC_MSG_WARN([mawk is known to have problems on some systems. You should install GNU awk])
2080       ;;
2081     *gawk)  
2082       ;;
2083     bork)   
2084       AC_MSG_ERROR([Could not find awk; Install GNU awk])
2085       ;;
2086     *)
2087       AC_MSG_CHECKING([if $AWK is broken])
2088       if ! $AWK 'function foo() {}' >/dev/null 2>&1 ; then
2089         AC_MSG_RESULT([yes])
2090         AC_MSG_ERROR([You should install GNU awk])
2091       else
2092         AC_MSG_RESULT([no])
2093       fi
2094       ;;
2095   esac
2096   PHP_SUBST(AWK)
2100 dnl PHP_PROG_BISON
2102 dnl Search for bison and check it's version
2104 AC_DEFUN([PHP_PROG_BISON], [
2105   AC_PROG_YACC
2106   LIBZEND_BISON_CHECK
2107   PHP_SUBST(YACC)
2111 dnl PHP_PROG_LEX
2113 dnl Search for (f)lex and check it's version
2115 AC_DEFUN([PHP_PROG_LEX], [
2116 dnl we only support certain flex versions
2117   flex_version_list="2.5.4"
2118    
2119   AC_PROG_LEX
2120   if test "$LEX" = "flex"; then
2121 dnl AC_DECL_YYTEXT is obsolete since autoconf 2.50 and merged into AC_PROG_LEX
2122 dnl this is what causes that annoying "PHP_PROG_LEX is expanded from" warning with autoconf 2.50+
2123 dnl it should be removed once we drop support of autoconf 2.13 (if ever)
2124     AC_DECL_YYTEXT
2125     :
2126   fi
2127   dnl ## Make flex scanners use const if they can, even if __STDC__ is not
2128   dnl ## true, for compilers like Sun's that only set __STDC__ true in
2129   dnl ## "limit-to-ANSI-standard" mode, not in "ANSI-compatible" mode
2130   AC_C_CONST
2131   if test "$ac_cv_c_const" = "yes" ; then
2132     LEX_CFLAGS="-DYY_USE_CONST"
2133   fi
2135   if test "$LEX" = "flex"; then
2136     AC_CACHE_CHECK([for flex version], php_cv_flex_version, [
2137       flex_version=`$LEX -V -v --version 2>/dev/null | $SED -e 's/^.* //'`
2138       php_cv_flex_version=invalid
2139       for flex_check_version in $flex_version_list; do
2140         if test "$flex_version" = "$flex_check_version"; then
2141           php_cv_flex_version="$flex_check_version (ok)"
2142         fi
2143       done
2144     ])
2145   else
2146     flex_version=none
2147   fi
2148   
2149   case $php_cv_flex_version in
2150     ""|invalid[)]
2151       if test -f "$abs_srcdir/Zend/zend_language_scanner.c" && test -f "$abs_srcdir/Zend/zend_ini_scanner.c"; then
2152         AC_MSG_WARN([flex versions supported for regeneration of the Zend/PHP parsers: $flex_version_list  (found: $flex_version)])
2153       else
2154         flex_msg="Supported flex versions are: $flex_version_list"
2155         if test "$flex_version" = "none"; then
2156           flex_msg="flex not found. flex is required to generate the Zend/PHP parsers! $flex_msg"
2157         else
2158           flex_msg="Found invalid flex version: $flex_version. $flex_msg"
2159         fi
2160         AC_MSG_ERROR([$flex_msg])
2161       fi
2162       LEX="exit 0;"
2163       ;;
2164   esac
2165   PHP_SUBST(LEX)
2169 dnl PHP_PROG_RE2C
2171 dnl Search for the re2c binary and check the version
2173 AC_DEFUN([PHP_PROG_RE2C],[
2174   AC_CHECK_PROG(RE2C, re2c, re2c)
2175   if test -n "$RE2C"; then
2176     AC_CACHE_CHECK([for re2c version], php_cv_re2c_version, [
2177       re2c_vernum=`$RE2C --vernum 2>/dev/null`
2178       if test -z "$re2c_vernum" || test "$re2c_vernum" -lt "1304"; then
2179         php_cv_re2c_version=invalid
2180       else
2181         php_cv_re2c_version="`$RE2C --version | cut -d ' ' -f 2  2>/dev/null` (ok)"
2182       fi 
2183     ])
2184   fi
2185   case $php_cv_re2c_version in
2186     ""|invalid[)]
2187       AC_MSG_WARN([You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.])
2188       RE2C="exit 0;"
2189       ;;
2190   esac
2191   PHP_SUBST(RE2C)
2194 dnl -------------------------------------------------------------------------
2195 dnl Common setup macros: PHP_SETUP_<what>
2196 dnl -------------------------------------------------------------------------
2199 dnl PHP_SETUP_ICU([shared-add])
2201 dnl Common setup macro for ICU
2203 AC_DEFUN([PHP_SETUP_ICU],[
2204   PHP_ARG_WITH(icu-dir,,
2205   [  --with-icu-dir=DIR      Specify where ICU libraries and headers can be found], DEFAULT, no)
2207   if test "$PHP_ICU_DIR" = "no"; then
2208     PHP_ICU_DIR=DEFAULT
2209   fi
2211   if test "$PHP_ICU_DIR" = "DEFAULT"; then
2212     dnl Try to find icu-config
2213     AC_PATH_PROG(ICU_CONFIG, icu-config, no, [$PATH:/usr/local/bin])
2214   else
2215     ICU_CONFIG="$PHP_ICU_DIR/bin/icu-config"
2216   fi
2218   AC_MSG_CHECKING([for location of ICU headers and libraries])
2220   dnl Trust icu-config to know better what the install prefix is..
2221   icu_install_prefix=`$ICU_CONFIG --prefix 2> /dev/null`
2222   if test "$?" != "0" || test -z "$icu_install_prefix"; then
2223     AC_MSG_RESULT([not found])
2224     AC_MSG_ERROR([Unable to detect ICU prefix or $ICU_CONFIG failed. Please verify ICU install prefix and make sure icu-config works.])
2225   else
2226     AC_MSG_RESULT([$icu_install_prefix])
2228     dnl Check ICU version
2229     AC_MSG_CHECKING([for ICU 3.4 or greater])
2230     icu_version_full=`$ICU_CONFIG --version`
2231     ac_IFS=$IFS
2232     IFS="."
2233     set $icu_version_full
2234     IFS=$ac_IFS
2235     icu_version=`expr [$]1 \* 1000 + [$]2`
2236     AC_MSG_RESULT([found $icu_version_full])
2238     if test "$icu_version" -lt "3004"; then
2239       AC_MSG_ERROR([ICU version 3.4 or later is required])
2240     fi
2242     ICU_VERSION=$icu_version
2243     ICU_INCS=`$ICU_CONFIG --cppflags-searchpath`
2244     ICU_LIBS=`$ICU_CONFIG --ldflags --ldflags-icuio`
2245     PHP_EVAL_INCLINE($ICU_INCS)
2246     PHP_EVAL_LIBLINE($ICU_LIBS, $1)
2247   fi
2251 dnl PHP_SETUP_KERBEROS(shared-add [, action-found [, action-not-found]])
2253 dnl Common setup macro for kerberos
2255 AC_DEFUN([PHP_SETUP_KERBEROS],[
2256   found_kerberos=no
2257   unset KERBEROS_CFLAGS
2258   unset KERBEROS_LIBS
2260   dnl First try to find krb5-config
2261   if test -z "$KRB5_CONFIG"; then
2262     AC_PATH_PROG(KRB5_CONFIG, krb5-config, no, [$PATH:/usr/kerberos/bin:/usr/local/bin])
2263   fi
2265   dnl If krb5-config is found try using it
2266   if test "$PHP_KERBEROS" = "yes" && test -x "$KRB5_CONFIG"; then
2267     KERBEROS_LIBS=`$KRB5_CONFIG --libs gssapi`
2268     KERBEROS_CFLAGS=`$KRB5_CONFIG --cflags gssapi`
2270     if test -n "$KERBEROS_LIBS"; then
2271       found_kerberos=yes
2272       PHP_EVAL_LIBLINE($KERBEROS_LIBS, $1)
2273       PHP_EVAL_INCLINE($KERBEROS_CFLAGS)
2274     fi
2275   fi
2277   dnl If still not found use old skool method
2278   if test "$found_kerberos" = "no"; then
2280     if test "$PHP_KERBEROS" = "yes"; then
2281       PHP_KERBEROS="/usr/kerberos /usr/local /usr"
2282     fi
2284     for i in $PHP_KERBEROS; do
2285       if test -f $i/$PHP_LIBDIR/libkrb5.a || test -f $i/$PHP_LIBDIR/libkrb5.$SHLIB_SUFFIX_NAME; then
2286         PHP_KERBEROS_DIR=$i
2287         break
2288       fi
2289     done
2291     if test "$PHP_KERBEROS_DIR"; then
2292       found_kerberos=yes
2293       PHP_ADD_LIBPATH($PHP_KERBEROS_DIR/$PHP_LIBDIR, $1)
2294       PHP_ADD_LIBRARY(gssapi_krb5, 1, $1)
2295       PHP_ADD_LIBRARY(krb5, 1, $1)
2296       PHP_ADD_LIBRARY(k5crypto, 1, $1)
2297       PHP_ADD_LIBRARY(com_err,  1, $1)
2298       PHP_ADD_INCLUDE($PHP_KERBEROS_DIR/include)
2299     fi
2300   fi
2302   if test "$found_kerberos" = "yes"; then
2303 ifelse([$2],[],:,[$2])
2304 ifelse([$3],[],,[else $3])
2305   fi
2308 dnl 
2309 dnl PHP_SETUP_OPENSSL(shared-add [, action-found [, action-not-found]])
2311 dnl Common setup macro for openssl
2313 AC_DEFUN([PHP_SETUP_OPENSSL],[
2314   found_openssl=no
2315   unset OPENSSL_INCDIR
2316   unset OPENSSL_LIBDIR
2318   dnl Empty variable means 'no'
2319   test -z "$PHP_OPENSSL" && PHP_OPENSSL=no
2320   test -z "$PHP_IMAP_SSL" && PHP_IMAP_SSL=no
2322   dnl Fallbacks for different configure options
2323   if test "$PHP_OPENSSL" != "no"; then
2324     PHP_OPENSSL_DIR=$PHP_OPENSSL
2325   elif test "$PHP_IMAP_SSL" != "no"; then
2326     PHP_OPENSSL_DIR=$PHP_IMAP_SSL
2327   fi
2329   dnl First try to find pkg-config
2330   if test -z "$PKG_CONFIG"; then
2331     AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
2332   fi
2334   dnl If pkg-config is found try using it
2335   if test "$PHP_OPENSSL_DIR" = "yes" && test -x "$PKG_CONFIG" && $PKG_CONFIG --exists openssl; then
2336     if $PKG_CONFIG --atleast-version=0.9.6 openssl; then
2337       found_openssl=yes
2338       OPENSSL_LIBS=`$PKG_CONFIG --libs openssl`
2339       OPENSSL_INCS=`$PKG_CONFIG --cflags-only-I openssl`
2340       OPENSSL_INCDIR=`$PKG_CONFIG --variable=includedir openssl`
2341     else
2342       AC_MSG_ERROR([OpenSSL version 0.9.6 or greater required.])
2343     fi
2345     if test -n "$OPENSSL_LIBS" && test -n "$OPENSSL_INCS"; then
2346       PHP_EVAL_LIBLINE($OPENSSL_LIBS, $1)
2347       PHP_EVAL_INCLINE($OPENSSL_INCS)
2348     fi
2349   fi
2351   dnl If pkg-config fails for some reason, revert to the old method
2352   if test "$found_openssl" = "no"; then
2353   
2354     if test "$PHP_OPENSSL_DIR" = "yes"; then
2355       PHP_OPENSSL_DIR="/usr/local/ssl /usr/local /usr /usr/local/openssl"
2356     fi
2358     for i in $PHP_OPENSSL_DIR; do
2359       if test -r $i/include/openssl/evp.h; then
2360         OPENSSL_INCDIR=$i/include
2361       fi
2362       if test -r $i/$PHP_LIBDIR/libssl.a -o -r $i/$PHP_LIBDIR/libssl.$SHLIB_SUFFIX_NAME; then
2363         OPENSSL_LIBDIR=$i/$PHP_LIBDIR
2364       fi
2365       test -n "$OPENSSL_INCDIR" && test -n "$OPENSSL_LIBDIR" && break
2366     done
2368     if test -z "$OPENSSL_INCDIR"; then
2369       AC_MSG_ERROR([Cannot find OpenSSL's <evp.h>])
2370     fi
2372     if test -z "$OPENSSL_LIBDIR"; then
2373       AC_MSG_ERROR([Cannot find OpenSSL's libraries])
2374     fi
2376     old_CPPFLAGS=$CPPFLAGS
2377     CPPFLAGS=-I$OPENSSL_INCDIR
2378     AC_MSG_CHECKING([for OpenSSL version])
2379     AC_EGREP_CPP(yes,[
2380 #include <openssl/opensslv.h>
2381 #if OPENSSL_VERSION_NUMBER >= 0x0090600fL
2382   yes
2383 #endif
2384     ],[
2385       AC_MSG_RESULT([>= 0.9.6])
2386     ],[
2387       AC_MSG_ERROR([OpenSSL version 0.9.6 or greater required.])
2388     ])
2389     CPPFLAGS=$old_CPPFLAGS
2391     PHP_ADD_INCLUDE($OPENSSL_INCDIR)
2392   
2393     PHP_CHECK_LIBRARY(crypto, CRYPTO_free, [
2394       PHP_ADD_LIBRARY(crypto,,$1)
2395     ],[
2396       AC_MSG_ERROR([libcrypto not found!])
2397     ],[
2398       -L$OPENSSL_LIBDIR
2399     ])
2401     old_LIBS=$LIBS
2402     LIBS="$LIBS -lcrypto"
2403     PHP_CHECK_LIBRARY(ssl, SSL_CTX_set_ssl_version, [
2404       found_openssl=yes
2405     ],[
2406       AC_MSG_ERROR([libssl not found!])
2407     ],[
2408       -L$OPENSSL_LIBDIR
2409     ])
2410     LIBS=$old_LIBS
2411     PHP_ADD_LIBRARY(ssl,,$1)
2412     PHP_ADD_LIBRARY(crypto,,$1)
2414     PHP_ADD_LIBPATH($OPENSSL_LIBDIR, $1)
2415   fi
2417   if test "$found_openssl" = "yes"; then
2418   dnl For apache 1.3.x static build
2419   OPENSSL_INCDIR_OPT=-I$OPENSSL_INCDIR
2420   AC_SUBST(OPENSSL_INCDIR_OPT)
2422 ifelse([$2],[],:,[$2])
2423 ifelse([$3],[],,[else $3])
2424   fi
2427 dnl 
2428 dnl PHP_SETUP_ICONV(shared-add [, action-found [, action-not-found]])
2430 dnl Common setup macro for iconv
2432 AC_DEFUN([PHP_SETUP_ICONV], [
2433   found_iconv=no
2434   unset ICONV_DIR
2436   # Create the directories for a VPATH build:
2437   $php_shtool mkdir -p ext/iconv
2439   echo > ext/iconv/php_have_bsd_iconv.h
2440   echo > ext/iconv/php_have_ibm_iconv.h
2441   echo > ext/iconv/php_have_glibc_iconv.h
2442   echo > ext/iconv/php_have_libiconv.h
2443   echo > ext/iconv/php_have_iconv.h
2444   echo > ext/iconv/php_php_iconv_impl.h
2445   echo > ext/iconv/php_iconv_aliased_libiconv.h
2446   echo > ext/iconv/php_php_iconv_h_path.h
2447   echo > ext/iconv/php_iconv_supports_errno.h
2449   dnl
2450   dnl Check libc first if no path is provided in --with-iconv
2451   dnl
2453   if test "$PHP_ICONV" = "yes"; then
2454     dnl Reset LIBS temporarily as it may have already been included
2455     dnl -liconv in.
2456     LIBS_save="$LIBS"
2457     LIBS=
2458     AC_CHECK_FUNC(iconv, [
2459       found_iconv=yes
2460     ],[
2461       AC_CHECK_FUNC(libiconv,[
2462         PHP_DEFINE(HAVE_LIBICONV,1,[ext/iconv])
2463         AC_DEFINE(HAVE_LIBICONV, 1, [ ])
2464         found_iconv=yes
2465       ])
2466     ])
2467     LIBS="$LIBS_save"
2468   fi
2470   dnl
2471   dnl Check external libs for iconv funcs
2472   dnl
2473   if test "$found_iconv" = "no"; then
2475     for i in $PHP_ICONV /usr/local /usr; do
2476       if test -r $i/include/giconv.h; then
2477         AC_DEFINE(HAVE_GICONV_H, 1, [ ])
2478         ICONV_DIR=$i
2479         iconv_lib_name=giconv
2480         break
2481       elif test -r $i/include/iconv.h; then
2482         ICONV_DIR=$i
2483         iconv_lib_name=iconv
2484         break
2485       fi
2486     done
2488     if test -z "$ICONV_DIR"; then
2489       AC_MSG_ERROR([Please specify the install prefix of iconv with --with-iconv=<DIR>])
2490     fi
2491   
2492     if test -f $ICONV_DIR/$PHP_LIBDIR/lib$iconv_lib_name.a ||
2493        test -f $ICONV_DIR/$PHP_LIBDIR/lib$iconv_lib_name.$SHLIB_SUFFIX_NAME
2494     then
2495       PHP_CHECK_LIBRARY($iconv_lib_name, libiconv, [
2496         found_iconv=yes
2497         PHP_DEFINE(HAVE_LIBICONV,1,[ext/iconv])
2498         AC_DEFINE(HAVE_LIBICONV,1,[ ])
2499         PHP_DEFINE([ICONV_ALIASED_LIBICONV],1,[ext/iconv])
2500         AC_DEFINE([ICONV_ALIASED_LIBICONV],1,[iconv() is aliased to libiconv() in -liconv])
2501       ], [
2502         PHP_CHECK_LIBRARY($iconv_lib_name, iconv, [
2503           found_iconv=yes
2504         ], [], [
2505           -L$ICONV_DIR/$PHP_LIBDIR
2506         ])
2507       ], [
2508         -L$ICONV_DIR/$PHP_LIBDIR
2509       ])
2510     fi
2511   fi
2513   if test "$found_iconv" = "yes"; then
2514     PHP_DEFINE(HAVE_ICONV,1,[ext/iconv])
2515     AC_DEFINE(HAVE_ICONV,1,[ ])
2516     if test -n "$ICONV_DIR"; then
2517       PHP_ADD_LIBRARY_WITH_PATH($iconv_lib_name, $ICONV_DIR/$PHP_LIBDIR, $1)
2518       PHP_ADD_INCLUDE($ICONV_DIR/include)
2519     fi
2520     $2
2521 ifelse([$3],[],,[else $3])
2522   fi
2525 dnl 
2526 dnl PHP_SETUP_LIBXML(shared-add [, action-found [, action-not-found]])
2528 dnl Common setup macro for libxml
2530 AC_DEFUN([PHP_SETUP_LIBXML], [
2531 AC_CACHE_CHECK([for xml2-config path], ac_cv_php_xml2_config_path,
2533   for i in $PHP_LIBXML_DIR /usr/local /usr; do
2534     if test -x "$i/bin/xml2-config"; then
2535       ac_cv_php_xml2_config_path="$i/bin/xml2-config"
2536       break
2537     fi
2538   done
2541   if test -x "$ac_cv_php_xml2_config_path"; then
2542     XML2_CONFIG="$ac_cv_php_xml2_config_path"
2543     libxml_full_version=`$XML2_CONFIG --version`
2544     ac_IFS=$IFS
2545     IFS="."
2546     set $libxml_full_version
2547     IFS=$ac_IFS
2548     LIBXML_VERSION=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3`
2549     if test "$LIBXML_VERSION" -ge "2006011"; then
2550       LIBXML_LIBS=`$XML2_CONFIG --libs`
2551       LIBXML_INCS=`$XML2_CONFIG --cflags`
2552       PHP_EVAL_LIBLINE($LIBXML_LIBS, $1)
2553       PHP_EVAL_INCLINE($LIBXML_INCS)
2555       dnl Check that build works with given libs
2556       AC_CACHE_CHECK(whether libxml build works, php_cv_libxml_build_works, [
2557         PHP_TEST_BUILD(xmlInitParser,
2558         [
2559           php_cv_libxml_build_works=yes
2560         ], [
2561           AC_MSG_RESULT(no)
2562           AC_MSG_ERROR([build test failed.  Please check the config.log for details.])
2563         ], [
2564           [$]$1
2565         ])
2566       ])
2567       if test "$php_cv_libxml_build_works" = "yes"; then
2568         AC_DEFINE(HAVE_LIBXML, 1, [ ])
2569       fi
2570       $2
2571     else
2572       AC_MSG_ERROR([libxml2 version 2.6.11 or greater required.])
2573     fi
2574 ifelse([$3],[],,[else $3])
2575   fi
2578 dnl -------------------------------------------------------------------------
2579 dnl Misc. macros
2580 dnl -------------------------------------------------------------------------
2582 dnl 
2583 dnl PHP_INSTALL_HEADERS(path [, file ...])
2585 dnl PHP header files to be installed
2587 AC_DEFUN([PHP_INSTALL_HEADERS],[
2588   ifelse([$2],[],[
2589     for header_file in $1; do
2590       PHP_RUN_ONCE(INSTALLHEADERS, $header_file, [
2591         INSTALL_HEADERS="$INSTALL_HEADERS $header_file"
2592       ])
2593     done 
2594   ], [
2595     header_path=$1
2596     for header_file in $2; do
2597       hp_hf="$header_path/$header_file"
2598       PHP_RUN_ONCE(INSTALLHEADERS, $hp_hf, [
2599         INSTALL_HEADERS="$INSTALL_HEADERS $hp_hf"
2600       ])
2601     done 
2602   ])
2606 dnl PHP_AP_EXTRACT_VERSION(/path/httpd)
2608 dnl This macro is used to get a comparable
2609 dnl version for apache1/2.
2611 AC_DEFUN([PHP_AP_EXTRACT_VERSION],[
2612   ac_output=`$1 -v 2>&1 | grep version | $SED -e 's/Oracle-HTTP-//'`
2613   ac_IFS=$IFS
2614 IFS="- /.
2616   set $ac_output
2617   IFS=$ac_IFS
2619   APACHE_VERSION=`expr [$]4 \* 1000000 + [$]5 \* 1000 + [$]6`
2623 dnl PHP_DEBUG_MACRO(filename)
2624 dnl 
2625 AC_DEFUN([PHP_DEBUG_MACRO],[
2626   DEBUG_LOG=$1
2627   cat >$1 <<X
2628 CONFIGURE:  $CONFIGURE_COMMAND
2629 CC:         $CC
2630 CFLAGS:     $CFLAGS
2631 CPPFLAGS:   $CPPFLAGS
2632 CXX:        $CXX
2633 CXXFLAGS:   $CXXFLAGS
2634 INCLUDES:   $INCLUDES
2635 LDFLAGS:    $LDFLAGS
2636 LIBS:       $LIBS
2637 DLIBS:      $DLIBS
2638 SAPI:       $PHP_SAPI
2639 PHP_RPATHS: $PHP_RPATHS
2640 uname -a:   `uname -a`
2643     cat >conftest.$ac_ext <<X
2644 main()
2646   exit(0);
2649     (eval echo \"$ac_link\"; eval $ac_link && ./conftest) >>$1 2>&1
2650     rm -fr conftest*
2654 dnl PHP_CONFIG_NICE(filename)
2656 dnl Generates the config.nice file
2658 AC_DEFUN([PHP_CONFIG_NICE],[
2659   AC_REQUIRE([AC_PROG_EGREP])
2660   AC_REQUIRE([LT_AC_PROG_SED])
2661   PHP_SUBST_OLD(EGREP)
2662   PHP_SUBST_OLD(SED)
2663   test -f $1 && mv $1 $1.old
2664   rm -f $1.old
2665   cat >$1<<EOF
2666 #! /bin/sh
2668 # Created by configure
2672   for var in CFLAGS CXXFLAGS CPPFLAGS LDFLAGS EXTRA_LDFLAGS_PROGRAM LIBS CC CXX; do
2673     eval val=\$$var
2674     if test -n "$val"; then
2675       echo "$var='$val' \\" >> $1
2676     fi
2677   done
2679   echo "'[$]0' \\" >> $1
2680   if test `expr -- [$]0 : "'.*"` = 0; then
2681     CONFIGURE_COMMAND="$CONFIGURE_COMMAND '[$]0'"
2682   else 
2683     CONFIGURE_COMMAND="$CONFIGURE_COMMAND [$]0"
2684   fi
2685   for arg in $ac_configure_args; do
2686     if test `expr -- $arg : "'.*"` = 0; then
2687       if test `expr -- $arg : "--.*"` = 0; then
2688         break;
2689       fi
2690       echo "'[$]arg' \\" >> $1
2691       CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS '[$]arg'"
2692     else
2693       if test `expr -- $arg : "'--.*"` = 0; then
2694         break;
2695       fi
2696       echo "[$]arg \\" >> $1
2697       CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS [$]arg"
2698     fi
2699   done
2700   echo '"[$]@"' >> $1
2701   chmod +x $1
2702   CONFIGURE_COMMAND="$CONFIGURE_COMMAND $CONFIGURE_OPTIONS"
2703   PHP_SUBST_OLD(CONFIGURE_COMMAND)
2704   PHP_SUBST_OLD(CONFIGURE_OPTIONS)
2708 dnl PHP_CHECK_CONFIGURE_OPTIONS
2710 AC_DEFUN([PHP_CHECK_CONFIGURE_OPTIONS],[
2711   for arg in $ac_configure_args; do
2712     case $arg in
2713       --with-*[)]
2714         arg_name="`echo [$]arg | $SED -e 's/--with-/with-/g' -e 's/=.*//g'`"
2715         ;;
2716       --without-*[)]
2717         arg_name="`echo [$]arg | $SED -e 's/--without-/with-/g' -e 's/=.*//g'`"
2718         ;;
2719       --enable-*[)]
2720         arg_name="`echo [$]arg | $SED -e 's/--enable-/enable-/g' -e 's/=.*//g'`"
2721         ;;
2722       --disable-*[)]
2723         arg_name="`echo [$]arg | $SED -e 's/--disable-/enable-/g' -e 's/=.*//g'`"
2724         ;;
2725       *[)]
2726         continue
2727         ;;
2728     esac
2729     case $arg_name in
2730       # Allow --disable-all / --enable-all
2731       enable-all[)];;
2733       # Allow certain libtool options
2734       enable-libtool-lock | with-pic | with-tags | enable-shared | enable-static | enable-fast-install | with-gnu-ld[)];;
2736       # Allow certain TSRM options
2737       with-tsrm-pth | with-tsrm-st | with-tsrm-pthreads[)];;
2739       # Allow certain Zend options
2740       with-zend-vm | enable-maintainer-zts | enable-inline-optimization[)];;
2742       # All the rest must be set using the PHP_ARG_* macros
2743       # PHP_ARG_* macros set php_enable_<arg_name> or php_with_<arg_name>
2744       *[)]
2745         # Options that exist before PHP 6
2746         if test "$PHP_MAJOR_VERSION" -lt "6"; then
2747           case $arg_name in
2748             enable-zend-multibyte[)] continue;;
2749           esac 
2750         fi
2752         is_arg_set=php_[]`echo [$]arg_name | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-' 'abcdefghijklmnopqrstuvwxyz_'`
2753         if eval test "x\$$is_arg_set" = "x"; then
2754           PHP_UNKNOWN_CONFIGURE_OPTIONS="$PHP_UNKNOWN_CONFIGURE_OPTIONS
2755 [$]arg"
2756         fi
2757         ;;
2758     esac
2759   done
2763 dnl PHP_CHECK_PDO_INCLUDES([found [, not-found]])
2765 AC_DEFUN([PHP_CHECK_PDO_INCLUDES],[
2766   AC_CACHE_CHECK([for PDO includes], pdo_cv_inc_path, [
2767     AC_MSG_CHECKING([for PDO includes])
2768     if test -f $abs_srcdir/include/php/ext/pdo/php_pdo_driver.h; then
2769       pdo_cv_inc_path=$abs_srcdir/ext
2770     elif test -f $abs_srcdir/ext/pdo/php_pdo_driver.h; then
2771       pdo_cv_inc_path=$abs_srcdir/ext
2772     elif test -f $prefix/include/php/ext/pdo/php_pdo_driver.h; then
2773       pdo_cv_inc_path=$prefix/include/php/ext
2774     fi
2775   ])
2776   if test -n "$pdo_cv_inc_path"; then
2777 ifelse([$1],[],:,[$1])
2778   else
2779 ifelse([$2],[],[AC_MSG_ERROR([Cannot find php_pdo_driver.h.])],[$2])
2780   fi
2784 dnl PHP_DETECT_ICC
2785 dnl Detect Intel C++ Compiler and unset $GCC if ICC found
2786 AC_DEFUN([PHP_DETECT_ICC],
2788   ICC="no"
2789   AC_MSG_CHECKING([for icc])
2790   AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
2791     ICC="no"
2792     AC_MSG_RESULT([no]),
2793     ICC="yes"
2794     GCC="no"
2795     AC_MSG_RESULT([yes])
2796   )
2799 dnl PHP_DETECT_SUNCC
2800 dnl Detect if the systems default compiler is suncc.
2801 dnl We also set some usefull CFLAGS if the user didn't set any
2802 AC_DEFUN([PHP_DETECT_SUNCC],[
2803   SUNCC="no"
2804   AC_MSG_CHECKING([for suncc])
2805   AC_EGREP_CPP([^__SUNPRO_C], [__SUNPRO_C],
2806     SUNCC="no"
2807     AC_MSG_RESULT([no]),
2808     SUNCC="yes"
2809     GCC="no"
2810     test -n "$auto_cflags" && CFLAGS="-O -xs -xstrconst -zlazyload"
2811     GCC=""
2812     AC_MSG_RESULT([yes])
2813   )
2817 dnl PHP_CRYPT_R_STYLE
2818 dnl detect the style of crypt_r() is any is available
2819 dnl see APR_CHECK_CRYPT_R_STYLE() for original version
2821 AC_DEFUN([PHP_CRYPT_R_STYLE],
2823   AC_CACHE_CHECK([which data struct is used by crypt_r], php_cv_crypt_r_style,[
2824     php_cv_crypt_r_style=none
2825     AC_TRY_COMPILE([
2826 #define _REENTRANT 1
2827 #include <crypt.h>
2829 CRYPTD buffer;
2830 crypt_r("passwd", "hash", &buffer);
2831 ], 
2832 php_cv_crypt_r_style=cryptd)
2834     if test "$php_cv_crypt_r_style" = "none"; then
2835       AC_TRY_COMPILE([
2836 #define _REENTRANT 1
2837 #include <crypt.h>
2839 struct crypt_data buffer;
2840 crypt_r("passwd", "hash", &buffer);
2841 ], 
2842 php_cv_crypt_r_style=struct_crypt_data)
2843     fi
2845     if test "$php_cv_crypt_r_style" = "none"; then
2846       AC_TRY_COMPILE([
2847 #define _REENTRANT 1
2848 #define _GNU_SOURCE
2849 #include <crypt.h>
2851 struct crypt_data buffer;
2852 crypt_r("passwd", "hash", &buffer);
2853 ], 
2854 php_cv_crypt_r_style=struct_crypt_data_gnu_source)
2855     fi
2856     ])
2858   if test "$php_cv_crypt_r_style" = "cryptd"; then
2859     AC_DEFINE(CRYPT_R_CRYPTD, 1, [Define if crypt_r has uses CRYPTD])
2860   fi
2861   if test "$php_cv_crypt_r_style" = "struct_crypt_data" -o "$php_cv_crypt_r_style" = "struct_crypt_data_gnu_source"; then
2862     AC_DEFINE(CRYPT_R_STRUCT_CRYPT_DATA, 1, [Define if crypt_r uses struct crypt_data])
2863   fi
2864   if test "$php_cv_crypt_r_style" = "struct_crypt_data_gnu_source"; then
2865     AC_DEFINE(CRYPT_R_GNU_SOURCE, 1, [Define if struct crypt_data requires _GNU_SOURCE])
2866   fi
2867   if test "$php_cv_crypt_r_style" = "none"; then
2868     AC_MSG_ERROR([Unable to detect data struct used by crypt_r])
2869   fi
2873 dnl PHP_TEST_WRITE_STDOUT
2875 AC_DEFUN([PHP_TEST_WRITE_STDOUT],[
2876   AC_CACHE_CHECK(whether writing to stdout works,ac_cv_write_stdout,[
2877     AC_TRY_RUN([
2878 #ifdef HAVE_UNISTD_H
2879 #include <unistd.h>
2880 #endif
2882 #define TEXT "This is the test message -- "
2884 main()
2886   int n;
2888   n = write(1, TEXT, sizeof(TEXT)-1);
2889   return (!(n == sizeof(TEXT)-1));
2891     ],[
2892       ac_cv_write_stdout=yes
2893     ],[
2894       ac_cv_write_stdout=no
2895     ],[
2896       ac_cv_write_stdout=no
2897     ])
2898   ])
2899   if test "$ac_cv_write_stdout" = "yes"; then
2900     AC_DEFINE(PHP_WRITE_STDOUT, 1, [whether write(2) works])
2901   fi
2905 dnl PHP_INIT_DTRACE(providerdesc, header-file, sources [, module])
2907 AC_DEFUN([PHP_INIT_DTRACE],[
2908 dnl Set paths properly when called from extension
2909   case "$4" in
2910     ""[)] ac_srcdir="$abs_srcdir/"; unset ac_bdir;;
2911     /*[)] ac_srcdir=`echo "$4"|cut -c 2-`"/"; ac_bdir=$ac_srcdir;;
2912     *[)] ac_srcdir="$abs_srcdir/$1/"; ac_bdir="$4/";;
2913   esac
2915 dnl providerdesc
2916   ac_provsrc=$1
2917   old_IFS=[$]IFS
2918   IFS=.
2919   set $ac_provsrc
2920   ac_provobj=[$]1
2921   IFS=$old_IFS
2923 dnl header-file
2924   ac_hdrobj=$2
2926 dnl Add providerdesc.o into global objects when needed
2927   case $host_alias in
2928   *freebsd*)
2929     PHP_GLOBAL_OBJS="[$]PHP_GLOBAL_OBJS [$]ac_bdir[$]ac_provsrc.o"
2930     PHP_LDFLAGS="$PHP_LDFLAGS -lelf"
2931     ;;
2932   *solaris*)
2933     PHP_GLOBAL_OBJS="[$]PHP_GLOBAL_OBJS [$]ac_bdir[$]ac_provsrc.o"
2934     ;;
2935   esac
2937 dnl DTrace objects
2938   old_IFS=[$]IFS
2939   for ac_src in $3; do
2940     IFS=.
2941     set $ac_src
2942     ac_obj=[$]1
2943     IFS=$old_IFS
2945     PHP_DTRACE_OBJS="[$]PHP_DTRACE_OBJS [$]ac_bdir[$]ac_obj.lo"
2946   done;
2948   case [$]php_sapi_module in
2949   shared[)]
2950     for ac_lo in $PHP_DTRACE_OBJS; do
2951       dtrace_objs="[$]dtrace_objs `echo $ac_lo | $SED -e 's,\.lo$,.o,' -e 's#\(.*\)\/#\1\/.libs\/#'`"
2952     done;
2953     ;;
2954   *[)]
2955     dtrace_objs='$(PHP_DTRACE_OBJS:.lo=.o)'
2956     ;;
2957   esac
2959 dnl Generate Makefile.objects entries
2960   cat>>Makefile.objects<<EOF
2962 $ac_bdir[$]ac_hdrobj: $abs_srcdir/$ac_provsrc
2963         dtrace -h -C -s $ac_srcdir[$]ac_provsrc -o \$[]@ && \$(SED) -ibak 's,PHP_,DTRACE_,g' \$[]@
2965 \$(PHP_DTRACE_OBJS): $ac_bdir[$]ac_hdrobj
2967 $ac_bdir[$]ac_provsrc.o: \$(PHP_DTRACE_OBJS)
2968         dtrace -G -o \$[]@ -s $abs_srcdir/$ac_provsrc $dtrace_objs