Setting TARGET_LLCFLAGS in the environment

Weird issue beyond my make-fu:

When running the test-suite, this works fine:

make TARGET_LLCFLAGS='-mcpu=cortex-a8 -mattr=+thumb2' TEST=nightly report

But this fails:

export TARGET_LLCFLAGS='-mcpu=cortex-a8 -mattr=+thumb2'
make TEST=nightly report

It looks like the following line from Makefile.rules is executed multiple times:

TARGET_LLCFLAGS += -relocation-model=pic -disable-fp-elim

This causes llc to complain about the -relocation-model and -disable-fp-elim options being given multiple times. (Sometime they are repeated three or four times).

Clearly there is some make magic I don't understand here. Does anyone know what is going on?

The variables set on the command-line to make are passed along to recursive makes via $(MAKEFLAGS). If you set TARGET_LLCFLAGS on the command-line, every recursive invocation is going to get that same value and will add “-relocation-model=pic -disable-fp-elim” only once. But, if you don’t set it on the command-line, make will pick up the value from the environment and add those extra options to whatever it finds. I bet it is then updating the environment value, so that a child make process will see the value that already has the extra options. If that child make also includes Makefile.rules, it will then add another copy of the extra options. Each level of recursive make will keep adding another copy. (The way that make interacts with the environment is confusing, so I’m not 100% sure this is what’s happening but it matches the symptoms you are seeing.)

That makes sense. I think the number of extra arguments added was dependent on the directory level of the test case.

One rather horrible fix would be

TARGET_LLCFLAGS := $(filter-out -relocation-model=pic, $TARGET_LLCFLAGS) -relocation-model=pic

Or I can just keep on typing in the long command lines...

Thanks!

/jakob