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