Is it possible to update the environment from a makefile? I want to be able to create a target to set the client environment variables for them. Something like this:
AXIS2_HOME ?= /usr/local/axis2-1.4.1 JAVA_HOME ?= /usr/java/latest CLASSPATH := foo foo setenv: export AXIS2_HOME export JAVA_HOME export CLASSPATH
So that the client can simply do:
make setenv all java MainClass
and have it work without them needing to set the classpath for the java execution themselves.
Or am I looking to do this the wrong way and there is a better way?
No, you can’t update the environment in the calling process this way. In general, a subprocess cannot modify the environment of the parent process. One notable exception is batch files on Windows, when run from a cmd shell. Based on the example you show, I guess you are not running on Windows though.
Usually, what you’re trying to accomplish is done with a shell script that sets up the environment and then invokes your intended process. For example, you might write a go.sh script like this:
Make go.sh executable and now you can run your app as
./go.sh. You can make your script more elaborate too, if you like — for example, you may want to make ‘MainClass’ a parameter to the script rather than hard coding it.