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-05-02 14:31:00 $'
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 echo "$progname (GNU $package) $version"
140 echo "Copyright (C) 2002-2005 Free Software Foundation, Inc.
141 This is free software; see the source for copying conditions. There is NO
142 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
143 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
147 # creates a temporary directory.
149 # - tmp pathname of freshly created temporary directory
152 # Use the environment variable TMPDIR, falling back to /tmp. This allows
153 # users to specify a different temporary directory, for example, if their
154 # /tmp is filled up or too small.
157 # Use the mktemp program if available. If not available, hide the error
159 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
160 test -n "$tmp" && test -d "$tmp"
163 # Use a simple mkdir command. It is guaranteed to fail if the directory
164 # already exists. $RANDOM is bash specific and expands to empty in shells
165 # other than bash, ksh and zsh. Its use does not increase security;
166 # rather, it minimizes the probability of failure in a very cluttered /tmp
168 tmp=$TMPDIR/gl$$-$RANDOM
169 (umask 077 && mkdir "$tmp")
172 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
173 { (exit 1); exit 1; }
177 # func_fatal_error message
178 # outputs to stderr a fatal error message, and terminates the program.
181 echo "gnulib-tool: *** $1" 1>&2
182 echo "gnulib-tool: *** Stop." 1>&2
186 # func_readlink SYMLINK
187 # outputs the target of the given symlink.
188 if (type -p readlink) > /dev/null 2>&1; then
191 # Use the readlink program from GNU coreutils.
197 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
198 # would do the wrong thing if the link target contains " -> ".
199 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
203 # func_ln_if_changed SRC DEST
204 # Like ln -s, but avoids munging timestamps if the link is correct.
205 func_ln_if_changed ()
207 if test $# -ne 2; then
208 echo "usage: func_ln_if_changed SRC DEST" >&2
210 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
218 # Command-line option processing.
219 # Removes the OPTIONS from the arguments. Sets the variables:
220 # - mode list or import or create-testdir or create-megatestdir
221 # - destdir from --dir
222 # - libname, supplied_libname from --lib
223 # - sourcebase from --source-base
224 # - m4base from --m4-base
225 # - testsbase from --tests-base
226 # - auxdir from --aux-dir
227 # - inctests true if --with-tests was given, blank otherwise
228 # - avoidlist list of modules to avoid, from --avoid
229 # - lgpl true if --lgpl was given, blank otherwise
230 # - libtool true if --libtool was given, blank otherwise
231 # - do_changelog false if --no-changelog was given, : otherwise
232 # - doit : if actions shall be executed, false if only to be printed
253 while test $# -gt 0; do
258 --import | --impor | --impo | --imp | --im | --i )
261 --update | --updat | --upda | --upd | --up | --u )
264 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
267 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
268 mode=create-megatestdir
270 --test | --tes | --te | --t )
273 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
277 mode=`echo "X$1" | sed -e 's/^X--//'`
282 func_fatal_error "missing argument for --dir"
287 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
292 func_fatal_error "missing argument for --lib"
295 supplied_libname=true
298 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
299 supplied_libname=true
304 func_fatal_error "missing argument for --source-base"
309 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
314 func_fatal_error "missing argument for --m4-base"
319 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
324 func_fatal_error "missing argument for --tests-base"
329 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
334 func_fatal_error "missing argument for --aux-dir"
339 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
347 func_fatal_error "missing argument for --avoid"
349 avoidlist="$avoidlist $1"
352 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
363 func_fatal_error "missing argument for --macro-prefix"
368 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
370 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
376 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
379 --help | --hel | --he | --h )
382 --version | --versio | --versi | --vers | --ver | --ve | --v )
386 # Stop option processing
390 echo "gnulib-tool: unknown option $1" 1>&2
391 echo "Try 'gnulib-tool --help' for more information." 1>&2
398 if test "$mode" = update; then
399 if test $# != 0; then
400 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
401 echo "Try 'gnulib-tool --help' for more information." 1>&2
402 echo "If you really want to modify the gnulib configuration of your project," 1>&2
403 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
406 if test -n "$supplied_libname" || test -n "$sourcebase" || test -n "$m4base" \
407 || test -n "$testsbase" || test -n "$auxdir" || test -n "$inctests" \
408 || test -n "$avoidlist" || test -n "$lgpl" || test -n "$macro_prefix"; then
409 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
410 echo "Try 'gnulib-tool --help' for more information." 1>&2
411 echo "If you really want to modify the gnulib configuration of your project," 1>&2
412 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
418 # Remove trailing slashes from the directory names. This is necessary for
419 # m4base (to avoid an error in func_import) and optional for the others.
420 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
421 case "$sourcebase" in
422 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
425 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
428 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
431 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
436 /*) self_abspathname="$0" ;;
437 */*) self_abspathname=`pwd`/"$0" ;;
438 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
439 if test -x "$d/$0" && test ! -d "$d/$0"; then
440 self_abspathname="$d/$0"
444 if test -z "$self_abspathname"; then
445 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
449 while test -h "$self_abspathname"; do
450 # Resolve symbolic link.
451 linkval=`func_readlink "$self_abspathname"`
452 test -n "$linkval" || break
454 /* ) self_abspathname="$linkval" ;;
455 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
458 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
463 # Filter out metainformation files like README, which are not modules.
464 # Filter out unit test modules; they can be retrieved through
465 # --extract-tests-module if desired.
466 (cd "$gnulib_dir/modules" && ls -1) \
467 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
468 | sed -e '/-tests$/d' \
473 # verifies a module name
474 func_verify_module ()
476 if test ! -f "$gnulib_dir/modules/$module" \
477 || test "CVS" = "$module" \
478 || test "ChangeLog" = "$module" \
479 || test "README" = "$module" \
480 || test "TEMPLATE" = "$module" \
481 || test "TEMPLATE-TESTS" = "$module"; then
482 echo "gnulib-tool: module $module doesn't exist" 1>&2
487 # func_verify_nontests_module
488 # verifies a module name, excluding tests modules
489 func_verify_nontests_module ()
493 * ) func_verify_module ;;
497 # func_verify_tests_module
498 # verifies a module name, considering only tests modules
499 func_verify_tests_module ()
502 *-tests ) func_verify_module ;;
507 sed_extract_prog=':[ ]*$/ {
510 s/^Description:[ ]*$//
512 s/^Depends-on:[ ]*$//
513 s/^configure\.ac:[ ]*$//
514 s/^Makefile\.am:[ ]*$//
517 s/^Maintainer:[ ]*$//
524 # func_get_description module
525 func_get_description ()
527 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
530 # func_get_filelist module
533 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
535 echo m4/onceonly_2_57.m4
538 # func_get_dependencies module
539 func_get_dependencies ()
541 # ${module}-tests always implicitly depends on ${module}.
542 echo "$1" | sed -n -e 's/-tests//p'
543 # Then the explicit dependencies listed in the module description.
544 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
547 # func_get_autoconf_snippet module
548 func_get_autoconf_snippet ()
550 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
553 # func_get_automake_snippet module
554 func_get_automake_snippet ()
556 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
559 # func_get_include_directive module
560 func_get_include_directive ()
562 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
563 sed -e 's/^\(["<]\)/#include \1/'
566 # func_get_license module
569 sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
572 # func_get_maintainer module
573 func_get_maintainer ()
575 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
578 # func_get_tests_module module
579 func_get_tests_module ()
581 # The naming convention for tests modules is hardwired: ${module}-tests.
582 if test -f modules/"$1"-tests; then
587 # func_acceptable module
588 # tests whether a module is acceptable.
590 # - avoidlist list of modules to avoid
593 for avoid in $avoidlist; do
594 if test "$avoid" = "$1"; then
601 # func_modules_transitive_closure
603 # - modules list of specified modules
604 # - inctests true if tests should be included, blank otherwise
605 # - avoidlist list of modules to avoid
607 # - modules list of modules, including dependencies
608 func_modules_transitive_closure ()
612 for module in $modules; do
614 if test -n "$module"; then
615 # Duplicate dependencies are harmless, but Jim wants a warning.
616 duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
617 if test -n "$duplicated_deps"; then
618 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
620 if func_acceptable $module; then
621 xmodules="$xmodules $module"
622 for depmodule in `func_get_dependencies $module`; do
623 if func_acceptable $depmodule; then
624 xmodules="$xmodules $depmodule"
627 if test -n "$inctests"; then
628 testsmodule=`func_get_tests_module $module`
629 if test -n "$testsmodule"; then
630 if func_acceptable $testsmodule; then
631 xmodules="$xmodules $testsmodule"
632 for depmodule in `func_get_dependencies $testsmodule`; do
633 if func_acceptable $depmodule; then
634 xmodules="$xmodules $depmodule"
643 xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
644 if test "$xmodules" = "$modules"; then
651 # func_modules_add_dummy
653 # - modules list of modules, including dependencies
655 # - modules list of modules, including 'dummy' if needed
656 func_modules_add_dummy ()
659 sed_remove_backslash_newline=':a
666 for module in $modules; do
667 func_verify_nontests_module
668 if test -n "$module"; then
669 # Extract the value of "lib_SOURCES += ...".
670 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
671 # Ignore .h files since they are not compiled.
674 *) have_lib_SOURCES=yes ;;
679 # Add the dummy module, to make sure the library will be non-empty.
680 if test -z "$have_lib_SOURCES"; then
681 modules="$modules dummy"
685 # func_modules_to_filelist
687 # - modules list of modules, including dependencies
689 # - files list of files
690 func_modules_to_filelist ()
693 for module in $modules; do
695 if test -n "$module"; then
696 files="$files "`func_get_filelist $module`
699 files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
702 # func_emit_lib_Makefile_am
703 # emits the contents of lib/Makefile.am to standard output.
705 # - modules list of modules, including dependencies
706 # - libname library name
707 # - libtool true if libtool will be used, blank otherwise
708 # - actioncmd (optional) command that will reproduce this invocation
709 func_emit_lib_Makefile_am ()
711 if test -n "$libtool"; then
718 echo "## Process this file with automake to produce Makefile.in."
719 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
721 echo "# This file is free software, distributed under the terms of the GNU"
722 echo "# General Public License. As a special exception to the GNU General"
723 echo "# Public License, this file may be distributed as part of a program"
724 echo "# that contains a configuration script generated by Automake, under"
725 echo "# the same distribution terms as the rest of that program."
727 echo "# Generated by gnulib-tool."
728 if test -n "$actioncmd"; then
729 echo "# Reproduce by: $actioncmd"
732 # No need to generate dependencies since the sources are in gnulib, not here.
733 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
735 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
737 echo "${libname}_${libext}_SOURCES ="
738 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
739 echo "noinst_HEADERS ="
741 echo "BUILT_SOURCES ="
743 echo "MOSTLYCLEANFILES ="
745 echo "DISTCLEANFILES ="
746 echo "MAINTAINERCLEANFILES ="
750 for module in $modules; do
751 func_verify_nontests_module
752 if test -n "$module"; then
754 func_get_automake_snippet "$module" |
755 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
756 if test "$module" = 'alloca'; then
757 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
760 # Skip the contents if its entirely empty.
761 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
762 echo "## begin gnulib module $module"
765 echo "## end gnulib module $module"
772 echo "# Makefile.am ends here"
775 # func_emit_tests_Makefile_am
776 # emits the contents of tests/Makefile.am to standard output.
778 # - modules list of modules, including dependencies
779 # - libname library name
780 # - libtool true if libtool will be used, blank otherwise
781 # - sourcebase relative directory containing lib source code
782 # - m4base relative directory containing autoconf macros
783 # - testsbase relative directory containing unit test code
784 func_emit_tests_Makefile_am ()
786 if test -n "$libtool"; then
791 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
792 echo "## Process this file with automake to produce Makefile.in."
793 echo "# Copyright (C) 2004-2005 Free Software Foundation, Inc."
795 echo "# This file is free software, distributed under the terms of the GNU"
796 echo "# General Public License. As a special exception to the GNU General"
797 echo "# Public License, this file may be distributed as part of a program"
798 echo "# that contains a configuration script generated by Automake, under"
799 echo "# the same distribution terms as the rest of that program."
801 echo "# Generated by gnulib-tool."
803 # Generate dependencies here, since it eases the debugging of test failures.
804 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
806 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
808 # Nothing is being added to SUBDIRS; nevertheless the existence of this
809 # variable is needed to avoid an error from automake:
810 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
813 echo "TESTS_ENVIRONMENT ="
814 echo "noinst_PROGRAMS ="
815 echo "check_PROGRAMS ="
816 echo "noinst_HEADERS ="
818 echo "BUILT_SOURCES ="
820 echo "MOSTLYCLEANFILES ="
822 echo "DISTCLEANFILES ="
823 echo "MAINTAINERCLEANFILES ="
825 echo "AM_CPPFLAGS = \\"
826 echo " -I. -I\$(srcdir) \\"
827 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
828 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
830 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
832 for module in $modules; do
833 func_verify_tests_module
834 if test -n "$module"; then
835 func_get_automake_snippet "$module" > amsnippet.tmp
836 # Skip the contents if its entirely empty.
837 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
838 echo "## begin gnulib module $module"
841 echo "## end gnulib module $module"
847 echo "# Clean up after Solaris cc."
849 echo " rm -rf SunWS_cache"
851 echo "# Makefile.am ends here"
854 # func_import modules
855 # Uses also the variables
856 # - destdir target directory
857 # - libname library name
858 # - sourcebase directory relative to destdir where to place source code
859 # - m4base directory relative to destdir where to place *.m4 macros
860 # - testsbase directory relative to destdir where to place unit test code
861 # - auxdir directory relative to destdir where to place build aux files
862 # - inctests true if --with-tests was given, blank otherwise
863 # - avoidlist list of modules to avoid, from --avoid
864 # - lgpl true if library's license shall be LGPL, blank otherwise
865 # - libtool true if libtool will be used, blank otherwise
866 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
867 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
868 # - doit : if actions shall be executed, false if only to be printed
869 # - symbolic true if files should be symlinked, copied otherwise
872 # Get the cached settings.
873 cached_specified_modules=
883 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
889 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
892 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
895 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
898 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
901 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
904 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
907 s,^.*$,cached_lgpl=true,p
910 s,^.*$,cached_libtool=true,p
913 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
915 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
916 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
921 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
922 s,^.*$,cached_files=",p
934 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
938 # Merge the cached settings with the specified ones.
939 # The m4base must be the same as expected from the pathname.
940 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
941 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
943 # Append the cached and the specified module names. So that
944 # "gnulib-tool --import foo" means to add the module foo.
945 specified_modules="$cached_specified_modules $1"
946 # Append the cached and the specified avoidlist. This is probably better
947 # than dropping the cached one when --avoid is specified at least once.
948 avoidlist=`echo $cached_avoidlist $avoidlist`
949 # The sourcebase defaults to the cached one.
950 if test -z "$sourcebase"; then
951 sourcebase="$cached_sourcebase"
952 if test -z "$sourcebase"; then
953 func_fatal_error "missing --source-base option"
956 # The testsbase defaults to the cached one.
957 if test -z "$testsbase"; then
958 testsbase="$cached_testsbase"
959 if test -z "$testsbase"; then
960 func_fatal_error "missing --tests-base option"
963 # The libname defaults to the cached one.
964 if test -z "$supplied_libname"; then
965 libname="$cached_libname"
966 if test -z "$libname"; then
967 func_fatal_error "missing --lib option"
970 # Require LGPL if specified either way.
971 if test -z "$lgpl"; then
974 # Use libtool if specified either way, or if guessed.
975 if test -z "$libtool"; then
976 if test -n "$cached_m4base"; then
977 libtool="$cached_libtool"
979 libtool="$guessed_libtool"
982 # The macro_prefix defaults to the cached one.
983 if test -z "$macro_prefix"; then
984 macro_prefix="$cached_macro_prefix"
985 if test -z "$macro_prefix"; then
986 func_fatal_error "missing --macro-prefix option"
990 # Canonicalize the list of specified modules.
991 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
993 # Determine final module list.
994 modules="$specified_modules"
995 func_modules_transitive_closure
996 echo "Module list with included dependencies:"
997 echo "$modules" | sed -e 's/^/ /'
999 # Add the dummy module if needed.
1000 func_modules_add_dummy
1002 # If --lgpl, check the license of modules are compatible.
1003 if test -n "$lgpl"; then
1004 for module in $modules; do
1005 license=`func_get_license $module`
1007 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
1008 *) func_fatal_error "incompatible license on module $module: $license" ;;
1013 # Determine final file list.
1014 func_modules_to_filelist
1016 echo "$files" | sed -e 's/^/ /'
1019 || func_fatal_error "refusing to do nothing"
1021 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1022 new_files="$files m4/gnulib-tool.m4"
1023 old_files="$cached_files"
1024 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1025 old_files="$old_files m4/gnulib-tool.m4"
1028 # Create directories.
1029 if test ! -d "$destdir/$sourcebase"; then
1031 echo "Creating directory $destdir/$sourcebase"
1032 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1034 echo "Create directory $destdir/$sourcebase"
1037 if test ! -d "$destdir/$m4base"; then
1039 echo "Creating directory $destdir/$m4base"
1040 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1042 echo "Create directory $destdir/$m4base"
1045 if test -n "$inctests"; then
1046 if test ! -d "$destdir/$testsbase"; then
1048 echo "Creating directory $destdir/$testsbase"
1049 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1051 echo "Create directory $destdir/$testsbase"
1055 if test ! -d "$destdir/$auxdir"; then
1057 echo "Creating directory $destdir/$auxdir"
1058 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1060 echo "Create directory $destdir/$auxdir"
1065 trap 'rm -rf "$tmp"' 0 1 2 3 15
1066 # func_dest_tmpfilename file
1067 # determines the name of a temporary file (file is relative to destdir).
1069 # - tmpfile absolute filename of the temporary file
1070 func_dest_tmpfilename ()
1073 # Put the new contents of $file in a file in the same directory (needed
1074 # to guarantee that an 'mv' to "$destdir/$file" works).
1075 tmpfile="$destdir/$1.tmp"
1077 # Put the new contents of $file in a file in a temporary directory
1078 # (because the directory of "$file" might not exist).
1079 tmpfile="$tmp"/`basename "$1"`.tmp
1083 # Copy files or make symbolic links. Remove obsolete files.
1085 for f in $old_files; do
1087 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1088 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1089 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1090 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1093 echo "$g""$delimiter""$f"
1094 done | LC_ALL=C sort > "$tmp"/old-files
1095 for f in $new_files; do
1097 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1098 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1099 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1100 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1103 echo "$g""$delimiter""$f"
1104 done | LC_ALL=C sort > "$tmp"/new-files
1105 # First the files that are in old-files, but not in new-files:
1106 sed_take_first_column='s,'"$delimiter"'.*,,'
1107 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1108 # Remove the file. Do nothing if the user already removed it.
1109 if test -f "$destdir/$g"; then
1111 echo "Removing file $g (backup in ${g}~)"
1112 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1114 echo "Remove file $g (backup in ${g}~)"
1118 # func_add_or_update handles a file that ought to be present afterwards.
1119 # Uses parameters f, g, already_present.
1120 func_add_or_update ()
1122 func_dest_tmpfilename "$g"
1123 cp "$gnulib_dir/$f" "$tmpfile" || func_fatal_error "failed"
1124 if test -n "$lgpl"; then
1128 sed -e 's/GNU General/GNU Lesser General/g' \
1129 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1130 < "$gnulib_dir/$f" > "$tmpfile" || func_fatal_error "failed"
1134 if test -f "$destdir/$g"; then
1135 # The file already exists.
1136 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1137 : # The file has not changed.
1141 if test -n "$already_present"; then
1142 echo "Updating file $g (backup in ${g}~)"
1144 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1146 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1147 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1148 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1150 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1153 if test -n "$already_present"; then
1154 echo "Update file $g (backup in ${g}~)"
1156 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1162 # Don't protest if the file should be there but isn't: it happens
1163 # frequently that developers don't put autogenerated files into CVS.
1165 echo "Copying file $g"
1166 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1167 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1169 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1177 # Then the files that are in new-files, but not in old-files:
1178 sed_take_last_column='s,^.*'"$delimiter"',,'
1180 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1182 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1183 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1184 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1185 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1190 # Then the files that are in new-files and in old-files:
1191 already_present=true
1192 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1194 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1195 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1196 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1197 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1203 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1204 actioncmd="gnulib-tool --import"
1205 actioncmd="$actioncmd --dir=$destdir"
1206 actioncmd="$actioncmd --lib=$libname"
1207 actioncmd="$actioncmd --source-base=$sourcebase"
1208 actioncmd="$actioncmd --m4-base=$m4base"
1209 actioncmd="$actioncmd --aux-dir=$auxdir"
1210 for module in $avoidlist; do
1211 actioncmd="$actioncmd --avoid=$module"
1213 if test -n "$lgpl"; then
1214 actioncmd="$actioncmd --lgpl"
1216 if test -n "$libtool"; then
1217 actioncmd="$actioncmd --libtool"
1219 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1220 actioncmd="$actioncmd `echo $specified_modules`"
1222 # Create lib/Makefile.am.
1223 func_dest_tmpfilename $sourcebase/Makefile.am
1224 func_emit_lib_Makefile_am > "$tmpfile"
1225 if test -f "$destdir"/$sourcebase/Makefile.am; then
1226 if cmp "$destdir"/$sourcebase/Makefile.am "$tmpfile" > /dev/null; then
1230 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1231 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1232 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1234 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1240 echo "Creating $sourcebase/Makefile.am"
1241 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1243 echo "Create $sourcebase/Makefile.am"
1248 # Create m4/gnulib-cache.m4.
1249 func_dest_tmpfilename $m4base/gnulib-cache.m4
1251 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1252 echo "# This file is free software, distributed under the terms of the GNU"
1253 echo "# General Public License. As a special exception to the GNU General"
1254 echo "# Public License, this file may be distributed as part of a program"
1255 echo "# that contains a configuration script generated by Autoconf, under"
1256 echo "# the same distribution terms as the rest of that program."
1258 echo "# Generated by gnulib-tool."
1260 echo "# This file represents the specification of how gnulib-tool is used."
1261 echo "# It acts as a cache: It is written and read by gnulib-tool."
1262 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1263 echo "# like the configure.ac and various Makefile.am files."
1266 echo "# Specification in the form of a command-line invocation:"
1269 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1270 echo "gl_MODULES(["`echo $specified_modules`"])"
1271 echo "gl_AVOID([$avoidlist])"
1272 echo "gl_SOURCE_BASE([$sourcebase])"
1273 echo "gl_M4_BASE([$m4base])"
1274 echo "gl_TESTS_BASE([$testsbase])"
1275 echo "gl_LIB([$libname])"
1276 test -z "$lgpl" || echo "gl_LGPL"
1277 test -z "$libtool" || echo "gl_LIBTOOL"
1278 echo "gl_MACRO_PREFIX([$macro_prefix])"
1280 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1281 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1285 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1286 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1287 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1289 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1293 echo "# gnulib-cache.m4 ends here"
1300 echo "Creating $m4base/gnulib-cache.m4"
1301 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1303 echo "Create $m4base/gnulib-cache.m4"
1309 # Create m4/gnulib-comp.m4.
1310 func_dest_tmpfilename $m4base/gnulib-comp.m4
1312 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1313 echo "# This file is free software, distributed under the terms of the GNU"
1314 echo "# General Public License. As a special exception to the GNU General"
1315 echo "# Public License, this file may be distributed as part of a program"
1316 echo "# that contains a configuration script generated by Autoconf, under"
1317 echo "# the same distribution terms as the rest of that program."
1319 echo "# Generated by gnulib-tool."
1321 echo "# This file represents the compiled summary of the specification in"
1322 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1323 echo "# to be invoked from configure.ac."
1324 echo "# In projects using CVS, this file can be treated like other built files."
1327 echo "# This macro should be invoked from $configure_ac, in the section"
1328 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1329 echo "# any checks for libraries, header files, types and library functions."
1330 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1332 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1333 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1334 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1336 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1337 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1339 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1340 echo " AC_REQUIRE([gl_LOCK])"
1344 echo "# This macro should be invoked from $configure_ac, in the section"
1345 echo "# \"Check for header files, types and library functions\"."
1346 echo "AC_DEFUN([${macro_prefix}_INIT],"
1348 if test -z "$libtool"; then
1349 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1351 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1353 if test "$auxdir" != "build-aux"; then
1354 sed_replace_build_aux='
1356 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1357 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1360 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1362 sed_replace_build_aux=
1364 for module in $modules; do
1366 if test -n "$module"; then
1367 func_get_autoconf_snippet "$module" \
1368 | sed -e '/^$/d;' -e 's/^/ /' \
1369 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1370 -e "$sed_replace_build_aux"
1371 if test "$module" = 'alloca' && test -n "$libtool"; then
1372 echo 'changequote(,)dnl'
1373 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1374 echo 'changequote([, ])dnl'
1375 echo 'AC_SUBST([LTALLOCA])'
1381 echo "# This macro records the list of files which have been installed by"
1382 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1383 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1384 echo "$files" | sed -e 's,^, ,'
1387 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1388 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
1392 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1393 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1394 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1396 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1400 echo "# gnulib-comp.m4 ends here"
1407 echo "Creating $m4base/gnulib-comp.m4"
1408 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1410 echo "Create $m4base/gnulib-comp.m4"
1416 if test -n "$inctests"; then
1417 # Create tests/Makefile.am.
1418 func_dest_tmpfilename $testsbase/Makefile.am
1419 func_emit_tests_Makefile_am > "$tmpfile"
1420 if test -f "$destdir"/$testsbase/Makefile.am; then
1421 if cmp "$destdir"/$testsbase/Makefile.am "$tmpfile" > /dev/null; then
1425 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1426 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1427 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1429 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1435 echo "Creating $testsbase/Makefile.am"
1436 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1438 echo "Create $testsbase/Makefile.am"
1445 # Undo the effect of the previous 'trap' command. Some shellology:
1446 # We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
1447 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
1448 # exit); for the others we need to call 'exit' explicitly. The value of $? is
1449 # 128 + signal number and is set before the trap-registered command is run.
1451 trap 'exit $?' 1 2 3 15
1455 echo "You may need to add #include directives for the following .h files."
1457 # First the #include <...> directives without #ifs, sorted for convenience.
1458 for module in $modules; do
1459 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1462 func_get_include_directive "$module" | grep -v 'include "'
1464 done | LC_ALL=C sort -u
1465 # Then the #include "..." directives without #ifs, sorted for convenience.
1466 for module in $modules; do
1467 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1470 func_get_include_directive "$module" | grep 'include "'
1472 done | LC_ALL=C sort -u
1473 # Then the #include directives that are surrounded by #ifs. Not sorted.
1474 for module in $modules; do
1475 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1476 func_get_include_directive "$module"
1479 ) | sed -e '/^$/d;' -e 's/^/ /'
1481 echo "Don't forget to"
1482 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1483 if test -n "$inctests"; then
1484 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1486 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1487 sourcebase_base=`basename "$sourcebase"`
1488 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1489 if test -n "$inctests"; then
1490 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1491 testsbase_base=`basename "$testsbase"`
1492 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1494 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1495 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1496 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1499 # func_create_testdir testdir modules
1501 # - auxdir directory relative to destdir where to place build aux files
1502 func_create_testdir ()
1506 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1508 # Determine final module list.
1509 func_modules_transitive_closure
1510 echo "Module list with included dependencies:"
1511 echo "$modules" | sed -e 's/^/ /'
1513 # Add the dummy module if needed.
1514 func_modules_add_dummy
1516 # Determine final file list.
1517 func_modules_to_filelist
1519 echo "$files" | sed -e 's/^/ /'
1521 # Create directories.
1522 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1523 if test "$d" = build-aux; then
1524 mkdir -p "$testdir/$auxdir"
1526 mkdir -p "$testdir/$d"
1530 # Copy files or make symbolic links.
1533 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1536 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1537 if test -z "$symbolic"; then
1538 cp -p "$gnulib_dir/$f" "$testdir/$g"
1540 ln -s "$gnulib_dir/$f" "$testdir/$g"
1544 # Create lib/Makefile.am.
1545 mkdir -p "$testdir/lib"
1546 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1548 # Create m4/Makefile.am.
1549 mkdir -p "$testdir/m4"
1550 (echo "## Process this file with automake to produce Makefile.in."
1556 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1559 ) > "$testdir/m4/Makefile.am"
1562 subdirs_with_configure_ac=""
1564 if test -f "$testdir"/m4/gettext.m4; then
1565 # Avoid stupid error message from automake:
1566 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1567 mkdir -p "$testdir/po"
1568 (echo "## Process this file with automake to produce Makefile.in."
1569 ) > "$testdir/po/Makefile.am"
1570 subdirs="$subdirs po"
1573 if test -n "$inctests"; then
1574 test -d "$testdir/tests" || mkdir "$testdir/tests"
1575 # Create tests/Makefile.am.
1579 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1580 # Create tests/configure.ac.
1581 (echo "# Process this file with autoconf to produce a configure script."
1582 echo "AC_INIT([dummy], [0])"
1583 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1584 echo "AM_INIT_AUTOMAKE"
1586 echo "AM_CONFIG_HEADER([config.h])"
1589 echo "AC_PROG_INSTALL"
1590 echo "AC_PROG_MAKE_SET"
1591 echo "AC_PROG_RANLIB"
1593 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1594 echo "AC_GNU_SOURCE"
1597 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1598 echo "gl_USE_SYSTEM_EXTENSIONS"
1601 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1605 if test -z "$libtool"; then
1606 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1608 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1610 if test "$auxdir" != "build-aux"; then
1611 sed_replace_build_aux='
1613 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1614 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1617 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1619 sed_replace_build_aux=
1621 # We don't have explicit ordering constraints between the various
1622 # autoconf snippets. It's cleanest to put those of the library before
1623 # those of the tests.
1624 for module in $modules; do
1625 func_verify_nontests_module
1626 if test -n "$module"; then
1627 func_get_autoconf_snippet "$module" \
1628 | sed -e "$sed_replace_build_aux"
1631 for module in $modules; do
1632 func_verify_tests_module
1633 if test -n "$module"; then
1634 func_get_autoconf_snippet "$module" \
1635 | sed -e "$sed_replace_build_aux"
1639 # Usually tests/config.h will be a superset of config.h. Verify this by
1640 # "merging" config.h into tests/config.h; look out for gcc warnings.
1641 echo "AH_TOP([#include \"../config.h\"])"
1643 echo "AC_OUTPUT([Makefile])"
1644 ) > "$testdir/tests/configure.ac"
1645 subdirs="$subdirs tests"
1646 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1649 # Create Makefile.am.
1650 (echo "## Process this file with automake to produce Makefile.in."
1652 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1654 echo "SUBDIRS = $subdirs"
1656 echo "ACLOCAL_AMFLAGS = -I m4"
1657 ) > "$testdir/Makefile.am"
1659 # Create configure.ac.
1660 (echo "# Process this file with autoconf to produce a configure script."
1661 echo "AC_INIT([dummy], [0])"
1662 if test "$auxdir" != "."; then
1663 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1665 echo "AM_INIT_AUTOMAKE"
1667 echo "AM_CONFIG_HEADER([config.h])"
1670 echo "AC_PROG_INSTALL"
1671 echo "AC_PROG_MAKE_SET"
1672 echo "AC_PROG_RANLIB"
1674 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1675 echo "AC_GNU_SOURCE"
1678 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1679 echo "gl_USE_SYSTEM_EXTENSIONS"
1682 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1686 if test -z "$libtool"; then
1687 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1689 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1691 if test "$auxdir" != "build-aux"; then
1692 sed_replace_build_aux='
1694 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1695 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1698 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1700 sed_replace_build_aux=
1702 for module in $modules; do
1703 func_verify_nontests_module
1704 if test -n "$module"; then
1705 func_get_autoconf_snippet "$module" \
1706 | sed -e "$sed_replace_build_aux"
1710 if test -n "$subdirs_with_configure_ac"; then
1711 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1713 makefiles="Makefile"
1714 for d in $subdirs; do
1715 # For subdirs that have a configure.ac by their own, it's the subdir's
1716 # configure.ac which creates the subdir's Makefile.am, not this one.
1717 case " $subdirs_with_configure_ac " in
1719 *) makefiles="$makefiles $d/Makefile" ;;
1722 echo "AC_OUTPUT([$makefiles])"
1723 ) > "$testdir/configure.ac"
1725 # Create autogenerated files.
1727 echo "executing ${AUTORECONF} --force --install"
1728 ${AUTORECONF} --force --install
1730 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1734 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1742 # func_create_megatestdir megatestdir allmodules
1744 # - auxdir directory relative to destdir where to place build aux files
1745 func_create_megatestdir ()
1749 if test -z "$allmodules"; then
1750 allmodules=`func_all_modules`
1754 # First, all modules one by one.
1755 for onemodule in $allmodules; do
1756 func_create_testdir "$megatestdir/$onemodule" $onemodule
1757 megasubdirs="${megasubdirs}$onemodule "
1759 # Then, all modules all together.
1760 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1761 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1762 func_create_testdir "$megatestdir/ALL" "$allmodules"
1763 megasubdirs="${megasubdirs}ALL"
1765 # Create Makefile.am.
1766 (echo "## Process this file with automake to produce Makefile.in."
1768 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1770 echo "SUBDIRS = $megasubdirs"
1771 ) > "$megatestdir/Makefile.am"
1773 # Create configure.ac.
1774 (echo "# Process this file with autoconf to produce a configure script."
1775 echo "AC_INIT([dummy], [0])"
1776 if test "$auxdir" != "."; then
1777 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1779 echo "AM_INIT_AUTOMAKE"
1781 echo "AC_PROG_MAKE_SET"
1783 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1784 echo "AC_OUTPUT([Makefile])"
1785 ) > "$megatestdir/configure.ac"
1787 # Create autogenerated files.
1789 # Do not use "${AUTORECONF} --install", because autoreconf operates
1790 # recursively, but the subdirectories are already finished, therefore
1791 # calling autoreconf here would only waste lots of CPU time.
1792 echo "executing ${ACLOCAL}"
1794 echo "executing mkdir build-aux"
1796 echo "executing ${AUTOCONF}"
1798 echo "executing ${AUTOMAKE} --add-missing --copy"
1799 ${AUTOMAKE} --add-missing --copy
1805 func_fatal_error "no mode specified" ;;
1814 if test -z "$destdir"; then
1817 test -d "$destdir" \
1818 || func_fatal_error "destination directory does not exist: $destdir"
1820 # Prefer configure.ac to configure.in.
1821 if test -f "$destdir"/configure.ac; then
1822 configure_ac="$destdir/configure.ac"
1824 if test -f "$destdir"/configure.in; then
1825 configure_ac="$destdir/configure.in"
1827 func_fatal_error "cannot find $destdir/configure.ac"
1831 test -f "$destdir"/Makefile.am \
1832 || func_fatal_error "cannot find $destdir/Makefile.am"
1834 # Analyze configure.ac.
1841 /AC_CONFIG_AUX_DIR/ {
1842 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1844 /A[CM]_PROG_LIBTOOL/ {
1845 s,^.*$,guessed_libtool=true,p
1847 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1849 if test -z "$auxdir"; then
1850 auxdir="$guessed_auxdir"
1853 # Determine where to apply func_import.
1854 if test -n "$m4base"; then
1855 # Apply func_import to a particular gnulib directory.
1856 # Any number of additional modules can be given.
1857 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1858 # First use of gnulib in the given m4base.
1859 test -n "$supplied_libname" || supplied_libname=true
1860 test -n "$sourcebase" || sourcebase="lib"
1861 test -n "$testsbase" || testsbase="tests"
1862 test -n "$macro_prefix" || macro_prefix="gl"
1866 # Apply func_import to all gnulib directories.
1867 # To get this list of directories, look at Makefile.am. (Not at
1868 # configure, because it may be omitted from CVS. Also, don't run
1869 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1870 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
1874 for arg in $aclocal_amflags; do
1875 if test -n "$m4dir_is_next"; then
1876 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1880 if test -f "$destdir/$arg"/gnulib-cache.m4; then
1881 m4dirs="$m4dirs $arg"
1882 m4dirs_count=`expr $m4dirs_count + 1`
1887 if test "X$arg" = "X-I"; then
1894 if test $m4dirs_count = 0; then
1895 # First use of gnulib in a package.
1896 # Any number of additional modules can be given.
1897 test -n "$supplied_libname" || supplied_libname=true
1898 test -n "$sourcebase" || sourcebase="lib"
1900 test -n "$testsbase" || testsbase="tests"
1901 test -n "$macro_prefix" || macro_prefix="gl"
1904 if test $m4dirs_count = 1; then
1905 # There's only one use of gnulib here. Assume the user means it.
1906 # Any number of additional modules can be given.
1907 for m4base in $m4dirs; do
1911 # Ambiguous - guess what the user meant.
1912 if test $# = 0; then
1913 # No further arguments. Guess the user wants to update all of them.
1914 for m4base in $m4dirs; do
1919 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
1927 if test -z "$destdir"; then
1928 func_fatal_error "please specify --dir option"
1931 test -d "$destdir" \
1932 || func_fatal_error "could not create destination directory"
1933 test -n "$auxdir" || auxdir="build-aux"
1934 func_create_testdir "$destdir" "$*"
1937 create-megatestdir )
1938 if test -z "$destdir"; then
1939 func_fatal_error "please specify --dir option"
1941 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1942 test -n "$auxdir" || auxdir="build-aux"
1943 func_create_megatestdir "$destdir" "$*"
1947 test -n "$destdir" || destdir=testdir$$
1948 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1949 test -n "$auxdir" || auxdir="build-aux"
1950 func_create_testdir "$destdir" "$*"
1958 remaining=`find . -type f -print`
1959 if test -n "$remaining"; then
1960 echo "Remaining files:" $remaining 1>&2
1961 echo "gnulib-tool: *** Stop." 1>&2
1970 test -n "$destdir" || destdir=testdir$$
1971 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1972 test -n "$auxdir" || auxdir="build-aux"
1973 func_create_megatestdir "$destdir" "$*"
1981 remaining=`find . -type f -print`
1982 if test -n "$remaining"; then
1983 echo "Remaining files:" $remaining 1>&2
1984 echo "gnulib-tool: *** Stop." 1>&2
1992 extract-description )
1996 if test -n "$module"; then
1997 func_get_description "$module"
2006 if test -n "$module"; then
2007 func_get_filelist "$module"
2012 extract-dependencies )
2016 if test -n "$module"; then
2017 func_get_dependencies "$module"
2022 extract-autoconf-snippet )
2026 if test -n "$module"; then
2027 func_get_autoconf_snippet "$module"
2032 extract-automake-snippet )
2036 if test -n "$module"; then
2037 func_get_automake_snippet "$module"
2042 extract-include-directive )
2046 if test -n "$module"; then
2047 func_get_include_directive "$module"
2056 if test -n "$module"; then
2057 func_get_license "$module"
2062 extract-maintainer )
2066 if test -n "$module"; then
2067 func_get_maintainer "$module"
2072 extract-tests-module )
2076 if test -n "$module"; then
2077 func_get_tests_module "$module"
2083 func_fatal_error "unknown operation mode --$mode" ;;