user2928667
user2928667

Reputation: 31

How to conditionally include sub automake configuration files

I'm working in a project which uses automake to build the applications. We use one automake configuration file (Makefile.am) to build the application for multiple platforms. In this Makefile.am, platform specific sub automake configuration files (let's name them to Makefile.platform) are included like below:

include platform_A/Makefile.platform
include platform_B/Makefile.platform
...
include platform_X/Makefile.platform

What I want to do in a recent effort is to modify the Makefile.am to separate one of the platforms out while still keep it work for other platforms. I'm trying to do below

if PLATFORM_A
include platform_A/Makefile.platform
endif
include platform_B/Makefile.platform
...
include platform_X/Makefile.platform

But it seems that "include" takes effect before if/endif is evaluated, which means, if I remove "platform_A/Makefile.platform", automake will fail to parse Makefile.am successfully when I tried to build applications for other platforms (such as platform_B & platfrom_X)as it can't find "platform_A/Makefile.platform".

Could any expert here tell me how to conditionally include the external files in automake configuration file? The "conditionally" here means that if the condition is not fulfilled, the external file will not be included (imported) at all.

Many thanks!

Upvotes: 3

Views: 1210

Answers (3)

umläute
umläute

Reputation: 31284

depending on what your Makefile-snippets do, you could get away with:

if PLATFORM_A
-include platform_A/Makefile.platform
endif

in this case, the Makefile-snippets are simply included and not parsed by automake. also note that if the -included snippet does not exist, no error will be generated (the important part is the hyphen (-) prefixed to include)

Upvotes: 3

ldav1s
ldav1s

Reputation: 16305

I don't know of a way to do what you want. You can flip the placement of the conditional around to accomplish the same thing:

Makefile.am

include platform_A/Makefile.platform
include platform_B/Makefile.platform
...

platform_A/Makefile.platform

if PLATFORM_A
...
endif

The description of the automake include directive says of included fragments:

Makefile fragments included this way are always distributed because they are needed to rebuild Makefile.in.

Upvotes: 0

Etan Reisner
Etan Reisner

Reputation: 80931

I can't speak for automake specifically but for GNU make at least ifeq/etc. works correctly to control conditional inclusion of makefiles.

$ more * | cat
::::::::::::::
Makefile
::::::::::::::
ifneq ($(ONE),)
include one.mk
endif
include two.mk
include both.mk

all: ;
::::::::::::::
both.mk
::::::::::::::
$(warning both.mk)
::::::::::::::
one.mk
::::::::::::::
$(warning one.mk)
::::::::::::::
two.mk
::::::::::::::
$(warning two.mk)
$ make
two.mk:1: two.mk
both.mk:1: both.mk
make: `all' is up to date.
$ make ONE=f
one.mk:1: one.mk
two.mk:1: two.mk
both.mk:1: both.mk
make: `all' is up to date.

Upvotes: 0

Related Questions