auto
[gnulib.git] / gnulib-tool
1 #! /bin/sh
2 #
3 # Copyright (C) 2002, 2003, 2004 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 2, or (at your option)
8 # 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, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #
19
20 # This program is meant for authors or maintainers which want to import
21 # modules from gnulib into their packages.
22
23 progname=$0
24 package=gnulib
25 cvsdatestamp='$Date: 2004-08-17 23:36:21 $'
26 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
27 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
28
29 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
30 AUTOCONFPATH=
31 case $USER in
32   bruno )
33     AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
34     AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
35     ;;
36 esac
37
38 AUTOCONF="${AUTOCONFPATH}autoconf"
39 AUTOHEADER="${AUTOCONFPATH}autoheader"
40 AUTOMAKE="${AUTOCONFPATH}automake-1.7"
41 ACLOCAL="aclocal-1.7"
42
43 # func_usage
44 # outputs to stdout the --help usage message.
45 func_usage ()
46 {
47   echo "\
48 Usage: gnulib-tool --list
49        gnulib-tool --import [MODULE...]
50        gnulib-tool --create-testdir --dir=directory module1 ... moduleN
51        gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
52        gnulib-tool --test --dir=directory module1 ... moduleN
53        gnulib-tool --megatest --dir=directory [module1 ... moduleN]
54        gnulib-tool --extract-description module
55        gnulib-tool --extract-filelist module
56        gnulib-tool --extract-dependencies module
57        gnulib-tool --extract-autoconf-snippet module
58        gnulib-tool --extract-automake-snippet module
59        gnulib-tool --extract-include-directive module
60        gnulib-tool --extract-maintainer module
61
62 Operation modes:
63       --list                print the available module names
64       --import              import the given modules into the current package
65       --create-testdir      create a scratch package with the given modules
66       --create-megatestdir  create a mega scratch package with the given modules
67                             one by one and all together
68       --test                test the combination of the given modules
69                             (recommended to use CC=\"gcc -Wall\" here)
70       --megatest            test the given modules one by one and all together
71                             (recommended to use CC=\"gcc -Wall\" here)
72       --extract-description        extract the description
73       --extract-filelist           extract the list of files
74       --extract-dependencies       extract the dependencies
75       --extract-autoconf-snippet   extract the snippet for configure.ac
76       --extract-automake-snippet   extract the snippet for lib/Makefile.am
77       --extract-include-directive  extract the #include directive
78       --extract-maintainer         report the maintainer(s) inside gnulib
79
80 Options:
81       --dir=DIRECTORY       specify the target directory
82                             For --import, this specify where your
83                             configure.ac can be found.  Defaults to current
84                             directory.
85       --lib=LIBRARY         Specify the library name.  Defaults to 'libgnu'.
86       --source-base=DIRECTORY
87                             Directory relative --dir where source code is
88                             placed (default \"lib\"), for --import.
89       --m4-base=DIRECTORY   Directory relative --dir where *.m4 macros are
90                             placed (default \"m4\"), for --import.
91       --libtool             Use libtool rules, for --import.
92       --no-changelog        don't update or create ChangeLog files
93       --dry-run             For --import, only print what would have been done.
94
95 Report bugs to <bug-gnulib@gnu.org>."
96 }
97
98 # func_version
99 # outputs to stdout the --version message.
100 func_version ()
101 {
102   echo "$progname (GNU $package) $version"
103   echo "Copyright (C) 2002 Free Software Foundation, Inc.
104 This is free software; see the source for copying conditions.  There is NO
105 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
106   echo "Written by" "Bruno Haible"
107 }
108
109 # func_fatal_error message
110 # outputs to stderr a fatal error message, and terminates the program.
111 func_fatal_error ()
112 {
113   echo "gnulib-tool: *** $1" 1>&2
114   echo "gnulib-tool: *** Stop." 1>&2
115   exit 1
116 }
117
118 # Command-line option processing.
119 # Removes the OPTIONS from the arguments. Sets the variables:
120 # - mode            list or import or create-testdir or create-megatestdir
121 # - destdir         from --dir
122 # - libname         from --lib
123 # - sourcebase      from --source-base
124 # - m4base          from --m4-base
125 # - libtool         true if --libtool was given, blank otherwise
126 # - do_changelog    false if --no-changelog was given, : otherwise
127 # - dry_run         true if --dry-run was given, blank otherwise
128 {
129   mode=
130   destdir=
131   libname=libgnu
132   sourcebase=
133   m4base=
134   libtool=
135   do_changelog=:
136   dry_run=
137
138   supplied_opts="$@"
139
140   while test $# -gt 0; do
141     case "$1" in
142       --list | --lis )
143         mode=list
144         shift ;;
145       --import | --impor | --impo | --imp | --im | --i )
146         mode=import
147         shift ;;
148       --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
149         mode=create-testdir
150         shift ;;
151       --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
152         mode=create-megatestdir
153         shift ;;
154       --test | --tes | --te | --t )
155         mode=test
156         shift ;;
157       --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
158         mode=megatest
159         shift ;;
160       --extract-* )
161         mode=`echo "X$1" | sed -e 's/^X--//'`
162         shift ;;
163       --dir )
164         shift
165         if test $# = 0; then
166           func_fatal_error "missing argument for --dir"
167         fi
168         destdir=$1
169         shift ;;
170       --dir=* )
171         destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
172         shift ;;
173       --lib )
174         shift
175         if test $# = 0; then
176           func_fatal_error "missing argument for --lib"
177         fi
178         libname=$1
179         supplied_libname=true
180         shift ;;
181       --lib=* )
182         libname=`echo "X$1" | sed -e 's/^X--lib=//'`
183         supplied_libname=true
184         shift ;;
185       --source-base )
186         shift
187         if test $# = 0; then
188           func_fatal_error "missing argument for --source-base"
189         fi
190         sourcebase=$1
191         shift ;;
192       --source-base=* )
193         sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
194         shift ;;
195       --m4-base )
196         shift
197         if test $# = 0; then
198           func_fatal_error "missing argument for --m4-base"
199         fi
200         m4base=$1
201         shift ;;
202       --m4-base=* )
203         m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
204         shift ;;
205       --libtool )
206         libtool=true
207         shift ;;
208       --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
209         do_changelog=false
210         shift ;;
211       --dry-run )
212         dry_run=true
213         shift ;;
214       --help | --hel | --he | --h )
215         func_usage
216         exit 0 ;;
217       --version | --versio | --versi | --vers | --ver | --ve | --v )
218         func_version
219         exit 0 ;;
220       -- )
221         # Stop option prcessing
222         shift
223         break ;;
224       -* )
225         echo "gnulib-tool: unknown option $1" 1>&2
226         echo "Try 'gnulib-tool --help' for more information." 1>&2
227         exit 1 ;;
228       * )
229         break ;;
230     esac
231   done
232 }
233
234 case "$0" in
235   /*) self_abspathname="$0" ;;
236   */*) self_abspathname=`pwd`/"$0" ;;
237   *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
238        if test -x "$d/$0" && test ! -d "$d/$0"; then
239          self_abspathname="$d/$0"
240          break
241        fi
242      done
243      if test -z "$self_abspathname"; then
244        func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
245      fi
246      ;;
247 esac
248 while test -h "$self_abspathname"; do
249   # Resolve symbolic link.
250   sedexpr1='s, -> ,#%%#,'
251   sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
252   linkval=`LC_ALL=C ls -l "$self_abspathname" | sed -e "$sedexpr1" | sed -n -e "$sedexpr2"`
253   test -n "$linkval" || break
254   case "$linkval" in
255     /* ) self_abspathname="$linkval" ;;
256     * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
257   esac
258 done
259 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
260
261 # func_all_modules
262 func_all_modules ()
263 {
264   (cd "$gnulib_dir/modules" && ls -1) \
265       | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^TEMPLATE$/d' -e '/~$/d' \
266       | sort
267 }
268
269 # func_verify_module
270 # verifies a module name
271 func_verify_module ()
272 {
273   if test ! -f "$gnulib_dir/modules/$module" \
274      || test "CVS" = "$module" \
275      || test "ChangeLog" = "$module" \
276      || test "TEMPLATE" = "$module"; then
277     echo "gnulib-tool: module $module doesn't exist" 1>&2
278     module=
279   fi
280 }
281
282 sed_extract_prog=':[    ]*$/ {
283   :a
284     n
285     s/^Description:[    ]*$//
286     s/^Files:[  ]*$//
287     s/^Depends-on:[     ]*$//
288     s/^configure\.ac:[  ]*$//
289     s/^Makefile\.am:[   ]*$//
290     s/^Include:[        ]*$//
291     s/^Maintainer:[     ]*$//
292     tb
293     p
294     ba
295   :b
296 }'
297
298 # func_get_description module
299 func_get_description ()
300 {
301   sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
302 }
303
304 # func_get_filelist module
305 func_get_filelist ()
306 {
307   sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
308   #echo m4/onceonly.m4
309   echo m4/onceonly_2_57.m4
310 }
311
312 # func_get_dependencies module
313 func_get_dependencies ()
314 {
315   sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
316 }
317
318 # func_get_autoconf_snippet module
319 func_get_autoconf_snippet ()
320 {
321   sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
322 }
323
324 # func_get_automake_snippet module
325 func_get_automake_snippet ()
326 {
327   sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
328 }
329
330 # func_get_include_directive module
331 func_get_include_directive ()
332 {
333   sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
334   sed -e 's/^\(["<]\)/#include \1/'
335 }
336
337 # func_get_maintainer module
338 func_get_maintainer ()
339 {
340   sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
341 }
342
343 # func_create_testdir testdir modules
344 func_create_testdir ()
345 {
346   testdir="$1"
347   modules="$2"
348   modules=`for m in $modules; do echo $m; done | sort | uniq`
349
350   # Determine final module list.
351   while true; do
352     xmodules=
353     for module in $modules; do
354       func_verify_module
355       if test -n "$module"; then
356         # Duplicate dependenies are harmless, but Jim wants a warning.
357         duplicated_deps=`func_get_dependencies $module | sort | uniq -d`
358         if test -n "$duplicated_deps"; then
359           echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
360         fi
361         xmodules="$xmodules $module "`func_get_dependencies $module`
362       fi
363     done
364     xmodules=`for m in $xmodules; do echo $m; done | sort | uniq`
365     if test "$xmodules" = "$modules"; then
366       break
367     fi
368     modules="$xmodules"
369   done
370   echo "Module list with included dependencies:"
371   echo "$modules" | sed -e 's/^/  /'
372
373   # Determine final file list.
374   files=
375   for module in $modules; do
376     func_verify_module
377     if test -n "$module"; then
378       files="$files "`func_get_filelist $module`
379     fi
380   done
381   files=`for f in $files; do echo $f; done | sort | uniq`
382   echo "File list:"
383   echo "$files" | sed -e 's/^/  /'
384
385   # Create directories.
386   for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
387     if test "$d" != config; then
388       mkdir -p "$testdir/$d"
389     fi
390   done
391
392   # Copy files.
393   for f in $files; do
394     case "$f" in
395       config/*) g=`echo "$f" | sed -e 's,^config/,,'` ;;
396       *) g="$f" ;;
397     esac
398     ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
399     cp -p "$gnulib_dir/$f" "$testdir/$g"
400   done
401
402   # Create lib/Makefile.am.
403   mkdir -p "$testdir/lib"
404   (echo "## Process this file with automake to produce Makefile.in."
405    echo
406    echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
407    echo
408    echo "noinst_LIBRARIES = $libname.a"
409    echo
410    echo "$libname"'_a_SOURCES ='
411    echo "$libname"'_a_LIBADD = @LIBOBJS@'
412    echo '#'"$libname"'_la_LIBADD = @LTLIBOBJS@'
413    echo "EXTRA_DIST ="
414    echo "BUILT_SOURCES ="
415    echo "SUFFIXES ="
416    echo "MOSTLYCLEANFILES ="
417    echo "CLEANFILES ="
418    echo "DISTCLEANFILES ="
419    echo "MAINTAINERCLEANFILES ="
420    for module in $modules; do
421      func_verify_module
422      if test -n "$module"; then
423        func_get_automake_snippet "$module" | sed -e "s,lib_SOURCES,$libname"'_a_SOURCES,g' -e "s,lib_OBJECTS,$libname"'_a_OBJECTS,g'
424        if test "$module" = 'alloca'; then
425          echo "$libname"'_a_LIBADD += @ALLOCA@'
426          echo '#'"$libname"'_la_LIBADD += @LTALLOCA@'
427        fi
428      fi
429    done
430   ) > "$testdir/lib/Makefile.am"
431
432   # Create m4/Makefile.am.
433   mkdir -p "$testdir/m4"
434   (echo "## Process this file with automake to produce Makefile.in."
435    echo
436    echo "EXTRA_DIST ="
437    for f in $files; do
438      case "$f" in
439        m4/* )
440          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
441      esac
442    done
443   ) > "$testdir/m4/Makefile.am"
444
445   subdirs="lib m4"
446
447   if test -f "$testdir"/m4/gettext.m4; then
448     # Avoid stupid error message from automake:
449     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
450     mkdir -p "$testdir/po"
451     (echo "## Process this file with automake to produce Makefile.in."
452     ) > "$testdir/po/Makefile.am"
453     subdirs="$subdirs po"
454   fi
455
456   # Create Makefile.am.
457   (echo "## Process this file with automake to produce Makefile.in."
458    echo
459    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
460    echo
461    echo "SUBDIRS = $subdirs"
462    echo
463    echo "ACLOCAL_AMFLAGS = -I m4"
464   ) > "$testdir/Makefile.am"
465
466   # Create configure.ac.
467   (echo "# Process this file with autoconf to produce a configure script."
468    echo "AC_INIT(dummy,0)"
469    echo "AM_INIT_AUTOMAKE"
470    echo
471    echo "AM_CONFIG_HEADER(config.h)"
472    echo
473    echo "AC_PROG_CC"
474    echo "AC_PROG_INSTALL"
475    echo "AC_PROG_MAKE_SET"
476    echo "AC_PROG_RANLIB"
477    echo
478    if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
479      echo "AC_GNU_SOURCE"
480      echo
481    fi
482    if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
483      echo "gl_USE_SYSTEM_EXTENSIONS"
484      echo
485    fi
486    for module in $modules; do
487      func_verify_module
488      if test -n "$module"; then
489        func_get_autoconf_snippet "$module"
490      fi
491    done
492    echo
493    makefiles="Makefile"
494    for d in $subdirs; do
495      makefiles="$makefiles $d/Makefile"
496    done
497    echo "AC_OUTPUT([$makefiles])"
498   ) > "$testdir/configure.ac"
499
500   # Create autogenerated files.
501   (cd "$testdir"
502    echo "executing ${ACLOCAL} -I m4"
503    ${ACLOCAL} -I m4
504    echo "executing ${AUTOHEADER}"
505    ${AUTOHEADER}
506    echo "executing ${AUTOCONF}"
507    ${AUTOCONF}
508    echo "executing ${AUTOMAKE} --add-missing --copy"
509    ${AUTOMAKE} --add-missing --copy
510   )
511   if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
512     (cd "$testdir"
513      ./configure
514        cd lib
515        built_sources=`grep '^BUILT_SOURCES *=' Makefile.in | sed -e 's/^BUILT_SOURCES *=//'`
516        if test -n "$built_sources"; then
517          make $built_sources
518        fi
519        cd ..
520      make distclean
521     )
522   fi
523 }
524
525 # func_create_megatestdir megatestdir allmodules
526 func_create_megatestdir ()
527 {
528   megatestdir="$1"
529   allmodules="$2"
530   if test -z "$allmodules"; then
531     allmodules=`func_all_modules`
532   fi
533
534   megasubdirs=
535   # First, all modules one by one.
536   for onemodule in $allmodules; do
537     func_create_testdir "$megatestdir/$onemodule" $onemodule
538     megasubdirs="${megasubdirs}$onemodule "
539   done
540   # Then, all modules all together.
541   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
542   allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
543   func_create_testdir "$megatestdir/ALL" "$allmodules"
544   megasubdirs="${megasubdirs}ALL"
545
546   # Create Makefile.am.
547   (echo "## Process this file with automake to produce Makefile.in."
548    echo
549    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
550    echo
551    echo "SUBDIRS = $megasubdirs"
552   ) > "$megatestdir/Makefile.am"
553
554   # Create configure.ac.
555   (echo "# Process this file with autoconf to produce a configure script."
556    echo "AC_INIT(dummy,0)"
557    echo "AM_INIT_AUTOMAKE"
558    echo
559    echo "AC_PROG_MAKE_SET"
560    echo
561    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
562    echo "AC_OUTPUT([Makefile])"
563   ) > "$megatestdir/configure.ac"
564
565   # Create autogenerated files.
566   (cd "$megatestdir"
567    echo "executing ${ACLOCAL}"
568    ${ACLOCAL}
569    echo "executing ${AUTOCONF}"
570    ${AUTOCONF}
571    echo "executing ${AUTOMAKE} --add-missing --copy Makefile"
572    ${AUTOMAKE} --add-missing --copy Makefile
573   )
574 }
575
576 case $mode in
577   "" )
578     func_fatal_error "no mode specified" ;;
579
580   list )
581     func_all_modules
582     ;;
583
584   import )
585         # Where to import.
586         if test -z "$destdir"; then
587             destdir=.
588         fi
589         test -d "$destdir" \
590             || func_fatal_error "destination directory does not exist: $destdir"
591
592         # Prefer configure.ac to configure.in
593         test -f $destdir/configure.in && configure_ac=$destdir/configure.in
594         test -f $destdir/configure.ac && configure_ac=$destdir/configure.ac
595         test -f "$configure_ac" \
596             || func_fatal_error "cannot find $destdir/configure.ac"
597
598         # Get settings.
599         my_sed_traces='s,#.*$,,; s,^dnl .*$,,; s, dnl .*$,,;
600         /gl_MODULES[^_]/  {
601             s,^.*gl_MODULES([[   ]*\([^])]*\).*$,ac_modules="\1",; p;
602         };
603         /gl_SOURCE_BASE/   {
604             s,^.*gl_SOURCE_BASE([[         ]*\([^])]*\).*$,ac_sourcebase="\1",; p;
605         };
606         /gl_M4_BASE/   {
607             s,^.*gl_M4_BASE([[         ]*\([^])]*\).*$,ac_m4base="\1",; p;
608         };
609         /gl_LIB/   {
610             s,^.*gl_LIB([[         ]*\([^])]*\).*$,ac_libname="\1",; p;
611         };
612         /A[CM]_PROG_LIBTOOL/ { s,^.*$,seen_libtool=:,; p; };
613         /LT_INIT/            { s,^.*$,seen_libtool=:,; p; };
614         d;'
615         eval `cat $configure_ac | sed "$my_sed_traces"`
616
617         # Override libname?
618         if test -z "$supplied_libname" && test -n "$ac_libname"; then
619             libname="$ac_libname"
620         fi
621
622         # Set up source base.
623         test -z "$sourcebase" && sourcebase="$ac_sourcebase"
624         test -z "$sourcebase" && sourcebase="lib"
625         test -d "$destdir/$sourcebase" || \
626             (test -z "$dry_run" && mkdir "$destdir/$sourcebase") || \
627             func_fatal_error "source base $destdir/$sourcebase doesn't exist"
628
629         # Set up m4 base.
630         test -z "$m4base" && m4base="$ac_m4base"
631         test -z "$sourcebase" && m4base="m4"
632         test -d "$destdir/$m4base" || \
633             (test -z "$dry_run" && mkdir "$destdir/$m4base") || \
634             func_fatal_error "m4 base $destdir/$m4base doesn't exist"
635
636         # Using libtool?
637         if test x$seen_libtool != x; then
638             libtool=true
639         fi
640
641         # What modules to extract.
642         supplied_modules="$*"
643         modules=`for m in $supplied_modules; do echo $m; done | sort | uniq`
644         if test -z "$modules"; then
645             modules="$ac_modules"
646         fi
647
648         # Determine final module list.
649         while true; do
650             xmodules=
651             for module in $modules; do
652                 func_verify_module
653                 if test -n "$module"; then
654                     # Duplicate dependenies are harmless, but Jim wants a warning.
655                     duplicated_deps=`func_get_dependencies $module | sort | uniq -d`
656                     if test -n "$duplicated_deps"; then
657                         echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
658                     fi
659                     xmodules="$xmodules $module "`func_get_dependencies $module`
660                 fi
661             done
662             xmodules=`for m in $xmodules; do echo $m; done | sort | uniq`
663             if test "$xmodules" = "$modules"; then
664                 break
665             fi
666             modules="$xmodules"
667         done
668         echo "Module list with included dependencies:"
669         echo "$modules" | sed -e 's/^/  /'
670
671         # Determine final file list.
672         files=
673         for module in $modules; do
674             func_verify_module
675             if test -n "$module"; then
676                 files="$files "`func_get_filelist $module`
677             fi
678         done
679         files=`for f in $files; do echo $f; done | sort | uniq`
680         echo "File list:"
681         echo "$files" | sed -e 's/^/  /'
682
683         test -n "$files" \
684             || func_fatal_error "refusing to do nothing"
685
686         # Copy files.
687         for f in $files; do
688             case "$f" in
689                 config/*) g=`echo "$f" | sed -e 's,^config/,,'` ;;
690                 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
691                 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
692                 *) g="$f" ;;
693             esac
694             test -n "$dry_run" && dry=echo
695             $dry cp -p "$gnulib_dir/$f" "$destdir/$g"
696         done
697
698         # Commands printed in a comment in generated files.
699         cmd="gnulib-tool $supplied_opts"
700         opt_libtool=
701         if test -n "$libtool"; then
702             opt_libtool="--libtool"
703         fi
704         actioncmd="gnulib-tool --import --dir=$destdir --lib=$libname --source-base=$sourcebase --m4-base=$m4base $opt_libtool `echo $modules`"
705
706         # Create lib/Makefile.am.
707         echo "Creating $destdir/$sourcebase/Makefile.am..."
708         if test -n "$libtool"; then
709             libext=la
710             perhapsLT=LT
711         else
712             libext=a
713             perhapsLT=
714         fi
715         (
716             if test -z "$dry_run"; then
717                 exec > $destdir/$sourcebase/Makefile.am
718             else
719                 echo "# $destdir/$sourcebase/Makefile.am"
720             fi
721             echo "## Process this file with automake to produce Makefile.in."
722             echo "# Copyright (C) 2004 Free Software Foundation, Inc."
723             echo "#"
724             echo "# This file is free software, distributed under the terms of the GNU"
725             echo "# General Public License.  As a special exception to the GNU General"
726             echo "# Public License, this file may be distributed as part of a program"
727             echo "# that contains a configuration script generated by Automake, under"
728             echo "# the same distribution terms as the rest of that program."
729             echo "#"
730             echo "# Generated by gnulib-tool."
731             echo "#"
732             echo "# Invoked as: $cmd"
733             echo "# Reproduce by: $actioncmd"
734             echo
735             echo "AUTOMAKE_OPTIONS = 1.8 gnits"
736             echo
737             echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
738             echo
739             echo "${libname}_${libext}_SOURCES ="
740             echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
741             echo "EXTRA_DIST ="
742             echo "BUILT_SOURCES ="
743             echo "SUFFIXES ="
744             echo "MOSTLYCLEANFILES ="
745             echo "CLEANFILES ="
746             echo "DISTCLEANFILES ="
747             echo "MAINTAINERCLEANFILES ="
748             for module in $modules; do
749                 func_verify_module
750                 if test -n "$module"; then
751                     func_get_automake_snippet "$module" | sed -e "s,lib_SOURCES,${libname}_${libext}_SOURCES,g" -e "s,lib_OBJECTS,${libname}_${libext}_OBJECTS,g"
752                     if test "$module" = 'alloca'; then
753                         echo "${libname}_${libext}_LIBADD += @ALLOCA@"
754                     fi
755                 fi
756             done
757             echo
758             echo "# Makefile.am ends here"
759         )
760
761         # Create gnulib.m4.
762         echo "Creating $destdir/$m4base/gnulib.m4..."
763         (
764             if test -z "$dry_run"; then
765                 exec > $destdir/$m4base/gnulib.m4
766             else
767                 echo "# $destdir/$m4base/gnulib.m4"
768             fi
769             echo "# Copyright (C) 2004 Free Software Foundation, Inc."
770             echo "# This file is free software, distributed under the terms of the GNU"
771             echo "# General Public License.  As a special exception to the GNU General"
772             echo "# Public License, this file may be distributed as part of a program"
773             echo "# that contains a configuration script generated by Autoconf, under"
774             echo "# the same distribution terms as the rest of that program."
775             echo "#"
776             echo "# Generated by gnulib-tool."
777             echo "#"
778             echo "# Invoked as: $cmd"
779             echo "# Reproduce by: $actioncmd"
780             echo
781             echo "AC_DEFUN([gl_EARLY],"
782             echo "["
783             if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 > /dev/null; then
784                 echo "  AC_GNU_SOURCE"
785             fi
786             if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 > /dev/null; then
787                 echo "  gl_USE_SYSTEM_EXTENSIONS"
788             fi
789             echo "])"
790             echo
791             echo "AC_DEFUN([gl_INIT],"
792             echo "["
793             for module in $modules; do
794                 func_verify_module
795                 if test -n "$module"; then
796                     func_get_autoconf_snippet "$module" | sed -e '/^$/d;' -e 's/^/  /' -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./'
797                 fi
798             done
799             echo "])"
800             echo
801             echo "dnl Usage: gl_MODULES(module1 module2 ...)"
802             echo "AC_DEFUN([gl_MODULES], [])"
803             echo
804             echo "dnl Usage: gl_SOURCE_BASE(DIR)"
805             echo "AC_DEFUN([gl_SOURCE_BASE], [])"
806             echo
807             echo "dnl Usage: gl_M4_BASE(DIR)"
808             echo "AC_DEFUN([gl_M4_BASE], [])"
809             echo
810             echo "# gnulib.m4 ends here"
811         )
812         echo "Finished."
813         echo
814         echo "Don't forget to add \"$sourcebase/Makefile\""
815         echo "to AC_CONFIG_FILES in \"$configure_ac\" and to mention"
816         echo "\"`basename $sourcebase`\" in SUBDIRS in some Makefile.am."
817         ;;
818
819   create-testdir )
820     if test -z "$destdir"; then
821       func_fatal_error "please specify --dir option"
822     fi
823     mkdir "$destdir"
824     test -d "$destdir" \
825       || func_fatal_error "could not create destination directory"
826     func_create_testdir "$destdir" "$*"
827     ;;
828
829   create-megatestdir )
830     if test -z "$destdir"; then
831       func_fatal_error "please specify --dir option"
832     fi
833     mkdir "$destdir" || func_fatal_error "could not create destination directory"
834     func_create_megatestdir "$destdir" "$*"
835     ;;
836
837   test )
838     test -n "$destdir" || destdir=testdir$$
839     mkdir "$destdir" || func_fatal_error "could not create destination directory"
840     func_create_testdir "$destdir" "$*"
841     cd "$destdir"
842       mkdir build
843       cd build
844         ../configure
845         make
846         make check
847         make distclean
848         remaining=`find . -type f -print`
849         if test -n "$remaining"; then
850           echo "Remaining files:" $remaining 1>&2
851           echo "gnulib-tool: *** Stop." 1>&2
852           exit 1
853         fi
854       cd ..
855     cd ..
856     rm -rf "$destdir"
857     ;;
858
859   megatest )
860     test -n "$destdir" || destdir=testdir$$
861     mkdir "$destdir" || func_fatal_error "could not create destination directory"
862     func_create_megatestdir "$destdir" "$*"
863     cd "$destdir"
864       mkdir build
865       cd build
866         ../configure
867         make
868         make check
869         make distclean
870         remaining=`find . -type f -print`
871         if test -n "$remaining"; then
872           echo "Remaining files:" $remaining 1>&2
873           echo "gnulib-tool: *** Stop." 1>&2
874           exit 1
875         fi
876       cd ..
877     cd ..
878     rm -rf "$destdir"
879     ;;
880
881   extract-description )
882     for module
883     do
884       func_verify_module
885       if test -n "$module"; then
886         func_get_description "$module"
887       fi
888     done
889     ;;
890
891   extract-filelist )
892     for module
893     do
894       func_verify_module
895       if test -n "$module"; then
896         func_get_filelist "$module"
897       fi
898     done
899     ;;
900
901   extract-dependencies )
902     for module
903     do
904       func_verify_module
905       if test -n "$module"; then
906         func_get_dependencies "$module"
907       fi
908     done
909     ;;
910
911   extract-autoconf-snippet )
912     for module
913     do
914       func_verify_module
915       if test -n "$module"; then
916         func_get_autoconf_snippet "$module"
917       fi
918     done
919     ;;
920
921   extract-automake-snippet )
922     for module
923     do
924       func_verify_module
925       if test -n "$module"; then
926         func_get_automake_snippet "$module"
927       fi
928     done
929     ;;
930
931   extract-include-directive )
932     for module
933     do
934       func_verify_module
935       if test -n "$module"; then
936         func_get_include_directive "$module"
937       fi
938     done
939     ;;
940
941   extract-maintainer )
942     for module
943     do
944       func_verify_module
945       if test -n "$module"; then
946         func_get_maintainer "$module"
947       fi
948     done
949     ;;
950
951   * )
952     func_fatal_error "unknown operation mode --$mode" ;;
953 esac
954
955 exit 0