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 15:27:08 $'
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 # - docbase from --doc-base
244 # - testsbase from --tests-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
273 while test $# -gt 0; do
278 --import | --impor | --impo | --imp | --im | --i )
281 --update | --updat | --upda | --upd | --up | --u )
284 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
287 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
288 mode=create-megatestdir
290 --test | --tes | --te | --t )
293 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
297 mode=`echo "X$1" | sed -e 's/^X--//'`
302 func_fatal_error "missing argument for --dir"
307 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
312 func_fatal_error "missing argument for --lib"
315 supplied_libname=true
318 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
319 supplied_libname=true
324 func_fatal_error "missing argument for --source-base"
329 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
334 func_fatal_error "missing argument for --m4-base"
339 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
344 func_fatal_error "missing argument for --doc-base"
349 docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
354 func_fatal_error "missing argument for --tests-base"
359 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
364 func_fatal_error "missing argument for --aux-dir"
369 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
377 func_fatal_error "missing argument for --avoid"
379 avoidlist="$avoidlist $1"
382 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
393 func_fatal_error "missing argument for --macro-prefix"
398 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
400 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
406 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
409 --help | --hel | --he | --h )
412 --version | --versio | --versi | --vers | --ver | --ve | --v )
416 # Stop option processing
420 echo "gnulib-tool: unknown option $1" 1>&2
421 echo "Try 'gnulib-tool --help' for more information." 1>&2
428 if test "$mode" = update; then
429 if test $# != 0; then
430 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
431 echo "Try 'gnulib-tool --help' for more information." 1>&2
432 echo "If you really want to modify the gnulib configuration of your project," 1>&2
433 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
436 if test -n "$supplied_libname" || test -n "$sourcebase" || test -n "$m4base" \
437 || test -n "$testsbase" || test -n "$auxdir" || test -n "$inctests" \
438 || test -n "$docbase" \
439 || test -n "$avoidlist" || test -n "$lgpl" || test -n "$macro_prefix"; then
440 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
441 echo "Try 'gnulib-tool --help' for more information." 1>&2
442 echo "If you really want to modify the gnulib configuration of your project," 1>&2
443 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
449 # Remove trailing slashes from the directory names. This is necessary for
450 # m4base (to avoid an error in func_import) and optional for the others.
451 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
452 case "$sourcebase" in
453 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
456 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
459 */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
462 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
465 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
470 /*) self_abspathname="$0" ;;
471 */*) self_abspathname=`pwd`/"$0" ;;
472 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
473 if test -x "$d/$0" && test ! -d "$d/$0"; then
474 self_abspathname="$d/$0"
478 if test -z "$self_abspathname"; then
479 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
483 while test -h "$self_abspathname"; do
484 # Resolve symbolic link.
485 linkval=`func_readlink "$self_abspathname"`
486 test -n "$linkval" || break
488 /* ) self_abspathname="$linkval" ;;
489 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
492 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
497 # Filter out metainformation files like README, which are not modules.
498 # Filter out unit test modules; they can be retrieved through
499 # --extract-tests-module if desired.
500 (cd "$gnulib_dir/modules" && ls -1) \
501 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
502 | sed -e '/-tests$/d' \
507 # verifies a module name
508 func_verify_module ()
510 if test ! -f "$gnulib_dir/modules/$module" \
511 || test "CVS" = "$module" \
512 || test "ChangeLog" = "$module" \
513 || test "README" = "$module" \
514 || test "TEMPLATE" = "$module" \
515 || test "TEMPLATE-TESTS" = "$module"; then
516 echo "gnulib-tool: module $module doesn't exist" 1>&2
521 # func_verify_nontests_module
522 # verifies a module name, excluding tests modules
523 func_verify_nontests_module ()
527 * ) func_verify_module ;;
531 # func_verify_tests_module
532 # verifies a module name, considering only tests modules
533 func_verify_tests_module ()
536 *-tests ) func_verify_module ;;
541 sed_extract_prog=':[ ]*$/ {
544 s/^Description:[ ]*$//
546 s/^Depends-on:[ ]*$//
547 s/^configure\.ac:[ ]*$//
548 s/^Makefile\.am:[ ]*$//
551 s/^Maintainer:[ ]*$//
558 # func_get_description module
559 func_get_description ()
561 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
564 # func_get_filelist module
567 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
569 #echo m4/onceonly_2_57.m4
572 # func_get_dependencies module
573 func_get_dependencies ()
575 # ${module}-tests always implicitly depends on ${module}.
576 echo "$1" | sed -n -e 's/-tests//p'
577 # Then the explicit dependencies listed in the module description.
578 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
581 # func_get_autoconf_snippet module
582 func_get_autoconf_snippet ()
584 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
587 # func_get_automake_snippet module
588 func_get_automake_snippet ()
590 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
593 # func_get_include_directive module
594 func_get_include_directive ()
596 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
597 sed -e 's/^\(["<]\)/#include \1/'
600 # func_get_license module
603 sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
606 # func_get_maintainer module
607 func_get_maintainer ()
609 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
612 # func_get_tests_module module
613 func_get_tests_module ()
615 # The naming convention for tests modules is hardwired: ${module}-tests.
616 if test -f modules/"$1"-tests; then
621 # func_acceptable module
622 # tests whether a module is acceptable.
624 # - avoidlist list of modules to avoid
627 for avoid in $avoidlist; do
628 if test "$avoid" = "$1"; then
635 # func_modules_transitive_closure
637 # - modules list of specified modules
638 # - inctests true if tests should be included, blank otherwise
639 # - avoidlist list of modules to avoid
641 # - modules list of modules, including dependencies
642 func_modules_transitive_closure ()
646 for module in $modules; do
648 if test -n "$module"; then
649 # Duplicate dependencies are harmless, but Jim wants a warning.
650 duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
651 if test -n "$duplicated_deps"; then
652 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
654 if func_acceptable $module; then
655 xmodules="$xmodules $module"
656 for depmodule in `func_get_dependencies $module`; do
657 if func_acceptable $depmodule; then
658 xmodules="$xmodules $depmodule"
661 if test -n "$inctests"; then
662 testsmodule=`func_get_tests_module $module`
663 if test -n "$testsmodule"; then
664 if func_acceptable $testsmodule; then
665 xmodules="$xmodules $testsmodule"
666 for depmodule in `func_get_dependencies $testsmodule`; do
667 if func_acceptable $depmodule; then
668 xmodules="$xmodules $depmodule"
677 xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
678 if test "$xmodules" = "$modules"; then
685 # func_modules_add_dummy
687 # - modules list of modules, including dependencies
689 # - modules list of modules, including 'dummy' if needed
690 func_modules_add_dummy ()
693 sed_remove_backslash_newline=':a
700 for module in $modules; do
701 func_verify_nontests_module
702 if test -n "$module"; then
703 # Extract the value of "lib_SOURCES += ...".
704 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
705 # Ignore .h files since they are not compiled.
708 *) have_lib_SOURCES=yes ;;
713 # Add the dummy module, to make sure the library will be non-empty.
714 if test -z "$have_lib_SOURCES"; then
715 modules="$modules dummy"
719 # func_modules_to_filelist
721 # - modules list of modules, including dependencies
723 # - files list of files
724 func_modules_to_filelist ()
727 for module in $modules; do
729 if test -n "$module"; then
730 files="$files "`func_get_filelist $module`
733 files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
736 # func_emit_lib_Makefile_am
737 # emits the contents of lib/Makefile.am to standard output.
739 # - modules list of modules, including dependencies
740 # - libname library name
741 # - libtool true if libtool will be used, blank otherwise
742 # - actioncmd (optional) command that will reproduce this invocation
743 func_emit_lib_Makefile_am ()
745 if test -n "$libtool"; then
752 echo "## Process this file with automake to produce Makefile.in."
753 func_emit_copyright_notice
754 if test -n "$actioncmd"; then
755 echo "# Reproduce by: $actioncmd"
758 # No need to generate dependencies since the sources are in gnulib, not here.
759 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
761 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
763 echo "${libname}_${libext}_SOURCES ="
764 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
765 echo "noinst_HEADERS ="
767 echo "BUILT_SOURCES ="
769 echo "MOSTLYCLEANFILES ="
770 echo "MOSTLYCLEANDIRS ="
772 echo "DISTCLEANFILES ="
773 echo "MAINTAINERCLEANFILES ="
777 for module in $modules; do
778 func_verify_nontests_module
779 if test -n "$module"; then
781 func_get_automake_snippet "$module" |
782 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
783 if test "$module" = 'alloca'; then
784 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
787 # Skip the contents if its entirely empty.
788 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
789 echo "## begin gnulib module $module"
792 echo "## end gnulib module $module"
799 echo "mostlyclean-local:"
800 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
801 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
802 echo " if test -d \$\$dir; then \\"
803 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
807 echo "# Makefile.am ends here"
810 # func_emit_tests_Makefile_am
811 # emits the contents of tests/Makefile.am to standard output.
813 # - modules list of modules, including dependencies
814 # - libname library name
815 # - libtool true if libtool will be used, blank otherwise
816 # - sourcebase relative directory containing lib source code
817 # - m4base relative directory containing autoconf macros
818 # - testsbase relative directory containing unit test code
819 func_emit_tests_Makefile_am ()
821 if test -n "$libtool"; then
826 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
827 echo "## Process this file with automake to produce Makefile.in."
828 func_emit_copyright_notice
830 # Generate dependencies here, since it eases the debugging of test failures.
831 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
833 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
835 # Nothing is being added to SUBDIRS; nevertheless the existence of this
836 # variable is needed to avoid an error from automake:
837 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
840 echo "TESTS_ENVIRONMENT ="
841 echo "noinst_PROGRAMS ="
842 echo "check_PROGRAMS ="
843 echo "noinst_HEADERS ="
845 echo "BUILT_SOURCES ="
847 echo "MOSTLYCLEANFILES ="
848 echo "MOSTLYCLEANDIRS ="
850 echo "DISTCLEANFILES ="
851 echo "MAINTAINERCLEANFILES ="
853 echo "AM_CPPFLAGS = \\"
854 echo " -I. -I\$(srcdir) \\"
855 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
856 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
858 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
860 for module in $modules; do
861 func_verify_tests_module
862 if test -n "$module"; then
863 func_get_automake_snippet "$module" > amsnippet.tmp
864 # Skip the contents if its entirely empty.
865 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
866 echo "## begin gnulib module $module"
869 echo "## end gnulib module $module"
875 echo "# Clean up after Solaris cc."
877 echo " rm -rf SunWS_cache"
879 echo "mostlyclean-local:"
880 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
881 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
882 echo " if test -d \$\$dir; then \\"
883 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
887 echo "# Makefile.am ends here"
890 # func_import modules
891 # Uses also the variables
892 # - destdir target directory
893 # - libname library name
894 # - sourcebase directory relative to destdir where to place source code
895 # - m4base directory relative to destdir where to place *.m4 macros
896 # - docbase directory relative to destdir where to place doc files
897 # - testsbase directory relative to destdir where to place unit test code
898 # - auxdir directory relative to destdir where to place build aux files
899 # - inctests true if --with-tests was given, blank otherwise
900 # - avoidlist list of modules to avoid, from --avoid
901 # - lgpl true if library's license shall be LGPL, blank otherwise
902 # - libtool true if libtool will be used, blank otherwise
903 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
904 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
905 # - doit : if actions shall be executed, false if only to be printed
906 # - symbolic true if files should be symlinked, copied otherwise
909 # Get the cached settings.
910 cached_specified_modules=
921 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
927 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
930 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
933 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
936 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
939 s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
942 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
945 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
948 s,^.*$,cached_lgpl=true,p
951 s,^.*$,cached_libtool=true,p
954 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
956 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
957 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
962 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
963 s,^.*$,cached_files=",p
975 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
979 # Merge the cached settings with the specified ones.
980 # The m4base must be the same as expected from the pathname.
981 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
982 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
984 # Append the cached and the specified module names. So that
985 # "gnulib-tool --import foo" means to add the module foo.
986 specified_modules="$cached_specified_modules $1"
987 # Append the cached and the specified avoidlist. This is probably better
988 # than dropping the cached one when --avoid is specified at least once.
989 avoidlist=`echo $cached_avoidlist $avoidlist`
990 # The sourcebase defaults to the cached one.
991 if test -z "$sourcebase"; then
992 sourcebase="$cached_sourcebase"
993 if test -z "$sourcebase"; then
994 func_fatal_error "missing --source-base option"
997 # The docbase defaults to the cached one.
998 if test -z "$docbase"; then
999 docbase="$cached_docbase"
1000 if test -z "$docbase"; then
1001 func_fatal_error "missing --doc-base option"
1004 # The testsbase defaults to the cached one.
1005 if test -z "$testsbase"; then
1006 testsbase="$cached_testsbase"
1007 if test -z "$testsbase"; then
1008 func_fatal_error "missing --tests-base option"
1011 # The libname defaults to the cached one.
1012 if test -z "$supplied_libname"; then
1013 libname="$cached_libname"
1014 if test -z "$libname"; then
1015 func_fatal_error "missing --lib option"
1018 # Require LGPL if specified either way.
1019 if test -z "$lgpl"; then
1022 # Use libtool if specified either way, or if guessed.
1023 if test -z "$libtool"; then
1024 if test -n "$cached_m4base"; then
1025 libtool="$cached_libtool"
1027 libtool="$guessed_libtool"
1030 # The macro_prefix defaults to the cached one.
1031 if test -z "$macro_prefix"; then
1032 macro_prefix="$cached_macro_prefix"
1033 if test -z "$macro_prefix"; then
1034 func_fatal_error "missing --macro-prefix option"
1038 # Canonicalize the list of specified modules.
1039 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1041 # Determine final module list.
1042 modules="$specified_modules"
1043 func_modules_transitive_closure
1044 echo "Module list with included dependencies:"
1045 echo "$modules" | sed -e 's/^/ /'
1047 # Add the dummy module if needed.
1048 func_modules_add_dummy
1050 # If --lgpl, check the license of modules are compatible.
1051 if test -n "$lgpl"; then
1052 for module in $modules; do
1053 license=`func_get_license $module`
1055 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
1056 *) func_fatal_error "incompatible license on module $module: $license" ;;
1061 # Determine final file list.
1062 func_modules_to_filelist
1064 echo "$files" | sed -e 's/^/ /'
1067 || func_fatal_error "refusing to do nothing"
1069 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1070 new_files="$files m4/gnulib-tool.m4"
1071 old_files="$cached_files"
1072 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1073 old_files="$old_files m4/gnulib-tool.m4"
1076 # Create directories.
1077 if test ! -d "$destdir/$sourcebase"; then
1079 echo "Creating directory $destdir/$sourcebase"
1080 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1082 echo "Create directory $destdir/$sourcebase"
1085 if test ! -d "$destdir/$m4base"; then
1087 echo "Creating directory $destdir/$m4base"
1088 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1090 echo "Create directory $destdir/$m4base"
1093 if test ! -d "$destdir/$docbase"; then
1095 echo "Creating directory $destdir/$docbase"
1096 mkdir "$destdir/$docbase" || func_fatal_error "failed"
1098 echo "Create directory $destdir/$docbase"
1101 if test -n "$inctests"; then
1102 if test ! -d "$destdir/$testsbase"; then
1104 echo "Creating directory $destdir/$testsbase"
1105 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1107 echo "Create directory $destdir/$testsbase"
1111 if test ! -d "$destdir/$auxdir"; then
1113 echo "Creating directory $destdir/$auxdir"
1114 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1116 echo "Create directory $destdir/$auxdir"
1121 trap 'rm -rf "$tmp"' 0 1 2 3 15
1122 # func_dest_tmpfilename file
1123 # determines the name of a temporary file (file is relative to destdir).
1125 # - tmpfile absolute filename of the temporary file
1126 func_dest_tmpfilename ()
1129 # Put the new contents of $file in a file in the same directory (needed
1130 # to guarantee that an 'mv' to "$destdir/$file" works).
1131 tmpfile="$destdir/$1.tmp"
1133 # Put the new contents of $file in a file in a temporary directory
1134 # (because the directory of "$file" might not exist).
1135 tmpfile="$tmp"/`basename "$1"`.tmp
1139 # Copy files or make symbolic links. Remove obsolete files.
1141 for f in $old_files; do
1143 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1144 doc/*) g=`echo "$f" | sed -e "s,^doc/,$cached_docbase/,"` ;;
1145 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1146 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1147 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1150 echo "$g""$delimiter""$f"
1151 done | LC_ALL=C sort > "$tmp"/old-files
1152 for f in $new_files; do
1154 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1155 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1156 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1157 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1158 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1161 echo "$g""$delimiter""$f"
1162 done | LC_ALL=C sort > "$tmp"/new-files
1163 # First the files that are in old-files, but not in new-files:
1164 sed_take_first_column='s,'"$delimiter"'.*,,'
1165 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1166 # Remove the file. Do nothing if the user already removed it.
1167 if test -f "$destdir/$g"; then
1169 echo "Removing file $g (backup in ${g}~)"
1170 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1172 echo "Remove file $g (backup in ${g}~)"
1176 # func_add_or_update handles a file that ought to be present afterwards.
1177 # Uses parameters f, g, already_present.
1178 func_add_or_update ()
1180 func_dest_tmpfilename "$g"
1181 cp "$gnulib_dir/$f" "$tmpfile" || func_fatal_error "failed"
1182 if test -n "$lgpl"; then
1186 sed -e 's/GNU General/GNU Lesser General/g' \
1187 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1188 < "$gnulib_dir/$f" > "$tmpfile" || func_fatal_error "failed"
1192 if test -f "$destdir/$g"; then
1193 # The file already exists.
1194 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1195 : # The file has not changed.
1199 if test -n "$already_present"; then
1200 echo "Updating file $g (backup in ${g}~)"
1202 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1204 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1205 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1206 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1208 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1211 if test -n "$already_present"; then
1212 echo "Update file $g (backup in ${g}~)"
1214 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1220 # Don't protest if the file should be there but isn't: it happens
1221 # frequently that developers don't put autogenerated files into CVS.
1223 echo "Copying file $g"
1224 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1225 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1227 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1235 # Then the files that are in new-files, but not in old-files:
1236 sed_take_last_column='s,^.*'"$delimiter"',,'
1238 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1240 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1241 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1242 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1243 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1244 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1249 # Then the files that are in new-files and in old-files:
1250 already_present=true
1251 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1253 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1254 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1255 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1256 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1257 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1263 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1264 actioncmd="gnulib-tool --import"
1265 actioncmd="$actioncmd --dir=$destdir"
1266 actioncmd="$actioncmd --lib=$libname"
1267 actioncmd="$actioncmd --source-base=$sourcebase"
1268 actioncmd="$actioncmd --m4-base=$m4base"
1269 actioncmd="$actioncmd --doc-base=$docbase"
1270 actioncmd="$actioncmd --aux-dir=$auxdir"
1271 for module in $avoidlist; do
1272 actioncmd="$actioncmd --avoid=$module"
1274 if test -n "$lgpl"; then
1275 actioncmd="$actioncmd --lgpl"
1277 if test -n "$libtool"; then
1278 actioncmd="$actioncmd --libtool"
1280 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1281 actioncmd="$actioncmd `echo $specified_modules`"
1283 # Create lib/Makefile.am.
1284 func_dest_tmpfilename $sourcebase/Makefile.am
1285 func_emit_lib_Makefile_am > "$tmpfile"
1286 if test -f "$destdir"/$sourcebase/Makefile.am; then
1287 if cmp "$destdir"/$sourcebase/Makefile.am "$tmpfile" > /dev/null; then
1291 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1292 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1293 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1295 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1301 echo "Creating $sourcebase/Makefile.am"
1302 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1304 echo "Create $sourcebase/Makefile.am"
1309 # Create m4/gnulib-cache.m4.
1310 func_dest_tmpfilename $m4base/gnulib-cache.m4
1312 func_emit_copyright_notice
1314 echo "# This file represents the specification of how gnulib-tool is used."
1315 echo "# It acts as a cache: It is written and read by gnulib-tool."
1316 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1317 echo "# like the configure.ac and various Makefile.am files."
1320 echo "# Specification in the form of a command-line invocation:"
1323 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1324 echo "gl_MODULES(["`echo $specified_modules`"])"
1325 echo "gl_AVOID([$avoidlist])"
1326 echo "gl_SOURCE_BASE([$sourcebase])"
1327 echo "gl_M4_BASE([$m4base])"
1328 echo "gl_DOC_BASE([$docbase])"
1329 echo "gl_TESTS_BASE([$testsbase])"
1330 echo "gl_LIB([$libname])"
1331 test -z "$lgpl" || echo "gl_LGPL"
1332 test -z "$libtool" || echo "gl_LIBTOOL"
1333 echo "gl_MACRO_PREFIX([$macro_prefix])"
1335 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1336 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1340 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1341 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1342 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1344 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1348 echo "# gnulib-cache.m4 ends here"
1355 echo "Creating $m4base/gnulib-cache.m4"
1356 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1358 echo "Create $m4base/gnulib-cache.m4"
1364 # Create m4/gnulib-comp.m4.
1365 func_dest_tmpfilename $m4base/gnulib-comp.m4
1367 func_emit_copyright_notice
1369 echo "# This file represents the compiled summary of the specification in"
1370 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1371 echo "# to be invoked from configure.ac."
1372 echo "# In projects using CVS, this file can be treated like other built files."
1375 echo "# This macro should be invoked from $configure_ac, in the section"
1376 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1377 echo "# any checks for libraries, header files, types and library functions."
1378 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1380 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1381 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1382 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1384 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1385 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1387 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1388 echo " AC_REQUIRE([gl_LOCK])"
1392 echo "# This macro should be invoked from $configure_ac, in the section"
1393 echo "# \"Check for header files, types and library functions\"."
1394 echo "AC_DEFUN([${macro_prefix}_INIT],"
1396 if test -z "$libtool"; then
1397 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1399 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1401 if test "$auxdir" != "build-aux"; then
1402 sed_replace_build_aux='
1404 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1405 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1408 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1410 sed_replace_build_aux=
1412 for module in $modules; do
1414 if test -n "$module"; then
1415 func_get_autoconf_snippet "$module" \
1416 | sed -e '/^$/d;' -e 's/^/ /' \
1417 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1418 -e "$sed_replace_build_aux"
1419 if test "$module" = 'alloca' && test -n "$libtool"; then
1420 echo 'changequote(,)dnl'
1421 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1422 echo 'changequote([, ])dnl'
1423 echo 'AC_SUBST([LTALLOCA])'
1429 echo "# This macro records the list of files which have been installed by"
1430 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1431 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1432 echo "$files" | sed -e 's,^, ,'
1435 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1436 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
1440 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1441 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1442 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1444 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1448 echo "# gnulib-comp.m4 ends here"
1455 echo "Creating $m4base/gnulib-comp.m4"
1456 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1458 echo "Create $m4base/gnulib-comp.m4"
1464 if test -n "$inctests"; then
1465 # Create tests/Makefile.am.
1466 func_dest_tmpfilename $testsbase/Makefile.am
1467 func_emit_tests_Makefile_am > "$tmpfile"
1468 if test -f "$destdir"/$testsbase/Makefile.am; then
1469 if cmp "$destdir"/$testsbase/Makefile.am "$tmpfile" > /dev/null; then
1473 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1474 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1475 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1477 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1483 echo "Creating $testsbase/Makefile.am"
1484 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1486 echo "Create $testsbase/Makefile.am"
1493 # Undo the effect of the previous 'trap' command. Some shellology:
1494 # We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
1495 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
1496 # exit); for the others we need to call 'exit' explicitly. The value of $? is
1497 # 128 + signal number and is set before the trap-registered command is run.
1499 trap 'exit $?' 1 2 3 15
1503 echo "You may need to add #include directives for the following .h files."
1505 # First the #include <...> directives without #ifs, sorted for convenience.
1506 for module in $modules; do
1507 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1510 func_get_include_directive "$module" | grep -v 'include "'
1512 done | LC_ALL=C sort -u
1513 # Then the #include "..." directives without #ifs, sorted for convenience.
1514 for module in $modules; do
1515 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1518 func_get_include_directive "$module" | grep 'include "'
1520 done | LC_ALL=C sort -u
1521 # Then the #include directives that are surrounded by #ifs. Not sorted.
1522 for module in $modules; do
1523 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1524 func_get_include_directive "$module"
1527 ) | sed -e '/^$/d;' -e 's/^/ /'
1529 echo "Don't forget to"
1530 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1531 if test -n "$inctests"; then
1532 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1534 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1535 sourcebase_base=`basename "$sourcebase"`
1536 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1537 if test -n "$inctests"; then
1538 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1539 testsbase_base=`basename "$testsbase"`
1540 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1542 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1543 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1544 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1547 # func_create_testdir testdir modules
1549 # - auxdir directory relative to destdir where to place build aux files
1550 func_create_testdir ()
1554 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1556 # Determine final module list.
1557 func_modules_transitive_closure
1558 echo "Module list with included dependencies:"
1559 echo "$modules" | sed -e 's/^/ /'
1561 # Add the dummy module if needed.
1562 func_modules_add_dummy
1564 # Determine final file list.
1565 func_modules_to_filelist
1567 echo "$files" | sed -e 's/^/ /'
1569 # Create directories.
1570 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1571 if test "$d" = build-aux; then
1572 mkdir -p "$testdir/$auxdir"
1574 mkdir -p "$testdir/$d"
1578 # Copy files or make symbolic links.
1581 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1584 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1585 if test -z "$symbolic"; then
1586 cp -p "$gnulib_dir/$f" "$testdir/$g"
1588 ln -s "$gnulib_dir/$f" "$testdir/$g"
1592 # Create lib/Makefile.am.
1593 mkdir -p "$testdir/lib"
1594 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1596 # Create m4/Makefile.am.
1597 mkdir -p "$testdir/m4"
1598 (echo "## Process this file with automake to produce Makefile.in."
1604 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1607 ) > "$testdir/m4/Makefile.am"
1610 subdirs_with_configure_ac=""
1612 if test -f "$testdir"/m4/gettext.m4; then
1613 # Avoid stupid error message from automake:
1614 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1615 mkdir -p "$testdir/po"
1616 (echo "## Process this file with automake to produce Makefile.in."
1617 ) > "$testdir/po/Makefile.am"
1618 subdirs="$subdirs po"
1621 if test -n "$inctests"; then
1622 test -d "$testdir/tests" || mkdir "$testdir/tests"
1623 # Create tests/Makefile.am.
1627 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1628 # Create tests/configure.ac.
1629 (echo "# Process this file with autoconf to produce a configure script."
1630 echo "AC_INIT([dummy], [0])"
1631 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1632 echo "AM_INIT_AUTOMAKE"
1634 echo "AM_CONFIG_HEADER([config.h])"
1637 echo "AC_PROG_INSTALL"
1638 echo "AC_PROG_MAKE_SET"
1639 echo "AC_PROG_RANLIB"
1641 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1642 echo "AC_GNU_SOURCE"
1645 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1646 echo "gl_USE_SYSTEM_EXTENSIONS"
1649 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1653 if test -z "$libtool"; then
1654 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1656 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1658 if test "$auxdir" != "build-aux"; then
1659 sed_replace_build_aux='
1661 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1662 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1665 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1667 sed_replace_build_aux=
1669 # We don't have explicit ordering constraints between the various
1670 # autoconf snippets. It's cleanest to put those of the library before
1671 # those of the tests.
1672 for module in $modules; do
1673 func_verify_nontests_module
1674 if test -n "$module"; then
1675 func_get_autoconf_snippet "$module" \
1676 | sed -e "$sed_replace_build_aux"
1679 for module in $modules; do
1680 func_verify_tests_module
1681 if test -n "$module"; then
1682 func_get_autoconf_snippet "$module" \
1683 | sed -e "$sed_replace_build_aux"
1687 # Usually tests/config.h will be a superset of config.h. Verify this by
1688 # "merging" config.h into tests/config.h; look out for gcc warnings.
1689 echo "AH_TOP([#include \"../config.h\"])"
1691 echo "AC_OUTPUT([Makefile])"
1692 ) > "$testdir/tests/configure.ac"
1693 subdirs="$subdirs tests"
1694 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1697 # Create Makefile.am.
1698 (echo "## Process this file with automake to produce Makefile.in."
1700 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1702 echo "SUBDIRS = $subdirs"
1704 echo "ACLOCAL_AMFLAGS = -I m4"
1705 ) > "$testdir/Makefile.am"
1707 # Create configure.ac.
1708 (echo "# Process this file with autoconf to produce a configure script."
1709 echo "AC_INIT([dummy], [0])"
1710 if test "$auxdir" != "."; then
1711 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1713 echo "AM_INIT_AUTOMAKE"
1715 echo "AM_CONFIG_HEADER([config.h])"
1718 echo "AC_PROG_INSTALL"
1719 echo "AC_PROG_MAKE_SET"
1720 echo "AC_PROG_RANLIB"
1722 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1723 echo "AC_GNU_SOURCE"
1726 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1727 echo "gl_USE_SYSTEM_EXTENSIONS"
1730 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1734 if test -z "$libtool"; then
1735 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1737 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1739 if test "$auxdir" != "build-aux"; then
1740 sed_replace_build_aux='
1742 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1743 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1746 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1748 sed_replace_build_aux=
1750 for module in $modules; do
1751 func_verify_nontests_module
1752 if test -n "$module"; then
1753 func_get_autoconf_snippet "$module" \
1754 | sed -e "$sed_replace_build_aux"
1758 if test -n "$subdirs_with_configure_ac"; then
1759 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1761 makefiles="Makefile"
1762 for d in $subdirs; do
1763 # For subdirs that have a configure.ac by their own, it's the subdir's
1764 # configure.ac which creates the subdir's Makefile.am, not this one.
1765 case " $subdirs_with_configure_ac " in
1767 *) makefiles="$makefiles $d/Makefile" ;;
1770 echo "AC_OUTPUT([$makefiles])"
1771 ) > "$testdir/configure.ac"
1773 # Create autogenerated files.
1775 echo "executing ${AUTORECONF} --force --install"
1776 ${AUTORECONF} --force --install
1778 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1782 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1790 # func_create_megatestdir megatestdir allmodules
1792 # - auxdir directory relative to destdir where to place build aux files
1793 func_create_megatestdir ()
1797 if test -z "$allmodules"; then
1798 allmodules=`func_all_modules`
1802 # First, all modules one by one.
1803 for onemodule in $allmodules; do
1804 func_create_testdir "$megatestdir/$onemodule" $onemodule
1805 megasubdirs="${megasubdirs}$onemodule "
1807 # Then, all modules all together.
1808 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1809 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1810 func_create_testdir "$megatestdir/ALL" "$allmodules"
1811 megasubdirs="${megasubdirs}ALL"
1813 # Create Makefile.am.
1814 (echo "## Process this file with automake to produce Makefile.in."
1816 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1818 echo "SUBDIRS = $megasubdirs"
1819 ) > "$megatestdir/Makefile.am"
1821 # Create configure.ac.
1822 (echo "# Process this file with autoconf to produce a configure script."
1823 echo "AC_INIT([dummy], [0])"
1824 if test "$auxdir" != "."; then
1825 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1827 echo "AM_INIT_AUTOMAKE"
1829 echo "AC_PROG_MAKE_SET"
1831 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1832 echo "AC_OUTPUT([Makefile])"
1833 ) > "$megatestdir/configure.ac"
1835 # Create autogenerated files.
1837 # Do not use "${AUTORECONF} --install", because autoreconf operates
1838 # recursively, but the subdirectories are already finished, therefore
1839 # calling autoreconf here would only waste lots of CPU time.
1840 echo "executing ${ACLOCAL}"
1842 echo "executing mkdir build-aux"
1844 echo "executing ${AUTOCONF}"
1846 echo "executing ${AUTOMAKE} --add-missing --copy"
1847 ${AUTOMAKE} --add-missing --copy
1853 func_fatal_error "no mode specified" ;;
1862 if test -z "$destdir"; then
1865 test -d "$destdir" \
1866 || func_fatal_error "destination directory does not exist: $destdir"
1868 # Prefer configure.ac to configure.in.
1869 if test -f "$destdir"/configure.ac; then
1870 configure_ac="$destdir/configure.ac"
1872 if test -f "$destdir"/configure.in; then
1873 configure_ac="$destdir/configure.in"
1875 func_fatal_error "cannot find $destdir/configure.ac"
1879 test -f "$destdir"/Makefile.am \
1880 || func_fatal_error "cannot find $destdir/Makefile.am"
1882 # Analyze configure.ac.
1889 /AC_CONFIG_AUX_DIR/ {
1890 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1892 /A[CM]_PROG_LIBTOOL/ {
1893 s,^.*$,guessed_libtool=true,p
1895 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1897 if test -z "$auxdir"; then
1898 auxdir="$guessed_auxdir"
1901 # Determine where to apply func_import.
1902 if test -n "$m4base"; then
1903 # Apply func_import to a particular gnulib directory.
1904 # Any number of additional modules can be given.
1905 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1906 # First use of gnulib in the given m4base.
1907 test -n "$supplied_libname" || supplied_libname=true
1908 test -n "$sourcebase" || sourcebase="lib"
1909 test -n "$docbase" || docbase="doc"
1910 test -n "$testsbase" || testsbase="tests"
1911 test -n "$macro_prefix" || macro_prefix="gl"
1915 # Apply func_import to all gnulib directories.
1916 # To get this list of directories, look at Makefile.am. (Not at
1917 # configure, because it may be omitted from CVS. Also, don't run
1918 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1919 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
1923 for arg in $aclocal_amflags; do
1924 if test -n "$m4dir_is_next"; then
1925 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1929 if test -f "$destdir/$arg"/gnulib-cache.m4; then
1930 m4dirs="$m4dirs $arg"
1931 m4dirs_count=`expr $m4dirs_count + 1`
1936 if test "X$arg" = "X-I"; then
1943 if test $m4dirs_count = 0; then
1944 # First use of gnulib in a package.
1945 # Any number of additional modules can be given.
1946 test -n "$supplied_libname" || supplied_libname=true
1947 test -n "$sourcebase" || sourcebase="lib"
1949 test -n "$docbase" || docbase="doc"
1950 test -n "$testsbase" || testsbase="tests"
1951 test -n "$macro_prefix" || macro_prefix="gl"
1954 if test $m4dirs_count = 1; then
1955 # There's only one use of gnulib here. Assume the user means it.
1956 # Any number of additional modules can be given.
1957 for m4base in $m4dirs; do
1961 # Ambiguous - guess what the user meant.
1962 if test $# = 0; then
1963 # No further arguments. Guess the user wants to update all of them.
1964 for m4base in $m4dirs; do
1969 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
1977 if test -z "$destdir"; then
1978 func_fatal_error "please specify --dir option"
1981 test -d "$destdir" \
1982 || func_fatal_error "could not create destination directory"
1983 test -n "$auxdir" || auxdir="build-aux"
1984 func_create_testdir "$destdir" "$*"
1987 create-megatestdir )
1988 if test -z "$destdir"; then
1989 func_fatal_error "please specify --dir option"
1991 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1992 test -n "$auxdir" || auxdir="build-aux"
1993 func_create_megatestdir "$destdir" "$*"
1997 test -n "$destdir" || destdir=testdir$$
1998 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1999 test -n "$auxdir" || auxdir="build-aux"
2000 func_create_testdir "$destdir" "$*"
2008 remaining=`find . -type f -print`
2009 if test -n "$remaining"; then
2010 echo "Remaining files:" $remaining 1>&2
2011 echo "gnulib-tool: *** Stop." 1>&2
2020 test -n "$destdir" || destdir=testdir$$
2021 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2022 test -n "$auxdir" || auxdir="build-aux"
2023 func_create_megatestdir "$destdir" "$*"
2031 remaining=`find . -type f -print`
2032 if test -n "$remaining"; then
2033 echo "Remaining files:" $remaining 1>&2
2034 echo "gnulib-tool: *** Stop." 1>&2
2042 extract-description )
2046 if test -n "$module"; then
2047 func_get_description "$module"
2056 if test -n "$module"; then
2057 func_get_filelist "$module"
2062 extract-dependencies )
2066 if test -n "$module"; then
2067 func_get_dependencies "$module"
2072 extract-autoconf-snippet )
2076 if test -n "$module"; then
2077 func_get_autoconf_snippet "$module"
2082 extract-automake-snippet )
2086 if test -n "$module"; then
2087 func_get_automake_snippet "$module"
2092 extract-include-directive )
2096 if test -n "$module"; then
2097 func_get_include_directive "$module"
2106 if test -n "$module"; then
2107 func_get_license "$module"
2112 extract-maintainer )
2116 if test -n "$module"; then
2117 func_get_maintainer "$module"
2122 extract-tests-module )
2126 if test -n "$module"; then
2127 func_get_tests_module "$module"
2133 func_fatal_error "unknown operation mode --$mode" ;;