+2003-01-19 Alexandre Duret-Lutz <adl@gnu.org>
+
+ * automake.texi (Conditional Programs): Show a sample Makefile.am.
+ Remind $(EXEEXT) must be appended to configure substitutions.
+ Show how Automake conditionals can be used instead.
+ * tests/exeext.test (check_PROGRAMS): Make sure EXEEXT is also
+ appended to conditionally defined programs.
+
2003-01-16 Jim Meyering <jim@meyering.net>
Accept --help and --version, and lots of syntactic clean-up.
@node Conditional Programs, , Conditional Sources, A Program
@subsection Conditional compilation of programs
+@cindex Conditional programs
+@cindex Programs, conditional
-Sometimes it is useful to determine the programs that are to be built at
-configure time. For instance, GNU @code{cpio} only builds @code{mt} and
-@code{rmt} under special circumstances.
+Sometimes it is useful to determine the programs that are to be built
+at configure time. For instance, GNU @code{cpio} only builds
+@code{mt} and @code{rmt} under special circumstances. The means to
+achieve conditional compilation of programs are the same you can use
+to compile source files conditionally: substitutions or conditionals.
-@cindex EXTRA_PROGRAMS, defined
+@subsubsection Conditional programs using @code{configure} substitutions
In this case, you must notify Automake of all the programs that can
possibly be built, but at the same time cause the generated
@samp{_PROGRAMS} definition, while listing all optionally built programs
in @code{EXTRA_PROGRAMS}.
@vindex EXTRA_PROGRAMS
+@cindex EXTRA_PROGRAMS, defined
+
+@example
+bin_PROGRAMS = cpio pax $(MT)
+libexec_PROGRAMS = $(RMT)
+EXTRA_PROGRAMS = mt rmt
+@end example
-Of course you can use Automake conditionals to determine the programs to
-be built.
+As explained in @ref{EXEEXT}, Automake will rewrite
+@code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
+@code{EXTRA_PROGRAMS}, appending @code{$(EXEEXT)} to each binary.
+Obviously it cannot rewrite values obtained at run-time through
+@code{configure} substitutions, therefore you should take care of
+appending @code{$(EXEEXT)} yourself, as in @code{AC_SUBST([MT],
+['mt$@{EXEEXT@}'])}.
+
+@subsubsection Conditional programs using Automake conditionals
+
+You can also use Automake conditionals (@pxref{Conditionals}) to
+select programs to be built. In this case you don't have to worry
+about @code{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
+
+@example
+bin_PROGRAMS = cpio pax
+if WANT_MT
+ bin_PROGRAMS += mt
+endif
+if WANT_RMT
+ libexec_PROGRAMS = rmt
+endif
+@end example
@node A Library, A Shared Library, A Program, Programs
#! /bin/sh
-# Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
#
# This file is part of GNU Automake.
#
# Test to make sure `.' in an exe name doesn't fool us.
# Report from Robert Collins.
+# Also make sure we rewrite conditionals variables.
. ./defs || exit 1
cat >> configure.in << 'END'
AC_PROG_CC
-AC_EXEEXT
+AM_CONDITIONAL([WANT_MT], [:])
+AM_CONDITIONAL([WANT_RMT], [:])
END
cat > Makefile.am << 'END'
## Use a different dir for each to make grep easy.
-bin_PROGRAMS = maude
+bin_PROGRAMS = maude
sbin_PROGRAMS = maude.static
## We don't define this one for now. Probably it is an error.
## noinst_PROGRAMS = maude2.exe
check_PROGRAMS = maude3$(EXEEXT)
+
+if WANT_MT
+ bin_PROGRAMS += mt
+endif
+if WANT_RMT
+ libexec_PROGRAMS = rmt
+endif
END
set -e
grep '^maude3$(EXEEXT):' Makefile.in
grep 'check_PROGRAMS =.*maude3$(EXEEXT)' Makefile.in
+
+grep '^mt$(EXEEXT):' Makefile.in
+grep '@WANT_MT_TRUE@bin_PROGRAMS =.* mt$(EXEEXT)' Makefile.in
+
+grep '^rmt$(EXEEXT):' Makefile.in
+grep '@WANT_RMT_TRUE@libexec_PROGRAMS =.*rmt$(EXEEXT)' Makefile.in