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