Add a license tag to every module.
[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-09-22 15:11: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 [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       --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/^License:[        ]*$//
292     s/^Maintainer:[     ]*$//
293     tb
294     p
295     ba
296   :b
297 }'
298
299 # func_get_description module
300 func_get_description ()
301 {
302   sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
303 }
304
305 # func_get_filelist module
306 func_get_filelist ()
307 {
308   sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
309   #echo m4/onceonly.m4
310   echo m4/onceonly_2_57.m4
311 }
312
313 # func_get_dependencies module
314 func_get_dependencies ()
315 {
316   sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
317 }
318
319 # func_get_autoconf_snippet module
320 func_get_autoconf_snippet ()
321 {
322   sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
323 }
324
325 # func_get_automake_snippet module
326 func_get_automake_snippet ()
327 {
328   sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
329 }
330
331 # func_get_include_directive module
332 func_get_include_directive ()
333 {
334   sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
335   sed -e 's/^\(["<]\)/#include \1/'
336 }
337
338 # func_get_license module
339 func_get_license ()
340 {
341   sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
342 }
343
344 # func_get_maintainer module
345 func_get_maintainer ()
346 {
347   sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
348 }
349
350 # func_create_testdir testdir modules
351 func_create_testdir ()
352 {
353   testdir="$1"
354   modules="$2"
355   modules=`for m in $modules; do echo $m; done | sort | uniq`
356
357   # Determine final module list.
358   while true; do
359     xmodules=
360     for module in $modules; do
361       func_verify_module
362       if test -n "$module"; then
363         # Duplicate dependenies are harmless, but Jim wants a warning.
364         duplicated_deps=`func_get_dependencies $module | sort | uniq -d`
365         if test -n "$duplicated_deps"; then
366           echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
367         fi
368         xmodules="$xmodules $module "`func_get_dependencies $module`
369       fi
370     done
371     xmodules=`for m in $xmodules; do echo $m; done | sort | uniq`
372     if test "$xmodules" = "$modules"; then
373       break
374     fi
375     modules="$xmodules"
376   done
377   echo "Module list with included dependencies:"
378   echo "$modules" | sed -e 's/^/  /'
379
380   # Determine final file list.
381   files=
382   for module in $modules; do
383     func_verify_module
384     if test -n "$module"; then
385       files="$files "`func_get_filelist $module`
386     fi
387   done
388   files=`for f in $files; do echo $f; done | sort | uniq`
389   echo "File list:"
390   echo "$files" | sed -e 's/^/  /'
391
392   # Create directories.
393   for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
394     if test "$d" != config; then
395       mkdir -p "$testdir/$d"
396     fi
397   done
398
399   # Copy files.
400   for f in $files; do
401     case "$f" in
402       config/*) g=`echo "$f" | sed -e 's,^config/,,'` ;;
403       *) g="$f" ;;
404     esac
405     ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
406     cp -p "$gnulib_dir/$f" "$testdir/$g"
407   done
408
409   # Create lib/Makefile.am.
410   mkdir -p "$testdir/lib"
411   (echo "## Process this file with automake to produce Makefile.in."
412    echo
413    echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
414    echo
415    echo "noinst_LIBRARIES = $libname.a"
416    echo
417    echo "$libname"'_a_SOURCES ='
418    echo "$libname"'_a_LIBADD = @LIBOBJS@'
419    echo '#'"$libname"'_la_LIBADD = @LTLIBOBJS@'
420    echo "EXTRA_DIST ="
421    echo "BUILT_SOURCES ="
422    echo "SUFFIXES ="
423    echo "MOSTLYCLEANFILES ="
424    echo "CLEANFILES ="
425    echo "DISTCLEANFILES ="
426    echo "MAINTAINERCLEANFILES ="
427    for module in $modules; do
428      func_verify_module
429      if test -n "$module"; then
430        func_get_automake_snippet "$module" | sed -e "s,lib_SOURCES,$libname"'_a_SOURCES,g' -e "s,lib_OBJECTS,$libname"'_a_OBJECTS,g'
431        if test "$module" = 'alloca'; then
432          echo "$libname"'_a_LIBADD += @ALLOCA@'
433          echo '#'"$libname"'_la_LIBADD += @LTALLOCA@'
434        fi
435      fi
436    done
437   ) > "$testdir/lib/Makefile.am"
438
439   # Create m4/Makefile.am.
440   mkdir -p "$testdir/m4"
441   (echo "## Process this file with automake to produce Makefile.in."
442    echo
443    echo "EXTRA_DIST ="
444    for f in $files; do
445      case "$f" in
446        m4/* )
447          echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
448      esac
449    done
450   ) > "$testdir/m4/Makefile.am"
451
452   subdirs="lib m4"
453
454   if test -f "$testdir"/m4/gettext.m4; then
455     # Avoid stupid error message from automake:
456     # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
457     mkdir -p "$testdir/po"
458     (echo "## Process this file with automake to produce Makefile.in."
459     ) > "$testdir/po/Makefile.am"
460     subdirs="$subdirs po"
461   fi
462
463   # Create Makefile.am.
464   (echo "## Process this file with automake to produce Makefile.in."
465    echo
466    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
467    echo
468    echo "SUBDIRS = $subdirs"
469    echo
470    echo "ACLOCAL_AMFLAGS = -I m4"
471   ) > "$testdir/Makefile.am"
472
473   # Create configure.ac.
474   (echo "# Process this file with autoconf to produce a configure script."
475    echo "AC_INIT(dummy,0)"
476    echo "AM_INIT_AUTOMAKE"
477    echo
478    echo "AM_CONFIG_HEADER(config.h)"
479    echo
480    echo "AC_PROG_CC"
481    echo "AC_PROG_INSTALL"
482    echo "AC_PROG_MAKE_SET"
483    echo "AC_PROG_RANLIB"
484    echo
485    if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
486      echo "AC_GNU_SOURCE"
487      echo
488    fi
489    if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
490      echo "gl_USE_SYSTEM_EXTENSIONS"
491      echo
492    fi
493    for module in $modules; do
494      func_verify_module
495      if test -n "$module"; then
496        func_get_autoconf_snippet "$module"
497      fi
498    done
499    echo
500    makefiles="Makefile"
501    for d in $subdirs; do
502      makefiles="$makefiles $d/Makefile"
503    done
504    echo "AC_OUTPUT([$makefiles])"
505   ) > "$testdir/configure.ac"
506
507   # Create autogenerated files.
508   (cd "$testdir"
509    echo "executing ${AUTORECONF} --force --install"
510    ${AUTORECONF} --force --install
511   )
512   if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
513     (cd "$testdir"
514      ./configure
515        cd lib
516        built_sources=`grep '^BUILT_SOURCES *=' Makefile.in | sed -e 's/^BUILT_SOURCES *=//'`
517        if test -n "$built_sources"; then
518          make $built_sources
519        fi
520        cd ..
521      make distclean
522     )
523   fi
524 }
525
526 # func_create_megatestdir megatestdir allmodules
527 func_create_megatestdir ()
528 {
529   megatestdir="$1"
530   allmodules="$2"
531   if test -z "$allmodules"; then
532     allmodules=`func_all_modules`
533   fi
534
535   megasubdirs=
536   # First, all modules one by one.
537   for onemodule in $allmodules; do
538     func_create_testdir "$megatestdir/$onemodule" $onemodule
539     megasubdirs="${megasubdirs}$onemodule "
540   done
541   # Then, all modules all together.
542   # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
543   allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
544   func_create_testdir "$megatestdir/ALL" "$allmodules"
545   megasubdirs="${megasubdirs}ALL"
546
547   # Create Makefile.am.
548   (echo "## Process this file with automake to produce Makefile.in."
549    echo
550    echo "AUTOMAKE_OPTIONS = 1.5 foreign"
551    echo
552    echo "SUBDIRS = $megasubdirs"
553   ) > "$megatestdir/Makefile.am"
554
555   # Create configure.ac.
556   (echo "# Process this file with autoconf to produce a configure script."
557    echo "AC_INIT(dummy,0)"
558    echo "AM_INIT_AUTOMAKE"
559    echo
560    echo "AC_PROG_MAKE_SET"
561    echo
562    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
563    echo "AC_OUTPUT([Makefile])"
564   ) > "$megatestdir/configure.ac"
565
566   # Create autogenerated files.
567   (cd "$megatestdir"
568    echo "executing ${AUTORECONF} --force --install"
569    ${AUTORECONF} --force --install
570   )
571 }
572
573 case $mode in
574   "" )
575     func_fatal_error "no mode specified" ;;
576
577   list )
578     func_all_modules
579     ;;
580
581   import )
582         # Where to import.
583         if test -z "$destdir"; then
584             destdir=.
585         fi
586         test -d "$destdir" \
587             || func_fatal_error "destination directory does not exist: $destdir"
588
589         # Prefer configure.ac to configure.in
590         test -f $destdir/configure.in && configure_ac=$destdir/configure.in
591         test -f $destdir/configure.ac && configure_ac=$destdir/configure.ac
592         test -f "$configure_ac" \
593             || func_fatal_error "cannot find $destdir/configure.ac"
594
595         # Get settings.
596         my_sed_traces='s,#.*$,,; s,^dnl .*$,,; s, dnl .*$,,;
597         /gl_MODULES[^_]/  {
598             s,^.*gl_MODULES([[   ]*\([^])]*\).*$,ac_modules="\1",; p;
599         };
600         /gl_SOURCE_BASE/   {
601             s,^.*gl_SOURCE_BASE([[         ]*\([^])]*\).*$,ac_sourcebase="\1",; p;
602         };
603         /gl_M4_BASE/   {
604             s,^.*gl_M4_BASE([[         ]*\([^])]*\).*$,ac_m4base="\1",; p;
605         };
606         /gl_LIB/   {
607             s,^.*gl_LIB([[         ]*\([^])]*\).*$,ac_libname="\1",; p;
608         };
609         /A[CM]_PROG_LIBTOOL/ { s,^.*$,seen_libtool=:,; p; };
610         /LT_INIT/            { s,^.*$,seen_libtool=:,; p; };
611         d;'
612         eval `cat $configure_ac | sed "$my_sed_traces"`
613
614         # Override libname?
615         if test -z "$supplied_libname" && test -n "$ac_libname"; then
616             libname="$ac_libname"
617         fi
618
619         # Set up source base.
620         test -z "$sourcebase" && sourcebase="$ac_sourcebase"
621         test -z "$sourcebase" && sourcebase="lib"
622         test -d "$destdir/$sourcebase" || \
623             (test -z "$dry_run" && mkdir "$destdir/$sourcebase") || \
624             func_fatal_error "source base $destdir/$sourcebase doesn't exist"
625
626         # Set up m4 base.
627         test -z "$m4base" && m4base="$ac_m4base"
628         test -z "$sourcebase" && m4base="m4"
629         test -d "$destdir/$m4base" || \
630             (test -z "$dry_run" && mkdir "$destdir/$m4base") || \
631             func_fatal_error "m4 base $destdir/$m4base doesn't exist"
632
633         # Using libtool?
634         if test x$seen_libtool != x; then
635             libtool=true
636         fi
637
638         # What modules to extract.
639         supplied_modules="$*"
640         modules=`for m in $supplied_modules; do echo $m; done | sort | uniq`
641         if test -z "$modules"; then
642             modules="$ac_modules"
643         fi
644
645         # Determine final module list.
646         while true; do
647             xmodules=
648             for module in $modules; do
649                 func_verify_module
650                 if test -n "$module"; then
651                     # Duplicate dependenies are harmless, but Jim wants a warning.
652                     duplicated_deps=`func_get_dependencies $module | sort | uniq -d`
653                     if test -n "$duplicated_deps"; then
654                         echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
655                     fi
656                     xmodules="$xmodules $module "`func_get_dependencies $module`
657                 fi
658             done
659             xmodules=`for m in $xmodules; do echo $m; done | sort | uniq`
660             if test "$xmodules" = "$modules"; then
661                 break
662             fi
663             modules="$xmodules"
664         done
665         echo "Module list with included dependencies:"
666         echo "$modules" | sed -e 's/^/  /'
667
668         # Determine final file list.
669         files=
670         for module in $modules; do
671             func_verify_module
672             if test -n "$module"; then
673                 files="$files "`func_get_filelist $module`
674             fi
675         done
676         files=`for f in $files; do echo $f; done | sort | uniq`
677         echo "File list:"
678         echo "$files" | sed -e 's/^/  /'
679
680         test -n "$files" \
681             || func_fatal_error "refusing to do nothing"
682
683         # Copy files.
684         for f in $files; do
685             case "$f" in
686                 config/*) g=`echo "$f" | sed -e 's,^config/,,'` ;;
687                 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
688                 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
689                 *) g="$f" ;;
690             esac
691             test -n "$dry_run" && dry=echo
692             $dry cp -p "$gnulib_dir/$f" "$destdir/$g"
693         done
694
695         # Commands printed in a comment in generated files.
696         cmd="gnulib-tool $supplied_opts"
697         opt_libtool=
698         if test -n "$libtool"; then
699             opt_libtool="--libtool"
700         fi
701         actioncmd="gnulib-tool --import --dir=$destdir --lib=$libname --source-base=$sourcebase --m4-base=$m4base $opt_libtool `echo $modules`"
702
703         # Create lib/Makefile.am.
704         echo "Creating $destdir/$sourcebase/Makefile.am..."
705         if test -n "$libtool"; then
706             libext=la
707             perhapsLT=LT
708         else
709             libext=a
710             perhapsLT=
711         fi
712         (
713             if test -z "$dry_run"; then
714                 exec > $destdir/$sourcebase/Makefile.am
715             else
716                 echo "# $destdir/$sourcebase/Makefile.am"
717             fi
718             echo "## Process this file with automake to produce Makefile.in."
719             echo "# Copyright (C) 2004 Free Software Foundation, Inc."
720             echo "#"
721             echo "# This file is free software, distributed under the terms of the GNU"
722             echo "# General Public License.  As a special exception to the GNU General"
723             echo "# Public License, this file may be distributed as part of a program"
724             echo "# that contains a configuration script generated by Automake, under"
725             echo "# the same distribution terms as the rest of that program."
726             echo "#"
727             echo "# Generated by gnulib-tool."
728             echo "#"
729             echo "# Invoked as: $cmd"
730             echo "# Reproduce by: $actioncmd"
731             echo
732             echo "AUTOMAKE_OPTIONS = 1.8 gnits"
733             echo
734             echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
735             echo
736             echo "${libname}_${libext}_SOURCES ="
737             echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
738             echo "EXTRA_DIST ="
739             echo "BUILT_SOURCES ="
740             echo "SUFFIXES ="
741             echo "MOSTLYCLEANFILES ="
742             echo "CLEANFILES ="
743             echo "DISTCLEANFILES ="
744             echo "MAINTAINERCLEANFILES ="
745             for module in $modules; do
746                 func_verify_module
747                 if test -n "$module"; then
748                     func_get_automake_snippet "$module" | sed -e "s,lib_SOURCES,${libname}_${libext}_SOURCES,g" -e "s,lib_OBJECTS,${libname}_${libext}_OBJECTS,g"
749                     if test "$module" = 'alloca'; then
750                         echo "${libname}_${libext}_LIBADD += @ALLOCA@"
751                     fi
752                 fi
753             done
754             echo
755             echo "# Makefile.am ends here"
756         )
757
758         # Create gnulib.m4.
759         echo "Creating $destdir/$m4base/gnulib.m4..."
760         (
761             if test -z "$dry_run"; then
762                 exec > $destdir/$m4base/gnulib.m4
763             else
764                 echo "# $destdir/$m4base/gnulib.m4"
765             fi
766             echo "# Copyright (C) 2004 Free Software Foundation, Inc."
767             echo "# This file is free software, distributed under the terms of the GNU"
768             echo "# General Public License.  As a special exception to the GNU General"
769             echo "# Public License, this file may be distributed as part of a program"
770             echo "# that contains a configuration script generated by Autoconf, under"
771             echo "# the same distribution terms as the rest of that program."
772             echo "#"
773             echo "# Generated by gnulib-tool."
774             echo "#"
775             echo "# Invoked as: $cmd"
776             echo "# Reproduce by: $actioncmd"
777             echo
778             echo "AC_DEFUN([gl_EARLY],"
779             echo "["
780             if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 > /dev/null; then
781                 echo "  AC_GNU_SOURCE"
782             fi
783             if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 > /dev/null; then
784                 echo "  gl_USE_SYSTEM_EXTENSIONS"
785             fi
786             echo "])"
787             echo
788             echo "AC_DEFUN([gl_INIT],"
789             echo "["
790             for module in $modules; do
791                 func_verify_module
792                 if test -n "$module"; then
793                     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./'
794                 fi
795             done
796             echo "])"
797             echo
798             echo "dnl Usage: gl_MODULES(module1 module2 ...)"
799             echo "AC_DEFUN([gl_MODULES], [])"
800             echo
801             echo "dnl Usage: gl_SOURCE_BASE(DIR)"
802             echo "AC_DEFUN([gl_SOURCE_BASE], [])"
803             echo
804             echo "dnl Usage: gl_M4_BASE(DIR)"
805             echo "AC_DEFUN([gl_M4_BASE], [])"
806             echo
807             echo "dnl Usage: gl_LIB(LIBNAME)"
808             echo "AC_DEFUN([gl_LIB], [])"
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-license )
942     for module
943     do
944       func_verify_module
945       if test -n "$module"; then
946         func_get_license "$module"
947       fi
948     done
949     ;;
950
951   extract-maintainer )
952     for module
953     do
954       func_verify_module
955       if test -n "$module"; then
956         func_get_maintainer "$module"
957       fi
958     done
959     ;;
960
961   * )
962     func_fatal_error "unknown operation mode --$mode" ;;
963 esac
964
965 exit 0