automake Environment Variable Condition

≯℡__Kan透↙ 提交于 2019-12-06 10:28:45

Use the AM_CONDITIONAL macro in configure.ac.

The script sets a variable you can test, e.g., a variable that is set to non-empty if the condition is enabled: AM_CONDITIONAL([ENABLE_SOURCECODEPATH], [test "x$ac_srcpath" != "x"])

Then in Makefile.am:

if !ENABLE_SOURCECODEPATH
SOURCECODEPATH = ...
endif

However, since you are explicitly defining the variable if it's not defined, you should probably define it in configure.ac regardless, using AC_SUBST(SRCPATH, $ac_srcpath) :

SOURCECODEPATH = @SRCPATH@ # or $(SRCPATH)

you could simply use an auxiliary makefile that get's included by Makefile.am (and it's expansion).

Makefile.am:

#...
include Makefile.env
#...

and Makefile.env:

ifndef SOURCECODEPATH
   SOURCECODEPATH := /home/root/source_code_path
endif

automake will not touch (or try to parse) the included Makefile.env

laindir

The following solution should work in at least GNU Make and BSD Make. The autotools solution by Brett Hale should work everywhere, but it's considerably more complex.

SOURCECODEPATH?=/home/root/source_code_path

You really should not be using automake to generate non-portable makefiles, but if you really want to do this to generate a Makefile for use with GNU make then you can simply add a space before the endif:

ifndef SOURCECODEPATH
   SOURCECODEPATH := /home/root/source_code_path
 endif

If the e is not in the first column, Automake will not try to parse endif as the end of an automake conditional, but will copy the text verbatim to the Makefile. GNU-make will recognize the conditional with the space (at least, 3.80 recognizes it. I haven't tried any others.)

Actually, as http://www.gnu.org/software/make/manual/make.html#Flavors says, ?= is used for variables declared with =. If you need set default values for variables declared with :=, use construction like this:

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