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