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