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