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-31 11:35:20 $'
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 --no-libtool Don't use libtool rules.
139 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
140 'gl_INIT'. Default is 'gl'.
141 --no-changelog don't update or create ChangeLog files
143 Options for --import and --update:
144 --dry-run For --import, only print what would have been done.
145 -s, --symbolic, --symlink Make symbolic links instead of copying files.
147 Report bugs to <bug-gnulib@gnu.org>."
151 # outputs to stdout the --version message.
154 year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
155 echo "$progname (GNU $package) $version"
156 echo "Copyright (C) $year Free Software Foundation, Inc.
157 This is free software; see the source for copying conditions. There is NO
158 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
159 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
162 # func_emit_copyright_notice
163 # outputs to stdout a header for a generated file.
164 func_emit_copyright_notice ()
166 echo "# Copyright (C) 2004-2006 Free Software Foundation, Inc."
168 echo "# This file is free software, distributed under the terms of the GNU"
169 echo "# General Public License. As a special exception to the GNU General"
170 echo "# Public License, this file may be distributed as part of a program"
171 echo "# that contains a configuration script generated by Autoconf, under"
172 echo "# the same distribution terms as the rest of that program."
174 echo "# Generated by gnulib-tool."
178 # creates a temporary directory.
180 # - tmp pathname of freshly created temporary directory
183 # Use the environment variable TMPDIR, falling back to /tmp. This allows
184 # users to specify a different temporary directory, for example, if their
185 # /tmp is filled up or too small.
188 # Use the mktemp program if available. If not available, hide the error
190 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
191 test -n "$tmp" && test -d "$tmp"
194 # Use a simple mkdir command. It is guaranteed to fail if the directory
195 # already exists. $RANDOM is bash specific and expands to empty in shells
196 # other than bash, ksh and zsh. Its use does not increase security;
197 # rather, it minimizes the probability of failure in a very cluttered /tmp
199 tmp=$TMPDIR/gl$$-$RANDOM
200 (umask 077 && mkdir "$tmp")
203 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
204 { (exit 1); exit 1; }
208 # func_fatal_error message
209 # outputs to stderr a fatal error message, and terminates the program.
212 echo "gnulib-tool: *** $1" 1>&2
213 echo "gnulib-tool: *** Stop." 1>&2
217 # func_readlink SYMLINK
218 # outputs the target of the given symlink.
219 if (type -p readlink) > /dev/null 2>&1; then
222 # Use the readlink program from GNU coreutils.
228 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
229 # would do the wrong thing if the link target contains " -> ".
230 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
234 # func_ln_if_changed SRC DEST
235 # Like ln -s, but avoids munging timestamps if the link is correct.
236 func_ln_if_changed ()
238 if test $# -ne 2; then
239 echo "usage: func_ln_if_changed SRC DEST" >&2
241 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
249 # Command-line option processing.
250 # Removes the OPTIONS from the arguments. Sets the variables:
251 # - mode list or import or create-testdir or create-megatestdir
252 # - destdir from --dir
253 # - libname, supplied_libname from --lib
254 # - sourcebase from --source-base
255 # - m4base from --m4-base
256 # - docbase from --doc-base
257 # - testsbase from --tests-base
258 # - auxdir from --aux-dir
259 # - inctests true if --with-tests was given, blank otherwise
260 # - avoidlist list of modules to avoid, from --avoid
261 # - lgpl true if --lgpl was given, blank otherwise
262 # - libtool true if --libtool was given, false if --no-libtool was
263 # given, blank otherwise
264 # - macro_prefix from --macro-prefix
265 # - autoconf_minversion minimum supported autoconf version
266 # - do_changelog false if --no-changelog was given, : otherwise
267 # - doit : if actions shall be executed, false if only to be printed
268 # - local_gnulib_dir from --local-dir
269 # - symbolic true if --symbolic was given, blank otherwise
293 while test $# -gt 0; do
298 --import | --impor | --impo | --imp | --im | --i )
301 --update | --updat | --upda | --upd | --up | --u )
304 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
307 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
308 mode=create-megatestdir
310 --test | --tes | --te | --t )
313 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
317 mode=`echo "X$1" | sed -e 's/^X--//'`
322 func_fatal_error "missing argument for --dir"
327 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
332 func_fatal_error "missing argument for --lib"
335 supplied_libname=true
338 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
339 supplied_libname=true
344 func_fatal_error "missing argument for --source-base"
349 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
354 func_fatal_error "missing argument for --m4-base"
359 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
364 func_fatal_error "missing argument for --doc-base"
369 docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
374 func_fatal_error "missing argument for --tests-base"
379 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
384 func_fatal_error "missing argument for --aux-dir"
389 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
397 func_fatal_error "missing argument for --avoid"
399 avoidlist="$avoidlist $1"
402 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
416 func_fatal_error "missing argument for --macro-prefix"
421 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
423 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
432 func_fatal_error "missing argument for --local-dir"
437 local_gnulib_dir=`echo "X$1" | sed -e 's/^X--local-dir=//'`
439 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
442 --help | --hel | --he | --h )
445 --version | --versio | --versi | --vers | --ver | --ve | --v )
449 # Stop option processing
453 echo "gnulib-tool: unknown option $1" 1>&2
454 echo "Try 'gnulib-tool --help' for more information." 1>&2
461 if test "$mode" = update; then
462 if test $# != 0; then
463 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
464 echo "Try 'gnulib-tool --help' for more information." 1>&2
465 echo "If you really want to modify the gnulib configuration of your project," 1>&2
466 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
469 if test -n "$supplied_libname" || test -n "$sourcebase" || test -n "$m4base" \
470 || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
471 || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
472 || test -n "$macro_prefix"; then
473 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
474 echo "Try 'gnulib-tool --help' for more information." 1>&2
475 echo "If you really want to modify the gnulib configuration of your project," 1>&2
476 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
482 # Determine the minimum supported autoconf version from the project's
484 DEFAULT_AUTOCONF_MINVERSION="2.59"
485 if test -f configure.ac; then
486 autoconf_minversion=`$AUTOCONF --trace=AC_PREREQ:'$1' | $SORT -g | uniq | tail -1`
488 if test -z "$autoconf_minversion"; then
489 autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
491 case "$autoconf_minversion" in
492 1.* | 2.[0-4]* | 2.5[0-8]*)
493 func_fatal_error "minimum supported autoconf version is 2.59. Try adding AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
496 # Remove trailing slashes from the directory names. This is necessary for
497 # m4base (to avoid an error in func_import) and optional for the others.
498 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
499 case "$sourcebase" in
500 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
503 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
506 */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
509 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
512 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
517 /*) self_abspathname="$0" ;;
518 */*) self_abspathname=`pwd`/"$0" ;;
519 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
520 if test -x "$d/$0" && test ! -d "$d/$0"; then
521 self_abspathname="$d/$0"
525 if test -z "$self_abspathname"; then
526 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
530 while test -h "$self_abspathname"; do
531 # Resolve symbolic link.
532 linkval=`func_readlink "$self_abspathname"`
533 test -n "$linkval" || break
535 /* ) self_abspathname="$linkval" ;;
536 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
539 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
542 trap 'rm -rf "$tmp"' 0 1 2 3 15
544 # func_lookup_file file
545 # looks up a file in $local_gnulib_dir or $gnulib_dir, or combines it through
548 # - lookedup_file name of the merged (combined) file
549 # - lookedup_tmp true if it is located in the tmp directory, blank otherwise
553 if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile"; then
554 lookedup_file="$local_gnulib_dir/$lkfile"
557 if test -f "$gnulib_dir/$lkfile"; then
558 if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile.diff"; then
559 lkbase=`echo "$lkfile" | sed -e 's,^.*/,,'`
561 cp "$gnulib_dir/$lkfile" "$tmp/$lkbase"
562 patch -s "$tmp/$lkbase" < "$local_gnulib_dir/$lkfile.diff" \
563 || func_fatal_error "patch file $local_gnulib_dir/$lkfile.diff didn't apply cleanly"
564 lookedup_file="$tmp/$lkbase"
567 lookedup_file="$gnulib_dir/$lkfile"
571 func_fatal_error "file $gnulib_dir/$lkfile not found"
579 # Filter out metainformation files like README, which are not modules.
580 # Filter out unit test modules; they can be retrieved through
581 # --extract-tests-module if desired.
583 (cd "$gnulib_dir/modules" && ls -1)
584 if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
585 (cd "$local_gnulib_dir/modules" && ls -1 | sed -e 's,\.diff$,,')
588 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
589 | sed -e '/-tests$/d' \
595 # verifies a module name
596 func_verify_module ()
598 if ! { test -f "$gnulib_dir/modules/$module" \
599 || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
600 && test -f "$local_gnulib_dir/modules/$module"; }; } \
601 || test "CVS" = "$module" \
602 || test "ChangeLog" = "$module" \
603 || test "README" = "$module" \
604 || test "TEMPLATE" = "$module" \
605 || test "TEMPLATE-TESTS" = "$module"; then
606 echo "gnulib-tool: module $module doesn't exist" 1>&2
611 # func_verify_nontests_module
612 # verifies a module name, excluding tests modules
613 func_verify_nontests_module ()
617 * ) func_verify_module ;;
621 # func_verify_tests_module
622 # verifies a module name, considering only tests modules
623 func_verify_tests_module ()
626 *-tests ) func_verify_module ;;
631 sed_extract_prog=':[ ]*$/ {
634 s/^Description:[ ]*$//
636 s/^Depends-on:[ ]*$//
637 s/^configure\.ac:[ ]*$//
638 s/^Makefile\.am:[ ]*$//
641 s/^Maintainer:[ ]*$//
648 # func_get_description module
649 func_get_description ()
651 func_lookup_file "modules/$1"
652 sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
655 # func_get_filelist module
658 func_lookup_file "modules/$1"
659 sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"
660 case "$autoconf_minversion" in
663 echo m4/onceonly_2_57.m4
668 # func_get_dependencies module
669 func_get_dependencies ()
671 # ${module}-tests always implicitly depends on ${module}.
672 echo "$1" | sed -n -e 's/-tests//p'
673 # Then the explicit dependencies listed in the module description.
674 func_lookup_file "modules/$1"
675 sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"
678 # func_get_autoconf_snippet module
679 func_get_autoconf_snippet ()
681 func_lookup_file "modules/$1"
682 sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
685 # func_get_automake_snippet module
686 func_get_automake_snippet ()
688 func_lookup_file "modules/$1"
689 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
692 # func_get_include_directive module
693 func_get_include_directive ()
695 func_lookup_file "modules/$1"
696 sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" | \
697 sed -e 's/^\(["<]\)/#include \1/'
700 # func_get_license module
703 func_lookup_file "modules/$1"
704 sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
707 # func_get_maintainer module
708 func_get_maintainer ()
710 func_lookup_file "modules/$1"
711 sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
714 # func_get_tests_module module
715 func_get_tests_module ()
717 # The naming convention for tests modules is hardwired: ${module}-tests.
718 if test -f modules/"$1"-tests; then
723 # func_acceptable module
724 # tests whether a module is acceptable.
726 # - avoidlist list of modules to avoid
729 for avoid in $avoidlist; do
730 if test "$avoid" = "$1"; then
737 # func_modules_transitive_closure
739 # - modules list of specified modules
740 # - inctests true if tests should be included, blank otherwise
741 # - avoidlist list of modules to avoid
743 # - modules list of modules, including dependencies
744 func_modules_transitive_closure ()
748 for module in $modules; do
750 if test -n "$module"; then
751 # Duplicate dependencies are harmless, but Jim wants a warning.
752 duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
753 if test -n "$duplicated_deps"; then
754 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
756 if func_acceptable $module; then
757 xmodules="$xmodules $module"
758 for depmodule in `func_get_dependencies $module`; do
759 if func_acceptable $depmodule; then
760 xmodules="$xmodules $depmodule"
763 if test -n "$inctests"; then
764 testsmodule=`func_get_tests_module $module`
765 if test -n "$testsmodule"; then
766 if func_acceptable $testsmodule; then
767 xmodules="$xmodules $testsmodule"
768 for depmodule in `func_get_dependencies $testsmodule`; do
769 if func_acceptable $depmodule; then
770 xmodules="$xmodules $depmodule"
779 xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
780 if test "$xmodules" = "$modules"; then
787 # func_modules_add_dummy
789 # - modules list of modules, including dependencies
791 # - modules list of modules, including 'dummy' if needed
792 func_modules_add_dummy ()
795 sed_remove_backslash_newline=':a
802 for module in $modules; do
803 func_verify_nontests_module
804 if test -n "$module"; then
805 # Extract the value of "lib_SOURCES += ...".
806 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
807 # Ignore .h files since they are not compiled.
810 *) have_lib_SOURCES=yes ;;
815 # Add the dummy module, to make sure the library will be non-empty.
816 if test -z "$have_lib_SOURCES"; then
817 modules="$modules dummy"
821 # func_modules_to_filelist
823 # - modules list of modules, including dependencies
825 # - files list of files
826 func_modules_to_filelist ()
829 for module in $modules; do
831 if test -n "$module"; then
832 files="$files "`func_get_filelist $module`
835 files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
838 # func_emit_lib_Makefile_am
839 # emits the contents of lib/Makefile.am to standard output.
841 # - modules list of modules, including dependencies
842 # - libname library name
843 # - libtool true if libtool will be used, false or blank otherwise
844 # - actioncmd (optional) command that will reproduce this invocation
845 func_emit_lib_Makefile_am ()
847 if test "$libtool" = true; then
854 echo "## Process this file with automake to produce Makefile.in."
855 func_emit_copyright_notice
856 if test -n "$actioncmd"; then
857 echo "# Reproduce by: $actioncmd"
860 # No need to generate dependencies since the sources are in gnulib, not here.
861 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
863 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
865 echo "${libname}_${libext}_SOURCES ="
866 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
867 echo "noinst_HEADERS ="
869 echo "BUILT_SOURCES ="
871 echo "MOSTLYCLEANFILES ="
872 echo "MOSTLYCLEANDIRS ="
874 echo "DISTCLEANFILES ="
875 echo "MAINTAINERCLEANFILES ="
879 for module in $modules; do
880 func_verify_nontests_module
881 if test -n "$module"; then
883 func_get_automake_snippet "$module" |
884 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
885 if test "$module" = 'alloca'; then
886 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
889 # Skip the contents if its entirely empty.
890 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
891 echo "## begin gnulib module $module"
894 echo "## end gnulib module $module"
901 echo "mostlyclean-local:"
902 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
903 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
904 echo " if test -d \$\$dir; then \\"
905 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
909 echo "# Makefile.am ends here"
912 # func_emit_tests_Makefile_am
913 # emits the contents of tests/Makefile.am to standard output.
915 # - modules list of modules, including dependencies
916 # - libname library name
917 # - libtool true if libtool will be used, false or blank otherwise
918 # - sourcebase relative directory containing lib source code
919 # - m4base relative directory containing autoconf macros
920 # - testsbase relative directory containing unit test code
921 func_emit_tests_Makefile_am ()
923 if test "$libtool" = true; then
928 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
929 echo "## Process this file with automake to produce Makefile.in."
930 func_emit_copyright_notice
932 # Generate dependencies here, since it eases the debugging of test failures.
933 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
935 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
937 # Nothing is being added to SUBDIRS; nevertheless the existence of this
938 # variable is needed to avoid an error from automake:
939 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
942 echo "TESTS_ENVIRONMENT ="
943 echo "noinst_PROGRAMS ="
944 echo "check_PROGRAMS ="
945 echo "noinst_HEADERS ="
947 echo "BUILT_SOURCES ="
949 echo "MOSTLYCLEANFILES ="
950 echo "MOSTLYCLEANDIRS ="
952 echo "DISTCLEANFILES ="
953 echo "MAINTAINERCLEANFILES ="
955 echo "AM_CPPFLAGS = \\"
956 echo " -I. -I\$(srcdir) \\"
957 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
958 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
960 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
962 for module in $modules; do
963 func_verify_tests_module
964 if test -n "$module"; then
965 func_get_automake_snippet "$module" > amsnippet.tmp
966 # Skip the contents if its entirely empty.
967 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
968 echo "## begin gnulib module $module"
971 echo "## end gnulib module $module"
977 echo "# Clean up after Solaris cc."
979 echo " rm -rf SunWS_cache"
981 echo "mostlyclean-local:"
982 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
983 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
984 echo " if test -d \$\$dir; then \\"
985 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
989 echo "# Makefile.am ends here"
992 # func_import modules
993 # Uses also the variables
994 # - destdir target directory
995 # - libname library name
996 # - sourcebase directory relative to destdir where to place source code
997 # - m4base directory relative to destdir where to place *.m4 macros
998 # - docbase directory relative to destdir where to place doc files
999 # - testsbase directory relative to destdir where to place unit test code
1000 # - auxdir directory relative to destdir where to place build aux files
1001 # - inctests true if --with-tests was given, blank otherwise
1002 # - avoidlist list of modules to avoid, from --avoid
1003 # - lgpl true if library's license shall be LGPL, blank otherwise
1004 # - libtool true if --libtool was given, false if --no-libtool was
1005 # given, blank otherwise
1006 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
1007 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
1008 # - autoconf_minversion minimum supported autoconf version
1009 # - doit : if actions shall be executed, false if only to be printed
1010 # - symbolic true if files should be symlinked, copied otherwise
1013 # Get the cached settings.
1014 cached_specified_modules=
1023 cached_macro_prefix=
1025 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1026 cached_libtool=false
1032 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
1035 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
1038 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
1041 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
1044 s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
1047 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
1050 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
1053 s,^.*$,cached_lgpl=true,p
1056 s,^.*$,cached_libtool=true,p
1058 /gl_MACRO_PREFIX(/ {
1059 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
1061 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
1062 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1067 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
1068 s,^.*$,cached_files=",p
1080 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
1084 # Merge the cached settings with the specified ones.
1085 # The m4base must be the same as expected from the pathname.
1086 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
1087 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
1089 # Append the cached and the specified module names. So that
1090 # "gnulib-tool --import foo" means to add the module foo.
1091 specified_modules="$cached_specified_modules $1"
1092 # Append the cached and the specified avoidlist. This is probably better
1093 # than dropping the cached one when --avoid is specified at least once.
1094 avoidlist=`echo $cached_avoidlist $avoidlist`
1095 # The sourcebase defaults to the cached one.
1096 if test -z "$sourcebase"; then
1097 sourcebase="$cached_sourcebase"
1098 if test -z "$sourcebase"; then
1099 func_fatal_error "missing --source-base option"
1102 # The docbase defaults to the cached one.
1103 if test -z "$docbase"; then
1104 docbase="$cached_docbase"
1105 if test -z "$docbase"; then
1106 func_fatal_error "missing --doc-base option. --doc-base has been introduced on 2006-07-11; if your last invocation of 'gnulib-tool --import' is before that date, you need to run 'gnulib-tool --import' once, with a --doc-base option."
1109 # The testsbase defaults to the cached one.
1110 if test -z "$testsbase"; then
1111 testsbase="$cached_testsbase"
1112 if test -z "$testsbase"; then
1113 func_fatal_error "missing --tests-base option"
1116 # The libname defaults to the cached one.
1117 if test -z "$supplied_libname"; then
1118 libname="$cached_libname"
1119 if test -z "$libname"; then
1120 func_fatal_error "missing --lib option"
1123 # Require LGPL if specified either way.
1124 if test -z "$lgpl"; then
1127 # Use libtool if specified either way, or if guessed.
1128 if test -z "$libtool"; then
1129 if test -n "$cached_m4base"; then
1130 libtool="$cached_libtool"
1132 libtool="$guessed_libtool"
1135 # The macro_prefix defaults to the cached one.
1136 if test -z "$macro_prefix"; then
1137 macro_prefix="$cached_macro_prefix"
1138 if test -z "$macro_prefix"; then
1139 func_fatal_error "missing --macro-prefix option"
1143 # Canonicalize the list of specified modules.
1144 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1146 # Determine final module list.
1147 modules="$specified_modules"
1148 func_modules_transitive_closure
1149 echo "Module list with included dependencies:"
1150 echo "$modules" | sed -e 's/^/ /'
1152 # Add the dummy module if needed.
1153 func_modules_add_dummy
1155 # If --lgpl, check the license of modules are compatible.
1156 if test -n "$lgpl"; then
1157 for module in $modules; do
1158 license=`func_get_license $module`
1160 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
1161 *) func_fatal_error "incompatible license on module $module: $license" ;;
1166 # Determine final file list.
1167 func_modules_to_filelist
1169 echo "$files" | sed -e 's/^/ /'
1172 || func_fatal_error "refusing to do nothing"
1174 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1175 new_files="$files m4/gnulib-tool.m4"
1176 old_files="$cached_files"
1177 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1178 old_files="$old_files m4/gnulib-tool.m4"
1181 # Create directories.
1182 if test ! -d "$destdir/$sourcebase"; then
1184 echo "Creating directory $destdir/$sourcebase"
1185 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1187 echo "Create directory $destdir/$sourcebase"
1190 if test ! -d "$destdir/$m4base"; then
1192 echo "Creating directory $destdir/$m4base"
1193 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1195 echo "Create directory $destdir/$m4base"
1198 docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
1199 if test -n "$docfiles"; then
1200 if test ! -d "$destdir/$docbase"; then
1202 echo "Creating directory $destdir/$docbase"
1203 mkdir "$destdir/$docbase" || func_fatal_error "failed"
1205 echo "Create directory $destdir/$docbase"
1209 if test -n "$inctests"; then
1210 if test ! -d "$destdir/$testsbase"; then
1212 echo "Creating directory $destdir/$testsbase"
1213 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1215 echo "Create directory $destdir/$testsbase"
1219 if test ! -d "$destdir/$auxdir"; then
1221 echo "Creating directory $destdir/$auxdir"
1222 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1224 echo "Create directory $destdir/$auxdir"
1228 # func_dest_tmpfilename file
1229 # determines the name of a temporary file (file is relative to destdir).
1231 # - tmpfile absolute filename of the temporary file
1232 func_dest_tmpfilename ()
1235 # Put the new contents of $file in a file in the same directory (needed
1236 # to guarantee that an 'mv' to "$destdir/$file" works).
1237 tmpfile="$destdir/$1.tmp"
1239 # Put the new contents of $file in a file in a temporary directory
1240 # (because the directory of "$file" might not exist).
1241 tmpfile="$tmp"/`basename "$1"`.tmp
1245 # Copy files or make symbolic links. Remove obsolete files.
1247 for f in $old_files; do
1249 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1250 doc/*) g=`echo "$f" | sed -e "s,^doc/,$cached_docbase/,"` ;;
1251 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1252 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1253 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1256 echo "$g""$delimiter""$f"
1257 done | LC_ALL=C sort > "$tmp"/old-files
1258 for f in $new_files; do
1260 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1261 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1262 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1263 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1264 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1267 echo "$g""$delimiter""$f"
1268 done | LC_ALL=C sort > "$tmp"/new-files
1269 # First the files that are in old-files, but not in new-files:
1270 sed_take_first_column='s,'"$delimiter"'.*,,'
1271 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1272 # Remove the file. Do nothing if the user already removed it.
1273 if test -f "$destdir/$g"; then
1275 echo "Removing file $g (backup in ${g}~)"
1276 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1278 echo "Remove file $g (backup in ${g}~)"
1282 # func_add_or_update handles a file that ought to be present afterwards.
1283 # Uses parameters f, g, already_present.
1284 func_add_or_update ()
1286 func_dest_tmpfilename "$g"
1287 func_lookup_file "$f"
1288 cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
1289 if test -n "$lgpl"; then
1293 sed -e 's/GNU General/GNU Lesser General/g' \
1294 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1295 < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
1299 if test -f "$destdir/$g"; then
1300 # The file already exists.
1301 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1302 : # The file has not changed.
1306 if test -n "$already_present"; then
1307 echo "Updating file $g (backup in ${g}~)"
1309 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1311 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1312 if test -n "$symbolic" && test -z "$lookedup_tmp" \
1313 && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1314 func_ln_if_changed "$lookedup_file" "$destdir/$g"
1316 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1319 if test -n "$already_present"; then
1320 echo "Update file $g (backup in ${g}~)"
1322 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1328 # Don't protest if the file should be there but isn't: it happens
1329 # frequently that developers don't put autogenerated files into CVS.
1331 echo "Copying file $g"
1332 if test -n "$symbolic" && test -z "$lookedup_tmp" \
1333 && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1334 func_ln_if_changed "$lookedup_file" "$destdir/$g"
1336 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1344 # Then the files that are in new-files, but not in old-files:
1345 sed_take_last_column='s,^.*'"$delimiter"',,'
1347 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1349 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1350 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1351 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1352 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1353 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1358 # Then the files that are in new-files and in old-files:
1359 already_present=true
1360 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1362 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1363 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1364 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1365 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1366 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1372 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1373 actioncmd="gnulib-tool --import"
1374 actioncmd="$actioncmd --dir=$destdir"
1375 actioncmd="$actioncmd --lib=$libname"
1376 actioncmd="$actioncmd --source-base=$sourcebase"
1377 actioncmd="$actioncmd --m4-base=$m4base"
1378 actioncmd="$actioncmd --doc-base=$docbase"
1379 actioncmd="$actioncmd --aux-dir=$auxdir"
1380 for module in $avoidlist; do
1381 actioncmd="$actioncmd --avoid=$module"
1383 if test -n "$lgpl"; then
1384 actioncmd="$actioncmd --lgpl"
1386 if test "$libtool" = true; then
1387 actioncmd="$actioncmd --libtool"
1389 actioncmd="$actioncmd --no-libtool"
1391 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1392 actioncmd="$actioncmd `echo $specified_modules`"
1394 # Create lib/Makefile.am.
1395 func_dest_tmpfilename $sourcebase/Makefile.am
1396 func_emit_lib_Makefile_am > "$tmpfile"
1397 if test -f "$destdir"/$sourcebase/Makefile.am; then
1398 if cmp "$destdir"/$sourcebase/Makefile.am "$tmpfile" > /dev/null; then
1402 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1403 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1404 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1406 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1412 echo "Creating $sourcebase/Makefile.am"
1413 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1415 echo "Create $sourcebase/Makefile.am"
1420 # Create m4/gnulib-cache.m4.
1421 func_dest_tmpfilename $m4base/gnulib-cache.m4
1423 func_emit_copyright_notice
1425 echo "# This file represents the specification of how gnulib-tool is used."
1426 echo "# It acts as a cache: It is written and read by gnulib-tool."
1427 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1428 echo "# like the configure.ac and various Makefile.am files."
1431 echo "# Specification in the form of a command-line invocation:"
1434 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1435 echo "gl_MODULES(["`echo $specified_modules`"])"
1436 echo "gl_AVOID([$avoidlist])"
1437 echo "gl_SOURCE_BASE([$sourcebase])"
1438 echo "gl_M4_BASE([$m4base])"
1439 echo "gl_DOC_BASE([$docbase])"
1440 echo "gl_TESTS_BASE([$testsbase])"
1441 echo "gl_LIB([$libname])"
1442 test -z "$lgpl" || echo "gl_LGPL"
1443 if test "$libtool" = true; then
1446 echo "gl_MACRO_PREFIX([$macro_prefix])"
1448 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1449 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1453 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1454 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1455 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1457 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1461 echo "# gnulib-cache.m4 ends here"
1468 echo "Creating $m4base/gnulib-cache.m4"
1469 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1471 echo "Create $m4base/gnulib-cache.m4"
1477 # Create m4/gnulib-comp.m4.
1478 func_dest_tmpfilename $m4base/gnulib-comp.m4
1480 func_emit_copyright_notice
1482 echo "# This file represents the compiled summary of the specification in"
1483 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1484 echo "# to be invoked from configure.ac."
1485 echo "# In projects using CVS, this file can be treated like other built files."
1488 echo "# This macro should be invoked from $configure_ac, in the section"
1489 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1490 echo "# any checks for libraries, header files, types and library functions."
1491 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1493 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1494 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1495 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1497 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1498 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1500 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1501 echo " AC_REQUIRE([gl_LOCK])"
1505 echo "# This macro should be invoked from $configure_ac, in the section"
1506 echo "# \"Check for header files, types and library functions\"."
1507 echo "AC_DEFUN([${macro_prefix}_INIT],"
1509 if test "$libtool" = true; then
1510 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1512 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1514 if test "$auxdir" != "build-aux"; then
1515 sed_replace_build_aux='
1517 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1518 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1521 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1523 sed_replace_build_aux=
1525 for module in $modules; do
1527 if test -n "$module"; then
1528 func_get_autoconf_snippet "$module" \
1529 | sed -e '/^$/d;' -e 's/^/ /' \
1530 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1531 -e "$sed_replace_build_aux"
1532 if test "$module" = 'alloca' && test "$libtool" = true; then
1533 echo 'changequote(,)dnl'
1534 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1535 echo 'changequote([, ])dnl'
1536 echo 'AC_SUBST([LTALLOCA])'
1542 echo "# This macro records the list of files which have been installed by"
1543 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1544 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1545 echo "$files" | sed -e 's,^, ,'
1548 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1549 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
1553 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1554 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1555 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1557 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1561 echo "# gnulib-comp.m4 ends here"
1568 echo "Creating $m4base/gnulib-comp.m4"
1569 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1571 echo "Create $m4base/gnulib-comp.m4"
1577 if test -n "$inctests"; then
1578 # Create tests/Makefile.am.
1579 func_dest_tmpfilename $testsbase/Makefile.am
1580 func_emit_tests_Makefile_am > "$tmpfile"
1581 if test -f "$destdir"/$testsbase/Makefile.am; then
1582 if cmp "$destdir"/$testsbase/Makefile.am "$tmpfile" > /dev/null; then
1586 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1587 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1588 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1590 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1596 echo "Creating $testsbase/Makefile.am"
1597 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1599 echo "Create $testsbase/Makefile.am"
1607 echo "You may need to add #include directives for the following .h files."
1609 # First the #include <...> directives without #ifs, sorted for convenience.
1610 for module in $modules; do
1611 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1614 func_get_include_directive "$module" | grep -v 'include "'
1616 done | LC_ALL=C sort -u
1617 # Then the #include "..." directives without #ifs, sorted for convenience.
1618 for module in $modules; do
1619 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1622 func_get_include_directive "$module" | grep 'include "'
1624 done | LC_ALL=C sort -u
1625 # Then the #include directives that are surrounded by #ifs. Not sorted.
1626 for module in $modules; do
1627 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1628 func_get_include_directive "$module"
1631 ) | sed -e '/^$/d;' -e 's/^/ /'
1633 echo "Don't forget to"
1634 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1635 if test -n "$inctests"; then
1636 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1638 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1639 sourcebase_base=`basename "$sourcebase"`
1640 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1641 if test -n "$inctests"; then
1642 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1643 testsbase_base=`basename "$testsbase"`
1644 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1646 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1647 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1648 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1651 # func_create_testdir testdir modules
1653 # - auxdir directory relative to destdir where to place build aux files
1654 func_create_testdir ()
1658 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1660 # Determine final module list.
1661 func_modules_transitive_closure
1662 echo "Module list with included dependencies:"
1663 echo "$modules" | sed -e 's/^/ /'
1665 # Add the dummy module if needed.
1666 func_modules_add_dummy
1668 # Determine final file list.
1669 func_modules_to_filelist
1671 echo "$files" | sed -e 's/^/ /'
1673 # Create directories.
1674 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1675 if test "$d" = build-aux; then
1676 mkdir -p "$testdir/$auxdir"
1678 mkdir -p "$testdir/$d"
1682 # Copy files or make symbolic links.
1684 func_lookup_file "$f"
1686 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1689 if test -n "$lookedup_tmp"; then
1690 cp -p "$lookedup_file" "$testdir/$g"
1692 ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
1693 if test -z "$symbolic"; then
1694 cp -p "$lookedup_file" "$testdir/$g"
1696 ln -s "$lookedup_file" "$testdir/$g"
1701 # Create lib/Makefile.am.
1702 mkdir -p "$testdir/lib"
1703 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1705 # Create m4/Makefile.am.
1706 mkdir -p "$testdir/m4"
1707 (echo "## Process this file with automake to produce Makefile.in."
1713 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1716 ) > "$testdir/m4/Makefile.am"
1719 subdirs_with_configure_ac=""
1721 if test -f "$testdir"/m4/gettext.m4; then
1722 # Avoid stupid error message from automake:
1723 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1724 mkdir -p "$testdir/po"
1725 (echo "## Process this file with automake to produce Makefile.in."
1726 ) > "$testdir/po/Makefile.am"
1727 subdirs="$subdirs po"
1730 if test -n "$inctests"; then
1731 test -d "$testdir/tests" || mkdir "$testdir/tests"
1732 # Create tests/Makefile.am.
1736 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1737 # Create tests/configure.ac.
1738 (echo "# Process this file with autoconf to produce a configure script."
1739 echo "AC_INIT([dummy], [0])"
1740 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1741 echo "AM_INIT_AUTOMAKE"
1743 echo "AM_CONFIG_HEADER([config.h])"
1746 echo "AC_PROG_INSTALL"
1747 echo "AC_PROG_MAKE_SET"
1748 echo "AC_PROG_RANLIB"
1750 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1751 echo "AC_GNU_SOURCE"
1754 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1755 echo "gl_USE_SYSTEM_EXTENSIONS"
1758 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1762 if test "$libtool" = true; then
1763 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1765 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1767 if test "$auxdir" != "build-aux"; then
1768 sed_replace_build_aux='
1770 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1771 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1774 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1776 sed_replace_build_aux=
1778 # We don't have explicit ordering constraints between the various
1779 # autoconf snippets. It's cleanest to put those of the library before
1780 # those of the tests.
1781 for module in $modules; do
1782 func_verify_nontests_module
1783 if test -n "$module"; then
1784 func_get_autoconf_snippet "$module" \
1785 | sed -e "$sed_replace_build_aux"
1788 for module in $modules; do
1789 func_verify_tests_module
1790 if test -n "$module"; then
1791 func_get_autoconf_snippet "$module" \
1792 | sed -e "$sed_replace_build_aux"
1796 # Usually tests/config.h will be a superset of config.h. Verify this by
1797 # "merging" config.h into tests/config.h; look out for gcc warnings.
1798 echo "AH_TOP([#include \"../config.h\"])"
1800 echo "AC_OUTPUT([Makefile])"
1801 ) > "$testdir/tests/configure.ac"
1802 subdirs="$subdirs tests"
1803 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1806 # Create Makefile.am.
1807 (echo "## Process this file with automake to produce Makefile.in."
1809 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1811 echo "SUBDIRS = $subdirs"
1813 echo "ACLOCAL_AMFLAGS = -I m4"
1814 ) > "$testdir/Makefile.am"
1816 # Create configure.ac.
1817 (echo "# Process this file with autoconf to produce a configure script."
1818 echo "AC_INIT([dummy], [0])"
1819 if test "$auxdir" != "."; then
1820 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1822 echo "AM_INIT_AUTOMAKE"
1824 echo "AM_CONFIG_HEADER([config.h])"
1827 echo "AC_PROG_INSTALL"
1828 echo "AC_PROG_MAKE_SET"
1829 echo "AC_PROG_RANLIB"
1831 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1832 echo "AC_GNU_SOURCE"
1835 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1836 echo "gl_USE_SYSTEM_EXTENSIONS"
1839 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1843 if test "$libtool" = true; then
1844 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1846 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1848 if test "$auxdir" != "build-aux"; then
1849 sed_replace_build_aux='
1851 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1852 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1855 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1857 sed_replace_build_aux=
1859 for module in $modules; do
1860 func_verify_nontests_module
1861 if test -n "$module"; then
1862 func_get_autoconf_snippet "$module" \
1863 | sed -e "$sed_replace_build_aux"
1867 if test -n "$subdirs_with_configure_ac"; then
1868 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1870 makefiles="Makefile"
1871 for d in $subdirs; do
1872 # For subdirs that have a configure.ac by their own, it's the subdir's
1873 # configure.ac which creates the subdir's Makefile.am, not this one.
1874 case " $subdirs_with_configure_ac " in
1876 *) makefiles="$makefiles $d/Makefile" ;;
1879 echo "AC_OUTPUT([$makefiles])"
1880 ) > "$testdir/configure.ac"
1882 # Create autogenerated files.
1884 echo "executing ${AUTORECONF} --force --install"
1885 ${AUTORECONF} --force --install
1887 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1891 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1899 # func_create_megatestdir megatestdir allmodules
1901 # - auxdir directory relative to destdir where to place build aux files
1902 func_create_megatestdir ()
1906 if test -z "$allmodules"; then
1907 allmodules=`func_all_modules`
1911 # First, all modules one by one.
1912 for onemodule in $allmodules; do
1913 func_create_testdir "$megatestdir/$onemodule" $onemodule
1914 megasubdirs="${megasubdirs}$onemodule "
1916 # Then, all modules all together.
1917 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1918 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1919 func_create_testdir "$megatestdir/ALL" "$allmodules"
1920 megasubdirs="${megasubdirs}ALL"
1922 # Create Makefile.am.
1923 (echo "## Process this file with automake to produce Makefile.in."
1925 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1927 echo "SUBDIRS = $megasubdirs"
1928 ) > "$megatestdir/Makefile.am"
1930 # Create configure.ac.
1931 (echo "# Process this file with autoconf to produce a configure script."
1932 echo "AC_INIT([dummy], [0])"
1933 if test "$auxdir" != "."; then
1934 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1936 echo "AM_INIT_AUTOMAKE"
1938 echo "AC_PROG_MAKE_SET"
1940 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1941 echo "AC_OUTPUT([Makefile])"
1942 ) > "$megatestdir/configure.ac"
1944 # Create autogenerated files.
1946 # Do not use "${AUTORECONF} --install", because autoreconf operates
1947 # recursively, but the subdirectories are already finished, therefore
1948 # calling autoreconf here would only waste lots of CPU time.
1949 echo "executing ${ACLOCAL}"
1951 echo "executing mkdir build-aux"
1953 echo "executing ${AUTOCONF}"
1955 echo "executing ${AUTOMAKE} --add-missing --copy"
1956 ${AUTOMAKE} --add-missing --copy
1962 func_fatal_error "no mode specified" ;;
1971 if test -z "$destdir"; then
1974 test -d "$destdir" \
1975 || func_fatal_error "destination directory does not exist: $destdir"
1977 # Prefer configure.ac to configure.in.
1978 if test -f "$destdir"/configure.ac; then
1979 configure_ac="$destdir/configure.ac"
1981 if test -f "$destdir"/configure.in; then
1982 configure_ac="$destdir/configure.in"
1984 func_fatal_error "cannot find $destdir/configure.ac"
1988 # Analyze configure.ac.
1990 guessed_libtool=false
1995 /AC_CONFIG_AUX_DIR/ {
1996 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
1998 /A[CM]_PROG_LIBTOOL/ {
1999 s,^.*$,guessed_libtool=true,p
2001 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
2003 if test -z "$auxdir"; then
2004 auxdir="$guessed_auxdir"
2007 # Determine where to apply func_import.
2008 if test -n "$m4base"; then
2009 # Apply func_import to a particular gnulib directory.
2010 # Any number of additional modules can be given.
2011 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
2012 # First use of gnulib in the given m4base.
2013 test -n "$supplied_libname" || supplied_libname=true
2014 test -n "$sourcebase" || sourcebase="lib"
2015 test -n "$docbase" || docbase="doc"
2016 test -n "$testsbase" || testsbase="tests"
2017 test -n "$macro_prefix" || macro_prefix="gl"
2021 # Apply func_import to all gnulib directories.
2022 # To get this list of directories, look at Makefile.am. (Not at
2023 # configure, because it may be omitted from CVS. Also, don't run
2024 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
2027 if test -f "$destdir"/Makefile.am; then
2028 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
2030 for arg in $aclocal_amflags; do
2031 if test -n "$m4dir_is_next"; then
2032 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
2036 if test -f "$destdir/$arg"/gnulib-cache.m4; then
2037 m4dirs="$m4dirs $arg"
2038 m4dirs_count=`expr $m4dirs_count + 1`
2043 if test "X$arg" = "X-I"; then
2051 # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
2052 if test -f "$destdir"/aclocal.m4; then
2053 sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
2054 sedexpr2='s,^[^/]*$,.,'
2055 sedexpr3='s,/[^/]*$,,'
2056 m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort | LC_ALL=C uniq`
2057 m4dirs_count=`echo "$m4dirs" | wc -l`
2060 if test $m4dirs_count = 0; then
2061 # First use of gnulib in a package.
2062 # Any number of additional modules can be given.
2063 test -n "$supplied_libname" || supplied_libname=true
2064 test -n "$sourcebase" || sourcebase="lib"
2066 test -n "$docbase" || docbase="doc"
2067 test -n "$testsbase" || testsbase="tests"
2068 test -n "$macro_prefix" || macro_prefix="gl"
2071 if test $m4dirs_count = 1; then
2072 # There's only one use of gnulib here. Assume the user means it.
2073 # Any number of additional modules can be given.
2074 for m4base in $m4dirs; do
2078 # Ambiguous - guess what the user meant.
2079 if test $# = 0; then
2080 # No further arguments. Guess the user wants to update all of them.
2081 for m4base in $m4dirs; do
2086 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
2094 if test -z "$destdir"; then
2095 func_fatal_error "please specify --dir option"
2098 test -d "$destdir" \
2099 || func_fatal_error "could not create destination directory"
2100 test -n "$auxdir" || auxdir="build-aux"
2101 func_create_testdir "$destdir" "$*"
2104 create-megatestdir )
2105 if test -z "$destdir"; then
2106 func_fatal_error "please specify --dir option"
2108 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2109 test -n "$auxdir" || auxdir="build-aux"
2110 func_create_megatestdir "$destdir" "$*"
2114 test -n "$destdir" || destdir=testdir$$
2115 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2116 test -n "$auxdir" || auxdir="build-aux"
2117 func_create_testdir "$destdir" "$*"
2125 remaining=`find . -type f -print`
2126 if test -n "$remaining"; then
2127 echo "Remaining files:" $remaining 1>&2
2128 echo "gnulib-tool: *** Stop." 1>&2
2137 test -n "$destdir" || destdir=testdir$$
2138 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2139 test -n "$auxdir" || auxdir="build-aux"
2140 func_create_megatestdir "$destdir" "$*"
2148 remaining=`find . -type f -print`
2149 if test -n "$remaining"; then
2150 echo "Remaining files:" $remaining 1>&2
2151 echo "gnulib-tool: *** Stop." 1>&2
2159 extract-description )
2163 if test -n "$module"; then
2164 func_get_description "$module"
2173 if test -n "$module"; then
2174 func_get_filelist "$module"
2179 extract-dependencies )
2183 if test -n "$module"; then
2184 func_get_dependencies "$module"
2189 extract-autoconf-snippet )
2193 if test -n "$module"; then
2194 func_get_autoconf_snippet "$module"
2199 extract-automake-snippet )
2203 if test -n "$module"; then
2204 func_get_automake_snippet "$module"
2209 extract-include-directive )
2213 if test -n "$module"; then
2214 func_get_include_directive "$module"
2223 if test -n "$module"; then
2224 func_get_license "$module"
2229 extract-maintainer )
2233 if test -n "$module"; then
2234 func_get_maintainer "$module"
2239 extract-tests-module )
2243 if test -n "$module"; then
2244 func_get_tests_module "$module"
2250 func_fatal_error "unknown operation mode --$mode" ;;
2254 # Undo the effect of the previous 'trap' command. Some shellology:
2255 # We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
2256 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
2257 # exit); for the others we need to call 'exit' explicitly. The value of $? is
2258 # 128 + signal number and is set before the trap-registered command is run.
2260 trap 'exit $?' 1 2 3 15