4

I'm trying to pass a variable from my bitbake (.bb) recipe to a Makefile that I have it calling.

In my recipe I have:

export FOO="bar"

When it runs the do_compile() method I have it calling a Makefile I generated. In the Makefile I tested the variable was set correctly via:

ifeq ($(FOO), "bar")
    echo $(FOO) >> ./test.txt
else
    echo "Didn't work" >> ./test.txt
endif

When I bake the recipe I just see "Didn't work" in the log. I thought this was very strange because if I had FOO="bar" in my Makefile and just ran make, then I would see "bar" printed in the test file. So why didn't it "pass" correctly?

I ran one more test to verify, in my Makefile I only put this line:

echo $(FOO) >> ./always_print.txt

And then after baking the recipe I see bar printed in my "always_print.txt" file yet I see "Didn't work" printed in test.txt...

Does anyone have a clue what I'm doing wrong here?

Mike
  • 47,263
  • 29
  • 113
  • 177

2 Answers2

7

Before defining your do_compile method, you have to define the variable EXTRA_OEMAKE which this content:

EXTRA_OEMAKE = "FOO=bar"

After that, in your do_compile method you must call 'oe_runmake'. That call invokes the command 'make', and all contents defined in EXTRA_OEMAKE variable are passed as argument to the 'make' command. Hope this helps!

aicastell
  • 2,182
  • 2
  • 21
  • 33
  • The default behavior of this task is to run the oe_runmake function if a makefile (Makefile, makefile, or GNUmakefile) is found. If no such file is found, the do_compile task does nothing. – Dražen G. Jan 12 '22 at 14:06
6

The make language does not use " as a quoting character, so you're comparing $(FOO) against "bar" (quotes included). Just omit the quotes:

ifeq ($(FOO),bar)
  ...
Idelic
  • 14,976
  • 5
  • 35
  • 40
  • Thank you very much. I was making that too complex. One question for you, why was it working when I added FOO="bar" directly in my Makefile and running it with `make`? Is it because there's a difference in how it handles a local define vs. an exported one? – Mike Mar 13 '13 at 16:58
  • 2
    If you do `FOO="bar"` in the Makefile, then `$(FOO)` will include the quotes, so your original comparison will work. In `BitBake` the `"` character *is* used for quoting, so `export FOO="bar"` will result in `$(FOO)` containing the string `bar` (without quotes). – Idelic Mar 13 '13 at 17:10