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