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 AS_HELP_STRING(--with-$1=DIR,root directory of aci_help installation),
86 if test "$withval" = yes ; then good=no; fi
87 if test "$withval" = no ; then good=no; fi
88 if test $good = no ; then
89 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)])
91 aci_pkg_prefix_$1="$withval"
92 CFLAGS_$1="-I$withval/include $CFLAGS_$1"
93 LIBS_$1="-L$withval/lib $LIBS_$1"
96 AC_ARG_WITH([$1-includes],
97 AS_HELP_STRING(--with-$1-includes=DIR,specify exact include dir for aci_help headers),
98 [CFLAGS_$1="-I$withval $CFLAGS_$1"
99 aci_pkg_inc_$1="$withval"
102 AC_ARG_WITH([$1-libraries],
103 AS_HELP_STRING(--with-$1-libraries=DIR,specify exact library dir for aci_help library
104 ),[LIBS_$1="-L$withval $LIBS_$1"
105 aci_pkg_lib_$1="$withval"])
107 AC_ARG_WITH([$1-extra],
108 AS_HELP_STRING(--with-$1-extra=ARG,specify extra args to pass to the linker to get the aci_help library (with no space. A sed to change "!" to " " is run)
109 ),[LIBS_$1=`echo $withval|sed 's/!/ /g'`" $LIBS_$1"
110 aci_pkg_extra_$1="$withval"])
112 AC_SUBST([aci_pkg_prefix_$1])dnl
113 AC_SUBST([aci_pkg_inc_$1])dnl
114 AC_SUBST([aci_pkg_lib_$1])dnl
115 AC_SUBST([aci_pkg_extra_$1])dnl
122 OLD_CPPFLAGS=$CPPFLAGS
124 dnl make sure there is no newline in paths
125 i=`echo aci_paths|wc -l`
126 if test $i != 1 && test $i != 0 ; then
127 AC_MSG_ERROR([Badly formed args for function ACI-PACKAGE.
128 please no newline and no tab.])
131 ac_func_search_save_LIBS="$LIBS"
132 ac_func_search_save_this_LIBS="$LIBS_$1"
134 echo "----------------------------------------" >&5
135 AC_MSG_CHECKING([for aci_name. Can I access aci_func without new libs])
136 AC_TRY_LINK_FUNC([$3],[AC_MSG_RESULT([yes]) aci_found="yes"],[AC_MSG_RESULT([no])])
137 if test "$aci_found" = "no"; then
138 if test -n "$LIBS_$1" ; then
140 echo "----------------------------------------" >&5
141 AC_MSG_CHECKING([for aci_name. Can I access aci_func the specified extra args])
142 AC_TRY_LINK_FUNC(aci_func,aci_found="yes",aci_found="no")
143 AC_MSG_RESULT($aci_found)
148 if test "x$aci_found" = "xno"; then
149 LIBS_$1=`echo "$i $ac_func_search_save_this_LIBS"|sed 's/!/ /g'`
150 LIBS="$LIBS_$1 $ac_func_search_save_LIBS"
151 echo "----------------------------------------" >&5
152 AC_MSG_CHECKING([for aci_name. Can I access aci_func with $LIBS_$1])
153 AC_TRY_LINK_FUNC(aci_func,aci_found="yes",aci_found="no")
154 AC_MSG_RESULT($aci_found)
157 LIBS="$ac_func_search_save_LIBS"
160 dnl search for the header (only if the lib was found)
162 if test "x$aci_found" = "xyes" && test "x"aci_header != "x" ; then
163 CPPFLAGS="$CPPFLAGS $CFLAGS_$1"
164 ACI_D("CPPFLAGS=$CPPFLAGS")
165 AC_CHECK_HEADER(aci_header,good=yes,good=no)
167 if test "x$aci_found" = "xno" ; then
168 dnl Something where not found.
169 dnl If the caller specified what to do in this case, do it.
172 [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).)],
175 dnl Anything where found
177 ifelse(aci_if_yes, , echo >/dev/null, aci_if_yes)
179 if test "x$HAVE_$1" != "xyes" ; then
183 dnl AC_SUBST what should be
188 ACI_D("[END OF ACI-PACKAGE($1)]")
189 dnl restore the old settings
191 CPPFLAGS=$OLDCPPFLAGS
195 dnl ACI_PACKAGE_SAVED: same as ACI_PACKAGE, but with an external cache
197 dnl 1=Package (name of the package)
198 dnl 2=Description (human readable, for documentation)
199 dnl 3=Cache program.Should accept --libs and --cflags (like gnome-config does)
200 dnl 4=Extra arg to pass to this prog (like a name of library)
201 dnl 5=what to do if found
202 dnl 6=what to do if not found (default AC_MSG_ERROR(blabla))
204 dnl - try to find the cache program
205 dnl - AC_SUBST the following values:
206 dnl HAVE_$1: 'yes' or 'no'
207 dnl CFLAGS_$1: CFLAGS to acces to this package
208 dnl LIBS_$1: LDFLAGS to acces to this package
210 AC_DEFUN([ACI_PACKAGE_SAVED],[
211 ACI_D("[BEGINING OF ACI-PACKAGE-SAVED($1)]")
212 AC_PATH_PROG(ACI_CACHE_PROG,$3,no)
213 aci_module_desc_$1="$2"
214 AC_SUBST([aci_module_desc_$1])dnl
216 AC_SUBST([aci_pkg_config_$1])dnl
217 aci_packages="$aci_packages $1"
218 if test x$ACI_CACHE_PROG = xno; then
222 ifelse($6, ,[AC_MSG_ERROR([Cannot find $1: Is $3 in your path?])],$6)
225 CFLAGS_$1=`$ACI_CACHE_PROG --cflags $4`
226 LIBS_$1=`$ACI_CACHE_PROG --libs $4`
227 ifelse($5, ,echo >/dev/null,$5)
229 dnl AC_SUBST what should be
230 AC_SUBST([HAVE_$1])dnl
231 AC_SUBST([CFLAGS_$1])dnl
232 AC_SUBST([LIBS_$1])dnl
233 ACI_D("[END OF ACI-PACKAGE-SAVED($1)]")
237 dnl ACI_MODULE: defines a module (ie, a part of the code we are building)
239 dnl 2=human readable description
240 dnl 3=dependencies (space separated list of abbrev)
241 dnl 4=submodules (space separated list of abbrev)
242 dnl 5=default ([yes]/no) (if not given, yes is assumed)
243 dnl 6=extra childs, which are listed under it in tree, without being a module
245 AC_DEFUN([ACI_MODULE],[
246 ACI_D("[BEGINING OF ACI-MODULE($1)]")
247 aci_nameok=`echo $1|sed 'y/-/./'`
248 if test "x$1" != "x$aci_nameok" ; then
249 AC_MSG_ERROR([ACI error: Please no '-' in module name. (ie, $1 is not a valid name)])
251 aci_module_desc_$1="$2"
252 aci_module_dep_$1="$3"
253 aci_module_sub_$1="$4"
254 aci_module_child_$1="$4 $6"
255 AC_SUBST(aci_module_desc_$1)
256 AC_SUBST(aci_module_dep_$1)
257 AC_SUBST(aci_module_sub_$1)
258 AC_SUBST(aci_module_child_$1)
259 AC_SUBST(SUBMODULES_$1)
260 AC_SUBST(DIST_SUBMODULES_$1)
263 AS_HELP_STRING(--enable-$1,Enable the module $1, $2.))
265 ifelse(ifelse([$5], ,[yes],[$5]),[yes],
266 dnl what to do if module is enabled by default
267 [aci_module_default_$1="enabled"],
268 [aci_module_default_$1="disabled"])
270 if test "x$enable_$1" == "xyes" ; then
271 aci_module_status_$1="enabled"
272 else if test "x$enable_$1" == "xno" ; then
273 aci_module_status_$1="disabled"
275 aci_module_status_$1="$aci_module_default_$1"
277 if test "$aci_module_status_$1" == "enabled" ; then
278 aci_modules_possible="$aci_modules_possible $1"
280 aci_modules_disabled="$aci_modules_disabled $1"
282 ACI_D("[END OF ACI-MODULE($1). Default:$aci_module_default_$1; Result:$aci_module_status_$1]")
285 dnl ACI_MODULES_VERIFY: verify which module can be satisfied
287 dnl - SUBMODULES_$1 to Makefiles, init'ed to the list of submodules to build
288 dnl (use it in SUBDIRS in Makefile.am)
289 dnl - DIST_SUBMODULES_$1 to Makefiles, init'ed to the list of submodules which could
290 dnl be build but have unsatisfied dependencies
291 dnl (use it in DIST_SUBDIRS in Makefile.am)
292 dnl 1: the name of this group of modules
294 AC_DEFUN([ACI_MODULES_VERIFY],[
298 if echo $aci_modules_disabled $aci_modules_possible | grep $1 >/dev/null ; then
301 AC_MSG_ERROR([ACI Error: You called MODULES_VERIFY($1), but $1 isn't a module])
304 dnl Check the dependencies of everyone
305 for aci_module in $aci_modules_possible
308 ACI_D("Look module $aci_module")
309 for aci_mod_dep in `eval echo '$aci_module_dep_'"$aci_module"`
311 ACI_D($ECHO_N " it depends on $aci_mod_dep...")
312 if test `eval echo 'x$'"HAVE_$aci_mod_dep"` != xyes; then
313 ACI_D("Not satisfied !")
314 aci_mod_bad=`echo "$aci_mod_bad $aci_mod_dep"|sed 's/^ *//'`
319 if test -z "$aci_mod_bad"; then
320 ACI_D("Module $aci_module will be builded")
322 aci_modules="$aci_modules $aci_module"
323 eval "HAVE_$aci_module=\"yes\""
325 ACI_D("Won't build $aci_module because it depends on $aci_mod_bad.")
327 eval "aci_module_misdep_$aci_module=\"$aci_mod_bad\""
328 aci_modules_broken="$aci_modules_broken $aci_module"
329 eval "HAVE_$aci_module=\"no\""
333 dnl Build the list of submodules to build
334 ACI_D("Build the submodules lists")
335 for aci_module in $aci_modules_possible
337 ACI_D($ECHO_N " Look for $aci_module: ")
338 for aci_mod_sub in `eval echo '$aci_module_sub_'"$aci_module"`
340 if test `eval echo 'x$HAVE_'"$aci_mod_sub"` = xyes; then
341 ACI_D($ECHO_N "$aci_mod_sub ")
342 eval "SUBMODULES_$aci_module=\"\$MODULES_$aci_module $aci_mod_sub\""
344 ACI_D($ECHO_N "NOT $aci_mod_sub ")
345 eval "DIST_SUBMODULES_$aci_module=\"\$DIST_MODULES_$aci_module $aci_mod_sub\""
351 dnl support for external interactif configurator
352 AC_SUBST([ac_configure_args])dnl which argument were passed to configure
353 AC_SUBST([aci_modules_possible])dnl
354 AC_SUBST([aci_modules])dnl
355 AC_SUBST([aci_modules_broken])dnl
356 AC_SUBST([aci_modules_disabled])dnl
357 AC_SUBST([aci_packages])dnl
360 dnl ACI_MODULES_SUMMARY: give a summary of what will be build to user
361 dnl 1: Name of the root of modules (can be a space separated list)
363 AC_DEFUN([ACI_MODULES_SUMMARY],[
364 if test "x$aci_modules" != "x"; then
365 echo "The following modules will be builded: "
366 for aci_module in $aci_modules
368 echo " - $aci_module: "`eval echo '$aci_module_desc_'"$aci_module"`
369 if test -n "`echo "\$MODULES_$aci_module"`" ; then
370 echo " builded submodules: "`eval echo '$MODULES_'"$aci_module"`
374 echo "No module will be build."
378 if test "x$aci_modules_disabled" != "x"; then
379 echo "The following modules are disabled, either by you or by default."
380 for aci_module in $aci_modules_disabled
382 echo " - $aci_module: "`eval echo '$aci_module_desc_'"$aci_module"`
387 if test "x$aci_modules_broken" != "x"; then
388 echo "The following modules have BROKEN dependencies:"
389 for aci_module in $aci_modules_broken
391 echo " - $aci_module: "`eval echo '$aci_module_desc_'"$aci_module"`
392 echo " Depends on: "`eval echo '$aci_module_misdep_'"$aci_module"`
396 echo " If you think I'm a dumb script, and these dependencies can be"
397 echo " satified, please try to use the --with-PACKAGE options. See:"
398 echo " ./configure --help=short"
400 echo "The other modules may be build even if these ones are not."
406 dnl ACI_MODULES_SUMMARY_FANCY: same as ACI_MODULES_SUMMARY, in a fancy way.
407 AC_DEFUN([ACI_MODULES_SUMMARY_FANCY],[
408 # the file conftests.nexts is a file containing the modules we still have to
409 # handle. Each line have the form "level nb module", defining at which
410 # <level> <module> is defined. It is the <nb>th at this level
415 if echo $aci_modules_disabled $aci_modules_possible | grep $1 >/dev/null ; then
418 AC_MSG_ERROR([ACI Error: You called MODULES_SUMMARY_FANCY($1), but $1 isn't a module])
426 echo "BEGIN OF ACI_SUMMARY_FANCY">&5
427 ACI_ECHO(["Summary of the configuration for $name"])
428 aci_sum_more="no" # If there is more modules to handle
429 rm -f conftest.nexts conftest.nexts.new
431 # initialize aci_sum_nexts and aci_sum_more from the given argument
433 for aci_sum_tmp in $1
435 echo "0 $aci_sum_nb $aci_sum_tmp" >> conftest.nexts
437 aci_sum_nb=`expr $aci_sum_nb - 1`
446 while test "x$aci_sum_more" = "xyes" ; do
449 sort -r -k 1,3 conftest.nexts > conftest.nexts.new
450 mv conftest.nexts.new conftest.nexts
452 changequote(<<, >>)dnl because of the regexp [[:blank:]]
454 # get the next elem to handle and its level, and remove it from the list
455 aci_sum_this=`head -n 1 conftest.nexts|\
456 sed -e 's/^[0-9]*[[:blank:]]*[0-9]*[[:blank:]]*\([^[:blank:]]*$\)/\1/'`
457 aci_sum_lvl=`head -n 1 conftest.nexts |\
458 sed -e 's/^\([0-9]*\)[[:blank:]].*$/\1/'`
460 # aci_sum_this=`sed -e '1~1000s/^[0-9]*[[:blank:]]*[0-9]*[[:blank:]]*\([^[:blank:]]*$\)/\1/'\
463 # aci_sum_lvl=`sed -e '1~1000s/^\([0-9]*\)[[:blank:]].*$/\1/'\
467 tail +2l conftest.nexts > conftest.nexts.new
468 mv conftest.nexts.new conftest.nexts
470 #echo "aci_sum_this=$aci_sum_this"
473 # stop if nothing else to do
474 if test "x$aci_sum_this" = x ; then
477 # Add the sub modules of this on to the file
478 aci_sum_sub=`expr $aci_sum_lvl + 1`
480 for aci_sum_tmp in `eval echo '$aci_module_child_'"$aci_sum_this"`
482 echo "$aci_sum_sub $aci_sum_nb $aci_sum_tmp" >> conftest.nexts
483 aci_sum_nb=`expr $aci_sum_nb - 1`
486 # compute the status of this module
487 if echo $aci_modules_disabled|grep $aci_sum_this >/dev/null; then
488 aci_sum_status="(DISABLED)"
490 if test `eval echo '"x$aci_module_misdep_'"$aci_sum_this\""` = x ; then
491 aci_sum_status="(OK)"
493 aci_sum_status="(BROKEN)"
497 # Outputs the title of this module
499 while test $aci_sum_lvl -ne 0
501 aci_sum_header="$aci_sum_header "
502 aci_sum_lvl=`expr $aci_sum_lvl - 1`
505 changequote([, ])dnl back to normality, there is no regexp afterward
506 ACI_ECHO("$aci_sum_header"'>'" $aci_sum_this$aci_sum_status: "`eval echo '$aci_module_desc_'"$aci_sum_this"`)
508 aci_sum_head_dep="$aci_sum_header "
509 aci_sum_tmp=`eval echo '$'"MODULES_$aci_sum_this"|
510 sed 's/[^[:blank:]] .*$//'`
511 if test "x$aci_sum_tmp" != x ; then
512 ACI_ECHO("$aci_sum_head_dep Optional submodules to build: "`eval echo '$'"MODULES_$aci_sum_this"`)
516 # outputs the dependencies of this module
518 aci_sum_dep_some="no"
519 for aci_sum_dep in `eval echo '$aci_module_dep_'"$aci_sum_this"`
521 if echo $aci_packages|grep $aci_sum_dep>/dev/null ||\
522 echo `eval echo '$aci_module_misdep_'"$aci_sum_this"`|grep $aci_sum_dep >/dev/null; then
523 aci_sum_deps="$aci_sum_deps $aci_sum_dep"
524 aci_sum_dep_some="yes"
527 if test "x$aci_sum_dep_some" = xyes ; then
528 ACI_ECHO("$aci_sum_head_dep Packages and modules it depends on:")
529 for aci_sum_dep in $aci_sum_deps
531 # compute the status of this package
532 if test `eval echo 'x$'"HAVE_$aci_sum_dep"` = xyes ; then
533 aci_sum_pkg_status="(FOUND)"
535 aci_sum_pkg_status="(NOT FOUND)"
538 # output the status of this package
539 ACI_ECHO("$aci_sum_head_dep o $aci_sum_dep$aci_sum_pkg_status: "`eval echo '$aci_module_desc_'"$aci_sum_dep"`)
540 aci_sum_tmp=`eval echo '$'"LIBS_$aci_sum_dep"|
541 sed 's/[^[:blank:]] .*$//'`
542 if test "x$aci_sum_tmp" != x ; then
543 ACI_ECHO( "$aci_sum_head_dep LIBS: "`eval echo '$'"LIBS_$aci_sum_dep"`)
545 aci_sum_tmp=`eval echo '$'"CFLAGS_$aci_sum_dep"|
546 sed 's/[^[:blank:]] .*$//'`
547 if test "x$aci_sum_tmp" != x ; then
548 ACI_ECHO("$aci_sum_head_dep CFLAGS: "`eval echo '$'"CFLAGS_$aci_sum_dep"`)
553 ACI_ECHO("$aci_sum_header")
555 if test "x$aci_modules_disabled" != "x"; then
556 ACI_ECHO( " Some modules are disabled[,] either by you or by default")
559 if test "x$aci_modules_broken" != "x"; then
560 ACI_ECHO( " If you think I'm a dumb script[,] and these broken dependencies can")
561 ACI_ECHO( " be satified[,] please try to use the --with-PACKAGE options. See:")
562 ACI_ECHO( " ./configure --help=short")
564 ACI_ECHO( "The other modules may be build even if these ones are not.")
567 if test "x$aci_modules_disabled$aci_modules_broken" = "x"; then
568 ACI_ECHO( " Everything went well.")
570 echo "END OF ACI_SUMMARY_FANCY">&5