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