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