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-05-09 02:38:16 $'
26 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
27 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
29 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
33 # AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
34 # AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
38 # You can set AUTOMAKEPATH to empty if automake 1.9.x is already in your PATH.
41 # If you didn't set AUTOCONFPATH and AUTOMAKEPATH, you can also set the
42 # variables AUTOCONF, ACLOCAL, AUTOMAKE, AUTORECONF individually.
43 if test -z "${AUTOCONF}" || test -n "${AUTOCONFPATH}"; then
44 AUTOCONF="${AUTOCONFPATH}autoconf"
46 if test -z "${ACLOCAL}" || test -n "${AUTOMAKEPATH}"; then
47 ACLOCAL="${AUTOMAKEPATH}aclocal"
49 if test -z "${AUTOMAKE}" || test -n "${AUTOMAKEPATH}"; then
50 AUTOMAKE="${AUTOMAKEPATH}automake"
52 if test -z "${AUTORECONF}" || test -n "${AUTOCONFPATH}"; then
53 AUTORECONF="${AUTOCONFPATH}autoreconf"
57 # outputs to stdout the --help usage message.
61 Usage: gnulib-tool --list
62 gnulib-tool --import [module1 ... moduleN]
64 gnulib-tool --create-testdir --dir=directory module1 ... moduleN
65 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
66 gnulib-tool --test --dir=directory module1 ... moduleN
67 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
68 gnulib-tool --extract-description module
69 gnulib-tool --extract-filelist module
70 gnulib-tool --extract-dependencies module
71 gnulib-tool --extract-autoconf-snippet module
72 gnulib-tool --extract-automake-snippet module
73 gnulib-tool --extract-include-directive module
74 gnulib-tool --extract-license module
75 gnulib-tool --extract-maintainer module
76 gnulib-tool --extract-tests-module module
79 --list print the available module names
80 --import import the given modules into the current package;
81 if no modules are specified, update the current
82 package from the current gnulib
83 --update update the current package, restore files omitted
85 --create-testdir create a scratch package with the given modules
86 --create-megatestdir create a mega scratch package with the given modules
87 one by one and all together
88 --test test the combination of the given modules
89 (recommended to use CC=\"gcc -Wall\" here)
90 --megatest test the given modules one by one and all together
91 (recommended to use CC=\"gcc -Wall\" here)
92 --extract-description extract the description
93 --extract-filelist extract the list of files
94 --extract-dependencies extract the dependencies
95 --extract-autoconf-snippet extract the snippet for configure.ac
96 --extract-automake-snippet extract the snippet for lib/Makefile.am
97 --extract-include-directive extract the #include directive
98 --extract-license report the license terms of the source files
100 --extract-maintainer report the maintainer(s) inside gnulib
101 --extract-tests-module report the unit test module, if it exists
104 --dir=DIRECTORY specify the target directory
105 For --import, this specifies where your
106 configure.ac can be found. Defaults to current
108 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
109 --source-base=DIRECTORY
110 Directory relative --dir where source code is
111 placed (default \"lib\"), for --import.
112 --m4-base=DIRECTORY Directory relative --dir where *.m4 macros are
113 placed (default \"m4\"), for --import.
114 --tests-base=DIRECTORY
115 Directory relative --dir where unit tests are
116 placed (default \"tests\"), for --import.
117 --aux-dir=DIRECTORY Directory relative --dir where auxiliary build
118 tools are placed (default \"build-aux\").
119 --with-tests Include unit tests for the included modules.
120 --avoid=MODULE Avoid including the given MODULE. Useful if you
121 have code that provides equivalent functionality.
122 This option can be repeated.
123 --lgpl Abort if modules aren't available under the LGPL.
124 Also modify license template from GPL to LGPL.
125 --libtool Use libtool rules, for --import.
126 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
127 'gl_INIT'. Default is 'gl'.
128 --no-changelog don't update or create ChangeLog files
129 --dry-run For --import, only print what would have been done.
130 -s, --symbolic, --symlink Make symbolic links instead of copying files.
132 Report bugs to <bug-gnulib@gnu.org>."
136 # outputs to stdout the --version message.
139 year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
140 echo "$progname (GNU $package) $version"
141 echo "Copyright (C) $year Free Software Foundation, Inc.
142 This is free software; see the source for copying conditions. There is NO
143 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
144 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
147 # func_emit_copyright_notice
148 # outputs to stdout a header for a generated file.
149 func_emit_copyright_notice ()
151 echo "# Copyright (C) 2004-2006 Free Software Foundation, Inc."
153 echo "# This file is free software, distributed under the terms of the GNU"
154 echo "# General Public License. As a special exception to the GNU General"
155 echo "# Public License, this file may be distributed as part of a program"
156 echo "# that contains a configuration script generated by Autoconf, under"
157 echo "# the same distribution terms as the rest of that program."
159 echo "# Generated by gnulib-tool."
163 # creates a temporary directory.
165 # - tmp pathname of freshly created temporary directory
168 # Use the environment variable TMPDIR, falling back to /tmp. This allows
169 # users to specify a different temporary directory, for example, if their
170 # /tmp is filled up or too small.
173 # Use the mktemp program if available. If not available, hide the error
175 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
176 test -n "$tmp" && test -d "$tmp"
179 # Use a simple mkdir command. It is guaranteed to fail if the directory
180 # already exists. $RANDOM is bash specific and expands to empty in shells
181 # other than bash, ksh and zsh. Its use does not increase security;
182 # rather, it minimizes the probability of failure in a very cluttered /tmp
184 tmp=$TMPDIR/gl$$-$RANDOM
185 (umask 077 && mkdir "$tmp")
188 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
189 { (exit 1); exit 1; }
193 # func_fatal_error message
194 # outputs to stderr a fatal error message, and terminates the program.
197 echo "gnulib-tool: *** $1" 1>&2
198 echo "gnulib-tool: *** Stop." 1>&2
202 # func_readlink SYMLINK
203 # outputs the target of the given symlink.
204 if (type -p readlink) > /dev/null 2>&1; then
207 # Use the readlink program from GNU coreutils.
213 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
214 # would do the wrong thing if the link target contains " -> ".
215 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
219 # func_ln_if_changed SRC DEST
220 # Like ln -s, but avoids munging timestamps if the link is correct.
221 func_ln_if_changed ()
223 if test $# -ne 2; then
224 echo "usage: func_ln_if_changed SRC DEST" >&2
226 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
234 # Command-line option processing.
235 # Removes the OPTIONS from the arguments. Sets the variables:
236 # - mode list or import or create-testdir or create-megatestdir
237 # - destdir from --dir
238 # - libname, supplied_libname from --lib
239 # - sourcebase from --source-base
240 # - m4base from --m4-base
241 # - testsbase from --tests-base
242 # - auxdir from --aux-dir
243 # - inctests true if --with-tests was given, blank otherwise
244 # - avoidlist list of modules to avoid, from --avoid
245 # - lgpl true if --lgpl was given, blank otherwise
246 # - libtool true if --libtool was given, blank otherwise
247 # - do_changelog false if --no-changelog was given, : otherwise
248 # - doit : if actions shall be executed, false if only to be printed
269 while test $# -gt 0; do
274 --import | --impor | --impo | --imp | --im | --i )
277 --update | --updat | --upda | --upd | --up | --u )
280 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
283 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
284 mode=create-megatestdir
286 --test | --tes | --te | --t )
289 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
293 mode=`echo "X$1" | sed -e 's/^X--//'`
298 func_fatal_error "missing argument for --dir"
303 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
308 func_fatal_error "missing argument for --lib"
311 supplied_libname=true
314 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
315 supplied_libname=true
320 func_fatal_error "missing argument for --source-base"
325 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
330 func_fatal_error "missing argument for --m4-base"
335 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
340 func_fatal_error "missing argument for --tests-base"
345 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
350 func_fatal_error "missing argument for --aux-dir"
355 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
363 func_fatal_error "missing argument for --avoid"
365 avoidlist="$avoidlist $1"
368 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
379 func_fatal_error "missing argument for --macro-prefix"
384 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
386 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
392 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
395 --help | --hel | --he | --h )
398 --version | --versio | --versi | --vers | --ver | --ve | --v )
402 # Stop option processing
406 echo "gnulib-tool: unknown option $1" 1>&2
407 echo "Try 'gnulib-tool --help' for more information." 1>&2
414 if test "$mode" = update; then
415 if test $# != 0; then
416 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
417 echo "Try 'gnulib-tool --help' for more information." 1>&2
418 echo "If you really want to modify the gnulib configuration of your project," 1>&2
419 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
422 if test -n "$supplied_libname" || test -n "$sourcebase" || test -n "$m4base" \
423 || test -n "$testsbase" || test -n "$auxdir" || test -n "$inctests" \
424 || test -n "$avoidlist" || test -n "$lgpl" || test -n "$macro_prefix"; then
425 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
426 echo "Try 'gnulib-tool --help' for more information." 1>&2
427 echo "If you really want to modify the gnulib configuration of your project," 1>&2
428 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
434 # Remove trailing slashes from the directory names. This is necessary for
435 # m4base (to avoid an error in func_import) and optional for the others.
436 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
437 case "$sourcebase" in
438 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
441 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
444 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
447 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
452 /*) self_abspathname="$0" ;;
453 */*) self_abspathname=`pwd`/"$0" ;;
454 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
455 if test -x "$d/$0" && test ! -d "$d/$0"; then
456 self_abspathname="$d/$0"
460 if test -z "$self_abspathname"; then
461 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
465 while test -h "$self_abspathname"; do
466 # Resolve symbolic link.
467 linkval=`func_readlink "$self_abspathname"`
468 test -n "$linkval" || break
470 /* ) self_abspathname="$linkval" ;;
471 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
474 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
479 # Filter out metainformation files like README, which are not modules.
480 # Filter out unit test modules; they can be retrieved through
481 # --extract-tests-module if desired.
482 (cd "$gnulib_dir/modules" && ls -1) \
483 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
484 | sed -e '/-tests$/d' \
489 # verifies a module name
490 func_verify_module ()
492 if test ! -f "$gnulib_dir/modules/$module" \
493 || test "CVS" = "$module" \
494 || test "ChangeLog" = "$module" \
495 || test "README" = "$module" \
496 || test "TEMPLATE" = "$module" \
497 || test "TEMPLATE-TESTS" = "$module"; then
498 echo "gnulib-tool: module $module doesn't exist" 1>&2
503 # func_verify_nontests_module
504 # verifies a module name, excluding tests modules
505 func_verify_nontests_module ()
509 * ) func_verify_module ;;
513 # func_verify_tests_module
514 # verifies a module name, considering only tests modules
515 func_verify_tests_module ()
518 *-tests ) func_verify_module ;;
523 sed_extract_prog=':[ ]*$/ {
526 s/^Description:[ ]*$//
528 s/^Depends-on:[ ]*$//
529 s/^configure\.ac:[ ]*$//
530 s/^Makefile\.am:[ ]*$//
533 s/^Maintainer:[ ]*$//
540 # func_get_description module
541 func_get_description ()
543 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
546 # func_get_filelist module
549 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
551 echo m4/onceonly_2_57.m4
554 # func_get_dependencies module
555 func_get_dependencies ()
557 # ${module}-tests always implicitly depends on ${module}.
558 echo "$1" | sed -n -e 's/-tests//p'
559 # Then the explicit dependencies listed in the module description.
560 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
563 # func_get_autoconf_snippet module
564 func_get_autoconf_snippet ()
566 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
569 # func_get_automake_snippet module
570 func_get_automake_snippet ()
572 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
575 # func_get_include_directive module
576 func_get_include_directive ()
578 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
579 sed -e 's/^\(["<]\)/#include \1/'
582 # func_get_license module
585 sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
588 # func_get_maintainer module
589 func_get_maintainer ()
591 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
594 # func_get_tests_module module
595 func_get_tests_module ()
597 # The naming convention for tests modules is hardwired: ${module}-tests.
598 if test -f modules/"$1"-tests; then
603 # func_acceptable module
604 # tests whether a module is acceptable.
606 # - avoidlist list of modules to avoid
609 for avoid in $avoidlist; do
610 if test "$avoid" = "$1"; then
617 # func_modules_transitive_closure
619 # - modules list of specified modules
620 # - inctests true if tests should be included, blank otherwise
621 # - avoidlist list of modules to avoid
623 # - modules list of modules, including dependencies
624 func_modules_transitive_closure ()
628 for module in $modules; do
630 if test -n "$module"; then
631 # Duplicate dependencies are harmless, but Jim wants a warning.
632 duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
633 if test -n "$duplicated_deps"; then
634 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
636 if func_acceptable $module; then
637 xmodules="$xmodules $module"
638 for depmodule in `func_get_dependencies $module`; do
639 if func_acceptable $depmodule; then
640 xmodules="$xmodules $depmodule"
643 if test -n "$inctests"; then
644 testsmodule=`func_get_tests_module $module`
645 if test -n "$testsmodule"; then
646 if func_acceptable $testsmodule; then
647 xmodules="$xmodules $testsmodule"
648 for depmodule in `func_get_dependencies $testsmodule`; do
649 if func_acceptable $depmodule; then
650 xmodules="$xmodules $depmodule"
659 xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
660 if test "$xmodules" = "$modules"; then
667 # func_modules_add_dummy
669 # - modules list of modules, including dependencies
671 # - modules list of modules, including 'dummy' if needed
672 func_modules_add_dummy ()
675 sed_remove_backslash_newline=':a
682 for module in $modules; do
683 func_verify_nontests_module
684 if test -n "$module"; then
685 # Extract the value of "lib_SOURCES += ...".
686 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
687 # Ignore .h files since they are not compiled.
690 *) have_lib_SOURCES=yes ;;
695 # Add the dummy module, to make sure the library will be non-empty.
696 if test -z "$have_lib_SOURCES"; then
697 modules="$modules dummy"
701 # func_modules_to_filelist
703 # - modules list of modules, including dependencies
705 # - files list of files
706 func_modules_to_filelist ()
709 for module in $modules; do
711 if test -n "$module"; then
712 files="$files "`func_get_filelist $module`
715 files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
718 # func_emit_lib_Makefile_am
719 # emits the contents of lib/Makefile.am to standard output.
721 # - modules list of modules, including dependencies
722 # - libname library name
723 # - libtool true if libtool will be used, blank otherwise
724 # - actioncmd (optional) command that will reproduce this invocation
725 func_emit_lib_Makefile_am ()
727 if test -n "$libtool"; then
734 echo "## Process this file with automake to produce Makefile.in."
735 func_emit_copyright_notice
736 if test -n "$actioncmd"; then
737 echo "# Reproduce by: $actioncmd"
740 # No need to generate dependencies since the sources are in gnulib, not here.
741 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
743 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
745 echo "${libname}_${libext}_SOURCES ="
746 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
747 echo "noinst_HEADERS ="
749 echo "BUILT_SOURCES ="
751 echo "MOSTLYCLEANFILES ="
753 echo "DISTCLEANFILES ="
754 echo "MAINTAINERCLEANFILES ="
758 for module in $modules; do
759 func_verify_nontests_module
760 if test -n "$module"; then
762 func_get_automake_snippet "$module" |
763 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
764 if test "$module" = 'alloca'; then
765 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
768 # Skip the contents if its entirely empty.
769 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
770 echo "## begin gnulib module $module"
773 echo "## end gnulib module $module"
780 echo "# Makefile.am ends here"
783 # func_emit_tests_Makefile_am
784 # emits the contents of tests/Makefile.am to standard output.
786 # - modules list of modules, including dependencies
787 # - libname library name
788 # - libtool true if libtool will be used, blank otherwise
789 # - sourcebase relative directory containing lib source code
790 # - m4base relative directory containing autoconf macros
791 # - testsbase relative directory containing unit test code
792 func_emit_tests_Makefile_am ()
794 if test -n "$libtool"; then
799 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
800 echo "## Process this file with automake to produce Makefile.in."
801 func_emit_copyright_notice
803 # Generate dependencies here, since it eases the debugging of test failures.
804 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
806 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
808 # Nothing is being added to SUBDIRS; nevertheless the existence of this
809 # variable is needed to avoid an error from automake:
810 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
813 echo "TESTS_ENVIRONMENT ="
814 echo "noinst_PROGRAMS ="
815 echo "check_PROGRAMS ="
816 echo "noinst_HEADERS ="
818 echo "BUILT_SOURCES ="
820 echo "MOSTLYCLEANFILES ="
822 echo "DISTCLEANFILES ="
823 echo "MAINTAINERCLEANFILES ="
825 echo "AM_CPPFLAGS = \\"
826 echo " -I. -I\$(srcdir) \\"
827 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
828 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
830 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
832 for module in $modules; do
833 func_verify_tests_module
834 if test -n "$module"; then
835 func_get_automake_snippet "$module" > amsnippet.tmp
836 # Skip the contents if its entirely empty.
837 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
838 echo "## begin gnulib module $module"
841 echo "## end gnulib module $module"
847 echo "# Clean up after Solaris cc."
849 echo " rm -rf SunWS_cache"
851 echo "# Makefile.am ends here"
854 # func_import modules
855 # Uses also the variables
856 # - destdir target directory
857 # - libname library name
858 # - sourcebase directory relative to destdir where to place source code
859 # - m4base directory relative to destdir where to place *.m4 macros
860 # - testsbase directory relative to destdir where to place unit test code
861 # - auxdir directory relative to destdir where to place build aux files
862 # - inctests true if --with-tests was given, blank otherwise
863 # - avoidlist list of modules to avoid, from --avoid
864 # - lgpl true if library's license shall be LGPL, blank otherwise
865 # - libtool true if libtool will be used, blank otherwise
866 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
867 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
868 # - doit : if actions shall be executed, false if only to be printed
869 # - symbolic true if files should be symlinked, copied otherwise
872 # Get the cached settings.
873 cached_specified_modules=
883 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
889 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
892 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
895 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
898 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
901 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
904 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
907 s,^.*$,cached_lgpl=true,p
910 s,^.*$,cached_libtool=true,p
913 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
915 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
916 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
921 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
922 s,^.*$,cached_files=",p
934 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
938 # Merge the cached settings with the specified ones.
939 # The m4base must be the same as expected from the pathname.
940 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
941 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
943 # Append the cached and the specified module names. So that
944 # "gnulib-tool --import foo" means to add the module foo.
945 specified_modules="$cached_specified_modules $1"
946 # Append the cached and the specified avoidlist. This is probably better
947 # than dropping the cached one when --avoid is specified at least once.
948 avoidlist=`echo $cached_avoidlist $avoidlist`
949 # The sourcebase defaults to the cached one.
950 if test -z "$sourcebase"; then
951 sourcebase="$cached_sourcebase"
952 if test -z "$sourcebase"; then
953 func_fatal_error "missing --source-base option"
956 # The testsbase defaults to the cached one.
957 if test -z "$testsbase"; then
958 testsbase="$cached_testsbase"
959 if test -z "$testsbase"; then
960 func_fatal_error "missing --tests-base option"
963 # The libname defaults to the cached one.
964 if test -z "$supplied_libname"; then
965 libname="$cached_libname"
966 if test -z "$libname"; then
967 func_fatal_error "missing --lib option"
970 # Require LGPL if specified either way.
971 if test -z "$lgpl"; then
974 # Use libtool if specified either way, or if guessed.
975 if test -z "$libtool"; then
976 if test -n "$cached_m4base"; then
977 libtool="$cached_libtool"
979 libtool="$guessed_libtool"
982 # The macro_prefix defaults to the cached one.
983 if test -z "$macro_prefix"; then
984 macro_prefix="$cached_macro_prefix"
985 if test -z "$macro_prefix"; then
986 func_fatal_error "missing --macro-prefix option"
990 # Canonicalize the list of specified modules.
991 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
993 # Determine final module list.
994 modules="$specified_modules"
995 func_modules_transitive_closure
996 echo "Module list with included dependencies:"
997 echo "$modules" | sed -e 's/^/ /'
999 # Add the dummy module if needed.
1000 func_modules_add_dummy
1002 # If --lgpl, check the license of modules are compatible.
1003 if test -n "$lgpl"; then
1004 for module in $modules; do
1005 license=`func_get_license $module`
1007 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
1008 *) func_fatal_error "incompatible license on module $module: $license" ;;
1013 # Determine final file list.
1014 func_modules_to_filelist
1016 echo "$files" | sed -e 's/^/ /'
1019 || func_fatal_error "refusing to do nothing"
1021 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1022 new_files="$files m4/gnulib-tool.m4"
1023 old_files="$cached_files"
1024 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1025 old_files="$old_files m4/gnulib-tool.m4"
1028 # Create directories.
1029 if test ! -d "$destdir/$sourcebase"; then
1031 echo "Creating directory $destdir/$sourcebase"
1032 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1034 echo "Create directory $destdir/$sourcebase"
1037 if test ! -d "$destdir/$m4base"; then
1039 echo "Creating directory $destdir/$m4base"
1040 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1042 echo "Create directory $destdir/$m4base"
1045 if test -n "$inctests"; then
1046 if test ! -d "$destdir/$testsbase"; then
1048 echo "Creating directory $destdir/$testsbase"
1049 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1051 echo "Create directory $destdir/$testsbase"
1055 if test ! -d "$destdir/$auxdir"; then
1057 echo "Creating directory $destdir/$auxdir"
1058 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1060 echo "Create directory $destdir/$auxdir"
1065 trap 'rm -rf "$tmp"' 0 1 2 3 15
1066 # func_dest_tmpfilename file
1067 # determines the name of a temporary file (file is relative to destdir).
1069 # - tmpfile absolute filename of the temporary file
1070 func_dest_tmpfilename ()
1073 # Put the new contents of $file in a file in the same directory (needed
1074 # to guarantee that an 'mv' to "$destdir/$file" works).
1075 tmpfile="$destdir/$1.tmp"
1077 # Put the new contents of $file in a file in a temporary directory
1078 # (because the directory of "$file" might not exist).
1079 tmpfile="$tmp"/`basename "$1"`.tmp
1083 # Copy files or make symbolic links. Remove obsolete files.
1085 for f in $old_files; do
1087 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1088 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1089 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1090 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1093 echo "$g""$delimiter""$f"
1094 done | LC_ALL=C sort > "$tmp"/old-files
1095 for f in $new_files; do
1097 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1098 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1099 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1100 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1103 echo "$g""$delimiter""$f"
1104 done | LC_ALL=C sort > "$tmp"/new-files
1105 # First the files that are in old-files, but not in new-files:
1106 sed_take_first_column='s,'"$delimiter"'.*,,'
1107 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1108 # Remove the file. Do nothing if the user already removed it.
1109 if test -f "$destdir/$g"; then
1111 echo "Removing file $g (backup in ${g}~)"
1112 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1114 echo "Remove file $g (backup in ${g}~)"
1118 # func_add_or_update handles a file that ought to be present afterwards.
1119 # Uses parameters f, g, already_present.
1120 func_add_or_update ()
1122 func_dest_tmpfilename "$g"
1123 cp "$gnulib_dir/$f" "$tmpfile" || func_fatal_error "failed"
1124 if test -n "$lgpl"; then
1128 sed -e 's/GNU General/GNU Lesser General/g' \
1129 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1130 < "$gnulib_dir/$f" > "$tmpfile" || func_fatal_error "failed"
1134 if test -f "$destdir/$g"; then
1135 # The file already exists.
1136 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1137 : # The file has not changed.
1141 if test -n "$already_present"; then
1142 echo "Updating file $g (backup in ${g}~)"
1144 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1146 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1147 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1148 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1150 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1153 if test -n "$already_present"; then
1154 echo "Update file $g (backup in ${g}~)"
1156 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1162 # Don't protest if the file should be there but isn't: it happens
1163 # frequently that developers don't put autogenerated files into CVS.
1165 echo "Copying file $g"
1166 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1167 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1169 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1177 # Then the files that are in new-files, but not in old-files:
1178 sed_take_last_column='s,^.*'"$delimiter"',,'
1180 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1182 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1183 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1184 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1185 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1190 # Then the files that are in new-files and in old-files:
1191 already_present=true
1192 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1194 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1195 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1196 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1197 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1203 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1204 actioncmd="gnulib-tool --import"
1205 actioncmd="$actioncmd --dir=$destdir"
1206 actioncmd="$actioncmd --lib=$libname"
1207 actioncmd="$actioncmd --source-base=$sourcebase"
1208 actioncmd="$actioncmd --m4-base=$m4base"
1209 actioncmd="$actioncmd --aux-dir=$auxdir"
1210 for module in $avoidlist; do
1211 actioncmd="$actioncmd --avoid=$module"
1213 if test -n "$lgpl"; then
1214 actioncmd="$actioncmd --lgpl"
1216 if test -n "$libtool"; then
1217 actioncmd="$actioncmd --libtool"
1219 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1220 actioncmd="$actioncmd `echo $specified_modules`"
1222 # Create lib/Makefile.am.
1223 func_dest_tmpfilename $sourcebase/Makefile.am
1224 func_emit_lib_Makefile_am > "$tmpfile"
1225 if test -f "$destdir"/$sourcebase/Makefile.am; then
1226 if cmp "$destdir"/$sourcebase/Makefile.am "$tmpfile" > /dev/null; then
1230 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1231 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1232 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1234 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1240 echo "Creating $sourcebase/Makefile.am"
1241 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1243 echo "Create $sourcebase/Makefile.am"
1248 # Create m4/gnulib-cache.m4.
1249 func_dest_tmpfilename $m4base/gnulib-cache.m4
1251 func_emit_copyright_notice
1253 echo "# This file represents the specification of how gnulib-tool is used."
1254 echo "# It acts as a cache: It is written and read by gnulib-tool."
1255 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1256 echo "# like the configure.ac and various Makefile.am files."
1259 echo "# Specification in the form of a command-line invocation:"
1262 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1263 echo "gl_MODULES(["`echo $specified_modules`"])"
1264 echo "gl_AVOID([$avoidlist])"
1265 echo "gl_SOURCE_BASE([$sourcebase])"
1266 echo "gl_M4_BASE([$m4base])"
1267 echo "gl_TESTS_BASE([$testsbase])"
1268 echo "gl_LIB([$libname])"
1269 test -z "$lgpl" || echo "gl_LGPL"
1270 test -z "$libtool" || echo "gl_LIBTOOL"
1271 echo "gl_MACRO_PREFIX([$macro_prefix])"
1273 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1274 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1278 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1279 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1280 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1282 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1286 echo "# gnulib-cache.m4 ends here"
1293 echo "Creating $m4base/gnulib-cache.m4"
1294 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1296 echo "Create $m4base/gnulib-cache.m4"
1302 # Create m4/gnulib-comp.m4.
1303 func_dest_tmpfilename $m4base/gnulib-comp.m4
1305 func_emit_copyright_notice
1307 echo "# This file represents the compiled summary of the specification in"
1308 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1309 echo "# to be invoked from configure.ac."
1310 echo "# In projects using CVS, this file can be treated like other built files."
1313 echo "# This macro should be invoked from $configure_ac, in the section"
1314 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1315 echo "# any checks for libraries, header files, types and library functions."
1316 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1318 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1319 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1320 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1322 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1323 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1325 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1326 echo " AC_REQUIRE([gl_LOCK])"
1330 echo "# This macro should be invoked from $configure_ac, in the section"
1331 echo "# \"Check for header files, types and library functions\"."
1332 echo "AC_DEFUN([${macro_prefix}_INIT],"
1334 if test -z "$libtool"; then
1335 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1337 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1339 if test "$auxdir" != "build-aux"; then
1340 sed_replace_build_aux='
1342 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1343 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1346 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1348 sed_replace_build_aux=
1350 for module in $modules; do
1352 if test -n "$module"; then
1353 func_get_autoconf_snippet "$module" \
1354 | sed -e '/^$/d;' -e 's/^/ /' \
1355 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1356 -e "$sed_replace_build_aux"
1357 if test "$module" = 'alloca' && test -n "$libtool"; then
1358 echo 'changequote(,)dnl'
1359 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1360 echo 'changequote([, ])dnl'
1361 echo 'AC_SUBST([LTALLOCA])'
1367 echo "# This macro records the list of files which have been installed by"
1368 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1369 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1370 echo "$files" | sed -e 's,^, ,'
1373 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1374 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
1378 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1379 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1380 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1382 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1386 echo "# gnulib-comp.m4 ends here"
1393 echo "Creating $m4base/gnulib-comp.m4"
1394 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1396 echo "Create $m4base/gnulib-comp.m4"
1402 if test -n "$inctests"; then
1403 # Create tests/Makefile.am.
1404 func_dest_tmpfilename $testsbase/Makefile.am
1405 func_emit_tests_Makefile_am > "$tmpfile"
1406 if test -f "$destdir"/$testsbase/Makefile.am; then
1407 if cmp "$destdir"/$testsbase/Makefile.am "$tmpfile" > /dev/null; then
1411 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1412 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1413 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1415 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1421 echo "Creating $testsbase/Makefile.am"
1422 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1424 echo "Create $testsbase/Makefile.am"
1431 # Undo the effect of the previous 'trap' command. Some shellology:
1432 # We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
1433 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
1434 # exit); for the others we need to call 'exit' explicitly. The value of $? is
1435 # 128 + signal number and is set before the trap-registered command is run.
1437 trap 'exit $?' 1 2 3 15
1441 echo "You may need to add #include directives for the following .h files."
1443 # First the #include <...> directives without #ifs, sorted for convenience.
1444 for module in $modules; do
1445 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1448 func_get_include_directive "$module" | grep -v 'include "'
1450 done | LC_ALL=C sort -u
1451 # Then the #include "..." directives without #ifs, sorted for convenience.
1452 for module in $modules; do
1453 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1456 func_get_include_directive "$module" | grep 'include "'
1458 done | LC_ALL=C sort -u
1459 # Then the #include directives that are surrounded by #ifs. Not sorted.
1460 for module in $modules; do
1461 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1462 func_get_include_directive "$module"
1465 ) | sed -e '/^$/d;' -e 's/^/ /'
1467 echo "Don't forget to"
1468 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1469 if test -n "$inctests"; then
1470 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1472 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1473 sourcebase_base=`basename "$sourcebase"`
1474 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1475 if test -n "$inctests"; then
1476 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1477 testsbase_base=`basename "$testsbase"`
1478 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1480 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1481 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1482 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1485 # func_create_testdir testdir modules
1487 # - auxdir directory relative to destdir where to place build aux files
1488 func_create_testdir ()
1492 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1494 # Determine final module list.
1495 func_modules_transitive_closure
1496 echo "Module list with included dependencies:"
1497 echo "$modules" | sed -e 's/^/ /'
1499 # Add the dummy module if needed.
1500 func_modules_add_dummy
1502 # Determine final file list.
1503 func_modules_to_filelist
1505 echo "$files" | sed -e 's/^/ /'
1507 # Create directories.
1508 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1509 if test "$d" = build-aux; then
1510 mkdir -p "$testdir/$auxdir"
1512 mkdir -p "$testdir/$d"
1516 # Copy files or make symbolic links.
1519 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1522 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1523 if test -z "$symbolic"; then
1524 cp -p "$gnulib_dir/$f" "$testdir/$g"
1526 ln -s "$gnulib_dir/$f" "$testdir/$g"
1530 # Create lib/Makefile.am.
1531 mkdir -p "$testdir/lib"
1532 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1534 # Create m4/Makefile.am.
1535 mkdir -p "$testdir/m4"
1536 (echo "## Process this file with automake to produce Makefile.in."
1542 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1545 ) > "$testdir/m4/Makefile.am"
1548 subdirs_with_configure_ac=""
1550 if test -f "$testdir"/m4/gettext.m4; then
1551 # Avoid stupid error message from automake:
1552 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1553 mkdir -p "$testdir/po"
1554 (echo "## Process this file with automake to produce Makefile.in."
1555 ) > "$testdir/po/Makefile.am"
1556 subdirs="$subdirs po"
1559 if test -n "$inctests"; then
1560 test -d "$testdir/tests" || mkdir "$testdir/tests"
1561 # Create tests/Makefile.am.
1565 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1566 # Create tests/configure.ac.
1567 (echo "# Process this file with autoconf to produce a configure script."
1568 echo "AC_INIT([dummy], [0])"
1569 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1570 echo "AM_INIT_AUTOMAKE"
1572 echo "AM_CONFIG_HEADER([config.h])"
1575 echo "AC_PROG_INSTALL"
1576 echo "AC_PROG_MAKE_SET"
1577 echo "AC_PROG_RANLIB"
1579 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1580 echo "AC_GNU_SOURCE"
1583 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1584 echo "gl_USE_SYSTEM_EXTENSIONS"
1587 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1591 if test -z "$libtool"; then
1592 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1594 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1596 if test "$auxdir" != "build-aux"; then
1597 sed_replace_build_aux='
1599 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1600 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1603 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1605 sed_replace_build_aux=
1607 # We don't have explicit ordering constraints between the various
1608 # autoconf snippets. It's cleanest to put those of the library before
1609 # those of the tests.
1610 for module in $modules; do
1611 func_verify_nontests_module
1612 if test -n "$module"; then
1613 func_get_autoconf_snippet "$module" \
1614 | sed -e "$sed_replace_build_aux"
1617 for module in $modules; do
1618 func_verify_tests_module
1619 if test -n "$module"; then
1620 func_get_autoconf_snippet "$module" \
1621 | sed -e "$sed_replace_build_aux"
1625 # Usually tests/config.h will be a superset of config.h. Verify this by
1626 # "merging" config.h into tests/config.h; look out for gcc warnings.
1627 echo "AH_TOP([#include \"../config.h\"])"
1629 echo "AC_OUTPUT([Makefile])"
1630 ) > "$testdir/tests/configure.ac"
1631 subdirs="$subdirs tests"
1632 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1635 # Create Makefile.am.
1636 (echo "## Process this file with automake to produce Makefile.in."
1638 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1640 echo "SUBDIRS = $subdirs"
1642 echo "ACLOCAL_AMFLAGS = -I m4"
1643 ) > "$testdir/Makefile.am"
1645 # Create configure.ac.
1646 (echo "# Process this file with autoconf to produce a configure script."
1647 echo "AC_INIT([dummy], [0])"
1648 if test "$auxdir" != "."; then
1649 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1651 echo "AM_INIT_AUTOMAKE"
1653 echo "AM_CONFIG_HEADER([config.h])"
1656 echo "AC_PROG_INSTALL"
1657 echo "AC_PROG_MAKE_SET"
1658 echo "AC_PROG_RANLIB"
1660 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1661 echo "AC_GNU_SOURCE"
1664 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1665 echo "gl_USE_SYSTEM_EXTENSIONS"
1668 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1672 if test -z "$libtool"; then
1673 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1675 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1677 if test "$auxdir" != "build-aux"; then
1678 sed_replace_build_aux='
1680 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1681 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1684 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1686 sed_replace_build_aux=
1688 for module in $modules; do
1689 func_verify_nontests_module
1690 if test -n "$module"; then
1691 func_get_autoconf_snippet "$module" \
1692 | sed -e "$sed_replace_build_aux"
1696 if test -n "$subdirs_with_configure_ac"; then
1697 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1699 makefiles="Makefile"
1700 for d in $subdirs; do
1701 # For subdirs that have a configure.ac by their own, it's the subdir's
1702 # configure.ac which creates the subdir's Makefile.am, not this one.
1703 case " $subdirs_with_configure_ac " in
1705 *) makefiles="$makefiles $d/Makefile" ;;
1708 echo "AC_OUTPUT([$makefiles])"
1709 ) > "$testdir/configure.ac"
1711 # Create autogenerated files.
1713 echo "executing ${AUTORECONF} --force --install"
1714 ${AUTORECONF} --force --install
1716 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1720 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1728 # func_create_megatestdir megatestdir allmodules
1730 # - auxdir directory relative to destdir where to place build aux files
1731 func_create_megatestdir ()
1735 if test -z "$allmodules"; then
1736 allmodules=`func_all_modules`
1740 # First, all modules one by one.
1741 for onemodule in $allmodules; do
1742 func_create_testdir "$megatestdir/$onemodule" $onemodule
1743 megasubdirs="${megasubdirs}$onemodule "
1745 # Then, all modules all together.
1746 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1747 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1748 func_create_testdir "$megatestdir/ALL" "$allmodules"
1749 megasubdirs="${megasubdirs}ALL"
1751 # Create Makefile.am.
1752 (echo "## Process this file with automake to produce Makefile.in."
1754 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1756 echo "SUBDIRS = $megasubdirs"
1757 ) > "$megatestdir/Makefile.am"
1759 # Create configure.ac.
1760 (echo "# Process this file with autoconf to produce a configure script."
1761 echo "AC_INIT([dummy], [0])"
1762 if test "$auxdir" != "."; then
1763 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1765 echo "AM_INIT_AUTOMAKE"
1767 echo "AC_PROG_MAKE_SET"
1769 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1770 echo "AC_OUTPUT([Makefile])"
1771 ) > "$megatestdir/configure.ac"
1773 # Create autogenerated files.
1775 # Do not use "${AUTORECONF} --install", because autoreconf operates
1776 # recursively, but the subdirectories are already finished, therefore
1777 # calling autoreconf here would only waste lots of CPU time.
1778 echo "executing ${ACLOCAL}"
1780 echo "executing mkdir build-aux"
1782 echo "executing ${AUTOCONF}"
1784 echo "executing ${AUTOMAKE} --add-missing --copy"
1785 ${AUTOMAKE} --add-missing --copy
1791 func_fatal_error "no mode specified" ;;
1800 if test -z "$destdir"; then
1803 test -d "$destdir" \
1804 || func_fatal_error "destination directory does not exist: $destdir"
1806 # Prefer configure.ac to configure.in.
1807 if test -f "$destdir"/configure.ac; then
1808 configure_ac="$destdir/configure.ac"
1810 if test -f "$destdir"/configure.in; then
1811 configure_ac="$destdir/configure.in"
1813 func_fatal_error "cannot find $destdir/configure.ac"
1817 test -f "$destdir"/Makefile.am \
1818 || func_fatal_error "cannot find $destdir/Makefile.am"
1820 # Analyze configure.ac.
1827 /AC_CONFIG_AUX_DIR/ {
1828 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1830 /A[CM]_PROG_LIBTOOL/ {
1831 s,^.*$,guessed_libtool=true,p
1833 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1835 if test -z "$auxdir"; then
1836 auxdir="$guessed_auxdir"
1839 # Determine where to apply func_import.
1840 if test -n "$m4base"; then
1841 # Apply func_import to a particular gnulib directory.
1842 # Any number of additional modules can be given.
1843 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1844 # First use of gnulib in the given m4base.
1845 test -n "$supplied_libname" || supplied_libname=true
1846 test -n "$sourcebase" || sourcebase="lib"
1847 test -n "$testsbase" || testsbase="tests"
1848 test -n "$macro_prefix" || macro_prefix="gl"
1852 # Apply func_import to all gnulib directories.
1853 # To get this list of directories, look at Makefile.am. (Not at
1854 # configure, because it may be omitted from CVS. Also, don't run
1855 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1856 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
1860 for arg in $aclocal_amflags; do
1861 if test -n "$m4dir_is_next"; then
1862 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1866 if test -f "$destdir/$arg"/gnulib-cache.m4; then
1867 m4dirs="$m4dirs $arg"
1868 m4dirs_count=`expr $m4dirs_count + 1`
1873 if test "X$arg" = "X-I"; then
1880 if test $m4dirs_count = 0; then
1881 # First use of gnulib in a package.
1882 # Any number of additional modules can be given.
1883 test -n "$supplied_libname" || supplied_libname=true
1884 test -n "$sourcebase" || sourcebase="lib"
1886 test -n "$testsbase" || testsbase="tests"
1887 test -n "$macro_prefix" || macro_prefix="gl"
1890 if test $m4dirs_count = 1; then
1891 # There's only one use of gnulib here. Assume the user means it.
1892 # Any number of additional modules can be given.
1893 for m4base in $m4dirs; do
1897 # Ambiguous - guess what the user meant.
1898 if test $# = 0; then
1899 # No further arguments. Guess the user wants to update all of them.
1900 for m4base in $m4dirs; do
1905 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
1913 if test -z "$destdir"; then
1914 func_fatal_error "please specify --dir option"
1917 test -d "$destdir" \
1918 || func_fatal_error "could not create destination directory"
1919 test -n "$auxdir" || auxdir="build-aux"
1920 func_create_testdir "$destdir" "$*"
1923 create-megatestdir )
1924 if test -z "$destdir"; then
1925 func_fatal_error "please specify --dir option"
1927 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1928 test -n "$auxdir" || auxdir="build-aux"
1929 func_create_megatestdir "$destdir" "$*"
1933 test -n "$destdir" || destdir=testdir$$
1934 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1935 test -n "$auxdir" || auxdir="build-aux"
1936 func_create_testdir "$destdir" "$*"
1944 remaining=`find . -type f -print`
1945 if test -n "$remaining"; then
1946 echo "Remaining files:" $remaining 1>&2
1947 echo "gnulib-tool: *** Stop." 1>&2
1956 test -n "$destdir" || destdir=testdir$$
1957 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1958 test -n "$auxdir" || auxdir="build-aux"
1959 func_create_megatestdir "$destdir" "$*"
1967 remaining=`find . -type f -print`
1968 if test -n "$remaining"; then
1969 echo "Remaining files:" $remaining 1>&2
1970 echo "gnulib-tool: *** Stop." 1>&2
1978 extract-description )
1982 if test -n "$module"; then
1983 func_get_description "$module"
1992 if test -n "$module"; then
1993 func_get_filelist "$module"
1998 extract-dependencies )
2002 if test -n "$module"; then
2003 func_get_dependencies "$module"
2008 extract-autoconf-snippet )
2012 if test -n "$module"; then
2013 func_get_autoconf_snippet "$module"
2018 extract-automake-snippet )
2022 if test -n "$module"; then
2023 func_get_automake_snippet "$module"
2028 extract-include-directive )
2032 if test -n "$module"; then
2033 func_get_include_directive "$module"
2042 if test -n "$module"; then
2043 func_get_license "$module"
2048 extract-maintainer )
2052 if test -n "$module"; then
2053 func_get_maintainer "$module"
2058 extract-tests-module )
2062 if test -n "$module"; then
2063 func_get_tests_module "$module"
2069 func_fatal_error "unknown operation mode --$mode" ;;