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-25 21:20:54 $'
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,/.*$,,'`
161 $progname (GNU $package) $version
162 Copyright (C) $year Free Software Foundation, Inc.
163 This is free software; see the source for copying conditions. There is NO
164 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
165 Written by" "Bruno Haible" "and" "Simon Josefsson"
168 # func_emit_copyright_notice
169 # outputs to stdout a header for a generated file.
170 func_emit_copyright_notice ()
172 echo "# Copyright (C) 2004-2006 Free Software Foundation, Inc."
174 echo "# This file is free software, distributed under the terms of the GNU"
175 echo "# General Public License. As a special exception to the GNU General"
176 echo "# Public License, this file may be distributed as part of a program"
177 echo "# that contains a configuration script generated by Autoconf, under"
178 echo "# the same distribution terms as the rest of that program."
180 echo "# Generated by gnulib-tool."
191 # creates a temporary directory.
193 # - tmp pathname of freshly created temporary directory
196 # Use the environment variable TMPDIR, falling back to /tmp. This allows
197 # users to specify a different temporary directory, for example, if their
198 # /tmp is filled up or too small.
201 # Use the mktemp program if available. If not available, hide the error
203 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
204 test -n "$tmp" && test -d "$tmp"
207 # Use a simple mkdir command. It is guaranteed to fail if the directory
208 # already exists. $RANDOM is bash specific and expands to empty in shells
209 # other than bash, ksh and zsh. Its use does not increase security;
210 # rather, it minimizes the probability of failure in a very cluttered /tmp
212 tmp=$TMPDIR/gl$$-$RANDOM
213 (umask 077 && mkdir "$tmp")
216 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
221 # func_append var value
222 # appends the given value to the shell variable var.
223 if ( foo=bar; foo+=baz && test "$foo" = barbaz ) >/dev/null 2>&1; then
224 # Use bash's += operator. It reduces complexity of appending repeatedly to
225 # a single variable from O(n^2) to O(n).
233 eval "$1=\"\$$1\$2\""
237 # func_fatal_error message
238 # outputs to stderr a fatal error message, and terminates the program.
241 echo "gnulib-tool: *** $1" 1>&2
242 echo "gnulib-tool: *** Stop." 1>&2
246 # func_readlink SYMLINK
247 # outputs the target of the given symlink.
248 if (type -p readlink) > /dev/null 2>&1; then
251 # Use the readlink program from GNU coreutils.
257 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
258 # would do the wrong thing if the link target contains " -> ".
259 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
263 # func_ln_if_changed SRC DEST
264 # Like ln -s, but avoids munging timestamps if the link is correct.
265 func_ln_if_changed ()
267 if test $# -ne 2; then
268 echo "usage: func_ln_if_changed SRC DEST" >&2
270 if test -L "$2" && test "$1" = "`func_readlink "$2"`"; then
278 # func_relativize DIR1 DIR2
279 # computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
281 # - DIR1 relative pathname, relative to the current directory
282 # - DIR2 relative pathname, relative to the current directory
284 # - reldir relative pathname of DIR2, relative to DIR1
290 sed_first='s,^\([^/]*\)/.*$,\1,'
291 sed_rest='s,^[^/]*/*,,'
292 sed_last='s,^.*/\([^/]*\)$,\1,'
293 sed_butlast='s,/*[^/]*$,,'
294 while test -n "$dir1"; do
295 first=`echo "$dir1" | sed -e "$sed_first"`
296 if test "$first" != "."; then
297 if test "$first" = ".."; then
298 dir2=`echo "$dir0" | sed -e "$sed_last"`/"$dir2"
299 dir0=`echo "$dir0" | sed -e "$sed_butlast"`
301 first2=`echo "$dir2" | sed -e "$sed_first"`
302 if test "$first2" = "$first"; then
303 dir2=`echo "$dir2" | sed -e "$sed_rest"`
307 dir0="$dir0"/"$first"
310 dir1=`echo "$dir1" | sed -e "$sed_rest"`
315 # func_relconcat DIR1 DIR2
316 # computes a relative pathname DIR1/DIR2, with obvious simplifications.
318 # - DIR1 relative pathname, relative to the current directory
319 # - DIR2 relative pathname, relative to DIR1
321 # - relconcat DIR1/DIR2, relative to the current directory
326 sed_first='s,^\([^/]*\)/.*$,\1,'
327 sed_rest='s,^[^/]*/*,,'
328 sed_last='s,^.*/\([^/]*\)$,\1,'
329 sed_butlast='s,/*[^/]*$,,'
331 first=`echo "$dir2" | sed -e "$sed_first"`
332 if test "$first" = "."; then
333 dir2=`echo "$dir2" | sed -e "$sed_rest"`
334 if test -z "$dir2"; then
339 last=`echo "$dir1" | sed -e "$sed_last"`
340 while test "$last" = "."; do
341 dir1=`echo "$dir1" | sed -e "$sed_butlast"`
342 last=`echo "$dir1" | sed -e "$sed_last"`
344 if test -z "$dir1"; then
348 if test "$first" = ".."; then
349 if test "$last" = ".."; then
350 relconcat="$dir1/$dir2"
353 dir1=`echo "$dir1" | sed -e "$sed_butlast"`
354 dir2=`echo "$dir2" | sed -e "$sed_rest"`
355 if test -z "$dir1"; then
359 if test -z "$dir2"; then
364 relconcat="$dir1/$dir2"
371 # Command-line option processing.
372 # Removes the OPTIONS from the arguments. Sets the variables:
373 # - mode list or import or create-testdir or create-megatestdir
374 # - destdir from --dir
375 # - local_gnulib_dir from --local-dir
376 # - libname, supplied_libname from --lib
377 # - sourcebase from --source-base
378 # - m4base from --m4-base
379 # - docbase from --doc-base
380 # - testsbase from --tests-base
381 # - auxdir from --aux-dir
382 # - inctests true if --with-tests was given, blank otherwise
383 # - avoidlist list of modules to avoid, from --avoid
384 # - lgpl true if --lgpl was given, blank otherwise
385 # - makefile_name from --makefile-name
386 # - libtool true if --libtool was given, false if --no-libtool was
387 # given, blank otherwise
388 # - macro_prefix from --macro-prefix
389 # - autoconf_minversion minimum supported autoconf version
390 # - do_changelog false if --no-changelog was given, : otherwise
391 # - doit : if actions shall be executed, false if only to be printed
392 # - symbolic true if --symbolic was given, blank otherwise
416 while test $# -gt 0; do
421 --import | --impor | --impo | --imp | --im | --i )
424 --update | --updat | --upda | --upd | --up | --u )
427 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
430 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
431 mode=create-megatestdir
433 --test | --tes | --te | --t )
436 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
440 mode=`echo "X$1" | sed -e 's/^X--//'`
445 func_fatal_error "missing argument for --dir"
450 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
455 func_fatal_error "missing argument for --local-dir"
460 local_gnulib_dir=`echo "X$1" | sed -e 's/^X--local-dir=//'`
465 func_fatal_error "missing argument for --lib"
468 supplied_libname=true
471 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
472 supplied_libname=true
477 func_fatal_error "missing argument for --source-base"
482 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
487 func_fatal_error "missing argument for --m4-base"
492 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
497 func_fatal_error "missing argument for --doc-base"
502 docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
507 func_fatal_error "missing argument for --tests-base"
512 testsbase=`echo "X$1" | sed -e 's/^X--tests-base=//'`
517 func_fatal_error "missing argument for --aux-dir"
522 auxdir=`echo "X$1" | sed -e 's/^X--aux-dir=//'`
530 func_fatal_error "missing argument for --avoid"
532 func_append avoidlist " $1"
535 arg=`echo "X$1" | sed -e 's/^X--avoid=//'`
536 func_append avoidlist " $arg"
544 func_fatal_error "missing argument for --makefile-name"
549 makefile_name=`echo "X$1" | sed -e 's/^X--makefile-name=//'`
560 func_fatal_error "missing argument for --macro-prefix"
565 macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
567 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
573 -s | --symbolic | --symboli | --symbol | --symbo | --symb | --symlink | --symlin | --symli | --syml | --sym | --sy )
576 --help | --hel | --he | --h )
579 --version | --versio | --versi | --vers | --ver | --ve | --v )
583 # Stop option processing
587 echo "gnulib-tool: unknown option $1" 1>&2
588 echo "Try 'gnulib-tool --help' for more information." 1>&2
595 if test "$mode" = update; then
596 if test $# != 0; then
597 echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
598 echo "Try 'gnulib-tool --help' for more information." 1>&2
599 echo "If you really want to modify the gnulib configuration of your project," 1>&2
600 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
603 if test -n "$local_gnulib_dir" || test -n "$supplied_libname" \
604 || test -n "$sourcebase" || test -n "$m4base" \
605 || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
606 || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
607 || test -n "$makefile_name" || test -n "$macro_prefix"; then
608 echo "gnulib-tool: invalid options for 'update' mode" 1>&2
609 echo "Try 'gnulib-tool --help' for more information." 1>&2
610 echo "If you really want to modify the gnulib configuration of your project," 1>&2
611 echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
617 # Determine the minimum supported autoconf version from the project's
619 DEFAULT_AUTOCONF_MINVERSION="2.59"
622 if { test "$mode" = import || test "$mode" = update; } && test -n "$destdir"; then
623 if test -f "$destdir"/configure.ac; then
624 configure_ac="$destdir/configure.ac"
626 if test -f "$destdir"/configure.in; then
627 configure_ac="$destdir/configure.in"
631 if test -f configure.ac; then
632 configure_ac="configure.ac"
634 if test -f configure.in; then
635 configure_ac="configure.in"
639 if test -n "$configure_ac"; then
640 # Use sed, not autoconf --trace, to look for the AC_PREREQ invocation,
641 # because when some m4 files are omitted from a CVS repository,
642 # "autoconf --trace=AC_PREREQ" fails with an error message like this:
643 # m4: aclocal.m4:851: Cannot open m4/absolute-header.m4: No such file or directory
644 # autom4te: m4 failed with exit status: 1
651 s,^.*AC_PREREQ([[ ]*\([^])]*\).*$,prereqs="$prereqs \1",p
653 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
654 if test -n "$prereqs"; then
655 autoconf_minversion=`for version in $prereqs; do echo $version; done | $SORT -g -u | tail -1`
658 if test -z "$autoconf_minversion"; then
659 autoconf_minversion=$DEFAULT_AUTOCONF_MINVERSION
661 case "$autoconf_minversion" in
662 1.* | 2.[0-4]* | 2.5[0-8]*)
663 func_fatal_error "minimum supported autoconf version is 2.59. Try adding AC_PREREQ([$DEFAULT_AUTOCONF_MINVERSION]) to your configure.ac." ;;
666 # Remove trailing slashes from the directory names. This is necessary for
667 # m4base (to avoid an error in func_import) and optional for the others.
668 sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
669 case "$local_gnulib_dir" in
670 */ ) sourcebase=`echo "$local_gnulib_dir" | sed -e "$sed_trimtrailingslashes"` ;;
672 case "$sourcebase" in
673 */ ) sourcebase=`echo "$sourcebase" | sed -e "$sed_trimtrailingslashes"` ;;
676 */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
679 */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
682 */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
685 */ ) auxdir=`echo "$auxdir" | sed -e "$sed_trimtrailingslashes"` ;;
690 /*) self_abspathname="$0" ;;
691 */*) self_abspathname=`pwd`/"$0" ;;
692 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
693 if test -x "$d/$0" && test ! -d "$d/$0"; then
694 self_abspathname="$d/$0"
698 if test -z "$self_abspathname"; then
699 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
703 while test -h "$self_abspathname"; do
704 # Resolve symbolic link.
705 linkval=`func_readlink "$self_abspathname"`
706 test -n "$linkval" || break
708 /* ) self_abspathname="$linkval" ;;
709 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
712 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
716 if test "$signal" != 0; then
717 echo "caught signal $signal" >&2
721 for signal in 1 2 3 13 15; do
722 trap '{ signal='$signal'; func_exit 1; }' $signal
726 # func_lookup_file file
727 # looks up a file in $local_gnulib_dir or $gnulib_dir, or combines it through
730 # - local_gnulib_dir from --local-dir
732 # - lookedup_file name of the merged (combined) file
733 # - lookedup_tmp true if it is located in the tmp directory, blank otherwise
737 if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile"; then
738 lookedup_file="$local_gnulib_dir/$lkfile"
741 if test -f "$gnulib_dir/$lkfile"; then
742 if test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$lkfile.diff"; then
743 lkbase=`echo "$lkfile" | sed -e 's,^.*/,,'`
745 cp "$gnulib_dir/$lkfile" "$tmp/$lkbase"
746 patch -s "$tmp/$lkbase" < "$local_gnulib_dir/$lkfile.diff" \
747 || func_fatal_error "patch file $local_gnulib_dir/$lkfile.diff didn't apply cleanly"
748 lookedup_file="$tmp/$lkbase"
751 lookedup_file="$gnulib_dir/$lkfile"
755 func_fatal_error "file $gnulib_dir/$lkfile not found"
762 # - local_gnulib_dir from --local-dir
765 # Filter out metainformation files like README, which are not modules.
766 # Filter out unit test modules; they can be retrieved through
767 # --extract-tests-module if desired.
769 (cd "$gnulib_dir/modules" && ls -1)
770 if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then
771 (cd "$local_gnulib_dir/modules" && ls -1 | sed -e 's,\.diff$,,')
774 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^COPYING$/d' -e '/^README$/d' -e '/^TEMPLATE$/d' -e '/^TEMPLATE-TESTS$/d' -e '/~$/d' \
775 | sed -e '/-tests$/d' \
780 # verifies a module name
782 # - local_gnulib_dir from --local-dir
783 # - module module name argument
784 func_verify_module ()
786 if { test -f "$gnulib_dir/modules/$module" \
787 || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
788 && test -f "$local_gnulib_dir/modules/$module"; }; } \
789 && test "CVS" != "$module" \
790 && test "ChangeLog" != "$module" \
791 && test "COPYING" != "$module" \
792 && test "README" != "$module" \
793 && test "TEMPLATE" != "$module" \
794 && test "TEMPLATE-TESTS" != "$module"; then
795 # OK, $module is a correct module name.
796 # Verify that building the module description with 'patch' succeeds.
797 func_lookup_file "modules/$module"
799 echo "gnulib-tool: module $module doesn't exist" 1>&2
804 # func_verify_nontests_module
805 # verifies a module name, excluding tests modules
807 # - local_gnulib_dir from --local-dir
808 # - module module name argument
809 func_verify_nontests_module ()
813 * ) func_verify_module ;;
817 # func_verify_tests_module
818 # verifies a module name, considering only tests modules
820 # - local_gnulib_dir from --local-dir
821 # - module module name argument
822 func_verify_tests_module ()
825 *-tests ) func_verify_module ;;
830 sed_extract_prog=':[ ]*$/ {
833 s/^Description:[ ]*$//
835 s/^Depends-on:[ ]*$//
836 s/^configure\.ac:[ ]*$//
837 s/^Makefile\.am:[ ]*$//
840 s/^Maintainer:[ ]*$//
847 # func_get_description module
849 # - local_gnulib_dir from --local-dir
850 func_get_description ()
852 func_lookup_file "modules/$1"
853 sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
856 # func_get_filelist module
858 # - local_gnulib_dir from --local-dir
861 func_lookup_file "modules/$1"
862 sed -n -e "/^Files$sed_extract_prog" < "$lookedup_file"
863 case "$autoconf_minversion" in
866 echo m4/onceonly_2_57.m4
871 # func_get_dependencies module
873 # - local_gnulib_dir from --local-dir
874 func_get_dependencies ()
876 # ${module}-tests always implicitly depends on ${module}.
877 echo "$1" | sed -n -e 's/-tests//p'
878 # Then the explicit dependencies listed in the module description.
879 func_lookup_file "modules/$1"
880 sed -n -e "/^Depends-on$sed_extract_prog" < "$lookedup_file"
883 # func_get_autoconf_snippet module
885 # - local_gnulib_dir from --local-dir
886 func_get_autoconf_snippet ()
888 func_lookup_file "modules/$1"
889 sed -n -e "/^configure\.ac$sed_extract_prog" < "$lookedup_file"
892 # func_get_automake_snippet module
894 # - local_gnulib_dir from --local-dir
895 func_get_automake_snippet ()
897 func_lookup_file "modules/$1"
898 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$lookedup_file"
901 # func_get_include_directive module
903 # - local_gnulib_dir from --local-dir
904 func_get_include_directive ()
906 func_lookup_file "modules/$1"
907 sed -n -e "/^Include$sed_extract_prog" < "$lookedup_file" | \
908 sed -e 's/^\(["<]\)/#include \1/'
911 # func_get_license module
913 # - local_gnulib_dir from --local-dir
916 func_lookup_file "modules/$1"
917 sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
920 # func_get_maintainer module
922 # - local_gnulib_dir from --local-dir
923 func_get_maintainer ()
925 func_lookup_file "modules/$1"
926 sed -n -e "/^Maintainer$sed_extract_prog" < "$lookedup_file"
929 # func_get_tests_module module
931 # - local_gnulib_dir from --local-dir
932 func_get_tests_module ()
934 # The naming convention for tests modules is hardwired: ${module}-tests.
935 if test -f "$gnulib_dir/modules/$1"-tests \
936 || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
937 && test -f "$local_gnulib_dir/modules/$1"-tests; }; then
942 # func_acceptable module
943 # tests whether a module is acceptable.
945 # - avoidlist list of modules to avoid
948 for avoid in $avoidlist; do
949 if test "$avoid" = "$1"; then
956 # func_modules_transitive_closure
958 # - local_gnulib_dir from --local-dir
959 # - modules list of specified modules
960 # - inctests true if tests should be included, blank otherwise
961 # - avoidlist list of modules to avoid
962 # - tmp pathname of a temporary directory
964 # - modules list of modules, including dependencies
965 func_modules_transitive_closure ()
967 # In order to process every module only once (for speed), process an "input
968 # list" of modules, producing an "output list" of modules. During each round,
969 # more modules can be queued in the input list. Once a module on the input
970 # list has been processed, it is added to the "handled list", so we can avoid
971 # to process it again.
975 while test -n "$inmodules"; do
976 inmodules_this_round="$inmodules"
977 inmodules= # Accumulator, queue for next round
978 for module in $inmodules_this_round; do
980 if test -n "$module"; then
981 if func_acceptable $module; then
982 func_append outmodules " $module"
983 deps=`func_get_dependencies $module`
984 # Duplicate dependencies are harmless, but Jim wants a warning.
985 duplicated_deps=`echo "$deps" | LC_ALL=C sort | LC_ALL=C uniq -d`
986 if test -n "$duplicated_deps"; then
987 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
989 func_append inmodules " $deps"
990 if test -n "$inctests"; then
991 testsmodule=`func_get_tests_module $module`
992 if test -n "$testsmodule"; then
993 func_append inmodules " $testsmodule"
999 handledmodules=`for m in $handledmodules $inmodules_this_round; do echo $m; done | LC_ALL=C sort -u`
1000 # Remove $handledmodules from $inmodules.
1001 for m in $inmodules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/queued-modules
1002 inmodules=`echo "$handledmodules" | LC_ALL=C join -v 2 - "$tmp"/queued-modules`
1004 modules=`for m in $outmodules; do echo $m; done | LC_ALL=C sort -u`
1005 rm -f "$tmp"/queued-modules
1008 # func_modules_add_dummy
1010 # - local_gnulib_dir from --local-dir
1011 # - modules list of modules, including dependencies
1013 # - modules list of modules, including 'dummy' if needed
1014 func_modules_add_dummy ()
1017 sed_remove_backslash_newline=':a
1024 for module in $modules; do
1025 func_verify_nontests_module
1026 if test -n "$module"; then
1027 # Extract the value of "lib_SOURCES += ...".
1028 for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[ ]*+=\([^#]*\).*$,\1,p'`; do
1029 # Ignore .h files since they are not compiled.
1032 *) have_lib_SOURCES=yes ;;
1037 # Add the dummy module, to make sure the library will be non-empty.
1038 if test -z "$have_lib_SOURCES"; then
1039 func_append modules " dummy"
1043 # func_modules_to_filelist
1045 # - local_gnulib_dir from --local-dir
1046 # - modules list of modules, including dependencies
1048 # - files list of files
1049 func_modules_to_filelist ()
1052 for module in $modules; do
1054 if test -n "$module"; then
1055 fs=`func_get_filelist $module`
1056 func_append files " $fs"
1059 files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
1062 # func_emit_lib_Makefile_am
1063 # emits the contents of library makefile to standard output.
1065 # - local_gnulib_dir from --local-dir
1066 # - modules list of modules, including dependencies
1067 # - libname library name
1068 # - makefile_name from --makefile-name
1069 # - libtool true if libtool will be used, false or blank otherwise
1070 # - actioncmd (optional) command that will reproduce this invocation
1071 func_emit_lib_Makefile_am ()
1073 # When creating an includable Makefile.am snippet, augment variables with
1074 # += instead of assigning them.
1075 if test -n "$makefile_name"; then
1080 if test "$libtool" = true; then
1083 sed_eliminate_LDFLAGS=
1087 sed_eliminate_LDFLAGS='/^lib_LDFLAGS[ ]*+=/d'
1089 echo "## Process this file with automake to produce Makefile.in."
1090 func_emit_copyright_notice
1091 if test -n "$actioncmd"; then
1092 echo "# Reproduce by: $actioncmd"
1095 if test -z "$makefile_name"; then
1096 # No need to generate dependencies since the sources are in gnulib, not here.
1097 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
1101 for module in $modules; do
1102 func_verify_nontests_module
1103 if test -n "$module"; then
1105 func_get_automake_snippet "$module" |
1106 sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1107 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
1108 sed -e "$sed_eliminate_LDFLAGS" |
1109 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
1110 sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1111 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g'
1112 if test "$module" = 'alloca'; then
1113 echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
1116 # Skip the contents if its entirely empty.
1117 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
1118 echo "## begin gnulib module $module"
1121 echo "## end gnulib module $module"
1128 if grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *= *$libname\\.$libext\$" allsnippets.tmp > /dev/null; then
1129 # One of the snippets already specifies an installation location for the
1130 # library. Don't confuse automake by saying it should not be installed.
1133 # By default, the generated library should not be installed.
1134 echo "noinst_${perhapsLT}LIBRARIES $assign $libname.$libext"
1137 echo "${libname}_${libext}_SOURCES ="
1138 # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1139 # automake during its analyses looks for $(LIBOBJS), not for @LIBOBJS@.
1140 echo "${libname}_${libext}_LIBADD = \$(${perhapsLT}LIBOBJS)"
1141 if test "$libtool" = true; then
1142 echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
1144 if test -z "$makefile_name"; then
1145 echo "noinst_HEADERS ="
1146 # Automake versions < 1.9b create an empty pkgdatadir at installation time
1147 # if you specify pkgdata_DATA to empty. This is a workaround.
1148 if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1149 echo "pkgdata_DATA ="
1152 echo "BUILT_SOURCES ="
1155 echo "MOSTLYCLEANFILES $assign core *.stackdump"
1156 if test -z "$makefile_name"; then
1157 echo "MOSTLYCLEANDIRS ="
1159 echo "DISTCLEANFILES ="
1160 echo "MAINTAINERCLEANFILES ="
1162 echo "AM_CPPFLAGS ="
1167 echo "mostlyclean-local: mostlyclean-generic"
1168 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
1169 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
1170 echo " if test -d \$\$dir; then \\"
1171 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1174 rm -f allsnippets.tmp
1177 # func_emit_tests_Makefile_am
1178 # emits the contents of tests makefile to standard output.
1180 # - local_gnulib_dir from --local-dir
1181 # - modules list of modules, including dependencies
1182 # - libname library name
1183 # - makefile_name from --makefile-name
1184 # - libtool true if libtool will be used, false or blank otherwise
1185 # - sourcebase relative directory containing lib source code
1186 # - m4base relative directory containing autoconf macros
1187 # - testsbase relative directory containing unit test code
1188 func_emit_tests_Makefile_am ()
1190 if test "$libtool" = true; then
1195 if test "$libtool" = true; then
1197 sed_eliminate_LDFLAGS=
1200 sed_eliminate_LDFLAGS='/^lib_LDFLAGS[ ]*+=/d'
1202 testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
1203 echo "## Process this file with automake to produce Makefile.in."
1204 func_emit_copyright_notice
1206 # Generate dependencies here, since it eases the debugging of test failures.
1207 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
1209 echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
1212 for module in $modules; do
1213 func_verify_tests_module
1214 if test -n "$module"; then
1216 func_get_automake_snippet "$module" |
1217 sed -e 's,lib_LIBRARIES,lib%_LIBRARIES,g' \
1218 -e 's,lib_LTLIBRARIES,lib%_LTLIBRARIES,g' |
1219 sed -e "$sed_eliminate_LDFLAGS" |
1220 sed -e 's,lib_\([A-Z][A-Z]*\),'"${libname}_${libext}"'_\1,g' |
1221 sed -e 's,lib%_LIBRARIES,lib_LIBRARIES,g' \
1222 -e 's,lib%_LTLIBRARIES,lib_LTLIBRARIES,g'
1224 # Skip the contents if its entirely empty.
1225 if grep '[^ ]' amsnippet.tmp > /dev/null ; then
1226 echo "## begin gnulib module $module"
1229 echo "## end gnulib module $module"
1236 # Nothing is being added to SUBDIRS; nevertheless the existence of this
1237 # variable is needed to avoid an error from automake:
1238 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
1241 echo "TESTS_ENVIRONMENT ="
1242 echo "noinst_PROGRAMS ="
1243 echo "check_PROGRAMS ="
1244 echo "noinst_HEADERS ="
1245 if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
1246 echo "pkgdata_DATA ="
1249 echo "BUILT_SOURCES ="
1251 echo "MOSTLYCLEANFILES = core *.stackdump"
1252 echo "MOSTLYCLEANDIRS ="
1254 echo "DISTCLEANFILES ="
1255 echo "MAINTAINERCLEANFILES ="
1257 echo "AM_CPPFLAGS = \\"
1258 echo " -I. -I\$(srcdir) \\"
1259 echo " -I${testsbase_inverse} -I\$(srcdir)/${testsbase_inverse} \\"
1260 echo " -I${testsbase_inverse}/${sourcebase-lib} -I\$(srcdir)/${testsbase_inverse}/${sourcebase-lib}"
1262 echo "LDADD = ${testsbase_inverse}/${sourcebase-lib}/${libname}.${libext}"
1265 echo "# Clean up after Solaris cc."
1267 echo " rm -rf SunWS_cache"
1269 echo "mostlyclean-local: mostlyclean-generic"
1270 echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
1271 echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
1272 echo " if test -d \$\$dir; then \\"
1273 echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
1276 rm -f allsnippets.tmp
1279 # func_import modules
1280 # Uses also the variables
1281 # - destdir target directory
1282 # - local_gnulib_dir from --local-dir
1283 # - libname library name
1284 # - sourcebase directory relative to destdir where to place source code
1285 # - m4base directory relative to destdir where to place *.m4 macros
1286 # - docbase directory relative to destdir where to place doc files
1287 # - testsbase directory relative to destdir where to place unit test code
1288 # - auxdir directory relative to destdir where to place build aux files
1289 # - inctests true if --with-tests was given, blank otherwise
1290 # - avoidlist list of modules to avoid, from --avoid
1291 # - lgpl true if library's license shall be LGPL, blank otherwise
1292 # - makefile_name from --makefile-name
1293 # - libtool true if --libtool was given, false if --no-libtool was
1294 # given, blank otherwise
1295 # - guessed_libtool true if the configure.ac file uses libtool, false otherwise
1296 # - macro_prefix prefix of gl_EARLY, gl_INIT macros to use
1297 # - autoconf_minversion minimum supported autoconf version
1298 # - doit : if actions shall be executed, false if only to be printed
1299 # - symbolic true if files should be symlinked, copied otherwise
1302 # Get the cached settings.
1303 cached_local_gnulib_dir=
1304 cached_specified_modules=
1312 cached_makefile_name=
1314 cached_macro_prefix=
1316 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1317 cached_libtool=false
1323 s,^.*gl_LOCAL_DIR([[ ]*\([^])]*\).*$,cached_local_gnulib_dir="\1",p
1326 s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
1329 s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
1332 s,^.*gl_SOURCE_BASE([[ ]*\([^])]*\).*$,cached_sourcebase="\1",p
1335 s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
1338 s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
1341 s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
1344 s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
1347 s,^.*$,cached_lgpl=true,p
1349 /gl_MAKEFILE_NAME(/ {
1350 s,^.*gl_MAKEFILE_NAME([[ ]*\([^])]*\).*$,cached_makefile_name="\1",p
1353 s,^.*$,cached_libtool=true,p
1355 /gl_MACRO_PREFIX(/ {
1356 s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
1358 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
1359 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1364 /AC_DEFUN(\['"${cached_macro_prefix}"'_FILE_LIST\], \[/ {
1365 s,^.*$,cached_files=",p
1377 eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-comp.m4`
1381 # Merge the cached settings with the specified ones.
1382 # The m4base must be the same as expected from the pathname.
1383 if test -n "$cached_m4base" && test "$cached_m4base" != "$m4base"; then
1384 func_fatal_error "$m4base/gnulib-cache.m4 is expected to contain gl_M4_BASE([$m4base])"
1386 # The local_gnulib_dir defaults to the cached one. Recall that the cached one
1387 # is relative to $destdir, whereas the one we use is relative to . or absolute.
1388 if test -z "$local_gnulib_dir"; then
1389 if test -n "$cached_local_gnulib_dir"; then
1392 local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1394 case "$cached_local_gnulib_dir" in
1396 local_gnulib_dir="$destdir/$cached_local_gnulib_dir" ;;
1398 func_relconcat "$destdir" "$cached_local_gnulib_dir"
1399 local_gnulib_dir="$relconcat" ;;
1404 # Append the cached and the specified module names. So that
1405 # "gnulib-tool --import foo" means to add the module foo.
1406 specified_modules="$cached_specified_modules $1"
1407 # Append the cached and the specified avoidlist. This is probably better
1408 # than dropping the cached one when --avoid is specified at least once.
1409 avoidlist=`echo $cached_avoidlist $avoidlist`
1410 # The sourcebase defaults to the cached one.
1411 if test -z "$sourcebase"; then
1412 sourcebase="$cached_sourcebase"
1413 if test -z "$sourcebase"; then
1414 func_fatal_error "missing --source-base option"
1417 # The docbase defaults to the cached one.
1418 if test -z "$docbase"; then
1419 docbase="$cached_docbase"
1420 if test -z "$docbase"; then
1421 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."
1424 # The testsbase defaults to the cached one.
1425 if test -z "$testsbase"; then
1426 testsbase="$cached_testsbase"
1427 if test -z "$testsbase"; then
1428 func_fatal_error "missing --tests-base option"
1431 # The libname defaults to the cached one.
1432 if test -z "$supplied_libname"; then
1433 libname="$cached_libname"
1434 if test -z "$libname"; then
1435 func_fatal_error "missing --lib option"
1438 # Require LGPL if specified either way.
1439 if test -z "$lgpl"; then
1442 # The makefile_name defaults to the cached one.
1443 if test -z "$makefile_name"; then
1444 makefile_name="$cached_makefile_name"
1446 # Use libtool if specified either way, or if guessed.
1447 if test -z "$libtool"; then
1448 if test -n "$cached_m4base"; then
1449 libtool="$cached_libtool"
1451 libtool="$guessed_libtool"
1454 # The macro_prefix defaults to the cached one.
1455 if test -z "$macro_prefix"; then
1456 macro_prefix="$cached_macro_prefix"
1457 if test -z "$macro_prefix"; then
1458 func_fatal_error "missing --macro-prefix option"
1462 # Canonicalize the list of specified modules.
1463 specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort -u`
1465 # Determine final module list.
1466 modules="$specified_modules"
1467 func_modules_transitive_closure
1468 echo "Module list with included dependencies:"
1469 echo "$modules" | sed -e 's/^/ /'
1471 # Add the dummy module if needed.
1472 func_modules_add_dummy
1474 # If --lgpl, verify that the licenses of modules are compatible.
1475 if test -n "$lgpl"; then
1476 for module in $modules; do
1477 license=`func_get_license $module`
1479 LGPL | 'GPLed build tool') ;;
1480 'public domain' | 'unlimited' | 'unmodifiable license text') ;;
1481 *) func_fatal_error "incompatible license on module $module: $license" ;;
1486 # Determine script to apply to imported library files.
1487 sed_transform_lib_file=
1488 for module in $modules; do
1489 if test $module = config-h; then
1490 # Assume config.h exists, and that -DHAVE_CONFIG_H is omitted.
1491 sed_transform_lib_file=$sed_transform_lib_file'
1492 s/^#ifdef[ ]*HAVE_CONFIG_H[ ]*$/#if 1/
1497 if test -n "$lgpl"; then
1499 sed_transform_lib_file=$sed_transform_lib_file'
1500 s/GNU General/GNU Lesser General/g
1501 s/version 2\([ ,]\)/version 2.1\1/g
1505 # Determine final file list.
1506 func_modules_to_filelist
1508 echo "$files" | sed -e 's/^/ /'
1511 || func_fatal_error "refusing to do nothing"
1513 # Add m4/gnulib-tool.m4 to the file list. It is not part of any module.
1514 new_files="$files m4/gnulib-tool.m4"
1515 old_files="$cached_files"
1516 if test -f "$destdir"/$m4base/gnulib-tool.m4; then
1517 func_append old_files " m4/gnulib-tool.m4"
1520 # Create directories.
1521 if test ! -d "$destdir/$sourcebase"; then
1523 echo "Creating directory $destdir/$sourcebase"
1524 mkdir "$destdir/$sourcebase" || func_fatal_error "failed"
1526 echo "Create directory $destdir/$sourcebase"
1529 if test ! -d "$destdir/$m4base"; then
1531 echo "Creating directory $destdir/$m4base"
1532 mkdir "$destdir/$m4base" || func_fatal_error "failed"
1534 echo "Create directory $destdir/$m4base"
1537 docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
1538 if test -n "$docfiles"; then
1539 if test ! -d "$destdir/$docbase"; then
1541 echo "Creating directory $destdir/$docbase"
1542 mkdir "$destdir/$docbase" || func_fatal_error "failed"
1544 echo "Create directory $destdir/$docbase"
1548 if test -n "$inctests"; then
1549 if test ! -d "$destdir/$testsbase"; then
1551 echo "Creating directory $destdir/$testsbase"
1552 mkdir "$destdir/$testsbase" || func_fatal_error "failed"
1554 echo "Create directory $destdir/$testsbase"
1558 if test ! -d "$destdir/$auxdir"; then
1560 echo "Creating directory $destdir/$auxdir"
1561 mkdir "$destdir/$auxdir" || func_fatal_error "failed"
1563 echo "Create directory $destdir/$auxdir"
1567 # func_dest_tmpfilename file
1568 # determines the name of a temporary file (file is relative to destdir).
1570 # - tmpfile absolute filename of the temporary file
1571 func_dest_tmpfilename ()
1574 # Put the new contents of $file in a file in the same directory (needed
1575 # to guarantee that an 'mv' to "$destdir/$file" works).
1576 tmpfile="$destdir/$1.tmp"
1578 # Put the new contents of $file in a file in a temporary directory
1579 # (because the directory of "$file" might not exist).
1580 tmpfile="$tmp"/`basename "$1"`.tmp
1584 # Copy files or make symbolic links. Remove obsolete files.
1586 sed_rewrite_old_files="\
1587 s,^build-aux/,$auxdir/,
1588 s,^doc/,$cached_docbase/,
1589 s,^lib/,$cached_sourcebase/,
1590 s,^m4/,$cached_m4base/,
1591 s,^tests/,$cached_testsbase/,"
1592 sed_rewrite_new_files="\
1593 s,^build-aux/,$auxdir/,
1595 s,^lib/,$sourcebase/,
1597 s,^tests/,$testsbase/,"
1598 # Construct a table with 2 columns: rewritten-file-name original-file-name,
1599 # representing the files according to the last gnulib-tool invocation.
1600 for f in $old_files; do echo $f; done \
1601 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_old_files" \
1604 # Construct a table with 2 columns: rewritten-file-name original-file-name,
1605 # representing the files after this gnulib-tool invocation.
1606 for f in $new_files; do echo $f; done \
1607 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" \
1610 # First the files that are in old-files, but not in new-files:
1611 sed_take_first_column='s,'"$delimiter"'.*,,'
1612 for g in `LC_ALL=C join -t"$delimiter" -v1 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_first_column"`; do
1613 # Remove the file. Do nothing if the user already removed it.
1614 if test -f "$destdir/$g"; then
1616 echo "Removing file $g (backup in ${g}~)"
1617 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1619 echo "Remove file $g (backup in ${g}~)"
1623 # func_add_or_update handles a file that ought to be present afterwards.
1625 # - f the original file name
1626 # - g the rewritten file name
1627 # - already_present nonempty if the file already exists, empty otherwise
1628 func_add_or_update ()
1630 func_dest_tmpfilename "$g"
1631 func_lookup_file "$f"
1632 cp "$lookedup_file" "$tmpfile" || func_fatal_error "failed"
1633 if test -n "$sed_transform_lib_file"; then
1636 sed -e "$sed_transform_lib_file" \
1637 < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
1641 if test -f "$destdir/$g"; then
1642 # The file already exists.
1643 if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
1644 : # The file has not changed.
1648 if test -n "$already_present"; then
1649 echo "Updating file $g (backup in ${g}~)"
1651 echo "Replacing file $g (non-gnulib code backuped in ${g}~) !!"
1653 mv -f "$destdir/$g" "$destdir/${g}~" || func_fatal_error "failed"
1654 if test -n "$symbolic" && test -z "$lookedup_tmp" \
1655 && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1656 func_ln_if_changed "$lookedup_file" "$destdir/$g"
1658 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1661 if test -n "$already_present"; then
1662 echo "Update file $g (backup in ${g}~)"
1664 echo "Replace file $g (non-gnulib code backuped in ${g}~) !!"
1670 # Don't protest if the file should be there but isn't: it happens
1671 # frequently that developers don't put autogenerated files into CVS.
1673 echo "Copying file $g"
1674 if test -n "$symbolic" && test -z "$lookedup_tmp" \
1675 && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
1676 func_ln_if_changed "$lookedup_file" "$destdir/$g"
1678 mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
1686 # Then the files that are in new-files, but not in old-files:
1687 sed_take_last_column='s,^.*'"$delimiter"',,'
1689 LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files \
1690 | sed -e "$sed_take_last_column" \
1691 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/added-files
1692 { # Rearrange file descriptors. Needed because "while ... done < ..."
1693 # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
1694 exec 5<&0 < "$tmp"/added-files
1700 # Then the files that are in new-files and in old-files:
1701 already_present=true
1702 LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files \
1703 | sed -e "$sed_take_last_column" \
1704 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_new_files" > "$tmp"/kept-files
1705 { # Rearrange file descriptors. Needed because "while ... done < ..."
1706 # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
1707 exec 5<&0 < "$tmp"/kept-files
1714 # Command-line invocation printed in a comment in generated gnulib-cache.m4.
1715 actioncmd="gnulib-tool --import"
1716 func_append actioncmd " --dir=$destdir"
1717 if test -n "$local_gnulib_dir"; then
1718 func_append actioncmd " --local-dir=$local_gnulib_dir"
1720 func_append actioncmd " --lib=$libname"
1721 func_append actioncmd " --source-base=$sourcebase"
1722 func_append actioncmd " --m4-base=$m4base"
1723 func_append actioncmd " --doc-base=$docbase"
1724 func_append actioncmd " --aux-dir=$auxdir"
1725 for module in $avoidlist; do
1726 func_append actioncmd " --avoid=$module"
1728 if test -n "$lgpl"; then
1729 func_append actioncmd " --lgpl"
1731 if test -n "$makefile_name"; then
1732 func_append actioncmd " --makefile_name=$makefile_name"
1734 if test "$libtool" = true; then
1735 func_append actioncmd " --libtool"
1737 func_append actioncmd " --no-libtool"
1739 func_append actioncmd " --macro-prefix=$macro_prefix"
1740 func_append actioncmd " `echo $specified_modules`"
1742 # Default the makefile name to Makefile.am.
1743 if test -n "$makefile_name"; then
1744 makefile_am=$makefile_name
1746 makefile_am=Makefile.am
1749 # Create library makefile.
1750 func_dest_tmpfilename $sourcebase/$makefile_am
1751 func_emit_lib_Makefile_am > "$tmpfile"
1752 if test -f "$destdir"/$sourcebase/$makefile_am; then
1753 if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
1757 echo "Updating $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
1758 mv -f "$destdir"/$sourcebase/$makefile_am "$destdir"/$sourcebase/$makefile_am~
1759 mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
1761 echo "Update $sourcebase/$makefile_am (backup in $sourcebase/$makefile_am~)"
1767 echo "Creating $sourcebase/$makefile_am"
1768 mv -f "$tmpfile" "$destdir"/$sourcebase/$makefile_am
1770 echo "Create $sourcebase/$makefile_am"
1775 # Create m4/gnulib-cache.m4.
1776 func_dest_tmpfilename $m4base/gnulib-cache.m4
1778 func_emit_copyright_notice
1780 echo "# This file represents the specification of how gnulib-tool is used."
1781 echo "# It acts as a cache: It is written and read by gnulib-tool."
1782 echo "# In projects using CVS, this file is meant to be stored in CVS,"
1783 echo "# like the configure.ac and various Makefile.am files."
1786 echo "# Specification in the form of a command-line invocation:"
1789 echo "# Specification in the form of a few gnulib-tool.m4 macro invocations:"
1790 # Store the local_gnulib_dir relative to destdir.
1791 case "$local_gnulib_dir" in
1793 relative_local_gnulib_dir="$local_gnulib_dir" ;;
1796 /*) relative_local_gnulib_dir="$local_gnulib_dir" ;;
1798 # destdir, local_gnulib_dir are both relative.
1799 func_relativize "$destdir" "$local_gnulib_dir"
1800 relative_local_gnulib_dir="$reldir" ;;
1803 echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
1804 echo "gl_MODULES(["`echo $specified_modules`"])"
1805 echo "gl_AVOID([$avoidlist])"
1806 echo "gl_SOURCE_BASE([$sourcebase])"
1807 echo "gl_M4_BASE([$m4base])"
1808 echo "gl_DOC_BASE([$docbase])"
1809 echo "gl_TESTS_BASE([$testsbase])"
1810 echo "gl_LIB([$libname])"
1811 test -z "$lgpl" || echo "gl_LGPL"
1812 echo "gl_MAKEFILE_NAME([$makefile_name])"
1813 if test "$libtool" = true; then
1816 echo "gl_MACRO_PREFIX([$macro_prefix])"
1818 if test -f "$destdir"/$m4base/gnulib-cache.m4; then
1819 if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
1823 echo "Updating $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1824 mv -f "$destdir"/$m4base/gnulib-cache.m4 "$destdir"/$m4base/gnulib-cache.m4~
1825 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1827 echo "Update $m4base/gnulib-cache.m4 (backup in $m4base/gnulib-cache.m4~)"
1831 echo "# gnulib-cache.m4 ends here"
1838 echo "Creating $m4base/gnulib-cache.m4"
1839 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-cache.m4
1841 echo "Create $m4base/gnulib-cache.m4"
1847 # Create m4/gnulib-comp.m4.
1848 func_dest_tmpfilename $m4base/gnulib-comp.m4
1850 func_emit_copyright_notice
1852 echo "# This file represents the compiled summary of the specification in"
1853 echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
1854 echo "# to be invoked from configure.ac."
1855 echo "# In projects using CVS, this file can be treated like other built files."
1858 echo "# This macro should be invoked from $configure_ac, in the section"
1859 echo "# \"Checks for programs\", right after AC_PROG_CC, and certainly before"
1860 echo "# any checks for libraries, header files, types and library functions."
1861 echo "AC_DEFUN([${macro_prefix}_EARLY],"
1863 echo " m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
1864 echo " m4_pattern_allow([^gl_ES$])dnl a valid locale name"
1865 echo " AC_REQUIRE([AC_PROG_RANLIB])"
1866 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1867 echo " AC_REQUIRE([AC_GNU_SOURCE])"
1869 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1870 echo " AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])"
1872 if grep gl_LOCK "$destdir"/$m4base/*.m4 >/dev/null 2>/dev/null; then
1873 echo " AC_REQUIRE([gl_LOCK_EARLY])"
1877 echo "# This macro should be invoked from $configure_ac, in the section"
1878 echo "# \"Check for header files, types and library functions\"."
1879 echo "AC_DEFUN([${macro_prefix}_INIT],"
1881 if test "$libtool" = true; then
1882 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
1883 echo " gl_cond_libtool=true"
1885 echo " AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
1886 echo " gl_cond_libtool=false"
1888 echo " gl_ltlibdeps="
1890 echo " gl_source_base='$sourcebase'"
1891 if test "$auxdir" != "build-aux"; then
1892 sed_replace_build_aux='
1894 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
1895 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
1898 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
1900 sed_replace_build_aux=
1902 for module in $modules; do
1904 if test -n "$module"; then
1905 func_get_autoconf_snippet "$module" \
1906 | sed -e '/^$/d;' -e 's/^/ /' \
1907 -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./' \
1908 -e "$sed_replace_build_aux"
1909 if test "$module" = 'alloca' && test "$libtool" = true; then
1910 echo 'changequote(,)dnl'
1911 echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
1912 echo 'changequote([, ])dnl'
1913 echo 'AC_SUBST([LTALLOCA])'
1917 # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
1918 # created using libtool, because libtool already handles the dependencies.
1919 if test "$libtool" != true; then
1920 libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
1921 echo " ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
1922 echo " AC_SUBST([${libname_upper}_LIBDEPS])"
1923 echo " ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
1924 echo " AC_SUBST([${libname_upper}_LTLIBDEPS])"
1928 echo "# This macro records the list of files which have been installed by"
1929 echo "# gnulib-tool and may be removed by future gnulib-tool invocations."
1930 echo "AC_DEFUN([${macro_prefix}_FILE_LIST], ["
1931 echo "$files" | sed -e 's,^, ,'
1934 if test -f "$destdir"/$m4base/gnulib-comp.m4; then
1935 if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
1939 echo "Updating $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1940 mv -f "$destdir"/$m4base/gnulib-comp.m4 "$destdir"/$m4base/gnulib-comp.m4~
1941 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1943 echo "Update $m4base/gnulib-comp.m4 (backup in $m4base/gnulib-comp.m4~)"
1947 echo "# gnulib-comp.m4 ends here"
1954 echo "Creating $m4base/gnulib-comp.m4"
1955 mv -f "$tmpfile" "$destdir"/$m4base/gnulib-comp.m4
1957 echo "Create $m4base/gnulib-comp.m4"
1963 if test -n "$inctests"; then
1964 # Create tests makefile.
1965 func_dest_tmpfilename $testsbase/$makefile_am
1966 func_emit_tests_Makefile_am > "$tmpfile"
1967 if test -f "$destdir"/$testsbase/$makefile_am; then
1968 if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
1972 echo "Updating $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
1973 mv -f "$destdir"/$testsbase/$makefile_am "$destdir"/$testsbase/$makefile_am~
1974 mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
1976 echo "Update $testsbase/$makefile_am (backup in $testsbase/$makefile_am~)"
1982 echo "Creating $testsbase/$makefile_am"
1983 mv -f "$tmpfile" "$destdir"/$testsbase/$makefile_am
1985 echo "Create $testsbase/$makefile_am"
1993 echo "You may need to add #include directives for the following .h files."
1994 # First the #include <...> directives without #ifs, sorted for convenience,
1995 # then the #include "..." directives without #ifs, sorted for convenience,
1996 # then the #include directives that are surrounded by #ifs. Not sorted.
1997 for module in $modules; do
1998 include_directive=`func_get_include_directive "$module"`
1999 case "$nl$include_directive" in
2001 echo "$include_directive" 1>&5
2004 echo "$include_directive" | grep -v 'include "' 1>&6
2005 echo "$include_directive" | grep 'include "' 1>&7
2008 done 5> "$tmp"/include-if 6> "$tmp"/include-angles 7> "$tmp"/include-quotes
2010 LC_ALL=C sort -u "$tmp"/include-angles
2011 LC_ALL=C sort -u "$tmp"/include-quotes
2012 cat "$tmp"/include-if
2013 ) | sed -e '/^$/d' -e 's/^/ /'
2014 rm -f "$tmp"/include-angles "$tmp"/include-quotes "$tmp"/include-if
2017 echo "Don't forget to"
2018 if test "$makefile_am" = Makefile.am; then
2019 echo " - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2021 echo " - \"include $makefile_name\" from within \"$sourcebase/Makefile.am\","
2023 if test -n "$inctests"; then
2024 if test "$makefile_am" = Makefile.am; then
2025 echo " - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
2027 echo " - \"include $makefile_name\" from within \"$testsbase/Makefile.am\","
2030 if test "$makefile_am" = Makefile.am; then
2031 sourcebase_dir=`echo "$sourcebase" | sed -n -e 's,/[^/]*$,/,p'`
2032 sourcebase_base=`basename "$sourcebase"`
2033 echo " - mention \"${sourcebase_base}\" in SUBDIRS in ${sourcebase_dir}Makefile.am,"
2035 if test -n "$inctests"; then
2036 if test "$makefile_am" = Makefile.am; then
2037 testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
2038 testsbase_base=`basename "$testsbase"`
2039 echo " - mention \"${testsbase_base}\" in SUBDIRS in ${testsbase_dir}Makefile.am,"
2042 echo " - mention \"-I ${m4base}\" in ACLOCAL_AMFLAGS in Makefile.am,"
2043 echo " - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
2044 echo " - invoke ${macro_prefix}_INIT in $configure_ac."
2047 # func_create_testdir testdir modules
2049 # - local_gnulib_dir from --local-dir
2050 # - auxdir directory relative to destdir where to place build aux files
2051 func_create_testdir ()
2055 modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
2057 # Subdirectory names.
2063 # Determine final module list.
2064 func_modules_transitive_closure
2065 echo "Module list with included dependencies:"
2066 echo "$modules" | sed -e 's/^/ /'
2068 # Add the dummy module if needed.
2069 func_modules_add_dummy
2071 # Determine final file list.
2072 func_modules_to_filelist
2074 echo "$files" | sed -e 's/^/ /'
2076 # Create directories.
2077 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
2079 build-aux) mkdir -p "$testdir/$auxdir" ;;
2080 doc) mkdir -p "$testdir/$docbase" ;;
2081 lib) mkdir -p "$testdir/$sourcebase" ;;
2082 m4) mkdir -p "$testdir/$m4base" ;;
2083 tests) mkdir -p "$testdir/$testsbase" ;;
2084 *) mkdir -p "$testdir/$d" ;;
2088 # Copy files or make symbolic links.
2090 sed_rewrite_files="\
2091 s,^build-aux/,$auxdir/,
2093 s,^lib/,$sourcebase/,
2095 s,^tests/,$testsbase/,"
2096 for f in $files; do echo $f; done \
2097 | sed -e "s,^.*\$,&$delimiter&," -e "$sed_rewrite_files" \
2100 { # Rearrange file descriptors. Needed because "while ... done < ..."
2101 # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
2102 exec 5<&0 < "$tmp"/files
2104 func_lookup_file "$f"
2105 if test -n "$lookedup_tmp"; then
2106 cp -p "$lookedup_file" "$testdir/$g"
2108 ln "$lookedup_file" "$testdir/$g" 2>/dev/null ||
2109 if test -z "$symbolic"; then
2110 cp -p "$lookedup_file" "$testdir/$g"
2112 ln -s "$lookedup_file" "$testdir/$g"
2119 # Create $sourcebase/Makefile.am.
2120 mkdir -p "$testdir/$sourcebase"
2121 func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
2123 # Create $m4base/Makefile.am.
2124 mkdir -p "$testdir/$m4base"
2125 (echo "## Process this file with automake to produce Makefile.in."
2131 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
2134 ) > "$testdir/$m4base/Makefile.am"
2136 subdirs="$sourcebase $m4base"
2137 subdirs_with_configure_ac=""
2139 if test -f "$testdir"/$m4base/gettext.m4; then
2140 # Avoid stupid error message from automake:
2141 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
2142 mkdir -p "$testdir/po"
2143 (echo "## Process this file with automake to produce Makefile.in."
2144 ) > "$testdir/po/Makefile.am"
2145 func_append subdirs " po"
2148 if test -n "$inctests"; then
2149 test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
2150 # Create $testsbase/Makefile.am.
2151 func_emit_tests_Makefile_am > "$testdir/$testsbase/Makefile.am"
2152 # Create $testsbase/configure.ac.
2153 (echo "# Process this file with autoconf to produce a configure script."
2154 echo "AC_INIT([dummy], [0])"
2155 echo "AC_CONFIG_AUX_DIR([../$auxdir])"
2156 echo "AM_INIT_AUTOMAKE"
2158 echo "AM_CONFIG_HEADER([config.h])"
2161 echo "AC_PROG_INSTALL"
2162 echo "AC_PROG_MAKE_SET"
2163 echo "AC_PROG_RANLIB"
2165 if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2166 echo "AC_GNU_SOURCE"
2169 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2170 echo "gl_USE_SYSTEM_EXTENSIONS"
2173 if grep gl_LOCK "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2174 echo "gl_LOCK_EARLY"
2177 if test "$libtool" = true; then
2178 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2179 echo "gl_cond_libtool=true"
2181 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2182 echo "gl_cond_libtool=false"
2184 echo "gl_ltlibdeps="
2186 echo "gl_source_base='$testsbase'"
2187 # Wrap the set of autoconf snippets into an autoconf macro that is then
2188 # invoked. This is needed because autoconf does not support AC_REQUIRE
2190 # error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2191 # but we want the AC_REQUIRE to have its normal meaning (provide one
2192 # expansion of the required macro before the current point, and only one
2194 echo "AC_DEFUN([gl_INIT], ["
2195 if test "$auxdir" != "build-aux"; then
2196 sed_replace_build_aux='
2198 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2199 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:../'"$auxdir"'/\2)|
2202 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
2204 sed_replace_build_aux=
2206 # We don't have explicit ordering constraints between the various
2207 # autoconf snippets. It's cleanest to put those of the library before
2208 # those of the tests.
2209 for module in $modules; do
2210 func_verify_nontests_module
2211 if test -n "$module"; then
2212 func_get_autoconf_snippet "$module" \
2213 | sed -e "$sed_replace_build_aux"
2216 for module in $modules; do
2217 func_verify_tests_module
2218 if test -n "$module"; then
2219 func_get_autoconf_snippet "$module" \
2220 | sed -e "$sed_replace_build_aux"
2223 # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2224 # created using libtool, because libtool already handles the dependencies.
2225 if test "$libtool" != true; then
2226 libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
2227 echo " ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2228 echo " AC_SUBST([${libname_upper}_LIBDEPS])"
2229 echo " ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2230 echo " AC_SUBST([${libname_upper}_LTLIBDEPS])"
2235 # Usually $testsbase/config.h will be a superset of config.h. Verify this
2236 # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
2237 echo "AH_TOP([#include \"../config.h\"])"
2239 echo "AC_OUTPUT([Makefile])"
2240 ) > "$testdir/$testsbase/configure.ac"
2241 func_append subdirs " $testsbase"
2242 subdirs_with_configure_ac="$subdirs_with_configure_ac $testsbase"
2245 # Create Makefile.am.
2246 (echo "## Process this file with automake to produce Makefile.in."
2248 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
2250 echo "SUBDIRS = $subdirs"
2252 echo "ACLOCAL_AMFLAGS = -I $m4base"
2253 ) > "$testdir/Makefile.am"
2255 # Create configure.ac.
2256 (echo "# Process this file with autoconf to produce a configure script."
2257 echo "AC_INIT([dummy], [0])"
2258 if test "$auxdir" != "."; then
2259 echo "AC_CONFIG_AUX_DIR([$auxdir])"
2261 echo "AM_INIT_AUTOMAKE"
2263 echo "AM_CONFIG_HEADER([config.h])"
2266 echo "AC_PROG_INSTALL"
2267 echo "AC_PROG_MAKE_SET"
2269 echo "m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace"
2270 echo "m4_pattern_allow([^gl_ES$])dnl a valid locale name"
2272 echo "AC_PROG_RANLIB"
2274 if grep AC_GNU_SOURCE "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2275 echo "AC_GNU_SOURCE"
2278 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2279 echo "gl_USE_SYSTEM_EXTENSIONS"
2282 if grep gl_LOCK "$testdir/$m4base"/*.m4 >/dev/null 2>/dev/null; then
2283 echo "gl_LOCK_EARLY"
2286 if test "$libtool" = true; then
2287 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [true])"
2288 echo "gl_cond_libtool=true"
2290 echo "AM_CONDITIONAL([GL_COND_LIBTOOL], [false])"
2291 echo "gl_cond_libtool=false"
2293 echo "gl_ltlibdeps="
2295 echo "gl_source_base='$sourcebase'"
2296 # Wrap the set of autoconf snippets into an autoconf macro that is then
2297 # invoked. This is needed because autoconf does not support AC_REQUIRE
2299 # error: AC_REQUIRE(gt_CSHARPCOMP): cannot be used outside of an AC_DEFUN'd macro
2300 # but we want the AC_REQUIRE to have its normal meaning (provide one
2301 # expansion of the required macro before the current point, and only one
2303 echo "AC_DEFUN([gl_INIT], ["
2304 if test "$auxdir" != "build-aux"; then
2305 sed_replace_build_aux='
2307 /AC_CONFIG_FILES(.*:build-aux\/.*)/{
2308 s|AC_CONFIG_FILES(\(.*\):build-aux/\(.*\))|AC_CONFIG_FILES(\1:'"$auxdir"'/\2)|
2311 sed_replace_build_aux=`echo "$sed_replace_build_aux" | sed -e 1d -e 's/^ *//'`
2313 sed_replace_build_aux=
2315 for module in $modules; do
2316 func_verify_nontests_module
2317 if test -n "$module"; then
2318 func_get_autoconf_snippet "$module" \
2319 | sed -e "$sed_replace_build_aux"
2322 # _LIBDEPS and _LTLIBDEPS variables are not needed if this library is
2323 # created using libtool, because libtool already handles the dependencies.
2324 if test "$libtool" != true; then
2325 libname_upper=`echo "$libname" | tr 'a-z' 'A-Z'`
2326 echo " ${libname_upper}_LIBDEPS=\"\$gl_libdeps\""
2327 echo " AC_SUBST([${libname_upper}_LIBDEPS])"
2328 echo " ${libname_upper}_LTLIBDEPS=\"\$gl_ltlibdeps\""
2329 echo " AC_SUBST([${libname_upper}_LTLIBDEPS])"
2334 if test -n "$subdirs_with_configure_ac"; then
2335 echo "AC_CONFIG_SUBDIRS(["`echo $subdirs_with_configure_ac`"])"
2337 makefiles="Makefile"
2338 for d in $subdirs; do
2339 # For subdirs that have a configure.ac by their own, it's the subdir's
2340 # configure.ac which creates the subdir's Makefile.am, not this one.
2341 case " $subdirs_with_configure_ac " in
2343 *) func_append makefiles " $d/Makefile" ;;
2346 echo "AC_OUTPUT([$makefiles])"
2347 ) > "$testdir/configure.ac"
2349 # Create autogenerated files.
2351 echo "executing ${AUTORECONF} --force --install"
2352 ${AUTORECONF} --force --install
2354 if grep '^BUILT_SOURCES *+=' "$testdir/$sourcebase/Makefile.am" > /dev/null; then
2358 echo 'built_sources: $(BUILT_SOURCES)' >> Makefile
2366 # func_create_megatestdir megatestdir allmodules
2368 # - local_gnulib_dir from --local-dir
2369 # - auxdir directory relative to destdir where to place build aux files
2370 func_create_megatestdir ()
2374 if test -z "$allmodules"; then
2375 allmodules=`func_all_modules`
2379 # First, all modules one by one.
2380 for onemodule in $allmodules; do
2381 func_create_testdir "$megatestdir/$onemodule" $onemodule
2382 func_append megasubdirs "$onemodule "
2384 # Then, all modules all together.
2385 # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
2386 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
2387 allmodules=`for m in $allmodules; do if test $m != config-h && test $m != fnmatch-posix; then echo $m; fi; done`
2388 func_create_testdir "$megatestdir/ALL" "$allmodules"
2389 func_append megasubdirs "ALL"
2391 # Create Makefile.am.
2392 (echo "## Process this file with automake to produce Makefile.in."
2394 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
2396 echo "SUBDIRS = $megasubdirs"
2397 ) > "$megatestdir/Makefile.am"
2399 # Create configure.ac.
2400 (echo "# Process this file with autoconf to produce a configure script."
2401 echo "AC_INIT([dummy], [0])"
2402 if test "$auxdir" != "."; then
2403 echo "AC_CONFIG_AUX_DIR([$auxdir])"
2405 echo "AM_INIT_AUTOMAKE"
2407 echo "AC_PROG_MAKE_SET"
2409 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
2410 echo "AC_OUTPUT([Makefile])"
2411 ) > "$megatestdir/configure.ac"
2413 # Create autogenerated files.
2415 # Do not use "${AUTORECONF} --install", because autoreconf operates
2416 # recursively, but the subdirectories are already finished, therefore
2417 # calling autoreconf here would only waste lots of CPU time.
2418 echo "executing ${ACLOCAL}"
2420 echo "executing mkdir build-aux"
2422 echo "executing ${AUTOCONF}"
2424 echo "executing ${AUTOMAKE} --add-missing --copy"
2425 ${AUTOMAKE} --add-missing --copy
2431 func_fatal_error "no mode specified" ;;
2440 if test -z "$destdir"; then
2443 test -d "$destdir" \
2444 || func_fatal_error "destination directory does not exist: $destdir"
2446 # Prefer configure.ac to configure.in.
2447 if test -f "$destdir"/configure.ac; then
2448 configure_ac="$destdir/configure.ac"
2450 if test -f "$destdir"/configure.in; then
2451 configure_ac="$destdir/configure.in"
2453 func_fatal_error "cannot find $destdir/configure.ac"
2457 # Analyze configure.ac.
2459 guessed_libtool=false
2464 /AC_CONFIG_AUX_DIR/ {
2465 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,guessed_auxdir="\1",p
2467 /A[CM]_PROG_LIBTOOL/ {
2468 s,^.*$,guessed_libtool=true,p
2470 eval `sed -n -e "$my_sed_traces" < "$configure_ac"`
2472 if test -z "$auxdir"; then
2473 auxdir="$guessed_auxdir"
2476 # Determine where to apply func_import.
2477 if test -n "$m4base"; then
2478 # Apply func_import to a particular gnulib directory.
2479 # Any number of additional modules can be given.
2480 if test ! -f "$destdir/$m4base"/gnulib-cache.m4; then
2481 # First use of gnulib in the given m4base.
2482 test -n "$supplied_libname" || supplied_libname=true
2483 test -n "$sourcebase" || sourcebase="lib"
2484 test -n "$docbase" || docbase="doc"
2485 test -n "$testsbase" || testsbase="tests"
2486 test -n "$macro_prefix" || macro_prefix="gl"
2490 # Apply func_import to all gnulib directories.
2491 # To get this list of directories, look at Makefile.am. (Not at
2492 # configure, because it may be omitted from CVS. Also, don't run
2493 # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
2496 if test -f "$destdir"/Makefile.am; then
2497 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
2499 for arg in $aclocal_amflags; do
2500 if test -n "$m4dir_is_next"; then
2501 # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
2505 if test -f "$destdir/$arg"/gnulib-cache.m4; then
2506 func_append m4dirs " $arg"
2507 m4dirs_count=`expr $m4dirs_count + 1`
2512 if test "X$arg" = "X-I"; then
2520 # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
2521 if test -f "$destdir"/aclocal.m4; then
2522 sedexpr1='s,^m4_include(\[\(.*\)])$,\1,p'
2523 sedexpr2='s,^[^/]*$,.,'
2524 sedexpr3='s,/[^/]*$,,'
2525 m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
2526 m4dirs_count=`echo "$m4dirs" | wc -l`
2529 if test $m4dirs_count = 0; then
2530 # First use of gnulib in a package.
2531 # Any number of additional modules can be given.
2532 test -n "$supplied_libname" || supplied_libname=true
2533 test -n "$sourcebase" || sourcebase="lib"
2535 test -n "$docbase" || docbase="doc"
2536 test -n "$testsbase" || testsbase="tests"
2537 test -n "$macro_prefix" || macro_prefix="gl"
2540 if test $m4dirs_count = 1; then
2541 # There's only one use of gnulib here. Assume the user means it.
2542 # Any number of additional modules can be given.
2543 for m4base in $m4dirs; do
2547 # Ambiguous - guess what the user meant.
2548 if test $# = 0; then
2549 # No further arguments. Guess the user wants to update all of them.
2550 for m4base in $m4dirs; do
2551 # Perform func_import in a subshell, so that variable values
2553 # local_gnulib_dir, avoidlist, sourcebase, m4base, docbase,
2554 # testsbase, libname, lgpl, makefile_name, libtool, macro_prefix
2555 # don't propagate from one directory to another.
2556 (func_import) || func_exit 1
2560 func_fatal_error "Ambiguity: to which directory should the modules be added? Please specify at least --m4-base=..."
2568 if test -z "$destdir"; then
2569 func_fatal_error "please specify --dir option"
2572 test -d "$destdir" \
2573 || func_fatal_error "could not create destination directory"
2574 test -n "$auxdir" || auxdir="build-aux"
2575 func_create_testdir "$destdir" "$*"
2578 create-megatestdir )
2579 if test -z "$destdir"; then
2580 func_fatal_error "please specify --dir option"
2582 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2583 test -n "$auxdir" || auxdir="build-aux"
2584 func_create_megatestdir "$destdir" "$*"
2588 test -n "$destdir" || destdir=testdir$$
2589 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2590 test -n "$auxdir" || auxdir="build-aux"
2591 func_create_testdir "$destdir" "$*"
2599 remaining=`find . -type f -print`
2600 if test -n "$remaining"; then
2601 echo "Remaining files:" $remaining 1>&2
2602 echo "gnulib-tool: *** Stop." 1>&2
2611 test -n "$destdir" || destdir=testdir$$
2612 mkdir "$destdir" || func_fatal_error "could not create destination directory"
2613 test -n "$auxdir" || auxdir="build-aux"
2614 func_create_megatestdir "$destdir" "$*"
2622 remaining=`find . -type f -print`
2623 if test -n "$remaining"; then
2624 echo "Remaining files:" $remaining 1>&2
2625 echo "gnulib-tool: *** Stop." 1>&2
2633 extract-description )
2637 if test -n "$module"; then
2638 func_get_description "$module"
2647 if test -n "$module"; then
2648 func_get_filelist "$module"
2653 extract-dependencies )
2657 if test -n "$module"; then
2658 func_get_dependencies "$module"
2663 extract-autoconf-snippet )
2667 if test -n "$module"; then
2668 func_get_autoconf_snippet "$module"
2673 extract-automake-snippet )
2677 if test -n "$module"; then
2678 func_get_automake_snippet "$module"
2683 extract-include-directive )
2687 if test -n "$module"; then
2688 func_get_include_directive "$module"
2697 if test -n "$module"; then
2698 func_get_license "$module"
2703 extract-maintainer )
2707 if test -n "$module"; then
2708 func_get_maintainer "$module"
2713 extract-tests-module )
2717 if test -n "$module"; then
2718 func_get_tests_module "$module"
2724 func_fatal_error "unknown operation mode --$mode" ;;
2728 # Undo the effect of the previous 'trap' command. Some shellology:
2729 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
2730 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
2731 # exit); for the others we need to call 'exit' explicitly. The value of $? is
2732 # 128 + signal number and is set before the trap-registered command is run.
2734 trap 'func_exit $?' 1 2 3 13 15
2739 # indent-tabs-mode: nil
2740 # whitespace-check-buffer-indent: nil