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