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-07-29 13:29:02 $'
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"
56 # GNU sort is needed. Set SORT to its location (not needed if it's called
57 # 'sort' and already in the PATH).
58 if test -z "$SORT"; then
63 # outputs to stdout the --help usage message.
67 Usage: gnulib-tool --list
68 gnulib-tool --import [module1 ... moduleN]
70 gnulib-tool --create-testdir --dir=directory module1 ... moduleN
71 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
72 gnulib-tool --test --dir=directory module1 ... moduleN
73 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
74 gnulib-tool --extract-description module
75 gnulib-tool --extract-filelist module
76 gnulib-tool --extract-dependencies module
77 gnulib-tool --extract-autoconf-snippet module
78 gnulib-tool --extract-automake-snippet module
79 gnulib-tool --extract-include-directive module
80 gnulib-tool --extract-license module
81 gnulib-tool --extract-maintainer module
82 gnulib-tool --extract-tests-module module
85 --list print the available module names
86 --import import the given modules into the current package;
87 if no modules are specified, update the current
88 package from the current gnulib
89 --update update the current package, restore files omitted
91 --create-testdir create a scratch package with the given modules
92 --create-megatestdir create a mega scratch package with the given modules
93 one by one and all together
94 --test test the combination of the given modules
95 (recommended to use CC=\"gcc -Wall\" here)
96 --megatest test the given modules one by one and all together
97 (recommended to use CC=\"gcc -Wall\" here)
98 --extract-description extract the description
99 --extract-filelist extract the list of files
100 --extract-dependencies extract the dependencies
101 --extract-autoconf-snippet extract the snippet for configure.ac
102 --extract-automake-snippet extract the snippet for lib/Makefile.am
103 --extract-include-directive extract the #include directive
104 --extract-license report the license terms of the source files
106 --extract-maintainer report the maintainer(s) inside gnulib
107 --extract-tests-module report the unit test module, if it exists
110 --dir=DIRECTORY Specify the target directory.
111 For --import, this specifies where your
112 configure.ac can be found. Defaults to current
114 --local-dir=DIRECTORY Specify a local override directory where to look
115 up files before looking in gnulib's directory.
117 Options for --import:
118 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
119 --source-base=DIRECTORY
120 Directory relative to --dir where source code is
121 placed (default \"lib\").
122 --m4-base=DIRECTORY Directory relative to --dir where *.m4 macros are
123 placed (default \"m4\").
124 --doc-base=DIRECTORY Directory relative to --dir where doc files are
125 placed (default \"doc\").
126 --tests-base=DIRECTORY
127 Directory relative to --dir where unit tests are
128 placed (default \"tests\").
129 --aux-dir=DIRECTORY Directory relative to --dir where auxiliary build
130 tools are placed (default \"build-aux\").
131 --with-tests Include unit tests for the included modules.
132 --avoid=MODULE Avoid including the given MODULE. Useful if you
133 have code that provides equivalent functionality.
134 This option can be repeated.
135 --lgpl Abort if modules aren't available under the LGPL.
136 Also modify license template from GPL to LGPL.
137 --libtool Use libtool rules.
138 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
139 'gl_INIT'. Default is 'gl'.
140 --no-changelog don't update or create ChangeLog files
142 Options for --import and --update:
143 --dry-run For --import, only print what would have been done.
144 -s, --symbolic, --symlink Make symbolic links instead of copying files.
146 Report bugs to <bug-gnulib@gnu.org>."
150 # outputs to stdout the --version message.
153 year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
154 echo "$progname (GNU $package) $version"
155 echo "Copyright (C) $year Free Software Foundation, Inc.
156 This is free software; see the source for copying conditions. There is NO
157 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
158 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
161 # func_emit_copyright_notice
162 # outputs to stdout a header for a generated file.
163 func_emit_copyright_notice ()
165 echo "# Copyright (C) 2004-2006 Free Software Foundation, Inc."
167 echo "# This file is free software, distributed under the terms of the GNU"
168 echo "# General Public License. As a special exception to the GNU General"
169 echo "# Public License, this file may be distributed as part of a program"
170 echo "# that contains a configuration script generated by Autoconf, under"
171 echo "# the same distribution terms as the rest of that program."
173 echo "# Generated by gnulib-tool."
177 # creates a temporary directory.
179 # - tmp pathname of freshly created temporary directory
182 # Use the environment variable TMPDIR, falling back to /tmp. This allows
183 # users to specify a different temporary directory, for example, if their
184 # /tmp is filled up or too small.
187 # Use the mktemp program if available. If not available, hide the error
189 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
190 test -n "$tmp" && test -d "$tmp"
193 # Use a simple mkdir command. It is guaranteed to fail if the directory
194 # already exists. $RANDOM is bash specific and expands to empty in shells
195 # other than bash, ksh and zsh. Its use does not increase security;
196 # rather, it minimizes the probability of failure in a very cluttered /tmp
198 tmp=$TMPDIR/gl$$-$RANDOM
199 (umask 077 && mkdir "$tmp")
202 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
203 { (exit 1); exit 1; }
207 # func_fatal_error message
208 # outputs to stderr a fatal error message, and terminates the program.
211 echo "gnulib-tool: *** $1" 1>&2
212 echo "gnulib-tool: *** Stop." 1>&2
216 # func_readlink SYMLINK
217 # outputs the target of the given symlink.
218 if (type -p readlink) > /dev/null 2>&1; then
221 # Use the readlink program from GNU coreutils.
227 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
228 # would do the wrong thing if the link target contains " -> ".
229 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
233 # func_ln_if_changed SRC DEST
234 # Like ln -s, but avoids munging timestamps if the link is correct.
235 func_ln_if_changed ()
237 if test $# -ne 2; then
238 echo "usage: func_ln_if_changed SRC DEST" >&2
240 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
248 # Command-line option processing.
249 # Removes the OPTIONS from the arguments. Sets the variables:
250 # - mode list or import or create-testdir or create-megatestdir
251 # - destdir from --dir
252 # - libname, supplied_libname from --lib
253 # - sourcebase from --source-base
254 # - m4base from --m4-base
255 # - docbase from --doc-base
256 # - testsbase from --tests-base
257 # - auxdir from --aux-dir
258 # - inctests true if --with-tests was given, blank otherwise
259 # - avoidlist list of modules to avoid, from --avoid
260 # - lgpl true if --lgpl was given, blank otherwise
261 # - libtool true if --libtool was given, blank otherwise
262 # - macro_prefix from --macro-prefix
263 # - autoconf_minversion minimum supported autoconf version
264 # - do_changelog false if --no-changelog was given, : otherwise
265 # - doit : if actions shall be executed, false if only to be printed
266 # - local_gnulib_dir from --local-dir
267 # - symbolic true if --symbolic was given, blank otherwise
291 while test $# -gt 0; do
296 --import | --impor | --impo | --imp | --im | --i )
299 --update | --updat | --upda | --upd | --up | --u )
302 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
305 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
306 mode=create-megatestdir
308 --test | --tes | --te | --t )
311 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
315 mode=`echo "X$1" | sed -e 's/^X--//'`
320 func_fatal_error "missing argument for --dir"
325 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
330 func_fatal_error "missing argument for --lib"
333 supplied_libname=true
336 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
337 supplied_libname=true
342 func_fatal_error "missing argument for --source-base"
347 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
352 func_fatal_error "missing argument for --m4-base"
357 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
362 func_fatal_error "missing argument for --doc-base"
367 docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
372 func_fatal_error "missing argument for --tests-base"
377 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
382 func_fatal_error "missing argument for --aux-dir"
387 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
395 func_fatal_error "missing argument for --avoid"
397 avoidlist="$avoidlist $1"
400 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
411 func_fatal_error "missing argument for --macro-prefix"
416 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
418 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
427 func_fatal_error "missing argument for --local-dir"
432 local_gnulib_dir=`echo "X$1" | sed -e 's/^X--local-dir=//'`
434 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
437 --help | --hel | --he | --h )
440 --version | --versio | --versi | --vers | --ver | --ve | --v )
444 # Stop option processing
448 echo "gnulib-tool: unknown option $1" 1>&2
449 echo "Try 'gnulib-tool --help' for more information." 1>&2
456 if test "$mode" = update; then
457 if test $# != 0; then
458 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
459 echo "Try 'gnulib-tool --help' for more information." 1>&2
460 echo "If you really want to modify the gnulib configuration of your project," 1>&2
461 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
464 if test -n "$supplied_libname" || test -n "$sourcebase" || test -n "$m4base" \
465 || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
466 || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
467 || test -n "$macro_prefix"; then
468 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
469 echo "Try 'gnulib-tool --help' for more information." 1>&2
470 echo "If you really want to modify the gnulib configuration of your project," 1>&2
471 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
477 # Determine the minimum supported autoconf version from the project's
479 DEFAULT_AUTOCONF_MINVERSION="2.59"
480 if test -f configure.ac; then
481 autoconf_minversion=`$AUTOCONF --trace=AC_PREREQ:'$1' | $SORT -g | uniq | tail -1`
483 if test -z "$autoconf_minversion"; then
484 autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
486 case "$autoconf_minversion" in
487 1.* | 2.[0-4]* | 2.5[0-8]*)
488 func_fatal_error "minimum supported autoconf version is 2.59. Try adding AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
491 # Remove trailing slashes from the directory names. This is necessary for
492 # m4base (to avoid an error in func_import) and optional for the others.
493 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
494 case "$sourcebase" in
495 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
498 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
501 */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
504 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
507 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
512 /*) self_abspathname="$0" ;;
513 */*) self_abspathname=`pwd`/"$0" ;;
514 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
515 if test -x "$d/$0" && test ! -d "$d/$0"; then
516 self_abspathname="$d/$0"
520 if test -z "$self_abspathname"; then
521 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
525 while test -h "$self_abspathname"; do
526 # Resolve symbolic link.
527 linkval=`func_readlink "$self_abspathname"`
528 test -n "$linkval" || break
530 /* ) self_abspathname="$linkval" ;;
531 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
534 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
537 trap 'rm -rf "$tmp"' 0 1 2 3 15
539 # func_lookup_file file
540 # looks up a file in $local_gnulib_dir or $gnulib_dir, or combines it through
543 # - lookedup_file name of the merged (combined) file
544 # - lookedup_tmp true if it is located in the tmp directory, blank otherwise
548 if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile"; then
549 lookedup_file="$local_gnulib_dir/$lkfile"
552 if test -f "$gnulib_dir/$lkfile"; then
553 if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile.diff"; then
554 lkbase=`echo "$lkfile" | sed -e 's,^.*/,,'`
556 cp "$gnulib_dir/$lkfile" "$tmp/$lkbase"
557 patch -s "$tmp/$lkbase" < "$local_gnulib_dir/$lkfile.diff" \
558 || func_fatal_error "patch file $local_gnulib_dir/$lkfile.diff didn't apply cleanly"
559 lookedup_file="$tmp/$lkbase"
562 lookedup_file="$gnulib_dir/$lkfile"
566 func_fatal_error "file $gnulib_dir/$lkfile not found"
574 # Filter out metainformation files like README, which are not modules.
575 # Filter out unit test modules; they can be retrieved through
576 # --extract-tests-module if desired.
578 (cd "$gnulib_dir/modules" && ls -1)
579 if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
580 (cd "$local_gnulib_dir/modules" && ls -1 | sed -e 's,\.diff$,,')
583 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
584 | sed -e '/-tests$/d' \
590 # verifies a module name
591 func_verify_module ()
593 if ! { test -f "$gnulib_dir/modules/$module" \
594 || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
595 && test -f "$local_gnulib_dir/modules/$module"; }; } \
596 || test "CVS" = "$module" \
597 || test "ChangeLog" = "$module" \
598 || test "README" = "$module" \
599 || test "TEMPLATE" = "$module" \
600 || test "TEMPLATE-TESTS" = "$module"; then
601 echo "gnulib-tool: module $module doesn't exist" 1>&2
606 # func_verify_nontests_module
607 # verifies a module name, excluding tests modules
608 func_verify_nontests_module ()
612 * ) func_verify_module ;;
616 # func_verify_tests_module
617 # verifies a module name, considering only tests modules
618 func_verify_tests_module ()
621 *-tests ) func_verify_module ;;
626 sed_extract_prog=':[ ]*$/ {
629 s/^Description:[ ]*$//
631 s/^Depends-on:[ ]*$//
632 s/^configure\.ac:[ ]*$//
633 s/^Makefile\.am:[ ]*$//
636 s/^Maintainer:[ ]*$//
643 # func_get_description module
644 func_get_description ()
646 func_lookup_file "modules/$1"
647 sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
650 # func_get_filelist module
653 func_lookup_file "modules/$1"
654 sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"
655 case "$autoconf_minversion" in
658 echo m4/onceonly_2_57.m4
663 # func_get_dependencies module
664 func_get_dependencies ()
666 # ${module}-tests always implicitly depends on ${module}.
667 echo "$1" | sed -n -e 's/-tests//p'
668 # Then the explicit dependencies listed in the module description.
669 func_lookup_file "modules/$1"
670 sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"
673 # func_get_autoconf_snippet module
674 func_get_autoconf_snippet ()
676 func_lookup_file "modules/$1"
677 sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
680 # func_get_automake_snippet module
681 func_get_automake_snippet ()
683 func_lookup_file "modules/$1"
684 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
687 # func_get_include_directive module
688 func_get_include_directive ()
690 func_lookup_file "modules/$1"
691 sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" | \
692 sed -e 's/^\(["<]\)/#include \1/'
695 # func_get_license module
698 func_lookup_file "modules/$1"
699 sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
702 # func_get_maintainer module
703 func_get_maintainer ()
705 func_lookup_file "modules/$1"
706 sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
709 # func_get_tests_module module
710 func_get_tests_module ()
712 # The naming convention for tests modules is hardwired: ${module}-tests.
713 if test -f modules/"$1"-tests; then
718 # func_acceptable module
719 # tests whether a module is acceptable.
721 # - avoidlist list of modules to avoid
724 for avoid in $avoidlist; do
725 if test "$avoid" = "$1"; then
732 # func_modules_transitive_closure
734 # - modules list of specified modules
735 # - inctests true if tests should be included, blank otherwise
736 # - avoidlist list of modules to avoid
738 # - modules list of modules, including dependencies
739 func_modules_transitive_closure ()
743 for module in $modules; do
745 if test -n "$module"; then
746 # Duplicate dependencies are harmless, but Jim wants a warning.
747 duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
748 if test -n "$duplicated_deps"; then
749 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
751 if func_acceptable $module; then
752 xmodules="$xmodules $module"
753 for depmodule in `func_get_dependencies $module`; do
754 if func_acceptable $depmodule; then
755 xmodules="$xmodules $depmodule"
758 if test -n "$inctests"; then
759 testsmodule=`func_get_tests_module $module`
760 if test -n "$testsmodule"; then
761 if func_acceptable $testsmodule; then
762 xmodules="$xmodules $testsmodule"
763 for depmodule in `func_get_dependencies $testsmodule`; do
764 if func_acceptable $depmodule; then
765 xmodules="$xmodules $depmodule"
774 xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
775 if test "$xmodules" = "$modules"; then
782 # func_modules_add_dummy
784 # - modules list of modules, including dependencies
786 # - modules list of modules, including 'dummy' if needed
787 func_modules_add_dummy ()
790 sed_remove_backslash_newline=':a
797 for module in $modules; do
798 func_verify_nontests_module
799 if test -n "$module"; then
800 # Extract the value of "lib_SOURCES += ...".
801 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
802 # Ignore .h files since they are not compiled.
805 *) have_lib_SOURCES=yes ;;
810 # Add the dummy module, to make sure the library will be non-empty.
811 if test -z "$have_lib_SOURCES"; then
812 modules="$modules dummy"
816 # func_modules_to_filelist
818 # - modules list of modules, including dependencies
820 # - files list of files
821 func_modules_to_filelist ()
824 for module in $modules; do
826 if test -n "$module"; then
827 files="$files "`func_get_filelist $module`
830 files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
833 # func_emit_lib_Makefile_am
834 # emits the contents of lib/Makefile.am to standard output.
836 # - modules list of modules, including dependencies
837 # - libname library name
838 # - libtool true if libtool will be used, blank otherwise
839 # - actioncmd (optional) command that will reproduce this invocation
840 func_emit_lib_Makefile_am ()
842 if test -n "$libtool"; then
849 echo "## Process this file with automake to produce Makefile.in."
850 func_emit_copyright_notice
851 if test -n "$actioncmd"; then
852 echo "# Reproduce by: $actioncmd"
855 # No need to generate dependencies since the sources are in gnulib, not here.
856 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
858 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
860 echo "${libname}_${libext}_SOURCES ="
861 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
862 echo "noinst_HEADERS ="
864 echo "BUILT_SOURCES ="
866 echo "MOSTLYCLEANFILES ="
867 echo "MOSTLYCLEANDIRS ="
869 echo "DISTCLEANFILES ="
870 echo "MAINTAINERCLEANFILES ="
874 for module in $modules; do
875 func_verify_nontests_module
876 if test -n "$module"; then
878 func_get_automake_snippet "$module" |
879 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
880 if test "$module" = 'alloca'; then
881 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
884 # Skip the contents if its entirely empty.
885 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
886 echo "## begin gnulib module $module"
889 echo "## end gnulib module $module"
896 echo "mostlyclean-local:"
897 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
898 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
899 echo " if test -d \$\$dir; then \\"
900 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
904 echo "# Makefile.am ends here"
907 # func_emit_tests_Makefile_am
908 # emits the contents of tests/Makefile.am to standard output.
910 # - modules list of modules, including dependencies
911 # - libname library name
912 # - libtool true if libtool will be used, blank otherwise
913 # - sourcebase relative directory containing lib source code
914 # - m4base relative directory containing autoconf macros
915 # - testsbase relative directory containing unit test code
916 func_emit_tests_Makefile_am ()
918 if test -n "$libtool"; then
923 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
924 echo "## Process this file with automake to produce Makefile.in."
925 func_emit_copyright_notice
927 # Generate dependencies here, since it eases the debugging of test failures.
928 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
930 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
932 # Nothing is being added to SUBDIRS; nevertheless the existence of this
933 # variable is needed to avoid an error from automake:
934 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
937 echo "TESTS_ENVIRONMENT ="
938 echo "noinst_PROGRAMS ="
939 echo "check_PROGRAMS ="
940 echo "noinst_HEADERS ="
942 echo "BUILT_SOURCES ="
944 echo "MOSTLYCLEANFILES ="
945 echo "MOSTLYCLEANDIRS ="
947 echo "DISTCLEANFILES ="
948 echo "MAINTAINERCLEANFILES ="
950 echo "AM_CPPFLAGS = \\"
951 echo " -I. -I\$(srcdir) \\"
952 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
953 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
955 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
957 for module in $modules; do
958 func_verify_tests_module
959 if test -n "$module"; then
960 func_get_automake_snippet "$module" > amsnippet.tmp
961 # Skip the contents if its entirely empty.
962 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
963 echo "## begin gnulib module $module"
966 echo "## end gnulib module $module"
972 echo "# Clean up after Solaris cc."
974 echo " rm -rf SunWS_cache"
976 echo "mostlyclean-local:"
977 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
978 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
979 echo " if test -d \$\$dir; then \\"
980 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
984 echo "# Makefile.am ends here"
987 # func_import modules
988 # Uses also the variables
989 # - destdir target directory
990 # - libname library name
991 # - sourcebase directory relative to destdir where to place source code
992 # - m4base directory relative to destdir where to place *.m4 macros
993 # - docbase directory relative to destdir where to place doc files
994 # - testsbase directory relative to destdir where to place unit test code
995 # - auxdir directory relative to destdir where to place build aux files
996 # - inctests true if --with-tests was given, blank otherwise
997 # - avoidlist list of modules to avoid, from --avoid
998 # - lgpl true if library's license shall be LGPL, blank otherwise
999 # - libtool true if libtool will be used, blank otherwise
1000 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
1001 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
1002 # - autoconf_minversion minimum supported autoconf version
1003 # - doit : if actions shall be executed, false if only to be printed
1004 # - symbolic true if files should be symlinked, copied otherwise
1007 # Get the cached settings.
1008 cached_specified_modules=
1017 cached_macro_prefix=
1019 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1025 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
1028 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
1031 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
1034 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
1037 s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
1040 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
1043 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
1046 s,^.*$,cached_lgpl=true,p
1049 s,^.*$,cached_libtool=true,p
1051 /gl_MACRO_PREFIX(/ {
1052 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
1054 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
1055 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1060 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
1061 s,^.*$,cached_files=",p
1073 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
1077 # Merge the cached settings with the specified ones.
1078 # The m4base must be the same as expected from the pathname.
1079 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
1080 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
1082 # Append the cached and the specified module names. So that
1083 # "gnulib-tool --import foo" means to add the module foo.
1084 specified_modules="$cached_specified_modules $1"
1085 # Append the cached and the specified avoidlist. This is probably better
1086 # than dropping the cached one when --avoid is specified at least once.
1087 avoidlist=`echo $cached_avoidlist $avoidlist`
1088 # The sourcebase defaults to the cached one.
1089 if test -z "$sourcebase"; then
1090 sourcebase="$cached_sourcebase"
1091 if test -z "$sourcebase"; then
1092 func_fatal_error "missing --source-base option"
1095 # The docbase defaults to the cached one.
1096 if test -z "$docbase"; then
1097 docbase="$cached_docbase"
1098 if test -z "$docbase"; then
1099 func_fatal_error "missing --doc-base option. --doc-base has been introduced on 2006-07-11; if your last invocation of 'gnulib-tool --update' is before that date, you need to run 'gnulib-tool --update' once, with a --doc-base option."
1102 # The testsbase defaults to the cached one.
1103 if test -z "$testsbase"; then
1104 testsbase="$cached_testsbase"
1105 if test -z "$testsbase"; then
1106 func_fatal_error "missing --tests-base option"
1109 # The libname defaults to the cached one.
1110 if test -z "$supplied_libname"; then
1111 libname="$cached_libname"
1112 if test -z "$libname"; then
1113 func_fatal_error "missing --lib option"
1116 # Require LGPL if specified either way.
1117 if test -z "$lgpl"; then
1120 # Use libtool if specified either way, or if guessed.
1121 if test -z "$libtool"; then
1122 if test -n "$cached_m4base"; then
1123 libtool="$cached_libtool"
1125 libtool="$guessed_libtool"
1128 # The macro_prefix defaults to the cached one.
1129 if test -z "$macro_prefix"; then
1130 macro_prefix="$cached_macro_prefix"
1131 if test -z "$macro_prefix"; then
1132 func_fatal_error "missing --macro-prefix option"
1136 # Canonicalize the list of specified modules.
1137 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1139 # Determine final module list.
1140 modules="$specified_modules"
1141 func_modules_transitive_closure
1142 echo "Module list with included dependencies:"
1143 echo "$modules" | sed -e 's/^/ /'
1145 # Add the dummy module if needed.
1146 func_modules_add_dummy
1148 # If --lgpl, check the license of modules are compatible.
1149 if test -n "$lgpl"; then
1150 for module in $modules; do
1151 license=`func_get_license $module`
1153 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
1154 *) func_fatal_error "incompatible license on module $module: $license" ;;
1159 # Determine final file list.
1160 func_modules_to_filelist
1162 echo "$files" | sed -e 's/^/ /'
1165 || func_fatal_error "refusing to do nothing"
1167 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1168 new_files="$files m4/gnulib-tool.m4"
1169 old_files="$cached_files"
1170 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1171 old_files="$old_files m4/gnulib-tool.m4"
1174 # Create directories.
1175 if test ! -d "$destdir/$sourcebase"; then
1177 echo "Creating directory $destdir/$sourcebase"
1178 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1180 echo "Create directory $destdir/$sourcebase"
1183 if test ! -d "$destdir/$m4base"; then
1185 echo "Creating directory $destdir/$m4base"
1186 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1188 echo "Create directory $destdir/$m4base"
1191 docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
1192 if test -n "$docfiles"; then
1193 if test ! -d "$destdir/$docbase"; then
1195 echo "Creating directory $destdir/$docbase"
1196 mkdir "$destdir/$docbase" || func_fatal_error "failed"
1198 echo "Create directory $destdir/$docbase"
1202 if test -n "$inctests"; then
1203 if test ! -d "$destdir/$testsbase"; then
1205 echo "Creating directory $destdir/$testsbase"
1206 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1208 echo "Create directory $destdir/$testsbase"
1212 if test ! -d "$destdir/$auxdir"; then
1214 echo "Creating directory $destdir/$auxdir"
1215 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1217 echo "Create directory $destdir/$auxdir"
1221 # func_dest_tmpfilename file
1222 # determines the name of a temporary file (file is relative to destdir).
1224 # - tmpfile absolute filename of the temporary file
1225 func_dest_tmpfilename ()
1228 # Put the new contents of $file in a file in the same directory (needed
1229 # to guarantee that an 'mv' to "$destdir/$file" works).
1230 tmpfile="$destdir/$1.tmp"
1232 # Put the new contents of $file in a file in a temporary directory
1233 # (because the directory of "$file" might not exist).
1234 tmpfile="$tmp"/`basename "$1"`.tmp
1238 # Copy files or make symbolic links. Remove obsolete files.
1240 for f in $old_files; do
1242 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1243 doc/*) g=`echo "$f" | sed -e "s,^doc/,$cached_docbase/,"` ;;
1244 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1245 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1246 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1249 echo "$g""$delimiter""$f"
1250 done | LC_ALL=C sort > "$tmp"/old-files
1251 for f in $new_files; do
1253 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1254 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1255 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1256 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1257 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1260 echo "$g""$delimiter""$f"
1261 done | LC_ALL=C sort > "$tmp"/new-files
1262 # First the files that are in old-files, but not in new-files:
1263 sed_take_first_column='s,'"$delimiter"'.*,,'
1264 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1265 # Remove the file. Do nothing if the user already removed it.
1266 if test -f "$destdir/$g"; then
1268 echo "Removing file $g (backup in ${g}~)"
1269 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1271 echo "Remove file $g (backup in ${g}~)"
1275 # func_add_or_update handles a file that ought to be present afterwards.
1276 # Uses parameters f, g, already_present.
1277 func_add_or_update ()
1279 func_dest_tmpfilename "$g"
1280 func_lookup_file "$f"
1281 cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
1282 if test -n "$lgpl"; then
1286 sed -e 's/GNU General/GNU Lesser General/g' \
1287 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1288 < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
1292 if test -f "$destdir/$g"; then
1293 # The file already exists.
1294 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1295 : # The file has not changed.
1299 if test -n "$already_present"; then
1300 echo "Updating file $g (backup in ${g}~)"
1302 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1304 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1305 if test -n "$symbolic" && test -z "$lookedup_tmp" \
1306 && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1307 func_ln_if_changed "$lookedup_file" "$destdir/$g"
1309 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1312 if test -n "$already_present"; then
1313 echo "Update file $g (backup in ${g}~)"
1315 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1321 # Don't protest if the file should be there but isn't: it happens
1322 # frequently that developers don't put autogenerated files into CVS.
1324 echo "Copying file $g"
1325 if test -n "$symbolic" && test -z "$lookedup_tmp" \
1326 && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1327 func_ln_if_changed "$lookedup_file" "$destdir/$g"
1329 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1337 # Then the files that are in new-files, but not in old-files:
1338 sed_take_last_column='s,^.*'"$delimiter"',,'
1340 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1342 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1343 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1344 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1345 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1346 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1351 # Then the files that are in new-files and in old-files:
1352 already_present=true
1353 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1355 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1356 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1357 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1358 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1359 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1365 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1366 actioncmd="gnulib-tool --import"
1367 actioncmd="$actioncmd --dir=$destdir"
1368 actioncmd="$actioncmd --lib=$libname"
1369 actioncmd="$actioncmd --source-base=$sourcebase"
1370 actioncmd="$actioncmd --m4-base=$m4base"
1371 actioncmd="$actioncmd --doc-base=$docbase"
1372 actioncmd="$actioncmd --aux-dir=$auxdir"
1373 for module in $avoidlist; do
1374 actioncmd="$actioncmd --avoid=$module"
1376 if test -n "$lgpl"; then
1377 actioncmd="$actioncmd --lgpl"
1379 if test -n "$libtool"; then
1380 actioncmd="$actioncmd --libtool"
1382 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1383 actioncmd="$actioncmd `echo $specified_modules`"
1385 # Create lib/Makefile.am.
1386 func_dest_tmpfilename $sourcebase/Makefile.am
1387 func_emit_lib_Makefile_am > "$tmpfile"
1388 if test -f "$destdir"/$sourcebase/Makefile.am; then
1389 if cmp "$destdir"/$sourcebase/Makefile.am "$tmpfile" > /dev/null; then
1393 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1394 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1395 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1397 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1403 echo "Creating $sourcebase/Makefile.am"
1404 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1406 echo "Create $sourcebase/Makefile.am"
1411 # Create m4/gnulib-cache.m4.
1412 func_dest_tmpfilename $m4base/gnulib-cache.m4
1414 func_emit_copyright_notice
1416 echo "# This file represents the specification of how gnulib-tool is used."
1417 echo "# It acts as a cache: It is written and read by gnulib-tool."
1418 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1419 echo "# like the configure.ac and various Makefile.am files."
1422 echo "# Specification in the form of a command-line invocation:"
1425 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1426 echo "gl_MODULES(["`echo $specified_modules`"])"
1427 echo "gl_AVOID([$avoidlist])"
1428 echo "gl_SOURCE_BASE([$sourcebase])"
1429 echo "gl_M4_BASE([$m4base])"
1430 echo "gl_DOC_BASE([$docbase])"
1431 echo "gl_TESTS_BASE([$testsbase])"
1432 echo "gl_LIB([$libname])"
1433 test -z "$lgpl" || echo "gl_LGPL"
1434 test -z "$libtool" || echo "gl_LIBTOOL"
1435 echo "gl_MACRO_PREFIX([$macro_prefix])"
1437 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1438 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1442 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1443 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1444 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1446 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1450 echo "# gnulib-cache.m4 ends here"
1457 echo "Creating $m4base/gnulib-cache.m4"
1458 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1460 echo "Create $m4base/gnulib-cache.m4"
1466 # Create m4/gnulib-comp.m4.
1467 func_dest_tmpfilename $m4base/gnulib-comp.m4
1469 func_emit_copyright_notice
1471 echo "# This file represents the compiled summary of the specification in"
1472 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1473 echo "# to be invoked from configure.ac."
1474 echo "# In projects using CVS, this file can be treated like other built files."
1477 echo "# This macro should be invoked from $configure_ac, in the section"
1478 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1479 echo "# any checks for libraries, header files, types and library functions."
1480 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1482 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1483 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1484 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1486 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1487 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1489 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1490 echo " AC_REQUIRE([gl_LOCK])"
1494 echo "# This macro should be invoked from $configure_ac, in the section"
1495 echo "# \"Check for header files, types and library functions\"."
1496 echo "AC_DEFUN([${macro_prefix}_INIT],"
1498 if test -z "$libtool"; then
1499 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1501 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1503 if test "$auxdir" != "build-aux"; then
1504 sed_replace_build_aux='
1506 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1507 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1510 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1512 sed_replace_build_aux=
1514 for module in $modules; do
1516 if test -n "$module"; then
1517 func_get_autoconf_snippet "$module" \
1518 | sed -e '/^$/d;' -e 's/^/ /' \
1519 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1520 -e "$sed_replace_build_aux"
1521 if test "$module" = 'alloca' && test -n "$libtool"; then
1522 echo 'changequote(,)dnl'
1523 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1524 echo 'changequote([, ])dnl'
1525 echo 'AC_SUBST([LTALLOCA])'
1531 echo "# This macro records the list of files which have been installed by"
1532 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1533 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1534 echo "$files" | sed -e 's,^, ,'
1537 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1538 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
1542 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1543 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1544 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1546 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1550 echo "# gnulib-comp.m4 ends here"
1557 echo "Creating $m4base/gnulib-comp.m4"
1558 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1560 echo "Create $m4base/gnulib-comp.m4"
1566 if test -n "$inctests"; then
1567 # Create tests/Makefile.am.
1568 func_dest_tmpfilename $testsbase/Makefile.am
1569 func_emit_tests_Makefile_am > "$tmpfile"
1570 if test -f "$destdir"/$testsbase/Makefile.am; then
1571 if cmp "$destdir"/$testsbase/Makefile.am "$tmpfile" > /dev/null; then
1575 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1576 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1577 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1579 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1585 echo "Creating $testsbase/Makefile.am"
1586 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1588 echo "Create $testsbase/Makefile.am"
1596 echo "You may need to add #include directives for the following .h files."
1598 # First the #include <...> directives without #ifs, sorted for convenience.
1599 for module in $modules; do
1600 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1603 func_get_include_directive "$module" | grep -v 'include "'
1605 done | LC_ALL=C sort -u
1606 # Then the #include "..." directives without #ifs, sorted for convenience.
1607 for module in $modules; do
1608 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1611 func_get_include_directive "$module" | grep 'include "'
1613 done | LC_ALL=C sort -u
1614 # Then the #include directives that are surrounded by #ifs. Not sorted.
1615 for module in $modules; do
1616 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1617 func_get_include_directive "$module"
1620 ) | sed -e '/^$/d;' -e 's/^/ /'
1622 echo "Don't forget to"
1623 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1624 if test -n "$inctests"; then
1625 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1627 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1628 sourcebase_base=`basename "$sourcebase"`
1629 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1630 if test -n "$inctests"; then
1631 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1632 testsbase_base=`basename "$testsbase"`
1633 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1635 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1636 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1637 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1640 # func_create_testdir testdir modules
1642 # - auxdir directory relative to destdir where to place build aux files
1643 func_create_testdir ()
1647 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1649 # Determine final module list.
1650 func_modules_transitive_closure
1651 echo "Module list with included dependencies:"
1652 echo "$modules" | sed -e 's/^/ /'
1654 # Add the dummy module if needed.
1655 func_modules_add_dummy
1657 # Determine final file list.
1658 func_modules_to_filelist
1660 echo "$files" | sed -e 's/^/ /'
1662 # Create directories.
1663 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1664 if test "$d" = build-aux; then
1665 mkdir -p "$testdir/$auxdir"
1667 mkdir -p "$testdir/$d"
1671 # Copy files or make symbolic links.
1673 func_lookup_file "$f"
1675 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1678 if test -n "$lookedup_tmp"; then
1679 cp -p "$lookedup_file" "$testdir/$g"
1681 ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
1682 if test -z "$symbolic"; then
1683 cp -p "$lookedup_file" "$testdir/$g"
1685 ln -s "$lookedup_file" "$testdir/$g"
1690 # Create lib/Makefile.am.
1691 mkdir -p "$testdir/lib"
1692 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1694 # Create m4/Makefile.am.
1695 mkdir -p "$testdir/m4"
1696 (echo "## Process this file with automake to produce Makefile.in."
1702 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1705 ) > "$testdir/m4/Makefile.am"
1708 subdirs_with_configure_ac=""
1710 if test -f "$testdir"/m4/gettext.m4; then
1711 # Avoid stupid error message from automake:
1712 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1713 mkdir -p "$testdir/po"
1714 (echo "## Process this file with automake to produce Makefile.in."
1715 ) > "$testdir/po/Makefile.am"
1716 subdirs="$subdirs po"
1719 if test -n "$inctests"; then
1720 test -d "$testdir/tests" || mkdir "$testdir/tests"
1721 # Create tests/Makefile.am.
1725 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1726 # Create tests/configure.ac.
1727 (echo "# Process this file with autoconf to produce a configure script."
1728 echo "AC_INIT([dummy], [0])"
1729 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1730 echo "AM_INIT_AUTOMAKE"
1732 echo "AM_CONFIG_HEADER([config.h])"
1735 echo "AC_PROG_INSTALL"
1736 echo "AC_PROG_MAKE_SET"
1737 echo "AC_PROG_RANLIB"
1739 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1740 echo "AC_GNU_SOURCE"
1743 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1744 echo "gl_USE_SYSTEM_EXTENSIONS"
1747 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1751 if test -z "$libtool"; then
1752 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1754 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1756 if test "$auxdir" != "build-aux"; then
1757 sed_replace_build_aux='
1759 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1760 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1763 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1765 sed_replace_build_aux=
1767 # We don't have explicit ordering constraints between the various
1768 # autoconf snippets. It's cleanest to put those of the library before
1769 # those of the tests.
1770 for module in $modules; do
1771 func_verify_nontests_module
1772 if test -n "$module"; then
1773 func_get_autoconf_snippet "$module" \
1774 | sed -e "$sed_replace_build_aux"
1777 for module in $modules; do
1778 func_verify_tests_module
1779 if test -n "$module"; then
1780 func_get_autoconf_snippet "$module" \
1781 | sed -e "$sed_replace_build_aux"
1785 # Usually tests/config.h will be a superset of config.h. Verify this by
1786 # "merging" config.h into tests/config.h; look out for gcc warnings.
1787 echo "AH_TOP([#include \"../config.h\"])"
1789 echo "AC_OUTPUT([Makefile])"
1790 ) > "$testdir/tests/configure.ac"
1791 subdirs="$subdirs tests"
1792 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1795 # Create Makefile.am.
1796 (echo "## Process this file with automake to produce Makefile.in."
1798 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1800 echo "SUBDIRS = $subdirs"
1802 echo "ACLOCAL_AMFLAGS = -I m4"
1803 ) > "$testdir/Makefile.am"
1805 # Create configure.ac.
1806 (echo "# Process this file with autoconf to produce a configure script."
1807 echo "AC_INIT([dummy], [0])"
1808 if test "$auxdir" != "."; then
1809 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1811 echo "AM_INIT_AUTOMAKE"
1813 echo "AM_CONFIG_HEADER([config.h])"
1816 echo "AC_PROG_INSTALL"
1817 echo "AC_PROG_MAKE_SET"
1818 echo "AC_PROG_RANLIB"
1820 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1821 echo "AC_GNU_SOURCE"
1824 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1825 echo "gl_USE_SYSTEM_EXTENSIONS"
1828 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1832 if test -z "$libtool"; then
1833 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1835 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1837 if test "$auxdir" != "build-aux"; then
1838 sed_replace_build_aux='
1840 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1841 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1844 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1846 sed_replace_build_aux=
1848 for module in $modules; do
1849 func_verify_nontests_module
1850 if test -n "$module"; then
1851 func_get_autoconf_snippet "$module" \
1852 | sed -e "$sed_replace_build_aux"
1856 if test -n "$subdirs_with_configure_ac"; then
1857 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1859 makefiles="Makefile"
1860 for d in $subdirs; do
1861 # For subdirs that have a configure.ac by their own, it's the subdir's
1862 # configure.ac which creates the subdir's Makefile.am, not this one.
1863 case " $subdirs_with_configure_ac " in
1865 *) makefiles="$makefiles $d/Makefile" ;;
1868 echo "AC_OUTPUT([$makefiles])"
1869 ) > "$testdir/configure.ac"
1871 # Create autogenerated files.
1873 echo "executing ${AUTORECONF} --force --install"
1874 ${AUTORECONF} --force --install
1876 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1880 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1888 # func_create_megatestdir megatestdir allmodules
1890 # - auxdir directory relative to destdir where to place build aux files
1891 func_create_megatestdir ()
1895 if test -z "$allmodules"; then
1896 allmodules=`func_all_modules`
1900 # First, all modules one by one.
1901 for onemodule in $allmodules; do
1902 func_create_testdir "$megatestdir/$onemodule" $onemodule
1903 megasubdirs="${megasubdirs}$onemodule "
1905 # Then, all modules all together.
1906 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1907 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1908 func_create_testdir "$megatestdir/ALL" "$allmodules"
1909 megasubdirs="${megasubdirs}ALL"
1911 # Create Makefile.am.
1912 (echo "## Process this file with automake to produce Makefile.in."
1914 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1916 echo "SUBDIRS = $megasubdirs"
1917 ) > "$megatestdir/Makefile.am"
1919 # Create configure.ac.
1920 (echo "# Process this file with autoconf to produce a configure script."
1921 echo "AC_INIT([dummy], [0])"
1922 if test "$auxdir" != "."; then
1923 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1925 echo "AM_INIT_AUTOMAKE"
1927 echo "AC_PROG_MAKE_SET"
1929 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1930 echo "AC_OUTPUT([Makefile])"
1931 ) > "$megatestdir/configure.ac"
1933 # Create autogenerated files.
1935 # Do not use "${AUTORECONF} --install", because autoreconf operates
1936 # recursively, but the subdirectories are already finished, therefore
1937 # calling autoreconf here would only waste lots of CPU time.
1938 echo "executing ${ACLOCAL}"
1940 echo "executing mkdir build-aux"
1942 echo "executing ${AUTOCONF}"
1944 echo "executing ${AUTOMAKE} --add-missing --copy"
1945 ${AUTOMAKE} --add-missing --copy
1951 func_fatal_error "no mode specified" ;;
1960 if test -z "$destdir"; then
1963 test -d "$destdir" \
1964 || func_fatal_error "destination directory does not exist: $destdir"
1966 # Prefer configure.ac to configure.in.
1967 if test -f "$destdir"/configure.ac; then
1968 configure_ac="$destdir/configure.ac"
1970 if test -f "$destdir"/configure.in; then
1971 configure_ac="$destdir/configure.in"
1973 func_fatal_error "cannot find $destdir/configure.ac"
1977 # Analyze configure.ac.
1984 /AC_CONFIG_AUX_DIR/ {
1985 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1987 /A[CM]_PROG_LIBTOOL/ {
1988 s,^.*$,guessed_libtool=true,p
1990 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
1992 if test -z "$auxdir"; then
1993 auxdir="$guessed_auxdir"
1996 # Determine where to apply func_import.
1997 if test -n "$m4base"; then
1998 # Apply func_import to a particular gnulib directory.
1999 # Any number of additional modules can be given.
2000 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
2001 # First use of gnulib in the given m4base.
2002 test -n "$supplied_libname" || supplied_libname=true
2003 test -n "$sourcebase" || sourcebase="lib"
2004 test -n "$docbase" || docbase="doc"
2005 test -n "$testsbase" || testsbase="tests"
2006 test -n "$macro_prefix" || macro_prefix="gl"
2010 # Apply func_import to all gnulib directories.
2011 # To get this list of directories, look at Makefile.am. (Not at
2012 # configure, because it may be omitted from CVS. Also, don't run
2013 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
2016 if test -f "$destdir"/Makefile.am; then
2017 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
2019 for arg in $aclocal_amflags; do
2020 if test -n "$m4dir_is_next"; then
2021 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
2025 if test -f "$destdir/$arg"/gnulib-cache.m4; then
2026 m4dirs="$m4dirs $arg"
2027 m4dirs_count=`expr $m4dirs_count + 1`
2032 if test "X$arg" = "X-I"; then
2040 # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
2041 if test -f "$destdir"/aclocal.m4; then
2042 sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
2043 sedexpr2='s,^[^/]*$,.,'
2044 sedexpr3='s,/[^/]*$,,'
2045 m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort | LC_ALL=C uniq`
2046 m4dirs_count=`echo "$m4dirs" | wc -l`
2049 if test $m4dirs_count = 0; then
2050 # First use of gnulib in a package.
2051 # Any number of additional modules can be given.
2052 test -n "$supplied_libname" || supplied_libname=true
2053 test -n "$sourcebase" || sourcebase="lib"
2055 test -n "$docbase" || docbase="doc"
2056 test -n "$testsbase" || testsbase="tests"
2057 test -n "$macro_prefix" || macro_prefix="gl"
2060 if test $m4dirs_count = 1; then
2061 # There's only one use of gnulib here. Assume the user means it.
2062 # Any number of additional modules can be given.
2063 for m4base in $m4dirs; do
2067 # Ambiguous - guess what the user meant.
2068 if test $# = 0; then
2069 # No further arguments. Guess the user wants to update all of them.
2070 for m4base in $m4dirs; do
2075 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
2083 if test -z "$destdir"; then
2084 func_fatal_error "please specify --dir option"
2087 test -d "$destdir" \
2088 || func_fatal_error "could not create destination directory"
2089 test -n "$auxdir" || auxdir="build-aux"
2090 func_create_testdir "$destdir" "$*"
2093 create-megatestdir )
2094 if test -z "$destdir"; then
2095 func_fatal_error "please specify --dir option"
2097 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2098 test -n "$auxdir" || auxdir="build-aux"
2099 func_create_megatestdir "$destdir" "$*"
2103 test -n "$destdir" || destdir=testdir$$
2104 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2105 test -n "$auxdir" || auxdir="build-aux"
2106 func_create_testdir "$destdir" "$*"
2114 remaining=`find . -type f -print`
2115 if test -n "$remaining"; then
2116 echo "Remaining files:" $remaining 1>&2
2117 echo "gnulib-tool: *** Stop." 1>&2
2126 test -n "$destdir" || destdir=testdir$$
2127 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2128 test -n "$auxdir" || auxdir="build-aux"
2129 func_create_megatestdir "$destdir" "$*"
2137 remaining=`find . -type f -print`
2138 if test -n "$remaining"; then
2139 echo "Remaining files:" $remaining 1>&2
2140 echo "gnulib-tool: *** Stop." 1>&2
2148 extract-description )
2152 if test -n "$module"; then
2153 func_get_description "$module"
2162 if test -n "$module"; then
2163 func_get_filelist "$module"
2168 extract-dependencies )
2172 if test -n "$module"; then
2173 func_get_dependencies "$module"
2178 extract-autoconf-snippet )
2182 if test -n "$module"; then
2183 func_get_autoconf_snippet "$module"
2188 extract-automake-snippet )
2192 if test -n "$module"; then
2193 func_get_automake_snippet "$module"
2198 extract-include-directive )
2202 if test -n "$module"; then
2203 func_get_include_directive "$module"
2212 if test -n "$module"; then
2213 func_get_license "$module"
2218 extract-maintainer )
2222 if test -n "$module"; then
2223 func_get_maintainer "$module"
2228 extract-tests-module )
2232 if test -n "$module"; then
2233 func_get_tests_module "$module"
2239 func_fatal_error "unknown operation mode --$mode" ;;
2243 # Undo the effect of the previous 'trap' command. Some shellology:
2244 # We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
2245 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
2246 # exit); for the others we need to call 'exit' explicitly. The value of $? is
2247 # 128 + signal number and is set before the trap-registered command is run.
2249 trap 'exit $?' 1 2 3 15