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