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