Archive: How to check env-var on compile time


How to check env-var on compile time
HELP. I'd like to check whether an environment variable is defined when compiling an nsi file(because which files to pack relies on that env-var).

To check env-var UTBS, I tried :


!if "$%UTBS%" == ""
!echo "Env-var UTBS is not defined. I cannot continue."
!else
!echo "Env-var UTBS is defined to $%UTBS%"
!endif



If UTBS is defined, NSIS compiler outputs what we expect, i.e. %UTBS% is replaced with what UTBS's value is.

But if UTBS is not defined, it outputs

Processing script file: "checkenv.nsi"
Env-var UTBS is defined to $%UTBS% (checkenv.nsi:5)
That is not I'm expecting.

What can I do? (using NSIS v2.31)

Edit: My workaround... It didn't work. :)

Edit 2:
Okay this one should work...

!define S $

!if "$%UTBS%" == "${S}%UTBS%"
!echo "Env-var UTBS is not defined. I cannot continue."
!else
!echo "Env-var UTBS is defined to $%UTBS%"
!endif

In compile time $$ constants doesn't work in front of the environment variable. So using !if "$%UTBS%" == "$$%UTBS%" didn't work.

Thank you very much. Your trick really works.