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