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-09-18 17:03:47 $'
26 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
27 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
31 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
35 # AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
36 # AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
40 # You can set AUTOMAKEPATH to empty if automake 1.9.x is already in your PATH.
43 # If you didn't set AUTOCONFPATH and AUTOMAKEPATH, you can also set the
44 # variables AUTOCONF, ACLOCAL, AUTOMAKE, AUTORECONF individually.
45 if test -z "${AUTOCONF}" || test -n "${AUTOCONFPATH}"; then
46 AUTOCONF="${AUTOCONFPATH}autoconf"
48 if test -z "${ACLOCAL}" || test -n "${AUTOMAKEPATH}"; then
49 ACLOCAL="${AUTOMAKEPATH}aclocal"
51 if test -z "${AUTOMAKE}" || test -n "${AUTOMAKEPATH}"; then
52 AUTOMAKE="${AUTOMAKEPATH}automake"
54 if test -z "${AUTORECONF}" || test -n "${AUTOCONFPATH}"; then
55 AUTORECONF="${AUTOCONFPATH}autoreconf"
58 # GNU sort is needed. Set SORT to its location (not needed if it's called
59 # 'sort' and already in the PATH).
60 if test -z "$SORT"; then
65 # outputs to stdout the --help usage message.
69 Usage: gnulib-tool --list
70 gnulib-tool --import [module1 ... moduleN]
72 gnulib-tool --create-testdir --dir=directory module1 ... moduleN
73 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
74 gnulib-tool --test --dir=directory module1 ... moduleN
75 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
76 gnulib-tool --extract-description module
77 gnulib-tool --extract-filelist module
78 gnulib-tool --extract-dependencies module
79 gnulib-tool --extract-autoconf-snippet module
80 gnulib-tool --extract-automake-snippet module
81 gnulib-tool --extract-include-directive module
82 gnulib-tool --extract-license module
83 gnulib-tool --extract-maintainer module
84 gnulib-tool --extract-tests-module module
87 --list print the available module names
88 --import import the given modules into the current package;
89 if no modules are specified, update the current
90 package from the current gnulib
91 --update update the current package, restore files omitted
93 --create-testdir create a scratch package with the given modules
94 --create-megatestdir create a mega scratch package with the given modules
95 one by one and all together
96 --test test the combination of the given modules
97 (recommended to use CC=\"gcc -Wall\" here)
98 --megatest test the given modules one by one and all together
99 (recommended to use CC=\"gcc -Wall\" here)
100 --extract-description extract the description
101 --extract-filelist extract the list of files
102 --extract-dependencies extract the dependencies
103 --extract-autoconf-snippet extract the snippet for configure.ac
104 --extract-automake-snippet extract the snippet for library makefile
105 --extract-include-directive extract the #include directive
106 --extract-license report the license terms of the source files
108 --extract-maintainer report the maintainer(s) inside gnulib
109 --extract-tests-module report the unit test module, if it exists
112 --dir=DIRECTORY Specify the target directory.
113 For --import, this specifies where your
114 configure.ac can be found. Defaults to current
116 --local-dir=DIRECTORY Specify a local override directory where to look
117 up files before looking in gnulib's directory.
119 Options for --import:
120 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
121 --source-base=DIRECTORY
122 Directory relative to --dir where source code is
123 placed (default \"lib\").
124 --m4-base=DIRECTORY Directory relative to --dir where *.m4 macros are
125 placed (default \"m4\").
126 --doc-base=DIRECTORY Directory relative to --dir where doc files are
127 placed (default \"doc\").
128 --tests-base=DIRECTORY
129 Directory relative to --dir where unit tests are
130 placed (default \"tests\").
131 --aux-dir=DIRECTORY Directory relative to --dir where auxiliary build
132 tools are placed (default \"build-aux\").
133 --with-tests Include unit tests for the included modules.
134 --avoid=MODULE Avoid including the given MODULE. Useful if you
135 have code that provides equivalent functionality.
136 This option can be repeated.
137 --lgpl Abort if modules aren't available under the LGPL.
138 Also modify license template from GPL to LGPL.
139 --makefile-name=NAME Name of makefile in automake syntax in the
140 source-base and tests-base directories
141 (default \"Makefile.am\").
142 --libtool Use libtool rules.
143 --no-libtool Don't use libtool rules.
144 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
145 'gl_INIT'. Default is 'gl'.
146 --no-changelog don't update or create ChangeLog files
148 Options for --import and --update:
149 --dry-run For --import, only print what would have been done.
150 -s, --symbolic, --symlink Make symbolic links instead of copying files.
152 Report bugs to <bug-gnulib@gnu.org>."
156 # outputs to stdout the --version message.
159 year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
160 echo "$progname (GNU $package) $version"
161 echo "Copyright (C) $year Free Software Foundation, Inc.
162 This is free software; see the source for copying conditions. There is NO
163 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
164 echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
167 # func_emit_copyright_notice
168 # outputs to stdout a header for a generated file.
169 func_emit_copyright_notice ()
171 echo "# Copyright (C) 2004-2006 Free Software Foundation, Inc."
173 echo "# This file is free software, distributed under the terms of the GNU"
174 echo "# General Public License. As a special exception to the GNU General"
175 echo "# Public License, this file may be distributed as part of a program"
176 echo "# that contains a configuration script generated by Autoconf, under"
177 echo "# the same distribution terms as the rest of that program."
179 echo "# Generated by gnulib-tool."
183 # creates a temporary directory.
185 # - tmp pathname of freshly created temporary directory
188 # Use the environment variable TMPDIR, falling back to /tmp. This allows
189 # users to specify a different temporary directory, for example, if their
190 # /tmp is filled up or too small.
193 # Use the mktemp program if available. If not available, hide the error
195 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
196 test -n "$tmp" && test -d "$tmp"
199 # Use a simple mkdir command. It is guaranteed to fail if the directory
200 # already exists. $RANDOM is bash specific and expands to empty in shells
201 # other than bash, ksh and zsh. Its use does not increase security;
202 # rather, it minimizes the probability of failure in a very cluttered /tmp
204 tmp=$TMPDIR/gl$$-$RANDOM
205 (umask 077 && mkdir "$tmp")
208 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
209 { (exit 1); exit 1; }
213 # func_append var value
214 # appends the given value to the shell variable var.
215 if ( foo=bar; foo+=baz && test "$foo" = barbaz ) >/dev/null 2>&1; then
216 # Use bash's += operator. It reduces complexity of appending repeatedly to
217 # a single variable from O(n^2) to O(n).
225 eval "$1=\"\$$1\$2\""
229 # func_fatal_error message
230 # outputs to stderr a fatal error message, and terminates the program.
233 echo "gnulib-tool: *** $1" 1>&2
234 echo "gnulib-tool: *** Stop." 1>&2
238 # func_readlink SYMLINK
239 # outputs the target of the given symlink.
240 if (type -p readlink) > /dev/null 2>&1; then
243 # Use the readlink program from GNU coreutils.
249 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
250 # would do the wrong thing if the link target contains " -> ".
251 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
255 # func_ln_if_changed SRC DEST
256 # Like ln -s, but avoids munging timestamps if the link is correct.
257 func_ln_if_changed ()
259 if test $# -ne 2; then
260 echo "usage: func_ln_if_changed SRC DEST" >&2
262 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
270 # func_relativize DIR1 DIR2
271 # computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
273 # - DIR1 relative pathname, relative to the current directory
274 # - DIR2 relative pathname, relative to the current directory
276 # - reldir relative pathname of DIR2, relative to DIR1
282 sed_first='s,^\([^/]*\)/.*$,\1,'
283 sed_rest='s,^[^/]*/*,,'
284 sed_last='s,^.*/\([^/]*\)$,\1,'
285 sed_butlast='s,/*[^/]*$,,'
286 while test -n "$dir1"; do
287 first=`echo "$dir1" | sed -e "$sed_first"`
288 if test "$first" != "."; then
289 if test "$first" = ".."; then
290 dir2=`echo "$dir0" | sed -e "$sed_last"`/"$dir2"
291 dir0=`echo "$dir0" | sed -e "$sed_butlast"`
293 first2=`echo "$dir2" | sed -e "$sed_first"`
294 if test "$first2" = "$first"; then
295 dir2=`echo "$dir2" | sed -e "$sed_rest"`
299 dir0="$dir0"/"$first"
302 dir1=`echo "$dir1" | sed -e "$sed_rest"`
307 # func_relconcat DIR1 DIR2
308 # computes a relative pathname DIR1/DIR2, with obvious simplifications.
310 # - DIR1 relative pathname, relative to the current directory
311 # - DIR2 relative pathname, relative to DIR1
313 # - relconcat DIR1/DIR2, relative to the current directory
318 sed_first='s,^\([^/]*\)/.*$,\1,'
319 sed_rest='s,^[^/]*/*,,'
320 sed_last='s,^.*/\([^/]*\)$,\1,'
321 sed_butlast='s,/*[^/]*$,,'
323 first=`echo "$dir2" | sed -e "$sed_first"`
324 if test "$first" = "."; then
325 dir2=`echo "$dir2" | sed -e "$sed_rest"`
326 if test -z "$dir2"; then
331 last=`echo "$dir1" | sed -e "$sed_last"`
332 while test "$last" = "."; do
333 dir1=`echo "$dir1" | sed -e "$sed_butlast"`
334 last=`echo "$dir1" | sed -e "$sed_last"`
336 if test -z "$dir1"; then
340 if test "$first" = ".."; then
341 if test "$last" = ".."; then
342 relconcat="$dir1/$dir2"
345 dir1=`echo "$dir1" | sed -e "$sed_butlast"`
346 dir2=`echo "$dir2" | sed -e "$sed_rest"`
347 if test -z "$dir1"; then
351 if test -z "$dir2"; then
356 relconcat="$dir1/$dir2"
363 # Command-line option processing.
364 # Removes the OPTIONS from the arguments. Sets the variables:
365 # - mode list or import or create-testdir or create-megatestdir
366 # - destdir from --dir
367 # - local_gnulib_dir from --local-dir
368 # - libname, supplied_libname from --lib
369 # - sourcebase from --source-base
370 # - m4base from --m4-base
371 # - docbase from --doc-base
372 # - testsbase from --tests-base
373 # - auxdir from --aux-dir
374 # - inctests true if --with-tests was given, blank otherwise
375 # - avoidlist list of modules to avoid, from --avoid
376 # - lgpl true if --lgpl was given, blank otherwise
377 # - makefile_name from --makefile-name
378 # - libtool true if --libtool was given, false if --no-libtool was
379 # given, blank otherwise
380 # - macro_prefix from --macro-prefix
381 # - autoconf_minversion minimum supported autoconf version
382 # - do_changelog false if --no-changelog was given, : otherwise
383 # - doit : if actions shall be executed, false if only to be printed
384 # - symbolic true if --symbolic was given, blank otherwise
408 while test $# -gt 0; do
413 --import | --impor | --impo | --imp | --im | --i )
416 --update | --updat | --upda | --upd | --up | --u )
419 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
422 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
423 mode=create-megatestdir
425 --test | --tes | --te | --t )
428 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
432 mode=`echo "X$1" | sed -e 's/^X--//'`
437 func_fatal_error "missing argument for --dir"
442 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
447 func_fatal_error "missing argument for --local-dir"
452 local_gnulib_dir=`echo "X$1" | sed -e 's/^X--local-dir=//'`
457 func_fatal_error "missing argument for --lib"
460 supplied_libname=true
463 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
464 supplied_libname=true
469 func_fatal_error "missing argument for --source-base"
474 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
479 func_fatal_error "missing argument for --m4-base"
484 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
489 func_fatal_error "missing argument for --doc-base"
494 docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
499 func_fatal_error "missing argument for --tests-base"
504 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
509 func_fatal_error "missing argument for --aux-dir"
514 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
522 func_fatal_error "missing argument for --avoid"
524 func_append avoidlist " $1"
527 arg=`echo "X$1" | sed -e 's/^X--avoid=//'`
528 func_append avoidlist " $arg"
536 func_fatal_error "missing argument for --makefile-name"
541 makefile_name=`echo "X$1" | sed -e 's/^X--makefile-name=//'`
552 func_fatal_error "missing argument for --macro-prefix"
557 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
559 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
565 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
568 --help | --hel | --he | --h )
571 --version | --versio | --versi | --vers | --ver | --ve | --v )
575 # Stop option processing
579 echo "gnulib-tool: unknown option $1" 1>&2
580 echo "Try 'gnulib-tool --help' for more information." 1>&2
587 if test "$mode" = update; then
588 if test $# != 0; then
589 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
590 echo "Try 'gnulib-tool --help' for more information." 1>&2
591 echo "If you really want to modify the gnulib configuration of your project," 1>&2
592 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
595 if test -n "$local_gnulib_dir" || test -n "$supplied_libname" \
596 || test -n "$sourcebase" || test -n "$m4base" \
597 || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
598 || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
599 || test -n "$makefile_name" || test -n "$macro_prefix"; then
600 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
601 echo "Try 'gnulib-tool --help' for more information." 1>&2
602 echo "If you really want to modify the gnulib configuration of your project," 1>&2
603 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
609 # Determine the minimum supported autoconf version from the project's
611 DEFAULT_AUTOCONF_MINVERSION="2.59"
614 if { test "$mode" = import || test "$mode" = update; } && test -n "$destdir"; then
615 if test -f "$destdir"/configure.ac; then
616 configure_ac="$destdir/configure.ac"
618 if test -f "$destdir"/configure.in; then
619 configure_ac="$destdir/configure.in"
623 if test -f configure.ac; then
624 configure_ac="configure.ac"
626 if test -f configure.in; then
627 configure_ac="configure.in"
631 if test -n "$configure_ac"; then
632 # Use sed, not autoconf --trace, to look for the AC_PREREQ invocation,
633 # because when some m4 files are omitted from a CVS repository,
634 # "autoconf --trace=AC_PREREQ" fails with an error message like this:
635 # m4: aclocal.m4:851: Cannot open m4/absolute-header.m4: No such file or directory
636 # autom4te: m4 failed with exit status: 1
643 s,^.*AC_PREREQ([[ ]*\([^])]*\).*$,prereqs="$prereqs \1",p
645 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
646 if test -n "$prereqs"; then
647 autoconf_minversion=`for version in $prereqs; do echo $version; done | $SORT -g -u | tail -1`
650 if test -z "$autoconf_minversion"; then
651 autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
653 case "$autoconf_minversion" in
654 1.* | 2.[0-4]* | 2.5[0-8]*)
655 func_fatal_error "minimum supported autoconf version is 2.59. Try adding AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
658 # Remove trailing slashes from the directory names. This is necessary for
659 # m4base (to avoid an error in func_import) and optional for the others.
660 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
661 case "$local_gnulib_dir" in
662 */ ) sourcebase=`echo "$local_gnulib_dir" | sed -e "$sed_trimtrailingslashes"` ;;
664 case "$sourcebase" in
665 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
668 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
671 */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
674 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
677 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
682 /*) self_abspathname="$0" ;;
683 */*) self_abspathname=`pwd`/"$0" ;;
684 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
685 if test -x "$d/$0" && test ! -d "$d/$0"; then
686 self_abspathname="$d/$0"
690 if test -z "$self_abspathname"; then
691 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
695 while test -h "$self_abspathname"; do
696 # Resolve symbolic link.
697 linkval=`func_readlink "$self_abspathname"`
698 test -n "$linkval" || break
700 /* ) self_abspathname="$linkval" ;;
701 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
704 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
707 trap 'rm -rf "$tmp"' 0 1 2 3 15
709 # func_lookup_file file
710 # looks up a file in $local_gnulib_dir or $gnulib_dir, or combines it through
713 # - local_gnulib_dir from --local-dir
715 # - lookedup_file name of the merged (combined) file
716 # - lookedup_tmp true if it is located in the tmp directory, blank otherwise
720 if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile"; then
721 lookedup_file="$local_gnulib_dir/$lkfile"
724 if test -f "$gnulib_dir/$lkfile"; then
725 if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile.diff"; then
726 lkbase=`echo "$lkfile" | sed -e 's,^.*/,,'`
728 cp "$gnulib_dir/$lkfile" "$tmp/$lkbase"
729 patch -s "$tmp/$lkbase" < "$local_gnulib_dir/$lkfile.diff" \
730 || func_fatal_error "patch file $local_gnulib_dir/$lkfile.diff didn't apply cleanly"
731 lookedup_file="$tmp/$lkbase"
734 lookedup_file="$gnulib_dir/$lkfile"
738 func_fatal_error "file $gnulib_dir/$lkfile not found"
745 # - local_gnulib_dir from --local-dir
748 # Filter out metainformation files like README, which are not modules.
749 # Filter out unit test modules; they can be retrieved through
750 # --extract-tests-module if desired.
752 (cd "$gnulib_dir/modules" && ls -1)
753 if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
754 (cd "$local_gnulib_dir/modules" && ls -1 | sed -e 's,\.diff$,,')
757 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^COPYING$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
758 | sed -e '/-tests$/d' \
763 # verifies a module name
765 # - local_gnulib_dir from --local-dir
766 # - module module name argument
767 func_verify_module ()
769 if { test -f "$gnulib_dir/modules/$module" \
770 || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
771 && test -f "$local_gnulib_dir/modules/$module"; }; } \
772 && test "CVS" != "$module" \
773 && test "ChangeLog" != "$module" \
774 && test "COPYING" != "$module" \
775 && test "README" != "$module" \
776 && test "TEMPLATE" != "$module" \
777 && test "TEMPLATE-TESTS" != "$module"; then
778 # OK, $module is a correct module name.
779 # Verify that building the module description with 'patch' succeeds.
780 func_lookup_file "modules/$module"
782 echo "gnulib-tool: module $module doesn't exist" 1>&2
787 # func_verify_nontests_module
788 # verifies a module name, excluding tests modules
790 # - local_gnulib_dir from --local-dir
791 # - module module name argument
792 func_verify_nontests_module ()
796 * ) func_verify_module ;;
800 # func_verify_tests_module
801 # verifies a module name, considering only tests modules
803 # - local_gnulib_dir from --local-dir
804 # - module module name argument
805 func_verify_tests_module ()
808 *-tests ) func_verify_module ;;
813 sed_extract_prog=':[ ]*$/ {
816 s/^Description:[ ]*$//
818 s/^Depends-on:[ ]*$//
819 s/^configure\.ac:[ ]*$//
820 s/^Makefile\.am:[ ]*$//
823 s/^Maintainer:[ ]*$//
830 # func_get_description module
832 # - local_gnulib_dir from --local-dir
833 func_get_description ()
835 func_lookup_file "modules/$1"
836 sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
839 # func_get_filelist module
841 # - local_gnulib_dir from --local-dir
844 func_lookup_file "modules/$1"
845 sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"
846 case "$autoconf_minversion" in
849 echo m4/onceonly_2_57.m4
854 # func_get_dependencies module
856 # - local_gnulib_dir from --local-dir
857 func_get_dependencies ()
859 # ${module}-tests always implicitly depends on ${module}.
860 echo "$1" | sed -n -e 's/-tests//p'
861 # Then the explicit dependencies listed in the module description.
862 func_lookup_file "modules/$1"
863 sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"
866 # func_get_autoconf_snippet module
868 # - local_gnulib_dir from --local-dir
869 func_get_autoconf_snippet ()
871 func_lookup_file "modules/$1"
872 sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
875 # func_get_automake_snippet module
877 # - local_gnulib_dir from --local-dir
878 func_get_automake_snippet ()
880 func_lookup_file "modules/$1"
881 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
884 # func_get_include_directive module
886 # - local_gnulib_dir from --local-dir
887 func_get_include_directive ()
889 func_lookup_file "modules/$1"
890 sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" | \
891 sed -e 's/^\(["<]\)/#include \1/'
894 # func_get_license module
896 # - local_gnulib_dir from --local-dir
899 func_lookup_file "modules/$1"
900 sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
903 # func_get_maintainer module
905 # - local_gnulib_dir from --local-dir
906 func_get_maintainer ()
908 func_lookup_file "modules/$1"
909 sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
912 # func_get_tests_module module
914 # - local_gnulib_dir from --local-dir
915 func_get_tests_module ()
917 # The naming convention for tests modules is hardwired: ${module}-tests.
918 if test -f "$gnulib_dir/modules/$1"-tests \
919 || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
920 && test -f "$local_gnulib_dir/modules/$1"-tests; }; then
925 # func_acceptable module
926 # tests whether a module is acceptable.
928 # - avoidlist list of modules to avoid
931 for avoid in $avoidlist; do
932 if test "$avoid" = "$1"; then
939 # func_modules_transitive_closure
941 # - local_gnulib_dir from --local-dir
942 # - modules list of specified modules
943 # - inctests true if tests should be included, blank otherwise
944 # - avoidlist list of modules to avoid
945 # - tmp pathname of a temporary directory
947 # - modules list of modules, including dependencies
948 func_modules_transitive_closure ()
950 # In order to process every module only once (for speed), process an "input
951 # list" of modules, producing an "output list" of modules. During each round,
952 # more modules can be queued in the input list. Once a module on the input
953 # list has been processed, it is added to the "handled list", so we can avoid
954 # to process it again.
958 while test -n "$inmodules"; do
959 inmodules_this_round="$inmodules"
960 inmodules= # Accumulator, queue for next round
961 for module in $inmodules_this_round; do
963 if test -n "$module"; then
964 if func_acceptable $module; then
965 func_append outmodules " $module"
966 deps=`func_get_dependencies $module`
967 # Duplicate dependencies are harmless, but Jim wants a warning.
968 duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
969 if test -n "$duplicated_deps"; then
970 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
972 func_append inmodules " $deps"
973 if test -n "$inctests"; then
974 testsmodule=`func_get_tests_module $module`
975 if test -n "$testsmodule"; then
976 func_append inmodules " $testsmodule"
982 handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
983 # Remove $handledmodules from $inmodules.
984 for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
985 inmodules=`echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
987 modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
988 rm -f "$tmp"/queued-modules
991 # func_modules_add_dummy
993 # - local_gnulib_dir from --local-dir
994 # - modules list of modules, including dependencies
996 # - modules list of modules, including 'dummy' if needed
997 func_modules_add_dummy ()
1000 sed_remove_backslash_newline=':a
1007 for module in $modules; do
1008 func_verify_nontests_module
1009 if test -n "$module"; then
1010 # Extract the value of "lib_SOURCES += ...".
1011 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
1012 # Ignore .h files since they are not compiled.
1015 *) have_lib_SOURCES=yes ;;
1020 # Add the dummy module, to make sure the library will be non-empty.
1021 if test -z "$have_lib_SOURCES"; then
1022 func_append modules " dummy"
1026 # func_modules_to_filelist
1028 # - local_gnulib_dir from --local-dir
1029 # - modules list of modules, including dependencies
1031 # - files list of files
1032 func_modules_to_filelist ()
1035 for module in $modules; do
1037 if test -n "$module"; then
1038 fs=`func_get_filelist $module`
1039 func_append files " $fs"
1042 files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
1045 # func_emit_lib_Makefile_am
1046 # emits the contents of library makefile to standard output.
1048 # - local_gnulib_dir from --local-dir
1049 # - modules list of modules, including dependencies
1050 # - libname library name
1051 # - makefile_name from --makefile-name
1052 # - libtool true if libtool will be used, false or blank otherwise
1053 # - actioncmd (optional) command that will reproduce this invocation
1054 func_emit_lib_Makefile_am ()
1056 # When creating an includable Makefile.am snippet, augment variables with
1057 # += instead of assigning them.
1058 if test -n "$makefile_name"; then
1063 if test "$libtool" = true; then
1066 sed_eliminate_LDFLAGS=
1070 sed_eliminate_LDFLAGS='/^lib_LDFLAGS[ ]*+=/d'
1072 echo "## Process this file with automake to produce Makefile.in."
1073 func_emit_copyright_notice
1074 if test -n "$actioncmd"; then
1075 echo "# Reproduce by: $actioncmd"
1078 if test -z "$makefile_name"; then
1079 # No need to generate dependencies since the sources are in gnulib, not here.
1080 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
1084 for module in $modules; do
1085 func_verify_nontests_module
1086 if test -n "$module"; then
1088 func_get_automake_snippet "$module" |
1089 sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1090 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
1091 sed -e "$sed_eliminate_LDFLAGS" |
1092 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
1093 sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1094 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g'
1095 if test "$module" = 'alloca'; then
1096 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
1099 # Skip the contents if its entirely empty.
1100 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
1101 echo "## begin gnulib module $module"
1104 echo "## end gnulib module $module"
1111 if grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *= *$libname\\.$libext\$" allsnippets.tmp > /dev/null; then
1112 # One of the snippets already specifies an installation location for the
1113 # library. Don't confuse automake by saying it should not be installed.
1116 # By default, the generated library should not be installed.
1117 echo "noinst_${perhapsLT}LIBRARIES $assign $libname.$libext"
1120 echo "${libname}_${libext}_SOURCES ="
1121 # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1122 # automake during its analyses looks for $(LIBOBJS), not for @LIBOBJS@.
1123 echo "${libname}_${libext}_LIBADD = \$(${perhapsLT}LIBOBJS)"
1124 if test "$libtool" = true; then
1125 echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
1127 if test -z "$makefile_name"; then
1128 echo "noinst_HEADERS ="
1129 # Automake versions < 1.9b create an empty pkgdatadir at installation time
1130 # if you specify pkgdata_DATA to empty. This is a workaround.
1131 if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1132 echo "pkgdata_DATA ="
1135 echo "BUILT_SOURCES ="
1138 echo "MOSTLYCLEANFILES $assign core *.stackdump"
1139 if test -z "$makefile_name"; then
1140 echo "MOSTLYCLEANDIRS ="
1142 echo "DISTCLEANFILES ="
1143 echo "MAINTAINERCLEANFILES ="
1145 echo "AM_CPPFLAGS ="
1150 echo "mostlyclean-local: mostlyclean-generic"
1151 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
1152 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
1153 echo " if test -d \$\$dir; then \\"
1154 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1157 rm -f allsnippets.tmp
1160 # func_emit_tests_Makefile_am
1161 # emits the contents of tests makefile to standard output.
1163 # - local_gnulib_dir from --local-dir
1164 # - modules list of modules, including dependencies
1165 # - libname library name
1166 # - makefile_name from --makefile-name
1167 # - libtool true if libtool will be used, false or blank otherwise
1168 # - sourcebase relative directory containing lib source code
1169 # - m4base relative directory containing autoconf macros
1170 # - testsbase relative directory containing unit test code
1171 func_emit_tests_Makefile_am ()
1173 if test "$libtool" = true; then
1178 if test "$libtool" = true; then
1180 sed_eliminate_LDFLAGS=
1183 sed_eliminate_LDFLAGS='/^lib_LDFLAGS[ ]*+=/d'
1185 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
1186 echo "## Process this file with automake to produce Makefile.in."
1187 func_emit_copyright_notice
1189 # Generate dependencies here, since it eases the debugging of test failures.
1190 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1192 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
1195 for module in $modules; do
1196 func_verify_tests_module
1197 if test -n "$module"; then
1199 func_get_automake_snippet "$module" |
1200 sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1201 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
1202 sed -e "$sed_eliminate_LDFLAGS" |
1203 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
1204 sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1205 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g'
1207 # Skip the contents if its entirely empty.
1208 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
1209 echo "## begin gnulib module $module"
1212 echo "## end gnulib module $module"
1219 # Nothing is being added to SUBDIRS; nevertheless the existence of this
1220 # variable is needed to avoid an error from automake:
1221 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
1224 echo "TESTS_ENVIRONMENT ="
1225 echo "noinst_PROGRAMS ="
1226 echo "check_PROGRAMS ="
1227 echo "noinst_HEADERS ="
1228 if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1229 echo "pkgdata_DATA ="
1232 echo "BUILT_SOURCES ="
1234 echo "MOSTLYCLEANFILES = core *.stackdump"
1235 echo "MOSTLYCLEANDIRS ="
1237 echo "DISTCLEANFILES ="
1238 echo "MAINTAINERCLEANFILES ="
1240 echo "AM_CPPFLAGS = \\"
1241 echo " -I. -I\$(srcdir) \\"
1242 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
1243 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
1245 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
1248 echo "# Clean up after Solaris cc."
1250 echo " rm -rf SunWS_cache"
1252 echo "mostlyclean-local: mostlyclean-generic"
1253 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
1254 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
1255 echo " if test -d \$\$dir; then \\"
1256 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1259 rm -f allsnippets.tmp
1262 # func_import modules
1263 # Uses also the variables
1264 # - destdir target directory
1265 # - local_gnulib_dir from --local-dir
1266 # - libname library name
1267 # - sourcebase directory relative to destdir where to place source code
1268 # - m4base directory relative to destdir where to place *.m4 macros
1269 # - docbase directory relative to destdir where to place doc files
1270 # - testsbase directory relative to destdir where to place unit test code
1271 # - auxdir directory relative to destdir where to place build aux files
1272 # - inctests true if --with-tests was given, blank otherwise
1273 # - avoidlist list of modules to avoid, from --avoid
1274 # - lgpl true if library's license shall be LGPL, blank otherwise
1275 # - makefile_name from --makefile-name
1276 # - libtool true if --libtool was given, false if --no-libtool was
1277 # given, blank otherwise
1278 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
1279 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
1280 # - autoconf_minversion minimum supported autoconf version
1281 # - doit : if actions shall be executed, false if only to be printed
1282 # - symbolic true if files should be symlinked, copied otherwise
1285 # Get the cached settings.
1286 cached_local_gnulib_dir=
1287 cached_specified_modules=
1295 cached_makefile_name=
1297 cached_macro_prefix=
1299 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1300 cached_libtool=false
1306 s,^.*gl_LOCAL_DIR([[ ]*\([^])]*\).*$,cached_local_gnulib_dir="\1",p
1309 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
1312 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
1315 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
1318 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
1321 s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
1324 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
1327 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
1330 s,^.*$,cached_lgpl=true,p
1332 /gl_MAKEFILE_NAME(/ {
1333 s,^.*gl_MAKEFILE_NAME([[ ]*\([^])]*\).*$,cached_makefile_name="\1",p
1336 s,^.*$,cached_libtool=true,p
1338 /gl_MACRO_PREFIX(/ {
1339 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
1341 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
1342 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1347 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
1348 s,^.*$,cached_files=",p
1360 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
1364 # Merge the cached settings with the specified ones.
1365 # The m4base must be the same as expected from the pathname.
1366 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
1367 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
1369 # The local_gnulib_dir defaults to the cached one. Recall that the cached one
1370 # is relative to $destdir, whereas the one we use is relative to . or absolute.
1371 if test -z "$local_gnulib_dir"; then
1372 if test -n "$cached_local_gnulib_dir"; then
1375 local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1377 case "$cached_local_gnulib_dir" in
1379 local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1381 func_relconcat "$destdir" "$cached_local_gnulib_dir"
1382 local_gnulib_dir="$relconcat" ;;
1387 # Append the cached and the specified module names. So that
1388 # "gnulib-tool --import foo" means to add the module foo.
1389 specified_modules="$cached_specified_modules $1"
1390 # Append the cached and the specified avoidlist. This is probably better
1391 # than dropping the cached one when --avoid is specified at least once.
1392 avoidlist=`echo $cached_avoidlist $avoidlist`
1393 # The sourcebase defaults to the cached one.
1394 if test -z "$sourcebase"; then
1395 sourcebase="$cached_sourcebase"
1396 if test -z "$sourcebase"; then
1397 func_fatal_error "missing --source-base option"
1400 # The docbase defaults to the cached one.
1401 if test -z "$docbase"; then
1402 docbase="$cached_docbase"
1403 if test -z "$docbase"; then
1404 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."
1407 # The testsbase defaults to the cached one.
1408 if test -z "$testsbase"; then
1409 testsbase="$cached_testsbase"
1410 if test -z "$testsbase"; then
1411 func_fatal_error "missing --tests-base option"
1414 # The libname defaults to the cached one.
1415 if test -z "$supplied_libname"; then
1416 libname="$cached_libname"
1417 if test -z "$libname"; then
1418 func_fatal_error "missing --lib option"
1421 # Require LGPL if specified either way.
1422 if test -z "$lgpl"; then
1425 # The makefile_name defaults to the cached one.
1426 if test -z "$makefile_name"; then
1427 makefile_name="$cached_makefile_name"
1429 # Use libtool if specified either way, or if guessed.
1430 if test -z "$libtool"; then
1431 if test -n "$cached_m4base"; then
1432 libtool="$cached_libtool"
1434 libtool="$guessed_libtool"
1437 # The macro_prefix defaults to the cached one.
1438 if test -z "$macro_prefix"; then
1439 macro_prefix="$cached_macro_prefix"
1440 if test -z "$macro_prefix"; then
1441 func_fatal_error "missing --macro-prefix option"
1445 # Canonicalize the list of specified modules.
1446 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
1448 # Determine final module list.
1449 modules="$specified_modules"
1450 func_modules_transitive_closure
1451 echo "Module list with included dependencies:"
1452 echo "$modules" | sed -e 's/^/ /'
1454 # Add the dummy module if needed.
1455 func_modules_add_dummy
1457 # If --lgpl, verify that the licenses of modules are compatible.
1458 if test -n "$lgpl"; then
1459 for module in $modules; do
1460 license=`func_get_license $module`
1462 LGPL | 'GPLed build tool') ;;
1463 'public domain' | 'unlimited' | 'unmodifiable license text') ;;
1464 *) func_fatal_error "incompatible license on module $module: $license" ;;
1469 # Determine script to apply to imported library files.
1470 sed_transform_lib_file=
1471 for module in $modules; do
1472 if test $module = config-h; then
1473 # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
1474 sed_transform_lib_file=$sed_transform_lib_file'
1475 s/^#ifdef[ ]*HAVE_CONFIG_H[ ]*$/#if 1/
1480 if test -n "$lgpl"; then
1482 sed_transform_lib_file=$sed_transform_lib_file'
1483 s/GNU General/GNU Lesser General/g
1484 s/version 2\([ ,]\)/version 2.1\1/g
1488 # Determine final file list.
1489 func_modules_to_filelist
1491 echo "$files" | sed -e 's/^/ /'
1494 || func_fatal_error "refusing to do nothing"
1496 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1497 new_files="$files m4/gnulib-tool.m4"
1498 old_files="$cached_files"
1499 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1500 func_append old_files " m4/gnulib-tool.m4"
1503 # Create directories.
1504 if test ! -d "$destdir/$sourcebase"; then
1506 echo "Creating directory $destdir/$sourcebase"
1507 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1509 echo "Create directory $destdir/$sourcebase"
1512 if test ! -d "$destdir/$m4base"; then
1514 echo "Creating directory $destdir/$m4base"
1515 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1517 echo "Create directory $destdir/$m4base"
1520 docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
1521 if test -n "$docfiles"; then
1522 if test ! -d "$destdir/$docbase"; then
1524 echo "Creating directory $destdir/$docbase"
1525 mkdir "$destdir/$docbase" || func_fatal_error "failed"
1527 echo "Create directory $destdir/$docbase"
1531 if test -n "$inctests"; then
1532 if test ! -d "$destdir/$testsbase"; then
1534 echo "Creating directory $destdir/$testsbase"
1535 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1537 echo "Create directory $destdir/$testsbase"
1541 if test ! -d "$destdir/$auxdir"; then
1543 echo "Creating directory $destdir/$auxdir"
1544 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1546 echo "Create directory $destdir/$auxdir"
1550 # func_dest_tmpfilename file
1551 # determines the name of a temporary file (file is relative to destdir).
1553 # - tmpfile absolute filename of the temporary file
1554 func_dest_tmpfilename ()
1557 # Put the new contents of $file in a file in the same directory (needed
1558 # to guarantee that an 'mv' to "$destdir/$file" works).
1559 tmpfile="$destdir/$1.tmp"
1561 # Put the new contents of $file in a file in a temporary directory
1562 # (because the directory of "$file" might not exist).
1563 tmpfile="$tmp"/`basename "$1"`.tmp
1567 # Copy files or make symbolic links. Remove obsolete files.
1569 sed_rewrite_old_files="\
1570 s,^build-aux/,$auxdir/,
1571 s,^doc/,$cached_docbase/,
1572 s,^lib/,$cached_sourcebase/,
1573 s,^m4/,$cached_m4base/,
1574 s,^tests/,$cached_testsbase/,"
1575 sed_rewrite_new_files="\
1576 s,^build-aux/,$auxdir/,
1578 s,^lib/,$sourcebase/,
1580 s,^tests/,$testsbase/,"
1581 # Construct a table with 2 columns: rewritten-file-name original-file-name,
1582 # representing the files according to the last gnulib-tool invocation.
1583 for f in $old_files; do echo $f; done \
1584 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
1587 # Construct a table with 2 columns: rewritten-file-name original-file-name,
1588 # representing the files after this gnulib-tool invocation.
1589 for f in $new_files; do echo $f; done \
1590 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
1593 # First the files that are in old-files, but not in new-files:
1594 sed_take_first_column='s,'"$delimiter"'.*,,'
1595 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1596 # Remove the file. Do nothing if the user already removed it.
1597 if test -f "$destdir/$g"; then
1599 echo "Removing file $g (backup in ${g}~)"
1600 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1602 echo "Remove file $g (backup in ${g}~)"
1606 # func_add_or_update handles a file that ought to be present afterwards.
1608 # - f the original file name
1609 # - g the rewritten file name
1610 # - already_present nonempty if the file already exists, empty otherwise
1611 func_add_or_update ()
1613 func_dest_tmpfilename "$g"
1614 func_lookup_file "$f"
1615 cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
1616 if test -n "$sed_transform_lib_file"; then
1619 sed -e "$sed_transform_lib_file" \
1620 < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
1624 if test -f "$destdir/$g"; then
1625 # The file already exists.
1626 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1627 : # The file has not changed.
1631 if test -n "$already_present"; then
1632 echo "Updating file $g (backup in ${g}~)"
1634 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1636 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1637 if test -n "$symbolic" && test -z "$lookedup_tmp" \
1638 && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1639 func_ln_if_changed "$lookedup_file" "$destdir/$g"
1641 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1644 if test -n "$already_present"; then
1645 echo "Update file $g (backup in ${g}~)"
1647 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1653 # Don't protest if the file should be there but isn't: it happens
1654 # frequently that developers don't put autogenerated files into CVS.
1656 echo "Copying file $g"
1657 if test -n "$symbolic" && test -z "$lookedup_tmp" \
1658 && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1659 func_ln_if_changed "$lookedup_file" "$destdir/$g"
1661 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1669 # Then the files that are in new-files, but not in old-files:
1670 sed_take_last_column='s,^.*'"$delimiter"',,'
1672 LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
1673 | sed -e "$sed_take_last_column" \
1674 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
1675 { # Rearrange file descriptors. Needed because "while ... done < ..."
1676 # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
1677 exec 5<&1 < "$tmp"/added-files
1683 # Then the files that are in new-files and in old-files:
1684 already_present=true
1685 LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
1686 | sed -e "$sed_take_last_column" \
1687 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
1688 { # Rearrange file descriptors. Needed because "while ... done < ..."
1689 # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
1690 exec 5<&1 < "$tmp"/kept-files
1697 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1698 actioncmd="gnulib-tool --import"
1699 func_append actioncmd " --dir=$destdir"
1700 if test -n "$local_gnulib_dir"; then
1701 func_append actioncmd " --local-dir=$local_gnulib_dir"
1703 func_append actioncmd " --lib=$libname"
1704 func_append actioncmd " --source-base=$sourcebase"
1705 func_append actioncmd " --m4-base=$m4base"
1706 func_append actioncmd " --doc-base=$docbase"
1707 func_append actioncmd " --aux-dir=$auxdir"
1708 for module in $avoidlist; do
1709 func_append actioncmd " --avoid=$module"
1711 if test -n "$lgpl"; then
1712 func_append actioncmd " --lgpl"
1714 if test -n "$makefile_name"; then
1715 func_append actioncmd " --makefile_name=$makefile_name"
1717 if test "$libtool" = true; then
1718 func_append actioncmd " --libtool"
1720 func_append actioncmd " --no-libtool"
1722 func_append actioncmd " --macro-prefix=$macro_prefix"
1723 func_append actioncmd " `echo $specified_modules`"
1725 # Default the makefile name to Makefile.am.
1726 if test -n "$makefile_name"; then
1727 makefile_am=$makefile_name
1729 makefile_am=Makefile.am
1732 # Create library makefile.
1733 func_dest_tmpfilename $sourcebase/$makefile_am
1734 func_emit_lib_Makefile_am > "$tmpfile"
1735 if test -f "$destdir"/$sourcebase/$makefile_am; then
1736 if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
1740 echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
1741 mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
1742 mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
1744 echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
1750 echo "Creating $sourcebase/$makefile_am"
1751 mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
1753 echo "Create $sourcebase/$makefile_am"
1758 # Create m4/gnulib-cache.m4.
1759 func_dest_tmpfilename $m4base/gnulib-cache.m4
1761 func_emit_copyright_notice
1763 echo "# This file represents the specification of how gnulib-tool is used."
1764 echo "# It acts as a cache: It is written and read by gnulib-tool."
1765 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1766 echo "# like the configure.ac and various Makefile.am files."
1769 echo "# Specification in the form of a command-line invocation:"
1772 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1773 # Store the local_gnulib_dir relative to destdir.
1774 case "$local_gnulib_dir" in
1776 relative_local_gnulib_dir="$local_gnulib_dir" ;;
1779 /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
1781 # destdir, local_gnulib_dir are both relative.
1782 func_relativize "$destdir" "$local_gnulib_dir"
1783 relative_local_gnulib_dir="$reldir" ;;
1786 echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
1787 echo "gl_MODULES(["`echo $specified_modules`"])"
1788 echo "gl_AVOID([$avoidlist])"
1789 echo "gl_SOURCE_BASE([$sourcebase])"
1790 echo "gl_M4_BASE([$m4base])"
1791 echo "gl_DOC_BASE([$docbase])"
1792 echo "gl_TESTS_BASE([$testsbase])"
1793 echo "gl_LIB([$libname])"
1794 test -z "$lgpl" || echo "gl_LGPL"
1795 echo "gl_MAKEFILE_NAME([$makefile_name])"
1796 if test "$libtool" = true; then
1799 echo "gl_MACRO_PREFIX([$macro_prefix])"
1801 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1802 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1806 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1807 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1808 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1810 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1814 echo "# gnulib-cache.m4 ends here"
1821 echo "Creating $m4base/gnulib-cache.m4"
1822 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1824 echo "Create $m4base/gnulib-cache.m4"
1830 # Create m4/gnulib-comp.m4.
1831 func_dest_tmpfilename $m4base/gnulib-comp.m4
1833 func_emit_copyright_notice
1835 echo "# This file represents the compiled summary of the specification in"
1836 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1837 echo "# to be invoked from configure.ac."
1838 echo "# In projects using CVS, this file can be treated like other built files."
1841 echo "# This macro should be invoked from $configure_ac, in the section"
1842 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1843 echo "# any checks for libraries, header files, types and library functions."
1844 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1846 echo " m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
1847 echo " m4_pattern_allow([^gl_ES$])dnl a valid locale name"
1848 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1849 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1850 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1852 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1853 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1855 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1856 echo " AC_REQUIRE([gl_LOCK_EARLY])"
1860 echo "# This macro should be invoked from $configure_ac, in the section"
1861 echo "# \"Check for header files, types and library functions\"."
1862 echo "AC_DEFUN([${macro_prefix}_INIT],"
1864 if test "$libtool" = true; then
1865 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1866 echo " gl_cond_libtool=true"
1868 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1869 echo " gl_cond_libtool=false"
1871 echo " gl_ltlibdeps="
1873 if test "$auxdir" != "build-aux"; then
1874 sed_replace_build_aux='
1876 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1877 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1880 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1882 sed_replace_build_aux=
1884 for module in $modules; do
1886 if test -n "$module"; then
1887 func_get_autoconf_snippet "$module" \
1888 | sed -e '/^$/d;' -e 's/^/ /' \
1889 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1890 -e "$sed_replace_build_aux"
1891 if test "$module" = 'alloca' && test "$libtool" = true; then
1892 echo 'changequote(,)dnl'
1893 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1894 echo 'changequote([, ])dnl'
1895 echo 'AC_SUBST([LTALLOCA])'
1899 # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
1900 # created using libtool, because libtool already handles the dependencies.
1901 if test "$libtool" != true; then
1902 libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
1903 echo " ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
1904 echo " AC_SUBST([${libname_upper}_LIBDEPS])"
1905 echo " ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
1906 echo " AC_SUBST([${libname_upper}_LTLIBDEPS])"
1910 echo "# This macro records the list of files which have been installed by"
1911 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1912 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1913 echo "$files" | sed -e 's,^, ,'
1916 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1917 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
1921 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1922 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1923 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1925 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1929 echo "# gnulib-comp.m4 ends here"
1936 echo "Creating $m4base/gnulib-comp.m4"
1937 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1939 echo "Create $m4base/gnulib-comp.m4"
1945 if test -n "$inctests"; then
1946 # Create tests makefile.
1947 func_dest_tmpfilename $testsbase/$makefile_am
1948 func_emit_tests_Makefile_am > "$tmpfile"
1949 if test -f "$destdir"/$testsbase/$makefile_am; then
1950 if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
1954 echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
1955 mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
1956 mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
1958 echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
1964 echo "Creating $testsbase/$makefile_am"
1965 mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
1967 echo "Create $testsbase/$makefile_am"
1975 echo "You may need to add #include directives for the following .h files."
1976 # First the #include <...> directives without #ifs, sorted for convenience,
1977 # then the #include "..." directives without #ifs, sorted for convenience,
1978 # then the #include directives that are surrounded by #ifs. Not sorted.
1979 for module in $modules; do
1980 include_directive=`func_get_include_directive "$module"`
1981 case "$nl$include_directive" in
1983 echo "$include_directive" 1>&5
1986 echo "$include_directive" | grep -v 'include "' 1>&6
1987 echo "$include_directive" | grep 'include "' 1>&7
1990 done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
1992 LC_ALL=C sort -u "$tmp"/include-angles
1993 LC_ALL=C sort -u "$tmp"/include-quotes
1994 cat "$tmp"/include-if
1995 ) | sed -e '/^$/d' -e 's/^/ /'
1996 rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
1999 echo "Don't forget to"
2000 if test "$makefile_am" = Makefile.am; then
2001 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2003 echo " - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
2005 if test -n "$inctests"; then
2006 if test "$makefile_am" = Makefile.am; then
2007 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2009 echo " - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
2012 if test "$makefile_am" = Makefile.am; then
2013 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
2014 sourcebase_base=`basename "$sourcebase"`
2015 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
2017 if test -n "$inctests"; then
2018 if test "$makefile_am" = Makefile.am; then
2019 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
2020 testsbase_base=`basename "$testsbase"`
2021 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
2024 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
2025 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
2026 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
2029 # func_create_testdir testdir modules
2031 # - local_gnulib_dir from --local-dir
2032 # - auxdir directory relative to destdir where to place build aux files
2033 func_create_testdir ()
2037 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
2039 # Subdirectory names.
2045 # Determine final module list.
2046 func_modules_transitive_closure
2047 echo "Module list with included dependencies:"
2048 echo "$modules" | sed -e 's/^/ /'
2050 # Add the dummy module if needed.
2051 func_modules_add_dummy
2053 # Determine final file list.
2054 func_modules_to_filelist
2056 echo "$files" | sed -e 's/^/ /'
2058 # Create directories.
2059 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
2061 build-aux) mkdir -p "$testdir/$auxdir" ;;
2062 doc) mkdir -p "$testdir/$docbase" ;;
2063 lib) mkdir -p "$testdir/$sourcebase" ;;
2064 m4) mkdir -p "$testdir/$m4base" ;;
2065 tests) mkdir -p "$testdir/$testsbase" ;;
2066 *) mkdir -p "$testdir/$d" ;;
2070 # Copy files or make symbolic links.
2072 sed_rewrite_files="\
2073 s,^build-aux/,$auxdir/,
2075 s,^lib/,$sourcebase/,
2077 s,^tests/,$testsbase/,"
2078 for f in $files; do echo $f; done \
2079 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
2082 { # Rearrange file descriptors. Needed because "while ... done < ..."
2083 # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2084 exec 5<&1 < "$tmp"/files
2086 func_lookup_file "$f"
2087 if test -n "$lookedup_tmp"; then
2088 cp -p "$lookedup_file" "$testdir/$g"
2090 ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
2091 if test -z "$symbolic"; then
2092 cp -p "$lookedup_file" "$testdir/$g"
2094 ln -s "$lookedup_file" "$testdir/$g"
2101 # Create $sourcebase/Makefile.am.
2102 mkdir -p "$testdir/$sourcebase"
2103 func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
2105 # Create $m4base/Makefile.am.
2106 mkdir -p "$testdir/$m4base"
2107 (echo "## Process this file with automake to produce Makefile.in."
2113 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
2116 ) > "$testdir/$m4base/Makefile.am"
2118 subdirs="$sourcebase $m4base"
2119 subdirs_with_configure_ac=""
2121 if test -f "$testdir"/$m4base/gettext.m4; then
2122 # Avoid stupid error message from automake:
2123 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
2124 mkdir -p "$testdir/po"
2125 (echo "## Process this file with automake to produce Makefile.in."
2126 ) > "$testdir/po/Makefile.am"
2127 func_append subdirs " po"
2130 if test -n "$inctests"; then
2131 test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
2132 # Create $testsbase/Makefile.am.
2133 func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
2134 # Create $testsbase/configure.ac.
2135 (echo "# Process this file with autoconf to produce a configure script."
2136 echo "AC_INIT([dummy], [0])"
2137 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
2138 echo "AM_INIT_AUTOMAKE"
2140 echo "AM_CONFIG_HEADER([config.h])"
2143 echo "AC_PROG_INSTALL"
2144 echo "AC_PROG_MAKE_SET"
2145 echo "AC_PROG_RANLIB"
2147 if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2148 echo "AC_GNU_SOURCE"
2151 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2152 echo "gl_USE_SYSTEM_EXTENSIONS"
2155 if grep gl_LOCK "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2156 echo "gl_LOCK_EARLY"
2159 if test "$libtool" = true; then
2160 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2161 echo "gl_cond_libtool=true"
2163 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2164 echo "gl_cond_libtool=false"
2166 echo "gl_ltlibdeps="
2168 # Wrap the set of autoconf snippets into an autoconf macro that is then
2169 # invoked. This is needed because autoconf does not support AC_REQUIRE
2171 # error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2172 # but we want the AC_REQUIRE to have its normal meaning (provide one
2173 # expansion of the required macro before the current point, and only one
2175 echo "AC_DEFUN([gl_INIT], ["
2176 if test "$auxdir" != "build-aux"; then
2177 sed_replace_build_aux='
2179 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2180 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
2183 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
2185 sed_replace_build_aux=
2187 # We don't have explicit ordering constraints between the various
2188 # autoconf snippets. It's cleanest to put those of the library before
2189 # those of the tests.
2190 for module in $modules; do
2191 func_verify_nontests_module
2192 if test -n "$module"; then
2193 func_get_autoconf_snippet "$module" \
2194 | sed -e "$sed_replace_build_aux"
2197 for module in $modules; do
2198 func_verify_tests_module
2199 if test -n "$module"; then
2200 func_get_autoconf_snippet "$module" \
2201 | sed -e "$sed_replace_build_aux"
2204 # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2205 # created using libtool, because libtool already handles the dependencies.
2206 if test "$libtool" != true; then
2207 libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
2208 echo " ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2209 echo " AC_SUBST([${libname_upper}_LIBDEPS])"
2210 echo " ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2211 echo " AC_SUBST([${libname_upper}_LTLIBDEPS])"
2216 # Usually $testsbase/config.h will be a superset of config.h. Verify this
2217 # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
2218 echo "AH_TOP([#include \"../config.h\"])"
2220 echo "AC_OUTPUT([Makefile])"
2221 ) > "$testdir/$testsbase/configure.ac"
2222 func_append subdirs " $testsbase"
2223 subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
2226 # Create Makefile.am.
2227 (echo "## Process this file with automake to produce Makefile.in."
2229 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
2231 echo "SUBDIRS = $subdirs"
2233 echo "ACLOCAL_AMFLAGS = -I $m4base"
2234 ) > "$testdir/Makefile.am"
2236 # Create configure.ac.
2237 (echo "# Process this file with autoconf to produce a configure script."
2238 echo "AC_INIT([dummy], [0])"
2239 if test "$auxdir" != "."; then
2240 echo "AC_CONFIG_AUX_DIR([$auxdir])"
2242 echo "AM_INIT_AUTOMAKE"
2244 echo "AM_CONFIG_HEADER([config.h])"
2247 echo "AC_PROG_INSTALL"
2248 echo "AC_PROG_MAKE_SET"
2250 echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2251 echo "m4_pattern_allow([^gl_ES$])dnl a valid locale name"
2253 echo "AC_PROG_RANLIB"
2255 if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2256 echo "AC_GNU_SOURCE"
2259 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2260 echo "gl_USE_SYSTEM_EXTENSIONS"
2263 if grep gl_LOCK "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2264 echo "gl_LOCK_EARLY"
2267 if test "$libtool" = true; then
2268 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2269 echo "gl_cond_libtool=true"
2271 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2272 echo "gl_cond_libtool=false"
2274 echo "gl_ltlibdeps="
2276 # Wrap the set of autoconf snippets into an autoconf macro that is then
2277 # invoked. This is needed because autoconf does not support AC_REQUIRE
2279 # error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2280 # but we want the AC_REQUIRE to have its normal meaning (provide one
2281 # expansion of the required macro before the current point, and only one
2283 echo "AC_DEFUN([gl_INIT], ["
2284 if test "$auxdir" != "build-aux"; then
2285 sed_replace_build_aux='
2287 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2288 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
2291 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
2293 sed_replace_build_aux=
2295 for module in $modules; do
2296 func_verify_nontests_module
2297 if test -n "$module"; then
2298 func_get_autoconf_snippet "$module" \
2299 | sed -e "$sed_replace_build_aux"
2302 # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2303 # created using libtool, because libtool already handles the dependencies.
2304 if test "$libtool" != true; then
2305 libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
2306 echo " ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2307 echo " AC_SUBST([${libname_upper}_LIBDEPS])"
2308 echo " ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2309 echo " AC_SUBST([${libname_upper}_LTLIBDEPS])"
2314 if test -n "$subdirs_with_configure_ac"; then
2315 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
2317 makefiles="Makefile"
2318 for d in $subdirs; do
2319 # For subdirs that have a configure.ac by their own, it's the subdir's
2320 # configure.ac which creates the subdir's Makefile.am, not this one.
2321 case " $subdirs_with_configure_ac " in
2323 *) func_append makefiles " $d/Makefile" ;;
2326 echo "AC_OUTPUT([$makefiles])"
2327 ) > "$testdir/configure.ac"
2329 # Create autogenerated files.
2331 echo "executing ${AUTORECONF} --force --install"
2332 ${AUTORECONF} --force --install
2334 if grep '^BUILT_SOURCES *+=' "$testdir/$sourcebase/Makefile.am" > /dev/null; then
2338 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
2346 # func_create_megatestdir megatestdir allmodules
2348 # - local_gnulib_dir from --local-dir
2349 # - auxdir directory relative to destdir where to place build aux files
2350 func_create_megatestdir ()
2354 if test -z "$allmodules"; then
2355 allmodules=`func_all_modules`
2359 # First, all modules one by one.
2360 for onemodule in $allmodules; do
2361 func_create_testdir "$megatestdir/$onemodule" $onemodule
2362 func_append megasubdirs "$onemodule "
2364 # Then, all modules all together.
2365 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
2366 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
2367 func_create_testdir "$megatestdir/ALL" "$allmodules"
2368 func_append megasubdirs "ALL"
2370 # Create Makefile.am.
2371 (echo "## Process this file with automake to produce Makefile.in."
2373 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
2375 echo "SUBDIRS = $megasubdirs"
2376 ) > "$megatestdir/Makefile.am"
2378 # Create configure.ac.
2379 (echo "# Process this file with autoconf to produce a configure script."
2380 echo "AC_INIT([dummy], [0])"
2381 if test "$auxdir" != "."; then
2382 echo "AC_CONFIG_AUX_DIR([$auxdir])"
2384 echo "AM_INIT_AUTOMAKE"
2386 echo "AC_PROG_MAKE_SET"
2388 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
2389 echo "AC_OUTPUT([Makefile])"
2390 ) > "$megatestdir/configure.ac"
2392 # Create autogenerated files.
2394 # Do not use "${AUTORECONF} --install", because autoreconf operates
2395 # recursively, but the subdirectories are already finished, therefore
2396 # calling autoreconf here would only waste lots of CPU time.
2397 echo "executing ${ACLOCAL}"
2399 echo "executing mkdir build-aux"
2401 echo "executing ${AUTOCONF}"
2403 echo "executing ${AUTOMAKE} --add-missing --copy"
2404 ${AUTOMAKE} --add-missing --copy
2410 func_fatal_error "no mode specified" ;;
2419 if test -z "$destdir"; then
2422 test -d "$destdir" \
2423 || func_fatal_error "destination directory does not exist: $destdir"
2425 # Prefer configure.ac to configure.in.
2426 if test -f "$destdir"/configure.ac; then
2427 configure_ac="$destdir/configure.ac"
2429 if test -f "$destdir"/configure.in; then
2430 configure_ac="$destdir/configure.in"
2432 func_fatal_error "cannot find $destdir/configure.ac"
2436 # Analyze configure.ac.
2438 guessed_libtool=false
2443 /AC_CONFIG_AUX_DIR/ {
2444 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
2446 /A[CM]_PROG_LIBTOOL/ {
2447 s,^.*$,guessed_libtool=true,p
2449 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
2451 if test -z "$auxdir"; then
2452 auxdir="$guessed_auxdir"
2455 # Determine where to apply func_import.
2456 if test -n "$m4base"; then
2457 # Apply func_import to a particular gnulib directory.
2458 # Any number of additional modules can be given.
2459 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
2460 # First use of gnulib in the given m4base.
2461 test -n "$supplied_libname" || supplied_libname=true
2462 test -n "$sourcebase" || sourcebase="lib"
2463 test -n "$docbase" || docbase="doc"
2464 test -n "$testsbase" || testsbase="tests"
2465 test -n "$macro_prefix" || macro_prefix="gl"
2469 # Apply func_import to all gnulib directories.
2470 # To get this list of directories, look at Makefile.am. (Not at
2471 # configure, because it may be omitted from CVS. Also, don't run
2472 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
2475 if test -f "$destdir"/Makefile.am; then
2476 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
2478 for arg in $aclocal_amflags; do
2479 if test -n "$m4dir_is_next"; then
2480 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
2484 if test -f "$destdir/$arg"/gnulib-cache.m4; then
2485 func_append m4dirs " $arg"
2486 m4dirs_count=`expr $m4dirs_count + 1`
2491 if test "X$arg" = "X-I"; then
2499 # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
2500 if test -f "$destdir"/aclocal.m4; then
2501 sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
2502 sedexpr2='s,^[^/]*$,.,'
2503 sedexpr3='s,/[^/]*$,,'
2504 m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
2505 m4dirs_count=`echo "$m4dirs" | wc -l`
2508 if test $m4dirs_count = 0; then
2509 # First use of gnulib in a package.
2510 # Any number of additional modules can be given.
2511 test -n "$supplied_libname" || supplied_libname=true
2512 test -n "$sourcebase" || sourcebase="lib"
2514 test -n "$docbase" || docbase="doc"
2515 test -n "$testsbase" || testsbase="tests"
2516 test -n "$macro_prefix" || macro_prefix="gl"
2519 if test $m4dirs_count = 1; then
2520 # There's only one use of gnulib here. Assume the user means it.
2521 # Any number of additional modules can be given.
2522 for m4base in $m4dirs; do
2526 # Ambiguous - guess what the user meant.
2527 if test $# = 0; then
2528 # No further arguments. Guess the user wants to update all of them.
2529 for m4base in $m4dirs; do
2530 # Perform func_import in a subshell, so that variable values
2532 # local_gnulib_dir, avoidlist, sourcebase, m4base, docbase,
2533 # testsbase, libname, lgpl, makefile_name, libtool, macro_prefix
2534 # don't propagate from one directory to another.
2535 (func_import) || exit 1
2539 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
2547 if test -z "$destdir"; then
2548 func_fatal_error "please specify --dir option"
2551 test -d "$destdir" \
2552 || func_fatal_error "could not create destination directory"
2553 test -n "$auxdir" || auxdir="build-aux"
2554 func_create_testdir "$destdir" "$*"
2557 create-megatestdir )
2558 if test -z "$destdir"; then
2559 func_fatal_error "please specify --dir option"
2561 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2562 test -n "$auxdir" || auxdir="build-aux"
2563 func_create_megatestdir "$destdir" "$*"
2567 test -n "$destdir" || destdir=testdir$$
2568 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2569 test -n "$auxdir" || auxdir="build-aux"
2570 func_create_testdir "$destdir" "$*"
2578 remaining=`find . -type f -print`
2579 if test -n "$remaining"; then
2580 echo "Remaining files:" $remaining 1>&2
2581 echo "gnulib-tool: *** Stop." 1>&2
2590 test -n "$destdir" || destdir=testdir$$
2591 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2592 test -n "$auxdir" || auxdir="build-aux"
2593 func_create_megatestdir "$destdir" "$*"
2601 remaining=`find . -type f -print`
2602 if test -n "$remaining"; then
2603 echo "Remaining files:" $remaining 1>&2
2604 echo "gnulib-tool: *** Stop." 1>&2
2612 extract-description )
2616 if test -n "$module"; then
2617 func_get_description "$module"
2626 if test -n "$module"; then
2627 func_get_filelist "$module"
2632 extract-dependencies )
2636 if test -n "$module"; then
2637 func_get_dependencies "$module"
2642 extract-autoconf-snippet )
2646 if test -n "$module"; then
2647 func_get_autoconf_snippet "$module"
2652 extract-automake-snippet )
2656 if test -n "$module"; then
2657 func_get_automake_snippet "$module"
2662 extract-include-directive )
2666 if test -n "$module"; then
2667 func_get_include_directive "$module"
2676 if test -n "$module"; then
2677 func_get_license "$module"
2682 extract-maintainer )
2686 if test -n "$module"; then
2687 func_get_maintainer "$module"
2692 extract-tests-module )
2696 if test -n "$module"; then
2697 func_get_tests_module "$module"
2703 func_fatal_error "unknown operation mode --$mode" ;;
2707 # Undo the effect of the previous 'trap' command. Some shellology:
2708 # We cannot use "trap - 0 1 2 3 15", because Solaris sh would attempt to
2709 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
2710 # exit); for the others we need to call 'exit' explicitly. The value of $? is
2711 # 128 + signal number and is set before the trap-registered command is run.
2713 trap 'exit $?' 1 2 3 15
2718 # indent-tabs-mode: nil
2719 # whitespace-check-buffer-indent: nil