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-02-13 15:40:25 $'
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
83 --create-testdir create a scratch package with the given modules
84 --create-megatestdir create a mega scratch package with the given modules
85 one by one and all together
86 --test test the combination of the given modules
87 (recommended to use CC=\"gcc -Wall\" here)
88 --megatest test the given modules one by one and all together
89 (recommended to use CC=\"gcc -Wall\" here)
90 --extract-description extract the description
91 --extract-filelist extract the list of files
92 --extract-dependencies extract the dependencies
93 --extract-autoconf-snippet extract the snippet for configure.ac
94 --extract-automake-snippet extract the snippet for lib/Makefile.am
95 --extract-include-directive extract the #include directive
96 --extract-license report the license terms of the source files
98 --extract-maintainer report the maintainer(s) inside gnulib
99 --extract-tests-module report the unit test module, if it exists
102 --dir=DIRECTORY specify the target directory
103 For --import, this specifies where your
104 configure.ac can be found. Defaults to current
106 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
107 --source-base=DIRECTORY
108 Directory relative --dir where source code is
109 placed (default \"lib\"), for --import.
110 --m4-base=DIRECTORY Directory relative --dir where *.m4 macros are
111 placed (default \"m4\"), for --import.
112 --tests-base=DIRECTORY
113 Directory relative --dir where unit tests are
114 placed (default \"tests\"), for --import.
115 --aux-dir=DIRECTORY Directory relative --dir where auxiliary build
116 tools are placed (default \"build-aux\").
117 --with-tests Include unit tests for the included modules.
118 --avoid=MODULE Avoid including the given MODULE. Useful if you
119 have code that provides equivalent functionality.
120 This option can be repeated.
121 --lgpl Abort if modules aren't available under the LGPL.
122 Also modify license template from GPL to LGPL.
123 --libtool Use libtool rules, for --import.
124 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
125 'gl_INIT'. Default is 'gl'.
126 --no-changelog don't update or create ChangeLog files
127 --dry-run For --import, only print what would have been done.
128 -s, --symbolic, --symlink Make symbolic links instead of copying files.
130 Report bugs to <bug-gnulib@gnu.org>."
134 # outputs to stdout the --version message.
137 echo "$progname (GNU $package) $version"
138 echo "Copyright (C) 2002-2005 Free Software Foundation, Inc.
139 This is free software; see the source for copying conditions. There is NO
140 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
141 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
145 # creates a temporary directory.
147 # - tmp pathname of freshly created temporary directory
150 # Use the environment variable TMPDIR, falling back to /tmp. This allows
151 # users to specify a different temporary directory, for example, if their
152 # /tmp is filled up or too small.
155 # Use the mktemp program if available. If not available, hide the error
157 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
158 test -n "$tmp" && test -d "$tmp"
161 # Use a simple mkdir command. It is guaranteed to fail if the directory
162 # already exists. $RANDOM is bash specific and expands to empty in shells
163 # other than bash, ksh and zsh. Its use does not increase security;
164 # rather, it minimizes the probability of failure in a very cluttered /tmp
166 tmp=$TMPDIR/gl$$-$RANDOM
167 (umask 077 && mkdir "$tmp")
170 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
171 { (exit 1); exit 1; }
175 # func_fatal_error message
176 # outputs to stderr a fatal error message, and terminates the program.
179 echo "gnulib-tool: *** $1" 1>&2
180 echo "gnulib-tool: *** Stop." 1>&2
184 # func_readlink SYMLINK
185 # outputs the target of the given symlink.
186 if (type -p readlink) > /dev/null 2>&1; then
189 # Use the readlink program from GNU coreutils.
195 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
196 # would do the wrong thing if the link target contains " -> ".
197 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
201 # func_ln_if_changed SRC DEST
202 # Like ln -s, but avoids munging timestamps if the link is correct.
203 func_ln_if_changed ()
205 if test $# -ne 2; then
206 echo "usage: func_ln_if_changed SRC DEST" >&2
208 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
216 # Command-line option processing.
217 # Removes the OPTIONS from the arguments. Sets the variables:
218 # - mode list or import or create-testdir or create-megatestdir
219 # - destdir from --dir
220 # - libname, supplied_libname from --lib
221 # - sourcebase from --source-base
222 # - m4base from --m4-base
223 # - testsbase from --tests-base
224 # - auxdir from --aux-dir
225 # - inctests true if --with-tests was given, blank otherwise
226 # - avoidlist list of modules to avoid, from --avoid
227 # - lgpl true if --lgpl was given, blank otherwise
228 # - libtool true if --libtool was given, blank otherwise
229 # - do_changelog false if --no-changelog was given, : otherwise
230 # - doit : if actions shall be executed, false if only to be printed
251 while test $# -gt 0; do
256 --import | --impor | --impo | --imp | --im | --i )
259 --update | --updat | --upda | --upd | --up | --u )
262 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
265 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
266 mode=create-megatestdir
268 --test | --tes | --te | --t )
271 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
275 mode=`echo "X$1" | sed -e 's/^X--//'`
280 func_fatal_error "missing argument for --dir"
285 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
290 func_fatal_error "missing argument for --lib"
293 supplied_libname=true
296 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
297 supplied_libname=true
302 func_fatal_error "missing argument for --source-base"
307 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
312 func_fatal_error "missing argument for --m4-base"
317 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
322 func_fatal_error "missing argument for --tests-base"
327 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
332 func_fatal_error "missing argument for --aux-dir"
337 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
345 func_fatal_error "missing argument for --avoid"
347 avoidlist="$avoidlist $1"
350 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
361 func_fatal_error "missing argument for --macro-prefix"
366 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
368 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
374 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
377 --help | --hel | --he | --h )
380 --version | --versio | --versi | --vers | --ver | --ve | --v )
384 # Stop option processing
388 echo "gnulib-tool: unknown option $1" 1>&2
389 echo "Try 'gnulib-tool --help' for more information." 1>&2
396 if test "$mode" = update; then
397 if test $# != 0; then
398 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
399 echo "Try 'gnulib-tool --help' for more information." 1>&2
400 echo "If you really want to modify the gnulib configuration of your project," 1>&2
401 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
404 if test -n "$libname" || test -n "$sourcebase" || test -n "$m4base" \
405 || test -n "$testsbase" || test -n "$auxdir" || test -n "$inctests" \
406 || test -n "$avoidlist" || test -n "$lgpl" || test -n "$macro_prefix"; then
407 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
408 echo "Try 'gnulib-tool --help' for more information." 1>&2
409 echo "If you really want to modify the gnulib configuration of your project," 1>&2
410 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
416 # Remove trailing slashes from the directory names. This is necessary for
417 # m4base (to avoid an error in func_import) and optional for the others.
418 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
419 case "$sourcebase" in
420 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
423 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
426 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
429 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
434 /*) self_abspathname="$0" ;;
435 */*) self_abspathname=`pwd`/"$0" ;;
436 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
437 if test -x "$d/$0" && test ! -d "$d/$0"; then
438 self_abspathname="$d/$0"
442 if test -z "$self_abspathname"; then
443 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
447 while test -h "$self_abspathname"; do
448 # Resolve symbolic link.
449 linkval=`func_readlink "$self_abspathname"`
450 test -n "$linkval" || break
452 /* ) self_abspathname="$linkval" ;;
453 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
456 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
461 # Filter out metainformation files like README, which are not modules.
462 # Filter out unit test modules; they can be retrieved through
463 # --extract-tests-module if desired.
464 (cd "$gnulib_dir/modules" && ls -1) \
465 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
466 | sed -e '/-tests$/d' \
471 # verifies a module name
472 func_verify_module ()
474 if test ! -f "$gnulib_dir/modules/$module" \
475 || test "CVS" = "$module" \
476 || test "ChangeLog" = "$module" \
477 || test "README" = "$module" \
478 || test "TEMPLATE" = "$module" \
479 || test "TEMPLATE-TESTS" = "$module"; then
480 echo "gnulib-tool: module $module doesn't exist" 1>&2
485 # func_verify_nontests_module
486 # verifies a module name, excluding tests modules
487 func_verify_nontests_module ()
491 * ) func_verify_module ;;
495 # func_verify_tests_module
496 # verifies a module name, considering only tests modules
497 func_verify_tests_module ()
500 *-tests ) func_verify_module ;;
505 sed_extract_prog=':[ ]*$/ {
508 s/^Description:[ ]*$//
510 s/^Depends-on:[ ]*$//
511 s/^configure\.ac:[ ]*$//
512 s/^Makefile\.am:[ ]*$//
515 s/^Maintainer:[ ]*$//
522 # func_get_description module
523 func_get_description ()
525 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
528 # func_get_filelist module
531 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
533 echo m4/onceonly_2_57.m4
536 # func_get_dependencies module
537 func_get_dependencies ()
539 # ${module}-tests always implicitly depends on ${module}.
540 echo "$1" | sed -n -e 's/-tests//p'
541 # Then the explicit dependencies listed in the module description.
542 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
545 # func_get_autoconf_snippet module
546 func_get_autoconf_snippet ()
548 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
551 # func_get_automake_snippet module
552 func_get_automake_snippet ()
554 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
557 # func_get_include_directive module
558 func_get_include_directive ()
560 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
561 sed -e 's/^\(["<]\)/#include \1/'
564 # func_get_license module
567 sed -n -e "/^License$sed_extract_prog" < "$gnulib_dir/modules/$1"
570 # func_get_maintainer module
571 func_get_maintainer ()
573 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
576 # func_get_tests_module module
577 func_get_tests_module ()
579 # The naming convention for tests modules is hardwired: ${module}-tests.
580 if test -f modules/"$1"-tests; then
585 # func_acceptable module
586 # tests whether a module is acceptable.
588 # - avoidlist list of modules to avoid
591 for avoid in $avoidlist; do
592 if test "$avoid" = "$1"; then
599 # func_modules_transitive_closure
601 # - modules list of specified modules
602 # - inctests true if tests should be included, blank otherwise
603 # - avoidlist list of modules to avoid
605 # - modules list of modules, including dependencies
606 func_modules_transitive_closure ()
610 for module in $modules; do
612 if test -n "$module"; then
613 # Duplicate dependencies are harmless, but Jim wants a warning.
614 duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
615 if test -n "$duplicated_deps"; then
616 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
618 if func_acceptable $module; then
619 xmodules="$xmodules $module"
620 for depmodule in `func_get_dependencies $module`; do
621 if func_acceptable $depmodule; then
622 xmodules="$xmodules $depmodule"
625 if test -n "$inctests"; then
626 testsmodule=`func_get_tests_module $module`
627 if test -n "$testsmodule"; then
628 if func_acceptable $testsmodule; then
629 xmodules="$xmodules $testsmodule"
630 for depmodule in `func_get_dependencies $testsmodule`; do
631 if func_acceptable $depmodule; then
632 xmodules="$xmodules $depmodule"
641 xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
642 if test "$xmodules" = "$modules"; then
649 # func_modules_add_dummy
651 # - modules list of modules, including dependencies
653 # - modules list of modules, including 'dummy' if needed
654 func_modules_add_dummy ()
657 sed_remove_backslash_newline=':a
664 for module in $modules; do
665 func_verify_nontests_module
666 if test -n "$module"; then
667 # Extract the value of "lib_SOURCES += ...".
668 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
669 # Ignore .h files since they are not compiled.
672 *) have_lib_SOURCES=yes ;;
677 # Add the dummy module, to make sure the library will be non-empty.
678 if test -z "$have_lib_SOURCES"; then
679 modules="$modules dummy"
683 # func_modules_to_filelist
685 # - modules list of modules, including dependencies
687 # - files list of files
688 func_modules_to_filelist ()
691 for module in $modules; do
693 if test -n "$module"; then
694 files="$files "`func_get_filelist $module`
697 files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
700 # func_emit_lib_Makefile_am
701 # emits the contents of lib/Makefile.am to standard output.
703 # - modules list of modules, including dependencies
704 # - libname library name
705 # - libtool true if libtool will be used, blank otherwise
706 # - actioncmd (optional) command that will reproduce this invocation
707 func_emit_lib_Makefile_am ()
709 if test -n "$libtool"; then
716 echo "## Process this file with automake to produce Makefile.in."
717 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
719 echo "# This file is free software, distributed under the terms of the GNU"
720 echo "# General Public License. As a special exception to the GNU General"
721 echo "# Public License, this file may be distributed as part of a program"
722 echo "# that contains a configuration script generated by Automake, under"
723 echo "# the same distribution terms as the rest of that program."
725 echo "# Generated by gnulib-tool."
726 if test -n "$actioncmd"; then
727 echo "# Reproduce by: $actioncmd"
730 # No need to generate dependencies since the sources are in gnulib, not here.
731 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
733 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
735 echo "${libname}_${libext}_SOURCES ="
736 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
737 echo "noinst_HEADERS ="
739 echo "BUILT_SOURCES ="
741 echo "MOSTLYCLEANFILES ="
743 echo "DISTCLEANFILES ="
744 echo "MAINTAINERCLEANFILES ="
746 for module in $modules; do
747 func_verify_nontests_module
748 if test -n "$module"; then
750 func_get_automake_snippet "$module" |
751 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
752 if test "$module" = 'alloca'; then
753 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
756 # Skip the contents if its entirely empty.
757 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
758 echo "## begin gnulib module $module"
761 echo "## end gnulib module $module"
768 echo "# Makefile.am ends here"
771 # func_emit_tests_Makefile_am
772 # emits the contents of tests/Makefile.am to standard output.
774 # - modules list of modules, including dependencies
775 # - libname library name
776 # - libtool true if libtool will be used, blank otherwise
777 # - sourcebase relative directory containing lib source code
778 # - m4base relative directory containing autoconf macros
779 # - testsbase relative directory containing unit test code
780 func_emit_tests_Makefile_am ()
782 if test -n "$libtool"; then
787 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
788 echo "## Process this file with automake to produce Makefile.in."
789 echo "# Copyright (C) 2004-2005 Free Software Foundation, Inc."
791 echo "# This file is free software, distributed under the terms of the GNU"
792 echo "# General Public License. As a special exception to the GNU General"
793 echo "# Public License, this file may be distributed as part of a program"
794 echo "# that contains a configuration script generated by Automake, under"
795 echo "# the same distribution terms as the rest of that program."
797 echo "# Generated by gnulib-tool."
799 # Generate dependencies here, since it eases the debugging of test failures.
800 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
802 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
804 # Nothing is being added to SUBDIRS; nevertheless the existence of this
805 # variable is needed to avoid an error from automake:
806 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
809 echo "TESTS_ENVIRONMENT ="
810 echo "noinst_PROGRAMS ="
811 echo "check_PROGRAMS ="
812 echo "noinst_HEADERS ="
814 echo "BUILT_SOURCES ="
816 echo "MOSTLYCLEANFILES ="
818 echo "DISTCLEANFILES ="
819 echo "MAINTAINERCLEANFILES ="
821 echo "AM_CPPFLAGS = \\"
822 echo " -I. -I\$(srcdir) \\"
823 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
824 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
826 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
828 for module in $modules; do
829 func_verify_tests_module
830 if test -n "$module"; then
831 func_get_automake_snippet "$module" > amsnippet.tmp
832 # Skip the contents if its entirely empty.
833 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
834 echo "## begin gnulib module $module"
837 echo "## end gnulib module $module"
843 echo "# Clean up after Solaris cc."
845 echo " rm -rf SunWS_cache"
847 echo "# Makefile.am ends here"
850 # func_import modules
851 # Uses also the variables
852 # - destdir target directory
853 # - libname library name
854 # - sourcebase directory relative to destdir where to place source code
855 # - m4base directory relative to destdir where to place *.m4 macros
856 # - testsbase directory relative to destdir where to place unit test code
857 # - auxdir directory relative to destdir where to place build aux files
858 # - inctests true if --with-tests was given, blank otherwise
859 # - avoidlist list of modules to avoid, from --avoid
860 # - lgpl true if library's license shall be LGPL, blank otherwise
861 # - libtool true if libtool will be used, blank otherwise
862 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
863 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
864 # - doit : if actions shall be executed, false if only to be printed
865 # - symbolic true if files should be symlinked, copied otherwise
868 # Get the cached settings.
869 cached_specified_modules=
879 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
885 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
888 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
891 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
894 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
897 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
900 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
903 s,^.*$,cached_lgpl=true,p
906 s,^.*$,cached_libtool=true,p
909 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
911 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
912 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
917 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
918 s,^.*$,cached_files=",p
930 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
934 # Merge the cached settings with the specified ones.
935 # The m4base must be the same as expected from the pathname.
936 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
937 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
939 # Append the cached and the specified module names. So that
940 # "gnulib-tool --import foo" means to add the module foo.
941 specified_modules="$cached_specified_modules $1"
942 # Append the cached and the specified avoidlist. This is probably better
943 # than dropping the cached one when --avoid is specified at least once.
944 avoidlist=`echo $cached_avoidlist $avoidlist`
945 # The sourcebase defaults to the cached one.
946 if test -z "$sourcebase"; then
947 sourcebase="$cached_sourcebase"
948 if test -z "$sourcebase"; then
949 func_fatal_error "missing --source-base option"
952 # The testsbase defaults to the cached one.
953 if test -z "$testsbase"; then
954 testsbase="$cached_testsbase"
955 if test -z "$testsbase"; then
956 func_fatal_error "missing --tests-base option"
959 # The libname defaults to the cached one.
960 if test -z "$supplied_libname"; then
961 libname="$cached_libname"
962 if test -z "$libname"; then
963 func_fatal_error "missing --lib option"
966 # Require LGPL if specified either way.
967 if test -z "$lgpl"; then
970 # Use libtool if specified either way, or if guessed.
971 if test -z "$libtool"; then
972 if test -n "$cached_m4base"; then
973 libtool="$cached_libtool"
975 libtool="$guessed_libtool"
978 # The macro_prefix defaults to the cached one.
979 if test -z "$macro_prefix"; then
980 macro_prefix="$cached_macro_prefix"
981 if test -z "$macro_prefix"; then
982 func_fatal_error "missing --macro-prefix option"
986 # Canonicalize the list of specified modules.
987 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
989 # Determine final module list.
990 modules="$specified_modules"
991 func_modules_transitive_closure
992 echo "Module list with included dependencies:"
993 echo "$modules" | sed -e 's/^/ /'
995 # Add the dummy module if needed.
996 func_modules_add_dummy
998 # If --lgpl, check the license of modules are compatible.
999 if test -n "$lgpl"; then
1000 for module in $modules; do
1001 license=`func_get_license $module`
1003 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
1004 *) func_fatal_error "incompatible license on module $module: $license" ;;
1009 # Determine final file list.
1010 func_modules_to_filelist
1012 echo "$files" | sed -e 's/^/ /'
1015 || func_fatal_error "refusing to do nothing"
1017 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1018 new_files="$files m4/gnulib-tool.m4"
1019 old_files="$cached_files"
1020 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1021 old_files="$old_files m4/gnulib-tool.m4"
1024 # Create directories.
1025 if test ! -d "$destdir/$sourcebase"; then
1027 echo "Creating directory $destdir/$sourcebase"
1028 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1030 echo "Create directory $destdir/$sourcebase"
1033 if test ! -d "$destdir/$m4base"; then
1035 echo "Creating directory $destdir/$m4base"
1036 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1038 echo "Create directory $destdir/$m4base"
1041 if test -n "$inctests"; then
1042 if test ! -d "$destdir/$testsbase"; then
1044 echo "Creating directory $destdir/$testsbase"
1045 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1047 echo "Create directory $destdir/$testsbase"
1051 if test ! -d "$destdir/$auxdir"; then
1053 echo "Creating directory $destdir/$auxdir"
1054 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1056 echo "Create directory $destdir/$auxdir"
1060 # Copy files or make symbolic links. Remove obsolete files.
1062 trap 'rm -rf "$tmp"' 0 1 2 3 15
1064 for f in $old_files; do
1066 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1067 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1068 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1069 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1072 echo "$g""$delimiter""$f"
1073 done | LC_ALL=C sort > "$tmp"/old-files
1074 for f in $new_files; do
1076 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1077 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1078 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1079 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1082 echo "$g""$delimiter""$f"
1083 done | LC_ALL=C sort > "$tmp"/new-files
1084 # First the files that are in old-files, but not in new-files:
1085 sed_take_first_column='s,'"$delimiter"'.*,,'
1086 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1087 # Remove the file. Do nothing if the user already removed it.
1088 if test -f "$destdir/$g"; then
1090 echo "Removing file $g (backup in ${g}~)"
1091 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1093 echo "Remove file $g (backup in ${g}~)"
1097 # func_add_or_update handles a file that ought to be present afterwards.
1098 # Uses parameters f, g, already_present.
1099 func_add_or_update ()
1101 cp "$gnulib_dir/$f" "$destdir/$g.tmp" || func_fatal_error "failed"
1102 if test -n "$lgpl"; then
1106 sed -e 's/GNU General/GNU Lesser General/g' \
1107 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1108 < "$gnulib_dir/$f" > "$destdir/$g.tmp" || func_fatal_error "failed"
1112 if test -f "$destdir/$g"; then
1113 # The file already exists.
1114 if cmp "$destdir/$g" "$destdir/$g.tmp" > /dev/null; then
1115 : # The file has not changed.
1119 if test -n "$already_present"; then
1120 echo "Updating file $g (backup in ${g}~)"
1122 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1124 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1125 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$destdir/$g.tmp" > /dev/null; then
1126 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1128 mv -f "$destdir/$g.tmp" "$destdir/${g}" || func_fatal_error "failed"
1131 if test -n "$already_present"; then
1132 echo "Update file $g (backup in ${g}~)"
1134 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1140 # Don't protest if the file should be there but isn't: it happens
1141 # frequently that developers don't put autogenerated files into CVS.
1143 echo "Copying file $g"
1144 if test -n "$symbolic" && cmp "$gnulib_dir/$f" "$destdir/$g.tmp" > /dev/null; then
1145 func_ln_if_changed "$gnulib_dir/$f" "$destdir/$g"
1147 mv -f "$destdir/$g.tmp" "$destdir/${g}" || func_fatal_error "failed"
1153 rm -f "$destdir/$g.tmp"
1155 # Then the files that are in new-files, but not in old-files:
1156 sed_take_last_column='s,^.*'"$delimiter"',,'
1158 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1160 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1161 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1162 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1163 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1168 # Then the files that are in new-files and in old-files:
1169 already_present=true
1170 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1172 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1173 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1174 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1175 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1181 # Undo the effect of the previous 'trap' command. Some shellology:
1182 # We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
1183 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
1184 # exit); for the others we need to call 'exit' explicitly. The value of $? is
1185 # 128 + signal number and is set before the trap-registered command is run.
1187 trap 'exit $?' 1 2 3 15
1189 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1190 actioncmd="gnulib-tool --import"
1191 actioncmd="$actioncmd --dir=$destdir"
1192 actioncmd="$actioncmd --lib=$libname"
1193 actioncmd="$actioncmd --source-base=$sourcebase"
1194 actioncmd="$actioncmd --m4-base=$m4base"
1195 actioncmd="$actioncmd --aux-dir=$auxdir"
1196 for module in $avoidlist; do
1197 actioncmd="$actioncmd --avoid=$module"
1199 if test -n "$lgpl"; then
1200 actioncmd="$actioncmd --lgpl"
1202 if test -n "$libtool"; then
1203 actioncmd="$actioncmd --libtool"
1205 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1206 actioncmd="$actioncmd `echo $specified_modules`"
1208 # Create lib/Makefile.am.
1209 func_emit_lib_Makefile_am > "$destdir"/$sourcebase/Makefile.am.tmp
1210 if test -f "$destdir"/$sourcebase/Makefile.am; then
1211 if cmp "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am.tmp > /dev/null; then
1212 rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1215 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1216 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1217 mv -f "$destdir"/$sourcebase/Makefile.am.tmp "$destdir"/$sourcebase/Makefile.am
1219 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1220 rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1225 echo "Creating $sourcebase/Makefile.am"
1226 mv -f "$destdir"/$sourcebase/Makefile.am.tmp "$destdir"/$sourcebase/Makefile.am
1228 echo "Create $sourcebase/Makefile.am"
1229 rm -f "$destdir"/$sourcebase/Makefile.am.tmp
1233 # Create m4/gnulib-cache.m4.
1235 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1236 echo "# This file is free software, distributed under the terms of the GNU"
1237 echo "# General Public License. As a special exception to the GNU General"
1238 echo "# Public License, this file may be distributed as part of a program"
1239 echo "# that contains a configuration script generated by Autoconf, under"
1240 echo "# the same distribution terms as the rest of that program."
1242 echo "# Generated by gnulib-tool."
1244 echo "# This file represents the specification of how gnulib-tool is used."
1245 echo "# It acts as a cache: It is written and read by gnulib-tool."
1246 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1247 echo "# like the configure.ac and various Makefile.am files."
1250 echo "# Specification in the form of a command-line invocation:"
1253 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1254 echo "gl_MODULES(["`echo $specified_modules`"])"
1255 echo "gl_AVOID([$avoidlist])"
1256 echo "gl_SOURCE_BASE([$sourcebase])"
1257 echo "gl_M4_BASE([$m4base])"
1258 echo "gl_TESTS_BASE([$testsbase])"
1259 echo "gl_LIB([$libname])"
1260 test -z "$lgpl" || echo "gl_LGPL"
1261 test -z "$libtool" || echo "gl_LIBTOOL"
1262 echo "gl_MACRO_PREFIX([$macro_prefix])"
1263 ) > "$destdir"/$m4base/gnulib-cache.m4.tmp
1264 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1265 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4.tmp > /dev/null; then
1266 rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1269 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1270 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1271 mv -f "$destdir"/$m4base/gnulib-cache.m4.tmp "$destdir"/$m4base/gnulib-cache.m4
1273 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1275 cat "$destdir"/$m4base/gnulib-cache.m4.tmp
1277 echo "# gnulib-cache.m4 ends here"
1279 rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1284 echo "Creating $m4base/gnulib-cache.m4"
1285 mv -f "$destdir"/$m4base/gnulib-cache.m4.tmp "$destdir"/$m4base/gnulib-cache.m4
1287 echo "Create $m4base/gnulib-cache.m4"
1288 cat "$destdir"/$m4base/gnulib-cache.m4.tmp
1289 rm -f "$destdir"/$m4base/gnulib-cache.m4.tmp
1293 # Create m4/gnulib-comp.m4.
1295 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
1296 echo "# This file is free software, distributed under the terms of the GNU"
1297 echo "# General Public License. As a special exception to the GNU General"
1298 echo "# Public License, this file may be distributed as part of a program"
1299 echo "# that contains a configuration script generated by Autoconf, under"
1300 echo "# the same distribution terms as the rest of that program."
1302 echo "# Generated by gnulib-tool."
1304 echo "# This file represents the compiled summary of the specification in"
1305 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1306 echo "# to be invoked from configure.ac."
1307 echo "# In projects using CVS, this file can be treated like other built files."
1310 echo "# This macro should be invoked from $configure_ac, in the section"
1311 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1312 echo "# any checks for libraries, header files, types and library functions."
1313 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1315 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1316 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 > /dev/null; then
1317 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1319 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 > /dev/null; then
1320 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1322 if grep gl_LOCK "$destdir"/$m4base/*.m4 > /dev/null; then
1323 echo " AC_REQUIRE([gl_LOCK])"
1327 echo "# This macro should be invoked from $configure_ac, in the section"
1328 echo "# \"Check for header files, types and library functions\"."
1329 echo "AC_DEFUN([${macro_prefix}_INIT],"
1331 if test -z "$libtool"; then
1332 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1334 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1336 if test "$auxdir" != "build-aux"; then
1337 sed_replace_build_aux='
1339 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1340 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1343 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1345 sed_replace_build_aux=
1347 for module in $modules; do
1349 if test -n "$module"; then
1350 func_get_autoconf_snippet "$module" \
1351 | sed -e '/^$/d;' -e 's/^/ /' \
1352 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1353 -e "$sed_replace_build_aux"
1354 if test "$module" = 'alloca' && test -n "$libtool"; then
1355 echo 'changequote(,)dnl'
1356 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1357 echo 'changequote([, ])dnl'
1358 echo 'AC_SUBST([LTALLOCA])'
1364 echo "# This macro records the list of files which have been installed by"
1365 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1366 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1367 echo "$files" | sed -e 's,^, ,'
1369 ) > "$destdir"/$m4base/gnulib-comp.m4.tmp
1370 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1371 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4.tmp > /dev/null; then
1372 rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1375 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1376 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1377 mv -f "$destdir"/$m4base/gnulib-comp.m4.tmp "$destdir"/$m4base/gnulib-comp.m4
1379 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1381 cat "$destdir"/$m4base/gnulib-comp.m4.tmp
1383 echo "# gnulib-comp.m4 ends here"
1385 rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1390 echo "Creating $m4base/gnulib-comp.m4"
1391 mv -f "$destdir"/$m4base/gnulib-comp.m4.tmp "$destdir"/$m4base/gnulib-comp.m4
1393 echo "Create $m4base/gnulib-comp.m4"
1394 cat "$destdir"/$m4base/gnulib-comp.m4.tmp
1395 rm -f "$destdir"/$m4base/gnulib-comp.m4.tmp
1399 if test -n "$inctests"; then
1400 # Create tests/Makefile.am.
1401 func_emit_tests_Makefile_am > "$destdir"/$testsbase/Makefile.am.tmp
1402 if test -f "$destdir"/$testsbase/Makefile.am; then
1403 if cmp "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am.tmp > /dev/null; then
1404 rm -f "$destdir"/$testsbase/Makefile.am.tmp
1407 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1408 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1409 mv -f "$destdir"/$testsbase/Makefile.am.tmp "$destdir"/$testsbase/Makefile.am
1411 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1412 rm -f "$destdir"/$testsbase/Makefile.am.tmp
1417 echo "Creating $testsbase/Makefile.am"
1418 mv -f "$destdir"/$testsbase/Makefile.am.tmp "$destdir"/$testsbase/Makefile.am
1420 echo "Create $testsbase/Makefile.am"
1421 rm -f "$destdir"/$testsbase/Makefile.am.tmp
1428 echo "You may need to add #include directives for the following .h files."
1429 for module in $modules; do
1430 func_get_include_directive "$module"
1431 done | LC_ALL=C sort -u | sed -e '/^$/d;' -e 's/^/ /'
1433 echo "Don't forget to"
1434 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1435 if test -n "$inctests"; then
1436 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1438 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1439 sourcebase_base=`basename "$sourcebase"`
1440 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1441 if test -n "$inctests"; then
1442 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1443 testsbase_base=`basename "$testsbase"`
1444 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1446 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1447 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1448 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1451 # func_create_testdir testdir modules
1453 # - auxdir directory relative to destdir where to place build aux files
1454 func_create_testdir ()
1458 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1460 # Determine final module list.
1461 func_modules_transitive_closure
1462 echo "Module list with included dependencies:"
1463 echo "$modules" | sed -e 's/^/ /'
1465 # Add the dummy module if needed.
1466 func_modules_add_dummy
1468 # Determine final file list.
1469 func_modules_to_filelist
1471 echo "$files" | sed -e 's/^/ /'
1473 # Create directories.
1474 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1475 if test "$d" = build-aux; then
1476 mkdir -p "$testdir/$auxdir"
1478 mkdir -p "$testdir/$d"
1482 # Copy files or make symbolic links.
1485 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1488 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
1489 if test -z "$symbolic"; then
1490 cp -p "$gnulib_dir/$f" "$testdir/$g"
1492 ln -s "$gnulib_dir/$f" "$testdir/$g"
1496 # Create lib/Makefile.am.
1497 mkdir -p "$testdir/lib"
1498 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1500 # Create m4/Makefile.am.
1501 mkdir -p "$testdir/m4"
1502 (echo "## Process this file with automake to produce Makefile.in."
1508 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1511 ) > "$testdir/m4/Makefile.am"
1514 subdirs_with_configure_ac=""
1516 if test -f "$testdir"/m4/gettext.m4; then
1517 # Avoid stupid error message from automake:
1518 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1519 mkdir -p "$testdir/po"
1520 (echo "## Process this file with automake to produce Makefile.in."
1521 ) > "$testdir/po/Makefile.am"
1522 subdirs="$subdirs po"
1525 if test -n "$inctests"; then
1526 test -d "$testdir/tests" || mkdir "$testdir/tests"
1527 # Create tests/Makefile.am.
1531 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1532 # Create tests/configure.ac.
1533 (echo "# Process this file with autoconf to produce a configure script."
1534 echo "AC_INIT([dummy], [0])"
1535 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1536 echo "AM_INIT_AUTOMAKE"
1538 echo "AM_CONFIG_HEADER([config.h])"
1541 echo "AC_PROG_INSTALL"
1542 echo "AC_PROG_MAKE_SET"
1543 echo "AC_PROG_RANLIB"
1545 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
1546 echo "AC_GNU_SOURCE"
1549 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
1550 echo "gl_USE_SYSTEM_EXTENSIONS"
1553 if grep gl_LOCK "$testdir"/m4/*.m4 > /dev/null; then
1557 if test -z "$libtool"; then
1558 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1560 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1562 if test "$auxdir" != "build-aux"; then
1563 sed_replace_build_aux='
1565 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1566 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1569 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1571 sed_replace_build_aux=
1573 # We don't have explicit ordering constraints between the various
1574 # autoconf snippets. It's cleanest to put those of the library before
1575 # those of the tests.
1576 for module in $modules; do
1577 func_verify_nontests_module
1578 if test -n "$module"; then
1579 func_get_autoconf_snippet "$module" \
1580 | sed -e "$sed_replace_build_aux"
1583 for module in $modules; do
1584 func_verify_tests_module
1585 if test -n "$module"; then
1586 func_get_autoconf_snippet "$module" \
1587 | sed -e "$sed_replace_build_aux"
1591 # Usually tests/config.h will be a superset of config.h. Verify this by
1592 # "merging" config.h into tests/config.h; look out for gcc warnings.
1593 echo "AH_TOP([#include \"../config.h\"])"
1595 echo "AC_OUTPUT([Makefile])"
1596 ) > "$testdir/tests/configure.ac"
1597 subdirs="$subdirs tests"
1598 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1601 # Create Makefile.am.
1602 (echo "## Process this file with automake to produce Makefile.in."
1604 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1606 echo "SUBDIRS = $subdirs"
1608 echo "ACLOCAL_AMFLAGS = -I m4"
1609 ) > "$testdir/Makefile.am"
1611 # Create configure.ac.
1612 (echo "# Process this file with autoconf to produce a configure script."
1613 echo "AC_INIT([dummy], [0])"
1614 if test "$auxdir" != "."; then
1615 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1617 echo "AM_INIT_AUTOMAKE"
1619 echo "AM_CONFIG_HEADER([config.h])"
1622 echo "AC_PROG_INSTALL"
1623 echo "AC_PROG_MAKE_SET"
1624 echo "AC_PROG_RANLIB"
1626 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
1627 echo "AC_GNU_SOURCE"
1630 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
1631 echo "gl_USE_SYSTEM_EXTENSIONS"
1634 if grep gl_LOCK "$testdir"/m4/*.m4 > /dev/null; then
1638 if test -z "$libtool"; then
1639 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1641 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1643 if test "$auxdir" != "build-aux"; then
1644 sed_replace_build_aux='
1646 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1647 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1650 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1652 sed_replace_build_aux=
1654 for module in $modules; do
1655 func_verify_nontests_module
1656 if test -n "$module"; then
1657 func_get_autoconf_snippet "$module" \
1658 | sed -e "$sed_replace_build_aux"
1662 if test -n "$subdirs_with_configure_ac"; then
1663 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1665 makefiles="Makefile"
1666 for d in $subdirs; do
1667 # For subdirs that have a configure.ac by their own, it's the subdir's
1668 # configure.ac which creates the subdir's Makefile.am, not this one.
1669 case " $subdirs_with_configure_ac " in
1671 *) makefiles="$makefiles $d/Makefile" ;;
1674 echo "AC_OUTPUT([$makefiles])"
1675 ) > "$testdir/configure.ac"
1677 # Create autogenerated files.
1679 echo "executing ${AUTORECONF} --force --install"
1680 ${AUTORECONF} --force --install
1682 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1686 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1694 # func_create_megatestdir megatestdir allmodules
1696 # - auxdir directory relative to destdir where to place build aux files
1697 func_create_megatestdir ()
1701 if test -z "$allmodules"; then
1702 allmodules=`func_all_modules`
1706 # First, all modules one by one.
1707 for onemodule in $allmodules; do
1708 func_create_testdir "$megatestdir/$onemodule" $onemodule
1709 megasubdirs="${megasubdirs}$onemodule "
1711 # Then, all modules all together.
1712 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1713 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1714 func_create_testdir "$megatestdir/ALL" "$allmodules"
1715 megasubdirs="${megasubdirs}ALL"
1717 # Create Makefile.am.
1718 (echo "## Process this file with automake to produce Makefile.in."
1720 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1722 echo "SUBDIRS = $megasubdirs"
1723 ) > "$megatestdir/Makefile.am"
1725 # Create configure.ac.
1726 (echo "# Process this file with autoconf to produce a configure script."
1727 echo "AC_INIT([dummy], [0])"
1728 if test "$auxdir" != "."; then
1729 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1731 echo "AM_INIT_AUTOMAKE"
1733 echo "AC_PROG_MAKE_SET"
1735 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1736 echo "AC_OUTPUT([Makefile])"
1737 ) > "$megatestdir/configure.ac"
1739 # Create autogenerated files.
1741 # Do not use "${AUTORECONF} --install", because autoreconf operates
1742 # recursively, but the subdirectories are already finished, therefore
1743 # calling autoreconf here would only waste lots of CPU time.
1744 echo "executing ${ACLOCAL}"
1746 echo "executing mkdir build-aux"
1748 echo "executing ${AUTOCONF}"
1750 echo "executing ${AUTOMAKE} --add-missing --copy"
1751 ${AUTOMAKE} --add-missing --copy
1757 func_fatal_error "no mode specified" ;;
1766 if test -z "$destdir"; then
1769 test -d "$destdir" \
1770 || func_fatal_error "destination directory does not exist: $destdir"
1772 # Prefer configure.ac to configure.in.
1773 if test -f "$destdir"/configure.ac; then
1774 configure_ac="$destdir/configure.ac"
1776 if test -f "$destdir"/configure.in; then
1777 configure_ac="$destdir/configure.in"
1779 func_fatal_error "cannot find $destdir/configure.ac"
1783 test -f "$destdir"/Makefile.am \
1784 || func_fatal_error "cannot find $destdir/Makefile.am"
1786 # Analyze configure.ac.
1793 /AC_CONFIG_AUX_DIR/ {
1794 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1796 /A[CM]_PROG_LIBTOOL/ {
1797 s,^.*$,guessed_libtool=true,p
1799 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1801 if test -z "$auxdir"; then
1802 auxdir="$guessed_auxdir"
1805 # Determine where to apply func_import.
1806 if test -n "$m4base"; then
1807 # Apply func_import to a particular gnulib directory.
1808 # Any number of additional modules can be given.
1809 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
1810 # First use of gnulib in the given m4base.
1811 test -n "$supplied_libname" || supplied_libname=true
1812 test -n "$sourcebase" || sourcebase="lib"
1813 test -n "$testsbase" || testsbase="tests"
1814 test -n "$macro_prefix" || macro_prefix="gl"
1818 # Apply func_import to all gnulib directories.
1819 # To get this list of directories, look at Makefile.am. (Not at
1820 # configure, because it may be omitted from CVS. Also, don't run
1821 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
1822 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
1826 for arg in $aclocal_amflags; do
1827 if test -n "$m4dir_is_next"; then
1828 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
1832 if test -f "$destdir/$arg"/gnulib-cache.m4; then
1833 m4dirs="$m4dirs $arg"
1834 m4dirs_count=`expr $m4dirs_count + 1`
1839 if test "X$arg" = "X-I"; then
1846 if test $m4dirs_count = 0; then
1847 # First use of gnulib in a package.
1848 # Any number of additional modules can be given.
1849 test -n "$supplied_libname" || supplied_libname=true
1850 test -n "$sourcebase" || sourcebase="lib"
1852 test -n "$testsbase" || testsbase="tests"
1853 test -n "$macro_prefix" || macro_prefix="gl"
1856 if test $m4dirs_count = 1; then
1857 # There's only one use of gnulib here. Assume the user means it.
1858 # Any number of additional modules can be given.
1859 for m4base in $m4dirs; do
1863 # Ambiguous - guess what the user meant.
1864 if test $# = 0; then
1865 # No further arguments. Guess the user wants to update all of them.
1866 for m4base in $m4dirs; do
1871 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
1879 if test -z "$destdir"; then
1880 func_fatal_error "please specify --dir option"
1883 test -d "$destdir" \
1884 || func_fatal_error "could not create destination directory"
1885 test -n "$auxdir" || auxdir="build-aux"
1886 func_create_testdir "$destdir" "$*"
1889 create-megatestdir )
1890 if test -z "$destdir"; then
1891 func_fatal_error "please specify --dir option"
1893 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1894 test -n "$auxdir" || auxdir="build-aux"
1895 func_create_megatestdir "$destdir" "$*"
1899 test -n "$destdir" || destdir=testdir$$
1900 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1901 test -n "$auxdir" || auxdir="build-aux"
1902 func_create_testdir "$destdir" "$*"
1910 remaining=`find . -type f -print`
1911 if test -n "$remaining"; then
1912 echo "Remaining files:" $remaining 1>&2
1913 echo "gnulib-tool: *** Stop." 1>&2
1922 test -n "$destdir" || destdir=testdir$$
1923 mkdir "$destdir" || func_fatal_error "could not create destination directory"
1924 test -n "$auxdir" || auxdir="build-aux"
1925 func_create_megatestdir "$destdir" "$*"
1933 remaining=`find . -type f -print`
1934 if test -n "$remaining"; then
1935 echo "Remaining files:" $remaining 1>&2
1936 echo "gnulib-tool: *** Stop." 1>&2
1944 extract-description )
1948 if test -n "$module"; then
1949 func_get_description "$module"
1958 if test -n "$module"; then
1959 func_get_filelist "$module"
1964 extract-dependencies )
1968 if test -n "$module"; then
1969 func_get_dependencies "$module"
1974 extract-autoconf-snippet )
1978 if test -n "$module"; then
1979 func_get_autoconf_snippet "$module"
1984 extract-automake-snippet )
1988 if test -n "$module"; then
1989 func_get_automake_snippet "$module"
1994 extract-include-directive )
1998 if test -n "$module"; then
1999 func_get_include_directive "$module"
2008 if test -n "$module"; then
2009 func_get_license "$module"
2014 extract-maintainer )
2018 if test -n "$module"; then
2019 func_get_maintainer "$module"
2024 extract-tests-module )
2028 if test -n "$module"; then
2029 func_get_tests_module "$module"
2035 func_fatal_error "unknown operation mode --$mode" ;;