xref: /PHP-5.3/acinclude.m4 (revision 08334293)
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,cli,PHP_CLI_OBJS,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_cxx_done=yes
766  fi
767])
768
769dnl
770dnl PHP_BUILD_SHARED
771dnl
772AC_DEFUN([PHP_BUILD_SHARED],[
773  PHP_BUILD_PROGRAM
774  OVERALL_TARGET=libphp[]$PHP_MAJOR_VERSION[.la]
775  php_build_target=shared
776
777  php_c_pre=$shared_c_pre
778  php_c_meta=$shared_c_meta
779  php_c_post=$shared_c_post
780  php_cxx_pre=$shared_cxx_pre
781  php_cxx_meta=$shared_cxx_meta
782  php_cxx_post=$shared_cxx_post
783  php_lo=$shared_lo
784])
785
786dnl
787dnl PHP_BUILD_STATIC
788dnl
789AC_DEFUN([PHP_BUILD_STATIC],[
790  PHP_BUILD_PROGRAM
791  OVERALL_TARGET=libphp[]$PHP_MAJOR_VERSION[.la]
792  php_build_target=static
793])
794
795dnl
796dnl PHP_BUILD_BUNDLE
797dnl
798AC_DEFUN([PHP_BUILD_BUNDLE],[
799  PHP_BUILD_PROGRAM
800  OVERALL_TARGET=libs/libphp[]$PHP_MAJOR_VERSION[.bundle]
801  php_build_target=static
802])
803
804dnl
805dnl PHP_BUILD_PROGRAM
806dnl
807AC_DEFUN([PHP_BUILD_PROGRAM],[
808  OVERALL_TARGET=[]ifelse($1,,php,$1)
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  php_build_target=program
831])
832
833dnl
834dnl PHP_SHARED_MODULE(module-name, object-var, build-dir, cxx, zend_ext)
835dnl
836dnl Basically sets up the link-stage for building module-name
837dnl from object_var in build-dir.
838dnl
839AC_DEFUN([PHP_SHARED_MODULE],[
840  install_modules="install-modules"
841
842  case $host_alias in
843    *aix*[)]
844      suffix=so
845      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'
846      ;;
847    *netware*[)]
848      suffix=nlm
849      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)'
850      ;;
851    *[)]
852      suffix=la
853      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)'
854      ;;
855  esac
856
857  if test "x$5" = "xyes"; then
858    PHP_ZEND_EX="$PHP_ZEND_EX \$(phplibdir)/$1.$suffix"
859  else
860    PHP_MODULES="$PHP_MODULES \$(phplibdir)/$1.$suffix"
861  fi
862  PHP_SUBST($2)
863  cat >>Makefile.objects<<EOF
864\$(phplibdir)/$1.$suffix: $3/$1.$suffix
865	\$(LIBTOOL) --mode=install cp $3/$1.$suffix \$(phplibdir)
866
867$3/$1.$suffix: \$($2) \$(translit($1,a-z_-,A-Z__)_SHARED_DEPENDENCIES)
868	$link_cmd
869
870EOF
871])
872
873dnl
874dnl PHP_SELECT_SAPI(name, type[, sources [, extra-cflags [, build-target]]])
875dnl
876dnl Selects the SAPI name and type (static, shared, programm)
877dnl and optionally also the source-files for the SAPI-specific
878dnl objects.
879dnl
880AC_DEFUN([PHP_SELECT_SAPI],[
881  if test "$PHP_SAPI" != "default"; then
882AC_MSG_ERROR([
883+--------------------------------------------------------------------+
884|                        *** ATTENTION ***                           |
885|                                                                    |
886| You've configured multiple SAPIs to be build. You can build only   |
887| one SAPI module and CLI binary at the same time.                   |
888+--------------------------------------------------------------------+
889])
890  fi
891
892  PHP_SAPI=$1
893
894  case "$2" in
895  static[)] PHP_BUILD_STATIC;;
896  shared[)] PHP_BUILD_SHARED;;
897  bundle[)] PHP_BUILD_BUNDLE;;
898  program[)] PHP_BUILD_PROGRAM($5);;
899  esac
900
901  ifelse($3,,,[PHP_ADD_SOURCES([sapi/$1],[$3],[$4],[sapi])])
902])
903
904dnl deprecated
905AC_DEFUN([PHP_EXTENSION],[
906  sources=`$AWK -f $abs_srcdir/build/scan_makefile_in.awk < []PHP_EXT_SRCDIR($1)[]/Makefile.in`
907
908  PHP_NEW_EXTENSION($1, $sources, $2, $3)
909
910  if test -r "$ext_srcdir/Makefile.frag"; then
911    PHP_ADD_MAKEFILE_FRAGMENT
912  fi
913])
914
915AC_DEFUN([PHP_ADD_BUILD_DIR],[
916  ifelse($2,,[
917    BUILD_DIR="$BUILD_DIR $1"
918  ], [
919    $php_shtool mkdir -p $1
920  ])
921])
922
923AC_DEFUN([PHP_GEN_BUILD_DIRS],[
924  $php_shtool mkdir -p $BUILD_DIR
925])
926
927dnl
928dnl PHP_NEW_EXTENSION(extname, sources [, shared [, sapi_class [, extra-cflags [, cxx [, zend_ext]]]]])
929dnl
930dnl Includes an extension in the build.
931dnl
932dnl "extname" is the name of the ext/ subdir where the extension resides.
933dnl "sources" is a list of files relative to the subdir which are used
934dnl to build the extension.
935dnl "shared" can be set to "shared" or "yes" to build the extension as
936dnl a dynamically loadable library. Optional parameter "sapi_class" can
937dnl be set to "cli" to mark extension build only with CLI or CGI sapi's.
938dnl "extra-cflags" are passed to the compiler, with
939dnl @ext_srcdir@ and @ext_builddir@ being substituted.
940dnl "cxx" can be used to indicate that a C++ shared module is desired.
941dnl "zend_ext" indicates a zend extension.
942AC_DEFUN([PHP_NEW_EXTENSION],[
943  ext_builddir=[]PHP_EXT_BUILDDIR($1)
944  ext_srcdir=[]PHP_EXT_SRCDIR($1)
945
946  ifelse($5,,ac_extra=,[ac_extra=`echo "$5"|$SED s#@ext_srcdir@#$ext_srcdir#g|$SED s#@ext_builddir@#$ext_builddir#g`])
947
948  if test "$3" != "shared" && test "$3" != "yes" && test "$4" != "cli"; then
949dnl ---------------------------------------------- Static module
950    [PHP_]translit($1,a-z_-,A-Z__)[_SHARED]=no
951    PHP_ADD_SOURCES(PHP_EXT_DIR($1),$2,$ac_extra,)
952    EXT_STATIC="$EXT_STATIC $1"
953    if test "$3" != "nocli"; then
954      EXT_CLI_STATIC="$EXT_CLI_STATIC $1"
955    fi
956  else
957    if test "$3" = "shared" || test "$3" = "yes"; then
958dnl ---------------------------------------------- Shared module
959      [PHP_]translit($1,a-z_-,A-Z__)[_SHARED]=yes
960      PHP_ADD_SOURCES_X(PHP_EXT_DIR($1),$2,$ac_extra,shared_objects_$1,yes)
961      case $host_alias in
962        *netware*[)]
963          PHP_SHARED_MODULE(php$1,shared_objects_$1, $ext_builddir, $6, $7)
964          ;;
965        *[)]
966          PHP_SHARED_MODULE($1,shared_objects_$1, $ext_builddir, $6, $7)
967          ;;
968      esac
969      AC_DEFINE_UNQUOTED([COMPILE_DL_]translit($1,a-z_-,A-Z__), 1, Whether to build $1 as dynamic module)
970    fi
971  fi
972
973  if test "$3" != "shared" && test "$3" != "yes" && test "$4" = "cli"; then
974dnl ---------------------------------------------- CLI static module
975    [PHP_]translit($1,a-z_-,A-Z__)[_SHARED]=no
976    case "$PHP_SAPI" in
977      cgi|embed[)]
978        PHP_ADD_SOURCES(PHP_EXT_DIR($1),$2,$ac_extra,)
979        EXT_STATIC="$EXT_STATIC $1"
980        ;;
981      *[)]
982        PHP_ADD_SOURCES(PHP_EXT_DIR($1),$2,$ac_extra,cli)
983        ;;
984    esac
985    EXT_CLI_STATIC="$EXT_CLI_STATIC $1"
986  fi
987  PHP_ADD_BUILD_DIR($ext_builddir)
988
989dnl Set for phpize builds only
990dnl ---------------------------
991  if test "$ext_builddir" = "."; then
992    PHP_PECL_EXTENSION=$1
993    PHP_SUBST(PHP_PECL_EXTENSION)
994  fi
995])
996
997dnl
998dnl PHP_WITH_SHARED
999dnl
1000dnl Checks whether $withval is "shared" or starts with "shared,XXX"
1001dnl and sets $shared to "yes" or "no", and removes "shared,?" stuff
1002dnl from $withval.
1003dnl
1004AC_DEFUN([PHP_WITH_SHARED],[
1005  PHP_ARG_ANALYZE_EX(withval)
1006  shared=$ext_shared
1007  unset ext_shared ext_output
1008])
1009
1010dnl
1011dnl PHP_ADD_EXTENSION_DEP(extname, depends [, depconf])
1012dnl
1013dnl This macro is scanned by genif.sh when it builds the internal functions
1014dnl list, so that modules can be init'd in the correct order
1015dnl $1 = name of extension, $2 = extension upon which it depends
1016dnl $3 = optional: if true, it's ok for $2 to have not been configured
1017dnl default is false and should halt the build.
1018dnl To be effective, this macro must be invoked *after* PHP_NEW_EXTENSION.
1019dnl The extension on which it depends must also have been configured.
1020dnl See ADD_EXTENSION_DEP in win32 build
1021dnl
1022AC_DEFUN([PHP_ADD_EXTENSION_DEP], [
1023  am_i_shared=$[PHP_]translit($1,a-z_-,A-Z__)[_SHARED]
1024  is_it_shared=$[PHP_]translit($2,a-z_-,A-Z__)[_SHARED]
1025  is_it_enabled=$[PHP_]translit($2,a-z_-,A-Z__)
1026  if test "$am_i_shared" = "no" && test "$is_it_shared" = "yes" ; then
1027    AC_MSG_ERROR([
1028You've configured extension $1 to build statically, but it
1029depends on extension $2, which you've configured to build shared.
1030You either need to build $1 shared or build $2 statically for the
1031build to be successful.
1032])
1033  fi
1034  if test "x$is_it_enabled" = "xno" && test "x$3" != "xtrue"; then
1035    AC_MSG_ERROR([
1036You've configured extension $1, which depends on extension $2,
1037but you've either not enabled $2, or have disabled it.
1038])
1039  fi
1040  dnl Some systems require that we link $2 to $1 when building
1041])
1042
1043dnl -------------------------------------------------------------------------
1044dnl Checks for structures, typedefs, broken functions, etc.
1045dnl -------------------------------------------------------------------------
1046
1047dnl Internal helper macros
1048dnl
1049dnl _PHP_DEF_HAVE_FILE(what, filename)
1050AC_DEFUN([_PHP_DEF_HAVE_FILE], [
1051  php_def_have_what=HAVE_[]`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz-' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_' `
1052  echo "#define $php_def_have_what 1" >> $2
1053])
1054dnl
1055dnl _PHP_CHECK_SIZEOF(type, cross-value, extra-headers [, found-action [, not-found-action]])
1056dnl
1057AC_DEFUN([_PHP_CHECK_SIZEOF], [
1058  php_cache_value=php_cv_sizeof_[]$1
1059  AC_CACHE_VAL(php_cv_sizeof_[]$1, [
1060    old_LIBS=$LIBS
1061    LIBS=
1062    old_LDFLAGS=$LDFLAGS
1063    LDFLAGS=
1064    AC_TRY_RUN([#include <stdio.h>
1065#if STDC_HEADERS
1066#include <stdlib.h>
1067#include <stddef.h>
1068#endif
1069#ifdef HAVE_INTTYPES_H
1070#include <inttypes.h>
1071#endif
1072#ifdef HAVE_UNISTD_H
1073#include <unistd.h>
1074#endif
1075$3
1076
1077int main()
1078{
1079	FILE *fp = fopen("conftestval", "w");
1080	if (!fp) return(1);
1081	fprintf(fp, "%d\n", sizeof($1));
1082	return(0);
1083}
1084  ], [
1085    eval $php_cache_value=`cat conftestval`
1086  ], [
1087    eval $php_cache_value=0
1088  ], [
1089    ifelse([$2],,[eval $php_cache_value=0], [eval $php_cache_value=$2])
1090])
1091  LDFLAGS=$old_LDFLAGS
1092  LIBS=$old_LIBS
1093])
1094  if eval test "\$$php_cache_value" != "0"; then
1095ifelse([$4],[],:,[$4])
1096ifelse([$5],[],,[else $5])
1097  fi
1098])
1099
1100dnl
1101dnl PHP_CHECK_SIZEOF(type, cross-value, extra-headers)
1102dnl
1103AC_DEFUN([PHP_CHECK_SIZEOF], [
1104  AC_MSG_CHECKING([size of $1])
1105  _PHP_CHECK_SIZEOF($1, $2, $3, [
1106    AC_DEFINE_UNQUOTED([SIZEOF_]translit($1,a-z,A-Z_), [$]php_cv_sizeof_[]$1, [Size of $1])
1107    AC_DEFINE_UNQUOTED([HAVE_]translit($1,a-z,A-Z_), 1, [Whether $1 is available])
1108  ])
1109  AC_MSG_RESULT([[$][php_cv_sizeof_]translit($1, ,_)])
1110])
1111
1112dnl
1113dnl PHP_CHECK_TYPES(type-list, include-file [, extra-headers])
1114dnl
1115AC_DEFUN([PHP_CHECK_TYPES], [
1116  for php_typename in $1; do
1117    AC_MSG_CHECKING([whether $php_typename exists])
1118    _PHP_CHECK_SIZEOF($php_typename, 0, $3, [
1119      _PHP_DEF_HAVE_FILE($php_typename, $2)
1120      AC_MSG_RESULT([yes])
1121    ], [
1122      AC_MSG_RESULT([no])
1123    ])
1124  done
1125])
1126
1127dnl
1128dnl PHP_CHECK_IN_ADDR_T
1129dnl
1130AC_DEFUN([PHP_CHECK_IN_ADDR_T], [
1131dnl AIX keeps in_addr_t in /usr/include/netinet/in.h
1132AC_MSG_CHECKING([for in_addr_t])
1133AC_CACHE_VAL(ac_cv_type_in_addr_t,
1134[AC_EGREP_CPP(dnl
1135changequote(<<,>>)dnl
1136<<in_addr_t[^a-zA-Z_0-9]>>dnl
1137changequote([,]), [#include <sys/types.h>
1138#if STDC_HEADERS
1139#include <stdlib.h>
1140#include <stddef.h>
1141#endif
1142#ifdef HAVE_NETINET_IN_H
1143#include <netinet/in.h>
1144#endif], ac_cv_type_in_addr_t=yes, ac_cv_type_in_addr_t=no)])dnl
1145AC_MSG_RESULT([$ac_cv_type_in_addr_t])
1146if test $ac_cv_type_in_addr_t = no; then
1147  AC_DEFINE(in_addr_t, u_int, [ ])
1148fi
1149])
1150
1151dnl
1152dnl PHP_TIME_R_TYPE
1153dnl
1154dnl Check type of reentrant time-related functions
1155dnl Type can be: irix, hpux or POSIX
1156dnl
1157AC_DEFUN([PHP_TIME_R_TYPE],[
1158AC_CACHE_CHECK(for type of reentrant time-related functions, ac_cv_time_r_type,[
1159AC_TRY_RUN([
1160#include <time.h>
1161
1162main() {
1163char buf[27];
1164struct tm t;
1165time_t old = 0;
1166int r, s;
1167
1168s = gmtime_r(&old, &t);
1169r = (int) asctime_r(&t, buf, 26);
1170if (r == s && s == 0) return (0);
1171return (1);
1172}
1173],[
1174  ac_cv_time_r_type=hpux
1175],[
1176  AC_TRY_RUN([
1177#include <time.h>
1178main() {
1179  struct tm t, *s;
1180  time_t old = 0;
1181  char buf[27], *p;
1182
1183  s = gmtime_r(&old, &t);
1184  p = asctime_r(&t, buf, 26);
1185  if (p == buf && s == &t) return (0);
1186  return (1);
1187}
1188  ],[
1189    ac_cv_time_r_type=irix
1190  ],[
1191    ac_cv_time_r_type=POSIX
1192  ],[
1193    ac_cv_time_r_type=POSIX
1194  ])
1195],[
1196  ac_cv_time_r_type=POSIX
1197])
1198])
1199  case $ac_cv_time_r_type in
1200  hpux[)] AC_DEFINE(PHP_HPUX_TIME_R,1,[Whether you have HP-UX 10.x]) ;;
1201  irix[)] AC_DEFINE(PHP_IRIX_TIME_R,1,[Whether you have IRIX-style functions]) ;;
1202  esac
1203])
1204
1205dnl
1206dnl PHP_DOES_PWRITE_WORK
1207dnl internal
1208AC_DEFUN([PHP_DOES_PWRITE_WORK],[
1209  AC_TRY_RUN([
1210#include <sys/types.h>
1211#include <sys/stat.h>
1212#include <fcntl.h>
1213#include <unistd.h>
1214#include <errno.h>
1215$1
1216    main() {
1217    int fd = open("conftest_in", O_WRONLY|O_CREAT, 0600);
1218
1219    if (fd < 0) exit(1);
1220    if (pwrite(fd, "text", 4, 0) != 4) exit(1);
1221    /* Linux glibc breakage until 2.2.5 */
1222    if (pwrite(fd, "text", 4, -1) != -1 || errno != EINVAL) exit(1);
1223    exit(0);
1224    }
1225
1226  ],[
1227    ac_cv_pwrite=yes
1228  ],[
1229    ac_cv_pwrite=no
1230  ],[
1231    ac_cv_pwrite=no
1232  ])
1233])
1234
1235dnl PHP_DOES_PREAD_WORK
1236dnl internal
1237AC_DEFUN([PHP_DOES_PREAD_WORK],[
1238  echo test > conftest_in
1239  AC_TRY_RUN([
1240#include <sys/types.h>
1241#include <sys/stat.h>
1242#include <fcntl.h>
1243#include <unistd.h>
1244#include <errno.h>
1245$1
1246    main() {
1247    char buf[3];
1248    int fd = open("conftest_in", O_RDONLY);
1249    if (fd < 0) exit(1);
1250    if (pread(fd, buf, 2, 0) != 2) exit(1);
1251    /* Linux glibc breakage until 2.2.5 */
1252    if (pread(fd, buf, 2, -1) != -1 || errno != EINVAL) exit(1);
1253    exit(0);
1254    }
1255  ],[
1256    ac_cv_pread=yes
1257  ],[
1258    ac_cv_pread=no
1259  ],[
1260    ac_cv_pread=no
1261  ])
1262  rm -f conftest_in
1263])
1264
1265dnl
1266dnl PHP_PWRITE_TEST
1267dnl
1268AC_DEFUN([PHP_PWRITE_TEST],[
1269  AC_CACHE_CHECK(whether pwrite works,ac_cv_pwrite,[
1270    PHP_DOES_PWRITE_WORK
1271    if test "$ac_cv_pwrite" = "no"; then
1272      PHP_DOES_PWRITE_WORK([ssize_t pwrite(int, void *, size_t, off64_t);])
1273      if test "$ac_cv_pwrite" = "yes"; then
1274        ac_cv_pwrite=64
1275      fi
1276    fi
1277  ])
1278
1279  if test "$ac_cv_pwrite" != "no"; then
1280    AC_DEFINE(HAVE_PWRITE, 1, [ ])
1281    if test "$ac_cv_pwrite" = "64"; then
1282      AC_DEFINE(PHP_PWRITE_64, 1, [whether pwrite64 is default])
1283    fi
1284  fi
1285])
1286
1287dnl
1288dnl PHP_PREAD_TEST
1289dnl
1290AC_DEFUN([PHP_PREAD_TEST],[
1291  AC_CACHE_CHECK(whether pread works,ac_cv_pread,[
1292    PHP_DOES_PREAD_WORK
1293    if test "$ac_cv_pread" = "no"; then
1294      PHP_DOES_PREAD_WORK([ssize_t pread(int, void *, size_t, off64_t);])
1295      if test "$ac_cv_pread" = "yes"; then
1296        ac_cv_pread=64
1297      fi
1298    fi
1299  ])
1300
1301  if test "$ac_cv_pread" != "no"; then
1302    AC_DEFINE(HAVE_PREAD, 1, [ ])
1303    if test "$ac_cv_pread" = "64"; then
1304      AC_DEFINE(PHP_PREAD_64, 1, [whether pread64 is default])
1305    fi
1306  fi
1307])
1308
1309dnl
1310dnl PHP_MISSING_TIME_R_DECL
1311dnl
1312AC_DEFUN([PHP_MISSING_TIME_R_DECL],[
1313  AC_MSG_CHECKING([for missing declarations of reentrant functions])
1314  AC_TRY_COMPILE([#include <time.h>],[struct tm *(*func)() = localtime_r],[
1315    :
1316  ],[
1317    AC_DEFINE(MISSING_LOCALTIME_R_DECL,1,[Whether localtime_r is declared])
1318  ])
1319  AC_TRY_COMPILE([#include <time.h>],[struct tm *(*func)() = gmtime_r],[
1320    :
1321  ],[
1322    AC_DEFINE(MISSING_GMTIME_R_DECL,1,[Whether gmtime_r is declared])
1323  ])
1324  AC_TRY_COMPILE([#include <time.h>],[char *(*func)() = asctime_r],[
1325    :
1326  ],[
1327    AC_DEFINE(MISSING_ASCTIME_R_DECL,1,[Whether asctime_r is declared])
1328  ])
1329  AC_TRY_COMPILE([#include <time.h>],[char *(*func)() = ctime_r],[
1330    :
1331  ],[
1332    AC_DEFINE(MISSING_CTIME_R_DECL,1,[Whether ctime_r is declared])
1333  ])
1334  AC_TRY_COMPILE([#include <string.h>],[char *(*func)() = strtok_r],[
1335    :
1336  ],[
1337    AC_DEFINE(MISSING_STRTOK_R_DECL,1,[Whether strtok_r is declared])
1338  ])
1339  AC_MSG_RESULT([done])
1340])
1341
1342dnl
1343dnl PHP_READDIR_R_TYPE
1344dnl
1345AC_DEFUN([PHP_READDIR_R_TYPE],[
1346  dnl HAVE_READDIR_R is also defined by libmysql
1347  AC_CHECK_FUNC(readdir_r,ac_cv_func_readdir_r=yes,ac_cv_func_readdir=no)
1348  if test "$ac_cv_func_readdir_r" = "yes"; then
1349  AC_CACHE_CHECK(for type of readdir_r, ac_cv_what_readdir_r,[
1350    AC_TRY_RUN([
1351#define _REENTRANT
1352#include <sys/types.h>
1353#include <dirent.h>
1354
1355#ifndef PATH_MAX
1356#define PATH_MAX 1024
1357#endif
1358
1359main() {
1360  DIR *dir;
1361  char entry[sizeof(struct dirent)+PATH_MAX];
1362  struct dirent *pentry = (struct dirent *) &entry;
1363
1364  dir = opendir("/");
1365  if (!dir)
1366    exit(1);
1367  if (readdir_r(dir, (struct dirent *) entry, &pentry) == 0)
1368    exit(0);
1369  exit(1);
1370}
1371    ],[
1372      ac_cv_what_readdir_r=POSIX
1373    ],[
1374      AC_TRY_CPP([
1375#define _REENTRANT
1376#include <sys/types.h>
1377#include <dirent.h>
1378int readdir_r(DIR *, struct dirent *);
1379        ],[
1380          ac_cv_what_readdir_r=old-style
1381        ],[
1382          ac_cv_what_readdir_r=none
1383      ])
1384    ],[
1385      ac_cv_what_readdir_r=none
1386   ])
1387  ])
1388    case $ac_cv_what_readdir_r in
1389    POSIX)
1390      AC_DEFINE(HAVE_POSIX_READDIR_R,1,[whether you have POSIX readdir_r]);;
1391    old-style)
1392      AC_DEFINE(HAVE_OLD_READDIR_R,1,[whether you have old-style readdir_r]);;
1393    esac
1394  fi
1395])
1396
1397dnl
1398dnl PHP_TM_GMTOFF
1399dnl
1400AC_DEFUN([PHP_TM_GMTOFF],[
1401AC_CACHE_CHECK([for tm_gmtoff in struct tm], ac_cv_struct_tm_gmtoff,
1402[AC_TRY_COMPILE([#include <sys/types.h>
1403#include <$ac_cv_struct_tm>], [struct tm tm; tm.tm_gmtoff;],
1404  ac_cv_struct_tm_gmtoff=yes, ac_cv_struct_tm_gmtoff=no)])
1405
1406if test "$ac_cv_struct_tm_gmtoff" = yes; then
1407  AC_DEFINE(HAVE_TM_GMTOFF,1,[whether you have tm_gmtoff in struct tm])
1408fi
1409])
1410
1411dnl
1412dnl PHP_STRUCT_FLOCK
1413dnl
1414AC_DEFUN([PHP_STRUCT_FLOCK],[
1415AC_CACHE_CHECK(for struct flock,ac_cv_struct_flock,
1416    AC_TRY_COMPILE([
1417#include <unistd.h>
1418#include <fcntl.h>
1419        ],
1420        [struct flock x;],
1421        [
1422          ac_cv_struct_flock=yes
1423        ],[
1424          ac_cv_struct_flock=no
1425        ])
1426)
1427if test "$ac_cv_struct_flock" = "yes" ; then
1428    AC_DEFINE(HAVE_STRUCT_FLOCK, 1,[whether you have struct flock])
1429fi
1430])
1431
1432dnl
1433dnl PHP_SOCKLEN_T
1434dnl
1435AC_DEFUN([PHP_SOCKLEN_T],[
1436AC_CACHE_CHECK(for socklen_t,ac_cv_socklen_t,
1437  AC_TRY_COMPILE([
1438#include <sys/types.h>
1439#include <sys/socket.h>
1440],[
1441socklen_t x;
1442],[
1443  ac_cv_socklen_t=yes
1444],[
1445  ac_cv_socklen_t=no
1446]))
1447if test "$ac_cv_socklen_t" = "yes"; then
1448  AC_DEFINE(HAVE_SOCKLEN_T, 1, [Whether you have socklen_t])
1449fi
1450])
1451
1452dnl
1453dnl PHP_MISSING_FCLOSE_DECL
1454dnl
1455dnl See if we have broken header files like SunOS has.
1456dnl
1457AC_DEFUN([PHP_MISSING_FCLOSE_DECL],[
1458  AC_MSG_CHECKING([for fclose declaration])
1459  AC_TRY_COMPILE([#include <stdio.h>],[int (*func)() = fclose],[
1460    AC_DEFINE(MISSING_FCLOSE_DECL,0,[ ])
1461    AC_MSG_RESULT([ok])
1462  ],[
1463    AC_DEFINE(MISSING_FCLOSE_DECL,1,[ ])
1464    AC_MSG_RESULT([missing])
1465  ])
1466])
1467
1468dnl
1469dnl PHP_AC_BROKEN_SPRINTF
1470dnl
1471dnl Check for broken sprintf(), C99 conformance
1472dnl
1473AC_DEFUN([PHP_AC_BROKEN_SPRINTF],[
1474  AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[
1475    AC_TRY_RUN([main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[
1476      ac_cv_broken_sprintf=no
1477    ],[
1478      ac_cv_broken_sprintf=yes
1479    ],[
1480      ac_cv_broken_sprintf=no
1481    ])
1482  ])
1483  if test "$ac_cv_broken_sprintf" = "yes"; then
1484    AC_DEFINE(PHP_BROKEN_SPRINTF, 1, [Whether sprintf is C99 conform])
1485  else
1486    AC_DEFINE(PHP_BROKEN_SPRINTF, 0, [Whether sprintf is C99 conform])
1487  fi
1488])
1489
1490dnl
1491dnl PHP_AC_BROKEN_SNPRINTF
1492dnl
1493dnl Check for broken snprintf(), C99 conformance
1494dnl
1495AC_DEFUN([PHP_AC_BROKEN_SNPRINTF],[
1496  AC_CACHE_CHECK(whether snprintf is broken, ac_cv_broken_snprintf,[
1497    AC_TRY_RUN([
1498#define NULL (0L)
1499main() {
1500  char buf[20];
1501  int res = 0;
1502  res = res || (snprintf(buf, 2, "marcus") != 6);
1503  res = res || (buf[1] != '\0');
1504  /* Implementations may consider this as an encoding error */
1505  snprintf(buf, 0, "boerger");
1506  /* However, they MUST ignore the pointer */
1507  res = res || (buf[0] != 'm');
1508  res = res || (snprintf(NULL, 0, "boerger") != 7);
1509  res = res || (snprintf(buf, sizeof(buf), "%f", 0.12345678) != 8);
1510  exit(res);
1511}
1512    ],[
1513      ac_cv_broken_snprintf=no
1514    ],[
1515      ac_cv_broken_snprintf=yes
1516    ],[
1517      ac_cv_broken_snprintf=no
1518    ])
1519  ])
1520  if test "$ac_cv_broken_snprintf" = "yes"; then
1521    AC_DEFINE(PHP_BROKEN_SNPRINTF, 1, [Whether snprintf is C99 conform])
1522  else
1523    AC_DEFINE(PHP_BROKEN_SNPRINTF, 0, [Whether snprintf is C99 conform])
1524  fi
1525])
1526
1527dnl
1528dnl PHP_SOLARIS_PIC_WEIRDNESS
1529dnl
1530dnl Solaris requires main code to be position independent in order
1531dnl to let shared objects find symbols.  Weird.  Ugly.
1532dnl
1533dnl Must be run after all --with-NN options that let the user
1534dnl choose dynamic extensions, and after the gcc test.
1535dnl
1536AC_DEFUN([PHP_SOLARIS_PIC_WEIRDNESS],[
1537  AC_MSG_CHECKING([whether -fPIC is required])
1538  if test -n "$EXT_SHARED"; then
1539    os=`uname -sr 2>/dev/null`
1540    case $os in
1541      "SunOS 5.6"|"SunOS 5.7"[)]
1542        case $CC in
1543          gcc*|egcs*)
1544            CFLAGS="$CFLAGS -fPIC";;
1545          *[)]
1546            CFLAGS="$CFLAGS -fpic";;
1547        esac
1548        AC_MSG_RESULT([yes]);;
1549      *[)]
1550        AC_MSG_RESULT([no]);;
1551    esac
1552  else
1553    AC_MSG_RESULT([no])
1554  fi
1555])
1556
1557dnl
1558dnl PHP_SYS_LFS
1559dnl
1560dnl The problem is that the default compilation flags in Solaris 2.6 won't
1561dnl let programs access large files;  you need to tell the compiler that
1562dnl you actually want your programs to work on large files.  For more
1563dnl details about this brain damage please see:
1564dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
1565dnl
1566dnl Written by Paul Eggert <eggert@twinsun.com>.
1567dnl
1568AC_DEFUN([PHP_SYS_LFS],
1569[dnl
1570  # If available, prefer support for large files unless the user specified
1571  # one of the CPPFLAGS, LDFLAGS, or LIBS variables.
1572  AC_MSG_CHECKING([whether large file support needs explicit enabling])
1573  ac_getconfs=''
1574  ac_result=yes
1575  ac_set=''
1576  ac_shellvars='CPPFLAGS LDFLAGS LIBS'
1577  for ac_shellvar in $ac_shellvars; do
1578    case $ac_shellvar in
1579      CPPFLAGS[)] ac_lfsvar=LFS_CFLAGS ;;
1580      *[)] ac_lfsvar=LFS_$ac_shellvar ;;
1581    esac
1582    eval test '"${'$ac_shellvar'+set}"' = set && ac_set=$ac_shellvar
1583    (getconf $ac_lfsvar) >/dev/null 2>&1 || { ac_result=no; break; }
1584    ac_getconf=`getconf $ac_lfsvar`
1585    ac_getconfs=$ac_getconfs$ac_getconf
1586    eval ac_test_$ac_shellvar=\$ac_getconf
1587  done
1588  case "$ac_result$ac_getconfs" in
1589    yes[)] ac_result=no ;;
1590  esac
1591  case "$ac_result$ac_set" in
1592    yes?*[)] ac_result="yes, but $ac_set is already set, so use its settings"
1593  esac
1594  AC_MSG_RESULT([$ac_result])
1595  case $ac_result in
1596    yes[)]
1597      for ac_shellvar in $ac_shellvars; do
1598        eval $ac_shellvar=\$ac_test_$ac_shellvar
1599      done ;;
1600  esac
1601])
1602
1603dnl
1604dnl PHP_SOCKADDR_CHECKS
1605dnl
1606AC_DEFUN([PHP_SOCKADDR_CHECKS], [
1607  dnl Check for struct sockaddr_storage exists
1608  AC_CACHE_CHECK([for struct sockaddr_storage], ac_cv_sockaddr_storage,
1609    [AC_TRY_COMPILE([#include <sys/types.h>
1610#include <sys/socket.h>],
1611    [struct sockaddr_storage s; s],
1612    [ac_cv_sockaddr_storage=yes], [ac_cv_sockaddr_storage=no])
1613  ])
1614  if test "$ac_cv_sockaddr_storage" = "yes"; then
1615    AC_DEFINE(HAVE_SOCKADDR_STORAGE, 1, [Whether you have struct sockaddr_storage])
1616  fi
1617  dnl Check if field sa_len exists in struct sockaddr
1618  AC_CACHE_CHECK([for field sa_len in struct sockaddr],ac_cv_sockaddr_sa_len,[
1619    AC_TRY_COMPILE([#include <sys/types.h>
1620#include <sys/socket.h>],
1621    [static struct sockaddr sa; int n = (int) sa.sa_len; return n;],
1622    [ac_cv_sockaddr_sa_len=yes], [ac_cv_sockaddr_sa_len=no])
1623  ])
1624  if test "$ac_cv_sockaddr_sa_len" = "yes"; then
1625    AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has field sa_len])
1626  fi
1627])
1628
1629dnl
1630dnl PHP_DECLARED_TIMEZONE
1631dnl
1632AC_DEFUN([PHP_DECLARED_TIMEZONE],[
1633  AC_CACHE_CHECK(for declared timezone, ac_cv_declared_timezone,[
1634    AC_TRY_COMPILE([
1635#include <sys/types.h>
1636#include <time.h>
1637#ifdef HAVE_SYS_TIME_H
1638#include <sys/time.h>
1639#endif
1640],[
1641    time_t foo = (time_t) timezone;
1642],[
1643  ac_cv_declared_timezone=yes
1644],[
1645  ac_cv_declared_timezone=no
1646])])
1647  if test "$ac_cv_declared_timezone" = "yes"; then
1648    AC_DEFINE(HAVE_DECLARED_TIMEZONE, 1, [Whether system headers declare timezone])
1649  fi
1650])
1651
1652dnl
1653dnl PHP_EBCDIC
1654dnl
1655AC_DEFUN([PHP_EBCDIC], [
1656  AC_CACHE_CHECK([whether system uses EBCDIC],ac_cv_ebcdic,[
1657  AC_TRY_RUN( [
1658int main(void) {
1659  return (unsigned char)'A' != (unsigned char)0xC1;
1660}
1661],[
1662  ac_cv_ebcdic=yes
1663],[
1664  ac_cv_ebcdic=no
1665],[
1666  ac_cv_ebcdic=no
1667])])
1668  if test "$ac_cv_ebcdic" = "yes"; then
1669    AC_DEFINE(CHARSET_EBCDIC,1, [Define if system uses EBCDIC])
1670  fi
1671])
1672
1673dnl
1674dnl PHP_BROKEN_GETCWD
1675dnl
1676dnl Some systems, notably Solaris, cause getcwd() or realpath to fail if a
1677dnl component of the path has execute but not read permissions
1678dnl
1679AC_DEFUN([PHP_BROKEN_GETCWD],[
1680  AC_MSG_CHECKING([for broken getcwd])
1681  os=`uname -sr 2>/dev/null`
1682  case $os in
1683    SunOS*[)]
1684      AC_DEFINE(HAVE_BROKEN_GETCWD,1, [Define if system has broken getcwd])
1685      AC_MSG_RESULT([yes]);;
1686    *[)]
1687      AC_MSG_RESULT([no]);;
1688  esac
1689])
1690
1691dnl
1692dnl PHP_BROKEN_GLIBC_FOPEN_APPEND
1693dnl
1694AC_DEFUN([PHP_BROKEN_GLIBC_FOPEN_APPEND], [
1695  AC_MSG_CHECKING([for broken libc stdio])
1696  AC_CACHE_VAL(_cv_have_broken_glibc_fopen_append,[
1697  AC_TRY_RUN([
1698#include <stdio.h>
1699int main(int argc, char *argv[])
1700{
1701  FILE *fp;
1702  long position;
1703  char *filename = tmpnam(NULL);
1704
1705  fp = fopen(filename, "w");
1706  if (fp == NULL) {
1707    perror("fopen");
1708    exit(2);
1709  }
1710  fputs("foobar", fp);
1711  fclose(fp);
1712
1713  fp = fopen(filename, "a+");
1714  position = ftell(fp);
1715  fclose(fp);
1716  unlink(filename);
1717  if (position == 0)
1718  return 1;
1719  return 0;
1720}
1721],
1722[_cv_have_broken_glibc_fopen_append=no],
1723[_cv_have_broken_glibc_fopen_append=yes ],
1724AC_TRY_COMPILE([
1725#include <features.h>
1726],[
1727#if !__GLIBC_PREREQ(2,2)
1728choke me
1729#endif
1730],
1731[_cv_have_broken_glibc_fopen_append=yes],
1732[_cv_have_broken_glibc_fopen_append=no ])
1733)])
1734
1735  if test "$_cv_have_broken_glibc_fopen_append" = "yes"; then
1736    AC_MSG_RESULT(yes)
1737    AC_DEFINE(HAVE_BROKEN_GLIBC_FOPEN_APPEND,1, [Define if your glibc borks on fopen with mode a+])
1738  else
1739    AC_MSG_RESULT(no)
1740  fi
1741])
1742
1743dnl
1744dnl PHP_FOPENCOOKIE
1745dnl
1746AC_DEFUN([PHP_FOPENCOOKIE], [
1747  AC_CHECK_FUNC(fopencookie, [have_glibc_fopencookie=yes])
1748
1749  if test "$have_glibc_fopencookie" = "yes"; then
1750dnl this comes in two flavors:
1751dnl newer glibcs (since 2.1.2 ? )
1752dnl have a type called cookie_io_functions_t
1753AC_TRY_COMPILE([
1754#define _GNU_SOURCE
1755#include <stdio.h>
1756], [cookie_io_functions_t cookie;], [have_cookie_io_functions_t=yes], [])
1757
1758    if test "$have_cookie_io_functions_t" = "yes"; then
1759      cookie_io_functions_t=cookie_io_functions_t
1760      have_fopen_cookie=yes
1761
1762dnl even newer glibcs have a different seeker definition...
1763AC_TRY_RUN([
1764#define _GNU_SOURCE
1765#include <stdio.h>
1766
1767struct cookiedata {
1768  __off64_t pos;
1769};
1770
1771__ssize_t reader(void *cookie, char *buffer, size_t size)
1772{ return size; }
1773__ssize_t writer(void *cookie, const char *buffer, size_t size)
1774{ return size; }
1775int closer(void *cookie)
1776{ return 0; }
1777int seeker(void *cookie, __off64_t *position, int whence)
1778{ ((struct cookiedata*)cookie)->pos = *position; return 0; }
1779
1780cookie_io_functions_t funcs = {reader, writer, seeker, closer};
1781
1782main() {
1783  struct cookiedata g = { 0 };
1784  FILE *fp = fopencookie(&g, "r", funcs);
1785
1786  if (fp && fseek(fp, 8192, SEEK_SET) == 0 && g.pos == 8192)
1787    exit(0);
1788  exit(1);
1789}
1790
1791], [
1792  cookie_io_functions_use_off64_t=yes
1793], [
1794  cookie_io_functions_use_off64_t=no
1795], [
1796  cookie_io_functions_use_off64_t=no
1797])
1798
1799    else
1800
1801dnl older glibc versions (up to 2.1.2 ?)
1802dnl call it _IO_cookie_io_functions_t
1803AC_TRY_COMPILE([
1804#define _GNU_SOURCE
1805#include <stdio.h>
1806], [ _IO_cookie_io_functions_t cookie; ], [have_IO_cookie_io_functions_t=yes], [])
1807      if test "$have_cookie_io_functions_t" = "yes" ; then
1808        cookie_io_functions_t=_IO_cookie_io_functions_t
1809        have_fopen_cookie=yes
1810      fi
1811    fi
1812
1813    if test "$have_fopen_cookie" = "yes" ; then
1814      AC_DEFINE(HAVE_FOPENCOOKIE, 1, [ ])
1815      AC_DEFINE_UNQUOTED(COOKIE_IO_FUNCTIONS_T, $cookie_io_functions_t, [ ])
1816      if test "$cookie_io_functions_use_off64_t" = "yes" ; then
1817        AC_DEFINE(COOKIE_SEEKER_USES_OFF64_T, 1, [ ])
1818      fi
1819    fi
1820  fi
1821])
1822
1823dnl -------------------------------------------------------------------------
1824dnl Library/function existance and build sanity checks
1825dnl -------------------------------------------------------------------------
1826
1827dnl
1828dnl PHP_CHECK_LIBRARY(library, function [, action-found [, action-not-found [, extra-libs]]])
1829dnl
1830dnl Wrapper for AC_CHECK_LIB
1831dnl
1832AC_DEFUN([PHP_CHECK_LIBRARY], [
1833  save_old_LDFLAGS=$LDFLAGS
1834  ac_stuff="$5"
1835
1836  save_ext_shared=$ext_shared
1837  ext_shared=yes
1838  PHP_EVAL_LIBLINE([$]ac_stuff, LDFLAGS)
1839  AC_CHECK_LIB([$1],[$2],[
1840    LDFLAGS=$save_old_LDFLAGS
1841    ext_shared=$save_ext_shared
1842    $3
1843  ],[
1844    LDFLAGS=$save_old_LDFLAGS
1845    ext_shared=$save_ext_shared
1846    unset ac_cv_lib_$1[]_$2
1847    $4
1848  ])dnl
1849])
1850
1851dnl
1852dnl PHP_CHECK_FRAMEWORK(framework, function [, action-found [, action-not-found ]])
1853dnl
1854dnl El cheapo wrapper for AC_CHECK_LIB
1855dnl
1856AC_DEFUN([PHP_CHECK_FRAMEWORK], [
1857  save_old_LDFLAGS=$LDFLAGS
1858  LDFLAGS="-framework $1 $LDFLAGS"
1859  dnl supplying "c" to AC_CHECK_LIB is technically cheating, but
1860  dnl rewriting AC_CHECK_LIB is overkill and this only affects
1861  dnl the "checking.." output anyway.
1862  AC_CHECK_LIB(c,[$2],[
1863    LDFLAGS=$save_old_LDFLAGS
1864    $3
1865  ],[
1866    LDFLAGS=$save_old_LDFLAGS
1867    $4
1868  ])
1869])
1870
1871dnl
1872dnl PHP_CHECK_FUNC_LIB(func, libs)
1873dnl
1874dnl This macro checks whether 'func' or '__func' exists
1875dnl in the specified library.
1876dnl Defines HAVE_func and HAVE_library if found and adds the library to LIBS.
1877dnl This should be called in the ACTION-IF-NOT-FOUND part of PHP_CHECK_FUNC
1878dnl
1879dnl
1880dnl autoconf undefines the builtin "shift" :-(
1881dnl If possible, we use the builtin shift anyway, otherwise we use
1882dnl the ubercool definition I have tested so far with FreeBSD/GNU m4
1883ifdef([builtin],[builtin(define, phpshift, [builtin(shift, $@)])],[
1884define([phpshift],[ifelse(index([$@],[,]),-1,,[substr([$@],incr(index([$@],[,])))])])
1885])
1886dnl
1887AC_DEFUN([PHP_CHECK_FUNC_LIB],[
1888  ifelse($2,,:,[
1889  unset ac_cv_lib_$2[]_$1
1890  unset ac_cv_lib_$2[]___$1
1891  unset found
1892  AC_CHECK_LIB($2, $1, [found=yes], [
1893    AC_CHECK_LIB($2, __$1, [found=yes], [found=no])
1894  ])
1895
1896  if test "$found" = "yes"; then
1897    ac_libs=$LIBS
1898    LIBS="$LIBS -l$2"
1899    AC_TRY_RUN([main() { return (0); }],[found=yes],[found=no],[found=no])
1900    LIBS=$ac_libs
1901  fi
1902
1903  if test "$found" = "yes"; then
1904    PHP_ADD_LIBRARY($2)
1905    PHP_DEF_HAVE($1)
1906    PHP_DEF_HAVE(lib$2)
1907    ac_cv_func_$1=yes
1908  else
1909    PHP_CHECK_FUNC_LIB($1,phpshift(phpshift($@)))
1910  fi
1911  ])
1912])
1913
1914dnl
1915dnl PHP_CHECK_FUNC(func, ...)
1916dnl
1917dnl This macro checks whether 'func' or '__func' exists
1918dnl in the default libraries and as a fall back in the specified library.
1919dnl Defines HAVE_func and HAVE_library if found and adds the library to LIBS.
1920dnl
1921AC_DEFUN([PHP_CHECK_FUNC],[
1922  unset ac_cv_func_$1
1923  unset ac_cv_func___$1
1924  unset found
1925
1926  AC_CHECK_FUNC($1, [found=yes],[ AC_CHECK_FUNC(__$1,[found=yes],[found=no]) ])
1927
1928  case $found in
1929  yes[)]
1930    PHP_DEF_HAVE($1)
1931    ac_cv_func_$1=yes
1932  ;;
1933  ifelse($#,1,,[
1934    *[)] PHP_CHECK_FUNC_LIB($@) ;;
1935  ])
1936  esac
1937])
1938
1939dnl
1940dnl PHP_TEST_BUILD(function, action-if-ok, action-if-not-ok [, extra-libs [, extra-source]])
1941dnl
1942dnl This macro checks whether build works and given function exists.
1943dnl
1944AC_DEFUN([PHP_TEST_BUILD], [
1945  old_LIBS=$LIBS
1946  LIBS="$4 $LIBS"
1947  AC_TRY_RUN([
1948    $5
1949    char $1();
1950    int main() {
1951      $1();
1952      return 0;
1953    }
1954  ], [
1955    LIBS=$old_LIBS
1956    $2
1957  ],[
1958    LIBS=$old_LIBS
1959    $3
1960  ],[
1961    LIBS=$old_LIBS
1962  ])
1963])
1964
1965dnl -------------------------------------------------------------------------
1966dnl Platform characteristics checks
1967dnl -------------------------------------------------------------------------
1968
1969dnl
1970dnl PHP_SHLIB_SUFFIX_NAMES
1971dnl
1972dnl Determines link library suffix SHLIB_SUFFIX_NAME
1973dnl which can be: .so, .sl or .dylib
1974dnl
1975dnl Determines shared library suffix SHLIB_DL_SUFFIX_NAME
1976dnl suffix can be: .so or .sl
1977dnl
1978AC_DEFUN([PHP_SHLIB_SUFFIX_NAMES],[
1979 AC_REQUIRE([PHP_CANONICAL_HOST_TARGET])dnl
1980 PHP_SUBST_OLD(SHLIB_SUFFIX_NAME)
1981 PHP_SUBST_OLD(SHLIB_DL_SUFFIX_NAME)
1982 SHLIB_SUFFIX_NAME=so
1983 SHLIB_DL_SUFFIX_NAME=$SHLIB_SUFFIX_NAME
1984 case $host_alias in
1985 *hpux*[)]
1986   SHLIB_SUFFIX_NAME=sl
1987   SHLIB_DL_SUFFIX_NAME=sl
1988   ;;
1989 *darwin*[)]
1990   SHLIB_SUFFIX_NAME=dylib
1991   SHLIB_DL_SUFFIX_NAME=so
1992   ;;
1993 esac
1994])
1995
1996dnl
1997dnl PHP_CHECK_64BIT([do if 32], [do if 64])
1998dnl
1999dnl This macro is used to detect if we're at 64-bit platform or not.
2000dnl It could be useful for those external libs, that have different precompiled
2001dnl versions in different directories.
2002dnl
2003AC_DEFUN([PHP_CHECK_64BIT],[
2004  AC_CHECK_SIZEOF(long int, 4)
2005  AC_MSG_CHECKING([checking if we're at 64-bit platform])
2006  if test "$ac_cv_sizeof_long_int" = "4" ; then
2007    AC_MSG_RESULT([no])
2008    $1
2009  else
2010    AC_MSG_RESULT([yes])
2011    $2
2012  fi
2013])
2014
2015dnl
2016dnl PHP_C_BIGENDIAN
2017dnl
2018dnl Replacement macro for AC_C_BIGENDIAN
2019dnl
2020AC_DEFUN([PHP_C_BIGENDIAN],
2021[AC_CACHE_CHECK([whether byte ordering is bigendian], ac_cv_c_bigendian_php,
2022 [
2023  ac_cv_c_bigendian_php=unknown
2024  AC_TRY_RUN(
2025  [
2026int main(void)
2027{
2028  short one = 1;
2029  char *cp = (char *)&one;
2030
2031  if (*cp == 0) {
2032    return(0);
2033  } else {
2034    return(1);
2035  }
2036}
2037  ], [ac_cv_c_bigendian_php=yes], [ac_cv_c_bigendian_php=no], [ac_cv_c_bigendian_php=unknown])
2038 ])
2039 if test $ac_cv_c_bigendian_php = yes; then
2040   AC_DEFINE(WORDS_BIGENDIAN, [], [Define if processor uses big-endian word])
2041 fi
2042])
2043
2044dnl -------------------------------------------------------------------------
2045dnl Checks for programs: PHP_PROG_<program>
2046dnl -------------------------------------------------------------------------
2047
2048dnl
2049dnl PHP_PROG_SENDMAIL
2050dnl
2051dnl Search for the sendmail binary
2052dnl
2053AC_DEFUN([PHP_PROG_SENDMAIL], [
2054  PHP_ALT_PATH=/usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib
2055  AC_PATH_PROG(PROG_SENDMAIL, sendmail,[], $PATH:$PHP_ALT_PATH)
2056  PHP_SUBST(PROG_SENDMAIL)
2057])
2058
2059dnl
2060dnl PHP_PROG_AWK
2061dnl
2062dnl Some vendors force mawk before gawk; mawk is broken so we don't like that
2063dnl
2064AC_DEFUN([PHP_PROG_AWK], [
2065  AC_CHECK_PROGS(AWK, gawk nawk awk mawk, bork, /usr/xpg4/bin/:$PATH)
2066  case "$AWK" in
2067    *mawk)
2068      AC_MSG_WARN([mawk is known to have problems on some systems. You should install GNU awk])
2069      ;;
2070    *gawk)
2071      ;;
2072    bork)
2073      AC_MSG_ERROR([Could not find awk; Install GNU awk])
2074      ;;
2075    *)
2076      AC_MSG_CHECKING([if $AWK is broken])
2077      if ! $AWK 'function foo() {}' >/dev/null 2>&1 ; then
2078        AC_MSG_RESULT([yes])
2079        AC_MSG_ERROR([You should install GNU awk])
2080      else
2081        AC_MSG_RESULT([no])
2082      fi
2083      ;;
2084  esac
2085  PHP_SUBST(AWK)
2086])
2087
2088dnl
2089dnl PHP_PROG_BISON
2090dnl
2091dnl Search for bison and check it's version
2092dnl
2093AC_DEFUN([PHP_PROG_BISON], [
2094  AC_PROG_YACC
2095  LIBZEND_BISON_CHECK
2096  PHP_SUBST(YACC)
2097])
2098
2099dnl
2100dnl PHP_PROG_LEX
2101dnl
2102dnl Search for (f)lex and check it's version
2103dnl
2104AC_DEFUN([PHP_PROG_LEX], [
2105dnl we only support certain flex versions
2106  flex_version_list="2.5.4"
2107
2108  AC_PROG_LEX
2109  if test "$LEX" = "flex"; then
2110dnl AC_DECL_YYTEXT is obsolete since autoconf 2.50 and merged into AC_PROG_LEX
2111dnl this is what causes that annoying "PHP_PROG_LEX is expanded from" warning with autoconf 2.50+
2112dnl it should be removed once we drop support of autoconf 2.13 (if ever)
2113    AC_DECL_YYTEXT
2114    :
2115  fi
2116  dnl ## Make flex scanners use const if they can, even if __STDC__ is not
2117  dnl ## true, for compilers like Sun's that only set __STDC__ true in
2118  dnl ## "limit-to-ANSI-standard" mode, not in "ANSI-compatible" mode
2119  AC_C_CONST
2120  if test "$ac_cv_c_const" = "yes" ; then
2121    LEX_CFLAGS="-DYY_USE_CONST"
2122  fi
2123
2124  if test "$LEX" = "flex"; then
2125    AC_CACHE_CHECK([for flex version], php_cv_flex_version, [
2126      flex_version=`$LEX -V -v --version 2>/dev/null | $SED -e 's/^.* //'`
2127      php_cv_flex_version=invalid
2128      for flex_check_version in $flex_version_list; do
2129        if test "$flex_version" = "$flex_check_version"; then
2130          php_cv_flex_version="$flex_check_version (ok)"
2131        fi
2132      done
2133    ])
2134  else
2135    flex_version=none
2136  fi
2137
2138  case $php_cv_flex_version in
2139    ""|invalid[)]
2140      if test -f "$abs_srcdir/Zend/zend_language_scanner.c" && test -f "$abs_srcdir/Zend/zend_ini_scanner.c"; then
2141        AC_MSG_WARN([flex versions supported for regeneration of the Zend/PHP parsers: $flex_version_list  (found: $flex_version)])
2142      else
2143        flex_msg="Supported flex versions are: $flex_version_list"
2144        if test "$flex_version" = "none"; then
2145          flex_msg="flex not found. flex is required to generate the Zend/PHP parsers! $flex_msg"
2146        else
2147          flex_msg="Found invalid flex version: $flex_version. $flex_msg"
2148        fi
2149        AC_MSG_ERROR([$flex_msg])
2150      fi
2151      LEX="exit 0;"
2152      ;;
2153  esac
2154  PHP_SUBST(LEX)
2155])
2156
2157dnl
2158dnl PHP_PROG_RE2C
2159dnl
2160dnl Search for the re2c binary and check the version
2161dnl
2162AC_DEFUN([PHP_PROG_RE2C],[
2163  AC_CHECK_PROG(RE2C, re2c, re2c)
2164  if test -n "$RE2C"; then
2165    AC_CACHE_CHECK([for re2c version], php_cv_re2c_version, [
2166      re2c_vernum=`$RE2C --vernum 2>/dev/null`
2167      if test -z "$re2c_vernum" || test "$re2c_vernum" -lt "1304"; then
2168        php_cv_re2c_version=invalid
2169      else
2170        php_cv_re2c_version="`$RE2C --version | cut -d ' ' -f 2  2>/dev/null` (ok)"
2171      fi
2172    ])
2173  fi
2174  case $php_cv_re2c_version in
2175    ""|invalid[)]
2176      AC_MSG_WARN([You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.])
2177      RE2C="exit 0;"
2178      ;;
2179  esac
2180  PHP_SUBST(RE2C)
2181])
2182
2183dnl -------------------------------------------------------------------------
2184dnl Common setup macros: PHP_SETUP_<what>
2185dnl -------------------------------------------------------------------------
2186
2187dnl
2188dnl PHP_SETUP_ICU([shared-add])
2189dnl
2190dnl Common setup macro for ICU
2191dnl
2192AC_DEFUN([PHP_SETUP_ICU],[
2193  PHP_ARG_WITH(icu-dir,,
2194  [  --with-icu-dir=DIR      Specify where ICU libraries and headers can be found], DEFAULT, no)
2195
2196  if test "$PHP_ICU_DIR" = "no"; then
2197    PHP_ICU_DIR=DEFAULT
2198  fi
2199
2200  if test "$PHP_ICU_DIR" = "DEFAULT"; then
2201    dnl Try to find icu-config
2202    AC_PATH_PROG(ICU_CONFIG, icu-config, no, [$PATH:/usr/local/bin])
2203  else
2204    ICU_CONFIG="$PHP_ICU_DIR/bin/icu-config"
2205  fi
2206
2207  AC_MSG_CHECKING([for location of ICU headers and libraries])
2208
2209  dnl Trust icu-config to know better what the install prefix is..
2210  icu_install_prefix=`$ICU_CONFIG --prefix 2> /dev/null`
2211  if test "$?" != "0" || test -z "$icu_install_prefix"; then
2212    AC_MSG_RESULT([not found])
2213    AC_MSG_ERROR([Unable to detect ICU prefix or $ICU_CONFIG failed. Please verify ICU install prefix and make sure icu-config works.])
2214  else
2215    AC_MSG_RESULT([$icu_install_prefix])
2216
2217    dnl Check ICU version
2218    AC_MSG_CHECKING([for ICU 3.4 or greater])
2219    icu_version_full=`$ICU_CONFIG --version`
2220    ac_IFS=$IFS
2221    IFS="."
2222    set $icu_version_full
2223    IFS=$ac_IFS
2224    icu_version=`expr [$]1 \* 1000 + [$]2`
2225    AC_MSG_RESULT([found $icu_version_full])
2226
2227    if test "$icu_version" -lt "3004"; then
2228      AC_MSG_ERROR([ICU version 3.4 or later is required])
2229    fi
2230
2231    ICU_VERSION=$icu_version
2232    ICU_INCS=`$ICU_CONFIG --cppflags-searchpath`
2233    ICU_LIBS=`$ICU_CONFIG --ldflags --ldflags-icuio`
2234    PHP_EVAL_INCLINE($ICU_INCS)
2235    PHP_EVAL_LIBLINE($ICU_LIBS, $1)
2236  fi
2237])
2238
2239dnl
2240dnl PHP_SETUP_KERBEROS(shared-add [, action-found [, action-not-found]])
2241dnl
2242dnl Common setup macro for kerberos
2243dnl
2244AC_DEFUN([PHP_SETUP_KERBEROS],[
2245  found_kerberos=no
2246  unset KERBEROS_CFLAGS
2247  unset KERBEROS_LIBS
2248
2249  dnl First try to find krb5-config
2250  if test -z "$KRB5_CONFIG"; then
2251    AC_PATH_PROG(KRB5_CONFIG, krb5-config, no, [$PATH:/usr/kerberos/bin:/usr/local/bin])
2252  fi
2253
2254  dnl If krb5-config is found try using it
2255  if test "$PHP_KERBEROS" = "yes" && test -x "$KRB5_CONFIG"; then
2256    KERBEROS_LIBS=`$KRB5_CONFIG --libs gssapi`
2257    KERBEROS_CFLAGS=`$KRB5_CONFIG --cflags gssapi`
2258
2259    if test -n "$KERBEROS_LIBS"; then
2260      found_kerberos=yes
2261      PHP_EVAL_LIBLINE($KERBEROS_LIBS, $1)
2262      PHP_EVAL_INCLINE($KERBEROS_CFLAGS)
2263    fi
2264  fi
2265
2266  dnl If still not found use old skool method
2267  if test "$found_kerberos" = "no"; then
2268
2269    if test "$PHP_KERBEROS" = "yes"; then
2270      PHP_KERBEROS="/usr/kerberos /usr/local /usr"
2271    fi
2272
2273    for i in $PHP_KERBEROS; do
2274      if test -f $i/$PHP_LIBDIR/libkrb5.a || test -f $i/$PHP_LIBDIR/libkrb5.$SHLIB_SUFFIX_NAME; then
2275        PHP_KERBEROS_DIR=$i
2276        break
2277      fi
2278    done
2279
2280    if test "$PHP_KERBEROS_DIR"; then
2281      found_kerberos=yes
2282      PHP_ADD_LIBPATH($PHP_KERBEROS_DIR/$PHP_LIBDIR, $1)
2283      PHP_ADD_LIBRARY(gssapi_krb5, 1, $1)
2284      PHP_ADD_LIBRARY(krb5, 1, $1)
2285      PHP_ADD_LIBRARY(k5crypto, 1, $1)
2286      PHP_ADD_LIBRARY(com_err,  1, $1)
2287      PHP_ADD_INCLUDE($PHP_KERBEROS_DIR/include)
2288    fi
2289  fi
2290
2291  if test "$found_kerberos" = "yes"; then
2292ifelse([$2],[],:,[$2])
2293ifelse([$3],[],,[else $3])
2294  fi
2295])
2296
2297dnl
2298dnl PHP_SETUP_OPENSSL(shared-add [, action-found [, action-not-found]])
2299dnl
2300dnl Common setup macro for openssl
2301dnl
2302AC_DEFUN([PHP_SETUP_OPENSSL],[
2303  found_openssl=no
2304  unset OPENSSL_INCDIR
2305  unset OPENSSL_LIBDIR
2306
2307  dnl Empty variable means 'no'
2308  test -z "$PHP_OPENSSL" && PHP_OPENSSL=no
2309  test -z "$PHP_IMAP_SSL" && PHP_IMAP_SSL=no
2310
2311  dnl Fallbacks for different configure options
2312  if test "$PHP_OPENSSL" != "no"; then
2313    PHP_OPENSSL_DIR=$PHP_OPENSSL
2314  elif test "$PHP_IMAP_SSL" != "no"; then
2315    PHP_OPENSSL_DIR=$PHP_IMAP_SSL
2316  fi
2317
2318  dnl First try to find pkg-config
2319  if test -z "$PKG_CONFIG"; then
2320    AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
2321  fi
2322
2323  dnl If pkg-config is found try using it
2324  if test "$PHP_OPENSSL_DIR" = "yes" && test -x "$PKG_CONFIG" && $PKG_CONFIG --exists openssl; then
2325    if $PKG_CONFIG --atleast-version=0.9.6 openssl; then
2326      found_openssl=yes
2327      OPENSSL_LIBS=`$PKG_CONFIG --libs openssl`
2328      OPENSSL_INCS=`$PKG_CONFIG --cflags-only-I openssl`
2329      OPENSSL_INCDIR=`$PKG_CONFIG --variable=includedir openssl`
2330    else
2331      AC_MSG_ERROR([OpenSSL version 0.9.6 or greater required.])
2332    fi
2333
2334    if test -n "$OPENSSL_LIBS" && test -n "$OPENSSL_INCS"; then
2335      PHP_EVAL_LIBLINE($OPENSSL_LIBS, $1)
2336      PHP_EVAL_INCLINE($OPENSSL_INCS)
2337    fi
2338  fi
2339
2340  dnl If pkg-config fails for some reason, revert to the old method
2341  if test "$found_openssl" = "no"; then
2342
2343    if test "$PHP_OPENSSL_DIR" = "yes"; then
2344      PHP_OPENSSL_DIR="/usr/local/ssl /usr/local /usr /usr/local/openssl"
2345    fi
2346
2347    for i in $PHP_OPENSSL_DIR; do
2348      if test -r $i/include/openssl/evp.h; then
2349        OPENSSL_INCDIR=$i/include
2350      fi
2351      if test -r $i/$PHP_LIBDIR/libssl.a -o -r $i/$PHP_LIBDIR/libssl.$SHLIB_SUFFIX_NAME; then
2352        OPENSSL_LIBDIR=$i/$PHP_LIBDIR
2353      fi
2354      test -n "$OPENSSL_INCDIR" && test -n "$OPENSSL_LIBDIR" && break
2355    done
2356
2357    if test -z "$OPENSSL_INCDIR"; then
2358      AC_MSG_ERROR([Cannot find OpenSSL's <evp.h>])
2359    fi
2360
2361    if test -z "$OPENSSL_LIBDIR"; then
2362      AC_MSG_ERROR([Cannot find OpenSSL's libraries])
2363    fi
2364
2365    old_CPPFLAGS=$CPPFLAGS
2366    CPPFLAGS=-I$OPENSSL_INCDIR
2367    AC_MSG_CHECKING([for OpenSSL version])
2368    AC_EGREP_CPP(yes,[
2369#include <openssl/opensslv.h>
2370#if OPENSSL_VERSION_NUMBER >= 0x0090600fL
2371  yes
2372#endif
2373    ],[
2374      AC_MSG_RESULT([>= 0.9.6])
2375    ],[
2376      AC_MSG_ERROR([OpenSSL version 0.9.6 or greater required.])
2377    ])
2378    CPPFLAGS=$old_CPPFLAGS
2379
2380    PHP_ADD_INCLUDE($OPENSSL_INCDIR)
2381
2382    PHP_CHECK_LIBRARY(crypto, CRYPTO_free, [
2383      PHP_ADD_LIBRARY(crypto,,$1)
2384    ],[
2385      AC_MSG_ERROR([libcrypto not found!])
2386    ],[
2387      -L$OPENSSL_LIBDIR
2388    ])
2389
2390    old_LIBS=$LIBS
2391    LIBS="$LIBS -lcrypto"
2392    PHP_CHECK_LIBRARY(ssl, SSL_CTX_set_ssl_version, [
2393      found_openssl=yes
2394    ],[
2395      AC_MSG_ERROR([libssl not found!])
2396    ],[
2397      -L$OPENSSL_LIBDIR
2398    ])
2399    LIBS=$old_LIBS
2400    PHP_ADD_LIBRARY(ssl,,$1)
2401    PHP_ADD_LIBRARY(crypto,,$1)
2402
2403    PHP_ADD_LIBPATH($OPENSSL_LIBDIR, $1)
2404  fi
2405
2406  if test "$found_openssl" = "yes"; then
2407  dnl For apache 1.3.x static build
2408  OPENSSL_INCDIR_OPT=-I$OPENSSL_INCDIR
2409  AC_SUBST(OPENSSL_INCDIR_OPT)
2410
2411ifelse([$2],[],:,[$2])
2412ifelse([$3],[],,[else $3])
2413  fi
2414])
2415
2416dnl
2417dnl PHP_SETUP_ICONV(shared-add [, action-found [, action-not-found]])
2418dnl
2419dnl Common setup macro for iconv
2420dnl
2421AC_DEFUN([PHP_SETUP_ICONV], [
2422  found_iconv=no
2423  unset ICONV_DIR
2424
2425  # Create the directories for a VPATH build:
2426  $php_shtool mkdir -p ext/iconv
2427
2428  echo > ext/iconv/php_have_bsd_iconv.h
2429  echo > ext/iconv/php_have_ibm_iconv.h
2430  echo > ext/iconv/php_have_glibc_iconv.h
2431  echo > ext/iconv/php_have_libiconv.h
2432  echo > ext/iconv/php_have_iconv.h
2433  echo > ext/iconv/php_php_iconv_impl.h
2434  echo > ext/iconv/php_iconv_aliased_libiconv.h
2435  echo > ext/iconv/php_php_iconv_h_path.h
2436  echo > ext/iconv/php_iconv_supports_errno.h
2437
2438  dnl
2439  dnl Check libc first if no path is provided in --with-iconv
2440  dnl
2441
2442  if test "$PHP_ICONV" = "yes"; then
2443    dnl Reset LIBS temporarily as it may have already been included
2444    dnl -liconv in.
2445    LIBS_save="$LIBS"
2446    LIBS=
2447    AC_CHECK_FUNC(iconv, [
2448      found_iconv=yes
2449    ],[
2450      AC_CHECK_FUNC(libiconv,[
2451        PHP_DEFINE(HAVE_LIBICONV,1,[ext/iconv])
2452        AC_DEFINE(HAVE_LIBICONV, 1, [ ])
2453        found_iconv=yes
2454      ])
2455    ])
2456    LIBS="$LIBS_save"
2457  fi
2458
2459  dnl
2460  dnl Check external libs for iconv funcs
2461  dnl
2462  if test "$found_iconv" = "no"; then
2463
2464    for i in $PHP_ICONV /usr/local /usr; do
2465      if test -r $i/include/giconv.h; then
2466        AC_DEFINE(HAVE_GICONV_H, 1, [ ])
2467        ICONV_DIR=$i
2468        iconv_lib_name=giconv
2469        break
2470      elif test -r $i/include/iconv.h; then
2471        ICONV_DIR=$i
2472        iconv_lib_name=iconv
2473        break
2474      fi
2475    done
2476
2477    if test -z "$ICONV_DIR"; then
2478      AC_MSG_ERROR([Please specify the install prefix of iconv with --with-iconv=<DIR>])
2479    fi
2480
2481    if test -f $ICONV_DIR/$PHP_LIBDIR/lib$iconv_lib_name.a ||
2482       test -f $ICONV_DIR/$PHP_LIBDIR/lib$iconv_lib_name.$SHLIB_SUFFIX_NAME
2483    then
2484      PHP_CHECK_LIBRARY($iconv_lib_name, libiconv, [
2485        found_iconv=yes
2486        PHP_DEFINE(HAVE_LIBICONV,1,[ext/iconv])
2487        AC_DEFINE(HAVE_LIBICONV,1,[ ])
2488        PHP_DEFINE([ICONV_ALIASED_LIBICONV],1,[ext/iconv])
2489        AC_DEFINE([ICONV_ALIASED_LIBICONV],1,[iconv() is aliased to libiconv() in -liconv])
2490      ], [
2491        PHP_CHECK_LIBRARY($iconv_lib_name, iconv, [
2492          found_iconv=yes
2493        ], [], [
2494          -L$ICONV_DIR/$PHP_LIBDIR
2495        ])
2496      ], [
2497        -L$ICONV_DIR/$PHP_LIBDIR
2498      ])
2499    fi
2500  fi
2501
2502  if test "$found_iconv" = "yes"; then
2503    PHP_DEFINE(HAVE_ICONV,1,[ext/iconv])
2504    AC_DEFINE(HAVE_ICONV,1,[ ])
2505    if test -n "$ICONV_DIR"; then
2506      PHP_ADD_LIBRARY_WITH_PATH($iconv_lib_name, $ICONV_DIR/$PHP_LIBDIR, $1)
2507      PHP_ADD_INCLUDE($ICONV_DIR/include)
2508    fi
2509    $2
2510ifelse([$3],[],,[else $3])
2511  fi
2512])
2513
2514dnl
2515dnl PHP_SETUP_LIBXML(shared-add [, action-found [, action-not-found]])
2516dnl
2517dnl Common setup macro for libxml
2518dnl
2519AC_DEFUN([PHP_SETUP_LIBXML], [
2520AC_CACHE_CHECK([for xml2-config path], ac_cv_php_xml2_config_path,
2521[
2522  for i in $PHP_LIBXML_DIR /usr/local /usr; do
2523    if test -x "$i/bin/xml2-config"; then
2524      ac_cv_php_xml2_config_path="$i/bin/xml2-config"
2525      break
2526    fi
2527  done
2528])
2529
2530  if test -x "$ac_cv_php_xml2_config_path"; then
2531    XML2_CONFIG="$ac_cv_php_xml2_config_path"
2532    libxml_full_version=`$XML2_CONFIG --version`
2533    ac_IFS=$IFS
2534    IFS="."
2535    set $libxml_full_version
2536    IFS=$ac_IFS
2537    LIBXML_VERSION=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3`
2538    if test "$LIBXML_VERSION" -ge "2006011"; then
2539      LIBXML_LIBS=`$XML2_CONFIG --libs`
2540      LIBXML_INCS=`$XML2_CONFIG --cflags`
2541      PHP_EVAL_LIBLINE($LIBXML_LIBS, $1)
2542      PHP_EVAL_INCLINE($LIBXML_INCS)
2543
2544      dnl Check that build works with given libs
2545      AC_CACHE_CHECK(whether libxml build works, php_cv_libxml_build_works, [
2546        PHP_TEST_BUILD(xmlInitParser,
2547        [
2548          php_cv_libxml_build_works=yes
2549        ], [
2550          AC_MSG_RESULT(no)
2551          AC_MSG_ERROR([build test failed.  Please check the config.log for details.])
2552        ], [
2553          [$]$1
2554        ])
2555      ])
2556      if test "$php_cv_libxml_build_works" = "yes"; then
2557        AC_DEFINE(HAVE_LIBXML, 1, [ ])
2558      fi
2559      $2
2560    else
2561      AC_MSG_ERROR([libxml2 version 2.6.11 or greater required.])
2562    fi
2563ifelse([$3],[],,[else $3])
2564  fi
2565])
2566
2567dnl -------------------------------------------------------------------------
2568dnl Misc. macros
2569dnl -------------------------------------------------------------------------
2570
2571dnl
2572dnl PHP_INSTALL_HEADERS(path [, file ...])
2573dnl
2574dnl PHP header files to be installed
2575dnl
2576AC_DEFUN([PHP_INSTALL_HEADERS],[
2577  ifelse([$2],[],[
2578    for header_file in $1; do
2579      PHP_RUN_ONCE(INSTALLHEADERS, $header_file, [
2580        INSTALL_HEADERS="$INSTALL_HEADERS $header_file"
2581      ])
2582    done
2583  ], [
2584    header_path=$1
2585    for header_file in $2; do
2586      hp_hf="$header_path/$header_file"
2587      PHP_RUN_ONCE(INSTALLHEADERS, $hp_hf, [
2588        INSTALL_HEADERS="$INSTALL_HEADERS $hp_hf"
2589      ])
2590    done
2591  ])
2592])
2593
2594dnl
2595dnl PHP_AP_EXTRACT_VERSION(/path/httpd)
2596dnl
2597dnl This macro is used to get a comparable
2598dnl version for apache1/2.
2599dnl
2600AC_DEFUN([PHP_AP_EXTRACT_VERSION],[
2601  ac_output=`$1 -v 2>&1 | grep version | $SED -e 's/Oracle-HTTP-//'`
2602  ac_IFS=$IFS
2603IFS="- /.
2604"
2605  set $ac_output
2606  IFS=$ac_IFS
2607
2608  APACHE_VERSION=`expr [$]4 \* 1000000 + [$]5 \* 1000 + [$]6`
2609])
2610
2611dnl
2612dnl PHP_DEBUG_MACRO(filename)
2613dnl
2614AC_DEFUN([PHP_DEBUG_MACRO],[
2615  DEBUG_LOG=$1
2616  cat >$1 <<X
2617CONFIGURE:  $CONFIGURE_COMMAND
2618CC:         $CC
2619CFLAGS:     $CFLAGS
2620CPPFLAGS:   $CPPFLAGS
2621CXX:        $CXX
2622CXXFLAGS:   $CXXFLAGS
2623INCLUDES:   $INCLUDES
2624LDFLAGS:    $LDFLAGS
2625LIBS:       $LIBS
2626DLIBS:      $DLIBS
2627SAPI:       $PHP_SAPI
2628PHP_RPATHS: $PHP_RPATHS
2629uname -a:   `uname -a`
2630
2631X
2632    cat >conftest.$ac_ext <<X
2633main()
2634{
2635  exit(0);
2636}
2637X
2638    (eval echo \"$ac_link\"; eval $ac_link && ./conftest) >>$1 2>&1
2639    rm -fr conftest*
2640])
2641
2642dnl
2643dnl PHP_CONFIG_NICE(filename)
2644dnl
2645dnl Generates the config.nice file
2646dnl
2647AC_DEFUN([PHP_CONFIG_NICE],[
2648  AC_REQUIRE([AC_PROG_EGREP])
2649  AC_REQUIRE([LT_AC_PROG_SED])
2650  PHP_SUBST_OLD(EGREP)
2651  PHP_SUBST_OLD(SED)
2652  test -f $1 && mv $1 $1.old
2653  rm -f $1.old
2654  cat >$1<<EOF
2655#! /bin/sh
2656#
2657# Created by configure
2658
2659EOF
2660
2661  for var in CFLAGS CXXFLAGS CPPFLAGS LDFLAGS EXTRA_LDFLAGS_PROGRAM LIBS CC CXX; do
2662    eval val=\$$var
2663    if test -n "$val"; then
2664      echo "$var='$val' \\" >> $1
2665    fi
2666  done
2667
2668  echo "'[$]0' \\" >> $1
2669  if test `expr -- [$]0 : "'.*"` = 0; then
2670    CONFIGURE_COMMAND="$CONFIGURE_COMMAND '[$]0'"
2671  else
2672    CONFIGURE_COMMAND="$CONFIGURE_COMMAND [$]0"
2673  fi
2674  for arg in $ac_configure_args; do
2675     if test `expr -- $arg : "'.*"` = 0; then
2676        if test `expr -- $arg : "--.*"` = 0; then
2677          break;
2678        fi
2679        echo "'[$]arg' \\" >> $1
2680        CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS '[$]arg'"
2681     else
2682        if test `expr -- $arg : "'--.*"` = 0; then
2683          break;
2684        fi
2685        echo "[$]arg \\" >> $1
2686        CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS [$]arg"
2687     fi
2688  done
2689  echo '"[$]@"' >> $1
2690  chmod +x $1
2691  CONFIGURE_COMMAND="$CONFIGURE_COMMAND $CONFIGURE_OPTIONS"
2692  PHP_SUBST_OLD(CONFIGURE_COMMAND)
2693  PHP_SUBST_OLD(CONFIGURE_OPTIONS)
2694])
2695
2696dnl
2697dnl PHP_CHECK_CONFIGURE_OPTIONS
2698dnl
2699AC_DEFUN([PHP_CHECK_CONFIGURE_OPTIONS],[
2700  for arg in $ac_configure_args; do
2701    case $arg in
2702      --with-*[)]
2703        arg_name="`echo [$]arg | $SED -e 's/--with-/with-/g' -e 's/=.*//g'`"
2704        ;;
2705      --without-*[)]
2706        arg_name="`echo [$]arg | $SED -e 's/--without-/with-/g' -e 's/=.*//g'`"
2707        ;;
2708      --enable-*[)]
2709        arg_name="`echo [$]arg | $SED -e 's/--enable-/enable-/g' -e 's/=.*//g'`"
2710        ;;
2711      --disable-*[)]
2712        arg_name="`echo [$]arg | $SED -e 's/--disable-/enable-/g' -e 's/=.*//g'`"
2713        ;;
2714      *[)]
2715        continue
2716        ;;
2717    esac
2718    case $arg_name in
2719      # Allow --disable-all / --enable-all
2720      enable-all[)];;
2721
2722      # Allow certain libtool options
2723      enable-libtool-lock | with-pic | with-tags | enable-shared | enable-static | enable-fast-install | with-gnu-ld[)];;
2724
2725      # Allow certain TSRM options
2726      with-tsrm-pth | with-tsrm-st | with-tsrm-pthreads[)];;
2727
2728      # Allow certain Zend options
2729      with-zend-vm | enable-maintainer-zts | enable-inline-optimization[)];;
2730
2731      # All the rest must be set using the PHP_ARG_* macros
2732      # PHP_ARG_* macros set php_enable_<arg_name> or php_with_<arg_name>
2733      *[)]
2734        # Options that exist before PHP 6
2735        if test "$PHP_MAJOR_VERSION" -lt "6"; then
2736          case $arg_name in
2737            enable-zend-multibyte[)] continue;;
2738          esac
2739        fi
2740
2741        is_arg_set=php_[]`echo [$]arg_name | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-' 'abcdefghijklmnopqrstuvwxyz_'`
2742        if eval test "x\$$is_arg_set" = "x"; then
2743          PHP_UNKNOWN_CONFIGURE_OPTIONS="$PHP_UNKNOWN_CONFIGURE_OPTIONS
2744[$]arg"
2745        fi
2746        ;;
2747    esac
2748  done
2749])
2750
2751dnl
2752dnl PHP_CHECK_PDO_INCLUDES([found [, not-found]])
2753dnl
2754AC_DEFUN([PHP_CHECK_PDO_INCLUDES],[
2755  AC_CACHE_CHECK([for PDO includes], pdo_inc_path, [
2756    AC_MSG_CHECKING([for PDO includes])
2757    if test -f $abs_srcdir/include/php/ext/pdo/php_pdo_driver.h; then
2758      pdo_inc_path=$abs_srcdir/ext
2759    elif test -f $abs_srcdir/ext/pdo/php_pdo_driver.h; then
2760      pdo_inc_path=$abs_srcdir/ext
2761    elif test -f $prefix/include/php/ext/pdo/php_pdo_driver.h; then
2762      pdo_inc_path=$prefix/include/php/ext
2763    fi
2764  ])
2765  if test -n "$pdo_inc_path"; then
2766ifelse([$1],[],:,[$1])
2767  else
2768ifelse([$2],[],[AC_MSG_ERROR([Cannot find php_pdo_driver.h.])],[$2])
2769  fi
2770])
2771
2772dnl
2773dnl PHP_DETECT_ICC
2774dnl Detect Intel C++ Compiler and unset $GCC if ICC found
2775AC_DEFUN([PHP_DETECT_ICC],
2776[
2777  ICC="no"
2778  AC_MSG_CHECKING([for icc])
2779  AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
2780    ICC="no"
2781    AC_MSG_RESULT([no]),
2782    ICC="yes"
2783    GCC="no"
2784    AC_MSG_RESULT([yes])
2785  )
2786])
2787
2788dnl PHP_DETECT_SUNCC
2789dnl Detect if the systems default compiler is suncc.
2790dnl We also set some usefull CFLAGS if the user didn't set any
2791AC_DEFUN([PHP_DETECT_SUNCC],[
2792  SUNCC="no"
2793  AC_MSG_CHECKING([for suncc])
2794  AC_EGREP_CPP([^__SUNPRO_C], [__SUNPRO_C],
2795    SUNCC="no"
2796    AC_MSG_RESULT([no]),
2797    SUNCC="yes"
2798    GCC="no"
2799    test -n "$auto_cflags" && CFLAGS="-O -xs -xstrconst -zlazyload"
2800    GCC=""
2801    AC_MSG_RESULT([yes])
2802  )
2803])
2804
2805dnl
2806dnl PHP_CRYPT_R_STYLE
2807dnl detect the style of crypt_r() is any is available
2808dnl see APR_CHECK_CRYPT_R_STYLE() for original version
2809dnl
2810AC_DEFUN([PHP_CRYPT_R_STYLE],
2811[
2812  AC_CACHE_CHECK([which data struct is used by crypt_r], php_cv_crypt_r_style,[
2813    php_cv_crypt_r_style=none
2814    AC_TRY_COMPILE([
2815#define _REENTRANT 1
2816#include <crypt.h>
2817],[
2818CRYPTD buffer;
2819crypt_r("passwd", "hash", &buffer);
2820],
2821php_cv_crypt_r_style=cryptd)
2822
2823    if test "$php_cv_crypt_r_style" = "none"; then
2824      AC_TRY_COMPILE([
2825#define _REENTRANT 1
2826#include <crypt.h>
2827],[
2828struct crypt_data buffer;
2829crypt_r("passwd", "hash", &buffer);
2830],
2831php_cv_crypt_r_style=struct_crypt_data)
2832    fi
2833
2834    if test "$php_cv_crypt_r_style" = "none"; then
2835      AC_TRY_COMPILE([
2836#define _REENTRANT 1
2837#define _GNU_SOURCE
2838#include <crypt.h>
2839],[
2840struct crypt_data buffer;
2841crypt_r("passwd", "hash", &buffer);
2842],
2843php_cv_crypt_r_style=struct_crypt_data_gnu_source)
2844    fi
2845    ])
2846
2847  if test "$php_cv_crypt_r_style" = "cryptd"; then
2848    AC_DEFINE(CRYPT_R_CRYPTD, 1, [Define if crypt_r has uses CRYPTD])
2849  fi
2850  if test "$php_cv_crypt_r_style" = "struct_crypt_data" -o "$php_cv_crypt_r_style" = "struct_crypt_data_gnu_source"; then
2851    AC_DEFINE(CRYPT_R_STRUCT_CRYPT_DATA, 1, [Define if crypt_r uses struct crypt_data])
2852  fi
2853  if test "$php_cv_crypt_r_style" = "struct_crypt_data_gnu_source"; then
2854    AC_DEFINE(CRYPT_R_GNU_SOURCE, 1, [Define if struct crypt_data requires _GNU_SOURCE])
2855  fi
2856  if test "$php_cv_crypt_r_style" = "none"; then
2857    AC_MSG_ERROR([Unable to detect data struct used by crypt_r])
2858  fi
2859])
2860
2861dnl
2862dnl PHP_TEST_WRITE_STDOUT
2863dnl
2864AC_DEFUN([PHP_TEST_WRITE_STDOUT],[
2865  AC_CACHE_CHECK(whether writing to stdout works,ac_cv_write_stdout,[
2866    AC_TRY_RUN([
2867#ifdef HAVE_UNISTD_H
2868#include <unistd.h>
2869#endif
2870
2871#define TEXT "This is the test message -- "
2872
2873main()
2874{
2875  int n;
2876
2877  n = write(1, TEXT, sizeof(TEXT)-1);
2878  return (!(n == sizeof(TEXT)-1));
2879}
2880    ],[
2881      ac_cv_write_stdout=yes
2882    ],[
2883      ac_cv_write_stdout=no
2884    ],[
2885      ac_cv_write_stdout=no
2886    ])
2887  ])
2888  if test "$ac_cv_write_stdout" = "yes"; then
2889    AC_DEFINE(PHP_WRITE_STDOUT, 1, [whether write(2) works])
2890  fi
2891])
2892
2893