Archive: !define and environment variable


!define and environment variable
Hi all,

My installation requires a version number that is !define'd in the NSIS script. Is it possible to read a value from an environment variable (or pass a value to the compiler via command line) *at compile time*?

This would allow my "create release" batch to pass the version number to the NSIS script, thus freeing me from the need to set the version number there manually (which is rather error-prone).

Or is it, by some way, possible the other way round? Can the compiler "return" the version number to the calling batch?

I couldn't find anything useful when searching the forum and the net. Any idea or pointer would be greatly appreciated.

Regards,

Steve


I don't know whether NSIS can do it or not, someone else may provide an answer, but there are other preprocessors. My free PPWIZARD will certainly allow you to do this.

Bye
Dennis


Use the command line option /D to define you version.

makensis.exe /DVERSION=2 file.nsi

Make sure your script doesn't over right it though by doing the following.

!ifndef VERSION
!define VERSION 1
!endif


I couldn't find anything useful when searching the forum and the net. Any idea or pointer would be greatly appreciated.
Well, you didn't search hard enough... It's in the FAQ on the top of the page ;)

Works perfect, thanks a lot.

I must have been blind, though ... shouldn't have worked so late last night!

Steve


no problem and i know the feeling, hehe


Originally posted by dselkirk
Use the command line option /D to define you version.

makensis.exe /DVERSION=2 file.nsi

Make sure your script doesn't over right it though by doing the following.

!ifndef VERSION
!define VERSION 1
!endif
Ok, you just lost me. I am using code similar to what you said above, and it's not working. It shouldn't enter the ifndef unless it's not defined, right?

Lookie here:

I call

Makensis /V3 /NOCONFIG /HDRINFO /CD /DMAJORVER=2 /DMINORVER=2 /DMICROVER=0 TechDemo.nsi

In the nsi, I have this code:

!ifndef ${MAJORVER}
!warning "MAJORVER not defined."
!define MAJORVER 0
!endif

!ifndef ${MINORVER}
!warning "MINORVER not defined."
!define MINORVER 0
!endif

!ifndef ${MICROVER}
!warning "MICROVER not defined."
!define MICROVER 0
!endif

But get this error!:

warning: !warning: MAJORVER not defined. (TechDemo.nsi:35)

!define: "MAJORVER" already defined!
Error in script "TechDemo.nsi" on line 36 -- aborting creation process

Am I overlooking something?

You should call the ifndef like this:

!ifndef MAJORVER

${MAJORVER} translates to its value and because of that NSIS tries to see if 2 is not defined, which is of course true.


OK, in retrospect that should have been obvious. Thank you!