+# func_module_shellvar_name module
+# computes the shell variable name the will be set to true once the m4 macros
+# for the module have been executed.
+# Output:
+# - shellvar shell variable name
+func_module_shellvar_name ()
+{
+ case $1 in
+ *[!a-zA-Z0-9_]*)
+ shellvar=${macro_prefix}_gnulib_enabled_`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
+ *)
+ shellvar=${macro_prefix}_gnulib_enabled_$1 ;;
+ esac
+}
+
+# func_module_conditional_name module
+# computes the automake conditional name for the module.
+# Output:
+# - conditional name of automake conditional
+func_module_conditional_name ()
+{
+ case $1 in
+ *[!a-zA-Z0-9_]*)
+ conditional=${macro_prefix}_GNULIB_ENABLED_`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
+ *)
+ conditional=${macro_prefix}_GNULIB_ENABLED_$1 ;;
+ esac
+}
+
+# func_uncond_add_module B
+# notes the presence of B as an unconditional module.
+#
+# func_conddep_add_module A B cond
+# notes the presence of a conditional dependency from module A to module B,
+# subject to the condition that A is enabled and cond is true.
+#
+# func_cond_module_p B
+# tests whether module B is conditional.
+#
+# func_cond_module_condition A B
+# returns the condition when B should be enabled as a dependency of A, once the
+# m4 code for A has been executed.
+# Output: - condition
+#
+if $have_associative; then
+ declare -A conddep_isuncond
+ declare -A conddep_dependers
+ declare -A conddep_condition
+ func_uncond_add_module ()
+ {
+ eval 'conddep_isuncond[$1]=true'
+ eval 'unset conddep_dependers[$1]'
+ }
+ func_conddep_add_module ()
+ {
+ eval 'isuncond="${conddep_isuncond[$2]}"'
+ if test -z "$isuncond"; then
+ # No unconditional dependency to B known at this point.
+ eval 'conddep_dependers[$2]="${conddep_dependers[$2]} $1"'
+ eval 'conddep_condition[$1---$2]="$3"'
+ fi
+ }
+ func_cond_module_p ()
+ {
+ eval 'previous_dependers="${conddep_dependers[$1]}"'
+ test -n "$previous_dependers"
+ }
+ func_cond_module_condition ()
+ {
+ eval 'condition="${conddep_condition[$1---$2]}"'
+ }
+else
+ func_uncond_add_module ()
+ {
+ case $1 in
+ *[!a-zA-Z0-9_]*)
+ suffix=`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
+ *)
+ suffix=$1 ;;
+ esac
+ eval 'conddep_isuncond_'"$suffix"'=true'
+ eval 'unset conddep_dependers_'"$suffix"
+ }
+ func_conddep_add_module ()
+ {
+ case $2 in
+ *[!a-zA-Z0-9_]*)
+ suffix=`echo "$2" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
+ *)
+ suffix=$2 ;;
+ esac
+ eval 'isuncond="${conddep_isuncond_'"$suffix"'}"'
+ if test -z "$isuncond"; then
+ eval 'conddep_dependers_'"$suffix"'="${conddep_dependers_'"$suffix"'} $1"'
+ suffix=`echo "$1---$2" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"`
+ eval 'conddep_condition_'"$suffix"'="$3"'
+ fi
+ }
+ func_cond_module_p ()
+ {
+ case $1 in
+ *[!a-zA-Z0-9_]*)
+ suffix=`echo "$1" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"` ;;
+ *)
+ suffix=$1 ;;
+ esac
+ eval 'previous_dependers="${conddep_dependers_'"$suffix"'}"'
+ test -n "$previous_dependers"
+ }
+ func_cond_module_condition ()
+ {
+ suffix=`echo "$1---$2" | md5sum | LC_ALL=C sed -e "$sed_first_32_chars"`
+ eval 'condition="${conddep_condition_'"$suffix"'}"'
+ }
+fi
+
+sed_dependencies_without_conditions='s/ *\[.*//'
+
+# func_modules_transitive_closure
+# Input:
+# - local_gnulib_dir from --local-dir
+# - modcache true or false, from --cache-modules/--no-cache-modules
+# - modules list of specified modules
+# - inctests true if tests should be included, false otherwise
+# - incobsolete true if obsolete modules among dependencies should be
+# included, blank otherwise
+# - inc_cxx_tests true if C++ interoperability tests should be included,
+# blank otherwise
+# - inc_longrunning_tests true if long-runnings tests should be included,
+# blank otherwise
+# - inc_privileged_tests true if tests that require root privileges should be
+# included, blank otherwise
+# - inc_unportable_tests true if tests that fail on some platforms should be
+# included, blank otherwise
+# - inc_all_direct_tests true if all kinds of problematic unit tests among
+# the unit tests of the specified modules should be
+# included, blank otherwise
+# - inc_all_indirect_tests true if all kinds of problematic unit tests among
+# the unit tests of the dependencies should be
+# included, blank otherwise
+# - excl_cxx_tests true if C++ interoperability tests should be excluded,
+# blank otherwise
+# - excl_longrunning_tests true if long-runnings tests should be excluded,
+# blank otherwise
+# - excl_privileged_tests true if tests that require root privileges should be
+# excluded, blank otherwise
+# - excl_unportable_tests true if tests that fail on some platforms should be
+# excluded, blank otherwise
+# - avoidlist list of modules to avoid
+# - cond_dependencies true if conditional dependencies shall be supported,
+# blank otherwise
+# - tmp pathname of a temporary directory
+# Output:
+# - modules list of modules, including dependencies
+# - conddep_dependers, conddep_condition information about conditionally
+# enabled modules
+func_modules_transitive_closure ()
+{
+ sed_escape_dependency='s|\([/.]\)|\\\1|g'
+ # In order to process every module only once (for speed), process an "input
+ # list" of modules, producing an "output list" of modules. During each round,
+ # more modules can be queued in the input list. Once a module on the input
+ # list has been processed, it is added to the "handled list", so we can avoid
+ # to process it again.
+ handledmodules=
+ inmodules="$modules"
+ outmodules=
+ fmtc_inc_all_tests="$inc_all_direct_tests"
+ if test "$cond_dependencies" = true; then
+ for module in $inmodules; do
+ func_verify_module
+ if test -n "$module"; then
+ if func_acceptable $module; then
+ func_uncond_add_module $module
+ fi
+ fi
+ done
+ fi
+ while test -n "$inmodules"; do
+ inmodules_this_round="$inmodules"
+ inmodules= # Accumulator, queue for next round
+ for module in $inmodules_this_round; do
+ func_verify_module
+ if test -n "$module"; then
+ if func_acceptable $module; then
+ func_append outmodules " $module"
+ if test "$cond_dependencies" = true; then
+ if func_get_automake_snippet_conditional $module | grep '^if ' > /dev/null; then
+ # A module whose Makefile.am snippet contains a reference to an
+ # automake conditional. If we were to use it conditionally, we
+ # would get an error
+ # configure: error: conditional "..." was never defined.
+ # because automake 1.11.1 does not handle nested conditionals
+ # correctly. As a workaround, make the module unconditional.
+ func_uncond_add_module $module
+ fi
+ if func_cond_module_p $module; then
+ conditional=true
+ else
+ conditional=false
+ fi
+ fi
+ deps=`func_get_dependencies $module | sed -e "$sed_dependencies_without_conditions"`
+ # Duplicate dependencies are harmless, but Jim wants a warning.
+ duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
+ if test -n "$duplicated_deps"; then
+ func_warning "module $module has duplicated dependencies: "`echo $duplicated_deps`
+ fi
+ if $inctests; then
+ testsmodule=`func_get_tests_module $module`
+ if test -n "$testsmodule"; then
+ deps="$deps $testsmodule"
+ fi
+ fi
+ for dep in $deps; do
+ # Determine whether to include the dependency or tests module.
+ inc=true
+ for word in `func_get_status $dep`; do
+ case "$word" in
+ obsolete)
+ test -n "$incobsolete" \
+ || inc=false
+ ;;
+ c++-test)
+ test -z "$excl_cxx_tests" \
+ || inc=false
+ test -n "$fmtc_inc_all_tests" || test -n "$inc_cxx_tests" \
+ || inc=false
+ ;;
+ longrunning-test)
+ test -z "$excl_longrunning_tests" \
+ || inc=false
+ test -n "$fmtc_inc_all_tests" || test -n "$inc_longrunning_tests" \
+ || inc=false
+ ;;
+ privileged-test)
+ test -z "$excl_privileged_tests" \
+ || inc=false
+ test -n "$fmtc_inc_all_tests" || test -n "$inc_privileged_tests" \
+ || inc=false
+ ;;
+ unportable-test)
+ test -z "$excl_unportable_tests" \
+ || inc=false
+ test -n "$fmtc_inc_all_tests" || test -n "$inc_unportable_tests" \
+ || inc=false
+ ;;
+ *-test)
+ test -n "$fmtc_inc_all_tests" \
+ || inc=false
+ ;;
+ esac
+ done
+ if $inc && func_acceptable "$dep"; then
+ func_append inmodules " $dep"
+ if test "$cond_dependencies" = true; then
+ escaped_dep=`echo "$dep" | sed -e "$sed_escape_dependency"`
+ sed_extract_condition1='/^ *'"$escaped_dep"' *$/{
+ s/^.*$/true/p
+ }'
+ sed_extract_condition2='/^ *'"$escaped_dep"' *\[.*\] *$/{
+ s/^ *'"$escaped_dep"' *\[\(.*\)\] *$/\1/p
+ }'
+ condition=`func_get_dependencies $module | sed -n -e "$sed_extract_condition1" -e "$sed_extract_condition2"`
+ if test "$condition" = true; then
+ condition=
+ fi
+ if test -n "$condition"; then
+ func_conddep_add_module "$module" "$dep" "$condition"
+ else
+ if $conditional; then
+ func_conddep_add_module "$module" "$dep" true
+ else
+ func_uncond_add_module "$dep"
+ fi
+ fi
+ fi
+ fi
+ done
+ fi
+ fi
+ done
+ handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
+ # Remove $handledmodules from $inmodules.
+ for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
+ inmodules=`echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
+ fmtc_inc_all_tests="$inc_all_indirect_tests"
+ done
+ modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
+ rm -f "$tmp"/queued-modules
+}
+
+# func_show_module_list
+# Input:
+# - specified_modules list of specified modules (one per line, sorted)
+# - modules complete list of modules (one per line, sorted)
+# - tmp pathname of a temporary directory
+func_show_module_list ()
+{
+ if case "$TERM" in
+ xterm*) test -t 1;;
+ *) false;;
+ esac; then
+ # Assume xterm compatible escape sequences.
+ bold_on=`printf '\x1b[1m'`
+ bold_off=`printf '\x1b[0m'`
+ else
+ bold_on=
+ bold_off=
+ fi
+ echo "Module list with included dependencies (indented):"
+ echo "$specified_modules" | sed -e '/^$/d' -e 's/$/| /' > "$tmp"/specified-modules
+ echo "$modules" | sed -e '/^$/d' \
+ | LC_ALL=C join -t '|' -a2 "$tmp"/specified-modules - \
+ | sed -e 's/^\(.*\)|.*/|\1/' -e 's/^/ /' -e 's/^ |\(.*\)$/ '"${bold_on}"'\1'"${bold_off}"'/'
+}
+
+# func_modules_transitive_closure_separately
+# Determine main module list and tests-related module list separately.
+# The main module list is the transitive closure of the specified modules,
+# ignoring tests modules. Its lib/* sources go into $sourcebase/. If --lgpl
+# is specified, it will consist only of LGPLed source.
+# The tests-related module list is the transitive closure of the specified
+# modules, including tests modules, minus the main module list excluding
+# modules of applicability 'all'. Its lib/* sources (brought in through
+# dependencies of *-tests modules) go into $testsbase/. It may contain GPLed
+# source, even if --lgpl is specified.
+# Input:
+# - local_gnulib_dir from --local-dir
+# - modcache true or false, from --cache-modules/--no-cache-modules
+# - specified_modules list of specified modules
+# - inctests true if tests should be included, false otherwise
+# - incobsolete true if obsolete modules among dependencies should be
+# included, blank otherwise
+# - inc_cxx_tests true if C++ interoperability tests should be included,
+# blank otherwise
+# - inc_longrunning_tests true if long-runnings tests should be included,
+# blank otherwise
+# - inc_privileged_tests true if tests that require root privileges should be
+# included, blank otherwise
+# - inc_unportable_tests true if tests that fail on some platforms should be
+# included, blank otherwise
+# - inc_all_direct_tests true if all kinds of problematic unit tests among
+# the unit tests of the specified modules should be
+# included, blank otherwise
+# - inc_all_indirect_tests true if all kinds of problematic unit tests among
+# the unit tests of the dependencies should be
+# included, blank otherwise
+# - excl_cxx_tests true if C++ interoperability tests should be excluded,
+# blank otherwise
+# - excl_longrunning_tests true if long-runnings tests should be excluded,
+# blank otherwise
+# - excl_privileged_tests true if tests that require root privileges should be
+# excluded, blank otherwise
+# - excl_unportable_tests true if tests that fail on some platforms should be
+# excluded, blank otherwise
+# - avoidlist list of modules to avoid
+# - cond_dependencies true if conditional dependencies shall be supported,
+# blank otherwise
+# - tmp pathname of a temporary directory
+# Output:
+# - main_modules list of modules, including dependencies
+# - testsrelated_modules list of tests-related modules, including dependencies
+# - conddep_dependers, conddep_condition information about conditionally
+# enabled modules
+func_modules_transitive_closure_separately ()
+{
+ # Determine main module list.
+ saved_inctests="$inctests"
+ inctests=false
+ modules="$specified_modules"
+ func_modules_transitive_closure
+ main_modules="$modules"
+ inctests="$saved_inctests"
+ if test $verbose -ge 1; then
+ echo "Main module list:"
+ echo "$main_modules" | sed -e 's/^/ /'
+ fi
+ # Determine tests-related module list.
+ echo "$final_modules" | LC_ALL=C sort -u > "$tmp"/final-modules
+ testsrelated_modules=`for module in $main_modules; do
+ if test \`func_get_applicability $module\` = main; then
+ echo $module
+ fi
+ done \
+ | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/final-modules`
+ if test $verbose -ge 1; then
+ echo "Tests-related module list:"
+ echo "$testsrelated_modules" | sed -e 's/^/ /'
+ fi
+}
+
+# func_determine_use_libtests
+# Determines whether a $testsbase/libtests.a is needed.
+# Input:
+# - local_gnulib_dir from --local-dir
+# - modcache true or false, from --cache-modules/--no-cache-modules
+# - testsrelated_modules list of tests-related modules, including dependencies
+# Output:
+# - use_libtests true if a $testsbase/libtests.a is needed, false otherwise
+func_determine_use_libtests ()
+{
+ use_libtests=false
+ for module in $testsrelated_modules; do
+ func_verify_nontests_module
+ if test -n "$module"; then
+ all_files=`func_get_filelist $module`
+ # Test whether some file in $all_files lies in lib/.
+ for f in $all_files; do
+ case $f in
+ lib/*)
+ use_libtests=true
+ break 2
+ ;;
+ esac
+ done
+ fi
+ done
+}
+
+# func_modules_add_dummy