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