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-11-13 12:33:07 $'
26 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
27 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
31 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
35 # AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
36 # AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
40 # You can set AUTOMAKEPATH to empty if automake 1.9.x is already in your PATH.
43 # You can set GETTEXTPATH to empty if autopoint 0.15 is already in your PATH.
46 # If you didn't set AUTOCONFPATH and AUTOMAKEPATH, you can also set the
47 # variables AUTOCONF, AUTOHEADER, ACLOCAL, AUTOMAKE, AUTORECONF individually.
48 if test -z "${AUTOCONF}" || test -n "${AUTOCONFPATH}"; then
49 AUTOCONF="${AUTOCONFPATH}autoconf"
51 if test -z "${AUTOHEADER}" || test -n "${AUTOCONFPATH}"; then
52 AUTOHEADER="${AUTOCONFPATH}autoheader"
54 if test -z "${ACLOCAL}" || test -n "${AUTOMAKEPATH}"; then
55 ACLOCAL="${AUTOMAKEPATH}aclocal"
57 if test -z "${AUTOMAKE}" || test -n "${AUTOMAKEPATH}"; then
58 AUTOMAKE="${AUTOMAKEPATH}automake"
60 if test -z "${AUTORECONF}" || test -n "${AUTOCONFPATH}"; then
61 AUTORECONF="${AUTOCONFPATH}autoreconf"
64 # If you didn't set GETTEXTPATH, you can also set the variable AUTOPOINT.
65 if test -z "${AUTOPOINT}" || test -n "${GETTEXTPATH}"; then
66 AUTOPOINT="${GETTEXTPATH}autopoint"
69 # GNU sort is needed. Set SORT to its location (not needed if it's called
70 # 'sort' and already in the PATH).
71 if test -z "$SORT"; then
76 # outputs to stdout the --help usage message.
80 Usage: gnulib-tool --list
81 gnulib-tool --import [module1 ... moduleN]
83 gnulib-tool --create-testdir --dir=directory [module1 ... moduleN]
84 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
85 gnulib-tool --test --dir=directory module1 ... moduleN
86 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
87 gnulib-tool --extract-description module
88 gnulib-tool --extract-filelist module
89 gnulib-tool --extract-dependencies module
90 gnulib-tool --extract-autoconf-snippet module
91 gnulib-tool --extract-automake-snippet module
92 gnulib-tool --extract-include-directive module
93 gnulib-tool --extract-license module
94 gnulib-tool --extract-maintainer module
95 gnulib-tool --extract-tests-module module
98 --list print the available module names
99 --import import the given modules into the current package;
100 if no modules are specified, update the current
101 package from the current gnulib
102 --update update the current package, restore files omitted
104 --create-testdir create a scratch package with the given modules
105 --create-megatestdir create a mega scratch package with the given modules
106 one by one and all together
107 --test test the combination of the given modules
108 (recommended to use CC=\"gcc -Wall\" here)
109 --megatest test the given modules one by one and all together
110 (recommended to use CC=\"gcc -Wall\" here)
111 --extract-description extract the description
112 --extract-filelist extract the list of files
113 --extract-dependencies extract the dependencies
114 --extract-autoconf-snippet extract the snippet for configure.ac
115 --extract-automake-snippet extract the snippet for library makefile
116 --extract-include-directive extract the #include directive
117 --extract-license report the license terms of the source files
119 --extract-maintainer report the maintainer(s) inside gnulib
120 --extract-tests-module report the unit test module, if it exists
123 --dir=DIRECTORY Specify the target directory.
124 For --import, this specifies where your
125 configure.ac can be found. Defaults to current
127 --local-dir=DIRECTORY Specify a local override directory where to look
128 up files before looking in gnulib's directory.
130 Options for --import:
131 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
132 --source-base=DIRECTORY
133 Directory relative to --dir where source code is
134 placed (default \"lib\").
135 --m4-base=DIRECTORY Directory relative to --dir where *.m4 macros are
136 placed (default \"m4\").
137 --doc-base=DIRECTORY Directory relative to --dir where doc files are
138 placed (default \"doc\").
139 --tests-base=DIRECTORY
140 Directory relative to --dir where unit tests are
141 placed (default \"tests\").
142 --aux-dir=DIRECTORY Directory relative to --dir where auxiliary build
143 tools are placed (default \"build-aux\").
144 --with-tests Include unit tests for the included modules.
145 --avoid=MODULE Avoid including the given MODULE. Useful if you
146 have code that provides equivalent functionality.
147 This option can be repeated.
148 --lgpl Abort if modules aren't available under the LGPL.
149 Also modify license template from GPL to LGPL.
150 --makefile-name=NAME Name of makefile in automake syntax in the
151 source-base and tests-base directories
152 (default \"Makefile.am\").
153 --libtool Use libtool rules.
154 --no-libtool Don't use libtool rules.
155 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
156 'gl_INIT'. Default is 'gl'.
157 --no-changelog don't update or create ChangeLog files
159 Options for --import and --update:
160 --dry-run For --import, only print what would have been done.
161 -s, --symbolic, --symlink Make symbolic links instead of copying files.
163 Report bugs to <bug-gnulib@gnu.org>."
167 # outputs to stdout the --version message.
170 year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
172 $progname (GNU $package) $version
173 Copyright (C) $year Free Software Foundation, Inc.
174 This is free software; see the source for copying conditions. There is NO
175 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
176 Written by" "Bruno Haible" "and" "Simon Josefsson"
179 # func_emit_copyright_notice
180 # outputs to stdout a header for a generated file.
181 func_emit_copyright_notice ()
183 echo "# Copyright (C) 2004-2006 Free Software Foundation, Inc."
185 echo "# This file is free software, distributed under the terms of the GNU"
186 echo "# General Public License. As a special exception to the GNU General"
187 echo "# Public License, this file may be distributed as part of a program"
188 echo "# that contains a configuration script generated by Autoconf, under"
189 echo "# the same distribution terms as the rest of that program."
191 echo "# Generated by gnulib-tool."
202 # creates a temporary directory.
204 # - tmp pathname of freshly created temporary directory
207 # Use the environment variable TMPDIR, falling back to /tmp. This allows
208 # users to specify a different temporary directory, for example, if their
209 # /tmp is filled up or too small.
212 # Use the mktemp program if available. If not available, hide the error
214 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
215 test -n "$tmp" && test -d "$tmp"
218 # Use a simple mkdir command. It is guaranteed to fail if the directory
219 # already exists. $RANDOM is bash specific and expands to empty in shells
220 # other than bash, ksh and zsh. Its use does not increase security;
221 # rather, it minimizes the probability of failure in a very cluttered /tmp
223 tmp=$TMPDIR/gl$$-$RANDOM
224 (umask 077 && mkdir "$tmp")
227 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
232 # func_append var value
233 # appends the given value to the shell variable var.
234 if ( foo=bar; foo+=baz && test "$foo" = barbaz ) >/dev/null 2>&1; then
235 # Use bash's += operator. It reduces complexity of appending repeatedly to
236 # a single variable from O(n^2) to O(n).
244 eval "$1=\"\$$1\$2\""
248 # func_fatal_error message
249 # outputs to stderr a fatal error message, and terminates the program.
252 echo "gnulib-tool: *** $1" 1>&2
253 echo "gnulib-tool: *** Stop." 1>&2
257 # func_readlink SYMLINK
258 # outputs the target of the given symlink.
259 if (type -p readlink) > /dev/null 2>&1; then
262 # Use the readlink program from GNU coreutils.
268 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
269 # would do the wrong thing if the link target contains " -> ".
270 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
274 # func_ln_if_changed SRC DEST
275 # Like ln -s, but avoids munging timestamps if the link is correct.
276 func_ln_if_changed ()
278 if test $# -ne 2; then
279 echo "usage: func_ln_if_changed SRC DEST" >&2
281 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
289 # func_relativize DIR1 DIR2
290 # computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
292 # - DIR1 relative pathname, relative to the current directory
293 # - DIR2 relative pathname, relative to the current directory
295 # - reldir relative pathname of DIR2, relative to DIR1
301 sed_first='s,^\([^/]*\)/.*$,\1,'
302 sed_rest='s,^[^/]*/*,,'
303 sed_last='s,^.*/\([^/]*\)$,\1,'
304 sed_butlast='s,/*[^/]*$,,'
305 while test -n "$dir1"; do
306 first=`echo "$dir1" | sed -e "$sed_first"`
307 if test "$first" != "."; then
308 if test "$first" = ".."; then
309 dir2=`echo "$dir0" | sed -e "$sed_last"`/"$dir2"
310 dir0=`echo "$dir0" | sed -e "$sed_butlast"`
312 first2=`echo "$dir2" | sed -e "$sed_first"`
313 if test "$first2" = "$first"; then
314 dir2=`echo "$dir2" | sed -e "$sed_rest"`
318 dir0="$dir0"/"$first"
321 dir1=`echo "$dir1" | sed -e "$sed_rest"`
326 # func_relconcat DIR1 DIR2
327 # computes a relative pathname DIR1/DIR2, with obvious simplifications.
329 # - DIR1 relative pathname, relative to the current directory
330 # - DIR2 relative pathname, relative to DIR1
332 # - relconcat DIR1/DIR2, relative to the current directory
337 sed_first='s,^\([^/]*\)/.*$,\1,'
338 sed_rest='s,^[^/]*/*,,'
339 sed_last='s,^.*/\([^/]*\)$,\1,'
340 sed_butlast='s,/*[^/]*$,,'
342 first=`echo "$dir2" | sed -e "$sed_first"`
343 if test "$first" = "."; then
344 dir2=`echo "$dir2" | sed -e "$sed_rest"`
345 if test -z "$dir2"; then
350 last=`echo "$dir1" | sed -e "$sed_last"`
351 while test "$last" = "."; do
352 dir1=`echo "$dir1" | sed -e "$sed_butlast"`
353 last=`echo "$dir1" | sed -e "$sed_last"`
355 if test -z "$dir1"; then
359 if test "$first" = ".."; then
360 if test "$last" = ".."; then
361 relconcat="$dir1/$dir2"
364 dir1=`echo "$dir1" | sed -e "$sed_butlast"`
365 dir2=`echo "$dir2" | sed -e "$sed_rest"`
366 if test -z "$dir1"; then
370 if test -z "$dir2"; then
375 relconcat="$dir1/$dir2"
382 # Command-line option processing.
383 # Removes the OPTIONS from the arguments. Sets the variables:
384 # - mode list or import or create-testdir or create-megatestdir
385 # - destdir from --dir
386 # - local_gnulib_dir from --local-dir
387 # - libname, supplied_libname from --lib
388 # - sourcebase from --source-base
389 # - m4base from --m4-base
390 # - docbase from --doc-base
391 # - testsbase from --tests-base
392 # - auxdir from --aux-dir
393 # - inctests true if --with-tests was given, blank otherwise
394 # - avoidlist list of modules to avoid, from --avoid
395 # - lgpl true if --lgpl was given, blank otherwise
396 # - makefile_name from --makefile-name
397 # - libtool true if --libtool was given, false if --no-libtool was
398 # given, blank otherwise
399 # - macro_prefix from --macro-prefix
400 # - autoconf_minversion minimum supported autoconf version
401 # - do_changelog false if --no-changelog was given, : otherwise
402 # - doit : if actions shall be executed, false if only to be printed
403 # - symbolic true if --symbolic was given, blank otherwise
427 while test $# -gt 0; do
432 --import | --impor | --impo | --imp | --im | --i )
435 --update | --updat | --upda | --upd | --up | --u )
438 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
441 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
442 mode=create-megatestdir
444 --test | --tes | --te | --t )
447 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
451 mode=`echo "X$1" | sed -e 's/^X--//'`
456 func_fatal_error "missing argument for --dir"
461 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
466 func_fatal_error "missing argument for --local-dir"
471 local_gnulib_dir=`echo "X$1" | sed -e 's/^X--local-dir=//'`
476 func_fatal_error "missing argument for --lib"
479 supplied_libname=true
482 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
483 supplied_libname=true
488 func_fatal_error "missing argument for --source-base"
493 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
498 func_fatal_error "missing argument for --m4-base"
503 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
508 func_fatal_error "missing argument for --doc-base"
513 docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
518 func_fatal_error "missing argument for --tests-base"
523 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
528 func_fatal_error "missing argument for --aux-dir"
533 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
541 func_fatal_error "missing argument for --avoid"
543 func_append avoidlist " $1"
546 arg=`echo "X$1" | sed -e 's/^X--avoid=//'`
547 func_append avoidlist " $arg"
555 func_fatal_error "missing argument for --makefile-name"
560 makefile_name=`echo "X$1" | sed -e 's/^X--makefile-name=//'`
571 func_fatal_error "missing argument for --macro-prefix"
576 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
578 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
584 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
587 --help | --hel | --he | --h )
590 --version | --versio | --versi | --vers | --ver | --ve | --v )
594 # Stop option processing
598 echo "gnulib-tool: unknown option $1" 1>&2
599 echo "Try 'gnulib-tool --help' for more information." 1>&2
606 if test "$mode" = update; then
607 if test $# != 0; then
608 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
609 echo "Try 'gnulib-tool --help' for more information." 1>&2
610 echo "If you really want to modify the gnulib configuration of your project," 1>&2
611 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
614 if test -n "$local_gnulib_dir" || test -n "$supplied_libname" \
615 || test -n "$sourcebase" || test -n "$m4base" \
616 || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
617 || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
618 || test -n "$makefile_name" || test -n "$macro_prefix"; then
619 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
620 echo "Try 'gnulib-tool --help' for more information." 1>&2
621 echo "If you really want to modify the gnulib configuration of your project," 1>&2
622 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
628 # Determine the minimum supported autoconf version from the project's
630 DEFAULT_AUTOCONF_MINVERSION="2.59"
633 if { test "$mode" = import || test "$mode" = update; } && test -n "$destdir"; then
634 if test -f "$destdir"/configure.ac; then
635 configure_ac="$destdir/configure.ac"
637 if test -f "$destdir"/configure.in; then
638 configure_ac="$destdir/configure.in"
642 if test -f configure.ac; then
643 configure_ac="configure.ac"
645 if test -f configure.in; then
646 configure_ac="configure.in"
650 if test -n "$configure_ac"; then
651 # Use sed, not autoconf --trace, to look for the AC_PREREQ invocation,
652 # because when some m4 files are omitted from a CVS repository,
653 # "autoconf --trace=AC_PREREQ" fails with an error message like this:
654 # m4: aclocal.m4:851: Cannot open m4/absolute-header.m4: No such file or directory
655 # autom4te: m4 failed with exit status: 1
662 s,^.*AC_PREREQ([[ ]*\([^])]*\).*$,prereqs="$prereqs \1",p
664 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
665 if test -n "$prereqs"; then
666 autoconf_minversion=`for version in $prereqs; do echo $version; done | $SORT -g -u | tail -1`
669 if test -z "$autoconf_minversion"; then
670 autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
672 case "$autoconf_minversion" in
673 1.* | 2.[0-4]* | 2.5[0-8]*)
674 func_fatal_error "minimum supported autoconf version is 2.59. Try adding AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
677 # Remove trailing slashes from the directory names. This is necessary for
678 # m4base (to avoid an error in func_import) and optional for the others.
679 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
680 case "$local_gnulib_dir" in
681 */ ) local_gnulib_dir=`echo "$local_gnulib_dir" | sed -e "$sed_trimtrailingslashes"` ;;
683 case "$sourcebase" in
684 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
687 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
690 */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
693 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
696 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
701 /*) self_abspathname="$0" ;;
702 */*) self_abspathname=`pwd`/"$0" ;;
703 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
704 if test -x "$d/$0" && test ! -d "$d/$0"; then
705 self_abspathname="$d/$0"
709 if test -z "$self_abspathname"; then
710 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
714 while test -h "$self_abspathname"; do
715 # Resolve symbolic link.
716 linkval=`func_readlink "$self_abspathname"`
717 test -n "$linkval" || break
719 /* ) self_abspathname="$linkval" ;;
720 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
723 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
727 if test "$signal" != 0; then
728 echo "caught signal $signal" >&2
732 for signal in 1 2 3 13 15; do
733 trap '{ signal='$signal'; func_exit 1; }' $signal
737 # func_lookup_file file
738 # looks up a file in $local_gnulib_dir or $gnulib_dir, or combines it through
741 # - local_gnulib_dir from --local-dir
743 # - lookedup_file name of the merged (combined) file
744 # - lookedup_tmp true if it is located in the tmp directory, blank otherwise
748 if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile"; then
749 lookedup_file="$local_gnulib_dir/$lkfile"
752 if test -f "$gnulib_dir/$lkfile"; then
753 if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile.diff"; then
754 lkbase=`echo "$lkfile" | sed -e 's,^.*/,,'`
756 cp "$gnulib_dir/$lkfile" "$tmp/$lkbase"
757 patch -s "$tmp/$lkbase" < "$local_gnulib_dir/$lkfile.diff" \
758 || func_fatal_error "patch file $local_gnulib_dir/$lkfile.diff didn't apply cleanly"
759 lookedup_file="$tmp/$lkbase"
762 lookedup_file="$gnulib_dir/$lkfile"
766 func_fatal_error "file $gnulib_dir/$lkfile not found"
773 # - local_gnulib_dir from --local-dir
776 # Filter out metainformation files like README, which are not modules.
777 # Filter out unit test modules; they can be retrieved through
778 # --extract-tests-module if desired.
780 (cd "$gnulib_dir/modules" && ls -1)
781 if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
782 (cd "$local_gnulib_dir/modules" && ls -1 | sed -e 's,\.diff$,,')
785 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^COPYING$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
786 | sed -e '/-tests$/d' \
791 # verifies a module name
793 # - local_gnulib_dir from --local-dir
794 # - module module name argument
795 func_verify_module ()
797 if { test -f "$gnulib_dir/modules/$module" \
798 || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
799 && test -f "$local_gnulib_dir/modules/$module"; }; } \
800 && test "CVS" != "$module" \
801 && test "ChangeLog" != "$module" \
802 && test "COPYING" != "$module" \
803 && test "README" != "$module" \
804 && test "TEMPLATE" != "$module" \
805 && test "TEMPLATE-TESTS" != "$module"; then
806 # OK, $module is a correct module name.
807 # Verify that building the module description with 'patch' succeeds.
808 func_lookup_file "modules/$module"
810 echo "gnulib-tool: module $module doesn't exist" 1>&2
815 # func_verify_nontests_module
816 # verifies a module name, excluding tests modules
818 # - local_gnulib_dir from --local-dir
819 # - module module name argument
820 func_verify_nontests_module ()
824 * ) func_verify_module ;;
828 # func_verify_tests_module
829 # verifies a module name, considering only tests modules
831 # - local_gnulib_dir from --local-dir
832 # - module module name argument
833 func_verify_tests_module ()
836 *-tests ) func_verify_module ;;
841 sed_extract_prog=':[ ]*$/ {
844 s/^Description:[ ]*$//
846 s/^Depends-on:[ ]*$//
847 s/^configure\.ac:[ ]*$//
848 s/^Makefile\.am:[ ]*$//
851 s/^Maintainer:[ ]*$//
858 # func_get_description module
860 # - local_gnulib_dir from --local-dir
861 func_get_description ()
863 func_lookup_file "modules/$1"
864 sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
867 # func_get_filelist module
869 # - local_gnulib_dir from --local-dir
872 func_lookup_file "modules/$1"
873 sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"
874 case "$autoconf_minversion" in
877 echo m4/onceonly_2_57.m4
882 # func_get_dependencies module
884 # - local_gnulib_dir from --local-dir
885 func_get_dependencies ()
887 # ${module}-tests always implicitly depends on ${module}.
888 echo "$1" | sed -n -e 's/-tests//p'
889 # Then the explicit dependencies listed in the module description.
890 func_lookup_file "modules/$1"
891 sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"
894 # func_get_autoconf_snippet module
896 # - local_gnulib_dir from --local-dir
897 func_get_autoconf_snippet ()
899 func_lookup_file "modules/$1"
900 sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
903 # func_get_automake_snippet module
905 # - local_gnulib_dir from --local-dir
906 func_get_automake_snippet ()
908 func_lookup_file "modules/$1"
909 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
912 # *-tests module live in tests/, not lib/.
915 # Synthesize an EXTRA_DIST augmentation.
916 sed_combine_lines='/\\$/{
923 sed_extract_mentioned_files='s/^lib_SOURCES[ ]*+=[ ]*//p'
924 already_mentioned_files=` \
925 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file" \
926 | sed -e "$sed_combine_lines" \
927 | sed -n -e "$sed_extract_mentioned_files" | sed -e 's/#.*//'`
928 all_files=`func_get_filelist $1`
929 lib_files=`for f in $all_files; do \
933 done | sed -e 's,^lib/,,'`
934 # Remove $already_mentioned_files from $lib_files.
935 echo "$lib_files" | LC_ALL=C sort -u > "$tmp"/lib-files
936 extra_files=`for f in $already_mentioned_files; do echo $f; done \
937 | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/lib-files`
938 if test -n "$extra_files"; then
939 echo "EXTRA_DIST +=" $extra_files
942 # Synthesize also an EXTRA_lib_SOURCES augmentation.
943 # This is necessary so that automake can generate the right list of
945 # A possible approach would be to use autom4te --trace of the redefined
946 # AC_LIBOBJ and AC_REPLACE_FUNCS macros when creating the Makefile.am
947 # (use autom4te --trace, not just grep, so that AC_LIBOBJ invocations
948 # inside autoconf's built-in macros are not missed).
949 # But it's simpler and more robust to do it here, based on the file list.
950 # If some .c file exists and is not used with AC_LIBOBJ - for example,
951 # a .c file is preprocessed into another .c file for BUILT_SOURCES -,
952 # automake will generate a useless dependency; this is harmless.
953 sed_extract_c_files='/\.c$/p'
954 extra_files=`echo "$extra_files" | sed -n -e "$sed_extract_c_files"`
955 if test -n "$extra_files"; then
956 echo "EXTRA_lib_SOURCES +=" $extra_files
963 # func_get_include_directive module
965 # - local_gnulib_dir from --local-dir
966 func_get_include_directive ()
968 func_lookup_file "modules/$1"
969 sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" | \
970 sed -e 's/^\(["<]\)/#include \1/'
973 # func_get_license module
975 # - local_gnulib_dir from --local-dir
978 func_lookup_file "modules/$1"
979 sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
982 # func_get_maintainer module
984 # - local_gnulib_dir from --local-dir
985 func_get_maintainer ()
987 func_lookup_file "modules/$1"
988 sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
991 # func_get_tests_module module
993 # - local_gnulib_dir from --local-dir
994 func_get_tests_module ()
996 # The naming convention for tests modules is hardwired: ${module}-tests.
997 if test -f "$gnulib_dir/modules/$1"-tests \
998 || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
999 && test -f "$local_gnulib_dir/modules/$1"-tests; }; then
1004 # func_acceptable module
1005 # tests whether a module is acceptable.
1007 # - avoidlist list of modules to avoid
1010 for avoid in $avoidlist; do
1011 if test "$avoid" = "$1"; then
1018 # func_modules_transitive_closure
1020 # - local_gnulib_dir from --local-dir
1021 # - modules list of specified modules
1022 # - inctests true if tests should be included, blank otherwise
1023 # - avoidlist list of modules to avoid
1024 # - tmp pathname of a temporary directory
1026 # - modules list of modules, including dependencies
1027 func_modules_transitive_closure ()
1029 # In order to process every module only once (for speed), process an "input
1030 # list" of modules, producing an "output list" of modules. During each round,
1031 # more modules can be queued in the input list. Once a module on the input
1032 # list has been processed, it is added to the "handled list", so we can avoid
1033 # to process it again.
1035 inmodules="$modules"
1037 while test -n "$inmodules"; do
1038 inmodules_this_round="$inmodules"
1039 inmodules= # Accumulator, queue for next round
1040 for module in $inmodules_this_round; do
1042 if test -n "$module"; then
1043 if func_acceptable $module; then
1044 func_append outmodules " $module"
1045 deps=`func_get_dependencies $module`
1046 # Duplicate dependencies are harmless, but Jim wants a warning.
1047 duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
1048 if test -n "$duplicated_deps"; then
1049 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
1051 func_append inmodules " $deps"
1052 if test -n "$inctests"; then
1053 testsmodule=`func_get_tests_module $module`
1054 if test -n "$testsmodule"; then
1055 func_append inmodules " $testsmodule"
1061 handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
1062 # Remove $handledmodules from $inmodules.
1063 for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
1064 inmodules=`echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
1066 modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
1067 rm -f "$tmp"/queued-modules
1070 # func_modules_add_dummy
1072 # - local_gnulib_dir from --local-dir
1073 # - modules list of modules, including dependencies
1075 # - modules list of modules, including 'dummy' if needed
1076 func_modules_add_dummy ()
1079 sed_remove_backslash_newline=':a
1086 for module in $modules; do
1087 func_verify_nontests_module
1088 if test -n "$module"; then
1089 # Extract the value of "lib_SOURCES += ...".
1090 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
1091 # Ignore .h files since they are not compiled.
1094 *) have_lib_SOURCES=yes ;;
1099 # Add the dummy module, to make sure the library will be non-empty.
1100 if test -z "$have_lib_SOURCES"; then
1101 func_append modules " dummy"
1105 # func_modules_to_filelist
1107 # - local_gnulib_dir from --local-dir
1108 # - modules list of modules, including dependencies
1110 # - files list of files
1111 func_modules_to_filelist ()
1114 for module in $modules; do
1116 if test -n "$module"; then
1117 fs=`func_get_filelist $module`
1118 func_append files " $fs"
1121 files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
1124 # func_emit_lib_Makefile_am
1125 # emits the contents of library makefile to standard output.
1127 # - local_gnulib_dir from --local-dir
1128 # - modules list of modules, including dependencies
1129 # - libname library name
1130 # - makefile_name from --makefile-name
1131 # - libtool true if libtool will be used, false or blank otherwise
1132 # - macro_prefix prefix of gl_LIBOBJS macros to use
1133 # - actioncmd (optional) command that will reproduce this invocation
1134 func_emit_lib_Makefile_am ()
1136 # When creating an includable Makefile.am snippet, augment variables with
1137 # += instead of assigning them.
1138 if test -n "$makefile_name"; then
1143 if test "$libtool" = true; then
1146 sed_eliminate_LDFLAGS=
1150 sed_eliminate_LDFLAGS='/^lib_LDFLAGS[ ]*+=/d'
1152 echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1153 echo "## Process this file with automake to produce Makefile.in."
1154 func_emit_copyright_notice
1155 if test -n "$actioncmd"; then
1156 echo "# Reproduce by: $actioncmd"
1159 if test -z "$makefile_name"; then
1160 echo "AUTOMAKE_OPTIONS = 1.5 gnits"
1164 for module in $modules; do
1165 func_verify_nontests_module
1166 if test -n "$module"; then
1168 func_get_automake_snippet "$module" |
1169 sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1170 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
1171 sed -e "$sed_eliminate_LDFLAGS" |
1172 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
1173 sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1174 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g'
1175 if test "$module" = 'alloca'; then
1176 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
1177 echo "${libname}_${libext}_DEPENDENCIES += @${perhapsLT}ALLOCA@"
1180 # Skip the contents if its entirely empty.
1181 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
1182 echo "## begin gnulib module $module"
1185 echo "## end gnulib module $module"
1192 if grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *= *$libname\\.$libext\$" allsnippets.tmp > /dev/null; then
1193 # One of the snippets already specifies an installation location for the
1194 # library. Don't confuse automake by saying it should not be installed.
1197 # By default, the generated library should not be installed.
1198 echo "noinst_${perhapsLT}LIBRARIES $assign $libname.$libext"
1201 echo "${libname}_${libext}_SOURCES ="
1202 # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1203 # automake during its analyses looks for $(LIBOBJS), not for @LIBOBJS@.
1204 echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1205 echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1206 echo "EXTRA_${libname}_${libext}_SOURCES ="
1207 if test "$libtool" = true; then
1208 echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
1210 if test -z "$makefile_name"; then
1211 echo "noinst_HEADERS ="
1212 # Automake versions < 1.9b create an empty pkgdatadir at installation time
1213 # if you specify pkgdata_DATA to empty. This is a workaround.
1214 if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1215 echo "pkgdata_DATA ="
1218 echo "BUILT_SOURCES ="
1221 echo "MOSTLYCLEANFILES $assign core *.stackdump"
1222 if test -z "$makefile_name"; then
1223 echo "MOSTLYCLEANDIRS ="
1225 echo "DISTCLEANFILES ="
1226 echo "MAINTAINERCLEANFILES ="
1228 echo "AM_CPPFLAGS ="
1233 echo "mostlyclean-local: mostlyclean-generic"
1234 echo " @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1235 echo " if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1236 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1239 rm -f allsnippets.tmp
1242 # func_emit_tests_Makefile_am
1243 # emits the contents of tests makefile to standard output.
1245 # - local_gnulib_dir from --local-dir
1246 # - modules list of modules, including dependencies
1247 # - libname library name
1248 # - makefile_name from --makefile-name
1249 # - libtool true if libtool will be used, false or blank otherwise
1250 # - sourcebase relative directory containing lib source code
1251 # - m4base relative directory containing autoconf macros
1252 # - testsbase relative directory containing unit test code
1253 func_emit_tests_Makefile_am ()
1255 if test "$libtool" = true; then
1260 if test "$libtool" = true; then
1262 sed_eliminate_LDFLAGS=
1265 sed_eliminate_LDFLAGS='/^lib_LDFLAGS[ ]*+=/d'
1267 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
1268 echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1269 echo "## Process this file with automake to produce Makefile.in."
1270 func_emit_copyright_notice
1272 # Generate dependencies here, since it eases the debugging of test failures.
1273 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1275 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
1278 for module in $modules; do
1279 func_verify_tests_module
1280 if test -n "$module"; then
1282 func_get_automake_snippet "$module" |
1283 sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1284 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
1285 sed -e "$sed_eliminate_LDFLAGS" |
1286 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
1287 sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1288 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g'
1290 # Skip the contents if its entirely empty.
1291 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
1292 echo "## begin gnulib module $module"
1295 echo "## end gnulib module $module"
1302 # Nothing is being added to SUBDIRS; nevertheless the existence of this
1303 # variable is needed to avoid an error from automake:
1304 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
1307 echo "TESTS_ENVIRONMENT ="
1308 echo "noinst_PROGRAMS ="
1309 echo "check_PROGRAMS ="
1310 echo "noinst_HEADERS ="
1311 if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1312 echo "pkgdata_DATA ="
1315 echo "BUILT_SOURCES ="
1317 echo "MOSTLYCLEANFILES = core *.stackdump"
1318 echo "MOSTLYCLEANDIRS ="
1320 echo "DISTCLEANFILES ="
1321 echo "MAINTAINERCLEANFILES ="
1323 echo "AM_CPPFLAGS = \\"
1324 echo " -I. -I\$(srcdir) \\"
1325 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
1326 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
1328 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
1331 echo "# Clean up after Solaris cc."
1333 echo " rm -rf SunWS_cache"
1335 echo "mostlyclean-local: mostlyclean-generic"
1336 echo " @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1337 echo " if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1338 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1341 rm -f allsnippets.tmp
1344 # func_emit_initmacro_start
1345 # emits the first few statements of the gl_INIT macro to standard output.
1346 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
1347 func_emit_initmacro_start ()
1349 echo " m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix}_LIBOBJ]))"
1350 echo " m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix}_REPLACE_FUNCS]))"
1353 # func_emit_initmacro_end
1354 # emits the last few statements of the gl_INIT macro to standard output.
1355 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
1356 func_emit_initmacro_end ()
1358 echo " m4_popdef([AC_REPLACE_FUNCS])"
1359 echo " m4_popdef([AC_LIBOBJ])"
1360 echo " AC_CONFIG_COMMANDS_PRE(["
1361 echo " ${macro_prefix}_libobjs="
1362 echo " ${macro_prefix}_ltlibobjs="
1363 echo " if test -n \"\$${macro_prefix}_LIBOBJS\"; then"
1364 echo " # Remove the extension."
1365 echo " sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
1366 echo " for i in \`for i in \$${macro_prefix}_LIBOBJS; do echo \"\$i\"; done | sed \"\$sed_drop_objext\" | sort | uniq\`; do"
1367 echo " ${macro_prefix}_libobjs=\"\$${macro_prefix}_libobjs \$i.\$ac_objext\""
1368 echo " ${macro_prefix}_ltlibobjs=\"\$${macro_prefix}_ltlibobjs \$i.lo\""
1371 echo " AC_SUBST([${macro_prefix}_LIBOBJS], [\$${macro_prefix}_libobjs])"
1372 echo " AC_SUBST([${macro_prefix}_LTLIBOBJS], [\$${macro_prefix}_ltlibobjs])"
1376 # func_emit_initmacro_done
1377 # emits a few statements after the gl_INIT macro to standard output.
1378 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
1379 func_emit_initmacro_done ()
1382 echo "# Like AC_LIBOBJ, except that the module name goes"
1383 echo "# into ${macro_prefix}_LIBOBJS instead of into LIBOBJS."
1384 echo "AC_DEFUN([${macro_prefix}_LIBOBJ],"
1385 echo " [${macro_prefix}_LIBOBJS=\"\$${macro_prefix}_LIBOBJS \$1.\$ac_objext\"])"
1387 echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
1388 echo "# into ${macro_prefix}_LIBOBJS instead of into LIBOBJS."
1389 echo "AC_DEFUN([${macro_prefix}_REPLACE_FUNCS],"
1390 echo " [AC_CHECK_FUNCS([\$1], , [${macro_prefix}_LIBOBJ(\$ac_func)])])"
1393 # func_import modules
1394 # Uses also the variables
1395 # - destdir target directory
1396 # - local_gnulib_dir from --local-dir
1397 # - libname library name
1398 # - sourcebase directory relative to destdir where to place source code
1399 # - m4base directory relative to destdir where to place *.m4 macros
1400 # - docbase directory relative to destdir where to place doc files
1401 # - testsbase directory relative to destdir where to place unit test code
1402 # - auxdir directory relative to destdir where to place build aux files
1403 # - inctests true if --with-tests was given, blank otherwise
1404 # - avoidlist list of modules to avoid, from --avoid
1405 # - lgpl true if library's license shall be LGPL, blank otherwise
1406 # - makefile_name from --makefile-name
1407 # - libtool true if --libtool was given, false if --no-libtool was
1408 # given, blank otherwise
1409 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
1410 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
1411 # - autoconf_minversion minimum supported autoconf version
1412 # - doit : if actions shall be executed, false if only to be printed
1413 # - symbolic true if files should be symlinked, copied otherwise
1416 # Get the cached settings.
1417 cached_local_gnulib_dir=
1418 cached_specified_modules=
1426 cached_makefile_name=
1428 cached_macro_prefix=
1430 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1431 cached_libtool=false
1437 s,^.*gl_LOCAL_DIR([[ ]*\([^])]*\).*$,cached_local_gnulib_dir="\1",p
1440 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
1443 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
1446 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
1449 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
1452 s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
1455 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
1458 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
1461 s,^.*$,cached_lgpl=true,p
1463 /gl_MAKEFILE_NAME(/ {
1464 s,^.*gl_MAKEFILE_NAME([[ ]*\([^])]*\).*$,cached_makefile_name="\1",p
1467 s,^.*$,cached_libtool=true,p
1469 /gl_MACRO_PREFIX(/ {
1470 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
1472 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
1473 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1478 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
1479 s,^.*$,cached_files=",p
1491 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
1495 # Merge the cached settings with the specified ones.
1496 # The m4base must be the same as expected from the pathname.
1497 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
1498 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
1500 # The local_gnulib_dir defaults to the cached one. Recall that the cached one
1501 # is relative to $destdir, whereas the one we use is relative to . or absolute.
1502 if test -z "$local_gnulib_dir"; then
1503 if test -n "$cached_local_gnulib_dir"; then
1506 local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1508 case "$cached_local_gnulib_dir" in
1510 local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1512 func_relconcat "$destdir" "$cached_local_gnulib_dir"
1513 local_gnulib_dir="$relconcat" ;;
1518 # Append the cached and the specified module names. So that
1519 # "gnulib-tool --import foo" means to add the module foo.
1520 specified_modules="$cached_specified_modules $1"
1521 # Append the cached and the specified avoidlist. This is probably better
1522 # than dropping the cached one when --avoid is specified at least once.
1523 avoidlist=`echo $cached_avoidlist $avoidlist`
1524 # The sourcebase defaults to the cached one.
1525 if test -z "$sourcebase"; then
1526 sourcebase="$cached_sourcebase"
1527 if test -z "$sourcebase"; then
1528 func_fatal_error "missing --source-base option"
1531 # The docbase defaults to the cached one.
1532 if test -z "$docbase"; then
1533 docbase="$cached_docbase"
1534 if test -z "$docbase"; then
1535 func_fatal_error "missing --doc-base option. --doc-base has been introduced on 2006-07-11; if your last invocation of 'gnulib-tool --import' is before that date, you need to run 'gnulib-tool --import' once, with a --doc-base option."
1538 # The testsbase defaults to the cached one.
1539 if test -z "$testsbase"; then
1540 testsbase="$cached_testsbase"
1541 if test -z "$testsbase"; then
1542 func_fatal_error "missing --tests-base option"
1545 # The libname defaults to the cached one.
1546 if test -z "$supplied_libname"; then
1547 libname="$cached_libname"
1548 if test -z "$libname"; then
1549 func_fatal_error "missing --lib option"
1552 # Require LGPL if specified either way.
1553 if test -z "$lgpl"; then
1556 # The makefile_name defaults to the cached one.
1557 if test -z "$makefile_name"; then
1558 makefile_name="$cached_makefile_name"
1560 # Use libtool if specified either way, or if guessed.
1561 if test -z "$libtool"; then
1562 if test -n "$cached_m4base"; then
1563 libtool="$cached_libtool"
1565 libtool="$guessed_libtool"
1568 # The macro_prefix defaults to the cached one.
1569 if test -z "$macro_prefix"; then
1570 macro_prefix="$cached_macro_prefix"
1571 if test -z "$macro_prefix"; then
1572 func_fatal_error "missing --macro-prefix option"
1576 # Canonicalize the list of specified modules.
1577 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
1579 # Determine final module list.
1580 modules="$specified_modules"
1581 func_modules_transitive_closure
1582 echo "Module list with included dependencies:"
1583 echo "$modules" | sed -e 's/^/ /'
1585 # Add the dummy module if needed.
1586 func_modules_add_dummy
1588 # If --lgpl, verify that the licenses of modules are compatible.
1589 if test -n "$lgpl"; then
1590 for module in $modules; do
1591 license=`func_get_license $module`
1593 LGPL | 'GPLed build tool') ;;
1594 'public domain' | 'unlimited' | 'unmodifiable license text') ;;
1595 *) func_fatal_error "incompatible license on module $module: $license" ;;
1600 # Determine script to apply to imported library files.
1601 sed_transform_lib_file=
1602 for module in $modules; do
1603 if test $module = config-h; then
1604 # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
1605 sed_transform_lib_file=$sed_transform_lib_file'
1606 s/^#ifdef[ ]*HAVE_CONFIG_H[ ]*$/#if 1/
1611 if test -n "$lgpl"; then
1613 sed_transform_lib_file=$sed_transform_lib_file'
1614 s/GNU General/GNU Lesser General/g
1615 s/version 2\([ ,]\)/version 2.1\1/g
1619 # Determine final file list.
1620 func_modules_to_filelist
1622 echo "$files" | sed -e 's/^/ /'
1625 || func_fatal_error "refusing to do nothing"
1627 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1628 new_files="$files m4/gnulib-tool.m4"
1629 old_files="$cached_files"
1630 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1631 func_append old_files " m4/gnulib-tool.m4"
1634 sed_rewrite_old_files="\
1635 s,^build-aux/,$auxdir/,
1636 s,^doc/,$cached_docbase/,
1637 s,^lib/,$cached_sourcebase/,
1638 s,^m4/,$cached_m4base/,
1639 s,^tests/,$cached_testsbase/,"
1640 sed_rewrite_new_files="\
1641 s,^build-aux/,$auxdir/,
1643 s,^lib/,$sourcebase/,
1645 s,^tests/,$testsbase/,"
1647 # Create directories.
1648 { echo "$sourcebase"
1650 docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
1651 if test -n "$docfiles"; then
1654 if test -n "$inctests"; then
1658 for f in $files; do echo $f; done \
1659 | sed -e "$sed_rewrite_new_files" \
1660 | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
1663 { # Rearrange file descriptors. Needed because "while ... done < ..."
1664 # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
1665 exec 5<&0 < "$tmp"/dirs
1667 if test ! -d "$destdir/$d"; then
1669 echo "Creating directory $destdir/$d"
1670 mkdir -p "$destdir/$d" || func_fatal_error "failed"
1672 echo "Create directory $destdir/$d"
1679 # func_dest_tmpfilename file
1680 # determines the name of a temporary file (file is relative to destdir).
1682 # - tmpfile absolute filename of the temporary file
1683 func_dest_tmpfilename ()
1686 # Put the new contents of $file in a file in the same directory (needed
1687 # to guarantee that an 'mv' to "$destdir/$file" works).
1688 tmpfile="$destdir/$1.tmp"
1690 # Put the new contents of $file in a file in a temporary directory
1691 # (because the directory of "$file" might not exist).
1692 tmpfile="$tmp"/`basename "$1"`.tmp
1696 # Copy files or make symbolic links. Remove obsolete files.
1698 # Construct a table with 2 columns: rewritten-file-name original-file-name,
1699 # representing the files according to the last gnulib-tool invocation.
1700 for f in $old_files; do echo $f; done \
1701 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
1704 # Construct a table with 2 columns: rewritten-file-name original-file-name,
1705 # representing the files after this gnulib-tool invocation.
1706 for f in $new_files; do echo $f; done \
1707 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
1710 # First the files that are in old-files, but not in new-files:
1711 sed_take_first_column='s,'"$delimiter"'.*,,'
1712 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1713 # Remove the file. Do nothing if the user already removed it.
1714 if test -f "$destdir/$g"; then
1716 echo "Removing file $g (backup in ${g}~)"
1717 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1719 echo "Remove file $g (backup in ${g}~)"
1723 # func_add_or_update handles a file that ought to be present afterwards.
1725 # - f the original file name
1726 # - g the rewritten file name
1727 # - already_present nonempty if the file already exists, empty otherwise
1728 func_add_or_update ()
1730 func_dest_tmpfilename "$g"
1731 func_lookup_file "$f"
1732 cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
1733 if test -n "$sed_transform_lib_file"; then
1736 sed -e "$sed_transform_lib_file" \
1737 < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
1741 if test -f "$destdir/$g"; then
1742 # The file already exists.
1743 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1744 : # The file has not changed.
1748 if test -n "$already_present"; then
1749 echo "Updating file $g (backup in ${g}~)"
1751 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1753 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1754 if test -n "$symbolic" && test -z "$lookedup_tmp" \
1755 && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1756 func_ln_if_changed "$lookedup_file" "$destdir/$g"
1758 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1761 if test -n "$already_present"; then
1762 echo "Update file $g (backup in ${g}~)"
1764 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1770 # Don't protest if the file should be there but isn't: it happens
1771 # frequently that developers don't put autogenerated files into CVS.
1773 echo "Copying file $g"
1774 if test -n "$symbolic" && test -z "$lookedup_tmp" \
1775 && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1776 func_ln_if_changed "$lookedup_file" "$destdir/$g"
1778 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1786 # Then the files that are in new-files, but not in old-files:
1787 sed_take_last_column='s,^.*'"$delimiter"',,'
1789 LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
1790 | sed -e "$sed_take_last_column" \
1791 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
1792 { # Rearrange file descriptors. Needed because "while ... done < ..."
1793 # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
1794 exec 5<&0 < "$tmp"/added-files
1800 # Then the files that are in new-files and in old-files:
1801 already_present=true
1802 LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
1803 | sed -e "$sed_take_last_column" \
1804 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
1805 { # Rearrange file descriptors. Needed because "while ... done < ..."
1806 # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
1807 exec 5<&0 < "$tmp"/kept-files
1814 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1815 actioncmd="gnulib-tool --import"
1816 func_append actioncmd " --dir=$destdir"
1817 if test -n "$local_gnulib_dir"; then
1818 func_append actioncmd " --local-dir=$local_gnulib_dir"
1820 func_append actioncmd " --lib=$libname"
1821 func_append actioncmd " --source-base=$sourcebase"
1822 func_append actioncmd " --m4-base=$m4base"
1823 func_append actioncmd " --doc-base=$docbase"
1824 func_append actioncmd " --aux-dir=$auxdir"
1825 for module in $avoidlist; do
1826 func_append actioncmd " --avoid=$module"
1828 if test -n "$lgpl"; then
1829 func_append actioncmd " --lgpl"
1831 if test -n "$makefile_name"; then
1832 func_append actioncmd " --makefile-name=$makefile_name"
1834 if test "$libtool" = true; then
1835 func_append actioncmd " --libtool"
1837 func_append actioncmd " --no-libtool"
1839 func_append actioncmd " --macro-prefix=$macro_prefix"
1840 func_append actioncmd " `echo $specified_modules`"
1842 # Default the makefile name to Makefile.am.
1843 if test -n "$makefile_name"; then
1844 makefile_am=$makefile_name
1846 makefile_am=Makefile.am
1849 # Create library makefile.
1850 func_dest_tmpfilename $sourcebase/$makefile_am
1851 func_emit_lib_Makefile_am > "$tmpfile"
1852 if test -f "$destdir"/$sourcebase/$makefile_am; then
1853 if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
1857 echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
1858 mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
1859 mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
1861 echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
1867 echo "Creating $sourcebase/$makefile_am"
1868 mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
1870 echo "Create $sourcebase/$makefile_am"
1875 # Create m4/gnulib-cache.m4.
1876 func_dest_tmpfilename $m4base/gnulib-cache.m4
1878 func_emit_copyright_notice
1880 echo "# This file represents the specification of how gnulib-tool is used."
1881 echo "# It acts as a cache: It is written and read by gnulib-tool."
1882 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1883 echo "# like the configure.ac and various Makefile.am files."
1886 echo "# Specification in the form of a command-line invocation:"
1889 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1890 # Store the local_gnulib_dir relative to destdir.
1891 case "$local_gnulib_dir" in
1893 relative_local_gnulib_dir="$local_gnulib_dir" ;;
1896 /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
1898 # destdir, local_gnulib_dir are both relative.
1899 func_relativize "$destdir" "$local_gnulib_dir"
1900 relative_local_gnulib_dir="$reldir" ;;
1903 echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
1904 echo "gl_MODULES(["`echo $specified_modules`"])"
1905 echo "gl_AVOID([$avoidlist])"
1906 echo "gl_SOURCE_BASE([$sourcebase])"
1907 echo "gl_M4_BASE([$m4base])"
1908 echo "gl_DOC_BASE([$docbase])"
1909 echo "gl_TESTS_BASE([$testsbase])"
1910 echo "gl_LIB([$libname])"
1911 test -z "$lgpl" || echo "gl_LGPL"
1912 echo "gl_MAKEFILE_NAME([$makefile_name])"
1913 if test "$libtool" = true; then
1916 echo "gl_MACRO_PREFIX([$macro_prefix])"
1918 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1919 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1923 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1924 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1925 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1927 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1931 echo "# gnulib-cache.m4 ends here"
1938 echo "Creating $m4base/gnulib-cache.m4"
1939 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1941 echo "Create $m4base/gnulib-cache.m4"
1947 # Create m4/gnulib-comp.m4.
1948 func_dest_tmpfilename $m4base/gnulib-comp.m4
1950 echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
1951 func_emit_copyright_notice
1953 echo "# This file represents the compiled summary of the specification in"
1954 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1955 echo "# to be invoked from configure.ac."
1956 echo "# In projects using CVS, this file can be treated like other built files."
1959 echo "# This macro should be invoked from $configure_ac, in the section"
1960 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1961 echo "# any checks for libraries, header files, types and library functions."
1962 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1964 echo " m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
1965 echo " m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
1966 echo " m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
1967 echo " m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
1968 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1969 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1970 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1972 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1973 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1975 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1976 echo " AC_REQUIRE([gl_LOCK_EARLY])"
1980 echo "# This macro should be invoked from $configure_ac, in the section"
1981 echo "# \"Check for header files, types and library functions\"."
1982 echo "AC_DEFUN([${macro_prefix}_INIT],"
1984 func_emit_initmacro_start
1985 if test "$libtool" = true; then
1986 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1987 echo " gl_cond_libtool=true"
1989 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1990 echo " gl_cond_libtool=false"
1992 echo " gl_ltlibdeps="
1994 echo " gl_source_base='$sourcebase'"
1995 if test "$auxdir" != "build-aux"; then
1996 sed_replace_build_aux='
1998 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1999 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
2002 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
2004 sed_replace_build_aux=
2006 for module in $modules; do
2008 if test -n "$module"; then
2009 func_get_autoconf_snippet "$module" \
2010 | sed -e '/^$/d;' -e 's/^/ /' \
2011 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
2012 -e "$sed_replace_build_aux"
2013 if test "$module" = 'alloca' && test "$libtool" = true; then
2014 echo 'changequote(,)dnl'
2015 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
2016 echo 'changequote([, ])dnl'
2017 echo 'AC_SUBST([LTALLOCA])'
2021 # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2022 # created using libtool, because libtool already handles the dependencies.
2023 if test "$libtool" != true; then
2024 libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
2025 echo " ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2026 echo " AC_SUBST([${libname_upper}_LIBDEPS])"
2027 echo " ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2028 echo " AC_SUBST([${libname_upper}_LTLIBDEPS])"
2030 func_emit_initmacro_end
2032 func_emit_initmacro_done
2034 echo "# This macro records the list of files which have been installed by"
2035 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
2036 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
2037 echo "$files" | sed -e 's,^, ,'
2040 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
2041 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
2045 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
2046 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
2047 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
2049 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
2053 echo "# gnulib-comp.m4 ends here"
2060 echo "Creating $m4base/gnulib-comp.m4"
2061 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
2063 echo "Create $m4base/gnulib-comp.m4"
2069 if test -n "$inctests"; then
2070 # Create tests makefile.
2071 func_dest_tmpfilename $testsbase/$makefile_am
2072 func_emit_tests_Makefile_am > "$tmpfile"
2073 if test -f "$destdir"/$testsbase/$makefile_am; then
2074 if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
2078 echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
2079 mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
2080 mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
2082 echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
2088 echo "Creating $testsbase/$makefile_am"
2089 mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
2091 echo "Create $testsbase/$makefile_am"
2099 echo "You may need to add #include directives for the following .h files."
2100 # First the #include <...> directives without #ifs, sorted for convenience,
2101 # then the #include "..." directives without #ifs, sorted for convenience,
2102 # then the #include directives that are surrounded by #ifs. Not sorted.
2103 for module in $modules; do
2104 include_directive=`func_get_include_directive "$module"`
2105 case "$nl$include_directive" in
2107 echo "$include_directive" 1>&5
2110 echo "$include_directive" | grep -v 'include "' 1>&6
2111 echo "$include_directive" | grep 'include "' 1>&7
2114 done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
2116 LC_ALL=C sort -u "$tmp"/include-angles
2117 LC_ALL=C sort -u "$tmp"/include-quotes
2118 cat "$tmp"/include-if
2119 ) | sed -e '/^$/d' -e 's/^/ /'
2120 rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
2123 echo "Don't forget to"
2124 if test "$makefile_am" = Makefile.am; then
2125 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2127 echo " - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
2129 if test -n "$inctests"; then
2130 if test "$makefile_am" = Makefile.am; then
2131 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2133 echo " - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
2136 if test "$makefile_am" = Makefile.am; then
2137 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
2138 sourcebase_base=`basename "$sourcebase"`
2139 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
2141 if test -n "$inctests"; then
2142 if test "$makefile_am" = Makefile.am; then
2143 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
2144 testsbase_base=`basename "$testsbase"`
2145 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
2148 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
2149 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
2150 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
2153 # func_create_testdir testdir modules
2155 # - local_gnulib_dir from --local-dir
2156 # - auxdir directory relative to destdir where to place build aux files
2157 func_create_testdir ()
2161 if test -z "$modules"; then
2162 # All modules together.
2163 # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
2164 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
2165 # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
2166 modules=`func_all_modules`
2167 modules=`for m in $modules; do case $m in config-h | fnmatch-posix | ftruncate | mountlist) ;; *) echo $m;; esac; done`
2169 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
2171 # Subdirectory names.
2178 # Determine final module list.
2179 func_modules_transitive_closure
2180 echo "Module list with included dependencies:"
2181 echo "$modules" | sed -e 's/^/ /'
2183 # Add the dummy module if needed.
2184 func_modules_add_dummy
2186 # Determine final file list.
2187 func_modules_to_filelist
2189 echo "$files" | sed -e 's/^/ /'
2191 sed_rewrite_files="\
2192 s,^build-aux/,$auxdir/,
2194 s,^lib/,$sourcebase/,
2196 s,^tests/,$testsbase/,"
2198 # Create directories.
2199 for f in $files; do echo $f; done \
2200 | sed -e "$sed_rewrite_files" \
2201 | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
2202 | LC_ALL=C sort -u \
2204 { # Rearrange file descriptors. Needed because "while ... done < ..."
2205 # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2206 exec 5<&0 < "$tmp"/dirs
2208 mkdir -p "$testdir/$d"
2213 # Copy files or make symbolic links.
2215 for f in $files; do echo $f; done \
2216 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
2219 { # Rearrange file descriptors. Needed because "while ... done < ..."
2220 # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2221 exec 5<&0 < "$tmp"/files
2223 func_lookup_file "$f"
2224 if test -n "$lookedup_tmp"; then
2225 cp -p "$lookedup_file" "$testdir/$g"
2227 ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
2228 if test -z "$symbolic"; then
2229 cp -p "$lookedup_file" "$testdir/$g"
2231 ln -s "$lookedup_file" "$testdir/$g"
2238 # Create $sourcebase/Makefile.am.
2239 mkdir -p "$testdir/$sourcebase"
2240 func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
2242 # Create $m4base/Makefile.am.
2243 mkdir -p "$testdir/$m4base"
2244 (echo "## Process this file with automake to produce Makefile.in."
2250 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
2253 ) > "$testdir/$m4base/Makefile.am"
2255 subdirs="$sourcebase $m4base"
2256 subdirs_with_configure_ac=""
2258 if false && test -f "$testdir"/$m4base/gettext.m4; then
2259 # Avoid stupid error message from automake:
2260 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
2261 mkdir -p "$testdir/po"
2262 (echo "## Process this file with automake to produce Makefile.in."
2263 ) > "$testdir/po/Makefile.am"
2264 func_append subdirs " po"
2267 if test -n "$inctests"; then
2268 test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
2269 # Create $testsbase/Makefile.am.
2270 func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
2271 # Create $testsbase/configure.ac.
2272 (echo "# Process this file with autoconf to produce a configure script."
2273 echo "AC_INIT([dummy], [0])"
2274 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
2275 echo "AM_INIT_AUTOMAKE"
2277 echo "AM_CONFIG_HEADER([config.h])"
2280 echo "AC_PROG_INSTALL"
2281 echo "AC_PROG_MAKE_SET"
2282 echo "AC_PROG_RANLIB"
2284 if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2285 echo "AC_GNU_SOURCE"
2288 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2289 echo "gl_USE_SYSTEM_EXTENSIONS"
2292 if grep gl_LOCK "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2293 echo "gl_LOCK_EARLY"
2296 if test "$libtool" = true; then
2297 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2298 echo "gl_cond_libtool=true"
2300 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2301 echo "gl_cond_libtool=false"
2303 echo "gl_ltlibdeps="
2305 echo "gl_source_base='$testsbase'"
2306 # Wrap the set of autoconf snippets into an autoconf macro that is then
2307 # invoked. This is needed because autoconf does not support AC_REQUIRE
2309 # error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2310 # but we want the AC_REQUIRE to have its normal meaning (provide one
2311 # expansion of the required macro before the current point, and only one
2313 echo "AC_DEFUN([gl_INIT], ["
2314 func_emit_initmacro_start
2315 sed_replace_build_aux='
2317 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2318 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
2321 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
2322 # We don't have explicit ordering constraints between the various
2323 # autoconf snippets. It's cleanest to put those of the library before
2324 # those of the tests.
2325 for module in $modules; do
2326 func_verify_nontests_module
2327 if test -n "$module"; then
2328 func_get_autoconf_snippet "$module" \
2329 | sed -e "$sed_replace_build_aux"
2332 for module in $modules; do
2333 func_verify_tests_module
2334 if test -n "$module"; then
2335 func_get_autoconf_snippet "$module" \
2336 | sed -e "$sed_replace_build_aux"
2339 # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2340 # created using libtool, because libtool already handles the dependencies.
2341 if test "$libtool" != true; then
2342 libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
2343 echo " ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2344 echo " AC_SUBST([${libname_upper}_LIBDEPS])"
2345 echo " ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2346 echo " AC_SUBST([${libname_upper}_LTLIBDEPS])"
2348 func_emit_initmacro_end
2350 func_emit_initmacro_done
2354 # Usually $testsbase/config.h will be a superset of config.h. Verify this
2355 # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
2356 echo "AH_TOP([#include \"../config.h\"])"
2358 echo "AC_OUTPUT([Makefile])"
2359 ) > "$testdir/$testsbase/configure.ac"
2360 func_append subdirs " $testsbase"
2361 subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
2364 # Create Makefile.am.
2365 (echo "## Process this file with automake to produce Makefile.in."
2367 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
2369 echo "SUBDIRS = $subdirs"
2371 echo "ACLOCAL_AMFLAGS = -I $m4base"
2372 ) > "$testdir/Makefile.am"
2374 # Create configure.ac.
2375 (echo "# Process this file with autoconf to produce a configure script."
2376 echo "AC_INIT([dummy], [0])"
2377 if test "$auxdir" != "."; then
2378 echo "AC_CONFIG_AUX_DIR([$auxdir])"
2380 echo "AM_INIT_AUTOMAKE"
2382 echo "AM_CONFIG_HEADER([config.h])"
2385 echo "AC_PROG_INSTALL"
2386 echo "AC_PROG_MAKE_SET"
2388 echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2389 echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
2390 echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
2391 echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
2393 echo "AC_PROG_RANLIB"
2395 if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2396 echo "AC_GNU_SOURCE"
2399 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2400 echo "gl_USE_SYSTEM_EXTENSIONS"
2403 if grep gl_LOCK "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2404 echo "gl_LOCK_EARLY"
2407 if test "$libtool" = true; then
2408 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2409 echo "gl_cond_libtool=true"
2411 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2412 echo "gl_cond_libtool=false"
2414 echo "gl_ltlibdeps="
2416 echo "gl_source_base='$sourcebase'"
2417 # Wrap the set of autoconf snippets into an autoconf macro that is then
2418 # invoked. This is needed because autoconf does not support AC_REQUIRE
2420 # error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2421 # but we want the AC_REQUIRE to have its normal meaning (provide one
2422 # expansion of the required macro before the current point, and only one
2424 echo "AC_DEFUN([gl_INIT], ["
2425 func_emit_initmacro_start
2426 if test "$auxdir" != "build-aux"; then
2427 sed_replace_build_aux='
2429 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2430 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
2433 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
2435 sed_replace_build_aux=
2437 for module in $modules; do
2438 func_verify_nontests_module
2439 if test -n "$module"; then
2440 func_get_autoconf_snippet "$module" \
2441 | sed -e "$sed_replace_build_aux"
2444 # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2445 # created using libtool, because libtool already handles the dependencies.
2446 if test "$libtool" != true; then
2447 libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
2448 echo " ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2449 echo " AC_SUBST([${libname_upper}_LIBDEPS])"
2450 echo " ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2451 echo " AC_SUBST([${libname_upper}_LTLIBDEPS])"
2453 func_emit_initmacro_end
2455 func_emit_initmacro_done
2459 if test -n "$subdirs_with_configure_ac"; then
2460 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
2462 makefiles="Makefile"
2463 for d in $subdirs; do
2464 # For subdirs that have a configure.ac by their own, it's the subdir's
2465 # configure.ac which creates the subdir's Makefile.am, not this one.
2466 case " $subdirs_with_configure_ac " in
2468 *) func_append makefiles " $d/Makefile" ;;
2471 echo "AC_OUTPUT([$makefiles])"
2472 ) > "$testdir/configure.ac"
2474 # Create autogenerated files.
2476 # Do not use "${AUTORECONF} --force --install", because it may invoke
2477 # autopoint, which brings in older versions of some of our .m4 files.
2478 if test -f $m4base/gettext.m4; then
2479 echo "executing ${AUTOPOINT} --force"
2480 ${AUTOPOINT} --force || func_exit 1
2481 for f in $m4base/*.m4~; do
2482 mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
2485 echo "executing ${ACLOCAL} -I $m4base"
2486 ${ACLOCAL} -I $m4base || func_exit 1
2487 if ! test -d build-aux; then
2488 echo "executing mkdir build-aux"
2489 mkdir build-aux || func_exit 1
2491 echo "executing ${AUTOCONF}"
2492 ${AUTOCONF} || func_exit 1
2493 echo "executing ${AUTOHEADER}"
2494 ${AUTOHEADER} || func_exit 1
2495 echo "executing ${AUTOMAKE} --add-missing --copy"
2496 ${AUTOMAKE} --add-missing --copy || func_exit 1
2498 if test -n "$inctests"; then
2499 # Create autogenerated files.
2500 (cd "$testdir/$testsbase" || func_exit 1
2501 # Do not use "${AUTORECONF} --force --install", because it may invoke
2502 # autopoint, which brings in older versions of some of our .m4 files.
2503 if test -f ../$m4base/gettext.m4; then
2504 echo "executing ${AUTOPOINT} --force"
2505 ${AUTOPOINT} --force || func_exit 1
2506 for f in ../$m4base/*.m4~; do
2507 mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
2510 echo "executing ${ACLOCAL} -I ../$m4base"
2511 ${ACLOCAL} -I ../$m4base || func_exit 1
2512 if ! test -d ../build-aux; then
2513 echo "executing mkdir ../build-aux"
2516 echo "executing ${AUTOCONF}"
2517 ${AUTOCONF} || func_exit 1
2518 echo "executing ${AUTOHEADER}"
2519 ${AUTOHEADER} || func_exit 1
2520 echo "executing ${AUTOMAKE} --add-missing --copy"
2521 ${AUTOMAKE} --add-missing --copy || func_exit 1
2524 if grep '^BUILT_SOURCES *+=' "$testdir/$sourcebase/Makefile.am" > /dev/null; then
2526 ./configure || func_exit 1
2528 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
2529 make built_sources || func_exit 1
2531 make distclean || func_exit 1
2536 # func_create_megatestdir megatestdir allmodules
2538 # - local_gnulib_dir from --local-dir
2539 # - auxdir directory relative to destdir where to place build aux files
2540 func_create_megatestdir ()
2544 if test -z "$allmodules"; then
2545 allmodules=`func_all_modules`
2549 # First, all modules one by one.
2550 for onemodule in $allmodules; do
2551 func_create_testdir "$megatestdir/$onemodule" $onemodule
2552 func_append megasubdirs "$onemodule "
2554 # Then, all modules all together.
2555 # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
2556 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
2557 allmodules=`for m in $allmodules; do if test $m != config-h && test $m != fnmatch-posix; then echo $m; fi; done`
2558 func_create_testdir "$megatestdir/ALL" "$allmodules"
2559 func_append megasubdirs "ALL"
2561 # Create Makefile.am.
2562 (echo "## Process this file with automake to produce Makefile.in."
2564 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
2566 echo "SUBDIRS = $megasubdirs"
2567 ) > "$megatestdir/Makefile.am"
2569 # Create configure.ac.
2570 (echo "# Process this file with autoconf to produce a configure script."
2571 echo "AC_INIT([dummy], [0])"
2572 if test "$auxdir" != "."; then
2573 echo "AC_CONFIG_AUX_DIR([$auxdir])"
2575 echo "AM_INIT_AUTOMAKE"
2577 echo "AC_PROG_MAKE_SET"
2579 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
2580 echo "AC_OUTPUT([Makefile])"
2581 ) > "$megatestdir/configure.ac"
2583 # Create autogenerated files.
2585 # Do not use "${AUTORECONF} --install", because autoreconf operates
2586 # recursively, but the subdirectories are already finished, therefore
2587 # calling autoreconf here would only waste lots of CPU time.
2588 echo "executing ${ACLOCAL}"
2589 ${ACLOCAL} || func_exit 1
2590 echo "executing mkdir build-aux"
2592 echo "executing ${AUTOCONF}"
2593 ${AUTOCONF} || func_exit 1
2594 echo "executing ${AUTOMAKE} --add-missing --copy"
2595 ${AUTOMAKE} --add-missing --copy || func_exit 1
2601 func_fatal_error "no mode specified" ;;
2610 if test -z "$destdir"; then
2613 test -d "$destdir" \
2614 || func_fatal_error "destination directory does not exist: $destdir"
2616 # Prefer configure.ac to configure.in.
2617 if test -f "$destdir"/configure.ac; then
2618 configure_ac="$destdir/configure.ac"
2620 if test -f "$destdir"/configure.in; then
2621 configure_ac="$destdir/configure.in"
2623 func_fatal_error "cannot find $destdir/configure.ac"
2627 # Analyze configure.ac.
2629 guessed_libtool=false
2634 /AC_CONFIG_AUX_DIR/ {
2635 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
2637 /A[CM]_PROG_LIBTOOL/ {
2638 s,^.*$,guessed_libtool=true,p
2640 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
2642 if test -z "$auxdir"; then
2643 auxdir="$guessed_auxdir"
2646 # Determine where to apply func_import.
2647 if test -n "$m4base"; then
2648 # Apply func_import to a particular gnulib directory.
2649 # Any number of additional modules can be given.
2650 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
2651 # First use of gnulib in the given m4base.
2652 test -n "$supplied_libname" || supplied_libname=true
2653 test -n "$sourcebase" || sourcebase="lib"
2654 test -n "$docbase" || docbase="doc"
2655 test -n "$testsbase" || testsbase="tests"
2656 test -n "$macro_prefix" || macro_prefix="gl"
2660 # Apply func_import to all gnulib directories.
2661 # To get this list of directories, look at Makefile.am. (Not at
2662 # configure, because it may be omitted from CVS. Also, don't run
2663 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
2666 if test -f "$destdir"/Makefile.am; then
2667 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
2669 for arg in $aclocal_amflags; do
2670 if test -n "$m4dir_is_next"; then
2671 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
2675 if test -f "$destdir/$arg"/gnulib-cache.m4; then
2676 func_append m4dirs " $arg"
2677 m4dirs_count=`expr $m4dirs_count + 1`
2682 if test "X$arg" = "X-I"; then
2690 # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
2691 if test -f "$destdir"/aclocal.m4; then
2692 sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
2693 sedexpr2='s,^[^/]*$,.,'
2694 sedexpr3='s,/[^/]*$,,'
2695 m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
2696 m4dirs_count=`echo "$m4dirs" | wc -l`
2699 if test $m4dirs_count = 0; then
2700 # First use of gnulib in a package.
2701 # Any number of additional modules can be given.
2702 test -n "$supplied_libname" || supplied_libname=true
2703 test -n "$sourcebase" || sourcebase="lib"
2705 test -n "$docbase" || docbase="doc"
2706 test -n "$testsbase" || testsbase="tests"
2707 test -n "$macro_prefix" || macro_prefix="gl"
2710 if test $m4dirs_count = 1; then
2711 # There's only one use of gnulib here. Assume the user means it.
2712 # Any number of additional modules can be given.
2713 for m4base in $m4dirs; do
2717 # Ambiguous - guess what the user meant.
2718 if test $# = 0; then
2719 # No further arguments. Guess the user wants to update all of them.
2720 for m4base in $m4dirs; do
2721 # Perform func_import in a subshell, so that variable values
2723 # local_gnulib_dir, avoidlist, sourcebase, m4base, docbase,
2724 # testsbase, libname, lgpl, makefile_name, libtool, macro_prefix
2725 # don't propagate from one directory to another.
2726 (func_import) || func_exit 1
2730 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
2738 if test -z "$destdir"; then
2739 func_fatal_error "please specify --dir option"
2742 test -d "$destdir" \
2743 || func_fatal_error "could not create destination directory"
2744 test -n "$auxdir" || auxdir="build-aux"
2745 func_create_testdir "$destdir" "$*"
2748 create-megatestdir )
2749 if test -z "$destdir"; then
2750 func_fatal_error "please specify --dir option"
2752 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2753 test -n "$auxdir" || auxdir="build-aux"
2754 func_create_megatestdir "$destdir" "$*"
2758 test -n "$destdir" || destdir=testdir$$
2759 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2760 test -n "$auxdir" || auxdir="build-aux"
2761 func_create_testdir "$destdir" "$*"
2765 ../configure || func_exit 1
2767 make check || func_exit 1
2768 make distclean || func_exit 1
2769 remaining=`find . -type f -print`
2770 if test -n "$remaining"; then
2771 echo "Remaining files:" $remaining 1>&2
2772 echo "gnulib-tool: *** Stop." 1>&2
2781 test -n "$destdir" || destdir=testdir$$
2782 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2783 test -n "$auxdir" || auxdir="build-aux"
2784 func_create_megatestdir "$destdir" "$*"
2792 remaining=`find . -type f -print`
2793 if test -n "$remaining"; then
2794 echo "Remaining files:" $remaining 1>&2
2795 echo "gnulib-tool: *** Stop." 1>&2
2803 extract-description )
2807 if test -n "$module"; then
2808 func_get_description "$module"
2817 if test -n "$module"; then
2818 func_get_filelist "$module"
2823 extract-dependencies )
2827 if test -n "$module"; then
2828 func_get_dependencies "$module"
2833 extract-autoconf-snippet )
2837 if test -n "$module"; then
2838 func_get_autoconf_snippet "$module"
2843 extract-automake-snippet )
2847 if test -n "$module"; then
2848 func_get_automake_snippet "$module"
2853 extract-include-directive )
2857 if test -n "$module"; then
2858 func_get_include_directive "$module"
2867 if test -n "$module"; then
2868 func_get_license "$module"
2873 extract-maintainer )
2877 if test -n "$module"; then
2878 func_get_maintainer "$module"
2883 extract-tests-module )
2887 if test -n "$module"; then
2888 func_get_tests_module "$module"
2894 func_fatal_error "unknown operation mode --$mode" ;;
2898 # Undo the effect of the previous 'trap' command. Some shellology:
2899 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
2900 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
2901 # exit); for the others we need to call 'exit' explicitly. The value of $? is
2902 # 128 + signal number and is set before the trap-registered command is run.
2904 trap 'func_exit $?' 1 2 3 13 15
2909 # indent-tabs-mode: nil
2910 # whitespace-check-buffer-indent: nil