source: trunk/server/common/oursrc/php_scripts/test/acinclude.m4 @ 1137

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