]> granicus.if.org Git - apache/blob - acinclude.m4
ad92f1d1f549604a968904a36778008b4d6eac80
[apache] / acinclude.m4
1
2 dnl APACHE_HELP_STRING(LHS, RHS)
3 dnl Autoconf 2.50 can not handle substr correctly.  It does have 
4 dnl AC_HELP_STRING, so let's try to call it if we can.
5 dnl Note: this define must be on one line so that it can be properly returned
6 dnl as the help string.
7 AC_DEFUN(APACHE_HELP_STRING,[ifelse(regexp(AC_ACVERSION, 2\.1), -1, AC_HELP_STRING($1,$2),[  ]$1 substr([                       ],len($1))$2)])dnl
8
9 dnl APACHE_SUBST(VARIABLE)
10 dnl Makes VARIABLE available in generated files
11 dnl (do not use @variable@ in Makefiles, but $(variable))
12 AC_DEFUN(APACHE_SUBST,[
13   APACHE_VAR_SUBST="$APACHE_VAR_SUBST $1"
14   AC_SUBST($1)
15 ])
16
17 dnl APACHE_FAST_OUTPUT(FILENAME)
18 dnl Perform substitutions on FILENAME (Makefiles only)
19 AC_DEFUN(APACHE_FAST_OUTPUT,[
20   APACHE_FAST_OUTPUT_FILES="$APACHE_FAST_OUTPUT_FILES $1"
21 ])
22
23 dnl APACHE_MKDIR_P_CHECK
24 dnl checks whether mkdir -p works
25 AC_DEFUN(APACHE_MKDIR_P_CHECK,[
26   AC_CACHE_CHECK(for working mkdir -p, ac_cv_mkdir_p,[
27     test -d conftestdir && rm -rf conftestdir
28     mkdir -p conftestdir/somedir >/dev/null 2>&1
29     if test -d conftestdir/somedir; then
30       ac_cv_mkdir_p=yes
31     else
32       ac_cv_mkdir_p=no
33     fi
34     rm -rf conftestdir
35   ])
36 ])
37
38 dnl APACHE_GEN_CONFIG_VARS
39 dnl Creates config_vars.mk
40 AC_DEFUN(APACHE_GEN_CONFIG_VARS,[
41   APACHE_SUBST(abs_srcdir)
42   APACHE_SUBST(bindir)
43   APACHE_SUBST(sbindir)
44   APACHE_SUBST(cgidir)
45   APACHE_SUBST(logfiledir)
46   APACHE_SUBST(exec_prefix)
47   APACHE_SUBST(datadir)
48   APACHE_SUBST(localstatedir)
49   APACHE_SUBST(mandir)
50   APACHE_SUBST(libexecdir)
51   APACHE_SUBST(htdocsdir)
52   APACHE_SUBST(manualdir)
53   APACHE_SUBST(includedir)
54   APACHE_SUBST(errordir)
55   APACHE_SUBST(iconsdir)
56   APACHE_SUBST(sysconfdir)
57   APACHE_SUBST(installbuilddir)
58   APACHE_SUBST(other_targets)
59   APACHE_SUBST(progname)
60   APACHE_SUBST(prefix)
61   APACHE_SUBST(AWK)
62   APACHE_SUBST(CC)
63   APACHE_SUBST(CPP)
64   APACHE_SUBST(CXX)
65   APACHE_SUBST(CPPFLAGS)
66   APACHE_SUBST(CFLAGS)
67   APACHE_SUBST(CXXFLAGS)
68   APACHE_SUBST(LTFLAGS)
69   APACHE_SUBST(LDFLAGS)
70   APACHE_SUBST(LT_LDFLAGS)
71   APACHE_SUBST(SH_LDFLAGS)
72   APACHE_SUBST(HTTPD_LDFLAGS)
73   APACHE_SUBST(LIBS)
74   APACHE_SUBST(DEFS)
75   APACHE_SUBST(INCLUDES)
76   APACHE_SUBST(NOTEST_CPPFLAGS)
77   APACHE_SUBST(NOTEST_CFLAGS)
78   APACHE_SUBST(NOTEST_CXXFLAGS)
79   APACHE_SUBST(NOTEST_LDFLAGS)
80   APACHE_SUBST(NOTEST_LIBS)
81   APACHE_SUBST(EXTRA_CPPFLAGS)
82   APACHE_SUBST(EXTRA_CFLAGS)
83   APACHE_SUBST(EXTRA_CXXFLAGS)
84   APACHE_SUBST(EXTRA_LDFLAGS)
85   APACHE_SUBST(EXTRA_LIBS)
86   APACHE_SUBST(EXTRA_INCLUDES)
87   APACHE_SUBST(LIBTOOL)
88   APACHE_SUBST(SHELL)
89   APACHE_SUBST(MODULE_DIRS)
90   APACHE_SUBST(MODULE_CLEANDIRS)
91   APACHE_SUBST(PORT)
92   APACHE_SUBST(CORE_IMPLIB_FILE)
93   APACHE_SUBST(CORE_IMPLIB)
94   APACHE_SUBST(SH_LIBTOOL)
95   APACHE_SUBST(MK_IMPLIB)
96   APACHE_SUBST(INSTALL_PROG_FLAGS)
97
98   abs_srcdir="`(cd $srcdir && pwd)`"
99
100   APACHE_MKDIR_P_CHECK
101   echo creating config_vars.mk
102   > config_vars.mk
103   for i in $APACHE_VAR_SUBST; do
104     eval echo "$i = \$$i" >> config_vars.mk
105   done
106 ])
107
108 dnl APACHE_GEN_MAKEFILES
109 dnl Creates Makefiles
110 AC_DEFUN(APACHE_GEN_MAKEFILES,[
111   $SHELL $srcdir/build/fastgen.sh $srcdir $ac_cv_mkdir_p $BSD_MAKEFILE $APACHE_FAST_OUTPUT_FILES
112 ])
113
114 dnl ## APACHE_OUTPUT(file)
115 dnl ## adds "file" to the list of files generated by AC_OUTPUT
116 dnl ## This macro can be used several times.
117 AC_DEFUN(APACHE_OUTPUT, [
118   APACHE_OUTPUT_FILES="$APACHE_OUTPUT_FILES $1"
119 ])
120
121 dnl
122 dnl APACHE_TYPE_RLIM_T
123 dnl
124 dnl If rlim_t is not defined, define it to int
125 dnl
126 AC_DEFUN(APACHE_TYPE_RLIM_T, [
127   AC_CACHE_CHECK([for rlim_t], ac_cv_type_rlim_t, [
128     AC_TRY_COMPILE([
129 #include <sys/types.h>
130 #include <sys/time.h>
131 #include <sys/resource.h>
132 ], [rlim_t spoon;], [
133       ac_cv_type_rlim_t=yes
134     ],[ac_cv_type_rlim_t=no
135     ])
136   ])
137   if test "$ac_cv_type_rlim_t" = "no" ; then
138       AC_DEFINE(rlim_t, int,
139           [Define to 'int' if <sys/resource.h> doesn't define it for us])
140   fi
141 ])
142
143 dnl APACHE_MODPATH_INIT(modpath)
144 AC_DEFUN(APACHE_MODPATH_INIT,[
145   current_dir=$1
146   modpath_current=modules/$1
147   modpath_static=
148   modpath_shared=
149   test -d $1 || $srcdir/build/mkdir.sh $modpath_current
150   > $modpath_current/modules.mk
151 ])dnl
152 dnl
153 AC_DEFUN(APACHE_MODPATH_FINISH,[
154   echo "DISTCLEAN_TARGETS = modules.mk" >> $modpath_current/modules.mk
155   echo "static = $modpath_static" >> $modpath_current/modules.mk
156   echo "shared = $modpath_shared" >> $modpath_current/modules.mk
157   if test ! -z "$modpath_static" -o ! -z "$modpath_shared"; then
158     MODULE_DIRS="$MODULE_DIRS $current_dir"
159   else
160     MODULE_CLEANDIRS="$MODULE_CLEANDIRS $current_dir"
161   fi
162   APACHE_FAST_OUTPUT($modpath_current/Makefile)
163 ])dnl
164 dnl
165 dnl APACHE_MODPATH_ADD(name[, shared[, objects [, ldflags[, libs]]]])
166 AC_DEFUN(APACHE_MODPATH_ADD,[
167   if test -z "$3"; then
168     objects="mod_$1.lo"
169   else
170     objects="$3"
171   fi
172
173   if test -z "$module_standalone"; then
174     if test -z "$2"; then
175       libname="mod_$1.la"
176       BUILTIN_LIBS="$BUILTIN_LIBS $modpath_current/$libname"
177       modpath_static="$modpath_static $libname"
178       cat >>$modpath_current/modules.mk<<EOF
179 $libname: $objects
180         \$(MOD_LINK) $objects
181 EOF
182     else
183       apache_need_shared=yes
184       libname="mod_$1.la"
185       shobjects=`echo $objects | sed 's/\.lo/.slo/g'`
186       modpath_shared="$modpath_shared $libname"
187       cat >>$modpath_current/modules.mk<<EOF
188 $libname: $shobjects
189         \$(SH_LINK) -rpath \$(libexecdir) -module -avoid-version $4 $objects $5
190 EOF
191     fi
192   fi
193 ])dnl
194
195 dnl
196 dnl APACHE_MODULE(name, helptext[, objects[, structname[, default[, config]]]])
197 dnl
198 dnl default is one of:
199 dnl   yes    -- enabled by default. user must explicitly disable.
200 dnl   no     -- disabled under default, most, all. user must explicitly enable.
201 dnl   most   -- disabled by default. enabled explicitly or with most or all.
202 dnl   static -- enabled as static by default, must be explicitly changed.
203 dnl   ""     -- disabled under default, most. enabled explicitly or with all.
204 dnl
205 dnl basically: yes/no is a hard setting. "most" means follow the "most"
206 dnl            setting. otherwise, fall under the "all" setting.
207 dnl            explicit yes/no always overrides.
208 dnl
209 AC_DEFUN(APACHE_MODULE,[
210   AC_MSG_CHECKING(whether to enable mod_$1)
211   define([optname],[--]ifelse($5,yes,disable,enable)[-]translit($1,_,-))dnl
212   AC_ARG_ENABLE(translit($1,_,-),APACHE_HELP_STRING(optname(),$2),,enable_$1=ifelse($5,,maybe-all,$5))
213   undefine([optname])dnl
214   _apmod_extra_msg=""
215   dnl When --enable-modules=most is set and the module was not explicitly
216   dnl requested, allow a module to disable itself if its pre-reqs fail.
217   if test "$module_selection" = "most" -a "$enable_$1" = "most"; then
218     _apmod_error_fatal="no"
219   else
220     _apmod_error_fatal="yes"
221   fi
222   if test "$enable_$1" = "static"; then
223     enable_$1=yes
224   elif test "$enable_$1" = "yes"; then
225     enable_$1=$module_default
226     _apmod_extra_msg=" ($module_selection)"
227   elif test "$enable_$1" = "most"; then
228     if test "$module_selection" = "most" -o "$module_selection" = "all"; then
229       enable_$1=$module_default
230       _apmod_extra_msg=" ($module_selection)"
231     elif test "$enable_$1" != "yes"; then
232       enable_$1=no
233     fi
234   elif test "$enable_$1" = "maybe-all"; then
235     if test "$module_selection" = "all"; then
236       enable_$1=$module_default
237       _apmod_extra_msg=" (all)"
238     else
239       enable_$1=no
240     fi
241   fi
242   if test "$enable_$1" != "no"; then
243     dnl If we plan to enable it, allow the module to run some autoconf magic
244     dnl that may disable it because of missing dependencies.
245     ifelse([$6],,:,[AC_MSG_RESULT([checking dependencies])
246                     $6
247                     AC_MSG_CHECKING(whether to enable mod_$1)
248                     if test "$enable_$1" = "no"; then
249                       if test "$_apmod_error_fatal" = "no"; then
250                         _apmod_extra_msg=" (disabled)"
251                       else
252                         AC_MSG_ERROR([mod_$1 has been requested but can not be built due to prerequisite failures])
253                       fi
254                     fi])
255   fi
256   AC_MSG_RESULT($enable_$1$_apmod_extra_msg)
257   if test "$enable_$1" != "no"; then
258     case "$enable_$1" in
259     shared*)
260       enable_$1=`echo $ac_n $enable_$1$ac_c|sed 's/shared,*//'`
261       sharedobjs=yes
262       shared=yes;;
263     *)
264       MODLIST="$MODLIST ifelse($4,,$1,$4)"
265       if test "$1" = "so"; then
266           sharedobjs=yes
267       fi
268       shared="";;
269     esac
270     APACHE_MODPATH_ADD($1, $shared, $3)
271   fi
272 ])dnl
273 dnl
274 dnl APACHE_LAYOUT(configlayout, layoutname)
275 AC_DEFUN(APACHE_LAYOUT,[
276   if test ! -f $srcdir/config.layout; then
277     echo "** Error: Layout file $srcdir/config.layout not found"
278     echo "** Error: Cannot use undefined layout '$LAYOUT'"
279     exit 1
280   fi
281   pldconf=./config.pld
282   changequote({,})
283   sed -e "1,/[  ]*<[lL]ayout[   ]*$2[   ]*>[    ]*/d" \
284       -e '/[    ]*<\/Layout>[   ]*/,$d' \
285       -e "s/^[  ]*//g" \
286       -e "s/:[  ]*/=\'/g" \
287       -e "s/[   ]*$/'/g" \
288       $1 > $pldconf
289   layout_name=$2
290   . $pldconf
291   rm $pldconf
292   for var in prefix exec_prefix bindir sbindir libexecdir mandir \
293              sysconfdir datadir errordir iconsdir htdocsdir cgidir \
294              includedir localstatedir runtimedir logfiledir \
295              proxycachedir installbuilddir; do
296     eval "val=\"\$$var\""
297     case $val in
298       *+)
299         val=`echo $val | sed -e 's;\+$;;'`
300         eval "$var=\"\$val\""
301         autosuffix=yes
302         ;;
303       *)
304         autosuffix=no
305         ;;
306     esac
307     val=`echo $val | sed -e 's:\(.\)/*$:\1:'`
308     val=`echo $val | sed -e 's:[\$]\([a-z_]*\):$(\1):g'`
309     if test "$autosuffix" = "yes"; then
310       if echo $val | grep apache >/dev/null; then
311         addtarget=no
312       else
313         addtarget=yes
314       fi
315       if test "$addtarget" = "yes"; then
316         val="$val/apache"
317       fi
318     fi
319     eval "$var='$val'"
320   done
321   changequote([,])
322 ])dnl
323 dnl
324 dnl APACHE_ENABLE_LAYOUT
325 dnl
326 AC_DEFUN(APACHE_ENABLE_LAYOUT,[
327 AC_ARG_ENABLE(layout,
328 APACHE_HELP_STRING(--enable-layout=LAYOUT,Default file layout),[
329   LAYOUT=$enableval
330 ])
331
332 if test -z "$LAYOUT"; then
333   LAYOUT="Apache"
334 fi
335 APACHE_LAYOUT($srcdir/config.layout, $LAYOUT)
336
337 AC_MSG_CHECKING(for chosen layout)
338 AC_MSG_RESULT($layout_name)
339 ])
340
341 dnl
342 dnl APACHE_ENABLE_MODULES
343 dnl
344 AC_DEFUN(APACHE_ENABLE_MODULES,[
345   module_selection=default
346   module_default=yes
347
348   AC_ARG_ENABLE(modules,
349   APACHE_HELP_STRING(--enable-modules=MODULE-LIST,Modules to enable),[
350     for i in $enableval; do
351       if test "$i" = "all" -o "$i" = "most"; then
352         module_selection=$i
353       else
354         eval "enable_$i=yes"
355       fi
356     done
357   ])
358   
359   AC_ARG_ENABLE(mods-shared,
360   APACHE_HELP_STRING(--enable-mod-shared=MODULE-LIST,Shared modules to enable),[
361     for i in $enableval; do
362       if test "$i" = "all" -o "$i" = "most"; then
363         module_selection=$i
364         module_default=shared
365       else
366         i=`echo $i | sed 's/-/_/g'`
367         eval "enable_$i=shared"
368       fi
369     done
370   ])
371 ])
372
373 AC_DEFUN(APACHE_REQUIRE_CXX,[
374   if test -z "$apache_cxx_done"; then
375     AC_PROG_CXX
376     AC_PROG_CXXCPP
377     apache_cxx_done=yes
378   fi
379 ])
380
381 dnl
382 dnl APACHE_CHECK_SSL_TOOLKIT
383 dnl
384 dnl Find the openssl toolkit installation and check it for the right
385 dnl version, then add its flags to INCLUDES and LIBS.  This should
386 dnl really be using a custom AC_TRY_COMPILE function to test the includes
387 dnl and then AC_TRY_LINK to test the libraries directly for the version,
388 dnl but that will require someone who knows how to program openssl.
389 dnl
390 AC_DEFUN(APACHE_CHECK_SSL_TOOLKIT,[
391 if test "x$ap_ssltk_base" = "x"; then
392   AC_MSG_CHECKING(for SSL/TLS toolkit base)
393   ap_ssltk_base=""
394   AC_ARG_WITH(ssl, APACHE_HELP_STRING(--with-ssl=DIR,SSL/TLS toolkit (OpenSSL)), [
395     if test "x$withval" != "xyes" -a "x$withval" != "x"; then
396       ap_ssltk_base="$withval"
397     fi
398   ])
399   if test "x$ap_ssltk_base" = "x"; then
400     AC_CACHE_VAL(ap_cv_ssltk,[
401       #
402       # shotgun approach: find all occurrences of the openssl program
403       #
404       ap_ssltk_try=""
405       # The IFS=... trick eliminates the colons from $PATH, without using an external program
406       for p in `IFS=":$IFS"; echo $PATH` /usr/local/openssl/bin /usr/local/ssl/bin; do
407         if test -f "$p/openssl"; then
408           ap_ssltk_try="$ap_ssltk_try $p"
409         fi
410       done
411       if test "x$ap_ssltk_try" = "x"; then
412         AC_MSG_ERROR(['openssl' not found in path])
413       fi
414       for p in $ap_ssltk_try; do
415         ap_ssltk_version="`$p/openssl version`"
416         case "$ap_ssltk_version" in
417             "OpenSSL "[[1-9]]* | \
418             "OpenSSL "0.9.[[6-9]]* | \
419             "OpenSSL "0.[[1-9]][[0-9]]* )
420                 ap_cv_ssltk="`(cd $p/.. && pwd)`"
421                 break
422                 ;;
423             *)
424                 # skip because it is too old or a bad result
425                 ;;
426         esac
427       done
428       if test "x$ap_cv_ssltk" = "x"; then
429         AC_MSG_ERROR([requires OpenSSL 0.9.6 or higher])
430       fi
431     ])
432     ap_ssltk_base="$ap_cv_ssltk"
433   fi
434   if test ! -d $ap_ssltk_base; then
435     AC_MSG_ERROR([invalid SSL/TLS toolkit base directory $ap_ssltk_base])
436   fi
437   AC_MSG_RESULT($ap_ssltk_base)
438     
439   AC_MSG_CHECKING(for SSL/TLS toolkit version)
440   AC_MSG_RESULT($ap_ssltk_version)
441     
442   AC_MSG_CHECKING(for SSL/TLS toolkit includes)
443   ap_ssltk_incdir=""
444   for p in $ap_ssltk_base/include /usr/local/openssl/include \
445            /usr/local/ssl/include /usr/local/include /usr/include; do
446     if test -f "$p/openssl/ssl.h"; then
447       ap_ssltk_incdir="$p"
448       break
449     fi
450   done
451   if test "x$ap_ssltk_incdir" = "x"; then
452     AC_MSG_ERROR([OpenSSL headers not found])
453   fi
454   AC_MSG_RESULT($ap_ssltk_incdir)
455
456   AC_MSG_CHECKING(for SSL/TLS toolkit libraries)
457   ap_ssltk_libdir=""
458   for p in $ap_ssltk_base/lib /usr/local/openssl/lib \
459            /usr/local/ssl/lib /usr/local/lib /usr/lib /lib; do
460     if test -f "$p/libssl.a" -o -f "$p/libssl.so"; then
461       ap_ssltk_libdir="$p"
462       break
463     fi
464   done
465   if test ".$ap_ssltk_libdir" = .; then
466     AC_MSG_ERROR([OpenSSL libraries not found])
467   fi
468   AC_MSG_RESULT($ap_ssltk_libdir)
469
470   dnl #  annotate the Apache build environment with determined information
471   APR_ADDTO(INCLUDES, [-I$ap_ssltk_incdir/openssl])
472   if test "x$ap_ssltk_incdir" != "x/usr/include"; then
473     APR_ADDTO(INCLUDES, [-I$ap_ssltk_incdir])
474   fi
475   if test "x$ap_ssltk_libdir" != "x/usr/lib"; then
476     APR_ADDTO(LIBS, [-L$ap_ssltk_libdir])
477     if test "x$ap_platform_runtime_link_flag" != "x"; then
478       APR_ADDTO(LIBS, [$ap_platform_runtime_link_flag$ap_ssltk_libdir])
479     fi
480   fi
481   APR_ADDTO(LIBS, [-lssl -lcrypto])
482   ap_cv_ssltk="$ap_ssltk_base"
483 fi
484 ])
485