3 # Copyright (C) 2002, 2003, 2004, 2005 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
17 # Foundation, 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: 2005-11-04 18:25:19 $'
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 AUTORECONF="${AUTOCONFPATH}autoreconf"
41 # outputs to stdout the --help usage message.
45 Usage: gnulib-tool --list
46 gnulib-tool --import [module1 ... moduleN]
48 gnulib-tool --create-testdir --dir=directory module1 ... moduleN
49 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
50 gnulib-tool --test --dir=directory module1 ... moduleN
51 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
52 gnulib-tool --extract-description module
53 gnulib-tool --extract-filelist module
54 gnulib-tool --extract-dependencies module
55 gnulib-tool --extract-autoconf-snippet module
56 gnulib-tool --extract-automake-snippet module
57 gnulib-tool --extract-include-directive module
58 gnulib-tool --extract-license module
59 gnulib-tool --extract-maintainer module
60 gnulib-tool --extract-tests-module module
63 --list print the available module names
64 --import import the given modules into the current package
65 --create-testdir create a scratch package with the given modules
66 --create-megatestdir create a mega scratch package with the given modules
67 one by one and all together
68 --test test the combination of the given modules
69 (recommended to use CC=\"gcc -Wall\" here)
70 --megatest test the given modules one by one and all together
71 (recommended to use CC=\"gcc -Wall\" here)
72 --extract-description extract the description
73 --extract-filelist extract the list of files
74 --extract-dependencies extract the dependencies
75 --extract-autoconf-snippet extract the snippet for configure.ac
76 --extract-automake-snippet extract the snippet for lib/Makefile.am
77 --extract-include-directive extract the #include directive
78 --extract-license report the license terms of the source files
80 --extract-maintainer report the maintainer(s) inside gnulib
81 --extract-tests-module report the unit test module, if it exists
84 --dir=DIRECTORY specify the target directory
85 For --import, this specifies where your
86 configure.ac can be found. Defaults to current
88 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
89 --source-base=DIRECTORY
90 Directory relative --dir where source code is
91 placed (default \"lib\"), for --import.
92 --m4-base=DIRECTORY Directory relative --dir where *.m4 macros are
93 placed (default \"m4\"), for --import.
94 --tests-base=DIRECTORY
95 Directory relative --dir where unit tests are
96 placed (default \"tests\"), for --import.
97 --aux-dir=DIRECTORY Directory relative --dir where auxiliary build
98 tools are placed (default \"build-aux\").
99 --with-tests Include unit tests for the included modules.
100 --avoid=MODULE Avoid including the given MODULE. Useful if you
101 have code that provides equivalent functionality.
102 This option can be repeated.
103 --lgpl Abort if modules aren't available under the LGPL.
104 Also modify license template from GPL to LGPL.
105 --libtool Use libtool rules, for --import.
106 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
107 'gl_INIT'. Default is 'gl'.
108 --no-changelog don't update or create ChangeLog files
109 --dry-run For --import, only print what would have been done.
110 -s, --symbolic, --symlink Make symbolic links instead of copying files.
112 Report bugs to <bug-gnulib@gnu.org>."
116 # outputs to stdout the --version message.
119 echo "$progname (GNU $package) $version"
120 echo "Copyright (C) 2002-2005 Free Software Foundation, Inc.
121 This is free software; see the source for copying conditions. There is NO
122 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
123 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
127 # creates a temporary directory.
129 # - tmp pathname of freshly created temporary directory
132 # Use the environment variable TMPDIR, falling back to /tmp. This allows
133 # users to specify a different temporary directory, for example, if their
134 # /tmp is filled up or too small.
137 # Use the mktemp program if available. If not available, hide the error
139 tmp=`(umask 077 && mktemp -d -q "$TMPDIR/glXXXXXX") 2>/dev/null` &&
140 test -n "$tmp" && test -d "$tmp"
143 # Use a simple mkdir command. It is guaranteed to fail if the directory
144 # already exists. $RANDOM is bash specific and expands to empty in shells
145 # other than bash, ksh and zsh. Its use does not increase security;
146 # rather, it minimizes the probability of failure in a very cluttered /tmp
148 tmp=$TMPDIR/gl$$-$RANDOM
149 (umask 077 && mkdir "$tmp")
152 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
153 { (exit 1); exit 1; }
157 # func_fatal_error message
158 # outputs to stderr a fatal error message, and terminates the program.
161 echo "gnulib-tool: *** $1" 1>&2
162 echo "gnulib-tool: *** Stop." 1>&2
166 # func_readlink SYMLINK
167 # outputs the target of the given symlink.
168 if (type -p readlink) > /dev/null 2>&1; then
171 # Use the readlink program from GNU coreutils.
177 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
178 # would do the wrong thing if the link target contains " -> ".
179 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
183 # func_ln_if_changed SRC DEST
184 # Like ln -s, but avoids munging timestamps if the link is correct.
185 func_ln_if_changed ()
187 if test $# -ne 2; then
188 echo "usage: func_ln_if_changed SRC DEST" >&2
190 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
198 # Command-line option processing.
199 # Removes the OPTIONS from the arguments. Sets the variables:
200 # - mode list or import or create-testdir or create-megatestdir
201 # - destdir from --dir
202 # - libname, supplied_libname from --lib
203 # - sourcebase from --source-base
204 # - m4base from --m4-base
205 # - testsbase from --tests-base
206 # - auxdir from --aux-dir
207 # - inctests true if --with-tests was given, blank otherwise
208 # - avoidlist list of modules to avoid, from --avoid
209 # - lgpl true if --lgpl was given, blank otherwise
210 # - libtool true if --libtool was given, blank otherwise
211 # - do_changelog false if --no-changelog was given, : otherwise
212 # - doit : if actions shall be executed, false if only to be printed
233 while test $# -gt 0; do
238 --import | --impor | --impo | --imp | --im | --i )
241 --update | --updat | --upda | --upd | --up | --u )
244 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
247 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
248 mode=create-megatestdir
250 --test | --tes | --te | --t )
253 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
257 mode=`echo "X$1" | sed -e 's/^X--//'`
262 func_fatal_error "missing argument for --dir"
267 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
272 func_fatal_error "missing argument for --lib"
275 supplied_libname=true
278 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
279 supplied_libname=true
284 func_fatal_error "missing argument for --source-base"
289 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
294 func_fatal_error "missing argument for --m4-base"
299 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
304 func_fatal_error "missing argument for --tests-base"
309 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
314 func_fatal_error "missing argument for --aux-dir"
319 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
327 func_fatal_error "missing argument for --avoid"
329 avoidlist="$avoidlist $1"
332 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
343 func_fatal_error "missing argument for --macro-prefix"
348 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
350 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
356 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
359 --help | --hel | --he | --h )
362 --version | --versio | --versi | --vers | --ver | --ve | --v )
366 # Stop option processing
370 echo "gnulib-tool: unknown option $1" 1>&2
371 echo "Try 'gnulib-tool --help' for more information." 1>&2
378 if test "$mode" = update; then
379 if test $# != 0; then
380 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
381 echo "Try 'gnulib-tool --help' for more information." 1>&2
382 echo "If you really want to modify the gnulib configuration of your project," 1>&2
383 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
386 if test -n "$libname" || test -n "$sourcebase" || test -n "$m4base" \
387 || test -n "$testsbase" || test -n "$auxdir" || test -n "$inctests" \
388 || test -n "$avoidlist" || test -n "$lgpl" || test -n "$macro_prefix"; then
389 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
390 echo "Try 'gnulib-tool --help' for more information." 1>&2
391 echo "If you really want to modify the gnulib configuration of your project," 1>&2
392 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
398 # Remove trailing slashes from the directory names. This is necessary for
399 # m4base (to avoid an error in func_import) and optional for the others.
400 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
401 case "$sourcebase" in
402 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
405 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
408 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
411 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
416 /*) self_abspathname="$0" ;;
417 */*) self_abspathname=`pwd`/"$0" ;;
418 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
419 if test -x "$d/$0" && test ! -d "$d/$0"; then
420 self_abspathname="$d/$0"
424 if test -z "$self_abspathname"; then
425 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
429 while test -h "$self_abspathname"; do
430 # Resolve symbolic link.
431 linkval=`func_readlink "$self_abspathname"`
432 test -n "$linkval" || break
434 /* ) self_abspathname="$linkval" ;;
435 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
438 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
443 # Filter out metainformation files like README, which are not modules.
444 # Filter out unit test modules; they can be retrieved through
445 # --extract-tests-module if desired.
446 (cd "$gnulib_dir/modules" && ls -1) \
447 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
448 | sed -e '/-tests$/d' \
453 # verifies a module name
454 func_verify_module ()
456 if test ! -f "$gnulib_dir/modules/$module" \
457 || test "CVS" = "$module" \
458 || test "ChangeLog" = "$module" \
459 || test "README" = "$module" \
460 || test "TEMPLATE" = "$module" \
461 || test "TEMPLATE-TESTS" = "$module"; then
462 echo "gnulib-tool: module $module doesn't exist" 1>&2
467 # func_verify_nontests_module
468 # verifies a module name, excluding tests modules
469 func_verify_nontests_module ()
473 * ) func_verify_module ;;
477 # func_verify_tests_module
478 # verifies a module name, considering only tests modules
479 func_verify_tests_module ()
482 *-tests ) func_verify_module ;;
487 sed_extract_prog=':[ ]*$/ {
490 s/^Description:[ ]*$//
492 s/^Depends-on:[ ]*$//
493 s/^configure\.ac:[ ]*$//
494 s/^Makefile\.am:[ ]*$//
497 s/^Maintainer:[ ]*$//
504 # func_get_description module
505 func_get_description ()
507 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
510 # func_get_filelist module
513 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
515 echo m4/onceonly_2_57.m4
518 # func_get_dependencies module
519 func_get_dependencies ()
521 # ${module}-tests always implicitly depends on ${module}.
522 echo "$1" | sed -n -e 's/-tests//p'
523 # Then the explicit dependencies listed in the module description.
524 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
527 # func_get_autoconf_snippet module
528 func_get_autoconf_snippet ()
530 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
533 # func_get_automake_snippet module
534 func_get_automake_snippet ()
536 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
539 # func_get_include_directive module
540 func_get_include_directive ()
542 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
543 sed -e 's/^\(["<]\)/#include \1/'
546 # func_get_license module
549 sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
552 # func_get_maintainer module
553 func_get_maintainer ()
555 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
558 # func_get_tests_module module
559 func_get_tests_module ()
561 # The naming convention for tests modules is hardwired: ${module}-tests.
562 if test -f modules/"$1"-tests; then
567 # func_acceptable module
568 # tests whether a module is acceptable.
570 # - avoidlist list of modules to avoid
573 for avoid in $avoidlist; do
574 if test "$avoid" = "$1"; then
581 # func_modules_transitive_closure
583 # - modules list of specified modules
584 # - inctests true if tests should be included, blank otherwise
585 # - avoidlist list of modules to avoid
587 # - modules list of modules, including dependencies
588 func_modules_transitive_closure ()
592 for module in $modules; do
594 if test -n "$module"; then
595 # Duplicate dependencies are harmless, but Jim wants a warning.
596 duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
597 if test -n "$duplicated_deps"; then
598 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
600 if func_acceptable $module; then
601 xmodules="$xmodules $module"
602 for depmodule in `func_get_dependencies $module`; do
603 if func_acceptable $depmodule; then
604 xmodules="$xmodules $depmodule"
607 if test -n "$inctests"; then
608 testsmodule=`func_get_tests_module $module`
609 if test -n "$testsmodule"; then
610 if func_acceptable $testsmodule; then
611 xmodules="$xmodules $testsmodule"
612 for depmodule in `func_get_dependencies $testsmodule`; do
613 if func_acceptable $depmodule; then
614 xmodules="$xmodules $depmodule"
623 xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
624 if test "$xmodules" = "$modules"; then
631 # func_modules_to_filelist
633 # - modules list of modules, including dependencies
635 # - files list of files
636 func_modules_to_filelist ()
639 for module in $modules; do
641 if test -n "$module"; then
642 files="$files "`func_get_filelist $module`
645 files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
648 # func_emit_lib_Makefile_am
649 # emits the contents of lib/Makefile.am to standard output.
651 # - modules list of modules, including dependencies
652 # - libname library name
653 # - libtool true if libtool will be used, blank otherwise
654 # - actioncmd (optional) command that will reproduce this invocation
655 func_emit_lib_Makefile_am ()
657 if test -n "$libtool"; then
664 echo "## Process this file with automake to produce Makefile.in."
665 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
667 echo "# This file is free software, distributed under the terms of the GNU"
668 echo "# General Public License. As a special exception to the GNU General"
669 echo "# Public License, this file may be distributed as part of a program"
670 echo "# that contains a configuration script generated by Automake, under"
671 echo "# the same distribution terms as the rest of that program."
673 echo "# Generated by gnulib-tool."
674 if test -n "$actioncmd"; then
675 echo "# Reproduce by: $actioncmd"
678 # No need to generate dependencies since the sources are in gnulib, not here.
679 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
681 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
683 echo "${libname}_${libext}_SOURCES ="
684 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
686 echo "BUILT_SOURCES ="
688 echo "MOSTLYCLEANFILES ="
690 echo "DISTCLEANFILES ="
691 echo "MAINTAINERCLEANFILES ="
693 for module in $modules; do
694 func_verify_nontests_module
695 if test -n "$module"; then
697 func_get_automake_snippet "$module" |
698 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
699 if test "$module" = 'alloca'; then
700 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
703 # Skip the contents if its entirely empty.
704 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
705 echo "## begin gnulib module $module"
708 echo "## end gnulib module $module"
715 echo "# Makefile.am ends here"
718 # func_emit_tests_Makefile_am
719 # emits the contents of tests/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 # - sourcebase relative directory containing lib source code
725 # - m4base relative directory containing autoconf macros
726 # - testsbase relative directory containing unit test code
727 func_emit_tests_Makefile_am ()
729 if test -n "$libtool"; then
734 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
735 echo "## Process this file with automake to produce Makefile.in."
736 echo "# Copyright (C) 2004-2005 Free Software Foundation, Inc."
738 echo "# This file is free software, distributed under the terms of the GNU"
739 echo "# General Public License. As a special exception to the GNU General"
740 echo "# Public License, this file may be distributed as part of a program"
741 echo "# that contains a configuration script generated by Automake, under"
742 echo "# the same distribution terms as the rest of that program."
744 echo "# Generated by gnulib-tool."
746 # Generate dependencies here, since it eases the debugging of test failures.
747 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
749 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
752 echo "TESTS_ENVIRONMENT ="
753 echo "noinst_PROGRAMS ="
755 echo "BUILT_SOURCES ="
757 echo "MOSTLYCLEANFILES ="
759 echo "DISTCLEANFILES ="
760 echo "MAINTAINERCLEANFILES ="
762 echo "AM_CPPFLAGS = \\"
763 echo " -I. -I\$(srcdir) \\"
764 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
765 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
767 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
769 for module in $modules; do
770 func_verify_tests_module
771 if test -n "$module"; then
772 func_get_automake_snippet "$module" > amsnippet.tmp
773 # Skip the contents if its entirely empty.
774 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
775 echo "## begin gnulib module $module"
778 echo "## end gnulib module $module"
784 echo "# Clean up after Solaris cc."
786 echo " rm -rf SunWS_cache"
788 echo "# Makefile.am ends here"
791 # func_import modules
792 # Uses also the variables
793 # - destdir target directory
794 # - libname library name
795 # - sourcebase directory relative to destdir where to place source code
796 # - m4base directory relative to destdir where to place *.m4 macros
797 # - testsbase directory relative to destdir where to place unit test code
798 # - auxdir directory relative to destdir where to place build aux files
799 # - inctests true if --with-tests was given, blank otherwise
800 # - avoidlist list of modules to avoid, from --avoid
801 # - lgpl true if library's license shall be LGPL, blank otherwise
802 # - libtool true if libtool will be used, blank otherwise
803 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
804 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
805 # - doit : if actions shall be executed, false if only to be printed
806 # - symbolic true if files should be symlinked, copied otherwise
809 # Get the cached settings.
810 cached_specified_modules=
820 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
826 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
829 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
832 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
835 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
838 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
841 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
844 s,^.*$,cached_lgpl=true,p
847 s,^.*$,cached_libtool=true,p
850 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
852 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
853 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
858 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
859 s,^.*$,cached_files=",p
871 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
875 # Merge the cached settings with the specified ones.
876 # The m4base must be the same as expected from the pathname.
877 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
878 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
880 # Append the cached and the specified module names. So that
881 # "gnulib-tool --import foo" means to add the module foo.
882 specified_modules="$cached_specified_modules $1"
883 # Append the cached and the specified avoidlist. This is probably better
884 # than dropping the cached one when --avoid is specified at least once.
885 avoidlist=`echo $cached_avoidlist $avoidlist`
886 # The sourcebase defaults to the cached one.
887 if test -z "$sourcebase"; then
888 sourcebase="$cached_sourcebase"
889 if test -z "$sourcebase"; then
890 func_fatal_error "missing --source-base option"
893 # The testsbase defaults to the cached one.
894 if test -z "$testsbase"; then
895 testsbase="$cached_testsbase"
896 if test -z "$testsbase"; then
897 func_fatal_error "missing --tests-base option"
900 # The libname defaults to the cached one.
901 if test -z "$supplied_libname"; then
902 libname="$cached_libname"
903 if test -z "$libname"; then
904 func_fatal_error "missing --lib option"
907 # Require LGPL if specified either way.
908 if test -z "$lgpl"; then
911 # Use libtool if specified either way, or if guessed.
912 if test -z "$libtool"; then
913 if test -n "$cached_m4base"; then
914 libtool="$cached_libtool"
916 libtool="$guessed_libtool"
919 # The macro_prefix defaults to the cached one.
920 if test -z "$macro_prefix"; then
921 macro_prefix="$cached_macro_prefix"
922 if test -z "$macro_prefix"; then
923 func_fatal_error "missing --macro-prefix option"
927 # Canonicalize the list of specified modules.
928 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
930 # Determine final module list.
931 modules="$specified_modules"
932 func_modules_transitive_closure
933 echo "Module list with included dependencies:"
934 echo "$modules" | sed -e 's/^/ /'
936 # If --lgpl, check the license of modules are compatible.
937 if test -n "$lgpl"; then
938 for module in $modules; do
939 license=`func_get_license $module`
941 LGPL | 'public domain' | 'unlimited') ;;
942 *) func_fatal_error "incompatible license on module $module: $license" ;;
947 # Determine final file list.
948 func_modules_to_filelist
950 echo "$files" | sed -e 's/^/ /'
953 || func_fatal_error "refusing to do nothing"
955 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
956 new_files="$files m4/gnulib-tool.m4"
957 old_files="$cached_files"
958 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
959 old_files="$old_files m4/gnulib-tool.m4"
962 # Create directories.
963 if test ! -d "$destdir/$sourcebase"; then
965 echo "Creating directory $destdir/$sourcebase"
966 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
968 echo "Create directory $destdir/$sourcebase"
971 if test ! -d "$destdir/$m4base"; then
973 echo "Creating directory $destdir/$m4base"
974 mkdir "$destdir/$m4base" || func_fatal_error "failed"
976 echo "Create directory $destdir/$m4base"
979 if test -n "$inctests"; then
980 if test ! -d "$destdir/$testsbase"; then
982 echo "Creating directory $destdir/$testsbase"
983 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
985 echo "Create directory $destdir/$testsbase"
989 if test ! -d "$destdir/$auxdir"; then
991 echo "Creating directory $destdir/$auxdir"
992 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
994 echo "Create directory $destdir/$auxdir"
998 # Copy files or make symbolic links. Remove obsolete files.
1000 trap 'rm -rf "$tmp"' 0 1 2 3 15
1002 for f in $old_files; do
1004 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1005 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1006 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1007 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1010 echo "$g""$delimiter""$f"
1011 done | LC_ALL=C sort > "$tmp"/old-files
1012 for f in $new_files; do
1014 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1015 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1016 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1017 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1020 echo "$g""$delimiter""$f"
1021 done | LC_ALL=C sort > "$tmp"/new-files
1022 # First the files that are in old-files, but not in new-files:
1023 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e 's,'"$delimiter"'.*,,'`; do
1024 # Remove the file. Do nothing if the user already removed it.
1025 if test -f "$destdir/$g"; then
1027 echo "Removing file $g (backup in ${g}~)"
1028 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1030 echo "Remove file $g (backup in ${g}~)"
1034 # func_add_or_update handles a file that ought to be present afterwards.
1035 # Uses parameters f, g, already_present.
1036 func_add_or_update ()
1038 cp "$gnulib_dir/$f" "$destdir/$g.tmp" || func_fatal_error "failed"
1039 if test -n "$lgpl"; then
1043 sed -e 's/GNU General/GNU Lesser General/g' \
1044 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1045 < "$gnulib_dir/$f" > "$destdir/$g.tmp" || func_fatal_error "failed"
1049 if test -f "$destdir/$g"; then
1050 # The file already exists.
1051 if cmp "$destdir/$g" "$destdir/$g.tmp" > /dev/null; then
1052 : # The file has not changed.
1056 if test -n "$already_present"; then
1057 echo "Updating file $g (backup in ${g}~)"
1059 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1061 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1062 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$destdir/$g.tmp" > /dev/null; then
1063 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1065 mv -f "$destdir/$g.tmp" "$destdir/${g}" || func_fatal_error "failed"
1068 if test -n "$already_present"; then
1069 echo "Update file $g (backup in ${g}~)"
1071 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1077 # Don't protest if the file should be there but isn't: it happens
1078 # frequently that developers don't put autogenerated files into CVS.
1080 echo "Copying file $g"
1081 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$destdir/$g.tmp" > /dev/null; then
1082 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1084 mv -f "$destdir/$g.tmp" "$destdir/${g}" || func_fatal_error "failed"
1090 rm -f "$destdir/$g.tmp"
1092 # Then the files that are in new-files, but not in old-files:
1094 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e 's,'^.*"$delimiter"',,'`; do
1096 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1097 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1098 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1099 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1104 # Then the files that are in new-files and in old-files:
1105 already_present=true
1106 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e 's,'^.*"$delimiter"',,'`; do
1108 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1109 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1110 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1111 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1119 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1120 actioncmd="gnulib-tool --import"
1121 actioncmd="$actioncmd --dir=$destdir"
1122 actioncmd="$actioncmd --lib=$libname"
1123 actioncmd="$actioncmd --source-base=$sourcebase"
1124 actioncmd="$actioncmd --m4-base=$m4base"
1125 actioncmd="$actioncmd --aux-dir=$auxdir"
1126 for module in $avoidlist; do
1127 actioncmd="$actioncmd --avoid=$module"
1129 if test -n "$lgpl"; then
1130 actioncmd="$actioncmd --lgpl"
1132 if test -n "$libtool"; then
1133 actioncmd="$actioncmd --libtool"
1135 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1136 actioncmd="$actioncmd `echo $specified_modules`"
1138 # Create lib/Makefile.am.
1139 func_emit_lib_Makefile_am > "$destdir"/$sourcebase/Makefile.am.tmp
1140 if test -f "$destdir"/$sourcebase/Makefile.am; then
1141 if cmp "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am.tmp > /dev/null; then
1142 rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1145 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1146 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1147 mv -f "$destdir"/$sourcebase/Makefile.am.tmp "$destdir"/$sourcebase/Makefile.am
1149 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1150 rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1155 echo "Creating $sourcebase/Makefile.am"
1156 mv -f "$destdir"/$sourcebase/Makefile.am.tmp "$destdir"/$sourcebase/Makefile.am
1158 echo "Create $sourcebase/Makefile.am"
1159 rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1163 # Create m4/gnulib-cache.m4.
1165 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1166 echo "# This file is free software, distributed under the terms of the GNU"
1167 echo "# General Public License. As a special exception to the GNU General"
1168 echo "# Public License, this file may be distributed as part of a program"
1169 echo "# that contains a configuration script generated by Autoconf, under"
1170 echo "# the same distribution terms as the rest of that program."
1172 echo "# Generated by gnulib-tool."
1174 echo "# This file represents the specification of how gnulib-tool is used."
1175 echo "# It acts as a cache: It is written and read by gnulib-tool."
1176 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1177 echo "# like the configure.ac and various Makefile.am files."
1180 echo "# Specification in the form of a command-line invocation:"
1183 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1184 echo "gl_MODULES(["`echo $specified_modules`"])"
1185 echo "gl_AVOID([$avoidlist])"
1186 echo "gl_SOURCE_BASE([$sourcebase])"
1187 echo "gl_M4_BASE([$m4base])"
1188 echo "gl_TESTS_BASE([$testsbase])"
1189 echo "gl_LIB([$libname])"
1190 test -z "$lgpl" || echo "gl_LGPL"
1191 test -z "$libtool" || echo "gl_LIBTOOL"
1192 echo "gl_MACRO_PREFIX([$macro_prefix])"
1193 ) > "$destdir"/$m4base/gnulib-cache.m4.tmp
1194 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1195 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4.tmp > /dev/null; then
1196 rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1199 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1200 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1201 mv -f "$destdir"/$m4base/gnulib-cache.m4.tmp "$destdir"/$m4base/gnulib-cache.m4
1203 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1205 cat "$destdir"/$m4base/gnulib-cache.m4.tmp
1207 echo "# gnulib-cache.m4 ends here"
1209 rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1214 echo "Creating $m4base/gnulib-cache.m4"
1215 mv -f "$destdir"/$m4base/gnulib-cache.m4.tmp "$destdir"/$m4base/gnulib-cache.m4
1217 echo "Create $m4base/gnulib-cache.m4"
1218 cat "$destdir"/$m4base/gnulib-cache.m4.tmp
1219 rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1223 # Create m4/gnulib-comp.m4.
1225 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1226 echo "# This file is free software, distributed under the terms of the GNU"
1227 echo "# General Public License. As a special exception to the GNU General"
1228 echo "# Public License, this file may be distributed as part of a program"
1229 echo "# that contains a configuration script generated by Autoconf, under"
1230 echo "# the same distribution terms as the rest of that program."
1232 echo "# Generated by gnulib-tool."
1234 echo "# This file represents the compiled summary of the specification in"
1235 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1236 echo "# to be invoked from configure.ac."
1237 echo "# In projects using CVS, this file can be treated like other built files."
1240 echo "# This macro should be invoked from $configure_ac, in the section"
1241 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1242 echo "# any checks for libraries, header files, types and library functions."
1243 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1245 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 > /dev/null; then
1246 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1248 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 > /dev/null; then
1249 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1253 echo "# This macro should be invoked from $configure_ac, in the section"
1254 echo "# \"Check for header files, types and library functions\"."
1255 echo "AC_DEFUN([${macro_prefix}_INIT],"
1257 if test -z "$libtool"; then
1258 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1260 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1262 for module in $modules; do
1264 if test -n "$module"; then
1265 func_get_autoconf_snippet "$module" | sed -e '/^$/d;' -e 's/^/ /' -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./'
1266 if test "$module" = 'alloca' && test -n "$libtool"; then
1267 echo 'changequote(,)dnl'
1268 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1269 echo 'changequote([, ])dnl'
1270 echo 'AC_SUBST([LTALLOCA])'
1276 echo "# This macro records the list of files which have been installed by"
1277 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1278 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1279 echo "$files" | sed -e 's,^, ,'
1281 ) > "$destdir"/$m4base/gnulib-comp.m4.tmp
1282 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1283 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4.tmp > /dev/null; then
1284 rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1287 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1288 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1289 mv -f "$destdir"/$m4base/gnulib-comp.m4.tmp "$destdir"/$m4base/gnulib-comp.m4
1291 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1293 cat "$destdir"/$m4base/gnulib-comp.m4.tmp
1295 echo "# gnulib-comp.m4 ends here"
1297 rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1302 echo "Creating $m4base/gnulib-comp.m4"
1303 mv -f "$destdir"/$m4base/gnulib-comp.m4.tmp "$destdir"/$m4base/gnulib-comp.m4
1305 echo "Create $m4base/gnulib-comp.m4"
1306 cat "$destdir"/$m4base/gnulib-comp.m4.tmp
1307 rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1311 if test -n "$inctests"; then
1312 # Create tests/Makefile.am.
1313 func_emit_tests_Makefile_am > "$destdir"/$testsbase/Makefile.am.tmp
1314 if test -f "$destdir"/$testsbase/Makefile.am; then
1315 if cmp "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am.tmp > /dev/null; then
1316 rm -f "$destdir"/$testsbase/Makefile.am.tmp
1319 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1320 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1321 mv -f "$destdir"/$testsbase/Makefile.am.tmp "$destdir"/$testsbase/Makefile.am
1323 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1324 rm -f "$destdir"/$testsbase/Makefile.am.tmp
1329 echo "Creating $testsbase/Makefile.am"
1330 mv -f "$destdir"/$testsbase/Makefile.am.tmp "$destdir"/$testsbase/Makefile.am
1332 echo "Create $testsbase/Makefile.am"
1333 rm -f "$destdir"/$testsbase/Makefile.am.tmp
1340 echo "You may need to add #include directives for the following .h files."
1341 for module in $modules; do
1342 func_get_include_directive "$module"
1343 done | LC_ALL=C sort -u | sed -e '/^$/d;' -e 's/^/ /'
1345 echo "Don't forget to"
1346 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1347 if test -n "$inctests"; then
1348 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1350 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1351 sourcebase_base=`basename "$sourcebase"`
1352 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1353 if test -n "$inctests"; then
1354 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1355 testsbase_base=`basename "$testsbase"`
1356 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1358 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1359 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1360 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1363 # func_create_testdir testdir modules
1365 # - auxdir directory relative to destdir where to place build aux files
1366 func_create_testdir ()
1370 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1372 # Determine final module list.
1373 func_modules_transitive_closure
1374 echo "Module list with included dependencies:"
1375 echo "$modules" | sed -e 's/^/ /'
1377 # Determine final file list.
1378 func_modules_to_filelist
1380 echo "$files" | sed -e 's/^/ /'
1382 # Create directories.
1383 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1384 if test "$d" = build-aux; then
1385 mkdir -p "$testdir/$auxdir"
1387 mkdir -p "$testdir/$d"
1391 # Copy files or make symbolic links.
1394 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1397 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1398 if test -z "$symbolic"; then
1399 cp -p "$gnulib_dir/$f" "$testdir/$g"
1401 ln -s "$gnulib_dir/$f" "$testdir/$g"
1405 # Create lib/Makefile.am.
1406 mkdir -p "$testdir/lib"
1407 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1409 # Create m4/Makefile.am.
1410 mkdir -p "$testdir/m4"
1411 (echo "## Process this file with automake to produce Makefile.in."
1417 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1420 ) > "$testdir/m4/Makefile.am"
1423 subdirs_with_configure_ac=""
1425 if test -f "$testdir"/m4/gettext.m4; then
1426 # Avoid stupid error message from automake:
1427 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1428 mkdir -p "$testdir/po"
1429 (echo "## Process this file with automake to produce Makefile.in."
1430 ) > "$testdir/po/Makefile.am"
1431 subdirs="$subdirs po"
1434 if test -n "$inctests"; then
1435 test -d "$testdir/tests" || mkdir "$testdir/tests"
1436 # Create tests/Makefile.am.
1440 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1441 # Create tests/configure.ac.
1442 (echo "# Process this file with autoconf to produce a configure script."
1443 echo "AC_INIT([dummy], [0])"
1444 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1445 echo "AM_INIT_AUTOMAKE"
1447 echo "AM_CONFIG_HEADER([config.h])"
1450 echo "AC_PROG_INSTALL"
1451 echo "AC_PROG_MAKE_SET"
1452 echo "AC_PROG_RANLIB"
1454 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
1455 echo "AC_GNU_SOURCE"
1458 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
1459 echo "gl_USE_SYSTEM_EXTENSIONS"
1462 if test -z "$libtool"; then
1463 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1465 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1467 # We don't have explicit ordering constraints between the various
1468 # autoconf snippets. It's cleanest to put those of the library before
1469 # those of the tests.
1470 for module in $modules; do
1471 func_verify_nontests_module
1472 if test -n "$module"; then
1473 func_get_autoconf_snippet "$module"
1476 for module in $modules; do
1477 func_verify_tests_module
1478 if test -n "$module"; then
1479 func_get_autoconf_snippet "$module"
1483 # Usually tests/config.h will be a superset of config.h. Verify this by
1484 # "merging" config.h into tests/config.h; look out for gcc warnings.
1485 echo "AH_TOP([#include \"../config.h\"])"
1487 echo "AC_OUTPUT([Makefile])"
1488 ) > "$testdir/tests/configure.ac"
1489 subdirs="$subdirs tests"
1490 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1493 # Create Makefile.am.
1494 (echo "## Process this file with automake to produce Makefile.in."
1496 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1498 echo "SUBDIRS = $subdirs"
1500 echo "ACLOCAL_AMFLAGS = -I m4"
1501 ) > "$testdir/Makefile.am"
1503 # Create configure.ac.
1504 (echo "# Process this file with autoconf to produce a configure script."
1505 echo "AC_INIT([dummy], [0])"
1506 if test "$auxdir" != "."; then
1507 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1509 echo "AM_INIT_AUTOMAKE"
1511 echo "AM_CONFIG_HEADER([config.h])"
1514 echo "AC_PROG_INSTALL"
1515 echo "AC_PROG_MAKE_SET"
1516 echo "AC_PROG_RANLIB"
1518 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
1519 echo "AC_GNU_SOURCE"
1522 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
1523 echo "gl_USE_SYSTEM_EXTENSIONS"
1526 if test -z "$libtool"; then
1527 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1529 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1531 for module in $modules; do
1532 func_verify_nontests_module
1533 if test -n "$module"; then
1534 func_get_autoconf_snippet "$module"
1538 if test -n "$subdirs_with_configure_ac"; then
1539 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1541 makefiles="Makefile"
1542 for d in $subdirs; do
1543 # For subdirs that have a configure.ac by their own, it's the subdir's
1544 # configure.ac which creates the subdir's Makefile.am, not this one.
1545 case " $subdirs_with_configure_ac " in
1547 *) makefiles="$makefiles $d/Makefile" ;;
1550 echo "AC_OUTPUT([$makefiles])"
1551 ) > "$testdir/configure.ac"
1553 # Create autogenerated files.
1555 echo "executing ${AUTORECONF} --force --install"
1556 ${AUTORECONF} --force --install
1558 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1562 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1570 # func_create_megatestdir megatestdir allmodules
1572 # - auxdir directory relative to destdir where to place build aux files
1573 func_create_megatestdir ()
1577 if test -z "$allmodules"; then
1578 allmodules=`func_all_modules`
1582 # First, all modules one by one.
1583 for onemodule in $allmodules; do
1584 func_create_testdir "$megatestdir/$onemodule" $onemodule
1585 megasubdirs="${megasubdirs}$onemodule "
1587 # Then, all modules all together.
1588 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1589 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1590 func_create_testdir "$megatestdir/ALL" "$allmodules"
1591 megasubdirs="${megasubdirs}ALL"
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 = $megasubdirs"
1599 ) > "$megatestdir/Makefile.am"
1601 # Create configure.ac.
1602 (echo "# Process this file with autoconf to produce a configure script."
1603 echo "AC_INIT([dummy], [0])"
1604 if test "$auxdir" != "."; then
1605 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1607 echo "AM_INIT_AUTOMAKE"
1609 echo "AC_PROG_MAKE_SET"
1611 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1612 echo "AC_OUTPUT([Makefile])"
1613 ) > "$megatestdir/configure.ac"
1615 # Create autogenerated files.
1617 echo "executing ${AUTORECONF} --install"
1618 ${AUTORECONF} --install
1624 func_fatal_error "no mode specified" ;;
1633 if test -z "$destdir"; then
1636 test -d "$destdir" \
1637 || func_fatal_error "destination directory does not exist: $destdir"
1639 # Prefer configure.ac to configure.in.
1640 if test -f "$destdir"/configure.ac; then
1641 configure_ac="$destdir/configure.ac"
1643 if test -f "$destdir"/configure.in; then
1644 configure_ac="$destdir/configure.in"
1646 func_fatal_error "cannot find $destdir/configure.ac"
1650 test -f "$destdir"/Makefile.am \
1651 || func_fatal_error "cannot find $destdir/Makefile.am"
1653 # Analyze configure.ac.
1660 /AC_CONFIG_AUX_DIR/ {
1661 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1663 /A[CM]_PROG_LIBTOOL/ {
1664 s,^.*$,guessed_libtool=true,p
1666 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1668 if test -z "$auxdir"; then
1669 auxdir="$guessed_auxdir"
1672 # Determine where to apply func_import.
1673 if test -n "$m4base"; then
1674 # Apply func_import to a particular gnulib directory.
1675 # Any number of additional modules can be given.
1676 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1677 # First use of gnulib in the given m4base.
1678 test -n "$supplied_libname" || supplied_libname=true
1679 test -n "$sourcebase" || sourcebase="lib"
1680 test -n "$testsbase" || testsbase="tests"
1681 test -n "$macro_prefix" || macro_prefix="gl"
1685 # Apply func_import to all gnulib directories.
1686 # To get this list of directories, look at Makefile.am. (Not at
1687 # configure, because it may be omitted from CVS. Also, don't run
1688 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1689 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
1693 for arg in $aclocal_amflags; do
1694 if test -n "$m4dir_is_next"; then
1695 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1699 if test -f "$destdir/$arg"/gnulib-cache.m4; then
1700 m4dirs="$m4dirs $arg"
1701 m4dirs_count=`expr $m4dirs_count + 1`
1706 if test "X$arg" = "X-I"; then
1713 if test $m4dirs_count = 0; then
1714 # First use of gnulib in a package.
1715 # Any number of additional modules can be given.
1716 test -n "$supplied_libname" || supplied_libname=true
1717 test -n "$sourcebase" || sourcebase="lib"
1719 test -n "$testsbase" || testsbase="tests"
1720 test -n "$macro_prefix" || macro_prefix="gl"
1723 if test $m4dirs_count = 1; then
1724 # There's only one use of gnulib here. Assume the user means it.
1725 # Any number of additional modules can be given.
1726 for m4base in $m4dirs; do
1730 # Ambiguous - guess what the user meant.
1731 if test $# = 0; then
1732 # No further arguments. Guess the user wants to update all of them.
1733 for m4base in $m4dirs; do
1738 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
1746 if test -z "$destdir"; then
1747 func_fatal_error "please specify --dir option"
1750 test -d "$destdir" \
1751 || func_fatal_error "could not create destination directory"
1752 test -n "$auxdir" || auxdir="build-aux"
1753 func_create_testdir "$destdir" "$*"
1756 create-megatestdir )
1757 if test -z "$destdir"; then
1758 func_fatal_error "please specify --dir option"
1760 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1761 test -n "$auxdir" || auxdir="build-aux"
1762 func_create_megatestdir "$destdir" "$*"
1766 test -n "$destdir" || destdir=testdir$$
1767 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1768 test -n "$auxdir" || auxdir="build-aux"
1769 func_create_testdir "$destdir" "$*"
1777 remaining=`find . -type f -print`
1778 if test -n "$remaining"; then
1779 echo "Remaining files:" $remaining 1>&2
1780 echo "gnulib-tool: *** Stop." 1>&2
1789 test -n "$destdir" || destdir=testdir$$
1790 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1791 test -n "$auxdir" || auxdir="build-aux"
1792 func_create_megatestdir "$destdir" "$*"
1800 remaining=`find . -type f -print`
1801 if test -n "$remaining"; then
1802 echo "Remaining files:" $remaining 1>&2
1803 echo "gnulib-tool: *** Stop." 1>&2
1811 extract-description )
1815 if test -n "$module"; then
1816 func_get_description "$module"
1825 if test -n "$module"; then
1826 func_get_filelist "$module"
1831 extract-dependencies )
1835 if test -n "$module"; then
1836 func_get_dependencies "$module"
1841 extract-autoconf-snippet )
1845 if test -n "$module"; then
1846 func_get_autoconf_snippet "$module"
1851 extract-automake-snippet )
1855 if test -n "$module"; then
1856 func_get_automake_snippet "$module"
1861 extract-include-directive )
1865 if test -n "$module"; then
1866 func_get_include_directive "$module"
1875 if test -n "$module"; then
1876 func_get_license "$module"
1881 extract-maintainer )
1885 if test -n "$module"; then
1886 func_get_maintainer "$module"
1891 extract-tests-module )
1895 if test -n "$module"; then
1896 func_get_tests_module "$module"
1902 func_fatal_error "unknown operation mode --$mode" ;;