Reading Makefile variables in golang when building Android

Viewed 325

In device/vendor/rules.mk we have couples of flags. For example:

INCLUDE_VENDOR_PACKAGES:=true

I am writing a go package to do some conditional operation based on above flag. I tried couples of ways to fetch this flag's value such as via Golang's os package API and via $ operator like we do in shell script. But none of these worked.

Is there anyway to fetch the flag from Makefile at build time in go packages?

1 Answers

Make variables are internal to make.* They are not (directly) exposed to the recipes running in rules (or to commands run by GNU function implementations). You need to make explicit provision for feeding these values to commands that make runs, generally either by explicitly placing the wanted values into individual commands' environments or by passing them as command-line arguments to those commands.


* However, one place that make obtains variable values is from like-named environment variables, which will also be available under some circumstances to commands that make runs in turn.

Related