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