[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AM_CONDITIONAL + AM_COND_IF does not work
From: |
Tom Ghyselinck |
Subject: |
Re: AM_CONDITIONAL + AM_COND_IF does not work |
Date: |
Tue, 10 Mar 2015 19:11:23 +0100 |
Hi,
I had a similar issue and solved it as follows:
use AC_CONFIG_FILES with and AC_SUBST-ed variable:
AC_SUBST([VARIABLE_CONTAINING_MY_MAKEFILES])
AC_CONFIG_FILES([${VARIABLE_CONTAINING_MY_MAKEFILES}])
Snippet from our solution (little bit adjusted to match your issue):
_EXCENTIS_PROTOBUF_MAKEFILES=
AC_MSG_CHECKING([Excentis PROTOBUF ${srcdir}/src/Makefile.am exists])
AM_CONDITIONAL([EXCENTIS_PROTOBUF__BUILD_FROM_SOURCE], [test -f
"${srcdir}/src/Makefile.am"])
dnl
dnl AC_CONFIG_FILES within AS_IF does not work here because automake
dnl does not check it when processing `Makefile.am` in
`AC_CONFIG_FILES`!
dnl
dnl See also
[http://www.gnu.org/software/automake/manual/html_node/Requirements.html] for
more information
dnl
dnl See
[http://www.gnu.org/software/automake/manual/html_node/Usage-of-Conditionals.html#Usage-of-Conditionals]
dnl for the fix.
dnl
dnl => Defining _EXCENTIS_PROTOBUF_MAKEFILES variable
dnl
AM_COND_IF([EXCENTIS_PROTOBUF__BUILD_FROM_SOURCE],
[AC_MSG_RESULT([yes])
_EXCENTIS_PROTOBUF_MAKEFILES="src/Makefile"],
[AC_MSG_RESULT([no])])
dnl
dnl @note
dnl Automake processing `AC_CONFIG_FILES` with variable subtitution
dnl only works when the variable is `AC_SUBST`ed
dnl
dnl See also
[http://www.gnu.org/software/automake/manual/html_node/Requirements.html]
dnl
AC_SUBST([_EXCENTIS_PROTOBUF_MAKEFILES])
AC_CONFIG_FILES([${_EXCENTIS_PROTOBUF_MAKEFILES}])
I hope this helps!
With best regards,
Tom.
On di, 2015-03-10 at 10:02 +0100, Marc Wäckerlin wrote:
> Hi Gavin
>
> Thank you, that helps up to the next step ...
>
> Am 09.03.2015 18:45, schrieb Gavin Smith:
> > automake doesn't know or care that one of these uses of
> > AC_CONFIG_FILES was conditional. It is looking for the input files to
> > automake (like "Makefile.am"), which it will derive from the arguments
> > to AC_CONFIG_FILES. It wouldn't be possible for these input files to
> > be defined conditionally in the configure script, because logically
> > automake runs before the configure script.
>
> That's what I thought, so AM_COND_IF + AC_CONFIG_FILES only works for
> existing files, but not in my case. A limitation, that should be better
> documented ...
>
> In my eyes, this behaviour is a bug, automake should not test, read or
> evaluate conditional files, if the condition does not match.
>
>
> Now, is there a way to workaround that?
>
> Your idea is a good approach:
>
> > The automake manual says that automake won't recognize an argument to
> > AC_CONFIG_FILES if its value is given indirectly through a shell
> > variable (see "Requirements" node), so maybe you could try that.
>
> It works, e.g. I always generate RPM spec files by filling in configure
> information:
> ------------------------------------------
> AC_CONFIG_FILES([${PACKAGE_NAME}.spec])
> ------------------------------------------
>
> That works great. But here, automake is not involved. Unfortunately,
> variables seem not to work, if automake is required. The code:
> ------------------------------------------
> makefile=makefile
> AM_CONDITIONAL([HAVE_SRC_DIR], [test -f src/${makefile}.am])
> AM_COND_IF([HAVE_SRC_DIR], [AC_CONFIG_FILES([src/${makefile}])])
> ------------------------------------------
> does not generate "src/makefile.in" by automake, as it should.
>
> So, the meaning od the above mentioned manual text is: "variables don't
> work with automake" ... :(
>
>
> Other ideas? Other solutions?
>
> Am I the only one with dozens of similar projects who wants to save some
> typing ...? ;)
>
>
>
>
> > On 9 March 2015 at 15:06, Marc Wäckerlin <address@hidden> wrote:
> >> I try to generically find out, whether examples/makefile.am exists in
> >> a
> >> project and to automatically use it, if it exists:
> >> ------------------------------------------
> >> AM_CONDITIONAL([HAVE_EXAMPLES_DIR], [test -f examples/makefile.am])
> >> AM_COND_IF([HAVE_EXAMPLES_DIR],
> >> [AC_CONFIG_FILES([examples/makefile])])
> >> ------------------------------------------
>
> A note for those who did not understand the intention:
>
> If and only if file "examples/makefile.am" exists, then it should be
> added to "AC_CONFIG_FILES". That means, it is possible and wanted
> behavior that "examples/makefile.am" does not exists, then it should
> simply not be added. So if "examples/makefile.am" does not exists, also
> "examples/makefile.in" will not exist.
>
> The idea behind: I have a standard project setup, where examples, tests
> and other subdirectories are optional and I want to write a generic
> M4-file that scans for the existing makefiles and automatically adds
> those that exist.
>
> So, yes the file does not exits, but no, it does not have to, since
> that's exactly the idea of the test: Find out if it exists and use it in
> case it exists.
>
>
>
> Thank you
> Regards
> Marc
--
________________________________________________________________________
| address@hidden
|
| Tom Ghyselinck
| Senior Engineer
| Excentis N.V.
| Gildestraat 8 B-9000 Ghent, Belgium
| Tel: +32 9 269 22 91 - Fax: +32 9 329 31 74
________________________________________________________________________