3 # Copyright (C) 2002-2006 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 # This program is meant for authors or maintainers which want to import
21 # modules from gnulib into their packages.
25 cvsdatestamp='$Date: 2006-07-11 12:58:27 $'
26 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
27 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
29 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
33 # AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
34 # AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
38 # You can set AUTOMAKEPATH to empty if automake 1.9.x is already in your PATH.
41 # If you didn't set AUTOCONFPATH and AUTOMAKEPATH, you can also set the
42 # variables AUTOCONF, ACLOCAL, AUTOMAKE, AUTORECONF individually.
43 if test -z "${AUTOCONF}" || test -n "${AUTOCONFPATH}"; then
44 AUTOCONF="${AUTOCONFPATH}autoconf"
46 if test -z "${ACLOCAL}" || test -n "${AUTOMAKEPATH}"; then
47 ACLOCAL="${AUTOMAKEPATH}aclocal"
49 if test -z "${AUTOMAKE}" || test -n "${AUTOMAKEPATH}"; then
50 AUTOMAKE="${AUTOMAKEPATH}automake"
52 if test -z "${AUTORECONF}" || test -n "${AUTOCONFPATH}"; then
53 AUTORECONF="${AUTOCONFPATH}autoreconf"
57 # outputs to stdout the --help usage message.
61 Usage: gnulib-tool --list
62 gnulib-tool --import [module1 ... moduleN]
64 gnulib-tool --create-testdir --dir=directory module1 ... moduleN
65 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
66 gnulib-tool --test --dir=directory module1 ... moduleN
67 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
68 gnulib-tool --extract-description module
69 gnulib-tool --extract-filelist module
70 gnulib-tool --extract-dependencies module
71 gnulib-tool --extract-autoconf-snippet module
72 gnulib-tool --extract-automake-snippet module
73 gnulib-tool --extract-include-directive module
74 gnulib-tool --extract-license module
75 gnulib-tool --extract-maintainer module
76 gnulib-tool --extract-tests-module module
79 --list print the available module names
80 --import import the given modules into the current package;
81 if no modules are specified, update the current
82 package from the current gnulib
83 --update update the current package, restore files omitted
85 --create-testdir create a scratch package with the given modules
86 --create-megatestdir create a mega scratch package with the given modules
87 one by one and all together
88 --test test the combination of the given modules
89 (recommended to use CC=\"gcc -Wall\" here)
90 --megatest test the given modules one by one and all together
91 (recommended to use CC=\"gcc -Wall\" here)
92 --extract-description extract the description
93 --extract-filelist extract the list of files
94 --extract-dependencies extract the dependencies
95 --extract-autoconf-snippet extract the snippet for configure.ac
96 --extract-automake-snippet extract the snippet for lib/Makefile.am
97 --extract-include-directive extract the #include directive
98 --extract-license report the license terms of the source files
100 --extract-maintainer report the maintainer(s) inside gnulib
101 --extract-tests-module report the unit test module, if it exists
104 --dir=DIRECTORY specify the target directory
105 For --import, this specifies where your
106 configure.ac can be found. Defaults to current
108 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
109 --source-base=DIRECTORY
110 Directory relative --dir where source code is
111 placed (default \"lib\"), for --import.
112 --m4-base=DIRECTORY Directory relative --dir where *.m4 macros are
113 placed (default \"m4\"), for --import.
114 --tests-base=DIRECTORY
115 Directory relative --dir where unit tests are
116 placed (default \"tests\"), for --import.
117 --doc-base=DIRECTORY Directory relative --dir where doc files are
118 placed (default \"doc\"), for --import.
119 --aux-dir=DIRECTORY Directory relative --dir where auxiliary build
120 tools are placed (default \"build-aux\").
121 --with-tests Include unit tests for the included modules.
122 --avoid=MODULE Avoid including the given MODULE. Useful if you
123 have code that provides equivalent functionality.
124 This option can be repeated.
125 --lgpl Abort if modules aren't available under the LGPL.
126 Also modify license template from GPL to LGPL.
127 --libtool Use libtool rules, for --import.
128 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
129 'gl_INIT'. Default is 'gl'.
130 --no-changelog don't update or create ChangeLog files
131 --dry-run For --import, only print what would have been done.
132 -s, --symbolic, --symlink Make symbolic links instead of copying files.
134 Report bugs to <bug-gnulib@gnu.org>."
138 # outputs to stdout the --version message.
141 year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
142 echo "$progname (GNU $package) $version"
143 echo "Copyright (C) $year Free Software Foundation, Inc.
144 This is free software; see the source for copying conditions. There is NO
145 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
146 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
149 # func_emit_copyright_notice
150 # outputs to stdout a header for a generated file.
151 func_emit_copyright_notice ()
153 echo "# Copyright (C) 2004-2006 Free Software Foundation, Inc."
155 echo "# This file is free software, distributed under the terms of the GNU"
156 echo "# General Public License. As a special exception to the GNU General"
157 echo "# Public License, this file may be distributed as part of a program"
158 echo "# that contains a configuration script generated by Autoconf, under"
159 echo "# the same distribution terms as the rest of that program."
161 echo "# Generated by gnulib-tool."
165 # creates a temporary directory.
167 # - tmp pathname of freshly created temporary directory
170 # Use the environment variable TMPDIR, falling back to /tmp. This allows
171 # users to specify a different temporary directory, for example, if their
172 # /tmp is filled up or too small.
175 # Use the mktemp program if available. If not available, hide the error
177 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
178 test -n "$tmp" && test -d "$tmp"
181 # Use a simple mkdir command. It is guaranteed to fail if the directory
182 # already exists. $RANDOM is bash specific and expands to empty in shells
183 # other than bash, ksh and zsh. Its use does not increase security;
184 # rather, it minimizes the probability of failure in a very cluttered /tmp
186 tmp=$TMPDIR/gl$$-$RANDOM
187 (umask 077 && mkdir "$tmp")
190 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
191 { (exit 1); exit 1; }
195 # func_fatal_error message
196 # outputs to stderr a fatal error message, and terminates the program.
199 echo "gnulib-tool: *** $1" 1>&2
200 echo "gnulib-tool: *** Stop." 1>&2
204 # func_readlink SYMLINK
205 # outputs the target of the given symlink.
206 if (type -p readlink) > /dev/null 2>&1; then
209 # Use the readlink program from GNU coreutils.
215 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
216 # would do the wrong thing if the link target contains " -> ".
217 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
221 # func_ln_if_changed SRC DEST
222 # Like ln -s, but avoids munging timestamps if the link is correct.
223 func_ln_if_changed ()
225 if test $# -ne 2; then
226 echo "usage: func_ln_if_changed SRC DEST" >&2
228 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
236 # Command-line option processing.
237 # Removes the OPTIONS from the arguments. Sets the variables:
238 # - mode list or import or create-testdir or create-megatestdir
239 # - destdir from --dir
240 # - libname, supplied_libname from --lib
241 # - sourcebase from --source-base
242 # - m4base from --m4-base
243 # - testsbase from --tests-base
244 # - docbase from --doc-base
245 # - auxdir from --aux-dir
246 # - inctests true if --with-tests was given, blank otherwise
247 # - avoidlist list of modules to avoid, from --avoid
248 # - lgpl true if --lgpl was given, blank otherwise
249 # - libtool true if --libtool was given, blank otherwise
250 # - do_changelog false if --no-changelog was given, : otherwise
251 # - doit : if actions shall be executed, false if only to be printed
272 while test $# -gt 0; do
277 --import | --impor | --impo | --imp | --im | --i )
280 --update | --updat | --upda | --upd | --up | --u )
283 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
286 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
287 mode=create-megatestdir
289 --test | --tes | --te | --t )
292 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
296 mode=`echo "X$1" | sed -e 's/^X--//'`
301 func_fatal_error "missing argument for --dir"
306 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
311 func_fatal_error "missing argument for --lib"
314 supplied_libname=true
317 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
318 supplied_libname=true
323 func_fatal_error "missing argument for --source-base"
328 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
333 func_fatal_error "missing argument for --m4-base"
338 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
343 func_fatal_error "missing argument for --tests-base"
348 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
353 func_fatal_error "missing argument for --doc-base"
358 docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
363 func_fatal_error "missing argument for --aux-dir"
368 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
376 func_fatal_error "missing argument for --avoid"
378 avoidlist="$avoidlist $1"
381 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
392 func_fatal_error "missing argument for --macro-prefix"
397 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
399 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
405 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
408 --help | --hel | --he | --h )
411 --version | --versio | --versi | --vers | --ver | --ve | --v )
415 # Stop option processing
419 echo "gnulib-tool: unknown option $1" 1>&2
420 echo "Try 'gnulib-tool --help' for more information." 1>&2
427 if test "$mode" = update; then
428 if test $# != 0; then
429 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
430 echo "Try 'gnulib-tool --help' for more information." 1>&2
431 echo "If you really want to modify the gnulib configuration of your project," 1>&2
432 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
435 if test -n "$supplied_libname" || test -n "$sourcebase" || test -n "$m4base" \
436 || test -n "$testsbase" || test -n "$auxdir" || test -n "$inctests" \
437 || test -n "$docbase" \
438 || test -n "$avoidlist" || test -n "$lgpl" || test -n "$macro_prefix"; then
439 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
440 echo "Try 'gnulib-tool --help' for more information." 1>&2
441 echo "If you really want to modify the gnulib configuration of your project," 1>&2
442 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
448 # Remove trailing slashes from the directory names. This is necessary for
449 # m4base (to avoid an error in func_import) and optional for the others.
450 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
451 case "$sourcebase" in
452 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
455 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
458 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
461 */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
464 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
469 /*) self_abspathname="$0" ;;
470 */*) self_abspathname=`pwd`/"$0" ;;
471 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
472 if test -x "$d/$0" && test ! -d "$d/$0"; then
473 self_abspathname="$d/$0"
477 if test -z "$self_abspathname"; then
478 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
482 while test -h "$self_abspathname"; do
483 # Resolve symbolic link.
484 linkval=`func_readlink "$self_abspathname"`
485 test -n "$linkval" || break
487 /* ) self_abspathname="$linkval" ;;
488 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
491 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
496 # Filter out metainformation files like README, which are not modules.
497 # Filter out unit test modules; they can be retrieved through
498 # --extract-tests-module if desired.
499 (cd "$gnulib_dir/modules" && ls -1) \
500 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
501 | sed -e '/-tests$/d' \
506 # verifies a module name
507 func_verify_module ()
509 if test ! -f "$gnulib_dir/modules/$module" \
510 || test "CVS" = "$module" \
511 || test "ChangeLog" = "$module" \
512 || test "README" = "$module" \
513 || test "TEMPLATE" = "$module" \
514 || test "TEMPLATE-TESTS" = "$module"; then
515 echo "gnulib-tool: module $module doesn't exist" 1>&2
520 # func_verify_nontests_module
521 # verifies a module name, excluding tests modules
522 func_verify_nontests_module ()
526 * ) func_verify_module ;;
530 # func_verify_tests_module
531 # verifies a module name, considering only tests modules
532 func_verify_tests_module ()
535 *-tests ) func_verify_module ;;
540 sed_extract_prog=':[ ]*$/ {
543 s/^Description:[ ]*$//
545 s/^Depends-on:[ ]*$//
546 s/^configure\.ac:[ ]*$//
547 s/^Makefile\.am:[ ]*$//
550 s/^Maintainer:[ ]*$//
557 # func_get_description module
558 func_get_description ()
560 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
563 # func_get_filelist module
566 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
568 #echo m4/onceonly_2_57.m4
571 # func_get_dependencies module
572 func_get_dependencies ()
574 # ${module}-tests always implicitly depends on ${module}.
575 echo "$1" | sed -n -e 's/-tests//p'
576 # Then the explicit dependencies listed in the module description.
577 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
580 # func_get_autoconf_snippet module
581 func_get_autoconf_snippet ()
583 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
586 # func_get_automake_snippet module
587 func_get_automake_snippet ()
589 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
592 # func_get_include_directive module
593 func_get_include_directive ()
595 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
596 sed -e 's/^\(["<]\)/#include \1/'
599 # func_get_license module
602 sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
605 # func_get_maintainer module
606 func_get_maintainer ()
608 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
611 # func_get_tests_module module
612 func_get_tests_module ()
614 # The naming convention for tests modules is hardwired: ${module}-tests.
615 if test -f modules/"$1"-tests; then
620 # func_acceptable module
621 # tests whether a module is acceptable.
623 # - avoidlist list of modules to avoid
626 for avoid in $avoidlist; do
627 if test "$avoid" = "$1"; then
634 # func_modules_transitive_closure
636 # - modules list of specified modules
637 # - inctests true if tests should be included, blank otherwise
638 # - avoidlist list of modules to avoid
640 # - modules list of modules, including dependencies
641 func_modules_transitive_closure ()
645 for module in $modules; do
647 if test -n "$module"; then
648 # Duplicate dependencies are harmless, but Jim wants a warning.
649 duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
650 if test -n "$duplicated_deps"; then
651 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
653 if func_acceptable $module; then
654 xmodules="$xmodules $module"
655 for depmodule in `func_get_dependencies $module`; do
656 if func_acceptable $depmodule; then
657 xmodules="$xmodules $depmodule"
660 if test -n "$inctests"; then
661 testsmodule=`func_get_tests_module $module`
662 if test -n "$testsmodule"; then
663 if func_acceptable $testsmodule; then
664 xmodules="$xmodules $testsmodule"
665 for depmodule in `func_get_dependencies $testsmodule`; do
666 if func_acceptable $depmodule; then
667 xmodules="$xmodules $depmodule"
676 xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
677 if test "$xmodules" = "$modules"; then
684 # func_modules_add_dummy
686 # - modules list of modules, including dependencies
688 # - modules list of modules, including 'dummy' if needed
689 func_modules_add_dummy ()
692 sed_remove_backslash_newline=':a
699 for module in $modules; do
700 func_verify_nontests_module
701 if test -n "$module"; then
702 # Extract the value of "lib_SOURCES += ...".
703 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
704 # Ignore .h files since they are not compiled.
707 *) have_lib_SOURCES=yes ;;
712 # Add the dummy module, to make sure the library will be non-empty.
713 if test -z "$have_lib_SOURCES"; then
714 modules="$modules dummy"
718 # func_modules_to_filelist
720 # - modules list of modules, including dependencies
722 # - files list of files
723 func_modules_to_filelist ()
726 for module in $modules; do
728 if test -n "$module"; then
729 files="$files "`func_get_filelist $module`
732 files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
735 # func_emit_lib_Makefile_am
736 # emits the contents of lib/Makefile.am to standard output.
738 # - modules list of modules, including dependencies
739 # - libname library name
740 # - libtool true if libtool will be used, blank otherwise
741 # - actioncmd (optional) command that will reproduce this invocation
742 func_emit_lib_Makefile_am ()
744 if test -n "$libtool"; then
751 echo "## Process this file with automake to produce Makefile.in."
752 func_emit_copyright_notice
753 if test -n "$actioncmd"; then
754 echo "# Reproduce by: $actioncmd"
757 # No need to generate dependencies since the sources are in gnulib, not here.
758 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
760 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
762 echo "${libname}_${libext}_SOURCES ="
763 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
764 echo "noinst_HEADERS ="
766 echo "BUILT_SOURCES ="
768 echo "MOSTLYCLEANFILES ="
769 echo "MOSTLYCLEANDIRS ="
771 echo "DISTCLEANFILES ="
772 echo "MAINTAINERCLEANFILES ="
776 for module in $modules; do
777 func_verify_nontests_module
778 if test -n "$module"; then
780 func_get_automake_snippet "$module" |
781 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
782 if test "$module" = 'alloca'; then
783 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
786 # Skip the contents if its entirely empty.
787 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
788 echo "## begin gnulib module $module"
791 echo "## end gnulib module $module"
798 echo "mostlyclean-local:"
799 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
800 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
801 echo " if test -d \$\$dir; then \\"
802 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
806 echo "# Makefile.am ends here"
809 # func_emit_tests_Makefile_am
810 # emits the contents of tests/Makefile.am to standard output.
812 # - modules list of modules, including dependencies
813 # - libname library name
814 # - libtool true if libtool will be used, blank otherwise
815 # - sourcebase relative directory containing lib source code
816 # - m4base relative directory containing autoconf macros
817 # - testsbase relative directory containing unit test code
818 func_emit_tests_Makefile_am ()
820 if test -n "$libtool"; then
825 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
826 echo "## Process this file with automake to produce Makefile.in."
827 func_emit_copyright_notice
829 # Generate dependencies here, since it eases the debugging of test failures.
830 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
832 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
834 # Nothing is being added to SUBDIRS; nevertheless the existence of this
835 # variable is needed to avoid an error from automake:
836 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
839 echo "TESTS_ENVIRONMENT ="
840 echo "noinst_PROGRAMS ="
841 echo "check_PROGRAMS ="
842 echo "noinst_HEADERS ="
844 echo "BUILT_SOURCES ="
846 echo "MOSTLYCLEANFILES ="
847 echo "MOSTLYCLEANDIRS ="
849 echo "DISTCLEANFILES ="
850 echo "MAINTAINERCLEANFILES ="
852 echo "AM_CPPFLAGS = \\"
853 echo " -I. -I\$(srcdir) \\"
854 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
855 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
857 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
859 for module in $modules; do
860 func_verify_tests_module
861 if test -n "$module"; then
862 func_get_automake_snippet "$module" > amsnippet.tmp
863 # Skip the contents if its entirely empty.
864 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
865 echo "## begin gnulib module $module"
868 echo "## end gnulib module $module"
874 echo "# Clean up after Solaris cc."
876 echo " rm -rf SunWS_cache"
878 echo "mostlyclean-local:"
879 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
880 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
881 echo " if test -d \$\$dir; then \\"
882 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
886 echo "# Makefile.am ends here"
889 # func_import modules
890 # Uses also the variables
891 # - destdir target directory
892 # - libname library name
893 # - sourcebase directory relative to destdir where to place source code
894 # - m4base directory relative to destdir where to place *.m4 macros
895 # - testsbase directory relative to destdir where to place unit test code
896 # - docbase directory relative to destdir where to place doc files
897 # - auxdir directory relative to destdir where to place build aux files
898 # - inctests true if --with-tests was given, blank otherwise
899 # - avoidlist list of modules to avoid, from --avoid
900 # - lgpl true if library's license shall be LGPL, blank otherwise
901 # - libtool true if libtool will be used, blank otherwise
902 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
903 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
904 # - doit : if actions shall be executed, false if only to be printed
905 # - symbolic true if files should be symlinked, copied otherwise
908 # Get the cached settings.
909 cached_specified_modules=
920 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
926 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
929 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
932 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
935 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
938 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
941 s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
944 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
947 s,^.*$,cached_lgpl=true,p
950 s,^.*$,cached_libtool=true,p
953 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
955 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
956 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
961 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
962 s,^.*$,cached_files=",p
974 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
978 # Merge the cached settings with the specified ones.
979 # The m4base must be the same as expected from the pathname.
980 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
981 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
983 # Append the cached and the specified module names. So that
984 # "gnulib-tool --import foo" means to add the module foo.
985 specified_modules="$cached_specified_modules $1"
986 # Append the cached and the specified avoidlist. This is probably better
987 # than dropping the cached one when --avoid is specified at least once.
988 avoidlist=`echo $cached_avoidlist $avoidlist`
989 # The sourcebase defaults to the cached one.
990 if test -z "$sourcebase"; then
991 sourcebase="$cached_sourcebase"
992 if test -z "$sourcebase"; then
993 func_fatal_error "missing --source-base option"
996 # The testsbase defaults to the cached one.
997 if test -z "$testsbase"; then
998 testsbase="$cached_testsbase"
999 if test -z "$testsbase"; then
1000 func_fatal_error "missing --tests-base option"
1003 # The docbase defaults to the cached one.
1004 if test -z "$docbase"; then
1005 docbase="$cached_docbase"
1006 if test -z "$docbase"; then
1007 func_fatal_error "missing --doc-base option"
1010 # The libname defaults to the cached one.
1011 if test -z "$supplied_libname"; then
1012 libname="$cached_libname"
1013 if test -z "$libname"; then
1014 func_fatal_error "missing --lib option"
1017 # Require LGPL if specified either way.
1018 if test -z "$lgpl"; then
1021 # Use libtool if specified either way, or if guessed.
1022 if test -z "$libtool"; then
1023 if test -n "$cached_m4base"; then
1024 libtool="$cached_libtool"
1026 libtool="$guessed_libtool"
1029 # The macro_prefix defaults to the cached one.
1030 if test -z "$macro_prefix"; then
1031 macro_prefix="$cached_macro_prefix"
1032 if test -z "$macro_prefix"; then
1033 func_fatal_error "missing --macro-prefix option"
1037 # Canonicalize the list of specified modules.
1038 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1040 # Determine final module list.
1041 modules="$specified_modules"
1042 func_modules_transitive_closure
1043 echo "Module list with included dependencies:"
1044 echo "$modules" | sed -e 's/^/ /'
1046 # Add the dummy module if needed.
1047 func_modules_add_dummy
1049 # If --lgpl, check the license of modules are compatible.
1050 if test -n "$lgpl"; then
1051 for module in $modules; do
1052 license=`func_get_license $module`
1054 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
1055 *) func_fatal_error "incompatible license on module $module: $license" ;;
1060 # Determine final file list.
1061 func_modules_to_filelist
1063 echo "$files" | sed -e 's/^/ /'
1066 || func_fatal_error "refusing to do nothing"
1068 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1069 new_files="$files m4/gnulib-tool.m4"
1070 old_files="$cached_files"
1071 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1072 old_files="$old_files m4/gnulib-tool.m4"
1075 # Create directories.
1076 if test ! -d "$destdir/$sourcebase"; then
1078 echo "Creating directory $destdir/$sourcebase"
1079 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1081 echo "Create directory $destdir/$sourcebase"
1084 if test ! -d "$destdir/$m4base"; then
1086 echo "Creating directory $destdir/$m4base"
1087 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1089 echo "Create directory $destdir/$m4base"
1092 if test -n "$inctests"; then
1093 if test ! -d "$destdir/$testsbase"; then
1095 echo "Creating directory $destdir/$testsbase"
1096 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1098 echo "Create directory $destdir/$testsbase"
1102 if test ! -d "$destdir/$docbase"; then
1104 echo "Creating directory $destdir/$docbase"
1105 mkdir "$destdir/$docbase" || func_fatal_error "failed"
1107 echo "Create directory $destdir/$docbase"
1110 if test ! -d "$destdir/$auxdir"; then
1112 echo "Creating directory $destdir/$auxdir"
1113 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1115 echo "Create directory $destdir/$auxdir"
1120 trap 'rm -rf "$tmp"' 0 1 2 3 15
1121 # func_dest_tmpfilename file
1122 # determines the name of a temporary file (file is relative to destdir).
1124 # - tmpfile absolute filename of the temporary file
1125 func_dest_tmpfilename ()
1128 # Put the new contents of $file in a file in the same directory (needed
1129 # to guarantee that an 'mv' to "$destdir/$file" works).
1130 tmpfile="$destdir/$1.tmp"
1132 # Put the new contents of $file in a file in a temporary directory
1133 # (because the directory of "$file" might not exist).
1134 tmpfile="$tmp"/`basename "$1"`.tmp
1138 # Copy files or make symbolic links. Remove obsolete files.
1140 for f in $old_files; do
1142 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1143 doc/*) g=`echo "$f" | sed -e "s,^doc/,$cached_docbase/,"` ;;
1144 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1145 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1146 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1149 echo "$g""$delimiter""$f"
1150 done | LC_ALL=C sort > "$tmp"/old-files
1151 for f in $new_files; do
1153 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1154 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1155 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1156 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1157 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1160 echo "$g""$delimiter""$f"
1161 done | LC_ALL=C sort > "$tmp"/new-files
1162 # First the files that are in old-files, but not in new-files:
1163 sed_take_first_column='s,'"$delimiter"'.*,,'
1164 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1165 # Remove the file. Do nothing if the user already removed it.
1166 if test -f "$destdir/$g"; then
1168 echo "Removing file $g (backup in ${g}~)"
1169 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1171 echo "Remove file $g (backup in ${g}~)"
1175 # func_add_or_update handles a file that ought to be present afterwards.
1176 # Uses parameters f, g, already_present.
1177 func_add_or_update ()
1179 func_dest_tmpfilename "$g"
1180 cp "$gnulib_dir/$f" "$tmpfile" || func_fatal_error "failed"
1181 if test -n "$lgpl"; then
1185 sed -e 's/GNU General/GNU Lesser General/g' \
1186 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1187 < "$gnulib_dir/$f" > "$tmpfile" || func_fatal_error "failed"
1191 if test -f "$destdir/$g"; then
1192 # The file already exists.
1193 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1194 : # The file has not changed.
1198 if test -n "$already_present"; then
1199 echo "Updating file $g (backup in ${g}~)"
1201 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1203 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1204 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1205 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1207 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1210 if test -n "$already_present"; then
1211 echo "Update file $g (backup in ${g}~)"
1213 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1219 # Don't protest if the file should be there but isn't: it happens
1220 # frequently that developers don't put autogenerated files into CVS.
1222 echo "Copying file $g"
1223 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1224 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1226 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1234 # Then the files that are in new-files, but not in old-files:
1235 sed_take_last_column='s,^.*'"$delimiter"',,'
1237 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1239 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1240 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1241 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1242 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1243 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1248 # Then the files that are in new-files and in old-files:
1249 already_present=true
1250 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1252 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1253 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1254 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1255 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1256 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1262 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1263 actioncmd="gnulib-tool --import"
1264 actioncmd="$actioncmd --dir=$destdir"
1265 actioncmd="$actioncmd --lib=$libname"
1266 actioncmd="$actioncmd --source-base=$sourcebase"
1267 actioncmd="$actioncmd --m4-base=$m4base"
1268 actioncmd="$actioncmd --doc-base=$docbase"
1269 actioncmd="$actioncmd --aux-dir=$auxdir"
1270 for module in $avoidlist; do
1271 actioncmd="$actioncmd --avoid=$module"
1273 if test -n "$lgpl"; then
1274 actioncmd="$actioncmd --lgpl"
1276 if test -n "$libtool"; then
1277 actioncmd="$actioncmd --libtool"
1279 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1280 actioncmd="$actioncmd `echo $specified_modules`"
1282 # Create lib/Makefile.am.
1283 func_dest_tmpfilename $sourcebase/Makefile.am
1284 func_emit_lib_Makefile_am > "$tmpfile"
1285 if test -f "$destdir"/$sourcebase/Makefile.am; then
1286 if cmp "$destdir"/$sourcebase/Makefile.am "$tmpfile" > /dev/null; then
1290 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1291 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1292 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1294 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1300 echo "Creating $sourcebase/Makefile.am"
1301 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1303 echo "Create $sourcebase/Makefile.am"
1308 # Create m4/gnulib-cache.m4.
1309 func_dest_tmpfilename $m4base/gnulib-cache.m4
1311 func_emit_copyright_notice
1313 echo "# This file represents the specification of how gnulib-tool is used."
1314 echo "# It acts as a cache: It is written and read by gnulib-tool."
1315 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1316 echo "# like the configure.ac and various Makefile.am files."
1319 echo "# Specification in the form of a command-line invocation:"
1322 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1323 echo "gl_MODULES(["`echo $specified_modules`"])"
1324 echo "gl_AVOID([$avoidlist])"
1325 echo "gl_SOURCE_BASE([$sourcebase])"
1326 echo "gl_M4_BASE([$m4base])"
1327 echo "gl_TESTS_BASE([$testsbase])"
1328 echo "gl_DOC_BASE([$docbase])"
1329 echo "gl_LIB([$libname])"
1330 test -z "$lgpl" || echo "gl_LGPL"
1331 test -z "$libtool" || echo "gl_LIBTOOL"
1332 echo "gl_MACRO_PREFIX([$macro_prefix])"
1334 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1335 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1339 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1340 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1341 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1343 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1347 echo "# gnulib-cache.m4 ends here"
1354 echo "Creating $m4base/gnulib-cache.m4"
1355 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1357 echo "Create $m4base/gnulib-cache.m4"
1363 # Create m4/gnulib-comp.m4.
1364 func_dest_tmpfilename $m4base/gnulib-comp.m4
1366 func_emit_copyright_notice
1368 echo "# This file represents the compiled summary of the specification in"
1369 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1370 echo "# to be invoked from configure.ac."
1371 echo "# In projects using CVS, this file can be treated like other built files."
1374 echo "# This macro should be invoked from $configure_ac, in the section"
1375 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1376 echo "# any checks for libraries, header files, types and library functions."
1377 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1379 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1380 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1381 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1383 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1384 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1386 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1387 echo " AC_REQUIRE([gl_LOCK])"
1391 echo "# This macro should be invoked from $configure_ac, in the section"
1392 echo "# \"Check for header files, types and library functions\"."
1393 echo "AC_DEFUN([${macro_prefix}_INIT],"
1395 if test -z "$libtool"; then
1396 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1398 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1400 if test "$auxdir" != "build-aux"; then
1401 sed_replace_build_aux='
1403 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1404 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1407 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1409 sed_replace_build_aux=
1411 for module in $modules; do
1413 if test -n "$module"; then
1414 func_get_autoconf_snippet "$module" \
1415 | sed -e '/^$/d;' -e 's/^/ /' \
1416 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1417 -e "$sed_replace_build_aux"
1418 if test "$module" = 'alloca' && test -n "$libtool"; then
1419 echo 'changequote(,)dnl'
1420 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1421 echo 'changequote([, ])dnl'
1422 echo 'AC_SUBST([LTALLOCA])'
1428 echo "# This macro records the list of files which have been installed by"
1429 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1430 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1431 echo "$files" | sed -e 's,^, ,'
1434 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1435 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
1439 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1440 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1441 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1443 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1447 echo "# gnulib-comp.m4 ends here"
1454 echo "Creating $m4base/gnulib-comp.m4"
1455 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1457 echo "Create $m4base/gnulib-comp.m4"
1463 if test -n "$inctests"; then
1464 # Create tests/Makefile.am.
1465 func_dest_tmpfilename $testsbase/Makefile.am
1466 func_emit_tests_Makefile_am > "$tmpfile"
1467 if test -f "$destdir"/$testsbase/Makefile.am; then
1468 if cmp "$destdir"/$testsbase/Makefile.am "$tmpfile" > /dev/null; then
1472 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1473 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1474 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1476 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1482 echo "Creating $testsbase/Makefile.am"
1483 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1485 echo "Create $testsbase/Makefile.am"
1492 # Undo the effect of the previous 'trap' command. Some shellology:
1493 # We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
1494 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
1495 # exit); for the others we need to call 'exit' explicitly. The value of $? is
1496 # 128 + signal number and is set before the trap-registered command is run.
1498 trap 'exit $?' 1 2 3 15
1502 echo "You may need to add #include directives for the following .h files."
1504 # First the #include <...> directives without #ifs, sorted for convenience.
1505 for module in $modules; do
1506 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1509 func_get_include_directive "$module" | grep -v 'include "'
1511 done | LC_ALL=C sort -u
1512 # Then the #include "..." directives without #ifs, sorted for convenience.
1513 for module in $modules; do
1514 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1517 func_get_include_directive "$module" | grep 'include "'
1519 done | LC_ALL=C sort -u
1520 # Then the #include directives that are surrounded by #ifs. Not sorted.
1521 for module in $modules; do
1522 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1523 func_get_include_directive "$module"
1526 ) | sed -e '/^$/d;' -e 's/^/ /'
1528 echo "Don't forget to"
1529 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1530 if test -n "$inctests"; then
1531 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1533 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1534 sourcebase_base=`basename "$sourcebase"`
1535 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1536 if test -n "$inctests"; then
1537 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1538 testsbase_base=`basename "$testsbase"`
1539 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1541 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1542 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1543 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1546 # func_create_testdir testdir modules
1548 # - auxdir directory relative to destdir where to place build aux files
1549 func_create_testdir ()
1553 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1555 # Determine final module list.
1556 func_modules_transitive_closure
1557 echo "Module list with included dependencies:"
1558 echo "$modules" | sed -e 's/^/ /'
1560 # Add the dummy module if needed.
1561 func_modules_add_dummy
1563 # Determine final file list.
1564 func_modules_to_filelist
1566 echo "$files" | sed -e 's/^/ /'
1568 # Create directories.
1569 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1570 if test "$d" = build-aux; then
1571 mkdir -p "$testdir/$auxdir"
1573 mkdir -p "$testdir/$d"
1577 # Copy files or make symbolic links.
1580 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1583 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1584 if test -z "$symbolic"; then
1585 cp -p "$gnulib_dir/$f" "$testdir/$g"
1587 ln -s "$gnulib_dir/$f" "$testdir/$g"
1591 # Create lib/Makefile.am.
1592 mkdir -p "$testdir/lib"
1593 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1595 # Create m4/Makefile.am.
1596 mkdir -p "$testdir/m4"
1597 (echo "## Process this file with automake to produce Makefile.in."
1603 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1606 ) > "$testdir/m4/Makefile.am"
1609 subdirs_with_configure_ac=""
1611 if test -f "$testdir"/m4/gettext.m4; then
1612 # Avoid stupid error message from automake:
1613 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1614 mkdir -p "$testdir/po"
1615 (echo "## Process this file with automake to produce Makefile.in."
1616 ) > "$testdir/po/Makefile.am"
1617 subdirs="$subdirs po"
1620 if test -n "$inctests"; then
1621 test -d "$testdir/tests" || mkdir "$testdir/tests"
1622 # Create tests/Makefile.am.
1626 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1627 # Create tests/configure.ac.
1628 (echo "# Process this file with autoconf to produce a configure script."
1629 echo "AC_INIT([dummy], [0])"
1630 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1631 echo "AM_INIT_AUTOMAKE"
1633 echo "AM_CONFIG_HEADER([config.h])"
1636 echo "AC_PROG_INSTALL"
1637 echo "AC_PROG_MAKE_SET"
1638 echo "AC_PROG_RANLIB"
1640 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1641 echo "AC_GNU_SOURCE"
1644 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1645 echo "gl_USE_SYSTEM_EXTENSIONS"
1648 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1652 if test -z "$libtool"; then
1653 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1655 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1657 if test "$auxdir" != "build-aux"; then
1658 sed_replace_build_aux='
1660 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1661 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1664 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1666 sed_replace_build_aux=
1668 # We don't have explicit ordering constraints between the various
1669 # autoconf snippets. It's cleanest to put those of the library before
1670 # those of the tests.
1671 for module in $modules; do
1672 func_verify_nontests_module
1673 if test -n "$module"; then
1674 func_get_autoconf_snippet "$module" \
1675 | sed -e "$sed_replace_build_aux"
1678 for module in $modules; do
1679 func_verify_tests_module
1680 if test -n "$module"; then
1681 func_get_autoconf_snippet "$module" \
1682 | sed -e "$sed_replace_build_aux"
1686 # Usually tests/config.h will be a superset of config.h. Verify this by
1687 # "merging" config.h into tests/config.h; look out for gcc warnings.
1688 echo "AH_TOP([#include \"../config.h\"])"
1690 echo "AC_OUTPUT([Makefile])"
1691 ) > "$testdir/tests/configure.ac"
1692 subdirs="$subdirs tests"
1693 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1696 # Create Makefile.am.
1697 (echo "## Process this file with automake to produce Makefile.in."
1699 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1701 echo "SUBDIRS = $subdirs"
1703 echo "ACLOCAL_AMFLAGS = -I m4"
1704 ) > "$testdir/Makefile.am"
1706 # Create configure.ac.
1707 (echo "# Process this file with autoconf to produce a configure script."
1708 echo "AC_INIT([dummy], [0])"
1709 if test "$auxdir" != "."; then
1710 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1712 echo "AM_INIT_AUTOMAKE"
1714 echo "AM_CONFIG_HEADER([config.h])"
1717 echo "AC_PROG_INSTALL"
1718 echo "AC_PROG_MAKE_SET"
1719 echo "AC_PROG_RANLIB"
1721 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1722 echo "AC_GNU_SOURCE"
1725 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1726 echo "gl_USE_SYSTEM_EXTENSIONS"
1729 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1733 if test -z "$libtool"; then
1734 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1736 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1738 if test "$auxdir" != "build-aux"; then
1739 sed_replace_build_aux='
1741 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1742 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1745 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1747 sed_replace_build_aux=
1749 for module in $modules; do
1750 func_verify_nontests_module
1751 if test -n "$module"; then
1752 func_get_autoconf_snippet "$module" \
1753 | sed -e "$sed_replace_build_aux"
1757 if test -n "$subdirs_with_configure_ac"; then
1758 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1760 makefiles="Makefile"
1761 for d in $subdirs; do
1762 # For subdirs that have a configure.ac by their own, it's the subdir's
1763 # configure.ac which creates the subdir's Makefile.am, not this one.
1764 case " $subdirs_with_configure_ac " in
1766 *) makefiles="$makefiles $d/Makefile" ;;
1769 echo "AC_OUTPUT([$makefiles])"
1770 ) > "$testdir/configure.ac"
1772 # Create autogenerated files.
1774 echo "executing ${AUTORECONF} --force --install"
1775 ${AUTORECONF} --force --install
1777 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1781 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1789 # func_create_megatestdir megatestdir allmodules
1791 # - auxdir directory relative to destdir where to place build aux files
1792 func_create_megatestdir ()
1796 if test -z "$allmodules"; then
1797 allmodules=`func_all_modules`
1801 # First, all modules one by one.
1802 for onemodule in $allmodules; do
1803 func_create_testdir "$megatestdir/$onemodule" $onemodule
1804 megasubdirs="${megasubdirs}$onemodule "
1806 # Then, all modules all together.
1807 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1808 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1809 func_create_testdir "$megatestdir/ALL" "$allmodules"
1810 megasubdirs="${megasubdirs}ALL"
1812 # Create Makefile.am.
1813 (echo "## Process this file with automake to produce Makefile.in."
1815 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1817 echo "SUBDIRS = $megasubdirs"
1818 ) > "$megatestdir/Makefile.am"
1820 # Create configure.ac.
1821 (echo "# Process this file with autoconf to produce a configure script."
1822 echo "AC_INIT([dummy], [0])"
1823 if test "$auxdir" != "."; then
1824 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1826 echo "AM_INIT_AUTOMAKE"
1828 echo "AC_PROG_MAKE_SET"
1830 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1831 echo "AC_OUTPUT([Makefile])"
1832 ) > "$megatestdir/configure.ac"
1834 # Create autogenerated files.
1836 # Do not use "${AUTORECONF} --install", because autoreconf operates
1837 # recursively, but the subdirectories are already finished, therefore
1838 # calling autoreconf here would only waste lots of CPU time.
1839 echo "executing ${ACLOCAL}"
1841 echo "executing mkdir build-aux"
1843 echo "executing ${AUTOCONF}"
1845 echo "executing ${AUTOMAKE} --add-missing --copy"
1846 ${AUTOMAKE} --add-missing --copy
1852 func_fatal_error "no mode specified" ;;
1861 if test -z "$destdir"; then
1864 test -d "$destdir" \
1865 || func_fatal_error "destination directory does not exist: $destdir"
1867 # Prefer configure.ac to configure.in.
1868 if test -f "$destdir"/configure.ac; then
1869 configure_ac="$destdir/configure.ac"
1871 if test -f "$destdir"/configure.in; then
1872 configure_ac="$destdir/configure.in"
1874 func_fatal_error "cannot find $destdir/configure.ac"
1878 test -f "$destdir"/Makefile.am \
1879 || func_fatal_error "cannot find $destdir/Makefile.am"
1881 # Analyze configure.ac.
1888 /AC_CONFIG_AUX_DIR/ {
1889 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1891 /A[CM]_PROG_LIBTOOL/ {
1892 s,^.*$,guessed_libtool=true,p
1894 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1896 if test -z "$auxdir"; then
1897 auxdir="$guessed_auxdir"
1900 # Determine where to apply func_import.
1901 if test -n "$m4base"; then
1902 # Apply func_import to a particular gnulib directory.
1903 # Any number of additional modules can be given.
1904 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1905 # First use of gnulib in the given m4base.
1906 test -n "$supplied_libname" || supplied_libname=true
1907 test -n "$sourcebase" || sourcebase="lib"
1908 test -n "$testsbase" || testsbase="tests"
1909 test -n "$docbase" || docbase="doc"
1910 test -n "$macro_prefix" || macro_prefix="gl"
1914 # Apply func_import to all gnulib directories.
1915 # To get this list of directories, look at Makefile.am. (Not at
1916 # configure, because it may be omitted from CVS. Also, don't run
1917 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1918 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
1922 for arg in $aclocal_amflags; do
1923 if test -n "$m4dir_is_next"; then
1924 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1928 if test -f "$destdir/$arg"/gnulib-cache.m4; then
1929 m4dirs="$m4dirs $arg"
1930 m4dirs_count=`expr $m4dirs_count + 1`
1935 if test "X$arg" = "X-I"; then
1942 if test $m4dirs_count = 0; then
1943 # First use of gnulib in a package.
1944 # Any number of additional modules can be given.
1945 test -n "$supplied_libname" || supplied_libname=true
1946 test -n "$sourcebase" || sourcebase="lib"
1948 test -n "$testsbase" || testsbase="tests"
1949 test -n "$docbase" || docbase="doc"
1950 test -n "$macro_prefix" || macro_prefix="gl"
1953 if test $m4dirs_count = 1; then
1954 # There's only one use of gnulib here. Assume the user means it.
1955 # Any number of additional modules can be given.
1956 for m4base in $m4dirs; do
1960 # Ambiguous - guess what the user meant.
1961 if test $# = 0; then
1962 # No further arguments. Guess the user wants to update all of them.
1963 for m4base in $m4dirs; do
1968 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
1976 if test -z "$destdir"; then
1977 func_fatal_error "please specify --dir option"
1980 test -d "$destdir" \
1981 || func_fatal_error "could not create destination directory"
1982 test -n "$auxdir" || auxdir="build-aux"
1983 func_create_testdir "$destdir" "$*"
1986 create-megatestdir )
1987 if test -z "$destdir"; then
1988 func_fatal_error "please specify --dir option"
1990 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1991 test -n "$auxdir" || auxdir="build-aux"
1992 func_create_megatestdir "$destdir" "$*"
1996 test -n "$destdir" || destdir=testdir$$
1997 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1998 test -n "$auxdir" || auxdir="build-aux"
1999 func_create_testdir "$destdir" "$*"
2007 remaining=`find . -type f -print`
2008 if test -n "$remaining"; then
2009 echo "Remaining files:" $remaining 1>&2
2010 echo "gnulib-tool: *** Stop." 1>&2
2019 test -n "$destdir" || destdir=testdir$$
2020 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2021 test -n "$auxdir" || auxdir="build-aux"
2022 func_create_megatestdir "$destdir" "$*"
2030 remaining=`find . -type f -print`
2031 if test -n "$remaining"; then
2032 echo "Remaining files:" $remaining 1>&2
2033 echo "gnulib-tool: *** Stop." 1>&2
2041 extract-description )
2045 if test -n "$module"; then
2046 func_get_description "$module"
2055 if test -n "$module"; then
2056 func_get_filelist "$module"
2061 extract-dependencies )
2065 if test -n "$module"; then
2066 func_get_dependencies "$module"
2071 extract-autoconf-snippet )
2075 if test -n "$module"; then
2076 func_get_autoconf_snippet "$module"
2081 extract-automake-snippet )
2085 if test -n "$module"; then
2086 func_get_automake_snippet "$module"
2091 extract-include-directive )
2095 if test -n "$module"; then
2096 func_get_include_directive "$module"
2105 if test -n "$module"; then
2106 func_get_license "$module"
2111 extract-maintainer )
2115 if test -n "$module"; then
2116 func_get_maintainer "$module"
2121 extract-tests-module )
2125 if test -n "$module"; then
2126 func_get_tests_module "$module"
2132 func_fatal_error "unknown operation mode --$mode" ;;