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