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