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