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