grahamk
11th November 2010 14:02 UTC
Determine whether an environment variable is set at build time
Does anyone know of a tidier/simpler way than this?
!searchreplace ENVTEMP '$%FOO%' '%FOO%' ''
!if '${ENVTMP}' == '$'
!echo "FOO is not set"
!endif
The idea here is that if FOO is defined, $%FOO% will be replaced with the contents of the FOO variable, and searchreplace will (probably) make no changes to that.
If it's not set, environment variable substitution will not happen, and searchreplace will leave only the dollar sign.
I was hoping to do something a bit more straightforward, like this:
!define ENVTMP '$%FOO%'
# This doesn't work
!if '${ENVTMP}' == '$$%FOO%'
!echo "FOO is not set"
!endif
but it looks like NSIS is doing environment substitution even though I tried to "escape" the dollar sign in the !if statement.
Animaether
11th November 2010 16:09 UTC
ran into that the other day in a mostly unrelated thread (Determining whether Win or Linux was compiling).. couldn't find any other method (stumbled upon searchreplace this morning) either.
Anders
11th November 2010 19:02 UTC
The NSIS parser is broken when it comes to $$ and a few other things, I'm thinking we need to add support for $\$
For now, try
!define DOLLAR $
!if '$%windir%' == '${DOLLAR}%windir%'
!warning "not set"
!else
!warning "is set"
!endif
@Animaether: !ifdef NSIS_WIN32_MAKENSIS
Animaether
11th November 2010 19:23 UTC
Anders.. ahh! okay.. DocNote: document NSIS_WIN32_MAKENSIS ;)
( it's currently hidden away in the version history, now that I do a search on it )
Anders
11th November 2010 20:15 UTC
It is also visible in makensis /hdrinfo