I have a file Makefile.am I am using to generate a Makefile. In the generated Makefile I want to have something like:
ifndef SOURCECODEPATH
SOURCECODEPATH := /home/root/source_code_path
endif
It seems so simple, does anyone know how I can do it?
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
:However, since you are explicitly defining the variable if it's not defined, you should probably define it in
configure.ac
regardless, usingAC_SUBST(SRCPATH, $ac_srcpath)
: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
:If the
e
is not in the first column, Automake will not try to parseendif
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.)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.
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:you could simply use an auxiliary makefile that get's included by Makefile.am (and it's expansion).
Makefile.am:
and Makefile.env:
automake
will not touch (or try to parse) theinclude
d Makefile.env