bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: $(EXEEXT) in TESTS required?


From: Alexandre Duret-Lutz
Subject: Re: $(EXEEXT) in TESTS required?
Date: Sun, 29 Jan 2006 18:34:30 +0100
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/22.0.50 (gnu/linux)

>>> "SJ" == Simon Josefsson <address@hidden> writes:
 SJ> Ralf Wildenhues <address@hidden> writes:
 >> Now I wonder how to best "fix" this in Automake:
 >> - document the fact that $(EXEEXT) should be used in `TESTS', for the
 >> benefit of cross-compilation,
 >> - have Automake rewrite TESTS to add $(EXEEXT) where appropriate (is
 >> this possible in all cases?),

 SJ> The second one seem fine.  If it is impossible to add $(EXEEXT)
 SJ> reliably to TESTS, perhaps a new name could be used.  

Thanks for the report, I'm installing the following patch.

 SJ> While at it, if it is possible to reduce the redundancy in
 SJ> statements like:

 SJ> TESTS += test-gc$(EXEEXT)
 SJ> check_PROGRAMS += test-gc

 SJ> that would be useful.

 SJ> How about simply:

 SJ> tests_PROGRAMS += test-gc
[...]
 SJ> Or something, I'm not really sure.  I have always found this
 SJ> redundancy a bit disturbing though.

I don't think a new syntax is necessary since you can do

  TESTS = $(testprograms) other scripts
  check_PROGRAMS = $(testprograms) other programs

and then

  testprograms += test-gc$(EXEEXT)
  testprograms += test-whatever$(EXEEXT)
  ...

(And with the patch below you won't need $(EXEEXT).)


Note to self: need to tune transform_variable_recursively so it doesn't
create a temporary variable when no transformation has occurred.

2006-01-29  Alexandre Duret-Lutz  <address@hidden>

        Append $(EXEEXT) to programs that may be listed in TESTS.
        Report from Simon Josefsson.

        * automake.in (%known_programs): New global.
        (initialize_per_input): Reset it.
        (append_exeext): Take a predicate as first argument to select
        the filename to rewrite.
        (handle_programs): Fill %known_programs.
        (handle_tests): Append $(EXEEXT) to all tests that are in
        %known_programs.
        (am_install_var): Update call to append_exeext.
        * doc/automake.texi (EXEEXT): TESTS is also rewritten.
        (Tests): More about the difference between check_PROGRAMS and TESTS.
        Give an example of TEST_ENVIRONMENT.
        * tests/cond32.test: Augment with a nested condition.
        * tests/exeext4.test: Also check TESTS.
        * tests/check5.test: New file.
        * tests/Makefile.am (TESTS): Add check5.test.

Index: NEWS
===================================================================
RCS file: /cvs/automake/automake/NEWS,v
retrieving revision 1.300
diff -u -r1.300 NEWS
--- NEWS        14 May 2005 20:28:50 -0000      1.300
+++ NEWS        29 Jan 2006 12:38:55 -0000
@@ -89,6 +89,10 @@
     $(LIBOBJS), $(LTLIBOBJS), $(ALLOCA), and $(LTALLOCA) can be used
     in different directories.
 
+  - $(EXEEXT) is automatically appended to filenames of TESTS and
+    that have been declared as programs in the same Makefile.
+    This is mostly useful when some check_PROGRAMS are listed in TESTS.
+
 
 New in 1.9:
 
Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1615
diff -u -r1.1615 automake.in
--- automake.in 5 Jan 2006 23:47:36 -0000       1.1615
+++ automake.in 29 Jan 2006 12:38:56 -0000
@@ -538,6 +538,10 @@
 # This is a list of all targets to run during "make dist".
 my @dist_targets;
 
+# Keep track of all programs declared in this Makefile, without
+# $(EXEEXT).  @substitution@ are not listed.
+my %known_programs;
+
 # Keys in this hash are the basenames of files which must depend on
 # ansi2knr.  Values are either the empty string, or the directory in
 # which the ANSI source file appears; the directory must have a
@@ -659,6 +663,8 @@
 
     @dist_targets = ();
 
+    %known_programs = ();
+
     %de_ansi_files = ();
 
     $all_target = '';
@@ -1482,6 +1488,32 @@
       }
 }
 
+
+# append_exeext { PREDICATE } $MACRO
+# ----------------------------------
+# Append $(EXEEXT) to each filename in $F appearing in the Makefile
+# variable $MACRO if &PREDICATE($F) is true.  @substitutions@ are
+# ignored.
+#
+# This is typically used on all filenames of *_PROGRAMS, and filenames
+# of TESTS that are programs.
+sub append_exeext (&$)
+{
+  my ($pred, $macro) = @_;
+
+  transform_variable_recursively
+    ($macro, $macro, 'am__EXEEXT', 0, INTERNAL,
+     sub {
+       my ($subvar, $val, $cond, $full_cond) = @_;
+       # Append $(EXEEXT) unless the user did it already, or it's a
+       # @address@hidden
+       $val .= '$(EXEEXT)'
+        if $val !~ /(?:\$\(EXEEXT\)$|address@hidden@]$)/ && &$pred ($val);
+       return $val;
+     });
+}
+
+
 # Check to make sure a source defined in LIBOBJS is not explicitly
 # mentioned.  This is a separate function (as opposed to being inlined
 # in handle_source_transform) because it isn't always appropriate to
@@ -2371,6 +2403,8 @@
       # We'll add $(EXEEXT) back later anyway.
       $one_file =~ s/\$\(EXEEXT\)$//;
 
+      $known_programs{$one_file} = $where;
+
       # Canonicalize names and check for misspellings.
       my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
                                             '_SOURCES', '_OBJECTS',
@@ -4577,6 +4611,9 @@
     {
       push (@check_tests, 'check-TESTS');
       $output_rules .= &file_contents ('check', new Automake::Location);
+
+      # Tests that are known programs should have $(EXEEXT) appended.
+      append_exeext { exists $known_programs{$_[0]} } 'TESTS';
     }
 }
 
@@ -6660,29 +6697,6 @@
 }
 
 
-# &append_exeext ($MACRO)
-# -----------------------
-# Macro is an Automake magic macro which primary is PROGRAMS, e.g.
-# bin_PROGRAMS.  Make sure these programs have $(EXEEXT) appended.
-sub append_exeext ($)
-{
-  my ($macro) = @_;
-
-  prog_error "append_exeext ($macro)"
-    unless $macro =~ /_PROGRAMS$/;
-
-  transform_variable_recursively
-    ($macro, $macro, 'am__EXEEXT', 0, INTERNAL,
-     sub {
-       my ($subvar, $val, $cond, $full_cond) = @_;
-       # Append $(EXEEXT) unless the user did it already, or it's a
-       # @address@hidden
-       $val .= '$(EXEEXT)' unless $val =~ 
/(?:\$\(EXEEXT\)$|address@hidden@]$)/;
-       return $val;
-     });
-}
-
-
 # @PREFIX
 # &am_primary_prefixes ($PRIMARY, $CAN_DIST, @PREFIXES)
 # -----------------------------------------------------
@@ -6883,7 +6897,7 @@
        }
       # A blatant hack: we rewrite each _PROGRAMS primary to include
       # EXEEXT.
-      append_exeext ($one_name)
+      append_exeext { 1 } $one_name
        if $primary eq 'PROGRAMS';
       # "EXTRA" shouldn't be used when generating clean targets,
       # all, or install targets.  We used to warn if EXTRA_FOO was
@@ -7446,6 +7460,7 @@
   handle_subdirs;
   handle_tags;
   handle_minor_options;
+  # Must come after handle_programs so that %known_programs is up-to-date.
   handle_tests;
 
   # This must come after most other rules.
Index: doc/automake.texi
===================================================================
RCS file: /cvs/automake/automake/doc/automake.texi,v
retrieving revision 1.125
diff -u -r1.125 automake.texi
--- doc/automake.texi   6 Jan 2006 00:45:22 -0000       1.125
+++ doc/automake.texi   29 Jan 2006 12:38:57 -0000
@@ -5198,6 +5198,11 @@
 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
 extension.
 
+The variable @code{TESTS} (@pxref{Tests}) is also rewritten if it
+contains filenames that have been declared as programs in the same
address@hidden  (This is mostly useful when some programs from
address@hidden are listed in @code{TESTS}.)
+
 However, Automake cannot apply this rewriting to @command{configure}
 substitutions.  This means that if you are conditionally building a
 program using such a substitution, then your @file{configure.ac} must
@@ -6681,15 +6686,13 @@
 
 @section Simple Tests
 
-If the variable @code{TESTS} is defined, its value is taken to be a list
-of programs to run in order to do the testing.  The programs can either
-be derived objects or source objects; the generated rule will look both
-in @code{srcdir} and @file{.}.  Programs needing data files should look
-for them in @code{srcdir} (which is both an environment variable and a
-make variable) so they work when building in a separate directory
-(@pxref{Build Directories, , Build Directories , autoconf, The Autoconf
-Manual}), and in particular for the @code{distcheck} rule
-(@pxref{Dist}).
+If the variable @code{TESTS} is defined, its value is taken to be a
+list of programs or scripts to run in order to do the testing.
+Programs needing data files should look for them in @code{srcdir}
+(which is both an environment variable and a make variable) so they
+work when building in a separate directory (@pxref{Build Directories,
+, Build Directories , autoconf, The Autoconf Manual}), and in
+particular for the @code{distcheck} rule (@pxref{Dist}).
 
 @cindex Exit status 77, special interpretation
 
@@ -6698,13 +6701,20 @@
 in the final count.  This feature allows non-portable tests to be
 ignored in environments where they don't make sense.
 
address@hidden TESTS
address@hidden TESTS_ENVIRONMENT
 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
 variables for the test run; the environment variable @code{srcdir} is
 set in the rule.  If all your test programs are scripts, you can also
 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
address@hidden(SHELL) -x}); this can be useful for debugging the tests.
address@hidden TESTS
address@hidden TESTS_ENVIRONMENT
address@hidden(SHELL) -x} can be useful for debugging the tests), or any other
+interpreter.  For instance the following setup is used by the Automake
+package to run four tests in Perl.
address@hidden
+TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w
+TESTS = Condition.pl DisjConditions.pl Version.pl Wrap.pl
address@hidden example
+
 
 @cindex Tests, expected failure
 @cindex Expected test failure
@@ -6714,12 +6724,22 @@
 reverse the result of those tests.
 @vindex XFAIL_TESTS
 
-Automake ensures that each program listed in @code{TESTS} is built
-before any tests are run; you can list both source and derived programs
-in @code{TESTS}.  For instance, you might want to run a C program as a
-test.  To do this you would list its name in @code{TESTS} and also in
address@hidden, and then specify it as you would any other
-program.
+Automake ensures that each file listed in @code{TESTS} is built before
+any tests are run; you can list both source and derived programs (or
+scripts) in @code{TESTS}; the generated rule will look both in
address@hidden and @file{.}.  For instance, you might want to run a C
+program as a test.  To do this you would list its name in @code{TESTS}
+and also in @code{check_PROGRAMS}, and then specify it as you would
+any other program.
+
+Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
address@hidden) are only built during @code{make check},
+not during @code{make all}.  You should list there any program needed
+by your tests that does not need to be built by @code{make all}.  Note
+that @code{check_PROGRAMS} are @emph{not} automatically added to
address@hidden because @code{check_PROGRAMS} usually lists programs used
+by the tests, not the tests themselves.  Of course you can set
address@hidden = $(check_PROGRAMS)} if all your programs are test cases.
 
 @section DejaGnu Tests
 
Index: doc/stamp-vti
===================================================================
RCS file: /cvs/automake/automake/doc/stamp-vti,v
retrieving revision 1.107
diff -u -r1.107 stamp-vti
--- doc/stamp-vti       5 Jan 2006 23:47:36 -0000       1.107
+++ doc/stamp-vti       29 Jan 2006 12:38:57 -0000
@@ -1,4 +1,4 @@
address@hidden UPDATED 6 January 2006
address@hidden UPDATED 29 January 2006
 @set UPDATED-MONTH January 2006
 @set EDITION 1.9a
 @set VERSION 1.9a
Index: doc/version.texi
===================================================================
RCS file: /cvs/automake/automake/doc/version.texi,v
retrieving revision 1.107
diff -u -r1.107 version.texi
--- doc/version.texi    5 Jan 2006 23:47:36 -0000       1.107
+++ doc/version.texi    29 Jan 2006 12:38:57 -0000
@@ -1,4 +1,4 @@
address@hidden UPDATED 6 January 2006
address@hidden UPDATED 29 January 2006
 @set UPDATED-MONTH January 2006
 @set EDITION 1.9a
 @set VERSION 1.9a
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.591
diff -u -r1.591 Makefile.am
--- tests/Makefile.am   30 Jun 2005 21:19:47 -0000      1.591
+++ tests/Makefile.am   29 Jan 2006 12:38:57 -0000
@@ -78,6 +78,7 @@
 check2.test \
 check3.test \
 check4.test \
+check5.test \
 checkall.test \
 clean.test \
 clean2.test \
Index: tests/check5.test
===================================================================
RCS file: tests/check5.test
diff -N tests/check5.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/check5.test   29 Jan 2006 12:38:57 -0000
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 2006  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Test TESTS = $(check_PROGRAMS)
+
+. ./defs || exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+check_PROGRAMS = one two
+TESTS = $(check_PROGRAMS)
+check-local:
+       test -f one$(EXEEXT)
+       test -f two$(EXEEXT)
+       touch ok
+print-tests:
+       echo BEG: $(TESTS) :END
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+cat >one.c <<END
+int main() { return 0; }
+END
+cp one.c two.c
+
+./configure
+$MAKE check
+test -f ok
+$MAKE EXEEXT=.bin print-tests >output
+cat output
+grep 'BEG: one.bin two.bin :END' output
Index: tests/cond32.test
===================================================================
RCS file: /cvs/automake/automake/tests/cond32.test,v
retrieving revision 1.2
diff -u -r1.2 cond32.test
--- tests/cond32.test   14 May 2005 20:28:54 -0000      1.2
+++ tests/cond32.test   29 Jan 2006 12:38:57 -0000
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (C) 2003  Free Software Foundation, Inc.
+# Copyright (C) 2003, 2006  Free Software Foundation, Inc.
 #
 # This file is part of GNU Automake.
 #
@@ -28,6 +28,7 @@
 AC_PROG_CC
 AM_CONDITIONAL(C1, [test -z "$two"])
 AM_CONDITIONAL(C2, [test -n "$two"])
+AM_CONDITIONAL(C3, [test -z "$three"])
 AC_SUBST([MYSUB], [foo.o])
 AC_OUTPUT
 EOF
@@ -41,7 +42,12 @@
 # using some self computed a_DEPENDENCIES variable.
 endif
 if C2
-a_LDADD = bar.o
+if C3
+BAR = bar.o
+else
+BAR = baz.o
+endif
+a_LDADD = $(BAR)
 endif
 print:
        @echo BEG: $(a_DEPENDENCIES) :END
@@ -56,7 +62,12 @@
 cat stdout
 grep 'BEG: foo.o nonsense.a :END' stdout
 
-./configure two=yes
+./configure two=yes three=
 $MAKE -e print > stdout
 cat stdout
 grep 'BEG: bar.o :END' stdout
+
+./configure two=yes three=yes
+$MAKE -e print > stdout
+cat stdout
+grep 'BEG: baz.o :END' stdout
Index: tests/exeext4.test
===================================================================
RCS file: /cvs/automake/automake/tests/exeext4.test,v
retrieving revision 1.2
diff -u -r1.2 exeext4.test
--- tests/exeext4.test  14 May 2005 20:28:55 -0000      1.2
+++ tests/exeext4.test  29 Jan 2006 12:38:57 -0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2003  Free Software Foundation, Inc.
+# Copyright (C) 2003, 2006  Free Software Foundation, Inc.
 #
 # This file is part of GNU Automake.
 #
@@ -18,13 +18,15 @@
 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 
-# Make sure $(EXEEXT) is not appended to @address@hidden
+# Make sure $(EXEEXT) is appended to programs and to tests that are
+# programs, but not to @address@hidden
 
 . ./defs || exit 1
 
 set -e
 
 cat >> configure.in << 'END'
+AM_CONDITIONAL([COND], [test -n "$cond"])
 AC_SUBST([programs], ['prg1$(EXEEXT) prg2$(EXEEXT)'])
 AC_PROG_CC
 AC_OUTPUT
@@ -32,12 +34,24 @@
 
 cat > Makefile.am << 'END'
 EXEEXT = .bin
-bin_PROGRAMS = $(programs) @programs@ prg3
+if COND
+  BAR = bar
+  DEP = bar
+  BAZE = baz$(EXEEXT)
+  BAZ = baz $(DEP)
+endif
+bin_PROGRAMS = $(programs) @programs@ prg3 $(BAR) $(BAZE)
 EXTRA_PROGRAMS = prg1 prg2 prg3
+TESTS = prg1 prg3 prg4 $(BAZ)
+
 print-bin:
        echo BEG: $(bin_PROGRAMS) :END
 print-extra:
        echo BEG: $(EXTRA_PROGRAMS) :END
+print-tests:
+       echo BEG: $(TESTS) :END
+print-barbaz:
+       echo BEG: $(BAR) $(BAZ) :END
 END
 
 $ACLOCAL
@@ -50,3 +64,17 @@
 $MAKE print-extra > output
 cat output
 grep 'prg1.bin prg2.bin prg3.bin' output
+$MAKE print-tests > output
+cat output
+grep 'prg1.bin prg3.bin prg4' output
+
+./configure cond=yes
+$MAKE print-bin > output
+cat output
+grep 'prg1.bin prg2.bin prg1.bin prg2.bin prg3.bin bar.bin baz.bin' output
+$MAKE print-tests > output
+cat output
+grep 'prg1.bin prg3.bin prg4 baz.bin bar.bin' output
+$MAKE print-barbaz > output
+cat output
+grep 'bar baz bar' output

-- 
Alexandre Duret-Lutz

Shared books are happy books.     http://www.bookcrossing.com/friend/gadl





reply via email to

[Prev in Thread] Current Thread [Next in Thread]