Xodarap
Xodarap

Reputation: 11849

Creating environment variables with a script for make

(Related to Shell script to export environment variables in make)

I want to use a shell script to create some variables that make can later use. I thought I could just source the script:

target:
  . myscript
  echo ${FOO}   # FOO is exported in myscript

but this doesn't seem to work. Is there a way to do this?

Upvotes: 0

Views: 132

Answers (3)

jjlin
jjlin

Reputation: 4703

Using an include directive to set a target-specific variable might be the closest thing to what you're asking for.

Upvotes: 1

William Pursell
William Pursell

Reputation: 212228

This will work, but not quite the way you have it. make invokes a new shell for each line, so in the example you give, echo ${FOO} is in a new shell. You could simply do:

target:
  . myscript; \
  echo $${FOO}

note that you need two '$' signs on the $${FOO}

Upvotes: 0

Kashyap
Kashyap

Reputation: 17411

How abt using an include directive instead. Put the variables defs in a separate makefile instead of a shell script.

Upvotes: 1

Related Questions