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