2 dnl ACI macros -- intra and extra package dependencies handling macros.
3 dnl those autoconf macro allows you to declare which parts of your project
4 dnl depend on which external package, or even on other parts of your code.
7 dnl Copyright (C) 2000,2001,2002,2003 Free Software Foundation, Inc.
8 dnl This file is free software; the Free Software Foundation
9 dnl gives unlimited permission to copy and/or distribute it,
10 dnl with or without modifications, as long as this notice is preserved.
12 dnl This program is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
14 dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 dnl PARTICULAR PURPOSE.
18 dnl one day, I'll do a public release. Until then, check the FAST changelogs.
21 dnl ACI_PREREQ: Check that at least version $1 of ACI macros are available
23 m4_define([aci_version],[2003.01.16])
24 m4_define([ACI_PREREQ],
25 [m4_if(m4_version_compare(m4_defn([aci_version]), [$1]), -1,
27 [m4_fatal([ACI macros version $1 or higher is required])])],
32 dnl ACI_D: echo something to the config.log
33 AC_DEFUN([ACI_D],[echo $1>&5;])dnl >&5
34 AC_DEFUN([ACI_ECHO],[echo $1;echo $1>&5])
37 dnl ACI_PACKAGE: defines a package (ie, an external package we should search)
39 dnl 1=Package (name of the package)
40 dnl 2=Description (human readable, for documentation)
41 dnl 3=Function (the main function to search)
42 dnl 4=Library list (where to search, space separated list of group of LDFLAGS
43 dnl each LDFLAGS is ! separated.
44 dnl example: "-lldap -lldap!-llber"
45 dnl warning: can't contain tabs or newlines)
47 dnl 6=what to do if found
48 dnl 7=what to do if not found (default: AC_MSG_ERROR(blabla))
49 dnl It is possible to change any of the exported values in $6 or $7
51 dnl - try to find the function in each part of LDFLAGS and the header.
52 dnl - AC_SUBST the following values:
53 dnl HAVE_$1: 'yes' or 'no'
54 dnl CFLAGS_$1: CFLAGS to acces to this package
55 dnl LIBS_$1: LDFLAGS to acces to this package
56 dnl - define the following arguments to ./configure:
57 dnl --with-$1 root dir of install
58 dnl --with-$1-includes where to search the header
59 dnl --with-$1-libs where to search the libs
60 dnl --with-$1-extra extra LDFLAGS to pass to the linker
61 AC_DEFUN([ACI_PACKAGE],[
62 pushdef([aci_name], [$1])
63 pushdef([aci_help], [$2])
64 pushdef([aci_func], [$3])
65 pushdef([aci_paths], [$4])
66 pushdef([aci_header], [$5])
67 pushdef([aci_if_yes], [$6])
68 pushdef([aci_if_no], [$7])
70 aci_nameok=`echo $1|sed 'y/-/./'`
71 if test "x$1" != "x$aci_nameok" ; then
72 AC_MSG_ERROR([ACI error: Please no '-' in package name. (ie, $1 is not a valid name)])
74 ACI_D("[BEGINING OF ACI-PACKAGE($1)]")
75 aci_module_desc_$1="$2"
76 AC_SUBST([aci_module_desc_$1])dnl
77 aci_packages="$aci_packages $1"
80 dnl Specify the options
83 AC_HELP_STRING([--with-$1=DIR],
84 [root directory of aci_help installation]),
87 if test "$withval" = yes ; then good=no; fi
88 if test "$withval" = no ; then good=no; fi
89 if test $good = no ; then
90 AC_MSG_ERROR([You gave me --with-$1=$withval. I wait for a location[,] not yes or no (use --enable-[]aci_help or --disable-[]aci_help for that)])
92 aci_pkg_prefix_$1="$withval"
93 CFLAGS_$1="-I$withval/include $CFLAGS_$1"
94 LIBS_$1="-L$withval/lib $LIBS_$1"
97 AC_ARG_WITH([$1-includes],
98 AC_HELP_STRING([--with-$1-includes=DIR],
99 [specify exact include dir for aci_help headers]),
100 [CFLAGS_$1="-I$withval $CFLAGS_$1"
101 aci_pkg_inc_$1="$withval"
104 AC_ARG_WITH([$1-libraries],
105 AC_HELP_STRING([--with-$1-libraries=DIR],
106 [specify exact library dir for aci_help library]
107 ),[LIBS_$1="-L$withval $LIBS_$1"
108 aci_pkg_lib_$1="$withval"])
110 AC_ARG_WITH([$1-extra],
111 AC_HELP_STRING([--with-$1-extra=ARG],
112 [specify extra args to pass to the linker to get the aci_help library (with no space. A sed to change "!" to " " is run)]
113 ),[LIBS_$1=`echo $withval|sed 's/!/ /g'`" $LIBS_$1"
114 aci_pkg_extra_$1="$withval"])
116 AC_SUBST([aci_pkg_prefix_$1])dnl
117 AC_SUBST([aci_pkg_inc_$1])dnl
118 AC_SUBST([aci_pkg_lib_$1])dnl
119 AC_SUBST([aci_pkg_extra_$1])dnl
126 OLD_CPPFLAGS=$CPPFLAGS
128 dnl make sure there is no newline in paths
129 i=`echo aci_paths|wc -l`
130 if test $i != 1 && test $i != 0 ; then
131 AC_MSG_ERROR([Badly formed args for function ACI-PACKAGE.
132 please no newline and no tab.])
135 ac_func_search_save_LIBS="$LIBS"
136 ac_func_search_save_this_LIBS="$LIBS_$1"
138 echo "----------------------------------------" >&5
139 AC_MSG_CHECKING([for aci_name. Can I access aci_func without new libs])
140 AC_TRY_LINK_FUNC([$3],[AC_MSG_RESULT([yes]) aci_found="yes"],[AC_MSG_RESULT([no])])
141 if test "$aci_found" = "no"; then
142 if test -n "$LIBS_$1" ; then
144 echo "----------------------------------------" >&5
145 AC_MSG_CHECKING([for aci_name. Can I access aci_func the specified extra args])
146 AC_TRY_LINK_FUNC(aci_func,aci_found="yes",aci_found="no")
147 AC_MSG_RESULT($aci_found)
152 if test "x$aci_found" = "xno"; then
153 LIBS_$1=`echo "$i $ac_func_search_save_this_LIBS"|sed 's/!/ /g'`
154 LIBS="$LIBS_$1 $ac_func_search_save_LIBS"
155 echo "----------------------------------------" >&5
156 AC_MSG_CHECKING([for aci_name. Can I access aci_func with $LIBS_$1])
157 AC_TRY_LINK_FUNC(aci_func,aci_found="yes",aci_found="no")
158 AC_MSG_RESULT($aci_found)
161 LIBS="$ac_func_search_save_LIBS"
164 dnl search for the header (only if the lib was found)
166 if test "x$aci_found" = "xyes" && test "x"aci_header != "x" ; then
167 CPPFLAGS="$CPPFLAGS $CFLAGS_$1"
168 ACI_D("CPPFLAGS=$CPPFLAGS")
169 AC_CHECK_HEADER(aci_header,good=yes,good=no)
171 if test "x$aci_found" = "xno" ; then
172 dnl Something where not found.
173 dnl If the caller specified what to do in this case, do it.
176 [AC_MSG_ERROR(Can't find the package $1. Please install it[,] or if it is installed[,] tell me where with the --with-$1 argument (see ./configure --help=short).)],
179 dnl Anything where found
181 ifelse(aci_if_yes, , echo >/dev/null, aci_if_yes)
183 if test "x$HAVE_$1" != "xyes" ; then
187 dnl AC_SUBST what should be
192 ACI_D("[END OF ACI-PACKAGE($1)]")
193 dnl restore the old settings
195 CPPFLAGS=$OLDCPPFLAGS
199 dnl ACI_PACKAGE_SAVED: same as ACI_PACKAGE, but with an external cache
201 dnl 1=Package (name of the package)
202 dnl 2=Description (human readable, for documentation)
203 dnl 3=Cache program.Should accept --libs and --cflags (like gnome-config does)
204 dnl 4=Extra arg to pass to this prog (like a name of library)
205 dnl 5=what to do if found
206 dnl 6=what to do if not found (default AC_MSG_ERROR(blabla))
208 dnl - try to find the cache program
209 dnl - AC_SUBST the following values:
210 dnl HAVE_$1: 'yes' or 'no'
211 dnl CFLAGS_$1: CFLAGS to acces to this package
212 dnl LIBS_$1: LDFLAGS to acces to this package
214 AC_DEFUN([ACI_PACKAGE_SAVED],[
215 ACI_D("[BEGINING OF ACI-PACKAGE-SAVED($1)]")
216 AC_PATH_PROG(ACI_CACHE_PROG,$3,no)
217 aci_module_desc_$1="$2"
218 AC_SUBST([aci_module_desc_$1])dnl
220 AC_SUBST([aci_pkg_config_$1])dnl
221 aci_packages="$aci_packages $1"
222 if test x$ACI_CACHE_PROG = xno; then
226 ifelse($6, ,[AC_MSG_ERROR([Cannot find $1: Is $3 in your path?])],$6)
229 CFLAGS_$1=`$ACI_CACHE_PROG --cflags $4`
230 LIBS_$1=`$ACI_CACHE_PROG --libs $4`
231 ifelse($5, ,echo >/dev/null,$5)
233 dnl AC_SUBST what should be
234 AC_SUBST([HAVE_$1])dnl
235 AC_SUBST([CFLAGS_$1])dnl
236 AC_SUBST([LIBS_$1])dnl
237 ACI_D("[END OF ACI-PACKAGE-SAVED($1)]")
241 dnl ACI_MODULE: defines a module (ie, a part of the code we are building)
243 dnl 2=human readable description
244 dnl 3=dependencies (space separated list of abbrev)
245 dnl 4=submodules (space separated list of abbrev)
246 dnl 5=default ([yes]/no) (if not given, yes is assumed)
247 dnl 6=extra childs, which are listed under it in tree, without being a module
249 AC_DEFUN([ACI_MODULE],[
250 ACI_D("[BEGINING OF ACI-MODULE($1)]")
251 aci_nameok=`echo $1|sed 'y/-/./'`
252 if test "x$1" != "x$aci_nameok" ; then
253 AC_MSG_ERROR([ACI error: Please no '-' in module name. (ie, $1 is not a valid name)])
255 aci_module_desc_$1="$2"
256 aci_module_dep_$1="$3"
257 aci_module_sub_$1="$4"
258 aci_module_child_$1="$4 $6"
259 AC_SUBST(aci_module_desc_$1)
260 AC_SUBST(aci_module_dep_$1)
261 AC_SUBST(aci_module_sub_$1)
262 AC_SUBST(aci_module_child_$1)
263 AC_SUBST(SUBMODULES_$1)
264 AC_SUBST(DIST_SUBMODULES_$1)
267 AC_HELP_STRING([--enable-$1],
268 [Enable the module $1, $2.]))
270 ifelse(ifelse([$5], ,[yes],[$5]),[yes],
271 dnl what to do if module is enabled by default
272 [aci_module_default_$1="enabled"],
273 [aci_module_default_$1="disabled"])
275 if test "x$enable_$1" == "xyes" ; then
276 aci_module_status_$1="enabled"
277 else if test "x$enable_$1" == "xno" ; then
278 aci_module_status_$1="disabled"
280 aci_module_status_$1="$aci_module_default_$1"
282 if test "$aci_module_status_$1" == "enabled" ; then
283 aci_modules_possible="$aci_modules_possible $1"
285 aci_modules_disabled="$aci_modules_disabled $1"
287 ACI_D("[END OF ACI-MODULE($1). Default:$aci_module_default_$1; Result:$aci_module_status_$1]")
290 dnl ACI_MODULES_VERIFY: verify which module can be satisfied
292 dnl - SUBMODULES_$1 to Makefiles, init'ed to the list of submodules to build
293 dnl (use it in SUBDIRS in Makefile.am)
294 dnl - DIST_SUBMODULES_$1 to Makefiles, init'ed to the list of submodules which could
295 dnl be build but have unsatisfied dependencies
296 dnl (use it in DIST_SUBDIRS in Makefile.am)
297 dnl 1: the name of this group of modules
299 AC_DEFUN([ACI_MODULES_VERIFY],[
303 if echo $aci_modules_disabled $aci_modules_possible | grep $1 >/dev/null ; then
306 AC_MSG_ERROR([ACI Error: You called MODULES_VERIFY($1), but $1 isn't a module])
309 dnl Check the dependencies of everyone
310 for aci_module in $aci_modules_possible
313 ACI_D("Look module $aci_module")
314 for aci_mod_dep in `eval echo '$aci_module_dep_'"$aci_module"`
316 ACI_D($ECHO_N " it depends on $aci_mod_dep...")
317 if test `eval echo 'x$'"HAVE_$aci_mod_dep"` != xyes; then
318 ACI_D("Not satisfied !")
319 aci_mod_bad=`echo "$aci_mod_bad $aci_mod_dep"|sed 's/^ *//'`
324 if test -z "$aci_mod_bad"; then
325 ACI_D("Module $aci_module will be builded")
327 aci_modules="$aci_modules $aci_module"
328 eval "HAVE_$aci_module=\"yes\""
330 ACI_D("Won't build $aci_module because it depends on $aci_mod_bad.")
332 eval "aci_module_misdep_$aci_module=\"$aci_mod_bad\""
333 aci_modules_broken="$aci_modules_broken $aci_module"
334 eval "HAVE_$aci_module=\"no\""
338 dnl Build the list of submodules to build
339 ACI_D("Build the submodules lists")
340 for aci_module in $aci_modules_possible
342 ACI_D($ECHO_N " Look for $aci_module: ")
343 for aci_mod_sub in `eval echo '$aci_module_sub_'"$aci_module"`
345 if test `eval echo 'x$HAVE_'"$aci_mod_sub"` = xyes; then
346 ACI_D($ECHO_N "$aci_mod_sub ")
347 eval "SUBMODULES_$aci_module=\"\$MODULES_$aci_module $aci_mod_sub\""
349 ACI_D($ECHO_N "NOT $aci_mod_sub ")
350 eval "DIST_SUBMODULES_$aci_module=\"\$DIST_MODULES_$aci_module $aci_mod_sub\""
356 dnl support for external interactif configurator
357 AC_SUBST([ac_configure_args])dnl which argument were passed to configure
358 AC_SUBST([aci_modules_possible])dnl
359 AC_SUBST([aci_modules])dnl
360 AC_SUBST([aci_modules_broken])dnl
361 AC_SUBST([aci_modules_disabled])dnl
362 AC_SUBST([aci_packages])dnl
365 dnl ACI_MODULES_SUMMARY: give a summary of what will be build to user
366 dnl 1: Name of the root of modules (can be a space separated list)
368 AC_DEFUN([ACI_MODULES_SUMMARY],[
369 if test "x$aci_modules" != "x"; then
370 echo "The following modules will be builded: "
371 for aci_module in $aci_modules
373 echo " - $aci_module: "`eval echo '$aci_module_desc_'"$aci_module"`
374 if test -n "`echo "\$MODULES_$aci_module"`" ; then
375 echo " builded submodules: "`eval echo '$MODULES_'"$aci_module"`
379 echo "No module will be build."
383 if test "x$aci_modules_disabled" != "x"; then
384 echo "The following modules are disabled, either by you or by default."
385 for aci_module in $aci_modules_disabled
387 echo " - $aci_module: "`eval echo '$aci_module_desc_'"$aci_module"`
392 if test "x$aci_modules_broken" != "x"; then
393 echo "The following modules have BROKEN dependencies:"
394 for aci_module in $aci_modules_broken
396 echo " - $aci_module: "`eval echo '$aci_module_desc_'"$aci_module"`
397 echo " Depends on: "`eval echo '$aci_module_misdep_'"$aci_module"`
401 echo " If you think I'm a dumb script, and these dependencies can be"
402 echo " satified, please try to use the --with-PACKAGE options. See:"
403 echo " ./configure --help=short"
405 echo "The other modules may be build even if these ones are not."
411 dnl ACI_MODULES_SUMMARY_FANCY: same as ACI_MODULES_SUMMARY, in a fancy way.
412 AC_DEFUN([ACI_MODULES_SUMMARY_FANCY],[
413 # the file conftests.nexts is a file containing the modules we still have to
414 # handle. Each line have the form "level nb module", defining at which
415 # <level> <module> is defined. It is the <nb>th at this level
420 if echo $aci_modules_disabled $aci_modules_possible | grep $1 >/dev/null ; then
423 AC_MSG_ERROR([ACI Error: You called MODULES_SUMMARY_FANCY($1), but $1 isn't a module])
431 echo "BEGIN OF ACI_SUMMARY_FANCY">&5
432 ACI_ECHO(["Summary of the configuration for $name"])
433 aci_sum_more="no" # If there is more modules to handle
434 rm -f conftest.nexts conftest.nexts.new
436 # initialize aci_sum_nexts and aci_sum_more from the given argument
438 for aci_sum_tmp in $1
440 echo "0 $aci_sum_nb $aci_sum_tmp" >> conftest.nexts
442 aci_sum_nb=`expr $aci_sum_nb - 1`
451 while test "x$aci_sum_more" = "xyes" ; do
454 sort -r -k 1,3 conftest.nexts > conftest.nexts.new
455 mv conftest.nexts.new conftest.nexts
457 changequote(<<, >>)dnl because of the regexp [[:blank:]]
459 # get the next elem to handle and its level, and remove it from the list
460 aci_sum_this=`head -n 1 conftest.nexts|\
461 sed -e 's/^[0-9]*[[:blank:]]*[0-9]*[[:blank:]]*\([^[:blank:]]*$\)/\1/'`
462 aci_sum_lvl=`head -n 1 conftest.nexts |\
463 sed -e 's/^\([0-9]*\)[[:blank:]].*$/\1/'`
465 # aci_sum_this=`sed -e '1~1000s/^[0-9]*[[:blank:]]*[0-9]*[[:blank:]]*\([^[:blank:]]*$\)/\1/'\
468 # aci_sum_lvl=`sed -e '1~1000s/^\([0-9]*\)[[:blank:]].*$/\1/'\
472 tail +2l conftest.nexts > conftest.nexts.new
473 mv conftest.nexts.new conftest.nexts
475 #echo "aci_sum_this=$aci_sum_this"
478 # stop if nothing else to do
479 if test "x$aci_sum_this" = x ; then
482 # Add the sub modules of this on to the file
483 aci_sum_sub=`expr $aci_sum_lvl + 1`
485 for aci_sum_tmp in `eval echo '$aci_module_child_'"$aci_sum_this"`
487 echo "$aci_sum_sub $aci_sum_nb $aci_sum_tmp" >> conftest.nexts
488 aci_sum_nb=`expr $aci_sum_nb - 1`
491 # compute the status of this module
492 if echo $aci_modules_disabled|grep $aci_sum_this >/dev/null; then
493 aci_sum_status="(DISABLED)"
495 if test `eval echo '"x$aci_module_misdep_'"$aci_sum_this\""` = x ; then
496 aci_sum_status="(OK)"
498 aci_sum_status="(BROKEN)"
502 # Outputs the title of this module
504 while test $aci_sum_lvl -ne 0
506 aci_sum_header="$aci_sum_header "
507 aci_sum_lvl=`expr $aci_sum_lvl - 1`
510 changequote([, ])dnl back to normality, there is no regexp afterward
511 ACI_ECHO("$aci_sum_header"'>'" $aci_sum_this$aci_sum_status: "`eval echo '$aci_module_desc_'"$aci_sum_this"`)
513 aci_sum_head_dep="$aci_sum_header "
514 aci_sum_tmp=`eval echo '$'"MODULES_$aci_sum_this"|
515 sed 's/[^[:blank:]] .*$//'`
516 if test "x$aci_sum_tmp" != x ; then
517 ACI_ECHO("$aci_sum_head_dep Optional submodules to build: "`eval echo '$'"MODULES_$aci_sum_this"`)
521 # outputs the dependencies of this module
523 aci_sum_dep_some="no"
524 for aci_sum_dep in `eval echo '$aci_module_dep_'"$aci_sum_this"`
526 if echo $aci_packages|grep $aci_sum_dep>/dev/null ||\
527 echo `eval echo '$aci_module_misdep_'"$aci_sum_this"`|grep $aci_sum_dep >/dev/null; then
528 aci_sum_deps="$aci_sum_deps $aci_sum_dep"
529 aci_sum_dep_some="yes"
532 if test "x$aci_sum_dep_some" = xyes ; then
533 ACI_ECHO("$aci_sum_head_dep Packages and modules it depends on:")
534 for aci_sum_dep in $aci_sum_deps
536 # compute the status of this package
537 if test `eval echo 'x$'"HAVE_$aci_sum_dep"` = xyes ; then
538 aci_sum_pkg_status="(FOUND)"
540 aci_sum_pkg_status="(NOT FOUND)"
543 # output the status of this package
544 ACI_ECHO("$aci_sum_head_dep o $aci_sum_dep$aci_sum_pkg_status: "`eval echo '$aci_module_desc_'"$aci_sum_dep"`)
545 aci_sum_tmp=`eval echo '$'"LIBS_$aci_sum_dep"|
546 sed 's/[^[:blank:]] .*$//'`
547 if test "x$aci_sum_tmp" != x ; then
548 ACI_ECHO( "$aci_sum_head_dep LIBS: "`eval echo '$'"LIBS_$aci_sum_dep"`)
550 aci_sum_tmp=`eval echo '$'"CFLAGS_$aci_sum_dep"|
551 sed 's/[^[:blank:]] .*$//'`
552 if test "x$aci_sum_tmp" != x ; then
553 ACI_ECHO("$aci_sum_head_dep CFLAGS: "`eval echo '$'"CFLAGS_$aci_sum_dep"`)
558 ACI_ECHO("$aci_sum_header")
560 if test "x$aci_modules_disabled" != "x"; then
561 ACI_ECHO( " Some modules are disabled[,] either by you or by default")
564 if test "x$aci_modules_broken" != "x"; then
565 ACI_ECHO( " If you think I'm a dumb script[,] and these broken dependencies can")
566 ACI_ECHO( " be satified[,] please try to use the --with-PACKAGE options. See:")
567 ACI_ECHO( " ./configure --help=short")
569 ACI_ECHO( "The other modules may be build even if these ones are not.")
572 if test "x$aci_modules_disabled$aci_modules_broken" = "x"; then
573 ACI_ECHO( " Everything went well.")
575 echo "END OF ACI_SUMMARY_FANCY">&5