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