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