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-29 13:18:04 $'
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"
56 # GNU sort is needed. Set SORT to its location (not needed if it's called
57 # 'sort' and already in the PATH).
58 if test -z "$SORT"; then
63 # outputs to stdout the --help usage message.
67 Usage: gnulib-tool --list
68 gnulib-tool --import [module1 ... moduleN]
70 gnulib-tool --create-testdir --dir=directory module1 ... moduleN
71 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
72 gnulib-tool --test --dir=directory module1 ... moduleN
73 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
74 gnulib-tool --extract-description module
75 gnulib-tool --extract-filelist module
76 gnulib-tool --extract-dependencies module
77 gnulib-tool --extract-autoconf-snippet module
78 gnulib-tool --extract-automake-snippet module
79 gnulib-tool --extract-include-directive module
80 gnulib-tool --extract-license module
81 gnulib-tool --extract-maintainer module
82 gnulib-tool --extract-tests-module module
85 --list print the available module names
86 --import import the given modules into the current package;
87 if no modules are specified, update the current
88 package from the current gnulib
89 --update update the current package, restore files omitted
91 --create-testdir create a scratch package with the given modules
92 --create-megatestdir create a mega scratch package with the given modules
93 one by one and all together
94 --test test the combination of the given modules
95 (recommended to use CC=\"gcc -Wall\" here)
96 --megatest test the given modules one by one and all together
97 (recommended to use CC=\"gcc -Wall\" here)
98 --extract-description extract the description
99 --extract-filelist extract the list of files
100 --extract-dependencies extract the dependencies
101 --extract-autoconf-snippet extract the snippet for configure.ac
102 --extract-automake-snippet extract the snippet for lib/Makefile.am
103 --extract-include-directive extract the #include directive
104 --extract-license report the license terms of the source files
106 --extract-maintainer report the maintainer(s) inside gnulib
107 --extract-tests-module report the unit test module, if it exists
110 --dir=DIRECTORY Specify the target directory.
111 For --import, this specifies where your
112 configure.ac can be found. Defaults to current
115 Options for --import:
116 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
117 --source-base=DIRECTORY
118 Directory relative to --dir where source code is
119 placed (default \"lib\").
120 --m4-base=DIRECTORY Directory relative to --dir where *.m4 macros are
121 placed (default \"m4\").
122 --doc-base=DIRECTORY Directory relative to --dir where doc files are
123 placed (default \"doc\").
124 --tests-base=DIRECTORY
125 Directory relative to --dir where unit tests are
126 placed (default \"tests\").
127 --aux-dir=DIRECTORY Directory relative to --dir where auxiliary build
128 tools are placed (default \"build-aux\").
129 --with-tests Include unit tests for the included modules.
130 --avoid=MODULE Avoid including the given MODULE. Useful if you
131 have code that provides equivalent functionality.
132 This option can be repeated.
133 --lgpl Abort if modules aren't available under the LGPL.
134 Also modify license template from GPL to LGPL.
135 --libtool Use libtool rules.
136 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
137 'gl_INIT'. Default is 'gl'.
138 --no-changelog don't update or create ChangeLog files
140 Options for --import and --update:
141 --dry-run For --import, only print what would have been done.
142 -s, --symbolic, --symlink Make symbolic links instead of copying files.
144 Report bugs to <bug-gnulib@gnu.org>."
148 # outputs to stdout the --version message.
151 year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
152 echo "$progname (GNU $package) $version"
153 echo "Copyright (C) $year Free Software Foundation, Inc.
154 This is free software; see the source for copying conditions. There is NO
155 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
156 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
159 # func_emit_copyright_notice
160 # outputs to stdout a header for a generated file.
161 func_emit_copyright_notice ()
163 echo "# Copyright (C) 2004-2006 Free Software Foundation, Inc."
165 echo "# This file is free software, distributed under the terms of the GNU"
166 echo "# General Public License. As a special exception to the GNU General"
167 echo "# Public License, this file may be distributed as part of a program"
168 echo "# that contains a configuration script generated by Autoconf, under"
169 echo "# the same distribution terms as the rest of that program."
171 echo "# Generated by gnulib-tool."
175 # creates a temporary directory.
177 # - tmp pathname of freshly created temporary directory
180 # Use the environment variable TMPDIR, falling back to /tmp. This allows
181 # users to specify a different temporary directory, for example, if their
182 # /tmp is filled up or too small.
185 # Use the mktemp program if available. If not available, hide the error
187 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
188 test -n "$tmp" && test -d "$tmp"
191 # Use a simple mkdir command. It is guaranteed to fail if the directory
192 # already exists. $RANDOM is bash specific and expands to empty in shells
193 # other than bash, ksh and zsh. Its use does not increase security;
194 # rather, it minimizes the probability of failure in a very cluttered /tmp
196 tmp=$TMPDIR/gl$$-$RANDOM
197 (umask 077 && mkdir "$tmp")
200 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
201 { (exit 1); exit 1; }
205 # func_fatal_error message
206 # outputs to stderr a fatal error message, and terminates the program.
209 echo "gnulib-tool: *** $1" 1>&2
210 echo "gnulib-tool: *** Stop." 1>&2
214 # func_readlink SYMLINK
215 # outputs the target of the given symlink.
216 if (type -p readlink) > /dev/null 2>&1; then
219 # Use the readlink program from GNU coreutils.
225 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
226 # would do the wrong thing if the link target contains " -> ".
227 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
231 # func_ln_if_changed SRC DEST
232 # Like ln -s, but avoids munging timestamps if the link is correct.
233 func_ln_if_changed ()
235 if test $# -ne 2; then
236 echo "usage: func_ln_if_changed SRC DEST" >&2
238 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
246 # Command-line option processing.
247 # Removes the OPTIONS from the arguments. Sets the variables:
248 # - mode list or import or create-testdir or create-megatestdir
249 # - destdir from --dir
250 # - libname, supplied_libname from --lib
251 # - sourcebase from --source-base
252 # - m4base from --m4-base
253 # - docbase from --doc-base
254 # - testsbase from --tests-base
255 # - auxdir from --aux-dir
256 # - inctests true if --with-tests was given, blank otherwise
257 # - avoidlist list of modules to avoid, from --avoid
258 # - lgpl true if --lgpl was given, blank otherwise
259 # - libtool true if --libtool was given, blank otherwise
260 # - macro_prefix from --macro-prefix
261 # - autoconf_minversion minimum supported autoconf version
262 # - do_changelog false if --no-changelog was given, : otherwise
263 # - doit : if actions shall be executed, false if only to be printed
286 while test $# -gt 0; do
291 --import | --impor | --impo | --imp | --im | --i )
294 --update | --updat | --upda | --upd | --up | --u )
297 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
300 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
301 mode=create-megatestdir
303 --test | --tes | --te | --t )
306 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
310 mode=`echo "X$1" | sed -e 's/^X--//'`
315 func_fatal_error "missing argument for --dir"
320 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
325 func_fatal_error "missing argument for --lib"
328 supplied_libname=true
331 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
332 supplied_libname=true
337 func_fatal_error "missing argument for --source-base"
342 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
347 func_fatal_error "missing argument for --m4-base"
352 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
357 func_fatal_error "missing argument for --doc-base"
362 docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
367 func_fatal_error "missing argument for --tests-base"
372 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
377 func_fatal_error "missing argument for --aux-dir"
382 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
390 func_fatal_error "missing argument for --avoid"
392 avoidlist="$avoidlist $1"
395 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
406 func_fatal_error "missing argument for --macro-prefix"
411 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
413 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
419 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
422 --help | --hel | --he | --h )
425 --version | --versio | --versi | --vers | --ver | --ve | --v )
429 # Stop option processing
433 echo "gnulib-tool: unknown option $1" 1>&2
434 echo "Try 'gnulib-tool --help' for more information." 1>&2
441 if test "$mode" = update; then
442 if test $# != 0; then
443 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
444 echo "Try 'gnulib-tool --help' for more information." 1>&2
445 echo "If you really want to modify the gnulib configuration of your project," 1>&2
446 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
449 if test -n "$supplied_libname" || test -n "$sourcebase" || test -n "$m4base" \
450 || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
451 || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
452 || test -n "$macro_prefix"; then
453 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
454 echo "Try 'gnulib-tool --help' for more information." 1>&2
455 echo "If you really want to modify the gnulib configuration of your project," 1>&2
456 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
462 # Determine the minimum supported autoconf version from the project's
464 DEFAULT_AUTOCONF_MINVERSION="2.59"
465 if test -f configure.ac; then
466 autoconf_minversion=`$AUTOCONF --trace=AC_PREREQ:'$1' | $SORT -g | uniq | tail -1`
468 if test -z "$autoconf_minversion"; then
469 autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
471 case "$autoconf_minversion" in
472 1.* | 2.[0-4]* | 2.5[0-8]*)
473 func_fatal_error "minimum supported autoconf version is 2.59. Try adding AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
476 # Remove trailing slashes from the directory names. This is necessary for
477 # m4base (to avoid an error in func_import) and optional for the others.
478 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
479 case "$sourcebase" in
480 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
483 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
486 */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
489 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
492 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
497 /*) self_abspathname="$0" ;;
498 */*) self_abspathname=`pwd`/"$0" ;;
499 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
500 if test -x "$d/$0" && test ! -d "$d/$0"; then
501 self_abspathname="$d/$0"
505 if test -z "$self_abspathname"; then
506 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
510 while test -h "$self_abspathname"; do
511 # Resolve symbolic link.
512 linkval=`func_readlink "$self_abspathname"`
513 test -n "$linkval" || break
515 /* ) self_abspathname="$linkval" ;;
516 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
519 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
524 # Filter out metainformation files like README, which are not modules.
525 # Filter out unit test modules; they can be retrieved through
526 # --extract-tests-module if desired.
527 (cd "$gnulib_dir/modules" && ls -1) \
528 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
529 | sed -e '/-tests$/d' \
534 # verifies a module name
535 func_verify_module ()
537 if test ! -f "$gnulib_dir/modules/$module" \
538 || test "CVS" = "$module" \
539 || test "ChangeLog" = "$module" \
540 || test "README" = "$module" \
541 || test "TEMPLATE" = "$module" \
542 || test "TEMPLATE-TESTS" = "$module"; then
543 echo "gnulib-tool: module $module doesn't exist" 1>&2
548 # func_verify_nontests_module
549 # verifies a module name, excluding tests modules
550 func_verify_nontests_module ()
554 * ) func_verify_module ;;
558 # func_verify_tests_module
559 # verifies a module name, considering only tests modules
560 func_verify_tests_module ()
563 *-tests ) func_verify_module ;;
568 sed_extract_prog=':[ ]*$/ {
571 s/^Description:[ ]*$//
573 s/^Depends-on:[ ]*$//
574 s/^configure\.ac:[ ]*$//
575 s/^Makefile\.am:[ ]*$//
578 s/^Maintainer:[ ]*$//
585 # func_get_description module
586 func_get_description ()
588 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
591 # func_get_filelist module
594 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
595 case "$autoconf_minversion" in
598 echo m4/onceonly_2_57.m4
603 # func_get_dependencies module
604 func_get_dependencies ()
606 # ${module}-tests always implicitly depends on ${module}.
607 echo "$1" | sed -n -e 's/-tests//p'
608 # Then the explicit dependencies listed in the module description.
609 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
612 # func_get_autoconf_snippet module
613 func_get_autoconf_snippet ()
615 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
618 # func_get_automake_snippet module
619 func_get_automake_snippet ()
621 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
624 # func_get_include_directive module
625 func_get_include_directive ()
627 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
628 sed -e 's/^\(["<]\)/#include \1/'
631 # func_get_license module
634 sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
637 # func_get_maintainer module
638 func_get_maintainer ()
640 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
643 # func_get_tests_module module
644 func_get_tests_module ()
646 # The naming convention for tests modules is hardwired: ${module}-tests.
647 if test -f modules/"$1"-tests; then
652 # func_acceptable module
653 # tests whether a module is acceptable.
655 # - avoidlist list of modules to avoid
658 for avoid in $avoidlist; do
659 if test "$avoid" = "$1"; then
666 # func_modules_transitive_closure
668 # - modules list of specified modules
669 # - inctests true if tests should be included, blank otherwise
670 # - avoidlist list of modules to avoid
672 # - modules list of modules, including dependencies
673 func_modules_transitive_closure ()
677 for module in $modules; do
679 if test -n "$module"; then
680 # Duplicate dependencies are harmless, but Jim wants a warning.
681 duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
682 if test -n "$duplicated_deps"; then
683 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
685 if func_acceptable $module; then
686 xmodules="$xmodules $module"
687 for depmodule in `func_get_dependencies $module`; do
688 if func_acceptable $depmodule; then
689 xmodules="$xmodules $depmodule"
692 if test -n "$inctests"; then
693 testsmodule=`func_get_tests_module $module`
694 if test -n "$testsmodule"; then
695 if func_acceptable $testsmodule; then
696 xmodules="$xmodules $testsmodule"
697 for depmodule in `func_get_dependencies $testsmodule`; do
698 if func_acceptable $depmodule; then
699 xmodules="$xmodules $depmodule"
708 xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
709 if test "$xmodules" = "$modules"; then
716 # func_modules_add_dummy
718 # - modules list of modules, including dependencies
720 # - modules list of modules, including 'dummy' if needed
721 func_modules_add_dummy ()
724 sed_remove_backslash_newline=':a
731 for module in $modules; do
732 func_verify_nontests_module
733 if test -n "$module"; then
734 # Extract the value of "lib_SOURCES += ...".
735 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
736 # Ignore .h files since they are not compiled.
739 *) have_lib_SOURCES=yes ;;
744 # Add the dummy module, to make sure the library will be non-empty.
745 if test -z "$have_lib_SOURCES"; then
746 modules="$modules dummy"
750 # func_modules_to_filelist
752 # - modules list of modules, including dependencies
754 # - files list of files
755 func_modules_to_filelist ()
758 for module in $modules; do
760 if test -n "$module"; then
761 files="$files "`func_get_filelist $module`
764 files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
767 # func_emit_lib_Makefile_am
768 # emits the contents of lib/Makefile.am to standard output.
770 # - modules list of modules, including dependencies
771 # - libname library name
772 # - libtool true if libtool will be used, blank otherwise
773 # - actioncmd (optional) command that will reproduce this invocation
774 func_emit_lib_Makefile_am ()
776 if test -n "$libtool"; then
783 echo "## Process this file with automake to produce Makefile.in."
784 func_emit_copyright_notice
785 if test -n "$actioncmd"; then
786 echo "# Reproduce by: $actioncmd"
789 # No need to generate dependencies since the sources are in gnulib, not here.
790 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
792 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
794 echo "${libname}_${libext}_SOURCES ="
795 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
796 echo "noinst_HEADERS ="
798 echo "BUILT_SOURCES ="
800 echo "MOSTLYCLEANFILES ="
801 echo "MOSTLYCLEANDIRS ="
803 echo "DISTCLEANFILES ="
804 echo "MAINTAINERCLEANFILES ="
808 for module in $modules; do
809 func_verify_nontests_module
810 if test -n "$module"; then
812 func_get_automake_snippet "$module" |
813 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
814 if test "$module" = 'alloca'; then
815 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
818 # Skip the contents if its entirely empty.
819 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
820 echo "## begin gnulib module $module"
823 echo "## end gnulib module $module"
830 echo "mostlyclean-local:"
831 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
832 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
833 echo " if test -d \$\$dir; then \\"
834 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
838 echo "# Makefile.am ends here"
841 # func_emit_tests_Makefile_am
842 # emits the contents of tests/Makefile.am to standard output.
844 # - modules list of modules, including dependencies
845 # - libname library name
846 # - libtool true if libtool will be used, blank otherwise
847 # - sourcebase relative directory containing lib source code
848 # - m4base relative directory containing autoconf macros
849 # - testsbase relative directory containing unit test code
850 func_emit_tests_Makefile_am ()
852 if test -n "$libtool"; then
857 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
858 echo "## Process this file with automake to produce Makefile.in."
859 func_emit_copyright_notice
861 # Generate dependencies here, since it eases the debugging of test failures.
862 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
864 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
866 # Nothing is being added to SUBDIRS; nevertheless the existence of this
867 # variable is needed to avoid an error from automake:
868 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
871 echo "TESTS_ENVIRONMENT ="
872 echo "noinst_PROGRAMS ="
873 echo "check_PROGRAMS ="
874 echo "noinst_HEADERS ="
876 echo "BUILT_SOURCES ="
878 echo "MOSTLYCLEANFILES ="
879 echo "MOSTLYCLEANDIRS ="
881 echo "DISTCLEANFILES ="
882 echo "MAINTAINERCLEANFILES ="
884 echo "AM_CPPFLAGS = \\"
885 echo " -I. -I\$(srcdir) \\"
886 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
887 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
889 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
891 for module in $modules; do
892 func_verify_tests_module
893 if test -n "$module"; then
894 func_get_automake_snippet "$module" > amsnippet.tmp
895 # Skip the contents if its entirely empty.
896 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
897 echo "## begin gnulib module $module"
900 echo "## end gnulib module $module"
906 echo "# Clean up after Solaris cc."
908 echo " rm -rf SunWS_cache"
910 echo "mostlyclean-local:"
911 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
912 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
913 echo " if test -d \$\$dir; then \\"
914 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
918 echo "# Makefile.am ends here"
921 # func_import modules
922 # Uses also the variables
923 # - destdir target directory
924 # - libname library name
925 # - sourcebase directory relative to destdir where to place source code
926 # - m4base directory relative to destdir where to place *.m4 macros
927 # - docbase directory relative to destdir where to place doc files
928 # - testsbase directory relative to destdir where to place unit test code
929 # - auxdir directory relative to destdir where to place build aux files
930 # - inctests true if --with-tests was given, blank otherwise
931 # - avoidlist list of modules to avoid, from --avoid
932 # - lgpl true if library's license shall be LGPL, blank otherwise
933 # - libtool true if libtool will be used, blank otherwise
934 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
935 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
936 # - autoconf_minversion minimum supported autoconf version
937 # - doit : if actions shall be executed, false if only to be printed
938 # - symbolic true if files should be symlinked, copied otherwise
941 # Get the cached settings.
942 cached_specified_modules=
953 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
959 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
962 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
965 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
968 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
971 s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
974 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
977 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
980 s,^.*$,cached_lgpl=true,p
983 s,^.*$,cached_libtool=true,p
986 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
988 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
989 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
994 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
995 s,^.*$,cached_files=",p
1007 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
1011 # Merge the cached settings with the specified ones.
1012 # The m4base must be the same as expected from the pathname.
1013 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
1014 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
1016 # Append the cached and the specified module names. So that
1017 # "gnulib-tool --import foo" means to add the module foo.
1018 specified_modules="$cached_specified_modules $1"
1019 # Append the cached and the specified avoidlist. This is probably better
1020 # than dropping the cached one when --avoid is specified at least once.
1021 avoidlist=`echo $cached_avoidlist $avoidlist`
1022 # The sourcebase defaults to the cached one.
1023 if test -z "$sourcebase"; then
1024 sourcebase="$cached_sourcebase"
1025 if test -z "$sourcebase"; then
1026 func_fatal_error "missing --source-base option"
1029 # The docbase defaults to the cached one.
1030 if test -z "$docbase"; then
1031 docbase="$cached_docbase"
1032 if test -z "$docbase"; then
1033 func_fatal_error "missing --doc-base option. --doc-base has been introduced on 2006-07-11; if your last invocation of 'gnulib-tool --update' is before that date, you need to run 'gnulib-tool --update' once, with a --doc-base option."
1036 # The testsbase defaults to the cached one.
1037 if test -z "$testsbase"; then
1038 testsbase="$cached_testsbase"
1039 if test -z "$testsbase"; then
1040 func_fatal_error "missing --tests-base option"
1043 # The libname defaults to the cached one.
1044 if test -z "$supplied_libname"; then
1045 libname="$cached_libname"
1046 if test -z "$libname"; then
1047 func_fatal_error "missing --lib option"
1050 # Require LGPL if specified either way.
1051 if test -z "$lgpl"; then
1054 # Use libtool if specified either way, or if guessed.
1055 if test -z "$libtool"; then
1056 if test -n "$cached_m4base"; then
1057 libtool="$cached_libtool"
1059 libtool="$guessed_libtool"
1062 # The macro_prefix defaults to the cached one.
1063 if test -z "$macro_prefix"; then
1064 macro_prefix="$cached_macro_prefix"
1065 if test -z "$macro_prefix"; then
1066 func_fatal_error "missing --macro-prefix option"
1070 # Canonicalize the list of specified modules.
1071 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1073 # Determine final module list.
1074 modules="$specified_modules"
1075 func_modules_transitive_closure
1076 echo "Module list with included dependencies:"
1077 echo "$modules" | sed -e 's/^/ /'
1079 # Add the dummy module if needed.
1080 func_modules_add_dummy
1082 # If --lgpl, check the license of modules are compatible.
1083 if test -n "$lgpl"; then
1084 for module in $modules; do
1085 license=`func_get_license $module`
1087 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
1088 *) func_fatal_error "incompatible license on module $module: $license" ;;
1093 # Determine final file list.
1094 func_modules_to_filelist
1096 echo "$files" | sed -e 's/^/ /'
1099 || func_fatal_error "refusing to do nothing"
1101 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1102 new_files="$files m4/gnulib-tool.m4"
1103 old_files="$cached_files"
1104 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1105 old_files="$old_files m4/gnulib-tool.m4"
1108 # Create directories.
1109 if test ! -d "$destdir/$sourcebase"; then
1111 echo "Creating directory $destdir/$sourcebase"
1112 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1114 echo "Create directory $destdir/$sourcebase"
1117 if test ! -d "$destdir/$m4base"; then
1119 echo "Creating directory $destdir/$m4base"
1120 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1122 echo "Create directory $destdir/$m4base"
1125 docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
1126 if test -n "$docfiles"; then
1127 if test ! -d "$destdir/$docbase"; then
1129 echo "Creating directory $destdir/$docbase"
1130 mkdir "$destdir/$docbase" || func_fatal_error "failed"
1132 echo "Create directory $destdir/$docbase"
1136 if test -n "$inctests"; then
1137 if test ! -d "$destdir/$testsbase"; then
1139 echo "Creating directory $destdir/$testsbase"
1140 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1142 echo "Create directory $destdir/$testsbase"
1146 if test ! -d "$destdir/$auxdir"; then
1148 echo "Creating directory $destdir/$auxdir"
1149 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1151 echo "Create directory $destdir/$auxdir"
1156 trap 'rm -rf "$tmp"' 0 1 2 3 15
1157 # func_dest_tmpfilename file
1158 # determines the name of a temporary file (file is relative to destdir).
1160 # - tmpfile absolute filename of the temporary file
1161 func_dest_tmpfilename ()
1164 # Put the new contents of $file in a file in the same directory (needed
1165 # to guarantee that an 'mv' to "$destdir/$file" works).
1166 tmpfile="$destdir/$1.tmp"
1168 # Put the new contents of $file in a file in a temporary directory
1169 # (because the directory of "$file" might not exist).
1170 tmpfile="$tmp"/`basename "$1"`.tmp
1174 # Copy files or make symbolic links. Remove obsolete files.
1176 for f in $old_files; do
1178 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1179 doc/*) g=`echo "$f" | sed -e "s,^doc/,$cached_docbase/,"` ;;
1180 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1181 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1182 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1185 echo "$g""$delimiter""$f"
1186 done | LC_ALL=C sort > "$tmp"/old-files
1187 for f in $new_files; do
1189 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1190 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1191 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1192 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1193 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1196 echo "$g""$delimiter""$f"
1197 done | LC_ALL=C sort > "$tmp"/new-files
1198 # First the files that are in old-files, but not in new-files:
1199 sed_take_first_column='s,'"$delimiter"'.*,,'
1200 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1201 # Remove the file. Do nothing if the user already removed it.
1202 if test -f "$destdir/$g"; then
1204 echo "Removing file $g (backup in ${g}~)"
1205 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1207 echo "Remove file $g (backup in ${g}~)"
1211 # func_add_or_update handles a file that ought to be present afterwards.
1212 # Uses parameters f, g, already_present.
1213 func_add_or_update ()
1215 func_dest_tmpfilename "$g"
1216 cp "$gnulib_dir/$f" "$tmpfile" || func_fatal_error "failed"
1217 if test -n "$lgpl"; then
1221 sed -e 's/GNU General/GNU Lesser General/g' \
1222 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1223 < "$gnulib_dir/$f" > "$tmpfile" || func_fatal_error "failed"
1227 if test -f "$destdir/$g"; then
1228 # The file already exists.
1229 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1230 : # The file has not changed.
1234 if test -n "$already_present"; then
1235 echo "Updating file $g (backup in ${g}~)"
1237 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1239 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1240 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1241 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1243 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1246 if test -n "$already_present"; then
1247 echo "Update file $g (backup in ${g}~)"
1249 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1255 # Don't protest if the file should be there but isn't: it happens
1256 # frequently that developers don't put autogenerated files into CVS.
1258 echo "Copying file $g"
1259 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1260 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1262 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1270 # Then the files that are in new-files, but not in old-files:
1271 sed_take_last_column='s,^.*'"$delimiter"',,'
1273 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1275 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1276 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1277 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1278 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1279 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1284 # Then the files that are in new-files and in old-files:
1285 already_present=true
1286 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1288 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1289 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1290 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1291 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1292 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1298 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1299 actioncmd="gnulib-tool --import"
1300 actioncmd="$actioncmd --dir=$destdir"
1301 actioncmd="$actioncmd --lib=$libname"
1302 actioncmd="$actioncmd --source-base=$sourcebase"
1303 actioncmd="$actioncmd --m4-base=$m4base"
1304 actioncmd="$actioncmd --doc-base=$docbase"
1305 actioncmd="$actioncmd --aux-dir=$auxdir"
1306 for module in $avoidlist; do
1307 actioncmd="$actioncmd --avoid=$module"
1309 if test -n "$lgpl"; then
1310 actioncmd="$actioncmd --lgpl"
1312 if test -n "$libtool"; then
1313 actioncmd="$actioncmd --libtool"
1315 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1316 actioncmd="$actioncmd `echo $specified_modules`"
1318 # Create lib/Makefile.am.
1319 func_dest_tmpfilename $sourcebase/Makefile.am
1320 func_emit_lib_Makefile_am > "$tmpfile"
1321 if test -f "$destdir"/$sourcebase/Makefile.am; then
1322 if cmp "$destdir"/$sourcebase/Makefile.am "$tmpfile" > /dev/null; then
1326 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1327 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1328 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1330 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1336 echo "Creating $sourcebase/Makefile.am"
1337 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1339 echo "Create $sourcebase/Makefile.am"
1344 # Create m4/gnulib-cache.m4.
1345 func_dest_tmpfilename $m4base/gnulib-cache.m4
1347 func_emit_copyright_notice
1349 echo "# This file represents the specification of how gnulib-tool is used."
1350 echo "# It acts as a cache: It is written and read by gnulib-tool."
1351 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1352 echo "# like the configure.ac and various Makefile.am files."
1355 echo "# Specification in the form of a command-line invocation:"
1358 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1359 echo "gl_MODULES(["`echo $specified_modules`"])"
1360 echo "gl_AVOID([$avoidlist])"
1361 echo "gl_SOURCE_BASE([$sourcebase])"
1362 echo "gl_M4_BASE([$m4base])"
1363 echo "gl_DOC_BASE([$docbase])"
1364 echo "gl_TESTS_BASE([$testsbase])"
1365 echo "gl_LIB([$libname])"
1366 test -z "$lgpl" || echo "gl_LGPL"
1367 test -z "$libtool" || echo "gl_LIBTOOL"
1368 echo "gl_MACRO_PREFIX([$macro_prefix])"
1370 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1371 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1375 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1376 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1377 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1379 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1383 echo "# gnulib-cache.m4 ends here"
1390 echo "Creating $m4base/gnulib-cache.m4"
1391 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1393 echo "Create $m4base/gnulib-cache.m4"
1399 # Create m4/gnulib-comp.m4.
1400 func_dest_tmpfilename $m4base/gnulib-comp.m4
1402 func_emit_copyright_notice
1404 echo "# This file represents the compiled summary of the specification in"
1405 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1406 echo "# to be invoked from configure.ac."
1407 echo "# In projects using CVS, this file can be treated like other built files."
1410 echo "# This macro should be invoked from $configure_ac, in the section"
1411 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1412 echo "# any checks for libraries, header files, types and library functions."
1413 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1415 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1416 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1417 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1419 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1420 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1422 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1423 echo " AC_REQUIRE([gl_LOCK])"
1427 echo "# This macro should be invoked from $configure_ac, in the section"
1428 echo "# \"Check for header files, types and library functions\"."
1429 echo "AC_DEFUN([${macro_prefix}_INIT],"
1431 if test -z "$libtool"; then
1432 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1434 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1436 if test "$auxdir" != "build-aux"; then
1437 sed_replace_build_aux='
1439 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1440 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1443 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1445 sed_replace_build_aux=
1447 for module in $modules; do
1449 if test -n "$module"; then
1450 func_get_autoconf_snippet "$module" \
1451 | sed -e '/^$/d;' -e 's/^/ /' \
1452 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1453 -e "$sed_replace_build_aux"
1454 if test "$module" = 'alloca' && test -n "$libtool"; then
1455 echo 'changequote(,)dnl'
1456 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1457 echo 'changequote([, ])dnl'
1458 echo 'AC_SUBST([LTALLOCA])'
1464 echo "# This macro records the list of files which have been installed by"
1465 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1466 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1467 echo "$files" | sed -e 's,^, ,'
1470 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1471 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
1475 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1476 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1477 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1479 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1483 echo "# gnulib-comp.m4 ends here"
1490 echo "Creating $m4base/gnulib-comp.m4"
1491 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1493 echo "Create $m4base/gnulib-comp.m4"
1499 if test -n "$inctests"; then
1500 # Create tests/Makefile.am.
1501 func_dest_tmpfilename $testsbase/Makefile.am
1502 func_emit_tests_Makefile_am > "$tmpfile"
1503 if test -f "$destdir"/$testsbase/Makefile.am; then
1504 if cmp "$destdir"/$testsbase/Makefile.am "$tmpfile" > /dev/null; then
1508 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1509 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1510 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1512 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1518 echo "Creating $testsbase/Makefile.am"
1519 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1521 echo "Create $testsbase/Makefile.am"
1528 # Undo the effect of the previous 'trap' command. Some shellology:
1529 # We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
1530 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
1531 # exit); for the others we need to call 'exit' explicitly. The value of $? is
1532 # 128 + signal number and is set before the trap-registered command is run.
1534 trap 'exit $?' 1 2 3 15
1538 echo "You may need to add #include directives for the following .h files."
1540 # First the #include <...> directives without #ifs, sorted for convenience.
1541 for module in $modules; do
1542 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1545 func_get_include_directive "$module" | grep -v 'include "'
1547 done | LC_ALL=C sort -u
1548 # Then the #include "..." directives without #ifs, sorted for convenience.
1549 for module in $modules; do
1550 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1553 func_get_include_directive "$module" | grep 'include "'
1555 done | LC_ALL=C sort -u
1556 # Then the #include directives that are surrounded by #ifs. Not sorted.
1557 for module in $modules; do
1558 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1559 func_get_include_directive "$module"
1562 ) | sed -e '/^$/d;' -e 's/^/ /'
1564 echo "Don't forget to"
1565 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1566 if test -n "$inctests"; then
1567 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1569 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1570 sourcebase_base=`basename "$sourcebase"`
1571 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1572 if test -n "$inctests"; then
1573 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1574 testsbase_base=`basename "$testsbase"`
1575 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1577 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1578 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1579 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1582 # func_create_testdir testdir modules
1584 # - auxdir directory relative to destdir where to place build aux files
1585 func_create_testdir ()
1589 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1591 # Determine final module list.
1592 func_modules_transitive_closure
1593 echo "Module list with included dependencies:"
1594 echo "$modules" | sed -e 's/^/ /'
1596 # Add the dummy module if needed.
1597 func_modules_add_dummy
1599 # Determine final file list.
1600 func_modules_to_filelist
1602 echo "$files" | sed -e 's/^/ /'
1604 # Create directories.
1605 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1606 if test "$d" = build-aux; then
1607 mkdir -p "$testdir/$auxdir"
1609 mkdir -p "$testdir/$d"
1613 # Copy files or make symbolic links.
1616 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1619 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1620 if test -z "$symbolic"; then
1621 cp -p "$gnulib_dir/$f" "$testdir/$g"
1623 ln -s "$gnulib_dir/$f" "$testdir/$g"
1627 # Create lib/Makefile.am.
1628 mkdir -p "$testdir/lib"
1629 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1631 # Create m4/Makefile.am.
1632 mkdir -p "$testdir/m4"
1633 (echo "## Process this file with automake to produce Makefile.in."
1639 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1642 ) > "$testdir/m4/Makefile.am"
1645 subdirs_with_configure_ac=""
1647 if test -f "$testdir"/m4/gettext.m4; then
1648 # Avoid stupid error message from automake:
1649 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1650 mkdir -p "$testdir/po"
1651 (echo "## Process this file with automake to produce Makefile.in."
1652 ) > "$testdir/po/Makefile.am"
1653 subdirs="$subdirs po"
1656 if test -n "$inctests"; then
1657 test -d "$testdir/tests" || mkdir "$testdir/tests"
1658 # Create tests/Makefile.am.
1662 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1663 # Create tests/configure.ac.
1664 (echo "# Process this file with autoconf to produce a configure script."
1665 echo "AC_INIT([dummy], [0])"
1666 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1667 echo "AM_INIT_AUTOMAKE"
1669 echo "AM_CONFIG_HEADER([config.h])"
1672 echo "AC_PROG_INSTALL"
1673 echo "AC_PROG_MAKE_SET"
1674 echo "AC_PROG_RANLIB"
1676 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1677 echo "AC_GNU_SOURCE"
1680 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1681 echo "gl_USE_SYSTEM_EXTENSIONS"
1684 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1688 if test -z "$libtool"; then
1689 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1691 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1693 if test "$auxdir" != "build-aux"; then
1694 sed_replace_build_aux='
1696 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1697 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1700 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1702 sed_replace_build_aux=
1704 # We don't have explicit ordering constraints between the various
1705 # autoconf snippets. It's cleanest to put those of the library before
1706 # those of the tests.
1707 for module in $modules; do
1708 func_verify_nontests_module
1709 if test -n "$module"; then
1710 func_get_autoconf_snippet "$module" \
1711 | sed -e "$sed_replace_build_aux"
1714 for module in $modules; do
1715 func_verify_tests_module
1716 if test -n "$module"; then
1717 func_get_autoconf_snippet "$module" \
1718 | sed -e "$sed_replace_build_aux"
1722 # Usually tests/config.h will be a superset of config.h. Verify this by
1723 # "merging" config.h into tests/config.h; look out for gcc warnings.
1724 echo "AH_TOP([#include \"../config.h\"])"
1726 echo "AC_OUTPUT([Makefile])"
1727 ) > "$testdir/tests/configure.ac"
1728 subdirs="$subdirs tests"
1729 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1732 # Create Makefile.am.
1733 (echo "## Process this file with automake to produce Makefile.in."
1735 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1737 echo "SUBDIRS = $subdirs"
1739 echo "ACLOCAL_AMFLAGS = -I m4"
1740 ) > "$testdir/Makefile.am"
1742 # Create configure.ac.
1743 (echo "# Process this file with autoconf to produce a configure script."
1744 echo "AC_INIT([dummy], [0])"
1745 if test "$auxdir" != "."; then
1746 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1748 echo "AM_INIT_AUTOMAKE"
1750 echo "AM_CONFIG_HEADER([config.h])"
1753 echo "AC_PROG_INSTALL"
1754 echo "AC_PROG_MAKE_SET"
1755 echo "AC_PROG_RANLIB"
1757 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1758 echo "AC_GNU_SOURCE"
1761 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1762 echo "gl_USE_SYSTEM_EXTENSIONS"
1765 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1769 if test -z "$libtool"; then
1770 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1772 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1774 if test "$auxdir" != "build-aux"; then
1775 sed_replace_build_aux='
1777 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1778 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1781 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1783 sed_replace_build_aux=
1785 for module in $modules; do
1786 func_verify_nontests_module
1787 if test -n "$module"; then
1788 func_get_autoconf_snippet "$module" \
1789 | sed -e "$sed_replace_build_aux"
1793 if test -n "$subdirs_with_configure_ac"; then
1794 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1796 makefiles="Makefile"
1797 for d in $subdirs; do
1798 # For subdirs that have a configure.ac by their own, it's the subdir's
1799 # configure.ac which creates the subdir's Makefile.am, not this one.
1800 case " $subdirs_with_configure_ac " in
1802 *) makefiles="$makefiles $d/Makefile" ;;
1805 echo "AC_OUTPUT([$makefiles])"
1806 ) > "$testdir/configure.ac"
1808 # Create autogenerated files.
1810 echo "executing ${AUTORECONF} --force --install"
1811 ${AUTORECONF} --force --install
1813 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1817 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1825 # func_create_megatestdir megatestdir allmodules
1827 # - auxdir directory relative to destdir where to place build aux files
1828 func_create_megatestdir ()
1832 if test -z "$allmodules"; then
1833 allmodules=`func_all_modules`
1837 # First, all modules one by one.
1838 for onemodule in $allmodules; do
1839 func_create_testdir "$megatestdir/$onemodule" $onemodule
1840 megasubdirs="${megasubdirs}$onemodule "
1842 # Then, all modules all together.
1843 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1844 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1845 func_create_testdir "$megatestdir/ALL" "$allmodules"
1846 megasubdirs="${megasubdirs}ALL"
1848 # Create Makefile.am.
1849 (echo "## Process this file with automake to produce Makefile.in."
1851 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1853 echo "SUBDIRS = $megasubdirs"
1854 ) > "$megatestdir/Makefile.am"
1856 # Create configure.ac.
1857 (echo "# Process this file with autoconf to produce a configure script."
1858 echo "AC_INIT([dummy], [0])"
1859 if test "$auxdir" != "."; then
1860 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1862 echo "AM_INIT_AUTOMAKE"
1864 echo "AC_PROG_MAKE_SET"
1866 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1867 echo "AC_OUTPUT([Makefile])"
1868 ) > "$megatestdir/configure.ac"
1870 # Create autogenerated files.
1872 # Do not use "${AUTORECONF} --install", because autoreconf operates
1873 # recursively, but the subdirectories are already finished, therefore
1874 # calling autoreconf here would only waste lots of CPU time.
1875 echo "executing ${ACLOCAL}"
1877 echo "executing mkdir build-aux"
1879 echo "executing ${AUTOCONF}"
1881 echo "executing ${AUTOMAKE} --add-missing --copy"
1882 ${AUTOMAKE} --add-missing --copy
1888 func_fatal_error "no mode specified" ;;
1897 if test -z "$destdir"; then
1900 test -d "$destdir" \
1901 || func_fatal_error "destination directory does not exist: $destdir"
1903 # Prefer configure.ac to configure.in.
1904 if test -f "$destdir"/configure.ac; then
1905 configure_ac="$destdir/configure.ac"
1907 if test -f "$destdir"/configure.in; then
1908 configure_ac="$destdir/configure.in"
1910 func_fatal_error "cannot find $destdir/configure.ac"
1914 # Analyze configure.ac.
1921 /AC_CONFIG_AUX_DIR/ {
1922 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1924 /A[CM]_PROG_LIBTOOL/ {
1925 s,^.*$,guessed_libtool=true,p
1927 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1929 if test -z "$auxdir"; then
1930 auxdir="$guessed_auxdir"
1933 # Determine where to apply func_import.
1934 if test -n "$m4base"; then
1935 # Apply func_import to a particular gnulib directory.
1936 # Any number of additional modules can be given.
1937 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1938 # First use of gnulib in the given m4base.
1939 test -n "$supplied_libname" || supplied_libname=true
1940 test -n "$sourcebase" || sourcebase="lib"
1941 test -n "$docbase" || docbase="doc"
1942 test -n "$testsbase" || testsbase="tests"
1943 test -n "$macro_prefix" || macro_prefix="gl"
1947 # Apply func_import to all gnulib directories.
1948 # To get this list of directories, look at Makefile.am. (Not at
1949 # configure, because it may be omitted from CVS. Also, don't run
1950 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1953 if test -f "$destdir"/Makefile.am; then
1954 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
1956 for arg in $aclocal_amflags; do
1957 if test -n "$m4dir_is_next"; then
1958 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1962 if test -f "$destdir/$arg"/gnulib-cache.m4; then
1963 m4dirs="$m4dirs $arg"
1964 m4dirs_count=`expr $m4dirs_count + 1`
1969 if test "X$arg" = "X-I"; then
1977 # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
1978 if test -f "$destdir"/aclocal.m4; then
1979 sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
1980 sedexpr2='s,^[^/]*$,.,'
1981 sedexpr3='s,/[^/]*$,,'
1982 m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort | LC_ALL=C uniq`
1983 m4dirs_count=`echo "$m4dirs" | wc -l`
1986 if test $m4dirs_count = 0; then
1987 # First use of gnulib in a package.
1988 # Any number of additional modules can be given.
1989 test -n "$supplied_libname" || supplied_libname=true
1990 test -n "$sourcebase" || sourcebase="lib"
1992 test -n "$docbase" || docbase="doc"
1993 test -n "$testsbase" || testsbase="tests"
1994 test -n "$macro_prefix" || macro_prefix="gl"
1997 if test $m4dirs_count = 1; then
1998 # There's only one use of gnulib here. Assume the user means it.
1999 # Any number of additional modules can be given.
2000 for m4base in $m4dirs; do
2004 # Ambiguous - guess what the user meant.
2005 if test $# = 0; then
2006 # No further arguments. Guess the user wants to update all of them.
2007 for m4base in $m4dirs; do
2012 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
2020 if test -z "$destdir"; then
2021 func_fatal_error "please specify --dir option"
2024 test -d "$destdir" \
2025 || func_fatal_error "could not create destination directory"
2026 test -n "$auxdir" || auxdir="build-aux"
2027 func_create_testdir "$destdir" "$*"
2030 create-megatestdir )
2031 if test -z "$destdir"; then
2032 func_fatal_error "please specify --dir option"
2034 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2035 test -n "$auxdir" || auxdir="build-aux"
2036 func_create_megatestdir "$destdir" "$*"
2040 test -n "$destdir" || destdir=testdir$$
2041 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2042 test -n "$auxdir" || auxdir="build-aux"
2043 func_create_testdir "$destdir" "$*"
2051 remaining=`find . -type f -print`
2052 if test -n "$remaining"; then
2053 echo "Remaining files:" $remaining 1>&2
2054 echo "gnulib-tool: *** Stop." 1>&2
2063 test -n "$destdir" || destdir=testdir$$
2064 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2065 test -n "$auxdir" || auxdir="build-aux"
2066 func_create_megatestdir "$destdir" "$*"
2074 remaining=`find . -type f -print`
2075 if test -n "$remaining"; then
2076 echo "Remaining files:" $remaining 1>&2
2077 echo "gnulib-tool: *** Stop." 1>&2
2085 extract-description )
2089 if test -n "$module"; then
2090 func_get_description "$module"
2099 if test -n "$module"; then
2100 func_get_filelist "$module"
2105 extract-dependencies )
2109 if test -n "$module"; then
2110 func_get_dependencies "$module"
2115 extract-autoconf-snippet )
2119 if test -n "$module"; then
2120 func_get_autoconf_snippet "$module"
2125 extract-automake-snippet )
2129 if test -n "$module"; then
2130 func_get_automake_snippet "$module"
2135 extract-include-directive )
2139 if test -n "$module"; then
2140 func_get_include_directive "$module"
2149 if test -n "$module"; then
2150 func_get_license "$module"
2155 extract-maintainer )
2159 if test -n "$module"; then
2160 func_get_maintainer "$module"
2165 extract-tests-module )
2169 if test -n "$module"; then
2170 func_get_tests_module "$module"
2176 func_fatal_error "unknown operation mode --$mode" ;;