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