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