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-11 13:01:13 $'
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 AUTOCONF="${AUTOCONFPATH}autoconf"
42 ACLOCAL="${AUTOMAKEPATH}aclocal"
43 AUTOMAKE="${AUTOMAKEPATH}automake"
44 AUTORECONF="${AUTOCONFPATH}autoreconf"
47 # outputs to stdout the --help usage message.
51 Usage: gnulib-tool --list
52 gnulib-tool --import [module1 ... moduleN]
54 gnulib-tool --create-testdir --dir=directory module1 ... moduleN
55 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
56 gnulib-tool --test --dir=directory module1 ... moduleN
57 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
58 gnulib-tool --extract-description module
59 gnulib-tool --extract-filelist module
60 gnulib-tool --extract-dependencies module
61 gnulib-tool --extract-autoconf-snippet module
62 gnulib-tool --extract-automake-snippet module
63 gnulib-tool --extract-include-directive module
64 gnulib-tool --extract-license module
65 gnulib-tool --extract-maintainer module
66 gnulib-tool --extract-tests-module module
69 --list print the available module names
70 --import import the given modules into the current package
71 --create-testdir create a scratch package with the given modules
72 --create-megatestdir create a mega scratch package with the given modules
73 one by one and all together
74 --test test the combination of the given modules
75 (recommended to use CC=\"gcc -Wall\" here)
76 --megatest test the given modules one by one and all together
77 (recommended to use CC=\"gcc -Wall\" here)
78 --extract-description extract the description
79 --extract-filelist extract the list of files
80 --extract-dependencies extract the dependencies
81 --extract-autoconf-snippet extract the snippet for configure.ac
82 --extract-automake-snippet extract the snippet for lib/Makefile.am
83 --extract-include-directive extract the #include directive
84 --extract-license report the license terms of the source files
86 --extract-maintainer report the maintainer(s) inside gnulib
87 --extract-tests-module report the unit test module, if it exists
90 --dir=DIRECTORY specify the target directory
91 For --import, this specifies where your
92 configure.ac can be found. Defaults to current
94 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
95 --source-base=DIRECTORY
96 Directory relative --dir where source code is
97 placed (default \"lib\"), for --import.
98 --m4-base=DIRECTORY Directory relative --dir where *.m4 macros are
99 placed (default \"m4\"), for --import.
100 --tests-base=DIRECTORY
101 Directory relative --dir where unit tests are
102 placed (default \"tests\"), for --import.
103 --aux-dir=DIRECTORY Directory relative --dir where auxiliary build
104 tools are placed (default \"build-aux\").
105 --with-tests Include unit tests for the included modules.
106 --avoid=MODULE Avoid including the given MODULE. Useful if you
107 have code that provides equivalent functionality.
108 This option can be repeated.
109 --lgpl Abort if modules aren't available under the LGPL.
110 Also modify license template from GPL to LGPL.
111 --libtool Use libtool rules, for --import.
112 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
113 'gl_INIT'. Default is 'gl'.
114 --no-changelog don't update or create ChangeLog files
115 --dry-run For --import, only print what would have been done.
116 -s, --symbolic, --symlink Make symbolic links instead of copying files.
118 Report bugs to <bug-gnulib@gnu.org>."
122 # outputs to stdout the --version message.
125 echo "$progname (GNU $package) $version"
126 echo "Copyright (C) 2002-2005 Free Software Foundation, Inc.
127 This is free software; see the source for copying conditions. There is NO
128 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
129 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
133 # creates a temporary directory.
135 # - tmp pathname of freshly created temporary directory
138 # Use the environment variable TMPDIR, falling back to /tmp. This allows
139 # users to specify a different temporary directory, for example, if their
140 # /tmp is filled up or too small.
143 # Use the mktemp program if available. If not available, hide the error
145 tmp=`(umask 077 && mktemp -d -q "$TMPDIR/glXXXXXX") 2>/dev/null` &&
146 test -n "$tmp" && test -d "$tmp"
149 # Use a simple mkdir command. It is guaranteed to fail if the directory
150 # already exists. $RANDOM is bash specific and expands to empty in shells
151 # other than bash, ksh and zsh. Its use does not increase security;
152 # rather, it minimizes the probability of failure in a very cluttered /tmp
154 tmp=$TMPDIR/gl$$-$RANDOM
155 (umask 077 && mkdir "$tmp")
158 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
159 { (exit 1); exit 1; }
163 # func_fatal_error message
164 # outputs to stderr a fatal error message, and terminates the program.
167 echo "gnulib-tool: *** $1" 1>&2
168 echo "gnulib-tool: *** Stop." 1>&2
172 # func_readlink SYMLINK
173 # outputs the target of the given symlink.
174 if (type -p readlink) > /dev/null 2>&1; then
177 # Use the readlink program from GNU coreutils.
183 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
184 # would do the wrong thing if the link target contains " -> ".
185 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
189 # func_ln_if_changed SRC DEST
190 # Like ln -s, but avoids munging timestamps if the link is correct.
191 func_ln_if_changed ()
193 if test $# -ne 2; then
194 echo "usage: func_ln_if_changed SRC DEST" >&2
196 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
204 # Command-line option processing.
205 # Removes the OPTIONS from the arguments. Sets the variables:
206 # - mode list or import or create-testdir or create-megatestdir
207 # - destdir from --dir
208 # - libname, supplied_libname from --lib
209 # - sourcebase from --source-base
210 # - m4base from --m4-base
211 # - testsbase from --tests-base
212 # - auxdir from --aux-dir
213 # - inctests true if --with-tests was given, blank otherwise
214 # - avoidlist list of modules to avoid, from --avoid
215 # - lgpl true if --lgpl was given, blank otherwise
216 # - libtool true if --libtool was given, blank otherwise
217 # - do_changelog false if --no-changelog was given, : otherwise
218 # - doit : if actions shall be executed, false if only to be printed
239 while test $# -gt 0; do
244 --import | --impor | --impo | --imp | --im | --i )
247 --update | --updat | --upda | --upd | --up | --u )
250 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
253 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
254 mode=create-megatestdir
256 --test | --tes | --te | --t )
259 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
263 mode=`echo "X$1" | sed -e 's/^X--//'`
268 func_fatal_error "missing argument for --dir"
273 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
278 func_fatal_error "missing argument for --lib"
281 supplied_libname=true
284 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
285 supplied_libname=true
290 func_fatal_error "missing argument for --source-base"
295 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
300 func_fatal_error "missing argument for --m4-base"
305 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
310 func_fatal_error "missing argument for --tests-base"
315 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
320 func_fatal_error "missing argument for --aux-dir"
325 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
333 func_fatal_error "missing argument for --avoid"
335 avoidlist="$avoidlist $1"
338 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
349 func_fatal_error "missing argument for --macro-prefix"
354 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
356 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
362 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
365 --help | --hel | --he | --h )
368 --version | --versio | --versi | --vers | --ver | --ve | --v )
372 # Stop option processing
376 echo "gnulib-tool: unknown option $1" 1>&2
377 echo "Try 'gnulib-tool --help' for more information." 1>&2
384 if test "$mode" = update; then
385 if test $# != 0; then
386 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
387 echo "Try 'gnulib-tool --help' for more information." 1>&2
388 echo "If you really want to modify the gnulib configuration of your project," 1>&2
389 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
392 if test -n "$libname" || test -n "$sourcebase" || test -n "$m4base" \
393 || test -n "$testsbase" || test -n "$auxdir" || test -n "$inctests" \
394 || test -n "$avoidlist" || test -n "$lgpl" || test -n "$macro_prefix"; then
395 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
396 echo "Try 'gnulib-tool --help' for more information." 1>&2
397 echo "If you really want to modify the gnulib configuration of your project," 1>&2
398 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
404 # Remove trailing slashes from the directory names. This is necessary for
405 # m4base (to avoid an error in func_import) and optional for the others.
406 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
407 case "$sourcebase" in
408 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
411 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
414 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
417 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
422 /*) self_abspathname="$0" ;;
423 */*) self_abspathname=`pwd`/"$0" ;;
424 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
425 if test -x "$d/$0" && test ! -d "$d/$0"; then
426 self_abspathname="$d/$0"
430 if test -z "$self_abspathname"; then
431 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
435 while test -h "$self_abspathname"; do
436 # Resolve symbolic link.
437 linkval=`func_readlink "$self_abspathname"`
438 test -n "$linkval" || break
440 /* ) self_abspathname="$linkval" ;;
441 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
444 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
449 # Filter out metainformation files like README, which are not modules.
450 # Filter out unit test modules; they can be retrieved through
451 # --extract-tests-module if desired.
452 (cd "$gnulib_dir/modules" && ls -1) \
453 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
454 | sed -e '/-tests$/d' \
459 # verifies a module name
460 func_verify_module ()
462 if test ! -f "$gnulib_dir/modules/$module" \
463 || test "CVS" = "$module" \
464 || test "ChangeLog" = "$module" \
465 || test "README" = "$module" \
466 || test "TEMPLATE" = "$module" \
467 || test "TEMPLATE-TESTS" = "$module"; then
468 echo "gnulib-tool: module $module doesn't exist" 1>&2
473 # func_verify_nontests_module
474 # verifies a module name, excluding tests modules
475 func_verify_nontests_module ()
479 * ) func_verify_module ;;
483 # func_verify_tests_module
484 # verifies a module name, considering only tests modules
485 func_verify_tests_module ()
488 *-tests ) func_verify_module ;;
493 sed_extract_prog=':[ ]*$/ {
496 s/^Description:[ ]*$//
498 s/^Depends-on:[ ]*$//
499 s/^configure\.ac:[ ]*$//
500 s/^Makefile\.am:[ ]*$//
503 s/^Maintainer:[ ]*$//
510 # func_get_description module
511 func_get_description ()
513 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
516 # func_get_filelist module
519 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
521 echo m4/onceonly_2_57.m4
524 # func_get_dependencies module
525 func_get_dependencies ()
527 # ${module}-tests always implicitly depends on ${module}.
528 echo "$1" | sed -n -e 's/-tests//p'
529 # Then the explicit dependencies listed in the module description.
530 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
533 # func_get_autoconf_snippet module
534 func_get_autoconf_snippet ()
536 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
539 # func_get_automake_snippet module
540 func_get_automake_snippet ()
542 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
545 # func_get_include_directive module
546 func_get_include_directive ()
548 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
549 sed -e 's/^\(["<]\)/#include \1/'
552 # func_get_license module
555 sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
558 # func_get_maintainer module
559 func_get_maintainer ()
561 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
564 # func_get_tests_module module
565 func_get_tests_module ()
567 # The naming convention for tests modules is hardwired: ${module}-tests.
568 if test -f modules/"$1"-tests; then
573 # func_acceptable module
574 # tests whether a module is acceptable.
576 # - avoidlist list of modules to avoid
579 for avoid in $avoidlist; do
580 if test "$avoid" = "$1"; then
587 # func_modules_transitive_closure
589 # - modules list of specified modules
590 # - inctests true if tests should be included, blank otherwise
591 # - avoidlist list of modules to avoid
593 # - modules list of modules, including dependencies
594 func_modules_transitive_closure ()
598 for module in $modules; do
600 if test -n "$module"; then
601 # Duplicate dependencies are harmless, but Jim wants a warning.
602 duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
603 if test -n "$duplicated_deps"; then
604 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
606 if func_acceptable $module; then
607 xmodules="$xmodules $module"
608 for depmodule in `func_get_dependencies $module`; do
609 if func_acceptable $depmodule; then
610 xmodules="$xmodules $depmodule"
613 if test -n "$inctests"; then
614 testsmodule=`func_get_tests_module $module`
615 if test -n "$testsmodule"; then
616 if func_acceptable $testsmodule; then
617 xmodules="$xmodules $testsmodule"
618 for depmodule in `func_get_dependencies $testsmodule`; do
619 if func_acceptable $depmodule; then
620 xmodules="$xmodules $depmodule"
629 xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
630 if test "$xmodules" = "$modules"; then
637 # func_modules_to_filelist
639 # - modules list of modules, including dependencies
641 # - files list of files
642 func_modules_to_filelist ()
645 for module in $modules; do
647 if test -n "$module"; then
648 files="$files "`func_get_filelist $module`
651 files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
654 # func_emit_lib_Makefile_am
655 # emits the contents of lib/Makefile.am to standard output.
657 # - modules list of modules, including dependencies
658 # - libname library name
659 # - libtool true if libtool will be used, blank otherwise
660 # - actioncmd (optional) command that will reproduce this invocation
661 func_emit_lib_Makefile_am ()
663 if test -n "$libtool"; then
670 echo "## Process this file with automake to produce Makefile.in."
671 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
673 echo "# This file is free software, distributed under the terms of the GNU"
674 echo "# General Public License. As a special exception to the GNU General"
675 echo "# Public License, this file may be distributed as part of a program"
676 echo "# that contains a configuration script generated by Automake, under"
677 echo "# the same distribution terms as the rest of that program."
679 echo "# Generated by gnulib-tool."
680 if test -n "$actioncmd"; then
681 echo "# Reproduce by: $actioncmd"
684 # No need to generate dependencies since the sources are in gnulib, not here.
685 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
687 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
689 echo "${libname}_${libext}_SOURCES ="
690 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
691 echo "noinst_HEADERS ="
693 echo "BUILT_SOURCES ="
695 echo "MOSTLYCLEANFILES ="
697 echo "DISTCLEANFILES ="
698 echo "MAINTAINERCLEANFILES ="
700 for module in $modules; do
701 func_verify_nontests_module
702 if test -n "$module"; then
704 func_get_automake_snippet "$module" |
705 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
706 if test "$module" = 'alloca'; then
707 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
710 # Skip the contents if its entirely empty.
711 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
712 echo "## begin gnulib module $module"
715 echo "## end gnulib module $module"
722 echo "# Makefile.am ends here"
725 # func_emit_tests_Makefile_am
726 # emits the contents of tests/Makefile.am to standard output.
728 # - modules list of modules, including dependencies
729 # - libname library name
730 # - libtool true if libtool will be used, blank otherwise
731 # - sourcebase relative directory containing lib source code
732 # - m4base relative directory containing autoconf macros
733 # - testsbase relative directory containing unit test code
734 func_emit_tests_Makefile_am ()
736 if test -n "$libtool"; then
741 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
742 echo "## Process this file with automake to produce Makefile.in."
743 echo "# Copyright (C) 2004-2005 Free Software Foundation, Inc."
745 echo "# This file is free software, distributed under the terms of the GNU"
746 echo "# General Public License. As a special exception to the GNU General"
747 echo "# Public License, this file may be distributed as part of a program"
748 echo "# that contains a configuration script generated by Automake, under"
749 echo "# the same distribution terms as the rest of that program."
751 echo "# Generated by gnulib-tool."
753 # Generate dependencies here, since it eases the debugging of test failures.
754 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
756 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
758 # Nothing is being added to SUBDIRS; nevertheless the existence of this
759 # variable is needed to avoid an error from automake:
760 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
763 echo "TESTS_ENVIRONMENT ="
764 echo "noinst_PROGRAMS ="
765 echo "noinst_HEADERS ="
767 echo "BUILT_SOURCES ="
769 echo "MOSTLYCLEANFILES ="
771 echo "DISTCLEANFILES ="
772 echo "MAINTAINERCLEANFILES ="
774 echo "AM_CPPFLAGS = \\"
775 echo " -I. -I\$(srcdir) \\"
776 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
777 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
779 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
781 for module in $modules; do
782 func_verify_tests_module
783 if test -n "$module"; then
784 func_get_automake_snippet "$module" > amsnippet.tmp
785 # Skip the contents if its entirely empty.
786 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
787 echo "## begin gnulib module $module"
790 echo "## end gnulib module $module"
796 echo "# Clean up after Solaris cc."
798 echo " rm -rf SunWS_cache"
800 echo "# Makefile.am ends here"
803 # func_import modules
804 # Uses also the variables
805 # - destdir target directory
806 # - libname library name
807 # - sourcebase directory relative to destdir where to place source code
808 # - m4base directory relative to destdir where to place *.m4 macros
809 # - testsbase directory relative to destdir where to place unit test code
810 # - auxdir directory relative to destdir where to place build aux files
811 # - inctests true if --with-tests was given, blank otherwise
812 # - avoidlist list of modules to avoid, from --avoid
813 # - lgpl true if library's license shall be LGPL, blank otherwise
814 # - libtool true if libtool will be used, blank otherwise
815 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
816 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
817 # - doit : if actions shall be executed, false if only to be printed
818 # - symbolic true if files should be symlinked, copied otherwise
821 # Get the cached settings.
822 cached_specified_modules=
832 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
838 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
841 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
844 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
847 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
850 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
853 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
856 s,^.*$,cached_lgpl=true,p
859 s,^.*$,cached_libtool=true,p
862 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
864 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
865 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
870 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
871 s,^.*$,cached_files=",p
883 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
887 # Merge the cached settings with the specified ones.
888 # The m4base must be the same as expected from the pathname.
889 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
890 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
892 # Append the cached and the specified module names. So that
893 # "gnulib-tool --import foo" means to add the module foo.
894 specified_modules="$cached_specified_modules $1"
895 # Append the cached and the specified avoidlist. This is probably better
896 # than dropping the cached one when --avoid is specified at least once.
897 avoidlist=`echo $cached_avoidlist $avoidlist`
898 # The sourcebase defaults to the cached one.
899 if test -z "$sourcebase"; then
900 sourcebase="$cached_sourcebase"
901 if test -z "$sourcebase"; then
902 func_fatal_error "missing --source-base option"
905 # The testsbase defaults to the cached one.
906 if test -z "$testsbase"; then
907 testsbase="$cached_testsbase"
908 if test -z "$testsbase"; then
909 func_fatal_error "missing --tests-base option"
912 # The libname defaults to the cached one.
913 if test -z "$supplied_libname"; then
914 libname="$cached_libname"
915 if test -z "$libname"; then
916 func_fatal_error "missing --lib option"
919 # Require LGPL if specified either way.
920 if test -z "$lgpl"; then
923 # Use libtool if specified either way, or if guessed.
924 if test -z "$libtool"; then
925 if test -n "$cached_m4base"; then
926 libtool="$cached_libtool"
928 libtool="$guessed_libtool"
931 # The macro_prefix defaults to the cached one.
932 if test -z "$macro_prefix"; then
933 macro_prefix="$cached_macro_prefix"
934 if test -z "$macro_prefix"; then
935 func_fatal_error "missing --macro-prefix option"
939 # Canonicalize the list of specified modules.
940 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
942 # Determine final module list.
943 modules="$specified_modules"
944 func_modules_transitive_closure
945 echo "Module list with included dependencies:"
946 echo "$modules" | sed -e 's/^/ /'
948 # If --lgpl, check the license of modules are compatible.
949 if test -n "$lgpl"; then
950 for module in $modules; do
951 license=`func_get_license $module`
953 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
954 *) func_fatal_error "incompatible license on module $module: $license" ;;
959 # Determine final file list.
960 func_modules_to_filelist
962 echo "$files" | sed -e 's/^/ /'
965 || func_fatal_error "refusing to do nothing"
967 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
968 new_files="$files m4/gnulib-tool.m4"
969 old_files="$cached_files"
970 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
971 old_files="$old_files m4/gnulib-tool.m4"
974 # Create directories.
975 if test ! -d "$destdir/$sourcebase"; then
977 echo "Creating directory $destdir/$sourcebase"
978 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
980 echo "Create directory $destdir/$sourcebase"
983 if test ! -d "$destdir/$m4base"; then
985 echo "Creating directory $destdir/$m4base"
986 mkdir "$destdir/$m4base" || func_fatal_error "failed"
988 echo "Create directory $destdir/$m4base"
991 if test -n "$inctests"; then
992 if test ! -d "$destdir/$testsbase"; then
994 echo "Creating directory $destdir/$testsbase"
995 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
997 echo "Create directory $destdir/$testsbase"
1001 if test ! -d "$destdir/$auxdir"; then
1003 echo "Creating directory $destdir/$auxdir"
1004 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1006 echo "Create directory $destdir/$auxdir"
1010 # Copy files or make symbolic links. Remove obsolete files.
1012 trap 'rm -rf "$tmp"' 0 1 2 3 15
1014 for f in $old_files; do
1016 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1017 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1018 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1019 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1022 echo "$g""$delimiter""$f"
1023 done | LC_ALL=C sort > "$tmp"/old-files
1024 for f in $new_files; do
1026 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1027 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1028 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1029 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1032 echo "$g""$delimiter""$f"
1033 done | LC_ALL=C sort > "$tmp"/new-files
1034 # First the files that are in old-files, but not in new-files:
1035 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e 's,'"$delimiter"'.*,,'`; do
1036 # Remove the file. Do nothing if the user already removed it.
1037 if test -f "$destdir/$g"; then
1039 echo "Removing file $g (backup in ${g}~)"
1040 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1042 echo "Remove file $g (backup in ${g}~)"
1046 # func_add_or_update handles a file that ought to be present afterwards.
1047 # Uses parameters f, g, already_present.
1048 func_add_or_update ()
1050 cp "$gnulib_dir/$f" "$destdir/$g.tmp" || func_fatal_error "failed"
1051 if test -n "$lgpl"; then
1055 sed -e 's/GNU General/GNU Lesser General/g' \
1056 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1057 < "$gnulib_dir/$f" > "$destdir/$g.tmp" || func_fatal_error "failed"
1061 if test -f "$destdir/$g"; then
1062 # The file already exists.
1063 if cmp "$destdir/$g" "$destdir/$g.tmp" > /dev/null; then
1064 : # The file has not changed.
1068 if test -n "$already_present"; then
1069 echo "Updating file $g (backup in ${g}~)"
1071 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1073 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1074 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$destdir/$g.tmp" > /dev/null; then
1075 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1077 mv -f "$destdir/$g.tmp" "$destdir/${g}" || func_fatal_error "failed"
1080 if test -n "$already_present"; then
1081 echo "Update file $g (backup in ${g}~)"
1083 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1089 # Don't protest if the file should be there but isn't: it happens
1090 # frequently that developers don't put autogenerated files into CVS.
1092 echo "Copying file $g"
1093 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$destdir/$g.tmp" > /dev/null; then
1094 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1096 mv -f "$destdir/$g.tmp" "$destdir/${g}" || func_fatal_error "failed"
1102 rm -f "$destdir/$g.tmp"
1104 # Then the files that are in new-files, but not in old-files:
1106 for f in `LC_ALL=C join -t"$delimiter" -v2 "$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/,"` ;;
1116 # Then the files that are in new-files and in old-files:
1117 already_present=true
1118 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e 's,'^.*"$delimiter"',,'`; do
1120 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1121 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1122 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1123 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1131 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1132 actioncmd="gnulib-tool --import"
1133 actioncmd="$actioncmd --dir=$destdir"
1134 actioncmd="$actioncmd --lib=$libname"
1135 actioncmd="$actioncmd --source-base=$sourcebase"
1136 actioncmd="$actioncmd --m4-base=$m4base"
1137 actioncmd="$actioncmd --aux-dir=$auxdir"
1138 for module in $avoidlist; do
1139 actioncmd="$actioncmd --avoid=$module"
1141 if test -n "$lgpl"; then
1142 actioncmd="$actioncmd --lgpl"
1144 if test -n "$libtool"; then
1145 actioncmd="$actioncmd --libtool"
1147 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1148 actioncmd="$actioncmd `echo $specified_modules`"
1150 # Create lib/Makefile.am.
1151 func_emit_lib_Makefile_am > "$destdir"/$sourcebase/Makefile.am.tmp
1152 if test -f "$destdir"/$sourcebase/Makefile.am; then
1153 if cmp "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am.tmp > /dev/null; then
1154 rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1157 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1158 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1159 mv -f "$destdir"/$sourcebase/Makefile.am.tmp "$destdir"/$sourcebase/Makefile.am
1161 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1162 rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1167 echo "Creating $sourcebase/Makefile.am"
1168 mv -f "$destdir"/$sourcebase/Makefile.am.tmp "$destdir"/$sourcebase/Makefile.am
1170 echo "Create $sourcebase/Makefile.am"
1171 rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1175 # Create m4/gnulib-cache.m4.
1177 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1178 echo "# This file is free software, distributed under the terms of the GNU"
1179 echo "# General Public License. As a special exception to the GNU General"
1180 echo "# Public License, this file may be distributed as part of a program"
1181 echo "# that contains a configuration script generated by Autoconf, under"
1182 echo "# the same distribution terms as the rest of that program."
1184 echo "# Generated by gnulib-tool."
1186 echo "# This file represents the specification of how gnulib-tool is used."
1187 echo "# It acts as a cache: It is written and read by gnulib-tool."
1188 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1189 echo "# like the configure.ac and various Makefile.am files."
1192 echo "# Specification in the form of a command-line invocation:"
1195 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1196 echo "gl_MODULES(["`echo $specified_modules`"])"
1197 echo "gl_AVOID([$avoidlist])"
1198 echo "gl_SOURCE_BASE([$sourcebase])"
1199 echo "gl_M4_BASE([$m4base])"
1200 echo "gl_TESTS_BASE([$testsbase])"
1201 echo "gl_LIB([$libname])"
1202 test -z "$lgpl" || echo "gl_LGPL"
1203 test -z "$libtool" || echo "gl_LIBTOOL"
1204 echo "gl_MACRO_PREFIX([$macro_prefix])"
1205 ) > "$destdir"/$m4base/gnulib-cache.m4.tmp
1206 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1207 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4.tmp > /dev/null; then
1208 rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1211 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1212 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1213 mv -f "$destdir"/$m4base/gnulib-cache.m4.tmp "$destdir"/$m4base/gnulib-cache.m4
1215 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1217 cat "$destdir"/$m4base/gnulib-cache.m4.tmp
1219 echo "# gnulib-cache.m4 ends here"
1221 rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1226 echo "Creating $m4base/gnulib-cache.m4"
1227 mv -f "$destdir"/$m4base/gnulib-cache.m4.tmp "$destdir"/$m4base/gnulib-cache.m4
1229 echo "Create $m4base/gnulib-cache.m4"
1230 cat "$destdir"/$m4base/gnulib-cache.m4.tmp
1231 rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1235 # Create m4/gnulib-comp.m4.
1237 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1238 echo "# This file is free software, distributed under the terms of the GNU"
1239 echo "# General Public License. As a special exception to the GNU General"
1240 echo "# Public License, this file may be distributed as part of a program"
1241 echo "# that contains a configuration script generated by Autoconf, under"
1242 echo "# the same distribution terms as the rest of that program."
1244 echo "# Generated by gnulib-tool."
1246 echo "# This file represents the compiled summary of the specification in"
1247 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1248 echo "# to be invoked from configure.ac."
1249 echo "# In projects using CVS, this file can be treated like other built files."
1252 echo "# This macro should be invoked from $configure_ac, in the section"
1253 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1254 echo "# any checks for libraries, header files, types and library functions."
1255 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1257 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1258 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 > /dev/null; then
1259 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1261 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 > /dev/null; then
1262 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1264 if grep gl_LOCK "$destdir"/$m4base/*.m4 > /dev/null; then
1265 echo " AC_REQUIRE([gl_LOCK])"
1269 echo "# This macro should be invoked from $configure_ac, in the section"
1270 echo "# \"Check for header files, types and library functions\"."
1271 echo "AC_DEFUN([${macro_prefix}_INIT],"
1273 if test -z "$libtool"; then
1274 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1276 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1278 sed_replace_build_aux='
1280 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1281 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1284 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1285 for module in $modules; do
1287 if test -n "$module"; then
1288 func_get_autoconf_snippet "$module" \
1289 | sed -e '/^$/d;' -e 's/^/ /' \
1290 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1291 -e "$sed_replace_build_aux"
1292 if test "$module" = 'alloca' && test -n "$libtool"; then
1293 echo 'changequote(,)dnl'
1294 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1295 echo 'changequote([, ])dnl'
1296 echo 'AC_SUBST([LTALLOCA])'
1302 echo "# This macro records the list of files which have been installed by"
1303 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1304 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1305 echo "$files" | sed -e 's,^, ,'
1307 ) > "$destdir"/$m4base/gnulib-comp.m4.tmp
1308 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1309 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4.tmp > /dev/null; then
1310 rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1313 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1314 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1315 mv -f "$destdir"/$m4base/gnulib-comp.m4.tmp "$destdir"/$m4base/gnulib-comp.m4
1317 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1319 cat "$destdir"/$m4base/gnulib-comp.m4.tmp
1321 echo "# gnulib-comp.m4 ends here"
1323 rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1328 echo "Creating $m4base/gnulib-comp.m4"
1329 mv -f "$destdir"/$m4base/gnulib-comp.m4.tmp "$destdir"/$m4base/gnulib-comp.m4
1331 echo "Create $m4base/gnulib-comp.m4"
1332 cat "$destdir"/$m4base/gnulib-comp.m4.tmp
1333 rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1337 if test -n "$inctests"; then
1338 # Create tests/Makefile.am.
1339 func_emit_tests_Makefile_am > "$destdir"/$testsbase/Makefile.am.tmp
1340 if test -f "$destdir"/$testsbase/Makefile.am; then
1341 if cmp "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am.tmp > /dev/null; then
1342 rm -f "$destdir"/$testsbase/Makefile.am.tmp
1345 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1346 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1347 mv -f "$destdir"/$testsbase/Makefile.am.tmp "$destdir"/$testsbase/Makefile.am
1349 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1350 rm -f "$destdir"/$testsbase/Makefile.am.tmp
1355 echo "Creating $testsbase/Makefile.am"
1356 mv -f "$destdir"/$testsbase/Makefile.am.tmp "$destdir"/$testsbase/Makefile.am
1358 echo "Create $testsbase/Makefile.am"
1359 rm -f "$destdir"/$testsbase/Makefile.am.tmp
1366 echo "You may need to add #include directives for the following .h files."
1367 for module in $modules; do
1368 func_get_include_directive "$module"
1369 done | LC_ALL=C sort -u | sed -e '/^$/d;' -e 's/^/ /'
1371 echo "Don't forget to"
1372 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1373 if test -n "$inctests"; then
1374 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1376 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1377 sourcebase_base=`basename "$sourcebase"`
1378 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1379 if test -n "$inctests"; then
1380 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1381 testsbase_base=`basename "$testsbase"`
1382 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1384 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1385 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1386 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1389 # func_create_testdir testdir modules
1391 # - auxdir directory relative to destdir where to place build aux files
1392 func_create_testdir ()
1396 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1398 # Determine final module list.
1399 func_modules_transitive_closure
1400 echo "Module list with included dependencies:"
1401 echo "$modules" | sed -e 's/^/ /'
1403 # Determine final file list.
1404 func_modules_to_filelist
1406 echo "$files" | sed -e 's/^/ /'
1408 # Create directories.
1409 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1410 if test "$d" = build-aux; then
1411 mkdir -p "$testdir/$auxdir"
1413 mkdir -p "$testdir/$d"
1417 # Copy files or make symbolic links.
1420 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1423 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1424 if test -z "$symbolic"; then
1425 cp -p "$gnulib_dir/$f" "$testdir/$g"
1427 ln -s "$gnulib_dir/$f" "$testdir/$g"
1431 # Create lib/Makefile.am.
1432 mkdir -p "$testdir/lib"
1433 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1435 # Create m4/Makefile.am.
1436 mkdir -p "$testdir/m4"
1437 (echo "## Process this file with automake to produce Makefile.in."
1443 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1446 ) > "$testdir/m4/Makefile.am"
1449 subdirs_with_configure_ac=""
1451 if test -f "$testdir"/m4/gettext.m4; then
1452 # Avoid stupid error message from automake:
1453 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1454 mkdir -p "$testdir/po"
1455 (echo "## Process this file with automake to produce Makefile.in."
1456 ) > "$testdir/po/Makefile.am"
1457 subdirs="$subdirs po"
1460 if test -n "$inctests"; then
1461 test -d "$testdir/tests" || mkdir "$testdir/tests"
1462 # Create tests/Makefile.am.
1466 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1467 # Create tests/configure.ac.
1468 (echo "# Process this file with autoconf to produce a configure script."
1469 echo "AC_INIT([dummy], [0])"
1470 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1471 echo "AM_INIT_AUTOMAKE"
1473 echo "AM_CONFIG_HEADER([config.h])"
1476 echo "AC_PROG_INSTALL"
1477 echo "AC_PROG_MAKE_SET"
1478 echo "AC_PROG_RANLIB"
1480 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
1481 echo "AC_GNU_SOURCE"
1484 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
1485 echo "gl_USE_SYSTEM_EXTENSIONS"
1488 if grep gl_LOCK "$testdir"/m4/*.m4 > /dev/null; then
1492 if test -z "$libtool"; then
1493 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1495 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1497 sed_replace_build_aux='
1499 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1500 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1503 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1504 # We don't have explicit ordering constraints between the various
1505 # autoconf snippets. It's cleanest to put those of the library before
1506 # those of the tests.
1507 for module in $modules; do
1508 func_verify_nontests_module
1509 if test -n "$module"; then
1510 func_get_autoconf_snippet "$module" \
1511 | sed -e "$sed_replace_build_aux"
1514 for module in $modules; do
1515 func_verify_tests_module
1516 if test -n "$module"; then
1517 func_get_autoconf_snippet "$module" \
1518 | sed -e "$sed_replace_build_aux"
1522 # Usually tests/config.h will be a superset of config.h. Verify this by
1523 # "merging" config.h into tests/config.h; look out for gcc warnings.
1524 echo "AH_TOP([#include \"../config.h\"])"
1526 echo "AC_OUTPUT([Makefile])"
1527 ) > "$testdir/tests/configure.ac"
1528 subdirs="$subdirs tests"
1529 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1532 # Create Makefile.am.
1533 (echo "## Process this file with automake to produce Makefile.in."
1535 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1537 echo "SUBDIRS = $subdirs"
1539 echo "ACLOCAL_AMFLAGS = -I m4"
1540 ) > "$testdir/Makefile.am"
1542 # Create configure.ac.
1543 (echo "# Process this file with autoconf to produce a configure script."
1544 echo "AC_INIT([dummy], [0])"
1545 if test "$auxdir" != "."; then
1546 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1548 echo "AM_INIT_AUTOMAKE"
1550 echo "AM_CONFIG_HEADER([config.h])"
1553 echo "AC_PROG_INSTALL"
1554 echo "AC_PROG_MAKE_SET"
1555 echo "AC_PROG_RANLIB"
1557 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
1558 echo "AC_GNU_SOURCE"
1561 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
1562 echo "gl_USE_SYSTEM_EXTENSIONS"
1565 if grep gl_LOCK "$testdir"/m4/*.m4 > /dev/null; then
1569 if test -z "$libtool"; then
1570 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1572 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1574 sed_replace_build_aux='
1576 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1577 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1580 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1581 for module in $modules; do
1582 func_verify_nontests_module
1583 if test -n "$module"; then
1584 func_get_autoconf_snippet "$module" \
1585 | sed -e "$sed_replace_build_aux"
1589 if test -n "$subdirs_with_configure_ac"; then
1590 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1592 makefiles="Makefile"
1593 for d in $subdirs; do
1594 # For subdirs that have a configure.ac by their own, it's the subdir's
1595 # configure.ac which creates the subdir's Makefile.am, not this one.
1596 case " $subdirs_with_configure_ac " in
1598 *) makefiles="$makefiles $d/Makefile" ;;
1601 echo "AC_OUTPUT([$makefiles])"
1602 ) > "$testdir/configure.ac"
1604 # Create autogenerated files.
1606 echo "executing ${AUTORECONF} --force --install"
1607 ${AUTORECONF} --force --install
1609 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1613 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1621 # func_create_megatestdir megatestdir allmodules
1623 # - auxdir directory relative to destdir where to place build aux files
1624 func_create_megatestdir ()
1628 if test -z "$allmodules"; then
1629 allmodules=`func_all_modules`
1633 # First, all modules one by one.
1634 for onemodule in $allmodules; do
1635 func_create_testdir "$megatestdir/$onemodule" $onemodule
1636 megasubdirs="${megasubdirs}$onemodule "
1638 # Then, all modules all together.
1639 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1640 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1641 func_create_testdir "$megatestdir/ALL" "$allmodules"
1642 megasubdirs="${megasubdirs}ALL"
1644 # Create Makefile.am.
1645 (echo "## Process this file with automake to produce Makefile.in."
1647 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1649 echo "SUBDIRS = $megasubdirs"
1650 ) > "$megatestdir/Makefile.am"
1652 # Create configure.ac.
1653 (echo "# Process this file with autoconf to produce a configure script."
1654 echo "AC_INIT([dummy], [0])"
1655 if test "$auxdir" != "."; then
1656 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1658 echo "AM_INIT_AUTOMAKE"
1660 echo "AC_PROG_MAKE_SET"
1662 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1663 echo "AC_OUTPUT([Makefile])"
1664 ) > "$megatestdir/configure.ac"
1666 # Create autogenerated files.
1668 # Do not use "${AUTORECONF} --install", because autoreconf operates
1669 # recursively, but the subdirectories are already finished, therefore
1670 # calling autoreconf here would only waste lots of CPU time.
1671 echo "executing ${ACLOCAL}"
1673 echo "executing mkdir build-aux"
1675 echo "executing ${AUTOCONF}"
1677 echo "executing ${AUTOMAKE} --add-missing --copy"
1678 ${AUTOMAKE} --add-missing --copy
1684 func_fatal_error "no mode specified" ;;
1693 if test -z "$destdir"; then
1696 test -d "$destdir" \
1697 || func_fatal_error "destination directory does not exist: $destdir"
1699 # Prefer configure.ac to configure.in.
1700 if test -f "$destdir"/configure.ac; then
1701 configure_ac="$destdir/configure.ac"
1703 if test -f "$destdir"/configure.in; then
1704 configure_ac="$destdir/configure.in"
1706 func_fatal_error "cannot find $destdir/configure.ac"
1710 test -f "$destdir"/Makefile.am \
1711 || func_fatal_error "cannot find $destdir/Makefile.am"
1713 # Analyze configure.ac.
1720 /AC_CONFIG_AUX_DIR/ {
1721 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1723 /A[CM]_PROG_LIBTOOL/ {
1724 s,^.*$,guessed_libtool=true,p
1726 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1728 if test -z "$auxdir"; then
1729 auxdir="$guessed_auxdir"
1732 # Determine where to apply func_import.
1733 if test -n "$m4base"; then
1734 # Apply func_import to a particular gnulib directory.
1735 # Any number of additional modules can be given.
1736 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1737 # First use of gnulib in the given m4base.
1738 test -n "$supplied_libname" || supplied_libname=true
1739 test -n "$sourcebase" || sourcebase="lib"
1740 test -n "$testsbase" || testsbase="tests"
1741 test -n "$macro_prefix" || macro_prefix="gl"
1745 # Apply func_import to all gnulib directories.
1746 # To get this list of directories, look at Makefile.am. (Not at
1747 # configure, because it may be omitted from CVS. Also, don't run
1748 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1749 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
1753 for arg in $aclocal_amflags; do
1754 if test -n "$m4dir_is_next"; then
1755 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1759 if test -f "$destdir/$arg"/gnulib-cache.m4; then
1760 m4dirs="$m4dirs $arg"
1761 m4dirs_count=`expr $m4dirs_count + 1`
1766 if test "X$arg" = "X-I"; then
1773 if test $m4dirs_count = 0; then
1774 # First use of gnulib in a package.
1775 # Any number of additional modules can be given.
1776 test -n "$supplied_libname" || supplied_libname=true
1777 test -n "$sourcebase" || sourcebase="lib"
1779 test -n "$testsbase" || testsbase="tests"
1780 test -n "$macro_prefix" || macro_prefix="gl"
1783 if test $m4dirs_count = 1; then
1784 # There's only one use of gnulib here. Assume the user means it.
1785 # Any number of additional modules can be given.
1786 for m4base in $m4dirs; do
1790 # Ambiguous - guess what the user meant.
1791 if test $# = 0; then
1792 # No further arguments. Guess the user wants to update all of them.
1793 for m4base in $m4dirs; do
1798 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
1806 if test -z "$destdir"; then
1807 func_fatal_error "please specify --dir option"
1810 test -d "$destdir" \
1811 || func_fatal_error "could not create destination directory"
1812 test -n "$auxdir" || auxdir="build-aux"
1813 func_create_testdir "$destdir" "$*"
1816 create-megatestdir )
1817 if test -z "$destdir"; then
1818 func_fatal_error "please specify --dir option"
1820 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1821 test -n "$auxdir" || auxdir="build-aux"
1822 func_create_megatestdir "$destdir" "$*"
1826 test -n "$destdir" || destdir=testdir$$
1827 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1828 test -n "$auxdir" || auxdir="build-aux"
1829 func_create_testdir "$destdir" "$*"
1837 remaining=`find . -type f -print`
1838 if test -n "$remaining"; then
1839 echo "Remaining files:" $remaining 1>&2
1840 echo "gnulib-tool: *** Stop." 1>&2
1849 test -n "$destdir" || destdir=testdir$$
1850 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1851 test -n "$auxdir" || auxdir="build-aux"
1852 func_create_megatestdir "$destdir" "$*"
1860 remaining=`find . -type f -print`
1861 if test -n "$remaining"; then
1862 echo "Remaining files:" $remaining 1>&2
1863 echo "gnulib-tool: *** Stop." 1>&2
1871 extract-description )
1875 if test -n "$module"; then
1876 func_get_description "$module"
1885 if test -n "$module"; then
1886 func_get_filelist "$module"
1891 extract-dependencies )
1895 if test -n "$module"; then
1896 func_get_dependencies "$module"
1901 extract-autoconf-snippet )
1905 if test -n "$module"; then
1906 func_get_autoconf_snippet "$module"
1911 extract-automake-snippet )
1915 if test -n "$module"; then
1916 func_get_automake_snippet "$module"
1921 extract-include-directive )
1925 if test -n "$module"; then
1926 func_get_include_directive "$module"
1935 if test -n "$module"; then
1936 func_get_license "$module"
1941 extract-maintainer )
1945 if test -n "$module"; then
1946 func_get_maintainer "$module"
1951 extract-tests-module )
1955 if test -n "$module"; then
1956 func_get_tests_module "$module"
1962 func_fatal_error "unknown operation mode --$mode" ;;