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