I'm trying to compile u-boot via Emacs' compilation mode, and it looks like Emacs doesn't know how to find bash environment variables. Even though I set them, and can compile via Emacs shell emulation, compilation mode still tries to compile as if they aren't there.
What do I need to do to make it more environment conscious?
This is where the environment variables of the process that started
emacs
are:You seem to be assuming that emacs was started from a bash session. However, often processes under X are started from an sh session, which would not read the environment variables you had set in your
~/.bashrc
script. One simple way to circumvent this is to change your~/.xinitrc
file to use bash instead of sh (it could be as simple as adding#!/bin/bash
at the top of the file).Source: gnu.org
It doesn't strictly answer your question, but you can always pass environment variables on the
make
command-line. For example : M-xcompile
RETmake -k CXXFLAGS='-Wall'
RETYou can try adding something like to your
.emacs
:Depending on whether you've set the env variables in
.bash_profile
or.bashrc
you might need to slightly adjust this snippet. The example is for thePATH
variable, which is a bit more special (since you have to setexec-path
in Emacs as well), but can be extended to work for arbitrary variables - you could have a list of variables that have to be read from.bashrc
and set into Emacs.I'm not sure whether you're using OS X or GNU/Linux. Starting Emacs from the GUI's menu-bar in Linux will typically result in an Emacs that does not have the same
PATH
as one launched from the command line. This problem dates back to the firstxdm
Xsession scripts, and while they are fairly easy to fix (basically use anXsessionwrapper
script that doesexec $SHELL -c Xsession
so the shell gets run before running the user's Xsession), nobody has bother to do so in a very long time (and I doubt that anyone will). As far as I know the problem is present even into moder xdm descendants such askdm
andgdm
.On OS X the handling of the env variables is another problem entirely and to get your ENV variables you typically have to run Emacs from the command line like this
/Applications/Emacs.app/Contents/MacOS/Emacs
or play with~/.MacOSX/environment.plist
. The code snippet I've provided should cover you in both cases though.Update
Recently this process was made easier by the exec-path-from-shell extension. It sets the emacs
$PATH
in more or less the same manner, but using an extension is generally preferable to hacking the solution yourself.