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