albttx
albttx

Reputation: 3784

Print Makefile variable as text

I didn't find anything about that, and i am trying to wrote this rule in my Makefile.

setenv:
    @echo "export DYLD_LIBRARY_PATH=."
    @echo "export DYLD_INSERT_LIBRARIES=$(NAME).so"
    @echo "export DYLD_FORCE_FLAT_NAMESPACE=1"
    @echo "# Run eval $$(make setenv)"

So by running eval $(make setenv) in my terminal, the environment variable will be set.

But it's starting an infinite loop.

I've also try with:

\$(make setenv)

but nothing work ... What is the correct syntax for this ?

EDIT:

\$$(make setenv) Did the trick !

Upvotes: 0

Views: 89

Answers (1)

Andrea Biondo
Andrea Biondo

Reputation: 1686

If you're setting environment variables for other recipes, note that:

  • Using $(shell export ...) won't work: $(shell ...) always spawns a new shell, so anything that is exported into it won't be available outside of that particular invocation;
  • Using export shell commands in a recipe will only work if .ONESHELL is used (not recommended), because each recipe line runs in a different shell.

The typical way to export environment variables to sub-makes and sub-shells is to use export as a Makefile directive, like this:

export DYLD_LIBRARY_PATH=.
export DYLD_INSERT_LIBRARIES=$(NAME).so
export DYLD_FORCE_FLAT_NAMESPACE=1

Outside any recipe.

Upvotes: 1

Related Questions