3 # Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
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)
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.
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.
20 # This program is meant for authors or maintainers which want to import
21 # modules from gnulib into their packages.
25 cvsdatestamp='$Date: 2005-03-04 19:36:42 $'
26 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
27 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
29 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
33 # AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
34 # AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
38 AUTORECONF="${AUTOCONFPATH}autoreconf"
41 # outputs to stdout the --help usage message.
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
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
78 --extract-maintainer report the maintainer(s) inside gnulib
81 --dir=DIRECTORY specify the target directory
82 For --import, this specifies where your
83 configure.ac can be found. Defaults to current
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 --lgpl Abort if modules aren't available under the LGPL.
92 Also modify license template from GPL to LGPL.
93 --libtool Use libtool rules, for --import.
94 --no-changelog don't update or create ChangeLog files
95 --dry-run For --import, only print what would have been done.
97 Report bugs to <bug-gnulib@gnu.org>."
101 # outputs to stdout the --version message.
104 echo "$progname (GNU $package) $version"
105 echo "Copyright (C) 2002 Free Software Foundation, Inc.
106 This is free software; see the source for copying conditions. There is NO
107 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
108 echo "Written by" "Bruno Haible"
111 # func_fatal_error message
112 # outputs to stderr a fatal error message, and terminates the program.
115 echo "gnulib-tool: *** $1" 1>&2
116 echo "gnulib-tool: *** Stop." 1>&2
120 # func_cp_if_changed SRC DEST
121 # Like cp, but avoids munging timestamps if the file hasn't changed.
122 # Uses also the variables
123 # - dry_run true if actions shall only be printed, blank otherwise
124 func_cp_if_changed ()
126 if test $# -ne 2; then
127 echo "usage: func_cp_if_changed SRC DEST" >&2
129 test -n "$dry_run" && dry=echo
130 if cmp "$1" "$2" >/dev/null 2>&1; then
137 # func_mv_if_changed SRC DEST
138 # Like mv, but avoids munging timestamps if the file hasn't changed.
139 # Removes SRC if it is not renamed.
140 # Uses also the variables
141 # - dry_run true if actions shall only be printed, blank otherwise
142 func_mv_if_changed ()
144 if test $# -ne 2; then
145 echo "usage: func_mv_if_changed SRC DEST" >&2
147 test -n "$dry_run" && dry=echo
148 if cmp "$1" "$2" >/dev/null 2>&1; then
155 # Command-line option processing.
156 # Removes the OPTIONS from the arguments. Sets the variables:
157 # - mode list or import or create-testdir or create-megatestdir
158 # - destdir from --dir
159 # - libname, supplied_libname from --lib
160 # - sourcebase from --source-base
161 # - m4base from --m4-base
162 # - libtool true if --libtool was given, blank otherwise
163 # - lgpl true if --lgpl was given, blank otherwise
164 # - do_changelog false if --no-changelog was given, : otherwise
165 # - dry_run true if --dry-run was given, blank otherwise
181 while test $# -gt 0; do
186 --import | --impor | --impo | --imp | --im | --i )
189 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
192 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
193 mode=create-megatestdir
195 --test | --tes | --te | --t )
198 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
202 mode=`echo "X$1" | sed -e 's/^X--//'`
207 func_fatal_error "missing argument for --dir"
212 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
217 func_fatal_error "missing argument for --lib"
220 supplied_libname=true
223 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
224 supplied_libname=true
229 func_fatal_error "missing argument for --source-base"
234 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
239 func_fatal_error "missing argument for --m4-base"
244 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
252 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
258 --help | --hel | --he | --h )
261 --version | --versio | --versi | --vers | --ver | --ve | --v )
265 # Stop option prcessing
269 echo "gnulib-tool: unknown option $1" 1>&2
270 echo "Try 'gnulib-tool --help' for more information." 1>&2
279 /*) self_abspathname="$0" ;;
280 */*) self_abspathname=`pwd`/"$0" ;;
281 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
282 if test -x "$d/$0" && test ! -d "$d/$0"; then
283 self_abspathname="$d/$0"
287 if test -z "$self_abspathname"; then
288 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
292 while test -h "$self_abspathname"; do
293 # Resolve symbolic link.
294 sedexpr1='s, -> ,#%%#,'
295 sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
296 linkval=`LC_ALL=C ls -l "$self_abspathname" | sed -e "$sedexpr1" | sed -n -e "$sedexpr2"`
297 test -n "$linkval" || break
299 /* ) self_abspathname="$linkval" ;;
300 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
303 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
308 (cd "$gnulib_dir/modules" && ls -1) \
309 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/~$/d' \
314 # verifies a module name
315 func_verify_module ()
317 if test ! -f "$gnulib_dir/modules/$module" \
318 || test "CVS" = "$module" \
319 || test "ChangeLog" = "$module" \
320 || test "README" = "$module" \
321 || test "TEMPLATE" = "$module"; then
322 echo "gnulib-tool: module $module doesn't exist" 1>&2
327 sed_extract_prog=':[ ]*$/ {
330 s/^Description:[ ]*$//
332 s/^Depends-on:[ ]*$//
333 s/^configure\.ac:[ ]*$//
334 s/^Makefile\.am:[ ]*$//
337 s/^Maintainer:[ ]*$//
344 # func_get_description module
345 func_get_description ()
347 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
350 # func_get_filelist module
353 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
355 echo m4/onceonly_2_57.m4
358 # func_get_dependencies module
359 func_get_dependencies ()
361 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
364 # func_get_autoconf_snippet module
365 func_get_autoconf_snippet ()
367 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
370 # func_get_automake_snippet module
371 func_get_automake_snippet ()
373 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
376 # func_get_include_directive module
377 func_get_include_directive ()
379 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
380 sed -e 's/^\(["<]\)/#include \1/'
383 # func_get_license module
386 sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
389 # func_get_maintainer module
390 func_get_maintainer ()
392 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
395 # func_modules_transitive_closure
397 # - modules list of specified modules
399 # - modules list of modules, including dependencies
400 func_modules_transitive_closure ()
404 for module in $modules; do
406 if test -n "$module"; then
407 # Duplicate dependenies are harmless, but Jim wants a warning.
408 duplicated_deps=`func_get_dependencies $module | sort | uniq -d`
409 if test -n "$duplicated_deps"; then
410 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
412 xmodules="$xmodules $module "`func_get_dependencies $module`
415 xmodules=`for m in $xmodules; do echo $m; done | sort | uniq`
416 if test "$xmodules" = "$modules"; then
423 # func_modules_to_filelist
425 # - modules list of modules, including dependencies
427 # - files list of files
428 func_modules_to_filelist ()
431 for module in $modules; do
433 if test -n "$module"; then
434 files="$files "`func_get_filelist $module`
437 files=`for f in $files; do echo $f; done | sort | uniq`
440 # func_emit_lib_Makefile_am
441 # emits the contents of lib/Makefile.am to standard output.
443 # - modules list of modules, including dependencies
444 # - libname library name
445 # - libtool true if libtool will be used, blank otherwise
446 # - cmd (optional) command that led to this invocation
447 # - actioncmd (optional) command that will reproduce this invocation
448 func_emit_lib_Makefile_am ()
450 if test -n "$libtool"; then
457 echo "## Process this file with automake to produce Makefile.in."
458 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
460 echo "# This file is free software, distributed under the terms of the GNU"
461 echo "# General Public License. As a special exception to the GNU General"
462 echo "# Public License, this file may be distributed as part of a program"
463 echo "# that contains a configuration script generated by Automake, under"
464 echo "# the same distribution terms as the rest of that program."
466 echo "# Generated by gnulib-tool."
467 if test -n "$cmd"; then
468 echo "# Invoked as: $cmd"
470 if test -n "$actioncmd"; then
471 echo "# Reproduce by: $actioncmd"
474 # No need to generate dependencies since the sources are in gnulib, not here.
475 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
477 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
479 echo "${libname}_${libext}_SOURCES ="
480 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
482 echo "BUILT_SOURCES ="
484 echo "MOSTLYCLEANFILES ="
486 echo "DISTCLEANFILES ="
487 echo "MAINTAINERCLEANFILES ="
489 for module in $modules; do
491 if test -n "$module"; then
493 func_get_automake_snippet "$module" |
494 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
495 if test "$module" = 'alloca'; then
496 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
499 # Skip the contents if its entirely empty.
500 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
501 echo "## begin gnulib module $module"
504 echo "## end gnulib module $module"
511 echo "# Makefile.am ends here"
514 # func_import modules
515 # Uses also the variables
516 # - destdir target directory
517 # - libname library name
518 # - sourcebase directory relative to destdir where to place source code
519 # - m4base directory relative to destdir where to place *.m4 macros
520 # - libtool true if libtool will be used, blank otherwise
521 # - lgpl true if library's license shall be LGPL, blank otherwise
522 # - dry_run true if actions shall only be printed, blank otherwise
523 # - supplied_opts all options passed to gnulib-tool
527 modules=`for m in $modules; do echo $m; done | sort | uniq`
529 # Determine final module list.
530 func_modules_transitive_closure
531 echo "Module list with included dependencies:"
532 echo "$modules" | sed -e 's/^/ /'
534 # If --lgpl, check the license of modules are compatible.
535 if test -n "$lgpl"; then
536 for module in $modules; do
537 license=`func_get_license $module`
538 if test $license != LGPL; then
539 func_fatal_error "incompatible license on module \`$module\`: $license"
544 # Determine final file list.
545 func_modules_to_filelist
547 echo "$files" | sed -e 's/^/ /'
550 || func_fatal_error "refusing to do nothing"
556 config/*) g=`echo "$f" | sed -e 's,^config/,,'` ;;
557 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"`; source=true ;;
558 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
561 func_cp_if_changed "$gnulib_dir/$f" "$destdir/$g"
563 if test -z "$dry_run" && test -n "$lgpl" && test -n "$source"; then
564 perl -pi -e 's/GNU General/GNU Lesser General/g;' \
565 -e 's/version 2([ ,])/version 2.1\1/g' \
570 # Commands printed in a comment in generated files.
571 cmd="gnulib-tool $supplied_opts"
573 if test -n "$libtool"; then
574 opt_libtool="--libtool"
577 if test -n "$lgpl"; then
580 actioncmd="gnulib-tool --import --dir=$destdir --lib=$libname --source-base=$sourcebase --m4-base=$m4base $opt_libtool $opt_lgpl `echo $modules`"
582 # Create lib/Makefile.am.
583 echo "Creating $destdir/$sourcebase/Makefile.am..."
584 if test -z "$dry_run"; then
585 func_emit_lib_Makefile_am > $destdir/$sourcebase/Makefile.am.new
587 func_emit_lib_Makefile_am
589 func_mv_if_changed $destdir/$sourcebase/Makefile.am.new \
590 $destdir/$sourcebase/Makefile.am
593 echo "Creating $destdir/$m4base/gnulib.m4..."
595 if test -z "$dry_run"; then
596 exec > $destdir/$m4base/gnulib.m4.new
598 echo "# $destdir/$m4base/gnulib.m4"
600 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
601 echo "# This file is free software, distributed under the terms of the GNU"
602 echo "# General Public License. As a special exception to the GNU General"
603 echo "# Public License, this file may be distributed as part of a program"
604 echo "# that contains a configuration script generated by Autoconf, under"
605 echo "# the same distribution terms as the rest of that program."
607 echo "# Generated by gnulib-tool."
609 echo "# Invoked as: $cmd"
610 echo "# Reproduce by: $actioncmd"
612 echo "AC_DEFUN([gl_EARLY],"
614 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 > /dev/null; then
615 echo " AC_GNU_SOURCE"
617 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 > /dev/null; then
618 echo " gl_USE_SYSTEM_EXTENSIONS"
622 echo "AC_DEFUN([gl_INIT],"
624 for module in $modules; do
626 if test -n "$module"; then
627 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./'
628 if test "$module" = 'alloca' && test -n "$libtool"; then
629 echo 'changequote(,)dnl'
630 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
631 echo 'changequote([, ])dnl'
632 echo 'AC_SUBST(LTALLOCA)'
638 echo "dnl Usage: gl_MODULES(module1 module2 ...)"
639 echo "AC_DEFUN([gl_MODULES], [])"
641 echo "dnl Usage: gl_SOURCE_BASE(DIR)"
642 echo "AC_DEFUN([gl_SOURCE_BASE], [])"
644 echo "dnl Usage: gl_M4_BASE(DIR)"
645 echo "AC_DEFUN([gl_M4_BASE], [])"
647 echo "dnl Usage: gl_LIB(LIBNAME)"
648 echo "AC_DEFUN([gl_LIB], [])"
650 echo "dnl Usage: gl_LGPL"
651 echo "AC_DEFUN([gl_LGPL], [])"
653 echo "# gnulib.m4 ends here"
655 func_mv_if_changed $destdir/$m4base/gnulib.m4.new $destdir/$m4base/gnulib.m4
658 echo "You may need to add #include directives for the following .h files."
659 for module in $modules; do
660 func_get_include_directive "$module" | sed -e '/^$/d;' -e 's/^/ /'
663 echo "Don't forget to add \"$sourcebase/Makefile\""
664 echo "to AC_CONFIG_FILES in \"$configure_ac\" and to mention"
665 echo "\"`basename $sourcebase`\" in SUBDIRS in some Makefile.am."
668 # func_create_testdir testdir modules
669 func_create_testdir ()
673 modules=`for m in $modules; do echo $m; done | sort | uniq`
675 # Determine final module list.
676 func_modules_transitive_closure
677 echo "Module list with included dependencies:"
678 echo "$modules" | sed -e 's/^/ /'
680 # Determine final file list.
681 func_modules_to_filelist
683 echo "$files" | sed -e 's/^/ /'
685 # Create directories.
686 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
687 if test "$d" != config; then
688 mkdir -p "$testdir/$d"
695 config/*) g=`echo "$f" | sed -e 's,^config/,,'` ;;
698 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
699 cp -p "$gnulib_dir/$f" "$testdir/$g"
702 # Create lib/Makefile.am.
703 mkdir -p "$testdir/lib"
704 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
706 # Create m4/Makefile.am.
707 mkdir -p "$testdir/m4"
708 (echo "## Process this file with automake to produce Makefile.in."
714 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
717 ) > "$testdir/m4/Makefile.am"
721 if test -f "$testdir"/m4/gettext.m4; then
722 # Avoid stupid error message from automake:
723 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
724 mkdir -p "$testdir/po"
725 (echo "## Process this file with automake to produce Makefile.in."
726 ) > "$testdir/po/Makefile.am"
727 subdirs="$subdirs po"
730 # Create Makefile.am.
731 (echo "## Process this file with automake to produce Makefile.in."
733 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
735 echo "SUBDIRS = $subdirs"
737 echo "ACLOCAL_AMFLAGS = -I m4"
738 ) > "$testdir/Makefile.am"
740 # Create configure.ac.
741 (echo "# Process this file with autoconf to produce a configure script."
742 echo "AC_INIT(dummy,0)"
743 echo "AM_INIT_AUTOMAKE"
745 echo "AM_CONFIG_HEADER(config.h)"
748 echo "AC_PROG_INSTALL"
749 echo "AC_PROG_MAKE_SET"
750 echo "AC_PROG_RANLIB"
752 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
756 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
757 echo "gl_USE_SYSTEM_EXTENSIONS"
760 for module in $modules; do
762 if test -n "$module"; then
763 func_get_autoconf_snippet "$module"
768 for d in $subdirs; do
769 makefiles="$makefiles $d/Makefile"
771 echo "AC_OUTPUT([$makefiles])"
772 ) > "$testdir/configure.ac"
774 # Create autogenerated files.
776 echo "executing ${AUTORECONF} --force --install"
777 ${AUTORECONF} --force --install
779 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
783 built_sources=`grep '^BUILT_SOURCES *=' Makefile.in | sed -e 's/^BUILT_SOURCES *=//'`
784 if test -n "$built_sources"; then
793 # func_create_megatestdir megatestdir allmodules
794 func_create_megatestdir ()
798 if test -z "$allmodules"; then
799 allmodules=`func_all_modules`
803 # First, all modules one by one.
804 for onemodule in $allmodules; do
805 func_create_testdir "$megatestdir/$onemodule" $onemodule
806 megasubdirs="${megasubdirs}$onemodule "
808 # Then, all modules all together.
809 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
810 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
811 func_create_testdir "$megatestdir/ALL" "$allmodules"
812 megasubdirs="${megasubdirs}ALL"
814 # Create Makefile.am.
815 (echo "## Process this file with automake to produce Makefile.in."
817 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
819 echo "SUBDIRS = $megasubdirs"
820 ) > "$megatestdir/Makefile.am"
822 # Create configure.ac.
823 (echo "# Process this file with autoconf to produce a configure script."
824 echo "AC_INIT(dummy,0)"
825 echo "AM_INIT_AUTOMAKE"
827 echo "AC_PROG_MAKE_SET"
829 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
830 echo "AC_OUTPUT([Makefile])"
831 ) > "$megatestdir/configure.ac"
833 # Create autogenerated files.
835 echo "executing ${AUTORECONF} --force --install"
836 ${AUTORECONF} --force --install
842 func_fatal_error "no mode specified" ;;
850 if test -z "$destdir"; then
854 || func_fatal_error "destination directory does not exist: $destdir"
856 # Prefer configure.ac to configure.in
857 test -f $destdir/configure.in && configure_ac=$destdir/configure.in
858 test -f $destdir/configure.ac && configure_ac=$destdir/configure.ac
859 test -f "$configure_ac" \
860 || func_fatal_error "cannot find $destdir/configure.ac"
863 my_sed_traces='s,#.*$,,; s,^dnl .*$,,; s, dnl .*$,,;
865 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,ac_modules="\1",; p;
868 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,ac_sourcebase="\1",; p;
871 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,ac_m4base="\1",; p;
874 s,^.*gl_LIB([[ ]*\([^])]*\).*$,ac_libname="\1",; p;
876 /A[CM]_PROG_LIBTOOL/ { s,^.*$,seen_libtool=:,; p; };
877 /LT_INIT/ { s,^.*$,seen_libtool=:,; p; };
878 /gl_LGPL/ { s,^.*$,lgpl=true,; p; };
880 eval `cat $configure_ac | sed "$my_sed_traces"`
883 if test -z "$supplied_libname" && test -n "$ac_libname"; then
884 libname="$ac_libname"
887 # Set up source base.
888 test -z "$sourcebase" && sourcebase="$ac_sourcebase"
889 test -z "$sourcebase" && sourcebase="lib"
890 test -d "$destdir/$sourcebase" \
891 || (test -z "$dry_run" && mkdir "$destdir/$sourcebase") \
892 || func_fatal_error "source base $destdir/$sourcebase doesn't exist"
895 test -z "$m4base" && m4base="$ac_m4base"
896 test -z "$m4base" && m4base="m4"
897 test -d "$destdir/$m4base" \
898 || (test -z "$dry_run" && mkdir "$destdir/$m4base") \
899 || func_fatal_error "m4 base $destdir/$m4base doesn't exist"
902 if test -n "$seen_libtool"; then
906 # What modules to extract.
908 modules="$ac_modules"
913 func_import "$modules"
917 if test -z "$destdir"; then
918 func_fatal_error "please specify --dir option"
922 || func_fatal_error "could not create destination directory"
923 func_create_testdir "$destdir" "$*"
927 if test -z "$destdir"; then
928 func_fatal_error "please specify --dir option"
930 mkdir "$destdir" || func_fatal_error "could not create destination directory"
931 func_create_megatestdir "$destdir" "$*"
935 test -n "$destdir" || destdir=testdir$$
936 mkdir "$destdir" || func_fatal_error "could not create destination directory"
937 func_create_testdir "$destdir" "$*"
945 remaining=`find . -type f -print`
946 if test -n "$remaining"; then
947 echo "Remaining files:" $remaining 1>&2
948 echo "gnulib-tool: *** Stop." 1>&2
957 test -n "$destdir" || destdir=testdir$$
958 mkdir "$destdir" || func_fatal_error "could not create destination directory"
959 func_create_megatestdir "$destdir" "$*"
967 remaining=`find . -type f -print`
968 if test -n "$remaining"; then
969 echo "Remaining files:" $remaining 1>&2
970 echo "gnulib-tool: *** Stop." 1>&2
978 extract-description )
982 if test -n "$module"; then
983 func_get_description "$module"
992 if test -n "$module"; then
993 func_get_filelist "$module"
998 extract-dependencies )
1002 if test -n "$module"; then
1003 func_get_dependencies "$module"
1008 extract-autoconf-snippet )
1012 if test -n "$module"; then
1013 func_get_autoconf_snippet "$module"
1018 extract-automake-snippet )
1022 if test -n "$module"; then
1023 func_get_automake_snippet "$module"
1028 extract-include-directive )
1032 if test -n "$module"; then
1033 func_get_include_directive "$module"
1042 if test -n "$module"; then
1043 func_get_license "$module"
1048 extract-maintainer )
1052 if test -n "$module"; then
1053 func_get_maintainer "$module"
1059 func_fatal_error "unknown operation mode --$mode" ;;