- NSIS Discussion
- Conditional Compilation
Archive: Conditional Compilation
flizebogen
20th February 2005 07:59 UTC
Conditional Compilation
For some times i'm searching for a method to control the compile process, that for example compiling with an old version aborts the compile or changes a (few) line(s) because of limitations in the old versions.
I found the following in the RFE on Sourcefoge:
!define "ver_${NSIS_VERSION}"
!ifdef "ver_v2.05"
File /r /x .svn "${QUELLE_TC}\*.*"
!else
File /r "${QUELLE_TC}\*.*"
!endif
Unfortunatley this only works for a specific version. Is there a solution for any future versions? The sample above differs between pre 2.05 and 2.05 or higher. Perhaps something like the code below would be possible.
!ifdef "$NSIS_VERSION" >= "v2.05"
File /r /x .svn "${QUELLE_TC}\*.*"
!else
File /r "${QUELLE_TC}\*.*"
!endif
I don't want to change the code with every new nsis release.
Regards flizebogen
Afrow UK
20th February 2005 12:36 UTC
Do you know when NSIS_VERSION was introduced into NSIS?
I couldn't find it at all in the change log. If it was added recently, then you could do a straight !ifdef NSIS_VERSION, because older versions might not have it defined.
-Stu
Afrow UK
20th February 2005 13:05 UTC
Ok, so it seems NSIS_VERSION was added in v2.0, so this will work.
!define "CheckVer_${NSIS_VERSION}"
!ifdef "CheckVer_" | "CheckVer_v2.0" | "CheckVer_v2.01" | "CheckVer_v2.02" | "CheckVer_v2.03" | "CheckVer_v2.04"
File /r "${QUELLE_TC}\*.*"
!else
File /r /x .svn "${QUELLE_TC}\*.*"
!endif
-Stu
flizebogen
20th February 2005 14:02 UTC
What a workaround. Not very pretty as the list increases with every new version for new commands. In my opinion the "!ifdef" command should have the posibility for value checks.
DrO
20th February 2005 14:46 UTC
doing a >= on of ifdef doesn't really work with the whole idea of a ifdef i think since it's just there to see if the value is defined and not to do a conditional test. maybe you could create some sort of normal function and then do some string based checks on that which would set a variable/register value that you could then compare against. it's not great solution but it's an alternative work around.
-daz
flizebogen
20th February 2005 18:07 UTC
The problem is that it has to be processed at compile-time and the list of compile-time commands isn't this big.
Maybe we need a complete new command life !if ? How about it?
eccles
21st February 2005 23:39 UTC
Another workaround, but should do the trick nicely (unless you're compiling on < Win2k...)
!ifdef NSIS_VERSION
!system `(if /i "${NSIS_VERSION}" geq "v2.05" echo !define FILE_X_SUPPORTED) >"$%TEMP%\temp.nsh"`
!include $%TEMP%\temp.nsh
!system `del "$%TEMP%\temp.nsh"`
!endif
OutFile iftest.exe
Section
!ifdef FILE_X_SUPPORTED
MessageBox MB_OK "Yes"
!else
MessageBox MB_OK "No"
!endif
SectionEnd
Larsen
3rd March 2006 10:28 UTC
Originally posted by eccles
[B]Another workaround, but should do the trick nicely (unless you're compiling on < Win2k...)
That solved my problem, too. Thanks.
I compile my script via batch file that asks the user which versionnumber to use.
As I find it better to check for a missing versionnumber in the script (instead of several batch files) I now use this:
!system `(if "${VERSION}" equ "" echo !define NO_VERSION) >"$%TEMP%\temp.nsh"`
!include $%TEMP%\temp.nsh
!system `del "$%TEMP%\temp.nsh"`
!ifdef NO_VERSION
!error "No version defined!"
!endif
I would appreciate it if there was a !if function that could check for empty strings. I guess this would be helpful for several other people.
Afrow UK
3rd March 2006 10:44 UTC
Do you mean empty constants?
!define "Empty_${Define}"
!ifdef Empty_
!error "Define -> Empty"
!else
!echo "Define -> OK"
!end if
-Stu
kichik
3rd March 2006 10:47 UTC
Originally posted by Larsen
I would appreciate it if there was a !if function that could check for empty strings. I guess this would be helpful for several other people.
2.15 will have !if. You can check it out with the
nightly build.
Larsen
3rd March 2006 11:02 UTC
@Stu: Thanks for the workaround.
@kichik: That´s good news.