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