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