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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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-08-31 20:52:14 $'
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
59 gnulib-tool --extract-tests-module module
62 --list print the available module names
63 --import import the given modules into the current package
64 --create-testdir create a scratch package with the given modules
65 --create-megatestdir create a mega scratch package with the given modules
66 one by one and all together
67 --test test the combination of the given modules
68 (recommended to use CC=\"gcc -Wall\" here)
69 --megatest test the given modules one by one and all together
70 (recommended to use CC=\"gcc -Wall\" here)
71 --extract-description extract the description
72 --extract-filelist extract the list of files
73 --extract-dependencies extract the dependencies
74 --extract-autoconf-snippet extract the snippet for configure.ac
75 --extract-automake-snippet extract the snippet for lib/Makefile.am
76 --extract-include-directive extract the #include directive
77 --extract-license report the license terms of the source files
79 --extract-maintainer report the maintainer(s) inside gnulib
80 --extract-tests-module report the unit test module, if it exists
83 --dir=DIRECTORY specify the target directory
84 For --import, this specifies where your
85 configure.ac can be found. Defaults to current
87 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
88 --source-base=DIRECTORY
89 Directory relative --dir where source code is
90 placed (default \"lib\"), for --import.
91 --m4-base=DIRECTORY Directory relative --dir where *.m4 macros are
92 placed (default \"m4\"), for --import.
93 --tests-base=DIRECTORY
94 Directory relative --dir where unit tests are
95 placed (default \"tests\"), for --import.
96 --aux-dir=DIRECTORY Directory relative --dir where auxiliary build
97 tools are placed (default \"build-aux\").
98 --with-tests Include unit tests for the included modules.
99 --avoid=MODULE Avoid including the given MODULE. Useful if you
100 have code that provides equivalent functionality.
101 This option can be repeated.
102 --lgpl Abort if modules aren't available under the LGPL.
103 Also modify license template from GPL to LGPL.
104 --libtool Use libtool rules, for --import.
105 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
106 'gl_INIT'. Default is 'gl'.
107 --no-changelog don't update or create ChangeLog files
108 --dry-run For --import, only print what would have been done.
109 -s, --symbolic, --symlink Make symbolic links instead of copying files.
111 Report bugs to <bug-gnulib@gnu.org>."
115 # outputs to stdout the --version message.
118 echo "$progname (GNU $package) $version"
119 echo "Copyright (C) 2002-2005 Free Software Foundation, Inc.
120 This is free software; see the source for copying conditions. There is NO
121 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
122 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
125 # func_fatal_error message
126 # outputs to stderr a fatal error message, and terminates the program.
129 echo "gnulib-tool: *** $1" 1>&2
130 echo "gnulib-tool: *** Stop." 1>&2
134 # func_cp_if_changed SRC DEST
135 # Like cp, but avoids munging timestamps if the file hasn't changed.
136 # Uses also the variables
137 # - dry_run true if actions shall only be printed, blank otherwise
138 func_cp_if_changed ()
140 if test $# -ne 2; then
141 echo "usage: func_cp_if_changed SRC DEST" >&2
143 test -n "$dry_run" && dry=echo
144 if cmp "$1" "$2" >/dev/null 2>&1; then
151 # func_mv_if_changed SRC DEST
152 # Like mv, but avoids munging timestamps if the file hasn't changed.
153 # Removes SRC if it is not renamed.
154 # Uses also the variables
155 # - dry_run true if actions shall only be printed, blank otherwise
156 func_mv_if_changed ()
158 if test $# -ne 2; then
159 echo "usage: func_mv_if_changed SRC DEST" >&2
161 test -n "$dry_run" && dry=echo
162 if cmp "$1" "$2" >/dev/null 2>&1; then
169 # func_ln_if_changed SRC DEST
170 # Like ln -s, but avoids munging timestamps if the link is correct.
171 # Uses also the variables
172 # - dry_run true if actions shall only be printed, blank otherwise
173 func_ln_if_changed ()
175 if test $# -ne 2; then
176 echo "usage: func_ln_if_changed SRC DEST" >&2
178 test -n "$dry_run" && dry=echo
179 if test -L "$2" -a "$1" = "`readlink "$2"`"; then
187 # Command-line option processing.
188 # Removes the OPTIONS from the arguments. Sets the variables:
189 # - mode list or import or create-testdir or create-megatestdir
190 # - destdir from --dir
191 # - libname, supplied_libname from --lib
192 # - sourcebase from --source-base
193 # - m4base from --m4-base
194 # - testsbase from --tests-base
195 # - auxdir from --aux-dir
196 # - inctests true if --with-tests was given, blank otherwise
197 # - avoidlist list of modules to avoid, from --avoid
198 # - lgpl true if --lgpl was given, blank otherwise
199 # - libtool true if --libtool was given, blank otherwise
200 # - do_changelog false if --no-changelog was given, : otherwise
201 # - dry_run true if --dry-run was given, blank otherwise
222 while test $# -gt 0; do
227 --import | --impor | --impo | --imp | --im | --i )
230 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
233 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
234 mode=create-megatestdir
236 --test | --tes | --te | --t )
239 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
243 mode=`echo "X$1" | sed -e 's/^X--//'`
248 func_fatal_error "missing argument for --dir"
253 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
258 func_fatal_error "missing argument for --lib"
261 supplied_libname=true
264 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
265 supplied_libname=true
270 func_fatal_error "missing argument for --source-base"
275 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
280 func_fatal_error "missing argument for --m4-base"
285 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
290 func_fatal_error "missing argument for --tests-base"
295 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
300 func_fatal_error "missing argument for --aux-dir"
305 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
313 func_fatal_error "missing argument for --avoid"
315 avoidlist="$avoidlist $1"
318 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
329 func_fatal_error "missing argument for --macro-prefix"
334 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
336 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
342 -s | --symbolic | --symlink )
345 --help | --hel | --he | --h )
348 --version | --versio | --versi | --vers | --ver | --ve | --v )
352 # Stop option prcessing
356 echo "gnulib-tool: unknown option $1" 1>&2
357 echo "Try 'gnulib-tool --help' for more information." 1>&2
366 /*) self_abspathname="$0" ;;
367 */*) self_abspathname=`pwd`/"$0" ;;
368 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
369 if test -x "$d/$0" && test ! -d "$d/$0"; then
370 self_abspathname="$d/$0"
374 if test -z "$self_abspathname"; then
375 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
379 while test -h "$self_abspathname"; do
380 # Resolve symbolic link.
381 sedexpr1='s, -> ,#%%#,'
382 sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
383 linkval=`LC_ALL=C ls -l "$self_abspathname" | sed -e "$sedexpr1" | sed -n -e "$sedexpr2"`
384 test -n "$linkval" || break
386 /* ) self_abspathname="$linkval" ;;
387 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
390 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
395 # Filter out metainformation files like README, which are not modules.
396 # Filter out unit test modules; they can be retrieved through
397 # --extract-tests-module if desired.
398 (cd "$gnulib_dir/modules" && ls -1) \
399 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
400 | sed -e '/-tests$/d' \
405 # verifies a module name
406 func_verify_module ()
408 if test ! -f "$gnulib_dir/modules/$module" \
409 || test "CVS" = "$module" \
410 || test "ChangeLog" = "$module" \
411 || test "README" = "$module" \
412 || test "TEMPLATE" = "$module" \
413 || test "TEMPLATE-TESTS" = "$module"; then
414 echo "gnulib-tool: module $module doesn't exist" 1>&2
419 # func_verify_nontests_module
420 # verifies a module name, excluding tests modules
421 func_verify_nontests_module ()
425 * ) func_verify_module ;;
429 # func_verify_tests_module
430 # verifies a module name, considering only tests modules
431 func_verify_tests_module ()
434 *-tests ) func_verify_module ;;
439 sed_extract_prog=':[ ]*$/ {
442 s/^Description:[ ]*$//
444 s/^Depends-on:[ ]*$//
445 s/^configure\.ac:[ ]*$//
446 s/^Makefile\.am:[ ]*$//
449 s/^Maintainer:[ ]*$//
456 # func_get_description module
457 func_get_description ()
459 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
462 # func_get_filelist module
465 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
467 echo m4/onceonly_2_57.m4
470 # func_get_dependencies module
471 func_get_dependencies ()
473 # ${module}-tests always implicitly depends on ${module}.
474 echo "$1" | sed -n -e 's/-tests//p'
475 # Then the explicit dependencies listed in the module description.
476 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
479 # func_get_autoconf_snippet module
480 func_get_autoconf_snippet ()
482 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
485 # func_get_automake_snippet module
486 func_get_automake_snippet ()
488 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
491 # func_get_include_directive module
492 func_get_include_directive ()
494 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
495 sed -e 's/^\(["<]\)/#include \1/'
498 # func_get_license module
501 sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
504 # func_get_maintainer module
505 func_get_maintainer ()
507 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
510 # func_get_tests_module module
511 func_get_tests_module ()
513 # The naming convention for tests modules is hardwired: ${module}-tests.
514 if test -f modules/"$1"-tests; then
519 # func_acceptable module
520 # tests whether a module is acceptable.
522 # - avoidlist list of modules to avoid
525 for avoid in $avoidlist; do
526 if test "$avoid" = "$1"; then
533 # func_modules_transitive_closure
535 # - modules list of specified modules
536 # - inctests true if tests should be included, blank otherwise
537 # - avoidlist list of modules to avoid
539 # - modules list of modules, including dependencies
540 func_modules_transitive_closure ()
544 for module in $modules; do
546 if test -n "$module"; then
547 # Duplicate dependencies are harmless, but Jim wants a warning.
548 duplicated_deps=`func_get_dependencies $module | sort | uniq -d`
549 if test -n "$duplicated_deps"; then
550 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
552 if func_acceptable $module; then
553 xmodules="$xmodules $module"
554 for depmodule in `func_get_dependencies $module`; do
555 if func_acceptable $depmodule; then
556 xmodules="$xmodules $depmodule"
559 if test -n "$inctests"; then
560 testsmodule=`func_get_tests_module $module`
561 if test -n "$testsmodule"; then
562 if func_acceptable $testsmodule; then
563 xmodules="$xmodules $testsmodule"
564 for depmodule in `func_get_dependencies $testsmodule`; do
565 if func_acceptable $depmodule; then
566 xmodules="$xmodules $depmodule"
575 xmodules=`for m in $xmodules; do echo $m; done | sort | uniq`
576 if test "$xmodules" = "$modules"; then
583 # func_modules_to_filelist
585 # - modules list of modules, including dependencies
587 # - files list of files
588 func_modules_to_filelist ()
591 for module in $modules; do
593 if test -n "$module"; then
594 files="$files "`func_get_filelist $module`
597 files=`for f in $files; do echo $f; done | sort | uniq`
600 # func_emit_lib_Makefile_am
601 # emits the contents of lib/Makefile.am to standard output.
603 # - modules list of modules, including dependencies
604 # - libname library name
605 # - libtool true if libtool will be used, blank otherwise
606 # - cmd (optional) command that led to this invocation
607 # - actioncmd (optional) command that will reproduce this invocation
608 func_emit_lib_Makefile_am ()
610 if test -n "$libtool"; then
617 echo "## Process this file with automake to produce Makefile.in."
618 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
620 echo "# This file is free software, distributed under the terms of the GNU"
621 echo "# General Public License. As a special exception to the GNU General"
622 echo "# Public License, this file may be distributed as part of a program"
623 echo "# that contains a configuration script generated by Automake, under"
624 echo "# the same distribution terms as the rest of that program."
626 echo "# Generated by gnulib-tool."
627 if test -n "$cmd"; then
628 echo "# Invoked as: $cmd"
630 if test -n "$actioncmd"; then
631 echo "# Reproduce by: $actioncmd"
634 # No need to generate dependencies since the sources are in gnulib, not here.
635 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
637 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
639 echo "${libname}_${libext}_SOURCES ="
640 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
642 echo "BUILT_SOURCES ="
644 echo "MOSTLYCLEANFILES ="
646 echo "DISTCLEANFILES ="
647 echo "MAINTAINERCLEANFILES ="
649 for module in $modules; do
650 func_verify_nontests_module
651 if test -n "$module"; then
653 func_get_automake_snippet "$module" |
654 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
655 if test "$module" = 'alloca'; then
656 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
659 # Skip the contents if its entirely empty.
660 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
661 echo "## begin gnulib module $module"
664 echo "## end gnulib module $module"
671 echo "# Makefile.am ends here"
674 # func_emit_tests_Makefile_am
675 # emits the contents of tests/Makefile.am to standard output.
677 # - modules list of modules, including dependencies
678 # - libname library name
679 # - libtool true if libtool will be used, blank otherwise
680 # - sourcebase relative directory containing lib source code
681 func_emit_tests_Makefile_am ()
683 if test -n "$libtool"; then
688 echo "## Process this file with automake to produce Makefile.in."
689 echo "# Copyright (C) 2004-2005 Free Software Foundation, Inc."
691 echo "# This file is free software, distributed under the terms of the GNU"
692 echo "# General Public License. As a special exception to the GNU General"
693 echo "# Public License, this file may be distributed as part of a program"
694 echo "# that contains a configuration script generated by Automake, under"
695 echo "# the same distribution terms as the rest of that program."
697 echo "# Generated by gnulib-tool."
699 # Generate dependencies here, since it eases the debugging of test failures.
700 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
702 echo "ACLOCAL_AMFLAGS = -I ../m4"
705 echo "noinst_PROGRAMS ="
707 echo "BUILT_SOURCES ="
709 echo "MOSTLYCLEANFILES ="
711 echo "DISTCLEANFILES ="
712 echo "MAINTAINERCLEANFILES ="
714 echo "AM_CPPFLAGS = \\"
715 echo " -I. -I\$(srcdir) \\"
716 echo " -I.. -I\$(srcdir)/.. \\"
717 echo " -I../${sourcebase-lib} -I\$(srcdir)/../${sourcebase-lib}"
719 echo "LDADD = ../${sourcebase-lib}/${libname}.${libext}"
721 for module in $modules; do
722 func_verify_tests_module
723 if test -n "$module"; then
724 func_get_automake_snippet "$module" > amsnippet.tmp
725 # Skip the contents if its entirely empty.
726 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
727 echo "## begin gnulib module $module"
730 echo "## end gnulib module $module"
736 echo "# Clean up after Solaris cc."
738 echo " rm -rf SunWS_cache"
740 echo "# Makefile.am ends here"
743 # func_import modules
744 # Uses also the variables
745 # - destdir target directory
746 # - libname library name
747 # - sourcebase directory relative to destdir where to place source code
748 # - m4base directory relative to destdir where to place *.m4 macros
749 # - auxdir directory relative to destdir where to place build aux files
750 # - avoidlist list of modules to avoid, from --avoid
751 # - lgpl true if library's license shall be LGPL, blank otherwise
752 # - libtool true if libtool will be used, blank otherwise
753 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
754 # - dry_run true if actions shall only be printed, blank otherwise
755 # - symbolic true if files should be symlinked, copied otherwise
756 # - supplied_opts all options passed to gnulib-tool
760 modules=`for m in $modules; do echo $m; done | sort | uniq`
762 # Determine final module list.
763 func_modules_transitive_closure
764 echo "Module list with included dependencies:"
765 echo "$modules" | sed -e 's/^/ /'
767 # If --lgpl, check the license of modules are compatible.
768 if test -n "$lgpl"; then
769 for module in $modules; do
770 license=`func_get_license $module`
772 LGPL | 'public domain' | 'unlimited') ;;
775 "incompatible license on module \`$module\`: $license" ;;
780 # Determine final file list.
781 func_modules_to_filelist
783 echo "$files" | sed -e 's/^/ /'
786 || func_fatal_error "refusing to do nothing"
788 # Copy files or make symbolic links.
789 for f in $files m4/gnulib-tool.m4; do
792 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
793 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"`; source=true ;;
794 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
797 if test -z "$symbolic"; then
798 func_cp_if_changed "$gnulib_dir/$f" "$destdir/$g"
800 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
803 if test -z "$dry_run" && test -n "$lgpl" && test -n "$source"; then
804 perl -pi -e 's/GNU General/GNU Lesser General/g;' \
805 -e 's/version 2([ ,])/version 2.1\1/g' \
810 # Commands printed in a comment in generated files.
811 cmd="gnulib-tool $supplied_opts"
813 if test -n "$libtool"; then
814 opt_libtool="--libtool"
817 if test -n "$lgpl"; then
820 actioncmd="gnulib-tool --import --dir=$destdir --lib=$libname --source-base=$sourcebase --m4-base=$m4base --aux-dir=$auxdir $opt_libtool $opt_lgpl `echo $modules`"
822 # Create lib/Makefile.am.
823 echo "Creating $destdir/$sourcebase/Makefile.am..."
824 if test -z "$dry_run"; then
825 func_emit_lib_Makefile_am > "$destdir"/$sourcebase/Makefile.am.new
827 func_emit_lib_Makefile_am
829 func_mv_if_changed "$destdir"/$sourcebase/Makefile.am.new \
830 "$destdir"/$sourcebase/Makefile.am
833 echo "Creating $destdir/$m4base/gnulib.m4..."
835 if test -z "$dry_run"; then
836 exec > "$destdir"/$m4base/gnulib.m4.new
838 echo "# $destdir/$m4base/gnulib.m4"
840 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
841 echo "# This file is free software, distributed under the terms of the GNU"
842 echo "# General Public License. As a special exception to the GNU General"
843 echo "# Public License, this file may be distributed as part of a program"
844 echo "# that contains a configuration script generated by Autoconf, under"
845 echo "# the same distribution terms as the rest of that program."
847 echo "# Generated by gnulib-tool."
849 echo "# Invoked as: $cmd"
850 echo "# Reproduce by: $actioncmd"
852 echo "# This macro should be invoked from $configure_ac, in the section"
853 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
854 echo "# any checks for libraries, header files, types and library functions."
855 echo "AC_DEFUN([${macro_prefix}_EARLY],"
857 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 > /dev/null; then
858 echo " AC_REQUIRE([AC_GNU_SOURCE])"
860 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 > /dev/null; then
861 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
865 echo "# This macro should be invoked from $configure_ac, in the section"
866 echo "# \"Check for header files, types and library functions\"."
867 echo "AC_DEFUN([${macro_prefix}_INIT],"
869 for module in $modules; do
871 if test -n "$module"; then
872 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./'
873 if test "$module" = 'alloca' && test -n "$libtool"; then
874 echo 'changequote(,)dnl'
875 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
876 echo 'changequote([, ])dnl'
877 echo 'AC_SUBST([LTALLOCA])'
883 echo "# gnulib.m4 ends here"
885 func_mv_if_changed "$destdir"/$m4base/gnulib.m4.new "$destdir"/$m4base/gnulib.m4
888 echo "You may need to add #include directives for the following .h files."
889 for module in $modules; do
890 func_get_include_directive "$module"
891 done | LC_ALL=C sort -u | sed -e '/^$/d;' -e 's/^/ /'
893 echo "Don't forget to"
894 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
895 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
896 sourcebase_base=`basename "$sourcebase"`
897 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
898 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
899 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
900 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
903 # func_create_testdir testdir modules
905 # - auxdir directory relative to destdir where to place build aux files
906 func_create_testdir ()
910 modules=`for m in $modules; do echo $m; done | sort | uniq`
912 # Determine final module list.
913 func_modules_transitive_closure
914 echo "Module list with included dependencies:"
915 echo "$modules" | sed -e 's/^/ /'
917 # Determine final file list.
918 func_modules_to_filelist
920 echo "$files" | sed -e 's/^/ /'
922 # Create directories.
923 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
924 if test "$d" = build-aux; then
925 mkdir -p "$testdir/$auxdir"
927 mkdir -p "$testdir/$d"
931 # Copy files or make symbolic links.
934 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
937 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
938 if test -z "$symbolic"; then
939 cp -p "$gnulib_dir/$f" "$testdir/$g"
941 ln -s "$gnulib_dir/$f" "$testdir/$g"
945 # Create lib/Makefile.am.
946 mkdir -p "$testdir/lib"
947 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
949 # Create m4/Makefile.am.
950 mkdir -p "$testdir/m4"
951 (echo "## Process this file with automake to produce Makefile.in."
957 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
960 ) > "$testdir/m4/Makefile.am"
963 subdirs_with_configure_ac=""
965 if test -f "$testdir"/m4/gettext.m4; then
966 # Avoid stupid error message from automake:
967 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
968 mkdir -p "$testdir/po"
969 (echo "## Process this file with automake to produce Makefile.in."
970 ) > "$testdir/po/Makefile.am"
971 subdirs="$subdirs po"
974 if test -n "$inctests"; then
975 test -d "$testdir/tests" || mkdir "$testdir/tests"
976 # Create tests/Makefile.am.
978 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
979 # Create tests/configure.ac.
980 (echo "# Process this file with autoconf to produce a configure script."
981 echo "AC_INIT([dummy], [0])"
982 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
983 echo "AM_INIT_AUTOMAKE"
985 echo "AM_CONFIG_HEADER([config.h])"
988 echo "AC_PROG_INSTALL"
989 echo "AC_PROG_MAKE_SET"
990 echo "AC_PROG_RANLIB"
992 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
996 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
997 echo "gl_USE_SYSTEM_EXTENSIONS"
1000 # We don't have explicit ordering constraints between the various
1001 # autoconf snippets. It's cleanest to put those of the library before
1002 # those of the tests.
1003 for module in $modules; do
1004 func_verify_nontests_module
1005 if test -n "$module"; then
1006 func_get_autoconf_snippet "$module"
1009 for module in $modules; do
1010 func_verify_tests_module
1011 if test -n "$module"; then
1012 func_get_autoconf_snippet "$module"
1016 # Usually tests/config.h will be a superset of config.h. Verify this by
1017 # "merging" config.h into tests/config.h; look out for gcc warnings.
1018 echo "AH_TOP([#include \"../config.h\"])"
1020 echo "AC_OUTPUT([Makefile])"
1021 ) > "$testdir/tests/configure.ac"
1022 subdirs="$subdirs tests"
1023 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1026 # Create Makefile.am.
1027 (echo "## Process this file with automake to produce Makefile.in."
1029 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1031 echo "SUBDIRS = $subdirs"
1033 echo "ACLOCAL_AMFLAGS = -I m4"
1034 ) > "$testdir/Makefile.am"
1036 # Create configure.ac.
1037 (echo "# Process this file with autoconf to produce a configure script."
1038 echo "AC_INIT([dummy], [0])"
1039 if test "$auxdir" != "."; then
1040 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1042 echo "AM_INIT_AUTOMAKE"
1044 echo "AM_CONFIG_HEADER([config.h])"
1047 echo "AC_PROG_INSTALL"
1048 echo "AC_PROG_MAKE_SET"
1049 echo "AC_PROG_RANLIB"
1051 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
1052 echo "AC_GNU_SOURCE"
1055 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
1056 echo "gl_USE_SYSTEM_EXTENSIONS"
1059 for module in $modules; do
1060 func_verify_nontests_module
1061 if test -n "$module"; then
1062 func_get_autoconf_snippet "$module"
1066 if test -n "$subdirs_with_configure_ac"; then
1067 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1069 makefiles="Makefile"
1070 for d in $subdirs; do
1071 # For subdirs that have a configure.ac by their own, it's the subdir's
1072 # configure.ac which creates the subdir's Makefile.am, not this one.
1073 case " $subdirs_with_configure_ac " in
1075 *) makefiles="$makefiles $d/Makefile" ;;
1078 echo "AC_OUTPUT([$makefiles])"
1079 ) > "$testdir/configure.ac"
1081 # Create autogenerated files.
1083 echo "executing ${AUTORECONF} --force --install"
1084 ${AUTORECONF} --force --install
1086 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1090 built_sources=`grep '^BUILT_SOURCES *=' Makefile.in | sed -e 's/^BUILT_SOURCES *=//'`
1091 if test -n "$built_sources"; then
1100 # func_create_megatestdir megatestdir allmodules
1102 # - auxdir directory relative to destdir where to place build aux files
1103 func_create_megatestdir ()
1107 if test -z "$allmodules"; then
1108 allmodules=`func_all_modules`
1112 # First, all modules one by one.
1113 for onemodule in $allmodules; do
1114 func_create_testdir "$megatestdir/$onemodule" $onemodule
1115 megasubdirs="${megasubdirs}$onemodule "
1117 # Then, all modules all together.
1118 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1119 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1120 func_create_testdir "$megatestdir/ALL" "$allmodules"
1121 megasubdirs="${megasubdirs}ALL"
1123 # Create Makefile.am.
1124 (echo "## Process this file with automake to produce Makefile.in."
1126 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1128 echo "SUBDIRS = $megasubdirs"
1129 ) > "$megatestdir/Makefile.am"
1131 # Create configure.ac.
1132 (echo "# Process this file with autoconf to produce a configure script."
1133 echo "AC_INIT([dummy], [0])"
1134 if test "$auxdir" != "."; then
1135 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1137 echo "AM_INIT_AUTOMAKE"
1139 echo "AC_PROG_MAKE_SET"
1141 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1142 echo "AC_OUTPUT([Makefile])"
1143 ) > "$megatestdir/configure.ac"
1145 # Create autogenerated files.
1147 echo "executing ${AUTORECONF} --install"
1148 ${AUTORECONF} --install
1154 func_fatal_error "no mode specified" ;;
1162 if test -z "$destdir"; then
1165 test -d "$destdir" \
1166 || func_fatal_error "destination directory does not exist: $destdir"
1168 # Prefer configure.ac to configure.in
1169 test -f "$destdir"/configure.in && configure_ac="$destdir/configure.in"
1170 test -f "$destdir"/configure.ac && configure_ac="$destdir/configure.ac"
1171 test -f "$configure_ac" \
1172 || func_fatal_error "cannot find $destdir/configure.ac"
1175 my_sed_traces='s,#.*$,,; s,^dnl .*$,,; s, dnl .*$,,;
1177 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_modules="\1",; p;
1180 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",; p;
1183 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",; p;
1186 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",; p;
1189 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",; p;
1191 /AC_CONFIG_AUX_DIR/ {
1192 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,ac_auxdir="\1",; p;
1194 /A[CM]_PROG_LIBTOOL/ { s,^.*$,seen_libtool=:,; p; };
1195 /LT_INIT/ { s,^.*$,seen_libtool=:,; p; };
1196 /gl_LGPL/ { s,^.*$,cached_lgpl=true,; p; };
1197 /gl_LIBTOOL/ { s,^.*$,cached_libtool=:,; p; };
1199 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",; p;
1202 eval `cat $configure_ac | sed "$my_sed_traces"`
1205 if test -z "$supplied_libname" && test -n "$cached_libname"; then
1206 libname="$cached_libname"
1209 # Set up source base.
1210 test -z "$sourcebase" && sourcebase="$cached_sourcebase"
1211 test -z "$sourcebase" && sourcebase="lib"
1212 test -d "$destdir/$sourcebase" \
1213 || { test -z "$dry_run" && mkdir "$destdir/$sourcebase"; } \
1214 || func_fatal_error "source base $destdir/$sourcebase doesn't exist"
1217 test -z "$m4base" && m4base="$cached_m4base"
1218 test -z "$m4base" && m4base="m4"
1219 test -d "$destdir/$m4base" \
1220 || { test -z "$dry_run" && mkdir "$destdir/$m4base"; } \
1221 || func_fatal_error "m4 base $destdir/$m4base doesn't exist"
1223 # Set up auxiliary directory.
1224 test -z "$auxdir" && auxdir="$ac_auxdir"
1225 test -z "$auxdir" && auxdir="build-aux"
1226 test -d "$destdir/$auxdir" \
1227 || { test -z "$dry_run" && mkdir "$destdir/$auxdir"; } \
1228 || func_fatal_error "aux directory $destdir/$auxdir doesn't exist"
1231 if test -n "$cached_lgpl"; then
1236 if test -n "$seen_libtool" || test -n "$cached_libtool"; then
1241 test -z "$macro_prefix" && macro_prefix="$cached_macro_prefix"
1242 test -z "$macro_prefix" && macro_prefix="gl"
1244 # What modules to extract.
1245 if test $# = 0; then
1246 modules="$cached_modules"
1251 # Which modules to avoid?
1252 avoidlist=`echo $avoidlist $cached_avoidlist`
1254 func_import "$modules"
1258 if test -z "$destdir"; then
1259 func_fatal_error "please specify --dir option"
1262 test -d "$destdir" \
1263 || func_fatal_error "could not create destination directory"
1264 test -n "$auxdir" || auxdir="build-aux"
1265 func_create_testdir "$destdir" "$*"
1268 create-megatestdir )
1269 if test -z "$destdir"; then
1270 func_fatal_error "please specify --dir option"
1272 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1273 test -n "$auxdir" || auxdir="build-aux"
1274 func_create_megatestdir "$destdir" "$*"
1278 test -n "$destdir" || destdir=testdir$$
1279 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1280 test -n "$auxdir" || auxdir="build-aux"
1281 func_create_testdir "$destdir" "$*"
1289 remaining=`find . -type f -print`
1290 if test -n "$remaining"; then
1291 echo "Remaining files:" $remaining 1>&2
1292 echo "gnulib-tool: *** Stop." 1>&2
1301 test -n "$destdir" || destdir=testdir$$
1302 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1303 test -n "$auxdir" || auxdir="build-aux"
1304 func_create_megatestdir "$destdir" "$*"
1312 remaining=`find . -type f -print`
1313 if test -n "$remaining"; then
1314 echo "Remaining files:" $remaining 1>&2
1315 echo "gnulib-tool: *** Stop." 1>&2
1323 extract-description )
1327 if test -n "$module"; then
1328 func_get_description "$module"
1337 if test -n "$module"; then
1338 func_get_filelist "$module"
1343 extract-dependencies )
1347 if test -n "$module"; then
1348 func_get_dependencies "$module"
1353 extract-autoconf-snippet )
1357 if test -n "$module"; then
1358 func_get_autoconf_snippet "$module"
1363 extract-automake-snippet )
1367 if test -n "$module"; then
1368 func_get_automake_snippet "$module"
1373 extract-include-directive )
1377 if test -n "$module"; then
1378 func_get_include_directive "$module"
1387 if test -n "$module"; then
1388 func_get_license "$module"
1393 extract-maintainer )
1397 if test -n "$module"; then
1398 func_get_maintainer "$module"
1403 extract-tests-module )
1407 if test -n "$module"; then
1408 func_get_tests_module "$module"
1414 func_fatal_error "unknown operation mode --$mode" ;;