+# func_get_link_directive module
+# Input:
+# - local_gnulib_dir from --local-dir
+func_get_link_directive ()
+{
+ func_lookup_file "modules/$1"
+ sed -n -e "/^Link$sed_extract_prog" < "$lookedup_file"
+}
+
+# func_get_license module
+# Input:
+# - local_gnulib_dir from --local-dir
+func_get_license ()
+{
+ func_lookup_file "modules/$1"
+ { sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
+ # The default is GPL.
+ echo "GPL"
+ } | sed -e 's,^ *$,,' | sed -e 1q
+}
+
+# func_get_maintainer module
+# Input:
+# - local_gnulib_dir from --local-dir
+func_get_maintainer ()
+{
+ func_lookup_file "modules/$1"
+ sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
+}
+
+# func_get_tests_module module
+# Input:
+# - local_gnulib_dir from --local-dir
+func_get_tests_module ()
+{
+ # The naming convention for tests modules is hardwired: ${module}-tests.
+ if test -f "$gnulib_dir/modules/$1"-tests \
+ || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
+ && test -f "$local_gnulib_dir/modules/$1"-tests; }; then
+ echo "$1"-tests
+ fi
+}
+
+# func_acceptable module
+# tests whether a module is acceptable.
+# Input:
+# - avoidlist list of modules to avoid
+func_acceptable ()
+{
+ for avoid in $avoidlist; do
+ if test "$avoid" = "$1"; then
+ return 1
+ fi
+ done
+ return 0
+}
+
+# func_modules_transitive_closure
+# Input:
+# - local_gnulib_dir from --local-dir
+# - modules list of specified modules
+# - inctests true if tests should be included, blank otherwise
+# - avoidlist list of modules to avoid
+# - tmp pathname of a temporary directory
+# Output:
+# - modules list of modules, including dependencies
+func_modules_transitive_closure ()
+{
+ # 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=
+ 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"
+ deps=`func_get_dependencies $module`
+ # 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
+ echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
+ fi
+ func_append inmodules " $deps"
+ if test -n "$inctests"; then
+ testsmodule=`func_get_tests_module $module`
+ if test -n "$testsmodule"; then
+ func_append inmodules " $testsmodule"
+ fi
+ fi
+ 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`
+ done
+ modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
+ rm -f "$tmp"/queued-modules
+}
+
+# func_modules_add_dummy
+# Input:
+# - local_gnulib_dir from --local-dir
+# - modules list of modules, including dependencies
+# Output:
+# - modules list of modules, including 'dummy' if needed
+func_modules_add_dummy ()
+{
+ have_lib_SOURCES=
+ sed_remove_backslash_newline=':a
+/\\$/{
+s/\\$//
+N
+s/\n//
+ba
+}'
+ for module in $modules; do
+ func_verify_nontests_module
+ if test -n "$module"; then
+ # Extract the value of "lib_SOURCES += ...".
+ for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
+ # Ignore .h files since they are not compiled.
+ case "$file" in
+ *.h) ;;
+ *) have_lib_SOURCES=yes ;;
+ esac
+ done
+ fi
+ done
+ # Add the dummy module, to make sure the library will be non-empty.
+ if test -z "$have_lib_SOURCES"; then
+ func_append modules " dummy"
+ fi
+}
+
+# func_modules_to_filelist
+# Input:
+# - local_gnulib_dir from --local-dir
+# - modules list of modules, including dependencies
+# Output:
+# - files list of files
+func_modules_to_filelist ()
+{
+ files=
+ for module in $modules; do
+ func_verify_module
+ if test -n "$module"; then
+ fs=`func_get_filelist $module`
+ func_append files " $fs"
+ fi
+ done
+ files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
+}
+
+# func_emit_lib_Makefile_am
+# emits the contents of library makefile to standard output.
+# Input:
+# - local_gnulib_dir from --local-dir
+# - modules list of modules, including dependencies
+# - libname library name
+# - auxdir directory relative to destdir where to place build aux files
+# - makefile_name from --makefile-name
+# - libtool true if libtool will be used, false or blank otherwise
+# - macro_prefix prefix of gl_LIBOBJS macros to use
+# - actioncmd (optional) command that will reproduce this invocation
+# - for_test true if creating a package for testing, false otherwise
+# Output:
+# - uses_subdirs nonempty if object files in subdirs exist
+func_emit_lib_Makefile_am ()
+{
+ # When creating an includable Makefile.am snippet, augment variables with
+ # += instead of assigning them.
+ if test -n "$makefile_name"; then
+ assign='+='
+ else
+ assign='='
+ fi
+ if test "$libtool" = true; then
+ libext=la
+ perhapsLT=LT
+ sed_eliminate_LDFLAGS=
+ else
+ libext=a
+ perhapsLT=
+ sed_eliminate_LDFLAGS='/^lib_LDFLAGS[ ]*+=/d'
+ fi
+ if $for_test; then
+ # When creating a package for testing: Attempt to provoke failures,
+ # especially link errors, already during "make" rather than during
+ # "make check", because "make check" is not possible in a cross-compiling
+ # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
+ sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
+ else
+ sed_transform_check_PROGRAMS=
+ fi
+ echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
+ echo "## Process this file with automake to produce Makefile.in."
+ func_emit_copyright_notice
+ if test -n "$actioncmd"; then
+ echo "# Reproduce by: $actioncmd"
+ fi
+ echo
+ uses_subdirs=
+ {
+ for module in $modules; do
+ func_verify_nontests_module
+ if test -n "$module"; then
+ {
+ func_get_automake_snippet "$module" |
+ sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
+ -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
+ sed -e "$sed_eliminate_LDFLAGS" |
+ sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
+ sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
+ -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' |
+ sed -e "$sed_transform_check_PROGRAMS"
+ if test "$module" = 'alloca'; then
+ echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
+ echo "${libname}_${libext}_DEPENDENCIES += @${perhapsLT}ALLOCA@"
+ fi
+ } > amsnippet.tmp
+ # Skip the contents if its entirely empty.
+ if grep '[^ ]' amsnippet.tmp > /dev/null ; then
+ echo "## begin gnulib module $module"
+ echo
+ cat amsnippet.tmp
+ echo "## end gnulib module $module"
+ echo
+ fi
+ rm -f amsnippet.tmp
+ # Test whether there are some source files in subdirectories.
+ for f in `func_get_filelist "$module"`; do
+ case $f in
+ lib/*/*.c) uses_subdirs=yes ;;
+ esac
+ done
+ fi
+ done
+ } > allsnippets.tmp
+ if test -z "$makefile_name"; then
+ # If there are source files in subdirectories, prevent collision of the
+ # object files (example: hash.c and libxml/hash.c).
+ subdir_options=
+ if test -n "$uses_subdirs"; then
+ subdir_options=' subdir-objects'
+ fi
+ echo "AUTOMAKE_OPTIONS = 1.5 gnits${subdir_options}"
+ fi
+ echo
+ if test -z "$makefile_name"; then
+ echo "noinst_HEADERS ="
+ echo "noinst_LIBRARIES ="
+ echo "noinst_LTLIBRARIES ="
+ # Automake versions < 1.9b create an empty pkgdatadir at installation time
+ # if you specify pkgdata_DATA to empty. This is a workaround.
+ if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
+ echo "pkgdata_DATA ="
+ fi
+ echo "EXTRA_DIST ="
+ echo "BUILT_SOURCES ="
+ echo "SUFFIXES ="
+ fi
+ echo "MOSTLYCLEANFILES $assign core *.stackdump"
+ if test -z "$makefile_name"; then
+ echo "MOSTLYCLEANDIRS ="
+ echo "CLEANFILES ="
+ echo "DISTCLEANFILES ="
+ echo "MAINTAINERCLEANFILES ="
+ echo
+ echo "AM_CPPFLAGS ="
+ fi
+ echo
+ if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *= *$libname\\.$libext\$" allsnippets.tmp > /dev/null; then
+ # One of the snippets already specifies an installation location for the
+ # library. Don't confuse automake by saying it should not be installed.
+ :
+ else
+ # By default, the generated library should not be installed.
+ echo "noinst_${perhapsLT}LIBRARIES += $libname.$libext"
+ fi
+ echo
+ echo "${libname}_${libext}_SOURCES ="
+ # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
+ # automake during its analyses looks for $(LIBOBJS), not for @LIBOBJS@.
+ echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
+ echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
+ echo "EXTRA_${libname}_${libext}_SOURCES ="
+ if test "$libtool" = true; then
+ echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
+ fi
+ echo
+ cat allsnippets.tmp \
+ | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
+ echo
+ echo "mostlyclean-local: mostlyclean-generic"
+ echo " @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
+ echo " if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
+ echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
+ echo " fi; \\"
+ echo " done"
+ rm -f allsnippets.tmp
+}
+
+# func_emit_tests_Makefile_am
+# emits the contents of tests makefile to standard output.
+# Input:
+# - local_gnulib_dir from --local-dir
+# - modules list of modules, including dependencies
+# - libname library name
+# - makefile_name from --makefile-name
+# - libtool true if libtool will be used, false or blank otherwise
+# - sourcebase relative directory containing lib source code
+# - m4base relative directory containing autoconf macros
+# - testsbase relative directory containing unit test code
+# - for_test true if creating a package for testing, false otherwise
+func_emit_tests_Makefile_am ()
+{
+ if test "$libtool" = true; then
+ libext=la
+ else
+ libext=a
+ fi
+ if test "$libtool" = true; then
+ libext=la
+ sed_eliminate_LDFLAGS=
+ else
+ libext=a
+ sed_eliminate_LDFLAGS='/^lib_LDFLAGS[ ]*+=/d'
+ fi
+ if $for_test; then
+ # When creating a package for testing: Attempt to provoke failures,
+ # especially link errors, already during "make" rather than during
+ # "make check", because "make check" is not possible in a cross-compiling
+ # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
+ sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
+ else
+ sed_transform_check_PROGRAMS=
+ fi
+ testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
+ echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
+ echo "## Process this file with automake to produce Makefile.in."
+ func_emit_copyright_notice
+ echo
+ # Generate dependencies here, since it eases the debugging of test failures.
+ echo "AUTOMAKE_OPTIONS = 1.5 foreign"
+ echo
+ echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
+ echo
+ (
+ for module in $modules; do
+ func_verify_tests_module
+ if test -n "$module"; then
+ {
+ func_get_automake_snippet "$module" |
+ sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
+ -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
+ sed -e "$sed_eliminate_LDFLAGS" |
+ sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
+ sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
+ -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' |
+ sed -e "$sed_transform_check_PROGRAMS"
+ } > amsnippet.tmp
+ # Skip the contents if its entirely empty.
+ if grep '[^ ]' amsnippet.tmp > /dev/null ; then
+ echo "## begin gnulib module $module"
+ echo
+ cat amsnippet.tmp
+ echo "## end gnulib module $module"
+ echo
+ fi
+ rm -f amsnippet.tmp
+ fi
+ done
+ ) > allsnippets.tmp
+ # Nothing is being added to SUBDIRS; nevertheless the existence of this
+ # variable is needed to avoid an error from automake:
+ # "AM_GNU_GETTEXT used but SUBDIRS not defined"
+ echo "SUBDIRS ="
+ echo "TESTS ="
+ echo "TESTS_ENVIRONMENT ="
+ echo "noinst_PROGRAMS ="
+ if ! $for_test; then
+ echo "check_PROGRAMS ="
+ fi
+ echo "noinst_HEADERS ="
+ if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
+ echo "pkgdata_DATA ="
+ fi
+ echo "EXTRA_DIST ="
+ echo "BUILT_SOURCES ="
+ echo "SUFFIXES ="
+ echo "MOSTLYCLEANFILES = core *.stackdump"
+ echo "MOSTLYCLEANDIRS ="
+ echo "CLEANFILES ="
+ echo "DISTCLEANFILES ="
+ echo "MAINTAINERCLEANFILES ="
+ echo
+ echo "AM_CPPFLAGS = \\"
+ echo " -I. -I\$(srcdir) \\"
+ echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
+ echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
+ echo
+ echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
+ echo
+ cat allsnippets.tmp
+ echo "# Clean up after Solaris cc."
+ echo "clean-local:"
+ echo " rm -rf SunWS_cache"
+ echo
+ echo "mostlyclean-local: mostlyclean-generic"
+ echo " @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
+ echo " if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
+ echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
+ echo " fi; \\"
+ echo " done"
+ rm -f allsnippets.tmp
+}
+
+# func_emit_initmacro_start
+# emits the first few statements of the gl_INIT macro to standard output.
+# - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
+func_emit_initmacro_start ()
+{
+ # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
+ # platform-dependent object files in ${macro_prefix}_LIBOBJS instead of
+ # LIBOBJS. The purpose is to allow several gnulib instantiations under
+ # a single configure.ac file. (AC_CONFIG_LIBOBJ_DIR does not allow this
+ # flexibility.)
+ # Furthermore it avoids an automake error like this when a Makefile.am
+ # that uses pieces of gnulib also uses $(LIBOBJ):
+ # automatically discovered file `error.c' should not be explicitly mentioned
+ echo " m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix}_LIBOBJ]))"
+ echo " m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix}_REPLACE_FUNCS]))"
+ # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
+ # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
+ # automatically discovered file `error.c' should not be explicitly mentioned
+ # We let automake know about the files to be distributed through the
+ # EXTRA_lib_SOURCES variable.
+ echo " m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix}_LIBSOURCES]))"
+}
+
+# func_emit_initmacro_end
+# emits the last few statements of the gl_INIT macro to standard output.
+# - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
+func_emit_initmacro_end ()
+{
+ echo " m4_popdef([AC_LIBSOURCES])"
+ echo " m4_popdef([AC_REPLACE_FUNCS])"
+ echo " m4_popdef([AC_LIBOBJ])"
+ echo " AC_CONFIG_COMMANDS_PRE(["
+ echo " ${macro_prefix}_libobjs="
+ echo " ${macro_prefix}_ltlibobjs="
+ echo " if test -n \"\$${macro_prefix}_LIBOBJS\"; then"
+ echo " # Remove the extension."
+ echo " sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
+ echo " for i in \`for i in \$${macro_prefix}_LIBOBJS; do echo \"\$i\"; done | sed \"\$sed_drop_objext\" | sort | uniq\`; do"
+ echo " ${macro_prefix}_libobjs=\"\$${macro_prefix}_libobjs \$i.\$ac_objext\""
+ echo " ${macro_prefix}_ltlibobjs=\"\$${macro_prefix}_ltlibobjs \$i.lo\""
+ echo " done"
+ echo " fi"
+ echo " AC_SUBST([${macro_prefix}_LIBOBJS], [\$${macro_prefix}_libobjs])"
+ echo " AC_SUBST([${macro_prefix}_LTLIBOBJS], [\$${macro_prefix}_ltlibobjs])"
+ echo " ])"
+}
+
+# func_emit_initmacro_done
+# emits a few statements after the gl_INIT macro to standard output.
+# - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
+func_emit_initmacro_done ()
+{
+ echo
+ echo "# Like AC_LIBOBJ, except that the module name goes"
+ echo "# into ${macro_prefix}_LIBOBJS instead of into LIBOBJS."
+ echo "AC_DEFUN([${macro_prefix}_LIBOBJ],"
+ echo " [${macro_prefix}_LIBOBJS=\"\$${macro_prefix}_LIBOBJS \$1.\$ac_objext\"])"
+ echo
+ echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
+ echo "# into ${macro_prefix}_LIBOBJS instead of into LIBOBJS."
+ echo "AC_DEFUN([${macro_prefix}_REPLACE_FUNCS],"
+ echo " [AC_CHECK_FUNCS([\$1], , [${macro_prefix}_LIBOBJ(\$ac_func)])])"
+ echo
+ echo "# Like AC_LIBSOURCES, except that it does nothing."
+ echo "# We rely on EXTRA_lib..._SOURCES instead."
+ echo "AC_DEFUN([${macro_prefix}_LIBSOURCES],"
+ echo " [])"
+}
+
+# func_import modules
+# Uses also the variables
+# - destdir target directory
+# - local_gnulib_dir from --local-dir
+# - libname library name
+# - sourcebase directory relative to destdir where to place source code
+# - m4base directory relative to destdir where to place *.m4 macros
+# - docbase directory relative to destdir where to place doc files
+# - testsbase directory relative to destdir where to place unit test code
+# - auxdir directory relative to destdir where to place build aux files
+# - inctests true if --with-tests was given, blank otherwise
+# - avoidlist list of modules to avoid, from --avoid
+# - lgpl true if library's license shall be LGPL, blank otherwise
+# - makefile_name from --makefile-name
+# - libtool true if --libtool was given, false if --no-libtool was
+# given, blank otherwise
+# - guessed_libtool true if the configure.ac file uses libtool, false otherwise
+# - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
+# - autoconf_minversion minimum supported autoconf version
+# - doit : if actions shall be executed, false if only to be printed
+# - symbolic true if files should be symlinked, copied otherwise
+# - lsymbolic true if files from local_gnulib_dir should be symlinked,
+# copied otherwise
+func_import ()
+{
+ # Get the cached settings.
+ cached_local_gnulib_dir=
+ cached_specified_modules=
+ cached_avoidlist=
+ cached_sourcebase=
+ cached_m4base=
+ cached_docbase=
+ cached_testsbase=
+ cached_libname=
+ cached_lgpl=
+ cached_makefile_name=
+ cached_libtool=
+ cached_macro_prefix=
+ cached_files=
+ if test -f "$destdir"/$m4base/gnulib-cache.m4; then
+ cached_libtool=false
+ my_sed_traces='
+ s,#.*$,,
+ s,^dnl .*$,,
+ s, dnl .*$,,
+ /gl_LOCAL_DIR(/ {
+ s,^.*gl_LOCAL_DIR([[ ]*\([^])]*\).*$,cached_local_gnulib_dir="\1",p
+ }
+ /gl_MODULES(/ {
+ s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
+ }
+ /gl_AVOID(/ {
+ s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
+ }
+ /gl_SOURCE_BASE(/ {
+ s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
+ }
+ /gl_M4_BASE(/ {
+ s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
+ }
+ /gl_DOC_BASE(/ {
+ s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
+ }
+ /gl_TESTS_BASE(/ {
+ s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
+ }
+ /gl_LIB(/ {
+ s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
+ }
+ /gl_LGPL/ {
+ s,^.*$,cached_lgpl=true,p
+ }
+ /gl_MAKEFILE_NAME(/ {
+ s,^.*gl_MAKEFILE_NAME([[ ]*\([^])]*\).*$,cached_makefile_name="\1",p
+ }
+ /gl_LIBTOOL/ {
+ s,^.*$,cached_libtool=true,p
+ }
+ /gl_MACRO_PREFIX(/ {
+ s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
+ }'
+ eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
+ if test -f "$destdir"/$m4base/gnulib-comp.m4; then
+ my_sed_traces='
+ s,#.*$,,
+ s,^dnl .*$,,
+ s, dnl .*$,,
+ /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
+ s,^.*$,cached_files=",p
+ n
+ ta
+ :a
+ s,^\]).*$,",
+ tb
+ p
+ n
+ ba
+ :b
+ p
+ }'
+ eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
+ fi
+ fi
+
+ # Merge the cached settings with the specified ones.
+ # The m4base must be the same as expected from the pathname.
+ if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
+ func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
+ fi
+ # The local_gnulib_dir defaults to the cached one. Recall that the cached one
+ # is relative to $destdir, whereas the one we use is relative to . or absolute.
+ if test -z "$local_gnulib_dir"; then
+ if test -n "$cached_local_gnulib_dir"; then
+ case "$destdir" in
+ /*)
+ local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
+ *)
+ case "$cached_local_gnulib_dir" in
+ /*)
+ local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
+ *)
+ func_relconcat "$destdir" "$cached_local_gnulib_dir"
+ local_gnulib_dir="$relconcat" ;;
+ esac ;;
+ esac
+ fi
+ fi
+ # Append the cached and the specified module names. So that
+ # "gnulib-tool --import foo" means to add the module foo.
+ specified_modules="$cached_specified_modules $1"
+ # Append the cached and the specified avoidlist. This is probably better
+ # than dropping the cached one when --avoid is specified at least once.
+ avoidlist=`echo $cached_avoidlist $avoidlist`
+ # The sourcebase defaults to the cached one.
+ if test -z "$sourcebase"; then
+ sourcebase="$cached_sourcebase"
+ if test -z "$sourcebase"; then
+ func_fatal_error "missing --source-base option"
+ fi
+ fi
+ # The docbase defaults to the cached one.
+ if test -z "$docbase"; then
+ docbase="$cached_docbase"
+ if test -z "$docbase"; then
+ func_fatal_error "missing --doc-base option. --doc-base has been introduced on 2006-07-11; if your last invocation of 'gnulib-tool --import' is before that date, you need to run 'gnulib-tool --import' once, with a --doc-base option."
+ fi
+ fi
+ # The testsbase defaults to the cached one.
+ if test -z "$testsbase"; then
+ testsbase="$cached_testsbase"
+ if test -z "$testsbase"; then
+ func_fatal_error "missing --tests-base option"
+ fi
+ fi
+ # The libname defaults to the cached one.
+ if test -z "$supplied_libname"; then
+ libname="$cached_libname"
+ if test -z "$libname"; then
+ func_fatal_error "missing --lib option"
+ fi
+ fi
+ # Require LGPL if specified either way.
+ if test -z "$lgpl"; then
+ lgpl="$cached_lgpl"
+ fi
+ # The makefile_name defaults to the cached one.
+ if test -z "$makefile_name"; then
+ makefile_name="$cached_makefile_name"
+ fi
+ # Use libtool if specified either way, or if guessed.
+ if test -z "$libtool"; then
+ if test -n "$cached_m4base"; then
+ libtool="$cached_libtool"
+ else
+ libtool="$guessed_libtool"
+ fi
+ fi
+ # The macro_prefix defaults to the cached one.
+ if test -z "$macro_prefix"; then
+ macro_prefix="$cached_macro_prefix"
+ if test -z "$macro_prefix"; then
+ func_fatal_error "missing --macro-prefix option"
+ fi
+ fi
+
+ # Canonicalize the list of specified modules.
+ specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
+
+ # Determine final module list.
+ modules="$specified_modules"
+ func_modules_transitive_closure
+ echo "Module list with included dependencies:"
+ echo "$modules" | sed -e 's/^/ /'
+
+ # Add the dummy module if needed.
+ func_modules_add_dummy
+
+ # If --lgpl, verify that the licenses of modules are compatible.
+ if test -n "$lgpl"; then
+ for module in $modules; do
+ license=`func_get_license $module`
+ case $license in
+ LGPL | 'GPLed build tool') ;;
+ 'public domain' | 'unlimited' | 'unmodifiable license text') ;;
+ *) func_fatal_error "incompatible license on module $module: $license" ;;
+ esac
+ done
+ fi
+
+ # Determine script to apply to imported library files.
+ sed_transform_lib_file=
+ for module in $modules; do
+ if test $module = config-h; then
+ # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
+ sed_transform_lib_file=$sed_transform_lib_file'
+ s/^#ifdef[ ]*HAVE_CONFIG_H[ ]*$/#if 1/
+ '
+ break
+ fi
+ done
+ if test -n "$lgpl"; then
+ # Update license.
+ sed_transform_lib_file=$sed_transform_lib_file'
+ s/GNU General/GNU Lesser General/g
+ s/version 2\([ ,]\)/version 2.1\1/g
+ '
+ fi
+
+ # Determine final file list.
+ func_modules_to_filelist
+ echo "File list:"
+ echo "$files" | sed -e 's/^/ /'
+
+ test -n "$files" \
+ || func_fatal_error "refusing to do nothing"
+
+ # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
+ new_files="$files m4/gnulib-tool.m4"
+ old_files="$cached_files"
+ if test -f "$destdir"/$m4base/gnulib-tool.m4; then
+ func_append old_files " m4/gnulib-tool.m4"
+ fi
+
+ sed_rewrite_old_files="\
+ s,^build-aux/,$auxdir/,
+ s,^doc/,$cached_docbase/,
+ s,^lib/,$cached_sourcebase/,
+ s,^m4/,$cached_m4base/,
+ s,^tests/,$cached_testsbase/,"
+ sed_rewrite_new_files="\
+ s,^build-aux/,$auxdir/,
+ s,^doc/,$docbase/,
+ s,^lib/,$sourcebase/,
+ s,^m4/,$m4base/,
+ s,^tests/,$testsbase/,"
+
+ # Create directories.
+ { echo "$sourcebase"
+ echo "$m4base"
+ docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
+ if test -n "$docfiles"; then
+ echo "$docbase"
+ fi
+ if test -n "$inctests"; then
+ echo "$testsbase"
+ fi
+ echo "$auxdir"
+ for f in $files; do echo $f; done \
+ | sed -e "$sed_rewrite_new_files" \
+ | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
+ | LC_ALL=C sort -u
+ } > "$tmp"/dirs
+ { # Rearrange file descriptors. Needed because "while ... done < ..."
+ # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
+ exec 5<&0 < "$tmp"/dirs
+ while read d; do
+ if test ! -d "$destdir/$d"; then
+ if $doit; then
+ echo "Creating directory $destdir/$d"
+ mkdir -p "$destdir/$d" || func_fatal_error "failed"
+ else
+ echo "Create directory $destdir/$d"
+ fi
+ fi
+ done
+ exec 0<&5 5<&-
+ }
+
+ # func_dest_tmpfilename file
+ # determines the name of a temporary file (file is relative to destdir).
+ # Sets variable:
+ # - tmpfile absolute filename of the temporary file
+ func_dest_tmpfilename ()
+ {
+ if $doit; then
+ # Put the new contents of $file in a file in the same directory (needed
+ # to guarantee that an 'mv' to "$destdir/$file" works).
+ tmpfile="$destdir/$1.tmp"
+ else
+ # Put the new contents of $file in a file in a temporary directory
+ # (because the directory of "$file" might not exist).
+ tmpfile="$tmp"/`basename "$1"`.tmp
+ fi
+ }
+
+ # Copy files or make symbolic links. Remove obsolete files.
+ delimiter=' '
+ # Construct a table with 2 columns: rewritten-file-name original-file-name,
+ # representing the files according to the last gnulib-tool invocation.
+ for f in $old_files; do echo $f; done \
+ | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
+ | LC_ALL=C sort \
+ > "$tmp"/old-files
+ # Construct a table with 2 columns: rewritten-file-name original-file-name,
+ # representing the files after this gnulib-tool invocation.
+ for f in $new_files; do echo $f; done \
+ | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
+ | LC_ALL=C sort \
+ > "$tmp"/new-files
+ # First the files that are in old-files, but not in new-files:
+ sed_take_first_column='s,'"$delimiter"'.*,,'
+ for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
+ # Remove the file. Do nothing if the user already removed it.
+ if test -f "$destdir/$g"; then
+ if $doit; then
+ echo "Removing file $g (backup in ${g}~)"
+ mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
+ else
+ echo "Remove file $g (backup in ${g}~)"
+ fi
+ fi
+ done
+ # func_add_or_update handles a file that ought to be present afterwards.
+ # Uses parameters
+ # - f the original file name
+ # - g the rewritten file name
+ # - already_present nonempty if the file already exists, empty otherwise
+ func_add_or_update ()
+ {
+ func_dest_tmpfilename "$g"
+ func_lookup_file "$f"
+ cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
+ if test -n "$sed_transform_lib_file"; then
+ case "$f" in
+ lib/*)
+ sed -e "$sed_transform_lib_file" \
+ < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
+ ;;
+ esac
+ fi
+ if test -f "$destdir/$g"; then
+ # The file already exists.
+ if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
+ : # The file has not changed.
+ else
+ # Replace the file.
+ if $doit; then
+ if test -n "$already_present"; then
+ echo "Updating file $g (backup in ${g}~)"
+ else
+ echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
+ fi
+ mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
+ if { test -n "$symbolic" \
+ || { test -n "$lsymbolic" \
+ && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
+ && test -z "$lookedup_tmp" \
+ && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
+ func_ln_if_changed "$lookedup_file" "$destdir/$g"
+ else
+ mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
+ fi
+ else
+ if test -n "$already_present"; then
+ echo "Update file $g (backup in ${g}~)"
+ else
+ echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
+ fi
+ fi
+ fi
+ else
+ # Install the file.
+ # Don't protest if the file should be there but isn't: it happens
+ # frequently that developers don't put autogenerated files into CVS.
+ if $doit; then
+ echo "Copying file $g"
+ if { test -n "$symbolic" \
+ || { test -n "$lsymbolic" \
+ && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
+ && test -z "$lookedup_tmp" \
+ && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
+ func_ln_if_changed "$lookedup_file" "$destdir/$g"
+ else
+ mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
+ fi
+ else
+ echo "Copy file $g"
+ fi
+ fi
+ rm -f "$tmpfile"
+ }
+ # Then the files that are in new-files, but not in old-files:
+ sed_take_last_column='s,^.*'"$delimiter"',,'
+ already_present=
+ LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
+ | sed -e "$sed_take_last_column" \
+ | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
+ { # Rearrange file descriptors. Needed because "while ... done < ..."
+ # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
+ exec 5<&0 < "$tmp"/added-files
+ while read g f; do
+ func_add_or_update
+ done
+ exec 0<&5 5<&-
+ }
+ # Then the files that are in new-files and in old-files:
+ already_present=true
+ LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
+ | sed -e "$sed_take_last_column" \
+ | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
+ { # Rearrange file descriptors. Needed because "while ... done < ..."
+ # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
+ exec 5<&0 < "$tmp"/kept-files
+ while read g f; do
+ func_add_or_update
+ done
+ exec 0<&5 5<&-
+ }
+
+ # Command-line invocation printed in a comment in generated gnulib-cache.m4.
+ actioncmd="gnulib-tool --import"
+ func_append actioncmd " --dir=$destdir"
+ if test -n "$local_gnulib_dir"; then
+ func_append actioncmd " --local-dir=$local_gnulib_dir"
+ fi
+ func_append actioncmd " --lib=$libname"
+ func_append actioncmd " --source-base=$sourcebase"
+ func_append actioncmd " --m4-base=$m4base"
+ func_append actioncmd " --doc-base=$docbase"
+ func_append actioncmd " --aux-dir=$auxdir"
+ for module in $avoidlist; do
+ func_append actioncmd " --avoid=$module"
+ done
+ if test -n "$lgpl"; then
+ func_append actioncmd " --lgpl"
+ fi
+ if test -n "$makefile_name"; then
+ func_append actioncmd " --makefile-name=$makefile_name"
+ fi
+ if test "$libtool" = true; then
+ func_append actioncmd " --libtool"
+ else
+ func_append actioncmd " --no-libtool"
+ fi
+ func_append actioncmd " --macro-prefix=$macro_prefix"
+ func_append actioncmd " `echo $specified_modules`"
+
+ # Default the makefile name to Makefile.am.
+ if test -n "$makefile_name"; then
+ makefile_am=$makefile_name
+ else
+ makefile_am=Makefile.am
+ fi
+
+ # Create normal Makefile.ams.
+ for_test=false