I have a simple Makefile:
app : app.cpp
g++ -c app.cpp -o app
but my application demands that var environment variable is set (var := “/etc/file.cfg”), how to do this in Makefile? I mean, how to make it that after I ran command make Makefile I wold be able to do this:
mazix@computer:~/Desktop/ echo $(var) and I will be able to see “/etc/file.cfg” ?
A process can’t set an environment variable in its parent process; that’s just how UNIX works.
You can create a small script which sets the variable and runs the program. If the contents of the script are somewhat variable you could write your Makefile to generate the script for you:
Alternately, your Makefile could display a string meant to be copied and pasted into your
~/.profilefile, consisting of the command or commands to set those environment variables: