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