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