3 # Copyright (C) 2002-2006 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 Foundation,
17 # 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: 2006-06-23 19:27:17 $'
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 # You can set AUTOMAKEPATH to empty if automake 1.9.x is already in your PATH.
41 # If you didn't set AUTOCONFPATH and AUTOMAKEPATH, you can also set the
42 # variables AUTOCONF, ACLOCAL, AUTOMAKE, AUTORECONF individually.
43 if test -z "${AUTOCONF}" || test -n "${AUTOCONFPATH}"; then
44 AUTOCONF="${AUTOCONFPATH}autoconf"
46 if test -z "${ACLOCAL}" || test -n "${AUTOMAKEPATH}"; then
47 ACLOCAL="${AUTOMAKEPATH}aclocal"
49 if test -z "${AUTOMAKE}" || test -n "${AUTOMAKEPATH}"; then
50 AUTOMAKE="${AUTOMAKEPATH}automake"
52 if test -z "${AUTORECONF}" || test -n "${AUTOCONFPATH}"; then
53 AUTORECONF="${AUTOCONFPATH}autoreconf"
57 # outputs to stdout the --help usage message.
61 Usage: gnulib-tool --list
62 gnulib-tool --import [module1 ... moduleN]
64 gnulib-tool --create-testdir --dir=directory module1 ... moduleN
65 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
66 gnulib-tool --test --dir=directory module1 ... moduleN
67 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
68 gnulib-tool --extract-description module
69 gnulib-tool --extract-filelist module
70 gnulib-tool --extract-dependencies module
71 gnulib-tool --extract-autoconf-snippet module
72 gnulib-tool --extract-automake-snippet module
73 gnulib-tool --extract-include-directive module
74 gnulib-tool --extract-license module
75 gnulib-tool --extract-maintainer module
76 gnulib-tool --extract-tests-module module
79 --list print the available module names
80 --import import the given modules into the current package;
81 if no modules are specified, update the current
82 package from the current gnulib
83 --update update the current package, restore files omitted
85 --create-testdir create a scratch package with the given modules
86 --create-megatestdir create a mega scratch package with the given modules
87 one by one and all together
88 --test test the combination of the given modules
89 (recommended to use CC=\"gcc -Wall\" here)
90 --megatest test the given modules one by one and all together
91 (recommended to use CC=\"gcc -Wall\" here)
92 --extract-description extract the description
93 --extract-filelist extract the list of files
94 --extract-dependencies extract the dependencies
95 --extract-autoconf-snippet extract the snippet for configure.ac
96 --extract-automake-snippet extract the snippet for lib/Makefile.am
97 --extract-include-directive extract the #include directive
98 --extract-license report the license terms of the source files
100 --extract-maintainer report the maintainer(s) inside gnulib
101 --extract-tests-module report the unit test module, if it exists
104 --dir=DIRECTORY specify the target directory
105 For --import, this specifies where your
106 configure.ac can be found. Defaults to current
108 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
109 --source-base=DIRECTORY
110 Directory relative --dir where source code is
111 placed (default \"lib\"), for --import.
112 --m4-base=DIRECTORY Directory relative --dir where *.m4 macros are
113 placed (default \"m4\"), for --import.
114 --tests-base=DIRECTORY
115 Directory relative --dir where unit tests are
116 placed (default \"tests\"), for --import.
117 --aux-dir=DIRECTORY Directory relative --dir where auxiliary build
118 tools are placed (default \"build-aux\").
119 --with-tests Include unit tests for the included modules.
120 --avoid=MODULE Avoid including the given MODULE. Useful if you
121 have code that provides equivalent functionality.
122 This option can be repeated.
123 --lgpl Abort if modules aren't available under the LGPL.
124 Also modify license template from GPL to LGPL.
125 --libtool Use libtool rules, for --import.
126 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
127 'gl_INIT'. Default is 'gl'.
128 --no-changelog don't update or create ChangeLog files
129 --dry-run For --import, only print what would have been done.
130 -s, --symbolic, --symlink Make symbolic links instead of copying files.
132 Report bugs to <bug-gnulib@gnu.org>."
136 # outputs to stdout the --version message.
139 year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
140 echo "$progname (GNU $package) $version"
141 echo "Copyright (C) $year Free Software Foundation, Inc.
142 This is free software; see the source for copying conditions. There is NO
143 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
144 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
147 # func_emit_copyright_notice
148 # outputs to stdout a header for a generated file.
149 func_emit_copyright_notice ()
151 echo "# Copyright (C) 2004-2006 Free Software Foundation, Inc."
153 echo "# This file is free software, distributed under the terms of the GNU"
154 echo "# General Public License. As a special exception to the GNU General"
155 echo "# Public License, this file may be distributed as part of a program"
156 echo "# that contains a configuration script generated by Autoconf, under"
157 echo "# the same distribution terms as the rest of that program."
159 echo "# Generated by gnulib-tool."
163 # creates a temporary directory.
165 # - tmp pathname of freshly created temporary directory
168 # Use the environment variable TMPDIR, falling back to /tmp. This allows
169 # users to specify a different temporary directory, for example, if their
170 # /tmp is filled up or too small.
173 # Use the mktemp program if available. If not available, hide the error
175 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
176 test -n "$tmp" && test -d "$tmp"
179 # Use a simple mkdir command. It is guaranteed to fail if the directory
180 # already exists. $RANDOM is bash specific and expands to empty in shells
181 # other than bash, ksh and zsh. Its use does not increase security;
182 # rather, it minimizes the probability of failure in a very cluttered /tmp
184 tmp=$TMPDIR/gl$$-$RANDOM
185 (umask 077 && mkdir "$tmp")
188 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
189 { (exit 1); exit 1; }
193 # func_fatal_error message
194 # outputs to stderr a fatal error message, and terminates the program.
197 echo "gnulib-tool: *** $1" 1>&2
198 echo "gnulib-tool: *** Stop." 1>&2
202 # func_readlink SYMLINK
203 # outputs the target of the given symlink.
204 if (type -p readlink) > /dev/null 2>&1; then
207 # Use the readlink program from GNU coreutils.
213 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
214 # would do the wrong thing if the link target contains " -> ".
215 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
219 # func_ln_if_changed SRC DEST
220 # Like ln -s, but avoids munging timestamps if the link is correct.
221 func_ln_if_changed ()
223 if test $# -ne 2; then
224 echo "usage: func_ln_if_changed SRC DEST" >&2
226 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
234 # Command-line option processing.
235 # Removes the OPTIONS from the arguments. Sets the variables:
236 # - mode list or import or create-testdir or create-megatestdir
237 # - destdir from --dir
238 # - libname, supplied_libname from --lib
239 # - sourcebase from --source-base
240 # - m4base from --m4-base
241 # - testsbase from --tests-base
242 # - auxdir from --aux-dir
243 # - inctests true if --with-tests was given, blank otherwise
244 # - avoidlist list of modules to avoid, from --avoid
245 # - lgpl true if --lgpl was given, blank otherwise
246 # - libtool true if --libtool was given, blank otherwise
247 # - do_changelog false if --no-changelog was given, : otherwise
248 # - doit : if actions shall be executed, false if only to be printed
269 while test $# -gt 0; do
274 --import | --impor | --impo | --imp | --im | --i )
277 --update | --updat | --upda | --upd | --up | --u )
280 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
283 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
284 mode=create-megatestdir
286 --test | --tes | --te | --t )
289 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
293 mode=`echo "X$1" | sed -e 's/^X--//'`
298 func_fatal_error "missing argument for --dir"
303 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
308 func_fatal_error "missing argument for --lib"
311 supplied_libname=true
314 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
315 supplied_libname=true
320 func_fatal_error "missing argument for --source-base"
325 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
330 func_fatal_error "missing argument for --m4-base"
335 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
340 func_fatal_error "missing argument for --tests-base"
345 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
350 func_fatal_error "missing argument for --aux-dir"
355 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
363 func_fatal_error "missing argument for --avoid"
365 avoidlist="$avoidlist $1"
368 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
379 func_fatal_error "missing argument for --macro-prefix"
384 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
386 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
392 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
395 --help | --hel | --he | --h )
398 --version | --versio | --versi | --vers | --ver | --ve | --v )
402 # Stop option processing
406 echo "gnulib-tool: unknown option $1" 1>&2
407 echo "Try 'gnulib-tool --help' for more information." 1>&2
414 if test "$mode" = update; then
415 if test $# != 0; then
416 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
417 echo "Try 'gnulib-tool --help' for more information." 1>&2
418 echo "If you really want to modify the gnulib configuration of your project," 1>&2
419 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
422 if test -n "$supplied_libname" || test -n "$sourcebase" || test -n "$m4base" \
423 || test -n "$testsbase" || test -n "$auxdir" || test -n "$inctests" \
424 || test -n "$avoidlist" || test -n "$lgpl" || test -n "$macro_prefix"; then
425 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
426 echo "Try 'gnulib-tool --help' for more information." 1>&2
427 echo "If you really want to modify the gnulib configuration of your project," 1>&2
428 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
434 # Remove trailing slashes from the directory names. This is necessary for
435 # m4base (to avoid an error in func_import) and optional for the others.
436 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
437 case "$sourcebase" in
438 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
441 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
444 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
447 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
452 /*) self_abspathname="$0" ;;
453 */*) self_abspathname=`pwd`/"$0" ;;
454 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
455 if test -x "$d/$0" && test ! -d "$d/$0"; then
456 self_abspathname="$d/$0"
460 if test -z "$self_abspathname"; then
461 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
465 while test -h "$self_abspathname"; do
466 # Resolve symbolic link.
467 linkval=`func_readlink "$self_abspathname"`
468 test -n "$linkval" || break
470 /* ) self_abspathname="$linkval" ;;
471 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
474 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
479 # Filter out metainformation files like README, which are not modules.
480 # Filter out unit test modules; they can be retrieved through
481 # --extract-tests-module if desired.
482 (cd "$gnulib_dir/modules" && ls -1) \
483 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
484 | sed -e '/-tests$/d' \
489 # verifies a module name
490 func_verify_module ()
492 if test ! -f "$gnulib_dir/modules/$module" \
493 || test "CVS" = "$module" \
494 || test "ChangeLog" = "$module" \
495 || test "README" = "$module" \
496 || test "TEMPLATE" = "$module" \
497 || test "TEMPLATE-TESTS" = "$module"; then
498 echo "gnulib-tool: module $module doesn't exist" 1>&2
503 # func_verify_nontests_module
504 # verifies a module name, excluding tests modules
505 func_verify_nontests_module ()
509 * ) func_verify_module ;;
513 # func_verify_tests_module
514 # verifies a module name, considering only tests modules
515 func_verify_tests_module ()
518 *-tests ) func_verify_module ;;
523 sed_extract_prog=':[ ]*$/ {
526 s/^Description:[ ]*$//
528 s/^Depends-on:[ ]*$//
529 s/^configure\.ac:[ ]*$//
530 s/^Makefile\.am:[ ]*$//
533 s/^Maintainer:[ ]*$//
540 # func_get_description module
541 func_get_description ()
543 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
546 # func_get_filelist module
549 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
551 echo m4/onceonly_2_57.m4
554 # func_get_dependencies module
555 func_get_dependencies ()
557 # ${module}-tests always implicitly depends on ${module}.
558 echo "$1" | sed -n -e 's/-tests//p'
559 # Then the explicit dependencies listed in the module description.
560 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
563 # func_get_autoconf_snippet module
564 func_get_autoconf_snippet ()
566 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
569 # func_get_automake_snippet module
570 func_get_automake_snippet ()
572 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
575 # func_get_include_directive module
576 func_get_include_directive ()
578 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
579 sed -e 's/^\(["<]\)/#include \1/'
582 # func_get_license module
585 sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
588 # func_get_maintainer module
589 func_get_maintainer ()
591 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
594 # func_get_tests_module module
595 func_get_tests_module ()
597 # The naming convention for tests modules is hardwired: ${module}-tests.
598 if test -f modules/"$1"-tests; then
603 # func_acceptable module
604 # tests whether a module is acceptable.
606 # - avoidlist list of modules to avoid
609 for avoid in $avoidlist; do
610 if test "$avoid" = "$1"; then
617 # func_modules_transitive_closure
619 # - modules list of specified modules
620 # - inctests true if tests should be included, blank otherwise
621 # - avoidlist list of modules to avoid
623 # - modules list of modules, including dependencies
624 func_modules_transitive_closure ()
628 for module in $modules; do
630 if test -n "$module"; then
631 # Duplicate dependencies are harmless, but Jim wants a warning.
632 duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
633 if test -n "$duplicated_deps"; then
634 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
636 if func_acceptable $module; then
637 xmodules="$xmodules $module"
638 for depmodule in `func_get_dependencies $module`; do
639 if func_acceptable $depmodule; then
640 xmodules="$xmodules $depmodule"
643 if test -n "$inctests"; then
644 testsmodule=`func_get_tests_module $module`
645 if test -n "$testsmodule"; then
646 if func_acceptable $testsmodule; then
647 xmodules="$xmodules $testsmodule"
648 for depmodule in `func_get_dependencies $testsmodule`; do
649 if func_acceptable $depmodule; then
650 xmodules="$xmodules $depmodule"
659 xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
660 if test "$xmodules" = "$modules"; then
667 # func_modules_add_dummy
669 # - modules list of modules, including dependencies
671 # - modules list of modules, including 'dummy' if needed
672 func_modules_add_dummy ()
675 sed_remove_backslash_newline=':a
682 for module in $modules; do
683 func_verify_nontests_module
684 if test -n "$module"; then
685 # Extract the value of "lib_SOURCES += ...".
686 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
687 # Ignore .h files since they are not compiled.
690 *) have_lib_SOURCES=yes ;;
695 # Add the dummy module, to make sure the library will be non-empty.
696 if test -z "$have_lib_SOURCES"; then
697 modules="$modules dummy"
701 # func_modules_to_filelist
703 # - modules list of modules, including dependencies
705 # - files list of files
706 func_modules_to_filelist ()
709 for module in $modules; do
711 if test -n "$module"; then
712 files="$files "`func_get_filelist $module`
715 files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
718 # func_emit_lib_Makefile_am
719 # emits the contents of lib/Makefile.am to standard output.
721 # - modules list of modules, including dependencies
722 # - libname library name
723 # - libtool true if libtool will be used, blank otherwise
724 # - actioncmd (optional) command that will reproduce this invocation
725 func_emit_lib_Makefile_am ()
727 if test -n "$libtool"; then
734 echo "## Process this file with automake to produce Makefile.in."
735 func_emit_copyright_notice
736 if test -n "$actioncmd"; then
737 echo "# Reproduce by: $actioncmd"
740 # No need to generate dependencies since the sources are in gnulib, not here.
741 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
743 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
745 echo "${libname}_${libext}_SOURCES ="
746 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
747 echo "noinst_HEADERS ="
749 echo "BUILT_SOURCES ="
751 echo "MOSTLYCLEANFILES ="
752 echo "MOSTLYCLEANDIRS ="
754 echo "DISTCLEANFILES ="
755 echo "MAINTAINERCLEANFILES ="
759 for module in $modules; do
760 func_verify_nontests_module
761 if test -n "$module"; then
763 func_get_automake_snippet "$module" |
764 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
765 if test "$module" = 'alloca'; then
766 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
769 # Skip the contents if its entirely empty.
770 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
771 echo "## begin gnulib module $module"
774 echo "## end gnulib module $module"
781 echo "mostlyclean-local:"
782 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
783 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
784 echo " if test -d \$\$dir; then \\"
785 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
789 echo "# Makefile.am ends here"
792 # func_emit_tests_Makefile_am
793 # emits the contents of tests/Makefile.am to standard output.
795 # - modules list of modules, including dependencies
796 # - libname library name
797 # - libtool true if libtool will be used, blank otherwise
798 # - sourcebase relative directory containing lib source code
799 # - m4base relative directory containing autoconf macros
800 # - testsbase relative directory containing unit test code
801 func_emit_tests_Makefile_am ()
803 if test -n "$libtool"; then
808 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
809 echo "## Process this file with automake to produce Makefile.in."
810 func_emit_copyright_notice
812 # Generate dependencies here, since it eases the debugging of test failures.
813 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
815 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
817 # Nothing is being added to SUBDIRS; nevertheless the existence of this
818 # variable is needed to avoid an error from automake:
819 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
822 echo "TESTS_ENVIRONMENT ="
823 echo "noinst_PROGRAMS ="
824 echo "check_PROGRAMS ="
825 echo "noinst_HEADERS ="
827 echo "BUILT_SOURCES ="
829 echo "MOSTLYCLEANFILES ="
830 echo "MOSTLYCLEANDIRS ="
832 echo "DISTCLEANFILES ="
833 echo "MAINTAINERCLEANFILES ="
835 echo "AM_CPPFLAGS = \\"
836 echo " -I. -I\$(srcdir) \\"
837 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
838 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
840 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
842 for module in $modules; do
843 func_verify_tests_module
844 if test -n "$module"; then
845 func_get_automake_snippet "$module" > amsnippet.tmp
846 # Skip the contents if its entirely empty.
847 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
848 echo "## begin gnulib module $module"
851 echo "## end gnulib module $module"
857 echo "# Clean up after Solaris cc."
859 echo " rm -rf SunWS_cache"
861 echo "mostlyclean-local:"
862 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
863 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
864 echo " if test -d \$\$dir; then \\"
865 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
869 echo "# Makefile.am ends here"
872 # func_import modules
873 # Uses also the variables
874 # - destdir target directory
875 # - libname library name
876 # - sourcebase directory relative to destdir where to place source code
877 # - m4base directory relative to destdir where to place *.m4 macros
878 # - testsbase directory relative to destdir where to place unit test code
879 # - auxdir directory relative to destdir where to place build aux files
880 # - inctests true if --with-tests was given, blank otherwise
881 # - avoidlist list of modules to avoid, from --avoid
882 # - lgpl true if library's license shall be LGPL, blank otherwise
883 # - libtool true if libtool will be used, blank otherwise
884 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
885 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
886 # - doit : if actions shall be executed, false if only to be printed
887 # - symbolic true if files should be symlinked, copied otherwise
890 # Get the cached settings.
891 cached_specified_modules=
901 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
907 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
910 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
913 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
916 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
919 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
922 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
925 s,^.*$,cached_lgpl=true,p
928 s,^.*$,cached_libtool=true,p
931 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
933 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
934 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
939 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
940 s,^.*$,cached_files=",p
952 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
956 # Merge the cached settings with the specified ones.
957 # The m4base must be the same as expected from the pathname.
958 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
959 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
961 # Append the cached and the specified module names. So that
962 # "gnulib-tool --import foo" means to add the module foo.
963 specified_modules="$cached_specified_modules $1"
964 # Append the cached and the specified avoidlist. This is probably better
965 # than dropping the cached one when --avoid is specified at least once.
966 avoidlist=`echo $cached_avoidlist $avoidlist`
967 # The sourcebase defaults to the cached one.
968 if test -z "$sourcebase"; then
969 sourcebase="$cached_sourcebase"
970 if test -z "$sourcebase"; then
971 func_fatal_error "missing --source-base option"
974 # The testsbase defaults to the cached one.
975 if test -z "$testsbase"; then
976 testsbase="$cached_testsbase"
977 if test -z "$testsbase"; then
978 func_fatal_error "missing --tests-base option"
981 # The libname defaults to the cached one.
982 if test -z "$supplied_libname"; then
983 libname="$cached_libname"
984 if test -z "$libname"; then
985 func_fatal_error "missing --lib option"
988 # Require LGPL if specified either way.
989 if test -z "$lgpl"; then
992 # Use libtool if specified either way, or if guessed.
993 if test -z "$libtool"; then
994 if test -n "$cached_m4base"; then
995 libtool="$cached_libtool"
997 libtool="$guessed_libtool"
1000 # The macro_prefix defaults to the cached one.
1001 if test -z "$macro_prefix"; then
1002 macro_prefix="$cached_macro_prefix"
1003 if test -z "$macro_prefix"; then
1004 func_fatal_error "missing --macro-prefix option"
1008 # Canonicalize the list of specified modules.
1009 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1011 # Determine final module list.
1012 modules="$specified_modules"
1013 func_modules_transitive_closure
1014 echo "Module list with included dependencies:"
1015 echo "$modules" | sed -e 's/^/ /'
1017 # Add the dummy module if needed.
1018 func_modules_add_dummy
1020 # If --lgpl, check the license of modules are compatible.
1021 if test -n "$lgpl"; then
1022 for module in $modules; do
1023 license=`func_get_license $module`
1025 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
1026 *) func_fatal_error "incompatible license on module $module: $license" ;;
1031 # Determine final file list.
1032 func_modules_to_filelist
1034 echo "$files" | sed -e 's/^/ /'
1037 || func_fatal_error "refusing to do nothing"
1039 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1040 new_files="$files m4/gnulib-tool.m4"
1041 old_files="$cached_files"
1042 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1043 old_files="$old_files m4/gnulib-tool.m4"
1046 # Create directories.
1047 if test ! -d "$destdir/$sourcebase"; then
1049 echo "Creating directory $destdir/$sourcebase"
1050 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1052 echo "Create directory $destdir/$sourcebase"
1055 if test ! -d "$destdir/$m4base"; then
1057 echo "Creating directory $destdir/$m4base"
1058 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1060 echo "Create directory $destdir/$m4base"
1063 if test -n "$inctests"; then
1064 if test ! -d "$destdir/$testsbase"; then
1066 echo "Creating directory $destdir/$testsbase"
1067 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1069 echo "Create directory $destdir/$testsbase"
1073 if test ! -d "$destdir/$auxdir"; then
1075 echo "Creating directory $destdir/$auxdir"
1076 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1078 echo "Create directory $destdir/$auxdir"
1083 trap 'rm -rf "$tmp"' 0 1 2 3 15
1084 # func_dest_tmpfilename file
1085 # determines the name of a temporary file (file is relative to destdir).
1087 # - tmpfile absolute filename of the temporary file
1088 func_dest_tmpfilename ()
1091 # Put the new contents of $file in a file in the same directory (needed
1092 # to guarantee that an 'mv' to "$destdir/$file" works).
1093 tmpfile="$destdir/$1.tmp"
1095 # Put the new contents of $file in a file in a temporary directory
1096 # (because the directory of "$file" might not exist).
1097 tmpfile="$tmp"/`basename "$1"`.tmp
1101 # Copy files or make symbolic links. Remove obsolete files.
1103 for f in $old_files; do
1105 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1106 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1107 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1108 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1111 echo "$g""$delimiter""$f"
1112 done | LC_ALL=C sort > "$tmp"/old-files
1113 for f in $new_files; do
1115 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1116 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1117 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1118 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1121 echo "$g""$delimiter""$f"
1122 done | LC_ALL=C sort > "$tmp"/new-files
1123 # First the files that are in old-files, but not in new-files:
1124 sed_take_first_column='s,'"$delimiter"'.*,,'
1125 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1126 # Remove the file. Do nothing if the user already removed it.
1127 if test -f "$destdir/$g"; then
1129 echo "Removing file $g (backup in ${g}~)"
1130 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1132 echo "Remove file $g (backup in ${g}~)"
1136 # func_add_or_update handles a file that ought to be present afterwards.
1137 # Uses parameters f, g, already_present.
1138 func_add_or_update ()
1140 func_dest_tmpfilename "$g"
1141 cp "$gnulib_dir/$f" "$tmpfile" || func_fatal_error "failed"
1142 if test -n "$lgpl"; then
1146 sed -e 's/GNU General/GNU Lesser General/g' \
1147 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1148 < "$gnulib_dir/$f" > "$tmpfile" || func_fatal_error "failed"
1152 if test -f "$destdir/$g"; then
1153 # The file already exists.
1154 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1155 : # The file has not changed.
1159 if test -n "$already_present"; then
1160 echo "Updating file $g (backup in ${g}~)"
1162 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1164 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1165 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1166 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1168 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1171 if test -n "$already_present"; then
1172 echo "Update file $g (backup in ${g}~)"
1174 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1180 # Don't protest if the file should be there but isn't: it happens
1181 # frequently that developers don't put autogenerated files into CVS.
1183 echo "Copying file $g"
1184 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1185 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1187 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1195 # Then the files that are in new-files, but not in old-files:
1196 sed_take_last_column='s,^.*'"$delimiter"',,'
1198 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1200 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1201 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1202 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1203 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1208 # Then the files that are in new-files and in old-files:
1209 already_present=true
1210 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1212 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1213 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1214 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1215 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1221 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1222 actioncmd="gnulib-tool --import"
1223 actioncmd="$actioncmd --dir=$destdir"
1224 actioncmd="$actioncmd --lib=$libname"
1225 actioncmd="$actioncmd --source-base=$sourcebase"
1226 actioncmd="$actioncmd --m4-base=$m4base"
1227 actioncmd="$actioncmd --aux-dir=$auxdir"
1228 for module in $avoidlist; do
1229 actioncmd="$actioncmd --avoid=$module"
1231 if test -n "$lgpl"; then
1232 actioncmd="$actioncmd --lgpl"
1234 if test -n "$libtool"; then
1235 actioncmd="$actioncmd --libtool"
1237 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1238 actioncmd="$actioncmd `echo $specified_modules`"
1240 # Create lib/Makefile.am.
1241 func_dest_tmpfilename $sourcebase/Makefile.am
1242 func_emit_lib_Makefile_am > "$tmpfile"
1243 if test -f "$destdir"/$sourcebase/Makefile.am; then
1244 if cmp "$destdir"/$sourcebase/Makefile.am "$tmpfile" > /dev/null; then
1248 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1249 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1250 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1252 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1258 echo "Creating $sourcebase/Makefile.am"
1259 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1261 echo "Create $sourcebase/Makefile.am"
1266 # Create m4/gnulib-cache.m4.
1267 func_dest_tmpfilename $m4base/gnulib-cache.m4
1269 func_emit_copyright_notice
1271 echo "# This file represents the specification of how gnulib-tool is used."
1272 echo "# It acts as a cache: It is written and read by gnulib-tool."
1273 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1274 echo "# like the configure.ac and various Makefile.am files."
1277 echo "# Specification in the form of a command-line invocation:"
1280 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1281 echo "gl_MODULES(["`echo $specified_modules`"])"
1282 echo "gl_AVOID([$avoidlist])"
1283 echo "gl_SOURCE_BASE([$sourcebase])"
1284 echo "gl_M4_BASE([$m4base])"
1285 echo "gl_TESTS_BASE([$testsbase])"
1286 echo "gl_LIB([$libname])"
1287 test -z "$lgpl" || echo "gl_LGPL"
1288 test -z "$libtool" || echo "gl_LIBTOOL"
1289 echo "gl_MACRO_PREFIX([$macro_prefix])"
1291 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1292 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1296 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1297 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1298 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1300 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1304 echo "# gnulib-cache.m4 ends here"
1311 echo "Creating $m4base/gnulib-cache.m4"
1312 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1314 echo "Create $m4base/gnulib-cache.m4"
1320 # Create m4/gnulib-comp.m4.
1321 func_dest_tmpfilename $m4base/gnulib-comp.m4
1323 func_emit_copyright_notice
1325 echo "# This file represents the compiled summary of the specification in"
1326 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1327 echo "# to be invoked from configure.ac."
1328 echo "# In projects using CVS, this file can be treated like other built files."
1331 echo "# This macro should be invoked from $configure_ac, in the section"
1332 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1333 echo "# any checks for libraries, header files, types and library functions."
1334 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1336 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1337 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1338 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1340 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1341 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1343 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1344 echo " AC_REQUIRE([gl_LOCK])"
1348 echo "# This macro should be invoked from $configure_ac, in the section"
1349 echo "# \"Check for header files, types and library functions\"."
1350 echo "AC_DEFUN([${macro_prefix}_INIT],"
1352 if test -z "$libtool"; then
1353 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1355 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1357 if test "$auxdir" != "build-aux"; then
1358 sed_replace_build_aux='
1360 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1361 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1364 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1366 sed_replace_build_aux=
1368 for module in $modules; do
1370 if test -n "$module"; then
1371 func_get_autoconf_snippet "$module" \
1372 | sed -e '/^$/d;' -e 's/^/ /' \
1373 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1374 -e "$sed_replace_build_aux"
1375 if test "$module" = 'alloca' && test -n "$libtool"; then
1376 echo 'changequote(,)dnl'
1377 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1378 echo 'changequote([, ])dnl'
1379 echo 'AC_SUBST([LTALLOCA])'
1385 echo "# This macro records the list of files which have been installed by"
1386 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1387 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1388 echo "$files" | sed -e 's,^, ,'
1391 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1392 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
1396 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1397 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1398 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1400 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1404 echo "# gnulib-comp.m4 ends here"
1411 echo "Creating $m4base/gnulib-comp.m4"
1412 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1414 echo "Create $m4base/gnulib-comp.m4"
1420 if test -n "$inctests"; then
1421 # Create tests/Makefile.am.
1422 func_dest_tmpfilename $testsbase/Makefile.am
1423 func_emit_tests_Makefile_am > "$tmpfile"
1424 if test -f "$destdir"/$testsbase/Makefile.am; then
1425 if cmp "$destdir"/$testsbase/Makefile.am "$tmpfile" > /dev/null; then
1429 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1430 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1431 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1433 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1439 echo "Creating $testsbase/Makefile.am"
1440 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1442 echo "Create $testsbase/Makefile.am"
1449 # Undo the effect of the previous 'trap' command. Some shellology:
1450 # We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
1451 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
1452 # exit); for the others we need to call 'exit' explicitly. The value of $? is
1453 # 128 + signal number and is set before the trap-registered command is run.
1455 trap 'exit $?' 1 2 3 15
1459 echo "You may need to add #include directives for the following .h files."
1461 # First the #include <...> directives without #ifs, sorted for convenience.
1462 for module in $modules; do
1463 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1466 func_get_include_directive "$module" | grep -v 'include "'
1468 done | LC_ALL=C sort -u
1469 # Then the #include "..." directives without #ifs, sorted for convenience.
1470 for module in $modules; do
1471 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1474 func_get_include_directive "$module" | grep 'include "'
1476 done | LC_ALL=C sort -u
1477 # Then the #include directives that are surrounded by #ifs. Not sorted.
1478 for module in $modules; do
1479 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1480 func_get_include_directive "$module"
1483 ) | sed -e '/^$/d;' -e 's/^/ /'
1485 echo "Don't forget to"
1486 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1487 if test -n "$inctests"; then
1488 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1490 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1491 sourcebase_base=`basename "$sourcebase"`
1492 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1493 if test -n "$inctests"; then
1494 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1495 testsbase_base=`basename "$testsbase"`
1496 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1498 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1499 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1500 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1503 # func_create_testdir testdir modules
1505 # - auxdir directory relative to destdir where to place build aux files
1506 func_create_testdir ()
1510 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1512 # Determine final module list.
1513 func_modules_transitive_closure
1514 echo "Module list with included dependencies:"
1515 echo "$modules" | sed -e 's/^/ /'
1517 # Add the dummy module if needed.
1518 func_modules_add_dummy
1520 # Determine final file list.
1521 func_modules_to_filelist
1523 echo "$files" | sed -e 's/^/ /'
1525 # Create directories.
1526 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1527 if test "$d" = build-aux; then
1528 mkdir -p "$testdir/$auxdir"
1530 mkdir -p "$testdir/$d"
1534 # Copy files or make symbolic links.
1537 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1540 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1541 if test -z "$symbolic"; then
1542 cp -p "$gnulib_dir/$f" "$testdir/$g"
1544 ln -s "$gnulib_dir/$f" "$testdir/$g"
1548 # Create lib/Makefile.am.
1549 mkdir -p "$testdir/lib"
1550 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1552 # Create m4/Makefile.am.
1553 mkdir -p "$testdir/m4"
1554 (echo "## Process this file with automake to produce Makefile.in."
1560 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1563 ) > "$testdir/m4/Makefile.am"
1566 subdirs_with_configure_ac=""
1568 if test -f "$testdir"/m4/gettext.m4; then
1569 # Avoid stupid error message from automake:
1570 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1571 mkdir -p "$testdir/po"
1572 (echo "## Process this file with automake to produce Makefile.in."
1573 ) > "$testdir/po/Makefile.am"
1574 subdirs="$subdirs po"
1577 if test -n "$inctests"; then
1578 test -d "$testdir/tests" || mkdir "$testdir/tests"
1579 # Create tests/Makefile.am.
1583 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1584 # Create tests/configure.ac.
1585 (echo "# Process this file with autoconf to produce a configure script."
1586 echo "AC_INIT([dummy], [0])"
1587 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1588 echo "AM_INIT_AUTOMAKE"
1590 echo "AM_CONFIG_HEADER([config.h])"
1593 echo "AC_PROG_INSTALL"
1594 echo "AC_PROG_MAKE_SET"
1595 echo "AC_PROG_RANLIB"
1597 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1598 echo "AC_GNU_SOURCE"
1601 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1602 echo "gl_USE_SYSTEM_EXTENSIONS"
1605 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1609 if test -z "$libtool"; then
1610 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1612 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1614 if test "$auxdir" != "build-aux"; then
1615 sed_replace_build_aux='
1617 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1618 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1621 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1623 sed_replace_build_aux=
1625 # We don't have explicit ordering constraints between the various
1626 # autoconf snippets. It's cleanest to put those of the library before
1627 # those of the tests.
1628 for module in $modules; do
1629 func_verify_nontests_module
1630 if test -n "$module"; then
1631 func_get_autoconf_snippet "$module" \
1632 | sed -e "$sed_replace_build_aux"
1635 for module in $modules; do
1636 func_verify_tests_module
1637 if test -n "$module"; then
1638 func_get_autoconf_snippet "$module" \
1639 | sed -e "$sed_replace_build_aux"
1643 # Usually tests/config.h will be a superset of config.h. Verify this by
1644 # "merging" config.h into tests/config.h; look out for gcc warnings.
1645 echo "AH_TOP([#include \"../config.h\"])"
1647 echo "AC_OUTPUT([Makefile])"
1648 ) > "$testdir/tests/configure.ac"
1649 subdirs="$subdirs tests"
1650 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1653 # Create Makefile.am.
1654 (echo "## Process this file with automake to produce Makefile.in."
1656 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1658 echo "SUBDIRS = $subdirs"
1660 echo "ACLOCAL_AMFLAGS = -I m4"
1661 ) > "$testdir/Makefile.am"
1663 # Create configure.ac.
1664 (echo "# Process this file with autoconf to produce a configure script."
1665 echo "AC_INIT([dummy], [0])"
1666 if test "$auxdir" != "."; then
1667 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1669 echo "AM_INIT_AUTOMAKE"
1671 echo "AM_CONFIG_HEADER([config.h])"
1674 echo "AC_PROG_INSTALL"
1675 echo "AC_PROG_MAKE_SET"
1676 echo "AC_PROG_RANLIB"
1678 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1679 echo "AC_GNU_SOURCE"
1682 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1683 echo "gl_USE_SYSTEM_EXTENSIONS"
1686 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1690 if test -z "$libtool"; then
1691 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1693 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1695 if test "$auxdir" != "build-aux"; then
1696 sed_replace_build_aux='
1698 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1699 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1702 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1704 sed_replace_build_aux=
1706 for module in $modules; do
1707 func_verify_nontests_module
1708 if test -n "$module"; then
1709 func_get_autoconf_snippet "$module" \
1710 | sed -e "$sed_replace_build_aux"
1714 if test -n "$subdirs_with_configure_ac"; then
1715 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1717 makefiles="Makefile"
1718 for d in $subdirs; do
1719 # For subdirs that have a configure.ac by their own, it's the subdir's
1720 # configure.ac which creates the subdir's Makefile.am, not this one.
1721 case " $subdirs_with_configure_ac " in
1723 *) makefiles="$makefiles $d/Makefile" ;;
1726 echo "AC_OUTPUT([$makefiles])"
1727 ) > "$testdir/configure.ac"
1729 # Create autogenerated files.
1731 echo "executing ${AUTORECONF} --force --install"
1732 ${AUTORECONF} --force --install
1734 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1738 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1746 # func_create_megatestdir megatestdir allmodules
1748 # - auxdir directory relative to destdir where to place build aux files
1749 func_create_megatestdir ()
1753 if test -z "$allmodules"; then
1754 allmodules=`func_all_modules`
1758 # First, all modules one by one.
1759 for onemodule in $allmodules; do
1760 func_create_testdir "$megatestdir/$onemodule" $onemodule
1761 megasubdirs="${megasubdirs}$onemodule "
1763 # Then, all modules all together.
1764 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1765 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1766 func_create_testdir "$megatestdir/ALL" "$allmodules"
1767 megasubdirs="${megasubdirs}ALL"
1769 # Create Makefile.am.
1770 (echo "## Process this file with automake to produce Makefile.in."
1772 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1774 echo "SUBDIRS = $megasubdirs"
1775 ) > "$megatestdir/Makefile.am"
1777 # Create configure.ac.
1778 (echo "# Process this file with autoconf to produce a configure script."
1779 echo "AC_INIT([dummy], [0])"
1780 if test "$auxdir" != "."; then
1781 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1783 echo "AM_INIT_AUTOMAKE"
1785 echo "AC_PROG_MAKE_SET"
1787 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1788 echo "AC_OUTPUT([Makefile])"
1789 ) > "$megatestdir/configure.ac"
1791 # Create autogenerated files.
1793 # Do not use "${AUTORECONF} --install", because autoreconf operates
1794 # recursively, but the subdirectories are already finished, therefore
1795 # calling autoreconf here would only waste lots of CPU time.
1796 echo "executing ${ACLOCAL}"
1798 echo "executing mkdir build-aux"
1800 echo "executing ${AUTOCONF}"
1802 echo "executing ${AUTOMAKE} --add-missing --copy"
1803 ${AUTOMAKE} --add-missing --copy
1809 func_fatal_error "no mode specified" ;;
1818 if test -z "$destdir"; then
1821 test -d "$destdir" \
1822 || func_fatal_error "destination directory does not exist: $destdir"
1824 # Prefer configure.ac to configure.in.
1825 if test -f "$destdir"/configure.ac; then
1826 configure_ac="$destdir/configure.ac"
1828 if test -f "$destdir"/configure.in; then
1829 configure_ac="$destdir/configure.in"
1831 func_fatal_error "cannot find $destdir/configure.ac"
1835 test -f "$destdir"/Makefile.am \
1836 || func_fatal_error "cannot find $destdir/Makefile.am"
1838 # Analyze configure.ac.
1845 /AC_CONFIG_AUX_DIR/ {
1846 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1848 /A[CM]_PROG_LIBTOOL/ {
1849 s,^.*$,guessed_libtool=true,p
1851 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1853 if test -z "$auxdir"; then
1854 auxdir="$guessed_auxdir"
1857 # Determine where to apply func_import.
1858 if test -n "$m4base"; then
1859 # Apply func_import to a particular gnulib directory.
1860 # Any number of additional modules can be given.
1861 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1862 # First use of gnulib in the given m4base.
1863 test -n "$supplied_libname" || supplied_libname=true
1864 test -n "$sourcebase" || sourcebase="lib"
1865 test -n "$testsbase" || testsbase="tests"
1866 test -n "$macro_prefix" || macro_prefix="gl"
1870 # Apply func_import to all gnulib directories.
1871 # To get this list of directories, look at Makefile.am. (Not at
1872 # configure, because it may be omitted from CVS. Also, don't run
1873 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1874 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
1878 for arg in $aclocal_amflags; do
1879 if test -n "$m4dir_is_next"; then
1880 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1884 if test -f "$destdir/$arg"/gnulib-cache.m4; then
1885 m4dirs="$m4dirs $arg"
1886 m4dirs_count=`expr $m4dirs_count + 1`
1891 if test "X$arg" = "X-I"; then
1898 if test $m4dirs_count = 0; then
1899 # First use of gnulib in a package.
1900 # Any number of additional modules can be given.
1901 test -n "$supplied_libname" || supplied_libname=true
1902 test -n "$sourcebase" || sourcebase="lib"
1904 test -n "$testsbase" || testsbase="tests"
1905 test -n "$macro_prefix" || macro_prefix="gl"
1908 if test $m4dirs_count = 1; then
1909 # There's only one use of gnulib here. Assume the user means it.
1910 # Any number of additional modules can be given.
1911 for m4base in $m4dirs; do
1915 # Ambiguous - guess what the user meant.
1916 if test $# = 0; then
1917 # No further arguments. Guess the user wants to update all of them.
1918 for m4base in $m4dirs; do
1923 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
1931 if test -z "$destdir"; then
1932 func_fatal_error "please specify --dir option"
1935 test -d "$destdir" \
1936 || func_fatal_error "could not create destination directory"
1937 test -n "$auxdir" || auxdir="build-aux"
1938 func_create_testdir "$destdir" "$*"
1941 create-megatestdir )
1942 if test -z "$destdir"; then
1943 func_fatal_error "please specify --dir option"
1945 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1946 test -n "$auxdir" || auxdir="build-aux"
1947 func_create_megatestdir "$destdir" "$*"
1951 test -n "$destdir" || destdir=testdir$$
1952 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1953 test -n "$auxdir" || auxdir="build-aux"
1954 func_create_testdir "$destdir" "$*"
1962 remaining=`find . -type f -print`
1963 if test -n "$remaining"; then
1964 echo "Remaining files:" $remaining 1>&2
1965 echo "gnulib-tool: *** Stop." 1>&2
1974 test -n "$destdir" || destdir=testdir$$
1975 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1976 test -n "$auxdir" || auxdir="build-aux"
1977 func_create_megatestdir "$destdir" "$*"
1985 remaining=`find . -type f -print`
1986 if test -n "$remaining"; then
1987 echo "Remaining files:" $remaining 1>&2
1988 echo "gnulib-tool: *** Stop." 1>&2
1996 extract-description )
2000 if test -n "$module"; then
2001 func_get_description "$module"
2010 if test -n "$module"; then
2011 func_get_filelist "$module"
2016 extract-dependencies )
2020 if test -n "$module"; then
2021 func_get_dependencies "$module"
2026 extract-autoconf-snippet )
2030 if test -n "$module"; then
2031 func_get_autoconf_snippet "$module"
2036 extract-automake-snippet )
2040 if test -n "$module"; then
2041 func_get_automake_snippet "$module"
2046 extract-include-directive )
2050 if test -n "$module"; then
2051 func_get_include_directive "$module"
2060 if test -n "$module"; then
2061 func_get_license "$module"
2066 extract-maintainer )
2070 if test -n "$module"; then
2071 func_get_maintainer "$module"
2076 extract-tests-module )
2080 if test -n "$module"; then
2081 func_get_tests_module "$module"
2087 func_fatal_error "unknown operation mode --$mode" ;;