How to set environment variables in Makefile

How to set the child process environment variable in Makefile


I want to change this makefile:

to:

Unfortunately, the second one doesn't work (the node process will still run with the default setting.

What have I missed?

Reply:


By default, make variables are not exported to the environment of processes. However, you can use make to force them to do so. Change:

to:

(assuming you have a sufficiently modern version of GNU make> = 3.77).







As MadScientist pointed out, you can export individual variables with:

Or export variables for a specific target (target-specific variables):


You can also specify the destination to - you guessed it! - EXPORT ALL THINGS !!!:

See .EXPORT_ALL_VARIABLES





I only needed the environment variables locally to invoke my test command. Here is an example where multiple environment variables are set in a bash shell and the dollar login escaped.




I would rewrite the original target test, making sure that the required variable is defined IN THE SAME SUB-PROCESS as the application to start:

We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.