Archive: Determine whether an environment variable is set at build time


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.

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.


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

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 )


It is also visible in makensis /hdrinfo