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:04:18 $'
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 --assume-autoconf=VERSION
109 Assume a given autoconf version (or newer).
110 If VERSION is 'latest-stable', assume the latest
113 Options for --import:
114 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
115 --source-base=DIRECTORY
116 Directory relative to --dir where source code is
117 placed (default \"lib\").
118 --m4-base=DIRECTORY Directory relative to --dir where *.m4 macros are
119 placed (default \"m4\").
120 --doc-base=DIRECTORY Directory relative to --dir where doc files are
121 placed (default \"doc\").
122 --tests-base=DIRECTORY
123 Directory relative to --dir where unit tests are
124 placed (default \"tests\").
125 --aux-dir=DIRECTORY Directory relative to --dir where auxiliary build
126 tools are placed (default \"build-aux\").
127 --with-tests Include unit tests for the included modules.
128 --avoid=MODULE Avoid including the given MODULE. Useful if you
129 have code that provides equivalent functionality.
130 This option can be repeated.
131 --lgpl Abort if modules aren't available under the LGPL.
132 Also modify license template from GPL to LGPL.
133 --libtool Use libtool rules.
134 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
135 'gl_INIT'. Default is 'gl'.
136 --no-changelog don't update or create ChangeLog files
138 Options for --import and --update:
139 --dry-run For --import, only print what would have been done.
140 -s, --symbolic, --symlink Make symbolic links instead of copying files.
142 Report bugs to <bug-gnulib@gnu.org>."
146 # outputs to stdout the --version message.
149 year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
150 echo "$progname (GNU $package) $version"
151 echo "Copyright (C) $year Free Software Foundation, Inc.
152 This is free software; see the source for copying conditions. There is NO
153 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
154 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
157 # func_emit_copyright_notice
158 # outputs to stdout a header for a generated file.
159 func_emit_copyright_notice ()
161 echo "# Copyright (C) 2004-2006 Free Software Foundation, Inc."
163 echo "# This file is free software, distributed under the terms of the GNU"
164 echo "# General Public License. As a special exception to the GNU General"
165 echo "# Public License, this file may be distributed as part of a program"
166 echo "# that contains a configuration script generated by Autoconf, under"
167 echo "# the same distribution terms as the rest of that program."
169 echo "# Generated by gnulib-tool."
173 # creates a temporary directory.
175 # - tmp pathname of freshly created temporary directory
178 # Use the environment variable TMPDIR, falling back to /tmp. This allows
179 # users to specify a different temporary directory, for example, if their
180 # /tmp is filled up or too small.
183 # Use the mktemp program if available. If not available, hide the error
185 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
186 test -n "$tmp" && test -d "$tmp"
189 # Use a simple mkdir command. It is guaranteed to fail if the directory
190 # already exists. $RANDOM is bash specific and expands to empty in shells
191 # other than bash, ksh and zsh. Its use does not increase security;
192 # rather, it minimizes the probability of failure in a very cluttered /tmp
194 tmp=$TMPDIR/gl$$-$RANDOM
195 (umask 077 && mkdir "$tmp")
198 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
199 { (exit 1); exit 1; }
203 # func_fatal_error message
204 # outputs to stderr a fatal error message, and terminates the program.
207 echo "gnulib-tool: *** $1" 1>&2
208 echo "gnulib-tool: *** Stop." 1>&2
212 # func_readlink SYMLINK
213 # outputs the target of the given symlink.
214 if (type -p readlink) > /dev/null 2>&1; then
217 # Use the readlink program from GNU coreutils.
223 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
224 # would do the wrong thing if the link target contains " -> ".
225 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
229 # func_ln_if_changed SRC DEST
230 # Like ln -s, but avoids munging timestamps if the link is correct.
231 func_ln_if_changed ()
233 if test $# -ne 2; then
234 echo "usage: func_ln_if_changed SRC DEST" >&2
236 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
244 # Command-line option processing.
245 # Removes the OPTIONS from the arguments. Sets the variables:
246 # - mode list or import or create-testdir or create-megatestdir
247 # - destdir from --dir
248 # - libname, supplied_libname from --lib
249 # - sourcebase from --source-base
250 # - m4base from --m4-base
251 # - docbase from --doc-base
252 # - testsbase from --tests-base
253 # - auxdir from --aux-dir
254 # - inctests true if --with-tests was given, blank otherwise
255 # - avoidlist list of modules to avoid, from --avoid
256 # - lgpl true if --lgpl was given, blank otherwise
257 # - libtool true if --libtool was given, blank otherwise
258 # - macro_prefix from --macro-prefix
259 # - autoconf_minversion minimum supported autoconf version
260 # - do_changelog false if --no-changelog was given, : otherwise
261 # - doit : if actions shall be executed, false if only to be printed
284 while test $# -gt 0; do
289 --import | --impor | --impo | --imp | --im | --i )
292 --update | --updat | --upda | --upd | --up | --u )
295 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
298 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
299 mode=create-megatestdir
301 --test | --tes | --te | --t )
304 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
308 mode=`echo "X$1" | sed -e 's/^X--//'`
313 func_fatal_error "missing argument for --dir"
318 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
323 func_fatal_error "missing argument for --lib"
326 supplied_libname=true
329 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
330 supplied_libname=true
335 func_fatal_error "missing argument for --source-base"
340 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
345 func_fatal_error "missing argument for --m4-base"
350 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
355 func_fatal_error "missing argument for --doc-base"
360 docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
365 func_fatal_error "missing argument for --tests-base"
370 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
375 func_fatal_error "missing argument for --aux-dir"
380 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
388 func_fatal_error "missing argument for --avoid"
390 avoidlist="$avoidlist $1"
393 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
404 func_fatal_error "missing argument for --macro-prefix"
409 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
414 func_fatal_error "missing argument for --assume-autoconf"
416 autoconf_minversion="$1"
418 --assume-autoconf=* )
419 autoconf_minversion=`echo "X$1" | sed -e 's/^X--assume-autoconf=//'`
421 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
427 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
430 --help | --hel | --he | --h )
433 --version | --versio | --versi | --vers | --ver | --ve | --v )
437 # Stop option processing
441 echo "gnulib-tool: unknown option $1" 1>&2
442 echo "Try 'gnulib-tool --help' for more information." 1>&2
449 if test "$mode" = update; then
450 if test $# != 0; then
451 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
452 echo "Try 'gnulib-tool --help' for more information." 1>&2
453 echo "If you really want to modify the gnulib configuration of your project," 1>&2
454 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
457 if test -n "$supplied_libname" || test -n "$sourcebase" || test -n "$m4base" \
458 || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
459 || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
460 || test -n "$macro_prefix" || test -n "$autoconf_minversion"; then
461 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
462 echo "Try 'gnulib-tool --help' for more information." 1>&2
463 echo "If you really want to modify the gnulib configuration of your project," 1>&2
464 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
470 DEFAULT_AUTOCONF_MINVERSION="2.59"
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" ;;
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=
952 cached_autoconf_minversion=
954 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
960 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
963 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
966 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
969 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
972 s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
975 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
978 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
981 s,^.*$,cached_lgpl=true,p
984 s,^.*$,cached_libtool=true,p
987 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
989 /gl_AUTOCONF_MINVERSION(/ {
990 s,^.*gl_AUTOCONF_MINVERSION([[ ]*\([^])]*\).*$,cached_autoconf_minversion="\1",p
992 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
993 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
998 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
999 s,^.*$,cached_files=",p
1011 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
1015 # Merge the cached settings with the specified ones.
1016 # The m4base must be the same as expected from the pathname.
1017 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
1018 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
1020 # Append the cached and the specified module names. So that
1021 # "gnulib-tool --import foo" means to add the module foo.
1022 specified_modules="$cached_specified_modules $1"
1023 # Append the cached and the specified avoidlist. This is probably better
1024 # than dropping the cached one when --avoid is specified at least once.
1025 avoidlist=`echo $cached_avoidlist $avoidlist`
1026 # The sourcebase defaults to the cached one.
1027 if test -z "$sourcebase"; then
1028 sourcebase="$cached_sourcebase"
1029 if test -z "$sourcebase"; then
1030 func_fatal_error "missing --source-base option"
1033 # The docbase defaults to the cached one.
1034 if test -z "$docbase"; then
1035 docbase="$cached_docbase"
1036 if test -z "$docbase"; then
1037 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."
1040 # The testsbase defaults to the cached one.
1041 if test -z "$testsbase"; then
1042 testsbase="$cached_testsbase"
1043 if test -z "$testsbase"; then
1044 func_fatal_error "missing --tests-base option"
1047 # The libname defaults to the cached one.
1048 if test -z "$supplied_libname"; then
1049 libname="$cached_libname"
1050 if test -z "$libname"; then
1051 func_fatal_error "missing --lib option"
1054 # Require LGPL if specified either way.
1055 if test -z "$lgpl"; then
1058 # Use libtool if specified either way, or if guessed.
1059 if test -z "$libtool"; then
1060 if test -n "$cached_m4base"; then
1061 libtool="$cached_libtool"
1063 libtool="$guessed_libtool"
1066 # The macro_prefix defaults to the cached one.
1067 if test -z "$macro_prefix"; then
1068 macro_prefix="$cached_macro_prefix"
1069 if test -z "$macro_prefix"; then
1070 func_fatal_error "missing --macro-prefix option"
1073 # The autoconf_minversion defaults to the cached one.
1074 if test -z "$autoconf_minversion"; then
1075 autoconf_minversion="$cached_autoconf_minversion"
1076 if test -z "$autoconf_minversion"; then
1077 autoconf_minversion="$DEFAULT_AUTOCONF_MINVERSION"
1081 # Canonicalize the list of specified modules.
1082 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1084 # Determine final module list.
1085 modules="$specified_modules"
1086 func_modules_transitive_closure
1087 echo "Module list with included dependencies:"
1088 echo "$modules" | sed -e 's/^/ /'
1090 # Add the dummy module if needed.
1091 func_modules_add_dummy
1093 # If --lgpl, check the license of modules are compatible.
1094 if test -n "$lgpl"; then
1095 for module in $modules; do
1096 license=`func_get_license $module`
1098 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
1099 *) func_fatal_error "incompatible license on module $module: $license" ;;
1104 # Determine final file list.
1105 func_modules_to_filelist
1107 echo "$files" | sed -e 's/^/ /'
1110 || func_fatal_error "refusing to do nothing"
1112 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1113 new_files="$files m4/gnulib-tool.m4"
1114 old_files="$cached_files"
1115 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1116 old_files="$old_files m4/gnulib-tool.m4"
1119 # Create directories.
1120 if test ! -d "$destdir/$sourcebase"; then
1122 echo "Creating directory $destdir/$sourcebase"
1123 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1125 echo "Create directory $destdir/$sourcebase"
1128 if test ! -d "$destdir/$m4base"; then
1130 echo "Creating directory $destdir/$m4base"
1131 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1133 echo "Create directory $destdir/$m4base"
1136 if test ! -d "$destdir/$docbase"; then
1138 echo "Creating directory $destdir/$docbase"
1139 mkdir "$destdir/$docbase" || func_fatal_error "failed"
1141 echo "Create directory $destdir/$docbase"
1144 if test -n "$inctests"; then
1145 if test ! -d "$destdir/$testsbase"; then
1147 echo "Creating directory $destdir/$testsbase"
1148 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1150 echo "Create directory $destdir/$testsbase"
1154 if test ! -d "$destdir/$auxdir"; then
1156 echo "Creating directory $destdir/$auxdir"
1157 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1159 echo "Create directory $destdir/$auxdir"
1164 trap 'rm -rf "$tmp"' 0 1 2 3 15
1165 # func_dest_tmpfilename file
1166 # determines the name of a temporary file (file is relative to destdir).
1168 # - tmpfile absolute filename of the temporary file
1169 func_dest_tmpfilename ()
1172 # Put the new contents of $file in a file in the same directory (needed
1173 # to guarantee that an 'mv' to "$destdir/$file" works).
1174 tmpfile="$destdir/$1.tmp"
1176 # Put the new contents of $file in a file in a temporary directory
1177 # (because the directory of "$file" might not exist).
1178 tmpfile="$tmp"/`basename "$1"`.tmp
1182 # Copy files or make symbolic links. Remove obsolete files.
1184 for f in $old_files; do
1186 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1187 doc/*) g=`echo "$f" | sed -e "s,^doc/,$cached_docbase/,"` ;;
1188 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1189 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1190 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1193 echo "$g""$delimiter""$f"
1194 done | LC_ALL=C sort > "$tmp"/old-files
1195 for f in $new_files; do
1197 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1198 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1199 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1200 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1201 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1204 echo "$g""$delimiter""$f"
1205 done | LC_ALL=C sort > "$tmp"/new-files
1206 # First the files that are in old-files, but not in new-files:
1207 sed_take_first_column='s,'"$delimiter"'.*,,'
1208 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1209 # Remove the file. Do nothing if the user already removed it.
1210 if test -f "$destdir/$g"; then
1212 echo "Removing file $g (backup in ${g}~)"
1213 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1215 echo "Remove file $g (backup in ${g}~)"
1219 # func_add_or_update handles a file that ought to be present afterwards.
1220 # Uses parameters f, g, already_present.
1221 func_add_or_update ()
1223 func_dest_tmpfilename "$g"
1224 cp "$gnulib_dir/$f" "$tmpfile" || func_fatal_error "failed"
1225 if test -n "$lgpl"; then
1229 sed -e 's/GNU General/GNU Lesser General/g' \
1230 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1231 < "$gnulib_dir/$f" > "$tmpfile" || func_fatal_error "failed"
1235 if test -f "$destdir/$g"; then
1236 # The file already exists.
1237 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1238 : # The file has not changed.
1242 if test -n "$already_present"; then
1243 echo "Updating file $g (backup in ${g}~)"
1245 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1247 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1248 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1249 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1251 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1254 if test -n "$already_present"; then
1255 echo "Update file $g (backup in ${g}~)"
1257 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1263 # Don't protest if the file should be there but isn't: it happens
1264 # frequently that developers don't put autogenerated files into CVS.
1266 echo "Copying file $g"
1267 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1268 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1270 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1278 # Then the files that are in new-files, but not in old-files:
1279 sed_take_last_column='s,^.*'"$delimiter"',,'
1281 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1283 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1284 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1285 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1286 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1287 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1292 # Then the files that are in new-files and in old-files:
1293 already_present=true
1294 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1296 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1297 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1298 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1299 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1300 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1306 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1307 actioncmd="gnulib-tool --import"
1308 actioncmd="$actioncmd --dir=$destdir"
1309 actioncmd="$actioncmd --lib=$libname"
1310 actioncmd="$actioncmd --source-base=$sourcebase"
1311 actioncmd="$actioncmd --m4-base=$m4base"
1312 actioncmd="$actioncmd --doc-base=$docbase"
1313 actioncmd="$actioncmd --aux-dir=$auxdir"
1314 for module in $avoidlist; do
1315 actioncmd="$actioncmd --avoid=$module"
1317 if test -n "$lgpl"; then
1318 actioncmd="$actioncmd --lgpl"
1320 if test -n "$libtool"; then
1321 actioncmd="$actioncmd --libtool"
1323 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1324 actioncmd="$actioncmd --assume-autoconf=$autoconf_minversion"
1325 actioncmd="$actioncmd `echo $specified_modules`"
1327 # Create lib/Makefile.am.
1328 func_dest_tmpfilename $sourcebase/Makefile.am
1329 func_emit_lib_Makefile_am > "$tmpfile"
1330 if test -f "$destdir"/$sourcebase/Makefile.am; then
1331 if cmp "$destdir"/$sourcebase/Makefile.am "$tmpfile" > /dev/null; then
1335 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1336 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1337 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1339 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1345 echo "Creating $sourcebase/Makefile.am"
1346 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1348 echo "Create $sourcebase/Makefile.am"
1353 # Create m4/gnulib-cache.m4.
1354 func_dest_tmpfilename $m4base/gnulib-cache.m4
1356 func_emit_copyright_notice
1358 echo "# This file represents the specification of how gnulib-tool is used."
1359 echo "# It acts as a cache: It is written and read by gnulib-tool."
1360 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1361 echo "# like the configure.ac and various Makefile.am files."
1364 echo "# Specification in the form of a command-line invocation:"
1367 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1368 echo "gl_MODULES(["`echo $specified_modules`"])"
1369 echo "gl_AVOID([$avoidlist])"
1370 echo "gl_SOURCE_BASE([$sourcebase])"
1371 echo "gl_M4_BASE([$m4base])"
1372 echo "gl_DOC_BASE([$docbase])"
1373 echo "gl_TESTS_BASE([$testsbase])"
1374 echo "gl_LIB([$libname])"
1375 test -z "$lgpl" || echo "gl_LGPL"
1376 test -z "$libtool" || echo "gl_LIBTOOL"
1377 echo "gl_MACRO_PREFIX([$macro_prefix])"
1378 echo "gl_AUTOCONF_MINVERSION([$autoconf_minversion])"
1380 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1381 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1385 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1386 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1387 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1389 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1393 echo "# gnulib-cache.m4 ends here"
1400 echo "Creating $m4base/gnulib-cache.m4"
1401 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1403 echo "Create $m4base/gnulib-cache.m4"
1409 # Create m4/gnulib-comp.m4.
1410 func_dest_tmpfilename $m4base/gnulib-comp.m4
1412 func_emit_copyright_notice
1414 echo "# This file represents the compiled summary of the specification in"
1415 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1416 echo "# to be invoked from configure.ac."
1417 echo "# In projects using CVS, this file can be treated like other built files."
1420 echo "# This macro should be invoked from $configure_ac, in the section"
1421 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1422 echo "# any checks for libraries, header files, types and library functions."
1423 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1425 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1426 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1427 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1429 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1430 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1432 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1433 echo " AC_REQUIRE([gl_LOCK])"
1437 echo "# This macro should be invoked from $configure_ac, in the section"
1438 echo "# \"Check for header files, types and library functions\"."
1439 echo "AC_DEFUN([${macro_prefix}_INIT],"
1441 if test -z "$libtool"; then
1442 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1444 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1446 if test "$auxdir" != "build-aux"; then
1447 sed_replace_build_aux='
1449 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1450 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1453 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1455 sed_replace_build_aux=
1457 for module in $modules; do
1459 if test -n "$module"; then
1460 func_get_autoconf_snippet "$module" \
1461 | sed -e '/^$/d;' -e 's/^/ /' \
1462 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1463 -e "$sed_replace_build_aux"
1464 if test "$module" = 'alloca' && test -n "$libtool"; then
1465 echo 'changequote(,)dnl'
1466 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1467 echo 'changequote([, ])dnl'
1468 echo 'AC_SUBST([LTALLOCA])'
1474 echo "# This macro records the list of files which have been installed by"
1475 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1476 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1477 echo "$files" | sed -e 's,^, ,'
1480 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1481 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
1485 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1486 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1487 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1489 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1493 echo "# gnulib-comp.m4 ends here"
1500 echo "Creating $m4base/gnulib-comp.m4"
1501 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1503 echo "Create $m4base/gnulib-comp.m4"
1509 if test -n "$inctests"; then
1510 # Create tests/Makefile.am.
1511 func_dest_tmpfilename $testsbase/Makefile.am
1512 func_emit_tests_Makefile_am > "$tmpfile"
1513 if test -f "$destdir"/$testsbase/Makefile.am; then
1514 if cmp "$destdir"/$testsbase/Makefile.am "$tmpfile" > /dev/null; then
1518 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1519 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1520 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1522 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1528 echo "Creating $testsbase/Makefile.am"
1529 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1531 echo "Create $testsbase/Makefile.am"
1538 # Undo the effect of the previous 'trap' command. Some shellology:
1539 # We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
1540 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
1541 # exit); for the others we need to call 'exit' explicitly. The value of $? is
1542 # 128 + signal number and is set before the trap-registered command is run.
1544 trap 'exit $?' 1 2 3 15
1548 echo "You may need to add #include directives for the following .h files."
1550 # First the #include <...> directives without #ifs, sorted for convenience.
1551 for module in $modules; do
1552 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1555 func_get_include_directive "$module" | grep -v 'include "'
1557 done | LC_ALL=C sort -u
1558 # Then the #include "..." directives without #ifs, sorted for convenience.
1559 for module in $modules; do
1560 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1563 func_get_include_directive "$module" | grep 'include "'
1565 done | LC_ALL=C sort -u
1566 # Then the #include directives that are surrounded by #ifs. Not sorted.
1567 for module in $modules; do
1568 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1569 func_get_include_directive "$module"
1572 ) | sed -e '/^$/d;' -e 's/^/ /'
1574 echo "Don't forget to"
1575 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1576 if test -n "$inctests"; then
1577 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1579 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1580 sourcebase_base=`basename "$sourcebase"`
1581 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1582 if test -n "$inctests"; then
1583 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1584 testsbase_base=`basename "$testsbase"`
1585 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1587 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1588 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1589 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1592 # func_create_testdir testdir modules
1594 # - auxdir directory relative to destdir where to place build aux files
1595 func_create_testdir ()
1599 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1601 # Determine final module list.
1602 func_modules_transitive_closure
1603 echo "Module list with included dependencies:"
1604 echo "$modules" | sed -e 's/^/ /'
1606 # Add the dummy module if needed.
1607 func_modules_add_dummy
1609 # Determine final file list.
1610 func_modules_to_filelist
1612 echo "$files" | sed -e 's/^/ /'
1614 # Create directories.
1615 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1616 if test "$d" = build-aux; then
1617 mkdir -p "$testdir/$auxdir"
1619 mkdir -p "$testdir/$d"
1623 # Copy files or make symbolic links.
1626 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1629 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1630 if test -z "$symbolic"; then
1631 cp -p "$gnulib_dir/$f" "$testdir/$g"
1633 ln -s "$gnulib_dir/$f" "$testdir/$g"
1637 # Create lib/Makefile.am.
1638 mkdir -p "$testdir/lib"
1639 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1641 # Create m4/Makefile.am.
1642 mkdir -p "$testdir/m4"
1643 (echo "## Process this file with automake to produce Makefile.in."
1649 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1652 ) > "$testdir/m4/Makefile.am"
1655 subdirs_with_configure_ac=""
1657 if test -f "$testdir"/m4/gettext.m4; then
1658 # Avoid stupid error message from automake:
1659 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1660 mkdir -p "$testdir/po"
1661 (echo "## Process this file with automake to produce Makefile.in."
1662 ) > "$testdir/po/Makefile.am"
1663 subdirs="$subdirs po"
1666 if test -n "$inctests"; then
1667 test -d "$testdir/tests" || mkdir "$testdir/tests"
1668 # Create tests/Makefile.am.
1672 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1673 # Create tests/configure.ac.
1674 (echo "# Process this file with autoconf to produce a configure script."
1675 echo "AC_INIT([dummy], [0])"
1676 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1677 echo "AM_INIT_AUTOMAKE"
1679 echo "AM_CONFIG_HEADER([config.h])"
1682 echo "AC_PROG_INSTALL"
1683 echo "AC_PROG_MAKE_SET"
1684 echo "AC_PROG_RANLIB"
1686 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1687 echo "AC_GNU_SOURCE"
1690 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1691 echo "gl_USE_SYSTEM_EXTENSIONS"
1694 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1698 if test -z "$libtool"; then
1699 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1701 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1703 if test "$auxdir" != "build-aux"; then
1704 sed_replace_build_aux='
1706 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1707 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1710 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1712 sed_replace_build_aux=
1714 # We don't have explicit ordering constraints between the various
1715 # autoconf snippets. It's cleanest to put those of the library before
1716 # those of the tests.
1717 for module in $modules; do
1718 func_verify_nontests_module
1719 if test -n "$module"; then
1720 func_get_autoconf_snippet "$module" \
1721 | sed -e "$sed_replace_build_aux"
1724 for module in $modules; do
1725 func_verify_tests_module
1726 if test -n "$module"; then
1727 func_get_autoconf_snippet "$module" \
1728 | sed -e "$sed_replace_build_aux"
1732 # Usually tests/config.h will be a superset of config.h. Verify this by
1733 # "merging" config.h into tests/config.h; look out for gcc warnings.
1734 echo "AH_TOP([#include \"../config.h\"])"
1736 echo "AC_OUTPUT([Makefile])"
1737 ) > "$testdir/tests/configure.ac"
1738 subdirs="$subdirs tests"
1739 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1742 # Create Makefile.am.
1743 (echo "## Process this file with automake to produce Makefile.in."
1745 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1747 echo "SUBDIRS = $subdirs"
1749 echo "ACLOCAL_AMFLAGS = -I m4"
1750 ) > "$testdir/Makefile.am"
1752 # Create configure.ac.
1753 (echo "# Process this file with autoconf to produce a configure script."
1754 echo "AC_INIT([dummy], [0])"
1755 if test "$auxdir" != "."; then
1756 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1758 echo "AM_INIT_AUTOMAKE"
1760 echo "AM_CONFIG_HEADER([config.h])"
1763 echo "AC_PROG_INSTALL"
1764 echo "AC_PROG_MAKE_SET"
1765 echo "AC_PROG_RANLIB"
1767 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1768 echo "AC_GNU_SOURCE"
1771 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1772 echo "gl_USE_SYSTEM_EXTENSIONS"
1775 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1779 if test -z "$libtool"; then
1780 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1782 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1784 if test "$auxdir" != "build-aux"; then
1785 sed_replace_build_aux='
1787 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1788 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1791 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1793 sed_replace_build_aux=
1795 for module in $modules; do
1796 func_verify_nontests_module
1797 if test -n "$module"; then
1798 func_get_autoconf_snippet "$module" \
1799 | sed -e "$sed_replace_build_aux"
1803 if test -n "$subdirs_with_configure_ac"; then
1804 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1806 makefiles="Makefile"
1807 for d in $subdirs; do
1808 # For subdirs that have a configure.ac by their own, it's the subdir's
1809 # configure.ac which creates the subdir's Makefile.am, not this one.
1810 case " $subdirs_with_configure_ac " in
1812 *) makefiles="$makefiles $d/Makefile" ;;
1815 echo "AC_OUTPUT([$makefiles])"
1816 ) > "$testdir/configure.ac"
1818 # Create autogenerated files.
1820 echo "executing ${AUTORECONF} --force --install"
1821 ${AUTORECONF} --force --install
1823 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1827 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1835 # func_create_megatestdir megatestdir allmodules
1837 # - auxdir directory relative to destdir where to place build aux files
1838 func_create_megatestdir ()
1842 if test -z "$allmodules"; then
1843 allmodules=`func_all_modules`
1847 # First, all modules one by one.
1848 for onemodule in $allmodules; do
1849 func_create_testdir "$megatestdir/$onemodule" $onemodule
1850 megasubdirs="${megasubdirs}$onemodule "
1852 # Then, all modules all together.
1853 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1854 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1855 func_create_testdir "$megatestdir/ALL" "$allmodules"
1856 megasubdirs="${megasubdirs}ALL"
1858 # Create Makefile.am.
1859 (echo "## Process this file with automake to produce Makefile.in."
1861 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1863 echo "SUBDIRS = $megasubdirs"
1864 ) > "$megatestdir/Makefile.am"
1866 # Create configure.ac.
1867 (echo "# Process this file with autoconf to produce a configure script."
1868 echo "AC_INIT([dummy], [0])"
1869 if test "$auxdir" != "."; then
1870 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1872 echo "AM_INIT_AUTOMAKE"
1874 echo "AC_PROG_MAKE_SET"
1876 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1877 echo "AC_OUTPUT([Makefile])"
1878 ) > "$megatestdir/configure.ac"
1880 # Create autogenerated files.
1882 # Do not use "${AUTORECONF} --install", because autoreconf operates
1883 # recursively, but the subdirectories are already finished, therefore
1884 # calling autoreconf here would only waste lots of CPU time.
1885 echo "executing ${ACLOCAL}"
1887 echo "executing mkdir build-aux"
1889 echo "executing ${AUTOCONF}"
1891 echo "executing ${AUTOMAKE} --add-missing --copy"
1892 ${AUTOMAKE} --add-missing --copy
1898 func_fatal_error "no mode specified" ;;
1907 if test -z "$destdir"; then
1910 test -d "$destdir" \
1911 || func_fatal_error "destination directory does not exist: $destdir"
1913 # Prefer configure.ac to configure.in.
1914 if test -f "$destdir"/configure.ac; then
1915 configure_ac="$destdir/configure.ac"
1917 if test -f "$destdir"/configure.in; then
1918 configure_ac="$destdir/configure.in"
1920 func_fatal_error "cannot find $destdir/configure.ac"
1924 test -f "$destdir"/Makefile.am \
1925 || func_fatal_error "cannot find $destdir/Makefile.am"
1927 # Analyze configure.ac.
1934 /AC_CONFIG_AUX_DIR/ {
1935 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1937 /A[CM]_PROG_LIBTOOL/ {
1938 s,^.*$,guessed_libtool=true,p
1940 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1942 if test -z "$auxdir"; then
1943 auxdir="$guessed_auxdir"
1946 # Determine where to apply func_import.
1947 if test -n "$m4base"; then
1948 # Apply func_import to a particular gnulib directory.
1949 # Any number of additional modules can be given.
1950 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1951 # First use of gnulib in the given m4base.
1952 test -n "$supplied_libname" || supplied_libname=true
1953 test -n "$sourcebase" || sourcebase="lib"
1954 test -n "$docbase" || docbase="doc"
1955 test -n "$testsbase" || testsbase="tests"
1956 test -n "$macro_prefix" || macro_prefix="gl"
1957 test -n "$autoconf_minversion" || autoconf_minversion="$DEFAULT_AUTOCONF_MINVERSION"
1961 # Apply func_import to all gnulib directories.
1962 # To get this list of directories, look at Makefile.am. (Not at
1963 # configure, because it may be omitted from CVS. Also, don't run
1964 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1965 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
1969 for arg in $aclocal_amflags; do
1970 if test -n "$m4dir_is_next"; then
1971 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1975 if test -f "$destdir/$arg"/gnulib-cache.m4; then
1976 m4dirs="$m4dirs $arg"
1977 m4dirs_count=`expr $m4dirs_count + 1`
1982 if test "X$arg" = "X-I"; then
1989 if test $m4dirs_count = 0; then
1990 # First use of gnulib in a package.
1991 # Any number of additional modules can be given.
1992 test -n "$supplied_libname" || supplied_libname=true
1993 test -n "$sourcebase" || sourcebase="lib"
1995 test -n "$docbase" || docbase="doc"
1996 test -n "$testsbase" || testsbase="tests"
1997 test -n "$macro_prefix" || macro_prefix="gl"
1998 test -n "$autoconf_version" || autoconf_version="$DEFAULT_AUTOCONF_MINVERSION"
2001 if test $m4dirs_count = 1; then
2002 # There's only one use of gnulib here. Assume the user means it.
2003 # Any number of additional modules can be given.
2004 for m4base in $m4dirs; do
2008 # Ambiguous - guess what the user meant.
2009 if test $# = 0; then
2010 # No further arguments. Guess the user wants to update all of them.
2011 for m4base in $m4dirs; do
2016 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
2024 if test -z "$destdir"; then
2025 func_fatal_error "please specify --dir option"
2028 test -d "$destdir" \
2029 || func_fatal_error "could not create destination directory"
2030 test -n "$auxdir" || auxdir="build-aux"
2031 func_create_testdir "$destdir" "$*"
2034 create-megatestdir )
2035 if test -z "$destdir"; then
2036 func_fatal_error "please specify --dir option"
2038 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2039 test -n "$auxdir" || auxdir="build-aux"
2040 func_create_megatestdir "$destdir" "$*"
2044 test -n "$destdir" || destdir=testdir$$
2045 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2046 test -n "$auxdir" || auxdir="build-aux"
2047 func_create_testdir "$destdir" "$*"
2055 remaining=`find . -type f -print`
2056 if test -n "$remaining"; then
2057 echo "Remaining files:" $remaining 1>&2
2058 echo "gnulib-tool: *** Stop." 1>&2
2067 test -n "$destdir" || destdir=testdir$$
2068 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2069 test -n "$auxdir" || auxdir="build-aux"
2070 func_create_megatestdir "$destdir" "$*"
2078 remaining=`find . -type f -print`
2079 if test -n "$remaining"; then
2080 echo "Remaining files:" $remaining 1>&2
2081 echo "gnulib-tool: *** Stop." 1>&2
2089 extract-description )
2093 if test -n "$module"; then
2094 func_get_description "$module"
2103 if test -n "$module"; then
2104 func_get_filelist "$module"
2109 extract-dependencies )
2113 if test -n "$module"; then
2114 func_get_dependencies "$module"
2119 extract-autoconf-snippet )
2123 if test -n "$module"; then
2124 func_get_autoconf_snippet "$module"
2129 extract-automake-snippet )
2133 if test -n "$module"; then
2134 func_get_automake_snippet "$module"
2139 extract-include-directive )
2143 if test -n "$module"; then
2144 func_get_include_directive "$module"
2153 if test -n "$module"; then
2154 func_get_license "$module"
2159 extract-maintainer )
2163 if test -n "$module"; then
2164 func_get_maintainer "$module"
2169 extract-tests-module )
2173 if test -n "$module"; then
2174 func_get_tests_module "$module"
2180 func_fatal_error "unknown operation mode --$mode" ;;