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