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