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