Checking environment variable in make through automake

蹲街弑〆低调 提交于 2020-02-25 02:12:47

问题


Is there a way to have a conditional passed through automake so it is passed on to the resulting Makefile.in and Makefile later on?

I check whether JAVA_HOME is defined in the environment in a Makefile using

ifeq (undefined,$(origin JAVA_HOME))
#CALL with defaults
else
#CALL according to the variable
endif

But when I process this in a Makefile.am with automake I get two erros:

else without if
endif without if

Looks like automake does not digest the ifeq. Is there a way to pass this through it (if it makes sense doing so), or is there another autotools-friendly way of getting the same result?

The idea is also to allow setting/changing the variable just before running make to easily target different JDKs.


回答1:


What I think's the right way:

Rely on $(JAVA_HOME) being set in Makefile.am and make sure a sensible value for it is set by configure.

Answering the Question as Written:

Because automake wants to generate Makefiles that work on POSIX make, it doesn't work too well with GNU-make conditionals.

So you do the test in configure.ac:

AC_SUBST([JAVA_HOME])
AM_CONDITIONAL([JAVA_HOME_SET], [test ! -z "$JAVA_HOME"])

Then in Makefile.am:

if JAVA_HOME_SET
## Something that relies on JAVA_HOME
else
## Defaults
endif


来源:https://stackoverflow.com/questions/15368848/checking-environment-variable-in-make-through-automake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!