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