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