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