xref: /PHP-8.1/build/php.m4 (revision d93800ec)
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) --mode=compile $(CC)'
790  php_c_meta='$(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS)'
791  php_c_post=
792  php_cxx_pre='$(LIBTOOL) --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) --mode=compile $(CC)'
803  shared_c_meta='$(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) '$pic_setting
804  shared_c_post=
805  shared_cxx_pre='$(LIBTOOL) --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) --mode=install cp $3/$1.$suffix \$(phplibdir)
836
837$3/$1.$suffix: \$($2) \$(translit($1,a-z_-,A-Z__)_SHARED_DEPENDENCIES)
838	\$(LIBTOOL) --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()
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() {
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() {
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() {
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() {
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],[
1263  AC_MSG_CHECKING([for missing declarations of reentrant functions])
1264  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <time.h>]], [[struct tm *(*func)() = localtime_r]])],[
1265    :
1266  ],[
1267    AC_DEFINE(MISSING_LOCALTIME_R_DECL,1,[Whether localtime_r is declared])
1268  ])
1269  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <time.h>]], [[struct tm *(*func)() = gmtime_r]])],[
1270    :
1271  ],[
1272    AC_DEFINE(MISSING_GMTIME_R_DECL,1,[Whether gmtime_r is declared])
1273  ])
1274  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <time.h>]], [[char *(*func)() = asctime_r]])],[
1275    :
1276  ],[
1277    AC_DEFINE(MISSING_ASCTIME_R_DECL,1,[Whether asctime_r is declared])
1278  ])
1279  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <time.h>]], [[char *(*func)() = ctime_r]])],[
1280    :
1281  ],[
1282    AC_DEFINE(MISSING_CTIME_R_DECL,1,[Whether ctime_r is declared])
1283  ])
1284  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <string.h>]], [[char *(*func)() = strtok_r]])],[
1285    :
1286  ],[
1287    AC_DEFINE(MISSING_STRTOK_R_DECL,1,[Whether strtok_r is declared])
1288  ])
1289  AC_MSG_RESULT([done])
1290])
1291
1292dnl
1293dnl PHP_STRUCT_FLOCK
1294dnl
1295AC_DEFUN([PHP_STRUCT_FLOCK],[
1296AC_CACHE_CHECK(for struct flock,ac_cv_struct_flock,
1297    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1298#include <unistd.h>
1299#include <fcntl.h>
1300        ]], [[struct flock x;]])],[
1301          ac_cv_struct_flock=yes
1302        ],[
1303          ac_cv_struct_flock=no
1304        ])
1305)
1306if test "$ac_cv_struct_flock" = "yes" ; then
1307    AC_DEFINE(HAVE_STRUCT_FLOCK, 1,[whether you have struct flock])
1308fi
1309])
1310
1311dnl
1312dnl PHP_MISSING_FCLOSE_DECL
1313dnl
1314dnl See if we have broken header files like SunOS has.
1315dnl
1316AC_DEFUN([PHP_MISSING_FCLOSE_DECL],[
1317  AC_MSG_CHECKING([for fclose declaration])
1318  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]], [[int (*func)() = fclose]])],[
1319    AC_DEFINE(MISSING_FCLOSE_DECL,0,[ ])
1320    AC_MSG_RESULT([ok])
1321  ],[
1322    AC_DEFINE(MISSING_FCLOSE_DECL,1,[ ])
1323    AC_MSG_RESULT([missing])
1324  ])
1325])
1326
1327dnl
1328dnl PHP_SOCKADDR_CHECKS
1329dnl
1330AC_DEFUN([PHP_SOCKADDR_CHECKS], [
1331  dnl Check for struct sockaddr_storage exists.
1332  AC_CACHE_CHECK([for struct sockaddr_storage], ac_cv_sockaddr_storage,
1333    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
1334#include <sys/socket.h>]],
1335    [[struct sockaddr_storage s; s]])],
1336    [ac_cv_sockaddr_storage=yes], [ac_cv_sockaddr_storage=no])
1337  ])
1338  if test "$ac_cv_sockaddr_storage" = "yes"; then
1339    AC_DEFINE(HAVE_SOCKADDR_STORAGE, 1, [Whether you have struct sockaddr_storage])
1340  fi
1341  dnl Check if field sa_len exists in struct sockaddr.
1342  AC_CACHE_CHECK([for field sa_len in struct sockaddr],ac_cv_sockaddr_sa_len,[
1343    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
1344#include <sys/socket.h>]], [[static struct sockaddr sa; int n = (int) sa.sa_len; return n;]])],
1345    [ac_cv_sockaddr_sa_len=yes], [ac_cv_sockaddr_sa_len=no])
1346  ])
1347  if test "$ac_cv_sockaddr_sa_len" = "yes"; then
1348    AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has field sa_len])
1349  fi
1350])
1351
1352dnl
1353dnl PHP_EBCDIC
1354dnl
1355AC_DEFUN([PHP_EBCDIC], [
1356  AC_CACHE_CHECK([whether system uses EBCDIC],ac_cv_ebcdic,[
1357  AC_RUN_IFELSE([AC_LANG_SOURCE([[
1358int main(void) {
1359  return (unsigned char)'A' != (unsigned char)0xC1;
1360}
1361]])],[
1362  ac_cv_ebcdic=yes
1363],[
1364  ac_cv_ebcdic=no
1365],[
1366  ac_cv_ebcdic=no
1367])])
1368  if test "$ac_cv_ebcdic" = "yes"; then
1369    AC_MSG_ERROR([PHP does not support EBCDIC targets])
1370  fi
1371])
1372
1373dnl
1374dnl PHP_BROKEN_GETCWD
1375dnl
1376dnl Some systems, notably Solaris, cause getcwd() or realpath to fail if a
1377dnl component of the path has execute but not read permissions.
1378dnl
1379AC_DEFUN([PHP_BROKEN_GETCWD],[
1380  AC_MSG_CHECKING([for broken getcwd])
1381  os=`uname -sr 2>/dev/null`
1382  case $os in
1383    SunOS*[)]
1384      AC_DEFINE(HAVE_BROKEN_GETCWD,1, [Define if system has broken getcwd])
1385      AC_MSG_RESULT([yes]);;
1386    *[)]
1387      AC_MSG_RESULT([no]);;
1388  esac
1389])
1390
1391dnl
1392dnl PHP_BROKEN_GCC_STRLEN_OPT
1393dnl
1394dnl Early releases of GCC 8 shipped with a strlen() optimization bug, so they
1395dnl didn't properly handle the `char val[1]` struct hack. See bug #76510.
1396dnl
1397AC_DEFUN([PHP_BROKEN_GCC_STRLEN_OPT], [
1398  AC_CACHE_CHECK([for broken gcc optimize-strlen],ac_cv_have_broken_gcc_strlen_opt,[
1399  AC_RUN_IFELSE([AC_LANG_SOURCE([[
1400#include <stdlib.h>
1401#include <string.h>
1402#include <stdio.h>
1403struct s
1404{
1405  int i;
1406  char c[1];
1407};
1408int main()
1409{
1410  struct s *s = malloc(sizeof(struct s) + 3);
1411  s->i = 3;
1412  strcpy(s->c, "foo");
1413  return strlen(s->c+1) == 2;
1414}
1415]])],[
1416  ac_cv_have_broken_gcc_strlen_opt=yes
1417],[
1418  ac_cv_have_broken_gcc_strlen_opt=no
1419],[
1420  ac_cv_have_broken_gcc_strlen_opt=no
1421])])
1422  if test "$ac_cv_have_broken_gcc_strlen_opt" = "yes"; then
1423    CFLAGS="$CFLAGS -fno-optimize-strlen"
1424  fi
1425])
1426
1427dnl
1428dnl PHP_FOPENCOOKIE
1429dnl
1430AC_DEFUN([PHP_FOPENCOOKIE], [
1431  AC_CHECK_FUNC(fopencookie, [have_glibc_fopencookie=yes])
1432
1433  if test "$have_glibc_fopencookie" = "yes"; then
1434dnl This comes in two flavors: newer glibcs (since 2.1.2?) have a type called
1435dnl cookie_io_functions_t.
1436AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1437#define _GNU_SOURCE
1438#include <stdio.h>
1439]], [[cookie_io_functions_t cookie;]])],[have_cookie_io_functions_t=yes],[])
1440
1441    if test "$have_cookie_io_functions_t" = "yes"; then
1442      cookie_io_functions_t=cookie_io_functions_t
1443      have_fopen_cookie=yes
1444
1445dnl Even newer glibcs have a different seeker definition.
1446AC_RUN_IFELSE([AC_LANG_SOURCE([[
1447#define _GNU_SOURCE
1448#include <stdio.h>
1449#include <stdlib.h>
1450
1451struct cookiedata {
1452  off64_t pos;
1453};
1454
1455ssize_t reader(void *cookie, char *buffer, size_t size)
1456{ return size; }
1457ssize_t writer(void *cookie, const char *buffer, size_t size)
1458{ return size; }
1459int closer(void *cookie)
1460{ return 0; }
1461int seeker(void *cookie, off64_t *position, int whence)
1462{ ((struct cookiedata*)cookie)->pos = *position; return 0; }
1463
1464cookie_io_functions_t funcs = {reader, writer, seeker, closer};
1465
1466int main() {
1467  struct cookiedata g = { 0 };
1468  FILE *fp = fopencookie(&g, "r", funcs);
1469
1470  if (fp && fseek(fp, 8192, SEEK_SET) == 0 && g.pos == 8192)
1471    return 0;
1472  return 1;
1473}
1474
1475]])], [
1476  cookie_io_functions_use_off64_t=yes
1477], [
1478  cookie_io_functions_use_off64_t=no
1479], [
1480  dnl Cross compilation.
1481  case $host_alias in
1482    *linux*)
1483      cookie_io_functions_use_off64_t=yes
1484      ;;
1485    *)
1486      cookie_io_functions_use_off64_t=no
1487      ;;
1488  esac
1489])
1490
1491    else
1492
1493dnl Older glibc versions (up to 2.1.2?) call it _IO_cookie_io_functions_t.
1494AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1495#define _GNU_SOURCE
1496#include <stdio.h>
1497]], [[_IO_cookie_io_functions_t cookie;]])], [have_IO_cookie_io_functions_t=yes], [])
1498      if test "$have_cookie_io_functions_t" = "yes" ; then
1499        cookie_io_functions_t=_IO_cookie_io_functions_t
1500        have_fopen_cookie=yes
1501      fi
1502    fi
1503
1504    if test "$have_fopen_cookie" = "yes" ; then
1505      AC_DEFINE(HAVE_FOPENCOOKIE, 1, [ ])
1506      AC_DEFINE_UNQUOTED(COOKIE_IO_FUNCTIONS_T, $cookie_io_functions_t, [ ])
1507      if test "$cookie_io_functions_use_off64_t" = "yes" ; then
1508        AC_DEFINE(COOKIE_SEEKER_USES_OFF64_T, 1, [ ])
1509      fi
1510    fi
1511  fi
1512])
1513
1514dnl ----------------------------------------------------------------------------
1515dnl Library/function existence and build sanity checks.
1516dnl ----------------------------------------------------------------------------
1517
1518dnl
1519dnl PHP_CHECK_LIBRARY(library, function [, action-found [, action-not-found [, extra-libs]]])
1520dnl
1521dnl Wrapper for AC_CHECK_LIB.
1522dnl
1523AC_DEFUN([PHP_CHECK_LIBRARY], [
1524  save_old_LDFLAGS=$LDFLAGS
1525  ac_stuff="$5"
1526
1527  save_ext_shared=$ext_shared
1528  ext_shared=yes
1529  PHP_EVAL_LIBLINE([$]ac_stuff, LDFLAGS)
1530  AC_CHECK_LIB([$1],[$2],[
1531    LDFLAGS=$save_old_LDFLAGS
1532    ext_shared=$save_ext_shared
1533    $3
1534  ],[
1535    LDFLAGS=$save_old_LDFLAGS
1536    ext_shared=$save_ext_shared
1537    unset ac_cv_lib_$1[]_$2
1538    $4
1539  ])dnl
1540])
1541
1542dnl
1543dnl PHP_CHECK_FRAMEWORK(framework, function [, action-found [, action-not-found ]])
1544dnl
1545dnl El cheapo wrapper for AC_CHECK_LIB.
1546dnl
1547AC_DEFUN([PHP_CHECK_FRAMEWORK], [
1548  save_old_LDFLAGS=$LDFLAGS
1549  LDFLAGS="-framework $1 $LDFLAGS"
1550  dnl Supplying "c" to AC_CHECK_LIB is technically cheating, but rewriting
1551  dnl AC_CHECK_LIB is overkill and this only affects the "checking.." output
1552  dnl anyway.
1553  AC_CHECK_LIB(c,[$2],[
1554    LDFLAGS=$save_old_LDFLAGS
1555    $3
1556  ],[
1557    LDFLAGS=$save_old_LDFLAGS
1558    $4
1559  ])
1560])
1561
1562dnl
1563dnl PHP_CHECK_FUNC_LIB(func, libs)
1564dnl
1565dnl This macro checks whether 'func' or '__func' exists in the specified
1566dnl library. Defines HAVE_func and HAVE_library if found and adds the library to
1567dnl LIBS. This should be called in the ACTION-IF-NOT-FOUND part of
1568dnl PHP_CHECK_FUNC.
1569dnl
1570dnl autoconf undefines the builtin "shift" :-(
1571dnl If possible, we use the builtin shift anyway, otherwise we use the ubercool
1572dnl definition that has been tested so far with FreeBSD/GNU m4.
1573dnl
1574ifdef([builtin],[builtin(define, phpshift, [builtin(shift, $@)])],[
1575define([phpshift],[ifelse(index([$@],[,]),-1,,[substr([$@],incr(index([$@],[,])))])])
1576])
1577
1578dnl
1579dnl PHP_CHECK_FUNC_LIB
1580dnl
1581AC_DEFUN([PHP_CHECK_FUNC_LIB],[
1582  ifelse($2,,:,[
1583  unset ac_cv_lib_$2[]_$1
1584  unset ac_cv_lib_$2[]___$1
1585  unset found
1586  AC_CHECK_LIB($2, $1, [found=yes], [
1587    AC_CHECK_LIB($2, __$1, [found=yes], [found=no])
1588  ])
1589
1590  if test "$found" = "yes"; then
1591    ac_libs=$LIBS
1592    LIBS="$LIBS -l$2"
1593    AC_RUN_IFELSE([AC_LANG_SOURCE([[int main() { return (0); }]])],[found=yes],[found=no],[
1594      dnl Cross compilation.
1595      found=yes
1596    ])
1597    LIBS=$ac_libs
1598  fi
1599
1600  if test "$found" = "yes"; then
1601    PHP_ADD_LIBRARY($2)
1602    PHP_DEF_HAVE($1)
1603    PHP_DEF_HAVE(lib$2)
1604    ac_cv_func_$1=yes
1605  else
1606    PHP_CHECK_FUNC_LIB($1,phpshift(phpshift($@)))
1607  fi
1608  ])
1609])
1610
1611dnl
1612dnl PHP_CHECK_FUNC(func, ...)
1613dnl
1614dnl This macro checks whether 'func' or '__func' exists in the default libraries
1615dnl and as a fall back in the specified library. Defines HAVE_func and
1616dnl HAVE_library if found and adds the library to LIBS.
1617dnl
1618AC_DEFUN([PHP_CHECK_FUNC],[
1619  unset ac_cv_func_$1
1620  unset ac_cv_func___$1
1621  unset found
1622
1623  AC_CHECK_FUNC($1, [found=yes],[ AC_CHECK_FUNC(__$1,[found=yes],[found=no]) ])
1624
1625  case $found in
1626  yes[)]
1627    PHP_DEF_HAVE($1)
1628    ac_cv_func_$1=yes
1629  ;;
1630  ifelse($#,1,,[
1631    *[)] PHP_CHECK_FUNC_LIB($@) ;;
1632  ])
1633  esac
1634])
1635
1636dnl
1637dnl PHP_TEST_BUILD(function, action-if-ok, action-if-not-ok [, extra-libs [, extra-source]])
1638dnl
1639dnl This macro checks whether build works and given function exists.
1640dnl
1641AC_DEFUN([PHP_TEST_BUILD], [
1642  old_LIBS=$LIBS
1643  LIBS="$4 $LIBS"
1644  AC_LINK_IFELSE([AC_LANG_SOURCE([[
1645    $5
1646    char $1();
1647    int main() {
1648      $1();
1649      return 0;
1650    }
1651  ]])],[
1652    LIBS=$old_LIBS
1653    $2
1654  ],[
1655    LIBS=$old_LIBS
1656    $3
1657  ])
1658])
1659
1660dnl ----------------------------------------------------------------------------
1661dnl Platform characteristics checks.
1662dnl ----------------------------------------------------------------------------
1663
1664dnl
1665dnl PHP_SHLIB_SUFFIX_NAMES
1666dnl
1667dnl Determines link library suffix SHLIB_SUFFIX_NAME which can be: .so, .sl or
1668dnl .dylib
1669dnl
1670dnl Determines shared library suffix SHLIB_DL_SUFFIX_NAME suffix can be: .so or
1671dnl .sl
1672dnl
1673AC_DEFUN([PHP_SHLIB_SUFFIX_NAMES],[
1674 AC_REQUIRE([PHP_CANONICAL_HOST_TARGET])dnl
1675 PHP_SUBST_OLD(SHLIB_SUFFIX_NAME)
1676 PHP_SUBST_OLD(SHLIB_DL_SUFFIX_NAME)
1677 SHLIB_SUFFIX_NAME=so
1678 SHLIB_DL_SUFFIX_NAME=$SHLIB_SUFFIX_NAME
1679 case $host_alias in
1680 *hpux*[)]
1681   SHLIB_SUFFIX_NAME=sl
1682   SHLIB_DL_SUFFIX_NAME=sl
1683   ;;
1684 *darwin*[)]
1685   SHLIB_SUFFIX_NAME=dylib
1686   SHLIB_DL_SUFFIX_NAME=so
1687   ;;
1688 esac
1689])
1690
1691dnl
1692dnl PHP_C_BIGENDIAN
1693dnl
1694dnl Replacement macro for AC_C_BIGENDIAN.
1695dnl
1696AC_DEFUN([PHP_C_BIGENDIAN],
1697[AC_CACHE_CHECK([whether byte ordering is bigendian], ac_cv_c_bigendian_php,
1698 [
1699  ac_cv_c_bigendian_php=unknown
1700  AC_RUN_IFELSE([AC_LANG_SOURCE([[
1701int main(void)
1702{
1703  short one = 1;
1704  char *cp = (char *)&one;
1705
1706  if (*cp == 0) {
1707    return(0);
1708  } else {
1709    return(1);
1710  }
1711}
1712  ]])], [ac_cv_c_bigendian_php=yes], [ac_cv_c_bigendian_php=no], [ac_cv_c_bigendian_php=unknown])
1713 ])
1714 if test $ac_cv_c_bigendian_php = yes; then
1715   AC_DEFINE(WORDS_BIGENDIAN, [], [Define if processor uses big-endian word])
1716 fi
1717])
1718
1719dnl ----------------------------------------------------------------------------
1720dnl Checks for programs: PHP_PROG_<program>.
1721dnl ----------------------------------------------------------------------------
1722
1723dnl
1724dnl PHP_PROG_SENDMAIL
1725dnl
1726dnl Search for the sendmail binary.
1727dnl
1728AC_DEFUN([PHP_PROG_SENDMAIL], [
1729  PHP_ALT_PATH=/usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib
1730  AC_PATH_PROG(PROG_SENDMAIL, sendmail, /usr/sbin/sendmail, $PATH:$PHP_ALT_PATH)
1731  PHP_SUBST(PROG_SENDMAIL)
1732])
1733
1734dnl
1735dnl PHP_PROG_AWK
1736dnl
1737dnl Some vendors force mawk before gawk; mawk is broken so we don't like that.
1738dnl
1739AC_DEFUN([PHP_PROG_AWK], [
1740  AC_CHECK_PROGS(AWK, gawk nawk awk mawk, bork, /usr/xpg4/bin/:$PATH)
1741  case "$AWK" in
1742    *mawk)
1743      AC_MSG_WARN([mawk is known to have problems on some systems. You should install GNU awk])
1744      ;;
1745    *gawk)
1746      ;;
1747    bork)
1748      AC_MSG_ERROR([Could not find awk; Install GNU awk])
1749      ;;
1750    *)
1751      AC_MSG_CHECKING([if $AWK is broken])
1752      if ! $AWK 'function foo() {}' >/dev/null 2>&1 ; then
1753        AC_MSG_RESULT([yes])
1754        AC_MSG_ERROR([You should install GNU awk])
1755      else
1756        AC_MSG_RESULT([no])
1757      fi
1758      ;;
1759  esac
1760  PHP_SUBST(AWK)
1761])
1762
1763dnl
1764dnl PHP_PROG_BISON([MIN-VERSION], [EXCLUDED-VERSION...])
1765dnl
1766dnl Search for bison and optionally check if version is at least the minimum
1767dnl required version MIN-VERSION and doesn't match any of the blank separated
1768dnl list of excluded versions EXCLUDED-VERSION (for example "3.0 3.2").
1769dnl
1770AC_DEFUN([PHP_PROG_BISON], [
1771  AC_CHECK_PROG(YACC, bison, bison)
1772
1773  ifelse($1,,php_bison_required_version='',php_bison_required_version="$1")
1774  ifelse($2,,php_bison_excluded_versions='none',php_bison_excluded_versions="$2")
1775
1776  if test -n "$YACC"; then
1777    AC_MSG_CHECKING([for bison version])
1778
1779    php_bison_version=$($YACC --version 2> /dev/null | grep 'GNU Bison' | cut -d ' ' -f 4 | tr -d a-z)
1780    if test -z "$php_bison_version"; then
1781      php_bison_version=0.0.0
1782    fi
1783    ac_IFS=$IFS; IFS="."
1784    set $php_bison_version
1785    IFS=$ac_IFS
1786    php_bison_num=`expr [$]{1:-0} \* 10000 + [$]{2:-0} \* 100 + [$]{3:-0}`
1787    php_bison_branch="[$]1.[$]2"
1788    php_bison_check=ok
1789
1790    if test -z "$php_bison_required_version" && test -z "$php_bison_num"; then
1791      php_bison_check=invalid
1792    elif test -n "$php_bison_required_version"; then
1793      ac_IFS=$IFS; IFS="."
1794      set $php_bison_required_version
1795      IFS=$ac_IFS
1796      php_bison_required_num=`expr [$]{1:-0} \* 10000 + [$]{2:-0} \* 100 + [$]{3:-0}`
1797      php_bison_required_version="$php_bison_required_version or later"
1798
1799      if test -z "$php_bison_num" || test "$php_bison_num" -lt "$php_bison_required_num"; then
1800        php_bison_check=invalid
1801      fi
1802    fi
1803
1804    for php_bison_check_version in $php_bison_excluded_versions; do
1805      if test "$php_bison_version" = "$php_bison_check_version" || test "$php_bison_branch" = "$php_bison_check_version"; then
1806        php_bison_check=invalid
1807        break
1808      fi
1809    done
1810
1811    if test "$php_bison_check" != "invalid"; then
1812      PHP_SUBST_OLD([YFLAGS], [-Wall])
1813      AC_MSG_RESULT([$php_bison_version (ok)])
1814    else
1815      AC_MSG_RESULT([$php_bison_version])
1816    fi
1817  fi
1818
1819  case $php_bison_check in
1820    ""|invalid[)]
1821      if test ! -f "$abs_srcdir/Zend/zend_language_parser.h" || test ! -f "$abs_srcdir/Zend/zend_language_parser.c"; then
1822        AC_MSG_ERROR([bison $php_bison_required_version is required to generate PHP parsers (excluded versions: $php_bison_excluded_versions).])
1823      fi
1824
1825      YACC="exit 0;"
1826      ;;
1827  esac
1828
1829  PHP_SUBST(YACC)
1830])
1831
1832dnl
1833dnl PHP_PROG_RE2C([MIN-VERSION])
1834dnl
1835dnl Search for the re2c and optionally check if version is at least the minimum
1836dnl required version MIN-VERSION.
1837dnl
1838AC_DEFUN([PHP_PROG_RE2C],[
1839  AC_CHECK_PROG(RE2C, re2c, re2c)
1840
1841  ifelse($1,,php_re2c_required_version='',php_re2c_required_version="$1")
1842
1843  if test -n "$RE2C"; then
1844    AC_MSG_CHECKING([for re2c version])
1845
1846    php_re2c_version=$($RE2C --version | cut -d ' ' -f 2 2>/dev/null)
1847    if test -z "$php_re2c_version"; then
1848      php_re2c_version=0.0.0
1849    fi
1850    ac_IFS=$IFS; IFS="."
1851    set $php_re2c_version
1852    IFS=$ac_IFS
1853    php_re2c_num=`expr [$]{1:-0} \* 10000 + [$]{2:-0} \* 100 + [$]{3:-0}`
1854    php_re2c_check=ok
1855
1856    if test -z "$php_re2c_required_version" && test -z "$php_re2c_num"; then
1857      php_re2c_check=invalid
1858    elif test -n "$php_re2c_required_version"; then
1859      ac_IFS=$IFS; IFS="."
1860      set $php_re2c_required_version
1861      IFS=$ac_IFS
1862      php_re2c_required_num=`expr [$]{1:-0} \* 10000 + [$]{2:-0} \* 100 + [$]{3:-0}`
1863      php_re2c_required_version="$php_re2c_required_version or later"
1864
1865      if test -z "$php_re2c_num" || test "$php_re2c_num" -lt "$php_re2c_required_num"; then
1866        php_re2c_check=invalid
1867      fi
1868    fi
1869
1870    if test "$php_re2c_check" != "invalid"; then
1871      AC_MSG_RESULT([$php_re2c_version (ok)])
1872    else
1873      AC_MSG_RESULT([$php_re2c_version])
1874    fi
1875  fi
1876
1877  case $php_re2c_check in
1878    ""|invalid[)]
1879      if test ! -f "$abs_srcdir/Zend/zend_language_scanner.c"; then
1880        AC_MSG_ERROR([re2c $php_re2c_required_version is required to generate PHP lexers.])
1881      fi
1882
1883      RE2C="exit 0;"
1884      ;;
1885  esac
1886
1887  PHP_SUBST(RE2C)
1888])
1889
1890AC_DEFUN([PHP_PROG_PHP],[
1891  AC_CHECK_PROG(PHP, php, php)
1892
1893  if test -n "$PHP"; then
1894    AC_MSG_CHECKING([for php version])
1895    php_version=$($PHP -v | head -n1 | cut -d ' ' -f 2 | cut -d '-' -f 1)
1896    if test -z "$php_version"; then
1897      php_version=0.0.0
1898    fi
1899    ac_IFS=$IFS; IFS="."
1900    set $php_version
1901    IFS=$ac_IFS
1902    php_version_num=`expr [$]{1:-0} \* 10000 + [$]{2:-0} \* 100 + [$]{3:-0}`
1903    dnl Minimum supported version for gen_stubs.php is PHP 7.1.
1904    if test "$php_version_num" -lt 70100; then
1905      AC_MSG_RESULT([$php_version (too old)])
1906      unset PHP
1907    else
1908      AC_MSG_RESULT([$php_version (ok)])
1909    fi
1910  fi
1911  PHP_SUBST(PHP)
1912])
1913
1914dnl ----------------------------------------------------------------------------
1915dnl Common setup macros: PHP_SETUP_<what>
1916dnl ----------------------------------------------------------------------------
1917
1918dnl
1919dnl PHP_SETUP_ICU([shared-add])
1920dnl
1921dnl Common setup macro for ICU.
1922dnl
1923AC_DEFUN([PHP_SETUP_ICU],[
1924  PKG_CHECK_MODULES([ICU], [icu-uc >= 50.1 icu-io icu-i18n])
1925
1926  PHP_EVAL_INCLINE($ICU_CFLAGS)
1927  PHP_EVAL_LIBLINE($ICU_LIBS, $1)
1928
1929  ICU_CFLAGS="$ICU_CFLAGS -DU_NO_DEFAULT_INCLUDE_UTF_HEADERS=1"
1930  ICU_CXXFLAGS="$ICU_CXXFLAGS -DUNISTR_FROM_CHAR_EXPLICIT=explicit -DUNISTR_FROM_STRING_EXPLICIT=explicit"
1931
1932  if test "$PKG_CONFIG icu-io --atleast-version=60"; then
1933    ICU_CFLAGS="$ICU_CFLAGS -DU_HIDE_OBSOLETE_UTF_OLD_H=1"
1934  fi
1935])
1936
1937dnl
1938dnl PHP_SETUP_OPENSSL(shared-add [, action-found [, action-not-found]])
1939dnl
1940dnl Common setup macro for openssl.
1941dnl
1942AC_DEFUN([PHP_SETUP_OPENSSL],[
1943  found_openssl=no
1944
1945  PKG_CHECK_MODULES([OPENSSL], [openssl >= 1.0.2], [found_openssl=yes])
1946
1947  if test "$found_openssl" = "yes"; then
1948    PHP_EVAL_LIBLINE($OPENSSL_LIBS, $1)
1949    PHP_EVAL_INCLINE($OPENSSL_CFLAGS)
1950ifelse([$2],[],:,[$2])
1951ifelse([$3],[],,[else $3])
1952  fi
1953])
1954
1955dnl
1956dnl PHP_SETUP_ICONV(shared-add [, action-found [, action-not-found]])
1957dnl
1958dnl Common setup macro for iconv.
1959dnl
1960AC_DEFUN([PHP_SETUP_ICONV], [
1961  found_iconv=no
1962  unset ICONV_DIR
1963
1964  dnl Check libc first if no path is provided in --with-iconv.
1965  if test "$PHP_ICONV" = "yes"; then
1966    dnl Reset LIBS temporarily as it may have already been included -liconv in.
1967    LIBS_save="$LIBS"
1968    LIBS=
1969    AC_CHECK_FUNC(iconv, [
1970      found_iconv=yes
1971    ],[
1972      AC_CHECK_FUNC(libiconv,[
1973        AC_DEFINE(HAVE_LIBICONV, 1, [ ])
1974        found_iconv=yes
1975      ])
1976    ])
1977    LIBS="$LIBS_save"
1978  fi
1979
1980  dnl Check external libs for iconv funcs.
1981  if test "$found_iconv" = "no"; then
1982
1983    for i in $PHP_ICONV /usr/local /usr; do
1984      if test -r $i/include/gnu-libiconv/iconv.h; then
1985        ICONV_DIR=$i
1986        ICONV_INCLUDE_DIR=$i/include/gnu-libiconv
1987        iconv_lib_name=iconv
1988        break
1989      elif test -r $i/include/iconv.h; then
1990        ICONV_DIR=$i
1991        ICONV_INCLUDE_DIR=$i/include
1992        iconv_lib_name=iconv
1993        break
1994      fi
1995    done
1996
1997    if test -z "$ICONV_DIR"; then
1998      AC_MSG_ERROR([Please specify the install prefix of iconv with --with-iconv=<DIR>])
1999    fi
2000
2001    if test -f $ICONV_DIR/$PHP_LIBDIR/lib$iconv_lib_name.a ||
2002       test -f $ICONV_DIR/$PHP_LIBDIR/lib$iconv_lib_name.$SHLIB_SUFFIX_NAME ||
2003       test -f $ICONV_DIR/$PHP_LIBDIR/lib$iconv_lib_name.tbd
2004    then
2005      PHP_CHECK_LIBRARY($iconv_lib_name, libiconv, [
2006        found_iconv=yes
2007        AC_DEFINE(HAVE_LIBICONV,1,[ ])
2008        AC_DEFINE([ICONV_ALIASED_LIBICONV],1,[iconv() is aliased to libiconv() in -liconv])
2009      ], [
2010        PHP_CHECK_LIBRARY($iconv_lib_name, iconv, [
2011          found_iconv=yes
2012        ], [], [
2013          -L$ICONV_DIR/$PHP_LIBDIR
2014        ])
2015      ], [
2016        -L$ICONV_DIR/$PHP_LIBDIR
2017      ])
2018    fi
2019  fi
2020
2021  if test "$found_iconv" = "yes"; then
2022    AC_DEFINE(HAVE_ICONV,1,[ ])
2023    if test -n "$ICONV_DIR"; then
2024      PHP_ADD_LIBRARY_WITH_PATH($iconv_lib_name, $ICONV_DIR/$PHP_LIBDIR, $1)
2025      PHP_ADD_INCLUDE($ICONV_INCLUDE_DIR)
2026    fi
2027    $2
2028ifelse([$3],[],,[else $3])
2029  fi
2030])
2031
2032dnl
2033dnl PHP_SETUP_LIBXML(shared-add [, action-found [, action-not-found]])
2034dnl
2035dnl Common setup macro for libxml.
2036dnl
2037AC_DEFUN([PHP_SETUP_LIBXML], [
2038  PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.9.0])
2039
2040  PHP_EVAL_INCLINE($LIBXML_CFLAGS)
2041  PHP_EVAL_LIBLINE($LIBXML_LIBS, $1)
2042
2043  AC_DEFINE(HAVE_LIBXML, 1, [ ])
2044
2045  $2
2046])
2047
2048dnl
2049dnl PHP_SETUP_EXPAT([shared-add])
2050dnl
2051dnl Common setup macro for expat.
2052dnl
2053AC_DEFUN([PHP_SETUP_EXPAT], [
2054  PKG_CHECK_MODULES([EXPAT], [expat])
2055
2056  PHP_EVAL_INCLINE($EXPAT_CFLAGS)
2057  PHP_EVAL_LIBLINE($EXPAT_LIBS, $1)
2058
2059  AC_DEFINE(HAVE_LIBEXPAT, 1, [ ])
2060])
2061
2062dnl ----------------------------------------------------------------------------
2063dnl Misc. macros
2064dnl ----------------------------------------------------------------------------
2065
2066dnl
2067dnl PHP_INSTALL_HEADERS(path [, file ...])
2068dnl
2069dnl PHP header files to be installed.
2070dnl
2071AC_DEFUN([PHP_INSTALL_HEADERS],[
2072  ifelse([$2],[],[
2073    for header_file in $1; do
2074      PHP_RUN_ONCE(INSTALLHEADERS, $header_file, [
2075        INSTALL_HEADERS="$INSTALL_HEADERS $header_file"
2076      ])
2077    done
2078  ], [
2079    header_path=$1
2080    for header_file in $2; do
2081      hp_hf="$header_path/$header_file"
2082      PHP_RUN_ONCE(INSTALLHEADERS, $hp_hf, [
2083        INSTALL_HEADERS="$INSTALL_HEADERS $hp_hf"
2084      ])
2085    done
2086  ])
2087])
2088
2089dnl
2090dnl PHP_AP_EXTRACT_VERSION(/path/httpd)
2091dnl
2092dnl This macro is used to get a comparable version for Apache.
2093dnl
2094AC_DEFUN([PHP_AP_EXTRACT_VERSION],[
2095  ac_output=`$1 -v 2>&1 | grep version | $SED -e 's/Oracle-HTTP-//'`
2096  ac_IFS=$IFS
2097IFS="- /.
2098"
2099  set $ac_output
2100  IFS=$ac_IFS
2101
2102  APACHE_VERSION=`expr [$]4 \* 1000000 + [$]5 \* 1000 + [$]6`
2103])
2104
2105dnl
2106dnl PHP_CONFIG_NICE(filename)
2107dnl
2108dnl This macro creates script file with given filename which includes the last
2109dnl configure command run by user. This file is named 'config.nice' in PHP.
2110dnl
2111AC_DEFUN([PHP_CONFIG_NICE],[
2112  AC_REQUIRE([AC_PROG_EGREP])
2113  AC_REQUIRE([AC_PROG_SED])
2114  PHP_SUBST_OLD(EGREP)
2115  PHP_SUBST_OLD(SED)
2116  test -f $1 && mv $1 $1.old
2117  rm -f $1.old
2118  cat >$1<<EOF
2119#! /bin/sh
2120#
2121# Created by configure
2122
2123EOF
2124
2125  clean_configure_args=$ac_configure_args
2126  for var in CFLAGS CXXFLAGS CPPFLAGS LDFLAGS EXTRA_LDFLAGS_PROGRAM LIBS CC CXX; do
2127    eval val=\$$var
2128    if test -n "$val"; then
2129      echo "$var='$val' \\" >> $1
2130      if test `expr "X$ac_configure_args" : ".*${var}.*"` != 0; then
2131        clean_configure_args=$(echo $clean_configure_args | sed -e "s#'$var=$val'##")
2132      fi
2133    fi
2134  done
2135
2136  echo "'[$]0' \\" >> $1
2137  if test `expr " [$]0" : " '.*"` = 0; then
2138    CONFIGURE_COMMAND="$CONFIGURE_COMMAND '[$]0'"
2139  else
2140    CONFIGURE_COMMAND="$CONFIGURE_COMMAND [$]0"
2141  fi
2142  CONFIGURE_ARGS="$clean_configure_args"
2143  while test "X$CONFIGURE_ARGS" != "X";
2144  do
2145   if CURRENT_ARG=`expr "X$CONFIGURE_ARGS" : "X *\('[[^']]*'\)"`
2146   then
2147     CONFIGURE_ARGS=`expr "X$CONFIGURE_ARGS" : "X *'[[^']]*' \(.*\)"`
2148   elif CURRENT_ARG=`expr "X$CONFIGURE_ARGS" : "X *\([[^ ]]*\)"`
2149   then
2150     CONFIGURE_ARGS=`expr "X$CONFIGURE_ARGS" : "X *[[^ ]]* \(.*\)"`
2151     CURRENT_ARG="'$CURRENT_ARG'"
2152   else
2153    break
2154   fi
2155   AS_ECHO(["$CURRENT_ARG \\"]) >>$1
2156   CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS $CURRENT_ARG"
2157  done
2158  echo '"[$]@"' >> $1
2159  chmod +x $1
2160  CONFIGURE_COMMAND="$CONFIGURE_COMMAND $CONFIGURE_OPTIONS"
2161  PHP_SUBST_OLD(CONFIGURE_COMMAND)
2162  PHP_SUBST_OLD(CONFIGURE_OPTIONS)
2163])
2164
2165dnl
2166dnl PHP_CHECK_PDO_INCLUDES([found [, not-found]])
2167dnl
2168AC_DEFUN([PHP_CHECK_PDO_INCLUDES],[
2169  AC_CACHE_CHECK([for PDO includes], pdo_cv_inc_path, [
2170    if test -f $abs_srcdir/include/php/ext/pdo/php_pdo_driver.h; then
2171      pdo_cv_inc_path=$abs_srcdir/ext
2172    elif test -f $abs_srcdir/ext/pdo/php_pdo_driver.h; then
2173      pdo_cv_inc_path=$abs_srcdir/ext
2174    elif test -f $phpincludedir/ext/pdo/php_pdo_driver.h; then
2175      pdo_cv_inc_path=$phpincludedir/ext
2176    fi
2177  ])
2178  if test -n "$pdo_cv_inc_path"; then
2179ifelse([$1],[],:,[$1])
2180  else
2181ifelse([$2],[],[AC_MSG_ERROR([Cannot find php_pdo_driver.h.])],[$2])
2182  fi
2183])
2184
2185dnl
2186dnl PHP_DETECT_ICC
2187dnl
2188dnl Detect Intel C++ Compiler and unset $GCC if ICC found.
2189dnl
2190AC_DEFUN([PHP_DETECT_ICC],
2191[
2192  ICC="no"
2193  AC_MSG_CHECKING([for icc])
2194  AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
2195    ICC="no"
2196    AC_MSG_RESULT([no]),
2197    ICC="yes"
2198    GCC="no"
2199    AC_MSG_RESULT([yes])
2200  )
2201])
2202
2203dnl
2204dnl PHP_DETECT_SUNCC
2205dnl
2206dnl Detect if the systems default compiler is suncc. We also set some useful
2207dnl CFLAGS if the user didn't set any.
2208dnl
2209AC_DEFUN([PHP_DETECT_SUNCC],[
2210  SUNCC="no"
2211  AC_MSG_CHECKING([for suncc])
2212  AC_EGREP_CPP([^__SUNPRO_C], [__SUNPRO_C],
2213    SUNCC="no"
2214    AC_MSG_RESULT([no]),
2215    SUNCC="yes"
2216    GCC="no"
2217    test -n "$auto_cflags" && CFLAGS="-O -xs -xstrconst -zlazyload"
2218    GCC=""
2219    AC_MSG_RESULT([yes])
2220  )
2221])
2222
2223dnl
2224dnl PHP_CRYPT_R_STYLE
2225dnl
2226dnl Detect the style of crypt_r() if any is available.
2227dnl See APR_CHECK_CRYPT_R_STYLE() for original version.
2228dnl
2229AC_DEFUN([PHP_CRYPT_R_STYLE],
2230[
2231  AC_CACHE_CHECK([which data struct is used by crypt_r], php_cv_crypt_r_style,[
2232    php_cv_crypt_r_style=none
2233    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2234#define _REENTRANT 1
2235#include <crypt.h>
2236]], [[
2237CRYPTD buffer;
2238crypt_r("passwd", "hash", &buffer);
2239]])],[php_cv_crypt_r_style=cryptd],[])
2240
2241    if test "$php_cv_crypt_r_style" = "none"; then
2242      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2243#define _REENTRANT 1
2244#include <crypt.h>
2245]],[[
2246struct crypt_data buffer;
2247crypt_r("passwd", "hash", &buffer);
2248]])],[php_cv_crypt_r_style=struct_crypt_data],[])
2249    fi
2250
2251    if test "$php_cv_crypt_r_style" = "none"; then
2252      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2253#define _REENTRANT 1
2254#define _GNU_SOURCE
2255#include <crypt.h>
2256]],[[
2257struct crypt_data buffer;
2258crypt_r("passwd", "hash", &buffer);
2259]])],[php_cv_crypt_r_style=struct_crypt_data_gnu_source],[])
2260    fi
2261
2262    if test "$php_cv_crypt_r_style" = "none"; then
2263      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2264#include <stdlib.h>
2265#include <unistd.h>
2266]],[[
2267struct crypt_data buffer;
2268crypt_r("passwd", "hash", &buffer);
2269]])],[php_cv_crypt_r_style=struct_crypt_data],[])
2270    fi
2271    ])
2272
2273  if test "$php_cv_crypt_r_style" = "cryptd"; then
2274    AC_DEFINE(CRYPT_R_CRYPTD, 1, [Define if crypt_r has uses CRYPTD])
2275  fi
2276  if test "$php_cv_crypt_r_style" = "struct_crypt_data" -o "$php_cv_crypt_r_style" = "struct_crypt_data_gnu_source"; then
2277    AC_DEFINE(CRYPT_R_STRUCT_CRYPT_DATA, 1, [Define if crypt_r uses struct crypt_data])
2278  fi
2279  if test "$php_cv_crypt_r_style" = "struct_crypt_data_gnu_source"; then
2280    AC_DEFINE(CRYPT_R_GNU_SOURCE, 1, [Define if struct crypt_data requires _GNU_SOURCE])
2281  fi
2282  if test "$php_cv_crypt_r_style" = "none"; then
2283    AC_MSG_ERROR([Unable to detect data struct used by crypt_r])
2284  fi
2285])
2286
2287dnl
2288dnl PHP_TEST_WRITE_STDOUT
2289dnl
2290AC_DEFUN([PHP_TEST_WRITE_STDOUT],[
2291  AC_CACHE_CHECK(whether writing to stdout works,ac_cv_write_stdout,[
2292    AC_RUN_IFELSE([AC_LANG_SOURCE([[
2293#ifdef HAVE_UNISTD_H
2294#include <unistd.h>
2295#endif
2296
2297#define TEXT "This is the test message -- "
2298
2299int main()
2300{
2301  int n;
2302
2303  n = write(1, TEXT, sizeof(TEXT)-1);
2304  return (!(n == sizeof(TEXT)-1));
2305}
2306    ]])],[
2307      ac_cv_write_stdout=yes
2308    ],[
2309      ac_cv_write_stdout=no
2310    ],[
2311      case $host_alias in
2312        *linux*)
2313          ac_cv_write_stdout=yes
2314          ;;
2315        *)
2316          ac_cv_write_stdout=no
2317          ;;
2318      esac
2319    ])
2320  ])
2321  if test "$ac_cv_write_stdout" = "yes"; then
2322    AC_DEFINE(PHP_WRITE_STDOUT, 1, [whether write(2) works])
2323  fi
2324])
2325
2326dnl
2327dnl PHP_INIT_DTRACE(providerdesc, header-file, sources [, module])
2328dnl
2329AC_DEFUN([PHP_INIT_DTRACE],[
2330dnl Set paths properly when called from extension.
2331  case "$4" in
2332    ""[)] ac_srcdir="$abs_srcdir/"; unset ac_bdir;;
2333    /*[)] ac_srcdir=`echo "$4"|cut -c 2-`"/"; ac_bdir=$ac_srcdir;;
2334    *[)] ac_srcdir="$abs_srcdir/$1/"; ac_bdir="$4/";;
2335  esac
2336
2337dnl providerdesc.
2338  ac_provsrc=$1
2339  old_IFS=[$]IFS
2340  IFS=.
2341  set $ac_provsrc
2342  ac_provobj=[$]1
2343  IFS=$old_IFS
2344
2345dnl header-file.
2346  ac_hdrobj=$2
2347
2348dnl Add providerdesc.o or .lo into global objects when needed.
2349  case $host_alias in
2350  *freebsd*)
2351    PHP_GLOBAL_OBJS="[$]PHP_GLOBAL_OBJS [$]ac_bdir[$]ac_provsrc.lo"
2352    PHP_LDFLAGS="$PHP_LDFLAGS -lelf"
2353    ;;
2354  *solaris*)
2355    PHP_GLOBAL_OBJS="[$]PHP_GLOBAL_OBJS [$]ac_bdir[$]ac_provsrc.lo"
2356    ;;
2357  *linux*)
2358    PHP_GLOBAL_OBJS="[$]PHP_GLOBAL_OBJS [$]ac_bdir[$]ac_provsrc.lo"
2359    ;;
2360  esac
2361
2362dnl DTrace objects.
2363  old_IFS=[$]IFS
2364  for ac_src in $3; do
2365    IFS=.
2366    set $ac_src
2367    ac_obj=[$]1
2368    IFS=$old_IFS
2369
2370    PHP_DTRACE_OBJS="[$]PHP_DTRACE_OBJS [$]ac_bdir[$]ac_obj.lo"
2371  done;
2372
2373  case [$]php_sapi_module in
2374  shared[)]
2375    for ac_lo in $PHP_DTRACE_OBJS; do
2376      dtrace_objs="[$]dtrace_objs `echo $ac_lo | $SED -e 's,\.lo$,.o,' -e 's#\(.*\)\/#\1\/.libs\/#'`"
2377    done;
2378    ;;
2379  *[)]
2380    dtrace_objs='$(PHP_DTRACE_OBJS:.lo=.o)'
2381    ;;
2382  esac
2383
2384dnl Generate Makefile.objects entries. The empty $ac_provsrc command stops an
2385dnl implicit circular dependency in GNU Make which causes the .d file to be
2386dnl overwritten (Bug 61268).
2387  cat>>Makefile.objects<<EOF
2388
2389$abs_srcdir/$ac_provsrc:;
2390
2391$ac_bdir[$]ac_hdrobj: $abs_srcdir/$ac_provsrc
2392	CFLAGS="\$(CFLAGS_CLEAN)" dtrace -h -C -s $ac_srcdir[$]ac_provsrc -o \$[]@.bak && \$(SED) -e 's,PHP_,DTRACE_,g' \$[]@.bak > \$[]@
2393
2394\$(PHP_DTRACE_OBJS): $ac_bdir[$]ac_hdrobj
2395
2396EOF
2397
2398  case $host_alias in
2399  *solaris*|*linux*|*freebsd*)
2400    dtrace_prov_name="`echo $ac_provsrc | $SED -e 's#\(.*\)\/##'`.o"
2401    dtrace_lib_dir="`echo $ac_bdir[$]ac_provsrc | $SED -e 's#\(.*\)/[^/]*#\1#'`/.libs"
2402    dtrace_d_obj="`echo $ac_bdir[$]ac_provsrc | $SED -e 's#\(.*\)/\([^/]*\)#\1/.libs/\2#'`.o"
2403    dtrace_nolib_objs='$(PHP_DTRACE_OBJS:.lo=.o)'
2404    for ac_lo in $PHP_DTRACE_OBJS; do
2405      dtrace_lib_objs="[$]dtrace_lib_objs `echo $ac_lo | $SED -e 's,\.lo$,.o,' -e 's#\(.*\)\/#\1\/.libs\/#'`"
2406    done;
2407    dnl Always attempt to create both PIC and non-PIC DTrace objects (Bug 63692)
2408    cat>>Makefile.objects<<EOF
2409$ac_bdir[$]ac_provsrc.lo: \$(PHP_DTRACE_OBJS)
2410	echo "[#] Generated by Makefile for libtool" > \$[]@
2411	@test -d "$dtrace_lib_dir" || mkdir $dtrace_lib_dir
2412	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 [\\]
2413	  echo "pic_object=['].libs/$dtrace_prov_name[']" >> \$[]@ [;\\]
2414	else [\\]
2415	  echo "pic_object='none'" >> \$[]@ [;\\]
2416	fi
2417	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 [\\]
2418	  echo "non_pic_object=[']$dtrace_prov_name[']" >> \$[]@ [;\\]
2419	else [\\]
2420	  echo "non_pic_object='none'" >> \$[]@ [;\\]
2421	fi
2422
2423EOF
2424
2425    ;;
2426  *)
2427cat>>Makefile.objects<<EOF
2428$ac_bdir[$]ac_provsrc.o: \$(PHP_DTRACE_OBJS)
2429	CFLAGS="\$(CFLAGS_CLEAN)" dtrace -G -o \$[]@ -s $abs_srcdir/$ac_provsrc $dtrace_objs
2430
2431EOF
2432    ;;
2433  esac
2434])
2435
2436dnl
2437dnl PHP_CHECK_STDINT_TYPES
2438dnl
2439AC_DEFUN([PHP_CHECK_STDINT_TYPES], [
2440  AC_CHECK_SIZEOF([short])
2441  AC_CHECK_SIZEOF([int])
2442  AC_CHECK_SIZEOF([long])
2443  AC_CHECK_SIZEOF([long long])
2444  AC_CHECK_SIZEOF([size_t])
2445  AC_CHECK_SIZEOF([off_t])
2446  AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t], [], [
2447    AC_MSG_ERROR([One of the intN_t or uintN_t types is not available])
2448  ], [
2449#include <stdint.h>
2450#if HAVE_SYS_TYPES_H
2451# include <sys/types.h>
2452#endif
2453  ])
2454])
2455
2456dnl
2457dnl PHP_CHECK_BUILTIN_EXPECT
2458dnl
2459AC_DEFUN([PHP_CHECK_BUILTIN_EXPECT], [
2460  AC_MSG_CHECKING([for __builtin_expect])
2461
2462  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2463    return __builtin_expect(1,1) ? 1 : 0;
2464  ]])], [
2465    have_builtin_expect=1
2466    AC_MSG_RESULT([yes])
2467  ], [
2468    have_builtin_expect=0
2469    AC_MSG_RESULT([no])
2470  ])
2471
2472  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_EXPECT], [$have_builtin_expect], [Whether the compiler supports __builtin_expect])
2473])
2474
2475dnl
2476dnl PHP_CHECK_BUILTIN_CLZ
2477dnl
2478AC_DEFUN([PHP_CHECK_BUILTIN_CLZ], [
2479  AC_MSG_CHECKING([for __builtin_clz])
2480
2481  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2482    return __builtin_clz(1) ? 1 : 0;
2483  ]])], [
2484    have_builtin_clz=1
2485    AC_MSG_RESULT([yes])
2486  ], [
2487    have_builtin_clz=0
2488    AC_MSG_RESULT([no])
2489  ])
2490
2491  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_CLZ], [$have_builtin_clz], [Whether the compiler supports __builtin_clz])
2492])
2493
2494dnl
2495dnl PHP_CHECK_BUILTIN_CLZL
2496dnl
2497AC_DEFUN([PHP_CHECK_BUILTIN_CLZL], [
2498  AC_MSG_CHECKING([for __builtin_clzl])
2499
2500  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2501    return __builtin_clzl(1) ? 1 : 0;
2502  ]])], [
2503    have_builtin_clzl=1
2504    AC_MSG_RESULT([yes])
2505  ], [
2506    have_builtin_clzl=0
2507    AC_MSG_RESULT([no])
2508  ])
2509
2510  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_CLZL], [$have_builtin_clzl], [Whether the compiler supports __builtin_clzl])
2511])
2512
2513dnl
2514dnl PHP_CHECK_BUILTIN_CLZLL
2515dnl
2516AC_DEFUN([PHP_CHECK_BUILTIN_CLZLL], [
2517  AC_MSG_CHECKING([for __builtin_clzll])
2518
2519  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2520    return __builtin_clzll(1) ? 1 : 0;
2521  ]])], [
2522    have_builtin_clzll=1
2523    AC_MSG_RESULT([yes])
2524  ], [
2525    have_builtin_clzll=0
2526    AC_MSG_RESULT([no])
2527  ])
2528
2529  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_CLZLL], [$have_builtin_clzll], [Whether the compiler supports __builtin_clzll])
2530])
2531
2532dnl
2533dnl PHP_CHECK_BUILTIN_CTZL
2534dnl
2535AC_DEFUN([PHP_CHECK_BUILTIN_CTZL], [
2536  AC_MSG_CHECKING([for __builtin_ctzl])
2537
2538  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2539    return __builtin_ctzl(2L) ? 1 : 0;
2540  ]])], [
2541    have_builtin_ctzl=1
2542    AC_MSG_RESULT([yes])
2543  ], [
2544    have_builtin_ctzl=0
2545    AC_MSG_RESULT([no])
2546  ])
2547
2548  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_CTZL], [$have_builtin_ctzl], [Whether the compiler supports __builtin_ctzl])
2549])
2550
2551dnl
2552dnl PHP_CHECK_BUILTIN_CTZLL
2553dnl
2554AC_DEFUN([PHP_CHECK_BUILTIN_CTZLL], [
2555  AC_MSG_CHECKING([for __builtin_ctzll])
2556
2557  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2558    return __builtin_ctzll(2LL) ? 1 : 0;
2559  ]])], [
2560    have_builtin_ctzll=1
2561    AC_MSG_RESULT([yes])
2562  ], [
2563    have_builtin_ctzll=0
2564    AC_MSG_RESULT([no])
2565  ])
2566
2567  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_CTZLL], [$have_builtin_ctzll], [Whether the compiler supports __builtin_ctzll])
2568])
2569
2570dnl
2571dnl PHP_CHECK_BUILTIN_SMULL_OVERFLOW
2572dnl
2573AC_DEFUN([PHP_CHECK_BUILTIN_SMULL_OVERFLOW], [
2574  AC_MSG_CHECKING([for __builtin_smull_overflow])
2575
2576  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2577    long tmpvar;
2578    return __builtin_smull_overflow(3, 7, &tmpvar);
2579  ]])], [
2580    have_builtin_smull_overflow=1
2581    AC_MSG_RESULT([yes])
2582  ], [
2583    have_builtin_smull_overflow=0
2584    AC_MSG_RESULT([no])
2585  ])
2586
2587  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_SMULL_OVERFLOW],
2588   [$have_builtin_smull_overflow], [Whether the compiler supports __builtin_smull_overflow])
2589])
2590
2591dnl
2592dnl PHP_CHECK_BUILTIN_SMULLL_OVERFLOW
2593dnl
2594AC_DEFUN([PHP_CHECK_BUILTIN_SMULLL_OVERFLOW], [
2595  AC_MSG_CHECKING([for __builtin_smulll_overflow])
2596
2597  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2598    long long tmpvar;
2599    return __builtin_smulll_overflow(3, 7, &tmpvar);
2600  ]])], [
2601    have_builtin_smulll_overflow=1
2602    AC_MSG_RESULT([yes])
2603  ], [
2604    have_builtin_smulll_overflow=0
2605    AC_MSG_RESULT([no])
2606  ])
2607
2608  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_SMULLL_OVERFLOW],
2609   [$have_builtin_smulll_overflow], [Whether the compiler supports __builtin_smulll_overflow])
2610])
2611
2612dnl
2613dnl PHP_CHECK_BUILTIN_SADDL_OVERFLOW
2614dnl
2615AC_DEFUN([PHP_CHECK_BUILTIN_SADDL_OVERFLOW], [
2616  AC_MSG_CHECKING([for __builtin_saddl_overflow])
2617
2618  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2619    long tmpvar;
2620    return __builtin_saddl_overflow(3, 7, &tmpvar);
2621  ]])], [
2622    have_builtin_saddl_overflow=1
2623    AC_MSG_RESULT([yes])
2624  ], [
2625    have_builtin_saddl_overflow=0
2626    AC_MSG_RESULT([no])
2627  ])
2628
2629  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_SADDL_OVERFLOW],
2630   [$have_builtin_saddl_overflow], [Whether the compiler supports __builtin_saddl_overflow])
2631])
2632
2633dnl
2634dnl PHP_CHECK_BUILTIN_SADDLL_OVERFLOW
2635dnl
2636AC_DEFUN([PHP_CHECK_BUILTIN_SADDLL_OVERFLOW], [
2637  AC_MSG_CHECKING([for __builtin_saddll_overflow])
2638
2639  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2640    long long tmpvar;
2641    return __builtin_saddll_overflow(3, 7, &tmpvar);
2642  ]])], [
2643    have_builtin_saddll_overflow=1
2644    AC_MSG_RESULT([yes])
2645  ], [
2646    have_builtin_saddll_overflow=0
2647    AC_MSG_RESULT([no])
2648  ])
2649
2650  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_SADDLL_OVERFLOW],
2651   [$have_builtin_saddll_overflow], [Whether the compiler supports __builtin_saddll_overflow])
2652])
2653
2654dnl
2655dnl PHP_CHECK_BUILTIN_SSUBL_OVERFLOW
2656dnl
2657AC_DEFUN([PHP_CHECK_BUILTIN_SSUBL_OVERFLOW], [
2658  AC_MSG_CHECKING([for __builtin_ssubl_overflow])
2659
2660  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2661    long tmpvar;
2662    return __builtin_ssubl_overflow(3, 7, &tmpvar);
2663  ]])], [
2664    have_builtin_ssubl_overflow=1
2665    AC_MSG_RESULT([yes])
2666  ], [
2667    have_builtin_ssubl_overflow=0
2668    AC_MSG_RESULT([no])
2669  ])
2670
2671  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_SSUBL_OVERFLOW],
2672   [$have_builtin_ssubl_overflow], [Whether the compiler supports __builtin_ssubl_overflow])
2673])
2674
2675dnl
2676dnl PHP_CHECK_BUILTIN_SSUBLL_OVERFLOW
2677dnl
2678AC_DEFUN([PHP_CHECK_BUILTIN_SSUBLL_OVERFLOW], [
2679  AC_MSG_CHECKING([for __builtin_ssubll_overflow])
2680
2681  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2682    long long tmpvar;
2683    return __builtin_ssubll_overflow(3, 7, &tmpvar);
2684  ]])], [
2685    have_builtin_ssubll_overflow=1
2686    AC_MSG_RESULT([yes])
2687  ], [
2688    have_builtin_ssubll_overflow=0
2689    AC_MSG_RESULT([no])
2690  ])
2691
2692  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_SSUBLL_OVERFLOW],
2693   [$have_builtin_ssubll_overflow], [Whether the compiler supports __builtin_ssubll_overflow])
2694])
2695
2696dnl
2697dnl PHP_CHECK_BUILTIN_CPU_INIT
2698dnl
2699AC_DEFUN([PHP_CHECK_BUILTIN_CPU_INIT], [
2700  AC_MSG_CHECKING([for __builtin_cpu_init])
2701
2702  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2703    __builtin_cpu_init();
2704  ]])], [
2705    have_builtin_cpu_init=1
2706    AC_MSG_RESULT([yes])
2707  ], [
2708    have_builtin_cpu_init=0
2709    AC_MSG_RESULT([no])
2710  ])
2711
2712  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_CPU_INIT],
2713   [$have_builtin_cpu_init], [Whether the compiler supports __builtin_cpu_init])
2714])
2715
2716dnl
2717dnl PHP_CHECK_BUILTIN_CPU_SUPPORTS
2718dnl
2719AC_DEFUN([PHP_CHECK_BUILTIN_CPU_SUPPORTS], [
2720  AC_MSG_CHECKING([for __builtin_cpu_supports])
2721
2722  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
2723    return __builtin_cpu_supports("sse")? 1 : 0;
2724  ]])], [
2725    have_builtin_cpu_supports=1
2726    AC_MSG_RESULT([yes])
2727  ], [
2728    have_builtin_cpu_supports=0
2729    AC_MSG_RESULT([no])
2730  ])
2731
2732  AC_DEFINE_UNQUOTED([PHP_HAVE_BUILTIN_CPU_SUPPORTS],
2733   [$have_builtin_cpu_supports], [Whether the compiler supports __builtin_cpu_supports])
2734])
2735
2736dnl
2737dnl PHP_PATCH_CONFIG_HEADERS([FILE])
2738dnl
2739dnl PACKAGE_* symbols are automatically defined by Autoconf. When including
2740dnl configuration header, warnings about redefined symbols are emitted for such
2741dnl symbols if they are defined by multiple libraries. This disables all
2742dnl PACKAGE_* symbols in the generated configuration header template FILE. For
2743dnl example, main/php_config.h.in for PHP or config.h.in for PHP extensions.
2744dnl
2745AC_DEFUN([PHP_PATCH_CONFIG_HEADERS], [
2746  AC_MSG_NOTICE([patching $1])
2747
2748  $SED -e 's/^#undef PACKAGE_[^ ]*/\/\* & \*\//g' < $srcdir/$1 \
2749    > $srcdir/$1.tmp && mv $srcdir/$1.tmp $srcdir/$1
2750])
2751