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