Archive

Posts Tagged ‘env’

GNU Makefile setting env variables

January 12, 2019 Leave a comment

Problem:
Exporting env variables in Makefiles. The issue was that the environment variables were not visible across different targets. I needed the same env vars to be seen in both target1 and target2 below.

Solution:
Export the variables outside the target, eg at the top of the file.

VALUE1="myvalue1"
VALUE2="myvalue2"

export VALUE1
export VALUE2

target1:
    echo $VALUE1

target2:
    echo $VALUE2

Source:
https://stackoverflow.com/questions/2826029/passing-additional-variables-from-command-line-to-make
https://www.linuxquestions.org/questions/programming-9/exporting-makefile-variables-to-%24-shell-environment-807422/

Advertisements
Categories: bash, Interesting Tags: ,