简体   繁体   中英

Checking environment variable in make through automake

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM