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-04-24 11:30: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 "$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 ="
748 for module in $modules; do
749 func_verify_nontests_module
750 if test -n "$module"; then
752 func_get_automake_snippet "$module" |
753 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
754 if test "$module" = 'alloca'; then
755 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
758 # Skip the contents if its entirely empty.
759 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
760 echo "## begin gnulib module $module"
763 echo "## end gnulib module $module"
770 echo "# Makefile.am ends here"
773 # func_emit_tests_Makefile_am
774 # emits the contents of tests/Makefile.am to standard output.
776 # - modules list of modules, including dependencies
777 # - libname library name
778 # - libtool true if libtool will be used, blank otherwise
779 # - sourcebase relative directory containing lib source code
780 # - m4base relative directory containing autoconf macros
781 # - testsbase relative directory containing unit test code
782 func_emit_tests_Makefile_am ()
784 if test -n "$libtool"; then
789 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
790 echo "## Process this file with automake to produce Makefile.in."
791 echo "# Copyright (C) 2004-2005 Free Software Foundation, Inc."
793 echo "# This file is free software, distributed under the terms of the GNU"
794 echo "# General Public License. As a special exception to the GNU General"
795 echo "# Public License, this file may be distributed as part of a program"
796 echo "# that contains a configuration script generated by Automake, under"
797 echo "# the same distribution terms as the rest of that program."
799 echo "# Generated by gnulib-tool."
801 # Generate dependencies here, since it eases the debugging of test failures.
802 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
804 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
806 # Nothing is being added to SUBDIRS; nevertheless the existence of this
807 # variable is needed to avoid an error from automake:
808 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
811 echo "TESTS_ENVIRONMENT ="
812 echo "noinst_PROGRAMS ="
813 echo "check_PROGRAMS ="
814 echo "noinst_HEADERS ="
816 echo "BUILT_SOURCES ="
818 echo "MOSTLYCLEANFILES ="
820 echo "DISTCLEANFILES ="
821 echo "MAINTAINERCLEANFILES ="
823 echo "AM_CPPFLAGS = \\"
824 echo " -I. -I\$(srcdir) \\"
825 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
826 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
828 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
830 for module in $modules; do
831 func_verify_tests_module
832 if test -n "$module"; then
833 func_get_automake_snippet "$module" > amsnippet.tmp
834 # Skip the contents if its entirely empty.
835 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
836 echo "## begin gnulib module $module"
839 echo "## end gnulib module $module"
845 echo "# Clean up after Solaris cc."
847 echo " rm -rf SunWS_cache"
849 echo "# Makefile.am ends here"
852 # func_import modules
853 # Uses also the variables
854 # - destdir target directory
855 # - libname library name
856 # - sourcebase directory relative to destdir where to place source code
857 # - m4base directory relative to destdir where to place *.m4 macros
858 # - testsbase directory relative to destdir where to place unit test code
859 # - auxdir directory relative to destdir where to place build aux files
860 # - inctests true if --with-tests was given, blank otherwise
861 # - avoidlist list of modules to avoid, from --avoid
862 # - lgpl true if library's license shall be LGPL, blank otherwise
863 # - libtool true if libtool will be used, blank otherwise
864 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
865 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
866 # - doit : if actions shall be executed, false if only to be printed
867 # - symbolic true if files should be symlinked, copied otherwise
870 # Get the cached settings.
871 cached_specified_modules=
881 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
887 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
890 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
893 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
896 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
899 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
902 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
905 s,^.*$,cached_lgpl=true,p
908 s,^.*$,cached_libtool=true,p
911 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
913 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
914 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
919 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
920 s,^.*$,cached_files=",p
932 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
936 # Merge the cached settings with the specified ones.
937 # The m4base must be the same as expected from the pathname.
938 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
939 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
941 # Append the cached and the specified module names. So that
942 # "gnulib-tool --import foo" means to add the module foo.
943 specified_modules="$cached_specified_modules $1"
944 # Append the cached and the specified avoidlist. This is probably better
945 # than dropping the cached one when --avoid is specified at least once.
946 avoidlist=`echo $cached_avoidlist $avoidlist`
947 # The sourcebase defaults to the cached one.
948 if test -z "$sourcebase"; then
949 sourcebase="$cached_sourcebase"
950 if test -z "$sourcebase"; then
951 func_fatal_error "missing --source-base option"
954 # The testsbase defaults to the cached one.
955 if test -z "$testsbase"; then
956 testsbase="$cached_testsbase"
957 if test -z "$testsbase"; then
958 func_fatal_error "missing --tests-base option"
961 # The libname defaults to the cached one.
962 if test -z "$supplied_libname"; then
963 libname="$cached_libname"
964 if test -z "$libname"; then
965 func_fatal_error "missing --lib option"
968 # Require LGPL if specified either way.
969 if test -z "$lgpl"; then
972 # Use libtool if specified either way, or if guessed.
973 if test -z "$libtool"; then
974 if test -n "$cached_m4base"; then
975 libtool="$cached_libtool"
977 libtool="$guessed_libtool"
980 # The macro_prefix defaults to the cached one.
981 if test -z "$macro_prefix"; then
982 macro_prefix="$cached_macro_prefix"
983 if test -z "$macro_prefix"; then
984 func_fatal_error "missing --macro-prefix option"
988 # Canonicalize the list of specified modules.
989 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
991 # Determine final module list.
992 modules="$specified_modules"
993 func_modules_transitive_closure
994 echo "Module list with included dependencies:"
995 echo "$modules" | sed -e 's/^/ /'
997 # Add the dummy module if needed.
998 func_modules_add_dummy
1000 # If --lgpl, check the license of modules are compatible.
1001 if test -n "$lgpl"; then
1002 for module in $modules; do
1003 license=`func_get_license $module`
1005 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
1006 *) func_fatal_error "incompatible license on module $module: $license" ;;
1011 # Determine final file list.
1012 func_modules_to_filelist
1014 echo "$files" | sed -e 's/^/ /'
1017 || func_fatal_error "refusing to do nothing"
1019 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1020 new_files="$files m4/gnulib-tool.m4"
1021 old_files="$cached_files"
1022 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1023 old_files="$old_files m4/gnulib-tool.m4"
1026 # Create directories.
1027 if test ! -d "$destdir/$sourcebase"; then
1029 echo "Creating directory $destdir/$sourcebase"
1030 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1032 echo "Create directory $destdir/$sourcebase"
1035 if test ! -d "$destdir/$m4base"; then
1037 echo "Creating directory $destdir/$m4base"
1038 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1040 echo "Create directory $destdir/$m4base"
1043 if test -n "$inctests"; then
1044 if test ! -d "$destdir/$testsbase"; then
1046 echo "Creating directory $destdir/$testsbase"
1047 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1049 echo "Create directory $destdir/$testsbase"
1053 if test ! -d "$destdir/$auxdir"; then
1055 echo "Creating directory $destdir/$auxdir"
1056 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1058 echo "Create directory $destdir/$auxdir"
1063 trap 'rm -rf "$tmp"' 0 1 2 3 15
1064 # func_dest_tmpfilename file
1065 # determines the name of a temporary file (file is relative to destdir).
1067 # - tmpfile absolute filename of the temporary file
1068 func_dest_tmpfilename ()
1071 # Put the new contents of $file in a file in the same directory (needed
1072 # to guarantee that an 'mv' to "$destdir/$file" works).
1073 tmpfile="$destdir/$1.tmp"
1075 # Put the new contents of $file in a file in a temporary directory
1076 # (because the directory of "$file" might not exist).
1077 tmpfile="$tmp"/`basename "$1"`.tmp
1081 # Copy files or make symbolic links. Remove obsolete files.
1083 for f in $old_files; do
1085 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1086 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1087 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1088 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1091 echo "$g""$delimiter""$f"
1092 done | LC_ALL=C sort > "$tmp"/old-files
1093 for f in $new_files; do
1095 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1096 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1097 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1098 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1101 echo "$g""$delimiter""$f"
1102 done | LC_ALL=C sort > "$tmp"/new-files
1103 # First the files that are in old-files, but not in new-files:
1104 sed_take_first_column='s,'"$delimiter"'.*,,'
1105 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1106 # Remove the file. Do nothing if the user already removed it.
1107 if test -f "$destdir/$g"; then
1109 echo "Removing file $g (backup in ${g}~)"
1110 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1112 echo "Remove file $g (backup in ${g}~)"
1116 # func_add_or_update handles a file that ought to be present afterwards.
1117 # Uses parameters f, g, already_present.
1118 func_add_or_update ()
1120 func_dest_tmpfilename "$g"
1121 cp "$gnulib_dir/$f" "$tmpfile" || func_fatal_error "failed"
1122 if test -n "$lgpl"; then
1126 sed -e 's/GNU General/GNU Lesser General/g' \
1127 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1128 < "$gnulib_dir/$f" > "$tmpfile" || func_fatal_error "failed"
1132 if test -f "$destdir/$g"; then
1133 # The file already exists.
1134 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1135 : # The file has not changed.
1139 if test -n "$already_present"; then
1140 echo "Updating file $g (backup in ${g}~)"
1142 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1144 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1145 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1146 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1148 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1151 if test -n "$already_present"; then
1152 echo "Update file $g (backup in ${g}~)"
1154 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1160 # Don't protest if the file should be there but isn't: it happens
1161 # frequently that developers don't put autogenerated files into CVS.
1163 echo "Copying file $g"
1164 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$tmpfile" > /dev/null; then
1165 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1167 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1175 # Then the files that are in new-files, but not in old-files:
1176 sed_take_last_column='s,^.*'"$delimiter"',,'
1178 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1180 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1181 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1182 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1183 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1188 # Then the files that are in new-files and in old-files:
1189 already_present=true
1190 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1192 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1193 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1194 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1195 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1201 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1202 actioncmd="gnulib-tool --import"
1203 actioncmd="$actioncmd --dir=$destdir"
1204 actioncmd="$actioncmd --lib=$libname"
1205 actioncmd="$actioncmd --source-base=$sourcebase"
1206 actioncmd="$actioncmd --m4-base=$m4base"
1207 actioncmd="$actioncmd --aux-dir=$auxdir"
1208 for module in $avoidlist; do
1209 actioncmd="$actioncmd --avoid=$module"
1211 if test -n "$lgpl"; then
1212 actioncmd="$actioncmd --lgpl"
1214 if test -n "$libtool"; then
1215 actioncmd="$actioncmd --libtool"
1217 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1218 actioncmd="$actioncmd `echo $specified_modules`"
1220 # Create lib/Makefile.am.
1221 func_dest_tmpfilename $sourcebase/Makefile.am
1222 func_emit_lib_Makefile_am > "$tmpfile"
1223 if test -f "$destdir"/$sourcebase/Makefile.am; then
1224 if cmp "$destdir"/$sourcebase/Makefile.am "$tmpfile" > /dev/null; then
1228 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1229 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1230 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1232 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1238 echo "Creating $sourcebase/Makefile.am"
1239 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1241 echo "Create $sourcebase/Makefile.am"
1246 # Create m4/gnulib-cache.m4.
1247 func_dest_tmpfilename $m4base/gnulib-cache.m4
1249 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1250 echo "# This file is free software, distributed under the terms of the GNU"
1251 echo "# General Public License. As a special exception to the GNU General"
1252 echo "# Public License, this file may be distributed as part of a program"
1253 echo "# that contains a configuration script generated by Autoconf, under"
1254 echo "# the same distribution terms as the rest of that program."
1256 echo "# Generated by gnulib-tool."
1258 echo "# This file represents the specification of how gnulib-tool is used."
1259 echo "# It acts as a cache: It is written and read by gnulib-tool."
1260 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1261 echo "# like the configure.ac and various Makefile.am files."
1264 echo "# Specification in the form of a command-line invocation:"
1267 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1268 echo "gl_MODULES(["`echo $specified_modules`"])"
1269 echo "gl_AVOID([$avoidlist])"
1270 echo "gl_SOURCE_BASE([$sourcebase])"
1271 echo "gl_M4_BASE([$m4base])"
1272 echo "gl_TESTS_BASE([$testsbase])"
1273 echo "gl_LIB([$libname])"
1274 test -z "$lgpl" || echo "gl_LGPL"
1275 test -z "$libtool" || echo "gl_LIBTOOL"
1276 echo "gl_MACRO_PREFIX([$macro_prefix])"
1278 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1279 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1283 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1284 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1285 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1287 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1291 echo "# gnulib-cache.m4 ends here"
1298 echo "Creating $m4base/gnulib-cache.m4"
1299 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1301 echo "Create $m4base/gnulib-cache.m4"
1307 # Create m4/gnulib-comp.m4.
1308 func_dest_tmpfilename $m4base/gnulib-comp.m4
1310 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1311 echo "# This file is free software, distributed under the terms of the GNU"
1312 echo "# General Public License. As a special exception to the GNU General"
1313 echo "# Public License, this file may be distributed as part of a program"
1314 echo "# that contains a configuration script generated by Autoconf, under"
1315 echo "# the same distribution terms as the rest of that program."
1317 echo "# Generated by gnulib-tool."
1319 echo "# This file represents the compiled summary of the specification in"
1320 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1321 echo "# to be invoked from configure.ac."
1322 echo "# In projects using CVS, this file can be treated like other built files."
1325 echo "# This macro should be invoked from $configure_ac, in the section"
1326 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1327 echo "# any checks for libraries, header files, types and library functions."
1328 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1330 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1331 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1332 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1334 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1335 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1337 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1338 echo " AC_REQUIRE([gl_LOCK])"
1342 echo "# This macro should be invoked from $configure_ac, in the section"
1343 echo "# \"Check for header files, types and library functions\"."
1344 echo "AC_DEFUN([${macro_prefix}_INIT],"
1346 if test -z "$libtool"; then
1347 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1349 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1351 if test "$auxdir" != "build-aux"; then
1352 sed_replace_build_aux='
1354 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1355 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1358 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1360 sed_replace_build_aux=
1362 for module in $modules; do
1364 if test -n "$module"; then
1365 func_get_autoconf_snippet "$module" \
1366 | sed -e '/^$/d;' -e 's/^/ /' \
1367 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1368 -e "$sed_replace_build_aux"
1369 if test "$module" = 'alloca' && test -n "$libtool"; then
1370 echo 'changequote(,)dnl'
1371 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1372 echo 'changequote([, ])dnl'
1373 echo 'AC_SUBST([LTALLOCA])'
1379 echo "# This macro records the list of files which have been installed by"
1380 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1381 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1382 echo "$files" | sed -e 's,^, ,'
1385 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1386 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
1390 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1391 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1392 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1394 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1398 echo "# gnulib-comp.m4 ends here"
1405 echo "Creating $m4base/gnulib-comp.m4"
1406 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1408 echo "Create $m4base/gnulib-comp.m4"
1414 if test -n "$inctests"; then
1415 # Create tests/Makefile.am.
1416 func_dest_tmpfilename $testsbase/Makefile.am
1417 func_emit_tests_Makefile_am > "$tmpfile"
1418 if test -f "$destdir"/$testsbase/Makefile.am; then
1419 if cmp "$destdir"/$testsbase/Makefile.am "$tmpfile" > /dev/null; then
1423 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1424 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1425 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1427 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1433 echo "Creating $testsbase/Makefile.am"
1434 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1436 echo "Create $testsbase/Makefile.am"
1443 # Undo the effect of the previous 'trap' command. Some shellology:
1444 # We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
1445 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
1446 # exit); for the others we need to call 'exit' explicitly. The value of $? is
1447 # 128 + signal number and is set before the trap-registered command is run.
1449 trap 'exit $?' 1 2 3 15
1453 echo "You may need to add #include directives for the following .h files."
1454 for module in $modules; do
1455 func_get_include_directive "$module"
1456 done | LC_ALL=C sort -u | sed -e '/^$/d;' -e 's/^/ /'
1458 echo "Don't forget to"
1459 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1460 if test -n "$inctests"; then
1461 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1463 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1464 sourcebase_base=`basename "$sourcebase"`
1465 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1466 if test -n "$inctests"; then
1467 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1468 testsbase_base=`basename "$testsbase"`
1469 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1471 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1472 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1473 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1476 # func_create_testdir testdir modules
1478 # - auxdir directory relative to destdir where to place build aux files
1479 func_create_testdir ()
1483 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1485 # Determine final module list.
1486 func_modules_transitive_closure
1487 echo "Module list with included dependencies:"
1488 echo "$modules" | sed -e 's/^/ /'
1490 # Add the dummy module if needed.
1491 func_modules_add_dummy
1493 # Determine final file list.
1494 func_modules_to_filelist
1496 echo "$files" | sed -e 's/^/ /'
1498 # Create directories.
1499 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1500 if test "$d" = build-aux; then
1501 mkdir -p "$testdir/$auxdir"
1503 mkdir -p "$testdir/$d"
1507 # Copy files or make symbolic links.
1510 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1513 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1514 if test -z "$symbolic"; then
1515 cp -p "$gnulib_dir/$f" "$testdir/$g"
1517 ln -s "$gnulib_dir/$f" "$testdir/$g"
1521 # Create lib/Makefile.am.
1522 mkdir -p "$testdir/lib"
1523 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1525 # Create m4/Makefile.am.
1526 mkdir -p "$testdir/m4"
1527 (echo "## Process this file with automake to produce Makefile.in."
1533 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1536 ) > "$testdir/m4/Makefile.am"
1539 subdirs_with_configure_ac=""
1541 if test -f "$testdir"/m4/gettext.m4; then
1542 # Avoid stupid error message from automake:
1543 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1544 mkdir -p "$testdir/po"
1545 (echo "## Process this file with automake to produce Makefile.in."
1546 ) > "$testdir/po/Makefile.am"
1547 subdirs="$subdirs po"
1550 if test -n "$inctests"; then
1551 test -d "$testdir/tests" || mkdir "$testdir/tests"
1552 # Create tests/Makefile.am.
1556 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1557 # Create tests/configure.ac.
1558 (echo "# Process this file with autoconf to produce a configure script."
1559 echo "AC_INIT([dummy], [0])"
1560 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1561 echo "AM_INIT_AUTOMAKE"
1563 echo "AM_CONFIG_HEADER([config.h])"
1566 echo "AC_PROG_INSTALL"
1567 echo "AC_PROG_MAKE_SET"
1568 echo "AC_PROG_RANLIB"
1570 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1571 echo "AC_GNU_SOURCE"
1574 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1575 echo "gl_USE_SYSTEM_EXTENSIONS"
1578 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1582 if test -z "$libtool"; then
1583 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1585 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1587 if test "$auxdir" != "build-aux"; then
1588 sed_replace_build_aux='
1590 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1591 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1594 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1596 sed_replace_build_aux=
1598 # We don't have explicit ordering constraints between the various
1599 # autoconf snippets. It's cleanest to put those of the library before
1600 # those of the tests.
1601 for module in $modules; do
1602 func_verify_nontests_module
1603 if test -n "$module"; then
1604 func_get_autoconf_snippet "$module" \
1605 | sed -e "$sed_replace_build_aux"
1608 for module in $modules; do
1609 func_verify_tests_module
1610 if test -n "$module"; then
1611 func_get_autoconf_snippet "$module" \
1612 | sed -e "$sed_replace_build_aux"
1616 # Usually tests/config.h will be a superset of config.h. Verify this by
1617 # "merging" config.h into tests/config.h; look out for gcc warnings.
1618 echo "AH_TOP([#include \"../config.h\"])"
1620 echo "AC_OUTPUT([Makefile])"
1621 ) > "$testdir/tests/configure.ac"
1622 subdirs="$subdirs tests"
1623 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1626 # Create Makefile.am.
1627 (echo "## Process this file with automake to produce Makefile.in."
1629 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1631 echo "SUBDIRS = $subdirs"
1633 echo "ACLOCAL_AMFLAGS = -I m4"
1634 ) > "$testdir/Makefile.am"
1636 # Create configure.ac.
1637 (echo "# Process this file with autoconf to produce a configure script."
1638 echo "AC_INIT([dummy], [0])"
1639 if test "$auxdir" != "."; then
1640 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1642 echo "AM_INIT_AUTOMAKE"
1644 echo "AM_CONFIG_HEADER([config.h])"
1647 echo "AC_PROG_INSTALL"
1648 echo "AC_PROG_MAKE_SET"
1649 echo "AC_PROG_RANLIB"
1651 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1652 echo "AC_GNU_SOURCE"
1655 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1656 echo "gl_USE_SYSTEM_EXTENSIONS"
1659 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1663 if test -z "$libtool"; then
1664 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1666 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1668 if test "$auxdir" != "build-aux"; then
1669 sed_replace_build_aux='
1671 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1672 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1675 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1677 sed_replace_build_aux=
1679 for module in $modules; do
1680 func_verify_nontests_module
1681 if test -n "$module"; then
1682 func_get_autoconf_snippet "$module" \
1683 | sed -e "$sed_replace_build_aux"
1687 if test -n "$subdirs_with_configure_ac"; then
1688 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1690 makefiles="Makefile"
1691 for d in $subdirs; do
1692 # For subdirs that have a configure.ac by their own, it's the subdir's
1693 # configure.ac which creates the subdir's Makefile.am, not this one.
1694 case " $subdirs_with_configure_ac " in
1696 *) makefiles="$makefiles $d/Makefile" ;;
1699 echo "AC_OUTPUT([$makefiles])"
1700 ) > "$testdir/configure.ac"
1702 # Create autogenerated files.
1704 echo "executing ${AUTORECONF} --force --install"
1705 ${AUTORECONF} --force --install
1707 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1711 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1719 # func_create_megatestdir megatestdir allmodules
1721 # - auxdir directory relative to destdir where to place build aux files
1722 func_create_megatestdir ()
1726 if test -z "$allmodules"; then
1727 allmodules=`func_all_modules`
1731 # First, all modules one by one.
1732 for onemodule in $allmodules; do
1733 func_create_testdir "$megatestdir/$onemodule" $onemodule
1734 megasubdirs="${megasubdirs}$onemodule "
1736 # Then, all modules all together.
1737 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1738 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1739 func_create_testdir "$megatestdir/ALL" "$allmodules"
1740 megasubdirs="${megasubdirs}ALL"
1742 # Create Makefile.am.
1743 (echo "## Process this file with automake to produce Makefile.in."
1745 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1747 echo "SUBDIRS = $megasubdirs"
1748 ) > "$megatestdir/Makefile.am"
1750 # Create configure.ac.
1751 (echo "# Process this file with autoconf to produce a configure script."
1752 echo "AC_INIT([dummy], [0])"
1753 if test "$auxdir" != "."; then
1754 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1756 echo "AM_INIT_AUTOMAKE"
1758 echo "AC_PROG_MAKE_SET"
1760 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1761 echo "AC_OUTPUT([Makefile])"
1762 ) > "$megatestdir/configure.ac"
1764 # Create autogenerated files.
1766 # Do not use "${AUTORECONF} --install", because autoreconf operates
1767 # recursively, but the subdirectories are already finished, therefore
1768 # calling autoreconf here would only waste lots of CPU time.
1769 echo "executing ${ACLOCAL}"
1771 echo "executing mkdir build-aux"
1773 echo "executing ${AUTOCONF}"
1775 echo "executing ${AUTOMAKE} --add-missing --copy"
1776 ${AUTOMAKE} --add-missing --copy
1782 func_fatal_error "no mode specified" ;;
1791 if test -z "$destdir"; then
1794 test -d "$destdir" \
1795 || func_fatal_error "destination directory does not exist: $destdir"
1797 # Prefer configure.ac to configure.in.
1798 if test -f "$destdir"/configure.ac; then
1799 configure_ac="$destdir/configure.ac"
1801 if test -f "$destdir"/configure.in; then
1802 configure_ac="$destdir/configure.in"
1804 func_fatal_error "cannot find $destdir/configure.ac"
1808 test -f "$destdir"/Makefile.am \
1809 || func_fatal_error "cannot find $destdir/Makefile.am"
1811 # Analyze configure.ac.
1818 /AC_CONFIG_AUX_DIR/ {
1819 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1821 /A[CM]_PROG_LIBTOOL/ {
1822 s,^.*$,guessed_libtool=true,p
1824 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1826 if test -z "$auxdir"; then
1827 auxdir="$guessed_auxdir"
1830 # Determine where to apply func_import.
1831 if test -n "$m4base"; then
1832 # Apply func_import to a particular gnulib directory.
1833 # Any number of additional modules can be given.
1834 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1835 # First use of gnulib in the given m4base.
1836 test -n "$supplied_libname" || supplied_libname=true
1837 test -n "$sourcebase" || sourcebase="lib"
1838 test -n "$testsbase" || testsbase="tests"
1839 test -n "$macro_prefix" || macro_prefix="gl"
1843 # Apply func_import to all gnulib directories.
1844 # To get this list of directories, look at Makefile.am. (Not at
1845 # configure, because it may be omitted from CVS. Also, don't run
1846 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1847 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
1851 for arg in $aclocal_amflags; do
1852 if test -n "$m4dir_is_next"; then
1853 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1857 if test -f "$destdir/$arg"/gnulib-cache.m4; then
1858 m4dirs="$m4dirs $arg"
1859 m4dirs_count=`expr $m4dirs_count + 1`
1864 if test "X$arg" = "X-I"; then
1871 if test $m4dirs_count = 0; then
1872 # First use of gnulib in a package.
1873 # Any number of additional modules can be given.
1874 test -n "$supplied_libname" || supplied_libname=true
1875 test -n "$sourcebase" || sourcebase="lib"
1877 test -n "$testsbase" || testsbase="tests"
1878 test -n "$macro_prefix" || macro_prefix="gl"
1881 if test $m4dirs_count = 1; then
1882 # There's only one use of gnulib here. Assume the user means it.
1883 # Any number of additional modules can be given.
1884 for m4base in $m4dirs; do
1888 # Ambiguous - guess what the user meant.
1889 if test $# = 0; then
1890 # No further arguments. Guess the user wants to update all of them.
1891 for m4base in $m4dirs; do
1896 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
1904 if test -z "$destdir"; then
1905 func_fatal_error "please specify --dir option"
1908 test -d "$destdir" \
1909 || func_fatal_error "could not create destination directory"
1910 test -n "$auxdir" || auxdir="build-aux"
1911 func_create_testdir "$destdir" "$*"
1914 create-megatestdir )
1915 if test -z "$destdir"; then
1916 func_fatal_error "please specify --dir option"
1918 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1919 test -n "$auxdir" || auxdir="build-aux"
1920 func_create_megatestdir "$destdir" "$*"
1924 test -n "$destdir" || destdir=testdir$$
1925 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1926 test -n "$auxdir" || auxdir="build-aux"
1927 func_create_testdir "$destdir" "$*"
1935 remaining=`find . -type f -print`
1936 if test -n "$remaining"; then
1937 echo "Remaining files:" $remaining 1>&2
1938 echo "gnulib-tool: *** Stop." 1>&2
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_megatestdir "$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
1969 extract-description )
1973 if test -n "$module"; then
1974 func_get_description "$module"
1983 if test -n "$module"; then
1984 func_get_filelist "$module"
1989 extract-dependencies )
1993 if test -n "$module"; then
1994 func_get_dependencies "$module"
1999 extract-autoconf-snippet )
2003 if test -n "$module"; then
2004 func_get_autoconf_snippet "$module"
2009 extract-automake-snippet )
2013 if test -n "$module"; then
2014 func_get_automake_snippet "$module"
2019 extract-include-directive )
2023 if test -n "$module"; then
2024 func_get_include_directive "$module"
2033 if test -n "$module"; then
2034 func_get_license "$module"
2039 extract-maintainer )
2043 if test -n "$module"; then
2044 func_get_maintainer "$module"
2049 extract-tests-module )
2053 if test -n "$module"; then
2054 func_get_tests_module "$module"
2060 func_fatal_error "unknown operation mode --$mode" ;;