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:36:29 $'
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
292 while test $# -gt 0; do
297 --import | --impor | --impo | --imp | --im | --i )
300 --update | --updat | --upda | --upd | --up | --u )
303 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
306 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
307 mode=create-megatestdir
309 --test | --tes | --te | --t )
312 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
316 mode=`echo "X$1" | sed -e 's/^X--//'`
321 func_fatal_error "missing argument for --dir"
326 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
331 func_fatal_error "missing argument for --lib"
334 supplied_libname=true
337 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
338 supplied_libname=true
343 func_fatal_error "missing argument for --source-base"
348 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
353 func_fatal_error "missing argument for --m4-base"
358 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
363 func_fatal_error "missing argument for --doc-base"
368 docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
373 func_fatal_error "missing argument for --tests-base"
378 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
383 func_fatal_error "missing argument for --aux-dir"
388 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
396 func_fatal_error "missing argument for --avoid"
398 avoidlist="$avoidlist $1"
401 avoidlist="$avoidlist "`echo "X$1" | sed -e 's/^X--avoid=//'`
415 func_fatal_error "missing argument for --macro-prefix"
420 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
422 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
431 func_fatal_error "missing argument for --local-dir"
436 local_gnulib_dir=`echo "X$1" | sed -e 's/^X--local-dir=//'`
438 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
441 --help | --hel | --he | --h )
444 --version | --versio | --versi | --vers | --ver | --ve | --v )
448 # Stop option processing
452 echo "gnulib-tool: unknown option $1" 1>&2
453 echo "Try 'gnulib-tool --help' for more information." 1>&2
460 if test "$mode" = update; then
461 if test $# != 0; then
462 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
463 echo "Try 'gnulib-tool --help' for more information." 1>&2
464 echo "If you really want to modify the gnulib configuration of your project," 1>&2
465 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
468 if test -n "$supplied_libname" || test -n "$sourcebase" || test -n "$m4base" \
469 || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
470 || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
471 || test -n "$macro_prefix"; then
472 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
473 echo "Try 'gnulib-tool --help' for more information." 1>&2
474 echo "If you really want to modify the gnulib configuration of your project," 1>&2
475 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
481 # Determine the minimum supported autoconf version from the project's
483 DEFAULT_AUTOCONF_MINVERSION="2.59"
486 if { test "$mode" = import || test "$mode" = update; } && test -n "$destdir"; then
487 if test -f "$destdir"/configure.ac; then
488 configure_ac="$destdir/configure.ac"
490 if test -f "$destdir"/configure.in; then
491 configure_ac="$destdir/configure.in"
495 if test -f configure.ac; then
496 configure_ac="configure.ac"
498 if test -f configure.in; then
499 configure_ac="configure.in"
503 if test -n "$configure_ac"; then
504 # Use sed, not autoconf --trace, to look for the AC_PREREQ invocation,
505 # because when some m4 files are omitted from a CVS repository,
506 # "autoconf --trace=AC_PREREQ" fails with an error message like this:
507 # m4: aclocal.m4:851: Cannot open m4/absolute-header.m4: No such file or directory
508 # autom4te: m4 failed with exit status: 1
515 s,^.*AC_PREREQ([[ ]*\([^])]*\).*$,prereqs="$prereqs \1",p
517 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
518 if test -n "$prereqs"; then
519 autoconf_minversion=`for version in $prereqs; do echo $version; done | $SORT -g | uniq | tail -1`
522 if test -z "$autoconf_minversion"; then
523 autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
525 case "$autoconf_minversion" in
526 1.* | 2.[0-4]* | 2.5[0-8]*)
527 func_fatal_error "minimum supported autoconf version is 2.59. Try adding AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
530 # Remove trailing slashes from the directory names. This is necessary for
531 # m4base (to avoid an error in func_import) and optional for the others.
532 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
533 case "$sourcebase" in
534 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
537 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
540 */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
543 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
546 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
551 /*) self_abspathname="$0" ;;
552 */*) self_abspathname=`pwd`/"$0" ;;
553 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
554 if test -x "$d/$0" && test ! -d "$d/$0"; then
555 self_abspathname="$d/$0"
559 if test -z "$self_abspathname"; then
560 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
564 while test -h "$self_abspathname"; do
565 # Resolve symbolic link.
566 linkval=`func_readlink "$self_abspathname"`
567 test -n "$linkval" || break
569 /* ) self_abspathname="$linkval" ;;
570 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
573 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
576 trap 'rm -rf "$tmp"' 0 1 2 3 15
578 # func_lookup_file file
579 # looks up a file in $local_gnulib_dir or $gnulib_dir, or combines it through
582 # - lookedup_file name of the merged (combined) file
583 # - lookedup_tmp true if it is located in the tmp directory, blank otherwise
587 if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile"; then
588 lookedup_file="$local_gnulib_dir/$lkfile"
591 if test -f "$gnulib_dir/$lkfile"; then
592 if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile.diff"; then
593 lkbase=`echo "$lkfile" | sed -e 's,^.*/,,'`
595 cp "$gnulib_dir/$lkfile" "$tmp/$lkbase"
596 patch -s "$tmp/$lkbase" < "$local_gnulib_dir/$lkfile.diff" \
597 || func_fatal_error "patch file $local_gnulib_dir/$lkfile.diff didn't apply cleanly"
598 lookedup_file="$tmp/$lkbase"
601 lookedup_file="$gnulib_dir/$lkfile"
605 func_fatal_error "file $gnulib_dir/$lkfile not found"
613 # Filter out metainformation files like README, which are not modules.
614 # Filter out unit test modules; they can be retrieved through
615 # --extract-tests-module if desired.
617 (cd "$gnulib_dir/modules" && ls -1)
618 if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
619 (cd "$local_gnulib_dir/modules" && ls -1 | sed -e 's,\.diff$,,')
622 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
623 | sed -e '/-tests$/d' \
629 # verifies a module name
630 func_verify_module ()
632 if ! { test -f "$gnulib_dir/modules/$module" \
633 || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
634 && test -f "$local_gnulib_dir/modules/$module"; }; } \
635 || test "CVS" = "$module" \
636 || test "ChangeLog" = "$module" \
637 || test "README" = "$module" \
638 || test "TEMPLATE" = "$module" \
639 || test "TEMPLATE-TESTS" = "$module"; then
640 echo "gnulib-tool: module $module doesn't exist" 1>&2
645 # func_verify_nontests_module
646 # verifies a module name, excluding tests modules
647 func_verify_nontests_module ()
651 * ) func_verify_module ;;
655 # func_verify_tests_module
656 # verifies a module name, considering only tests modules
657 func_verify_tests_module ()
660 *-tests ) func_verify_module ;;
665 sed_extract_prog=':[ ]*$/ {
668 s/^Description:[ ]*$//
670 s/^Depends-on:[ ]*$//
671 s/^configure\.ac:[ ]*$//
672 s/^Makefile\.am:[ ]*$//
675 s/^Maintainer:[ ]*$//
682 # func_get_description module
683 func_get_description ()
685 func_lookup_file "modules/$1"
686 sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
689 # func_get_filelist module
692 func_lookup_file "modules/$1"
693 sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"
694 case "$autoconf_minversion" in
697 echo m4/onceonly_2_57.m4
702 # func_get_dependencies module
703 func_get_dependencies ()
705 # ${module}-tests always implicitly depends on ${module}.
706 echo "$1" | sed -n -e 's/-tests//p'
707 # Then the explicit dependencies listed in the module description.
708 func_lookup_file "modules/$1"
709 sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"
712 # func_get_autoconf_snippet module
713 func_get_autoconf_snippet ()
715 func_lookup_file "modules/$1"
716 sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
719 # func_get_automake_snippet module
720 func_get_automake_snippet ()
722 func_lookup_file "modules/$1"
723 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
726 # func_get_include_directive module
727 func_get_include_directive ()
729 func_lookup_file "modules/$1"
730 sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" | \
731 sed -e 's/^\(["<]\)/#include \1/'
734 # func_get_license module
737 func_lookup_file "modules/$1"
738 sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
741 # func_get_maintainer module
742 func_get_maintainer ()
744 func_lookup_file "modules/$1"
745 sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
748 # func_get_tests_module module
749 func_get_tests_module ()
751 # The naming convention for tests modules is hardwired: ${module}-tests.
752 if test -f modules/"$1"-tests; then
757 # func_acceptable module
758 # tests whether a module is acceptable.
760 # - avoidlist list of modules to avoid
763 for avoid in $avoidlist; do
764 if test "$avoid" = "$1"; then
771 # func_modules_transitive_closure
773 # - modules list of specified modules
774 # - inctests true if tests should be included, blank otherwise
775 # - avoidlist list of modules to avoid
777 # - modules list of modules, including dependencies
778 func_modules_transitive_closure ()
782 for module in $modules; do
784 if test -n "$module"; then
785 # Duplicate dependencies are harmless, but Jim wants a warning.
786 duplicated_deps=`func_get_dependencies $module | LC_ALL=C sort | LC_ALL=C uniq -d`
787 if test -n "$duplicated_deps"; then
788 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
790 if func_acceptable $module; then
791 xmodules="$xmodules $module"
792 for depmodule in `func_get_dependencies $module`; do
793 if func_acceptable $depmodule; then
794 xmodules="$xmodules $depmodule"
797 if test -n "$inctests"; then
798 testsmodule=`func_get_tests_module $module`
799 if test -n "$testsmodule"; then
800 if func_acceptable $testsmodule; then
801 xmodules="$xmodules $testsmodule"
802 for depmodule in `func_get_dependencies $testsmodule`; do
803 if func_acceptable $depmodule; then
804 xmodules="$xmodules $depmodule"
813 xmodules=`for m in $xmodules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
814 if test "$xmodules" = "$modules"; then
821 # func_modules_add_dummy
823 # - modules list of modules, including dependencies
825 # - modules list of modules, including 'dummy' if needed
826 func_modules_add_dummy ()
829 sed_remove_backslash_newline=':a
836 for module in $modules; do
837 func_verify_nontests_module
838 if test -n "$module"; then
839 # Extract the value of "lib_SOURCES += ...".
840 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
841 # Ignore .h files since they are not compiled.
844 *) have_lib_SOURCES=yes ;;
849 # Add the dummy module, to make sure the library will be non-empty.
850 if test -z "$have_lib_SOURCES"; then
851 modules="$modules dummy"
855 # func_modules_to_filelist
857 # - modules list of modules, including dependencies
859 # - files list of files
860 func_modules_to_filelist ()
863 for module in $modules; do
865 if test -n "$module"; then
866 files="$files "`func_get_filelist $module`
869 files=`for f in $files; do echo $f; done | LC_ALL=C sort | LC_ALL=C uniq`
872 # func_emit_lib_Makefile_am
873 # emits the contents of lib/Makefile.am to standard output.
875 # - modules list of modules, including dependencies
876 # - libname library name
877 # - libtool true if libtool will be used, false or blank otherwise
878 # - actioncmd (optional) command that will reproduce this invocation
879 func_emit_lib_Makefile_am ()
881 if test "$libtool" = true; then
888 echo "## Process this file with automake to produce Makefile.in."
889 func_emit_copyright_notice
890 if test -n "$actioncmd"; then
891 echo "# Reproduce by: $actioncmd"
894 # No need to generate dependencies since the sources are in gnulib, not here.
895 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
897 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
899 echo "${libname}_${libext}_SOURCES ="
900 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
901 echo "noinst_HEADERS ="
903 echo "BUILT_SOURCES ="
905 echo "MOSTLYCLEANFILES ="
906 echo "MOSTLYCLEANDIRS ="
908 echo "DISTCLEANFILES ="
909 echo "MAINTAINERCLEANFILES ="
913 for module in $modules; do
914 func_verify_nontests_module
915 if test -n "$module"; then
917 func_get_automake_snippet "$module" |
918 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g'
919 if test "$module" = 'alloca'; then
920 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
923 # Skip the contents if its entirely empty.
924 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
925 echo "## begin gnulib module $module"
928 echo "## end gnulib module $module"
935 echo "mostlyclean-local:"
936 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
937 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
938 echo " if test -d \$\$dir; then \\"
939 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
943 echo "# Makefile.am ends here"
946 # func_emit_tests_Makefile_am
947 # emits the contents of tests/Makefile.am to standard output.
949 # - modules list of modules, including dependencies
950 # - libname library name
951 # - libtool true if libtool will be used, false or blank otherwise
952 # - sourcebase relative directory containing lib source code
953 # - m4base relative directory containing autoconf macros
954 # - testsbase relative directory containing unit test code
955 func_emit_tests_Makefile_am ()
957 if test "$libtool" = true; then
962 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
963 echo "## Process this file with automake to produce Makefile.in."
964 func_emit_copyright_notice
966 # Generate dependencies here, since it eases the debugging of test failures.
967 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
969 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
971 # Nothing is being added to SUBDIRS; nevertheless the existence of this
972 # variable is needed to avoid an error from automake:
973 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
976 echo "TESTS_ENVIRONMENT ="
977 echo "noinst_PROGRAMS ="
978 echo "check_PROGRAMS ="
979 echo "noinst_HEADERS ="
981 echo "BUILT_SOURCES ="
983 echo "MOSTLYCLEANFILES ="
984 echo "MOSTLYCLEANDIRS ="
986 echo "DISTCLEANFILES ="
987 echo "MAINTAINERCLEANFILES ="
989 echo "AM_CPPFLAGS = \\"
990 echo " -I. -I\$(srcdir) \\"
991 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
992 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
994 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
996 for module in $modules; do
997 func_verify_tests_module
998 if test -n "$module"; then
999 func_get_automake_snippet "$module" > amsnippet.tmp
1000 # Skip the contents if its entirely empty.
1001 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
1002 echo "## begin gnulib module $module"
1005 echo "## end gnulib module $module"
1011 echo "# Clean up after Solaris cc."
1013 echo " rm -rf SunWS_cache"
1015 echo "mostlyclean-local:"
1016 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
1017 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
1018 echo " if test -d \$\$dir; then \\"
1019 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1023 echo "# Makefile.am ends here"
1026 # func_import modules
1027 # Uses also the variables
1028 # - destdir target directory
1029 # - libname library name
1030 # - sourcebase directory relative to destdir where to place source code
1031 # - m4base directory relative to destdir where to place *.m4 macros
1032 # - docbase directory relative to destdir where to place doc files
1033 # - testsbase directory relative to destdir where to place unit test code
1034 # - auxdir directory relative to destdir where to place build aux files
1035 # - inctests true if --with-tests was given, blank otherwise
1036 # - avoidlist list of modules to avoid, from --avoid
1037 # - lgpl true if library's license shall be LGPL, blank otherwise
1038 # - libtool true if --libtool was given, false if --no-libtool was
1039 # given, blank otherwise
1040 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
1041 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
1042 # - autoconf_minversion minimum supported autoconf version
1043 # - doit : if actions shall be executed, false if only to be printed
1044 # - symbolic true if files should be symlinked, copied otherwise
1047 # Get the cached settings.
1048 cached_specified_modules=
1057 cached_macro_prefix=
1059 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1060 cached_libtool=false
1066 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
1069 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
1072 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
1075 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
1078 s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
1081 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
1084 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
1087 s,^.*$,cached_lgpl=true,p
1090 s,^.*$,cached_libtool=true,p
1092 /gl_MACRO_PREFIX(/ {
1093 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
1095 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
1096 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1101 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
1102 s,^.*$,cached_files=",p
1114 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
1118 # Merge the cached settings with the specified ones.
1119 # The m4base must be the same as expected from the pathname.
1120 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
1121 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
1123 # Append the cached and the specified module names. So that
1124 # "gnulib-tool --import foo" means to add the module foo.
1125 specified_modules="$cached_specified_modules $1"
1126 # Append the cached and the specified avoidlist. This is probably better
1127 # than dropping the cached one when --avoid is specified at least once.
1128 avoidlist=`echo $cached_avoidlist $avoidlist`
1129 # The sourcebase defaults to the cached one.
1130 if test -z "$sourcebase"; then
1131 sourcebase="$cached_sourcebase"
1132 if test -z "$sourcebase"; then
1133 func_fatal_error "missing --source-base option"
1136 # The docbase defaults to the cached one.
1137 if test -z "$docbase"; then
1138 docbase="$cached_docbase"
1139 if test -z "$docbase"; then
1140 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."
1143 # The testsbase defaults to the cached one.
1144 if test -z "$testsbase"; then
1145 testsbase="$cached_testsbase"
1146 if test -z "$testsbase"; then
1147 func_fatal_error "missing --tests-base option"
1150 # The libname defaults to the cached one.
1151 if test -z "$supplied_libname"; then
1152 libname="$cached_libname"
1153 if test -z "$libname"; then
1154 func_fatal_error "missing --lib option"
1157 # Require LGPL if specified either way.
1158 if test -z "$lgpl"; then
1161 # Use libtool if specified either way, or if guessed.
1162 if test -z "$libtool"; then
1163 if test -n "$cached_m4base"; then
1164 libtool="$cached_libtool"
1166 libtool="$guessed_libtool"
1169 # The macro_prefix defaults to the cached one.
1170 if test -z "$macro_prefix"; then
1171 macro_prefix="$cached_macro_prefix"
1172 if test -z "$macro_prefix"; then
1173 func_fatal_error "missing --macro-prefix option"
1177 # Canonicalize the list of specified modules.
1178 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1180 # Determine final module list.
1181 modules="$specified_modules"
1182 func_modules_transitive_closure
1183 echo "Module list with included dependencies:"
1184 echo "$modules" | sed -e 's/^/ /'
1186 # Add the dummy module if needed.
1187 func_modules_add_dummy
1189 # If --lgpl, check the license of modules are compatible.
1190 if test -n "$lgpl"; then
1191 for module in $modules; do
1192 license=`func_get_license $module`
1194 LGPL | 'GPLed build tool' | 'public domain' | 'unlimited') ;;
1195 *) func_fatal_error "incompatible license on module $module: $license" ;;
1200 # Determine final file list.
1201 func_modules_to_filelist
1203 echo "$files" | sed -e 's/^/ /'
1206 || func_fatal_error "refusing to do nothing"
1208 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1209 new_files="$files m4/gnulib-tool.m4"
1210 old_files="$cached_files"
1211 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1212 old_files="$old_files m4/gnulib-tool.m4"
1215 # Create directories.
1216 if test ! -d "$destdir/$sourcebase"; then
1218 echo "Creating directory $destdir/$sourcebase"
1219 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1221 echo "Create directory $destdir/$sourcebase"
1224 if test ! -d "$destdir/$m4base"; then
1226 echo "Creating directory $destdir/$m4base"
1227 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1229 echo "Create directory $destdir/$m4base"
1232 docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
1233 if test -n "$docfiles"; then
1234 if test ! -d "$destdir/$docbase"; then
1236 echo "Creating directory $destdir/$docbase"
1237 mkdir "$destdir/$docbase" || func_fatal_error "failed"
1239 echo "Create directory $destdir/$docbase"
1243 if test -n "$inctests"; then
1244 if test ! -d "$destdir/$testsbase"; then
1246 echo "Creating directory $destdir/$testsbase"
1247 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1249 echo "Create directory $destdir/$testsbase"
1253 if test ! -d "$destdir/$auxdir"; then
1255 echo "Creating directory $destdir/$auxdir"
1256 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1258 echo "Create directory $destdir/$auxdir"
1262 # func_dest_tmpfilename file
1263 # determines the name of a temporary file (file is relative to destdir).
1265 # - tmpfile absolute filename of the temporary file
1266 func_dest_tmpfilename ()
1269 # Put the new contents of $file in a file in the same directory (needed
1270 # to guarantee that an 'mv' to "$destdir/$file" works).
1271 tmpfile="$destdir/$1.tmp"
1273 # Put the new contents of $file in a file in a temporary directory
1274 # (because the directory of "$file" might not exist).
1275 tmpfile="$tmp"/`basename "$1"`.tmp
1279 # Copy files or make symbolic links. Remove obsolete files.
1281 for f in $old_files; do
1283 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1284 doc/*) g=`echo "$f" | sed -e "s,^doc/,$cached_docbase/,"` ;;
1285 lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
1286 m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
1287 tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
1290 echo "$g""$delimiter""$f"
1291 done | LC_ALL=C sort > "$tmp"/old-files
1292 for f in $new_files; do
1294 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1295 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1296 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1297 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1298 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1301 echo "$g""$delimiter""$f"
1302 done | LC_ALL=C sort > "$tmp"/new-files
1303 # First the files that are in old-files, but not in new-files:
1304 sed_take_first_column='s,'"$delimiter"'.*,,'
1305 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1306 # Remove the file. Do nothing if the user already removed it.
1307 if test -f "$destdir/$g"; then
1309 echo "Removing file $g (backup in ${g}~)"
1310 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1312 echo "Remove file $g (backup in ${g}~)"
1316 # func_add_or_update handles a file that ought to be present afterwards.
1317 # Uses parameters f, g, already_present.
1318 func_add_or_update ()
1320 func_dest_tmpfilename "$g"
1321 func_lookup_file "$f"
1322 cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
1323 if test -n "$lgpl"; then
1327 sed -e 's/GNU General/GNU Lesser General/g' \
1328 -e 's/version 2\([ ,]\)/version 2.1\1/g' \
1329 < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
1333 if test -f "$destdir/$g"; then
1334 # The file already exists.
1335 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1336 : # The file has not changed.
1340 if test -n "$already_present"; then
1341 echo "Updating file $g (backup in ${g}~)"
1343 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1345 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1346 if test -n "$symbolic" && test -z "$lookedup_tmp" \
1347 && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1348 func_ln_if_changed "$lookedup_file" "$destdir/$g"
1350 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1353 if test -n "$already_present"; then
1354 echo "Update file $g (backup in ${g}~)"
1356 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1362 # Don't protest if the file should be there but isn't: it happens
1363 # frequently that developers don't put autogenerated files into CVS.
1365 echo "Copying file $g"
1366 if test -n "$symbolic" && test -z "$lookedup_tmp" \
1367 && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1368 func_ln_if_changed "$lookedup_file" "$destdir/$g"
1370 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1378 # Then the files that are in new-files, but not in old-files:
1379 sed_take_last_column='s,^.*'"$delimiter"',,'
1381 for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1383 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1384 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1385 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1386 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1387 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1392 # Then the files that are in new-files and in old-files:
1393 already_present=true
1394 for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
1396 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1397 doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
1398 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
1399 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
1400 tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
1406 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1407 actioncmd="gnulib-tool --import"
1408 actioncmd="$actioncmd --dir=$destdir"
1409 actioncmd="$actioncmd --lib=$libname"
1410 actioncmd="$actioncmd --source-base=$sourcebase"
1411 actioncmd="$actioncmd --m4-base=$m4base"
1412 actioncmd="$actioncmd --doc-base=$docbase"
1413 actioncmd="$actioncmd --aux-dir=$auxdir"
1414 for module in $avoidlist; do
1415 actioncmd="$actioncmd --avoid=$module"
1417 if test -n "$lgpl"; then
1418 actioncmd="$actioncmd --lgpl"
1420 if test "$libtool" = true; then
1421 actioncmd="$actioncmd --libtool"
1423 actioncmd="$actioncmd --no-libtool"
1425 actioncmd="$actioncmd --macro-prefix=$macro_prefix"
1426 actioncmd="$actioncmd `echo $specified_modules`"
1428 # Create lib/Makefile.am.
1429 func_dest_tmpfilename $sourcebase/Makefile.am
1430 func_emit_lib_Makefile_am > "$tmpfile"
1431 if test -f "$destdir"/$sourcebase/Makefile.am; then
1432 if cmp "$destdir"/$sourcebase/Makefile.am "$tmpfile" > /dev/null; then
1436 echo "Updating $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1437 mv -f "$destdir"/$sourcebase/Makefile.am "$destdir"/$sourcebase/Makefile.am~
1438 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1440 echo "Update $sourcebase/Makefile.am (backup in $sourcebase/Makefile.am~)"
1446 echo "Creating $sourcebase/Makefile.am"
1447 mv -f "$tmpfile" "$destdir"/$sourcebase/Makefile.am
1449 echo "Create $sourcebase/Makefile.am"
1454 # Create m4/gnulib-cache.m4.
1455 func_dest_tmpfilename $m4base/gnulib-cache.m4
1457 func_emit_copyright_notice
1459 echo "# This file represents the specification of how gnulib-tool is used."
1460 echo "# It acts as a cache: It is written and read by gnulib-tool."
1461 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1462 echo "# like the configure.ac and various Makefile.am files."
1465 echo "# Specification in the form of a command-line invocation:"
1468 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1469 echo "gl_MODULES(["`echo $specified_modules`"])"
1470 echo "gl_AVOID([$avoidlist])"
1471 echo "gl_SOURCE_BASE([$sourcebase])"
1472 echo "gl_M4_BASE([$m4base])"
1473 echo "gl_DOC_BASE([$docbase])"
1474 echo "gl_TESTS_BASE([$testsbase])"
1475 echo "gl_LIB([$libname])"
1476 test -z "$lgpl" || echo "gl_LGPL"
1477 if test "$libtool" = true; then
1480 echo "gl_MACRO_PREFIX([$macro_prefix])"
1482 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1483 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1487 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1488 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1489 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1491 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1495 echo "# gnulib-cache.m4 ends here"
1502 echo "Creating $m4base/gnulib-cache.m4"
1503 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1505 echo "Create $m4base/gnulib-cache.m4"
1511 # Create m4/gnulib-comp.m4.
1512 func_dest_tmpfilename $m4base/gnulib-comp.m4
1514 func_emit_copyright_notice
1516 echo "# This file represents the compiled summary of the specification in"
1517 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1518 echo "# to be invoked from configure.ac."
1519 echo "# In projects using CVS, this file can be treated like other built files."
1522 echo "# This macro should be invoked from $configure_ac, in the section"
1523 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1524 echo "# any checks for libraries, header files, types and library functions."
1525 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1527 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1528 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1529 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1531 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1532 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1534 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1535 echo " AC_REQUIRE([gl_LOCK])"
1539 echo "# This macro should be invoked from $configure_ac, in the section"
1540 echo "# \"Check for header files, types and library functions\"."
1541 echo "AC_DEFUN([${macro_prefix}_INIT],"
1543 if test "$libtool" = true; then
1544 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1546 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1548 if test "$auxdir" != "build-aux"; then
1549 sed_replace_build_aux='
1551 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1552 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1555 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1557 sed_replace_build_aux=
1559 for module in $modules; do
1561 if test -n "$module"; then
1562 func_get_autoconf_snippet "$module" \
1563 | sed -e '/^$/d;' -e 's/^/ /' \
1564 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1565 -e "$sed_replace_build_aux"
1566 if test "$module" = 'alloca' && test "$libtool" = true; then
1567 echo 'changequote(,)dnl'
1568 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1569 echo 'changequote([, ])dnl'
1570 echo 'AC_SUBST([LTALLOCA])'
1576 echo "# This macro records the list of files which have been installed by"
1577 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1578 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1579 echo "$files" | sed -e 's,^, ,'
1582 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1583 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
1587 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1588 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1589 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1591 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1595 echo "# gnulib-comp.m4 ends here"
1602 echo "Creating $m4base/gnulib-comp.m4"
1603 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1605 echo "Create $m4base/gnulib-comp.m4"
1611 if test -n "$inctests"; then
1612 # Create tests/Makefile.am.
1613 func_dest_tmpfilename $testsbase/Makefile.am
1614 func_emit_tests_Makefile_am > "$tmpfile"
1615 if test -f "$destdir"/$testsbase/Makefile.am; then
1616 if cmp "$destdir"/$testsbase/Makefile.am "$tmpfile" > /dev/null; then
1620 echo "Updating $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1621 mv -f "$destdir"/$testsbase/Makefile.am "$destdir"/$testsbase/Makefile.am~
1622 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1624 echo "Update $testsbase/Makefile.am (backup in $testsbase/Makefile.am~)"
1630 echo "Creating $testsbase/Makefile.am"
1631 mv -f "$tmpfile" "$destdir"/$testsbase/Makefile.am
1633 echo "Create $testsbase/Makefile.am"
1641 echo "You may need to add #include directives for the following .h files."
1643 # First the #include <...> directives without #ifs, sorted for convenience.
1644 for module in $modules; do
1645 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1648 func_get_include_directive "$module" | grep -v 'include "'
1650 done | LC_ALL=C sort -u
1651 # Then the #include "..." directives without #ifs, sorted for convenience.
1652 for module in $modules; do
1653 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1656 func_get_include_directive "$module" | grep 'include "'
1658 done | LC_ALL=C sort -u
1659 # Then the #include directives that are surrounded by #ifs. Not sorted.
1660 for module in $modules; do
1661 if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
1662 func_get_include_directive "$module"
1665 ) | sed -e '/^$/d;' -e 's/^/ /'
1667 echo "Don't forget to"
1668 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1669 if test -n "$inctests"; then
1670 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
1672 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
1673 sourcebase_base=`basename "$sourcebase"`
1674 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
1675 if test -n "$inctests"; then
1676 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
1677 testsbase_base=`basename "$testsbase"`
1678 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
1680 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
1681 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
1682 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
1685 # func_create_testdir testdir modules
1687 # - auxdir directory relative to destdir where to place build aux files
1688 func_create_testdir ()
1692 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
1694 # Determine final module list.
1695 func_modules_transitive_closure
1696 echo "Module list with included dependencies:"
1697 echo "$modules" | sed -e 's/^/ /'
1699 # Add the dummy module if needed.
1700 func_modules_add_dummy
1702 # Determine final file list.
1703 func_modules_to_filelist
1705 echo "$files" | sed -e 's/^/ /'
1707 # Create directories.
1708 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
1709 if test "$d" = build-aux; then
1710 mkdir -p "$testdir/$auxdir"
1712 mkdir -p "$testdir/$d"
1716 # Copy files or make symbolic links.
1718 func_lookup_file "$f"
1720 build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
1723 if test -n "$lookedup_tmp"; then
1724 cp -p "$lookedup_file" "$testdir/$g"
1726 ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
1727 if test -z "$symbolic"; then
1728 cp -p "$lookedup_file" "$testdir/$g"
1730 ln -s "$lookedup_file" "$testdir/$g"
1735 # Create lib/Makefile.am.
1736 mkdir -p "$testdir/lib"
1737 func_emit_lib_Makefile_am > "$testdir/lib/Makefile.am"
1739 # Create m4/Makefile.am.
1740 mkdir -p "$testdir/m4"
1741 (echo "## Process this file with automake to produce Makefile.in."
1747 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
1750 ) > "$testdir/m4/Makefile.am"
1753 subdirs_with_configure_ac=""
1755 if test -f "$testdir"/m4/gettext.m4; then
1756 # Avoid stupid error message from automake:
1757 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
1758 mkdir -p "$testdir/po"
1759 (echo "## Process this file with automake to produce Makefile.in."
1760 ) > "$testdir/po/Makefile.am"
1761 subdirs="$subdirs po"
1764 if test -n "$inctests"; then
1765 test -d "$testdir/tests" || mkdir "$testdir/tests"
1766 # Create tests/Makefile.am.
1770 func_emit_tests_Makefile_am > "$testdir/tests/Makefile.am"
1771 # Create tests/configure.ac.
1772 (echo "# Process this file with autoconf to produce a configure script."
1773 echo "AC_INIT([dummy], [0])"
1774 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
1775 echo "AM_INIT_AUTOMAKE"
1777 echo "AM_CONFIG_HEADER([config.h])"
1780 echo "AC_PROG_INSTALL"
1781 echo "AC_PROG_MAKE_SET"
1782 echo "AC_PROG_RANLIB"
1784 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1785 echo "AC_GNU_SOURCE"
1788 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1789 echo "gl_USE_SYSTEM_EXTENSIONS"
1792 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1796 if test "$libtool" = true; then
1797 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1799 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1801 if test "$auxdir" != "build-aux"; then
1802 sed_replace_build_aux='
1804 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1805 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
1808 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1810 sed_replace_build_aux=
1812 # We don't have explicit ordering constraints between the various
1813 # autoconf snippets. It's cleanest to put those of the library before
1814 # those of the tests.
1815 for module in $modules; do
1816 func_verify_nontests_module
1817 if test -n "$module"; then
1818 func_get_autoconf_snippet "$module" \
1819 | sed -e "$sed_replace_build_aux"
1822 for module in $modules; do
1823 func_verify_tests_module
1824 if test -n "$module"; then
1825 func_get_autoconf_snippet "$module" \
1826 | sed -e "$sed_replace_build_aux"
1830 # Usually tests/config.h will be a superset of config.h. Verify this by
1831 # "merging" config.h into tests/config.h; look out for gcc warnings.
1832 echo "AH_TOP([#include \"../config.h\"])"
1834 echo "AC_OUTPUT([Makefile])"
1835 ) > "$testdir/tests/configure.ac"
1836 subdirs="$subdirs tests"
1837 subdirs_with_configure_ac="$subdirs_with_configure_ac tests"
1840 # Create Makefile.am.
1841 (echo "## Process this file with automake to produce Makefile.in."
1843 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1845 echo "SUBDIRS = $subdirs"
1847 echo "ACLOCAL_AMFLAGS = -I m4"
1848 ) > "$testdir/Makefile.am"
1850 # Create configure.ac.
1851 (echo "# Process this file with autoconf to produce a configure script."
1852 echo "AC_INIT([dummy], [0])"
1853 if test "$auxdir" != "."; then
1854 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1856 echo "AM_INIT_AUTOMAKE"
1858 echo "AM_CONFIG_HEADER([config.h])"
1861 echo "AC_PROG_INSTALL"
1862 echo "AC_PROG_MAKE_SET"
1863 echo "AC_PROG_RANLIB"
1865 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1866 echo "AC_GNU_SOURCE"
1869 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1870 echo "gl_USE_SYSTEM_EXTENSIONS"
1873 if grep gl_LOCK "$testdir"/m4/*.m4 >/dev/null 2>/dev/null; then
1877 if test "$libtool" = true; then
1878 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1880 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1882 if test "$auxdir" != "build-aux"; then
1883 sed_replace_build_aux='
1885 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1886 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1889 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1891 sed_replace_build_aux=
1893 for module in $modules; do
1894 func_verify_nontests_module
1895 if test -n "$module"; then
1896 func_get_autoconf_snippet "$module" \
1897 | sed -e "$sed_replace_build_aux"
1901 if test -n "$subdirs_with_configure_ac"; then
1902 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
1904 makefiles="Makefile"
1905 for d in $subdirs; do
1906 # For subdirs that have a configure.ac by their own, it's the subdir's
1907 # configure.ac which creates the subdir's Makefile.am, not this one.
1908 case " $subdirs_with_configure_ac " in
1910 *) makefiles="$makefiles $d/Makefile" ;;
1913 echo "AC_OUTPUT([$makefiles])"
1914 ) > "$testdir/configure.ac"
1916 # Create autogenerated files.
1918 echo "executing ${AUTORECONF} --force --install"
1919 ${AUTORECONF} --force --install
1921 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
1925 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
1933 # func_create_megatestdir megatestdir allmodules
1935 # - auxdir directory relative to destdir where to place build aux files
1936 func_create_megatestdir ()
1940 if test -z "$allmodules"; then
1941 allmodules=`func_all_modules`
1945 # First, all modules one by one.
1946 for onemodule in $allmodules; do
1947 func_create_testdir "$megatestdir/$onemodule" $onemodule
1948 megasubdirs="${megasubdirs}$onemodule "
1950 # Then, all modules all together.
1951 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
1952 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
1953 func_create_testdir "$megatestdir/ALL" "$allmodules"
1954 megasubdirs="${megasubdirs}ALL"
1956 # Create Makefile.am.
1957 (echo "## Process this file with automake to produce Makefile.in."
1959 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1961 echo "SUBDIRS = $megasubdirs"
1962 ) > "$megatestdir/Makefile.am"
1964 # Create configure.ac.
1965 (echo "# Process this file with autoconf to produce a configure script."
1966 echo "AC_INIT([dummy], [0])"
1967 if test "$auxdir" != "."; then
1968 echo "AC_CONFIG_AUX_DIR([$auxdir])"
1970 echo "AM_INIT_AUTOMAKE"
1972 echo "AC_PROG_MAKE_SET"
1974 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
1975 echo "AC_OUTPUT([Makefile])"
1976 ) > "$megatestdir/configure.ac"
1978 # Create autogenerated files.
1980 # Do not use "${AUTORECONF} --install", because autoreconf operates
1981 # recursively, but the subdirectories are already finished, therefore
1982 # calling autoreconf here would only waste lots of CPU time.
1983 echo "executing ${ACLOCAL}"
1985 echo "executing mkdir build-aux"
1987 echo "executing ${AUTOCONF}"
1989 echo "executing ${AUTOMAKE} --add-missing --copy"
1990 ${AUTOMAKE} --add-missing --copy
1996 func_fatal_error "no mode specified" ;;
2005 if test -z "$destdir"; then
2008 test -d "$destdir" \
2009 || func_fatal_error "destination directory does not exist: $destdir"
2011 # Prefer configure.ac to configure.in.
2012 if test -f "$destdir"/configure.ac; then
2013 configure_ac="$destdir/configure.ac"
2015 if test -f "$destdir"/configure.in; then
2016 configure_ac="$destdir/configure.in"
2018 func_fatal_error "cannot find $destdir/configure.ac"
2022 # Analyze configure.ac.
2024 guessed_libtool=false
2029 /AC_CONFIG_AUX_DIR/ {
2030 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
2032 /A[CM]_PROG_LIBTOOL/ {
2033 s,^.*$,guessed_libtool=true,p
2035 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
2037 if test -z "$auxdir"; then
2038 auxdir="$guessed_auxdir"
2041 # Determine where to apply func_import.
2042 if test -n "$m4base"; then
2043 # Apply func_import to a particular gnulib directory.
2044 # Any number of additional modules can be given.
2045 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
2046 # First use of gnulib in the given m4base.
2047 test -n "$supplied_libname" || supplied_libname=true
2048 test -n "$sourcebase" || sourcebase="lib"
2049 test -n "$docbase" || docbase="doc"
2050 test -n "$testsbase" || testsbase="tests"
2051 test -n "$macro_prefix" || macro_prefix="gl"
2055 # Apply func_import to all gnulib directories.
2056 # To get this list of directories, look at Makefile.am. (Not at
2057 # configure, because it may be omitted from CVS. Also, don't run
2058 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
2061 if test -f "$destdir"/Makefile.am; then
2062 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
2064 for arg in $aclocal_amflags; do
2065 if test -n "$m4dir_is_next"; then
2066 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
2070 if test -f "$destdir/$arg"/gnulib-cache.m4; then
2071 m4dirs="$m4dirs $arg"
2072 m4dirs_count=`expr $m4dirs_count + 1`
2077 if test "X$arg" = "X-I"; then
2085 # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
2086 if test -f "$destdir"/aclocal.m4; then
2087 sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
2088 sedexpr2='s,^[^/]*$,.,'
2089 sedexpr3='s,/[^/]*$,,'
2090 m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort | LC_ALL=C uniq`
2091 m4dirs_count=`echo "$m4dirs" | wc -l`
2094 if test $m4dirs_count = 0; then
2095 # First use of gnulib in a package.
2096 # Any number of additional modules can be given.
2097 test -n "$supplied_libname" || supplied_libname=true
2098 test -n "$sourcebase" || sourcebase="lib"
2100 test -n "$docbase" || docbase="doc"
2101 test -n "$testsbase" || testsbase="tests"
2102 test -n "$macro_prefix" || macro_prefix="gl"
2105 if test $m4dirs_count = 1; then
2106 # There's only one use of gnulib here. Assume the user means it.
2107 # Any number of additional modules can be given.
2108 for m4base in $m4dirs; do
2112 # Ambiguous - guess what the user meant.
2113 if test $# = 0; then
2114 # No further arguments. Guess the user wants to update all of them.
2115 for m4base in $m4dirs; do
2120 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
2128 if test -z "$destdir"; then
2129 func_fatal_error "please specify --dir option"
2132 test -d "$destdir" \
2133 || func_fatal_error "could not create destination directory"
2134 test -n "$auxdir" || auxdir="build-aux"
2135 func_create_testdir "$destdir" "$*"
2138 create-megatestdir )
2139 if test -z "$destdir"; then
2140 func_fatal_error "please specify --dir option"
2142 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2143 test -n "$auxdir" || auxdir="build-aux"
2144 func_create_megatestdir "$destdir" "$*"
2148 test -n "$destdir" || destdir=testdir$$
2149 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2150 test -n "$auxdir" || auxdir="build-aux"
2151 func_create_testdir "$destdir" "$*"
2159 remaining=`find . -type f -print`
2160 if test -n "$remaining"; then
2161 echo "Remaining files:" $remaining 1>&2
2162 echo "gnulib-tool: *** Stop." 1>&2
2171 test -n "$destdir" || destdir=testdir$$
2172 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2173 test -n "$auxdir" || auxdir="build-aux"
2174 func_create_megatestdir "$destdir" "$*"
2182 remaining=`find . -type f -print`
2183 if test -n "$remaining"; then
2184 echo "Remaining files:" $remaining 1>&2
2185 echo "gnulib-tool: *** Stop." 1>&2
2193 extract-description )
2197 if test -n "$module"; then
2198 func_get_description "$module"
2207 if test -n "$module"; then
2208 func_get_filelist "$module"
2213 extract-dependencies )
2217 if test -n "$module"; then
2218 func_get_dependencies "$module"
2223 extract-autoconf-snippet )
2227 if test -n "$module"; then
2228 func_get_autoconf_snippet "$module"
2233 extract-automake-snippet )
2237 if test -n "$module"; then
2238 func_get_automake_snippet "$module"
2243 extract-include-directive )
2247 if test -n "$module"; then
2248 func_get_include_directive "$module"
2257 if test -n "$module"; then
2258 func_get_license "$module"
2263 extract-maintainer )
2267 if test -n "$module"; then
2268 func_get_maintainer "$module"
2273 extract-tests-module )
2277 if test -n "$module"; then
2278 func_get_tests_module "$module"
2284 func_fatal_error "unknown operation mode --$mode" ;;
2288 # Undo the effect of the previous 'trap' command. Some shellology:
2289 # We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
2290 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
2291 # exit); for the others we need to call 'exit' explicitly. The value of $? is
2292 # 128 + signal number and is set before the trap-registered command is run.
2294 trap 'exit $?' 1 2 3 15