Reputation: 65
I write a makefile to set a environment variables in windows,but it does not work. like this
local:
set CONFIGOR_ENV=local
echo %CONFIGOR_ENV%
then i exec it,it print
set CONFIGOR_ENV=local
echo %CONFIGOR_ENV%
ECHO 处于关闭状态。
then i got it **It's not possible for a makefile to set up your environment. A makefile runs commands in a separate instance of a shell. Just like if you have two cmd.exe windows open and you set a variable in one of them, it's not set in the other one. That's the same way make works. **
so i update it,
local:
set CONFIGOR_ENV=local ^
echo %CONFIGOR_ENV%
but it print the same massage
set CONFIGOR_ENV=local ^
echo %CONFIGOR_ENV%
ECHO 处于关闭状态。
i also try the oneshell
.ONESHELL:
local:
set CONFIGOR_ENV=local ^
echo %CONFIGOR_ENV%
print:
set CONFIGOR_ENV=local ^
echo %CONFIGOR_ENV%
ECHO 处于关闭状态。
make version:
GNU Make 3.82.90
Built for i686-pc-mingw32
Copyright (C) 1988-2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
I want to know that can makefile set enviranment variables in windows?
Upvotes: 0
Views: 818
Reputation: 100866
I'm not sure why you're using ^
here. That escapes a character: it doesn't seem like it's useful in this context.
You can either write:
local:
set CONFIGOR_ENV=local & echo %CONFIGOR_ENV%
(in Windows batch files, &
is a command separator sort of like ;
in POSIX shell) or you can use .ONESHELL
, if your version of make supports it, but you should remove the ^
; by adding ^
you simply escape the newline so the entire thing is assigned to the variable; that is, you're running:
set CONFIGOR_ENV=local echo %CONFIGOR_ENV%
so after this the value of the CONFIGOR_ENV
variable will be local echo
.
Upvotes: 2