通过automake检查make中的环境变量

通过automake检查make中的环境变量

本文介绍了通过automake检查make中的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过自动make传递条件,以便随后将其传递给生成的Makefile.in和Makefile?

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?

我检查是否在环境中使用Makefile在文件中定义了JAVA_HOME

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

但是当我使用自动makemake在Makefile.am中处理此错误时,我得到两个错误提示:

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

else without if
endif without if

看起来像automake不会消化ifeq.有没有办法(如果有意义的话)通过它,还是有另一种自动工具友好的方法来获得相同的结果?

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?

该想法还允许在运行make之前设置/更改变量,以轻松地针对不同的JDK.

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

推荐答案

我认为正确的方法是

依靠在Makefile.am中设置的$(JAVA_HOME)并确保由configure为其设置一个合理的值.

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.

因为automake想要生成可在POSIX make上运行的Makefile,所以在GNU-make条件条件下效果不佳.

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

因此您可以在configure.ac中进行测试:

So you do the test in configure.ac:

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

然后在Makefile.am中:

Then in Makefile.am:

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

这篇关于通过automake检查make中的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 10:19