Export an environment variable using a make target in MacOS - linux

Might sound like a very noob question, but what I want to do is create and set an env variable via a make target and access that env variable through other make targets.
I have tried the below and few other variations of it, but cannot figure it out.
.PHONY: exporttest
exporttest:
export MY_ENV_VAR=$(shell echo "Bang")
One of my colleagues ran the same target on his Mac and the env variable was set.
Please advise how I can get this done/fix my Mac?

Related

How do I set an environmental variable on my target board using a yocto recipe?

I would like to create an environmental variable called BOARD that is set to the physical board type from a Yocto recipe. This variable will not be used during the actual installation of recipes. I would also like to modify the HOME variable. These variables need to be accessible on the board after it is booted. What is the best of doing so?
I have tried using export but realized that this command doesn't affect the parent shell. I have read about modifying the dot.profile file, but I don't want to hard code a variable. I would like it to dynamically alter the variable depending on what MACHINE variable was used to run bitbake.
For example in the dot.profile file:
export BOARD = "${MACHINE}"
However, MACHINE doesn't seem to be accessible.
You can add something like this in image recipe or local.conf:
set_board_env(){
mkdir -p ${IMAGE_ROOTFS}/etc/profile.d
echo "export BOARD=${MACHINE}" > ${IMAGE_ROOTFS}/etc/profile.d/set_board_env
}
ROOTFS_POSTPROCESS_COMMAND += "set_board_env;"

Windows 7: What PATH to set to when using Conda

I've got anaconda installed and was able to create a Python 3.3 environment. I can switch to it and conda info -e shows that I've switched.
However, I'm confused about what to set my PATH variable to. If I hard code it to the exact env then it works, but I thought that the purpose of conda was to be able to switch easily, as well as update and maintain various environments separately.
Perhaps I misunderstood and there's no way around setting my PATH everytime...
In the Windows cmd shell, use the activate and deactivate commands to change the PATH automatically. For instance, if your environment is called python3, run python3 to "activate" (i.e., add to the PATH) the python3 environment. Use deactivate to remove it.

Where to define the postactivate hook with virtualenvwrapper-win?

I'm using virtualenvwrapper-win and want to use the postactivate hook of virtualenvwrapper to set environment variables. However it seems virtualenvwrapper-win doesn't include a postactivate file, and I haven't been able to get it to work by creating my own. Does anybody know how to get the postactivate hook to work with virtualenvwrapper-win?
I want to include this in postactivate to set an environment variable: SET APP_SETTINGS="example.setting"
I actually solved it myself. You can put any environment variables in the activate.bat file in the Scripts folder of your virtualenv.
If you have already defined your VIRTUALENVWRAPPER_HOOK_DIR variable, just add this line to workon.bat.
call "%VIRTUALENVWRAPPER_HOOK_DIR%\postactivate.bat"
Just make sure you put it above :END

cmake : Set environment variables from a script

I have a script that sets all variables needed for the cross-compilation. Here is just part of it :
export CONFIG_SITE=~/workspace/eldk-5.4/powerpc/site-config-powerpc-linux
export CC="powerpc-linux-gcc -m32 -mhard-float --sysroot=~/workspace/eldk-5.4/powerpc/sysroots/powerpc-linux"
export CXX="powerpc-linux-g++ -m32 -mhard-float --sysroot=~/workspace/eldk-5.4/powerpc/sysroots/powerpc-linux"
export CPP="powerpc-linux-gcc -E -m32 -mhard-float --sysroot=~/workspace/eldk-5.4/powerpc/sysroots/powerpc-linux"
export AS="powerpc-linux-as "
export LD="powerpc-linux-ld --sysroot=~/workspace/eldk-5.4/powerpc/sysroots/powerpc-linux"
export GDB=powerpc-linux-gdb
If I do source environment-setup-powerpc-linux, all environment variables are imported into the current shell session, and I can compile my example.
Is it possible to import these variables in cmake? If yes, how?
A bit more details :
I am using ELDK v 5.4, and it's install script generates a script which sets all environment variables
I found this tutorial, which explains how to manually set for cross-compilation, but not how to use the script, which sets everything
if I call the script before setting cmake, all works fine, and I can cross-compile, but I'd like that cmake calls the script
Reading through the cmake quick start, you can specify variable on a command line:
cmake -DVARIABLE1=value1 -DVARIABLE2=value2 ...
Otherwise, set command in the cmake script is probably what you want, see the reference manual. To set the environment variable PATH, do:
set(ENV{PATH} "/home/martink")
To set normal variable, do:
set(variable "value")
Not sure which ones you have to set, probably the environment ones.
That said, setting environment variable prior to calling cmake is often the easiest solution to solve the problem. If you want a cross-platform way to do this that doesn't depend on the syntax of a specific shell to set environment variables, there is the cmake -E env command.
The only way to set a compiler and flags to do cross-compilation reliably with CMake is with a toolchain-file as done in the tutorial you have found.
When we faced the same issue you have (a toolkit which produces a script so set the compile-environment) we changed the toolkit in a way that it produces a toolchain-file along with the script.
In reality a cmake-toolchain-file does not change that often. The basic flags used for the target are fixed quite early in a project - normally. And with CMake's CMAKE_BUILD_TYPE you can switch between Debug and Release compilations without changing the toolchain-file.
If you have different targets to support, create different toolchain and use the out-of-source-build with CMake.
EDIT: One thing you could do is to invoke cmake with the -D-argument setting the variables you want to and having sourced your script before:
source environment-setup-powerpc-linux
cmake -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX etc
The result will be identical as to having used a toolchain-file.

How to set a windows env variable from cygwin .bashrc?

Background: I am trying to run a windows-installed version of python from within cygwin, rather than the cygwin version (some packages I am using prefer the non-cygwin version). The following post got me up and running: Using Windows Python from Cygwin. However, I am now having an issue.
Problem: The PYTHONPATH variable does not seem to be working for me. I try "import module1" when I am using python in an arbitrary directory. module1 is located here: c:\cygwin\home\mcsefl\testFolder\module1.py. And my PYTHONPATH variable is set in my .bashrc file in the following way: "export PYTHONPATH=$PYTHONPATH:/home/mcsefl/testFolder". However I still get a "No module named..." error.
Alternate tries: Since I am running the Windows Python, I thought perhaps python did not care about the cygwin environment variables (not sure if this is true..?) So, I also tried to set the windows PYTHONPATH env variable in the control panel of windows with no luck as well.
Thanks in advance
I deleted the line in my .bashrc file that tried to set the PYTHONPATH variable and just let it be set by Windows. This corrects the problem.
Side note: The title for this Question is a misnomer now that I re-read it. My issue was resolved without addressing that overall question

Resources