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