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