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-01-25 14:20:06 $'
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 --create-testdir create a scratch package with the given modules
82 --create-megatestdir create a mega scratch package with the given modules
83 one by one and all together
84 --test test the combination of the given modules
85 (recommended to use CC=\"gcc -Wall\" here)
86 --megatest test the given modules one by one and all together
87 (recommended to use CC=\"gcc -Wall\" here)
88 --extract-description extract the description
89 --extract-filelist extract the list of files
90 --extract-dependencies extract the dependencies
91 --extract-autoconf-snippet extract the snippet for configure.ac
92 --extract-automake-snippet extract the snippet for lib/Makefile.am
93 --extract-include-directive extract the #include directive
94 --extract-license report the license terms of the source files
96 --extract-maintainer report the maintainer(s) inside gnulib
97 --extract-tests-module report the unit test module, if it exists
100 --dir=DIRECTORY specify the target directory
101 For --import, this specifies where your
102 configure.ac can be found. Defaults to current
104 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
105 --source-base=DIRECTORY
106 Directory relative --dir where source code is
107 placed (default \"lib\"), for --import.
108 --m4-base=DIRECTORY Directory relative --dir where *.m4 macros are
109 placed (default \"m4\"), for --import.
110 --tests-base=DIRECTORY
111 Directory relative --dir where unit tests are
112 placed (default \"tests\"), for --import.
113 --aux-dir=DIRECTORY Directory relative --dir where auxiliary build
114 tools are placed (default \"build-aux\").
115 --with-tests Include unit tests for the included modules.
116 --avoid=MODULE Avoid including the given MODULE. Useful if you
117 have code that provides equivalent functionality.
118 This option can be repeated.
119 --lgpl Abort if modules aren't available under the LGPL.
120 Also modify license template from GPL to LGPL.
121 --libtool Use libtool rules, for --import.
122 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
123 'gl_INIT'. Default is 'gl'.
124 --no-changelog don't update or create ChangeLog files
125 --dry-run For --import, only print what would have been done.
126 -s, --symbolic, --symlink Make symbolic links instead of copying files.
128 Report bugs to <bug-gnulib@gnu.org>."
132 # outputs to stdout the --version message.
135 echo "$progname (GNU $package) $version"
136 echo "Copyright (C) 2002-2005 Free Software Foundation, Inc.
137 This is free software; see the source for copying conditions. There is NO
138 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
139 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
143 # creates a temporary directory.
145 # - tmp pathname of freshly created temporary directory
148 # Use the environment variable TMPDIR, falling back to /tmp. This allows
149 # users to specify a different temporary directory, for example, if their
150 # /tmp is filled up or too small.
153 # Use the mktemp program if available. If not available, hide the error
155 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
156 test -n "$tmp" && test -d "$tmp"
159 # Use a simple mkdir command. It is guaranteed to fail if the directory
160 # already exists. $RANDOM is bash specific and expands to empty in shells
161 # other than bash, ksh and zsh. Its use does not increase security;
162 # rather, it minimizes the probability of failure in a very cluttered /tmp
164 tmp=$TMPDIR/gl$$-$RANDOM
165 (umask 077 && mkdir "$tmp")
168 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
169 { (exit 1); exit 1; }
173 # func_fatal_error message
174 # outputs to stderr a fatal error message, and terminates the program.
177 echo "gnulib-tool: *** $1" 1>&2
178 echo "gnulib-tool: *** Stop." 1>&2
182 # func_readlink SYMLINK
183 # outputs the target of the given symlink.
184 if (type -p readlink) > /dev/null 2>&1; then
187 # Use the readlink program from GNU coreutils.
193 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
194 # would do the wrong thing if the link target contains " -> ".
195 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
199 # func_ln_if_changed SRC DEST
200 # Like ln -s, but avoids munging timestamps if the link is correct.
201 func_ln_if_changed ()
203 if test $# -ne 2; then
204 echo "usage: func_ln_if_changed SRC DEST" >&2
206 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
214 # Command-line option processing.
215 # Removes the OPTIONS from the arguments. Sets the variables:
216 # - mode list or import or create-testdir or create-megatestdir
217 # - destdir from --dir
218 # - libname, supplied_libname from --lib
219 # - sourcebase from --source-base
220 # - m4base from --m4-base
221 # - testsbase from --tests-base
222 # - auxdir from --aux-dir
223 # - inctests true if --with-tests was given, blank otherwise
224 # - avoidlist list of modules to avoid, from --avoid
225 # - lgpl true if --lgpl was given, blank otherwise
226 # - libtool true if --libtool was given, blank otherwise
227 # - do_changelog false if --no-changelog was given, : otherwise
228 # - doit : if actions shall be executed, false if only to be printed
249 while test $# -gt 0; do
254 --import | --impor | --impo | --imp | --im | --i )
257 --update | --updat | --upda | --upd | --up | --u )
260 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
263 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
264 mode=create-megatestdir
266 --test | --tes | --te | --t )
269 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
273 mode=`echo "X$1" | sed -e 's/^X--//'`
278 func_fatal_error "missing argument for --dir"
283 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
288 func_fatal_error "missing argument for --lib"
291 supplied_libname=true
294 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
295 supplied_libname=true
300 func_fatal_error "missing argument for --source-base"
305 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
310 func_fatal_error "missing argument for --m4-base"
315 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
320 func_fatal_error "missing argument for --tests-base"
325 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
330 func_fatal_error "missing argument for --aux-dir"
335 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
343 func_fatal_error "missing argument for --avoid"
345 avoidlist="$avoidlist $1"
348 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
359 func_fatal_error "missing argument for --macro-prefix"
364 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
366 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
372 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
375 --help | --hel | --he | --h )
378 --version | --versio | --versi | --vers | --ver | --ve | --v )
382 # Stop option processing
386 echo "gnulib-tool: unknown option $1" 1>&2
387 echo "Try 'gnulib-tool --help' for more information." 1>&2
394 if test "$mode" = update; then
395 if test $# != 0; then
396 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
397 echo "Try 'gnulib-tool --help' for more information." 1>&2
398 echo "If you really want to modify the gnulib configuration of your project," 1>&2
399 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
402 if test -n "$libname" || test -n "$sourcebase" || test -n "$m4base" \
403 || test -n "$testsbase" || test -n "$auxdir" || test -n "$inctests" \
404 || test -n "$avoidlist" || test -n "$lgpl" || test -n "$macro_prefix"; then
405 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
406 echo "Try 'gnulib-tool --help' for more information." 1>&2
407 echo "If you really want to modify the gnulib configuration of your project," 1>&2
408 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
414 # Remove trailing slashes from the directory names. This is necessary for
415 # m4base (to avoid an error in func_import) and optional for the others.
416 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
417 case "$sourcebase" in
418 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
421 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
424 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
427 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
432 /*) self_abspathname="$0" ;;
433 */*) self_abspathname=`pwd`/"$0" ;;
434 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
435 if test -x "$d/$0" && test ! -d "$d/$0"; then
436 self_abspathname="$d/$0"
440 if test -z "$self_abspathname"; then
441 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
445 while test -h "$self_abspathname"; do
446 # Resolve symbolic link.
447 linkval=`func_readlink "$self_abspathname"`
448 test -n "$linkval" || break
450 /* ) self_abspathname="$linkval" ;;
451 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
454 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
459 # Filter out metainformation files like README, which are not modules.
460 # Filter out unit test modules; they can be retrieved through
461 # --extract-tests-module if desired.
462 (cd "$gnulib_dir/modules" && ls -1) \
463 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
464 | sed -e '/-tests$/d' \
469 # verifies a module name
470 func_verify_module ()
472 if test ! -f "$gnulib_dir/modules/$module" \
473 || test "CVS" = "$module" \
474 || test "ChangeLog" = "$module" \
475 || test "README" = "$module" \
476 || test "TEMPLATE" = "$module" \
477 || test "TEMPLATE-TESTS" = "$module"; then
478 echo "gnulib-tool: module $module doesn't exist" 1>&2
483 # func_verify_nontests_module
484 # verifies a module name, excluding tests modules
485 func_verify_nontests_module ()
489 * ) func_verify_module ;;
493 # func_verify_tests_module
494 # verifies a module name, considering only tests modules
495 func_verify_tests_module ()
498 *-tests ) func_verify_module ;;
503 sed_extract_prog=':[ ]*$/ {
506 s/^Description:[ ]*$//
508 s/^Depends-on:[ ]*$//
509 s/^configure\.ac:[ ]*$//
510 s/^Makefile\.am:[ ]*$//
513 s/^Maintainer:[ ]*$//
520 # func_get_description module
521 func_get_description ()
523 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
526 # func_get_filelist module
529 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
531 echo m4/onceonly_2_57.m4
534 # func_get_dependencies module
535 func_get_dependencies ()
537 # ${module}-tests always implicitly depends on ${module}.
538 echo "$1" | sed -n -e 's/-tests//p'
539 # Then the explicit dependencies listed in the module description.
540 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
543 # func_get_autoconf_snippet module
544 func_get_autoconf_snippet ()
546 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
549 # func_get_automake_snippet module
550 func_get_automake_snippet ()
552 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
555 # func_get_include_directive module
556 func_get_include_directive ()
558 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
559 sed -e 's/^\(["<]\)/#include \1/'
562 # func_get_license module
565 sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
568 # func_get_maintainer module
569 func_get_maintainer ()
571 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
574 # func_get_tests_module module
575 func_get_tests_module ()
577 # The naming convention for tests modules is hardwired: ${module}-tests.
578 if test -f modules/"$1"-tests; then
583 # func_acceptable module
584 # tests whether a module is acceptable.
586 # - avoidlist list of modules to avoid
589 for avoid in $avoidlist; do
590 if test "$avoid" = "$1"; then
597 # func_modules_transitive_closure
599 # - modules list of specified modules
600 # - inctests true if tests should be included, blank otherwise
601 # - avoidlist list of modules to avoid
603 # - modules list of modules, including dependencies
604 func_modules_transitive_closure ()
608 for module in $modules; do
610 if test -n "$module"; then
611 # Duplicate dependencies are harmless, but Jim wants a warning.
612 duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
613 if test -n "$duplicated_deps"; then
614 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
616 if func_acceptable $module; then
617 xmodules="$xmodules $module"
618 for depmodule in `func_get_dependencies $module`; do
619 if func_acceptable $depmodule; then
620 xmodules="$xmodules $depmodule"
623 if test -n "$inctests"; then
624 testsmodule=`func_get_tests_module $module`
625 if test -n "$testsmodule"; then
626 if func_acceptable $testsmodule; then
627 xmodules="$xmodules $testsmodule"
628 for depmodule in `func_get_dependencies $testsmodule`; do
629 if func_acceptable $depmodule; then
630 xmodules="$xmodules $depmodule"
639 xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
640 if test "$xmodules" = "$modules"; then
647 # func_modules_add_dummy
649 # - modules list of modules, including dependencies
651 # - modules list of modules, including 'dummy' if needed
652 func_modules_add_dummy ()
655 sed_remove_backslash_newline=':a
662 for module in $modules; do
663 func_verify_nontests_module
664 if test -n "$module"; then
665 # Extract the value of "lib_SOURCES += ...".
666 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
667 # Ignore .h files since they are not compiled.
670 *) have_lib_SOURCES=yes ;;
675 # Add the dummy module, to make sure the library will be non-empty.
676 if test -z "$have_lib_SOURCES"; then
677 modules="$modules dummy"
681 # func_modules_to_filelist
683 # - modules list of modules, including dependencies
685 # - files list of files
686 func_modules_to_filelist ()
689 for module in $modules; do
691 if test -n "$module"; then
692 files="$files "`func_get_filelist $module`
695 files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
698 # func_emit_lib_Makefile_am
699 # emits the contents of lib/Makefile.am to standard output.
701 # - modules list of modules, including dependencies
702 # - libname library name
703 # - libtool true if libtool will be used, blank otherwise
704 # - actioncmd (optional) command that will reproduce this invocation
705 func_emit_lib_Makefile_am ()
707 if test -n "$libtool"; then
714 echo "## Process this file with automake to produce Makefile.in."
715 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
717 echo "# This file is free software, distributed under the terms of the GNU"
718 echo "# General Public License. As a special exception to the GNU General"
719 echo "# Public License, this file may be distributed as part of a program"
720 echo "# that contains a configuration script generated by Automake, under"
721 echo "# the same distribution terms as the rest of that program."
723 echo "# Generated by gnulib-tool."
724 if test -n "$actioncmd"; then
725 echo "# Reproduce by: $actioncmd"
728 # No need to generate dependencies since the sources are in gnulib, not here.
729 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
731 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
733 echo "${libname}_${libext}_SOURCES ="
734 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
735 echo "noinst_HEADERS ="
737 echo "BUILT_SOURCES ="
739 echo "MOSTLYCLEANFILES ="
741 echo "DISTCLEANFILES ="
742 echo "MAINTAINERCLEANFILES ="
744 for module in $modules; do
745 func_verify_nontests_module
746 if test -n "$module"; then
748 func_get_automake_snippet "$module" |
749 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
750 if test "$module" = 'alloca'; then
751 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
754 # Skip the contents if its entirely empty.
755 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
756 echo "## begin gnulib module $module"
759 echo "## end gnulib module $module"
766 echo "# Makefile.am ends here"
769 # func_emit_tests_Makefile_am
770 # emits the contents of tests/Makefile.am to standard output.
772 # - modules list of modules, including dependencies
773 # - libname library name
774 # - libtool true if libtool will be used, blank otherwise
775 # - sourcebase relative directory containing lib source code
776 # - m4base relative directory containing autoconf macros
777 # - testsbase relative directory containing unit test code
778 func_emit_tests_Makefile_am ()
780 if test -n "$libtool"; then
785 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
786 echo "## Process this file with automake to produce Makefile.in."
787 echo "# Copyright (C) 2004-2005 Free Software Foundation, Inc."
789 echo "# This file is free software, distributed under the terms of the GNU"
790 echo "# General Public License. As a special exception to the GNU General"
791 echo "# Public License, this file may be distributed as part of a program"
792 echo "# that contains a configuration script generated by Automake, under"
793 echo "# the same distribution terms as the rest of that program."
795 echo "# Generated by gnulib-tool."
797 # Generate dependencies here, since it eases the debugging of test failures.
798 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
800 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
802 # Nothing is being added to SUBDIRS; nevertheless the existence of this
803 # variable is needed to avoid an error from automake:
804 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
807 echo "TESTS_ENVIRONMENT ="
808 echo "noinst_PROGRAMS ="
809 echo "check_PROGRAMS ="
810 echo "noinst_HEADERS ="
812 echo "BUILT_SOURCES ="
814 echo "MOSTLYCLEANFILES ="
816 echo "DISTCLEANFILES ="
817 echo "MAINTAINERCLEANFILES ="
819 echo "AM_CPPFLAGS = \\"
820 echo " -I. -I\$(srcdir) \\"
821 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
822 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
824 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
826 for module in $modules; do
827 func_verify_tests_module
828 if test -n "$module"; then
829 func_get_automake_snippet "$module" > amsnippet.tmp
830 # Skip the contents if its entirely empty.
831 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
832 echo "## begin gnulib module $module"
835 echo "## end gnulib module $module"
841 echo "# Clean up after Solaris cc."
843 echo " rm -rf SunWS_cache"
845 echo "# Makefile.am ends here"
848 # func_import modules
849 # Uses also the variables
850 # - destdir target directory
851 # - libname library name
852 # - sourcebase directory relative to destdir where to place source code
853 # - m4base directory relative to destdir where to place *.m4 macros
854 # - testsbase directory relative to destdir where to place unit test code
855 # - auxdir directory relative to destdir where to place build aux files
856 # - inctests true if --with-tests was given, blank otherwise
857 # - avoidlist list of modules to avoid, from --avoid
858 # - lgpl true if library's license shall be LGPL, blank otherwise
859 # - libtool true if libtool will be used, blank otherwise
860 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
861 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
862 # - doit : if actions shall be executed, false if only to be printed
863 # - symbolic true if files should be symlinked, copied otherwise
866 # Get the cached settings.
867 cached_specified_modules=
877 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
883 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
886 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
889 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
892 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
895 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
898 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
901 s,^.*$,cached_lgpl=true,p
904 s,^.*$,cached_libtool=true,p
907 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
909 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
910 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
915 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
916 s,^.*$,cached_files=",p
928 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
932 # Merge the cached settings with the specified ones.
933 # The m4base must be the same as expected from the pathname.
934 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
935 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
937 # Append the cached and the specified module names. So that
938 # "gnulib-tool --import foo" means to add the module foo.
939 specified_modules="$cached_specified_modules $1"
940 # Append the cached and the specified avoidlist. This is probably better
941 # than dropping the cached one when --avoid is specified at least once.
942 avoidlist=`echo $cached_avoidlist $avoidlist`
943 # The sourcebase defaults to the cached one.
944 if test -z "$sourcebase"; then
945 sourcebase="$cached_sourcebase"
946 if test -z "$sourcebase"; then
947 func_fatal_error "missing --source-base option"
950 # The testsbase defaults to the cached one.
951 if test -z "$testsbase"; then
952 testsbase="$cached_testsbase"
953 if test -z "$testsbase"; then
954 func_fatal_error "missing --tests-base option"
957 # The libname defaults to the cached one.
958 if test -z "$supplied_libname"; then
959 libname="$cached_libname"
960 if test -z "$libname"; then
961 func_fatal_error "missing --lib option"
964 # Require LGPL if specified either way.
965 if test -z "$lgpl"; then
968 # Use libtool if specified either way, or if guessed.
969 if test -z "$libtool"; then
970 if test -n "$cached_m4base"; then
971 libtool="$cached_libtool"
973 libtool="$guessed_libtool"
976 # The macro_prefix defaults to the cached one.
977 if test -z "$macro_prefix"; then
978 macro_prefix="$cached_macro_prefix"
979 if test -z "$macro_prefix"; then
980 func_fatal_error "missing --macro-prefix option"
984 # Canonicalize the list of specified modules.
985 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
987 # Determine final module list.
988 modules="$specified_modules"
989 func_modules_transitive_closure
990 echo "Module list with included dependencies:"
991 echo "$modules" | sed -e 's/^/ /'
993 # Add the dummy module if needed.
994 func_modules_add_dummy
996 # If --lgpl, check the license of modules are compatible.
997 if test -n "$lgpl"; then
998 for module in $modules; do
999 license=`func_get_license $module`
1001 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
1002 *) func_fatal_error "incompatible license on module $module: $license" ;;
1007 # Determine final file list.
1008 func_modules_to_filelist
1010 echo "$files" | sed -e 's/^/ /'
1013 || func_fatal_error "refusing to do nothing"
1015 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1016 new_files="$files m4/gnulib-tool.m4"
1017 old_files="$cached_files"
1018 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1019 old_files="$old_files m4/gnulib-tool.m4"
1022 # Create directories.
1023 if test ! -d "$destdir/$sourcebase"; then
1025 echo "Creating directory $destdir/$sourcebase"
1026 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1028 echo "Create directory $destdir/$sourcebase"
1031 if test ! -d "$destdir/$m4base"; then
1033 echo "Creating directory $destdir/$m4base"
1034 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1036 echo "Create directory $destdir/$m4base"
1039 if test -n "$inctests"; then
1040 if test ! -d "$destdir/$testsbase"; then
1042 echo "Creating directory $destdir/$testsbase"
1043 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1045 echo "Create directory $destdir/$testsbase"
1049 if test ! -d "$destdir/$auxdir"; then
1051 echo "Creating directory $destdir/$auxdir"
1052 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1054 echo "Create directory $destdir/$auxdir"
1058 # Copy files or make symbolic links. Remove obsolete files.
1060 trap 'rm -rf "$tmp"' 0 1 2 3 15
1062 for f in $old_files; do
1064 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1065 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1066 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1067 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1070 echo "$g""$delimiter""$f"
1071 done | LC_ALL=C sort > "$tmp"/old-files
1072 for f in $new_files; do
1074 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1075 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1076 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1077 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1080 echo "$g""$delimiter""$f"
1081 done | LC_ALL=C sort > "$tmp"/new-files
1082 # First the files that are in old-files, but not in new-files:
1083 sed_take_first_column='s,'"$delimiter"'.*,,'
1084 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1085 # Remove the file. Do nothing if the user already removed it.
1086 if test -f "$destdir/$g"; then
1088 echo "Removing file $g (backup in ${g}~)"
1089 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1091 echo "Remove file $g (backup in ${g}~)"
1095 # func_add_or_update handles a file that ought to be present afterwards.
1096 # Uses parameters f, g, already_present.
1097 func_add_or_update ()
1099 cp "$gnulib_dir/$f" "$destdir/$g.tmp" || func_fatal_error "failed"
1100 if test -n "$lgpl"; then
1104 sed -e 's/GNU General/GNU Lesser General/g' \
1105 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1106 < "$gnulib_dir/$f" > "$destdir/$g.tmp" || func_fatal_error "failed"
1110 if test -f "$destdir/$g"; then
1111 # The file already exists.
1112 if cmp "$destdir/$g" "$destdir/$g.tmp" > /dev/null; then
1113 : # The file has not changed.
1117 if test -n "$already_present"; then
1118 echo "Updating file $g (backup in ${g}~)"
1120 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1122 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1123 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$destdir/$g.tmp" > /dev/null; then
1124 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1126 mv -f "$destdir/$g.tmp" "$destdir/${g}" || func_fatal_error "failed"
1129 if test -n "$already_present"; then
1130 echo "Update file $g (backup in ${g}~)"
1132 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1138 # Don't protest if the file should be there but isn't: it happens
1139 # frequently that developers don't put autogenerated files into CVS.
1141 echo "Copying file $g"
1142 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$destdir/$g.tmp" > /dev/null; then
1143 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1145 mv -f "$destdir/$g.tmp" "$destdir/${g}" || func_fatal_error "failed"
1151 rm -f "$destdir/$g.tmp"
1153 # Then the files that are in new-files, but not in old-files:
1154 sed_take_last_column='s,^.*'"$delimiter"',,'
1156 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1158 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1159 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1160 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1161 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1166 # Then the files that are in new-files and in old-files:
1167 already_present=true
1168 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1170 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1171 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1172 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1173 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1181 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1182 actioncmd="gnulib-tool --import"
1183 actioncmd="$actioncmd --dir=$destdir"
1184 actioncmd="$actioncmd --lib=$libname"
1185 actioncmd="$actioncmd --source-base=$sourcebase"
1186 actioncmd="$actioncmd --m4-base=$m4base"
1187 actioncmd="$actioncmd --aux-dir=$auxdir"
1188 for module in $avoidlist; do
1189 actioncmd="$actioncmd --avoid=$module"
1191 if test -n "$lgpl"; then
1192 actioncmd="$actioncmd --lgpl"
1194 if test -n "$libtool"; then
1195 actioncmd="$actioncmd --libtool"
1197 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1198 actioncmd="$actioncmd `echo $specified_modules`"
1200 # Create lib/Makefile.am.
1201 func_emit_lib_Makefile_am > "$destdir"/$sourcebase/Makefile.am.tmp
1202 if test -f "$destdir"/$sourcebase/Makefile.am; then
1203 if cmp "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am.tmp > /dev/null; then
1204 rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1207 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1208 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1209 mv -f "$destdir"/$sourcebase/Makefile.am.tmp "$destdir"/$sourcebase/Makefile.am
1211 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1212 rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1217 echo "Creating $sourcebase/Makefile.am"
1218 mv -f "$destdir"/$sourcebase/Makefile.am.tmp "$destdir"/$sourcebase/Makefile.am
1220 echo "Create $sourcebase/Makefile.am"
1221 rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1225 # Create m4/gnulib-cache.m4.
1227 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1228 echo "# This file is free software, distributed under the terms of the GNU"
1229 echo "# General Public License. As a special exception to the GNU General"
1230 echo "# Public License, this file may be distributed as part of a program"
1231 echo "# that contains a configuration script generated by Autoconf, under"
1232 echo "# the same distribution terms as the rest of that program."
1234 echo "# Generated by gnulib-tool."
1236 echo "# This file represents the specification of how gnulib-tool is used."
1237 echo "# It acts as a cache: It is written and read by gnulib-tool."
1238 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1239 echo "# like the configure.ac and various Makefile.am files."
1242 echo "# Specification in the form of a command-line invocation:"
1245 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1246 echo "gl_MODULES(["`echo $specified_modules`"])"
1247 echo "gl_AVOID([$avoidlist])"
1248 echo "gl_SOURCE_BASE([$sourcebase])"
1249 echo "gl_M4_BASE([$m4base])"
1250 echo "gl_TESTS_BASE([$testsbase])"
1251 echo "gl_LIB([$libname])"
1252 test -z "$lgpl" || echo "gl_LGPL"
1253 test -z "$libtool" || echo "gl_LIBTOOL"
1254 echo "gl_MACRO_PREFIX([$macro_prefix])"
1255 ) > "$destdir"/$m4base/gnulib-cache.m4.tmp
1256 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1257 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4.tmp > /dev/null; then
1258 rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1261 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1262 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1263 mv -f "$destdir"/$m4base/gnulib-cache.m4.tmp "$destdir"/$m4base/gnulib-cache.m4
1265 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1267 cat "$destdir"/$m4base/gnulib-cache.m4.tmp
1269 echo "# gnulib-cache.m4 ends here"
1271 rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1276 echo "Creating $m4base/gnulib-cache.m4"
1277 mv -f "$destdir"/$m4base/gnulib-cache.m4.tmp "$destdir"/$m4base/gnulib-cache.m4
1279 echo "Create $m4base/gnulib-cache.m4"
1280 cat "$destdir"/$m4base/gnulib-cache.m4.tmp
1281 rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1285 # Create m4/gnulib-comp.m4.
1287 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1288 echo "# This file is free software, distributed under the terms of the GNU"
1289 echo "# General Public License. As a special exception to the GNU General"
1290 echo "# Public License, this file may be distributed as part of a program"
1291 echo "# that contains a configuration script generated by Autoconf, under"
1292 echo "# the same distribution terms as the rest of that program."
1294 echo "# Generated by gnulib-tool."
1296 echo "# This file represents the compiled summary of the specification in"
1297 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1298 echo "# to be invoked from configure.ac."
1299 echo "# In projects using CVS, this file can be treated like other built files."
1302 echo "# This macro should be invoked from $configure_ac, in the section"
1303 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1304 echo "# any checks for libraries, header files, types and library functions."
1305 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1307 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1308 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 > /dev/null; then
1309 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1311 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 > /dev/null; then
1312 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1314 if grep gl_LOCK "$destdir"/$m4base/*.m4 > /dev/null; then
1315 echo " AC_REQUIRE([gl_LOCK])"
1319 echo "# This macro should be invoked from $configure_ac, in the section"
1320 echo "# \"Check for header files, types and library functions\"."
1321 echo "AC_DEFUN([${macro_prefix}_INIT],"
1323 if test -z "$libtool"; then
1324 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1326 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1328 if test "$auxdir" != "build-aux"; then
1329 sed_replace_build_aux='
1331 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1332 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1335 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1337 sed_replace_build_aux=
1339 for module in $modules; do
1341 if test -n "$module"; then
1342 func_get_autoconf_snippet "$module" \
1343 | sed -e '/^$/d;' -e 's/^/ /' \
1344 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1345 -e "$sed_replace_build_aux"
1346 if test "$module" = 'alloca' && test -n "$libtool"; then
1347 echo 'changequote(,)dnl'
1348 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1349 echo 'changequote([, ])dnl'
1350 echo 'AC_SUBST([LTALLOCA])'
1356 echo "# This macro records the list of files which have been installed by"
1357 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1358 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1359 echo "$files" | sed -e 's,^, ,'
1361 ) > "$destdir"/$m4base/gnulib-comp.m4.tmp
1362 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1363 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4.tmp > /dev/null; then
1364 rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1367 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1368 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1369 mv -f "$destdir"/$m4base/gnulib-comp.m4.tmp "$destdir"/$m4base/gnulib-comp.m4
1371 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1373 cat "$destdir"/$m4base/gnulib-comp.m4.tmp
1375 echo "# gnulib-comp.m4 ends here"
1377 rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1382 echo "Creating $m4base/gnulib-comp.m4"
1383 mv -f "$destdir"/$m4base/gnulib-comp.m4.tmp "$destdir"/$m4base/gnulib-comp.m4
1385 echo "Create $m4base/gnulib-comp.m4"
1386 cat "$destdir"/$m4base/gnulib-comp.m4.tmp
1387 rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1391 if test -n "$inctests"; then
1392 # Create tests/Makefile.am.
1393 func_emit_tests_Makefile_am > "$destdir"/$testsbase/Makefile.am.tmp
1394 if test -f "$destdir"/$testsbase/Makefile.am; then
1395 if cmp "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am.tmp > /dev/null; then
1396 rm -f "$destdir"/$testsbase/Makefile.am.tmp
1399 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1400 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1401 mv -f "$destdir"/$testsbase/Makefile.am.tmp "$destdir"/$testsbase/Makefile.am
1403 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1404 rm -f "$destdir"/$testsbase/Makefile.am.tmp
1409 echo "Creating $testsbase/Makefile.am"
1410 mv -f "$destdir"/$testsbase/Makefile.am.tmp "$destdir"/$testsbase/Makefile.am
1412 echo "Create $testsbase/Makefile.am"
1413 rm -f "$destdir"/$testsbase/Makefile.am.tmp
1420 echo "You may need to add #include directives for the following .h files."
1421 for module in $modules; do
1422 func_get_include_directive "$module"
1423 done | LC_ALL=C sort -u | sed -e '/^$/d;' -e 's/^/ /'
1425 echo "Don't forget to"
1426 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1427 if test -n "$inctests"; then
1428 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1430 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1431 sourcebase_base=`basename "$sourcebase"`
1432 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1433 if test -n "$inctests"; then
1434 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1435 testsbase_base=`basename "$testsbase"`
1436 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1438 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1439 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1440 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1443 # func_create_testdir testdir modules
1445 # - auxdir directory relative to destdir where to place build aux files
1446 func_create_testdir ()
1450 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1452 # Determine final module list.
1453 func_modules_transitive_closure
1454 echo "Module list with included dependencies:"
1455 echo "$modules" | sed -e 's/^/ /'
1457 # Add the dummy module if needed.
1458 func_modules_add_dummy
1460 # Determine final file list.
1461 func_modules_to_filelist
1463 echo "$files" | sed -e 's/^/ /'
1465 # Create directories.
1466 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1467 if test "$d" = build-aux; then
1468 mkdir -p "$testdir/$auxdir"
1470 mkdir -p "$testdir/$d"
1474 # Copy files or make symbolic links.
1477 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1480 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1481 if test -z "$symbolic"; then
1482 cp -p "$gnulib_dir/$f" "$testdir/$g"
1484 ln -s "$gnulib_dir/$f" "$testdir/$g"
1488 # Create lib/Makefile.am.
1489 mkdir -p "$testdir/lib"
1490 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1492 # Create m4/Makefile.am.
1493 mkdir -p "$testdir/m4"
1494 (echo "## Process this file with automake to produce Makefile.in."
1500 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1503 ) > "$testdir/m4/Makefile.am"
1506 subdirs_with_configure_ac=""
1508 if test -f "$testdir"/m4/gettext.m4; then
1509 # Avoid stupid error message from automake:
1510 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1511 mkdir -p "$testdir/po"
1512 (echo "## Process this file with automake to produce Makefile.in."
1513 ) > "$testdir/po/Makefile.am"
1514 subdirs="$subdirs po"
1517 if test -n "$inctests"; then
1518 test -d "$testdir/tests" || mkdir "$testdir/tests"
1519 # Create tests/Makefile.am.
1523 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1524 # Create tests/configure.ac.
1525 (echo "# Process this file with autoconf to produce a configure script."
1526 echo "AC_INIT([dummy], [0])"
1527 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1528 echo "AM_INIT_AUTOMAKE"
1530 echo "AM_CONFIG_HEADER([config.h])"
1533 echo "AC_PROG_INSTALL"
1534 echo "AC_PROG_MAKE_SET"
1535 echo "AC_PROG_RANLIB"
1537 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
1538 echo "AC_GNU_SOURCE"
1541 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
1542 echo "gl_USE_SYSTEM_EXTENSIONS"
1545 if grep gl_LOCK "$testdir"/m4/*.m4 > /dev/null; then
1549 if test -z "$libtool"; then
1550 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1552 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1554 if test "$auxdir" != "build-aux"; then
1555 sed_replace_build_aux='
1557 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1558 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1561 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1563 sed_replace_build_aux=
1565 # We don't have explicit ordering constraints between the various
1566 # autoconf snippets. It's cleanest to put those of the library before
1567 # those of the tests.
1568 for module in $modules; do
1569 func_verify_nontests_module
1570 if test -n "$module"; then
1571 func_get_autoconf_snippet "$module" \
1572 | sed -e "$sed_replace_build_aux"
1575 for module in $modules; do
1576 func_verify_tests_module
1577 if test -n "$module"; then
1578 func_get_autoconf_snippet "$module" \
1579 | sed -e "$sed_replace_build_aux"
1583 # Usually tests/config.h will be a superset of config.h. Verify this by
1584 # "merging" config.h into tests/config.h; look out for gcc warnings.
1585 echo "AH_TOP([#include \"../config.h\"])"
1587 echo "AC_OUTPUT([Makefile])"
1588 ) > "$testdir/tests/configure.ac"
1589 subdirs="$subdirs tests"
1590 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1593 # Create Makefile.am.
1594 (echo "## Process this file with automake to produce Makefile.in."
1596 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1598 echo "SUBDIRS = $subdirs"
1600 echo "ACLOCAL_AMFLAGS = -I m4"
1601 ) > "$testdir/Makefile.am"
1603 # Create configure.ac.
1604 (echo "# Process this file with autoconf to produce a configure script."
1605 echo "AC_INIT([dummy], [0])"
1606 if test "$auxdir" != "."; then
1607 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1609 echo "AM_INIT_AUTOMAKE"
1611 echo "AM_CONFIG_HEADER([config.h])"
1614 echo "AC_PROG_INSTALL"
1615 echo "AC_PROG_MAKE_SET"
1616 echo "AC_PROG_RANLIB"
1618 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
1619 echo "AC_GNU_SOURCE"
1622 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
1623 echo "gl_USE_SYSTEM_EXTENSIONS"
1626 if grep gl_LOCK "$testdir"/m4/*.m4 > /dev/null; then
1630 if test -z "$libtool"; then
1631 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1633 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1635 if test "$auxdir" != "build-aux"; then
1636 sed_replace_build_aux='
1638 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1639 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1642 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1644 sed_replace_build_aux=
1646 for module in $modules; do
1647 func_verify_nontests_module
1648 if test -n "$module"; then
1649 func_get_autoconf_snippet "$module" \
1650 | sed -e "$sed_replace_build_aux"
1654 if test -n "$subdirs_with_configure_ac"; then
1655 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1657 makefiles="Makefile"
1658 for d in $subdirs; do
1659 # For subdirs that have a configure.ac by their own, it's the subdir's
1660 # configure.ac which creates the subdir's Makefile.am, not this one.
1661 case " $subdirs_with_configure_ac " in
1663 *) makefiles="$makefiles $d/Makefile" ;;
1666 echo "AC_OUTPUT([$makefiles])"
1667 ) > "$testdir/configure.ac"
1669 # Create autogenerated files.
1671 echo "executing ${AUTORECONF} --force --install"
1672 ${AUTORECONF} --force --install
1674 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1678 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1686 # func_create_megatestdir megatestdir allmodules
1688 # - auxdir directory relative to destdir where to place build aux files
1689 func_create_megatestdir ()
1693 if test -z "$allmodules"; then
1694 allmodules=`func_all_modules`
1698 # First, all modules one by one.
1699 for onemodule in $allmodules; do
1700 func_create_testdir "$megatestdir/$onemodule" $onemodule
1701 megasubdirs="${megasubdirs}$onemodule "
1703 # Then, all modules all together.
1704 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1705 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1706 func_create_testdir "$megatestdir/ALL" "$allmodules"
1707 megasubdirs="${megasubdirs}ALL"
1709 # Create Makefile.am.
1710 (echo "## Process this file with automake to produce Makefile.in."
1712 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1714 echo "SUBDIRS = $megasubdirs"
1715 ) > "$megatestdir/Makefile.am"
1717 # Create configure.ac.
1718 (echo "# Process this file with autoconf to produce a configure script."
1719 echo "AC_INIT([dummy], [0])"
1720 if test "$auxdir" != "."; then
1721 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1723 echo "AM_INIT_AUTOMAKE"
1725 echo "AC_PROG_MAKE_SET"
1727 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1728 echo "AC_OUTPUT([Makefile])"
1729 ) > "$megatestdir/configure.ac"
1731 # Create autogenerated files.
1733 # Do not use "${AUTORECONF} --install", because autoreconf operates
1734 # recursively, but the subdirectories are already finished, therefore
1735 # calling autoreconf here would only waste lots of CPU time.
1736 echo "executing ${ACLOCAL}"
1738 echo "executing mkdir build-aux"
1740 echo "executing ${AUTOCONF}"
1742 echo "executing ${AUTOMAKE} --add-missing --copy"
1743 ${AUTOMAKE} --add-missing --copy
1749 func_fatal_error "no mode specified" ;;
1758 if test -z "$destdir"; then
1761 test -d "$destdir" \
1762 || func_fatal_error "destination directory does not exist: $destdir"
1764 # Prefer configure.ac to configure.in.
1765 if test -f "$destdir"/configure.ac; then
1766 configure_ac="$destdir/configure.ac"
1768 if test -f "$destdir"/configure.in; then
1769 configure_ac="$destdir/configure.in"
1771 func_fatal_error "cannot find $destdir/configure.ac"
1775 test -f "$destdir"/Makefile.am \
1776 || func_fatal_error "cannot find $destdir/Makefile.am"
1778 # Analyze configure.ac.
1785 /AC_CONFIG_AUX_DIR/ {
1786 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1788 /A[CM]_PROG_LIBTOOL/ {
1789 s,^.*$,guessed_libtool=true,p
1791 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1793 if test -z "$auxdir"; then
1794 auxdir="$guessed_auxdir"
1797 # Determine where to apply func_import.
1798 if test -n "$m4base"; then
1799 # Apply func_import to a particular gnulib directory.
1800 # Any number of additional modules can be given.
1801 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1802 # First use of gnulib in the given m4base.
1803 test -n "$supplied_libname" || supplied_libname=true
1804 test -n "$sourcebase" || sourcebase="lib"
1805 test -n "$testsbase" || testsbase="tests"
1806 test -n "$macro_prefix" || macro_prefix="gl"
1810 # Apply func_import to all gnulib directories.
1811 # To get this list of directories, look at Makefile.am. (Not at
1812 # configure, because it may be omitted from CVS. Also, don't run
1813 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1814 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
1818 for arg in $aclocal_amflags; do
1819 if test -n "$m4dir_is_next"; then
1820 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1824 if test -f "$destdir/$arg"/gnulib-cache.m4; then
1825 m4dirs="$m4dirs $arg"
1826 m4dirs_count=`expr $m4dirs_count + 1`
1831 if test "X$arg" = "X-I"; then
1838 if test $m4dirs_count = 0; then
1839 # First use of gnulib in a package.
1840 # Any number of additional modules can be given.
1841 test -n "$supplied_libname" || supplied_libname=true
1842 test -n "$sourcebase" || sourcebase="lib"
1844 test -n "$testsbase" || testsbase="tests"
1845 test -n "$macro_prefix" || macro_prefix="gl"
1848 if test $m4dirs_count = 1; then
1849 # There's only one use of gnulib here. Assume the user means it.
1850 # Any number of additional modules can be given.
1851 for m4base in $m4dirs; do
1855 # Ambiguous - guess what the user meant.
1856 if test $# = 0; then
1857 # No further arguments. Guess the user wants to update all of them.
1858 for m4base in $m4dirs; do
1863 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
1871 if test -z "$destdir"; then
1872 func_fatal_error "please specify --dir option"
1875 test -d "$destdir" \
1876 || func_fatal_error "could not create destination directory"
1877 test -n "$auxdir" || auxdir="build-aux"
1878 func_create_testdir "$destdir" "$*"
1881 create-megatestdir )
1882 if test -z "$destdir"; then
1883 func_fatal_error "please specify --dir option"
1885 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1886 test -n "$auxdir" || auxdir="build-aux"
1887 func_create_megatestdir "$destdir" "$*"
1891 test -n "$destdir" || destdir=testdir$$
1892 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1893 test -n "$auxdir" || auxdir="build-aux"
1894 func_create_testdir "$destdir" "$*"
1902 remaining=`find . -type f -print`
1903 if test -n "$remaining"; then
1904 echo "Remaining files:" $remaining 1>&2
1905 echo "gnulib-tool: *** Stop." 1>&2
1914 test -n "$destdir" || destdir=testdir$$
1915 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1916 test -n "$auxdir" || auxdir="build-aux"
1917 func_create_megatestdir "$destdir" "$*"
1925 remaining=`find . -type f -print`
1926 if test -n "$remaining"; then
1927 echo "Remaining files:" $remaining 1>&2
1928 echo "gnulib-tool: *** Stop." 1>&2
1936 extract-description )
1940 if test -n "$module"; then
1941 func_get_description "$module"
1950 if test -n "$module"; then
1951 func_get_filelist "$module"
1956 extract-dependencies )
1960 if test -n "$module"; then
1961 func_get_dependencies "$module"
1966 extract-autoconf-snippet )
1970 if test -n "$module"; then
1971 func_get_autoconf_snippet "$module"
1976 extract-automake-snippet )
1980 if test -n "$module"; then
1981 func_get_automake_snippet "$module"
1986 extract-include-directive )
1990 if test -n "$module"; then
1991 func_get_include_directive "$module"
2000 if test -n "$module"; then
2001 func_get_license "$module"
2006 extract-maintainer )
2010 if test -n "$module"; then
2011 func_get_maintainer "$module"
2016 extract-tests-module )
2020 if test -n "$module"; then
2021 func_get_tests_module "$module"
2027 func_fatal_error "unknown operation mode --$mode" ;;