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