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