be206e7f7b567510dd49487d653b0530159b1725
[pspp] / gnulib-tool
1 #! /bin/sh
2 #
3 # Copyright (C) 2002-2008 Free Software Foundation, Inc.
4 #
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 3 of the License, or
8 # (at your option) any later version.
9 #
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.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18
19 # This program is meant for authors or maintainers which want to import
20 # modules from gnulib into their packages.
21
22 progname=$0
23 package=gnulib
24 nl='
25 '
26 IFS=" ""        $nl"
27
28 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
29 AUTOCONFPATH=
30 #case $USER in
31 #  bruno )
32 #    AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
33 #    AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
34 #    ;;
35 #esac
36
37 # You can set AUTOMAKEPATH to empty if automake 1.9.x is already in your PATH.
38 AUTOMAKEPATH=
39
40 # You can set GETTEXTPATH to empty if autopoint 0.15 is already in your PATH.
41 GETTEXTPATH=
42
43 # If you didn't set AUTOCONFPATH and AUTOMAKEPATH, you can also set the
44 # variables AUTOCONF, AUTOHEADER, ACLOCAL, AUTOMAKE, AUTORECONF individually.
45 if test -z "${AUTOCONF}" || test -n "${AUTOCONFPATH}"; then
46   AUTOCONF="${AUTOCONFPATH}autoconf"
47 fi
48 if test -z "${AUTOHEADER}" || test -n "${AUTOCONFPATH}"; then
49   AUTOHEADER="${AUTOCONFPATH}autoheader"
50 fi
51 if test -z "${ACLOCAL}" || test -n "${AUTOMAKEPATH}"; then
52   ACLOCAL="${AUTOMAKEPATH}aclocal"
53 fi
54 if test -z "${AUTOMAKE}" || test -n "${AUTOMAKEPATH}"; then
55   AUTOMAKE="${AUTOMAKEPATH}automake"
56 fi
57 if test -z "${AUTORECONF}" || test -n "${AUTOCONFPATH}"; then
58   AUTORECONF="${AUTOCONFPATH}autoreconf"
59 fi
60
61 # If you didn't set GETTEXTPATH, you can also set the variable AUTOPOINT.
62 if test -z "${AUTOPOINT}" || test -n "${GETTEXTPATH}"; then
63   AUTOPOINT="${GETTEXTPATH}autopoint"
64 fi
65
66 # When using GNU sed, turn off as many GNU extensions as possible,
67 # to minimize the risk of accidentally using non-portable features.
68 # However, do this only for gnulib-tool itself, not for the code that
69 # gnulib-tool generates, since we don't want "sed --posix" to leak
70 # into makefiles.
71 if (alias) > /dev/null 2>&1 && echo | sed --posix -e d >/dev/null 2>&1; then
72   # Define sed as an alias.
73   # It is not always possible to use aliases. Aliases are guaranteed to work
74   # if the executing shell is bash and either it is invoked as /bin/sh or
75   # is a version >= 2.0, supporting shopt. This is the common case.
76   # Two other approaches (use of a variable $sed or of a function func_sed
77   # instead of an alias) require massive, fragile code changes.
78   # An other approach (use of function sed) requires `which sed` - but 'which'
79   # is hard to emulate, due to missing "test -x" on some platforms.
80   if test -n "$BASH_VERSION"; then
81     shopt -s expand_aliases >/dev/null 2>&1
82   fi
83   alias sed='sed --posix'
84 fi
85
86 # func_usage
87 # outputs to stdout the --help usage message.
88 func_usage ()
89 {
90   echo "\
91 Usage: gnulib-tool --list
92        gnulib-tool --import [module1 ... moduleN]
93        gnulib-tool --update
94        gnulib-tool --create-testdir --dir=directory [module1 ... moduleN]
95        gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
96        gnulib-tool --test --dir=directory module1 ... moduleN
97        gnulib-tool --megatest --dir=directory [module1 ... moduleN]
98        gnulib-tool --extract-description module
99        gnulib-tool --extract-notice module
100        gnulib-tool --extract-filelist module
101        gnulib-tool --extract-dependencies module
102        gnulib-tool --extract-autoconf-snippet module
103        gnulib-tool --extract-automake-snippet module
104        gnulib-tool --extract-include-directive module
105        gnulib-tool --extract-link-directive module
106        gnulib-tool --extract-license module
107        gnulib-tool --extract-maintainer module
108        gnulib-tool --extract-tests-module module
109
110 Operation modes:
111       --list                print the available module names
112       --import              import the given modules into the current package;
113                             if no modules are specified, update the current
114                             package from the current gnulib
115       --update              update the current package, restore files omitted
116                             from CVS
117       --create-testdir      create a scratch package with the given modules
118       --create-megatestdir  create a mega scratch package with the given modules
119                             one by one and all together
120       --test                test the combination of the given modules
121                             (recommended to use CC=\"gcc -Wall\" here)
122       --megatest            test the given modules one by one and all together
123                             (recommended to use CC=\"gcc -Wall\" here)
124       --extract-description        extract the description
125       --extract-notice             extract the notice or banner
126       --extract-filelist           extract the list of files
127       --extract-dependencies       extract the dependencies
128       --extract-autoconf-snippet   extract the snippet for configure.ac
129       --extract-automake-snippet   extract the snippet for library makefile
130       --extract-include-directive  extract the #include directive
131       --extract-link-directive     extract the linker directive
132       --extract-license            report the license terms of the source files
133                                    under lib/
134       --extract-maintainer         report the maintainer(s) inside gnulib
135       --extract-tests-module       report the unit test module, if it exists
136
137 General options:
138       --dir=DIRECTORY       Specify the target directory.
139                             For --import, this specifies where your
140                             configure.ac can be found.  Defaults to current
141                             directory.
142       --local-dir=DIRECTORY  Specify a local override directory where to look
143                             up files before looking in gnulib's directory.
144       --verbose             Increase verbosity. May be repeated.
145       --quiet               Decrease verbosity. May be repeated.
146
147 Options for --import:
148       --lib=LIBRARY         Specify the library name.  Defaults to 'libgnu'.
149       --source-base=DIRECTORY
150                             Directory relative to --dir where source code is
151                             placed (default \"lib\").
152       --m4-base=DIRECTORY   Directory relative to --dir where *.m4 macros are
153                             placed (default \"m4\").
154       --po-base=DIRECTORY   Directory relative to --dir where *.po files are
155                             placed (default \"po\").
156       --doc-base=DIRECTORY  Directory relative to --dir where doc files are
157                             placed (default \"doc\").
158       --tests-base=DIRECTORY
159                             Directory relative to --dir where unit tests are
160                             placed (default \"tests\").
161       --aux-dir=DIRECTORY   Directory relative to --dir where auxiliary build
162                             tools are placed (default \"build-aux\").
163       --with-tests          Include unit tests for the included modules.
164       --avoid=MODULE        Avoid including the given MODULE. Useful if you
165                             have code that provides equivalent functionality.
166                             This option can be repeated.
167       --lgpl[=2|=3]         Abort if modules aren't available under the LGPL.
168                             Also modify license template from GPL to LGPL.
169                             The version number of the LGPL can be specified;
170                             the default is currently LGPLv3.
171       --makefile-name=NAME  Name of makefile in automake syntax in the
172                             source-base and tests-base directories
173                             (default \"Makefile.am\").
174       --libtool             Use libtool rules.
175       --no-libtool          Don't use libtool rules.
176       --macro-prefix=PREFIX  Specify the prefix of the macros 'gl_EARLY' and
177                             'gl_INIT'. Default is 'gl'.
178       --po-domain=NAME      Specify the prefix of the i18n domain. Usually use
179                             the package name. A suffix '-gnulib' is appended.
180       --no-changelog        don't update or create ChangeLog files
181
182 Options for --import and --update:
183       --dry-run             For --import, only print what would have been done.
184   -s, --symbolic, --symlink Make symbolic links instead of copying files.
185       --local-symlink       Make symbolic links instead of copying files, only
186                             for files from the local override directory.
187   -S, --more-symlinks       Make symbolic links instead of copying files, and
188                             don't replace copyright notices.
189
190 Report bugs to <bug-gnulib@gnu.org>."
191 }
192
193 # func_version
194 # outputs to stdout the --version message.
195 func_version ()
196 {
197   func_gnulib_dir
198   date=`sed 's/ .*//;q' "$gnulib_dir"/ChangeLog`
199   version=`"$gnulib_dir"/build-aux/git-version-gen /dev/null`
200   year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'`
201   echo "\
202 gnulib-tool (GNU $package $date) $version
203 Copyright (C) $year Free Software Foundation, Inc.
204 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
205 This is free software: you are free to change and redistribute it.
206 There is NO WARRANTY, to the extent permitted by law.
207
208 Written by" "Bruno Haible" "and" "Simon Josefsson"
209 }
210
211 # func_emit_copyright_notice
212 # outputs to stdout a header for a generated file.
213 func_emit_copyright_notice ()
214 {
215   sed -n '/Copyright/ {
216             p
217             q
218           }' < "$self_abspathname"
219   echo "#"
220   echo "# This file is free software, distributed under the terms of the GNU"
221   echo "# General Public License.  As a special exception to the GNU General"
222   echo "# Public License, this file may be distributed as part of a program"
223   echo "# that contains a configuration script generated by Autoconf, under"
224   echo "# the same distribution terms as the rest of that program."
225   echo "#"
226   echo "# Generated by gnulib-tool."
227 }
228
229 # func_exit STATUS
230 # exit with status
231 func_exit ()
232 {
233   (exit $1); exit $1
234 }
235
236 # func_gnulib_dir
237 # locates the directory where the gnulib repository lives
238 # Sets variables
239 # - self_abspathname         absolute pathname of gnulib-tool
240 # - gnulib_dir               absolute pathname of gnulib repository
241 func_gnulib_dir ()
242 {
243   case "$0" in
244     /*) self_abspathname="$0" ;;
245     */*) self_abspathname=`pwd`/"$0" ;;
246     *)
247       # Look in $PATH.
248       # Iterate through the elements of $PATH.
249       # We use IFS=: instead of
250       #   for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
251       # because the latter does not work when some PATH element contains spaces.
252       # We use a canonicalized $pathx instead of $PATH, because empty PATH
253       # elements are by definition equivalent to '.', however field splitting
254       # according to IFS=: loses empty fields in many shells:
255       #   - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
256       #     beginning, at the end, and in the middle),
257       #   - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
258       #     at the beginning and at the end,
259       #   - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
260       #     Solaris lose empty fields at the end.
261       # The 'case' statement is an optimization, to avoid evaluating the
262       # explicit canonicalization command when $PATH contains no empty fields.
263       self_abspathname=
264       if test "${PATH_SEPARATOR+set}" != set; then
265         func_tmpdir
266         { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh
267         chmod +x "$tmp"/conf.sh
268         if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then
269           PATH_SEPARATOR=';'
270         else
271           PATH_SEPARATOR=:
272         fi
273         rm -rf "$tmp"
274       fi
275       if test "$PATH_SEPARATOR" = ";"; then
276         # On Windows, programs are searched in "." before $PATH.
277         pathx=".;$PATH"
278       else
279         # On Unix, we have to convert empty PATH elements to ".".
280         pathx="$PATH"
281         case :$PATH: in
282           *::*)
283             pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
284             ;;
285         esac
286       fi
287       save_IFS="$IFS"
288       IFS="$PATH_SEPARATOR"
289       for d in $pathx; do
290         IFS="$save_IFS"
291         test -z "$d" && d=.
292         if test -x "$d/$0" && test ! -d "$d/$0"; then
293           self_abspathname="$d/$0"
294           break
295         fi
296       done
297       IFS="$save_IFS"
298       if test -z "$self_abspathname"; then
299         func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
300       fi
301       ;;
302   esac
303   while test -h "$self_abspathname"; do
304     # Resolve symbolic link.
305     linkval=`func_readlink "$self_abspathname"`
306     test -n "$linkval" || break
307     case "$linkval" in
308       /* ) self_abspathname="$linkval" ;;
309       * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
310     esac
311   done
312   gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
313 }
314
315 # func_tmpdir
316 # creates a temporary directory.
317 # Sets variable
318 # - tmp             pathname of freshly created temporary directory
319 func_tmpdir ()
320 {
321   # Use the environment variable TMPDIR, falling back to /tmp. This allows
322   # users to specify a different temporary directory, for example, if their
323   # /tmp is filled up or too small.
324   : ${TMPDIR=/tmp}
325   {
326     # Use the mktemp program if available. If not available, hide the error
327     # message.
328     tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
329     test -n "$tmp" && test -d "$tmp"
330   } ||
331   {
332     # Use a simple mkdir command. It is guaranteed to fail if the directory
333     # already exists.  $RANDOM is bash specific and expands to empty in shells
334     # other than bash, ksh and zsh.  Its use does not increase security;
335     # rather, it minimizes the probability of failure in a very cluttered /tmp
336     # directory.
337     tmp=$TMPDIR/gl$$-$RANDOM
338     (umask 077 && mkdir "$tmp")
339   } ||
340   {
341     echo "$0: cannot create a temporary directory in $TMPDIR" >&2
342     func_exit 1
343   }
344 }
345
346 # func_append var value
347 # appends the given value to the shell variable var.
348 if ( foo=bar; foo+=baz && test "$foo" = barbaz ) >/dev/null 2>&1; then
349   # Use bash's += operator. It reduces complexity of appending repeatedly to
350   # a single variable from O(n^2) to O(n).
351   func_append ()
352   {
353     eval "$1+=\"\$2\""
354   }
355 else
356   func_append ()
357   {
358     eval "$1=\"\$$1\$2\""
359   }
360 fi
361
362 # func_fatal_error message
363 # outputs to stderr a fatal error message, and terminates the program.
364 func_fatal_error ()
365 {
366   echo "gnulib-tool: *** $1" 1>&2
367   echo "gnulib-tool: *** Stop." 1>&2
368   func_exit 1
369 }
370
371 # func_readlink SYMLINK
372 # outputs the target of the given symlink.
373 if (type -p readlink) > /dev/null 2>&1; then
374   func_readlink ()
375   {
376     # Use the readlink program from GNU coreutils.
377     readlink "$1"
378   }
379 else
380   func_readlink ()
381   {
382     # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
383     # would do the wrong thing if the link target contains " -> ".
384     LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
385   }
386 fi
387
388 # func_relativize DIR1 DIR2
389 # computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
390 # Input:
391 # - DIR1            relative pathname, relative to the current directory
392 # - DIR2            relative pathname, relative to the current directory
393 # Output:
394 # - reldir          relative pathname of DIR2, relative to DIR1
395 func_relativize ()
396 {
397   dir0=`pwd`
398   dir1="$1"
399   dir2="$2"
400   sed_first='s,^\([^/]*\)/.*$,\1,'
401   sed_rest='s,^[^/]*/*,,'
402   sed_last='s,^.*/\([^/]*\)$,\1,'
403   sed_butlast='s,/*[^/]*$,,'
404   while test -n "$dir1"; do
405     first=`echo "$dir1" | sed -e "$sed_first"`
406     if test "$first" != "."; then
407       if test "$first" = ".."; then
408         dir2=`echo "$dir0" | sed -e "$sed_last"`/"$dir2"
409         dir0=`echo "$dir0" | sed -e "$sed_butlast"`
410       else
411         first2=`echo "$dir2" | sed -e "$sed_first"`
412         if test "$first2" = "$first"; then
413           dir2=`echo "$dir2" | sed -e "$sed_rest"`
414         else
415           dir2="../$dir2"
416         fi
417         dir0="$dir0"/"$first"
418       fi
419     fi
420     dir1=`echo "$dir1" | sed -e "$sed_rest"`
421   done
422   reldir="$dir2"
423 }
424
425 # func_relconcat DIR1 DIR2
426 # computes a relative pathname DIR1/DIR2, with obvious simplifications.
427 # Input:
428 # - DIR1            relative pathname, relative to the current directory
429 # - DIR2            relative pathname, relative to DIR1
430 # Output:
431 # - relconcat       DIR1/DIR2, relative to the current directory
432 func_relconcat ()
433 {
434   dir1="$1"
435   dir2="$2"
436   sed_first='s,^\([^/]*\)/.*$,\1,'
437   sed_rest='s,^[^/]*/*,,'
438   sed_last='s,^.*/\([^/]*\)$,\1,'
439   sed_butlast='s,/*[^/]*$,,'
440   while true; do
441     first=`echo "$dir2" | sed -e "$sed_first"`
442     if test "$first" = "."; then
443       dir2=`echo "$dir2" | sed -e "$sed_rest"`
444       if test -z "$dir2"; then
445         relconcat="$dir1"
446         break
447       fi
448     else
449       last=`echo "$dir1" | sed -e "$sed_last"`
450       while test "$last" = "."; do
451         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
452         last=`echo "$dir1" | sed -e "$sed_last"`
453       done
454       if test -z "$dir1"; then
455         relconcat="$dir2"
456         break
457       fi
458       if test "$first" = ".."; then
459         if test "$last" = ".."; then
460           relconcat="$dir1/$dir2"
461           break
462         fi
463         dir1=`echo "$dir1" | sed -e "$sed_butlast"`
464         dir2=`echo "$dir2" | sed -e "$sed_rest"`
465         if test -z "$dir1"; then
466           relconcat="$dir2"
467           break
468         fi
469         if test -z "$dir2"; then
470           relconcat="$dir1"
471           break
472         fi
473       else
474         relconcat="$dir1/$dir2"
475         break
476       fi
477     fi
478   done
479 }
480
481 # func_ln SRC DEST
482 # Like ln -s, except that SRC is given relative to the current directory (or
483 # absolute), not given relative to the directory of DEST.
484 func_ln ()
485 {
486   case "$1" in
487     /*)
488       ln -s "$1" "$2" ;;
489     *) # SRC is relative.
490       case "$2" in
491         /*)
492           ln -s "`pwd`/$1" "$2" ;;
493         *) # DEST is relative too.
494           ln_destdir=`echo "$2" | sed -e 's,[^/]*$,,'`
495           test -n "$ln_destdir" || ln_destdir="."
496           func_relativize "$ln_destdir" "$1"
497           ln -s "$reldir" "$2"
498           ;;
499       esac
500       ;;
501   esac
502 }
503
504 # func_ln_if_changed SRC DEST
505 # Like func_ln, but avoids munging timestamps if the link is correct.
506 func_ln_if_changed ()
507 {
508   if test $# -ne 2; then
509     echo "usage: func_ln_if_changed SRC DEST" >&2
510   fi
511   ln_target=`func_readlink "$2"`
512   if test -h "$2" && test "$1" = "$ln_target"; then
513     :
514   else
515     rm -f "$2"
516     func_ln "$1" "$2"
517   fi
518 }
519
520 # Ensure an 'echo' command that does not interpret backslashes.
521 # Test cases:
522 #   echo '\n' | wc -l                 prints 1 when OK, 2 when KO
523 #   echo '\t' | grep t > /dev/null    has return code 0 when OK, 1 when KO
524 # This problem is a weird heritage from SVR4. BSD got it right (except that
525 # BSD echo interprets '-n' as an option, which is also not desirable).
526 # Nowadays the problem occurs in 4 situations:
527 # - in bash, when the shell option xpg_echo is set (bash >= 2.04)
528 #            or when it was built with --enable-usg-echo-default (bash >= 2.0)
529 #            or when it was built with DEFAULT_ECHO_TO_USG (bash < 2.0),
530 # - in zsh, when sh-emulation is not set,
531 # - in ksh (e.g. AIX /bin/sh and Solaris /usr/xpg4/bin/sh are ksh instances,
532 #           and HP-UX /bin/sh and IRIX /bin/sh behave similarly),
533 # - in Solaris /bin/sh and OSF/1 /bin/sh.
534 # We try the following workarounds:
535 # - for all: respawn using $CONFIG_SHELL if that is set and works.
536 # - for bash >= 2.04: unset the shell option xpg_echo.
537 # - for bash >= 2.0: define echo to a function that uses the printf built-in.
538 # - for bash < 2.0: define echo to a function that uses cat of a here document.
539 # - for zsh: turn sh-emulation on.
540 # - for ksh: alias echo to 'print -r'.
541 # - for ksh: alias echo to a function that uses cat of a here document.
542 # - for Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh and rely on
543 #   the ksh workaround.
544 # - otherwise: respawn using /bin/sh and rely on the workarounds.
545 # When respawning, we pass --no-reexec as first argument, so as to avoid
546 # turning this script into a fork bomb in unlucky situations.
547 have_echo=
548 if echo '\t' | grep t > /dev/null; then
549   have_echo=yes # Lucky!
550 fi
551 # Try the workarounds.
552 # Respawn using $CONFIG_SHELL if that is set and works.
553 if test -z "$have_echo" \
554    && test "X$1" != "X--no-reexec" \
555    && test -n "$CONFIG_SHELL" \
556    && test -f "$CONFIG_SHELL" \
557    && $CONFIG_SHELL -c 'echo '\t' | grep t > /dev/null'; then
558   exec $CONFIG_SHELL "$0" --no-reexec "$@"
559   exit 127
560 fi
561 # For bash >= 2.04: unset the shell option xpg_echo.
562 if test -z "$have_echo" \
563    && test -n "$BASH_VERSION" \
564    && (shopt -o xpg_echo; echo '\t' | grep t > /dev/null) 2>/dev/null; then
565   shopt -o xpg_echo
566   have_echo=yes
567 fi
568 # For bash >= 2.0: define echo to a function that uses the printf built-in.
569 # For bash < 2.0: define echo to a function that uses cat of a here document.
570 # (There is no win in using 'printf' over 'cat' if it is not a shell built-in.)
571 if test -z "$have_echo" \
572    && test -n "$BASH_VERSION"; then \
573   if type printf 2>/dev/null | grep / > /dev/null; then
574     # 'printf' is not a shell built-in.
575 echo ()
576 {
577 cat <<EOF
578 $*
579 EOF
580 }
581   else
582     # 'printf' is a shell built-in.
583 echo ()
584 {
585   printf '%s\n' "$*"
586 }
587   fi
588   if echo '\t' | grep t > /dev/null; then
589     have_echo=yes
590   fi
591 fi
592 # For zsh: turn sh-emulation on.
593 if test -z "$have_echo" \
594    && test -n "$ZSH_VERSION" \
595    && (emulate sh) >/dev/null 2>&1; then
596   emulate sh
597 fi
598 # For ksh: alias echo to 'print -r'.
599 if test -z "$have_echo" \
600    && (type print) >/dev/null 2>&1; then
601   # A 'print' command exists.
602   if type print 2>/dev/null | grep / > /dev/null; then
603     :
604   else
605     # 'print' is a shell built-in.
606     if (print -r '\told' | grep told > /dev/null) 2>/dev/null; then
607       # 'print' is the ksh shell built-in.
608       alias echo='print -r'
609     fi
610   fi
611 fi
612 if test -z "$have_echo" \
613    && echo '\t' | grep t > /dev/null; then
614   have_echo=yes
615 fi
616 # For ksh: alias echo to a function that uses cat of a here document.
617 # The ksh manual page says:
618 #   "Aliasing is performed when scripts are read, not while they are executed.
619 #    Therefore, for an alias to take effect, the alias definition command has
620 #    to be executed before the command which references the alias is read."
621 # Because of this, we have to play strange tricks with have_echo, to ensure
622 # that the top-level statement containing the test starts after the 'alias'
623 # command.
624 if test -z "$have_echo"; then
625 bsd_echo ()
626 {
627 cat <<EOF
628 $*
629 EOF
630 }
631 alias echo=bsd_echo 2>/dev/null
632 fi
633 if test -z "$have_echo" \
634    && echo '\t' | grep t > /dev/null; then
635   have_echo=yes
636 fi
637 if test -z "$have_echo"; then
638   unalias echo 2>/dev/null
639 fi
640 # For Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh.
641 if test -z "$have_echo" \
642    && test "X$1" != "X--no-reexec" \
643    && test -f /bin/ksh; then
644   exec /bin/ksh "$0" --no-reexec "$@"
645   exit 127
646 fi
647 # Otherwise: respawn using /bin/sh.
648 if test -z "$have_echo" \
649    && test "X$1" != "X--no-reexec" \
650    && test -f /bin/sh; then
651   exec /bin/sh "$0" --no-reexec "$@"
652   exit 127
653 fi
654 if test -z "$have_echo"; then
655   func_fatal_error "Shell does not support 'echo' correctly. Please install GNU bash and set the environment variable CONFIG_SHELL to point to it."
656 fi
657 if echo '\t' | grep t > /dev/null; then
658   : # Works fine now.
659 else
660   func_fatal_error "Shell does not support 'echo' correctly. Workaround does not work. Please report this as a bug to bug-gnulib@gnu.org."
661 fi
662 if test "X$1" = "X--no-reexec"; then
663   shift
664 fi
665
666 # Command-line option processing.
667 # Removes the OPTIONS from the arguments. Sets the variables:
668 # - mode            list or import or create-testdir or create-megatestdir
669 # - destdir         from --dir
670 # - local_gnulib_dir  from --local-dir
671 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
672 # - libname, supplied_libname  from --lib
673 # - sourcebase      from --source-base
674 # - m4base          from --m4-base
675 # - pobase          from --po-base
676 # - docbase         from --doc-base
677 # - testsbase       from --tests-base
678 # - auxdir          from --aux-dir
679 # - inctests        true if --with-tests was given, blank otherwise
680 # - avoidlist       list of modules to avoid, from --avoid
681 # - lgpl            yes or a number if --lgpl was given, blank otherwise
682 # - makefile_name   from --makefile-name
683 # - libtool         true if --libtool was given, false if --no-libtool was
684 #                   given, blank otherwise
685 # - macro_prefix    from --macro-prefix
686 # - po_domain       from --po-domain
687 # - autoconf_minversion  minimum supported autoconf version
688 # - do_changelog    false if --no-changelog was given, : otherwise
689 # - doit            : if actions shall be executed, false if only to be printed
690 # - symbolic        true if --symlink or --more-symlinks was given, blank
691 #                   otherwise
692 # - lsymbolic       true if --local-symlink was given, blank otherwise
693 # - do_copyrights   blank if --more-symlinks was given, true otherwise
694 {
695   mode=
696   destdir=
697   local_gnulib_dir=
698   verbose=0
699   libname=libgnu
700   supplied_libname=
701   sourcebase=
702   m4base=
703   pobase=
704   docbase=
705   testsbase=
706   auxdir=
707   inctests=
708   avoidlist=
709   lgpl=
710   makefile_name=
711   libtool=
712   macro_prefix=
713   po_domain=
714   do_changelog=:
715   doit=:
716   symbolic=
717   lsymbolic=
718   do_copyrights=true
719
720   supplied_opts="$@"
721
722   while test $# -gt 0; do
723     case "$1" in
724       --list | --lis )
725         mode=list
726         shift ;;
727       --import | --impor | --impo | --imp | --im | --i )
728         mode=import
729         shift ;;
730       --update | --updat | --upda | --upd | --up | --u )
731         mode=update
732         shift ;;
733       --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
734         mode=create-testdir
735         shift ;;
736       --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
737         mode=create-megatestdir
738         shift ;;
739       --test | --tes | --te | --t )
740         mode=test
741         shift ;;
742       --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
743         mode=megatest
744         shift ;;
745       --extract-* )
746         mode=`echo "X$1" | sed -e 's/^X--//'`
747         shift ;;
748       --dir )
749         shift
750         if test $# = 0; then
751           func_fatal_error "missing argument for --dir"
752         fi
753         destdir=$1
754         shift ;;
755       --dir=* )
756         destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
757         shift ;;
758       --local-dir )
759         shift
760         if test $# = 0; then
761           func_fatal_error "missing argument for --local-dir"
762         fi
763         local_gnulib_dir=$1
764         shift ;;
765       --local-dir=* )
766         local_gnulib_dir=`echo "X$1" | sed -e 's/^X--local-dir=//'`
767         shift ;;
768       --verbose | --verbos | --verbo | --verb )
769         verbose=`expr $verbose + 1`
770         shift ;;
771       --quiet | --quie | --qui | --qu | --q )
772         verbose=`expr $verbose - 1`
773         shift ;;
774       --lib )
775         shift
776         if test $# = 0; then
777           func_fatal_error "missing argument for --lib"
778         fi
779         libname=$1
780         supplied_libname=true
781         shift ;;
782       --lib=* )
783         libname=`echo "X$1" | sed -e 's/^X--lib=//'`
784         supplied_libname=true
785         shift ;;
786       --source-base )
787         shift
788         if test $# = 0; then
789           func_fatal_error "missing argument for --source-base"
790         fi
791         sourcebase=$1
792         shift ;;
793       --source-base=* )
794         sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
795         shift ;;
796       --m4-base )
797         shift
798         if test $# = 0; then
799           func_fatal_error "missing argument for --m4-base"
800         fi
801         m4base=$1
802         shift ;;
803       --m4-base=* )
804         m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
805         shift ;;
806       --po-base )
807         shift
808         if test $# = 0; then
809           func_fatal_error "missing argument for --po-base"
810         fi
811         pobase=$1
812         shift ;;
813       --po-base=* )
814         pobase=`echo "X$1" | sed -e 's/^X--po-base=//'`
815         shift ;;
816       --doc-base )
817         shift
818         if test $# = 0; then
819           func_fatal_error "missing argument for --doc-base"
820         fi
821         docbase=$1
822         shift ;;
823       --doc-base=* )
824         docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
825         shift ;;
826       --tests-base )
827         shift
828         if test $# = 0; then
829           func_fatal_error "missing argument for --tests-base"
830         fi
831         testsbase=$1
832         shift ;;
833       --tests-base=* )
834         testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
835         shift ;;
836       --aux-dir )
837         shift
838         if test $# = 0; then
839           func_fatal_error "missing argument for --aux-dir"
840         fi
841         auxdir=$1
842         shift ;;
843       --aux-dir=* )
844         auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
845         shift ;;
846       --with-tests )
847         inctests=true
848         shift ;;
849       --avoid )
850         shift
851         if test $# = 0; then
852           func_fatal_error "missing argument for --avoid"
853         fi
854         func_append avoidlist " $1"
855         shift ;;
856       --avoid=* )
857         arg=`echo "X$1" | sed -e 's/^X--avoid=//'`
858         func_append avoidlist " $arg"
859         shift ;;
860       --lgpl )
861         lgpl=yes
862         shift ;;
863       --lgpl=* )
864         arg=`echo "X$1" | sed -e 's/^X--lgpl=//'`
865         case "$arg" in
866           2 | 3) ;;
867           *) func_fatal_error "invalid LGPL version number for --lgpl" ;;
868         esac
869         lgpl=$arg
870         shift ;;
871       --makefile-name )
872         shift
873         if test $# = 0; then
874           func_fatal_error "missing argument for --makefile-name"
875         fi
876         makefile_name="$1"
877         shift ;;
878       --makefile-name=* )
879         makefile_name=`echo "X$1" | sed -e 's/^X--makefile-name=//'`
880         shift ;;
881       --libtool )
882         libtool=true
883         shift ;;
884       --no-libtool )
885         libtool=false
886         shift ;;
887       --macro-prefix )
888         shift
889         if test $# = 0; then
890           func_fatal_error "missing argument for --macro-prefix"
891         fi
892         macro_prefix="$1"
893         shift ;;
894       --macro-prefix=* )
895         macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
896         shift ;;
897       --po-domain )
898         shift
899         if test $# = 0; then
900           func_fatal_error "missing argument for --po-domain"
901         fi
902         po_domain="$1"
903         shift ;;
904       --po-domain=* )
905         po_domain=`echo "X$1" | sed -e 's/^X--po-domain=//'`
906         shift ;;
907       --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
908         do_changelog=false
909         shift ;;
910       --dry-run )
911         doit=false
912         shift ;;
913       -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
914         symbolic=true
915         shift ;;
916       --local-symlink | --local-symlin | --local-symli | --local-syml | --local-sym | --local-sy | --local-s )
917         lsymbolic=true
918         shift ;;
919       -S | --more-symlinks | --more-symlink | --more-symlin | --more-symli | --more-syml | --more-sym | --more-sy | --more-s | --more- | --more | --mor | --mo )
920         symbolic=true
921         do_copyrights=
922         shift ;;
923       --help | --hel | --he | --h )
924         func_usage
925         func_exit $? ;;
926       --version | --versio | --versi | --vers )
927         func_version
928         func_exit $? ;;
929       -- )
930         # Stop option processing
931         shift
932         break ;;
933       -* )
934         echo "gnulib-tool: unknown option $1" 1>&2
935         echo "Try 'gnulib-tool --help' for more information." 1>&2
936         func_exit 1 ;;
937       * )
938         break ;;
939     esac
940   done
941
942   if test "$mode" = update; then
943     if test $# != 0; then
944       echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
945       echo "Try 'gnulib-tool --help' for more information." 1>&2
946       echo "If you really want to modify the gnulib configuration of your project," 1>&2
947       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
948       func_exit 1
949     fi
950     if test -n "$local_gnulib_dir" || test -n "$supplied_libname" \
951        || test -n "$sourcebase" || test -n "$m4base" || test -n "$pobase" \
952        || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
953        || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
954        || test -n "$makefile_name" || test -n "$macro_prefix" \
955        || test -n "$po_domain"; then
956       echo "gnulib-tool: invalid options for 'update' mode" 1>&2
957       echo "Try 'gnulib-tool --help' for more information." 1>&2
958       echo "If you really want to modify the gnulib configuration of your project," 1>&2
959       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
960       func_exit 1
961     fi
962     do_changelog=false
963   fi
964   if test -n "$pobase" && test -z "$po_domain"; then
965     echo "gnulib-tool: together with --po-base, you need to specify --po-domain" 1>&2
966     echo "Try 'gnulib-tool --help' for more information." 1>&2
967     func_exit 1
968   fi
969   if test -z "$pobase" && test -n "$po_domain"; then
970     echo "gnulib-tool: warning: --po-domain has no effect without a --po-base option" 1>&2
971   fi
972
973   # Determine the minimum supported autoconf version from the project's
974   # configure.ac.
975   DEFAULT_AUTOCONF_MINVERSION="2.59"
976   autoconf_minversion=
977   configure_ac=
978   if { test "$mode" = import || test "$mode" = update; } && test -n "$destdir"; then
979     if test -f "$destdir"/configure.ac; then
980       configure_ac="$destdir/configure.ac"
981     else
982       if test -f "$destdir"/configure.in; then
983         configure_ac="$destdir/configure.in"
984       fi
985     fi
986   else
987     if test -f configure.ac; then
988       configure_ac="configure.ac"
989     else
990       if test -f configure.in; then
991         configure_ac="configure.in"
992       fi
993     fi
994   fi
995   if test -n "$configure_ac"; then
996     # Use sed, not autoconf --trace, to look for the AC_PREREQ invocation,
997     # because when some m4 files are omitted from a CVS repository,
998     # "autoconf --trace=AC_PREREQ" fails with an error message like this:
999     #   m4: aclocal.m4:851: Cannot open m4/absolute-header.m4: No such file or directory
1000     #   autom4te: m4 failed with exit status: 1
1001     prereqs=
1002     my_sed_traces='
1003       s,#.*$,,
1004       s,^dnl .*$,,
1005       s, dnl .*$,,
1006       /AC_PREREQ/ {
1007         s,^.*AC_PREREQ([[ ]*\([^])]*\).*$,\1,p
1008       }'
1009     prereqs=`sed -n -e "$my_sed_traces" < "$configure_ac"`
1010     if test -n "$prereqs"; then
1011       autoconf_minversion=`
1012         for version in $prereqs; do echo $version; done |
1013         LC_ALL=C sort -nru | sed 1q
1014       `
1015     fi
1016   fi
1017   if test -z "$autoconf_minversion"; then
1018     autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
1019   fi
1020   case "$autoconf_minversion" in
1021     1.* | 2.[0-4]* | 2.5[0-8]*)
1022       func_fatal_error "minimum supported autoconf version is 2.59. Try adding AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
1023   esac
1024
1025   # Remove trailing slashes from the directory names. This is necessary for
1026   # m4base (to avoid an error in func_import) and optional for the others.
1027   sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
1028   case "$local_gnulib_dir" in
1029     */ ) local_gnulib_dir=`echo "$local_gnulib_dir" | sed -e "$sed_trimtrailingslashes"` ;;
1030   esac
1031   case "$sourcebase" in
1032     */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
1033   esac
1034   case "$m4base" in
1035     */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
1036   esac
1037   case "$pobase" in
1038     */ ) pobase=`echo "$pobase" | sed -e "$sed_trimtrailingslashes"` ;;
1039   esac
1040   case "$docbase" in
1041     */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
1042   esac
1043   case "$testsbase" in
1044     */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
1045   esac
1046   case "$auxdir" in
1047     */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
1048   esac
1049 }
1050
1051 func_gnulib_dir
1052 func_tmpdir
1053 trap 'exit_status=$?
1054       if test "$signal" != 0; then
1055         echo "caught signal $signal" >&2
1056       fi
1057       rm -rf "$tmp"
1058       exit $exit_status' 0
1059 for signal in 1 2 3 13 15; do
1060   trap '{ signal='$signal'; func_exit 1; }' $signal
1061 done
1062 signal=0
1063
1064 # func_lookup_file file
1065 # looks up a file in $local_gnulib_dir or $gnulib_dir, or combines it through
1066 # 'patch'.
1067 # Input:
1068 # - local_gnulib_dir  from --local-dir
1069 # Output:
1070 # - lookedup_file   name of the merged (combined) file
1071 # - lookedup_tmp    true if it is located in the tmp directory, blank otherwise
1072 func_lookup_file ()
1073 {
1074   lkfile="$1"
1075   if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile"; then
1076     lookedup_file="$local_gnulib_dir/$lkfile"
1077     lookedup_tmp=
1078   else
1079     if test -f "$gnulib_dir/$lkfile"; then
1080       if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile.diff"; then
1081         lkbase=`echo "$lkfile" | sed -e 's,^.*/,,'`
1082         rm -f "$tmp/$lkbase"
1083         cp "$gnulib_dir/$lkfile" "$tmp/$lkbase"
1084         patch -s "$tmp/$lkbase" < "$local_gnulib_dir/$lkfile.diff" \
1085           || func_fatal_error "patch file $local_gnulib_dir/$lkfile.diff didn't apply cleanly"
1086         lookedup_file="$tmp/$lkbase"
1087         lookedup_tmp=true
1088       else
1089         lookedup_file="$gnulib_dir/$lkfile"
1090         lookedup_tmp=
1091       fi
1092     else
1093       func_fatal_error "file $gnulib_dir/$lkfile not found"
1094     fi
1095   fi
1096 }
1097
1098 # func_all_modules
1099 # Input:
1100 # - local_gnulib_dir  from --local-dir
1101 func_all_modules ()
1102 {
1103   # Filter out metainformation files like README, which are not modules.
1104   # Filter out unit test modules; they can be retrieved through
1105   # --extract-tests-module if desired.
1106   {
1107     (cd "$gnulib_dir" && find modules -type f -print | sed -e 's,^modules/,,')
1108     if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
1109       (cd "$local_gnulib_dir" && find modules -type f -print | sed -e 's,^modules/,,' -e 's,\.diff$,,')
1110     fi
1111   } \
1112       | sed -e '/^CVS\//d' -e '/\/CVS\//d' \
1113             -e '/^ChangeLog$/d' -e '/\/ChangeLog$/d' \
1114             -e '/^COPYING$/d' -e '/\/COPYING$/d' \
1115             -e '/^README$/d' -e '/\/README$/d' \
1116             -e '/^TEMPLATE$/d' \
1117             -e '/^TEMPLATE-EXTENDED$/d' \
1118             -e '/^TEMPLATE-TESTS$/d' \
1119             -e '/^\..*/d' \
1120             -e '/~$/d' \
1121       | sed -e '/-tests$/d' \
1122       | LC_ALL=C sort -u
1123 }
1124
1125 # func_verify_module
1126 # verifies a module name
1127 # Input:
1128 # - local_gnulib_dir  from --local-dir
1129 # - module          module name argument
1130 func_verify_module ()
1131 {
1132   if { test -f "$gnulib_dir/modules/$module" \
1133        || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
1134             && test -f "$local_gnulib_dir/modules/$module"; }; } \
1135      && test "CVS" != "$module" \
1136      && test "ChangeLog" != "$module" \
1137      && test "COPYING" != "$module" \
1138      && test "README" != "$module" \
1139      && test "TEMPLATE" != "$module" \
1140      && test "TEMPLATE-EXTENDED" != "$module" \
1141      && test "TEMPLATE-TESTS" != "$module"; then
1142     # OK, $module is a correct module name.
1143     # Verify that building the module description with 'patch' succeeds.
1144     func_lookup_file "modules/$module"
1145   else
1146     echo "gnulib-tool: module $module doesn't exist" 1>&2
1147     module=
1148   fi
1149 }
1150
1151 # func_verify_nontests_module
1152 # verifies a module name, excluding tests modules
1153 # Input:
1154 # - local_gnulib_dir  from --local-dir
1155 # - module          module name argument
1156 func_verify_nontests_module ()
1157 {
1158   case "$module" in
1159     *-tests ) module= ;;
1160     * ) func_verify_module ;;
1161   esac
1162 }
1163
1164 # func_verify_tests_module
1165 # verifies a module name, considering only tests modules
1166 # Input:
1167 # - local_gnulib_dir  from --local-dir
1168 # - module          module name argument
1169 func_verify_tests_module ()
1170 {
1171   case "$module" in
1172     *-tests ) func_verify_module ;;
1173     * ) module= ;;
1174   esac
1175 }
1176
1177 sed_extract_prog=':[     ]*$/ {
1178   :a
1179     n
1180     s/^Description:[     ]*$//
1181     s/^Notice:[  ]*$//
1182     s/^Files:[   ]*$//
1183     s/^Depends-on:[      ]*$//
1184     s/^configure\.ac-early:[     ]*$//
1185     s/^configure\.ac:[   ]*$//
1186     s/^Makefile\.am:[    ]*$//
1187     s/^Include:[         ]*$//
1188     s/^Link:[    ]*$//
1189     s/^License:[         ]*$//
1190     s/^Maintainer:[      ]*$//
1191     tb
1192     p
1193     ba
1194   :b
1195 }'
1196
1197 # func_get_description module
1198 # Input:
1199 # - local_gnulib_dir  from --local-dir
1200 func_get_description ()
1201 {
1202   func_lookup_file "modules/$1"
1203   sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
1204 }
1205
1206 # func_get_notice module
1207 # Input:
1208 # - local_gnulib_dir  from --local-dir
1209 func_get_notice ()
1210 {
1211   func_lookup_file "modules/$1"
1212   sed -n -e "/^Notice$sed_extract_prog" < "$lookedup_file"
1213 }
1214
1215 # func_get_filelist module
1216 # Input:
1217 # - local_gnulib_dir  from --local-dir
1218 func_get_filelist ()
1219 {
1220   func_lookup_file "modules/$1"
1221   sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"
1222   echo m4/gnulib-common.m4
1223   case "$autoconf_minversion" in
1224     2.59)
1225       #echo m4/onceonly.m4
1226       echo m4/onceonly_2_57.m4
1227       ;;
1228   esac
1229 }
1230
1231 # func_get_dependencies module
1232 # Input:
1233 # - local_gnulib_dir  from --local-dir
1234 func_get_dependencies ()
1235 {
1236   # ${module}-tests always implicitly depends on ${module}.
1237   echo "$1" | sed -n -e 's/-tests$//p'
1238   # Then the explicit dependencies listed in the module description.
1239   func_lookup_file "modules/$1"
1240   sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"
1241 }
1242
1243 # func_get_autoconf_early_snippet module
1244 # Input:
1245 # - local_gnulib_dir  from --local-dir
1246 func_get_autoconf_early_snippet ()
1247 {
1248   func_lookup_file "modules/$1"
1249   sed -n -e "/^configure\.ac-early$sed_extract_prog" < "$lookedup_file"
1250 }
1251
1252 # func_get_autoconf_snippet module
1253 # Input:
1254 # - local_gnulib_dir  from --local-dir
1255 func_get_autoconf_snippet ()
1256 {
1257   func_lookup_file "modules/$1"
1258   sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
1259 }
1260
1261 # func_get_automake_snippet module
1262 # Input:
1263 # - local_gnulib_dir  from --local-dir
1264 func_get_automake_snippet ()
1265 {
1266   func_lookup_file "modules/$1"
1267   sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
1268   case "$1" in
1269     *-tests)
1270       # *-tests module live in tests/, not lib/.
1271       # Synthesize an EXTRA_DIST augmentation.
1272       all_files=`func_get_filelist $1`
1273       tests_files=`for f in $all_files; do \
1274                      case $f in \
1275                        tests/*) echo $f ;; \
1276                      esac; \
1277                    done | sed -e 's,^tests/,,'`
1278       extra_files="$tests_files"
1279       if test -n "$extra_files"; then
1280         echo "EXTRA_DIST +=" $extra_files
1281         echo
1282       fi
1283       ;;
1284     *)
1285       # Synthesize an EXTRA_DIST augmentation.
1286       sed_combine_lines='/\\$/{
1287         :a
1288         N
1289         s/\\\n/ /
1290         s/\\$/\\/
1291         ta
1292       }'
1293       sed_extract_mentioned_files='s/^lib_SOURCES[       ]*+=[   ]*//p'
1294       already_mentioned_files=` \
1295         sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file" \
1296         | sed -e "$sed_combine_lines" \
1297         | sed -n -e "$sed_extract_mentioned_files" | sed -e 's/#.*//'`
1298       all_files=`func_get_filelist $1`
1299       lib_files=`for f in $all_files; do \
1300                    case $f in \
1301                      lib/*) echo $f ;; \
1302                    esac; \
1303                  done | sed -e 's,^lib/,,'`
1304       # Remove $already_mentioned_files from $lib_files.
1305       echo "$lib_files" | LC_ALL=C sort -u > "$tmp"/lib-files
1306       extra_files=`for f in $already_mentioned_files; do echo $f; done \
1307                    | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/lib-files`
1308       if test -n "$extra_files"; then
1309         echo "EXTRA_DIST +=" $extra_files
1310         echo
1311       fi
1312       # Synthesize also an EXTRA_lib_SOURCES augmentation.
1313       # This is necessary so that automake can generate the right list of
1314       # dependency rules.
1315       # A possible approach would be to use autom4te --trace of the redefined
1316       # AC_LIBOBJ and AC_REPLACE_FUNCS macros when creating the Makefile.am
1317       # (use autom4te --trace, not just grep, so that AC_LIBOBJ invocations
1318       # inside autoconf's built-in macros are not missed).
1319       # But it's simpler and more robust to do it here, based on the file list.
1320       # If some .c file exists and is not used with AC_LIBOBJ - for example,
1321       # a .c file is preprocessed into another .c file for BUILT_SOURCES -,
1322       # automake will generate a useless dependency; this is harmless.
1323       case "$1" in
1324         relocatable-prog-wrapper) ;;
1325         *)
1326           sed_extract_c_files='/\.c$/p'
1327           extra_files=`echo "$extra_files" | sed -n -e "$sed_extract_c_files"`
1328           if test -n "$extra_files"; then
1329             echo "EXTRA_lib_SOURCES +=" $extra_files
1330             echo
1331           fi
1332           ;;
1333       esac
1334       # Synthesize an EXTRA_DIST augmentation also for the files in build-aux/.
1335       buildaux_files=`for f in $all_files; do \
1336                         case $f in \
1337                           build-aux/*) echo $f ;; \
1338                         esac; \
1339                       done | sed -e 's,^build-aux/,,'`
1340       if test -n "$buildaux_files"; then
1341         sed_prepend_auxdir='s,^,$(top_srcdir)/'"$auxdir"'/,'
1342         echo "EXTRA_DIST += "`echo "$buildaux_files" | sed -e "$sed_prepend_auxdir"`
1343         echo
1344       fi
1345       ;;
1346   esac
1347 }
1348
1349 # func_get_include_directive module
1350 # Input:
1351 # - local_gnulib_dir  from --local-dir
1352 func_get_include_directive ()
1353 {
1354   func_lookup_file "modules/$1"
1355   sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" | \
1356   sed -e 's/^\(["<]\)/#include \1/'
1357 }
1358
1359 # func_get_link_directive module
1360 # Input:
1361 # - local_gnulib_dir  from --local-dir
1362 func_get_link_directive ()
1363 {
1364   func_lookup_file "modules/$1"
1365   sed -n -e "/^Link$sed_extract_prog" < "$lookedup_file"
1366 }
1367
1368 # func_get_license module
1369 # Input:
1370 # - local_gnulib_dir  from --local-dir
1371 func_get_license ()
1372 {
1373   func_lookup_file "modules/$1"
1374   { sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
1375     # The default is GPL.
1376     echo "GPL"
1377   } | sed -e 's,^ *$,,' | sed -e 1q
1378 }
1379
1380 # func_get_maintainer module
1381 # Input:
1382 # - local_gnulib_dir  from --local-dir
1383 func_get_maintainer ()
1384 {
1385   func_lookup_file "modules/$1"
1386   sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
1387 }
1388
1389 # func_get_tests_module module
1390 # Input:
1391 # - local_gnulib_dir  from --local-dir
1392 func_get_tests_module ()
1393 {
1394   # The naming convention for tests modules is hardwired: ${module}-tests.
1395   if test -f "$gnulib_dir/modules/$1"-tests \
1396      || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
1397           && test -f "$local_gnulib_dir/modules/$1"-tests; }; then
1398     echo "$1"-tests
1399   fi
1400 }
1401
1402 # func_acceptable module
1403 # tests whether a module is acceptable.
1404 # Input:
1405 # - avoidlist       list of modules to avoid
1406 func_acceptable ()
1407 {
1408   for avoid in $avoidlist; do
1409     if test "$avoid" = "$1"; then
1410       return 1
1411     fi
1412   done
1413   return 0
1414 }
1415
1416 # func_modules_transitive_closure
1417 # Input:
1418 # - local_gnulib_dir  from --local-dir
1419 # - modules         list of specified modules
1420 # - inctests        true if tests should be included, blank otherwise
1421 # - avoidlist       list of modules to avoid
1422 # - tmp             pathname of a temporary directory
1423 # Output:
1424 # - modules         list of modules, including dependencies
1425 func_modules_transitive_closure ()
1426 {
1427   # In order to process every module only once (for speed), process an "input
1428   # list" of modules, producing an "output list" of modules. During each round,
1429   # more modules can be queued in the input list. Once a module on the input
1430   # list has been processed, it is added to the "handled list", so we can avoid
1431   # to process it again.
1432   handledmodules=
1433   inmodules="$modules"
1434   outmodules=
1435   while test -n "$inmodules"; do
1436     inmodules_this_round="$inmodules"
1437     inmodules=                    # Accumulator, queue for next round
1438     for module in $inmodules_this_round; do
1439       func_verify_module
1440       if test -n "$module"; then
1441         if func_acceptable $module; then
1442           func_append outmodules " $module"
1443           deps=`func_get_dependencies $module`
1444           # Duplicate dependencies are harmless, but Jim wants a warning.
1445           duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
1446           if test -n "$duplicated_deps"; then
1447             echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
1448           fi
1449           func_append inmodules " $deps"
1450           if test -n "$inctests"; then
1451             testsmodule=`func_get_tests_module $module`
1452             if test -n "$testsmodule"; then
1453               func_append inmodules " $testsmodule"
1454             fi
1455           fi
1456         fi
1457       fi
1458     done
1459     handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
1460     # Remove $handledmodules from $inmodules.
1461     for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
1462     inmodules=`echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
1463   done
1464   modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
1465   rm -f "$tmp"/queued-modules
1466 }
1467
1468 # func_modules_add_dummy
1469 # Input:
1470 # - local_gnulib_dir  from --local-dir
1471 # - modules         list of modules, including dependencies
1472 # Output:
1473 # - modules         list of modules, including 'dummy' if needed
1474 func_modules_add_dummy ()
1475 {
1476   have_lib_SOURCES=
1477   sed_remove_backslash_newline=':a
1478 /\\$/{
1479 s/\\$//
1480 N
1481 s/\n//
1482 ba
1483 }'
1484   for module in $modules; do
1485     func_verify_nontests_module
1486     if test -n "$module"; then
1487       # Extract the value of "lib_SOURCES += ...".
1488       for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[     ]*+=\([^#]*\).*$,\1,p'`; do
1489         # Ignore .h files since they are not compiled.
1490         case "$file" in
1491           *.h) ;;
1492           *) have_lib_SOURCES=yes ;;
1493         esac
1494       done
1495     fi
1496   done
1497   # Add the dummy module, to make sure the library will be non-empty.
1498   if test -z "$have_lib_SOURCES"; then
1499     if func_acceptable "dummy"; then
1500       func_append modules " dummy"
1501     fi
1502   fi
1503 }
1504
1505 # func_modules_notice
1506 # Input:
1507 # - local_gnulib_dir  from --local-dir
1508 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
1509 # - modules         list of modules, including dependencies
1510 func_modules_notice ()
1511 {
1512   if test $verbose -ge -1; then
1513     for module in $modules; do
1514       func_verify_module
1515       if test -n "$module"; then
1516         msg=`func_get_notice $module`
1517         if test -n "$msg"; then
1518           echo "Notice from module $module:"
1519           echo "$msg" | sed -e 's/^/  /'
1520         fi
1521       fi
1522     done
1523   fi
1524 }
1525
1526 # func_modules_to_filelist
1527 # Input:
1528 # - local_gnulib_dir  from --local-dir
1529 # - modules         list of modules, including dependencies
1530 # Output:
1531 # - files           list of files
1532 func_modules_to_filelist ()
1533 {
1534   files=
1535   for module in $modules; do
1536     func_verify_module
1537     if test -n "$module"; then
1538       fs=`func_get_filelist $module`
1539       func_append files " $fs"
1540     fi
1541   done
1542   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
1543 }
1544
1545 # func_execute_command command [args...]
1546 # Executes a command.
1547 # Uses also the variables
1548 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
1549 func_execute_command ()
1550 {
1551   if test $verbose -ge 0; then
1552     echo "executing $*"
1553     "$@"
1554   else
1555     # Commands like automake produce output to stderr even when the succeed.
1556     # Turn this output off if the command succeeds.
1557     "$@" > "$tmp"/cmdout 2>&1
1558     cmdret=$?
1559     if test $cmdret = 0; then
1560       rm -f "$tmp"/cmdout
1561     else
1562       echo "executing $*"
1563       cat "$tmp"/cmdout 1>&2
1564       rm -f "$tmp"/cmdout
1565       (exit $cmdret)
1566     fi
1567   fi
1568 }
1569
1570 # func_emit_lib_Makefile_am
1571 # emits the contents of library makefile to standard output.
1572 # Input:
1573 # - local_gnulib_dir  from --local-dir
1574 # - modules         list of modules, including dependencies
1575 # - libname         library name
1576 # - pobase          directory relative to destdir where to place *.po files
1577 # - auxdir          directory relative to destdir where to place build aux files
1578 # - makefile_name   from --makefile-name
1579 # - libtool         true if libtool will be used, false or blank otherwise
1580 # - macro_prefix    prefix of gl_LIBOBJS macros to use
1581 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
1582 # - actioncmd       (optional) command that will reproduce this invocation
1583 # - for_test        true if creating a package for testing, false otherwise
1584 # Output:
1585 # - uses_subdirs    nonempty if object files in subdirs exist
1586 func_emit_lib_Makefile_am ()
1587 {
1588   # When creating an includable Makefile.am snippet, augment variables with
1589   # += instead of assigning them.
1590   if test -n "$makefile_name"; then
1591     assign='+='
1592   else
1593     assign='='
1594   fi
1595   if test "$libtool" = true; then
1596     libext=la
1597     perhapsLT=LT
1598     sed_eliminate_LDFLAGS=
1599   else
1600     libext=a
1601     perhapsLT=
1602     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1603   fi
1604   if $for_test; then
1605     # When creating a package for testing: Attempt to provoke failures,
1606     # especially link errors, already during "make" rather than during
1607     # "make check", because "make check" is not possible in a cross-compiling
1608     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
1609     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
1610   else
1611     sed_transform_check_PROGRAMS=
1612   fi
1613   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1614   echo "## Process this file with automake to produce Makefile.in."
1615   func_emit_copyright_notice
1616   if test -n "$actioncmd"; then
1617     echo "# Reproduce by: $actioncmd"
1618   fi
1619   echo
1620   uses_subdirs=
1621   {
1622     for module in $modules; do
1623       func_verify_nontests_module
1624       if test -n "$module"; then
1625         {
1626           func_get_automake_snippet "$module" |
1627             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1628                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
1629                 -e "$sed_eliminate_LDFLAGS" \
1630                 -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' \
1631                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1632                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
1633                 -e "$sed_transform_check_PROGRAMS"
1634           if test "$module" = 'alloca'; then
1635             echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
1636             echo "${libname}_${libext}_DEPENDENCIES += @${perhapsLT}ALLOCA@"
1637           fi
1638         } > amsnippet.tmp
1639         # Skip the contents if its entirely empty.
1640         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1641           echo "## begin gnulib module $module"
1642           echo
1643           cat amsnippet.tmp
1644           echo "## end   gnulib module $module"
1645           echo
1646         fi
1647         rm -f amsnippet.tmp
1648         # Test whether there are some source files in subdirectories.
1649         for f in `func_get_filelist "$module"`; do
1650           case $f in
1651             lib/*/*.c) uses_subdirs=yes ;;
1652           esac
1653         done
1654       fi
1655     done
1656   } > allsnippets.tmp
1657   if test -z "$makefile_name"; then
1658     # If there are source files in subdirectories, prevent collision of the
1659     # object files (example: hash.c and libxml/hash.c).
1660     subdir_options=
1661     if test -n "$uses_subdirs"; then
1662       subdir_options=' subdir-objects'
1663     fi
1664     echo "AUTOMAKE_OPTIONS = 1.5 gnits${subdir_options}"
1665   fi
1666   echo
1667   if test -z "$makefile_name"; then
1668     echo "noinst_HEADERS ="
1669     echo "noinst_LIBRARIES ="
1670     echo "noinst_LTLIBRARIES ="
1671     # Automake versions < 1.9b create an empty pkgdatadir at installation time
1672     # if you specify pkgdata_DATA to empty. This is a workaround.
1673     if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1674       echo "pkgdata_DATA ="
1675     fi
1676     echo "EXTRA_DIST ="
1677     echo "BUILT_SOURCES ="
1678     echo "SUFFIXES ="
1679   fi
1680   echo "MOSTLYCLEANFILES $assign core *.stackdump"
1681   if test -z "$makefile_name"; then
1682     echo "MOSTLYCLEANDIRS ="
1683     echo "CLEANFILES ="
1684     echo "DISTCLEANFILES ="
1685     echo "MAINTAINERCLEANFILES ="
1686     echo
1687     echo "AM_CPPFLAGS ="
1688   fi
1689   echo
1690   if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *= *$libname\\.$libext\$" allsnippets.tmp > /dev/null; then
1691     # One of the snippets already specifies an installation location for the
1692     # library. Don't confuse automake by saying it should not be installed.
1693     :
1694   else
1695     # By default, the generated library should not be installed.
1696     echo "noinst_${perhapsLT}LIBRARIES += $libname.$libext"
1697   fi
1698   echo
1699   echo "${libname}_${libext}_SOURCES ="
1700   # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1701   # automake during its analyses looks for $(LIBOBJS), not for @LIBOBJS@.
1702   echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1703   echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
1704   echo "EXTRA_${libname}_${libext}_SOURCES ="
1705   if test "$libtool" = true; then
1706     echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
1707   fi
1708   echo
1709   if test -n "$pobase"; then
1710     echo "AM_CPPFLAGS += -DDEFAULT_TEXT_DOMAIN=\\\"${po_domain}-gnulib\\\""
1711     echo
1712   fi
1713   cat allsnippets.tmp \
1714     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
1715   echo
1716   echo "mostlyclean-local: mostlyclean-generic"
1717   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1718   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1719   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1720   echo "          fi; \\"
1721   echo "        done; \\"
1722   echo "        :"
1723   rm -f allsnippets.tmp
1724 }
1725
1726 # func_emit_po_Makevars
1727 # emits the contents of po/ makefile parametrization to standard output.
1728 # Input:
1729 # - local_gnulib_dir  from --local-dir
1730 # - sourcebase      directory relative to destdir where to place source code
1731 # - pobase          directory relative to destdir where to place *.po files
1732 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
1733 func_emit_po_Makevars ()
1734 {
1735   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1736   func_emit_copyright_notice
1737   echo
1738   echo "# Usually the message domain is the same as the package name."
1739   echo "# But here it has a '-gnulib' suffix."
1740   echo "DOMAIN = ${po_domain}-gnulib"
1741   echo
1742   echo "# These two variables depend on the location of this directory."
1743   echo "subdir = ${pobase}"
1744   echo "top_builddir = "`echo "$pobase" | sed -e 's,//*,/,g' -e 's,[^/][^/]*,..,g'`
1745   echo
1746   cat <<\EOF
1747 # These options get passed to xgettext.
1748 XGETTEXT_OPTIONS = \
1749   --keyword=_ --flag=_:1:pass-c-format \
1750   --keyword=N_ --flag=N_:1:pass-c-format \
1751   --keyword='proper_name:1,"This is a proper name. See the gettext manual, section Names."' \
1752   --keyword='proper_name_utf8:1,"This is a proper name. See the gettext manual, section Names."' \
1753   --flag=error:3:c-format --flag=error_at_line:5:c-format
1754
1755 # This is the copyright holder that gets inserted into the header of the
1756 # $(DOMAIN).pot file.  gnulib is copyrighted by the FSF.
1757 COPYRIGHT_HOLDER = Free Software Foundation, Inc.
1758
1759 # This is the email address or URL to which the translators shall report
1760 # bugs in the untranslated strings:
1761 # - Strings which are not entire sentences, see the maintainer guidelines
1762 #   in the GNU gettext documentation, section 'Preparing Strings'.
1763 # - Strings which use unclear terms or require additional context to be
1764 #   understood.
1765 # - Strings which make invalid assumptions about notation of date, time or
1766 #   money.
1767 # - Pluralisation problems.
1768 # - Incorrect English spelling.
1769 # - Incorrect formatting.
1770 # It can be your email address, or a mailing list address where translators
1771 # can write to without being subscribed, or the URL of a web page through
1772 # which the translators can contact you.
1773 MSGID_BUGS_ADDRESS = bug-gnulib@gnu.org
1774
1775 # This is the list of locale categories, beyond LC_MESSAGES, for which the
1776 # message catalogs shall be used.  It is usually empty.
1777 EXTRA_LOCALE_CATEGORIES =
1778
1779 # This tells whether the $(DOMAIN).pot file contains messages with an 'msgctxt'
1780 # context.  Possible values are "yes" and "no".  Set this to yes if the
1781 # package uses functions taking also a message context, like pgettext(), or
1782 # if in $(XGETTEXT_OPTIONS) you define keywords with a context argument.
1783 USE_MSGCTXT = no
1784 EOF
1785 }
1786
1787 # func_emit_po_POTFILES_in
1788 # emits the file list to be passed to xgettext to standard output.
1789 # Input:
1790 # - local_gnulib_dir  from --local-dir
1791 # - sourcebase      directory relative to destdir where to place source code
1792 # - files           list of new files
1793 func_emit_po_POTFILES_in ()
1794 {
1795   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1796   func_emit_copyright_notice
1797   echo
1798   echo "# List of files which contain translatable strings."
1799   echo "$files" | sed -n -e "s,^lib/,$sourcebase/,p"
1800 }
1801
1802 # func_emit_tests_Makefile_am
1803 # emits the contents of tests makefile to standard output.
1804 # Input:
1805 # - local_gnulib_dir  from --local-dir
1806 # - modules         list of modules, including dependencies
1807 # - libname         library name
1808 # - auxdir          directory relative to destdir where to place build aux files
1809 # - makefile_name   from --makefile-name
1810 # - libtool         true if libtool will be used, false or blank otherwise
1811 # - sourcebase      relative directory containing lib source code
1812 # - m4base          relative directory containing autoconf macros
1813 # - testsbase       relative directory containing unit test code
1814 # - macro_prefix    prefix of gl_LIBOBJS macros to use
1815 # - for_test        true if creating a package for testing, false otherwise
1816 # - use_libtests    true if a libtests.a should be built, false otherwise
1817 # Output:
1818 # - uses_subdirs    nonempty if object files in subdirs exist
1819 func_emit_tests_Makefile_am ()
1820 {
1821   if test "$libtool" = true; then
1822     libext=la
1823     sed_eliminate_LDFLAGS=
1824   else
1825     libext=a
1826     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[        ]*+=/d'
1827   fi
1828   if $for_test; then
1829     # When creating a package for testing: Attempt to provoke failures,
1830     # especially link errors, already during "make" rather than during
1831     # "make check", because "make check" is not possible in a cross-compiling
1832     # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
1833     sed_transform_check_PROGRAMS='s,check_PROGRAMS,noinst_PROGRAMS,g'
1834   else
1835     sed_transform_check_PROGRAMS=
1836   fi
1837   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
1838   echo "## DO NOT EDIT! GENERATED AUTOMATICALLY!"
1839   echo "## Process this file with automake to produce Makefile.in."
1840   func_emit_copyright_notice
1841   echo
1842   uses_subdirs=
1843   (
1844     for module in $modules; do
1845       if $for_test; then
1846         func_verify_tests_module
1847       else
1848         func_verify_module
1849       fi
1850       if test -n "$module"; then
1851         {
1852           func_get_automake_snippet "$module" |
1853             sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1854                 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' \
1855                 -e "$sed_eliminate_LDFLAGS" \
1856                 -e 's,lib_\([A-Z][A-Z]*\),libtests_a_\1,g' \
1857                 -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1858                 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g' \
1859                 -e "$sed_transform_check_PROGRAMS"
1860           if $use_libtests && test "$module" = 'alloca'; then
1861             echo "libtests_a_LIBADD += @${perhapsLT}ALLOCA@"
1862             echo "libtests_a_DEPENDENCIES += @${perhapsLT}ALLOCA@"
1863           fi
1864         } > amsnippet.tmp
1865         # Skip the contents if its entirely empty.
1866         if grep '[^      ]' amsnippet.tmp > /dev/null ; then
1867           echo "## begin gnulib module $module"
1868           echo
1869           cat amsnippet.tmp
1870           echo "## end   gnulib module $module"
1871           echo
1872         fi
1873         rm -f amsnippet.tmp
1874         # Test whether there are some source files in subdirectories.
1875         for f in `func_get_filelist "$module"`; do
1876           case $f in
1877             lib/*/*.c | tests/*/*.c) uses_subdirs=yes ;;
1878           esac
1879         done
1880       fi
1881     done
1882   ) > allsnippets.tmp
1883   # Generate dependencies here, since it eases the debugging of test failures.
1884   # If there are source files in subdirectories, prevent collision of the
1885   # object files (example: hash.c and libxml/hash.c).
1886   subdir_options=
1887   if test -n "$uses_subdirs"; then
1888     subdir_options=' subdir-objects'
1889   fi
1890   echo "AUTOMAKE_OPTIONS = 1.5 foreign${subdir_options}"
1891   echo
1892   if $for_test; then
1893     echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
1894     echo
1895   fi
1896   # Nothing is being added to SUBDIRS; nevertheless the existence of this
1897   # variable is needed to avoid an error from automake:
1898   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
1899   echo "SUBDIRS ="
1900   echo "TESTS ="
1901   echo "TESTS_ENVIRONMENT ="
1902   echo "noinst_PROGRAMS ="
1903   if ! $for_test; then
1904     echo "check_PROGRAMS ="
1905   fi
1906   echo "noinst_HEADERS ="
1907   echo "noinst_LIBRARIES ="
1908   if $use_libtests; then
1909     if $for_test; then
1910       echo "noinst_LIBRARIES += libtests.a"
1911     else
1912       echo "check_LIBRARIES = libtests.a"
1913     fi
1914   fi
1915   # Automake versions < 1.9b create an empty pkgdatadir at installation time
1916   # if you specify pkgdata_DATA to empty. This is a workaround.
1917   if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1918     echo "pkgdata_DATA ="
1919   fi
1920   echo "EXTRA_DIST ="
1921   echo "BUILT_SOURCES ="
1922   echo "SUFFIXES ="
1923   echo "MOSTLYCLEANFILES = core *.stackdump"
1924   echo "MOSTLYCLEANDIRS ="
1925   echo "CLEANFILES ="
1926   echo "DISTCLEANFILES ="
1927   echo "MAINTAINERCLEANFILES ="
1928   echo
1929   echo "AM_CPPFLAGS = \\"
1930   echo "  -I. -I\$(srcdir) \\"
1931   echo "  -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
1932   echo "  -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
1933   echo
1934   local_ldadd_before=''
1935   local_ldadd_after=''
1936   if $use_libtests; then
1937     # All test programs need to be linked with libtests.a.
1938     # It needs to be passed to the linker before ${libname}.${libext}, since
1939     # the tests-related modules depend on the main modules.
1940     # It also needs to be passed to the linker after ${libname}.${libext}
1941     # because the latter might contain incomplete modules (such as the 'error'
1942     # module whose dependency to 'progname' is voluntarily omitted).
1943     # The LIBTESTS_LIBDEPS can be passed to the linker once or twice, it does
1944     # not matter.
1945     local_ldadd_before=' libtests.a'
1946     local_ldadd_after=' libtests.a $(LIBTESTS_LIBDEPS)'
1947   fi
1948   echo "LDADD =${local_ldadd_before} ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}${local_ldadd_after}"
1949   echo
1950   if $use_libtests; then
1951     echo "libtests_a_SOURCES ="
1952     # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1953     # automake during its analyses looks for $(LIBOBJS), not for @LIBOBJS@.
1954     echo "libtests_a_LIBADD = \$(${macro_prefix}tests_LIBOBJS)"
1955     echo "libtests_a_DEPENDENCIES = \$(${macro_prefix}tests_LIBOBJS)"
1956     echo "EXTRA_libtests_a_SOURCES ="
1957     # The circular dependency in LDADD requires this.
1958     echo "AM_LIBTOOLFLAGS = --preserve-dup-deps"
1959     echo
1960   fi
1961   cat allsnippets.tmp \
1962     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
1963   echo "# Clean up after Solaris cc."
1964   echo "clean-local:"
1965   echo "        rm -rf SunWS_cache"
1966   echo
1967   echo "mostlyclean-local: mostlyclean-generic"
1968   echo "        @for dir in '' \$(MOSTLYCLEANDIRS); do \\"
1969   echo "          if test -n \"\$\$dir\" && test -d \$\$dir; then \\"
1970   echo "            echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1971   echo "          fi; \\"
1972   echo "        done; \\"
1973   echo "        :"
1974   rm -f allsnippets.tmp
1975 }
1976
1977 # func_emit_initmacro_start macro_prefix
1978 # emits the first few statements of the gl_INIT macro to standard output.
1979 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
1980 func_emit_initmacro_start ()
1981 {
1982   macro_prefix_arg="$1"
1983   # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
1984   # platform-dependent object files in ${macro_prefix_arg}_LIBOBJS instead of
1985   # LIBOBJS.  The purpose is to allow several gnulib instantiations under
1986   # a single configure.ac file.  (AC_CONFIG_LIBOBJ_DIR does not allow this
1987   # flexibility.)
1988   # Furthermore it avoids an automake error like this when a Makefile.am
1989   # that uses pieces of gnulib also uses $(LIBOBJ):
1990   #   automatically discovered file `error.c' should not be explicitly mentioned
1991   echo "  m4_pushdef([AC_LIBOBJ], m4_defn([${macro_prefix_arg}_LIBOBJ]))"
1992   echo "  m4_pushdef([AC_REPLACE_FUNCS], m4_defn([${macro_prefix_arg}_REPLACE_FUNCS]))"
1993   # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
1994   # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
1995   #   automatically discovered file `error.c' should not be explicitly mentioned
1996   # We let automake know about the files to be distributed through the
1997   # EXTRA_lib_SOURCES variable.
1998   echo "  m4_pushdef([AC_LIBSOURCES], m4_defn([${macro_prefix_arg}_LIBSOURCES]))"
1999 }
2000
2001 # func_emit_initmacro_end macro_prefix
2002 # emits the last few statements of the gl_INIT macro to standard output.
2003 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
2004 func_emit_initmacro_end ()
2005 {
2006   macro_prefix_arg="$1"
2007   echo "  m4_popdef([AC_LIBSOURCES])"
2008   echo "  m4_popdef([AC_REPLACE_FUNCS])"
2009   echo "  m4_popdef([AC_LIBOBJ])"
2010   echo "  AC_CONFIG_COMMANDS_PRE(["
2011   echo "    ${macro_prefix_arg}_libobjs="
2012   echo "    ${macro_prefix_arg}_ltlibobjs="
2013   echo "    if test -n \"\$${macro_prefix_arg}_LIBOBJS\"; then"
2014   echo "      # Remove the extension."
2015   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
2016   echo "      for i in \`for i in \$${macro_prefix_arg}_LIBOBJS; do echo \"\$i\"; done | sed \"\$sed_drop_objext\" | sort | uniq\`; do"
2017   echo "        ${macro_prefix_arg}_libobjs=\"\$${macro_prefix_arg}_libobjs \$i.\$ac_objext\""
2018   echo "        ${macro_prefix_arg}_ltlibobjs=\"\$${macro_prefix_arg}_ltlibobjs \$i.lo\""
2019   echo "      done"
2020   echo "    fi"
2021   echo "    AC_SUBST([${macro_prefix_arg}_LIBOBJS], [\$${macro_prefix_arg}_libobjs])"
2022   echo "    AC_SUBST([${macro_prefix_arg}_LTLIBOBJS], [\$${macro_prefix_arg}_ltlibobjs])"
2023   echo "  ])"
2024 }
2025
2026 # func_emit_initmacro_done macro_prefix sourcebase
2027 # emits a few statements after the gl_INIT macro to standard output.
2028 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
2029 # - sourcebase      directory relative to destdir where to place source code
2030 func_emit_initmacro_done ()
2031 {
2032   macro_prefix_arg="$1"
2033   sourcebase_arg="$2"
2034   echo
2035   echo "# Like AC_LIBOBJ, except that the module name goes"
2036   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
2037   echo "AC_DEFUN([${macro_prefix_arg}_LIBOBJ], ["
2038   echo "  AS_LITERAL_IF([\$1], [${macro_prefix_arg}_LIBSOURCES([\$1.c])])dnl"
2039   echo "  ${macro_prefix_arg}_LIBOBJS=\"\$${macro_prefix_arg}_LIBOBJS \$1.\$ac_objext\""
2040   echo "])"
2041   echo
2042   echo "# m4_foreach_w is provided by autoconf-2.59c and later."
2043   echo "# This definition is to accommodate developers using versions"
2044   echo "# of autoconf older than that."
2045   echo "m4_ifndef([m4_foreach_w],"
2046   echo "  [m4_define([m4_foreach_w],"
2047   echo "    [m4_foreach([\$1], m4_split(m4_normalize([\$2]), [ ]), [\$3])])])"
2048   echo
2049   echo "# Like AC_REPLACE_FUNCS, except that the module name goes"
2050   echo "# into ${macro_prefix_arg}_LIBOBJS instead of into LIBOBJS."
2051   echo "AC_DEFUN([${macro_prefix_arg}_REPLACE_FUNCS], ["
2052   echo "  m4_foreach_w([gl_NAME], [\$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl"
2053   echo "  AC_CHECK_FUNCS([\$1], , [${macro_prefix_arg}_LIBOBJ(\$ac_func)])"
2054   echo "])"
2055   echo
2056   echo "# Like AC_LIBSOURCES, except the directory where the source file is"
2057   echo "# expected is derived from the gnulib-tool parametrization,"
2058   echo "# and alloca is special cased (for the alloca-opt module)."
2059   echo "# We could also entirely rely on EXTRA_lib..._SOURCES."
2060   echo "AC_DEFUN([${macro_prefix_arg}_LIBSOURCES], ["
2061   echo "  m4_foreach([_gl_NAME], [\$1], ["
2062   echo "    m4_if(_gl_NAME, [alloca.c], [], ["
2063   echo "      m4_syscmd([test -r $sourcebase_arg/]_gl_NAME[ || test ! -d $sourcebase_arg])dnl"
2064   echo "      m4_if(m4_sysval, [0], [],"
2065   echo "        [AC_FATAL([missing $sourcebase_arg/]_gl_NAME)])"
2066   echo "    ])"
2067   echo "  ])"
2068   echo "])"
2069 }
2070
2071 # func_import modules
2072 # Uses also the variables
2073 # - destdir         target directory
2074 # - local_gnulib_dir  from --local-dir
2075 # - verbose         integer, default 0, inc/decremented by --verbose/--quiet
2076 # - libname         library name
2077 # - sourcebase      directory relative to destdir where to place source code
2078 # - m4base          directory relative to destdir where to place *.m4 macros
2079 # - pobase          directory relative to destdir where to place *.po files
2080 # - docbase         directory relative to destdir where to place doc files
2081 # - testsbase       directory relative to destdir where to place unit test code
2082 # - auxdir          directory relative to destdir where to place build aux files
2083 # - inctests        true if --with-tests was given, blank otherwise
2084 # - avoidlist       list of modules to avoid, from --avoid
2085 # - lgpl            yes or a number if library's license shall be LGPL,
2086 #                   blank otherwise
2087 # - makefile_name   from --makefile-name
2088 # - libtool         true if --libtool was given, false if --no-libtool was
2089 #                   given, blank otherwise
2090 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
2091 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
2092 # - po_domain       prefix of i18n domain to use (without -gnulib suffix)
2093 # - autoconf_minversion  minimum supported autoconf version
2094 # - doit            : if actions shall be executed, false if only to be printed
2095 # - symbolic        true if files should be symlinked, copied otherwise
2096 # - lsymbolic       true if files from local_gnulib_dir should be symlinked,
2097 #                   copied otherwise
2098 # - do_copyrights   true if copyright notices in files should be replaced,
2099 #                   blank otherwise
2100 func_import ()
2101 {
2102   # Get the cached settings.
2103   cached_local_gnulib_dir=
2104   cached_specified_modules=
2105   cached_avoidlist=
2106   cached_sourcebase=
2107   cached_m4base=
2108   cached_pobase=
2109   cached_docbase=
2110   cached_testsbase=
2111   cached_inctests=
2112   cached_libname=
2113   cached_lgpl=
2114   cached_makefile_name=
2115   cached_libtool=
2116   cached_macro_prefix=
2117   cached_po_domain=
2118   cached_files=
2119   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
2120     cached_libtool=false
2121     my_sed_traces='
2122       s,#.*$,,
2123       s,^dnl .*$,,
2124       s, dnl .*$,,
2125       /gl_LOCAL_DIR(/ {
2126         s,^.*gl_LOCAL_DIR([[ ]*\([^])]*\).*$,cached_local_gnulib_dir="\1",p
2127       }
2128       /gl_MODULES(/ {
2129         s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
2130       }
2131       /gl_AVOID(/ {
2132         s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
2133       }
2134       /gl_SOURCE_BASE(/ {
2135         s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
2136       }
2137       /gl_M4_BASE(/ {
2138         s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
2139       }
2140       /gl_PO_BASE(/ {
2141         s,^.*gl_PO_BASE([[ ]*\([^])]*\).*$,cached_pobase="\1",p
2142       }
2143       /gl_DOC_BASE(/ {
2144         s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
2145       }
2146       /gl_TESTS_BASE(/ {
2147         s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
2148       }
2149       /gl_WITH_TESTS/ {
2150         s,^.*$,cached_inctests=true,p
2151       }
2152       /gl_LIB(/ {
2153         s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
2154       }
2155       /gl_LGPL(/ {
2156         s,^.*gl_LGPL([[ ]*\([^])]*\).*$,cached_lgpl="\1",p
2157       }
2158       /gl_LGPL/ {
2159         s,^.*$,cached_lgpl=yes,p
2160       }
2161       /gl_MAKEFILE_NAME(/ {
2162         s,^.*gl_MAKEFILE_NAME([[ ]*\([^])]*\).*$,cached_makefile_name="\1",p
2163       }
2164       /gl_LIBTOOL/ {
2165         s,^.*$,cached_libtool=true,p
2166       }
2167       /gl_MACRO_PREFIX(/ {
2168         s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
2169       }
2170       /gl_PO_DOMAIN(/ {
2171         s,^.*gl_PO_DOMAIN([[ ]*\([^])]*\).*$,cached_po_domain="\1",p
2172       }'
2173     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
2174     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
2175       my_sed_traces='
2176         s,#.*$,,
2177         s,^dnl .*$,,
2178         s, dnl .*$,,
2179         /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
2180           s,^.*$,cached_files=",p
2181           n
2182           ta
2183           :a
2184           s,^\]).*$,",
2185           tb
2186           p
2187           n
2188           ba
2189           :b
2190           p
2191         }'
2192       eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
2193     fi
2194   fi
2195
2196   # Merge the cached settings with the specified ones.
2197   # The m4base must be the same as expected from the pathname.
2198   if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
2199     func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
2200   fi
2201   # The local_gnulib_dir defaults to the cached one. Recall that the cached one
2202   # is relative to $destdir, whereas the one we use is relative to . or absolute.
2203   if test -z "$local_gnulib_dir"; then
2204     if test -n "$cached_local_gnulib_dir"; then
2205       case "$destdir" in
2206         /*)
2207           local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
2208         *)
2209           case "$cached_local_gnulib_dir" in
2210             /*)
2211               local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
2212             *)
2213               func_relconcat "$destdir" "$cached_local_gnulib_dir"
2214               local_gnulib_dir="$relconcat" ;;
2215           esac ;;
2216       esac
2217     fi
2218   fi
2219   # Append the cached and the specified module names. So that
2220   # "gnulib-tool --import foo" means to add the module foo.
2221   specified_modules="$cached_specified_modules $1"
2222   # Append the cached and the specified avoidlist. This is probably better
2223   # than dropping the cached one when --avoid is specified at least once.
2224   avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
2225   avoidlist=`echo $avoidlist`
2226
2227   # The sourcebase defaults to the cached one.
2228   if test -z "$sourcebase"; then
2229     sourcebase="$cached_sourcebase"
2230     if test -z "$sourcebase"; then
2231       func_fatal_error "missing --source-base option"
2232     fi
2233   fi
2234   # The pobase defaults to the cached one.
2235   if test -z "$pobase"; then
2236     pobase="$cached_pobase"
2237   fi
2238   # The docbase defaults to the cached one.
2239   if test -z "$docbase"; then
2240     docbase="$cached_docbase"
2241     if test -z "$docbase"; then
2242       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."
2243     fi
2244   fi
2245   # The testsbase defaults to the cached one.
2246   if test -z "$testsbase"; then
2247     testsbase="$cached_testsbase"
2248     if test -z "$testsbase"; then
2249       func_fatal_error "missing --tests-base option"
2250     fi
2251   fi
2252   # Require the tests if specified either way.
2253   if test -z "$inctests"; then
2254     inctests="$cached_inctests"
2255   fi
2256   # The libname defaults to the cached one.
2257   if test -z "$supplied_libname"; then
2258     libname="$cached_libname"
2259     if test -z "$libname"; then
2260       func_fatal_error "missing --lib option"
2261     fi
2262   fi
2263   # Require LGPL if specified either way.
2264   if test -z "$lgpl"; then
2265     lgpl="$cached_lgpl"
2266   fi
2267   # The makefile_name defaults to the cached one.
2268   if test -z "$makefile_name"; then
2269     makefile_name="$cached_makefile_name"
2270   fi
2271   # Use libtool if specified either way, or if guessed.
2272   if test -z "$libtool"; then
2273     if test -n "$cached_m4base"; then
2274       libtool="$cached_libtool"
2275     else
2276       libtool="$guessed_libtool"
2277     fi
2278   fi
2279   # The macro_prefix defaults to the cached one.
2280   if test -z "$macro_prefix"; then
2281     macro_prefix="$cached_macro_prefix"
2282     if test -z "$macro_prefix"; then
2283       func_fatal_error "missing --macro-prefix option"
2284     fi
2285   fi
2286   # The po_domain defaults to the cached one.
2287   if test -z "$po_domain"; then
2288     po_domain="$cached_po_domain"
2289   fi
2290
2291   # Canonicalize the list of specified modules.
2292   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
2293
2294   # Determine final module list.
2295   modules="$specified_modules"
2296   func_modules_transitive_closure
2297   if test $verbose -ge 0; then
2298     echo "Module list with included dependencies:"
2299     echo "$modules" | sed -e 's/^/  /'
2300   fi
2301   final_modules="$modules"
2302
2303   # Determine main module list and tests-related module list separately.
2304   # The main module list is the transitive closure of the specified modules,
2305   # ignoring tests modules. Its lib/* sources go into $sourcebase/. If --lgpl
2306   # is specified, it will consist only of LGPLed source.
2307   # The tests-related module list is the transitive closure of the specified
2308   # modules, including tests modules, minus the main module list. Its lib/*
2309   # sources (brought in through dependencies of *-tests modules) go into
2310   # $testsbase/. It may contain GPLed source, even if --lgpl is specified.
2311   # Determine main module list.
2312   saved_inctests="$inctests"
2313   inctests=""
2314   modules="$specified_modules"
2315   func_modules_transitive_closure
2316   main_modules="$modules"
2317   inctests="$saved_inctests"
2318   if test $verbose -ge 1; then
2319     echo "Main module list:"
2320     echo "$main_modules" | sed -e 's/^/  /'
2321   fi
2322   # Determine tests-related module list.
2323   echo "$final_modules" | LC_ALL=C sort -u > "$tmp"/final-modules
2324   testsrelated_modules=`echo "$main_modules" | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/final-modules`
2325   if test $verbose -ge 1; then
2326     echo "Tests-related module list:"
2327     echo "$testsrelated_modules" | sed -e 's/^/  /'
2328   fi
2329
2330   # Add the dummy module to the main module list if needed.
2331   modules="$main_modules"
2332   func_modules_add_dummy
2333   main_modules="$modules"
2334
2335   # Determine whether a $testsbase/libtests.a is needed.
2336   use_libtests=false
2337   for module in $testsrelated_modules; do
2338     func_verify_nontests_module
2339     if test -n "$module"; then
2340       all_files=`func_get_filelist $module`
2341       lib_files=`for f in $all_files; do \
2342                    case $f in \
2343                      lib/*) echo $f ;; \
2344                    esac; \
2345                  done | sed -e 's,^lib/,,'`
2346       if test -n "$lib_files"; then
2347         use_libtests=true
2348         break
2349       fi
2350     fi
2351   done
2352
2353   # Add the dummy module to the tests-related module list if needed.
2354   if $use_libtests; then
2355     modules="$testsrelated_modules"
2356     func_modules_add_dummy
2357     testsrelated_modules="$modules"
2358   fi
2359
2360   # If --lgpl, verify that the licenses of modules are compatible.
2361   if test -n "$lgpl"; then
2362     for module in $main_modules; do
2363       license=`func_get_license $module`
2364       case $license in
2365         'GPLed build tool') ;;
2366         'public domain' | 'unlimited' | 'unmodifiable license text') ;;
2367         *)
2368           case "$lgpl" in
2369             yes | 3)
2370               case $license in
2371                 LGPL | LGPLv2+) ;;
2372                 *) func_fatal_error "incompatible license on module $module: $license" ;;
2373               esac
2374               ;;
2375             2)
2376               case $license in
2377                 LGPLv2+) ;;
2378                 *) func_fatal_error "incompatible license on module $module: $license" ;;
2379               esac
2380               ;;
2381             *) func_fatal_error "invalid value lgpl=$lgpl" ;;
2382           esac
2383           ;;
2384       esac
2385     done
2386   fi
2387
2388   # Show banner notice of every module.
2389   modules="$main_modules"
2390   func_modules_notice
2391
2392   # Determine script to apply to imported library files.
2393   sed_transform_lib_file=
2394   for module in $main_modules; do
2395     if test $module = config-h; then
2396       # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
2397       sed_transform_lib_file=$sed_transform_lib_file'
2398         s/^#ifdef[       ]*HAVE_CONFIG_H[        ]*$/#if 1/
2399       '
2400       break
2401     fi
2402   done
2403   sed_transform_main_lib_file="$sed_transform_lib_file"
2404   if test -n "$do_copyrights"; then
2405     if test -n "$lgpl"; then
2406       # Update license.
2407       case "$lgpl" in
2408         yes | 3)
2409           sed_transform_main_lib_file=$sed_transform_main_lib_file'
2410             s/GNU General/GNU Lesser General/g
2411           '
2412           ;;
2413         2)
2414           sed_transform_main_lib_file=$sed_transform_main_lib_file'
2415             s/GNU General/GNU Lesser General/g
2416             s/version [23]\([ ,]\)/version 2.1\1/g
2417           '
2418           ;;
2419         *) func_fatal_error "invalid value lgpl=$lgpl" ;;
2420       esac
2421     else
2422       # Update license.
2423       sed_transform_main_lib_file=$sed_transform_main_lib_file'
2424         s/GNU Lesser General/GNU General/g
2425         s/GNU Library General/GNU General/g
2426         s/version \(2\|2\.1\)\([ ,]\)/version 3\2/g
2427       '
2428     fi
2429   fi
2430
2431   # Determine script to apply to library files that go into $testsbase/.
2432   sed_transform_testsrelated_lib_file="$sed_transform_lib_file"
2433   if test -n "$do_copyrights"; then
2434     # Update license.
2435     sed_transform_testsrelated_lib_file=$sed_transform_testsrelated_lib_file'
2436       s/GNU Lesser General/GNU General/g
2437       s/GNU Library General/GNU General/g
2438       s/version \(2\|2\.1\)\([ ,]\)/version 3\2/g
2439     '
2440   fi
2441
2442   # Determine the final file lists.
2443   # They must be computed separately, because files in lib/* go into
2444   # $sourcebase/ if they are in the main file list but into $testsbase/
2445   # if they are in the tests-related file list. Furthermore lib/dummy.c
2446   # can be in both.
2447   # Determine final main file list.
2448   modules="$main_modules"
2449   func_modules_to_filelist
2450   main_files="$files"
2451   # Determine final tests-related file list.
2452   modules="$testsrelated_modules"
2453   func_modules_to_filelist
2454   testsrelated_files=`echo "$files" | sed -e 's,^lib/,tests=lib/,'`
2455   # Merge both file lists.
2456   sed_remove_empty_lines='/^$/d'
2457   files=`{ echo "$main_files"; echo "$testsrelated_files"; } | sed -e "$sed_remove_empty_lines" | LC_ALL=C sort -u`
2458   if test $verbose -ge 0; then
2459     echo "File list:"
2460     sed_prettyprint_files='s,^tests=lib/\(.*\)$,lib/\1 -> tests/\1,'
2461     echo "$files" | sed -e "$sed_prettyprint_files" -e 's/^/  /'
2462   fi
2463
2464   test -n "$files" \
2465     || func_fatal_error "refusing to do nothing"
2466
2467   # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
2468   new_files="$files m4/gnulib-tool.m4"
2469   old_files="$cached_files"
2470   if test -f "$destdir"/$m4base/gnulib-tool.m4; then
2471     func_append old_files " m4/gnulib-tool.m4"
2472   fi
2473
2474   sed_rewrite_old_files="\
2475     s,^build-aux/,$auxdir/,
2476     s,^doc/,$cached_docbase/,
2477     s,^lib/,$cached_sourcebase/,
2478     s,^m4/,$cached_m4base/,
2479     s,^tests/,$cached_testsbase/,
2480     s,^tests=lib/,$cached_testsbase/,"
2481   sed_rewrite_new_files="\
2482     s,^build-aux/,$auxdir/,
2483     s,^doc/,$docbase/,
2484     s,^lib/,$sourcebase/,
2485     s,^m4/,$m4base/,
2486     s,^tests/,$testsbase/,
2487     s,^tests=lib/,$testsbase/,"
2488
2489   # Create directories.
2490   { echo "$sourcebase"
2491     echo "$m4base"
2492     if test -n "$pobase"; then
2493       echo "$pobase"
2494     fi
2495     docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
2496     if test -n "$docfiles"; then
2497       echo "$docbase"
2498     fi
2499     if test -n "$inctests"; then
2500       echo "$testsbase"
2501     fi
2502     echo "$auxdir"
2503     for f in $files; do echo $f; done \
2504       | sed -e "$sed_rewrite_new_files" \
2505       | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
2506       | LC_ALL=C sort -u
2507   } > "$tmp"/dirs
2508   { # Rearrange file descriptors. Needed because "while ... done < ..."
2509     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2510     exec 5<&0 < "$tmp"/dirs
2511     while read d; do
2512       if test ! -d "$destdir/$d"; then
2513         if $doit; then
2514           echo "Creating directory $destdir/$d"
2515           mkdir -p "$destdir/$d" || func_fatal_error "failed"
2516         else
2517           echo "Create directory $destdir/$d"
2518         fi
2519       fi
2520     done
2521     exec 0<&5 5<&-
2522   }
2523
2524   # func_dest_tmpfilename file
2525   # determines the name of a temporary file (file is relative to destdir).
2526   # Sets variable:
2527   #   - tmpfile       absolute filename of the temporary file
2528   func_dest_tmpfilename ()
2529   {
2530     if $doit; then
2531       # Put the new contents of $file in a file in the same directory (needed
2532       # to guarantee that an 'mv' to "$destdir/$file" works).
2533       tmpfile="$destdir/$1.tmp"
2534     else
2535       # Put the new contents of $file in a file in a temporary directory
2536       # (because the directory of "$file" might not exist).
2537       tmpfile="$tmp"/`basename "$1"`.tmp
2538     fi
2539   }
2540
2541   # Copy files or make symbolic links. Remove obsolete files.
2542   added_files=''
2543   removed_files=''
2544   delimiter='   '
2545   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2546   # representing the files according to the last gnulib-tool invocation.
2547   for f in $old_files; do echo $f; done \
2548     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
2549     | LC_ALL=C sort \
2550     > "$tmp"/old-files
2551   # Construct a table with 2 columns: rewritten-file-name original-file-name,
2552   # representing the files after this gnulib-tool invocation.
2553   for f in $new_files; do echo $f; done \
2554     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
2555     | LC_ALL=C sort \
2556     > "$tmp"/new-files
2557   # First the files that are in old-files, but not in new-files:
2558   sed_take_first_column='s,'"$delimiter"'.*,,'
2559   for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
2560     # Remove the file. Do nothing if the user already removed it.
2561     if test -f "$destdir/$g" || test -h "$destdir/$g"; then
2562       if $doit; then
2563         echo "Removing file $g (backup in ${g}~)"
2564         mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2565       else
2566         echo "Remove file $g (backup in ${g}~)"
2567       fi
2568       func_append removed_files "$g$nl"
2569     fi
2570   done
2571   # func_add_or_update handles a file that ought to be present afterwards.
2572   # Uses parameters
2573   # - f             the original file name
2574   # - g             the rewritten file name
2575   # - already_present  nonempty if the file already exists, empty otherwise
2576   func_add_or_update ()
2577   {
2578     of="$f"
2579     case "$f" in
2580       tests=lib/*) f=`echo "$f" | sed -e 's,^tests=lib/,lib/,'` ;;
2581     esac
2582     func_dest_tmpfilename "$g"
2583     func_lookup_file "$f"
2584     cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
2585     if test -n "$sed_transform_main_lib_file"; then
2586       case "$of" in
2587         lib/*)
2588           sed -e "$sed_transform_main_lib_file" \
2589             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
2590           ;;
2591       esac
2592     fi
2593     if test -n "$sed_transform_testsrelated_lib_file"; then
2594       case "$of" in
2595         tests=lib/*)
2596           sed -e "$sed_transform_testsrelated_lib_file" \
2597             < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
2598           ;;
2599       esac
2600     fi
2601     if test -f "$destdir/$g"; then
2602       # The file already exists.
2603       if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
2604         : # The file has not changed.
2605       else
2606         # Replace the file.
2607         if $doit; then
2608           if test -n "$already_present"; then
2609             echo "Updating file $g (backup in ${g}~)"
2610           else
2611             echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
2612           fi
2613           mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
2614           if { test -n "$symbolic" \
2615                || { test -n "$lsymbolic" \
2616                     && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2617              && test -z "$lookedup_tmp" \
2618              && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2619             func_ln_if_changed "$lookedup_file" "$destdir/$g"
2620           else
2621             mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2622           fi
2623         else
2624           if test -n "$already_present"; then
2625             echo "Update file $g (backup in ${g}~)"
2626           else
2627             echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
2628           fi
2629         fi
2630       fi
2631     else
2632       # Install the file.
2633       # Don't protest if the file should be there but isn't: it happens
2634       # frequently that developers don't put autogenerated files into CVS.
2635       if $doit; then
2636         echo "Copying file $g"
2637         if { test -n "$symbolic" \
2638              || { test -n "$lsymbolic" \
2639                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
2640            && test -z "$lookedup_tmp" \
2641            && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
2642           func_ln_if_changed "$lookedup_file" "$destdir/$g"
2643         else
2644           mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
2645         fi
2646       else
2647         echo "Copy file $g"
2648       fi
2649       func_append added_files "$g$nl"
2650     fi
2651     rm -f "$tmpfile"
2652   }
2653   # Then the files that are in new-files, but not in old-files:
2654   sed_take_last_column='s,^.*'"$delimiter"',,'
2655   already_present=
2656   LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
2657     | sed -e "$sed_take_last_column" \
2658     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
2659   { # Rearrange file descriptors. Needed because "while ... done < ..."
2660     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2661     exec 5<&0 < "$tmp"/added-files
2662     while read g f; do
2663       func_add_or_update
2664     done
2665     exec 0<&5 5<&-
2666   }
2667   # Then the files that are in new-files and in old-files:
2668   already_present=true
2669   LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
2670     | sed -e "$sed_take_last_column" \
2671     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
2672   { # Rearrange file descriptors. Needed because "while ... done < ..."
2673     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2674     exec 5<&0 < "$tmp"/kept-files
2675     while read g f; do
2676       func_add_or_update
2677     done
2678     exec 0<&5 5<&-
2679   }
2680
2681   # Command-line invocation printed in a comment in generated gnulib-cache.m4.
2682   actioncmd="gnulib-tool --import"
2683   func_append actioncmd " --dir=$destdir"
2684   if test -n "$local_gnulib_dir"; then
2685     func_append actioncmd " --local-dir=$local_gnulib_dir"
2686   fi
2687   func_append actioncmd " --lib=$libname"
2688   func_append actioncmd " --source-base=$sourcebase"
2689   func_append actioncmd " --m4-base=$m4base"
2690   if test -n "$pobase"; then
2691     func_append actioncmd " --po-base=$pobase"
2692   fi
2693   func_append actioncmd " --doc-base=$docbase"
2694   func_append actioncmd " --aux-dir=$auxdir"
2695   if test -n "$inctests"; then
2696     func_append actioncmd " --with-tests"
2697   fi
2698   for module in $avoidlist; do
2699     func_append actioncmd " --avoid=$module"
2700   done
2701   if test -n "$lgpl"; then
2702     if test "$lgpl" = yes; then
2703       func_append actioncmd " --lgpl"
2704     else
2705       func_append actioncmd " --lgpl=$lgpl"
2706     fi
2707   fi
2708   if test -n "$makefile_name"; then
2709     func_append actioncmd " --makefile-name=$makefile_name"
2710   fi
2711   if test "$libtool" = true; then
2712     func_append actioncmd " --libtool"
2713   else
2714     func_append actioncmd " --no-libtool"
2715   fi
2716   func_append actioncmd " --macro-prefix=$macro_prefix"
2717   if test -n "$po_domain"; then
2718     func_append actioncmd " --po-domain=$po_domain"
2719   fi
2720   func_append actioncmd " `echo $specified_modules`"
2721
2722   # Default the makefile name to Makefile.am.
2723   if test -n "$makefile_name"; then
2724     makefile_am=$makefile_name
2725   else
2726     makefile_am=Makefile.am
2727   fi
2728
2729   # Create normal Makefile.ams.
2730   for_test=false
2731
2732   # Create library makefile.
2733   func_dest_tmpfilename $sourcebase/$makefile_am
2734   modules="$main_modules"
2735   func_emit_lib_Makefile_am > "$tmpfile"
2736   if test -f "$destdir"/$sourcebase/$makefile_am; then
2737     if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
2738       rm -f "$tmpfile"
2739     else
2740       if $doit; then
2741         echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2742         mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
2743         mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2744       else
2745         echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
2746         rm -f "$tmpfile"
2747       fi
2748     fi
2749   else
2750     if $doit; then
2751       echo "Creating $sourcebase/$makefile_am"
2752       mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
2753     else
2754       echo "Create $sourcebase/$makefile_am"
2755       rm -f "$tmpfile"
2756     fi
2757     func_append added_files "$sourcebase/$makefile_am$nl"
2758   fi
2759
2760   # Create po/ directory.
2761   if test -n "$pobase"; then
2762     # Create po makefile and auxiliary files.
2763     for file in Makefile.in.in remove-potcdate.sin; do
2764       func_dest_tmpfilename $pobase/$file
2765       func_lookup_file build-aux/po/$file
2766       cat "$lookedup_file" > "$tmpfile"
2767       if test -f "$destdir"/$pobase/$file; then
2768         if cmp "$destdir"/$pobase/$file "$tmpfile" > /dev/null; then
2769           rm -f "$tmpfile"
2770         else
2771           if $doit; then
2772             echo "Updating $pobase/$file (backup in $pobase/$file~)"
2773             mv -f "$destdir"/$pobase/$file "$destdir"/$pobase/$file~
2774             mv -f "$tmpfile" "$destdir"/$pobase/$file
2775           else
2776             echo "Update $pobase/$file (backup in $pobase/$file~)"
2777             rm -f "$tmpfile"
2778           fi
2779         fi
2780       else
2781         if $doit; then
2782           echo "Creating $pobase/$file"
2783           mv -f "$tmpfile" "$destdir"/$pobase/$file
2784         else
2785           echo "Create $pobase/$file"
2786           rm -f "$tmpfile"
2787         fi
2788         func_append added_files "$pobase/$file$nl"
2789       fi
2790     done
2791     # Create po makefile parametrization, part 1.
2792     func_dest_tmpfilename $pobase/Makevars
2793     func_emit_po_Makevars > "$tmpfile"
2794     if test -f "$destdir"/$pobase/Makevars; then
2795       if cmp "$destdir"/$pobase/Makevars "$tmpfile" > /dev/null; then
2796         rm -f "$tmpfile"
2797       else
2798         if $doit; then
2799           echo "Updating $pobase/Makevars (backup in $pobase/Makevars~)"
2800           mv -f "$destdir"/$pobase/Makevars "$destdir"/$pobase/Makevars~
2801           mv -f "$tmpfile" "$destdir"/$pobase/Makevars
2802         else
2803           echo "Update $pobase/Makevars (backup in $pobase/Makevars~)"
2804           rm -f "$tmpfile"
2805         fi
2806       fi
2807     else
2808       if $doit; then
2809         echo "Creating $pobase/Makevars"
2810         mv -f "$tmpfile" "$destdir"/$pobase/Makevars
2811       else
2812         echo "Create $pobase/Makevars"
2813         rm -f "$tmpfile"
2814       fi
2815       func_append added_files "$pobase/Makevars$nl"
2816     fi
2817     # Create po makefile parametrization, part 2.
2818     func_dest_tmpfilename $pobase/POTFILES.in
2819     func_emit_po_POTFILES_in > "$tmpfile"
2820     if test -f "$destdir"/$pobase/POTFILES.in; then
2821       if cmp "$destdir"/$pobase/POTFILES.in "$tmpfile" > /dev/null; then
2822         rm -f "$tmpfile"
2823       else
2824         if $doit; then
2825           echo "Updating $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
2826           mv -f "$destdir"/$pobase/POTFILES.in "$destdir"/$pobase/POTFILES.in~
2827           mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
2828         else
2829           echo "Update $pobase/POTFILES.in (backup in $pobase/POTFILES.in~)"
2830           rm -f "$tmpfile"
2831         fi
2832       fi
2833     else
2834       if $doit; then
2835         echo "Creating $pobase/POTFILES.in"
2836         mv -f "$tmpfile" "$destdir"/$pobase/POTFILES.in
2837       else
2838         echo "Create $pobase/POTFILES.in"
2839         rm -f "$tmpfile"
2840       fi
2841       func_append added_files "$pobase/POTFILES.in$nl"
2842     fi
2843     # Fetch PO files.
2844     TP_URL="http://translationproject.org/latest/"
2845     TP_RSYNC_URI="translationproject.org::tp/latest/"
2846     if $doit; then
2847       echo "Fetching gnulib PO files from $TP_URL"
2848       (cd "$destdir"/$pobase \
2849        && { # Prefer rsync over wget if it is available, since it consumes
2850             # less network bandwidth, due to compression.
2851             if type rsync 2>/dev/null | grep / > /dev/null; then
2852               rsync -Lrtz "${TP_RSYNC_URI}gnulib/" .
2853             else
2854               wget --quiet -r -l1 -nd -np -A.po "${TP_URL}gnulib"
2855             fi
2856           }
2857       )
2858     else
2859       echo "Fetch gnulib PO files from $TP_URL"
2860     fi
2861     # Create po/LINGUAS.
2862     if $doit; then
2863       func_dest_tmpfilename $pobase/LINGUAS
2864       (cd "$destdir"/$pobase \
2865        && { echo '# Set of available languages.'
2866             LC_ALL=C ls -1 *.po | sed -e 's,\.po$,,'
2867           }
2868       ) > "$tmpfile"
2869       if test -f "$destdir"/$pobase/LINGUAS; then
2870         if cmp "$destdir"/$pobase/LINGUAS "$tmpfile" > /dev/null; then
2871           rm -f "$tmpfile"
2872         else
2873           echo "Updating $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
2874           mv -f "$destdir"/$pobase/LINGUAS "$destdir"/$pobase/LINGUAS~
2875           mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
2876         fi
2877       else
2878         echo "Creating $pobase/LINGUAS"
2879         mv -f "$tmpfile" "$destdir"/$pobase/LINGUAS
2880         func_append added_files "$pobase/LINGUAS$nl"
2881       fi
2882     else
2883       if test -f "$destdir"/$pobase/LINGUAS; then
2884         echo "Update $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
2885       else
2886         echo "Create $pobase/LINGUAS"
2887       fi
2888     fi
2889   fi
2890
2891   # Create m4/gnulib-cache.m4.
2892   func_dest_tmpfilename $m4base/gnulib-cache.m4
2893   (
2894     func_emit_copyright_notice
2895     echo "#"
2896     echo "# This file represents the specification of how gnulib-tool is used."
2897     echo "# It acts as a cache: It is written and read by gnulib-tool."
2898     echo "# In projects using CVS, this file is meant to be stored in CVS,"
2899     echo "# like the configure.ac and various Makefile.am files."
2900     echo
2901     echo
2902     echo "# Specification in the form of a command-line invocation:"
2903     echo "#   $actioncmd"
2904     echo
2905     echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
2906     # Store the local_gnulib_dir relative to destdir.
2907     case "$local_gnulib_dir" in
2908       "" | /*)
2909         relative_local_gnulib_dir="$local_gnulib_dir" ;;
2910       * )
2911         case "$destdir" in
2912           /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
2913           *)
2914             # destdir, local_gnulib_dir are both relative.
2915             func_relativize "$destdir" "$local_gnulib_dir"
2916             relative_local_gnulib_dir="$reldir" ;;
2917         esac ;;
2918     esac
2919     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
2920     echo "gl_MODULES(["`echo $specified_modules`"])"
2921     echo "gl_AVOID([$avoidlist])"
2922     echo "gl_SOURCE_BASE([$sourcebase])"
2923     echo "gl_M4_BASE([$m4base])"
2924     echo "gl_PO_BASE([$pobase])"
2925     echo "gl_DOC_BASE([$docbase])"
2926     echo "gl_TESTS_BASE([$testsbase])"
2927     test -z "$inctests" || echo "gl_WITH_TESTS"
2928     echo "gl_LIB([$libname])"
2929     if test -n "$lgpl"; then
2930       if test "$lgpl" = yes; then
2931         echo "gl_LGPL"
2932       else
2933         echo "gl_LGPL([$lgpl])"
2934       fi
2935     fi
2936     echo "gl_MAKEFILE_NAME([$makefile_name])"
2937     if test "$libtool" = true; then
2938       echo "gl_LIBTOOL"
2939     fi
2940     echo "gl_MACRO_PREFIX([$macro_prefix])"
2941     echo "gl_PO_DOMAIN([$po_domain])"
2942   ) > "$tmpfile"
2943   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
2944     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
2945       rm -f "$tmpfile"
2946     else
2947       if $doit; then
2948         echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2949         mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
2950         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2951       else
2952         echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
2953         if false; then
2954           cat "$tmpfile"
2955           echo
2956           echo "# gnulib-cache.m4 ends here"
2957         fi
2958         rm -f "$tmpfile"
2959       fi
2960     fi
2961   else
2962     if $doit; then
2963       echo "Creating $m4base/gnulib-cache.m4"
2964       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
2965     else
2966       echo "Create $m4base/gnulib-cache.m4"
2967       cat "$tmpfile"
2968       rm -f "$tmpfile"
2969     fi
2970   fi
2971
2972   # Create m4/gnulib-comp.m4.
2973   func_dest_tmpfilename $m4base/gnulib-comp.m4
2974   (
2975     echo "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
2976     func_emit_copyright_notice
2977     echo "#"
2978     echo "# This file represents the compiled summary of the specification in"
2979     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
2980     echo "# to be invoked from configure.ac."
2981     echo "# In projects using CVS, this file can be treated like other built files."
2982     echo
2983     echo
2984     echo "# This macro should be invoked from $configure_ac, in the section"
2985     echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
2986     echo "# any checks for libraries, header files, types and library functions."
2987     echo "AC_DEFUN([${macro_prefix}_EARLY],"
2988     echo "["
2989     echo "  m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2990     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
2991     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
2992     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
2993     echo "  AC_REQUIRE([AC_PROG_RANLIB])"
2994     if test -n "$uses_subdirs"; then
2995       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
2996     fi
2997     if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
2998       echo "  AC_REQUIRE([AC_GNU_SOURCE])"
2999     fi
3000     for module in $final_modules; do
3001       func_verify_module
3002       if test -n "$module"; then
3003         func_get_autoconf_early_snippet "$module"
3004       fi
3005     done \
3006       | sed -e '/^$/d;' -e 's/^/  /'
3007     echo "])"
3008     echo
3009     echo "# This macro should be invoked from $configure_ac, in the section"
3010     echo "# \"Check for header files, types and library functions\"."
3011     echo "AC_DEFUN([${macro_prefix}_INIT],"
3012     echo "["
3013     if test "$libtool" = true; then
3014       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3015       echo "  gl_cond_libtool=true"
3016     else
3017       echo "  AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3018       echo "  gl_cond_libtool=false"
3019       echo "  gl_libdeps="
3020       echo "  gl_ltlibdeps="
3021     fi
3022     if test "$auxdir" != "build-aux"; then
3023       sed_replace_build_aux='
3024         :a
3025         /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3026           s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3027           ba
3028         }'
3029     else
3030       sed_replace_build_aux=
3031     fi
3032     func_emit_initmacro_start $macro_prefix
3033     echo "  gl_source_base='$sourcebase'"
3034     for module in $main_modules; do
3035       func_verify_module
3036       if test -n "$module"; then
3037         func_get_autoconf_snippet "$module" \
3038           | sed -e '/^$/d;' -e 's/^/  /' \
3039                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
3040                 -e "$sed_replace_build_aux"
3041         if test "$module" = 'alloca' && test "$libtool" = true; then
3042           echo 'changequote(,)dnl'
3043           echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
3044           echo 'changequote([, ])dnl'
3045           echo 'AC_SUBST([LTALLOCA])'
3046         fi
3047       fi
3048     done
3049     func_emit_initmacro_end $macro_prefix
3050     echo "  gltests_libdeps="
3051     echo "  gltests_ltlibdeps="
3052     func_emit_initmacro_start ${macro_prefix}tests
3053     echo "  gl_source_base='$testsbase'"
3054     for module in $testsrelated_modules; do
3055       func_verify_module
3056       if test -n "$module"; then
3057         func_get_autoconf_snippet "$module" \
3058           | sed -e '/^$/d;' -e 's/^/  /' \
3059                 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
3060                 -e "$sed_replace_build_aux" \
3061                 -e 's/\$gl_cond_libtool/false/g' \
3062                 -e 's/gl_libdeps/gltests_libdeps/g' \
3063                 -e 's/gl_ltlibdeps/gltests_ltlibdeps/g'
3064       fi
3065     done
3066     func_emit_initmacro_end ${macro_prefix}tests
3067     # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3068     # created using libtool, because libtool already handles the dependencies.
3069     if test "$libtool" != true; then
3070       libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3071       echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3072       echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3073       echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3074       echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3075     fi
3076     if $use_libtests; then
3077       echo "  LIBTESTS_LIBDEPS=\"\$gltests_libdeps\""
3078       echo "  AC_SUBST([LIBTESTS_LIBDEPS])"
3079     fi
3080     echo "])"
3081     func_emit_initmacro_done $macro_prefix $sourcebase
3082     func_emit_initmacro_done ${macro_prefix}tests $testsbase
3083     echo
3084     echo "# This macro records the list of files which have been installed by"
3085     echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
3086     echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
3087     echo "$files" | sed -e 's,^,  ,'
3088     echo "])"
3089   ) > "$tmpfile"
3090   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
3091     if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
3092       rm -f "$tmpfile"
3093     else
3094       if $doit; then
3095         echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
3096         mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
3097         mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
3098       else
3099         echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
3100         if false; then
3101           cat "$tmpfile"
3102           echo
3103           echo "# gnulib-comp.m4 ends here"
3104         fi
3105         rm -f "$tmpfile"
3106       fi
3107     fi
3108   else
3109     if $doit; then
3110       echo "Creating $m4base/gnulib-comp.m4"
3111       mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
3112     else
3113       echo "Create $m4base/gnulib-comp.m4"
3114       cat "$tmpfile"
3115       rm -f "$tmpfile"
3116     fi
3117   fi
3118
3119   if test -n "$inctests"; then
3120     # Create tests makefile.
3121     func_dest_tmpfilename $testsbase/$makefile_am
3122     modules="$testsrelated_modules"
3123     func_emit_tests_Makefile_am > "$tmpfile"
3124     if test -f "$destdir"/$testsbase/$makefile_am; then
3125       if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
3126         rm -f "$tmpfile"
3127       else
3128         if $doit; then
3129           echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
3130           mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
3131           mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
3132         else
3133           echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
3134           rm -f "$tmpfile"
3135         fi
3136       fi
3137     else
3138       if $doit; then
3139         echo "Creating $testsbase/$makefile_am"
3140         mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
3141       else
3142         echo "Create $testsbase/$makefile_am"
3143         rm -f "$tmpfile"
3144       fi
3145     func_append added_files "$testsbase/$makefile_am$nl"
3146     fi
3147   fi
3148
3149   # Update the .cvsignore and .gitignore files.
3150   { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
3151     echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
3152   } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
3153   { # Rearrange file descriptors. Needed because "while ... done < ..."
3154     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3155     exec 5<&0 < "$tmp"/fileset-changes
3156     func_update_ignorelist ()
3157     {
3158       ignore="$1"
3159       if test -f "$destdir/$dir$ignore"; then
3160         if test -n "$dir_added" || test -n "$dir_removed"; then
3161           LC_ALL=C sort "$destdir/$dir$ignore" > "$tmp"/ignore
3162           echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
3163             | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-added
3164           echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
3165             | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-removed
3166           if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
3167             if $doit; then
3168               echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
3169               mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
3170               sed -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed > "$tmp"/sed-ignore-removed
3171               cat "$destdir/$dir$ignore"~ "$tmp"/ignore-added \
3172                 | sed -f "$tmp"/sed-ignore-removed \
3173                 > "$destdir/$dir$ignore"
3174             else
3175               echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
3176             fi
3177           fi
3178         fi
3179       else
3180         if test -n "$dir_added"; then
3181           if $doit; then
3182             echo "Creating $destdir/$dir$ignore"
3183             {
3184               if test "$ignore" = .cvsignore; then
3185                 echo ".deps"
3186                 # Automake generates Makefile rules that create .dirstamp files.
3187                 echo ".dirstamp"
3188               fi
3189               echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u
3190             } > "$destdir/$dir$ignore"
3191           else
3192             echo "Create $destdir/$dir$ignore"
3193           fi
3194         fi
3195       fi
3196     }
3197     func_done_dir ()
3198     {
3199       dir="$1"
3200       dir_added="$2"
3201       dir_removed="$3"
3202       if test -d "$destdir/CVS" || test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
3203         func_update_ignorelist .cvsignore
3204       fi
3205       if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
3206         func_update_ignorelist .gitignore
3207       fi
3208     }
3209     last_dir=
3210     last_dir_added=
3211     last_dir_removed=
3212     while read line; do
3213       # Why not ''read next_dir op file'' ? Because the dir column can be empty.
3214       next_dir=`echo "$line" | sed -e 's,|.*,,'`
3215       op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
3216       file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
3217       if test "$next_dir" != "$last_dir"; then
3218         func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
3219         last_dir="$next_dir"
3220         last_dir_added=
3221         last_dir_removed=
3222       fi
3223       case $op in
3224         A) func_append last_dir_added "$file$nl";;
3225         R) func_append last_dir_removed "$file$nl";;
3226       esac
3227     done
3228     func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
3229     exec 0<&5 5<&-
3230   }
3231
3232   echo "Finished."
3233   echo
3234   echo "You may need to add #include directives for the following .h files."
3235   # Intersect $specified_modules and $main_modules
3236   # (since $specified_modules is not necessarily of subset of $main_modules
3237   # - some may have been skipped through --avoid, and since the elements of
3238   # $main_modules but not in $specified_modules can go away without explicit
3239   # notice - through changes in the module dependencies).
3240   echo "$specified_modules" > "$tmp"/modules1 # a sorted list, one module per line
3241   echo "$main_modules" > "$tmp"/modules2 # also a sorted list, one module per line
3242   # First the #include <...> directives without #ifs, sorted for convenience,
3243   # then the #include "..." directives without #ifs, sorted for convenience,
3244   # then the #include directives that are surrounded by #ifs. Not sorted.
3245   for module in `LC_ALL=C join "$tmp"/modules1 "$tmp"/modules2`; do
3246     include_directive=`func_get_include_directive "$module"`
3247     case "$nl$include_directive" in
3248       *"$nl#if"*)
3249         echo "$include_directive" 1>&5
3250         ;;
3251       *)
3252         echo "$include_directive" | grep -v 'include "' 1>&6
3253         echo "$include_directive" | grep 'include "' 1>&7
3254         ;;
3255     esac
3256   done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
3257   (
3258    LC_ALL=C sort -u "$tmp"/include-angles
3259    LC_ALL=C sort -u "$tmp"/include-quotes
3260    cat "$tmp"/include-if
3261   ) | sed -e '/^$/d' -e 's/^/  /'
3262   rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
3263
3264   for module in $main_modules; do
3265     func_get_link_directive "$module"
3266   done \
3267     | LC_ALL=C sort -u | sed -e '/^$/d' -e 's/^/  /' > "$tmp"/link
3268   if test `wc -l < "$tmp"/link` != 0; then
3269     echo
3270     echo "You may need to use the following Makefile variables when linking."
3271     echo "Use them in <program>_LDADD when linking a program, or"
3272     echo "in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library."
3273     cat "$tmp"/link
3274   fi
3275   rm -f "$tmp"/link
3276
3277   echo
3278   echo "Don't forget to"
3279   if test "$makefile_am" = Makefile.am; then
3280     echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
3281   else
3282     echo "  - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
3283   fi
3284   if test -n "$pobase"; then
3285     echo "  - add \"$pobase/Makefile.in\" to AC_CONFIG_FILES in $configure_ac,"
3286   fi
3287   if test -n "$inctests"; then
3288     if test "$makefile_am" = Makefile.am; then
3289       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
3290     else
3291       echo "  - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
3292     fi
3293   fi
3294   if test "$makefile_am" = Makefile.am; then
3295     sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
3296     sourcebase_base=`basename "$sourcebase"`
3297     echo "  - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
3298   fi
3299   if test -n "$pobase"; then
3300     pobase_dir=`echo "$pobase" | sed -n -e 's,/[^/]*$,/,p'`
3301     pobase_base=`basename "$pobase"`
3302     echo "  - mention \"${pobase_base}\" in SUBDIRS in ${pobase_dir}Makefile.am,"
3303   fi
3304   if test -n "$inctests"; then
3305     if test "$makefile_am" = Makefile.am; then
3306       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
3307       testsbase_base=`basename "$testsbase"`
3308       echo "  - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
3309     fi
3310   fi
3311   echo "  - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
3312   echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
3313   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
3314 }
3315
3316 # func_create_testdir testdir modules
3317 # Input:
3318 # - local_gnulib_dir  from --local-dir
3319 # - auxdir          directory relative to destdir where to place build aux files
3320 func_create_testdir ()
3321 {
3322   testdir="$1"
3323   modules="$2"
3324   if test -z "$modules"; then
3325     # All modules together.
3326     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
3327     # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
3328     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
3329     modules=`func_all_modules`
3330     modules=`for m in $modules; do case $m in config-h | fnmatch-posix | ftruncate | mountlist) ;; *) echo $m;; esac; done`
3331   fi
3332   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
3333
3334   # Check that the license of every module is consistent with the license of
3335   # its dependencies.
3336   saved_modules="$modules"
3337   saved_inctests="$inctests"
3338   # When computing transitive closures, don't consider $module to depend on
3339   # $module-tests. Need this becauses tests are implicitly GPL and may depend
3340   # on GPL modules - therefore we don't want a warning in this case.
3341   inctests=""
3342   for requested_module in $saved_modules; do
3343     requested_license=`func_get_license "$requested_module"`
3344     if test "$requested_license" != GPL; then
3345       # Here we use func_modules_transitive_closure, not just
3346       # func_get_dependencies, so that we also detect weird situations like
3347       # an LGPL module which depends on a GPLed build tool module which depends
3348       # on a GPL module.
3349       modules="$requested_module"
3350       func_modules_transitive_closure
3351       for module in $modules; do
3352         license=`func_get_license "$module"`
3353         case "$license" in
3354           'GPLed build tool') ;;
3355           'public domain' | 'unlimited' | 'unmodifiable license text') ;;
3356           *)
3357             case "$requested_license" in
3358               GPLv2+)
3359                 case "$license" in
3360                   GPLv2+ | LGPLv2+) ;;
3361                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3362                 esac
3363                 ;;
3364               LGPL)
3365                 case "$license" in
3366                   LGPL | LGPLv2+) ;;
3367                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3368                 esac
3369                 ;;
3370               LGPLv2+)
3371                 case "$license" in
3372                   LGPLv2+) ;;
3373                   *) echo "warning: module $requested_module depends on a module with an incompatible license: $module" 1>&2 ;;
3374                 esac
3375                 ;;
3376             esac
3377             ;;
3378         esac
3379       done
3380     fi
3381   done
3382   modules="$saved_modules"
3383   inctests="$saved_inctests"
3384
3385   # Subdirectory names.
3386   sourcebase=gllib
3387   m4base=glm4
3388   pobase=
3389   docbase=gldoc
3390   testsbase=gltests
3391   macro_prefix=gl
3392   po_domain=
3393
3394   # Determine final module list.
3395   func_modules_transitive_closure
3396   if test $verbose -ge 0; then
3397     echo "Module list with included dependencies:"
3398     echo "$modules" | sed -e 's/^/  /'
3399   fi
3400
3401   # Add the dummy module if needed.
3402   func_modules_add_dummy
3403
3404   # Show banner notice of every module.
3405   func_modules_notice
3406
3407   # Determine final file list.
3408   func_modules_to_filelist
3409   if test $verbose -ge 0; then
3410     echo "File list:"
3411     echo "$files" | sed -e 's/^/  /'
3412   fi
3413
3414   sed_rewrite_files="\
3415     s,^build-aux/,$auxdir/,
3416     s,^doc/,$docbase/,
3417     s,^lib/,$sourcebase/,
3418     s,^m4/,$m4base/,
3419     s,^tests/,$testsbase/,"
3420
3421   # Create directories.
3422   for f in $files; do echo $f; done \
3423     | sed -e "$sed_rewrite_files" \
3424     | sed -n -e 's,^\(.*\)/[^/]*,\1,p' \
3425     | LC_ALL=C sort -u \
3426     > "$tmp"/dirs
3427   { # Rearrange file descriptors. Needed because "while ... done < ..."
3428     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3429     exec 5<&0 < "$tmp"/dirs
3430     while read d; do
3431       mkdir -p "$testdir/$d"
3432     done
3433     exec 0<&5 5<&-
3434   }
3435
3436   # Copy files or make symbolic links.
3437   delimiter='   '
3438   for f in $files; do echo $f; done \
3439     | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
3440     | LC_ALL=C sort \
3441     > "$tmp"/files
3442   { # Rearrange file descriptors. Needed because "while ... done < ..."
3443     # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
3444     exec 5<&0 < "$tmp"/files
3445     while read g f; do
3446       func_lookup_file "$f"
3447       if test -n "$lookedup_tmp"; then
3448         cp -p "$lookedup_file" "$testdir/$g"
3449       else
3450         ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
3451         if { test -n "$symbolic" \
3452              || { test -n "$lsymbolic" \
3453                   && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; }; then
3454           func_ln "$lookedup_file" "$testdir/$g"
3455         else
3456           cp -p "$lookedup_file" "$testdir/$g"
3457         fi
3458       fi
3459     done
3460     exec 0<&5 5<&-
3461   }
3462
3463   # Create Makefile.ams that are for testing.
3464   for_test=true
3465
3466   # Create $sourcebase/Makefile.am.
3467   mkdir -p "$testdir/$sourcebase"
3468   func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
3469   any_uses_subdirs="$uses_subdirs"
3470
3471   # Create $m4base/Makefile.am.
3472   mkdir -p "$testdir/$m4base"
3473   (echo "## Process this file with automake to produce Makefile.in."
3474    echo
3475    echo "EXTRA_DIST ="
3476    for f in $files; do
3477      case "$f" in
3478        m4/* )
3479          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
3480      esac
3481    done
3482   ) > "$testdir/$m4base/Makefile.am"
3483
3484   subdirs="$sourcebase $m4base"
3485   subdirs_with_configure_ac=""
3486
3487   if false && test -f "$testdir"/$m4base/gettext.m4; then
3488     # Avoid stupid error message from automake:
3489     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
3490     mkdir -p "$testdir/po"
3491     (echo "## Process this file with automake to produce Makefile.in."
3492     ) > "$testdir/po/Makefile.am"
3493     func_append subdirs " po"
3494   fi
3495
3496   if test -n "$inctests"; then
3497     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
3498     # Viewed from the $testsbase subdirectory, $auxdir is different.
3499     saved_auxdir="$auxdir"
3500     auxdir=`echo "$testsbase/"|sed 's%[^/][^/]*//*%../%g'`"$auxdir"
3501     # Create $testsbase/Makefile.am.
3502     use_libtests=false
3503     func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
3504     any_uses_subdirs="$any_uses_subdirs$uses_subdirs"
3505     # Create $testsbase/configure.ac.
3506     (echo "# Process this file with autoconf to produce a configure script."
3507      echo "AC_INIT([dummy], [0])"
3508      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3509      echo "AM_INIT_AUTOMAKE"
3510      echo
3511      echo "AM_CONFIG_HEADER([config.h])"
3512      echo
3513      echo "AC_PROG_CC"
3514      echo "AC_PROG_INSTALL"
3515      echo "AC_PROG_MAKE_SET"
3516      echo "AC_PROG_RANLIB"
3517      echo
3518      if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
3519        echo "AC_GNU_SOURCE"
3520        echo
3521      fi
3522      for module in $modules; do
3523        func_verify_module
3524        if test -n "$module"; then
3525          func_get_autoconf_early_snippet "$module"
3526        fi
3527      done \
3528        | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
3529      if test "$libtool" = true; then
3530        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3531        echo "gl_cond_libtool=true"
3532      else
3533        echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3534        echo "gl_cond_libtool=false"
3535        echo "gl_libdeps="
3536        echo "gl_ltlibdeps="
3537      fi
3538      # Wrap the set of autoconf snippets into an autoconf macro that is then
3539      # invoked. This is needed because autoconf does not support AC_REQUIRE
3540      # at the top level:
3541      #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
3542      # but we want the AC_REQUIRE to have its normal meaning (provide one
3543      # expansion of the required macro before the current point, and only one
3544      # expansion total).
3545      echo "AC_DEFUN([gl_INIT], ["
3546      sed_replace_build_aux='
3547        :a
3548        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3549          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3550          ba
3551        }'
3552      func_emit_initmacro_start $macro_prefix
3553      # We don't have explicit ordering constraints between the various
3554      # autoconf snippets. It's cleanest to put those of the library before
3555      # those of the tests.
3556      echo "gl_source_base='../$sourcebase'"
3557      for module in $modules; do
3558        func_verify_nontests_module
3559        if test -n "$module"; then
3560          func_get_autoconf_snippet "$module" \
3561            | sed -e "$sed_replace_build_aux"
3562        fi
3563      done
3564      echo "gl_source_base='.'"
3565      for module in $modules; do
3566        func_verify_tests_module
3567        if test -n "$module"; then
3568          func_get_autoconf_snippet "$module" \
3569            | sed -e "$sed_replace_build_aux"
3570        fi
3571      done
3572      func_emit_initmacro_end $macro_prefix
3573      # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3574      # created using libtool, because libtool already handles the dependencies.
3575      if test "$libtool" != true; then
3576        libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3577        echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3578        echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3579        echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3580        echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3581      fi
3582      echo "])"
3583      func_emit_initmacro_done $macro_prefix $sourcebase # FIXME use $sourcebase or $testsbase?
3584      echo
3585      echo "gl_INIT"
3586      echo
3587      # Usually $testsbase/config.h will be a superset of config.h. Verify this
3588      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
3589      echo "AH_TOP([#include \"../config.h\"])"
3590      echo
3591      echo "AC_OUTPUT([Makefile])"
3592     ) > "$testdir/$testsbase/configure.ac"
3593     auxdir="$saved_auxdir"
3594     func_append subdirs " $testsbase"
3595     subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
3596   fi
3597
3598   # Create Makefile.am.
3599   (echo "## Process this file with automake to produce Makefile.in."
3600    echo
3601    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
3602    echo
3603    echo "SUBDIRS = $subdirs"
3604    echo
3605    echo "ACLOCAL_AMFLAGS = -I $m4base"
3606   ) > "$testdir/Makefile.am"
3607
3608   # Create configure.ac.
3609   (echo "# Process this file with autoconf to produce a configure script."
3610    echo "AC_INIT([dummy], [0])"
3611    if test "$auxdir" != "."; then
3612      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3613    fi
3614    echo "AM_INIT_AUTOMAKE"
3615    echo
3616    echo "AM_CONFIG_HEADER([config.h])"
3617    echo
3618    echo "AC_PROG_CC"
3619    echo "AC_PROG_INSTALL"
3620    echo "AC_PROG_MAKE_SET"
3621    echo
3622    echo "# For autobuild."
3623    echo "AC_CANONICAL_BUILD"
3624    echo "AC_CANONICAL_HOST"
3625    echo
3626    echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
3627    echo "m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
3628    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
3629    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
3630    echo
3631    echo "AC_PROG_RANLIB"
3632    echo
3633    if test -n "$any_uses_subdirs"; then
3634      echo "AM_PROG_CC_C_O"
3635      echo
3636    fi
3637    if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
3638      echo "AC_GNU_SOURCE"
3639      echo
3640    fi
3641    for module in $modules; do
3642      func_verify_nontests_module
3643      if test -n "$module"; then
3644        func_get_autoconf_early_snippet "$module"
3645      fi
3646    done \
3647      | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
3648    if test "$libtool" = true; then
3649      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
3650      echo "gl_cond_libtool=true"
3651    else
3652      echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
3653      echo "gl_cond_libtool=false"
3654      echo "gl_libdeps="
3655      echo "gl_ltlibdeps="
3656    fi
3657    # Wrap the set of autoconf snippets into an autoconf macro that is then
3658    # invoked. This is needed because autoconf does not support AC_REQUIRE
3659    # at the top level:
3660    #   error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
3661    # but we want the AC_REQUIRE to have its normal meaning (provide one
3662    # expansion of the required macro before the current point, and only one
3663    # expansion total).
3664    echo "AC_DEFUN([gl_INIT], ["
3665    if test "$auxdir" != "build-aux"; then
3666      sed_replace_build_aux='
3667        :a
3668        /AC_CONFIG_FILES(.*:build-aux\/.*)/{
3669          s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
3670          ba
3671        }'
3672    else
3673      sed_replace_build_aux=
3674    fi
3675    func_emit_initmacro_start $macro_prefix
3676    echo "gl_source_base='$sourcebase'"
3677    for module in $modules; do
3678      func_verify_nontests_module
3679      if test -n "$module"; then
3680        func_get_autoconf_snippet "$module" \
3681          | sed -e "$sed_replace_build_aux"
3682      fi
3683    done
3684    func_emit_initmacro_end $macro_prefix
3685    # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
3686    # created using libtool, because libtool already handles the dependencies.
3687    if test "$libtool" != true; then
3688      libname_upper=`echo "$libname" | LC_ALL=C tr 'a-z-' 'A-Z_'`
3689      echo "  ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
3690      echo "  AC_SUBST([${libname_upper}_LIBDEPS])"
3691      echo "  ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
3692      echo "  AC_SUBST([${libname_upper}_LTLIBDEPS])"
3693    fi
3694    echo "])"
3695    func_emit_initmacro_done $macro_prefix $sourcebase
3696    echo
3697    echo "gl_INIT"
3698    echo
3699    if test -n "$subdirs_with_configure_ac"; then
3700      echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
3701    fi
3702    makefiles="Makefile"
3703    for d in $subdirs; do
3704      # For subdirs that have a configure.ac by their own, it's the subdir's
3705      # configure.ac which creates the subdir's Makefile.am, not this one.
3706      case " $subdirs_with_configure_ac " in
3707        *" $d "*) ;;
3708        *) func_append makefiles " $d/Makefile" ;;
3709      esac
3710    done
3711    echo "AC_OUTPUT([$makefiles])"
3712   ) > "$testdir/configure.ac"
3713
3714   # Create autogenerated files.
3715   (cd "$testdir"
3716    # Do not use "${AUTORECONF} --force --install", because it may invoke
3717    # autopoint, which brings in older versions of some of our .m4 files.
3718    if test -f $m4base/gettext.m4; then
3719      func_execute_command ${AUTOPOINT} --force || func_exit 1
3720      for f in $m4base/*.m4~; do
3721        mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3722      done
3723    fi
3724    func_execute_command ${ACLOCAL} -I $m4base || func_exit 1
3725    if ! test -d build-aux; then
3726      func_execute_command mkdir build-aux || func_exit 1
3727    fi
3728    func_execute_command ${AUTOCONF} || func_exit 1
3729    func_execute_command ${AUTOHEADER} || func_exit 1
3730    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
3731   ) || func_exit 1
3732   if test -n "$inctests"; then
3733     # Create autogenerated files.
3734     (cd "$testdir/$testsbase" || func_exit 1
3735      # Do not use "${AUTORECONF} --force --install", because it may invoke
3736      # autopoint, which brings in older versions of some of our .m4 files.
3737      if test -f ../$m4base/gettext.m4; then
3738        func_execute_command ${AUTOPOINT} --force || func_exit 1
3739        for f in ../$m4base/*.m4~; do
3740          mv -f $f `echo $f | sed -e 's,~$,,'` || func_exit 1
3741        done
3742      fi
3743      func_execute_command ${ACLOCAL} -I ../$m4base || func_exit 1
3744      if ! test -d ../build-aux; then
3745        func_execute_command mkdir ../build-aux
3746      fi
3747      func_execute_command ${AUTOCONF} || func_exit 1
3748      func_execute_command ${AUTOHEADER} || func_exit 1
3749      func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
3750     ) || func_exit 1
3751   fi
3752   # Need to run configure and make once, to create built files that are to be
3753   # distributed (such as getdate.c).
3754   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
3755   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3756                  | sed -n -e 's,^CLEANFILES[     ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
3757   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
3758   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
3759   # such $(FOO_H) because they don't refer to distributed files.
3760   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
3761   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
3762                  | sed -n -e 's,^BUILT_SOURCES[  ]*+=\([^#]*\).*$,\1,p' \
3763                  | sed -e "$sed_remove_make_variables"`
3764   distributed_built_sources=`for file in $built_sources; do
3765                                case "$cleaned_files" in
3766                                  *" "$file" "*) ;;
3767                                  *) echo $file ;;
3768                                esac;
3769                              done`
3770   if test -n "$distributed_built_sources"; then
3771     (cd "$testdir"
3772      ./configure || func_exit 1
3773        cd "$sourcebase"
3774        echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
3775        make built_sources || func_exit 1
3776        cd ..
3777      make distclean || func_exit 1
3778     ) || func_exit 1
3779   fi
3780 }
3781
3782 # func_create_megatestdir megatestdir allmodules
3783 # Input:
3784 # - local_gnulib_dir  from --local-dir
3785 # - auxdir          directory relative to destdir where to place build aux files
3786 func_create_megatestdir ()
3787 {
3788   megatestdir="$1"
3789   allmodules="$2"
3790   if test -z "$allmodules"; then
3791     allmodules=`func_all_modules`
3792   fi
3793
3794   megasubdirs=
3795   # First, all modules one by one.
3796   for onemodule in $allmodules; do
3797     func_create_testdir "$megatestdir/$onemodule" $onemodule
3798     func_append megasubdirs "$onemodule "
3799   done
3800   # Then, all modules all together.
3801   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
3802   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
3803   allmodules=`for m in $allmodules; do if test $m != config-h && test $m != fnmatch-posix; then echo $m; fi; done`
3804   func_create_testdir "$megatestdir/ALL" "$allmodules"
3805   func_append megasubdirs "ALL"
3806
3807   # Create autobuild.
3808   cvsdate=`if test -f "$gnulib_dir/CVS/Entries"; then \
3809              vc_witness="$gnulib_dir/CVS/Entries"; \
3810            else \
3811              vc_witness="$gnulib_dir/.git/refs/heads/master"; \
3812            fi; \
3813            sh "$gnulib_dir/build-aux/mdate-sh" "$vc_witness" \
3814              | sed -e 's,January,01,'   -e 's,Jan,01,' \
3815                    -e 's,February,02,'  -e 's,Feb,02,' \
3816                    -e 's,March,03,'     -e 's,Mar,03,' \
3817                    -e 's,April,04,'     -e 's,Apr,04,' \
3818                    -e 's,May,05,'                      \
3819                    -e 's,June,06,'      -e 's,Jun,06,' \
3820                    -e 's,July,07,'      -e 's,Jul,07,' \
3821                    -e 's,August,08,'    -e 's,Aug,08,' \
3822                    -e 's,September,09,' -e 's,Sep,09,' \
3823                    -e 's,October,10,'   -e 's,Oct,10,' \
3824                    -e 's,November,11,'  -e 's,Nov,11,' \
3825                    -e 's,December,12,'  -e 's,Dec,12,' \
3826                    -e 's,^,00,' -e 's,^[0-9]*\([0-9][0-9] \),\1,' \
3827                    -e 's,^\([0-9]*\) \([0-9]*\) \([0-9]*\),\3\2\1,'`
3828   (echo '#!/bin/sh'
3829    echo "CVSDATE=$cvsdate"
3830    echo "test -d logs || mkdir logs"
3831    echo "for module in $megasubdirs; do"
3832    echo "  echo \"Working on module \$module...\""
3833    echo "  safemodule=\`echo \$module | sed -e 's|/|-|g'\`"
3834    echo "  (echo \"To: gnulib@autobuild.josefsson.org\""
3835    echo "   echo"
3836    echo "   set -x"
3837    echo "   : autobuild project... \$module"
3838    echo "   : autobuild revision... cvs-\$CVSDATE-000000"
3839    echo "   : autobuild timestamp... \`date \"+%Y%m%d-%H%M%S\"\`"
3840    echo "   : autobuild hostname... \`hostname\`"
3841    echo "   cd \$module && ./configure \$CONFIGURE_OPTIONS && make && make check && make distclean"
3842    echo "   echo rc=\$?"
3843    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
3844    echo "done"
3845   ) > "$megatestdir/do-autobuild"
3846   chmod a+x "$megatestdir/do-autobuild"
3847
3848   # Create Makefile.am.
3849   (echo "## Process this file with automake to produce Makefile.in."
3850    echo
3851    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
3852    echo
3853    echo "SUBDIRS = $megasubdirs"
3854    echo
3855    echo "EXTRA_DIST = do-autobuild"
3856   ) > "$megatestdir/Makefile.am"
3857
3858   # Create configure.ac.
3859   (echo "# Process this file with autoconf to produce a configure script."
3860    echo "AC_INIT([dummy], [0])"
3861    if test "$auxdir" != "."; then
3862      echo "AC_CONFIG_AUX_DIR([$auxdir])"
3863    fi
3864    echo "AM_INIT_AUTOMAKE"
3865    echo
3866    echo "AC_PROG_MAKE_SET"
3867    echo
3868    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
3869    echo "AC_OUTPUT([Makefile])"
3870   ) > "$megatestdir/configure.ac"
3871
3872   # Create autogenerated files.
3873   (cd "$megatestdir"
3874    # Do not use "${AUTORECONF} --install", because autoreconf operates
3875    # recursively, but the subdirectories are already finished, therefore
3876    # calling autoreconf here would only waste lots of CPU time.
3877    func_execute_command ${ACLOCAL} || func_exit 1
3878    func_execute_command mkdir build-aux
3879    func_execute_command ${AUTOCONF} || func_exit 1
3880    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
3881   ) || func_exit 1
3882 }
3883
3884 case $mode in
3885   "" )
3886     func_fatal_error "no mode specified" ;;
3887
3888   list )
3889     func_all_modules
3890     ;;
3891
3892   import | update )
3893
3894     # Where to import.
3895     if test -z "$destdir"; then
3896       destdir=.
3897     fi
3898     test -d "$destdir" \
3899       || func_fatal_error "destination directory does not exist: $destdir"
3900
3901     # Prefer configure.ac to configure.in.
3902     if test -f "$destdir"/configure.ac; then
3903       configure_ac="$destdir/configure.ac"
3904     else
3905       if test -f "$destdir"/configure.in; then
3906         configure_ac="$destdir/configure.in"
3907       else
3908         func_fatal_error "cannot find $destdir/configure.ac"
3909       fi
3910     fi
3911
3912     # Analyze configure.ac.
3913     guessed_auxdir="."
3914     guessed_libtool=false
3915     my_sed_traces='
3916       s,#.*$,,
3917       s,^dnl .*$,,
3918       s, dnl .*$,,
3919       /AC_CONFIG_AUX_DIR/ {
3920         s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
3921       }
3922       /A[CM]_PROG_LIBTOOL/ {
3923         s,^.*$,guessed_libtool=true,p
3924       }'
3925     eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
3926
3927     if test -z "$auxdir"; then
3928       auxdir="$guessed_auxdir"
3929     fi
3930
3931     # Determine where to apply func_import.
3932     if test -n "$m4base"; then
3933       # Apply func_import to a particular gnulib directory.
3934       # Any number of additional modules can be given.
3935       if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
3936         # First use of gnulib in the given m4base.
3937         test -n "$supplied_libname" || supplied_libname=true
3938         test -n "$sourcebase" || sourcebase="lib"
3939         test -n "$docbase" || docbase="doc"
3940         test -n "$testsbase" || testsbase="tests"
3941         test -n "$macro_prefix" || macro_prefix="gl"
3942       fi
3943       func_import "$*"
3944     else
3945       # Apply func_import to all gnulib directories.
3946       # To get this list of directories, look at Makefile.am. (Not at
3947       # configure, because it may be omitted from CVS. Also, don't run
3948       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
3949       m4dirs=
3950       m4dirs_count=0
3951       if test -f "$destdir"/Makefile.am; then
3952         aclocal_amflags=`sed -n 's/^ACLOCAL_AMFLAGS[     ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
3953         m4dir_is_next=
3954         for arg in $aclocal_amflags; do
3955           if test -n "$m4dir_is_next"; then
3956             # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
3957             case "$arg" in
3958               /*) ;;
3959               *)
3960                 if test -f "$destdir/$arg"/gnulib-cache.m4; then
3961                   func_append m4dirs " $arg"
3962                   m4dirs_count=`expr $m4dirs_count + 1`
3963                 fi
3964                 ;;
3965             esac
3966             m4dir_is_next=
3967           else
3968             if test "X$arg" = "X-I"; then
3969               m4dir_is_next=yes
3970             else
3971               m4dir_is_next=
3972             fi
3973           fi
3974         done
3975       else
3976         # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
3977         if test -f "$destdir"/aclocal.m4; then
3978           sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
3979           sedexpr2='s,^[^/]*$,.,'
3980           sedexpr3='s,/[^/]*$,,'
3981           m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
3982           m4dirs_count=`echo "$m4dirs" | wc -l`
3983         fi
3984       fi
3985       if test $m4dirs_count = 0; then
3986         # First use of gnulib in a package.
3987         # Any number of additional modules can be given.
3988         test -n "$supplied_libname" || supplied_libname=true
3989         test -n "$sourcebase" || sourcebase="lib"
3990         m4base="m4"
3991         test -n "$docbase" || docbase="doc"
3992         test -n "$testsbase" || testsbase="tests"
3993         test -n "$macro_prefix" || macro_prefix="gl"
3994         func_import "$*"
3995       else
3996         if test $m4dirs_count = 1; then
3997           # There's only one use of gnulib here. Assume the user means it.
3998           # Any number of additional modules can be given.
3999           for m4base in $m4dirs; do
4000             func_import "$*"
4001           done
4002         else
4003           # Ambiguous - guess what the user meant.
4004           if test $# = 0; then
4005             # No further arguments. Guess the user wants to update all of them.
4006             for m4base in $m4dirs; do
4007               # Perform func_import in a subshell, so that variable values
4008               # such as
4009               #   local_gnulib_dir, avoidlist, sourcebase, m4base, pobase,
4010               #   docbase, testsbase, inctests, libname, lgpl, makefile_name,
4011               #   libtool, macro_prefix, po_domain
4012               # don't propagate from one directory to another.
4013               (func_import) || func_exit 1
4014             done
4015           else
4016             # Really ambiguous.
4017             func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
4018           fi
4019         fi
4020       fi
4021     fi
4022     ;;
4023
4024   create-testdir )
4025     if test -z "$destdir"; then
4026       func_fatal_error "please specify --dir option"
4027     fi
4028     mkdir "$destdir"
4029     test -d "$destdir" \
4030       || func_fatal_error "could not create destination directory"
4031     test -n "$auxdir" || auxdir="build-aux"
4032     func_create_testdir "$destdir" "$*"
4033     ;;
4034
4035   create-megatestdir )
4036     if test -z "$destdir"; then
4037       func_fatal_error "please specify --dir option"
4038     fi
4039     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4040     test -n "$auxdir" || auxdir="build-aux"
4041     func_create_megatestdir "$destdir" "$*"
4042     ;;
4043
4044   test )
4045     test -n "$destdir" || destdir=testdir$$
4046     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4047     test -n "$auxdir" || auxdir="build-aux"
4048     func_create_testdir "$destdir" "$*"
4049     cd "$destdir"
4050       mkdir build
4051       cd build
4052         ../configure || func_exit 1
4053         make || func_exit 1
4054         make check || func_exit 1
4055         make distclean || func_exit 1
4056         remaining=`find . -type f -print`
4057         if test -n "$remaining"; then
4058           echo "Remaining files:" $remaining 1>&2
4059           echo "gnulib-tool: *** Stop." 1>&2
4060           func_exit 1
4061         fi
4062       cd ..
4063     cd ..
4064     rm -rf "$destdir"
4065     ;;
4066
4067   megatest )
4068     test -n "$destdir" || destdir=testdir$$
4069     mkdir "$destdir" || func_fatal_error "could not create destination directory"
4070     test -n "$auxdir" || auxdir="build-aux"
4071     func_create_megatestdir "$destdir" "$*"
4072     cd "$destdir"
4073       mkdir build
4074       cd build
4075         ../configure
4076         make
4077         make check
4078         make distclean
4079         remaining=`find . -type f -print`
4080         if test -n "$remaining"; then
4081           echo "Remaining files:" $remaining 1>&2
4082           echo "gnulib-tool: *** Stop." 1>&2
4083           func_exit 1
4084         fi
4085       cd ..
4086     cd ..
4087     rm -rf "$destdir"
4088     ;;
4089
4090   extract-description )
4091     for module
4092     do
4093       func_verify_module
4094       if test -n "$module"; then
4095         func_get_description "$module"
4096       fi
4097     done
4098     ;;
4099
4100   extract-notice )
4101     for module
4102     do
4103       func_verify_module
4104       if test -n "$module"; then
4105         func_get_notice "$module"
4106       fi
4107     done
4108     ;;
4109
4110   extract-filelist )
4111     for module
4112     do
4113       func_verify_module
4114       if test -n "$module"; then
4115         func_get_filelist "$module"
4116       fi
4117     done
4118     ;;
4119
4120   extract-dependencies )
4121     for module
4122     do
4123       func_verify_module
4124       if test -n "$module"; then
4125         func_get_dependencies "$module"
4126       fi
4127     done
4128     ;;
4129
4130   extract-autoconf-snippet )
4131     for module
4132     do
4133       func_verify_module
4134       if test -n "$module"; then
4135         func_get_autoconf_snippet "$module"
4136       fi
4137     done
4138     ;;
4139
4140   extract-automake-snippet )
4141     for module
4142     do
4143       func_verify_module
4144       if test -n "$module"; then
4145         func_get_automake_snippet "$module"
4146       fi
4147     done
4148     ;;
4149
4150   extract-include-directive )
4151     for module
4152     do
4153       func_verify_module
4154       if test -n "$module"; then
4155         func_get_include_directive "$module"
4156       fi
4157     done
4158     ;;
4159
4160   extract-link-directive )
4161     for module
4162     do
4163       func_verify_module
4164       if test -n "$module"; then
4165         func_get_link_directive "$module"
4166       fi
4167     done
4168     ;;
4169
4170   extract-license )
4171     for module
4172     do
4173       func_verify_module
4174       if test -n "$module"; then
4175         func_get_license "$module"
4176       fi
4177     done
4178     ;;
4179
4180   extract-maintainer )
4181     for module
4182     do
4183       func_verify_module
4184       if test -n "$module"; then
4185         func_get_maintainer "$module"
4186       fi
4187     done
4188     ;;
4189
4190   extract-tests-module )
4191     for module
4192     do
4193       func_verify_module
4194       if test -n "$module"; then
4195         func_get_tests_module "$module"
4196       fi
4197     done
4198     ;;
4199
4200   * )
4201     func_fatal_error "unknown operation mode --$mode" ;;
4202 esac
4203
4204 rm -rf "$tmp"
4205 # Undo the effect of the previous 'trap' command. Some shellology:
4206 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
4207 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
4208 # exit); for the others we need to call 'exit' explicitly. The value of $? is
4209 # 128 + signal number and is set before the trap-registered command is run.
4210 trap '' 0
4211 trap 'func_exit $?' 1 2 3 13 15
4212
4213 exit 0
4214
4215 # Local Variables:
4216 # indent-tabs-mode: nil
4217 # whitespace-check-buffer-indent: nil
4218 # End: